News for hackers. Stuff that matters.
Re:Writing a Mathematica Interpreter in Typescript by peter_d_sherman on Tuesday October 22, 2024 @02:55PM (#41917454)
>"Writing a toy differentiator turns out to be shockingly easy. It’s a near verbatim transcription of differentiation rules from any calculus textbook:

D[_?NumberQ, x_Symbol] = 0;

D[x_, x_Symbol] = 1;

D[Times[expr1_, expr2_], x_Symbol] = D[expr1, x] expr2 + D[expr2, x] expr1;

D[Plus[expr1_, expr2_], x_Symbol] = D[expr1, x] + D[expr2, x];

D[Sin[x_], x_Symbol] = Cos[x];

D[Cos[x_], x_Symbol] = -Sin[x];

D[f_Symbol[expr_], x_Symbol] := (D[f[x], x] /. x -> expr) * D[expr, x];

D[Power[expr_, p_Integer], x_Symbol] := p expr^(p - 1) * D[expr, x]; "

Absolutely brilliant! And simple! And terse! And brilliant!

There are no comments on this comment yet.