Permalink
Browse files

Add overload for ==(MathObject a, int b) etc.

  • Loading branch information...
1 parent 6bf4724 commit b195a5dbf67be0d72837856f9eefa07a0307ccdc @dharmatech committed Feb 3, 2013
Showing with 30 additions and 17 deletions.
  1. +19 −6 Symbolism/Program.cs
  2. +11 −11 Tests/Program.cs
View
@@ -42,8 +42,6 @@ public abstract class MathObject
{ return new Integer(a) ^ b; }
#endregion
//////////////////////////////////////////////////////////////////////
-
- //////////////////////////////////////////////////////////////////////
#region overloads for 'double'
public static MathObject operator +(MathObject a, double b)
@@ -79,25 +77,37 @@ public abstract class MathObject
#endregion
//////////////////////////////////////////////////////////////////////
-
public static Equation operator ==(MathObject a, MathObject b)
{ return new Equation(a, b); }
+ public static Equation operator !=(MathObject a, MathObject b)
+ { return new Equation(a, b, Equation.Operators.NotEqual); }
+
+
public static Equation operator ==(MathObject a, double b)
{ return new Equation(a, new DoubleFloat(b)); }
public static Equation operator ==(double a, MathObject b)
{ return new Equation(new DoubleFloat(a), b); }
- public static Equation operator !=(MathObject a, MathObject b)
- { return new Equation(a, b, Equation.Operators.NotEqual); }
-
public static Equation operator !=(MathObject a, double b)
{ return new Equation(a, new DoubleFloat(b), Equation.Operators.NotEqual); }
public static Equation operator !=(double a, MathObject b)
{ return new Equation(new DoubleFloat(a), b, Equation.Operators.NotEqual); }
+
+ public static Equation operator ==(MathObject a, int b)
+ { return new Equation(a, new Integer(b)); }
+
+ public static Equation operator ==(int a, MathObject b)
+ { return new Equation(new Integer(a), b); }
+
+ public static Equation operator !=(MathObject a, int b)
+ { return new Equation(a, new Integer(b), Equation.Operators.NotEqual); }
+
+ public static Equation operator !=(int a, MathObject b)
+ { return new Equation(new Integer(a), b, Equation.Operators.NotEqual); }
//////////////////////////////////////////////////////////////////////
public static MathObject operator +(MathObject a, MathObject b)
{ return new Sum(a, b).Simplify(); }
@@ -132,6 +142,9 @@ public MathObject Substitute(MathObject a, MathObject b)
return this;
}
+ //public MathObject Substitute(MathObject a, int b)
+ //{ return Substitute(a, new Integer(b)); }
+
public int Precedence()
{
if (this is Integer) return 1000;
View
@@ -52,9 +52,9 @@ static void Main(string[] args)
AssertIsTrue(((((x * y) ^ (Int(1) / 2)) * (z ^ 2)) ^ 2) == (x * y * (z ^ 4)));
- AssertIsTrue(x / x == Int(1));
+ AssertIsTrue(x / x == 1);
- AssertIsTrue(x / y * y / x == Int(1));
+ AssertIsTrue(x / y * y / x == 1);
AssertIsTrue((x ^ 2) * (x ^ 3) == (x ^ 5));
@@ -74,14 +74,14 @@ static void Main(string[] args)
// Power.Simplify
- AssertIsTrue((0 ^ x) == Int(0));
- AssertIsTrue((1 ^ x) == Int(1));
- AssertIsTrue((x ^ 0) == Int(1));
+ AssertIsTrue((0 ^ x) == 0);
+ AssertIsTrue((1 ^ x) == 1);
+ AssertIsTrue((x ^ 0) == 1);
AssertIsTrue((x ^ 1) == x);
// Product.Simplify
- AssertIsTrue(x * 0 == new Integer(0));
+ AssertIsTrue(x * 0 == 0);
// Difference
@@ -90,8 +90,8 @@ static void Main(string[] args)
AssertIsTrue(x - y == x + -1 * y);
- AssertIsTrue(Int(10).Substitute(Int(10), Int(20)) == Int(20));
- AssertIsTrue(Int(10).Substitute(Int(15), Int(20)) == Int(10));
+ AssertIsTrue(Int(10).Substitute(Int(10), Int(20)) == 20);
+ AssertIsTrue(Int(10).Substitute(Int(15), Int(20)) == 10);
AssertIsTrue(new DoubleFloat(1.0).Substitute(new DoubleFloat(1.0), new DoubleFloat(2.0)) == 2.0);
AssertIsTrue(new DoubleFloat(1.0).Substitute(new DoubleFloat(1.5), new DoubleFloat(2.0)) == 1.0);
@@ -105,7 +105,7 @@ static void Main(string[] args)
AssertIsTrue((x ^ y).Substitute(x, Int(10)) == (10 ^ y));
AssertIsTrue((x ^ y).Substitute(y, Int(10)) == (x ^ 10));
- AssertIsTrue((x ^ y).Substitute(x ^ y, Int(10)) == Int(10));
+ AssertIsTrue((x ^ y).Substitute(x ^ y, Int(10)) == 10);
AssertIsTrue((x * y * z).Substitute(x, y) == ((y ^ 2) * z));
AssertIsTrue((x * y * z).Substitute(x * y * z, x) == x);
@@ -118,7 +118,7 @@ static void Main(string[] args)
.Substitute(x, Int(10))
.Substitute(y, Int(20))
.Substitute(z, Int(3))
- == Int(16200)
+ == 16200
);
Func<MathObject, MathObject> sin = arg => new Sin(arg).Simplify();
@@ -143,7 +143,7 @@ static void Main(string[] args)
AssertIsTrue(x != y);
- AssertIsTrue(x != new Integer(10));
+ AssertIsTrue(x != 10);
// ==(double a, MathObject b)

0 comments on commit b195a5d

Please sign in to comment.