Beispiel #1
0
        public Exprs.NumberExpr NextPrime(EvalContext argContext, Exprs.Expr n)
        {
            var pInt = Integer(argContext, n);

            var pRet = BigInteger.NextProbablePrime(pInt, argContext.CancelToken);

            return(Exprs.Expr.Number(pRet));
        }
Beispiel #2
0
        public Exprs.ListExpr Primes(EvalContext argContext, Exprs.Expr start, Exprs.Expr end)
        {
            var pStartInt = Integer(argContext, start);
            var pEndInt   = Integer(argContext, end);
            var pPrimes   = from n in Math.MathEx.Primes(pStartInt, pEndInt, PrimePNumberOfTest, argContext.CancelToken) select Exprs.Expr.Number(n);

            return(Exprs.Expr.List(pPrimes));
        }
Beispiel #3
0
        public Exprs.BooleanExpr PrimeP(EvalContext argContext, Exprs.Expr n)
        {
            var pInt = Integer(argContext, n);

            var pRet = BigInteger.IsProbablePrime(pInt, PrimePNumberOfTest, argContext.CancelToken);

            return(Exprs.Expr.Boolean(pRet));
        }
Beispiel #4
0
        public BigInteger Integer(EvalContext argContext, Exprs.Expr e)
        {
            if (!Integer(argContext, e, out Exprs.Expr argRet, out BigInteger argInteger))
            {
                throw new EvalException(string.Format(Properties.Resources.NoExprIntegerException, e));
            }

            return(argInteger);
        }
Beispiel #5
0
 public void AddInOut(Exprs.Expr i, Exprs.Expr o, out string argNameVarOut)
 {
     lock (mInOutExprs)
     {
         mInOutExprs.Add(new InOutExpr {
             In = i, Out = o
         });
         argNameVarOut = OutNVar(mInOutExprs.Count);
     }
 }
Beispiel #6
0
        public string Tex(EvalContext argContext, Exprs.Expr e)
        {
            argContext.CancelToken.ThrowIfCancellationRequested();
            switch (e.TypeExpr)
            {
            case Exprs.ETypeExpr.List:
                return(Tex(argContext, (Exprs.ListExpr)e));

            default:
                return(e.ToString());
            }
        }
Beispiel #7
0
        public InOutExpr AddInOut(Exprs.Expr i, Exprs.Expr o, out string argNameVarIn, out string argNameVarOut)
        {
            lock (mInOutExprs)
            {
                var pIOE = new InOutExpr {
                    In = i, Out = o
                };

                mInOutExprs.Add(pIOE);
                argNameVarIn  = InNVar(mInOutExprs.Count);
                argNameVarOut = OutNVar(mInOutExprs.Count);

                return(pIOE);
            }
        }
Beispiel #8
0
        public bool Integer(EvalContext argContext, Exprs.Expr e, out Exprs.Expr argRet, out BigInteger argInteger)
        {
            var pRet = Approx(argContext, Exprs.EPrecisionNumber.Integer, e);

            argRet = pRet;
            if (pRet.TypeExpr == Exprs.ETypeExpr.Number && pRet is Exprs.IntegerNumberExpr en)
            {
                argInteger = en.PrecisionValue;

                return(true);
            }

            argInteger = null;

            return(false);
        }
Beispiel #9
0
        public Exprs.Expr Eval(EvalContext argContext, Exprs.Expr e)
        {
            switch (e.TypeExpr)
            {
            case Exprs.ETypeExpr.Number:
                if (e is Exprs.NumberExpr ne)
                {
                    return(ne.ConverTo(argContext.Precision, FPPrec));
                }

                break;

            case Exprs.ETypeExpr.Function:
                if (e is Exprs.FunctionExpr pFn)
                {
                    return(Eval(argContext, pFn));
                }

                break;
            }

            return(e);
        }
Beispiel #10
0
 protected virtual void PrintExpr(string argNameVarPrompt, Exprs.Expr e)
 {
 }
Beispiel #11
0
 public virtual void PrintExprOut(string argNameVarPrompt, Exprs.Expr e) => PrintExpr(argNameVarPrompt, e);
Beispiel #12
0
 public Exprs.Expr Eval(Exprs.Expr e, IVars argVars, CancellationToken argCancelToken) => e;
Beispiel #13
0
        public Exprs.Expr Approx(EvalContext argContext, Exprs.EPrecisionNumber argPrecision, Exprs.Expr e)
        {
            var c  = new EvalContext(argContext, argPrecision);
            var e1 = Eval(c, e);

            // falta aplicar operaciones y funciones matemáticas

            var e2 = e1;

            return((e2.TypeExpr == Exprs.ETypeExpr.Number && e2 is Exprs.NumberExpr ne) ? ne.ConverTo(argPrecision, FPPrec) : e2);
        }
Beispiel #14
0
        public Exprs.Expr EvalIn(EvalContext argContext, Exprs.Expr e)
        {
            var pExpr = (e.TypeExpr == Exprs.ETypeExpr.Function && e is Exprs.FunctionExpr pFn) ? Eval(argContext, pFn, false) : Eval(argContext, e);

            return(pExpr);
        }