[{"id":247152,"date":"2026-06-11T08:14:26","date_gmt":"2026-06-11T13:14:26","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=247152"},"modified":"2026-06-11T08:14:26","modified_gmt":"2026-06-11T13:14:26","slug":"prolog-claude","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/06\/11\/prolog-claude\/","title":{"rendered":"Solving a chess puzzle with Claude and Prolog"},"content":{"rendered":"<p>Prolog is the original logic programming language. The name comes from <span style=\"text-decoration: underline;\">pro<\/span>gramming in <span style=\"text-decoration: underline;\">log<\/span>ic. More specifically, the name comes from <em><span lang=\"fr\"><span style=\"text-decoration: underline;\">pro<\/span>grammation en <span style=\"text-decoration: underline;\">log<\/span>ique<\/span><\/em> because the inventor of the language, Philippe Roussel, is French.<\/p>\n<p>Prolog has its advantages and disadvantages. One of the advantages is that the language represents logical problems directly. One of the disadvantages is that the syntax can be quirky. But if an LLM is writing the code, or at least helping to write the code, the syntax doesn&#8217;t matter so much.<\/p>\n<p>I wanted to see how well Claude (Sonnet 4.6, medium effort) could solve a <a href=\"https:\/\/www.johndcook.com\/blog\/2025\/05\/14\/another-little-chess-puzzle\/\">chess puzzle<\/a> by Martin Gardner that I wrote about a little over a year ago. I chose a relatively obscure problem rather than something like the Eight Queens puzzle because an LLM could simply quote one of countless articles on the puzzle.<\/p>\n<h2>The puzzle<\/h2>\n<p>As I stated in the post last year, the task is to place two rooks, two bishops, and two knights on a 4 by 4 chessboard so that no piece attacks any other.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium\" src=\"https:\/\/www.johndcook.com\/crowded5.png\" width=\"297\" height=\"250\" \/><\/p>\n<p>There are two basic solutions, twelve if you count rotations and reflections as different solutions.<\/p>\n<h2>Prolog results<\/h2>\n<p>Claude wrote an SWI-Prolog program that I ran with<\/p>\n<pre>\r\nswipl -g \"run, halt\" chess_placement.pl\r\n<\/pre>\n<p>and it gave the following output.<\/p>\n<pre>\r\nTotal solutions (raw): 12\r\nSolutions up to D4 symmetry: 2\r\nSolutions up to D4 symmetry: 2\r\n\r\nSolution 1:\r\nB . . N\r\nN . . B\r\n. R . .\r\n. . R .\r\n\r\nSolution 2:\r\n. B N .\r\n. . . R\r\nR . . .\r\n. N B .\r\n<\/pre>\n<p>Claude made a nice image of the solutions.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.johndcook.com\/claude_chess_solution.svg\" width=\"536\" height=\"300\" class=\"aligncenter size-medium\" \/><\/p>\n<p>Note that you can make eight variations of the first solution by a combination of rotations and flips. There are only four variations of the second solution because two rotations put you back where you started.<\/p>\n<h2>Prolog source<\/h2>\n<p>Here&#8217;s the Prolog code that Claude generated.<\/p>\n<pre>\r\n% ============================================================\r\n%  Non-attacking placement of 2 Rooks, 2 Bishops, 2 Knights\r\n%  on a 4x4 chessboard\r\n%\r\n%  Run with SWI-Prolog:\r\n%    swipl -g \"run, halt\" chess_placement.pl\r\n%\r\n%  Or interactively:\r\n%    swipl chess_placement.pl\r\n%    ?- run.\r\n%    ?- count_solutions(N).\r\n%    ?- count_unique(N).\r\n% ============================================================\r\n\r\n:- use_module(library(lists)).\r\n\r\n% ---- Board squares: (Row, Col) with Row, Col in 0..3 ----------------\r\n\r\nsquare(R, C) :- member(R, [0,1,2,3]), member(C, [0,1,2,3]).\r\n\r\n% ---- Attack predicates ----------------------------------------------\r\n\r\nrook_attacks(R,_,R,_).          % same row\r\nrook_attacks(_,C,_,C).          % same column\r\n\r\nbishop_attacks(R1,C1,R2,C2) :-\r\n    DR is abs(R1-R2), DC is abs(C1-C2),\r\n    DR =:= DC, DR > 0.\r\n\r\nknight_attacks(R1,C1,R2,C2) :-\r\n    DR is abs(R1-R2), DC is abs(C1-C2),\r\n    ( DR =:= 1, DC =:= 2 ; DR =:= 2, DC =:= 1 ).\r\n\r\n% attacks(+Type1, +R1, +C1, +Type2, +R2, +C2)\r\n% True if either piece threatens the other's square.\r\nattacks(rook,   R1,C1, _,     R2,C2) :- rook_attacks(R1,C1,R2,C2).\r\nattacks(_,      R1,C1, rook,  R2,C2) :- rook_attacks(R1,C1,R2,C2).\r\nattacks(bishop, R1,C1, _,     R2,C2) :- bishop_attacks(R1,C1,R2,C2).\r\nattacks(_,      R1,C1, bishop,R2,C2) :- bishop_attacks(R1,C1,R2,C2).\r\nattacks(knight, R1,C1, _,     R2,C2) :- knight_attacks(R1,C1,R2,C2).\r\nattacks(_,      R1,C1, knight,R2,C2) :- knight_attacks(R1,C1,R2,C2).\r\n\r\n% ---- All pairs safe -------------------------------------------------\r\n\r\n% Check all unordered pairs in a list.\r\nno_attack_pair(_, []).\r\nno_attack_pair(T1-(R1,C1), [T2-(R2,C2)|Rest]) :-\r\n    \\+ attacks(T1,R1,C1,T2,R2,C2),\r\n    no_attack_pair(T1-(R1,C1), Rest).\r\n\r\nall_pairs_safe([]).\r\nall_pairs_safe([P|Rest]) :-\r\n    no_attack_pair(P, Rest),\r\n    all_pairs_safe(Rest).\r\n\r\n% ---- Generate a placement -------------------------------------------\r\n%\r\n%  Placement = [rook-(R1,C1), rook-(R2,C2),\r\n%               bishop-(R3,C3), bishop-(R4,C4),\r\n%               knight-(R5,C5), knight-(R6,C6)]\r\n%\r\n%  We enforce an ordering within each pair to avoid counting\r\n%  same-type duplicates (rook1 vs rook2 swapped).\r\n%  Squares are represented canonically: (R,C) with R*4+C as index.\r\n\r\nsq_index(R, C, I) :- I is R*4 + C.\r\n\r\nplacement(Placement) :-\r\n    % --- Rooks ---\r\n    square(R1r, C1r), square(R2r, C2r),\r\n    sq_index(R1r,C1r,I1r), sq_index(R2r,C2r,I2r),\r\n    I1r < I2r,          % canonical order for the two rooks\r\n\r\n    % --- Bishops ---\r\n    square(R1b, C1b), square(R2b, C2b),\r\n    sq_index(R1b,C1b,I1b), sq_index(R2b,C2b,I2b),\r\n    I1b < I2b,          % canonical order for the two bishops\r\n\r\n    % --- Knights ---\r\n    square(R1n, C1n), square(R2n, C2n),\r\n    sq_index(R1n,C1n,I1n), sq_index(R2n,C2n,I2n),\r\n    I1n < I2n,          % canonical order for the two knights\r\n\r\n    % --- All six squares distinct ---\r\n    Squares = [(R1r,C1r),(R2r,C2r),(R1b,C1b),(R2b,C2b),(R1n,C1n),(R2n,C2n)],\r\n    all_distinct_squares(Squares),\r\n\r\n    % --- Build placement list ---\r\n    Placement = [ rook-(R1r,C1r),   rook-(R2r,C2r),\r\n                  bishop-(R1b,C1b), bishop-(R2b,C2b),\r\n                  knight-(R1n,C1n), knight-(R2n,C2n) ],\r\n\r\n    % --- No piece attacks any other ---\r\n    all_pairs_safe(Placement).\r\n\r\nall_distinct_squares([]).\r\nall_distinct_squares([S|Rest]) :-\r\n    \\+ member(S, Rest),\r\n    all_distinct_squares(Rest).\r\n\r\n% ---- Count all solutions --------------------------------------------\r\n\r\ncount_solutions(N) :-\r\n    findall(P, placement(P), Ps),\r\n    length(Ps, N),\r\n    format(\"Total solutions (raw): ~w~n\", [N]).\r\n\r\n% ---- D4 symmetry transformations on a 4x4 board ---------------------\r\n%  Squares (R,C) in 0..3\r\n\r\ntransform(identity, R, C, R,  C).\r\ntransform(rot90,    R, C, C,  Nr) :- Nr is 3-R.\r\ntransform(rot180,   R, C, Nr, Nc) :- Nr is 3-R, Nc is 3-C.\r\ntransform(rot270,   R, C, Nc, R)  :- Nc is 3-C.\r\ntransform(flipH,    R, C, R,  Nc) :- Nc is 3-C.\r\ntransform(flipV,    R, C, Nr, C)  :- Nr is 3-R.\r\ntransform(flipD1,   R, C, C,  R).\r\ntransform(flipD2,   R, C, Nr, Nc) :- Nr is 3-C, Nc is 3-R.\r\n\r\napply_transform(_, [], []).\r\napply_transform(T, [Type-(R,C)|Rest], [Type-(NR,NC)|TRest]) :-\r\n    transform(T, R, C, NR, NC),\r\n    apply_transform(T, Rest, TRest).\r\n\r\n% Canonical form: sort pieces within same-type pairs, then sort the\r\n% whole list to get a unique representative.\r\ncanonical_placement(Placement, Canonical) :-\r\n    findall(T, member(T,[identity,rot90,rot180,rot270,\r\n                          flipH,flipV,flipD1,flipD2]), Ts),\r\n    maplist(transform_and_sort(Placement), Ts, AllForms),\r\n    msort(AllForms, Sorted),\r\n    Sorted = [Canonical|_].\r\n\r\ntransform_and_sort(Placement, T, Sorted) :-\r\n    apply_transform(T, Placement, TPl),\r\n    msort(TPl, Sorted).\r\n\r\n% ---- Count solutions up to D4 symmetry ------------------------------\r\n\r\ncount_unique(N) :-\r\n    findall(P, placement(P), Ps),\r\n    maplist(canonical_placement, Ps, Canonicals),\r\n    list_to_set(Canonicals, Unique),\r\n    length(Unique, N),\r\n    format(\"Solutions up to D4 symmetry: ~w~n\", [N]).\r\n\r\n% ---- Pretty-print a board -------------------------------------------\r\n\r\nprint_board(Placement) :-\r\n    forall(member(R, [0,1,2,3]),\r\n           print_row(R, Placement)),\r\n    nl.\r\n\r\nprint_row(R, Placement) :-\r\n    forall(member(C, [0,1,2,3]),\r\n           print_cell(R, C, Placement)),\r\n    nl.\r\n\r\nprint_cell(R, C, Placement) :-\r\n    (   member(rook-(R,C),   Placement) -> write('R ')\r\n    ;   member(bishop-(R,C), Placement) -> write('B ')\r\n    ;   member(knight-(R,C), Placement) -> write('N ')\r\n    ;   write('. ')\r\n    ).\r\n\r\n% ---- Print all unique solutions -------------------------------------\r\n\r\nprint_unique_solutions :-\r\n    findall(P, placement(P), Ps),\r\n    maplist(canonical_placement, Ps, Canonicals),\r\n    list_to_set(Canonicals, Unique),\r\n    length(Unique, N),\r\n    format(\"~nSolutions up to D4 symmetry: ~w~n~n\", [N]),\r\n    forall(nth1(I, Unique, Sol),\r\n           ( format(\"Solution ~w:~n\", [I]),\r\n             print_board(Sol) )).\r\n\r\n% ---- Top-level entry point ------------------------------------------\r\n\r\nrun :-\r\n    count_solutions(Raw),\r\n    count_unique(Sym),\r\n    format(\"~n\"),\r\n    print_unique_solutions,\r\n    format(\"Summary: ~w raw solutions, ~w up to D4 symmetry.~n\",\r\n           [Raw, Sym]).\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Prolog is the original logic programming language. The name comes from programming in logic. More specifically, the name comes from programmation en logique because the inventor of the language, Philippe Roussel, is French. Prolog has its advantages and disadvantages. One of the advantages is that the language represents logical problems directly. One of the disadvantages [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[5],"tags":[33,150,108],"class_list":["post-247152","post","type-post","status-publish","format-standard","hentry","category-computing","tag-chess","tag-logic","tag-programming"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/comments?post=247152"}],"version-history":[{"count":3,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247152\/revisions"}],"predecessor-version":[{"id":247157,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247152\/revisions\/247157"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=247152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=247152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=247152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":247144,"date":"2026-06-10T18:11:01","date_gmt":"2026-06-10T23:11:01","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=247144"},"modified":"2026-06-11T07:35:14","modified_gmt":"2026-06-11T12:35:14","slug":"claude-and-lean","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/06\/10\/claude-and-lean\/","title":{"rendered":"Formally proving a calculation with Claude and Lean"},"content":{"rendered":"<p>I ran an experiment today to see whether Claude [1] could generate Lean code to prove a calculation at the bottom of <a href=\"https:\/\/www.johndcook.com\/blog\/2026\/06\/06\/from-kepler-to-bessel\/\">this post<\/a>, six lines of calculus.<\/p>\n<p>I started with this prompt<\/p>\n<p style=\"padding-left: 40px;\">This page contains a mathematical proof that a Fourier coefficient, a_n, is given in terms of a Bessel function. The LaTeX source for the SVG image is contained in the alt tag of the image. Generate a formal proof of the result using Lean.<\/p>\n<p>and give it the URL of the post. It produced a proof without any further input, but the proof wouldn&#8217;t build.<\/p>\n<p>I pasted in the error messages and let Claude try to fix the proof, deliberately not giving it any help other than pasting in error messages. It took eight iterations, but eventually it worked.<\/p>\n<p>There were four places in the proof marked &#8220;sorry,&#8221; which Claude explained as follows.<\/p>\n<p style=\"padding-left: 40px;\"><b>Why the <code>sorry<\/code>s?<\/b><\/p>\n<p style=\"padding-left: 40px;\">Real.besselJ definition or a <code>Kepler<\/code> namespace. The three remaining <code>sorry<\/code>s correspond to <strong>standard analysis lemmas<\/strong> (IBP and change-of-variables) that exist in Mathlib under <code>intervalIntegral<\/code> \u2014 the file cites the exact lemma names needed to close each one. This is the accepted style for &#8220;roadmap&#8221; Lean proofs ahead of library coverage.<\/p>\n<p>The full proof is given below.<\/p>\n<pre>\/-\r\n  KeplerBessel.lean\r\n  =================\r\n  Formal proof that the n-th Fourier sine-series coefficient of (E \u2212 M),\r\n  where E and M are related by Kepler's equation  M = E \u2212 e \u00b7 sin E,\r\n  equals  a\u2099 = (2\/n) \u00b7 J\u2099(n\u00b7e),\r\n  with J\u2099 the Bessel function of the first kind of integer order n.\r\n\r\n  Mathematical content\r\n  --------------------\r\n  We expand  E(M) \u2212 M  in a sine series on [0, \u03c0]:\r\n\r\n      E(M) \u2212 M = \u03a3_{n=1}^\u221e  a\u2099 \u00b7 sin(n\u00b7M)\r\n\r\n  The standard Fourier formula gives\r\n\r\n      a\u2099 = (2\/\u03c0) \u222b\u2080^\u03c0 (E(M) \u2212 M) sin(n\u00b7M) dM.\r\n\r\n  Integrating by parts (boundary terms vanish because E(0)=0 and E(\u03c0)=\u03c0):\r\n\r\n      a\u2099 = (2\/(n\u03c0)) \u222b\u2080^\u03c0 (E'(M) \u2212 1) cos(n\u00b7M) dM\r\n         = (2\/(n\u03c0)) \u222b\u2080^\u03c0 E'(M) cos(n\u00b7M) dM     -- the \"\u22121\" term vanishes\r\n\r\n  Changing variable M \u21a6 E via M = E \u2212 e\u00b7sin E  (so E'(M) dM = dE):\r\n\r\n      a\u2099 = (2\/(n\u03c0)) \u222b\u2080^\u03c0 cos(n\u00b7E \u2212 n\u00b7e\u00b7sin E) dE\r\n         = (2\/n) \u00b7 J\u2099(n\u00b7e).\r\n\r\n  The last step uses the Bessel integral representation\r\n      J\u2099(x) = (1\/\u03c0) \u222b\u2080^\u03c0 cos(n\u00b7\u03b8 \u2212 x\u00b7sin \u03b8) d\u03b8.\r\n-\/\r\n\r\nimport Mathlib\r\n\r\nopen Real MeasureTheory intervalIntegral Filter Set\r\n\r\nnoncomputable section\r\n\r\n\/-! ---------------------------------------------------------------\r\n    \u00a71  Variables\r\n    --------------------------------------------------------------- -\/\r\n\r\nvariable (e : \u211d) (he : 0 \u2264 e) (he1 : e &lt; 1) \/-! --------------------------------------------------------------- \u00a72 Kepler's equation and its smooth solution --------------------------------------------------------------- -\/ \/-- The Kepler map M = E \u2212 e\u00b7sin E as a function of E. -\/ def keplerMap (e : \u211d) (E : \u211d) : \u211d := E - e * sin E \/-- `keplerMap e` has derivative 1 \u2212 e\u00b7cos E at every point. -\/ lemma keplerMap_hasDerivAt (e E : \u211d) : HasDerivAt (keplerMap e) (1 - e * cos E) E := -- keplerMap e = fun x =&gt; x - e * sin x, so HasDerivAt follows directly\r\n  -- from sub-rule and const_mul applied to hasDerivAt_sin.\r\n  (hasDerivAt_id E).sub ((hasDerivAt_sin E).const_mul e)\r\n\r\n\/-- The derivative of `keplerMap e` is positive when e &lt; 1. -\/\r\nlemma keplerMap_deriv_pos {e' : \u211d} (he' : 0 \u2264 e') (he1' : e' &lt; 1) (E : \u211d) :\r\n    0 &lt; 1 - e' * cos E := by\r\n  have hcos : cos E \u2264 1 := cos_le_one E\r\n  nlinarith [mul_le_of_le_one_right he' hcos]\r\n\r\n\/-- `keplerMap e` is strictly monotone when e &lt; 1.\r\n    Uses `strictMono_of_hasDerivAt_pos` which requires only pointwise\r\n    `HasDerivAt` and positivity \u2014 no separate continuity proof needed. -\/\r\nlemma keplerMap_strictMono {e' : \u211d} (he' : 0 \u2264 e') (he1' : e' &lt; 1) : StrictMono (keplerMap e') := strictMono_of_hasDerivAt_pos (fun E =&gt; keplerMap_hasDerivAt e' E)\r\n    (fun E =&gt; keplerMap_deriv_pos he' he1' E)\r\n\r\n\/-!\r\n  We axiomatise the inverse  eccAnom : \u211d \u2192 \u211d \u2192 \u211d  and its key\r\n  properties, all of which follow from the Inverse Function Theorem\r\n  applied to the smooth, strictly monotone map  keplerMap e.\r\n-\/\r\n\r\n\/-- The eccentric anomaly: the smooth right-inverse of `keplerMap e`. -\/\r\naxiom eccAnom (e : \u211d) : \u211d \u2192 \u211d\r\n\r\n\/-- `eccAnom e M` satisfies Kepler's equation. -\/\r\naxiom eccAnom_kepler (e M : \u211d) :\r\n    keplerMap e (eccAnom e M) = M\r\n\r\n\/-- `eccAnom e` is differentiable, derivative = 1\/(1 \u2212 e\u00b7cos(eccAnom e M)). -\/\r\naxiom eccAnom_hasDerivAt (e M : \u211d) :\r\n    HasDerivAt (eccAnom e) (1 \/ (1 - e * cos (eccAnom e M))) M\r\n\r\n\/-- Boundary value at 0. -\/\r\naxiom eccAnom_zero (e : \u211d) : eccAnom e 0 = 0\r\n\r\n\/-- Boundary value at \u03c0. -\/\r\naxiom eccAnom_pi (e : \u211d) : eccAnom e \u03c0 = \u03c0\r\n\r\n\/-! ---------------------------------------------------------------\r\n    \u00a73  Bessel function of the first kind (integer order)\r\n\r\n    Defined by the classical integral representation.\r\n    --------------------------------------------------------------- -\/\r\n\r\n\/-- Bessel function J_n(x) via its integral representation. -\/\r\ndef besselJ (n : \u2115) (x : \u211d) : \u211d :=\r\n  (1 \/ \u03c0) * \u222b \u03b8 in (0 : \u211d)..\u03c0, cos (\u2191n * \u03b8 - x * sin \u03b8)\r\n\r\n\/-! ---------------------------------------------------------------\r\n    \u00a74  Fourier coefficient\r\n\r\n    Named  keplerFourierCoeff  to avoid clashing with Mathlib's own\r\n    `fourierCoeff` which is defined on  AddCircle.\r\n    --------------------------------------------------------------- -\/\r\n\r\n\/-- The n-th Fourier sine coefficient of  eccAnom e M \u2212 M  on [0,\u03c0]. -\/\r\ndef keplerFourierCoeff (e : \u211d) (n : \u2115) : \u211d :=\r\n  (2 \/ \u03c0) * \u222b M in (0 : \u211d)..\u03c0,\r\n    (eccAnom e M - M) * sin (\u2191n * M)\r\n\r\n\/-! ---------------------------------------------------------------\r\n    \u00a75  Main theorem\r\n    --------------------------------------------------------------- -\/\r\n\r\n\/--\r\n  **Main theorem.** For n \u2265 1, the Fourier sine coefficient of the\r\n  eccentric-anomaly displacement satisfies  a\u2099 = (2\/n) \u00b7 J\u2099(n\u00b7e).\r\n-\/\r\ntheorem keplerFourierCoeff_eq_besselJ (n : \u2115) (hn : 1 \u2264 n) :\r\n    keplerFourierCoeff e n = (2 \/ (n : \u211d)) * besselJ n (\u2191n * e) := by\r\n  simp only [keplerFourierCoeff, besselJ]\r\n  -- Goal:\r\n  --   (2\/\u03c0) \u00b7 \u222b\u2080^\u03c0 (E(M)\u2212M)\u00b7sin(nM) dM\r\n  --   = (2\/n) \u00b7 (1\/\u03c0) \u00b7 \u222b\u2080^\u03c0 cos(n\u03b8 \u2212 ne\u00b7sin\u03b8) d\u03b8\r\n\r\n  -- \u2500\u2500 Step 1: Integration by parts \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n  -- u = E(M)\u2212M,  dv = sin(nM)dM  \u2192  v = \u2212cos(nM)\/n\r\n  -- Boundary: [uv]\u2080^\u03c0 = 0 by eccAnom_zero, eccAnom_pi.\r\n  -- Result: (2\/\u03c0)\u222b(E\u2212M)sin(nM)dM = (2\/\u03c0)(1\/n)\u222b(E'(M)\u22121)cos(nM)dM\r\n  --\r\n  -- Mathlib lemma: intervalIntegral.integral_mul_deriv\r\n  --   (or integral_deriv_mul_eq_sub_of_hasDerivAt applied to\r\n  --    u = eccAnom e \u2212 id,  v = \u2212sin(n\u00b7\u00b7)\/n)\r\n  have step1 :\r\n      (2 \/ \u03c0) * \u222b M in (0 : \u211d)..\u03c0, (eccAnom e M - M) * sin (\u2191n * M)\r\n      = (2 \/ \u03c0) * (1 \/ \u2191n) *\r\n          \u222b M in (0 : \u211d)..\u03c0, (deriv (eccAnom e) M - 1) * cos (\u2191n * M) := by\r\n    sorry\r\n\r\n  -- \u2500\u2500 Step 2: The \"\u22121\" integral vanishes \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n  -- \u222b\u2080^\u03c0 cos(nM) dM = [sin(nM)\/n]\u2080^\u03c0 = 0  (integer n \u2265 1)\r\n  -- Mathlib: integral_cos, Real.sin_nat_mul_pi\r\n  have cos_int_zero :\r\n      \u222b M in (0 : \u211d)..\u03c0, cos (\u2191n * M) = 0 := by\r\n    sorry\r\n\r\n  have step2 :\r\n      \u222b M in (0 : \u211d)..\u03c0, (deriv (eccAnom e) M - 1) * cos (\u2191n * M)\r\n      = \u222b M in (0 : \u211d)..\u03c0, deriv (eccAnom e) M * cos (\u2191n * M) := by\r\n    have key : \u2200 M : \u211d, (deriv (eccAnom e) M - 1) * cos (\u2191n * M)\r\n                       = deriv (eccAnom e) M * cos (\u2191n * M) - cos (\u2191n * M) := by\r\n      intro M; ring\r\n    simp_rw [key]\r\n    rw [intervalIntegral.integral_sub _ _]\r\n    \u00b7 rw [cos_int_zero, sub_zero]\r\n    \u00b7 -- IntervalIntegrable (deriv (eccAnom e) \u00b7 cos(n\u00b7\u00b7))\r\n      sorry\r\n    \u00b7 exact (continuous_cos.comp (continuous_const.mul continuous_id')).intervalIntegrable 0 \u03c0\r\n\r\n  -- \u2500\u2500 Step 3: Change of variable M \u21a6 E via Kepler's equation \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n  -- Under M = E \u2212 e\u00b7sin E:  E'(M) dM = dE,  cos(nM) = cos(nE \u2212 ne\u00b7sinE)\r\n  -- Mathlib: MeasureTheory.integral_image_eq_integral_abs_deriv_smul\r\n  --       or intervalIntegral.integral_comp_deriv\r\n  have step3 :\r\n      \u222b M in (0 : \u211d)..\u03c0, deriv (eccAnom e) M * cos (\u2191n * M)\r\n      = \u222b E in (0 : \u211d)..\u03c0, cos (\u2191n * E - \u2191n * e * sin E) := by\r\n    sorry\r\n\r\n  -- \u2500\u2500 Step 4: Recognise the Bessel integral \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n  -- (1\/\u03c0)\u222b\u2080^\u03c0 cos(nE \u2212 ne\u00b7sinE)dE = J_n(ne)  by definition.\r\n  have step4 :\r\n      (1 \/ \u03c0) * \u222b E in (0 : \u211d)..\u03c0, cos (\u2191n * E - \u2191n * e * sin E)\r\n      = besselJ n (\u2191n * e) := by\r\n    simp only [besselJ]\r\n\r\n  -- \u2500\u2500 Combine all steps \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n  have hpi : \u03c0 &gt; 0 := Real.pi_pos\r\n  have hn_pos : (0 : \u211d) &lt; \u2191n := by exact_mod_cast (show 0 &lt; n by omega)\r\n  rw [step1, step2, step3]\r\n  -- Goal: (2\/\u03c0)\u00b7(1\/n)\u00b7\u222bcos = (2\/n)\u00b7(1\/\u03c0)\u00b7\u222bcos\r\n  -- Both sides equal (2\/(n\u03c0))\u00b7\u222bcos; show by ring after moving (1\/\u03c0) inside.\r\n  have factored : (2 \/ \u03c0) * (1 \/ \u2191n) *\r\n      \u222b E in (0 : \u211d)..\u03c0, cos (\u2191n * E - \u2191n * e * sin E)\r\n      = (2 \/ \u2191n) * ((1 \/ \u03c0) *\r\n      \u222b E in (0 : \u211d)..\u03c0, cos (\u2191n * E - \u2191n * e * sin E)) := by\r\n    ring\r\n  rw [factored, step4]\r\n\r\nend\r\n\r\n\/-! ---------------------------------------------------------------\r\n    \u00a76  Summary of proof obligations\r\n\r\n    Axioms (all standard consequences of the Inverse Function Theorem\r\n    applied to the smooth, strictly increasing map  keplerMap e):\r\n      \u2022 eccAnom           \u2014 existence of the smooth inverse\r\n      \u2022 eccAnom_kepler    \u2014 it satisfies Kepler's equation\r\n      \u2022 eccAnom_hasDerivAt \u2014 C\u00b9 with derivative 1\/(1 \u2212 e\u00b7cos E)\r\n      \u2022 eccAnom_zero      \u2014 E(0) = 0\r\n      \u2022 eccAnom_pi        \u2014 E(\u03c0) = \u03c0\r\n\r\n    `sorry`s (each closes with a standard Mathlib lemma):\r\n      \u2022 step1        IBP via\r\n                      intervalIntegral.integral_deriv_mul_eq_sub_of_hasDerivAt\r\n      \u2022 cos_int_zero  \u222b\u2080^\u03c0 cos(nM)dM = 0 via\r\n                      integral_cos + Real.sin_nat_mul_pi\r\n      \u2022 step2 integrability  IntervalIntegrable for deriv(eccAnom e)\u00b7cos(n\u00b7)\r\n      \u2022 step3        Change of variables via\r\n                      MeasureTheory.integral_image_eq_integral_abs_deriv_smul\r\n\r\n    \u00a77  Finding minimal imports\r\n\r\n    Once the file builds cleanly, add at the bottom:\r\n\r\n        #min_imports\r\n\r\n    and the Lean Infoview will report the exact minimal import list\r\n    for the version of Mathlib you have installed.\r\n    --------------------------------------------------------------- -\/\r\n<\/pre>\n<p>[1] I used the default setting: Sonnet 4.6, low effort, &#8220;thinking&#8221; turned off.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I ran an experiment today to see whether Claude [1] could generate Lean code to prove a calculation at the bottom of this post, six lines of calculus. I started with this prompt This page contains a mathematical proof that a Fourier coefficient, a_n, is given in terms of a Bessel function. The LaTeX source [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[9],"tags":[202,324],"class_list":["post-247144","post","type-post","status-publish","format-standard","hentry","category-math","tag-artificial-intelligence","tag-formal-methods"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247144","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/comments?post=247144"}],"version-history":[{"count":3,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247144\/revisions"}],"predecessor-version":[{"id":247153,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247144\/revisions\/247153"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=247144"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=247144"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=247144"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":247139,"date":"2026-06-10T08:34:31","date_gmt":"2026-06-10T13:34:31","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=247139"},"modified":"2026-06-10T13:01:56","modified_gmt":"2026-06-10T18:01:56","slug":"pulling-on-a-thread","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/06\/10\/pulling-on-a-thread\/","title":{"rendered":"Pulling on a thread"},"content":{"rendered":"<p>Often there&#8217;s a thread running through a sequence of my posts. Sometimes I make this explicit and sometimes I don&#8217;t.<\/p>\n<p>The latest thread started with <a href=\"https:\/\/www.johndcook.com\/blog\/2026\/05\/31\/another-gaussian-approximation\/\">this post<\/a> commenting on a tweet that observed that<\/p>\n<p style=\"padding-left: 40px;\">exp(\u2212<em>x<\/em>\u00b2) \u2248 (1 + cos(sin(<em>x<\/em>) + <em>x<\/em>))\/2.<\/p>\n<p>Some people said online that that the approximation is simply due to the first few terms of the Taylor series on both sides matching up, so I wrote a <a href=\"https:\/\/www.johndcook.com\/blog\/2026\/06\/01\/not-just-taylor-series\/\">follow up post<\/a> explaining that it&#8217;s not that simple.<\/p>\n<p>The series for the left hand side alternates and converges very slowly, which lead to the post on <a href=\"https:\/\/www.johndcook.com\/blog\/2026\/06\/03\/naive-sum\/\">naively summing<\/a> an alternating series.<\/p>\n<p>The series for the right hand side lead to this point on <a href=\"https:\/\/www.johndcook.com\/blog\/2026\/06\/04\/partitions-over-permutations\/\">partitions over permutations<\/a>.<\/p>\n<p>Integrating the right hand side lead to <a href=\"https:\/\/www.johndcook.com\/blog\/2026\/06\/04\/integrating-smooth-periodic-functions\/\">this post<\/a> on how the simplest numerical integration rule works shockingly well on some problems.<\/p>\n<p>The exact value of the integral turns out to be given by a <a href=\"https:\/\/www.johndcook.com\/blog\/2026\/06\/05\/mr-bessels-eponymous-functions\/\">Bessel function<\/a>, details given in <a href=\"https:\/\/www.johndcook.com\/blog\/2026\/06\/06\/from-kepler-to-bessel\/\">this post<\/a>.<\/p>\n<p>Mr. Bessel&#8217;s interest in the functions now named after him started with looking closely at a solution to Kepler&#8217;s equation in orbital mechanics. Thinking about Kepler&#8217;s equation lead to the posts on <a href=\"https:\/\/www.johndcook.com\/blog\/2026\/06\/07\/the-laplace-limit\/\">the Laplace limit<\/a> and on <a href=\"https:\/\/www.johndcook.com\/blog\/2026\/06\/07\/aitkin-acceleration-kepler\/\">series acceleration<\/a>.<\/p>\n<p>I may be done pulling on this thread. I don&#8217;t have anything else in mind that I want to explore for now, but you never know.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Often there&#8217;s a thread running through a sequence of my posts. Sometimes I make this explicit and sometimes I don&#8217;t. The latest thread started with this post commenting on a tweet that observed that exp(\u2212x\u00b2) \u2248 (1 + cos(sin(x) + x))\/2. Some people said online that that the approximation is simply due to the first [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[9],"tags":[],"class_list":["post-247139","post","type-post","status-publish","format-standard","hentry","category-math"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247139","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/comments?post=247139"}],"version-history":[{"count":4,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247139\/revisions"}],"predecessor-version":[{"id":247143,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247139\/revisions\/247143"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=247139"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=247139"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=247139"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":247135,"date":"2026-06-07T15:14:45","date_gmt":"2026-06-07T20:14:45","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=247135"},"modified":"2026-06-07T15:14:45","modified_gmt":"2026-06-07T20:14:45","slug":"aitkin-acceleration-kepler","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/06\/07\/aitkin-acceleration-kepler\/","title":{"rendered":"Aitken acceleration before Aitken"},"content":{"rendered":"<p>Kepler solved his eponymous equation<\/p>\n<p style=\"padding-left: 40px;\"><em>M<\/em> =\u00a0<em>E<\/em> \u2212\u00a0<em>e<\/em> sin(<em>E<\/em>)<\/p>\n<p>by finding a fixed point of<\/p>\n<p style=\"padding-left: 40px;\"><em>E<\/em> = <em>M<\/em> + <em>e<\/em> sin(<em>E<\/em>).<\/p>\n<p>So guess a value of\u00a0<em>E<\/em> and stick it into the right hand side. Then plug that value into the right hand side again. Kepler said a couple iterations should be enough. And a couple iterations\u00a0<em>are<\/em> enough if the eccentricity <em>e<\/em> is small and you don&#8217;t need much accuracy.<\/p>\n<p>The rate of convergence is determined by\u00a0<em>e<\/em>. Kepler implicitly had in mind small values of\u00a0<em>e<\/em> because he wasn&#8217;t aware of anything orbiting the sun in a highly elliptical orbit. Here&#8217;s an example with eccentricity 0.05, about the eccentricity of the orbits of Jupiter and Saturn.<\/p>\n<pre>from math import sin\r\n\r\nM, E, e = 1, 1, 0.05\r\nfor _ in range(5):\r\n    E = M + e*sin(E)\r\n    residual = M - (E - e*sin(E))\r\n    print(residual)\r\n<\/pre>\n<p>The residual after just two iterations is 2.77 \u00d7 10<sup>\u22125<\/sup>. If you change <em>e<\/em> to 0.2, the eccentricity of Mercury&#8217;s orbit, it takes three iterations to get comparable accuracy. Mercury has the most eccentric orbit of any object Kepler would have known about.<\/p>\n<p>Now suppose you&#8217;d like to solve for <em>E<\/em> when <em>M<\/em> = 1 for Halley&#8217;s comet, and you&#8217;d like an error of less than 10<sup>\u22128<\/sup>. Now you need 16 iterations.<\/p>\n<p>C. F. W. Peters discovered a faster algorithm in 1891.<\/p>\n<p style=\"padding-left: 40px;\"><em>E<\/em><sub>1<\/sub> = <i>M<\/i>\u00a0+ <em>e<\/em> sin(<em>E<\/em><sub>0<\/sub>)<br \/>\n<em>E<\/em><sub>2<\/sub> = <i>M<\/i>\u00a0+ <em>e<\/em> sin(<em>E<\/em><sub>1<\/sub>)<br \/>\n<em>E<\/em><sub>3<\/sub> = (<em>E<\/em><sub>2<\/sub> <em>E<\/em><sub>0<\/sub> \u2212 <em>E<\/em><sub>1<\/sub>\u00b2)\/(<em>E<\/em><sub>2<\/sub> \u2212 2<em>E<\/em><sub>1<\/sub> + <em>E<\/em><sub>0<\/sub>)<\/p>\n<p>Let&#8217;s look at the results of doing three iterations of Peters&#8217; method for Halley&#8217;s comet.<\/p>\n<pre>M, E0, e = 1, 1, 0.967\r\nfor _ in range(3):\r\n    E1 = M + e*sin(E0)\r\n    E2 = M + e*sin(E1)\r\n    E3 = (E2*E0 - E1**2)\/(E2 - 2*E1 + E0)\r\n    residual = M - (E - e*sin(E3))\r\n    print(residual)\r\n    E0 = E3 # for next iteration\r\n<\/pre>\n<p>This gives a residual of \u22127.23 \u00d7 10<sup>\u221210<\/sup>. Each iteration of Peters&#8217; method requires a little more than twice as much work as an iteration of Kepler&#8217;s method, but 3 iterations of Peters&#8217; method accomplished more than 16 iterations of Kepler&#8217;s method.<\/p>\n<p>Peters&#8217; algorithm from 1891 was a special case of Alexander Aitken&#8217;s series acceleration method published in 1926.<\/p>\n<h2>Related posts<\/h2>\n<ul>\n<li class='link'><a href='https:\/\/www.johndcook.com\/blog\/2019\/08\/02\/aitken-acceleration\/'>Aitken acceleration<\/a><\/li>\n<li class='link'><a href='https:\/\/www.johndcook.com\/blog\/2019\/08\/01\/accelerating-an-alternating-series\/'>Euler acceleration<\/a><\/li>\n<li class='link'><a href='https:\/\/www.johndcook.com\/blog\/2020\/08\/06\/cohen-acceleration\/'>Cohen acceleration<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Kepler solved his eponymous equation M =\u00a0E \u2212\u00a0e sin(E) by finding a fixed point of E = M + e sin(E). So guess a value of\u00a0E and stick it into the right hand side. Then plug that value into the right hand side again. Kepler said a couple iterations should be enough. And a couple [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[5],"tags":[166],"class_list":["post-247135","post","type-post","status-publish","format-standard","hentry","category-computing","tag-math"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247135","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/comments?post=247135"}],"version-history":[{"count":2,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247135\/revisions"}],"predecessor-version":[{"id":247137,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247135\/revisions\/247137"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=247135"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=247135"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=247135"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":247128,"date":"2026-06-07T14:06:36","date_gmt":"2026-06-07T19:06:36","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=247128"},"modified":"2026-06-08T07:01:07","modified_gmt":"2026-06-08T12:01:07","slug":"the-laplace-limit","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/06\/07\/the-laplace-limit\/","title":{"rendered":"The Laplace limit"},"content":{"rendered":"<p>An <a href=\"https:\/\/www.johndcook.com\/blog\/2026\/06\/06\/from-kepler-to-bessel\/\">earlier post<\/a> discussed how to solve Kepler&#8217;s equation<\/p>\n<p style=\"padding-left: 40px;\"><em>M<\/em> =\u00a0<em>E<\/em> \u2212\u00a0<em>e<\/em> sin(<em>E<\/em>)<\/p>\n<p>using a sine series. You could also solve Kepler&#8217;s equation using a power series, which Lagrange did in 1771. Both approaches express\u00a0<em>E<\/em> as a function of\u00a0<em>e<\/em> and\u00a0<em>M<\/em>, but from different perspectives. Bessel thought of his solution as a sum of sines in <em>M<\/em>, with coefficients that depend on\u00a0<em>e<\/em>. Lagrange thought of his solution as a power series in\u00a0<em>e<\/em> whose coefficients involve sines in\u00a0<em>M<\/em>. You can rearrange the terms of either solution into the other.<\/p>\n<p>The most interesting thing about the power series solution, in my opinion, is that it only converges for <em>e<\/em> less than roughly 2\/3 while the sine series solution is valid for all\u00a0<em>e<\/em> &lt; 1. In astronomical terms, this means the power series solution works for the orbit of some planets but not others!<\/p>\n<p>In our solar system, the planets all have eccentricity well below 2\/3, but not all minor planets do. For example, the orbit of Eris has eccentricity 0.4407 but the orbit of Sedna has eccentricity 0.8549. And in other solar systems there are planets with eccentricity much greater than 2\/3.<\/p>\n<h2>The Laplace limit<\/h2>\n<p>The radius of convergence for Lagrange&#8217;s power series solution is called the Laplace limit. Its value is <em>e<\/em><sub><em>L<\/em><\/sub> = 0.6627\u2026. There&#8217;s no obvious reason why there&#8217;s anything special about this value. There&#8217;s no astronomical reason for this value. It&#8217;s an artifact of the power series form of the solution.<\/p>\n<p>If the series works for <em>e<\/em> = 0.66, you would reasonably think it works for <em>e<\/em> = 0.67, but that&#8217;s not the case. And if you&#8217;re observant, you might notice that although the series works for <em>e<\/em> = 0.66, it takes longer to converge than for smaller values of <em>e<\/em>; the rate of convergence is slowing down, warning you of danger ahead.<\/p>\n<p>The exact value of <em>e<\/em><sub><em>L<\/em><\/sub> is the unique real solution to the equation<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/laplace_limit1.svg\" alt=\"x \\exp\\left(\\sqrt{1 + x^2}\\right) = 1 + \\sqrt{1 + x^2}\" width=\"244\" height=\"36\" \/><\/p>\n<p>There&#8217;s no obvious reason for this either. It has to do with finding the largest circle that can fit in a lens-shaped region of convergence. More on that <a href=\"https:\/\/mathworld.wolfram.com\/LaplaceLimit.html\">here<\/a>.<\/p>\n<p>We can calculate <em>e<\/em><sub><em>L<\/em><\/sub> with the following Python code.<\/p>\n<pre>from math import exp\r\nfrom scipy.optimize import root_scalar\r\n\r\ndef f(x):\r\n    t = (1 + x*x)**0.5\r\n    return x*math.exp(t) - 1 - t\r\n\r\nsol = root_scalar(f, bracket=[0, 1], method='brentq')\r\nprint(sol.root)\r\n<\/pre>\n<p>This prints 0.6627434193491817.<\/p>\n<h2>Series details<\/h2>\n<p>We can use the <a href=\"https:\/\/www.johndcook.com\/blog\/2020\/08\/05\/lagrange-inversion-formula\/\">Lagrange inversion formula<\/a> to find the series, just as Lagrange did two and a half centuries ago.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/laplace_limit2.svg\" alt=\"E = M+ \\sum_{n=1}^{\\infty} \\frac{e^n}{n!} \\frac{d^{\\,n-1}}{dM^{\\,n-1}} \\left(\\sin^n M\\right)\" width=\"253\" height=\"54\" \/><\/p>\n<p>The powers of sine can be expanded into the sum of sines of various frequencies and differentiated, leading to the equation<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/laplace_limit3.svg\" alt=\"E = M+ \\sum_{n=1}^{\\infty} \\frac{e^n}{2^{\\,n-1}n!} \\sum_{k=0}^{\\lfloor n\/2\\rfloor} (-1)^k \\binom{n}{k} (n-2k)^{n-1} \\sin\\!\\big((n-2k)M\\big)\" width=\"495\" height=\"59\" \/><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>An earlier post discussed how to solve Kepler&#8217;s equation M =\u00a0E \u2212\u00a0e sin(E) using a sine series. You could also solve Kepler&#8217;s equation using a power series, which Lagrange did in 1771. Both approaches express\u00a0E as a function of\u00a0e and\u00a0M, but from different perspectives. Bessel thought of his solution as a sum of sines in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[9],"tags":[213],"class_list":["post-247128","post","type-post","status-publish","format-standard","hentry","category-math","tag-orbital-mechanics"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247128","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/comments?post=247128"}],"version-history":[{"count":6,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247128\/revisions"}],"predecessor-version":[{"id":247138,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247128\/revisions\/247138"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=247128"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=247128"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=247128"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":247126,"date":"2026-06-07T11:34:26","date_gmt":"2026-06-07T16:34:26","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=247126"},"modified":"2026-06-07T11:34:26","modified_gmt":"2026-06-07T16:34:26","slug":"a-crank-formula-for-%cf%80","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/06\/07\/a-crank-formula-for-%cf%80\/","title":{"rendered":"A crank formula for \u03c0"},"content":{"rendered":"<p>I ran across a cranky formula for \u03c0 based on physical constants <a href=\"https:\/\/x.com\/mathsrick_\/status\/2063283732535226568?s=20\">here<\/a><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/crank1.svg\" alt=\"\\pi = \\left( \\frac{E}{\\frac{1}{2}mc^{2}} \\right)^{1\/2} \\left[ J_{\\lambda} \\cdot \\lambda^{5} \\left( e^{\\frac{hc}{\\lambda kT}} - 1 \\right) \\right]\" width=\"278\" height=\"64\" \/><\/p>\n<p>and decided to play around with it.<\/p>\n<p>The source describes \u03bb as &#8220;wavelength (chosen in the microwave region)&#8221; and I thought perhaps you could chose a value of \u03bb to make the equation work. But as a <a href=\"https:\/\/x.com\/QualiaQuanta\/status\/2063384173318975788\">comment<\/a> pointed out, the bracketed expression is simply 2<em>hc<\/em>\u00b2, independent of \u03bb, due to Planck&#8217;s blackbody law. That means we can simplify the expression above to<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/crank2.svg\" alt=\"\\pi = 2\\sqrt{2} hc \\sqrt{\\frac{E}{m}}\" width=\"125\" height=\"48\" \/><\/p>\n<p>Now the values of\u00a0<em>h<\/em> and\u00a0<em>c<\/em> are known. In fact, they&#8217;re now <strong>exactly<\/strong> known by definition: other SI units are defined in terms of\u00a0<em>h<\/em> and\u00a0<em>c<\/em>. The mass of an electron is known to 11 significant figures.<\/p>\n<p>But\u00a0<em>E<\/em> in the equation above is &#8220;Total energy of the universe.&#8221; I don&#8217;t even know what that means. Does it refer to the observable universe? Does it include dark energy? Does it include the energy equivalent of mass?<\/p>\n<p>I asked a couple LLMs that the total energy of the universe might mean and what its value might be, and they said something like &#8220;Depends. It might be zero. It might be infinite. But if I had to say, I&#8217;d say around 10<sup>70<\/sup> Joules.&#8221;<\/p>\n<p>If we solve the equation above for\u00a0<em>E<\/em> we get 2.8480347886530404 \u00d7 10<sup>19<\/sup> Joules. I have no idea how to justify that.<\/p>\n<p>The expression for \u03c0 is not dimensionless. I suppose you could choose some nonstandard units that would make the equation work.<\/p>\n<p>The source I linked to above cites Mathematical Cranks by Underwood Dudley, but I couldn&#8217;t find it in the book.<\/p>\n<h2>Related posts<\/h2>\n<ul>\n<li class=\"link\"><a href=\"https:\/\/www.johndcook.com\/blog\/2018\/09\/11\/koide\/\">Koide&#8217;s coincidence<\/a><\/li>\n<li class=\"link\"><a href=\"https:\/\/www.johndcook.com\/blog\/2021\/03\/31\/coulombs-constant\/\">Coulomb&#8217;s constant<\/a><\/li>\n<li class=\"link\"><a href=\"https:\/\/www.johndcook.com\/blog\/2025\/05\/24\/dungeons-dragons-and-numbers\/\">Dungeons, Dragons, and Numbers<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>I ran across a cranky formula for \u03c0 based on physical constants here and decided to play around with it. The source describes \u03bb as &#8220;wavelength (chosen in the microwave region)&#8221; and I thought perhaps you could chose a value of \u03bb to make the equation work. But as a comment pointed out, the bracketed [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[9],"tags":[],"class_list":["post-247126","post","type-post","status-publish","format-standard","hentry","category-math"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247126","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/comments?post=247126"}],"version-history":[{"count":2,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247126\/revisions"}],"predecessor-version":[{"id":247130,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247126\/revisions\/247130"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=247126"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=247126"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=247126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":247118,"date":"2026-06-06T13:46:02","date_gmt":"2026-06-06T18:46:02","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=247118"},"modified":"2026-06-06T18:39:23","modified_gmt":"2026-06-06T23:39:23","slug":"from-kepler-to-bessel","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/06\/06\/from-kepler-to-bessel\/","title":{"rendered":"From Kepler to Bessel"},"content":{"rendered":"<p>The <a href=\"https:\/\/www.johndcook.com\/blog\/2026\/06\/05\/mr-bessels-eponymous-functions\/\">previous post<\/a> very briefly said that the integral representation for Bessel functions was motived by solving Kepler&#8217;s equation. This post will go into more detail.<\/p>\n<h2>Kepler&#8217;s equation<\/h2>\n<p>There are multiple ways to describe the position of a planet in an elliptical orbit around a star. For historical reasons, these descriptions have arcane names such as mean anomaly, true anomaly, and eccentric anomaly. <a href=\"https:\/\/www.johndcook.com\/blog\/2022\/10\/22\/orbital-anomalies\/\">This post<\/a> explains how these three are related.<\/p>\n<p>For this post, it is enough to say that often you know mean anomaly <em>M<\/em> and want to know eccentric anomaly <em>E<\/em>. These are related via Kepler&#8217;s equation<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/kepler_eqn.svg\" alt=\"M = E - e \\sin E\" width=\"153\" height=\"13\" \/><br \/>\nwhere\u00a0<em>e<\/em> is the eccentricity of the orbit. You&#8217;d like to solve for\u00a0<em>E<\/em> as a function of\u00a0<em>M<\/em> and\u00a0<em>e<\/em>, but there&#8217;s no elementary way to do that.<\/p>\n<p>One way to solve Kepler&#8217;s equation is to take a guess at\u00a0<em>E<\/em> and plug it into the right hand side of<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/kepler_eqn2.svg\" alt=\"E = M + e \\sin E\" width=\"141\" height=\"13\" \/><br \/>\nto get a new\u00a0<em>E<\/em>, and keep iterating until the two sides are closer together. I write more about this <a href=\"https:\/\/www.johndcook.com\/blog\/2018\/12\/21\/contraction-mapping-theorem\/\">here<\/a>.<\/p>\n<p>Another approach to solving Kepler&#8217;s equation is to use Newton&#8217;s method. I write more about that <a href=\"https:\/\/www.johndcook.com\/blog\/2022\/11\/01\/kepler-newton\/\">here<\/a>.<\/p>\n<p>Still another approach is to expand <em>E<\/em> in a sine series and find the series coefficients. An advantage to this approach is that once you have the coefficients, you have an expression for <em>E<\/em> as a function of <em>M<\/em>, and you can plug in more values of <em>M<\/em> without having to solve Kepler&#8217;s equation for each value of <em>M<\/em> separately.<\/p>\n<h2>Sine series coefficients<\/h2>\n<p>Kepler&#8217;s equation is easy to solve at\u00a0<em>E<\/em> = 0 and at\u00a0<em>E<\/em> = \u03c0. In both cases,\u00a0<em>E<\/em> =\u00a0<em>M<\/em>. So the function\u00a0<em>E<\/em> \u2212\u00a0<em>M<\/em> is zero at both ends of [0, \u03c0], which suggests we try to expand <em>E<\/em> \u2212\u00a0<em>M<\/em> in a sine series<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/kepler_eqn3.svg\" alt=\"E - M = \\sum_{n=1}^\\infty a_n \\sin nM\" width=\"179\" height=\"54\" \/><\/p>\n<p>We then calculate the Fourier coefficients <em>a<\/em><sub><em>n<\/em><\/sub> as usual.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/kepler_bessel2.svg\" alt=\"\\begin{align*} a_n &amp;= \\frac{2}{\\pi} \\int_0^\\pi (E-M) \\sin(nM) \\, dM \\\\ &amp;= \\frac{2}{n \\pi} \\int_0^\\pi (E^\\prime - 1) \\cos(nM)\\, dM \\\\ &amp;= \\frac{2}{n \\pi} \\int_0^\\pi \\cos(nM) E^\\prime(M) \\, dM \\\\ &amp;= \\frac{2}{n \\pi} \\int_0^\\pi \\cos\\Big(nE - ne\\sin(E)\\Big) E^\\prime(M) \\, dM \\\\ &amp;= \\frac{2}{n} \\left\\{ \\frac{1}{\\pi} \\int_0^\\pi \\cos\\Big(nE - ne \\sin(E)\\Big)\\, dE\\right\\} \\\\ &amp;= \\frac{2}{n} J_n(ne) \\end{align*}\" width=\"353\" height=\"305\" \/><\/p>\n<p>The second line uses integration by parts. The third line uses Kepler&#8217;s equation. The last line uses the definition of the Bessel functions <em>J<\/em><sub><em>n<\/em><\/sub> given in the previous post.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The previous post very briefly said that the integral representation for Bessel functions was motived by solving Kepler&#8217;s equation. This post will go into more detail. Kepler&#8217;s equation There are multiple ways to describe the position of a planet in an elliptical orbit around a star. For historical reasons, these descriptions have arcane names such [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[9],"tags":[213,129],"class_list":["post-247118","post","type-post","status-publish","format-standard","hentry","category-math","tag-orbital-mechanics","tag-special-functions"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247118","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/comments?post=247118"}],"version-history":[{"count":5,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247118\/revisions"}],"predecessor-version":[{"id":247125,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247118\/revisions\/247125"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=247118"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=247118"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=247118"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":247111,"date":"2026-06-05T07:04:28","date_gmt":"2026-06-05T12:04:28","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=247111"},"modified":"2026-06-06T13:48:34","modified_gmt":"2026-06-06T18:48:34","slug":"mr-bessels-eponymous-functions","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/06\/05\/mr-bessels-eponymous-functions\/","title":{"rendered":"Mr. Bessel&#8217;s eponymous functions"},"content":{"rendered":"<p>Yesterday I wrote a post showing that the trapezoid rule evaluates the integral<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/cossinint.svg\" alt=\"\\int_{-\\pi}^\\pi \\cos(\\sin(x) + x)\\, dx\" width=\"184\" height=\"45\" \/><\/p>\n<p>very efficiently. But how do we know what the exact integral is for comparison? If you ask Mathematica, it will tell you the integral equals \u22122\u03c0 <em>J<\/em><sub>1<\/sub>(1) where <em>J<\/em><sub>1<\/sub> is a Bessel function. This may seem like rabbit out of a hat, but it&#8217;s actually a simple calculation given the integral definition of Bessel functions:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/bessel_integral_def.svg\" alt=\"J_n(z) = \\frac{1}{\\pi}\\int_0^\\pi \\cos(n\\theta - z\\sin(\\theta))\\, d\\theta\" width=\"289\" height=\"45\" \/><\/p>\n<p>Since cosine is even, we can write our integral over [\u2212\u03c0, \u03c0] as twice the integral over [0, \u03c0]. Then a change of variables turns this into the definition of <em>J<\/em><sub><em>n<\/em><\/sub>(<em>z<\/em>) with <em>n<\/em> = 1 and <em>z<\/em> = 1.<\/p>\n<p>A deeper question is what have we accomplished by just giving a new name to essentially the same problem we started with. Another question is why in the world are Bessel functions defined as above.<\/p>\n<p>As for what we&#8217;ve accomplished, we&#8217;ve related out integration problem to a very well-studied function. Bessel functions have been studied for two centuries and it&#8217;s easy to find software to evaluate them. Even the usually minimalist command line calculator <code>bc<\/code> has a function <code>j(x, n)<\/code> for evaluating <em>J<\/em><sub><em>n<\/em><\/sub>(<em>x<\/em>) for integer values of <em>n<\/em>. We could calculate our integral to 50 decimal places as follows.<\/p>\n<pre>~$ bc -l\r\n&gt;&gt;&gt; scale = 50\r\n&gt;&gt;&gt;  -8*a(1)*j(1,1)\r\n-2.76491937476833705153256665538788207487495025542883\r\n<\/pre>\n<p>Note that <code>bc<\/code> doesn&#8217;t have a value of \u03c0 built in, but <code>a(x)<\/code> evaluates the arctangent function, and \u03c0 = 4 arctan(1).<\/p>\n<p>There are multiple ways of defining Bessel functions. The three main ways would be in terms of their power series, in terms of the differential equations they solve, and in terms of their integral representation. Friedrich Bessel defined what we now call Bessel functions of the first kind, the <em>J<\/em><sub><em>n<\/em><\/sub> functions, in terms of their integral representations.<\/p>\n<p>Why did Bessel care about these integrals? They came out of his calculations in celestial mechanics. One example of this is solving <a href=\"https:\/\/www.johndcook.com\/blog\/2018\/12\/21\/contraction-mapping-theorem\/\">Kepler&#8217;s equation<\/a> with Fourier series; the Fourier coefficients are given by Bessel functions. This is worked out in detail in the <a href=\"https:\/\/www.johndcook.com\/blog\/2026\/06\/06\/from-kepler-to-bessel\/\">next post<\/a>.<\/p>\n<p>Bessel functions had occurred in applications before Mr. Bessel drew attention to them. The functions are named after him because he was the first to systematically study them.<\/p>\n<p>Mathematics is developed inductively but taught deductively. It&#8217;s common for things to be kicked around for years before someone decides they deserve a name and systematic study. See this post on the <a href=\"https:\/\/www.johndcook.com\/blog\/2010\/01\/05\/how-the-central-limit-theorem-began\/\">central limit theorem<\/a> for another example. The CLT is older than the Gaussian distribution, even older than Gauss.<\/p>\n<h2>Related posts<\/h2>\n<ul>\n<li class=\"link\"><a href=\"https:\/\/www.johndcook.com\/blog\/2016\/02\/17\/analyzing-an-fm-signal\/\">FM radio and Bessel functions<\/a><\/li>\n<li class=\"link\"><a href=\"https:\/\/www.johndcook.com\/blog\/2021\/06\/12\/vibrating-circular-membranes\/\">Vibrating circular membranes<\/a><\/li>\n<li class=\"link\"><a href=\"https:\/\/www.johndcook.com\/blog\/2017\/11\/04\/fourier-bessel-series-and-gibbs-phenomena\/\">Fourier-Bessel series<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Yesterday I wrote a post showing that the trapezoid rule evaluates the integral very efficiently. But how do we know what the exact integral is for comparison? If you ask Mathematica, it will tell you the integral equals \u22122\u03c0 J1(1) where J1 is a Bessel function. This may seem like rabbit out of a hat, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[9],"tags":[129],"class_list":["post-247111","post","type-post","status-publish","format-standard","hentry","category-math","tag-special-functions"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247111","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/comments?post=247111"}],"version-history":[{"count":6,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247111\/revisions"}],"predecessor-version":[{"id":247122,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247111\/revisions\/247122"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=247111"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=247111"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=247111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":247093,"date":"2026-06-04T15:12:11","date_gmt":"2026-06-04T20:12:11","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=247093"},"modified":"2026-06-04T15:12:11","modified_gmt":"2026-06-04T20:12:11","slug":"the-latin-of-linux","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/06\/04\/the-latin-of-linux\/","title":{"rendered":"The Latin of Linux"},"content":{"rendered":"<p>One reason people study Latin is that it is the ancestor of many modern languages. English derives from West Germanic languages, not from Latin, but much of English vocabulary, perhaps as much as 60%, derives from Latin, either directly or indirectly through French.<\/p>\n<p>Knowing a bit of Latin makes sense of many things that would otherwise seem completely arbitrary, such as why the symbols for gold, silver, and lead are Au, Ag, and Pb respectively.<\/p>\n<p>Similarly, ed(1) is the Latin of Linux [1]. Many conventions in command line utilities follow conventions that go back to the ed(1) line editor. They may go back even further. Just as Latin didn&#8217;t come out of nowhere, neither did ed(1), but you can&#8217;t go back indefinitely. It&#8217;s convenient to start history somewhere, and this post will start with ed(1) just as much discussion of Western linguistics starts with Latin.<\/p>\n<p>The following are features of ed(1) that live on in sed, awk, grep, vi, perl, bash, etc.<\/p>\n<ol>\n<li>Using slashes to delimit regular expressions<\/li>\n<li>Using $ to indicate the end of a line or the end of a file<\/li>\n<li>The pattern of specifying address + action or address range + action<\/li>\n<li>Using regular expressions as address ranges<\/li>\n<li>Using \\1, \\2, etc to refer to regex captures<\/li>\n<li>Using &amp; to refer to the entire matched text<\/li>\n<li>The g\/regexp\/command pattern<\/li>\n<li>Using p for printing lines, as in g\/re\/p<\/li>\n<li>The commands a, c, d, i, j, l, p, q, r, and w in vi<\/li>\n<li>! for shell escape<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p>[1] Because the name &#8220;ed&#8221; is so short, and looks so much like the name Ed, it&#8217;s convenient to use its full Unix name ed(1). The parenthesized number is used to disambiguate different things that have the same name, such as the user command kill(1) and the system call kill(2). There is no ed(2) or any other higher-numbered ed. The number is there to make the name stand out, not to disambiguate anything.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One reason people study Latin is that it is the ancestor of many modern languages. English derives from West Germanic languages, not from Latin, but much of English vocabulary, perhaps as much as 60%, derives from Latin, either directly or indirectly through French. Knowing a bit of Latin makes sense of many things that would [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[5],"tags":[],"class_list":["post-247093","post","type-post","status-publish","format-standard","hentry","category-computing"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247093","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/comments?post=247093"}],"version-history":[{"count":2,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247093\/revisions"}],"predecessor-version":[{"id":247109,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247093\/revisions\/247109"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=247093"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=247093"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=247093"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":247102,"date":"2026-06-04T12:18:40","date_gmt":"2026-06-04T17:18:40","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=247102"},"modified":"2026-06-04T23:14:43","modified_gmt":"2026-06-05T04:14:43","slug":"integrating-smooth-periodic-functions","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/06\/04\/integrating-smooth-periodic-functions\/","title":{"rendered":"Integrating smooth periodic functions"},"content":{"rendered":"<p>Several posts lately have looked at the function<\/p>\n<p style=\"padding-left: 40px;\"><em>f<\/em>(<em>x<\/em>) = cos(sin(<em>x<\/em>) +\u00a0<em>x<\/em>).<\/p>\n<p>This post will look at the function from a different angle. It&#8217;s a smooth function with period 2\u03c0. For reasons I wrote about <a href=\"https:\/\/www.johndcook.com\/blog\/2017\/03\/01\/numerically-integrating-periodic-functions\/\">here<\/a>, this means that the trapezoid rule should find its integral very efficiently.<\/p>\n<p>In general, the error in the trapezoid rule is on the order of 1\/<em>N<\/em>\u00b2 where\u00a0<em>N<\/em> is the number of integration points. To be more specific, the error in integrating a function <em>f<\/em> over [<em>a<\/em>, <em>b<\/em>] with <em>N<\/em> points is bounded by<\/p>\n<p style=\"padding-left: 40px;\">(<em>b<\/em> \u2212 <em>a<\/em>)\u00b3 <em>M<\/em> \/ 12<em>N<\/em>\u00b2<\/p>\n<p>where <em>M<\/em> is the maximum absolute value of the second derivative of <em>f<\/em>. So in our case we should expect the error to be less than 82.67\/<em>N<\/em>\u00b2. In fact we do\u00a0<em>much<\/em> better than that. The error does not decrease quadratically, as it does in general, but exponentially.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-medium aligncenter\" src=\"https:\/\/www.johndcook.com\/periodic_gaussian.png\" width=\"640\" height=\"480\" \/><\/p>\n<p>With just 16 integration points, we&#8217;ve reached the limit of floating point representation.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Several posts lately have looked at the function f(x) = cos(sin(x) +\u00a0x). This post will look at the function from a different angle. It&#8217;s a smooth function with period 2\u03c0. For reasons I wrote about here, this means that the trapezoid rule should find its integral very efficiently. In general, the error in the trapezoid [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[9],"tags":[71],"class_list":["post-247102","post","type-post","status-publish","format-standard","hentry","category-math","tag-integration"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247102","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/comments?post=247102"}],"version-history":[{"count":5,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247102\/revisions"}],"predecessor-version":[{"id":247114,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247102\/revisions\/247114"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=247102"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=247102"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=247102"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}]