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

Symbols gets sorted even for user types #206

Closed
JanisErdmanis opened this issue Feb 19, 2021 · 3 comments
Closed

Symbols gets sorted even for user types #206

JanisErdmanis opened this issue Feb 19, 2021 · 3 comments

Comments

@JanisErdmanis
Copy link

I want to implement some noncommutative algebra rules for revising lengthy and thus error-prone calculations, as explained in the discourse. Currently, I am facing an issue that the symbols, even for user types, are being sorted automatically by their names. Which, for instance, prevents me from applying a rule:

abstract type SU2 end
@syms ηx::SU2 ηy::SU2 ηz::SU2
(@rule ηy*ηx => -im*ηz)(ηy*ηx)==nothing
@shashi
Copy link
Member

shashi commented Feb 19, 2021

Yes this is because there’s an issue which required us to define * on Symbolic rather thsn on Symbolic{Number}

You can define the method on Symbolic{SU2} to construct a Term instead of a Mul which would avoid the sort.

Should get closed with #155

@JanisErdmanis
Copy link
Author

Ok. So the rule indeed works on

(@rule  ηy*ηx => -im*ηz)(Term(*, [ηy, ηx])

However, if I try to automate the process by defining a method for * on Symbolic{SU2} like:

*(x::Symbolic{SU2}, y::Symbolic{SU2}) = Term(*, [x, y])

the rule matching fails with an error message:

Failed to apply rule ηy * ηx => -im * ηz on expression ηy * ηx
  (::SymbolicUtils.Rule{SymbolicUtils.Term{Any}, SymbolicUtils.var"#term_matcher#76"{Tuple{SymbolicUtils.var"#literal_matcher#72"{typeof(Main.workspace40.:*)}, SymbolicUtils.var"#literal_matcher#72"{SymbolicUtils.Sym{Main.workspace3.SU2}}, SymbolicUtils.var"#literal_matcher#72"{SymbolicUtils.Sym{Main.workspace3.SU2}}}}, Main.workspace40.var"#51#52"})(::SymbolicUtils.Term{Any})@rule.jl:142
    top-level scope

Are there a better way?

@shashi
Copy link
Member

shashi commented Apr 1, 2021

Okay now we throw the appropriate method errors and the usual operations are only defined on Symbolic numbers.

@shashi shashi closed this as completed Apr 1, 2021
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

2 participants