by cornstalks · 2w ago · 0 comments
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.
Which seems to be something Zig can't do.
Hell, you can define operators for generic length SIMD lane.
Can I write my SIMD/number abstraction and have it work?
Let's say I need rotors. With six dimensions. Can I overload it's basic numeric operations?