use of org.matheclipse.core.eval.exception.ArgumentTypeException in project symja_android_library by axkr.
the class HypergeometricJS method hypergeometric0F1.
// public static Complex hypergeometric0F1(Complex a, Complex x) {
// return hypergeometric0F1(a, x, Config.SPECIAL_FUNCTIONS_TOLERANCE);
// }
public static Complex hypergeometric0F1(Complex a, Complex x) {
final double useAsymptotic = 100;
if (a.isMathematicalInteger() && a.getReal() <= 0) {
throw new ArgumentTypeException("hypergeometric function pole");
}
// asymptotic form as per Johansson
if (x.norm() > useAsymptotic) {
// transform variables for convenience
Complex b = a.multiply(2).subtract(1);
a = a.subtract(0.5);
x = x.sqrt().multiply(4.0);
// copied from hypergeometric1F1
Complex t1 = Arithmetic.lanczosApproxGamma(b).multiply(x.negate().pow(a.negate())).multiply(Arithmetic.lanczosApproxGamma(b.subtract(a)).reciprocal());
t1 = t1.multiply(hypergeometric2F0(a, a.add(b.negate()).add(1), new Complex(-1.0).divide(x)));
Complex t2 = Arithmetic.lanczosApproxGamma(b).multiply(x.pow(a.subtract(b))).multiply(x.exp()).multiply(Arithmetic.lanczosApproxGamma(a).reciprocal());
t2 = t2.multiply(hypergeometric2F0(b.subtract(a), Complex.ONE.subtract(a), Complex.ONE.divide(x)));
return x.divide(-2.0).exp().multiply(t1.add(t2));
}
Complex s = Complex.ONE;
Complex p = Complex.ONE;
long i = 1;
long iterationLimit = EvalEngine.get().getIterationLimit();
while (Math.abs(p.getReal()) > Config.SPECIAL_FUNCTIONS_TOLERANCE || Math.abs(p.getImaginary()) > Config.SPECIAL_FUNCTIONS_TOLERANCE) {
p = p.multiply(x).multiply(a.reciprocal()).divide(i);
s = s.add(p);
a = a.add(1);
if (i++ > iterationLimit && iterationLimit > 0) {
IterationLimitExceeded.throwIt(i, S.Hypergeometric0F1);
}
}
return s;
}
use of org.matheclipse.core.eval.exception.ArgumentTypeException in project symja_android_library by axkr.
the class IntervalSym method normalizeArgument.
/**
* If the argument is a list of 2 elements, try sorting the elements. If the argument is not a
* list return a new <code>{argOfIntervalList, argOfIntervalList]</code>
*
* @param arg
* @param engine
* @return
*/
private static IAST normalizeArgument(final IExpr arg, final EvalEngine engine) {
if (arg.isList()) {
if (arg.size() == 3) {
IAST list = (IAST) arg;
IExpr arg1 = list.arg1();
IExpr arg2 = list.arg2();
if (arg1.isReal() && arg2.isReal()) {
if (arg1.greaterThan(arg2).isTrue()) {
return F.list(arg2, arg1);
}
return F.NIL;
}
IExpr min = arg1.isNumber() ? arg1 : engine.evaluate(arg1);
IExpr max = arg2.isNumber() ? arg2 : engine.evaluate(arg2);
if (min.isRealResult() && max.isRealResult()) {
if (min.greaterThan(max).isTrue()) {
return F.list(max, min);
}
}
return F.NIL;
}
// The expression `1` is not a valid interval.
String str = IOFunctions.getMessage("nvld", F.list(arg), engine);
throw new ArgumentTypeException(str);
}
if (arg instanceof INum) {
if (arg instanceof ApfloatNum) {
Apfloat apfloat = ((ApfloatNum) arg).fApfloat;
Apfloat[] values = interval(apfloat);
return //
F.list(//
F.num(values[0]), F.num(values[1]));
}
double value = ((ISignedNumber) arg).doubleValue();
return //
F.list(//
F.num(Math.nextDown(value)), F.num(Math.nextUp(value)));
}
return F.list(arg, arg);
}
use of org.matheclipse.core.eval.exception.ArgumentTypeException in project symja_android_library by axkr.
the class Symbol method reassignSymbolValue.
/**
* {@inheritDoc}
*/
@Override
public IExpr[] reassignSymbolValue(IASTMutable ast, ISymbol functionSymbol, EvalEngine engine) {
if (hasAssignedSymbolValue()) {
IExpr[] result = new IExpr[2];
result[0] = fValue;
// if (fReferences > 0 && result[0].isAST()) {
// result[0] = ((IAST) result[0]).copy();
// }
ast.set(1, result[0]);
// 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 AbstractAST method toDoubleMatrix.
/**
* {@inheritDoc}
*/
@Override
public double[][] toDoubleMatrix() {
int[] dim = isMatrix();
if (dim == null) {
return null;
}
try {
double[][] result = new double[dim[0]][dim[1]];
ISignedNumber signedNumber;
for (int i = 1; i <= dim[0]; i++) {
IAST row = (IAST) get(i);
for (int j = 1; j <= dim[1]; j++) {
signedNumber = row.get(j).evalReal();
if (signedNumber != null) {
result[i - 1][j - 1] = signedNumber.evalDouble();
} else {
return null;
}
}
}
return result;
} catch (ArgumentTypeException rex) {
//
}
return null;
}
use of org.matheclipse.core.eval.exception.ArgumentTypeException in project symja_android_library by axkr.
the class ASTAssociation method appendRule.
/**
* Adds the specified rule at the end of this association.Existing duplicate rule keys will be
* replaced by the new rule.
*
* @param rule the rule to add at the end of this association
*/
@Override
public final void appendRule(IExpr rule) {
int index = size();
if (rule.isRuleAST()) {
int value = getInt(rule.first());
if (value == 0) {
append(rule);
keyToIndexMap.assoc(rule.first(), index++);
} else {
set(value, rule);
}
} else if (rule.isEmptyList()) {
// ignore empty list entries
} else {
throw new ArgumentTypeException("rule expression expected instead of " + rule.toString());
}
}
Aggregations