Skip to content

Commit

Permalink
Tests for Together pass.
Browse files Browse the repository at this point in the history
  • Loading branch information
corywalker committed Jul 19, 2017
1 parent 5407f32 commit 365ccba
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions expreduce/resources/manip.m
@@ -1,20 +1,15 @@
DistributeMultiply[e_, multiplicand_] :=
ExpreduceDistributeMultiply[e_, multiplicand_] :=
If[Head[e] === Plus, (#*multiplicand) & /@ e, e*multiplicand];

Together::usage = "`Together[e]` attempts to put the terms in `e` under the same denominator.";
Together[(rest___ + a_*Rational[b_,c_])/d_] := (Print[5];Together[(a b+Expand[c Plus[rest]])/(c d)]);
Together[a_+Rational[b_,c_]*d_] := (Print[7];Together[(a c+b d)/c]);
Together[(rest___ + a_*Rational[b_,c_])/d_] := Together[(a b+Expand[c Plus[rest]])/(c d)];
Together[a_+Rational[b_,c_]*d_] := Together[(a c+b d)/c];
Together[(e_)^p_?((NumberQ[#] && # =!= -1)&)] := Together[Together[e]^p];

Together[(a_/b_+rest___)/d_] := (Print[1];Together[(a+Expand[DistributeMultiply[Plus[rest], b]])/(b d)]);
(*Together[(a_/b_+rest___)/(c_*d_)] := (Print[4];Together[(a+Expand[b Plus[rest]])/(b c d)]);*)
Together[a_/b_+c_+rest___] := (Print[2];Together[(a+b c)/b+rest]);
Together[1/(a__Plus) + b__] := (Print[3];Together[(1+Expand[a*Plus[b]])/(a)]);
Together[1/(a__Plus)+1/(b__Plus) + c___] := (Print[6];Together[(a+b+Expand[a*b*Plus[c]])/(a*b)]);
Together[1/(a_Symbol)+ rest___] := (Print[8];Together[(1+Expand[a*Plus[rest]])/(a)]);

(*Together[(b_/c_+rest__)*d_^(-1)*e_^(-1)] := (Print[9];Together[(b+Expand[c Plus[rest]])/(c d e)]);*)
(*Together[(b_/c_+rest__)*d_^(-1)*e_^(-2)] := (Print[9];Together[(b+Expand[c Plus[rest]])/(c d e^2)]);*)
Together[(a_/b_ + rest___)/d_] := Together[(a+Expand[ExpreduceDistributeMultiply[Plus[rest], b]])/(b d)];
Together[b_/a_ + rest___] := Together[(b+Expand[a*Plus[rest]])/(a)];
(* Needed because 1/a is actually a^-1 *)
Together[1/a_ + rest___] := Together[(1+Expand[a*Plus[rest]])/(a)];

Together[e_] := e;
Attributes[Together] = {Listable, Protected};
Expand All @@ -26,7 +21,7 @@
], ETests[
ESameTest[(c+a d+b d)/d, a+b+c/d//Together],
ESameTest[(a+b+c+d)/((a+b) (c+d)), 1/(a+b)+1/(c+d)//Together],
ESameTest[(a+b+c-a^2 c-a b c+d-a^2 d-a b d)/((a+b) (c+d)), 1/(a+b)+1/(c+d)-a//Together],
ESameTest[(a+b+c-a^2*c-a b c+d-a^2*d-a b d)/((a+b) (c+d)), 1/(a+b)+1/(c+d)-a//Together],
(*Only for when we have Cancel:*)
(*ESameTest[-(a/(2+a)), Together[a/(-2+a+a^2)-a^2/(-2+a+a^2)]],*)
ESameTest[(a+b c)/b, a/b+c//Together],
Expand All @@ -36,7 +31,7 @@
ESameTest[(6+a+2 b)/(2 a), (3+a/2+b)/a//Together],
ESameTest[a/(b e), (a/b)/e//Together],
ESameTest[(12+a)/(4 a), (3 + a*1/4)/a//Together],
ESameTest[1/2 (6+foo[a]), 3 + foo[a]*2/4//Together],
ESameTest[(1/2) (6+foo[a]), 3 + foo[a]*2/4//Together],
ESameTest[(6+a)/(2 a), 1/2 + 3/a//Together],
ESameTest[(a+b c)/(a b), (c+ a/b)/a//Together],
ESameTest[(a+b c+b e)/(b d), (c+e+ a/b)/d//Together],
Expand All @@ -46,12 +41,12 @@
ESameTest[(c+a d+b d)/d, Together[(c + a*d + b*d)/d]],
ESameTest[(6+a+2 b)/(2 a), (3+a/2+b)/a//Together],
ESameTest[a/(b e), (a/b)/e//Together],
ESameTest[(a+a^2 c+a b c+a d+b d)/(a (a+b)), Together[1/(a + b) + c+d/a]],
ESameTest[(a+a^2*c+a b c+a d+b d)/(a (a+b)), Together[1/(a + b) + c+d/a]],
ESameTest[(a+b) (c+d), (a+b)(c+d)//Together],
ESameTest[(a+b+c+d)/((a+b) (c+d)), 1/(a + b)+1/(c+d)//Together],
ESameTest[1/(a+b), 1/(a + b)//Together],
ESameTest[(a+b c e f)/(b c), a/(b*c)+(e*f)//Together],
ESameTest[(a+b+c-a^2 c-a b c+d-a^2 d-a b d)/((a+b) (c+d)), Together[1/(a + b) + 1/(c + d) - a]],
ESameTest[(a+b+c-a^2*c-a b c+d-a^2*d-a b d)/((a+b) (c+d)), Together[1/(a + b) + 1/(c + d) - a]],
ESameTest[(a+b)/(a b), 1/a+1/b//Together],
ESameTest[(a+b+a b c)/(a b), 1/a+1/b+c//Together],
ESameTest[(1+c d)/c, 1/c+d//Together],
Expand Down

0 comments on commit 365ccba

Please sign in to comment.