use of org.matheclipse.core.interfaces.IASTAppendable in project symja_android_library by axkr.
the class JASIExpr method complexPoly2Expr.
/**
* Convert a JAS complex polynomial to <code>IExpr</code>.
*
* @param poly
* @return
* @throws ArithmeticException
* @throws ClassCastException
*/
public IExpr complexPoly2Expr(final GenPolynomial<Complex<BigRational>> poly) throws ArithmeticException, ClassCastException {
if (poly.length() == 0) {
return F.C0;
}
IASTAppendable result = F.PlusAlloc(poly.length());
for (Monomial<Complex<BigRational>> monomial : poly) {
Complex<BigRational> coeff = monomial.coefficient();
ExpVector exp = monomial.exponent();
BigRational re = coeff.getRe();
BigRational im = coeff.getIm();
IASTAppendable monomTimes = F.Times(F.complex(F.fraction(re.numerator(), re.denominator()), F.fraction(im.numerator(), im.denominator())));
long lExp;
for (int i = 0; i < exp.length(); i++) {
lExp = exp.getVal(i);
if (lExp != 0) {
monomTimes.append(F.Power(fVariables.get(i), F.ZZ(lExp)));
}
}
if (monomTimes.isAST1()) {
result.append(monomTimes.arg1());
} else {
result.append(monomTimes);
}
}
if (result.isAST1()) {
return result.arg1();
} else {
return result;
}
}
use of org.matheclipse.core.interfaces.IASTAppendable in project symja_android_library by axkr.
the class JSONConvert method importJSONRecursive.
public static IExpr importJSONRecursive(JsonNode node) {
if (node instanceof ArrayNode) {
ArrayNode arrayNode = (ArrayNode) node;
Iterator<JsonNode> iter = arrayNode.elements();
IASTAppendable list = F.ListAlloc(arrayNode.size());
while (iter.hasNext()) {
JsonNode next = iter.next();
IExpr temp = importJSONRecursive(next);
if (temp.isPresent()) {
list.append(temp);
}
}
return list;
} else if (node instanceof ObjectNode) {
IASTAppendable list = F.ListAlloc();
ObjectNode objectNode = (ObjectNode) node;
Iterator<Entry<String, JsonNode>> iter = objectNode.fields();
while (iter.hasNext()) {
Entry<String, JsonNode> next = iter.next();
IExpr temp = importJSONRecursive(next.getValue());
if (temp.isPresent()) {
list.append(F.Rule(F.$str(next.getKey()), temp));
}
}
return list;
} else if (node instanceof ValueNode) {
ValueNode valueNode = (ValueNode) node;
if (valueNode instanceof NumericNode) {
if (valueNode instanceof DoubleNode) {
return F.num(valueNode.doubleValue());
} else if (valueNode instanceof FloatNode) {
return F.num(valueNode.doubleValue());
} else if (valueNode instanceof IntNode) {
return F.ZZ(valueNode.intValue());
} else if (valueNode instanceof LongNode) {
return F.ZZ(valueNode.longValue());
} else if (valueNode instanceof ShortNode) {
return F.ZZ(valueNode.intValue());
} else if (valueNode instanceof BigIntegerNode) {
return F.ZZ(valueNode.bigIntegerValue());
} else if (valueNode instanceof DecimalNode) {
return F.num(new Apfloat(valueNode.decimalValue()));
}
}
if (valueNode instanceof BooleanNode) {
return valueNode.booleanValue() ? S.True : S.False;
} else if (valueNode instanceof NullNode) {
return S.Null;
} else if (valueNode instanceof TextNode) {
return F.$str(valueNode.textValue());
}
return F.$str(valueNode.toString());
}
return F.NIL;
}
use of org.matheclipse.core.interfaces.IASTAppendable in project symja_android_library by axkr.
the class Object2Expr method convertList.
/**
* @param lst
* @param parseString if <code>true</code> and <code>obj instanceof String</code> parse the string
* as a Symja expression
* @param javaObject if <code>true</code> return a wrapper instanceof {@link JavaObjectExpr} if no
* other conversion was found
* @return
*/
public static IExpr convertList(java.util.Collection<?> lst, boolean parseString, boolean javaObject) {
if (lst.size() == 0) {
return List();
} else {
int size = lst.size();
IASTAppendable list = F.ast(S.List, size);
for (Object element : lst) {
list.append(convert(element, parseString, javaObject));
}
return list;
}
}
use of org.matheclipse.core.interfaces.IASTAppendable in project symja_android_library by axkr.
the class JASConvert method complexPoly2Expr.
/**
* Convert a JAS complex-rational polynomial to <code>IExpr</code>.
*
* @param poly
* @return
* @throws ArithmeticException
* @throws JASConversionException
*/
public IExpr complexPoly2Expr(final GenPolynomial<Complex<BigRational>> poly) throws ArithmeticException, JASConversionException {
if (poly.length() == 0) {
return F.C0;
}
IASTAppendable result = F.PlusAlloc(poly.length());
for (Monomial<Complex<BigRational>> monomial : poly) {
Complex<BigRational> coeff = monomial.coefficient();
ExpVector exp = monomial.exponent();
IASTAppendable monomTimes = F.TimesAlloc(exp.length() + 1);
monomialToExpr(coeff, exp, monomTimes);
result.append(monomTimes.oneIdentity1());
}
return result.oneIdentity0();
}
use of org.matheclipse.core.interfaces.IASTAppendable in project symja_android_library by axkr.
the class JASConvert method logIntegral2Expr.
/**
* Convert a jas <code>LogIntegral</code> into a matheclipse expression
*
* @param logIntegral the JAS LogIntegral
* @return
*/
public IAST logIntegral2Expr(LogIntegral<BigRational> logIntegral) {
List<BigRational> cfactors = logIntegral.cfactors;
List<GenPolynomial<BigRational>> cdenom = logIntegral.cdenom;
List<AlgebraicNumber<BigRational>> afactors = logIntegral.afactors;
List<GenPolynomial<AlgebraicNumber<BigRational>>> adenom = logIntegral.adenom;
IASTAppendable plus = F.PlusAlloc(cfactors.size() + afactors.size());
if (cfactors.size() > 0) {
for (int i = 0; i < cfactors.size(); i++) {
BigRational cp = cfactors.get(i);
GenPolynomial<BigRational> p = cdenom.get(i);
plus.append(F.Times(F.fraction(cp.numerator(), cp.denominator()), F.Log(rationalPoly2Expr(p, false))));
}
}
// TODO implement this conversion for AlgebraicNumbers...
if (afactors.size() > 0) {
for (int i = 0; i < afactors.size(); i++) {
AlgebraicNumber<BigRational> ap = afactors.get(i);
AlgebraicNumberRing<BigRational> ar = ap.factory();
GenPolynomial<AlgebraicNumber<BigRational>> p = adenom.get(i);
if (p.degree(0) < ar.modul.degree(0) && ar.modul.degree(0) > 2) {
}
GenPolynomial<BigRational> v = ap.getVal();
IASTAppendable times = F.TimesAlloc(2);
if (p.degree(0) < ar.modul.degree(0) && ar.modul.degree(0) > 2) {
IASTAppendable rootOf = F.ast(S.RootOf);
rootOf.append(rationalPoly2Expr(ar.modul, false));
times.append(rootOf);
throw new UnsupportedOperationException("JASConvert#logIntegral2Expr()");
}
times.append(rationalPoly2Expr(v, false));
times.append(F.Log(polyAlgebraicNumber2Expr(p)));
plus.append(times);
}
}
return plus;
}
Aggregations