use of org.matheclipse.core.interfaces.ISymbol in project symja_android_library by axkr.
the class JASModInteger method expr2IExprPoly.
private GenPolynomial<ModLong> expr2IExprPoly(final IExpr exprPoly) throws ArithmeticException, ClassCastException {
if (exprPoly instanceof IAST) {
final IAST ast = (IAST) exprPoly;
GenPolynomial<ModLong> result = fPolyFactory.getZERO();
GenPolynomial<ModLong> p = fPolyFactory.getZERO();
if (ast.isPlus()) {
IExpr expr = ast.arg1();
result = expr2IExprPoly(expr);
for (int i = 2; i < ast.size(); i++) {
expr = ast.get(i);
p = expr2IExprPoly(expr);
result = result.sum(p);
}
return result;
} else if (ast.isTimes()) {
IExpr expr = ast.arg1();
result = expr2IExprPoly(expr);
for (int i = 2; i < ast.size(); i++) {
expr = ast.get(i);
p = expr2IExprPoly(expr);
result = result.multiply(p);
}
return result;
} else if (ast.isPower()) {
final IExpr expr = ast.arg1();
for (int i = 0; i < fVariables.size(); i++) {
if (fVariables.get(i).equals(expr)) {
int exponent = -1;
try {
exponent = Validate.checkPowerExponent(ast);
} catch (WrongArgumentType e) {
//
}
if (exponent < 0) {
throw new ArithmeticException("JASConvert:expr2Poly - invalid exponent: " + ast.arg2().toString());
}
ExpVector e = ExpVector.create(fVariables.size(), i, exponent);
return fPolyFactory.getONE().multiply(e);
}
}
}
} else if (exprPoly instanceof ISymbol) {
for (int i = 0; i < fVariables.size(); i++) {
if (fVariables.get(i).equals(exprPoly)) {
ExpVector e = ExpVector.create(fVariables.size(), i, 1L);
return fPolyFactory.getONE().multiply(e);
}
}
return new GenPolynomial(fPolyFactory, exprPoly);
} else if (exprPoly instanceof IInteger) {
return fPolyFactory.fromInteger((java.math.BigInteger) ((IInteger) exprPoly).asType(java.math.BigInteger.class));
} else if (exprPoly instanceof IFraction) {
return fraction2Poly((IFraction) exprPoly);
}
if (exprPoly.isFree(t -> fVariables.contains(t), true)) {
return new GenPolynomial(fPolyFactory, exprPoly);
} else {
for (int i = 0; i < fVariables.size(); i++) {
if (fVariables.get(i).equals(exprPoly)) {
ExpVector e = ExpVector.create(fVariables.size(), i, 1L);
return fPolyFactory.getONE().multiply(e);
}
}
}
throw new ClassCastException(exprPoly.toString());
}
use of org.matheclipse.core.interfaces.ISymbol in project symja_android_library by axkr.
the class D method getDerivativeArg1.
/**
* Search for one of the <code>Derivative[a1][head]</code> rules.
*
*
* @param x
* @param a1
* @param header
* @return
*/
private IExpr getDerivativeArg1(IExpr x, final IExpr a1, final IExpr head, EvalEngine engine) {
if (head.isSymbol()) {
ISymbol header = (ISymbol) head;
// IExpr der = Derivative.derivative(1, header, engine);
// if (der.isPresent()) {
// // we've found a derivative for a function of the form f[x_]
// IExpr derivative = F.eval(F.unaryAST1(der, a1));
// return F.Times(F.D(a1, x), derivative);
// }
IAST fDerivParam = Derivative.createDerivative(1, header, a1);
if (x.equals(a1)) {
// return F.NIL;
return fDerivParam;
}
return F.Times(F.D(a1, x), fDerivParam);
}
return F.NIL;
}
use of org.matheclipse.core.interfaces.ISymbol in project symja_android_library by axkr.
the class Eliminate method evaluate.
/** {@inheritDoc} */
@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
Validate.checkSize(ast, 3);
try {
IAST vars = Validate.checkSymbolOrSymbolList(ast, 2);
IAST termsEqualZeroList = checkEquations(ast, 1);
IAST result = termsEqualZeroList;
IAST temp;
IAST equalAST;
ISymbol variable;
VariableCounterVisitor exprAnalyzer;
for (int i = 1; i < vars.size(); i++) {
variable = (ISymbol) vars.get(i);
ArrayList<VariableCounterVisitor> analyzerList = new ArrayList<VariableCounterVisitor>();
for (int j = 1; j < result.size(); j++) {
equalAST = result.getAST(j);
exprAnalyzer = new VariableCounterVisitor(equalAST, variable);
equalAST.accept(exprAnalyzer);
analyzerList.add(exprAnalyzer);
}
Collections.sort(analyzerList);
temp = eliminateOneVariable(analyzerList, variable);
if (temp.isPresent()) {
result = temp;
} else {
return result;
}
}
return result;
} catch (Exception ex) {
ex.printStackTrace();
}
return F.NIL;
}
use of org.matheclipse.core.interfaces.ISymbol in project symja_android_library by axkr.
the class FindRoot method evaluate.
@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
Validate.checkRange(ast, 3);
ISymbol method = Newton;
int maxIterations = 100;
if (ast.size() >= 4) {
final Options options = new Options(ast.topHead(), ast, 3, engine);
IExpr optionMaxIterations = options.getOption("MaxIterations");
if (optionMaxIterations.isSignedNumber()) {
maxIterations = ((ISignedNumber) optionMaxIterations).toInt();
}
IExpr optionMethod = options.getOption("Method");
if (optionMethod.isSymbol()) {
method = ((ISymbol) optionMethod);
} else {
if (ast.arg3().isSymbol()) {
method = (ISymbol) ast.arg3();
}
}
}
if ((ast.arg2().isList())) {
IAST list = (IAST) ast.arg2();
IExpr function = ast.arg1();
if (list.size() >= 3 && list.arg1().isSymbol()) {
if (function.isAST(F.Equal, 3)) {
function = F.Plus(((IAST) function).arg1(), F.Negate(((IAST) function).arg2()));
}
ISignedNumber min = list.arg2().evalSignedNumber();
ISignedNumber max = null;
if (list.size() > 3) {
max = list.arg3().evalSignedNumber();
}
if (min != null) {
return F.List(F.Rule(list.arg1(), Num.valueOf(findRoot(method, maxIterations, list, min, max, function, engine))));
}
}
}
return F.NIL;
}
use of org.matheclipse.core.interfaces.ISymbol in project symja_android_library by axkr.
the class CDF method evaluate.
@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
Validate.checkSize(ast, 3);
if (ast.arg1().isAST()) {
IAST arg1 = (IAST) ast.arg1();
IExpr xArg = ast.arg2();
if (arg1.isAST()) {
IAST dist = (IAST) arg1;
if (dist.head().isSymbol()) {
ISymbol head = (ISymbol) dist.head();
if (engine.isNumericMode()) {
// numeric calculations
return evaluateNumericMode(dist, xArg, head);
} else {
// symbolic calculations
}
}
}
}
return F.NIL;
}
Aggregations