nerdamer
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -9,3 +9,3 @@ { | ||
"license": "MIT", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"homepage": "http://nerdamer.com/", | ||
@@ -12,0 +12,0 @@ "directory": { |
45
Solve.js
@@ -240,3 +240,3 @@ /* | ||
var __ = core.Solve = { | ||
version: '2.0.1', | ||
version: '2.0.2', | ||
solutions: [], | ||
@@ -846,2 +846,33 @@ solve: function (eq, variable) { | ||
} | ||
}, | ||
sqrtSolve: function(symbol, v) { | ||
var sqrts = new Symbol(0); | ||
var rem = new Symbol(0); | ||
if(symbol.isComposite()) { | ||
symbol.each(function(x) { | ||
if(x.fname === 'sqrt' && x.contains(v)) { | ||
sqrts = _.add(sqrts, x.clone()); | ||
} | ||
else { | ||
rem = _.add(rem, x.clone()); | ||
} | ||
}); | ||
//quick and dirty ATM | ||
if(!sqrts.equals(0)) { | ||
var t = _.expand(_.multiply(_.parse(symbol.multiplier), _.subtract(_.pow(rem, new Symbol(2)), _.pow(sqrts, new Symbol(2))))); | ||
//square both sides | ||
var solutions = solve(t, v); | ||
//test the points. The dumb way of getting the answers | ||
solutions = solutions.filter(function(e) { | ||
if(e.isImaginary()) | ||
return e; | ||
var subs = {}; | ||
subs[v] = e; | ||
var point = evaluate(symbol, subs); | ||
if(point.equals(0)) | ||
return e; | ||
}); | ||
return solutions; | ||
} | ||
} | ||
} | ||
@@ -881,5 +912,5 @@ }; | ||
} | ||
//parse out functions. Fix for issue #300 | ||
//eqns = core.Utils.evaluate(eqns); | ||
solutions = solutions || []; | ||
@@ -955,2 +986,3 @@ //mark existing solutions as not to have duplicates | ||
var correct_denom = function (symbol) { | ||
symbol = _.expand(symbol); | ||
var original = symbol.clone(); //preserve the original | ||
@@ -1066,2 +1098,6 @@ | ||
} | ||
//try for nested sqrts as per issue #486 | ||
add_to_result(__.sqrtSolve(eq, solve_for)); | ||
//polynomial single variable | ||
@@ -1109,4 +1145,7 @@ if (numvars === 1) { | ||
else if (deg === 3) { | ||
var solutions = []; //set to blank | ||
//first try to factor and solve | ||
var solutions = solve(core.Algebra.Factor.factor(eqns)); | ||
var factored = core.Algebra.Factor.factor(eqns); | ||
//if it was successfully factored | ||
var solutions = !factored.equals(eqns) ? solve(factored, solve_for) : []; | ||
if(solutions.length > 0) | ||
@@ -1113,0 +1152,0 @@ add_to_result(solutions); |
@@ -177,2 +177,18 @@ /* global expect */ | ||
expected: '[a^(-1)*sqrt(-a),-a^(-1)*sqrt(-a)]' | ||
}, | ||
{ | ||
//NOTE: 4503599627370497/4503599627370496 result can be safely removed since it has rounding errors | ||
given: 'solve(sqrt(x)-2x+x^2,x)', | ||
expected: '[(1/2)*(-sqrt(5)+3),0,1,4503599627370497/4503599627370496]' | ||
}, | ||
{ | ||
given: 'solve((2x+x^2)^2-x,x)', | ||
expected: '[0,(-1/3)*(-43+3*sqrt(177))^(1/3)*2^(-1/3)+(-4/3)*(-43+3*sqrt(177))^(-1/3)*2^(1/3)-4/3,'+ | ||
'(1/6)*((-43+3*sqrt(177))^(1/3)*2^(-1/3))^(-1)*(-4*i*sqrt(3)+4)+(1/6)*(-43+3*sqrt(177))^(1/3)*'+ | ||
'(1+i*sqrt(3))*2^(-1/3)-4/3,(1/6)*((-43+3*sqrt(177))^(1/3)*2^(-1/3))^(-1)*(4+4*i*sqrt(3))+(1/6)*'+ | ||
'(-43+3*sqrt(177))^(1/3)*(-i*sqrt(3)+1)*2^(-1/3)-4/3]' | ||
}, | ||
{ | ||
given: 'solve((5*x^4-2)/(x+1)/(x^2-1),x)', | ||
expected: '[(-316684236/398209345)*i,(316684236/398209345)*i,-72425485/91070226,72425485/91070226]' | ||
} | ||
@@ -179,0 +195,0 @@ ]; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
1210849
23834
1