private void simplifyToolStripMenuItem_Click(object sender, EventArgs e) { PrintLine("P E R F O R M I N G S I M P L I F I C A T I O N T E S T S"); PrintLine("-------------------------------------------------------------"); try { var e1 = new Product(3, new Sum(x, y)); var e2 = new Sum(new Product(3, x), new Product(5, x)); PrintLine(e1.ToString() + " = " + Math.Simplify(e1).ToString(), Color.Blue); PrintLine(e2.ToString() + " = " + Math.Simplify(e2).ToString(), Color.Blue); PrintLine("SUCCESS", Color.Green); } catch (Exception ex) { PrintLine(ex.Message, Color.Red); } PrintLine(); }
/// <summary> /// Computes the symbolic addition between two expressions. /// </summary> /// <param name="E1">The first expression</param> /// <param name="E2">The second expression</param> public static Expression Add(Expression E1, Expression E2) { var O = new Sum(E1, E2); if (O.CanTransform()) return O.Apply(true); else return O; }
private void binaryOperationsToolStripMenuItem_Click(object sender, EventArgs e) { PrintLine("P E R F O R M I N G B I N A R Y O P E R A T I O N E Q U A L I T Y T E S T S"); PrintLine("-----------------------------------------------------------------------------------"); try { var s1 = new Sum(x, y); var s12 = new Sum(x, y); var s2 = new Sum(x, 2); var s3 = new Sum(y, x); var d1 = new Difference(x, y); var d12 = new Difference(x, y); var d2 = new Difference(x, 2); var d3 = new Difference(y, x); var p1 = new Product(x, y); var p12 = new Product(x, y); var p2 = new Product(x, 2); var p3 = new Product(y, x); var q1 = new Quotient(x, y); var q12 = new Quotient(x, y); var q2 = new Quotient(x, 2); var q3 = new Quotient(y, x); PrintLine("BASIC IDENTITY TESTS:"); PrintLine("(x + y) = (x + y) => " + (s1 == s12).ToString(), Color.Blue); PrintLine("(x + y) = (y + x) => " + (s1 == s3).ToString(), Color.Blue); PrintLine("(x + y) = (x + 2) => " + (s1 == s2).ToString(), Color.Blue); PrintLine("(x - y) = (x - y) => " + (d1 == d12).ToString(), Color.Blue); PrintLine("(x - y) = (y - x) => " + (d1 == d3).ToString(), Color.Blue); PrintLine("(x - y) = (x - 2) => " + (d1 == d2).ToString(), Color.Blue); PrintLine("(x * y) = (x * y) => " + (p1 == p12).ToString(), Color.Blue); PrintLine("(x * y) = (y * x) => " + (p1 == p3).ToString(), Color.Blue); PrintLine("(x * y) = (x * 2) => " + (p1 == p2).ToString(), Color.Blue); PrintLine("(x / y) = (x / y) => " + (q1 == q12).ToString(), Color.Blue); PrintLine("(x / y) = (y / x) => " + (q1 == q3).ToString(), Color.Blue); PrintLine("(x / y) = (x / 2) => " + (q1 == q2).ToString(), Color.Blue); var sr1 = new Sum(s1, z); var sr12 = new Sum(s1, z); var sr2 = new Sum(z, s1); var sr21 = new Sum(new Sum(z, y), x); var szc = new Sum(z, C); var sr3 = new Sum(s1, szc); var sr32 = new Sum(s1, szc); var scz = new Sum(C, z); var sr4 = new Sum(scz, s1); var dr1 = new Difference(d1, z); var dr12 = new Difference(d1, z); var dr2 = new Difference(z, d1); var dr21 = new Difference(new Difference(z, y), x); var dzc = new Difference(z, C); var dr3 = new Difference(d1, dzc); var dr32 = new Difference(d1, dzc); var dcz = new Difference(C, z); var dr4 = new Difference(dcz, d1); var pr1 = new Product(p1, z); var pr12 = new Product(p1, z); var pr2 = new Product(z, p1); var pr21 = new Product(new Product(z, y), x); var pzc = new Product(z, C); var pr3 = new Product(p1, pzc); var pr32 = new Product(p1, pzc); var pcz = new Product(C, z); var pr4 = new Product(pcz, p1); var qr1 = new Quotient(q1, z); var qr12 = new Quotient(q1, z); var qr2 = new Quotient(z, q1); var qr21 = new Quotient(new Quotient(z, y), x); var qzc = new Quotient(z, C); var qr3 = new Quotient(q1, qzc); var qr32 = new Quotient(q1, qzc); var qcz = new Quotient(C, z); var qr4 = new Quotient(qcz, q1); PrintLine("RECURSIVE IDENTITY TESTS:"); PrintLine("((x + y) + z) = ((x + y) + z) => " + (sr1 == sr12).ToString(), Color.Blue); PrintLine("((x + y) + z) = (x + (y + z)) => " + (sr1 == sr2).ToString(), Color.Blue); PrintLine("((x + y) + z) = ((z + y) + x) => " + (sr1 == sr21).ToString(), Color.Blue); PrintLine("((x + y) + (z + C)) = ((x + y) + (z + C)) => " + (sr3 == sr32).ToString(), Color.Blue); PrintLine("((x + y) + (z + C)) = ((C + z) + (x + y)) => " + (sr3 == sr4).ToString(), Color.Blue); PrintLine("((x - y) - z) = ((x - y) - z) => " + (dr1 == dr12).ToString(), Color.Blue); PrintLine("((x - y) - z) = (x - (y - z)) => " + (dr1 == dr2).ToString(), Color.Blue); PrintLine("((x - y) - z) = ((z - y) - x) => " + (dr1 == dr21).ToString(), Color.Blue); PrintLine("((x - y) - (z - C)) = ((x - y) - (z - C)) => " + (dr3 == dr32).ToString(), Color.Blue); PrintLine("((x - y) - (z - C)) = ((C - z) - (x - y)) => " + (dr3 == dr4).ToString(), Color.Blue); PrintLine("((x * y) * z) = ((x * y) * z) => " + (pr1 == pr12).ToString(), Color.Blue); PrintLine("((x * y) * z) = (x * (y * z)) => " + (pr1 == pr2).ToString(), Color.Blue); PrintLine("((x * y) * z) = ((z * y) * x) => " + (pr1 == pr21).ToString(), Color.Blue); PrintLine("((x * y) * (z * C)) = ((x * y) * (z * C)) => " + (pr3 == pr32).ToString(), Color.Blue); PrintLine("((x * y) * (z * C)) = ((C * z) * (x * y)) => " + (pr3 == pr4).ToString(), Color.Blue); PrintLine("((x / y) / z) = ((x / y) / z) => " + (qr1 == qr12).ToString(), Color.Blue); PrintLine("((x / y) / z) = (x / (y / z)) => " + (qr1 == qr2).ToString(), Color.Blue); PrintLine("((x / y) / z) = ((z / y) / x) => " + (qr1 == qr21).ToString(), Color.Blue); PrintLine("((x / y) / (z / C)) = ((x / y) / (z / C)) => " + (qr3 == qr32).ToString(), Color.Blue); PrintLine("((x / y) / (z / C)) = ((C / z) / (x / y)) => " + (qr3 == qr4).ToString(), Color.Blue); PrintLine("SUCCESS", Color.Green); } catch (Exception ex) { PrintLine(ex.Message, Color.Red); } PrintLine(); }
private static Expression SeperateIntegerProduct_Body(Product x) { //Seperate the integer and expression: Value I = 0; Expression E = 0; if (x.LeftExpression is Value) { I = x.LeftExpression as Value; E = x.RightExpression; } else if (x.RightExpression is Value) { I = x.RightExpression as Value; E = x.LeftExpression; } else throw new Exceptions.LogicException("Cannot transform expression - input expression is not a seperable integer product"); //If our integer product is negative, send it back through with the expression inverted if (I < -1) { return SeperateIntegerProduct_Body(new Product(-I, new Negation(E))); } //If our integer product is -1 if (I == -1) return new Difference(0, E); //If the integer value is 0, return 0 if (I == 0) return 0; //If the integer value is 1, return the other expression by itself if (I == 1) return E; //If the integer value is greater than 1 Expression Result = new Sum(E, E); for (int i = 2; i < I; i++) { Result = new Sum(Result, E); } return Result; }