示例#1
0
        public override void Calculate(CalculationItemStack calculationStack, bool isToAdd = true)
        {
            if (null == Value)
            {
                if (null == Numbers)
                {
                    if (null != Symbolic)
                    {
                        List <SymbolValuePair> symbolValueList = calculationStack.GetAsSymbolValueList();
                        Numbers = Symbolic.Clone(symbolValueList);
                    }
                    else
                    {
                        if (null != Symbol)
                        {
                            List <SymbolValuePair> symbolValueList = calculationStack.GetAsSymbolValueList();
                            Value = (ValueItem)Symbol.Clone(symbolValueList);
                            return;
                        }
                    }
                }

                double value = Numbers.GetValue();
                Value       = new ValueItem();
                Value.Value = value;
            }

            if (isToAdd)
            {
                calculationStack.Items.Add(this);
            }
        }
示例#2
0
    internal override Symbolic PreEval(Symbolic x)
    {
        Complex z = x.ToComplex();

        if (z.Re < 0 || z.Im != 0.0)
        {
            return(new Complex(JMath.log(z.Re * z.Re + z.Im * z.Im) / 2, JMath.atan2(z.Im, z.Re)));
        }
        return(new Complex(JMath.log(z.Re)));
    }
示例#3
0
    internal override Symbolic PreEval(Symbolic x)
    {
        Complex z = x.ToComplex();

        if (z.Im == 0.0)
        {
            return(new Complex(Math.Tan(z.Re)));
        }
        return(( Symbolic )evalx(trigrule, z));
    }
示例#4
0
    public virtual Algebraic rat_reverse(Algebraic expr)
    {
        if (gcd.Equals(Symbolic.ZERO))
        {
            return(expr);
        }
        Symbolic  gc = gcd;
        Algebraic s  = new Exponential(Symbolic.ONE, Symbolic.ZERO, @var, Symbolic.ONE * gc);

        return(expr.Value(t, s));
    }
示例#5
0
    public SubstExp(Variable @var, Algebraic expr)
    {
        this.@var = @var;
        ArrayList v = new ArrayList();

        (new GetExpVars2(v)).SymEval(expr);
        this.gcd = Exponential.exp_gcd(v, @var);
        if (gcd.Equals(Symbolic.ZERO))
        {
            t = @var;
        }
    }
示例#6
0
    public override bool Smaller(Symbolic x)
    {
        var xu = x.ToComplex();

        if (Re == xu.Re)
        {
            return(Im < xu.Im);
        }
        else
        {
            return(Re < xu.Re);
        }
    }
示例#7
0
    internal override Symbolic PreEval(Symbolic x)
    {
        Complex z = x.ToComplex();

        double r = JMath.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));
    }
示例#8
0
    internal override Symbolic PreEval(Symbolic x)
    {
        if (!x.IsInteger() || x.Smaller(Symbolic.ZERO))
        {
            throw new JasymcaException("Argument to factorial must be a positive integer, is " + x);
        }

        Algebraic r = Symbolic.ONE;

        while (Symbolic.ONE.Smaller(x))
        {
            r = r * x;
            x = ( Symbolic )(x - Symbolic.ONE);
        }

        return(( Symbolic )r);
    }
示例#9
0
 internal override Symbolic PreEval(Symbolic x)
 {
     return(Equals(x, Symbolic.ZERO) ? Symbolic.ONE : Symbolic.ZERO);
 }
示例#10
0
 internal override Algebraic SymEval(Symbolic x, Symbolic y)
 {
     return(x < y ? Symbolic.ONE : Symbolic.ZERO);
 }
示例#11
0
 internal override Algebraic SymEval(Symbolic x, Symbolic y)
 {
     return(y < x ? Symbolic.ZERO : Symbolic.ONE);
 }
示例#12
0
 internal override Symbolic PreEval(Symbolic x)
 {
     return(( Symbolic )SymEval(x));
 }
示例#13
0
 public abstract bool Smaller(Symbolic a);
示例#14
0
 internal override Symbolic PreEval(Symbolic x)
 {
     return(null);
 }
