use of org.matheclipse.core.interfaces.IASTAppendable in project symja_android_library by axkr.
the class Convert method complexMatrix2List.
public static IASTAppendable complexMatrix2List(final FieldMatrix<Complex> matrix, boolean matrixFormat) {
if (matrix == null) {
return F.NIL;
}
final int rowSize = matrix.getRowDimension();
final int colSize = matrix.getColumnDimension();
final IASTAppendable out = F.ListAlloc(rowSize);
IASTAppendable currOutRow;
for (int i = 0; i < rowSize; i++) {
currOutRow = F.ListAlloc(colSize);
out.append(currOutRow);
for (int j = 0; j < colSize; j++) {
final Complex expr = matrix.getEntry(i, j);
currOutRow.append(F.complexNum(expr));
}
}
if (matrixFormat) {
// because the rows can contain sub lists the IAST.IS_MATRIX flag cannot be set directly.
// isMatrix() must be
// used!
out.isMatrix(true);
}
return out;
}
use of org.matheclipse.core.interfaces.IASTAppendable in project symja_android_library by axkr.
the class Convert method polynomialFunction2Expr.
/**
* Converts an array of coefficients into the (polynomial) expression representation.
*
* @param coefficients the coefficients of the polynomial function
* @param sym the name of the polynomial functions variable
* @return
*/
public static IExpr polynomialFunction2Expr(double[] coefficients, ISymbol sym) {
if (coefficients[0] == 0.0) {
if (coefficients.length == 1) {
return F.C0;
}
}
IASTAppendable sum = F.PlusAlloc(coefficients.length);
sum.append(coefficients[0]);
for (int i = 1; i < coefficients.length; ++i) {
if (coefficients[i] != 0) {
sum.append(F.Times(F.num(coefficients[i]), F.Power(sym, F.ZZ(i))));
}
}
return sum;
}
use of org.matheclipse.core.interfaces.IASTAppendable in project symja_android_library by axkr.
the class CreamConvert method integerSolve.
/**
* Create a cream integer solver.
*
* @param list
* @param equationVariables all variables which are defined in the equations
* @param userDefinedVariables all variables which are defined by the user. May contain additional
* variables which aren't available in <code>equationVariables</code>
* @param engine
* @return a list of rules with the integer solutions
*/
public IAST integerSolve(final IAST list, final IAST equationVariables, final IAST userDefinedVariables, int maximumNumberOfResults, final EvalEngine engine) {
IASTAppendable result = F.ListAlloc();
Solver solver = new DefaultSolver(expr2Cream(list, equationVariables), Solver.DEFAULT);
// call with timeout
solver.findAll(new CreamSolutionHandler(result, equationVariables, userDefinedVariables, maximumNumberOfResults, engine), 10000);
return result;
}
use of org.matheclipse.core.interfaces.IASTAppendable in project symja_android_library by axkr.
the class Pods method parseInput.
/**
* package private
*/
static IExpr parseInput(String inputStr, EvalEngine engine) {
engine.setPackageMode(false);
IExpr inExpr = F.NIL;
// }
if (!inExpr.isPresent()) {
final FuzzyParser parser = new FuzzyParser(engine);
try {
inExpr = parser.parseFuzzyList(inputStr);
} catch (SyntaxError serr) {
// this includes syntax errors
LOGGER.debug("Pods: FuzzyParser.parseFuzzyList() failed", serr);
TeXParser texConverter = new TeXParser(engine);
inExpr = texConverter.toExpression(inputStr);
}
}
if (inExpr == S.$Aborted) {
return F.NIL;
}
if (inExpr.isList() && inExpr.size() == 2) {
inExpr = inExpr.first();
}
if (inExpr.isTimes() && !inExpr.isNumericFunction(true) && inExpr.argSize() <= 4) {
if (((IAST) inExpr).isEvalFlagOn(IAST.TIMES_PARSED_IMPLICIT)) {
inExpr = flattenTimes((IAST) inExpr).orElse(inExpr);
IAST rest = ((IAST) inExpr).setAtClone(0, S.List);
IASTAppendable specialFunction = F.NIL;
String stemForm = getStemForm(rest.arg1().toString().toLowerCase());
IExpr head = rest.head();
if (stemForm != null) {
head = STEM.getSymbol(stemForm);
if (head != null) {
specialFunction = rest.setAtClone(0, head);
specialFunction.remove(1);
}
}
if (!specialFunction.isPresent()) {
stemForm = getStemForm(rest.last().toString().toLowerCase());
if (stemForm != null) {
head = STEM.getSymbol(stemForm);
if (head != null) {
specialFunction = rest.setAtClone(0, head);
specialFunction.remove(rest.size() - 1);
}
}
}
if (specialFunction.isPresent()) {
if (head != null) {
if (head == S.UnitConvert) {
IExpr temp = unitConvert(engine, rest.rest());
if (temp.isPresent()) {
return temp;
}
} else {
int i = 1;
while (i < specialFunction.size()) {
String argStr = specialFunction.get(i).toString().toLowerCase();
if (argStr.equalsIgnoreCase("by") || argStr.equalsIgnoreCase("for")) {
specialFunction.remove(i);
continue;
}
i++;
}
return specialFunction;
}
}
}
if (rest.arg1().toString().equalsIgnoreCase("convert")) {
rest = inExpr.rest();
}
if (rest.argSize() > 2) {
rest = rest.removeIf(x -> x.toString().equals("in"));
}
IExpr temp = unitConvert(engine, rest);
if (temp.isPresent()) {
return temp;
}
}
}
return inExpr;
}
use of org.matheclipse.core.interfaces.IASTAppendable in project symja_android_library by axkr.
the class Pods method flattenTimesRecursive.
public static IASTAppendable flattenTimesRecursive(final IAST ast) {
int[] newSize = new int[1];
newSize[0] = 0;
boolean[] flattened = new boolean[] { false };
ast.forEach(expr -> {
if (ast.isTimes() && ast.isEvalFlagOn(IAST.TIMES_PARSED_IMPLICIT)) {
flattened[0] = true;
newSize[0] += ast.size();
} else {
newSize[0]++;
}
});
if (flattened[0]) {
IASTAppendable result = F.ast(ast.head(), newSize[0], false);
ast.forEach(expr -> {
if (expr.isTimes() && ((IAST) expr).isEvalFlagOn(IAST.TIMES_PARSED_IMPLICIT)) {
result.appendArgs(flattenTimesRecursive((IAST) expr).orElse((IAST) expr));
} else {
result.append(expr);
}
});
return result;
}
return F.NIL;
}
Aggregations