Search in sources :

Example 46 with IInteger

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

the class Series method createSeriesData.

/**
	 * 
	 * @param function
	 *            the function which should be generated as a power series
	 * @param x
	 *            the variable
	 * @param x0
	 *            the point to do the power expansion for
	 * @param n
	 *            the order of the expansion
	 * @param step
	 * @return
	 */
private IExpr createSeriesData(final IExpr function, IExpr x, IExpr x0, final int n, IExpr step) {
    IInteger nExpr = F.integer(n);
    IAST result = F.List();
    IAST seriesData = F.SeriesData(x, x0, result, x0, F.Plus(nExpr, step), step);
    IExpr derivedFunction = function;
    for (int i = 0; i <= n; i++) {
        result.append(F.Times(F.Power(F.Factorial(F.integer(i)), F.CN1), F.ReplaceAll(derivedFunction, F.Rule(x, x0))));
        derivedFunction = F.D(derivedFunction, x);
    }
    return seriesData;
}
Also used : IInteger(org.matheclipse.core.interfaces.IInteger) IAST(org.matheclipse.core.interfaces.IAST) IExpr(org.matheclipse.core.interfaces.IExpr)

Example 47 with IInteger

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

the class RandomInteger method evaluate.

@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
    Validate.checkSize(ast, 2);
    if (ast.arg1().isInteger()) {
        // RandomInteger[100] gives an integer between 0 and 100
        BigInteger n = ((IInteger) ast.arg1()).toBigNumerator();
        BigInteger r;
        do {
            r = new BigInteger(n.bitLength(), RANDOM);
        } while (r.compareTo(n) >= 0);
        return F.integer(r);
    }
    return F.NIL;
}
Also used : IInteger(org.matheclipse.core.interfaces.IInteger) BigInteger(java.math.BigInteger)

Example 48 with IInteger

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

the class AbstractArgMultiple method binaryOperator.

