use of org.matheclipse.core.interfaces.IAST in project symja_android_library by axkr.
the class AbstractArg12 method binaryOperator.
public IExpr binaryOperator(final IExpr o0, final IExpr o1) {
IExpr result = F.NIL;
if (o0 instanceof ApcomplexNum) {
if (o1.isNumber()) {
result = e2ApcomplexArg((ApcomplexNum) o0, ((INumber) o1).apcomplexNumValue(((ApcomplexNum) o0).precision()));
}
if (result.isPresent()) {
return result;
}
return e2ObjArg(o0, o1);
} else if (o1 instanceof ApcomplexNum) {
if (o0.isNumber()) {
result = e2ApcomplexArg(((INumber) o0).apcomplexNumValue(((ApcomplexNum) o1).precision()), (ApcomplexNum) o1);
}
if (result.isPresent()) {
return result;
}
return e2ObjArg(o0, o1);
} else if (o0 instanceof ComplexNum) {
if (o1.isNumber()) {
result = e2DblComArg((ComplexNum) o0, ((INumber) o1).complexNumValue());
}
if (result.isPresent()) {
return result;
}
return e2ObjArg(o0, o1);
} else if (o1 instanceof ComplexNum) {
if (o0.isNumber()) {
result = e2DblComArg(((INumber) o0).complexNumValue(), (ComplexNum) o1);
}
if (result.isPresent()) {
return result;
}
return e2ObjArg(o0, o1);
}
if (o0 instanceof ApfloatNum) {
if (o1.isSignedNumber()) {
result = e2ApfloatArg((ApfloatNum) o0, ((ISignedNumber) o1).apfloatNumValue(((ApfloatNum) o0).precision()));
}
if (result.isPresent()) {
return result;
}
return e2ObjArg(o0, o1);
} else if (o1 instanceof ApfloatNum) {
if (o0.isSignedNumber()) {
result = e2ApfloatArg(((ISignedNumber) o0).apfloatNumValue(((ApfloatNum) o1).precision()), (ApfloatNum) o1);
}
if (result.isPresent()) {
return result;
}
return e2ObjArg(o0, o1);
} else if (o0 instanceof Num) {
if (o1.isSignedNumber()) {
result = e2DblArg((Num) o0, ((ISignedNumber) o1).numValue());
}
if (result.isPresent()) {
return result;
}
return e2ObjArg(o0, o1);
} else if (o1 instanceof Num) {
if (o0.isSignedNumber()) {
result = e2DblArg(((ISignedNumber) o0).numValue(), (Num) o1);
}
if (result.isPresent()) {
return result;
}
return e2ObjArg(o0, o1);
}
result = e2ObjArg(o0, o1);
if (result.isPresent()) {
return result;
}
if (o0 instanceof IInteger) {
if (o1 instanceof IInteger) {
return e2IntArg((IInteger) o0, (IInteger) o1);
}
if (o1 instanceof IFraction) {
return e2FraArg(F.fraction((IInteger) o0, F.C1), (IFraction) o1);
}
if (o1 instanceof IComplex) {
return e2ComArg(F.complex((IInteger) o0, F.C0), (IComplex) o1);
}
return F.NIL;
}
if (o0 instanceof IFraction) {
if (o1 instanceof IInteger) {
return e2FraArg((IFraction) o0, F.fraction((IInteger) o1, F.C1));
}
if (o1 instanceof IFraction) {
return e2FraArg((IFraction) o0, (IFraction) o1);
}
if (o1 instanceof IComplex) {
return e2ComArg(F.complex((IFraction) o0), (IComplex) o1);
}
return F.NIL;
}
if (o0 instanceof IComplex) {
if (o1 instanceof IInteger) {
return eComIntArg((IComplex) o0, (IInteger) o1);
}
if (o1 instanceof IFraction) {
return eComFraArg((IComplex) o0, (IFraction) o1);
}
if (o1 instanceof IComplex) {
return e2ComArg((IComplex) o0, (IComplex) o1);
}
}
if (o0 instanceof ISymbol) {
if (o1 instanceof ISymbol) {
return e2SymArg((ISymbol) o0, (ISymbol) o1);
}
}
if (o0 instanceof IAST) {
if (o1 instanceof IInteger) {
return eFunIntArg((IAST) o0, (IInteger) o1);
}
if (o1 instanceof IAST) {
return e2FunArg((IAST) o0, (IAST) o1);
}
}
return F.NIL;
}
use of org.matheclipse.core.interfaces.IAST in project symja_android_library by axkr.
the class Console method main.
public static void main(final String[] args) {
// console.getDefaultSystemRulesFilename(),
F.initSymbols(null, null, true);
// null, false);
Console console;
try {
console = new Console();
} catch (final SyntaxError e1) {
e1.printStackTrace();
return;
}
String inputExpression = null;
String trimmedInput = null;
console.setArgs(args);
final File file = console.getFile();
if (file != null) {
try {
final BufferedReader f = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
final StringBuffer buff = new StringBuffer(1024);
String line;
while ((line = f.readLine()) != null) {
buff.append(line);
buff.append('\n');
}
f.close();
inputExpression = buff.toString();
System.out.println("In [" + COUNTER + "]: " + inputExpression);
console.resultPrinter(inputExpression);
COUNTER++;
} catch (final IOException ioe) {
final String msg = "Cannot read from the specified file. " + "Make sure the path exists and you have read permission.";
System.out.println(msg);
return;
}
}
while (true) {
try {
inputExpression = console.readString(System.out, ">> ");
if (inputExpression != null) {
trimmedInput = inputExpression.trim();
if ((inputExpression.length() >= 4) && inputExpression.toLowerCase(Locale.ENGLISH).substring(0, 4).equals("exit")) {
System.out.println("Closing Symja console... bye.");
System.exit(0);
} else if ((inputExpression.length() >= 10) && inputExpression.toLowerCase(Locale.ENGLISH).substring(0, 10).equals("timeoutoff")) {
System.out.println("Disabling timeout for evaluation");
console.fSeconds = -1;
continue;
} else if ((inputExpression.length() >= 9) && inputExpression.toLowerCase(Locale.ENGLISH).substring(0, 9).equals("timeouton")) {
System.out.println("Enabling timeout for evaluation to 60 seconds.");
console.fSeconds = 60;
continue;
} else if (trimmedInput.length() > 1 && trimmedInput.charAt(0) == '?') {
String name = trimmedInput.substring(1);
IAST list = Names.getNamesByPrefix(name);
for (int i = 1; i < list.size(); i++) {
System.out.print(list.get(i).toString());
if (i != list.size() - 1) {
System.out.print(", ");
}
}
System.out.println();
if (list.size() == 2) {
printDocumentation(list.get(1).toString());
} else if (list.size() == 1 && (name.equals("D") || name.equals("E") || name.equals("I") || name.equals("N"))) {
printDocumentation(name);
}
continue;
}
String postfix = Scanner.balanceCode(inputExpression);
if (postfix != null && postfix.length() > 0) {
System.err.println("Automatically closing brackets: " + postfix);
inputExpression = inputExpression + postfix;
}
System.out.println("In [" + COUNTER + "]: " + inputExpression);
if (console.fPrettyPrinter) {
console.prettyPrinter(inputExpression);
} else {
console.resultPrinter(inputExpression);
}
COUNTER++;
}
// } catch (final MathRuntimeException mre) {
// Throwable me = mre.getCause();
// System.out.println(me.getMessage());
} catch (final Exception e) {
System.out.println(e.getMessage());
}
}
}
use of org.matheclipse.core.interfaces.IAST in project symja_android_library by axkr.
the class TimesOp method timesNull.
public static IExpr timesNull(IExpr a1, IExpr a2) {
IAST times = F.Times(a1, a2);
IExpr temp = Arithmetic.CONST_TIMES.evaluate(times, null);
if (temp.isPresent()) {
return temp;
}
return null;
}
use of org.matheclipse.core.interfaces.IAST in project symja_android_library by axkr.
the class MathUtils method integrate.
/**
* Integrate a function numerically.
*
* @param method
* the following methods are possible: LegendreGauss, Simpson,
* Romberg, Trapezoid
* @param fun
* the function which should be integrated
* @param v
* the variable
* @param aS
* lower bound double value string for integration
* @param bS
* upper bound double value string for integration
* @return
* @throws MathException
*/
public static double integrate(String method, String fun, String v, String aS, String bS) throws MathException {
ExprEvaluator parser = new ExprEvaluator();
double a, b;
try {
a = parser.evaluateDoube(aS);
} catch (MathException e) {
// e.getMessage(), e.context);
throw e;
}
try {
// b = parser.parse(bS).getVal();
b = parser.evaluateDoube(bS);
} catch (MathException e) {
// e.getMessage(), e.context);
throw e;
}
IExpr function = parse(fun, null);
IExpr var = parse(v, null);
IAST list = F.List();
list.append(var);
list.append(F.num(a));
list.append(F.num(b));
return NIntegrate.integrate("LegendreGauss", list, a, b, function, NIntegrate.DEFAULT_MAX_POINTS, NIntegrate.DEFAULT_MAX_ITERATIONS);
}
use of org.matheclipse.core.interfaces.IAST in project symja_android_library by axkr.
the class PlusOp method plus.
/**
* Evaluate <code>a0 + a2</code>.
*
* @param a1
* @param a2
* @return
*/
public static IExpr plus(IExpr a1, IExpr a2) {
IAST plus = F.Plus(a1, a2);
IExpr expr = Arithmetic.CONST_PLUS.evaluate(plus, null);
if (!expr.isPresent()) {
return plus;
}
return expr;
}
Aggregations