use of org.matheclipse.core.expression.F.List in project symja_android_library by axkr.
the class Algebra method partialFractionDecompositionRational.
/**
* Returns an AST with head <code>Plus</code>, which contains the partial fraction decomposition of the numerator
* and denominator parts.
*
* @param pf
* partial fraction generator
* @param parts
* @param variable
* a variable
* @return <code>F.NIL</code> if the partial fraction decomposition wasn't constructed
*/
public static IExpr partialFractionDecompositionRational(IPartialFractionGenerator pf, IExpr[] parts, ISymbol variable) {
try {
IAST variableList = F.List(variable);
IExpr exprNumerator = F.evalExpandAll(parts[0]);
IExpr exprDenominator = F.evalExpandAll(parts[1]);
ASTRange r = new ASTRange(variableList, 1);
List<IExpr> varList = r;
String[] varListStr = new String[1];
varListStr[0] = variableList.arg1().toString();
JASConvert<BigRational> jas = new JASConvert<BigRational>(varList, BigRational.ZERO);
GenPolynomial<BigRational> numerator = jas.expr2JAS(exprNumerator, false);
GenPolynomial<BigRational> denominator = jas.expr2JAS(exprDenominator, false);
// get factors
FactorAbstract<BigRational> factorAbstract = FactorFactory.getImplementation(BigRational.ZERO);
SortedMap<GenPolynomial<BigRational>, Long> sfactors = factorAbstract.baseFactors(denominator);
List<GenPolynomial<BigRational>> D = new ArrayList<GenPolynomial<BigRational>>(sfactors.keySet());
SquarefreeAbstract<BigRational> sqf = SquarefreeFactory.getImplementation(BigRational.ZERO);
List<List<GenPolynomial<BigRational>>> Ai = sqf.basePartialFraction(numerator, sfactors);
if (Ai.size() > 0) {
// IAST result = F.Plus();
pf.allocPlus(Ai.size() * 2);
pf.setJAS(jas);
if (!Ai.get(0).get(0).isZERO()) {
pf.addNonFractionalPart(Ai.get(0).get(0));
}
for (int i = 1; i < Ai.size(); i++) {
List<GenPolynomial<BigRational>> list = Ai.get(i);
int j = 0;
for (GenPolynomial<BigRational> genPolynomial : list) {
if (!genPolynomial.isZERO()) {
GenPolynomial<BigRational> Di_1 = D.get(i - 1);
pf.addSinglePartialFraction(genPolynomial, Di_1, j);
}
j++;
}
}
return pf.getResult();
}
} catch (JASConversionException e) {
if (Config.DEBUG) {
e.printStackTrace();
}
}
return F.NIL;
}
use of org.matheclipse.core.expression.F.List in project symja_android_library by axkr.
the class Object2Expr method convert.
/**
* Converts the following J<va objects into an IExpr expression
*
* <pre>
* Java Object -> MathEclipse object
* -------------------------------------
* null object Null symbol
* IExpr IExpr type
* Boolean True or False symbol
* BigInteger Integer value
* java.math.BigInteger Integer value
* BigDecimal Double with doubleValue() value
* Double Double with doubleValue() value
* Float Double with doubleValue() value
* Number Integer with longValue() value
* java.util.List 0-th element of the list gives the head of the function
* 1..nth element of the list give the arguments of the function
* Object[] a list of converted objects
* int[] a list of <code>IntegerSym</code>Integer values
* double[] a list of <code>Num</code> values
* double[][] a matrix (i.e. nested lists) of Double values
* Complex[] a list of <code>ComplexNum</code> values
* boolean[] a list of True or False symbols
*
* </pre>
*
*/
public static IExpr convert(Object obj) throws ConversionException {
if (obj == null) {
return F.Null;
}
if (obj instanceof IExpr) {
return (IExpr) obj;
}
if (obj instanceof Boolean) {
if (((Boolean) obj).booleanValue()) {
return F.True;
}
return F.False;
}
if (obj instanceof BigInteger) {
return F.integer((BigInteger) obj);
}
if (obj instanceof java.math.BigInteger) {
return F.integer((java.math.BigInteger) obj);
}
if (obj instanceof Number) {
if (obj instanceof BigDecimal) {
return F.num(((BigDecimal) obj).doubleValue());
}
if (obj instanceof Double) {
return F.num(((Double) obj).doubleValue());
}
if (obj instanceof Float) {
return F.num(((Float) obj).doubleValue());
}
return F.integer(((Number) obj).longValue());
}
if (obj instanceof java.util.List) {
final java.util.List<?> lst = (java.util.List<?>) obj;
IAST list = F.NIL;
if (lst.size() == 0) {
list = List();
} else {
final ISymbol head = F.userSymbol(lst.get(0).toString());
int size = lst.size();
list = F.ast(head, size, false);
for (int i = 1; i < size; i++) {
list.append(convert(lst.get(i)));
}
}
return list;
}
if (obj instanceof Object[]) {
final Object[] array = (Object[]) obj;
final IAST list = F.ListAlloc(array.length);
for (int i = 0; i < array.length; i++) {
list.append(convert(array[i]));
}
return list;
}
if (obj instanceof int[]) {
return AST.newInstance(F.List, (int[]) obj);
}
if (obj instanceof double[]) {
return AST.newInstance(F.List, (double[]) obj);
}
if (obj instanceof double[][]) {
final double[][] dd = (double[][]) obj;
final IAST list = F.ListAlloc(dd.length);
for (int i = 0; i < dd.length; i++) {
final IAST row = F.ListAlloc(dd[i].length);
for (int j = 0; j < dd[i].length; j++) {
row.append(F.num(dd[i][j]));
}
list.append(row);
}
return list;
}
if (obj instanceof org.hipparchus.complex.Complex[]) {
return AST.newInstance(F.List, (org.hipparchus.complex.Complex[]) obj);
}
if (obj instanceof boolean[]) {
final boolean[] array = (boolean[]) obj;
final IAST list = F.ListAlloc(array.length);
for (int i = 0; i < array.length; i++) {
if (array[i]) {
list.append(F.True);
} else {
list.append(F.False);
}
}
return list;
}
return F.$str(obj.toString());
}
Aggregations