@Override
public IExpr binaryOperator(final IExpr o0, final IExpr o1) {
    IExpr result = F.NIL;
    if (o0 instanceof INum) {
        // use specialized methods for numeric mode
        if (o1 instanceof INum) {
            result = e2DblArg((INum) o0, (INum) o1);
        } else if (o1.isInteger()) {
            result = e2DblArg((INum) o0, F.num((IInteger) o1));
        } else if (o1.isFraction()) {
            result = e2DblArg((INum) o0, F.num((IFraction) o1));
        } else if (o1 instanceof IComplexNum) {
            if (o0 instanceof ApfloatNum) {
                result = e2DblComArg(F.complexNum(((ApfloatNum) o0).apfloatValue()), (IComplexNum) o1);
            } else {
                result = e2DblComArg(F.complexNum(((INum) o0).getRealPart()), (IComplexNum) o1);
            }
        }
        if (result.isPresent()) {
            return result;
        }
        return e2ObjArg(o0, o1);
    } else if (o1 instanceof INum) {
        // use specialized methods for numeric mode
        if (o0.isInteger()) {
            result = e2DblArg(F.num((IInteger) o0), (INum) o1);
        } else if (o0.isFraction()) {
            result = e2DblArg(F.num((IFraction) o0), (INum) o1);
        } else if (o0 instanceof IComplexNum) {
            if (o1 instanceof ApfloatNum) {
                result = e2DblComArg((IComplexNum) o0, F.complexNum(((ApfloatNum) o1).apfloatValue()));
            } else {
                result = e2DblComArg((IComplexNum) o0, F.complexNum(((INum) o1).getRealPart()));
            }
        }
        if (result.isPresent()) {
            return result;
        }
        return e2ObjArg(o0, o1);
    }
    if (o0 instanceof IComplexNum) {
        // use specialized methods for complex numeric mode
        if (o1 instanceof INum) {
            result = e2DblComArg((IComplexNum) o0, F.complexNum(((INum) o1).getRealPart()));
        } else if (o1.isInteger()) {
            result = e2DblComArg((IComplexNum) o0, F.complexNum((IInteger) o1));
        } else if (o1.isFraction()) {
            result = e2DblComArg((IComplexNum) o0, F.complexNum((IFraction) o1));
        } else if (o1 instanceof IComplexNum) {
            result = e2DblComArg((IComplexNum) o0, (IComplexNum) o1);
        }
        if (result.isPresent()) {
            return result;
        }
        return e2ObjArg(o0, o1);
    } else if (o1 instanceof IComplexNum) {
        // use specialized methods for complex numeric mode
        if (o0 instanceof INum) {
            result = e2DblComArg(F.complexNum(((INum) o0).getRealPart()), (IComplexNum) o1);
        } else if (o0.isInteger()) {
            result = e2DblComArg(F.complexNum((IInteger) o0), (IComplexNum) o1);
        } else if (o0.isFraction()) {
            result = e2DblComArg(F.complexNum((IFraction) o0), (IComplexNum) o1);
        }
        if (result.isPresent()) {
            return result;
        }
        return e2ObjArg(o0, o1);
    }
    if (o0 instanceof IInteger) {
        if (o1 instanceof IInteger) {
            return e2IntArg((IInteger) o0, (IInteger) o1);
        }
        if (o1 instanceof IFraction) {
            return e2FraArg(F.fraction((IInteger) o0, F.C1), (IFraction) o1);
        }
        if (o1 instanceof IComplex) {
            return e2ComArg(F.complex((IInteger) o0, F.C0), (IComplex) o1);
        }
    } else if (o0 instanceof IFraction) {
        if (o1 instanceof IInteger) {
            return e2FraArg((IFraction) o0, F.fraction((IInteger) o1, F.C1));
        }
        if (o1 instanceof IFraction) {
            return e2FraArg((IFraction) o0, (IFraction) o1);
        }
        if (o1 instanceof IComplex) {
            return e2ComArg(F.complex((IFraction) o0), (IComplex) o1);
        }
    } else if (o0 instanceof IComplex) {
        if (o1 instanceof IInteger) {
            return eComIntArg((IComplex) o0, (IInteger) o1);
        }
        if (o1 instanceof IComplex) {
            return e2ComArg((IComplex) o0, (IComplex) o1);
        }
    }
    result = e2ObjArg(o0, o1);
    if (result.isPresent()) {
        return result;
    }
    if (o0 instanceof ISymbol) {
        if (o1 instanceof ISymbol) {
            return e2SymArg((ISymbol) o0, (ISymbol) o1);
        }
    }
    if (o0 instanceof IAST) {
        IAST a0 = (IAST) o0;
        if (o1 instanceof IInteger) {
            return eFunIntArg(a0, (IInteger) o1);
        }
        if (o1 instanceof IAST) {
            return e2FunArg(a0, (IAST) o1);
        }
    }
    return F.NIL;
}
Also used : IFraction(org.matheclipse.core.interfaces.IFraction) IComplex(org.matheclipse.core.interfaces.IComplex) ISymbol(org.matheclipse.core.interfaces.ISymbol) IInteger(org.matheclipse.core.interfaces.IInteger) IComplexNum(org.matheclipse.core.interfaces.IComplexNum) IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST) ApfloatNum(org.matheclipse.core.expression.ApfloatNum) INum(org.matheclipse.core.interfaces.INum)

Example 49 with IInteger

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

the class Validate method checkListOfLongs.

/**
	 * Check the argument, if it's an {@code IAST} of {@code long} values in the range [{@code startValue},
	 * Long.MAX_VALUE]
	 * 
	 * @throws WrongArgumentType
	 */
public static long[] checkListOfLongs(IExpr arg, long startValue) {
    if (arg.isList()) {
        IAST list = (IAST) arg;
        long[] result = new long[list.size() - 1];
        long longValue = 0;
        try {
            IExpr expr;
            for (int i = 1; i < list.size(); i++) {
                expr = list.get(i);
                // the following may throw an ArithmeticException
                if (expr instanceof IInteger) {
                    longValue = ((IInteger) expr).toLong();
                } else if (expr instanceof INum) {
                    longValue = ((INum) expr).toLong();
                }
                if (startValue > longValue) {
                    throw new WrongArgumentType(expr, "Trying to convert the expression into the integer range: " + startValue + " - " + Long.MAX_VALUE);
                }
                result[i - 1] = longValue;
            }
            return result;
        } catch (ArithmeticException ae) {
        //
        }
    }
    throw new WrongArgumentType(arg, "Trying to convert the given list into a list of long numbers: " + arg);
}
Also used : IInteger(org.matheclipse.core.interfaces.IInteger) IAST(org.matheclipse.core.interfaces.IAST) IExpr(org.matheclipse.core.interfaces.IExpr) INum(org.matheclipse.core.interfaces.INum)

