Skip to content

Commit

Permalink
Improve PolyGamma(n,0) for negative n
Browse files Browse the repository at this point in the history
  • Loading branch information
axkr committed Sep 11, 2024
1 parent 9ee01ba commit 6d1219c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import org.matheclipse.core.interfaces.IInexactNumber;
import org.matheclipse.core.interfaces.IInteger;
import org.matheclipse.core.interfaces.INum;
import org.matheclipse.core.interfaces.INumber;
import org.matheclipse.core.interfaces.IRational;
import org.matheclipse.core.interfaces.IReal;
import org.matheclipse.core.interfaces.ISymbol;
Expand Down Expand Up @@ -1724,15 +1725,17 @@ public IExpr evaluate(final IAST ast, EvalEngine engine) {
return F.CComplexInfinity;
}
}
if (arg2.isZero() && arg1.isNumber()) {
IReal realPart = ((INumber) arg1).re();
if (realPart.isLT(F.CN1)) {
// https://github.com/mtommila/apfloat/issues/54
// https://functions.wolfram.com/GammaBetaErf/PolyGamma2/03/01/01/0002/
return F.C0;
}
}
if (engine.isNumericMode()) {
if (arg1.isZero()) {
return arg2.digamma();
// if (arg2 instanceof ApfloatNum) {
// return e1ApfloatArg(((ApfloatNum) arg2).apfloatValue());
// }
// if (arg2 instanceof ApcomplexNum) {
// return e1ApcomplexArg(((ApcomplexNum) arg2).apcomplexValue());
// }
}
long n = arg1.toLongDefault();
if (n != Long.MIN_VALUE && arg2.isNumber()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,11 +525,8 @@ public ComplexNum complexNumValue() {

@Override
public int complexSign() {
final int i = fApcomplex.real().signum();
if (i == 0) {
return fApcomplex.imag().signum();
}
return i;
final int signum = fApcomplex.real().signum();
return (signum == 0) ? fApcomplex.imag().signum() : signum;
}

/** @return */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,11 +577,8 @@ public ComplexNum complexNumValue() {

@Override
public int complexSign() {
final int i = (int) Math.signum(fComplex.getReal());
if (i == 0) {
return (int) Math.signum(fComplex.getImaginary());
}
return i;
final int signum = (int) Math.signum(fComplex.getReal());
return (signum == 0) ? (int) Math.signum(fComplex.getImaginary()) : signum;
}

public Complex complexValue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,8 @@ public ComplexNum complexNumValue() {

@Override
public int complexSign() {
final int i = fReal.numerator().complexSign();

if (i == 0) {
return fImaginary.numerator().complexSign();
}

return i;
final int signum = fReal.numerator().complexSign();
return (signum == 0) ? fImaginary.numerator().complexSign() : signum;
}

/** {@inheritDoc} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1237,8 +1237,16 @@ public void testPolyGamma() {
// TODO
check("N(PolyGamma(-2,3/2),30)", //
"PolyGamma(-2,1.5)");
check("N(PolyGamma(-I*1.0,0),30)", //
"PolyGamma(I*(-1),0)");
// TODO calculate for complex n:
checkNumeric("PolyGamma(6+I,2.5+3*I)", //
"PolyGamma(6.0+I*1.0,2.5+I*3.0)");

check("N(PolyGamma(-2,0),30)", //
"PolyGamma(-2,0)");
"0");
check("N(PolyGamma(-2-I*1,0),30)", //
"0");

check("PolyGamma(0,-42)", //
"ComplexInfinity");
Expand All @@ -1257,10 +1265,10 @@ public void testPolyGamma() {
check("PolyGamma(-2)", //
"ComplexInfinity");

// TODO calculate for complex n:
checkNumeric("PolyGamma(6 + I, 2.5 + 3 I)", //
"PolyGamma(6.0+I*1.0,2.5+I*3.0)");

checkNumeric("PolyGamma(-2.5 + 3*I)", //
"1.4452083452957394+I*2.358508608801951");
checkNumeric("PolyGamma(2.5 + 3*I)", //
"1.2812739190662312+I*0.9798053153445596");

checkNumeric("PolyGamma(0, 0.166667)", //
"-6.332115068746184");
Expand Down

0 comments on commit 6d1219c

Please sign in to comment.