Search in sources :

Example 1 with ArgumentTypeException

use of org.matheclipse.core.eval.exception.ArgumentTypeException in project symja_android_library by axkr.

the class BuiltInDummy method reassignSymbolValue.

/**
 * {@inheritDoc}
 */
@Override
public IExpr[] reassignSymbolValue(IASTMutable ast, ISymbol functionSymbol, EvalEngine engine) {
    IExpr temp = assignedValue();
    if (temp != null) {
        IExpr[] result = new IExpr[2];
        result[0] = temp;
        // IExpr calculatedResult = function.apply(symbolValue);
        ast.set(1, temp);
        // F.binaryAST2(this, symbolValue, value));
        IExpr calculatedResult = engine.evaluate(ast);
        if (calculatedResult != null) {
            assignValue(calculatedResult, false);
            result[1] = calculatedResult;
            return result;
        }
    }
    throw new ArgumentTypeException(functionSymbol.toString() + " - Symbol: " + toString() + " has no value! Reassignment with a new value is not possible");
}
Also used : IExpr(org.matheclipse.core.interfaces.IExpr) ArgumentTypeException(org.matheclipse.core.eval.exception.ArgumentTypeException)

Example 2 with ArgumentTypeException

use of org.matheclipse.core.eval.exception.ArgumentTypeException in project symja_android_library by axkr.

the class ASTAssociation method appendRules.

private void appendRules(int index, IAST listOfRules, int startPosition, int endPosition) {
    if (listOfRules.isRuleAST()) {
        appendRule(this, index, listOfRules);
    } else {
        for (int i = startPosition; i < endPosition; i++) {
            IExpr rule = listOfRules.getRule(i);
            if (rule.isAssociation()) {
                ASTAssociation assoc = (ASTAssociation) rule;
                for (int j = 1; j < assoc.size(); j++) {
                    index = appendRule(this, index, assoc.getRule(j));
                }
            } else if (rule.isRuleAST()) {
                index = appendRule(this, index, (IAST) rule);
            } else if (rule.isList()) {
                IAST list = (IAST) rule;
                appendRules(index, list, 1, list.size());
            } else {
                throw new ArgumentTypeException("rule expression expected instead of " + rule.toString());
            }
        }
    }
}
Also used : IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST) ArgumentTypeException(org.matheclipse.core.eval.exception.ArgumentTypeException)

Example 3 with ArgumentTypeException

use of org.matheclipse.core.eval.exception.ArgumentTypeException in project symja_android_library by axkr.

the class ASTAssociation method prependRule.

/**
 * Adds the specified rule at the start of this association. Existing duplicate rule keys will be
 * replaced by the new rule at position 1.
 *
 * @param rule the rule to add at the end of this association
 * @return always true
 */
@Override
public final void prependRule(IExpr rule) {
    if (rule.isRuleAST()) {
        int value = getInt(rule.first());
        hashValue = 0;
        if (value != 0) {
            remove(value);
        }
        insertAt(1, rule);
    } else if (rule.isEmptyList()) {
    // ignore empty list entries
    } else {
        throw new ArgumentTypeException("rule expression expected instead of " + rule.toString());
    }
}
Also used : ArgumentTypeException(org.matheclipse.core.eval.exception.ArgumentTypeException)

Example 4 with ArgumentTypeException

use of org.matheclipse.core.eval.exception.ArgumentTypeException in project symja_android_library by axkr.

the class ASTAssociation method prependRules.

@Override
public void prependRules(IAST listOfRules, int startPosition, int endPosition) {
    if (listOfRules.isRuleAST()) {
        prependRule(listOfRules);
    } else {
        // iterate backwards for prepend
        for (int i = endPosition - 1; i >= startPosition; i--) {
            IExpr rule = listOfRules.getRule(i);
            if (rule.isAssociation()) {
                ASTAssociation assoc = (ASTAssociation) rule;
                for (int j = 1; j < assoc.size(); j++) {
                    rule = assoc.getRule(j);
                    prependRule(rule);
                }
            } else if (rule.isRuleAST()) {
                prependRule(rule);
            } else if (rule.isList()) {
                IAST list = (IAST) rule;
                prependRules(list, 1, list.size());
            } else {
                throw new ArgumentTypeException("rule expression expected instead of " + rule.toString());
            }
        }
    }
}
Also used : IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST) ArgumentTypeException(org.matheclipse.core.eval.exception.ArgumentTypeException)

Example 5 with ArgumentTypeException

use of org.matheclipse.core.eval.exception.ArgumentTypeException in project symja_android_library by axkr.

the class HypergeometricJS method hypergeometricSeries.

public static Complex hypergeometricSeries(Complex[] A, Complex[] B, Complex x) {
    // , double
    // tolerance
    // see https://github.com/paulmasson/math/issues/12
    Complex s = Complex.ONE;
    Complex p = Complex.ONE;
    int i = 0;
    while (Math.abs(p.getReal()) > Config.SPECIAL_FUNCTIONS_TOLERANCE || Math.abs(p.getImaginary()) > Config.SPECIAL_FUNCTIONS_TOLERANCE) {
        for (int j = 0; j < A.length; j++) {
            p = p.multiply(A[j]);
            A[j] = A[j].add(1.0);
        }
        for (int j = 0; j < B.length; j++) {
            p = p.divide(B[j]);
            B[j] = B[j].add(1.0);
        }
        p = p.multiply(x).divide(++i);
        s = s.add(p);
        if (i > 500) {
            throw new ArgumentTypeException("maximum iteration exceeded in hypergeometricSeries (Complex)");
        }
    }
    return s;
}
Also used : Complex(org.hipparchus.complex.Complex) ArgumentTypeException(org.matheclipse.core.eval.exception.ArgumentTypeException)

Aggregations

ArgumentTypeException (org.matheclipse.core.eval.exception.ArgumentTypeException)44 IExpr (org.matheclipse.core.interfaces.IExpr)24 IAST (org.matheclipse.core.interfaces.IAST)16 Complex (org.hipparchus.complex.Complex)11 ISymbol (org.matheclipse.core.interfaces.ISymbol)10 EvalEngine (org.matheclipse.core.eval.EvalEngine)6 UnaryNumerical (org.matheclipse.core.generic.UnaryNumerical)6 UnivariateDifferentiableFunction (org.hipparchus.analysis.differentiation.UnivariateDifferentiableFunction)5 ISignedNumber (org.matheclipse.core.interfaces.ISignedNumber)5 ArrayList (java.util.ArrayList)4 IASTAppendable (org.matheclipse.core.interfaces.IASTAppendable)4 DSFactory (org.hipparchus.analysis.differentiation.DSFactory)3 FiniteDifferencesDifferentiator (org.hipparchus.analysis.differentiation.FiniteDifferencesDifferentiator)3 Config (org.matheclipse.core.basic.Config)3 F (org.matheclipse.core.expression.F)3 IInteger (org.matheclipse.core.interfaces.IInteger)3 INum (org.matheclipse.core.interfaces.INum)3 BisectionSolver (org.hipparchus.analysis.solvers.BisectionSolver)2 LinearConstraint (org.hipparchus.optim.linear.LinearConstraint)2 Gamma (org.hipparchus.special.Gamma)2