Ejemplo n.º 1
0
        static void Main(String[] args)
        {
            FDD f1 = (x) => Math.Sin(x);
            FDD f2 = (x) => (x * x);
            FDD f3 = (x) => (x > 0 ? Math.Abs(x) : Math.Sqrt(x));

            EFDD ef = (x, y) =>
                      f1(x) > f1(y)
                    ? f2(f3(x) + f3(y)) / (f1(x) == 0 ? 1 : f2(f3(x) + f3(y)))
                    : f3(f2(x + y)) / (f1(y) == 0 ? 1 : f2(f3(x) + f3(y)));

            var et = new ExpressionTree(ef);

            Print(et);

            Console.WriteLine(et.GetAllNodes().Count());

            Console.WriteLine(new String('-', 20) + "GetDublicateNodes");
            {
                var d = InvokeOptimizer.GetDublicateNodes(ef).ToArray();

                foreach (var i in d)
                {
                    Console.WriteLine(i);
                }
            }

            Console.WriteLine(new String('-', 20) + "GetNodesForReduce");
            {
                var d = new InvokeOptimizer(ef);

                d.Optimize();

                foreach (var i in d.ReducibleInvokes)
                {
                    Console.WriteLine(i);
                }

                Console.WriteLine("-------");
            }

            Console.ReadLine();
        }