JuliaSymbolics / SymbolicUtils.jl

Symbolic expressions, rewriting and simplification
https://docs.sciml.ai/SymbolicUtils/stable/
Other
527 stars 100 forks source link

Why don't `Pow` and `Div` have `hash` field? #465

Open bowenszhu opened 1 year ago

bowenszhu commented 1 year ago

https://github.com/JuliaSymbolics/SymbolicUtils.jl/blob/dcbe8613b1c6aa7572873b3308e0b1c50971296c/src/types.jl#L51-L61

https://github.com/JuliaSymbolics/SymbolicUtils.jl/blob/dcbe8613b1c6aa7572873b3308e0b1c50971296c/src/types.jl#L228-L256

For Add, Mul and Term, once hash() is called, the field hash is filled and then it doesn't need to recompute the hash down to the subtree when hash() is called later.

But Sym, Pow and Div don't share this benefit.

It would be inefficient for, for example, the following expression.

(((((a / b) ^ c) / d) ^ e) / f) ^ g