Skip to content

Commit

Permalink
IsolateVariable Or And
Browse files Browse the repository at this point in the history
  • Loading branch information
dharmatech committed Mar 1, 2015
1 parent 3bbdc98 commit d619517
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
19 changes: 2 additions & 17 deletions Symbolism/IsolateVariable.cs
Expand Up @@ -114,26 +114,11 @@ public static MathObject IsolateVariableEq(this Equation eq, Symbol sym)
throw new Exception();
}

public static MathObject IsolateVariableOr(this Or obj, Symbol sym)
{
return new Or() { args = obj.args.ConvertAll(elt => (elt as Equation).IsolateVariableEq(sym)) }.Simplify();
}

public static MathObject IsolateVariable(this MathObject obj, Symbol sym)
{
if (obj is Or) return (obj as Or).IsolateVariableOr(sym);

if (obj is And)
return new And()
{
args = (obj as And).args.Select(elt => elt.IsolateVariable(sym)).ToList()
}.Simplify();

// (obj as And).Map(elt => elt.IsolateVariable(sym))

// (obj as And).Map(IsolateVariable(sym))
if (obj is Or) return new Or() { args = (obj as Or).args.Select(elt => elt.IsolateVariable(sym)).ToList() }.Simplify();

// (obj as And).args.Select(_ => _.IsolateVariable(sym))
if (obj is And) return new And() { args = (obj as And).args.Select(elt => elt.IsolateVariable(sym)).ToList() }.Simplify();

if (obj is Equation) return (obj as Equation).IsolateVariableEq(sym);

Expand Down
4 changes: 4 additions & 0 deletions Tests/Tests.cs
Expand Up @@ -451,6 +451,10 @@ static void Main(string[] args)
.IsolateVariable(b)
.AssertEqTo(new And(x == y, b == a));

new Or(new And(y == x, z == x), new And(b == x, c == x))
.IsolateVariable(x)
.AssertEqTo(new Or(new And(x == y, x == z), new And(x == b, x == c)));

Assert((0 == x - y).IsolateVariableEq(x).Equals(x == y), "(0 == x - y).IsolateVariable(x).Equals(x == y)");

Func<MathObject, MathObject> sqrt = obj => obj ^ (new Integer(1) / 2);
Expand Down

0 comments on commit d619517

Please sign in to comment.