コード例 #1
0
        public static void ConstructionTest()
        {
            TestUtils.AddTestStartingMessage("MathematicaScalar Creation Test Started.");

            var s = MathematicaScalar.CreateRational(Cas, 3, 5);

            TestUtils.AddTest("Try create scalar from rational 3/5 ... ", s);

            s = MathematicaScalar.CreateSymbol(Cas, "x3");
            TestUtils.AddTest("Try create scalar from symbol name ... ", s);

            s = MathematicaScalar.Create(Cas, 5);
            TestUtils.AddTest("Try create scalar from integer 5 ... ", s);

            s = MathematicaScalar.Create(Cas, 5.0f);
            TestUtils.AddTest("Try create scalar from float 5.0f ... ", s);

            s = MathematicaScalar.Create(Cas, 5.0d);
            TestUtils.AddTest("Try create scalar from double 5.0d ... ", s);

            var e = Mfs.Plus["v1".ToSymbolExpr(), Mfs.Power[5.ToExpr(), "n".ToSymbolExpr()]];

            s = MathematicaScalar.Create(Cas, e);
            TestUtils.AddTest("Try create scalar from expression object ... ", s);

            s = MathematicaScalar.Create(Cas, @"Pi + 5 / 3");
            TestUtils.AddTest("Try create scalar from expression text \"Pi + 5 / 3\" ... ", s);

            TestUtils.AddTestCompletionMessage("MathematicaScalar Creation Test Completed.");
        }
コード例 #2
0
ファイル: GaSymMultivector.cs プロジェクト: cloudRoutine/GMac
        public static GaSymMultivector CreateSymbolicTerm(int gaSpaceDim, string baseCoefName, int id)
        {
            var vSpaceDim = gaSpaceDim.ToVSpaceDimension();

            return(new GaSymMultivector(gaSpaceDim)
                   .SetTermCoef(
                       id,
                       MathematicaScalar.CreateSymbol(
                           SymbolicUtils.Cas,
                           baseCoefName + id.PatternToString(vSpaceDim)
                           )));
        }
コード例 #3
0
        public static GaSymMultivectorHash CreateSymbolicTerm(int gaSpaceDim, string baseCoefName, int id)
        {
            var vSpaceDim = gaSpaceDim.ToVSpaceDimension();

            return(new GaSymMultivectorHash(gaSpaceDim)
            {
                [id] = MathematicaScalar.CreateSymbol(
                    SymbolicUtils.Cas,
                    baseCoefName + id.PatternToString(vSpaceDim)
                    ).Expression
            });
        }
コード例 #4
0
        public static GaTreeMultivector CreateSymbolic(int gaSpaceDim, string baseCoefName, IEnumerable <int> idsList)
        {
            var resultMv  = new GaTreeMultivector(gaSpaceDim);
            var vSpaceDim = gaSpaceDim.ToVSpaceDimension();

            foreach (var id in idsList)
            {
                resultMv[id] =
                    MathematicaScalar.CreateSymbol(
                        SymbolicUtils.Cas,
                        baseCoefName + id.PatternToString(vSpaceDim)
                        ).Expression;
            }

            return(resultMv);
        }
