# openfermion.transforms.reduce_number_of_terms

Reduce the number of Pauli strings of operator using stabilizers.

This function reduces the number of terms in a string by merging terms that are identical by the multiplication of stabilizers. The resulting Pauli strings maintain their length, unless specified otherwise. In the latter case, a list of indices can be passed to manually indicate the qubits to be fixed.

It is possible to reduce the number of terms in a Hamiltonian by merging Pauli strings :math:H_1, \, H_2 that are related by a stabilizer :math:S such that :math:H_1 = H_2 \cdot S. Given a stabilizer generator :math:\pm X \otimes p this algorithm fixes the first qubit, such that every Pauli string in the Hamiltonian acts with either :math:Z or the identity on it. Where necessary, this is achieved by multiplications with :math:\pm X \otimes p: a string :math:Y \otimes h, for instance, is turned into :math:Z \otimes (\mp ih\cdot p). Qubits on which a generator acts as :math:Y (:math:Z) are constrained to be acted on by the Hamiltonian as :math:Z (:math:X) or the identity. Fixing a different qubit for every stabilizer generator eliminates all redundant strings. The fixed representations are in the end re-expressed as the shortest of the original strings, :math:H_1 or :math:H_2.

operator (QubitOperator): Operator of which the number of terms will be reduced. stabilizers (QubitOperator): Stabilizer generators used for the reduction. Can also be passed as a list of QubitOperator. maintain_length (Boolean): Option deciding whether the fixed Pauli strings are re-expressed in their original form. Set to False by default. output_fixed_positions (Boolean): Option deciding whether to return the list of fixed qubit positions. Set to False by default. manual_input (Boolean): Option to pass the list of fixed qubits positions manually. Set to False by default. fixed_positions (list): (optional) List of fixed qubit positions. Passing a list is only effective if manual_input is True.

reduced_operator (QubitOperator): Operator with reduced number of terms.

fixed_positions (list): (optional) Fixed qubits.

TypeError Input terms must be QubitOperator.
TypeError Input stabilizers must be QubitOperator or list.
StabilizerError Trivial stabilizer (identity).
StabilizerError Stabilizer with complex coefficient.
TypeError List of fixed qubits required if manual input True.
StabilizerError The number of stabilizers must be equal to the number of qubits manually fixed.
StabilizerError All qubit positions must be different.