Feynman vs. Computer

Four lines of code vs decades of math tricks—who wins

TLDR: A coder showed you can estimate tough integrals with four lines of JavaScript using random samples. Commenters sparred over random methods vs classic techniques, detoured into analog op‑amp tricks, and asked when quick hacks beat deep math—highlighting how we pick tools when curves get weird.

A blogger pitted Richard Feynman’s clever hand‑math against four lines of JavaScript that use random samples to estimate area under a curve. The demo nails a simple case (0.70 vs 0.69) and stumbles on a spiky one, and the comments immediately split into Team RNG vs Team Real Math. The loudest spark came when eig asked if this beats Runge‑Kutta, and a swarm replied: that’s for solving differential equations, not counting area. Cue a brawl over classic quadrature (like Simpson’s rule) versus Monte Carlo, with one side crowning randomness as king of hard shapes and high dimensions, and the other calling it lazy.

Then came the plot twist: JKCalhoun rolled in with retro vibes, claiming an op‑amp integrator can literally output the area as a voltage. Half the thread screamed “science fair legend,” the other half yelled “okay but who’s soldering at 2 a.m.” Bananaflag’s curiosity about integrals that return functions sparked mini‑lectures on “function‑valued answers,” while messe dropped a mischievous hack—plug in a weird number like Zeta[3] and back‑solve—which earned equal parts eye‑rolls and applause.

Animats framed the mood: numerical integration is forgiving, symbolic integration is a maze. Memes flew—“RNGesus take the wheel,” “Feynman vs JavaScript cage match”—as the crowd debated whether quick code beats deep math when the curve gets nasty.

Key Points

  • The article proposes estimating definite integrals using uniform random sampling (Monte Carlo).
  • A four-line JavaScript function demonstrates how to compute the estimator quickly.
  • Increasing the number of samples improves approximation accuracy for well-behaved functions.
  • The integral equals the expected value of the function over a uniform distribution times the interval length.
  • Naive uniform sampling struggles near singularities, as shown by a case with a target value of −3.7.

Hottest takes

What is the advantage of this Monte Carlo approach over a typical numerical integration method (like Runge-Kutta)? — eig
a simple analog integrator (an op-amp with a capacitor connected in feedback) will also give you the area under the curve — JKCalhoun
just plug in a transcendental value for x like Zeta[3] — messe
Made with <3 by @siedrix and @shesho from CDMX. Powered by Forge&Hive.