コード例 #5
0
ファイル: LlDataItem.cs プロジェクト: cloudRoutine/GMac
        /// <summary>
        /// Create a low-level item with an assigned value (not a variable input item)
        /// </summary>
        /// <param name="llName"></param>
        /// <param name="hlValueAccess"></param>
        /// <param name="assignedValue"></param>
        private LlDataItem(string llName, LanguageValueAccess hlValueAccess, ValuePrimitive <MathematicaScalar> assignedValue)//, Expr testValueExpr)
        {
            var llVarNamesCount = assignedValue.Value.GetDistinctLowLevelVariablesNames().Count();
            var isLlVar         = assignedValue.Value.IsLowLevelVariable();

            EvaluationOrder = -1;

            //A constant item is independent of any other low-level item
            IsConstant = (llVarNamesCount == 0);

            ItemId   = CreateNewId();
            ItemName = llName;

            AssociatedValueAccess = hlValueAccess;

            AssignedRhsValue = assignedValue;
            //TestValueExpr = testValueExpr;

            //Apply a propagation step on the value of this item using its associated symbolic scalar
            //(that is used in the RHS values of following items)
            //Only propagate constants
            switch (GMacCompilerOptions.LowLevelPropagationMethod)
            {
            case GMacCompilerOptions.LowLevelPropagation.PropagateConstant:
                RhsUsableSymbolicScalar =
                    IsConstant
                        ? assignedValue.Value
                        : MathematicaScalar.CreateSymbol(SymbolicUtils.Cas, llName);
                break;

            case GMacCompilerOptions.LowLevelPropagation.PropagateSingleVariable:
                RhsUsableSymbolicScalar =
                    (IsConstant || isLlVar)
                        ? assignedValue.Value
                        : MathematicaScalar.CreateSymbol(SymbolicUtils.Cas, llName);
                break;

            default:
                RhsUsableSymbolicScalar =
                    (IsConstant || (llVarNamesCount == 1))
                        ? assignedValue.Value
                        : MathematicaScalar.CreateSymbol(SymbolicUtils.Cas, llName);
                break;
            }
        }
コード例 #6
0
ファイル: LlDataItem.cs プロジェクト: phreed/GMac
        /// <summary>
        /// Create a macro parameter variable low-level item
        /// </summary>
        /// <param name="llName"></param>
        /// <param name="hlValueAccess"></param>
        private LlDataItem(string llName, LanguageValueAccess hlValueAccess)
        {
            var isOutput = hlValueAccess.IsOutputParameter;

            EvaluationOrder       = -1;
            IsConstant            = false;
            ItemId                = CreateNewId();
            ItemName              = llName;
            AssociatedValueAccess = hlValueAccess;

            //Input variable low-level items have no assigned values to them, while output items get assigned
            //a default value
            AssignedRhsValue =
                (!isOutput) ? null :
                ((TypePrimitive)AssociatedValueAccess.ExpressionType).GetDefaultScalarValue();

            //Output variable low-level items can never be used in the RHS of any other item so they have no usable
            //symbolic scalar (i.e. for reading purposes)
            RhsUsableSymbolicScalar =
                isOutput ? null :
                MathematicaScalar.CreateSymbol(SymbolicUtils.Cas, llName);
        }
コード例 #7
0
        public static void BasicOpsTest()
        {
            //Expr e;
            var s1 = MathematicaScalar.CreateRational(Cas, -3, 5);
            var s2 = MathematicaScalar.CreateRational(Cas, 9, 5);
            var s3 = MathematicaScalar.Create(Cas, "Pi");

            TestUtils.AddTestStartingMessage("MathematicaScalar Basic Operations Test Started.");

            TestUtils.AddTest("Try negate rational -3/5 ... ", -s1);
            TestUtils.AddTest("Try add rationals -3/5 and 9/5 ... ", s1 + s2);
            TestUtils.AddTest("Try subtract rationals -3/5 and 9/5 ... ", s1 - s2);
            TestUtils.AddTest("Try multiply rationals -3/5 and 9/5 ... ", s1 * s2);
            TestUtils.AddTest("Try divide rationals -3/5 and 9/5 ... ", s1 / s2);
            TestUtils.AddTest("Try rise rational 9/5 to the power of Pi ... ", s2 ^ s3);

            TestUtils.AddTest("Try apply Abs to rational -3/5 ... ", s1.Abs());
            TestUtils.AddTest("Try apply Sqrt to rational -3/5 ... ", s1.Sqrt());
            TestUtils.AddTest("Try apply Sin to rational 9/5 ... ", s2.Sin());
            TestUtils.AddTest("Try apply Cos to rational 9/5 ... ", s2.Cos());
            TestUtils.AddTest("Try apply Tan to rational 9/5 ... ", s2.Tan());
            TestUtils.AddTest("Try apply Sinh to rational 9/5 ... ", s2.Sinh());
            TestUtils.AddTest("Try apply Cosh to rational 9/5 ... ", s2.Cosh());
            TestUtils.AddTest("Try apply Tanh to rational 9/5 ... ", s2.Tanh());
            TestUtils.AddTest("Try apply Log to rational 9/5 ... ", s2.Log());
            TestUtils.AddTest("Try apply Log10 to rational 9/5 ... ", s2.Log10());
            TestUtils.AddTest("Try apply Log2 to rational 9/5 ... ", s2.Log2());
            TestUtils.AddTest("Try apply Exp to rational 9/5 ... ", s2.Exp());

            var s = MathematicaScalar.Create(Cas, @"3 x ^ 2 + 2 Pi ^ x - Sin[x]");
            var d = MathematicaScalar.CreateSymbol(Cas, "x");

            TestUtils.AddTest("Try differentiate 3 x ^ 2 + 2 Pi ^ x - Sin[x] w.r.t. x ... ", s.DiffBy(d));

            TestUtils.AddTestCompletionMessage("MathematicaScalar Basic Operations Test Completed.");
        }
