3 ms·
There are Python packages that do what you want (units and numericalunits), but they aren't used much presumably due to the overhead they bring. You might also
by bjourne 9y ago
There are Python packages that do what you want (units and numericalunits), but they aren't used much presumably due to the overhead they bring. You might also be interested in Prolog which feature what is, essentially, invertible functions. E.g:
convert(Deg, Rad) :-
nonvar(Deg), Rad is Deg * pi / 180.
convert(Deg, Rad) :-
nonvar(Rad), Deg is Rad * 180 / pi.
In this case, it doesn't work well because of floating point math, but it works well for functions manipulating lists. The Factor language also feature function inversion in an addon: http://docs.factorcode.org/content/article-inverse%2Cintro.html http://docs.factorcode.org/content/article-inverse%2Cintro.h...
Afaik, figuring out what functions in general are invertible is an unsolved problem in computer science.