Better HN
topnewbestaskshowjobs
Log inSign up

jlotze

1 karma · joined Nov 13, 2026 (2w ago) · 2 submissions

Submissions

comment 2w ago · link · parent

In C++, the practical AD approach for large existing code-bases is operator-overloading. Swapping double for an active class, overload all math operations for this type, recording the computational graph on a tape, and then run the tape backwards for computing derivatives. This only works because operator-overloading and templates are language features.

Zig has no operator overloading, so tape-based AD means rewriting arithmetic as functon calls. Its compile-time code gen could instead do source transforamtion (like Enzyme / Tapenade, etc), which is a different trade-off.

Concrete example: With operator-overloading in C++, the Black-Scholes d1 expression, a statement with 5-inputs and 10 math operations, can be recorded with 10 nodes and operand links on tape. If adding expression templates, this reduces to a single tape entry function call, the rest is handled by the compiler. And the code is still readable like the original with double type.