neuralqx.utils.misc.levi_civita module

get_ijk_key(o, p)

Map a reference ordered triple to indices within another triple.

Given a reference triple o = (e1, e2, e3) and another triple p containing the same elements (typically a permutation), this function returns the index positions of o’s elements inside p as a tuple (i, j, k).

Example

o = ('a','b','c'), p = ('b','c','a') returns (2, 0, 1).

Parameters:
  • o (tuple) – Reference triple whose element order defines the canonical ordering.

  • p (tuple) – Target triple (typically a permutation of o) in which indices are looked up.

Return type:

tuple

Returns:

Tuple (i, j, k) giving the positions of o[0], o[1], o[2] in p.

Raises:

ValueError – If any element of o is not present in p.

get_sign_of_tuple_key(indices)

Compute the parity (+1/-1) of a permutation specified by index positions.

This function returns the sign of the permutation encoded by indices by counting the number of inversions. An even number of inversions yields +1 and an odd number yields -1. This is commonly used to obtain the Levi-Civita sign for a permuted triple.

Parameters:

indices (tuple) – Tuple of indices (e.g. (i, j, k)) encoding a permutation.

Return type:

int

Returns:

+1 if the permutation is even, otherwise -1.

compute_levi_civita_key(combinations, lc)

Populate a Levi-Civita lookup dictionary for permutations of a reference triple.

Given a list of permutations of a fixed triple (e1, e2, e3), this function computes the Levi-Civita sign ε(e1, e2, e3) for each permuted triple and stores it in lc. The dictionary is modified in-place and uses str(permuted_edge_triple) as the key.

The sign is computed by: 1) taking the first triple in combinations as the reference ordering, 2) mapping the reference elements into the permuted triple to obtain index positions, and 3) computing the parity of that permutation.

Parameters:
  • combinations (list) – List of triples (tuples) representing permutations of the same three items. The first element is treated as the reference ordering.

  • lc (dict) – Dictionary to be filled/updated with Levi-Civita signs. Modified in-place.

Return type:

None

Returns:

None.

Raises:

IndexError – If combinations is empty.