Skip to content

Commit

Permalink
bump apfloat from 1.13.0 to 1.14.0-SNAPSHOT
Browse files Browse the repository at this point in the history
- define polyLog
- mtommila/apfloat#47
  • Loading branch information
axkr committed Mar 11, 2024
1 parent 286f66d commit 526f80c
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1941,26 +1941,28 @@ public IExpr evaluate(final IAST ast, EvalEngine engine) {
@Override
public IExpr numericFunction(IAST ast, final EvalEngine engine) {
if (ast.argSize() == 2) {
IInexactNumber n = (IInexactNumber) ast.arg1();
IInexactNumber v = (IInexactNumber) ast.arg1();
IInexactNumber z = (IInexactNumber) ast.arg2();

IExpr temp = polyLogSymbolic(n, z);
IExpr temp = polyLogSymbolic(v, z);
if (temp.isPresent()) {
return temp;
}
// issue #929
// return v.polyLog(z);

if (engine.isDoubleMode()) {
try {
double nDouble = Double.NaN;
double xDouble = Double.NaN;
try {
nDouble = n.evalf();
nDouble = v.evalf();
xDouble = z.evalf();
} catch (ValidateException ve) {
}

if (Double.isNaN(nDouble) || Double.isNaN(xDouble)) {
Complex nComplex = n.evalfc();
Complex nComplex = v.evalfc();
Complex xComplex = z.evalfc();
return F.complexNum(ZetaJS.polyLog(nComplex, xComplex));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,15 @@ public IExpr polyGamma(long n) {
return IComplexNum.super.polyGamma(n);
}

@Override
public IExpr polyLog(IExpr arg2) {
if (arg2 instanceof INumber) {
return valueOf(
EvalEngine.getApfloat().polylog(fApcomplex, ((INumber) arg2).apcomplexValue()));
}
return IComplexNum.super.polyLog(arg2);
}

@Override
public IExpr pow(double value) {
return valueOf(EvalEngine.getApfloat().pow(fApcomplex, new Apfloat(value)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1285,6 +1285,23 @@ public IExpr polyGamma(long n) {
return INum.super.polyGamma(n);
}

@Override
public IExpr polyLog(IExpr arg2) {
if (arg2 instanceof IReal) {
try {
return valueOf(
EvalEngine.getApfloat().polylog(fApfloat, ((IReal) arg2).apfloatValue()));
} catch (ArithmeticException | ApfloatRuntimeException e) {
// try as computation with complex numbers
}
}
if (arg2 instanceof INumber) {
return F.complexNum(
EvalEngine.getApfloat().polylog(fApfloat, ((INumber) arg2).apcomplexValue()));
}
return INum.super.polyLog(arg2);
}

@Override
public ApfloatNum pow(double value) {
return valueOf(EvalEngine.getApfloat().pow(fApfloat, new Apfloat(value)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,16 @@ public IExpr polyGamma(long n) {
return IComplexNum.super.polyGamma(n);
}

@Override
public IExpr polyLog(IExpr arg2) {
if (arg2 instanceof INumber) {
Apcomplex polylog = EvalEngine.getApfloatDouble().polylog(apcomplexValue(),
((INumber) arg2).apcomplexValue());
return F.complexNum(polylog.real().doubleValue(), polylog.imag().doubleValue());
}
return IComplexNum.super.polyLog(arg2);
}

@Override
public IComplexNum pow(final IComplexNum val) {
if (Complex.equals(fComplex, Complex.ZERO, Config.DOUBLE_EPSILON)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,22 @@ public IExpr polyGamma(long n) {
return INum.super.polyGamma(n);
}


@Override
public IExpr polyLog(IExpr arg2) {
if (arg2 instanceof INumber) {
if (arg2 instanceof IReal) {
Apfloat polylog =
EvalEngine.getApfloatDouble().polylog(apfloatValue(), ((IReal) arg2).apfloatValue());
return F.num(polylog.doubleValue());
}
Apcomplex polylog = EvalEngine.getApfloatDouble().polylog(apfloatValue(),
((INumber) arg2).apcomplexValue());
return F.complexNum(polylog.real().doubleValue(), polylog.imag().doubleValue());
}
return INum.super.polyLog(arg2);
}

@Override
public Num pow(int n) {
return valueOf(Math.pow(value, n));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5692,6 +5692,10 @@ default IExpr polyGamma(long n) {
return F.NIL;
}

default IExpr polyLog(IExpr x) {
return F.NIL;
}

@Override
default IExpr pow(double n) {
return S.Power.of(this, F.num(n));
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7465,7 +7465,7 @@ public void testExpIntegralEi() {
checkNumeric("ExpIntegralEi(-1.0)", //
"-0.21938393439552029");
checkNumeric("ExpIntegralEi(1.0)", //
"1.895117816355937");
"1.8951178163559375");
check("ExpIntegralEi(I*Infinity)", //
"I*Pi");
check("ExpIntegralEi(-I*Infinity)", //
Expand Down Expand Up @@ -9652,7 +9652,7 @@ public void testFreeQ() {
@Test
public void testFresnelC() {
check("N(FresnelC(2),50)", //
"0.48825340607534075450022350335726103768836715450921");
"0.4882534060753407545002235033572610376883671545092");

check("FresnelC(1.8)", //
"0.333633");
Expand All @@ -9679,7 +9679,7 @@ public void testFresnelC() {
check("FresnelC(I*z)", //
"I*FresnelC(z)");
checkNumeric("FresnelC(1.8)", //
"0.3336329272215571");
"0.33363292722155713");

check("D(FresnelC(x),x)", //
"Cos(1/2*Pi*x^2)");
Expand Down Expand Up @@ -9714,7 +9714,7 @@ public void testFresnelS() {
check("FresnelS(I*z)", //
"-I*FresnelS(z)");
checkNumeric("FresnelS(1.8)", //
"0.45093876926758303");
"0.45093876926758314");
check("D(Fresnels(x),x)", //
"Sin(1/2*Pi*x^2)");
}
Expand Down Expand Up @@ -10264,7 +10264,7 @@ public void testFunctionURL() {
@Test
public void testGamma() {
check("Gamma(-9223372036854775808/11,-3.141592653589793,3/4)", //
"Gamma(-8.384883669867978*10^17,-3.141592653589793)-Gamma(-8.384883669867978*10^17,0.75)");
"-1.0032310722904763*10^104759677232087062");


check("Gamma(4,3)", //
Expand Down Expand Up @@ -10335,11 +10335,11 @@ public void testGamma() {
"Indeterminate");

checkNumeric("Gamma(1.5,7.5)", //
"0.00160996322827232");
"0.0016099632282723204");
checkNumeric("LogGamma(1.5)", //
"-0.12078223763524548");
checkNumeric("Gamma(0.5+0.5*-0.5, -0.5*-0.5)", //
"0.9293237832774184");
"0.9293237832774183");
check("Table(Gamma(-x+0.5*y, x*y), {x,-0.5, 0.5, 1/4}, {y,-0.5, 0.5, 1/4})", //
"{{0.929324,1.18798,1.77245,1.60979+I*(-0.423147),1.59749+I*(-0.372071)}," //
+ "{1.62343,1.91573,3.62561,2.00338+I*(-0.886162),1.77245+I*(-0.737708)}," //
Expand Down Expand Up @@ -12499,7 +12499,7 @@ public void testInverseErf() {
@Test
public void testInverseErfc() {
check("N(InverseErfc(33/100), 50)", //
"0.68880252811655645040250472890525783544948992349371");
"0.68880252811655645040250472890525783544948992349372");
check("InverseErfc(0.330000000000000000000000)", //
"0.688802528116556450402504");

Expand Down Expand Up @@ -18624,6 +18624,9 @@ public void testPolyLog() {
// issue #929
// check("(PolyLog(2,E^(I*1/270*Pi^2)))/Pi // N", //
// " ");
// check("PolyLog(2,0.9993319736282411 + 0.03654595031305655*I)", //
// "");

check("PolyLog(2,z) + PolyLog(2,1-z)", //
"Pi^2/6-Log(1-z)*Log(z)");
check("PolyLog(2,Sin(7)) + PolyLog(2,1-Sin(7))", //
Expand Down Expand Up @@ -23216,7 +23219,7 @@ public void testSinIntegral() {
@Test
public void testSinhIntegral() {
checkNumeric("SinhIntegral(-3.1)", //
"-5.318897351437731");
"-5.318897351437732");
check("SinhIntegral(93/13*I*x)", //
"I*SinIntegral(93/13*x)");
check("SinhIntegral(-x)", //
Expand Down Expand Up @@ -23992,7 +23995,7 @@ public void testSubfactorial() {
"True");

checkNumeric("Table(Subfactorial(x+I*y), {x,-2,2,0.5}, {y,-2 ,2,0.5})", //
"{{-9.227084993591351+I*226.34804545754852,-3.60341368902144+I*57.52215812828752,-1.4981325243711963+I*15.10153257973711,-0.6594078761887109+I*4.109712417378417,-0.30282511676493395+I*1.1557273497909215,-0.14180973765939986+I*0.3301098233309934,-0.06578326936162285+I*0.09168075208986826,-0.02922777135324635+I*0.022366556059606305,-0.011937189234760486+I*0.003341706779474045},{-224.51199155103046+I*33.783138994311265,-57.42494014380803+I*9.344563804698737,-15.326014503799536+I*2.5908324907783915,-4.324154363255359+I*0.6889085300780474,-1.3040986643465844+I*0.1523180276510737,-0.42007108938336646+I*0.008720205463217003,-0.1410130398831403+I*(-0.02117096465428944),-0.04657979136378597+I*(-0.020052290044888794),-0.0135786899199037+I*(-0.012819770339213575)},{-73.56847961607632+I*(-207.89387547036583),-21.43112760840351+I*(-52.11703759475536),-6.541027528670962+I*(-13.603400055365915),-2.0962132960874325+I*(-3.780008479284061),-0.6971748832350662+I*(-1.1557273497909215),-0.23112475035685875+I*(-0.40101469216069335),-0.06911140099201767+I*(-0.15746402145149108),-0.013305353757292544+I*(-0.06620821308947582),0.003386332944104408+I*(-0.027216085248995023)},{179.82227376413772+I*(-103.3592419198595),42.72931577895212+I*(-29.85265017649355),10.25383974267816+I*(-9.11009437436893),2.506531446666703+I*(-2.9928544643766957),0.6520493321732921+I*(-1.0761590138255368),0.20567544196007476+I*(-0.4222752237740536),0.09167748459585957+I*(-0.1736414758197678),0.05336833074922617+I*(-0.06882683304436397),0.03242888563837901+I*(-0.0226149374019086)},{119.70390458403307+I*147.13695923215263,33.1422220977232+I*32.146691412605264,9.537292577413355+I*6.541027528670962,2.9204731413233214+I*1.0481066480437162,1.0,0.4083869224311086+I*(-0.11556237517842938),0.20067793971526335+I*(-0.06911140099201767),0.10829561065534317+I*(-0.019958030635938814),0.05629961322969803+I*0.006772665888208815},{-116.80734695765014+I*124.1674870365595,-23.414317375264265+I*32.29747973318128,-3.98317450302985+I*8.331805702916647,-0.24316150885499624+I*2.060784425443652,0.3260246660866461+I*0.4619204930872316,0.3139753328670642+I*0.09957968544377244,0.21948021811769758+I*0.048070664949747925,0.12992441494115906+I*0.0546223706227867,0.0614443176230067+I*0.055417745307511694},{-121.51383247642643+I*(-92.27084993591352),-29.955519273225136+I*(-17.566641733979523),-7.062372526694953+I*(-2.9962650487423925),-1.3659509156201723+I*(-0.41212992261794434),0.0,0.25828853366956134+I*0.08863108603712493,0.22657542244350878+I*0.1315665387232457,0.12924936558812197+I*0.14248538534707594,0.0408868387215724+I*0.11937189234760487},{73.12395363664382+I*(-115.62573105462519),13.324743536875513+I*(-27.750082827187917),2.357043948371871+I*(-6.65980957537445),0.6656499494393316+I*(-1.5977199883723756),0.4890369991299692+I*(-0.30711926036915266),0.4211731565787101+I*0.09847761824842886,0.28114966222679844+I*0.24837229727854723,0.11295306647755853+I*0.2678368873247892,-0.01866901418051335+I*0.20414781047557296},{107.92229070008487+I*58.48596508102584,25.05677734243667+I*9.799995441878664,6.0196825306469695+I*1.0698424292101683,1.8725105884160347+I*(-0.14128438742580243),1.0,0.6801411006713222+I*0.3064064389090305,0.3647982244275441+I*0.4897084998900002,0.053753944176759445+I*0.47884481907633486,-0.15510266452035695+I*0.3205174621383546}}");
"{{-9.227084993591353+I*226.34804545754852,-3.6034136890214405+I*57.522158128287515,-1.498132524371197+I*15.10153257973711,-0.6594078761887111+I*4.109712417378417,-0.30282511676493384+I*1.1557273497909215,-0.14180973765939986+I*0.3301098233309934,-0.06578326936162285+I*0.09168075208986826,-0.02922777135324635+I*0.022366556059606305,-0.011937189234760486+I*0.003341706779474045},{-224.5119915510304+I*33.78313899431126,-57.42494014380803+I*9.344563804698737,-15.326014503799536+I*2.5908324907783915,-4.324154363255359+I*0.6889085300780474,-1.3040986643465842+I*0.15231802765107366,-0.42007108938336646+I*0.008720205463216996,-0.1410130398831403+I*(-0.02117096465428944),-0.04657979136378597+I*(-0.020052290044888794),-0.0135786899199037+I*(-0.012819770339213575)},{-73.56847961607632+I*(-207.89387547036583),-21.43112760840351+I*(-52.11703759475536),-6.541027528670962+I*(-13.603400055365915),-2.0962132960874325+I*(-3.780008479284061),-0.6971748832350664+I*(-1.1557273497909215),-0.2311247503568587+I*(-0.40101469216069335),-0.06911140099201767+I*(-0.15746402145149108),-0.013305353757292544+I*(-0.06620821308947582),0.003386332944104408+I*(-0.027216085248995023)},{179.82227376413772+I*(-103.3592419198595),42.72931577895212+I*(-29.85265017649355),10.25383974267816+I*(-9.11009437436893),2.506531446666703+I*(-2.9928544643766957),0.6520493321732921+I*(-1.0761590138255368),0.20567544196007476+I*(-0.4222752237740536),0.09167748459585957+I*(-0.1736414758197678),0.05336833074922617+I*(-0.06882683304436397),0.03242888563837901+I*(-0.0226149374019086)},{119.70390458403307+I*147.13695923215263,33.1422220977232+I*32.146691412605264,9.537292577413355+I*6.541027528670962,2.9204731413233214+I*1.0481066480437162,1.0,0.4083869224311086+I*(-0.11556237517842935),0.20067793971526335+I*(-0.06911140099201767),0.10829561065534317+I*(-0.019958030635938814),0.05629961322969803+I*0.006772665888208815},{-116.80734695765014+I*124.1674870365595,-23.414317375264265+I*32.29747973318128,-3.98317450302985+I*8.331805702916645,-0.24316150885499624+I*2.060784425443652,0.3260246660866461+I*0.4619204930872316,0.31397533286706414+I*0.09957968544377244,0.21948021811769758+I*0.048070664949747925,0.12992441494115903+I*0.054622370622786694,0.0614443176230067+I*0.055417745307511694},{-121.51383247642643+I*(-92.27084993591352),-29.955519273225136+I*(-17.566641733979523),-7.062372526694953+I*(-2.9962650487423925),-1.3659509156201723+I*(-0.41212992261794423),0.0,0.25828853366956134+I*0.08863108603712493,0.22657542244350878+I*0.13156653872324567,0.12924936558812197+I*0.14248538534707594,0.0408868387215724+I*0.11937189234760487},{73.12395363664382+I*(-115.62573105462519),13.324743536875513+I*(-27.750082827187917),2.357043948371871+I*(-6.65980957537445),0.6656499494393316+I*(-1.5977199883723756),0.4890369991299692+I*(-0.30711926036915266),0.4211731565787101+I*0.09847761824842886,0.28114966222679844+I*0.24837229727854723,0.11295306647755851+I*0.2678368873247892,-0.01866901418051335+I*0.20414781047557296},{107.92229070008484+I*58.48596508102583,25.05677734243667+I*9.799995441878664,6.0196825306469695+I*1.0698424292101683,1.8725105884160347+I*(-0.14128438742580243),1.0,0.680141100671322+I*0.3064064389090305,0.36479822442754406+I*0.4897084998900002,0.053753944176759445+I*0.47884481907633486,-0.15510266452035695+I*0.3205174621383546}}");

// check("Subfactorial(10000)", "Subfactorial(10000)");
}
Expand Down
2 changes: 1 addition & 1 deletion symja_android_library/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@
<dependency>
<groupId>org.apfloat</groupId>
<artifactId>apfloat</artifactId>
<version>1.13.0</version>
<version>1.14.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.codehaus.janino</groupId>
Expand Down

0 comments on commit 526f80c

Please sign in to comment.