JuliaSymbolics / SymbolicUtils.jl

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

Simplify printing of Term(identity, x) #450

Closed moble closed 1 year ago

moble commented 2 years ago

It can be helpful to encode a quantity q that should not be evaluated as Term(identity, q). This is the idea behind JuliaSymbolics/Symbolics.jl#638, which allows irrationals like π to be treated symbolically, rather than (typically) as Float64 in symbolic expressions. But that means that identity(π) appears everywhere we would normally just write π. This PR simply adds another case to show_term, to check if the function is identity, and just shows the argument instead.

moble commented 1 year ago

@shashi @YingboMa Given that https://github.com/JuliaSymbolics/Symbolics.jl/pull/638 has been merged, I think this is more relevant now. Any thoughts?

shashi commented 1 year ago

Ahh. Well I don't know how I feel about this haha. Can we take this branch only if args[1] is not issym(..) or istree(..) that way it should only do it for constants. At the very least I agree we should do it for Irrationals. @YingboMa

YingboMa commented 1 year ago

Yeah, I agree. We should check that args[1] is not symbolic.

moble commented 1 year ago

@shashi Tests pass locally. I added the new test at the bottom of test/code.jl; let me know if you want it somewhere else.

shashi commented 1 year ago

You can just use repr to get a string... but looks good.