示例#15
0
    internal virtual Algebraic fzexakt(Symbolic x)
    {
        if (x < Symbolic.ZERO)
        {
            var r = fzexakt(( Symbolic )(-x));

            if (r != null)
            {
                return(r.Conj());
            }
            return(r);
        }

        if (x.IsInteger())
        {
            if (x.ToInt() % 2 == 0)
            {
                return(Symbolic.ONE);
            }
            else
            {
                return(Symbolic.MINUS);
            }
        }

        var qs = x + new Complex(0.5);

        if (((Symbolic)qs).IsInteger())
        {
            if (((Symbolic)qs).ToInt() % 2 == 0)
            {
                return(Symbolic.IMINUS);
            }
            else
            {
                return(Symbolic.IONE);
            }
        }

        qs = x * new Complex(4);

        if (((Symbolic)qs).IsInteger())
        {
            Algebraic sq2 = FunctionVariable.Create("sqrt", new Complex(0.5));
            switch (((Symbolic)qs).ToInt() % 8)
            {
            case 1:
                return((Symbolic.ONE + Symbolic.IONE) / Symbolic.SQRT2);

            case 3:
                return((Symbolic.MINUS + Symbolic.IONE) / Symbolic.SQRT2);

            case 5:
                return((Symbolic.MINUS + Symbolic.IMINUS) / Symbolic.SQRT2);

            case 7:
                return((Symbolic.ONE + Symbolic.IMINUS) / Symbolic.SQRT2);
            }
        }

        qs = x * new Complex(6);

        if (((Symbolic)qs).IsInteger())
        {
            switch (((Symbolic)qs).ToInt() % 12)
            {
            case 1:
                return((Symbolic.SQRT3 + Symbolic.IONE) / Symbolic.TWO);

            case 2:
                return((Symbolic.ONE + Symbolic.SQRT3) * Symbolic.IONE / Symbolic.TWO);

            case 4:
                return((Symbolic.SQRT3 * Symbolic.IONE + Symbolic.MINUS) / Symbolic.TWO);

            case 5:
                return((Symbolic.IONE - Symbolic.SQRT3) / Symbolic.TWO);

            case 7:
                return((Symbolic.IMINUS - Symbolic.SQRT3) / Symbolic.TWO);

            case 8:
                return((Symbolic.SQRT3 * Symbolic.IMINUS - Symbolic.ONE) / Symbolic.TWO);

            case 10:
                return((Symbolic.SQRT3 * Symbolic.IMINUS + Symbolic.ONE) / Symbolic.TWO);

            case 11:
                return((Symbolic.IMINUS + Symbolic.SQRT3) / Symbolic.TWO);
            }
        }
        return(null);
    }
示例#16
0
 public override bool Smaller(Symbolic x)
 {
     return(ToComplex().Smaller(x));
 }
示例#17
0
 internal override Algebraic SymEval(Symbolic x, Symbolic y)
 {
     return(Equals(x, Symbolic.ONE) && Equals(y, Symbolic.ONE) ? Symbolic.ONE : Symbolic.ZERO);
 }
示例#18
0
 public virtual Symbolic gcd(Symbolic x)
 {
     return(ToNumber().gcd(x.ToNumber()));
 }
示例#19
0
 public SubstExp(Symbolic gcd, Variable @var)
 {
     this.gcd  = gcd;
     this.@var = @var;
 }
示例#20
0
 internal override Symbolic PreEval(Symbolic x)
 {
     return(new Complex(Sfun.logGamma(x.ToComplex().Re)));
 }
