public static MathObject CoefficientGpe(this MathObject u, MathObject x, int j)
            {
                if (!(u is Sum))
                {
                    var f = u.CoefficientMonomialGpe(x);

                    if (f == null) return null;

                    if (f.Item2 == j) return f.Item1;

                    return 0;
                }

                if (u == x) return j == 1 ? 1 : 0;

                var c = (MathObject)0;

                foreach (var elt in (u as Sum).elts)
                {
                    var f = elt.CoefficientMonomialGpe(x);

                    if (f == null) return null;

                    if (f.Item2 == j) c = c + f.Item1;
                }

                return c;
            }
            public static Tuple<MathObject, int> CoefficientMonomialGpe(this MathObject u, MathObject x)
            {
                if (u == x) return Tuple.Create((MathObject)1, 1);

                if (u is Power &&
                    (u as Power).bas == x &&
                    (u as Power).exp is Integer &&
                    ((u as Power).exp as Integer).val > 1)
                    return Tuple.Create((MathObject)1, ((u as Power).exp as Integer).val);

                if (u is Product)
                {
                    var m = 0;
                    var c = u;

                    foreach (var elt in (u as Product).elts)
                    {
                        var f = elt.CoefficientMonomialGpe(x);

                        if (f == null) return null;

                        if (f.Item2 != 0)
                        {
                            m = f.Item2;
                            c = u / (x ^ m);
                        }
                    }

                    return Tuple.Create(c, m);
                }

                if (u.FreeOf(x)) return Tuple.Create(u, 0);

                return null;
            }
예제 #3
0
        public static MathObject Mod(MathObject x, MathObject y)
        {
            if (x is Number && y is Number)
            {
                var result = Convert.ToInt32(Math.Floor(((x / y) as Number).ToDouble().val));

                return x - y * result;
            }

            throw new Exception();
        }
            static MathObject RationalizeSum(MathObject u, MathObject v)
            {
                var m = u.Numerator();
                var r = u.Denominator();
                var n = v.Numerator();
                var s = v.Denominator();

                if (r == 1 && s == 1) return u + v;

                return RationalizeSum(m * s, n * r) / (r * s);
            }
예제 #5
0
            public static MathObject ExpandProduct(this MathObject r, MathObject s)
            {
                if (r is Sum)
                {
                    var f = (r as Sum).elts[0];

                    return f.ExpandProduct(s) + (r - f).ExpandProduct(s);
                }

                if (s is Sum) return s.ExpandProduct(r);

                return r * s;
            }
예제 #6
0
            public static bool Has(this MathObject obj, MathObject a)
            {
                if (obj == a) return true;
                
                if (obj is Equation) return (obj as Equation).a.Has(a) || (obj as Equation).b.Has(a);

                if (obj is Power) return (((Power)obj).bas.Has(a) || ((Power)obj).exp.Has(a));

                if (obj is Product) return ((Product)obj).elts.Any(elt => elt.Has(a));
                if (obj is Sum) return ((Sum)obj).elts.Any(elt => elt.Has(a));
                if (obj is Function) return ((Function)obj).args.Any(elt => elt.Has(a));

                return false;
            }
