Skip to content

Commit

Permalink
CheckVariableEqLs (1/a != 0 && a != 0) -> a != 0
Browse files Browse the repository at this point in the history
  • Loading branch information
dharmatech committed Jun 15, 2015
1 parent de4bede commit 287c61e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
12 changes: 12 additions & 0 deletions Symbolism/EliminateVariable.cs
Expand Up @@ -13,8 +13,20 @@ public static class Extensions
{
public static MathObject CheckVariableEqLs(this List<Equation> eqs, Symbol sym)
{
// (a == 10, a == 0) -> 10 == 0 -> false

if (eqs.EliminateVariableEqLs(sym) == false) return false;

// (1/a != 0 && a != 0) -> a != 0

if (eqs.Any(eq => eq.Operator == Equation.Operators.NotEqual && eq.a == sym && eq.b == 0)
&&
eqs.Any(eq => eq.Operator == Equation.Operators.NotEqual && eq.a == 1 / sym && eq.b == 0))
return eqs
.Where(eq => (eq.Operator == Equation.Operators.NotEqual && eq.a == 1 / sym && eq.b == 0) == false)
.ToList()
.CheckVariableEqLs(sym);

return new And() { args = eqs.Select(eq => eq as MathObject).ToList() };
}

Expand Down
8 changes: 4 additions & 4 deletions Tests/Tests.cs
Expand Up @@ -1228,25 +1228,25 @@ static void Main(string[] args)
new Or(
new And(
vyB == -1 * ay * sqrt(2 * (ay ^ -1) * ((ay ^ -1) / 2 * (vyA ^ 2) + -1 * yA + yB)),
(ay ^ -1) != 0,
// (ay ^ -1) != 0,
vxA != 0,
ay != 0),
new And(
vyB == ay * sqrt(2 * (ay ^ -1) * ((ay ^ -1) / 2 * (vyA ^ 2) + -1 * yA + yB)),
(ay ^ -1) != 0,
// (ay ^ -1) != 0,
vxA != 0,
ay != 0)))
.SubstituteEqLs(zeros)
.AssertEqTo(
new Or(
new And(
vyB == -ay * sqrt(-2 / ay * yA),
1 / ay != 0,
// 1 / ay != 0,
vxA != 0,
ay != 0),
new And(
vyB == ay * sqrt(-2 / ay * yA),
1 / ay != 0,
// 1 / ay != 0,
vxA != 0,
ay != 0)))
.SubstituteEqLs(vals)
Expand Down

0 comments on commit 287c61e

Please sign in to comment.