コード例 #1
0
ファイル: LaTeX.cs プロジェクト: JackWangCUMT/ComputerAlgebra
        protected override string VisitCall(Call F)
        {
            // Special case for differentiate.
            if (F.Target.Name == "D" && F.Arguments.Count() == 2)
                return @"\frac{d}{d" + Visit(F.Arguments.ElementAt(1)) + "}[" + Visit(F.Arguments.ElementAt(0)) + "]";

            return Escape(F.Target.Name) + @"(" + String.Join(", ", F.Arguments.Select(i => Visit(i))) + @")";
        }
コード例 #2
0
 /// <summary>
 /// Substitute the variables into the expressions.
 /// </summary>
 /// <param name="x0"></param>
 /// <param name="IsTransform"></param>
 /// <returns></returns>
 public virtual Expression Substitute(Call C, IDictionary<Expression, Expression> x0, bool IsTransform)
 {
     return ComputerAlgebra.Call.New(C.Target, C.Arguments.Select(i => i.Substitute(x0, IsTransform)));
 }
コード例 #3
0
        protected override Expression VisitCall(Call C)
        {
            C = (Call)base.VisitCall(C);

            try
            {
                if (C.Target.CanCall(C.Arguments))
                {
                    Expression call = C.Target.Call(C.Arguments);
                    if (!ReferenceEquals(call, null))
                        return call;
                }
            }
            catch (Exception Ex) { exceptions.Add(Ex); }
            return C;
        }
コード例 #4
0
 protected override Expression VisitCall(Call F)
 {
     return F.Target.Substitute(F, x0, transform);
 }
コード例 #5
0
ファイル: Function.cs プロジェクト: Voxel8/ComputerAlgebra
 /// <summary>
 /// Substitute the variables into the expressions.
 /// </summary>
 /// <param name="x0"></param>
 /// <param name="IsTransform"></param>
 /// <returns></returns>
 public virtual Expression Substitute(Call C, IDictionary <Expression, Expression> x0, bool IsTransform)
 {
     return(ComputerAlgebra.Call.New(C.Target, C.Arguments.Select(i => i.Substitute(x0, IsTransform))));
 }
コード例 #6
0
 protected override Expression VisitCall(Call F)
 {
     return(F.Target.Substitute(F, x0, transform));
 }
コード例 #7
0
 private static Expression D(Expression f, Expression t)
 {
     return(Call.D(f, t));
 }
コード例 #8
0
        //P is
        //    if next is a unary operator
        //         const op := unary(next)
        //         consume
        //         q := prec( op )
        //         const t := Exp( q )
        //         return mkNode( op, t )
        //    else if next = "("
        //         consume
        //         const t := Exp( 0 )
        //         expect ")"
        //         return t
        //    else if next is a v
        //         const t := mkLeaf( next )
        //         consume
        //         return t
        //    else
        //         error
        private Expression P()
        {
            Operator op = new Operator();

            if (tokens.Tok == "+")
            {
                // Skip unary +.
                tokens.Consume();
                return(P());
            }
            else if (IsUnaryPreOperator(tokens.Tok, ref op))
            {
                // Unary operator.
                tokens.Consume();
                Expression t = Exp(Precedence(op));
                return(Unary.New(op, t));
            }
            else if (tokens.Tok == "(")
            {
                // Group.
                tokens.Consume();
                Expression t = Exp(0);
                tokens.Expect(")");
                return(t);
            }
            else if (tokens.Tok == "{")
            {
                // Set.
                tokens.Consume();
                return(Set.New(L(",", "}")));
            }
            else if (tokens.Tok == "[")
            {
                // Matrix.
                tokens.Consume();
                List <List <Expression> > entries = new List <List <Expression> >();
                while (tokens.Tok == "[")
                {
                    tokens.Consume();
                    entries.Add(L(",", "]"));
                }
                tokens.Expect("]");

                return(Matrix.New(entries));
            }
            else
            {
                string tok = tokens.Consume();

                decimal dec = 0;
                double  dbl = 0.0;
                if (decimal.TryParse(tok, NumberStyles.Float, culture, out dec))
                {
                    return(Constant.New(dec));
                }
                if (double.TryParse(tok, NumberStyles.Float, culture, out dbl))
                {
                    return(Constant.New(dbl));
                }
                else if (tok == "True")
                {
                    return(Constant.New(true));
                }
                else if (tok == "False")
                {
                    return(Constant.New(false));
                }
                else if (tok == "\u221E" || tok == "oo")
                {
                    return(Constant.New(Real.Infinity));
                }
                else if (tokens.Tok == "[")
                {
                    // Bracket function call.
                    tokens.Consume();
                    List <Expression> args = L(",", "]");
                    return(Call.New(Resolve(tok, args), args));
                }
                else if (tokens.Tok == "(")
                {
                    // Paren function call.
                    tokens.Consume();
                    List <Expression> args = L(",", ")");
                    return(Call.New(Resolve(tok, args), args));
                }
                else
                {
                    return(Resolve(tok));
                }
            }
        }
コード例 #9
0
        protected override string VisitCall(Call F)
        {
            string s = F.Target.Name + "[" + Join(F.Arguments, ", ") + "]";

            return(s);
        }
コード例 #10
0
 /// <summary>
 /// Integrate expression with respect to x.
 /// </summary>
 /// <param name="f"></param>
 /// <param name="x"></param>
 /// <returns></returns>
 public static Expression Integrate(this Expression f, Expression x)
 {
     return(Call.I(f, x));
 }