Search in sources :

Example 36 with IAST

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

the class MonomialList method monomialListModulus.

/**
	 * Get the monomial list of a univariate polynomial with coefficients
	 * reduced by a modulo value.
	 * 
	 * @param polynomial
	 * @param variable
	 * @param termOrder
	 *            the JAS term ordering
	 * @param option
	 *            the "Modulus" option
	 * @return the list of monomials of the univariate polynomial.
	 */
private static IAST monomialListModulus(IExpr polynomial, List<IExpr> variablesList, final TermOrder termOrder, IExpr option) throws JASConversionException {
    try {
        // found "Modulus" option => use ModIntegerRing
        ModLongRing modIntegerRing = JASModInteger.option2ModLongRing((ISignedNumber) option);
        JASModInteger jas = new JASModInteger(variablesList, modIntegerRing);
        GenPolynomial<ModLong> polyExpr = jas.expr2JAS(polynomial);
        IAST list = F.List();
        for (Monomial<ModLong> monomial : polyExpr) {
            ModLong coeff = monomial.coefficient();
            ExpVector exp = monomial.exponent();
            IAST monomTimes = F.Times();
            jas.monomialToExpr(F.integer(coeff.getVal()), exp, monomTimes);
            list.append(monomTimes);
        }
        return list;
    } catch (ArithmeticException ae) {
        // toInt() conversion failed
        if (Config.DEBUG) {
            ae.printStackTrace();
        }
    }
    return F.NIL;
}
Also used : ModLong(edu.jas.arith.ModLong) ExpVector(edu.jas.poly.ExpVector) IAST(org.matheclipse.core.interfaces.IAST) ModLongRing(edu.jas.arith.ModLongRing) JASModInteger(org.matheclipse.core.convert.JASModInteger)

Example 37 with IAST

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

the class FromPolarCoordinates method evaluate.

@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
    Validate.checkSize(ast, 2);
    int dim = ast.arg1().isVector();
    if (dim > 0) {
        IAST list = (IAST) ast.arg1();
        if (dim == 2) {
            IExpr r = list.arg1();
            IExpr theta = list.arg2();
            return F.List(F.Times(r, F.Cos(theta)), F.Times(r, F.Sin(theta)));
        } else if (dim == 3) {
            IExpr r = list.arg1();
            IExpr theta = list.arg2();
            IExpr phi = list.arg3();
            return F.List(F.Times(r, F.Cos(theta)), F.Times(r, F.Cos(phi), F.Sin(theta)), F.Times(r, F.Sin(theta), F.Sin(phi)));
        }
    } else if (ast.arg1().isList()) {
        return ((IAST) ast.arg1()).mapThread(F.List(), ast, 1);
    }
    return F.NIL;
}
Also used : IAST(org.matheclipse.core.interfaces.IAST) IExpr(org.matheclipse.core.interfaces.IExpr)

Example 38 with IAST

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

the class GeometricMean method evaluate.

@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
    Validate.checkSize(ast, 2);
    IAST arg1 = Validate.checkASTType(ast, 1);
    if (arg1.isRealVector()) {
        return F.num(StatUtils.geometricMean(arg1.toDoubleVector()));
    }
    if (arg1.size() > 1) {
        return F.Power(arg1.setAtClone(0, F.Times), F.fraction(1, arg1.size() - 1));
    }
    return F.NIL;
}
Also used : IAST(org.matheclipse.core.interfaces.IAST)

Example 39 with IAST

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

the class GroebnerBasis method computeGroebnerBasis.

/**
	 * 
	 * @param listOfPolynomials
	 *            a list of polynomials
	 * @param listOfVariables
	 *            a list of variable symbols
	 * @param termOrder
	 *            the term order
	 * @return <code>F.NIL</code> if
	 *         <code>stopUnevaluatedOnPolynomialConversionError==true</code> and
	 *         one of the polynomials in <code>listOfPolynomials</code> are not
	 *         convertible to JAS polynomials
	 */
