示例#1
0
        internal override Symbol PreEval(Symbol x)
        {
            Complex z = x.ToComplex();

            if (z.Im == 0.0)
            {
                return(new Complex(Math.tan(z.Re)));
            }
            return(( Symbol )evalx(trigrule, z));
        }
示例#2
0
        internal override Symbol PreEval(Symbol x)
        {
            var z = x.ToComplex();

            if (z.Re < 0 || z.Im != 0.0)
            {
                return(new Complex(Math.log(z.Re * z.Re + z.Im * z.Im) / 2, Math.atan2(z.Im, z.Re)));
            }

            return(new Complex(Math.log(z.Re)));
        }
示例#3
0
        internal override Symbol PreEval(Symbol x)
        {
            var z = x.ToComplex();

            var r = Math.exp(z.Re);

            if (z.Im != 0.0)
            {
                return(new Complex(r * Math.cos(z.Im), r * Math.sin(z.Im)));
            }

            return(new Complex(r));
        }
示例#4
0
        internal override Algebraic SymEval(Algebraic f)
        {
            if (gcd.Equals(Symbol.ZERO))
            {
                return(f);
            }
            if (f is Polynomial)
            {
                Polynomial p = ( Polynomial )f;

                if (p.Var is FunctionVariable && (( FunctionVariable )p.Var).Name.Equals("exp") && Poly.Degree((( FunctionVariable )p.Var).Var, vr) == 1)
                {
                    var arg = (( FunctionVariable )p.Var).Var;

                    var new_coef = new Algebraic[2];

                    new_coef[1] = gcd.ToComplex();
                    new_coef[0] = Symbol.ZERO;

                    Algebraic new_arg = new Polynomial(vr, new_coef);

                    var subst = FunctionVariable.Create("exp", new_arg);
                    var exp   = Poly.Coefficient(arg, vr, 1) / gcd;

                    if (!(exp is Symbol) && !(( Symbol )exp).IsInteger())
                    {
                        throw new SymbolicException("Not integer exponent in exponential simplification.");
                    }

                    subst = subst ^ (( Symbol )exp).ToInt();

                    subst = subst * FunctionVariable.Create("exp", Poly.Coefficient(arg, vr, 0));

                    var len = p.Coeffs.Length;

                    var r = SymEval(p[len - 1]);

                    for (var n = len - 2; n >= 0; n--)
                    {
                        r = r * subst + SymEval(p[n]);
                    }

                    return(r);
                }
            }

            return(f.Map(this));
        }
示例#5
0
        public override bool Smaller(Symbol x)
        {
            var xu = x.ToComplex();

            return(Re == xu.Re ? Im < xu.Im : Re < xu.Re);
        }
示例#6
0
 internal override Symbol PreEval(Symbol x)
 {
     return(new Complex(Math.logGamma(x.ToComplex().Re)));
 }