ssmit1986 / DualNumbers

Implementation of dual numbers for automatic differentiation of programs
MIT License
23 stars 5 forks source link

Dual numbers can be implemented with 1 line in Mathematica #3

Closed Anixx closed 2 years ago

Anixx commented 2 years ago

This one:

$Pre=MatrixFunction[Function[ε,#],{{0,0},{1,0}}]/.{{a_,b_},{0,a_}}->a+ε b /.{{a_,0},{b_,a_}}->a+ε b&;

After this, most built-in functions work with dual numbers:

 I^ε

 Out= 1 + (I ε Pi)/2
SjoerdSmitWolfram commented 2 years ago

Thanks for the input. That's an interesting suggestion, but I doubt that this approach scales very well for the purpose of automatic differentiation in programs. For example, it does not work with the example in the Readme document. Also: programming with $Pre isn't very robust, I would say.