コード例 #1
0
        /// <summary>
        /// Evaluates a Multivector to a summary of its expected value (-1, 0, 1).
        /// The function uses a Symbolic.RandomSymbolicEvaluator to randomly evaluate
        /// <paramref name="A"/>. If the results are consistently negative, zero or
        /// positive then -1, 0 or 1 is returned. Otherwise an exception is thrown.
        /// </summary>
        /// <param name="A">The multivector to evaluate</param>
        /// <returns>-1, 0 or 1</returns>
        /// <remarks>
        /// Used by Multivector.Exp(), Multivector.Cos() and Multivector.Sin() to see
        /// if the input bivector has a scalar square.
        /// </remarks>
        public static double EvaluateRandomSymbolicToScalar(Multivector A)
        {
            double EPS     = 1e-4;
            int    NB_ITER = 100;
            int    REQ     = 98;

            Symbolic.RandomSymbolicEvaluator RSE = new Symbolic.RandomSymbolicEvaluator(-100.0, 100.0);
            int pos = 0, neg = 0, zero = 0;

            for (int i = 0; i < NB_ITER; i++)
            {
                Multivector E          = A.SymbolicEval(RSE);
                double      scalarPart = E.RealScalarPart();
                Multivector theRest    = Multivector.Subtract(E, scalarPart);
                if (Math.Abs(theRest.Norm_e().RealScalarPart()) > Math.Abs(scalarPart) * EPS)
                {
                    throw new Exception("Multivector did not evaluate to scalar");
                }

                if (scalarPart > EPS)
                {
                    pos++;
                }
                else if (scalarPart < -EPS)
                {
                    neg++;
                }
                else
                {
                    zero++;
                }
            }

            if (pos >= REQ)
            {
                return(1.0);
            }
            else if (zero >= REQ)
            {
                return(0.0);
            }
            else if (neg >= REQ)
            {
                return(-1.0);
            }
            else
            {
                throw new Exception("Multivector did not evaluate to a consistent value");
            }
        }
コード例 #2
0
ファイル: Symbolic.cs プロジェクト: Sciumo/gaigen
        /// <summary>
        /// Evaluates a Multivector to a summary of its expected value (-1, 0, 1).
        /// The function uses a Symbolic.RandomSymbolicEvaluator to randomly evaluate
        /// <paramref name="A"/>. If the results are consistently negative, zero or 
        /// positive then -1, 0 or 1 is returned. Otherwise an exception is thrown.
        /// </summary>
        /// <param name="A">The multivector to evaluate</param>
        /// <returns>-1, 0 or 1</returns>
        /// <remarks>
        /// Used by Multivector.Exp(), Multivector.Cos() and Multivector.Sin() to see
        /// if the input bivector has a scalar square.
        /// </remarks>
        public static double EvaluateRandomSymbolicToScalar(Multivector A)
        {
            double EPS = 1e-4;
            int NB_ITER = 100;
            int REQ = 98;

            Symbolic.RandomSymbolicEvaluator RSE = new Symbolic.RandomSymbolicEvaluator(-100.0, 100.0);
            int pos = 0, neg = 0, zero = 0;
            for (int i = 0; i < NB_ITER; i++)
            {
                Multivector E = A.SymbolicEval(RSE);
                double scalarPart = E.RealScalarPart();
                Multivector theRest = Multivector.Subtract(E, scalarPart);
                if (Math.Abs(theRest.Norm_e().RealScalarPart()) > Math.Abs(scalarPart) * EPS)
                    throw new Exception("Multivector did not evaluate to scalar");

                if (scalarPart > EPS) pos++;
                else if (scalarPart < -EPS) neg++;
                else zero++;
            }

            if (pos >= REQ) return 1.0;
            else if (zero >= REQ) return 0.0;
            else if (neg >= REQ) return -1.0;
            else throw new Exception("Multivector did not evaluate to a consistent value");
        }