use of org.matheclipse.core.eval.EvalEngine in project symja_android_library by axkr.
the class F method complexNum.
public static IComplexNum complexNum(final IComplex value) {
final IRational realFraction = value.getRealPart();
final IRational imagFraction = value.getImaginaryPart();
final EvalEngine engine = EvalEngine.get();
if (engine.isApfloat()) {
return ApcomplexNum.valueOf(realFraction.toBigNumerator(), realFraction.toBigDenominator(), imagFraction.toBigNumerator(), imagFraction.toBigDenominator(), engine.getNumericPrecision());
}
// double precision complex number
double nr = realFraction.getNumerator().doubleValue();
double dr = realFraction.getDenominator().doubleValue();
double ni = imagFraction.getNumerator().doubleValue();
double di = imagFraction.getDenominator().doubleValue();
return complexNum(nr / dr, ni / di);
}
use of org.matheclipse.core.eval.EvalEngine in project symja_android_library by axkr.
the class F method expandAll.
/**
* Apply <code>ExpandAll()</code> to the given expression if it's an <code>IAST</code>. If expanding wasn't possible
* this method returns the given argument.
*
* @param a
* the expression which should be evaluated
* @param expandNegativePowers
* TODO
* @param distributePlus
* TODO
* @return the evaluated expression
* @see EvalEngine#evaluate(IExpr)
*/
public static IExpr expandAll(IExpr a, boolean expandNegativePowers, boolean distributePlus) {
if (a.isAST()) {
EvalEngine engine = EvalEngine.get();
IAST ast = engine.evalFlatOrderlessAttributesRecursive((IAST) a);
if (!ast.isPresent()) {
ast = (IAST) a;
}
IExpr temp = Algebra.expandAll(ast, null, expandNegativePowers, distributePlus);
if (temp.isPresent()) {
return temp;
}
return ast;
}
return a;
}
use of org.matheclipse.core.eval.EvalEngine in project symja_android_library by axkr.
the class Surd method e2ApfloatArg.
@Override
public IExpr e2ApfloatArg(final ApfloatNum af0, final ApfloatNum af1) {
if (af1.isZero()) {
EvalEngine ee = EvalEngine.get();
ee.printMessage("Surd(a,b) division by zero");
return F.Indeterminate;
}
if (af0.isNegative()) {
return af0.negate().pow(af1.inverse()).negate();
}
return af0.pow(af1.inverse());
}
use of org.matheclipse.core.eval.EvalEngine in project symja_android_library by axkr.
the class Surd method doubleSurd.
private double doubleSurd(double val, double r) {
if (r == 0.0d) {
EvalEngine ee = EvalEngine.get();
ee.printMessage("Surd(a,b) division by zero");
return Double.NaN;
}
if (val < 0.0d) {
return -Math.pow(-val, 1.0d / r);
}
return Math.pow(val, 1.0d / r);
}
use of org.matheclipse.core.eval.EvalEngine in project symja_android_library by axkr.
the class AbstractFunctionEvaluator method initSerializedRules.
/**
* Initialize the serialized Rubi integration rules from ressource
* <code>/ser/integrate.ser</code>.
*
* @param symbol
*/
public static void initSerializedRules(final ISymbol symbol) {
EvalEngine engine = EvalEngine.get();
boolean oldPackageMode = engine.isPackageMode();
boolean oldTraceMode = engine.isTraceMode();
try {
engine.setPackageMode(true);
engine.setTraceMode(false);
InputStream in = AbstractFunctionEvaluator.class.getResourceAsStream("/ser/" + symbol.getSymbolName().toLowerCase(Locale.ENGLISH) + ".ser");
ObjectInputStream ois = new ObjectInputStream(in);
// InputStream in = new FileInputStream("c:\\temp\\ser\\" +
// symbol.getSymbolName() + ".ser");
// read files with BufferedInputStream to improve performance
// ObjectInputStream ois = new ObjectInputStream(new
// BufferedInputStream(in));
symbol.readRules(ois);
ois.close();
in.close();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
engine.setPackageMode(oldPackageMode);
engine.setTraceMode(oldTraceMode);
}
}
Aggregations