Search in sources :

Example 21 with EvalEngine

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);
}
Also used : EvalEngine(org.matheclipse.core.eval.EvalEngine) IRational(org.matheclipse.core.interfaces.IRational)

Example 22 with EvalEngine

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;
}
Also used : EvalEngine(org.matheclipse.core.eval.EvalEngine) IAST(org.matheclipse.core.interfaces.IAST) IExpr(org.matheclipse.core.interfaces.IExpr)

Example 23 with EvalEngine

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());
}
Also used : EvalEngine(org.matheclipse.core.eval.EvalEngine)

Example 24 with EvalEngine

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);
}
Also used : EvalEngine(org.matheclipse.core.eval.EvalEngine)

Example 25 with EvalEngine

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);
    }
}
Also used : ObjectInputStream(java.io.ObjectInputStream) InputStream(java.io.InputStream) EvalEngine(org.matheclipse.core.eval.EvalEngine) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

EvalEngine (org.matheclipse.core.eval.EvalEngine)32 IExpr (org.matheclipse.core.interfaces.IExpr)15 IAST (org.matheclipse.core.interfaces.IAST)5 ISymbol (org.matheclipse.core.interfaces.ISymbol)5 IRational (org.matheclipse.core.interfaces.IRational)3 IOException (java.io.IOException)2 RecursionLimitExceeded (org.matheclipse.core.eval.exception.RecursionLimitExceeded)2 Num (org.matheclipse.core.expression.Num)2 IInteger (org.matheclipse.core.interfaces.IInteger)2 INum (org.matheclipse.core.interfaces.INum)2 Parser (org.matheclipse.parser.client.Parser)2 File (java.io.File)1 InputStream (java.io.InputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 PrintWriter (java.io.PrintWriter)1 Apint (org.apfloat.Apint)1 UnivariateFunction (org.hipparchus.analysis.UnivariateFunction)1 RombergIntegrator (org.hipparchus.analysis.integration.RombergIntegrator)1 SimpsonIntegrator (org.hipparchus.analysis.integration.SimpsonIntegrator)1 TrapezoidIntegrator (org.hipparchus.analysis.integration.TrapezoidIntegrator)1