On Friday, March 21, 2014 4:35:08 PM UTC+1, Matthew wrote:
>
> Efficient pattern dispatch is hard, particularly when you have associative 
> and commutative operators.  If we don't care about 
> associativity/commutitivity then it's fairly doable.  This is the sort of 
> thing I would build in my spare time if the community actually intended to 
> use it.
>

Actually, tensors have an even more complicated multiplicative symmetry 
support:

https://github.com/sympy/sympy/blob/master/sympy/tensor/tensor.py#L692

That is, there are arbitrary groups with their own mutual commutation 
properties.

In any case, have a look at how Tracer.m works:

http://www.physics.uc.edu/~johnson/HEP/mathematica/Tracer.m

The function *tr[ ]* to calculate the trace is overloaded many times. It 
implies a pattern dispatch on the structure of its arguments, which is then 
efficiently handled by Mathematica. I call this *pattern dispatch*, which 
is a generalization of multiple dispatch involving pattern matching.

My implementation of Kahane's algorithm is not clear at all, the logic is 
unreadable without comments:
https://github.com/sympy/sympy/blob/master/sympy/physics/hep/gamma_matrices.py#L404

I implemented it using standard procedural programming, as Python is meant 
to. I believe that the logic of QFT should be implemented through pattern 
matching, it is much easier. The same is true for Quantum Mechanics.

Pattern matching would not work that well on sympy.tensor.tensor objects, 
because they have a complicated inner structure. That is, the tensor 
structure also stores index symmetry information about its indices. So, a 
tensor A(i, j) does not have i and j indices in its args, rather a 
complicated tree with much information. I believe that this problem could 
be addressed by storing symmetry info in a separate data structure, maybe 
resembling the new assumptions system.

I am already considering a similar approach to store components data 
outside of the tensor objects, by a dictionary lookup. See 
https://github.com/sympy/sympy/pull/2805

(by the way, components data on sympy.tensor.tensor was an idea I had to 
allow also for tensor-components based computations, alongside with the 
abstract tensor notation).

If we can make sure that tensor symmetry information can be stored outside 
of their args tree, then pattern matching on tensors could become much 
easier.

By the way, it is *not *about *efficient* pattern matching, it's just the 
args structure of the current tensors which is a mess to match against.

I can try to perform such rewrite on the tensor module, and it would also 
be nice to have the ability to define pattern dispatched functions (a 
generalization of multiple dispatch). This would endow Peter Petrov with a 
powerful tool to implement QFT.

@Matthew Rocklin: would you try to generalize your multiple dispatch module 
to pattern dispatch?

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/d14d89ca-79a7-49de-a9f4-4589d66753b0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to