Exemplo n.º 1
0
        private void AssertEqualAfterSimplification(string original, string expected)
        {
            var formatter    = new SymbolicExpressionTreeStringFormatter();
            var importer     = new SymbolicExpressionImporter();
            var actualTree   = TreeSimplifier.Simplify(importer.Import(original));
            var expectedTree = importer.Import(expected);

            Assert.AreEqual(formatter.Format(expectedTree), formatter.Format(actualTree));
        }
        public override IOperation Apply()
        {
            var tree           = SymbolicExpressionTreeParameter.ActualValue;
            var simplifiedTree = TreeSimplifier.Simplify(tree);

            simplifiedTree = TreeSimplifier.Simplify(simplifiedTree);
            SymbolicExpressionTreeParameter.ActualValue = simplifiedTree;

            return(base.Apply());
        }
Exemplo n.º 3
0
        public static ISymbolicExpressionTree Derive(ISymbolicExpressionTree tree, string variableName)
        {
            if (tree.Root.SubtreeCount != 1)
            {
                throw new NotImplementedException("Derive is not implemented for symbolic expressions with automatically defined functions (ADF)");
            }
            if (tree.Root.GetSubtree(0).SubtreeCount != 1)
            {
                throw new NotImplementedException("Derive is not implemented for multi-variate symbolic expressions");
            }
            var mainBranch = tree.Root.GetSubtree(0).GetSubtree(0);
            var root       = new ProgramRootSymbol().CreateTreeNode();

            root.AddSubtree(new StartSymbol().CreateTreeNode());
            var dTree = TreeSimplifier.GetSimplifiedTree(Derive(mainBranch, variableName));

            //var dTree = Derive(mainBranch, variableName);
            root.GetSubtree(0).AddSubtree(dTree);
            return(new SymbolicExpressionTree(root));
        }
Exemplo n.º 4
0
 private void ParseIntoTree()
 {
     this.FunctionTree = new TreeNode("Root", ValueType.Unknown);
     Parser.ParseStringToTree(this.FunctionAsString, this.FunctionTree);
     this.FunctionTree = TreeSimplifier.Simplify(this.FunctionTree);
 }
Exemplo n.º 5
0
 public Function(TreeNode functionTreeRoot) : this()
 {
     this.FunctionTree     = functionTreeRoot;
     this.FunctionTree     = TreeSimplifier.Simplify(this.FunctionTree);
     this.FunctionAsString = Parser.ParseTreeToString(this.FunctionTree);
 }
        private void btnSimplify_Click(object sender, EventArgs e)
        {
            var simplifiedExpressionTree = TreeSimplifier.Simplify(Content.Model.SymbolicExpressionTree);

            UpdateModel(simplifiedExpressionTree);
        }