static ScalarValue DiLog1(ScalarValue e) { ScalarValue f = new ScalarValue(Math.PI * Math.PI / 6.0); if (e == 0.0) { return(f); } var L = e.Ln(); var ek = ScalarValue.One; for (int k = 1; k < 250; k++) { var f_old = f.Clone(); ek *= e; var df = ek * (L - 1.0 / k) / k; f += df; if (f == f_old) { return(f); } } throw new YAMPNotConvergedException("spence"); }
// series useful for large x static ScalarValue SeriesLarge(ScalarValue x) { var L1 = x.Ln(); var L2 = L1.Ln(); var L2L1 = L2 / L1; return L1 - L2 + L2L1 + (L2 - 2.0) * L2L1 / L1 / 2.0; }
static ScalarValue LogGamma_Stirling(ScalarValue z) { if (z.Im < 0.0) { return(LogGamma_Stirling(z.Conjugate()).Conjugate()); } var f = (z - 0.5) * z.Ln() - z + Math.Log(2.0 * Math.PI) / 2.0; var reduce = f.Im / (2.0 * Math.PI); reduce = f.Im - (int)(reduce) * 2.0 * Math.PI; f = new ScalarValue(f.Re, reduce); var zsqu = z * z; var zp = z.Clone(); for (var i = 1; i < 10; i++) { var f_old = f.Clone(); f += Helpers.BernoulliNumbers[i] / (2 * i) / (2 * i - 1) / zp; if (f == f_old) { return(f); } zp = zp * zsqu; } throw new YAMPNotConvergedException("gamma"); }
// series useful for large x static ScalarValue SeriesLarge(ScalarValue x) { var L1 = x.Ln(); var L2 = L1.Ln(); var L2L1 = L2 / L1; return(L1 - L2 + L2L1 + (L2 - 2.0) * L2L1 / L1 / 2.0); }
static ScalarValue LanczosLogGamma(ScalarValue z) { ScalarValue sum = new ScalarValue(Helpers.LanczosD[0], 0.0); for (int i = 1; i < Helpers.LanczosD.Length; i++) { sum += Helpers.LanczosD[i] / (z + i); } sum = (2.0 / Math.Sqrt(Math.PI)) * (sum / z); var zshift = z + 0.5; var t = zshift * (zshift + Helpers.LanczosR).Ln() - z; return(t + sum.Ln()); }
static ScalarValue DiLog_Log_Series(ScalarValue z) { var ln = z.Ln(); var ln2 = ln * ln; var f = Math.PI * Math.PI / 6.0 + ln * (1.0 - (-ln).Ln()) - ln2 / 4.0; var p = ln.Clone(); for (int k = 1; k < 17; k++) { var f_old = f.Clone(); p *= ln2 / (2 * k + 1) / (2 * k); f += (-Helpers.BernoulliNumbers[k] / (2 * k)) * p; if (f == f_old) { return(f); } } throw new YAMPNotConvergedException("spence"); }
protected override ScalarValue GetValue(ScalarValue value) { return value.Ln(); }
static ScalarValue LogGamma_Stirling(ScalarValue z) { if (z.Im < 0.0) { return LogGamma_Stirling(z.Conjugate()).Conjugate(); } var f = (z - 0.5) * z.Ln() - z + Math.Log(2.0 * Math.PI) / 2.0; var reduce = f.Im / (2.0 * Math.PI); reduce = f.Im - (int)(reduce) * 2.0 * Math.PI; f = new ScalarValue(f.Re, reduce); var zsqu = z * z; var zp = z.Clone(); for (var i = 1; i < 10; i++) { var f_old = f.Clone(); f += Helpers.BernoulliNumbers[i] / (2 * i) / (2 * i - 1) / zp; if (f == f_old) { return (f); } zp = zp * zsqu; } throw new YAMPNotConvergedException("gamma"); }
static ScalarValue LanczosLogGamma(ScalarValue z) { ScalarValue sum = new ScalarValue(Helpers.LanczosD[0], 0.0); for (int i = 1; i < Helpers.LanczosD.Length; i++) sum += Helpers.LanczosD[i] / (z + i); sum = (2.0 / Math.Sqrt(Math.PI)) * (sum / z); var zshift = z + 0.5; var t = zshift * (zshift + Helpers.LanczosR).Ln() - z; return t + sum.Ln(); }
static ScalarValue DiLog1(ScalarValue e) { var f = new ScalarValue(Math.PI * Math.PI / 6.0); if (e == 0.0) { return f; } var L = e.Ln(); var ek = ScalarValue.One; for (var k = 1; k < 250; k++) { var f_old = f.Clone(); ek *= e; var df = ek * (L - 1.0 / k) / k; f += df; if (f == f_old) { return f; } } throw new YAMPNotConvergedException("spence"); }
static ScalarValue DiLog_Log_Series(ScalarValue z) { var ln = z.Ln(); var ln2 = ln * ln; var f = Math.PI * Math.PI / 6.0 + ln * (1.0 - (-ln).Ln()) - ln2 / 4.0; var p = ln.Clone(); for (var k = 1; k < 17; k++) { var f_old = f.Clone(); p *= ln2 / (2 * k + 1) / (2 * k); f += (-Helpers.BernoulliNumbers[k] / (2 * k)) * p; if (f == f_old) { return f; } } throw new YAMPNotConvergedException("spence"); }
protected override ScalarValue GetValue(ScalarValue value) { return(value.Ln()); }