use of org.matheclipse.core.polynomials.ExprPolynomialRing in project symja_android_library by axkr.
the class Limit method timesLimit.
private static IExpr timesLimit(final IAST timesAST, LimitData data) {
IAST isFreeResult = timesAST.partitionTimes(Predicates.isFree(data.getSymbol()), F.C1, F.C1, F.List);
if (!isFreeResult.get(1).isOne()) {
return F.Times(isFreeResult.get(1), data.limit(isFreeResult.get(2)));
}
IExpr[] parts = Algebra.fractionalPartsTimesPower(timesAST, false, false, true, true);
if (parts != null) {
IExpr numerator = parts[0];
IExpr denominator = parts[1];
IExpr limit = data.getLimitValue();
ISymbol symbol = data.getSymbol();
if (limit.isInfinity() || limit.isNegativeInfinity()) {
try {
ExprPolynomialRing ring = new ExprPolynomialRing(symbol);
ExprPolynomial denominatorPoly = ring.create(denominator);
ExprPolynomial numeratorPoly = ring.create(numerator);
return limitsInfinityOfRationalFunctions(numeratorPoly, denominatorPoly, symbol, limit, data);
} catch (RuntimeException e) {
if (Config.DEBUG) {
e.printStackTrace();
}
}
}
IExpr plusResult = Algebra.partialFractionDecompositionRational(new PartialFractionGenerator(), parts, symbol);
if (plusResult.isPlus()) {
// if (plusResult.size() > 2) {
return data.mapLimit((IAST) plusResult);
// }
}
if (denominator.isOne()) {
if (limit.isInfinity() || limit.isNegativeInfinity()) {
IExpr temp = substituteInfinity(timesAST, data);
if (temp.isPresent()) {
return temp;
}
}
}
IExpr temp = numeratorDenominatorLimit(numerator, denominator, data);
if (temp.isPresent()) {
return temp;
}
}
return data.mapLimit(timesAST);
}
use of org.matheclipse.core.polynomials.ExprPolynomialRing in project symja_android_library by axkr.
the class CoefficientList method univariateCoefficientList.
/**
*
* @param polynomial
* @param variable
* @param resultList
* the coefficient list of the given univariate polynomial in increasing order
* @param resultListDiff
* the coefficient list of the derivative of the given univariate polynomial
* @return the degree of the univariate polynomial; if <code>degree >= Short.MAX_VALUE</code>, the result list will be empty.
*/
public static long univariateCoefficientList(IExpr polynomial, ISymbol variable, List<IExpr> resultList, List<IExpr> resultListDiff) throws JASConversionException {
try {
ExprPolynomialRing ring = new ExprPolynomialRing(F.List(variable));
ExprPolynomial poly = ring.create(polynomial);
// PolynomialOld poly = new PolynomialOld(polynomial, (ISymbol) variable);
// if (!poly.isPolynomial()) {
// throw new WrongArgumentType(polynomial, "Polynomial expected!");
// }
IAST polyExpr = poly.coefficientList();
int degree = polyExpr.size() - 2;
if (degree >= Short.MAX_VALUE) {
return degree;
}
for (int i = 0; i <= degree; i++) {
IExpr temp = polyExpr.get(i + 1);
resultList.add(temp);
}
IAST polyDiff = poly.derivative().coefficientList();
int degreeDiff = polyDiff.size() - 2;
for (int i = 0; i <= degreeDiff; i++) {
IExpr temp = polyDiff.get(i + 1);
resultListDiff.add(temp);
}
return degree;
} catch (RuntimeException ex) {
throw new WrongArgumentType(polynomial, "Polynomial expected!");
}
}
use of org.matheclipse.core.polynomials.ExprPolynomialRing in project symja_android_library by axkr.
the class PolynomialExample method main.
public static void main(String[] args) {
try {
ExprEvaluator util = new ExprEvaluator();
IExpr expr = util.evaluate("x^2+y+a*x+b*y+c");
System.out.println(expr.toString());
final IAST variables = F.List(F.x, F.y);
ExprPolynomialRing ring = new ExprPolynomialRing(ExprRingFactory.CONST, variables, variables.size() - 1, ExprTermOrderByName.Lexicographic, false);
ExprPolynomial poly = ring.create(expr);
System.out.println(poly.toString());
// x degree
System.out.println(poly.degree(0));
// y degree
System.out.println(poly.degree(1));
// show internal structure:
System.out.println(poly.coefficientRules());
System.out.println();
for (ExprMonomial monomial : poly) {
System.out.println(monomial.toString());
}
} catch (SyntaxError e) {
// catch Symja parser errors here
System.out.println(e.getMessage());
} catch (MathException me) {
// catch Symja math errors here
System.out.println(me.getMessage());
} catch (Exception e) {
e.printStackTrace();
} catch (final StackOverflowError soe) {
System.out.println(soe.getMessage());
} catch (final OutOfMemoryError oome) {
System.out.println(oome.getMessage());
}
}
use of org.matheclipse.core.polynomials.ExprPolynomialRing in project symja_android_library by axkr.
the class AbstractAST method isPolynomialOfMaxDegree.
public final boolean isPolynomialOfMaxDegree(IAST variables, long maxDegree) {
try {
if (isPlus() || isTimes() || isPower()) {
IExpr expr = F.evalExpandAll(this);
ExprPolynomialRing ring = new ExprPolynomialRing(variables);
ExprPolynomial poly = ring.create(expr);
return poly.degree() <= maxDegree;
}
} catch (RuntimeException ex) {
//
}
return false;
}
use of org.matheclipse.core.polynomials.ExprPolynomialRing in project symja_android_library by axkr.
the class AbstractAST method isPolynomial.
/** {@inheritDoc} */
@Override
public final boolean isPolynomial(IAST variables) {
if (isPlus() || isTimes() || isPower()) {
IExpr expr = F.evalExpandAll(this);
ExprPolynomialRing ring = new ExprPolynomialRing(variables);
return ring.isPolynomial(expr);
}
return false;
}
Aggregations