Open brandonwillard opened 3 years ago
I think the more general true_div
should be the canonical form even though most division rewrites probably apply only to the more restricted 1/x
cases...
Unless, of course, it complicates things too much (e.g., due to other less important rewrites that may affect the numerator)
Just found out that reciprocal is canonicalized to power(x, -1)
here: https://github.com/aesara-devs/aesara/blob/57a1eb72b89ade64920fe5b7196062792f2d6e8a/aesara/tensor/math_opt.py#L1911-L1916
Currently, expressions like
1 / (1 + x)
, which are expressed using atrue_div
Op
, aren't converted toreciprocal(1 + x)
during canonicalization. This implies that—among other things—we don't consider the two graphs equivalent in some sense, but they very much are.There is an existing rewrite that takes care of this (i.e.
local_div_to_reciprocal
), but it's under the "specialize" set of optimizations.If we made
local_div_to_reciprocal
a canonicalization rewrite, then we could, for instance, removelocal_reciprocal_1_plus_exp
(after replacingtrue_div
withreciprocal
in a few place), because it would be redundant. The same is true if we decided to go withtrue_div
as the canonical form, instead ofreciprocal
; either way, we should only have one form for these graphs.