-
Notifications
You must be signed in to change notification settings - Fork 116
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
Associative noncommutative rules #110
Comments
Nice issue! Thanks for digging for the problem! Maybe we could store another callback in |
Do you think it might work better if you just used @rule *(~~a, ~x::sym_isa(TypeA), ~y::sym_isa(TypeB), ~~b) => *((~~a)..., ~y*~x + one(~x), (~~b)...) Yup that should do the right thing! |
Thanks, this works perfectly! Still need some practice in finding what the "best" way to write things down is. Thanks a lot! |
Haha the rule of thumb is I'd welcome any documentation on this! Maybe a separate markdown file in docs/ with some thoughts on how to write rules for Q-Algebraic operations like these. Let me know if you end up using this in a package. Would love to have some examples we can link to! |
I was able to do it with Well, I am actually writing a package using this. It's not released yet, but hopefully will be at some point. It's in the context of quantum optics. The basic idea is to derive equations of motion for Q-commutative variables. Then you can perform some approximation (cumulant expansion) to convert these equations to c-number equations. Finally, I generate a function from this (basically just like MTK), which can be used in OrdinaryDiffEq. Most of the rules there are just copy-paste from SymbolicUtils, actually. You only need your own sorting (keeping non-commutativity in mind), and you need to expand |
Out of curiosity, is there a reason Qumulants isn't using MTK? Is it because of MTK can't work with the alternative algebras? This looks like something where you'll want to have features like sparse multithreaded Jacobians, so I hope we don't end up with diverging implementations of all of that, so I'd be curious to figure out where the abstractions have gone wrong (and it might just be in the algebras portion) |
It's just because of the non-commutative algebra Qumulants needs. At some point I'll switch to MTK for generating ODE functions. Right now this part of Qumulants is in a very basic state - I just wanted a cheap implementation that works for now. I don't plan on re-implementing things that MTK does really well anyways. Taking the current state of Qumulants, I could already convert the c-number expressions to MTK and leave things such as code generation and computing Jacobians to it. Anyway, down the line Qumulants will ideally just implement the symbolic derivation of Heisenberg equations (non-commutative differential equations) using a set of commutator rules, and functionality to convert these into commutative ones. Everything else would be SymbolicUtils and MTK. |
Sounds like a great application. I'll follow what you do and hopefully we can get you to where you need to be. Feel free to liberally file issues in both libraries. |
You can call
will need to be:
|
I'm working with q-commutative algebra, similar to #96, where some variables are noncommutative under multiplication but follow fixed commutation relations. In order to specify these, it would be practical to have associative noncommutative rules. These would be similar to
ACRule
but keep the order of the arguments.For example, consider two noncommutative variables
a::TypeA
andb::TypeB
, which have the commutation relation[a,b]=1
. I would like to rewritea*b => b*a +1
. If I dothen
a*b
is simplified correctly, but as soon as there are multiple arguments such as in2*a*b
it does no longer work. What I currently do is step through the arguments of a multiplication and look for consecutive occurrences ofa
andb
.This should be much simpler with something like
I found that this can be almost done already with the following:
The only problem with this approach is that when simplifying, this line
SymbolicUtils.jl/src/rule.jl
Line 326 in 3fd27d8
b*a*b*a
. Changing that to keep the order works for my case, but causes other issues (tests fail).Alternatively, one can implement a custom
ANCRule
type, which is essentially a copy-paste ofACRule
, but with a slightly modified application to expressions. This is what I found to work best for now, since it also doesn't require changes in SymbolicUtils directly.Would it make sense to have this implemented directly in SymbolicUtils? Is this even the right approach? Any input is appreciated, thanks.
The text was updated successfully, but these errors were encountered: