Beispiel #1
0
        public void DiffProduct()
        {
            Expression <Del2> expression = (x, y) => x * y;

            Assert.AreEqual(
                "y",
                ComputerAlgebra.Differentiate(expression.Body, variable: "x").ToString());
        }
Beispiel #2
0
        public void DiffPowConstant()
        {
            Expression <Del1> expression = (x) => Math.Pow(x, 3);

            Assert.AreEqual(
                new ScalarProduct <double>(new Constant <double>(3.0), new Pow <double>(VariableNode.Make <double>(0, "x"), new Constant <double>(2.0))).ToString(),
                ComputerAlgebra.Differentiate(Expressions2Tree.Parse(expression.Body), variable: "x").ToString());
        }
Beispiel #3
0
        public void DiffNegate()
        {
            Expression <Del1> expression = (x) => - x;

            Assert.AreEqual(
                "-1",
                ComputerAlgebra.Differentiate(expression.Body, variable: "x").ToString());
        }
Beispiel #4
0
        public void ResolveRuleMultipleTest()
        {
            Expression <Del1> node1 = (x) => P(x) | !Q(x) | R(x);
            Expression <Del1> node2 = (x) => !P(x) | Q(x) | !R(x);
            var result = ComputerAlgebra.Resolve(Expressions2LogicTree.Parse(node1), Expressions2LogicTree.Parse(node2));

            Assert.AreEqual(3, result.Count());
        }
Beispiel #5
0
        public void ResolveWithUnificateTest()
        {
            Expression <Del1> root      = (x) => P(x) | Q(f(x));
            Expression <Del1> gypotesis = (z) => !P(g(z));
            var result = ComputerAlgebra.Resolve(Expressions2LogicTree.Parse(root), Expressions2LogicTree.Parse(gypotesis)).ToList();

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual("Q(f(g(z)))", result[0].ToString());
        }
Beispiel #6
0
        public void DiffDivide()
        {
            Expression <Del2> expression = (x, y) => x / y;

            Assert.AreEqual(
                new Divide <double>(
                    VariableNode.Make <double>(1, "y"),
                    new Pow <double>(VariableNode.Make <double>(1, "y"), new Constant <double>(2))).ToString(),
                ComputerAlgebra.Differentiate(Expressions2Tree.Parse(expression.Body), variable: "x").ToString());
        }
Beispiel #7
0
        public void PredicateAndNegatePredicate()
        {
            Expression <Del1> root      = (x) => P(x);
            Expression <Del1> gypotesis = (x) => !P(x);

            var result =
                ComputerAlgebra.Resolve(Expressions2LogicTree.Parse(root), Expressions2LogicTree.Parse(gypotesis)).ToList();

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual("", result[0].ToString());
        }
Beispiel #8
0
        static void Main()
        {
            //Type the function you want to simplify
            Expression <Func <double, double, double, double, double> > function =
                (x, y, z, u) => (x + 42) / 1 + y * 0 / (z - 0) + 43 - Math.Pow(x, 0) * Math.Pow(u, 1) / (0 + 5);

            var tree           = Expressions2Tree.Parse(function);
            var simplifiedTree = ComputerAlgebra.Simplify(tree);

            Console.WriteLine("Initial function:{1}F(x,y,z,u) = {0}{1}", tree, Environment.NewLine);
            Console.WriteLine("Result of simplification:{1}{0}", simplifiedTree, Environment.NewLine);
        }
Beispiel #9
0
        public void DiffPowY()
        {
            Expression <Del2> expression = (x, y) => Math.Pow(x, y);

            Assert.AreEqual(
                new ScalarProduct <double>(
                    new Pow <double>(
                        VariableNode.Make <double>(0, "x"),
                        VariableNode.Make <double>(1, "y")),
                    new Ln(VariableNode.Make <double>(0, "x")))
                .ToString(),
                ComputerAlgebra.Differentiate(Expressions2Tree.Parse(expression.Body), variable: "y").ToString());
        }
Beispiel #10
0
        public void ResolveRuleTest()
        {
            // P(x) V Q(f(y))
            Expression <Del2> root = (x, y) => P(x) | Q(f(y));
            // !P(x)
            Expression <Del1> gypotesis = (x) => !P(x);
            var result = ComputerAlgebra.Resolve(Expressions2LogicTree.Parse(root), Expressions2LogicTree.Parse(gypotesis)).ToList();

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual("Q(f(y))", result[0].ToString());
            result = ComputerAlgebra.Resolve(Expressions2LogicTree.Parse(gypotesis), Expressions2LogicTree.Parse(root)).ToList();
            Assert.AreEqual("Q(f(y))", result[0].ToString());
        }
Beispiel #11
0
        public void ResolutionOnResultOfResolution()
        {
            Expression <Del1> f1 = (x) => P(x) | Q(x);
            Expression <Del1> f2 = (x) => !Q(x);
            Expression <Del1> f3 = (x) => !P(x);

            //P(x)
            var result = ComputerAlgebra.Resolve(Expressions2LogicTree.Parse(f1), Expressions2LogicTree.Parse(f2)).Single();
            //{} ?
            var result2 = ComputerAlgebra.Resolve(Expressions2LogicTree.Parse(f3), result).ToList();

            Assert.AreEqual(1, result2.Count);
            Assert.AreEqual("", result2[0].ToString());
        }
Beispiel #12
0
        static void Main()
        {
            //Type two clauses in SNF without quantifiers
            Expression <Func <int, int, int, int, BooleanGroup> > exp       = (x, y, z, u) => !P(x, y) | Q(z, g(u)) | R(z, f(u));
            Expression <Func <int, int, BooleanGroup> >           gypotesis = (x, u) => !R(x, f(u)) | P(b, h(a));

            var expNode       = Expressions2LogicTree.Parse(exp);
            var gypotesisNode = Expressions2LogicTree.Parse(gypotesis);

            Console.WriteLine("First clause: {0}", expNode);
            Console.WriteLine("Second clause: {0}", gypotesisNode);
            var result = ComputerAlgebra.Resolve(expNode, gypotesisNode).ToList();

            Console.WriteLine("Possible resolvents: [{0}]", string.Join(" ; ", result));
        }
Beispiel #13
0
        static void Main()
        {
            //Type the function you want to differentiate
            Expression <Func <double, double, double, double> > function = (x, y, z) => Math.Pow(x, 3) * y - Math.Pow(x, y) + 5 * z;
            var node = Expressions2Tree.Parse(function);

            // Differentiation
            var resultFromDiffX = ComputerAlgebra.Differentiate(node, variable: "x");
            var resultFromDiffY = ComputerAlgebra.Differentiate(node, variable: "y");
            var resultFromDiffZ = ComputerAlgebra.Differentiate(node, variable: "z");

            // Output
            Console.WriteLine("Initial function:{1}F(x,y,z) = {0}{1}", node, Environment.NewLine);
            Console.WriteLine("dF/dx = {0}{1}", resultFromDiffX, Environment.NewLine);
            Console.WriteLine("dF/dy = {0}{1}", resultFromDiffY, Environment.NewLine);
            Console.WriteLine("dF/dz = {0}{1}", resultFromDiffZ, Environment.NewLine);
        }
Beispiel #14
0
 public static INode SimplifyLogicTree(INode root)
 {
     return(ComputerAlgebra.Simplify(root));
 }
Beispiel #15
0
 public SignalChannel(ComputerAlgebra.Expression Signal)
 {
     signal = Signal.Compile<Func<double, double>>(Circuit.Component.t);
 }
Beispiel #16
0
 public Function(ComputerAlgebra.Function f)
 {
     this.f = f.Compile<Func<double, double>>();
 }
Beispiel #17
0
 public static INode SimplifyBinaryExpression(Expression e)
 {
     return(ComputerAlgebra.Simplify(Expressions2Tree.Parse(e)));
 }