# Is there an "in place" Toffoli gate?

I am trying to implement the multiplication of a scalar in $$\mathbb{Z}_2$$ and a polynomial in $$GF(2^n)$$ in Qiskit. One naive method of implementation that I can think of is:

for i in qpoly.qubit_indices:
qc.append(CCXGate(), [new_poly.qubit_indices[i], qpoly.qubit_indices[i], scalar.index])


Here, assume that my original quantum scalar is scalar, the quantum polynomial is qpoly, and the result is being stored in new_poly. qc is the QuantumCircuit, and qubit_indices contains the index of the qubits in the register it is called from. I am performing a term-by-term AND of the polynomial terms with the scalar. This will work because the scalar can only be $$0$$ or $$1$$.

However, the implementation of a Toffoli gate is expensive in practice, so I would like to avoid its use as much as possible. One thing I can optimize here is to do the operation in place, that is, store the new polynomial in qpoly itself.

Does there exist a combination of gates that performs the AND operation in-place? If not, is there some other more efficient way to perform this multiplication? Any help would be much appreciated!

This isn't possible, since the associated operation wouldn't be unitary if the scalar is $$0$$, as it would map both $$|0\rangle$$ and $$|1\rangle$$ to $$|0\rangle$$. The operation wouldn't be reversible and thus non-unitary.
If the scalar is classical, then it is easy to do: nothing for the $$0$$ case and a bunch of CNOTs for the other one.
Note that not all hope for optimisation is most though: if you know that one of the control is in the $$|+\rangle$$ state or if you later have to uncompute this Toffoli for instance, it is possible to use lighter implementations with less CNOT and $$T$$ gates.