Skip to content

Commit

Permalink
Improve HypergeometricXXX derivatives; implement NumericalSort
Browse files Browse the repository at this point in the history
  • Loading branch information
axkr committed Jul 30, 2023
1 parent cd1f585 commit cac89a6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -352,19 +352,26 @@ public IExpr evaluate(final IAST ast, EvalEngine engine) {
if (ast.isEvalFlagOn(IAST.IS_DERIVATIVE_EVALED)) {
return F.NIL;
}
IExpr xListN = xList.arg2();
if (xList.arg1().isList()) {
x = F.list(xList.arg1());
} else {
x = xList.arg1();
if (fx.isAST()) {
IAST derivativeN = createDerivativeN(fx.head(), (IAST) fx, x, xList.arg2());
if (xListN.isNegativeResult()
|| (!xListN.isInteger() && xListN.isNumericFunction())) {
// Multiple derivative specifier `1` does not have the form {variable, n} where n is
// a symbolic expression or a non-negative integer.
return IOFunctions.printMessage(S.D, "dvar", F.List(xList), engine);
}
IAST derivativeN = createDerivativeN(fx.head(), (IAST) fx, x, xListN);
IExpr derivativeNEvaled = engine.evaluateNIL(derivativeN);
if (derivativeNEvaled.isPresent()) {
return derivativeNEvaled;
}
}
}
IExpr arg2 = xList.arg2();
IExpr arg2 = xListN;
int n = arg2.toIntDefault();
if (n >= 0) {
IExpr temp = fx;
Expand Down Expand Up @@ -581,25 +588,25 @@ private static IExpr surd(final IAST function, IExpr x) {
private static IExpr hypergeometricPFQ(final IAST function, IExpr x) {
IAST list1 = (IAST) function.first();
IAST list2 = (IAST) function.second();
if (list1.isFree(x)&&list2.isFree(x)) {
IExpr arg3 = function.arg3();
if (list1.isEmpty() && list2.isEmpty()) {
return F.Times(F.Exp(arg3), F.D(arg3, x));
}
IExpr timesNumerator = list1.argSize() == 0 ? F.C1 : list1.apply(S.Times, 1);
IExpr timesDenominator = list2.argSize() == 0 ? F.C1 : list2.apply(S.Times, 1);
IASTAppendable newList1 = F.ListAlloc(list1.argSize());
if (list1.isFree(x) && list2.isFree(x)) {
IExpr arg3 = function.arg3();
if (list1.isEmpty() && list2.isEmpty()) {
return F.Times(F.Exp(arg3), F.D(arg3, x));
}
IExpr timesNumerator = list1.argSize() == 0 ? F.C1 : list1.apply(S.Times, 1);
IExpr timesDenominator = list2.argSize() == 0 ? F.C1 : list2.apply(S.Times, 1);
IASTAppendable newList1 = F.ListAlloc(list1.argSize());

for (int i = 1; i < list1.size(); i++) {
newList1.append(F.Plus(F.C1, list1.get(i)));
}
IASTAppendable newList2 = F.ListAlloc(list2.argSize());
for (int i = 1; i < list2.size(); i++) {
newList2.append(F.Plus(F.C1, list2.get(i)));
}
return F.Times(timesNumerator, F.Power(timesDenominator, F.CN1), //
F.HypergeometricPFQ(newList1, newList2, arg3), //
F.D(arg3, x));
for (int i = 1; i < list1.size(); i++) {
newList1.append(F.Plus(F.C1, list1.get(i)));
}
IASTAppendable newList2 = F.ListAlloc(list2.argSize());
for (int i = 1; i < list2.size(); i++) {
newList2.append(F.Plus(F.C1, list2.get(i)));
}
return F.Times(timesNumerator, F.Power(timesDenominator, F.CN1), //
F.HypergeometricPFQ(newList1, newList2, arg3), //
F.D(arg3, x));
}
return F.NIL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10931,6 +10931,9 @@ public void testHypergeometric1F1() {
}

public void testHypergeometric2F1() {
check("D( Hypergeometric2F1(a,b,c,x), {x,-4})", //
"D(Hypergeometric2F1(a,b,c,x),{x,-4})");

check("N(Hypergeometric2F1(1/2, 1/3, 2, 1), 50)", //
"1.1595952669639283657699920515700208819451652634397");
check("Hypergeometric2F1(1/2, 1/3, 2, 1.000000000000000000000000000000000)", //
Expand Down

0 comments on commit cac89a6

Please sign in to comment.