JuliaSymbolics / SymbolicUtils.jl

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

Simplifier doeas not work for AbstracType symbol #440

Closed albertomercurio closed 2 years ago

albertomercurio commented 2 years ago

Hello,

I'm implementing a non-commuting algebra, which is goverded by the rules of quantum operators, for example a b - b a = 1.

I'm developing a Julia package, which is hosted by this repo. I followed the source code of this repository, and I copied the simplify_rules.jl file.

However, when I apply the serial_simplifier or the serial_expand_simplifier it fails.

julia> using SecondQuantization
julia> simplify(b * a, rewriter = serial_simplifier())

MethodError: no method matching (::Metatheory.Rewriters.Fixpoint{Metatheory.Rewriters.IfElse{typeof(SymbolicUtils.has_trig_exp), Metatheory.Rewriters.Walk{:post, Metatheory.Rewriters.IfElse{SecondQuantization.var"#84#157", Metatheory.Rewriters.Chain, Metatheory.Rewriters.IfElse{SecondQuantization.var"#85#158", Metatheory.Rewriters.Chain, Metatheory.Rewriters.Empty}}, typeof(TermInterface.similarterm), false}, Metatheory.Rewriters.Walk{:post, Metatheory.Rewriters.Chain, typeof(TermInterface.similarterm), false}}})()
Closest candidates are:
  (::Metatheory.Rewriters.Fixpoint)(!Matched::Any) at ~/.julia/packages/Metatheory/XcKKW/src/Rewriters.jl:116

And it is strange, since if I import the rewriter it works

julia> using SymbolicUtils, SymbolicUtils.Rewriters
julia> simplify(b * a, rewriter = If(istree, Fixpoint(default_simplifier())))

a * b

but If(istree, Fixpoint(default_simplifier())) is exactly the serial_simplifier!

The stranger thing is that if I run the threaded_simplifier it works

julia> simplify(b * a, rewriter = threaded_simplifier(100))

a * b
albertomercurio commented 2 years ago

It was easy! The correct expression is without the brackets ()

julia> simplify(b * a, rewriter = serial_simplifier)

a*b