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

Simplify printing of Term(identity, x)

Open moble opened this issue 3 years ago • 5 comments

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 avatar Jun 30 '22 21:06 moble

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

moble avatar Jul 28 '22 01:07 moble

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

shashi avatar Jul 28 '22 02:07 shashi

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

YingboMa avatar Aug 01 '22 14:08 YingboMa

@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.

moble avatar Aug 01 '22 18:08 moble

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

shashi avatar Aug 02 '22 11:08 shashi