# DSL for specifying new tensors

When specifying a new tensor type, a few functions need to be provided:

`AngularMomentumAlgebra.system(::Type{TensorType})`

which returns the`AngularMomentumAlgebra.System`

the tensor acts on,`Base.iszero`

which indicates whether a reduced matrix element of the tensor vanishes without actually computing it,`couplings`

which generates all sets of quantum numbers the tensor couples to from a given set of quantum numbers,`rme`

which computes the actual reduced matrix element.

`AngularMomentumAlgebra.@tensor`

— Macro`@tensor(exprs, TensorType)`

Macro to generate `Base.iszero`

, `rme`

and `couplings`

for `TensorType`

, given a set of selection rules and an expression for the reduced matrix element.

`AngularMomentumAlgebra.strip′`

— Function`strip′(s::Symbol)`

Strip `s`

of a trailing `′`

, error if it is not present.

`AngularMomentumAlgebra.identify_quantum_numbers`

— Function`identify_quantum_numbers(selection_rules)`

Given the block of selection rules, identify the quantum numbers pertaining to the tensor under consideration. It is assumed that the left-hand side consists of a primed quantum number only, which is specified to be equal to an expression or belonging to a set/interval.

`AngularMomentumAlgebra.recursepm`

— Function`recursepm(e::Expr)`

Recursively expand the expression `e`

for instances of `±`

and `∓`

, generating `+`

and `-`

minus branches.

`recursepm(lhs, rhs)`

Recursively expand `lhs`

and `rhs`

for instances of `±`

and `∓`

and join all resulting cases into a short-circuiting `||`

test.

`AngularMomentumAlgebra.parse_selection_rule`

— Function`parse_selection_rule(rule)`

Parse a selection rule in the DSL of `@tensor`

; if the selection rule is an equality, its left- and right-hand sides are recursively expanded for possible cases of `±`

and `∓`

with `recursepm`

.

`AngularMomentumAlgebra.generate_iszero`

— Function`generate_iszero(TensorType, selection_rules, selection_rules_linenum)`

Generate a function for testing if the matrix element of `TensorType`

vanishes, given a set a quantum number deduced from `selection_rules`

, given at line number `selection_rules_linenum`

.

`AngularMomentumAlgebra.generate_rme`

— Function`generate_rme(TensorType, selection_rules, doc, rme, rme_linenum)`

Generate a function for computing the reduced matrix element of `TensorType`

, given a set a quantum number deduced from `selection_rules`

, along with the docstring and the definition `rme`

, given at line number `rme_linenum`

.

`AngularMomentumAlgebra.generate_couplings`

— Function`generate_copulings(TensorType, selection_rules, selection_rules_linenum)`

Generate a function that given the quantum numbers `γj`

generates lists of all permissible `γj′`

for which the reduced matrix element `⟨γj′||::TensorType||γj⟩`

does not vanish. This is deduced from the `selection_rules`

, given at line number `selection_rules_linenum`

.