示例#21
0
        /// <summary>
        /// If this FunctionGenerator can implement 'F', then this function should complete the (possible)
        /// blanks in 'F'. This means:
        ///  - Fill in F.m_returnTypeName if it is empty
        ///  - Fill in F.m_argumentTypeNames (and m_argumentVariableNames) if it is empty.
        ///
        /// As the return type is required, many functions will also compute the return value and other info
        /// needed for generating the code inside this function. These intermediate values are then
        /// stored in class variables so they can be reused in WriteFunction()
        /// </summary>
        public override void CompleteFGS()
        {
            NB_ARGS = m_fgs.NbArguments; // all arguments must be explicitly listed

            // init argument pointers from the completed typenames (language sensitive);
            m_fgs.InitArgumentPtrFromTypeNames(m_specification);

            // get all function info
            FloatType FT = m_specification.GetFloatType(m_fgs.FloatNames[0]);
            bool      computeMultivectorValue = true;

            G25.CG.Shared.FuncArgInfo[] tmpFAI = G25.CG.Shared.FuncArgInfo.GetAllFuncArgInfo(m_specification, m_fgs, NB_ARGS, FT, m_specification.m_GMV.Name, computeMultivectorValue);

            { // compute return value
                RefGA.Multivector no = GetOrigin(m_specification, m_fgs);
                RefGA.Multivector ni = GetInfinity(m_specification, m_fgs);

                // compose a vector value (the Euclidean part)
                RefGA.Multivector vectorValue = RefGA.Multivector.ZERO;
                if ((IsRandom(m_specification, m_fgs)) || (IsCoordBased(m_specification, m_fgs, FT)))
                {
                    m_returnValue = no;
                    for (int i = 0; i < m_specification.m_dimension - 2; i++)
                    {
                        string bvName = "e" + (i + 1).ToString(); // todo: this assumes a fixed name for the basis vectors. Make these names options?
                        int    bvIdx  = m_specification.GetBasisVectorIndex(bvName);
                        if (bvIdx < 0)
                        {
                            throw new G25.UserException("Cannot find basis vector " + bvName, XML.FunctionToXmlString(m_specification, m_fgs));
                        }

                        RefGA.Multivector basisVector = RefGA.Multivector.GetBasisVector(bvIdx);

                        if (IsRandom(m_specification, m_fgs))
                        {
                            vectorValue = RefGA.Multivector.Add(vectorValue, RefGA.Multivector.gp(new RefGA.Multivector("ce" + (i + 1).ToString()), basisVector));
                        }
                        else
                        {
                            vectorValue = RefGA.Multivector.Add(vectorValue, RefGA.Multivector.gp(tmpFAI[i].MultivectorValue[0], basisVector));
                        }
                    }
                }
                else if (IsVectorBased(m_specification, m_fgs, FT))
                {
                    vectorValue  = tmpFAI[0].MultivectorValue[0];
                    m_vectorType = tmpFAI[0].Type;
                }
                else if (IsFlatPointBased(m_specification, m_fgs, FT))
                {
                    m_flatPointType = tmpFAI[0].Type as G25.SMV;
                    RefGA.BasisBlade.InnerProductType lc = RefGA.BasisBlade.InnerProductType.LEFT_CONTRACTION;
                    RefGA.Multivector noni = RefGA.Multivector.OuterProduct(no, ni);
                    // scale = no^ni . pointPair
                    RefGA.Multivector scale =
                        RefGA.Multivector.InnerProduct(noni, tmpFAI[0].MultivectorValue[0], m_M, lc).ScalarPart();
                    if (m_G25M.m_round)
                    {
                        scale = scale.Round(1e-14);
                    }

                    // sphere = no . pointPair
                    RefGA.Multivector sphere = RefGA.Multivector.InnerProduct(no, tmpFAI[0].MultivectorValue[0], m_M, lc);
                    // normalizedSphere = sphere / scale

                    bool needToNormalize = (scale.HasSymbolicScalars() || (scale.RealScalarPart() != 1.0));
                    RefGA.Multivector normalizedSphere = (needToNormalize) ? RefGA.Multivector.gp(sphere, RefGA.Symbolic.UnaryScalarOp.Inverse(scale)) : sphere;

                    // keep only euclidean vectors
                    RefGA.Multivector euclMultivector = getSumOfUnitEuclideanBasisVectors();
                    // vector = sphere-noni
                    m_pointPairVectorValue = RefGA.Multivector.hp(normalizedSphere, euclMultivector);
                    // round vector
                    if (m_G25M.m_round)
                    {
                        m_pointPairVectorValue = m_pointPairVectorValue.Round(1e-14);
                    }

                    // get type
                    m_vectorType = (G25.SMV)G25.CG.Shared.SpecializedReturnType.FindTightestMatch(m_specification, m_pointPairVectorValue, FT);
                    if (m_vectorType == null)
                    {
                        throw new G25.UserException("Missing Euclidean vector type; cannot construct conformal point from " + m_fgs.ArgumentTypeNames[0], XML.FunctionToXmlString(m_specification, m_fgs));
                    }

                    // get 'value' (just a reference to the name of the variable where m_pointPairVectorValue will be stored.
                    bool pointer = false;
                    vectorValue = Symbolic.SMVtoSymbolicMultivector(m_specification, (G25.SMV)m_vectorType, VECTOR_NAME, pointer);
                }
                else
                {
                    throw new G25.UserException("Invalid arguments specified.", XML.FunctionToXmlString(m_specification, m_fgs));
                }

                { // add no and 0.5 vectorValue^2 ni
                    RefGA.Multivector vectorValueSquared = RefGA.Multivector.scp(vectorValue, vectorValue);
                    RefGA.Multivector niPart             = RefGA.Multivector.gp(
                        RefGA.Multivector.gp(vectorValueSquared, ni), 0.5);
                    m_returnValue = RefGA.Multivector.Add(RefGA.Multivector.Add(no, vectorValue), niPart);
                }
            } // end of compute return value

            // get name of return type
            if (m_fgs.m_returnTypeName.Length == 0)
            {
                m_fgs.m_returnTypeName = G25.CG.Shared.SpecializedReturnType.GetReturnType(m_specification, m_cgd, m_fgs, FT, m_returnValue).GetName();
            }
        } // end of CompleteFGS()