Search in sources :

Example 31 with ISignedNumber

use of org.matheclipse.core.interfaces.ISignedNumber in project symja_android_library by axkr.

the class CDF method evaluateNumericMode.

private IExpr evaluateNumericMode(IAST dist, IExpr xArg, ISymbol head) {
    try {
        RealDistribution realDistribution;
        IntegerDistribution intDistribution;
        if (dist.isAST1()) {
            if (head.equals(F.BernoulliDistribution)) {
            } else if (head.equals(F.PoissonDistribution)) {
                int n = ((ISignedNumber) dist.arg1()).toInt();
                int k = ((ISignedNumber) xArg).toInt();
            }
        } else if (dist.isAST2()) {
            if (head.equals(F.BinomialDistribution)) {
                int n = ((ISignedNumber) dist.arg1()).toInt();
                double p = ((ISignedNumber) dist.arg2()).doubleValue();
                int k = ((ISignedNumber) xArg).toInt();
            } else if (head.equals(F.NormalDistribution)) {
                double mean = ((ISignedNumber) dist.arg1()).doubleValue();
                double stdDev = ((ISignedNumber) dist.arg2()).doubleValue();
                double x = ((ISignedNumber) xArg).doubleValue();
            }
        } else if (dist.isAST3()) {
            if (head.equals(F.HypergeometricDistribution)) {
                int n = ((ISignedNumber) dist.arg1()).toInt();
                int nSucc = ((ISignedNumber) dist.arg2()).toInt();
                int nTot = ((ISignedNumber) dist.arg3()).toInt();
                int k = ((ISignedNumber) xArg).toInt();
            }
        }
    } catch (ArithmeticException ae) {
    } catch (ClassCastException cca) {
    }
    return F.NIL;
}
Also used : ISignedNumber(org.matheclipse.core.interfaces.ISignedNumber) IntegerDistribution(org.hipparchus.distribution.IntegerDistribution) RealDistribution(org.hipparchus.distribution.RealDistribution)

Example 32 with ISignedNumber

use of org.matheclipse.core.interfaces.ISignedNumber in project symja_android_library by axkr.

the class HornerScheme method collectTerm.

private void collectTerm(ISymbol sym, IExpr expr) {
    if (expr instanceof IAST) {
        IAST term = (IAST) expr;
        if (term.isASTSizeGE(F.Times, 2)) {
            for (int i = 1; i < term.size(); i++) {
                if (sym.equals(term.get(i))) {
                    IAST temp = F.ast(term, F.Times, false, i, i + 1);
                    addToMap(F.C1, temp);
                    return;
                } else if (term.get(i).isAST(F.Power, 3)) {
                    IAST pow = (IAST) term.get(i);
                    if (pow.arg1().equals(sym) && pow.arg2() instanceof ISignedNumber) {
                        IAST temp = F.ast(term, F.Times, false, i, i + 1);
                        addToMap((ISignedNumber) pow.arg2(), temp);
                        return;
                    }
                }
            }
        } else if (term.isAST(F.Power, 3)) {
            if (term.arg1().equals(sym) && term.arg2() instanceof ISignedNumber) {
                addToMap((ISignedNumber) term.arg2(), F.C1);
                return;
            }
        }
    } else if (expr instanceof ISymbol && expr.equals(sym)) {
        addToMap(F.C1, F.C1);
        return;
    }
    addToMap(F.C0, expr);
}
Also used : ISignedNumber(org.matheclipse.core.interfaces.ISignedNumber) ISymbol(org.matheclipse.core.interfaces.ISymbol) IAST(org.matheclipse.core.interfaces.IAST)

Example 33 with ISignedNumber

use of org.matheclipse.core.interfaces.ISignedNumber in project symja_android_library by axkr.

the class HornerScheme method collectTermN.

private void collectTermN(ISymbol sym, IExpr expr) {
    if (expr instanceof IAST) {
        IAST term = (IAST) expr;
        if (term.isASTSizeGE(F.Times, 2)) {
            for (int i = 1; i < term.size(); i++) {
                if (sym.equals(term.get(i))) {
                    IAST temp = F.ast(term, F.Times, false, i, i + 1);
                    addToMap(F.CD1, temp);
                    return;
                } else if (term.get(i).isAST(F.Power, 3)) {
                    IAST pow = (IAST) term.get(i);
                    if (pow.arg1().equals(sym) && pow.arg2().isSignedNumber()) {
                        IAST temp = F.ast(term, F.Times, false, i, i + 1);
                        addToMap((ISignedNumber) pow.arg2(), temp);
                        return;
                    }
                }
            }
        } else if (term.isAST(F.Power, 3)) {
            if (term.arg1().equals(sym) && term.arg2().isSignedNumber()) {
                addToMap((ISignedNumber) term.arg2(), F.CD1);
                return;
            }
        }
    } else if (expr instanceof ISymbol && expr.equals(sym)) {
        addToMap(F.CD1, F.CD1);
        return;
    }
    addToMap(F.CD0, expr);
}
Also used : ISignedNumber(org.matheclipse.core.interfaces.ISignedNumber) ISymbol(org.matheclipse.core.interfaces.ISymbol) IAST(org.matheclipse.core.interfaces.IAST)

