cadabra2 icon indicating copy to clipboard operation
cadabra2 copied to clipboard

Add get_indices() and get_dummy() to Indices class in python

Open dominicprice opened this issue 2 years ago • 0 comments

This adds two functions to core/pythoncdb/py_properties.cc:

std::vector<Ex> indices_get_all(const Indices* indices, bool include_wildcards) which returns all the indices associated with the Indices object. This just queries the kernel's properties for all patterns matching indices.

Ex indices_get_dummy(const Indices* indices, const Ex_ptr& ex) which returns an index form indices which does not appear in ex . This just calls the get_dummy function from IndexClassifier.

These are attached to the Py_Indices object to be exported to Python which makes it possible to write things like:

{a,b,c,d,e#}::Indices.

# Mock of getting the index property from a node
for node in $x_a$:
  i = Indices.get(node)

# Get all indices including wildcards - returns [^a,^b,^c,^d,^e#,_a,_b,_c,_d,_e#]
i.get_indices(True);

# Get all indices without wildcards - returns [^a,^b,^c,^d,_a,_b,_c,_d]
i.get_indices();

# Get covariant indices - returns [_a, _b, _c, _d, _e#]
[idx for idx in i.get_indices() if idx.top().parent_rel == parent_rel_t.sub];

# Get a dummy index - returns $^b$
i.get_dummy($x_a$);

# Get a dummy index from a wildcard - returns $^e3$
i.get_dummy($x_{a b c d e1 e2}$);

dominicprice avatar Jun 12 '22 20:06 dominicprice