Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplifying a/a #388

Closed
owiecc opened this issue Oct 25, 2021 · 4 comments
Closed

Simplifying a/a #388

owiecc opened this issue Oct 25, 2021 · 4 comments

Comments

@owiecc
Copy link

owiecc commented Oct 25, 2021

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 JuliaSymbolics/Symbolics.jl#351 (comment)

PS. Should we have a documented set of metadata (potentially) handled by the package? I cannot find any documentation on this.

@shashi
Copy link
Member

shashi commented Nov 2, 2021

@YingboMa

@0x0f0f0f
Copy link
Member

0x0f0f0f commented Nov 5, 2021

@0x0f0f0f
Copy link
Member

0x0f0f0f commented Nov 5, 2021

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)

@hersle
Copy link

hersle commented May 9, 2024

Now

using SymbolicUtils
@syms a
simplify(a/a)

gives

1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants