§
    ¹³Ùg©  ã                   óV   — d Z ddlmZ ddlZddlmZmZ ddlm	Z	  G d„ de¦  «        Z
dS )zExact reciprocal rotation.é    )ÚiscloseN)ÚQuantumCircuitÚQuantumRegister)ÚUCRYGatec                   ó<   ‡ — e Zd ZdZ	 ddededededd	f
ˆ fd
„Zˆ xZ	S )ÚExactReciprocalz„Exact reciprocal

    .. math::

        |x\rangle |0\rangle \mapsto \cos(1/x)|x\rangle|0\rangle + \sin(1/x)|x\rangle |1\rangle
    Fú1/xÚnum_state_qubitsÚscalingÚneg_valsÚnameÚreturnNc           
      óâ  •— t          |d¦  «        }t          dd¦  «        }t          |||¬¦  «        }dg}|rd|dz
  z  nd|z  }	t          d|	¦  «        D ]Œ}
t          ||	z  |
z  dd¬¦  «        r |                     t
          j        ¦  «         Œ:||	z  |
z  dk     r1|                     dt          j        ||	z  |
z  ¦  «        z  ¦  «         Œw|                     d¦  «         Œ�|                     t          |¦  «        |d	         g|d
t          |¦  «        |z
  …         z   d¬¦  «         |�ru|                     t          d„ |D ¦   «         ¦  «                             ¦   «         |d         g|d	         gz   |d
d…         z   d¬¦  «         dg}t          d|	¦  «        D ]±}
t          |dz  d|
|	z  z
  z  dd¬¦  «        r!|                     t
          j         ¦  «         ŒAt          j        |dz  d|
|	z  z
  z  ¦  «        dk     r7|                     dt          j        |dz  d|
|	z  z
  z  ¦  «        z  ¦  «         Œœ|                     d¦  «         Œ²|                     t          |¦  «                             ¦   «         |d         g|d	         gz   |d
d…         z   d¬¦  «          t          ¦   «         j        |j        d|iŽ |                      |                     ¦   «         | j        d¬¦  «         d
S )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   g        é   gñhãˆµøä>)Úabs_tolr   NT)Úinplacec                 ó   — g | ]}| ‘ŒS © r   )Ú.0Úthetas     úh/granary/edev/quantum/lib/python3.11/site-packages/qiskit/circuit/library/arithmetic/exact_reciprocal.pyú
<listcomp>z,ExactReciprocal.__init__.<locals>.<listcomp>E   s   € Ð5Ð5Ð5 U˜5˜&Ð5Ð5Ð5ó    éÿÿÿÿr   )Úqubitsr   )r   r   Úranger   ÚappendÚnpÚpiÚarcsinÚcomposer   ÚlenÚcontrolÚabsÚsuperÚ__init__ÚqregsÚto_gater   )Úselfr
   r   r   r   Úqr_stateÚqr_flagÚcircuitÚanglesÚnlÚiÚ
angles_negÚ	__class__s               €r   r)   zExactReciprocal.__init__   s7  ø€ õ& #Ð#3°WÑ=Ô=ˆÝ! ! VÑ,Ô,ˆÝ  ¨7¸Ð>Ñ>Ô>ˆà�ˆØ,4ÐMˆQÐ# aÑ'Ñ(Ð(¸!Ð=MÑ:Mˆõ �q˜"‘”ð 	#ð 	#ˆAÝ�w ‘| aÑ'¨°DÐ9Ñ9Ô9ð #Ø—’�bœeÑ$Ô$Ð$Ð$Ø˜2‘ Ñ! AÒ%Ð%Ø—’˜a¥"¤)¨G°b©L¸1Ñ,<Ñ"=Ô"=Ñ=Ñ>Ô>Ð>Ð>à—’˜cÑ"Ô"Ð"Ð"à�ŠÝ�VÑÔ˜w qœz˜l¨XÐ6P½¸H¹¼ÈÑ8PÐ6PÔ-QÑQÐ[_ð 	ñ 	
ô 	
ð 	
ð ñ 	Ø�OŠOÝÐ5Ð5¨fÐ5Ñ5Ô5Ñ6Ô6×>Ò>Ñ@Ô@Ø˜"”� '¨!¤* Ñ-°¸¸"¸´Ñ=Øð ñ ô ð ð
 ˜ˆJÝ˜1˜b‘\”\ð +ð +�Ý˜7 b™>¨Q°°R±©ZÑ8¸"ÀdÐKÑKÔKð +Ø×%Ò%¥r¤u fÑ-Ô-Ð-Ð-Ý”V˜G r™N¨a°!°b±&©jÑ9Ñ:Ô:¸QÒ>Ð>Ø×%Ò% a­"¬)°G¸r±NÀaÈ!ÈbÉ&ÁjÑ4QÑ*RÔ*RÑ&RÑSÔSÐSÐSà×%Ò% cÑ*Ô*Ð*Ð*Ø�OŠOÝ˜Ñ$Ô$×,Ò,Ñ.Ô.Ø˜"”� '¨!¤* Ñ-°¸¸"¸´Ñ=Øð ñ ô ð ð 	�‰ŒÔ˜'œ-Ð3¨dÐ3Ð3Ð3Ø�Š�W—_’_Ñ&Ô&¨t¬{ÀDˆÑIÔIÐIÐIÐIr   )Fr	   )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚintÚfloatÚboolÚstrr)   Ú__classcell__)r4   s   @r   r   r      s‹   ø€ € € € € ðð ð Z_ð<Jð <JØ #ð<JØ.3ð<JØ?Cð<JØSVð<Jà	ð<Jð <Jð <Jð <Jð <Jð <Jð <Jð <Jð <Jð <Jr   r   )r8   Úmathr   Únumpyr!   Úqiskit.circuitr   r   Ú(qiskit.circuit.library.generalized_gatesr   r   r   r   r   ú<module>rB      s�   ðð !Ð  à Ð Ð Ð Ð Ð Ø Ð Ð Ð Ø :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ø =Ð =Ð =Ð =Ð =Ð =ðDJð DJð DJð DJð DJ�nñ DJô DJð DJð DJð DJr   