
    z	i                         S r SSKrSSKJrJr  SSKJr  SSKJr  \R                  S:  a  SSK
Jr  OSSKJr   " S S	\5      rg)
z$
Mixin for gate operator interface.
    N)ABCabstractmethod)Integral)QiskitError)      )Selfc                       \ rS rSrSrS\4S jrS\4S jrS\4S jrS\4S jr	\
S\4S j5       r\
S\4S	 j5       r\
SS\4S jj5       rSS\4S jjrS\4S jrSrg
)
GroupMixin   a_  Abstract Mixin for operator group operations.

This class defines the following methods

    - :meth:`compose`
    - :meth:`dot`
    - :meth:`tensor`
    - :meth:`expand`
    - :meth:`power`

And the following operator overloads:

    - ``&``, ``__and__`` -> :meth:`compose`
    - ``@``, ``__matmul__`` -> :meth:`dot`
    - ``^``, ``__xor__`` -> `:meth:`tensor`
    - ``**``, ``__pow__`` -> :meth:`power`

The following abstract methods must be implemented by subclasses
using this mixin

    - ``compose(self, other, qargs=None, inplace=False)``
    - ``tensor(self, other)``
    - ``expand(self, other)``
returnc                 $    U R                  U5      $ Ncomposeselfothers     d/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/quantum_info/operators/mixins/group.py__and__GroupMixin.__and__7   s    ||E""    c                 $    U R                  U5      $ r   )power)r   ns     r   __pow__GroupMixin.__pow__:   s    zz!}r   c                 $    U R                  U5      $ r   )tensorr   s     r   __xor__GroupMixin.__xor__=   s    {{5!!r   c                 $    U R                  U5      $ r   )dotr   s     r   
__matmul__GroupMixin.__matmul__@   s    xxr   c                     g)a  Return the tensor product with another CLASS.

Args:
    other (CLASS): a CLASS object.

Returns:
    CLASS: the tensor product :math:`a \otimes b`, where :math:`a`
        is the current CLASS, and :math:`b` is the other CLASS.

.. note::
    The tensor product can be obtained using the ``^`` binary operator.
    Hence ``a.tensor(b)`` is equivalent to ``a ^ b``.

.. note:
    Tensor uses reversed operator ordering to :meth:`expand`.
    For two operators of the same type ``a.tensor(b) = b.expand(a)``.
N r   s     r   r   GroupMixin.tensorC       r   c                     g)a  Return the reverse-order tensor product with another CLASS.

Args:
    other (CLASS): a CLASS object.

Returns:
    CLASS: the tensor product :math:`b \otimes a`, where :math:`a`
        is the current CLASS, and :math:`b` is the other CLASS.

.. note:
    Expand is the opposite operator ordering to :meth:`tensor`.
    For two operators of the same type ``a.expand(b) = b.tensor(a)``.
Nr'   r   s     r   expandGroupMixin.expandW   r)   r   Nc                     g)aW  Return the operator composition with another CLASS.

Args:
    other (CLASS): a CLASS object.
    qargs (list or None): Optional, a list of subsystem positions to
                          apply other on. If None apply on all
                          subsystems (default: None).
    front (bool): If True compose using right operator multiplication,
                  instead of left multiplication [default: False].

Returns:
    CLASS: The composed CLASS.

Raises:
    QiskitError: if other cannot be converted to an operator, or has
                 incompatible dimensions for specified subsystems.

.. note::
    Composition (``&``) by default is defined as `left` matrix multiplication for
    matrix operators, while ``@`` (equivalent to :meth:`dot`) is defined as `right` matrix
    multiplication. That is that ``A & B == A.compose(B)`` is equivalent to
    ``B @ A == B.dot(A)`` when ``A`` and ``B`` are of the same type.

    Setting the ``front=True`` kwarg changes this to `right` matrix
    multiplication and is equivalent to the :meth:`dot` method
    ``A.dot(B) == A.compose(B, front=True)``.
Nr'   )r   r   qargsfronts       r   r   GroupMixin.composeg   r)   r   c                 "    U R                  XSS9$ )a  Return the right multiplied operator self * other.

Args:
    other (CLASS): an operator object.
    qargs (list or None): Optional, a list of subsystem positions to
                          apply other on. If None apply on all
                          subsystems (default: None).

Returns:
    CLASS: The right matrix multiplied CLASS.

.. note::
    The dot product can be obtained using the ``@`` binary operator.
    Hence ``a.dot(b)`` is equivalent to ``a @ b``.
T)r.   r/   r   )r   r   r.   s      r   r#   GroupMixin.dot   s      ||Ed|;;r   c                     [        U[        5      (       a  US:  a  [        S5      eU n[        SU5       H  nUR	                  U 5      nM     U$ )aC  Return the compose of a operator with itself n times.

Args:
    n (int): the number of times to compose with self (n>0).

Returns:
    CLASS: the n-times composed operator.

Raises:
    QiskitError: if the input and output dimensions of the operator
                 are not equal, or the power is not a positive integer.
   z,Can only power with positive integer powers.)
isinstancer   r   ranger#   )r   r   ret_s       r   r   GroupMixin.power   sJ     !X&&!a%LMMq!A''$-C 
r   r'   )NFr   )__name__
__module____qualname____firstlineno____doc__r	   r   r   r    r$   r   r   r+   r   r#   r   __static_attributes__r'   r   r   r   r      s    2# #D " "4  t  & t     :< <$$ r   r   )r>   sysabcr   r   numbersr   qiskit.exceptionsr   version_infotypingr	   typing_extensionsr   r'   r   r   <module>rG      s:     #  )w&N Nr   