Welcome to Cadabra Q&A, where you can ask questions and receive answers from other members of the community.
+1 vote

I am fiddling with making a very simple "Fermion" package that automatically handles assigning SelfAntiCommuting and AntiCommuting whenever you declare an object to be a Fermion.

Right now, I just keep calling AntiCommuting whenever I add a fermion to an internal list of fermions. But does this mean I have lists in memory that look like:

{F1, F2}::AntiCommuting {F1, F2, F3}::AntiCommuting {F1, F2, F3, F4}::AntiCommuting ... and so forth?

Or is anticommuting stored as a pairwise property?

Related question: does anyone know a way to query for existing AntiCommuting information?

in General questions by (1.0k points)

1 Answer

+1 vote

None of the above ;-)

First, remember that this is all stored on the C++ side. All properties are stored in two ways: a map from patterns to property objects, and a map from property objects to patterns. So for

{F1, F2, F3}::AntiCommuting

there is a map props which contains

F1 -> A1
F2 -> A1
F3 -> A1

where A1 is an instance of the property object AntiCommuting. And there is a map pats which contains

A1 -> F1
A1 -> F2
A1 -> F3

(so an ordered multi-map, to be precise).

Now the properties object which contains all this has methods to find a shared AntiCommuting object for two given patterns. So you can ask it "Do F1 and F2 have an AntiCommuting property in common?".

(This all looks terribly complicated until you start to build in property inheritance and the like, when simpler solutions tend to be insufficient).

Now most of this is not easily accessible on the Python side because it was written long before I added the Python wrapper on top of the C++ core. Your solution (of repeating the list property declaration) is by far the simplest. Of course if you run into something that cannot be done that way.

Unfortunately, while there is a way to retrieve property information for an expression using [PropertyName].get(...), you cannot use this to check whether to elements are in the same list (yet). So if you do

{F1, F2}::AntiCommuting;
p1 = AntiCommuting.get($F1$)
p2 = AntiCommuting.get($F2$)
p1 == p2

you get False, and there is no

p = AntiCommuting($F1$, $F2$)

yet either (which would probably be the easiest way out).

by (82.6k points)

Thanks for the comprehensive answer!

Just out of curiousity: Is there a way to erase a list in memory?

So if I have {F1, F2}::AntiCommuting, is there a way to unset that property and then set {F1,F2,F3}::AntiCommuting?

In practice, I doubt speed is an issue; it just bugs me that I have redundant info stored. ;-)

No, not on the Python side. You can see with the debug function properties() that the properties just get added, but that function just prints something, it doesn't actually return a list (or those props or pats) that you can manipulate.

...