Exemplo n.º 1
0
        internal MathematicaConstants(MathematicaInterface parentCas)
        {
            Cas = parentCas;

            True = MathematicaCondition.Create(parentCas, true);
            _constantsDictionary.Add("true", True);

            False = MathematicaCondition.Create(parentCas, false);
            _constantsDictionary.Add("false", False);

            Zero = MathematicaScalar.Create(parentCas, 0);
            _constantsDictionary.Add("zero", Zero);

            One = MathematicaScalar.Create(parentCas, 1);
            _constantsDictionary.Add("one", One);

            MinusOne = MathematicaScalar.Create(parentCas, -1);
            _constantsDictionary.Add("minusone", MinusOne);

            Pi = MathematicaScalar.Create(parentCas, CasConnection.EvaluateToExpr("Pi"));
            _constantsDictionary.Add("pi", Pi);

            TwoPi = MathematicaScalar.Create(parentCas, CasConnection.EvaluateToExpr("Times[2, Pi]"));
            _constantsDictionary.Add("twopi", TwoPi);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Evaluates the given expression and if the result is 'False' it returns true
        /// If the result is 'True' it returns false
        /// If the result is anything else it raises an error
        /// </summary>
        /// <param name="casInterface"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        public static bool EvalIsFalse(this MathematicaInterface casInterface, Expr e)
        {
            var result = casInterface.Connection.EvaluateToExpr(e).ToString();

            switch (result)
            {
            case "True":
                return(false);

            case "False":
                return(true);
            }

            throw new InvalidOperationException("Expression did not evaluate to a constant boolean value");
        }
Exemplo n.º 3
0
 /// <summary>
 /// Create a Mathematica Expr object from the given text expression using the Mathematica interface evaluator
 /// </summary>
 /// <param name="value"></param>
 /// <param name="mathematicaInterface"></param>
 /// <returns></returns>
 public static Expr ToExpr(this string value, MathematicaInterface mathematicaInterface)
 {
     return(mathematicaInterface.Connection.EvaluateToExpr(value));
 }
Exemplo n.º 4
0
        public static Expr CreateAssumeExpr(this MathematicaInterface parentCas, Dictionary <string, MathematicaAtomicType> varTypes)
        {
            var complexesList = new List <Expr>();
            var realsList     = new List <Expr>();
            var rationalsList = new List <Expr>();
            var integersList  = new List <Expr>();
            var booleansList  = new List <Expr>();

            foreach (var pair in varTypes)
            {
                switch (pair.Value)
                {
                case MathematicaAtomicType.Complex:
                    complexesList.Add(pair.Key.ToSymbolExpr());
                    break;

                case MathematicaAtomicType.Real:
                    realsList.Add(pair.Key.ToSymbolExpr());
                    break;

                case MathematicaAtomicType.Rational:
                    rationalsList.Add(pair.Key.ToSymbolExpr());
                    break;

                case MathematicaAtomicType.Integer:
                    integersList.Add(pair.Key.ToSymbolExpr());
                    break;

                case MathematicaAtomicType.Boolean:
                    booleansList.Add(pair.Key.ToSymbolExpr());
                    break;
                }
            }

            var domainElementsExpr = new List <Expr>(4);

            if (complexesList.Count > 0)
            {
                domainElementsExpr.Add(CreateElementExpr(complexesList, DomainSymbols.Complexes));
            }

            if (realsList.Count > 0)
            {
                domainElementsExpr.Add(CreateElementExpr(realsList, DomainSymbols.Reals));
            }

            if (rationalsList.Count > 0)
            {
                domainElementsExpr.Add(CreateElementExpr(rationalsList, DomainSymbols.Rationals));
            }

            if (integersList.Count > 0)
            {
                domainElementsExpr.Add(CreateElementExpr(integersList, DomainSymbols.Integers));
            }

            if (booleansList.Count > 0)
            {
                domainElementsExpr.Add(CreateElementExpr(booleansList, DomainSymbols.Booleans));
            }

            if (domainElementsExpr.Count == 0)
            {
                return(null);
            }

            var expr = domainElementsExpr.Count == 1
                ? parentCas[domainElementsExpr[0]]
                : parentCas[Mfs.And[domainElementsExpr.Cast <object>().ToArray()]];

            return(expr);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Evaluates the given expression and if the result is 'False' it returns true
 /// If the result is anything else it returns false and raises no errors
 /// </summary>
 /// <param name="casInterface"></param>
 /// <param name="e"></param>
 /// <returns></returns>
 public static bool EvalFalseQ(this MathematicaInterface casInterface, Expr e)
 {
     return(casInterface.Connection.EvaluateToExpr(e).ToString() == "False");
 }
Exemplo n.º 6
0
 internal MathematicaEvaluator(MathematicaInterface parentCas)
 {
     Cas = parentCas;
 }
Exemplo n.º 7
0
 internal MathematicaConnection(MathematicaInterface parentCas)
 {
     Cas = parentCas;
 }
Exemplo n.º 8
0
 public static bool IsNullOrEqualZero(this Expr expr, MathematicaInterface casInterface)
 {
     return(ReferenceEquals(expr, null) ||
            (expr.NumberQ() && expr.ToString() == "0") ||
            casInterface.EvalTrueQ(Mfs.Equal[expr, Expr.INT_ZERO]));
 }
Exemplo n.º 9
0
 public static Expr Simplify(this Expr expr, MathematicaInterface casInterface)
 {
     return(expr.AtomQ()
         ? expr
         : casInterface[Mfs.Simplify[expr]]);
 }