Example 50 with IInteger

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

the class AbstractArg2 method binaryOperator.

public IExpr binaryOperator(final IExpr o0, final IExpr o1) {
    IExpr result = F.NIL;
    if (o0.isNumber() && o1.isNumber()) {
        result = e2NumericArg(o0, o1);
        if (result.isPresent()) {
            return result;
        }
    }
    result = e2ObjArg(o0, o1);
    if (result.isPresent()) {
        return result;
    }
    if (o0 instanceof IInteger) {
        if (o1 instanceof IInteger) {
            return e2IntArg((IInteger) o0, (IInteger) o1);
        }
        if (o1 instanceof IFraction) {
            return e2FraArg(F.fraction((IInteger) o0, F.C1), (IFraction) o1);
        }
        if (o1 instanceof IComplex) {
            return e2ComArg(F.complex((IInteger) o0, F.C0), (IComplex) o1);
        }
        return F.NIL;
    }
    if (o0 instanceof IFraction) {
        if (o1 instanceof IInteger) {
            return e2FraArg((IFraction) o0, F.fraction((IInteger) o1, F.C1));
        }
        if (o1 instanceof IFraction) {
            return e2FraArg((IFraction) o0, (IFraction) o1);
        }
        if (o1 instanceof IComplex) {
            return e2ComArg(F.complex((IFraction) o0), (IComplex) o1);
        }
        return F.NIL;
    }
    if (o0 instanceof IComplex) {
        if (o1 instanceof IInteger) {
            return eComIntArg((IComplex) o0, (IInteger) o1);
        }
        if (o1 instanceof IFraction) {
            return eComFraArg((IComplex) o0, (IFraction) o1);
        }
        if (o1 instanceof IComplex) {
            return e2ComArg((IComplex) o0, (IComplex) o1);
        }
    }
    if (o0 instanceof ISymbol) {
        if (o1 instanceof ISymbol) {
            return e2SymArg((ISymbol) o0, (ISymbol) o1);
        }
    }
    if (o0 instanceof IAST) {
        if (o1 instanceof IInteger) {
            return eFunIntArg((IAST) o0, (IInteger) o1);
        }
        if (o1 instanceof IAST) {
            return e2FunArg((IAST) o0, (IAST) o1);
        }
    }
    return F.NIL;
}
Also used : IFraction(org.matheclipse.core.interfaces.IFraction) IComplex(org.matheclipse.core.interfaces.IComplex) ISymbol(org.matheclipse.core.interfaces.ISymbol) IInteger(org.matheclipse.core.interfaces.IInteger) IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST)

Aggregations

IInteger (org.matheclipse.core.interfaces.IInteger)59 IAST (org.matheclipse.core.interfaces.IAST)34 IExpr (org.matheclipse.core.interfaces.IExpr)29 ISymbol (org.matheclipse.core.interfaces.ISymbol)18 IFraction (org.matheclipse.core.interfaces.IFraction)16 BigInteger (java.math.BigInteger)11 INum (org.matheclipse.core.interfaces.INum)10 IComplex (org.matheclipse.core.interfaces.IComplex)7 IComplexNum (org.matheclipse.core.interfaces.IComplexNum)7 WrongArgumentType (org.matheclipse.core.eval.exception.WrongArgumentType)6 ExpVector (edu.jas.poly.ExpVector)5 INumber (org.matheclipse.core.interfaces.INumber)4 ModLong (edu.jas.arith.ModLong)3 GenPolynomial (edu.jas.poly.GenPolynomial)3 Num (org.matheclipse.core.expression.Num)3 IRational (org.matheclipse.core.interfaces.IRational)3 ISignedNumber (org.matheclipse.core.interfaces.ISignedNumber)3 TreeSet (java.util.TreeSet)2 BigFraction (org.hipparchus.fraction.BigFraction)2 KSubsetsList (org.matheclipse.core.builtin.Combinatoric.Subsets.KSubsetsList)2