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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations