|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/quantum/blob/v0.7.6/tensorflow_quantum/core/ops/math_ops/inner_product_op.py#L71-L151) |

Calculate the inner product between circuits.

    tfq.math.inner_product(
        programs, symbol_names, symbol_values, other_programs
    )

Compute (potentially many) inner products between the given circuits and
the symbol free comparison circuits.

Calculates out\[i\]\[j\] as:

\\\[
\\langle \\psi_{ ext{programs\[i\]} }( ext{symbol_values\[i\]}) \\mid
\\psi_{ ext{other_programs\[j\]} }
angle
\\\]

    symbols = sympy.symbols('alpha beta')
    qubits = cirq.GridQubit.rect(1, 2)
    reference_circuits = [
        cirq.Circuit((cirq.H**symbols[0]).on_each(qubits)),
        cirq.Circuit(
            cirq.X(qubits[0]) ** symbols[0],
            cirq.Y(qubits[1]) ** symbols[1])
    ]
    other_circuits = [
        cirq.Circuit(cirq.X.on_each(qubits)),
        cirq.Circuit((cirq.Y**0.125).on_each(qubits)),
        cirq.Circuit((cirq.X**0.5).on_each(qubits))
    ]
    reference_tensor = tfq.convert_to_tensor(reference_circuits)
    symbol_tensor = tf.convert_to_tensor([s.name for s in symbols])
    values_tensor = tf.convert_to_tensor(np.arange(4).reshape(2, 2))
    other_tensor = tfq.convert_to_tensor([other_circuits, other_circuits])
    ip = tfq.math.inner_product(reference_tensor, symbol_tensor,
                                values_tensor, other_tensor)
    ip
    tf.Tensor(
        [[ 0+0.j, 8.8871640e-01+0.3681184j,
           0+0.5j],
         [ 0+0.j, 7.3223300e-02-0.17677669j,
           0-0.5j]],shape=(2, 3), dtype=complex64)

> [!NOTE]
> **Note:** `other_programs` must not contain any free symbols. These can be resolved beforehand with [`tfq.resolve_parameters`](https://www.tensorflow.org/quantum/api_docs/python/tfq/resolve_parameters).

<br />

<br />

<br />

| ## Args ||
|---|---|
| `programs` | [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) of strings with shape \[batch_size\] containing the string representations of the circuits |
| `symbol_names` | [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) of strings with shape \[n_params\], which is used to specify the order in which the values in `symbol_values` should be placed inside of the circuits in `programs`. |
| `symbol_values` | [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) of real numbers with shape \[batch_size, n_params\] specifying parameter values to resolve into the circuits specificed by programs, following the ordering dictated by `symbol_names`. |
| `other_programs` | [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) of strings with shape \[batch_size, n_others\] containing the string representations of the circuits with which to compute the overlap on `programs` with. Must not contain any free symbols. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) with shape \[batch_size, n_others\] where `out[i][j]` is equal to the inner product of `programs[i]` with `symbol_values[i]` resolved in and `other_programs[i][j]`. ||

<br />