コード例 #8
0
        public static void IsOpsTest()
        {
            TestUtils.AddTestStartingMessage("MathematicaScalar 'Is' Operations Test Started.");

            var s1 = MathematicaScalar.Create(Cas, 0.0f);

            TestUtils.AddTest("Try apply IsPossibleZero() to 0.0f ... ", s1.IsPossibleZero());

            s1 = MathematicaScalar.CreateSymbol(Cas, "Pi");
            TestUtils.AddTest("Try apply IsPossibleZero() to Pi ... ", s1.IsPossibleZero());

            s1 = MathematicaScalar.Create(Cas, @"x - x");
            TestUtils.AddTest("Try apply IsPossibleZero() to (x - x) ... ", s1.IsPossibleZero());

            s1 = MathematicaScalar.Create(Cas, @"3 x ^ 2 + 2 Pi ^ x - Sin[x]");
            TestUtils.AddTest("Try apply IsPossibleZero() to 3 x ^ 2 + 2 Pi ^ x - Sin[x] ... ", s1.IsPossibleZero());


            s1 = MathematicaScalar.Create(Cas, 0.0f);
            TestUtils.AddTest("Try apply IsEqualZero() to 0.0f ... ", s1.IsEqualZero());

            s1 = MathematicaScalar.CreateSymbol(Cas, "Pi");
            TestUtils.AddTest("Try apply IsEqualZero() to Pi ... ", s1.IsEqualZero());

            s1 = MathematicaScalar.Create(Cas, @"x - x");
            TestUtils.AddTest("Try apply IsEqualZero() to (x - x) ... ", s1.IsEqualZero());

            s1 = MathematicaScalar.Create(Cas, @"3 x ^ 2 + 2 Pi ^ x - Sin[x]");
            TestUtils.AddTest("Try apply IsEqualZero() to 3 x ^ 2 + 2 Pi ^ x - Sin[x] ... ", s1.IsEqualZero());


            s1 = MathematicaScalar.Create(Cas, 5.0f);
            var s2 = MathematicaScalar.Create(Cas, 5);

            TestUtils.AddTest("Try apply IsPossibleScalar() to 5.0f with 5 ... ", s1.IsPossibleScalar(s2));

            s1 = MathematicaScalar.Create(Cas, 5.1f);
            s2 = MathematicaScalar.Create(Cas, 5);
            TestUtils.AddTest("Try apply IsPossibleScalar() to 5.1f with 5 ... ", s1.IsPossibleScalar(s2));

            s1 = MathematicaScalar.Create(Cas, 1.0f);
            s2 = MathematicaScalar.Create(Cas, "Sin[Pi]");
            TestUtils.AddTest("Try apply IsPossibleScalar() to 1.0f with Sin[Pi] ... ", s1.IsPossibleScalar(s2));

            s1 = MathematicaScalar.Create(Cas, -1.0f);
            s2 = MathematicaScalar.Create(Cas, "Cos[Pi]");
            TestUtils.AddTest("Try apply IsPossibleScalar() to -1.0f with Cos[Pi] ... ", s1.IsPossibleScalar(s2));


            s1 = MathematicaScalar.Create(Cas, 5.0f);
            s2 = MathematicaScalar.Create(Cas, 5);
            TestUtils.AddTest("Try apply IsEqualScalar() to 5.0f with 5 ... ", s1.IsEqualScalar(s2));

            s1 = MathematicaScalar.Create(Cas, 5.1f);
            s2 = MathematicaScalar.Create(Cas, 5);
            TestUtils.AddTest("Try apply IsEqualScalar() to 5.1f with 5 ... ", s1.IsEqualScalar(s2));

            s1 = MathematicaScalar.Create(Cas, 1.0f);
            s2 = MathematicaScalar.Create(Cas, "Sin[Pi]");
            TestUtils.AddTest("Try apply IsEqualScalar() to 1.0f with Sin[Pi] ... ", s1.IsEqualScalar(s2));

            s1 = MathematicaScalar.Create(Cas, -1.0f);
            s2 = MathematicaScalar.Create(Cas, "Cos[Pi]");
            TestUtils.AddTest("Try apply IsEqualScalar() to -1.0f with Cos[Pi] ... ", s1.IsEqualScalar(s2));


            s1 = MathematicaScalar.Create(Cas, -1.0f);
            TestUtils.AddTest("Try apply IsConstant() to -1.0f ... ", s1.IsConstant());

            s1 = MathematicaScalar.Create(Cas, "Sin[Pi]");
            TestUtils.AddTest("Try apply IsConstant() to Sin[Pi] ... ", s1.IsConstant());

            s1 = MathematicaScalar.Create(Cas, "Sin[x]");
            TestUtils.AddTest("Try apply IsConstant() to Sin[x] ... ", s1.IsConstant());

            s1 = MathematicaScalar.Create(Cas, "Sin[x - x]");
            TestUtils.AddTest("Try apply IsConstant() to Sin[x - x] ... ", s1.IsConstant());


            s1 = MathematicaScalar.Create(Cas, 0.0f);
            TestUtils.AddTest("Try apply IsNonZeroRealConstant() to 0.0f ... ", s1.IsNonZeroRealConstant());

            s1 = MathematicaScalar.Create(Cas, -1.0f);
            TestUtils.AddTest("Try apply IsNonZeroRealConstant() to -1.0f ... ", s1.IsNonZeroRealConstant());

            s1 = MathematicaScalar.Create(Cas, "Sin[Pi]");
            TestUtils.AddTest("Try apply IsNonZeroRealConstant() to Sin[Pi] ... ", s1.IsNonZeroRealConstant());

            s1 = MathematicaScalar.Create(Cas, "Sin[x]");
            TestUtils.AddTest("Try apply IsNonZeroRealConstant() to Sin[x] ... ", s1.IsNonZeroRealConstant());

            s1 = MathematicaScalar.Create(Cas, "Sin[x - x]");
            TestUtils.AddTest("Try apply IsNonZeroRealConstant() to Sin[x - x] ... ", s1.IsNonZeroRealConstant());

            s1 = MathematicaScalar.Create(Cas, "3 + i * Sin[Pi / 2]");
            TestUtils.AddTest("Try apply IsNonZeroRealConstant() to 3 + i * Sin[Pi / 2] ... ", s1.IsNonZeroRealConstant());


            TestUtils.AddTestCompletionMessage("MathematicaScalar 'Is' Operations Test Completed.");
        }