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");
}
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());
}
}
}
}
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());
}
}
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());
}
}
}
}
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;
}
Aggregations