A Number with a Shadow

Math magic in Rust sparks ‘AI wrote this’ brawl

TLDR: A Rust library uses dual numbers—value plus built-in change—to get exact derivatives without tiny steps or noise. The comments explode into an AI-writing accusation, style complaints, and math flexes, while others ask if it scales to big neural nets, making it both useful and controversial.

A Rust dev drops a crowd-pleaser: tag every number with a “shadow” of how it changes, and you get exact slopes without the fussy tiny-step trick that makes computers cry. The demo shows the old approach collapsing into noise as the step gets too small, while dual numbers—value plus derivative—glide through with no guesswork. Applause? Not exactly.

The top vibe-checker blasts in: “text reeks of LLMs,” accusing the author of sounding like AI. Another reader groans about punchy micro-sentences—“Really let down by these short sentences”—and begs for a proper edit. Then a math knight rides in, flexing a neat mini-proof: “let e^2 = 0,” explaining dual numbers like it’s freshman calculus, and suddenly the thread is a seminar.

Meanwhile, fans are hyped: one function, swap the number type, and you get exact gradients for free. Skeptics ask if it really scales, with debates on forward-mode vs reverse-mode (think: few knobs vs millions of dials). Memes fly about the “V-shaped trap” and “rulers that measure your hand shake,” with jokes like “the tangent line is gaslighting my CPU.” The library, tang, ships a buffet of math tools and even runs a browser demo, but the real show is the comments: is this genius—or ChatGPT with calculus?

Key Points

  • Finite-difference derivatives suffer from a step-size tradeoff: truncation error decreases with smaller h, but catastrophic cancellation increases, causing failure below ~1e−8 in f64.
  • Dual numbers represent a value and its derivative, propagating exact derivatives via calculus rules without limits or step-size tuning.
  • A Rust implementation shows exact derivative computation (e.g., f(x)=x³−2x+1 at x=3 yields 25) using dual numbers seeded with (x,1).
  • An in-browser demo compiles Rust code to WebAssembly to compute x·sin(x), updating the tangent exactly as the point moves.
  • The tang Rust library generalizes math types over a Scalar trait, enabling forward-mode (Dual<S>) and reverse-mode (tang-ad) automatic differentiation, including grad, jacobian, and hessian.

Hottest takes

"text reeks of LLMs" — konmok
"Really let down by these short sentences" — cadamsdotcom
"let e^2 = 0." — nh23423fefe
Made with <3 by @siedrix and @shesho from CDMX. Powered by Forge&Hive.