/** * Create a symbolic complex number * * @param re * @return */ public static IComplex complex(final IFraction re) { return complex(re, fraction(0, 1)); }
/** * Create a symbolic complex number * * @param re * @return */ public static IComplex CC(final IFraction re) { return complex(re, fraction(0L, 1L)); }
/** * Create a symbolic complex number * * @param re * @return */ public static IComplex complex(final IRational re) { return complex(re, fraction(0L, 1L)); }
@Override public IExpr visit(INum element) { return F.fraction(element.getRealPart(), epsilon); }
@Override public IExpr e2IntArg(final IInteger i0, final IInteger i1) { if (i0.equals(F.C0)) { // all other cases see e2ObjArg return null; } if (i1.isNegative()) { return F.fraction(F.C1, i0.pow(((IInteger) i1.negate()).getBigNumerator().intValue())); } return i0.pow(i1.getBigNumerator().intValue()); }
/** * * @return <code>F.NIL</code>, if no evaluation is possible */ @Override public IExpr visit(ISymbol element) { if (element.isNumericFunction()) { ISignedNumber signedNumber = element.evalReal(); if (signedNumber != null) { return F.fraction(signedNumber.doubleValue(), epsilon); } } return F.NIL; } }
@Override public IExpr visit(IASTMutable ast) { if (ast.isNumericFunction()) { ISignedNumber signedNumber = ast.evalReal(); if (signedNumber != null) { return F.fraction(signedNumber.doubleValue(), epsilon); } } return super.visitAST(ast); }
public boolean monomialToExpr(Complex<BigRational> coeff, ExpVector exp, IASTAppendable 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); }
public static IExpr factor(IExpr expr, List<IExpr> varList, boolean factorSquareFree) throws JASConversionException { JASConvert<BigRational> jas = new JASConvert<BigRational>(varList, BigRational.ZERO); GenPolynomial<BigRational> polyRat = jas.expr2JAS(expr); Object[] objects = jas.factorTerms(polyRat); java.math.BigInteger gcd = (java.math.BigInteger) objects[0]; java.math.BigInteger lcm = (java.math.BigInteger) objects[1]; GenPolynomial<edu.jas.arith.BigInteger> poly = (GenPolynomial<edu.jas.arith.BigInteger>) objects[2]; FactorAbstract<edu.jas.arith.BigInteger> factorAbstract = FactorFactory.getImplementation(edu.jas.arith.BigInteger.ONE); SortedMap<GenPolynomial<edu.jas.arith.BigInteger>, Long> map; if (factorSquareFree) { map = factorAbstract.squarefreeFactors(poly); } else { map = factorAbstract.factors(poly); } IAST result = F.Times(); if (!gcd.equals(java.math.BigInteger.ONE) || !lcm.equals(java.math.BigInteger.ONE)) { result.add(F.fraction(gcd, lcm)); } for (SortedMap.Entry<GenPolynomial<edu.jas.arith.BigInteger>, Long> entry : map.entrySet()) { if (entry.getKey().isONE() && entry.getValue().equals(1L)) { continue; } result.add(F.Power(jas.integerPoly2Expr(entry.getKey()), F.integer(entry.getValue()))); } return result; }
public boolean monomialToExpr(BigRational coeff, ExpVector exp, IASTAppendable monomTimes) { if (!coeff.isONE()) { IFraction coeffValue = F.fraction(coeff.numerator(), coeff.denominator()); monomTimes.append(coeffValue); } return expVectorToExpr(exp, monomTimes); }
public static INumber jas2Numeric(edu.jas.poly.Complex<BigRational> c, double epsilon) { IFraction re = F.fraction(c.getRe().numerator(), c.getRe().denominator()); double red = re.doubleValue(); IFraction im = F.fraction(c.getIm().numerator(), c.getIm().denominator()); double imd = im.doubleValue(); return F.chopNumber(F.complexNum(red, imd), epsilon); }
public static INumber jas2Numeric(edu.jas.poly.Complex<BigRational> c, double epsilon) { IFraction re = F.fraction(c.getRe().numerator(), c.getRe().denominator()); double red = re.doubleValue(); IFraction im = F.fraction(c.getIm().numerator(), c.getIm().denominator()); double imd = im.doubleValue(); if (F.isZero(imd, epsilon)) { return F.num(red); } return F.complexNum(red, imd); } }
@Override public IExpr evaluate(final IAST ast) { Validate.checkSize(ast, 3); try { // try to convert into a fractional number final EvalEngine engine = EvalEngine.get(); IExpr arg0 = ast.get(1); arg0 = engine.evaluate(arg0); IExpr arg1 = ast.get(2); arg1 = engine.evaluate(arg1); if (arg0.isInteger() && arg1.isInteger()) { return F.fraction((IInteger) arg0, (IInteger) arg1); } } catch (Exception e) { if (Config.SHOW_STACKTRACE) { e.printStackTrace(); } } return null; }
@Override public IExpr evaluate(final IAST ast) { Validate.checkSize(ast, 2); IExpr arg1 = ast.get(1); try { // try to convert into a fractional number final EvalEngine engine = EvalEngine.get(); arg1 = engine.evaluate(arg1); if (arg1.isRational()) { return arg1; } if (arg1 instanceof INum) { return F.fraction(((INum) arg1).getRealPart()); } if (arg1 instanceof IComplexNum) { return F.complex(((IComplexNum) arg1).getRealPart(), ((IComplexNum) arg1).getImaginaryPart()); } } catch (Exception e) { if (Config.SHOW_STACKTRACE) { e.printStackTrace(); } } return null; }
@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.setAtCopy(0, F.Times), F.fraction(1, arg1.argSize())); } return F.NIL; }
public IAST rationalPoly2Expr(final GenPolynomial<BigRational> poly) throws ArithmeticException, ClassCastException { if (poly.length() == 0) { return F.Plus(F.C0); } IAST result = F.Plus(); for (Monomial<BigRational> monomial : poly) { BigRational coeff = monomial.coefficient(); ExpVector exp = monomial.exponent(); IFraction coeffValue = F.fraction(coeff.numerator(), coeff.denominator()); IAST monomTimes = F.Times(coeffValue); long lExp; for (int i = 0; i < exp.length(); i++) { lExp = exp.getVal(i); if (lExp != 0) { monomTimes.add(F.Power(fVariables.get(i), F.integer(lExp))); } } result.add(monomTimes); } return result; }
@Override public IASTMutable createFunction(final IParserFactory factory, ExprParser parser, final IExpr lhs, final IExpr rhs) { if (rhs.isInteger() && !rhs.isZero()) { if (lhs.isInteger()) { if (!parser.isHoldOrHoldFormOrDefer()) { return (IASTMutable) F.Rational((IInteger) lhs, (IInteger) rhs); } } return (IASTMutable) F.Times(F.fraction(F.C1, (IInteger) rhs), lhs); } if (lhs.equals(F.C1)) { return (IASTMutable) F.Power(rhs, F.CN1); } if (rhs.isPower() && rhs.exponent().isNumber()) { return F.Times(lhs, F.Power(rhs.base(), rhs.exponent().negate())); } return F.Times(lhs, F.Power(rhs, F.CN1)); } }