예제 #7
0
            public static MathObject Substitute(this MathObject obj, MathObject a, MathObject b)
            {
                if (obj == a) return b;

                if (obj is Equation)
                {
                    if ((obj as Equation).Operator == Equation.Operators.Equal)
                        return ((obj as Equation).a.Substitute(a, b) == (obj as Equation).b.Substitute(a, b)).Simplify();

                    if ((obj as Equation).Operator == Equation.Operators.NotEqual)
                        return ((obj as Equation).a.Substitute(a, b) != (obj as Equation).b.Substitute(a, b)).Simplify();

                    if ((obj as Equation).Operator == Equation.Operators.LessThan)
                        return ((obj as Equation).a.Substitute(a, b) < (obj as Equation).b.Substitute(a, b)).Simplify();

                    if ((obj as Equation).Operator == Equation.Operators.GreaterThan)
                        return ((obj as Equation).a.Substitute(a, b) > (obj as Equation).b.Substitute(a, b)).Simplify();

                    throw new Exception();
                }

                if (obj is Power) return (obj as Power).bas.Substitute(a, b) ^ (obj as Power).exp.Substitute(a, b);

                if (obj is Product)
                    return
                        new Product() { elts = (obj as Product).elts.ConvertAll(elt => elt.Substitute(a, b)) }
                        .Simplify();

                if (obj is Sum)
                    return
                        new Sum() { elts = (obj as Sum).elts.ConvertAll(elt => elt.Substitute(a, b)) }
                        .Simplify();

                if (obj is Function)
                {
                    var obj_ = (obj as Function).Clone() as Function;

                    obj_.args = (obj as Function).args.ConvertAll(arg => arg.Substitute(a, b));

                    return obj_.Simplify();
                }

                return obj;
            }
예제 #8
0
            public override object CallLateBound(object thisObject, params object[] argumentValues)
            {
                var number = TypeConverter.ToNumber(thisObject);

                //No precision specified
                if (argumentValues.Length == 0 || argumentValues[0] == Undefined.Value || argumentValues[0] == Null.Value || argumentValues[0] == null)
                {
                    return(MathObject.Ceil(number));
                }

                var precision = TypeConverter.ToNumber(argumentValues[0]);

                var multiplier = Math.Pow(10, Math.Abs(precision));

                if (precision < 0)
                {
                    multiplier = 1 / multiplier;
                }
                return(MathObject.Ceil(number * multiplier) / multiplier);
            }
예제 #9
0
 public static MathObject AlgebraicExpand(this MathObject u)
 {
     if (u is Equation)
     {
         var eq = (Equation)u;
         return(eq.a.AlgebraicExpand() == eq.b.AlgebraicExpand());
     }
     if (u is Sum)
     {
         return(new Sum {
             elts = ((Sum)u).elts.Select(elt => elt.AlgebraicExpand()).ToList()
         }
                .Simplify());
     }
     if (u is Product)
     {
         var v = ((Product)u).elts[0];
         return(v.AlgebraicExpand()
                .ExpandProduct((u / v).AlgebraicExpand()));
     }
     if (u is Power)
     {
         var bas = ((Power)u).bas;
         var exp = ((Power)u).exp;
         if (exp is Integer && (exp as Integer).val >= 2)
         {
             return(bas.AlgebraicExpand().ExpandPower((exp as Integer).val));
         }
         return(u);
     }
     if (u is Function)
     {
         return(new Function
         {
             name = ((Function)u).name,
             proc = ((Function)u).proc,
             args = ((Function)u).args.ConvertAll(elt => elt.AlgebraicExpand())
         }.Simplify());
     }
     return(u);
 }
예제 #10
0
        public static MathObject LogicalExpand(this MathObject obj)
        {
            if (obj is Or)
            {
                return((obj as Or).Map(elt => elt.LogicalExpand()));
            }

            if (obj is And &&
                (obj as And).args.Any(elt => elt is Or) &&
                (obj as And).args.Count() > 1)
            {
                var before = new List <MathObject>();
                Or  or     = null;
                var after  = new List <MathObject>();

                foreach (var elt in (obj as And).args)
                {
                    if (elt is Or && or == null)
                    {
                        or = elt as Or;
                    }
                    else if (or == null)
                    {
                        before.Add(elt);
                    }
                    else
                    {
                        after.Add(elt);
                    }
                }

                return
                    (or.Map(or_elt =>
                            new And(
                                And.FromRange(before).Simplify().LogicalExpand(),
                                or_elt,
                                And.FromRange(after).Simplify().LogicalExpand()).Simplify()).LogicalExpand());
            }

            return(obj);
        }
