Math Is Fun Forum

  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#1 2025-03-06 22:39:27

lanxiyu
Member
Registered: 2022-05-10
Posts: 62

Mathematica implementation of Eisenstein series

BeginPackage["EisensteinE`"];

Unprotect[EisensteinE];

ClearAll[EisensteinE];

Begin["`Private`"];

EisensteinE[2, q_] /; InexactNumberQ[q] && Abs[q] < 1 :=
Block[{q2 = q^2, qn = -1, qn2 = 1, a = 1, b = 1, k = 1, t},
	While[qn *= q2; qn2 *= qn; k += 2; t = a + k^3*qn2; b += k*qn2; t != a, a = t];
	t / b
];

EisensteinE[n_, q_] /; EvenQ[n] && n >= 4 && InexactNumberQ[q] && Abs[q] < 1 :=
Block[{q2 = q^2, qn = 1, k = 1, r = n - 1, s = 0, t},
	While[qn *= q2; t = s + k^r*qn/(1 - qn); k++; t != s, s = t];
	1 - 2*n*t/BernoulliB[n]
];

End[];

SetAttributes[EisensteinE, {Listable, NHoldFirst, NumericFunction, ReadProtected}];

Protect[EisensteinE];

EndPackage[];

Test cases:

Module[{q},
q = RandomReal[WorkingPrecision -> 50];
On[Assert];
Assert[ResourceFunction["EisensteinE"][#, q] == EisensteinE[#, q]] & /@ Range[2,8,2];
];

Last edited by lanxiyu (2025-03-06 23:12:53)

Offline

#2 2025-03-07 00:26:17

ktesla39
Member
From: Nepal
Registered: 2024-10-08
Posts: 108
Website

Re: Mathematica implementation of Eisenstein series

Which language is it?


"Talent hits the target no one else can hit. Genius hits the target no one else can see." - Arthur Schopenhauer

Offline

Board footer

Powered by FluxBB