pprop.gates.utils module

pprop.gates.utils.get_frequency(term)[source]

Return the frequency of a CoeffTerm.

The frequency is defined as the total number of trigonometric factors, counting multiplicity:

\[\text{freq}(c, S, C) = |S| + |C|\]

where \(|S|\) and \(|C|\) are the lengths of sin_idx and cos_idx respectively. Repeated indices count as separate factors, so sin_idx = [0, 0] contributes a frequency of 2 (i.e. \(\sin^2(\theta_0)\)).

Parameters:

term (CoeffTerm) – A (coeff, sin_idx, cos_idx) tuple.

Returns:

Total number of trigonometric factors in the term.

Return type:

int

Examples

>>> get_frequency((0.5, [0, 0, 1], [2]))
4
>>> get_frequency((1.0, [], []))
0