Example 34 with ISignedNumber

use of org.matheclipse.core.interfaces.ISignedNumber in project symja_android_library by axkr.

the class PolyLog method evaluate.

/**
	 * See <a href="https://github.com/sympy/sympy/blob/master/sympy/functions/special/zeta_functions.py">Sympy - zeta_functions.py</a>
	 */
@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
    Validate.checkSize(ast, 3);
    IExpr arg1 = ast.arg1();
    IExpr arg2 = ast.arg2();
    if (arg2.isZero()) {
        return F.C0;
    }
    if (arg2.isOne()) {
        IExpr temp = arg1.re();
        if (temp.isSignedNumber()) {
            ISignedNumber num = (ISignedNumber) temp;
            if (num.isOne()) {
                return F.Indeterminate;
            } else if (num.isGreaterThan(F.C1)) {
                return F.Zeta(arg1);
            } else {
                return F.CComplexInfinity;
            }
        }
    } else if (arg2.isMinusOne()) {
        // (2^(1-arg1)-1)*Zeta(arg1)
        return Times(Plus(CN1, Power(C2, Plus(C1, Negate(arg1)))), Zeta(arg1));
    }
    if (arg1.isSignedNumber()) {
        if (arg1.isZero()) {
            // arg2/(1 - arg2)
            return Times(arg2, Power(Plus(C1, Negate(arg2)), -1));
        } else if (arg1.isOne()) {
            // -Log(1 - arg2))
            return Negate(Log(Plus(C1, Negate(arg2))));
        } else if (arg1.isMinusOne()) {
            // arg2/(arg2 - 1)^2
            return Times(arg2, Power(Plus(C1, Negate(arg2)), -2));
        } else if (arg1.equals(F.CN2)) {
            // -((arg2*(1 + arg2))/(arg2 - 1)^3)
            return Times(CN1, arg2, Plus(C1, arg2), Power(Plus(CN1, arg2), -3));
        } else if (arg1.equals(F.CN3)) {
            // (arg2*(1 + 4*arg2 + arg2^2))/(arg2 - 1)^4
            return Times(arg2, Plus(C1, Times(C4, arg2), Sqr(arg2)), Power(Plus(C1, Negate(arg2)), -4));
        }
    }
    return F.NIL;
}
Also used : ISignedNumber(org.matheclipse.core.interfaces.ISignedNumber) IExpr(org.matheclipse.core.interfaces.IExpr)

Example 35 with ISignedNumber

use of org.matheclipse.core.interfaces.ISignedNumber in project symja_android_library by axkr.

the class Round method evaluate.

@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
    Validate.checkSize(ast, 2);
    try {
        IExpr arg1 = F.eval(ast.arg1());
        ISignedNumber signedNumber = arg1.evalSignedNumber();
        if (signedNumber != null) {
            return signedNumber.round();
        }
        if (F.True.equals(AbstractAssumptions.assumeInteger(arg1))) {
            return arg1;
        }
        if (arg1.isPlus()) {
            IAST[] result = ((IAST) arg1).filter(new RoundPlusFunction());
            if (result[0].size() > 1) {
                if (result[1].size() > 1) {
                    result[0].append(F.Round(result[1]));
                }
                return result[0];
            }
        }
        IExpr negExpr = AbstractFunctionEvaluator.getNormalizedNegativeExpression(arg1);
        if (negExpr.isPresent()) {
            return Negate(Round(negExpr));
        }
    } catch (ArithmeticException ae) {
    // ISignedNumber#round() may throw ArithmeticException
    }
    return F.NIL;
}
Also used : ISignedNumber(org.matheclipse.core.interfaces.ISignedNumber) IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST)

Aggregations

ISignedNumber (org.matheclipse.core.interfaces.ISignedNumber)49 IExpr (org.matheclipse.core.interfaces.IExpr)31 IAST (org.matheclipse.core.interfaces.IAST)22 ISymbol (org.matheclipse.core.interfaces.ISymbol)10 WrongArgumentType (org.matheclipse.core.eval.exception.WrongArgumentType)7 LinearConstraint (org.hipparchus.optim.linear.LinearConstraint)3 Num (org.matheclipse.core.expression.Num)3 IInteger (org.matheclipse.core.interfaces.IInteger)3 IntegerDistribution (org.hipparchus.distribution.IntegerDistribution)2 RealDistribution (org.hipparchus.distribution.RealDistribution)2 MathIllegalStateException (org.hipparchus.exception.MathIllegalStateException)2 LinearObjectiveFunction (org.hipparchus.optim.linear.LinearObjectiveFunction)2 WrappedException (org.matheclipse.core.eval.exception.WrappedException)2 Options (org.matheclipse.core.eval.util.Options)2 ComplexNum (org.matheclipse.core.expression.ComplexNum)2 IComplex (org.matheclipse.core.interfaces.IComplex)2 IComplexNum (org.matheclipse.core.interfaces.IComplexNum)2 INum (org.matheclipse.core.interfaces.INum)2 IRational (org.matheclipse.core.interfaces.IRational)2 ArrayList (java.util.ArrayList)1