<a id="qf-operator-terms"></a>

# Operator Terms

The C API provides various functions to operate on the individual terms of an operator,
partitioning them based on their structure.

## Grouping

Refer to [Group operator terms: use the operator structure](../guides/grouping.html.md#grouping-explanation) for a detailed explanation of this module’s
functionality.

### Assignment

Rather than always relying on the user to provide the group indices themselves,
the C API provides a collection of functions which determine the grouping
information automatically.

| [`qf_ferm_op_group_terms_by_electronic_structure()`](qf-operators-terms-grouping.html.md#c.qf_ferm_op_group_terms_by_electronic_structure)   | Groups the terms of an operator by their electronic structure.   |
|------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------|

### Analysis

Group indices carry no intrinsic meaning: they only say which terms belong
together, never why. Accordingly, no function reports whether a grouping is
“correct”. The C API instead provides a collection of functions that each answer
one narrow, stated question about an existing grouping, so that an assumption a
downstream consumer makes can be checked up front rather than being paid for on
every call. Since these work with generic operator representations, they are
documented on the [grouping functions](qf-operators-terms-grouping.html.md) page.

## Filtering

The C API provides a collection of functions for removing terms from an operator
that do not contribute meaningfully to a downstream computation.

### Members

| [`qf_ferm_op_filter_diagonal_terms()`](qf-operators-terms-filtering.html.md#c.qf_ferm_op_filter_diagonal_terms)   | Filters out the terms of an operator that are diagonal.   |
|--------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------|

## Ordering

The C API provides functions to reorder the terms of an operator, either into a
canonical, coefficient-independent order or by group index.

Group indices are a per-term tag that says nothing about where those terms sit,
so the terms of one group are in general scattered throughout an operator.
Ordering by group gathers each into one contiguous run, which is what lets
`qf_op_type_split_out_groups` locate a requested group by binary search instead
of scanning every term.

### Members

| [`qf_ferm_op_canonical_order()`](qf-operators-terms-ordering.html.md#c.qf_ferm_op_canonical_order)         | Reorders the terms of a fermionic operator canonically.              |
|--------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------|
| [`qf_maj_op_canonical_order()`](qf-operators-terms-ordering.html.md#c.qf_maj_op_canonical_order)           | Reorders the terms of a Majorana operator canonically.               |
| [`qf_edge_op_canonical_order()`](qf-operators-terms-ordering.html.md#c.qf_edge_op_canonical_order)         | Reorders the terms of an edge-vertex operator canonically.           |
| [`qf_transfer_op_canonical_order()`](qf-operators-terms-ordering.html.md#c.qf_transfer_op_canonical_order) | Reorders the terms of a transfer-vertex operator<br/>canonically.    |
| [`qf_ferm_op_group_order()`](qf-operators-terms-ordering.html.md#c.qf_ferm_op_group_order)                 | Reorders the terms of a fermionic operator by group index.           |
| [`qf_maj_op_group_order()`](qf-operators-terms-ordering.html.md#c.qf_maj_op_group_order)                   | Reorders the terms of a Majorana operator by group index.            |
| [`qf_edge_op_group_order()`](qf-operators-terms-ordering.html.md#c.qf_edge_op_group_order)                 | Reorders the terms of an edge-vertex operator by group<br/>index.    |
| [`qf_transfer_op_group_order()`](qf-operators-terms-ordering.html.md#c.qf_transfer_op_group_order)         | Reorders the terms of a transfer-vertex operator by group<br/>index. |
