use of org.matheclipse.core.interfaces.IASTAppendable in project symja_android_library by axkr.
the class FuzzyParser method getFunctionArguments.
/**
* Get a function f[...][...]
*/
IASTMutable getFunctionArguments(final IExpr head) throws SyntaxError {
fRecursionDepth++;
getNextToken();
if (fToken == TT_ARGUMENTS_CLOSE) {
fRecursionDepth--;
getNextToken();
if (fToken == TT_ARGUMENTS_OPEN) {
return getFunctionArguments(F.headAST0(head));
}
return F.headAST0(head);
}
final IASTAppendable function = F.ast(head);
getArguments(function);
fRecursionDepth--;
if (fToken == TT_ARGUMENTS_CLOSE) {
getNextToken();
if (fToken == TT_ARGUMENTS_OPEN) {
return getFunctionArguments(reduceAST(function));
}
return reduceAST(function);
}
throwSyntaxError("']' expected.");
return null;
}
use of org.matheclipse.core.interfaces.IASTAppendable in project symja_android_library by axkr.
the class FuzzyParser method getFunction.
/**
* Get a function f[...][...]
*/
IASTMutable getFunction(final IExpr head) throws SyntaxError {
getNextToken();
if (fToken == TT_PRECEDENCE_CLOSE) {
getNextToken();
if (fToken == TT_PRECEDENCE_OPEN) {
return F.headAST0(head);
}
if (fToken == TT_ARGUMENTS_OPEN) {
return getFunctionArguments(F.headAST0(head));
}
return F.headAST0(head);
}
int size = determineSize(head, 10);
final IASTAppendable function = F.ast(head, size, false);
fRecursionDepth++;
try {
getArguments(function);
} finally {
fRecursionDepth--;
}
if (fToken == TT_PRECEDENCE_CLOSE) {
getNextToken();
if (fToken == TT_PRECEDENCE_OPEN) {
reduceAST(function);
}
if (fToken == TT_ARGUMENTS_OPEN) {
return getFunctionArguments(reduceAST(function));
}
return reduceAST(function);
}
throwSyntaxError("')' expected.");
return null;
}
use of org.matheclipse.core.interfaces.IASTAppendable in project symja_android_library by axkr.
the class FuzzyInfixExprOperator method createFunction.
public IASTMutable createFunction(final IParserFactory factory, FuzzyParser parser, final IExpr lhs, final IExpr rhs) {
if (fOperatorString.equals("//")) {
// lhs // rhs ==> rhs[lhs]
IASTAppendable function = F.ast(rhs);
function.append(lhs);
return function;
}
IASTAppendable function = F.ast(F.$s(getFunctionName()), 10, false);
function.append(lhs);
function.append(rhs);
return function;
}
use of org.matheclipse.core.interfaces.IASTAppendable in project symja_android_library by axkr.
the class IOFunctions method getNamesByPattern.
public static IAST getNamesByPattern(java.util.regex.Pattern pattern, EvalEngine engine) {
ContextPath contextPath = engine.getContextPath();
IASTAppendable list = F.ListAlloc(31);
Map<String, Context> contextMap = contextPath.getContextMap();
for (Map.Entry<String, Context> mapEntry : contextMap.entrySet()) {
Context context = mapEntry.getValue();
for (Map.Entry<String, ISymbol> entry : context.entrySet()) {
String fullName = context.completeContextName() + entry.getKey();
java.util.regex.Matcher matcher = pattern.matcher(fullName);
if (matcher.matches()) {
if (ParserConfig.PARSER_USE_LOWERCASE_SYMBOLS && context.equals(Context.SYSTEM)) {
String str = AST2Expr.PREDEFINED_SYMBOLS_MAP.get(entry.getValue().getSymbolName());
if (str != null) {
list.append(F.$str(str));
continue;
}
}
ISymbol value = entry.getValue();
if (context.isGlobal() || context.isSystem()) {
list.append(F.$str(value.toString()));
} else {
list.append(F.$str(fullName));
}
}
}
}
for (Context context : contextPath) {
String completeContextName = context.completeContextName();
if (!contextMap.containsKey(completeContextName)) {
for (Map.Entry<String, ISymbol> entry : context.entrySet()) {
String fullName = completeContextName + entry.getKey();
java.util.regex.Matcher matcher = pattern.matcher(fullName);
if (matcher.matches()) {
if (ParserConfig.PARSER_USE_LOWERCASE_SYMBOLS && context.equals(Context.SYSTEM)) {
String str = AST2Expr.PREDEFINED_SYMBOLS_MAP.get(entry.getValue().getSymbolName());
if (str != null) {
list.append(F.$str(str));
continue;
}
}
ISymbol value = entry.getValue();
if (context.isGlobal() || context.isSystem()) {
list.append(F.$str(value.toString()));
} else {
list.append(F.$str(fullName));
}
}
}
}
}
return list;
}
use of org.matheclipse.core.interfaces.IASTAppendable in project symja_android_library by axkr.
the class LinearAlgebra method cramersRule3x4.
/**
* Use cramer's rule to solve linear equations represented by a <code>3 x 4</code> augmented
* matrix which represents the system <code>M.x == b</code>, where the columns of the <code>3 x 3
* </code> matrix <code>M</code> are augmented by the vector <code>b</code>. This method assumes
* that the dimensions of the matrix are already checked by the caller. See:
* <a href="https://en.wikipedia.org/wiki/Cramer's_rule">Wikipedia Cramer's rule</a>
*
* @param matrix the <code>3 x 4</code> augmented matrix
* @param quiet show no message if there is no solution
* @param engine the evaluation engine
* @return a list of values which solve the equations or <code>F#NIL</code>, if the equations have
* no solution.
*/
public static IAST cramersRule3x4(FieldMatrix<IExpr> matrix, boolean quiet, EvalEngine engine) {
IASTAppendable list = F.ListAlloc(3);
FieldMatrix<IExpr> denominatorMatrix = matrix.getSubMatrix(0, 2, 0, 2);
IExpr denominator = determinant3x3(denominatorMatrix);
if (denominator.isZero()) {
if (!quiet) {
LOGGER.log(engine.getLogLevel(), "Row reduced linear equations have no solution.");
return F.NIL;
}
return F.NIL;
}
FieldMatrix<IExpr> xMatrix = denominatorMatrix.copy();
xMatrix.setColumn(0, new IExpr[] { matrix.getEntry(0, 3), matrix.getEntry(1, 3), matrix.getEntry(2, 3) });
IExpr xNumerator = determinant3x3(xMatrix);
list.append(F.Divide(xNumerator, denominator));
FieldMatrix<IExpr> yMatrix = denominatorMatrix.copy();
yMatrix.setColumn(1, new IExpr[] { matrix.getEntry(0, 3), matrix.getEntry(1, 3), matrix.getEntry(2, 3) });
IExpr yNumerator = determinant3x3(yMatrix);
list.append(F.Divide(yNumerator, denominator));
FieldMatrix<IExpr> zMatrix = denominatorMatrix.copy();
zMatrix.setColumn(2, new IExpr[] { matrix.getEntry(0, 3), matrix.getEntry(1, 3), matrix.getEntry(2, 3) });
IExpr zNumerator = determinant3x3(zMatrix);
list.append(F.Divide(zNumerator, denominator));
return list;
}
Aggregations