Skip to content

Commit

Permalink
Passes more cases but unstable Solve.
Browse files Browse the repository at this point in the history
  • Loading branch information
corywalker committed Jan 23, 2018
1 parent 52f4452 commit b6501e1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
1 change: 1 addition & 0 deletions expreduce/iterspec.go
Expand Up @@ -167,6 +167,7 @@ func multiIterSpecFromLists(es *EvalState, lists []Ex) (mis multiIterSpec, isOk
return mis, false
}
mis.iSpecs = append(mis.iSpecs, is)
mis.shouldCont = mis.shouldCont && is.cont()
}
return mis, true
}
Expand Down
8 changes: 4 additions & 4 deletions expreduce/resources.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions expreduce/resources/power.m
Expand Up @@ -60,6 +60,7 @@
4^(-1/2) := 1/2;
16^(-1/2) := 1/4;
16^(1/2) := 4;
4^(1/2) := 2;
Power[Rational[a_?Positive,b_?Positive], 1/2] := Power[a, 1/2] * Power[b, -1/2];
Power[Power[x_, y_Rational], -1] := Power[x, -y];
(*We may want to deprecate this in favor of the general definition.*)
Expand All @@ -69,6 +70,7 @@
2, -1,
3, -I];
Complex[re_,im_]^n_Integer := Module[{theta = ArcTan[re,im]}, Sqrt[re^2+im^2]^n*Complex[Cos[n*theta],Sin[n*theta]]];
Power[ComplexInfinity+_, -1] := 0;
Attributes[Power] = {Listable, NumericFunction, OneIdentity, Protected};
Tests`Power = {
ESimpleExamples[
Expand Down
25 changes: 25 additions & 0 deletions expreduce/resources/solve.m
Expand Up @@ -5,6 +5,8 @@

containsOneOccurrence[eqn_Equal, var_Symbol] :=
Count[eqn, var, -1] == 1;
containsZeroOccurrences[eqn_Equal, var_Symbol] :=
Count[eqn, var, -1] == 0;

checkedConditionalExpression[e_, c_] :=
Module[{nextC = 1, res, reps, newC = -1},
Expand Down Expand Up @@ -166,6 +168,7 @@
(*Computer Algebra - Lecture Notes in Computer Science. vol. 7. DOI: 10.1007/3-540-11607-9_13*)
(* Available at: http://www.research.ed.ac.uk/portal/files/413486/Solving_Symbolic_Equations_%20with_PRESS.pdf *)
Solve[eqn_Equal, var_Symbol] := Module[{degree, collected},
If[containsZeroOccurrences[eqn, var], Return[{}]];
(* Attempt isolation *)
If[containsOneOccurrence[eqn, var], Return[isolateInEqn[eqn, var]]];

Expand All @@ -182,11 +185,33 @@
Print["Solve found no solutions"];
SolveFailed
];
solveMultOrdered[eqns_List, vars_List] :=
Module[{firstSol, secondSol, toSolve},
If[Length[eqns] =!= 2 || Length[vars] =!= 2, Return[SolveFailed]];
firstSol = Solve[eqns[[1]], vars[[1]]];
Print[firstSol];
If[Length[firstSol] =!= 1, Return[TooManySols1]];
toSolve := eqns[[2]] /. firstSol[[1, 1]];
secondSol = Solve[toSolve, vars[[2]]];
Print[secondSol];
If[Length[secondSol] =!= 1, Return[TooManySols2]];
firstSol = firstSol /. secondSol[[1]];
{{firstSol[[1, 1]], secondSol[[1, 1]]}}
];
Solve[eqn_Equal, vars_List] := Solve[eqn, vars[[Length[vars]]]];
Solve[eqns_List, vars_List] := Module[{res, currVarOrder},
res = Do[
res = solveMultOrdered[eqns, currVarOrder];
If[Head[res] === List, Return[res]];
, {currVarOrder, Permutations[vars]}];
If[res === Null, NoneFound, res]
];

(* Special cases for Solve: *)
Solve[False, _] := {};
Solve[True, _] := {{}};
Solve[{}, _] := {{}};
Solve[x_Symbol+E^x_Symbol==0, x_Symbol] := {{x->-ProductLog[1]}};
(* Currently needed for Apart: *)
(*Orderless matching would be nice here*)
Solve[{a_.*x_Symbol+b_.*y_Symbol==c_,d_.*x_Symbol+e_.*y_Symbol==f_},{x_Symbol,y_Symbol}] := {{x->-((c e-b f)/(b d-a e)),y->-((-c d+a f)/(b d-a e))}} /;FreeQ[{a,b,c,d,e,f},x]&&FreeQ[{a,b,c,d,e,f},y]
Expand Down

0 comments on commit b6501e1

Please sign in to comment.