@@ -187,10 +187,13 @@ def targeted_conjugate_about(
187187 is a contraction between the given indices (indices for first $\cdot$,
188188 conj_indices for second $\cdot$).
189189
190- More specifically this computes
191- $\sum tensor_{i_0,...,i_{r-1},j_0,...,j_{r-1}} *
190+ More specifically, this computes:
191+
192+ $$
193+ \sum tensor_{i_0,...,i_{r-1},j_0,...,j_{r-1}} *
192194 target_{k_0,...,k_{r-1},l_0,...,l_{r-1}} *
193- tensor_{m_0,...,m_{r-1},n_0,...,n_{r-1}}^*$
195+ tensor_{m_0,...,m_{r-1},n_0,...,n_{r-1}}^*
196+ $$
194197
195198 where the sum is over indices where $j_s$ = $k_s$ and $s$ is in `indices`
196199 and $l_s$ = $m_s$ and s is in `conj_indices`.
@@ -212,7 +215,7 @@ def targeted_conjugate_about(
212215 buffer is used. Must have the same shape as target.
213216
214217 Returns:
215- The result the conjugation.
218+ The result of the conjugation, as a numpy array .
216219 """
217220 conj_indices = conj_indices or [i + target .ndim // 2 for i in indices ]
218221 first_multiply = targeted_left_multiply (tensor , target , indices , out = buffer )
@@ -230,28 +233,30 @@ def apply_matrix_to_slices(
230233 * ,
231234 out : Optional [np .ndarray ] = None ,
232235) -> np .ndarray :
233- """Left-multiplies an NxN matrix onto N slices of a numpy array.
234-
235- Example:
236- The 4x4 matrix of a fractional SWAP gate can be expressed as
237-
238- [ 1 ]
239- [ X**t ]
240- [ 1 ]
241-
242- Where X is the 2x2 Pauli X gate and t is the power of the swap with t=1
243- being a full swap. X**t is a power of the Pauli X gate's matrix.
244- Applying the fractional swap is equivalent to applying a fractional X
245- within the inner 2x2 subspace; the rest of the matrix is identity. This
246- can be expressed using `apply_matrix_to_slices` as follows:
247-
248- def fractional_swap(target):
249- assert target.shape == (4,)
250- return apply_matrix_to_slices(
251- target=target,
252- matrix=cirq.unitary(cirq.X**t),
253- slices=[1, 2]
254- )
236+ r"""Left-multiplies an NxN matrix onto N slices of a numpy array.
237+
238+ One example is that the 4x4 matrix of a fractional SWAP gate can be expressed as
239+
240+ $$
241+ \begin{bmatrix}
242+ 1 & & \\
243+ & X**t & \\
244+ & & 1 \\
245+ \end{bmatrix}
246+
247+ Where X is the 2x2 Pauli X gate and t is the power of the swap with t=1
248+ being a full swap. X**t is a power of the Pauli X gate's matrix.
249+ Applying the fractional swap is equivalent to applying a fractional X
250+ within the inner 2x2 subspace; the rest of the matrix is identity. This
251+ can be expressed using `apply_matrix_to_slices` as follows:
252+
253+ def fractional_swap(target):
254+ assert target.shape == (4,)
255+ return apply_matrix_to_slices(
256+ target=target,
257+ matrix=cirq.unitary(cirq.X**t),
258+ slices=[1, 2]
259+ )
255260
256261 Args:
257262 target: The input array with slices that need to be left-multiplied.
0 commit comments