private static IAST computeGroebnerBasis(IAST listOfPolynomials, IAST listOfVariables, TermOrder termOrder) {
    List<ISymbol> varList = new ArrayList<ISymbol>(listOfVariables.size() - 1);
    String[] pvars = new String[listOfVariables.size() - 1];
    for (int i = 1; i < listOfVariables.size(); i++) {
        if (!listOfVariables.get(i).isSymbol()) {
            return F.NIL;
        }
        varList.add((ISymbol) listOfVariables.get(i));
        pvars[i - 1] = ((ISymbol) listOfVariables.get(i)).toString();
    }
    List<GenPolynomial<BigRational>> polyList = new ArrayList<GenPolynomial<BigRational>>(listOfPolynomials.size() - 1);
    JASConvert<BigRational> jas = new JASConvert<BigRational>(varList, BigRational.ZERO, termOrder);
    for (int i = 1; i < listOfPolynomials.size(); i++) {
        IExpr expr = F.evalExpandAll(listOfPolynomials.get(i));
        try {
            GenPolynomial<BigRational> poly = jas.expr2JAS(expr, false);
            polyList.add(poly);
        } catch (JASConversionException e) {
            return F.NIL;
        }
    }
    if (polyList.size() == 0) {
        return F.NIL;
    }
    GroebnerBasePartial<BigRational> gbp = new GroebnerBasePartial<BigRational>();
    OptimizedPolynomialList<BigRational> opl = gbp.partialGB(polyList, pvars);
    List<GenPolynomial<BigRational>> list = OrderedPolynomialList.sort(opl.list);
    IAST resultList = F.List();
    for (GenPolynomial<BigRational> p : list) {
        // convert rational to integer coefficients and add
        // polynomial to result list
        resultList.append(jas.integerPoly2Expr((GenPolynomial<BigInteger>) jas.factorTerms(p)[2]));
    }
    return resultList;
}
Also used : GenPolynomial(edu.jas.poly.GenPolynomial) ISymbol(org.matheclipse.core.interfaces.ISymbol) BigRational(edu.jas.arith.BigRational) ArrayList(java.util.ArrayList) JASConversionException(org.matheclipse.core.eval.exception.JASConversionException) GroebnerBasePartial(edu.jas.gbufd.GroebnerBasePartial) JASConvert(org.matheclipse.core.convert.JASConvert) IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST)

Example 40 with IAST

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

the class Interval method evaluate.

@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
    Validate.checkRange(ast, 2);
    if (ast.isInterval1()) {
        IAST list = (IAST) ast.arg1();
        try {
            ISignedNumber min = (ISignedNumber) list.arg1();
            ISignedNumber max = (ISignedNumber) list.arg2();
            if (min.greaterThan(max).isTrue()) {
                throw new WrongArgumentType(ast, ast.get(1), 1, "Min > Mac in interval");
            }
        } catch (ClassCastException cca) {
        // do nothing
        }
    }
    return F.NIL;
}
Also used : ISignedNumber(org.matheclipse.core.interfaces.ISignedNumber) WrongArgumentType(org.matheclipse.core.eval.exception.WrongArgumentType) IAST(org.matheclipse.core.interfaces.IAST)

Aggregations

IAST (org.matheclipse.core.interfaces.IAST)413 IExpr (org.matheclipse.core.interfaces.IExpr)248 ISymbol (org.matheclipse.core.interfaces.ISymbol)76 IInteger (org.matheclipse.core.interfaces.IInteger)34 WrongArgumentType (org.matheclipse.core.eval.exception.WrongArgumentType)30 ISignedNumber (org.matheclipse.core.interfaces.ISignedNumber)22 ExpVector (edu.jas.poly.ExpVector)15 ArrayList (java.util.ArrayList)14 BigRational (edu.jas.arith.BigRational)13 JASIExpr (org.matheclipse.core.convert.JASIExpr)13 VariablesSet (org.matheclipse.core.convert.VariablesSet)13 INum (org.matheclipse.core.interfaces.INum)13 ExprPolynomial (org.matheclipse.core.polynomials.ExprPolynomial)12 GenPolynomial (edu.jas.poly.GenPolynomial)11 JASConversionException (org.matheclipse.core.eval.exception.JASConversionException)11 IFraction (org.matheclipse.core.interfaces.IFraction)11 INumber (org.matheclipse.core.interfaces.INumber)11 IComplex (org.matheclipse.core.interfaces.IComplex)10 ModLong (edu.jas.arith.ModLong)9 ExprPolynomialRing (org.matheclipse.core.polynomials.ExprPolynomialRing)9