Example #1
0
        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();
        }
Example #2
0
 /// <summary>
 /// Computes the symbolic division between two expressions.
 /// </summary>
 /// <param name="Numerator">The numerator expression</param>
 /// <param name="Denominator">The denominator expression</param>
 public static Expression Divide(Expression Numerator, Expression Denominator)
 {
     var O = new Quotient(Numerator, Denominator);
     if (O.CanTransform()) return O.Apply(true);
     else return O;
 }