
    z	i                     t    S r SSKJr  SSKrSSKJrJrJr  SSK	J
r
  SSKJr   " S S\5      r " S	 S
\5      rg)zExact reciprocal rotation.    )iscloseN)QuantumCircuitQuantumRegisterGate)UCRYGate)deprecate_funcc                   `   ^  \ rS rSrSr\" SSSS9 SS\S\S	\S
\	SS4
U 4S jjj5       r
SrU =r$ )ExactReciprocal   zxExact reciprocal

.. math::

    |x\rangle |0\rangle \mapsto \cos(1/x)|x\rangle|0\rangle + \sin(1/x)|x\rangle |1\rangle
z2.2zAUse the class qiskit.circuit.library.ExactReciprocalGate instead.zin Qiskit 3.0)sinceadditional_msgremoval_timelinenum_state_qubitsscalingneg_valsnamereturnNc                    > [        US5      n[        SS5      n[        TU ]	  XVUS9  [        XX4S9nU R	                  XpR
                  5        g)a  
Args:
    num_state_qubits: The number of qubits representing the value to invert.
    scaling: Scaling factor :math:`s` of the reciprocal function, i.e. to compute
        :math:`s / x`.
    neg_vals: Whether :math:`x` might represent negative values. In this case the first
        qubit is the sign, with :math:`|1\rangle` for negative and :math:`|0\rangle` for
        positive.  For the negative case it is assumed that the remaining string represents
        :math:`1 - x`. This is because :math:`e^{-2 \pi i x} = e^{2 \pi i (1 - x)}` for
        :math:`x \in [0,1)`.
    name: The name of the object.

.. note::

    It is assumed that the binary string :math:`x` represents a number < 1.
state   flag)r   labelN)r   super__init__ExactReciprocalGateappendqubits)	selfr   r   r   r   qr_stateqr_flag
reciprocal	__class__s	           l/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/circuit/library/arithmetic/exact_reciprocal.pyr   ExactReciprocal.__init__   sM    0 ##3W=!!V,6()9HY
J,     Fz1/x)__name__
__module____qualname____firstlineno____doc__r   intfloatboolstrr   __static_attributes____classcell__r#   s   @r$   r
   r
      sY     Z( Z_- #-.3-?C-SV-	-
-r&   r
   c                   P   ^  \ rS rSrSr SS\S\S\S\SS4
U 4S	 jjjr	S
 r
SrU =r$ )r   =   a  Implements an exact reciprocal function.

For a state :math:`|x\rangle` and a scaling factor :math:`s`, this gate implements the operation

.. math::

    |x\rangle |0\rangle \mapsto
        \cos\left(\arcsin\left(s\frac{2^n}{x}\right)\right)|x\rangle|0\rangle +
        \left(s\frac{2^n}{x}\right)|x\rangle|1\rangle.

States representing :math:`x = 0` or :math:`s 2^n / x \geq 1` are left unchanged, since
this function would not be defined.
r   r   r   r   r   Nc                 D   > [         TU ]  SUS-   / US9  X l        X0l        g)a  
Args:
    num_state_qubits: The number of qubits representing the value to invert.
    scaling: Scaling factor :math:`s` of the reciprocal function, i.e. to compute
        :math:`s / x`.
    neg_vals: Whether :math:`x` might represent negative values. In this case the first
        qubit is the sign, with :math:`|1\rangle` for negative and :math:`|0\rangle` for
        positive.  For the negative case it is assumed that the remaining string represents
        :math:`1 - x`. This is because :math:`e^{-2 \pi i x} = e^{2 \pi i (1 - x)}` for
        :math:`x \in [0,1)`.
    label: The label of the object.

.. note::

    It is assumed that the binary string :math:`x` represents a number < 1.
r
   r   r   N)r   r   r   r   )r   r   r   r   r   r#   s        r$   r   ExactReciprocalGate.__init__L   s,    & 	*,<q,@"ER r&   c           
         U R                   S-
  n[        US5      n[        SS5      n[        X#5      nS/nU R                  (       a  SUS-
  -  OSU-  n[	        SU5       H  n[        U R                  U-  U-  SSS9(       a!  UR                  [        R                  5        MD  U R                  U-  U-  S:  a:  UR                  S[        R                  " U R                  U-  U-  5      -  5        M  UR                  S5        M     UR                  [        U5      US   /US [        U5      U R                  -
   -   5        U R                  (       Gaa  UR                  [        U Vs/ s H  o* PM     sn5      R                  5       US	   /US   /-   US S	 -   5        S/n	[	        SU5       H  n[        U R                  S	-  SXv-  -
  -  S	SS9(       a"  U	R                  [        R                  * 5        MJ  [        R                  " U R                  S	-  SXv-  -
  -  5      S:  a?  U	R                  S[        R                  " U R                  S	-  SXv-  -
  -  5      -  5        M  U	R                  S5        M     UR                  [        U	5      R                  5       US	   /US   /-   US S	 -   5        X@l        g s  snf )
Nr   r   r   g           gh㈵>)abs_tolr   )
num_qubitsr   r   r   ranger   r   r   nppiarcsinr   lencontrolabs
definition)
r   r   r    r!   circuitanglesnlitheta
angles_negs
             r$   _defineExactReciprocalGate._defined   sh   ??Q."#3W=!!V, 3,0MMQ#a'(qBR?R q"At||b(1,a>bee$"Q&*a"))DLL2,=,A"BBCc"  	x''!*A`3x=SWS`S`C`8a)ab===NNf5fU&f56>>@"'!*-"= J1b\4<<2.!af*=r4P%%ruuf-VVDLLB/1qv:>?!C%%a"))DLLB4G1qv:4V*W&WX%%c* " NN$,,."'!*0MPXY\Z\P]0] " 6s   *J>)rE   r   r   r(   )r)   r*   r+   r,   r-   r.   r/   r0   r1   r   rL   r2   r3   r4   s   @r$   r   r   =   sK     [`! #!.3!?C!TW!	! !0%" %"r&   r   )r-   mathr   numpyr?   qiskit.circuitr   r   r   (qiskit.circuit.library.generalized_gatesr   qiskit.utils.deprecationr   r
   r   r'   r&   r$   <module>rS      s7    !   @ @ = 3%-n %-PL"$ L"r&   