예제 #11
0
        public static MathObject EliminateVariable(this MathObject expr, Symbol sym)
        {
            if (expr is And)
            {
                var eqs = (expr as And).args.Select(elt => elt as Equation);

                return(EliminateVariableEqLs(eqs.ToList(), sym));
            }

            if (expr is Or)
            {
                return(new Or()
                {
                    args = (expr as Or).args.Select(and_expr => and_expr.EliminateVariable(sym)).ToList()
                });

                // expr.Map(and_expr => and_expr.EliminateVar(sym))
            }

            throw new Exception();
        }
예제 #12
0
        public static MathObject SimplifyLogical(this MathObject expr)
        {
            if (expr is And && (expr as And).args.HasDuplicates())
            {
                return(And.FromRange((expr as And).args.RemoveDuplicates()));
            }

            if (expr is Or && (expr as Or).args.HasDuplicates())
            {
                return
                    (Or.FromRange((expr as Or).args.RemoveDuplicates())
                     .SimplifyLogical());
            }

            if (expr is Or)
            {
                return((expr as Or).Map(elt => elt.SimplifyLogical()));
            }

            return(expr);
        }
예제 #13
0
 public static MathObject RationalizeExpression(this MathObject u)
 {
     if (u is Equation)
     {
         return(new Equation(
                    ((Equation)u).a.RationalizeExpression(),
                    ((Equation)u).b.RationalizeExpression(),
                    ((Equation)u).Operator));
     }
     if (u is Power)
     {
         return(((Power)u).bas.RationalizeExpression() ^ ((Power)u).exp);
     }
     if (u is Product)
     {
         return
             new Product
             {
                 elts = ((Product)u).elts.Select(elt => elt.RationalizeExpression()).ToList()
             }
     }
예제 #14
0
        public static MathObject CheckVariable(this MathObject expr, Symbol sym)
        {
            // 1 / x == 0
            // 1 / x^2 == 0

            if (expr is Equation &&
                (expr as Equation).Operator == Equation.Operators.Equal &&
                (expr as Equation).b == 0 &&
                (expr as Equation).a.Has(sym) &&
                (expr as Equation).SimplifyEquation() is Equation &&
                ((expr as Equation).SimplifyEquation() as Equation).a is Power &&
                (((expr as Equation).SimplifyEquation() as Equation).a as Power).exp is Integer &&
                ((((expr as Equation).SimplifyEquation() as Equation).a as Power).exp as Integer).val < 0)
            {
                return(false);
            }

            if (expr is And)
            {
                var result = (expr as And).Map(elt => elt.CheckVariable(sym));

                if (result is And)
                {
                    var eqs = (expr as And).args.Select(elt => elt as Equation).ToList();

                    return(eqs.CheckVariableEqLs(sym));
                }

                return(result);
            }


            if (expr is Or &&
                (expr as Or).args.All(elt => elt is And))
            {
                return((expr as Or).Map(elt => elt.CheckVariable(sym)));
            }

            return(expr);
        }
예제 #15
0
        public static MathObject SimplifyEquation(this MathObject expr)
        {
            // 10 * x == 0   ->   x == 0
            // 10 * x != 0   ->   x == 0

            if (expr is Equation &&
                (expr as Equation).a is Product &&
                ((expr as Equation).a as Product).elts.Any(elt => elt is Number) &&
                ((expr as Equation).b == 0))
            {
                return(new Equation(
                           Product.FromRange(((expr as Equation).a as Product).elts.Where(elt => !(elt is Number))).Simplify(),
                           0,
                           (expr as Equation).Operator).Simplify());
            }

            // x ^ 2 == 0   ->   x == 0
            // x ^ 2 != 0   ->   x == 0

            if (expr is Equation &&
                (expr as Equation).b == 0 &&
                (expr as Equation).a is Power &&
                ((expr as Equation).a as Power).exp is Integer &&
                (((expr as Equation).a as Power).exp as Integer).val > 0)
            {
                return(((expr as Equation).a as Power).bas == 0);
            }

            if (expr is And)
            {
                return((expr as And).Map(elt => elt.SimplifyEquation()));
            }

            if (expr is Or)
            {
                return((expr as Or).Map(elt => elt.SimplifyEquation()));
            }

            return(expr);
        }
예제 #16
0
        // xB = xA + vAx t + 1/2 ax t^2                     (9)

        // yB = yA + vAy t + 1/2 ay t^2                     (10)

        // xB - xA = d cos th								(13)

        // yB - yA = d sin th								(14)

        // ax = 0											(11)

        // vAx = vA cos(thA)								(6)

        // vAy = vA sin(thA)								(7)


        // (9):	xB = xA + vAx t + 1/2 ax t^2

        //         xB - xA = vAx t + 1/2 ax t^2             (9.1)

        // (10):	yB = yA + vAy t + 1/2 ay t^2

        //         yB - yA = vAy t + 1/2 ay t^2             (10.1)


        // (13):		xB - xA = d cos th

        // /. (9.1)	vAx t + 1/2 ax t^2 = d cos th

        // /. (11)		vAx t = d cos th

        // t            t = d cos(th) / vAx                 (13.1)


        // (14):		yB - yA = d sin th

        // /. (10.1)	vAy t + 1/2 ay t^2 = d sin th

        // /. (13.1)	vAy [d cos(th) / vAx] + 1/2 ay [d cos(th) / vAx]^2 = d sin th

        //             vAy / vAx d cos(th) + 1/2 ay [d cos(th) / vAx]^2 = d sin th

        //             1/2 ay [d cos(th) / vAx]^2 = d sin th - vAy / vAx d cos(th)

        //             1/2 ay [d cos(th) / vAx]^2 = d [sin(th) - vAy / vAx cos(th)]

        //             1/2 ay d^2 [cos(th) / vAx]^2 = d [sin(th) - vAy / vAx cos(th)]

        //             1/2 ay d [cos(th) / vAx]^2 = [sin(th) - vAy / vAx cos(th)]

        //             d = 2 [sin(th) - vAy / vAx cos(th)] [vAx / cos(th)]^2 / ay

        // if vAy = 0 then it simplifies to:

        //             d = 2 sin(th) [vAx / cos(th)]^2 / ay

        #endregion

        public Point ProjectileInclineIntersection(MathObject theta)
        {
            if (theta != null &&
                velocity.x != null &&
                velocity.y != null &&
                acceleration.y != null &&
                acceleration.y != 0 &&
                acceleration.y != 0.0)
            {
                var d =
                    2 * (Trig.Sin(theta) - velocity.y / velocity.x * Trig.Cos(theta))
                    * ((velocity.x / Trig.Cos(theta)) ^ 2)
                    / acceleration.y;

                return
                    (new Point(
                         position.x + d * Trig.Cos(theta),
                         position.y + d * Trig.Sin(theta)));
            }

            throw new Exception();
        }
예제 #17
0
            public static MathObject DeepSelect(this MathObject obj, Func <MathObject, MathObject> proc)
            {
                var result = proc(obj);

                if (result is Power)
                {
                    return
                        ((result as Power).bas.DeepSelect(proc) ^
                         (result as Power).exp.DeepSelect(proc));
                }

                if (result is Or)
                {
                    return((result as Or).Map(elt => elt.DeepSelect(proc)));
                }

                if (result is And)
                {
                    return((result as And).Map(elt => elt.DeepSelect(proc)));
                }

                if (result is Equation)
                {
                    return
                        (new Equation(
                             (result as Equation).a.DeepSelect(proc),
                             (result as Equation).b.DeepSelect(proc),
                             (result as Equation).Operator));
                }

                if (result is Sum)
                {
                    return
                        new Sum()
                        {
                            elts = (result as Sum).elts.Select(elt => elt.DeepSelect(proc)).ToList()
                        }
                }
예제 #18
0
        public static MathObject QuadraticEquation(MathObject a, MathObject b, MathObject c, int solution = 0)
        {
            if (a == new Integer(0) || a == new DoubleFloat(0.0))
            {
                throw new Exception("a is zero. Equation is not quadratic.");
            }

            var discriminant = b * b - 4 * a * c;

            var half = new Integer(1) / 2;

            if (solution == 0)
            {
                return((-b + (discriminant ^ half)) / (2 * a));
            }

            if (solution == 1)
            {
                return((-b - (discriminant ^ half)) / (2 * a));
            }

            throw new Exception();
        }
예제 #19
0
            public static Tuple <MathObject, int> CoefficientMonomialGpe(this MathObject u, MathObject x)
            {
                if (u == x)
                {
                    return(Tuple.Create((MathObject)1, 1));
                }
                if (u is Power &&
                    ((Power)u).bas == x &&
                    ((Power)u).exp is Integer &&
                    ((Integer)((Power)u).exp).val > 1)
                {
                    return(Tuple.Create((MathObject)1, ((Integer)((Power)u).exp).val));
                }

                if (!(u is Product))
                {
                    return(u.FreeOf(x) ? Tuple.Create(u, 0) : null);
                }
                int        m = 0;
                MathObject c = u;

                foreach (Tuple <MathObject, int> f in ((Product)u).elts.Select(elt => elt.CoefficientMonomialGpe(x)))
                {
                    if (f == null)
                    {
                        return(null);
                    }

                    if (f.Item2 == 0)
                    {
                        continue;
                    }
                    m = f.Item2;
                    c = u / (x ^ m);
                }
                return(Tuple.Create(c, m));
            }
예제 #20
0
 public static MathObject LogicalExpand(this MathObject obj)
 {
     while (true)
     {
         if (obj is Or)
         {
             return(((Or)obj).Map(elt => elt.LogicalExpand()));
         }
         if (!(obj is And) || !((And)obj).args.Any(elt => elt is Or) || ((And)obj).args.Count() <= 1)
         {
             return(obj);
         }
         List <MathObject> before = new List <MathObject>();
         Or or = null;
         List <MathObject> after = new List <MathObject>();
         foreach (MathObject elt in ((And)obj).args)
         {
             if (elt is Or && or == null)
             {
                 or = elt as Or;
             }
             else if (or == null)
             {
                 before.Add(elt);
             }
             else
             {
                 after.Add(elt);
             }
         }
         obj = or.Map(or_elt => new And(new And {
             args = before
         }.Simplify().LogicalExpand(), or_elt, new And {
             args = after
         }.Simplify().LogicalExpand()).Simplify());
     }
 }
예제 #21
0
        public static void GatheringInput(MathObject eq)
        {
            Console.WriteLine("Welcome to my VHS app \n");
            Console.WriteLine("Type A - for Addition \n");
            Console.WriteLine("Type B - for Subtraction \n");
            Console.WriteLine("Type C - for Multiplication \n");
            Console.WriteLine("Type D - for Division \n");
            eq.op = Console.ReadLine().ToUpper();

            eq.newOperation = DetermineOperation(eq.op);

            Console.WriteLine("Thank you \n");
            Console.WriteLine("Please enter your first value: ");
            eq.value1 = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("Thank you \n");
            Console.WriteLine("Please enter your second value: ");
            eq.value2 = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("Thank you \n");

            Console.WriteLine("Ok, your equation is " + eq.value1 + eq.newOperation + eq.value2);

            Console.WriteLine("Hit Enter to continue");
            Console.ReadLine();
        }
예제 #22
0
            public static int DegreeMonomialGpe(this MathObject u, List <MathObject> v)
            {
                if (v.All(u.FreeOf))
                {
                    return(0);
                }

                if (v.Contains(u))
                {
                    return(1);
                }

                if (u is Power && ((Power)u).exp is Integer && ((Integer)((Power)u).exp).val > 1)
                {
                    return(((Integer)((Power)u).exp).val);
                }

                if (u is Product)
                {
                    return(((Product)u).elts.Select(elt => elt.DegreeMonomialGpe(v)).Sum());
                }

                return(0);
            }
예제 #23
0
        //     SERIALIZATION
        //_________________________________________________________________________________________

#if !SILVERLIGHT
        /// <summary>
        /// Initializes a new instance of the ObjectInstance class with serialized data.
        /// </summary>
        /// <param name="info"> The SerializationInfo that holds the serialized object data about
        /// the exception being thrown. </param>
        /// <param name="context"> The StreamingContext that contains contextual information about
        /// the source or destination. </param>
        private ScriptEngine(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
        {
            // Set the DeserializationEnvironment to this script engine.
            ScriptEngine.DeserializationEnvironment = this;

            // Create the initial hidden class schema.  This must be done first.
            this.emptySchema = HiddenClassSchema.CreateEmptySchema();

            // Deserialize the compatibility mode.
            this.compatibilityMode = (CompatibilityMode)info.GetInt32("compatibilityMode");

            // Deserialize the ForceStrictMode flag.
            this.ForceStrictMode = info.GetBoolean("forceStrictMode");

            // Deserialize the built-in objects.
            this.globalObject        = (GlobalObject)info.GetValue("globalObject", typeof(GlobalObject));
            this.arrayConstructor    = (ArrayConstructor)info.GetValue("arrayConstructor", typeof(ArrayConstructor));
            this.booleanConstructor  = (BooleanConstructor)info.GetValue("booleanConstructor", typeof(BooleanConstructor));
            this.dateConstructor     = (DateConstructor)info.GetValue("dateConstructor", typeof(DateConstructor));
            this.functionConstructor = (FunctionConstructor)info.GetValue("functionConstructor", typeof(FunctionConstructor));
            this.jsonObject          = (JSONObject)info.GetValue("jsonObject", typeof(JSONObject));
            this.mathObject          = (MathObject)info.GetValue("mathObject", typeof(MathObject));
            this.numberConstructor   = (NumberConstructor)info.GetValue("numberConstructor", typeof(NumberConstructor));
            this.objectConstructor   = (ObjectConstructor)info.GetValue("objectConstructor", typeof(ObjectConstructor));
            this.regExpConstructor   = (RegExpConstructor)info.GetValue("regExpConstructor", typeof(RegExpConstructor));
            this.stringConstructor   = (StringConstructor)info.GetValue("stringConstructor", typeof(StringConstructor));

            // Deserialize the built-in error objects.
            this.errorConstructor          = (ErrorConstructor)info.GetValue("errorConstructor", typeof(ErrorConstructor));
            this.rangeErrorConstructor     = (ErrorConstructor)info.GetValue("rangeErrorConstructor", typeof(ErrorConstructor));
            this.typeErrorConstructor      = (ErrorConstructor)info.GetValue("typeErrorConstructor", typeof(ErrorConstructor));
            this.syntaxErrorConstructor    = (ErrorConstructor)info.GetValue("syntaxErrorConstructor", typeof(ErrorConstructor));
            this.uriErrorConstructor       = (ErrorConstructor)info.GetValue("uriErrorConstructor", typeof(ErrorConstructor));
            this.evalErrorConstructor      = (ErrorConstructor)info.GetValue("evalErrorConstructor", typeof(ErrorConstructor));
            this.referenceErrorConstructor = (ErrorConstructor)info.GetValue("referenceErrorConstructor", typeof(ErrorConstructor));
        }
예제 #24
0
            public static MathObject Denominator(this MathObject obj)
            {
                if (obj is Fraction)
                {
                    return((obj as Fraction).denominator);
                }

                if (obj is Power)
                {
                    if ((obj as Power).exp is Integer &&
                        ((obj as Power).exp as Integer).val < 0)
                    {
                        return(obj ^ -1);
                    }

                    if ((obj as Power).exp is Fraction &&
                        ((obj as Power).exp as Fraction).ToDouble().val < 0)
                    {
                        return(obj ^ -1);
                    }

                    return(1);
                }

                if (obj is Product)
                {
                    return
                        (new Product()
                    {
                        elts = (obj as Product).elts.Select(elt => elt.Denominator()).ToList()
                    }
                         .Simplify());
                }

                return(1);
            }
예제 #25
0
            public static MathObject Substitute(this MathObject obj, MathObject a, MathObject b)
            {
                if (obj == a)
                {
                    return(b);
                }

                if (obj is Equation)
                {
                    switch (((Equation)obj).Operator)
                    {
                    case Equation.Operators.Equal:
                        return((((Equation)obj).a.Substitute(a, b) == ((Equation)obj).b.Substitute(a, b)).Simplify());

                    case Equation.Operators.NotEqual:
                        return((((Equation)obj).a.Substitute(a, b) != ((Equation)obj).b.Substitute(a, b)).Simplify());

                    case Equation.Operators.LessThan:
                        return((((Equation)obj).a.Substitute(a, b) < ((Equation)obj).b.Substitute(a, b)).Simplify());

                    case Equation.Operators.GreaterThan:
                        return((((Equation)obj).a.Substitute(a, b) > ((Equation)obj).b.Substitute(a, b)).Simplify());
                    }
                    throw new Exception();
                }
                if (obj is Power)
                {
                    return(((Power)obj).bas.Substitute(a, b) ^ ((Power)obj).exp.Substitute(a, b));
                }
                if (obj is Product)
                {
                    return
                        new Product {
                            elts = ((Product)obj).elts.ConvertAll(elt => elt.Substitute(a, b))
                        }
                }
예제 #26
0
            public static MathObject ExpandPower(this MathObject u, BigInteger n)
            {
                if (u is Sum)
                {
                    var f = (u as Sum).elts[0];

                    var r = u - f;

                    MathObject s = 0;

                    var k = 0;

                    while (true)
                    {
                        if (k > n)
                        {
                            return(s);
                        }
                        else
                        {
                            var c =
                                Factorial(n)
                                /
                                (Factorial(k) * Factorial(n - k));

                            s = s + (c * (f ^ (n - k))).ExpandProduct(r.ExpandPower(k));

                            k++;
                        }
                    }
                }
                else
                {
                    return(u ^ n);
                }
            }
예제 #27
0
 public static MathObject Substitute(this MathObject obj, MathObject a, int b)
 {
     return obj.Substitute(a, new Integer(b));
 }
예제 #28
0
 public static MathObject ToDegrees(this MathObject n) => 180 * n / Pi;
예제 #29
0
 public static MathObject ToRadians(this MathObject n) => n * Pi / 180;
예제 #30
0
 public Tan(MathObject param)
 {
     name = "tan";
     args = new List<MathObject>() { param };
     proc = TanProc;
 }
예제 #31
0
 public static MathObject ToRadians(this MathObject n)
 {
     return(n * Pi / 180);
 }
예제 #32
0
 public static MathObject cos(MathObject obj) => new Cos(obj).Simplify();
예제 #33
0
        private string ReplaceSuportedObject(string objectName, string objectValue, RowCollectionRow row)
        {
            //
            //  I N F O - ReplaceTagsFromInToOut will not cut this
            //

            Tag2 tag = new Tag2("{=" + objectName + "." + objectValue);

            if (objectName == "date")
            {
                // Call to datetime object
                return(this.DateObject(objectValue));
            }
            else if (objectName == "string")
            {
                // Call to main generic method, other method will call it to get object row value and then format it
                // this one just return pure text value


                //
                //   Ovo sa split je privremeno ovdje stavito
                //
                if (tag.Child.Name.Equals("split"))
                {
                    return(StringObject(row, tag));
                }
                else
                {
                    return(StringObject(row, objectValue));
                }
            }
            else if (objectName == "nth")
            {
                // Call to main generic method, other method will call it to get object row value and then format it
                // this one just return pure text value
                return(NTHObject(row, objectValue));
            }
            else if (objectName == "number")
            {
                // Call to main generic method, other method will call it to get object row value and then format it
                // this one just return pure text value
                return(NumberObject(row, objectValue));
            }
            else if (tag.Name == "input")
            {
                // Call to InputObject
                return(InputObject(row, tag));
            }
            else if (tag.Name == "var")
            {
                // Call to VarObject
                return(VarObject(tag));
            }
            else if (tag.Name == "array")
            {
                // Call to ArrayObject
                ArrayObject arrayObject = new ArrayObject(tag, varObjectList);
                return(arrayObject.ProcessTag());
            }
            else if (tag.Name == "format")
            {
                // Call to FormatObject, get and set method
                return(FormatObject(tag));
            }
            else if (objectName == "xml")
            {
                // Call to FormatObject, get and set method
                return(XMLObject(row, objectValue));
            }
            else if (objectName.StartsWith("random"))
            {
                return(RandomObject(objectName, objectValue));
            }
            else if (objectName.StartsWith("md5"))
            {
                return(MD5Object(objectName, objectValue));
            }
            else if (tag.Name == "file")
            {
                FileObject fileObject = new FileObject(tag, ref varObjectList);
                return(fileObject.ProcessTag());
            }
            else if (tag.Name == "dir")
            {
                DirObject dirObject = new DirObject(tag, ref varObjectList);
                return(dirObject.ProcessTag());
            }
            else if (tag.Name == "graphics")
            {
                GraphicsObject fileObject = new GraphicsObject(tag);
                return(fileObject.ProcessTag());
            }
            else if (tag.Name == "math")
            {
                MathObject mathObject = new MathObject(tag);
                return(mathObject.ProcessTag());
            }
            else
            {
                // objects that dont need be in initialization proccess
                if (isInitialization == false)
                {
                    if (tag.Name == "active")
                    {
                        return(ActiveObject(tag));
                    }
                    else if (tag.Name == "data")
                    {
                        // Call to main generic method, other method will call it to get object row value and then format it
                        // this one just return pure text value
                        return(DataObjectGetValue(row, tag));
                    }
                    //else if (objectName.StartsWith("data"))
                    //{
                    //    return DataObjectGetValue(objectName, objectValue);
                    //}
                    else
                    {
                        return(DataObjectGetValue(tag));
                    }
                }
            }

            return(null);
        }
예제 #34
0
 public static MathObject cos(MathObject obj) => new Cos(obj).Simplify();
예제 #35
0
 public static MathObject atan(MathObject obj) => new Atan(obj).Simplify();
예제 #36
0
 public Cos(MathObject param)
 {
     name = "cos";
     args = new List<MathObject>() { param };
     proc = CosProc;
 }
예제 #37
0
 public Sin(MathObject param)
 {
     name = "sin";
     args = new List<MathObject>() { param };
     proc = SinProc;
 }
예제 #38
0
 public static bool FreeOf(this MathObject obj, MathObject a) => !obj.Has(a);
예제 #39
0
 public static MathObject sin(MathObject obj) => new Sin(obj).Simplify();
예제 #40
0
파일: Has.cs 프로젝트: prvafina/Symbolism
 public static bool FreeOf(this MathObject obj, MathObject a) => !obj.Has(a);
예제 #41
0
 public static MathObject Substitute(this MathObject obj, MathObject a, double b)
 {
     return obj.Substitute(a, new DoubleFloat(b));
 }
예제 #42
0
 public static MathObject sin(MathObject obj) => new Sin(obj).Simplify();
예제 #43
0
 public Atan(MathObject param) : base("atan", AtanProc, new[] { param })
 {
 }
예제 #44
0
 public static MathObject atan(MathObject obj) => new Atan(obj).Simplify();
예제 #45
0
 public Atan2(MathObject a, MathObject b) : base("atan2", Atan2Proc, new[] { a, b })
 {
 }
예제 #46
0
 public static MathObject ToDegrees(this MathObject n)
 {
     return(180 * n / Pi);
 }
예제 #47
0
 public Atan2(MathObject a, MathObject b)
 {
     name = "atan2";
     args = new List<MathObject>() { a, b };
     proc = Atan2Proc;
 }