diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/SpecialFunctions.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/SpecialFunctions.java index 418441aae..37ddd07c5 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/SpecialFunctions.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/SpecialFunctions.java @@ -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; @@ -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()) { diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/ApcomplexNum.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/ApcomplexNum.java index 267994bef..524eb1554 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/ApcomplexNum.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/ApcomplexNum.java @@ -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 */ diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/ComplexNum.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/ComplexNum.java index 618f8ddc8..745795531 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/ComplexNum.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/ComplexNum.java @@ -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() { diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/ComplexSym.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/ComplexSym.java index ed2cecb2a..a84552c06 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/ComplexSym.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/ComplexSym.java @@ -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} */ diff --git a/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/GammaBetaErfTest.java b/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/GammaBetaErfTest.java index 155a8ca26..68f5d02a5 100644 --- a/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/GammaBetaErfTest.java +++ b/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/GammaBetaErfTest.java @@ -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"); @@ -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");