Search in sources :

Example 16 with ISymbol

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

the class Horner method evaluate.

@Override
@Deprecated
public IExpr evaluate(final IAST ast, EvalEngine engine) {
    Validate.checkSize(ast, 2);
    if (ast.arg1().isAST()) {
        IAST poly = (IAST) ast.arg1();
        VariablesSet eVar = new VariablesSet(ast.arg1());
        IAST variables = eVar.getVarList();
        if (variables.size() >= 2) {
            ISymbol sym = (ISymbol) variables.arg1();
            if (poly.isASTSizeGE(F.Plus, 2)) {
                HornerScheme scheme = new HornerScheme();
                return scheme.generate(engine.isNumericMode(), poly, sym);
            }
        }
    }
    return ast.arg1();
}
Also used : ISymbol(org.matheclipse.core.interfaces.ISymbol) HornerScheme(org.matheclipse.core.polynomials.HornerScheme) IAST(org.matheclipse.core.interfaces.IAST) VariablesSet(org.matheclipse.core.convert.VariablesSet)

Example 17 with ISymbol

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

the class HornerForm method evaluate.

@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
    Validate.checkRange(ast, 2, 3);
    IExpr arg1 = ast.arg1();
    if (arg1.isAST()) {
        IAST poly = (IAST) arg1;
        VariablesSet eVar;
        IAST variables;
        if (ast.isAST2()) {
            variables = Validate.checkSymbolOrSymbolList(ast, 2);
        } else {
            eVar = new VariablesSet(ast.arg1());
            variables = eVar.getVarList();
        }
        if (variables.size() >= 2) {
            ISymbol sym = (ISymbol) variables.arg1();
            if (poly.isASTSizeGE(F.Plus, 2)) {
                HornerScheme scheme = new HornerScheme();
                return scheme.generate(engine.isNumericMode(), poly, sym);
            }
        }
    }
    return arg1;
}
Also used : ISymbol(org.matheclipse.core.interfaces.ISymbol) HornerScheme(org.matheclipse.core.polynomials.HornerScheme) IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST) VariablesSet(org.matheclipse.core.convert.VariablesSet)

Example 18 with ISymbol

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

the class Limit method numeratorDenominatorLimit.

// private static IExpr mapLimit(final IAST ast, LimitData data) {
// return ast.mapThread(data.limit(null), 1);
// }
/**
	 * Try l'Hospitales rule for numerator and denominator expression.
	 * 
	 * @param numerator
	 * @param denominator
	 * @param data
	 *            the limit data definition
	 * @return <code>F.NIL</code> if no limit found
	 */
private static IExpr numeratorDenominatorLimit(final IExpr numerator, final IExpr denominator, LimitData data) {
    IExpr numValue;
    IExpr denValue;
    IExpr limit = data.getLimitValue();
    IAST rule = data.getRule();
    if (denominator.isOne() && numerator.isTimes()) {
        // Limit[a,sym->lim]*Limit[b,sym->lim]*Limit[c,sym->lim]
        return data.mapLimit((IAST) numerator);
    }
    if (!denominator.isNumber() || denominator.isZero()) {
        ISymbol x = data.getSymbol();
        denValue = F.evalBlock(denominator, x, limit);
        if (denValue.equals(F.Indeterminate)) {
            return F.NIL;
        } else if (denValue.isZero()) {
            numValue = F.evalBlock(numerator, x, limit);
            if (numValue.isZero()) {
                return lHospitalesRule(numerator, denominator, data);
            }
            return F.NIL;
        } else if (F.CInfinity.equals(denValue)) {
            numValue = F.evalBlock(numerator, x, limit);
            if (F.CInfinity.equals(numValue)) {
                return lHospitalesRule(numerator, denominator, data);
            }
            return F.NIL;
        } else if (denValue.isNegativeInfinity()) {
            numValue = F.evalBlock(numerator, x, limit);
            if (numValue.isNegativeInfinity()) {
                return lHospitalesRule(numerator, denominator, data);
            }
            return F.NIL;
        }
    }
    return F.Times(data.limit(numerator), F.Power(data.limit(denominator), F.CN1));
}
Also used : ISymbol(org.matheclipse.core.interfaces.ISymbol) IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST)

