SymbolicUtils.jl icon indicating copy to clipboard operation
SymbolicUtils.jl copied to clipboard

Simplifying a/a

Open owiecc opened this issue 4 years ago • 3 comments

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.

owiecc avatar Oct 25 '21 10:10 owiecc

@YingboMa

shashi avatar Nov 02 '21 23:11 shashi

See https://juliasymbolics.github.io/Metatheory.jl/dev/egraphs/#EGraph-Analyses

0x0f0f0f avatar Nov 05 '21 15:11 0x0f0f0f

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)

0x0f0f0f avatar Nov 05 '21 15:11 0x0f0f0f

Now

using SymbolicUtils
@syms a
simplify(a/a)

gives

1

hersle avatar May 09 '24 19:05 hersle