SymbolicUtils.jl
SymbolicUtils.jl copied to clipboard
Simplifying a/a
Simplification of a simple division a/a is currently not performed by the package.
using SymbolicUtils
@syms a
simplify(a/a) # ➞ a/a
I am aware of the special cases where a = 0 or a = ∞ but these could be avoided if we attach metadata (e.g. nonzero) to the variable. There was a small discussion on metadata in https://github.com/JuliaSymbolics/Symbolics.jl/pull/351#issuecomment-901453080
PS. Should we have a documented set of metadata (potentially) handled by the package? I cannot find any documentation on this.
@YingboMa
See https://juliasymbolics.github.io/Metatheory.jl/dev/egraphs/#EGraph-Analyses
We could have @rule a a::(nonzero && noninfinite)/a => a
Where
nonzero(x::Symbolic) = getmetadata(x, SignAnalysis) != 0
and
nonzero(g::EGraph, x::EClass) = let sign Metatheory.getdata(x, SignAnalysis, nothing)
sign != 0 && !isnothing(sign)
end
(same goes for noninfinite)
Where && is the unary functional and (&&)(a::Function, b::Function) = x -> a(x) && b(x)
Now
using SymbolicUtils
@syms a
simplify(a/a)
gives
1