Example 19 with ISymbol

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

the class Limit method evaluate.

@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
    Validate.checkRange(ast, 3, 4);
    if (!ast.arg2().isRuleAST()) {
        throw new WrongArgumentType(ast, ast.arg2(), 2, "Limit: rule definition expected!");
    }
    IAST rule = (IAST) ast.arg2();
    if (!(rule.arg1().isSymbol())) {
        throw new WrongArgumentType(ast, ast.arg1(), 2, "Limit: variable symbol for rule definition expected!");
    }
    // no direction as default
    int direction = DIRECTION_AUTOMATIC;
    if (ast.isAST3()) {
        final Options options = new Options(ast.topHead(), ast, 2, engine);
        IExpr option = options.getOption("Direction");
        if (option.isPresent()) {
            if (option.isOne()) {
                direction = DIRECTION_FROM_SMALLER_VALUES;
            } else if (option.isMinusOne()) {
                direction = DIRECTION_FROM_LARGER_VALUES;
            } else if (option.equals(F.Automatic)) {
                direction = DIRECTION_AUTOMATIC;
            } else {
                throw new WrongArgumentType(ast, ast.arg2(), 2, "Limit: direction option expected!");
            }
        } else {
            throw new WrongArgumentType(ast, ast.arg2(), 2, "Limit: direction option expected!");
        }
    }
    ISymbol symbol = (ISymbol) rule.arg1();
    IExpr limit = null;
    if (rule.isFreeAt(2, symbol)) {
        limit = rule.arg2();
    } else {
        throw new WrongArgumentType(ast, ast.arg2(), 2, "Limit: limit value contains variable symbol for rule definition!");
    }
    if (ast.isAST2() && direction == DIRECTION_AUTOMATIC) {
        // check if there's a direction specific rule available in the rule database
        IExpr temp = engine.evalLoop(F.Limit(ast.arg1(), ast.arg2(), F.Rule(F.Direction, F.CN1)));
        if (temp.isPresent()) {
            return temp;
        }
    }
    LimitData data = new LimitData(symbol, limit, rule, direction);
    return evalLimit(ast.arg1(), data, true);
}
Also used : Options(org.matheclipse.core.eval.util.Options) ISymbol(org.matheclipse.core.interfaces.ISymbol) WrongArgumentType(org.matheclipse.core.eval.exception.WrongArgumentType) IAST(org.matheclipse.core.interfaces.IAST) IExpr(org.matheclipse.core.interfaces.IExpr)

Example 20 with ISymbol

use of org.matheclipse.core.interfaces.ISymbol 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)

Aggregations

ISymbol (org.matheclipse.core.interfaces.ISymbol)117 IExpr (org.matheclipse.core.interfaces.IExpr)79 IAST (org.matheclipse.core.interfaces.IAST)76 IInteger (org.matheclipse.core.interfaces.IInteger)18 WrongArgumentType (org.matheclipse.core.eval.exception.WrongArgumentType)12 INum (org.matheclipse.core.interfaces.INum)10 ISignedNumber (org.matheclipse.core.interfaces.ISignedNumber)10 IFraction (org.matheclipse.core.interfaces.IFraction)9 IBuiltInSymbol (org.matheclipse.core.interfaces.IBuiltInSymbol)8 IComplex (org.matheclipse.core.interfaces.IComplex)7 IComplexNum (org.matheclipse.core.interfaces.IComplexNum)7 ArrayList (java.util.ArrayList)6 IPatternObject (org.matheclipse.core.interfaces.IPatternObject)6 HashSet (java.util.HashSet)5 EvalEngine (org.matheclipse.core.eval.EvalEngine)5 Num (org.matheclipse.core.expression.Num)5 GenPolynomial (edu.jas.poly.GenPolynomial)4 Options (org.matheclipse.core.eval.util.Options)4 ExprPolynomialRing (org.matheclipse.core.polynomials.ExprPolynomialRing)4 ExpVector (edu.jas.poly.ExpVector)3