use of edu.jas.arith.BigRational in project symja_android_library by axkr.
the class JASConvert method monomialToExpr.
public boolean monomialToExpr(Complex<BigRational> coeff, ExpVector exp, IAST monomTimes) {
BigRational re = coeff.getRe();
BigRational im = coeff.getIm();
monomTimes.append(F.complex(F.fraction(re.numerator(), re.denominator()), F.fraction(im.numerator(), im.denominator())));
return expVectorToExpr(exp, monomTimes);
}
use of edu.jas.arith.BigRational in project symja_android_library by axkr.
the class JASConvert method polyAlgebraicNumber2Expr.
public IAST polyAlgebraicNumber2Expr(final GenPolynomial<AlgebraicNumber<BigRational>> poly) throws ArithmeticException, ClassCastException {
if (poly.length() == 0) {
return F.Plus(F.C0);
}
SortedMap<ExpVector, AlgebraicNumber<BigRational>> val = poly.getMap();
if (val.size() == 0) {
return F.Plus(F.C0);
} else {
IAST result = F.Plus();
for (Map.Entry<ExpVector, AlgebraicNumber<BigRational>> m : val.entrySet()) {
AlgebraicNumber<BigRational> coeff = m.getValue();
IAST monomTimes = F.Times();
ExpVector exp = m.getKey();
monomialToExpr(coeff, exp, monomTimes);
result.append(monomTimes.getOneIdentity(F.C1));
}
return result;
}
}
use of edu.jas.arith.BigRational in project symja_android_library by axkr.
the class JASConvert method fraction2Poly.
private GenPolynomial<C> fraction2Poly(final IFraction exprPoly) {
// .toJavaBigInteger();
BigInteger n = exprPoly.toBigNumerator();
// .toJavaBigInteger();
BigInteger d = exprPoly.toBigDenominator();
BigRational nr = new BigRational(n);
BigRational dr = new BigRational(d);
BigRational r = nr.divide(dr);
if (fRingFactory instanceof ComplexRing) {
ComplexRing ring = (ComplexRing) fRingFactory;
Complex<BigRational> c = new Complex<BigRational>(ring, r);
return new GenPolynomial(fPolyFactory, c);
} else {
return new GenPolynomial(fPolyFactory, r);
}
}
use of edu.jas.arith.BigRational in project symja_android_library by axkr.
the class JASConvert method quotIntegral2Expr.
/**
* Convert a jas <code>Integral</code> into a matheclipse expression
*
* @param integral
* the JAS Integral
* @return
*/
public IAST quotIntegral2Expr(QuotIntegral<BigRational> integral) {
IAST sum = F.Plus();
List<Quotient<BigRational>> rational = integral.rational;
List<LogIntegral<BigRational>> logarithm = integral.logarithm;
if (rational.size() != 0) {
Quotient<BigRational> qTemp;
GenPolynomial<BigRational> qNum;
GenPolynomial<BigRational> qDen;
for (int i = 0; i < rational.size(); i++) {
qTemp = rational.get(i);
qNum = qTemp.num;
qDen = qTemp.den;
sum.append(F.Times(rationalPoly2Expr(qNum), F.Power(rationalPoly2Expr(qDen), F.CN1)));
}
}
if (logarithm.size() != 0) {
for (LogIntegral<BigRational> pf : logarithm) {
sum.append(logIntegral2Expr(pf));
}
}
return sum;
}
use of edu.jas.arith.BigRational in project symja_android_library by axkr.
the class GroebnerBasis method solveGroebnerBasis.
/**
* Used in <code>Solve()</code> function to reduce the polynomial list of
* equations.
*
* @param listOfPolynomials
* a list of polynomials
* @param listOfVariables
* a list of variable symbols
* @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
*/
public static IAST solveGroebnerBasis(IAST listOfPolynomials, IAST listOfVariables) {
List<ISymbol> varList = new ArrayList<ISymbol>(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));
}
IAST rest = F.List();
List<GenPolynomial<BigRational>> polyList = new ArrayList<GenPolynomial<BigRational>>(listOfPolynomials.size() - 1);
TermOrder termOrder = TermOrderByName.IGRLEX;
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) {
rest.append(expr);
}
}
if (polyList.size() == 0) {
return F.NIL;
}
GroebnerBaseAbstract<BigRational> engine = GBAlgorithmBuilder.<BigRational>polynomialRing(jas.getPolynomialRingFactory()).fractionFree().syzygyPairlist().build();
List<GenPolynomial<BigRational>> opl = engine.GB(polyList);
IAST resultList = F.List();
// polynomial to result list
for (GenPolynomial<BigRational> p : opl) {
resultList.append(jas.integerPoly2Expr((GenPolynomial<BigInteger>) jas.factorTerms(p)[2]));
}
for (int i = 1; i < rest.size(); i++) {
resultList.append(rest.get(i));
}
return resultList;
}
Aggregations