§
    OŠtj°]  ã                   ó  — d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ dd	lmZ d
dlmZmZ d
dlmZ d
dlmZmZ d
dlmZmZ d„ Z G d„ de¦  «        Zd„ Zed„ ¦   «         Zdd„Z d„ Z!d„ Z"d„ Z#d„ Z$edd„¦   «         Z%dS )zPrime ideals in number fields. é    )ÚPoly)ÚFF)ÚQQ)ÚZZ)ÚDomainMatrix)ÚCoercionFailed)ÚIntegerPowerable)Úpublicé   )Ú	round_twoÚnilradical_mod_p)ÚStructureError)ÚModuleEndomorphismÚfind_min_poly)Úcoeff_searchÚsupplement_a_subspacec                 ó¾   — d}d}|                       ¦   «         sd}n-|                      ¦   «         sd}n|                      ¦   «         sd}|�t          ||z   ¦  «        ‚dS )a  
    Several functions in this module accept an argument which is to be a
    :py:class:`~.Submodule` representing the maximal order in a number field,
    such as returned by the :py:func:`~sympy.polys.numberfields.basis.round_two`
    algorithm.

    We do not attempt to check that the given ``Submodule`` actually represents
    a maximal order, but we do check a basic set of formal conditions that the
    ``Submodule`` must satisfy, at a minimum. The purpose is to catch an
    obviously ill-formed argument.
    z4The submodule representing the maximal order should Nz'be a direct submodule of a power basis.zhave 1 as its first generator.z<have square matrix, of maximal rank, in Hermite Normal Form.)Úis_power_basis_submoduleÚstarts_with_unityÚis_sq_maxrank_HNFr   )Ú	submoduleÚprefixÚconds      ú]/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/sympy/polys/numberfields/primes.pyÚ*_check_formal_conditions_for_maximal_orderr      s�   € ð D€FØ€DØ×-Ò-Ñ/Ô/ð NØ8ˆˆØ×(Ò(Ñ*Ô*ð NØ/ˆˆØ×(Ò(Ñ*Ô*ð NØMˆØÐÝ˜V d™]Ñ+Ô+Ð+ð Ðó    c                   óŽ   — e Zd ZdZdd„Zd„ Zed„ ¦   «         Zdd„Zd„ Z	d	„ Z
d
„ Zd„ ZeZd„ ZeZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ ZdS )Ú
PrimeIdealz8
    A prime ideal in a ring of algebraic integers.
    Nc                 ó¬   — t          |¦  «         || _        || _        || _        || _        d| _        |�|n|                      ||z  ¦  «        | _        dS )aü  
        Parameters
        ==========

        ZK : :py:class:`~.Submodule`
            The maximal order where this ideal lives.
        p : int
            The rational prime this ideal divides.
        alpha : :py:class:`~.PowerBasisElement`
            Such that the ideal is equal to ``p*ZK + alpha*ZK``.
        f : int
            The inertia degree.
        e : int, ``None``, optional
            The ramification index, if already known. If ``None``, we will
            compute it here.

        N)r   ÚZKÚpÚalphaÚfÚ_test_factorÚ	valuationÚe)Úselfr    r!   r"   r#   r&   s         r   Ú__init__zPrimeIdeal.__init__.   sY   € õ$ 	3°2Ñ6Ô6Ð6ØˆŒØˆŒØˆŒ
ØˆŒØ ˆÔØ�m��¨¯ª¸¸B¹Ñ)?Ô)?ˆŒˆˆr   c                 óp   — | j         rd| j        › d�S d| j        › d| j                             ¦   «         › d�S )Nú(ú)ú, )Úis_inertr!   r"   Úas_expr©r'   s    r   Ú__str__zPrimeIdeal.__str__H   sE   € ØŒ=ð 	!Ø �t”v�=�=�=Ð Ø4�4”6Ð4Ð4˜TœZ×/Ò/Ñ1Ô1Ð4Ð4Ð4Ð4r   c                 ó,   — | j         | j        j        k    S )zv
        Say whether the rational prime we divide is inert, i.e. stays prime in
        our ring of integers.
        )r#   r    Únr/   s    r   r-   zPrimeIdeal.is_inertM   s   € ð Œv˜œœÒ"Ð"r   Fc                 ó<  — |p| j         j        j        j        }| j        | j        | j        | j        f\  }}}}t          | 	                    |¬¦  «         
                    ¦   «         ¦  «        }|j        dk    rd|› d|j        › �}d|› d|› d�}|r|S d|› d|› d	|› d
�S )a  
        Print a representation of this prime ideal.

        Examples
        ========

        >>> from sympy import cyclotomic_poly, QQ
        >>> from sympy.abc import x, zeta
        >>> T = cyclotomic_poly(7, x)
        >>> K = QQ.algebraic_field((T, zeta))
        >>> P = K.primes_above(11)
        >>> print(P[0].repr())
        [ (11, x**3 + 5*x**2 + 4*x - 1) e=1, f=3 ]
        >>> print(P[0].repr(field_gen=zeta))
        [ (11, zeta**3 + 5*zeta**2 + 4*zeta - 1) e=1, f=3 ]
        >>> print(P[0].repr(field_gen=zeta, just_gens=True))
        (11, zeta**3 + 5*zeta**2 + 4*zeta - 1)

        Parameters
        ==========

        field_gen : :py:class:`~.Symbol`, ``None``, optional (default=None)
            The symbol to use for the generator of the field. This will appear
            in our representation of ``self.alpha``. If ``None``, we use the
            variable of the defining polynomial of ``self.ZK``.
        just_gens : bool, optional (default=False)
            If ``True``, just print the "(p, alpha)" part, showing "just the
            generators" of the prime ideal. Otherwise, print a string of the
            form "[ (p, alpha) e=..., f=... ]", giving the ramification index
            and inertia degree, along with the generators.

        )Úxr   r*   z)/r,   r+   z[ z e=z, f=z ])r    ÚparentÚTÚgenr!   r"   r&   r#   ÚstrÚ	numeratorr.   Údenom)	r'   Ú	field_genÚ	just_gensr!   r"   r&   r#   Ú	alpha_repÚgenss	            r   ÚreprzPrimeIdeal.reprU   sÆ   € ðB Ð5 ¤¤Ô!1Ô!5ˆ	Øœ ¤¨T¬V°T´VÐ;‰ˆˆ5�!�QÝ˜Ÿš¨)˜Ñ4Ô4×<Ò<Ñ>Ô>Ñ?Ô?ˆ	ØŒ;˜Š?ˆ?Ø6˜IÐ6Ð6¨¬Ð6Ð6ˆIØ$�1Ð$Ð$˜	Ð$Ð$Ð$ˆØð 	ØˆKØ)�DÐ)Ð)˜QÐ)Ð) AÐ)Ð)Ð)Ð)r   c                 ó*   — |                       ¦   «         S ©N)r?   r/   s    r   Ú__repr__zPrimeIdeal.__repr__€   s   € Ø�yŠy‰{Œ{Ðr   c                 ó`   — | j         | j        z  | j        | j        z  z   }d|_        d|_        |S )aï  
        Represent this prime ideal as a :py:class:`~.Submodule`.

        Explanation
        ===========

        The :py:class:`~.PrimeIdeal` class serves to bundle information about
        a prime ideal, such as its inertia degree, ramification index, and
        two-generator representation, as well as to offer helpful methods like
        :py:meth:`~.PrimeIdeal.valuation` and
        :py:meth:`~.PrimeIdeal.test_factor`.

        However, in order to be added and multiplied by other ideals or
        rational numbers, it must first be converted into a
        :py:class:`~.Submodule`, which is a class that supports these
        operations.

        In many cases, the user need not perform this conversion deliberately,
        since it is automatically performed by the arithmetic operator methods
        :py:meth:`~.PrimeIdeal.__add__` and :py:meth:`~.PrimeIdeal.__mul__`.

        Raising a :py:class:`~.PrimeIdeal` to a non-negative integer power is
        also supported.

        Examples
        ========

        >>> from sympy import Poly, cyclotomic_poly, prime_decomp
        >>> T = Poly(cyclotomic_poly(7))
        >>> P0 = prime_decomp(7, T)[0]
        >>> print(P0**6 == 7*P0.ZK)
        True

        Note that, on both sides of the equation above, we had a
        :py:class:`~.Submodule`. In the next equation we recall that adding
        ideals yields their GCD. This time, we need a deliberate conversion
        to :py:class:`~.Submodule` on the right:

        >>> print(P0 + 7*P0.ZK == P0.as_submodule())
        True

        Returns
        =======

        :py:class:`~.Submodule`
            Will be equal to ``self.p * self.ZK + self.alpha * self.ZK``.

        See Also
        ========

        __add__
        __mul__

        FT)r!   r    r"   Ú_starts_with_unityÚ_is_sq_maxrank_HNF)r'   ÚMs     r   Úas_submodulezPrimeIdeal.as_submoduleƒ   s6   € ðn ŒF�T”WÑ˜tœz¨D¬GÑ3Ñ3ˆà$ˆÔØ#ˆÔØˆr   c                 óŽ   — t          |t          ¦  «        r*|                      ¦   «         |                     ¦   «         k    S t          S rA   )Ú
isinstancer   rG   ÚNotImplemented©r'   Úothers     r   Ú__eq__zPrimeIdeal.__eq__À   s=   € Ý�e�ZÑ(Ô(ð 	?Ø×$Ò$Ñ&Ô&¨%×*<Ò*<Ñ*>Ô*>Ò>Ð>ÝÐr   c                 ó0   — |                       ¦   «         |z   S )z¤
        Convert to a :py:class:`~.Submodule` and add to another
        :py:class:`~.Submodule`.

        See Also
        ========

        as_submodule

        ©rG   rK   s     r   Ú__add__zPrimeIdeal.__add__Å   ó   € ð × Ò Ñ"Ô" UÑ*Ð*r   c                 ó0   — |                       ¦   «         |z  S )z¾
        Convert to a :py:class:`~.Submodule` and multiply by another
        :py:class:`~.Submodule` or a rational number.

        See Also
        ========

        as_submodule

        rO   rK   s     r   Ú__mul__zPrimeIdeal.__mul__Ô   rQ   r   c                 ó   — | j         S rA   )r    r/   s    r   Ú_zeroth_powerzPrimeIdeal._zeroth_powerã   s	   € ØŒwˆr   c                 ó   — | S rA   © r/   s    r   Ú_first_powerzPrimeIdeal._first_poweræ   s   € Øˆr   c                 ój   — | j         €&t          | j        | j        g| j        ¦  «        | _         | j         S )aO  
        Compute a test factor for this prime ideal.

        Explanation
        ===========

        Write $\mathfrak{p}$ for this prime ideal, $p$ for the rational prime
        it divides. Then, for computing $\mathfrak{p}$-adic valuations it is
        useful to have a number $\beta \in \mathbb{Z}_K$ such that
        $p/\mathfrak{p} = p \mathbb{Z}_K + \beta \mathbb{Z}_K$.

        Essentially, this is the same as the number $\Psi$ (or the "reagent")
        from Kummer's 1847 paper (*Ueber die Zerlegung...*, Crelle vol. 35) in
        which ideal divisors were invented.
        )r$   Ú_compute_test_factorr!   r"   r    r/   s    r   Útest_factorzPrimeIdeal.test_factoré   s2   € ð  ÔÐ$Ý 4°T´V¸d¼j¸\È4Ì7Ñ SÔ SˆDÔØÔ Ð r   c                 ó"   — t          || ¦  «        S )zõ
        Compute the $\mathfrak{p}$-adic valuation of integral ideal I at this
        prime ideal.

        Parameters
        ==========

        I : :py:class:`~.Submodule`

        See Also
        ========

        prime_valuation

        )Úprime_valuation)r'   ÚIs     r   r%   zPrimeIdeal.valuationý   s   € õ  ˜q $Ñ'Ô'Ð'r   c                 óP   — |                       ¦   «                              |¦  «        S )aÐ  
        Reduce a :py:class:`~.PowerBasisElement` to a "small representative"
        modulo this prime ideal.

        Parameters
        ==========

        elt : :py:class:`~.PowerBasisElement`
            The element to be reduced.

        Returns
        =======

        :py:class:`~.PowerBasisElement`
            The reduced element.

        See Also
        ========

        reduce_ANP
        reduce_alg_num
        .Submodule.reduce_element

        )rG   Úreduce_element)r'   Úelts     r   r`   zPrimeIdeal.reduce_element  s$   € ð2 × Ò Ñ"Ô"×1Ò1°#Ñ6Ô6Ð6r   c                 ó’   — | j         j                             |¦  «        }|                      |¦  «        }|                     ¦   «         S )a«  
        Reduce an :py:class:`~.ANP` to a "small representative" modulo this
        prime ideal.

        Parameters
        ==========

        elt : :py:class:`~.ANP`
            The element to be reduced.

        Returns
        =======

        :py:class:`~.ANP`
            The reduced element.

        See Also
        ========

        reduce_element
        reduce_alg_num
        .Submodule.reduce_element

        )r    r5   Úelement_from_ANPr`   Úto_ANP©r'   Úara   Úreds       r   Ú
reduce_ANPzPrimeIdeal.reduce_ANP*  s<   € ð2 ŒgŒn×-Ò-¨aÑ0Ô0ˆØ×!Ò! #Ñ&Ô&ˆØ�zŠz‰|Œ|Ðr   c                 óö   — | j         j                             |¦  «        }|                      |¦  «        }|                     t          t          |j                             ¦   «         ¦  «        ¦  «        ¦  «        S )aË  
        Reduce an :py:class:`~.AlgebraicNumber` to a "small representative"
        modulo this prime ideal.

        Parameters
        ==========

        elt : :py:class:`~.AlgebraicNumber`
            The element to be reduced.

        Returns
        =======

        :py:class:`~.AlgebraicNumber`
            The reduced element.

        See Also
        ========

        reduce_element
        reduce_ANP
        .Submodule.reduce_element

        )	r    r5   Úelement_from_alg_numr`   Úfield_elementÚlistÚreversedÚQQ_colÚflatre   s       r   Úreduce_alg_numzPrimeIdeal.reduce_alg_numG  s\   € ð2 ŒgŒn×1Ò1°!Ñ4Ô4ˆØ×!Ò! #Ñ&Ô&ˆØ�Š�t¥H¨S¬Z¯_ª_Ñ->Ô->Ñ$?Ô$?Ñ@Ô@ÑAÔAÐAr   rA   )NF)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r(   r0   Úpropertyr-   r?   rB   rG   rM   rP   Ú__radd__rS   Ú__rmul__rU   rX   r[   r%   r`   rh   rp   rW   r   r   r   r   )   s=  € € € € € ðð ð@ð @ð @ð @ð45ð 5ð 5ð
 ð#ð #ñ „Xð#ð)*ð )*ð )*ð )*ðVð ð ð;ð ;ð ;ðzð ð ð
+ð +ð +ð €Hð+ð +ð +ð €Hðð ð ðð ð ð!ð !ð !ð((ð (ð (ð$7ð 7ð 7ð6ð ð ð:Bð Bð Bð Bð Br   r   c                 ó¨  ‡ ‡— t          |¦  «         |                     ¦   «         Šˆˆ fd„|D ¦   «         } t          j        d|j        ft          ‰ ¦  «        ¦  «        j        |Ž }|                     ¦   «         ddd…f                              ¦   «         }| 	                    |j
        |                     t          ¦  «        z  |j        ¬¦  «        }|S )aÝ  
    Compute the test factor for a :py:class:`~.PrimeIdeal` $\mathfrak{p}$.

    Parameters
    ==========

    p : int
        The rational prime $\mathfrak{p}$ divides

    gens : list of :py:class:`PowerBasisElement`
        A complete set of generators for $\mathfrak{p}$ over *ZK*, EXCEPT that
        an element equivalent to rational *p* can and should be omitted (since
        it has no effect except to waste time).

    ZK : :py:class:`~.Submodule`
        The maximal order where the prime ideal $\mathfrak{p}$ lives.

    Returns
    =======

    :py:class:`~.PowerBasisElement`

    References
    ==========

    .. [1] Cohen, H. *A Course in Computational Algebraic Number Theory.*
    (See Proposition 4.8.15.)

    c                 ób   •— g | ]+}‰                      |¦  «                             ‰¬ ¦  «        ‘Œ,S )©Úmodulus)Úinner_endomorphismÚmatrix)Ú.0ÚgÚEr!   s     €€r   ú
<listcomp>z(_compute_test_factor.<locals>.<listcomp>…  s8   ø€ ÐHÐHÐH¸a�×$Ò$ QÑ'Ô'×.Ò.°qÐ.Ñ9Ô9ÐHÐHÐHr   r   N©r:   )r   Úendomorphism_ringr   Úzerosr2   r   ÚvstackÚ	nullspaceÚ	transposer5   r}   Ú
convert_tor   r:   )r!   r>   r    ÚmatricesÚBr4   Úbetar€   s   `      @r   rZ   rZ   e  sÀ   øø€ õ< /¨rÑ2Ô2Ð2Ø
×ÒÑÔ€AØHÐHÐHÐHÐHÀ4ÐHÑHÔH€HØ3�Ô˜A˜rœt˜9¥b¨¡e¤eÑ,Ô,Ô3°XÐ>€Að 	
�Š‰Œ�a˜˜˜�dÔ×%Ò%Ñ'Ô'€AØ�9Š9�R”Y §¢­bÑ!1Ô!1Ñ1¸¼ˆ9ÑBÔB€DØ€Kr   c                 ó–  — |j         |j        }}|j        |j        |j        }}}|                     t          ¦  «                             ¦   «         | j        z  |z  | j        z  }|                     t          ¦  «        }| 	                    ¦   «         }||z  dk    rdS | 
                    ¦   «         }	||z  | 	                    ¦   «         z  }
|
|z  dk    }d}	 ||z  }t          |¦  «        D ]n}|                     |dd…|f         |¬¦  «        }||	z  }|                     |¦  «                             ¦   «         }t          |¦  «        D ]}||         |||f<   ŒŒo||dz
  |dz
  f         j        |z  dk    rnS||z  }|r,	 |                     t          ¦  «        }n*# t           $ r Y n$w xY w|                     t          ¦  «        }|dz  }Œó|S )aú  
    Compute the *P*-adic valuation for an integral ideal *I*.

    Examples
    ========

    >>> from sympy import QQ
    >>> from sympy.polys.numberfields import prime_valuation
    >>> K = QQ.cyclotomic_field(5)
    >>> P = K.primes_above(5)
    >>> ZK = K.maximal_order()
    >>> print(prime_valuation(25*ZK, P[0]))
    8

    Parameters
    ==========

    I : :py:class:`~.Submodule`
        An integral ideal whose valuation is desired.

    P : :py:class:`~.PrimeIdeal`
        The prime at which to compute the valuation.

    Returns
    =======

    int

    See Also
    ========

    .PrimeIdeal.valuation

    References
    ==========

    .. [1] Cohen, H. *A Course in Computational Algebraic Number Theory.*
       (See Algorithm 4.8.17.)

    r   TNr‚   r   )r!   r    r2   r}   r:   rˆ   r   Úinvr   Údetr[   Úranger5   Ú	representro   Úelementr   )r^   ÚPr!   r    r2   ÚWÚdÚAÚDr‹   r#   Úneed_complete_testÚvÚjÚcÚis                   r   r]   r]   “  sí  € ðT ŒC�”€r€AØŒd�B”I˜rœxˆ!€q€Aà	�Š•RÑÔ×ÒÑÔ ¤Ñ)¨AÑ-°´Ñ7€Að 	
�Š•RÑÔ€AØ	�Š‰Œ€AØˆ1�u�‚z€zØˆqà�=Š=‰?Œ?€Dà	ˆQ‰�!—%’%‘'”'Ñ€AØ˜a™% 1š*ÐØ	€Aðð �‰Eˆå�q‘”ð 	ð 	ˆAØ—	’	˜!˜A˜A˜A˜q˜Dœ'¨�	Ñ+Ô+ˆAØ�‰IˆAà—’˜Q‘”×$Ò$Ñ&Ô&ˆAÝ˜1‘X”Xð ð �Ø˜Aœ$��!�Q�$‘�ðàˆQ�‰U�A˜‘Eˆ\Œ?Ô" QÑ&¨!Ò+Ð+ØØ�‰Eˆð ð 		!ðØ—L’L¥Ñ$Ô$��øÝ!ð ð ð Ø�ðøøøð —’�RÑ Ô ˆAØ	ˆQ‰ˆð7ð8 €Hs   Å>F Æ
F&Æ%F&Nc                 óf  ‡— t          |¦  «         |j        }|j        }t          ˆfd„| D ¦   «         ¦  «        r|                     ¦   «         S |€A|�‰|z  }n9t          |                     | ¦  «        j                             ¦   «         ¦  «        }| 	                    ¦   «         }ˆfd„|dd…         D ¦   «         }|| z  }t          t          |¦  «        d¦  «        }	|	D ]Q}
t          d„ t          |
|¦  «        D ¦   «         ¦  «        }|                     |¦  «        |z  }|‰z  dk    r|‰z  c S ŒRdS )a  
    Given a set of *ZK*-generators of a prime ideal, compute a set of just two
    *ZK*-generators for the same ideal, one of which is *p* itself.

    Parameters
    ==========

    gens : list of :py:class:`PowerBasisElement`
        Generators for the prime ideal over *ZK*, the ring of integers of the
        field $K$.

    ZK : :py:class:`~.Submodule`
        The maximal order in $K$.

    p : int
        The rational prime divided by the prime ideal.

    f : int, optional
        The inertia degree of the prime ideal, if known.

    Np : int, optional
        The norm $p^f$ of the prime ideal, if known.
        NOTE: There is no reason to supply both *f* and *Np*. Either one will
        save us from having to compute the norm *Np* ourselves. If both are known,
        *Np* is preferred since it saves one exponentiation.

    Returns
    =======

    :py:class:`~.PowerBasisElement` representing a single algebraic integer
    alpha such that the prime ideal is equal to ``p*ZK + alpha*ZK``.

    References
    ==========

    .. [1] Cohen, H. *A Course in Computational Algebraic Number Theory.*
    (See Algorithm 4.7.10.)

    c              3   óH   •K  — | ]}|‰z                        d ¦  «        V — ŒdS )r   N)Úequiv)r~   r   r!   s     €r   ú	<genexpr>z_two_elt_rep.<locals>.<genexpr>  s3   øè è € Ð
*Ð
* ˆA�‰E�=Š=˜ÑÔÐ
*Ð
*Ð
*Ð
*Ð
*Ð
*r   Nc                 ó   •— g | ]}‰|z  ‘ŒS rW   rW   )r~   Úomr!   s     €r   r�   z _two_elt_rep.<locals>.<listcomp>#  s   ø€ Ð%Ð%Ð%�RˆAˆb‰DÐ%Ð%Ð%r   r   c              3   ó&   K  — | ]\  }}||z  V — Œd S rA   rW   )r~   ÚciÚbetais      r   rŸ   z_two_elt_rep.<locals>.<genexpr>'  s*   è è € Ð;Ð;¡  U�B�u‘HÐ;Ð;Ð;Ð;Ð;Ð;r   r   )r   r5   r6   ÚallÚzeroÚabsÚsubmodule_from_gensr}   rŽ   Úbasis_element_pullbacksr   ÚlenÚsumÚzipÚnorm)r>   r    r!   r#   ÚNpÚpbr6   Úomegar‹   Úsearchrš   r"   r2   s     `          r   Ú_two_elt_repr²   ì  s[  ø€ õP /¨rÑ2Ô2Ð2Ø	Œ€BØ
Œ€Aõ Ð
*Ð
*Ð
*Ð
* TÐ
*Ñ
*Ô
*Ñ*Ô*ð Ø�wŠw‰yŒyÐà	€zØˆ=Ø�A‘ˆBˆBå�R×+Ò+¨DÑ1Ô1Ô8×<Ò<Ñ>Ô>Ñ?Ô?ˆBà×&Ò&Ñ(Ô(€EØ%Ð%Ð%Ð%˜5   œ9Ð%Ñ%Ô%€DØˆD�L€DÝ�#˜d™)œ) QÑ'Ô'€FØð ð ˆÝÐ;Ð;­c°!°T©l¬lÐ;Ñ;Ô;Ñ;Ô;ˆð �JŠJ�q‰MŒM˜RÑˆØˆq‰5�AŠ:ˆ:à˜1‘9ÐÐÐð ðð r   c                 ó6  ‡ ‡— ‰j         j        }t          |‰ ¬¦  «        }|                     ¦   «         \  }}t	          |¦  «        dk    rB|d         d         dk    r0t          ‰‰ ‰j                              ¦   «         ‰j        d¦  «        gS ˆˆ fd„|D ¦   «         S )a?  
    Compute the decomposition of rational prime *p* in the ring of integers
    *ZK* (given as a :py:class:`~.Submodule`), in the "easy case", i.e. the
    case where *p* does not divide the index of $\theta$ in *ZK*, where
    $\theta$ is the generator of the ``PowerBasis`` of which *ZK* is a
    ``Submodule``.
    rz   r   r   c                 ó¸   •— g | ]V\  }}t          ‰‰‰j                             t          |t          ¬ ¦  «        ¦  «        |                     ¦   «         |¦  «        ‘ŒWS ©©Údomain)r   r5   Úelement_from_polyr   r   Údegree)r~   Útr&   r    r!   s      €€r   r�   z+_prime_decomp_easy_case.<locals>.<listcomp>>  sj   ø€ ð ð ð ñ ��1õ �r˜1Ø”y×2Ò2µ4¸Å"Ð3EÑ3EÔ3EÑFÔFØ—x’x‘z”z 1ñ&ô &ð ð ð r   )r5   r6   r   Úfactor_listrª   r   r¦   r2   )r!   r    r6   ÚT_barÚlcÚfls   ``    r   Ú_prime_decomp_easy_caser¿   1  s®   øø€ ð 	Œ	Œ€AÝ�˜AÐÑÔ€EØ×ÒÑ Ô �F€BˆÝ
ˆ2�w„w�!‚|€|˜˜1œ˜aœ Aš˜Ý˜2˜q "¤)§.¢.Ñ"2Ô"2°B´D¸!Ñ<Ô<Ð=Ð=ðð ð ð ð ð ðñ ô ð r   c                 óŒ  ‡— | j         }|j        \  }}|dk    r|                     |t          ¦  «        }n8|                     |                     |t          ¦  «        dd…df         ¦  «        }|j        d         |k     rGt          |                     t          ‰¦  «        ¦  «        ¦  «                             t          ¦  «        }|                     |¦  «        }| 	                    ¦   «          | 
                    |¦  «        }t          |ˆfd„¦  «        }|                     ‰¬¦  «        }	|	                     ¦   «         sJ ‚|	|fS )a+  
    Parameters
    ==========

    I : :py:class:`~.Module`
        An ideal of ``ZK/pZK``.
    p : int
        The rational prime being factored.
    ZK : :py:class:`~.Submodule`
        The maximal order.

    Returns
    =======

    Pair ``(N, G)``, where:

        ``N`` is a :py:class:`~.Module` representing the kernel of the map
        ``a |--> a**p - a`` on ``(O/pO)/I``, guaranteed to be a module with
        unity.

        ``G`` is a :py:class:`~.Module` representing a basis for the separable
        algebra ``A = O/I`` (see Cohen).

    r   Nr   c                 ó   •— | ‰z  | z
  S rA   rW   )r4   r!   s    €r   ú<lambda>z._prime_decomp_compute_kernel.<locals>.<lambda>s  s   ø€ ¨!¨Q©$°©(€ r   rz   )r}   ÚshapeÚeyer   Úhstackr   rˆ   r   Úsubmodule_from_matrixÚcompute_mult_tabÚdiscard_beforer   Úkernelr   )
r^   r!   r    r“   r2   ÚrrŠ   ÚGÚphiÚNs
    `        r   Ú_prime_decomp_compute_kernelrÎ   D  s"  ø€ ð2 	
Œ€AØŒ7�D€A€qð 	ˆA‚v€vØ�EŠE�!•R‰LŒLˆˆà�HŠH�Q—U’U˜1�b‘\”\ ! ! ! Q $Ô'Ñ(Ô(ˆØ„wˆq„z�A‚~€~Ý! !§,¢,­r°!©u¬uÑ"5Ô"5Ñ6Ô6×AÒAÅ"ÑEÔEˆà
× Ò  Ñ#Ô#€Að
 ×ÒÑÔÐØ	×Ò˜ÑÔ€Aå
˜QÐ 2Ð 2Ð 2Ð 2Ñ
3Ô
3€CØ�
Š
˜1ˆ
ÑÔ€AØ×ÒÑ Ô Ð Ð Ð Øˆaˆ4€Kr   c                 óä   ‡‡— | j         j        \  }}||z
  }‰j         | j         z  Šˆˆfd„t          ‰j        d         ¦  «        D ¦   «         }t          |‰||¬¦  «        }t	          ‰|||¦  «        S )aµ  
    We have reached the case where we have a maximal (hence prime) ideal *I*,
    which we know because the quotient ``O/I`` is a field.

    Parameters
    ==========

    I : :py:class:`~.Module`
        An ideal of ``O/pO``.
    p : int
        The rational prime being factored.
    ZK : :py:class:`~.Submodule`
        The maximal order.

    Returns
    =======

    :py:class:`~.PrimeIdeal` instance representing this prime

    c                 ó\   •— g | ](}‰                      ‰d d …|f         ‰j        ¬¦  «        ‘Œ)S )Nr‚   )r5   r:   )r~   r™   rË   r    s     €€r   r�   z/_prime_decomp_maximal_ideal.<locals>.<listcomp>‘  s7   ø€ ÐJÐJÐJ°1ˆB�IŠI�a˜˜˜˜1˜”g R¤XˆIÑ.Ô.ÐJÐJÐJr   r   )r#   )r}   rÃ   r�   r²   r   )	r^   r!   r    Úmr2   r#   r>   r"   rË   s	     `     @r   Ú_prime_decomp_maximal_idealrÒ   y  s~   øø€ ð* Œ8Œ>�D€A€qØ	ˆA‰€AØ
Œ	�A”HÑ€AØJÐJÐJÐJÐJ½¸a¼gÀa¼jÑ8IÔ8IÐJÑJÔJ€DÝ˜˜r 1¨Ð*Ñ*Ô*€EÝ�b˜!˜U AÑ&Ô&Ð&r   c                 ó:  ‡‡‡‡— | j         |k    r|j         |u r	|j         |u sJ ‚ |d¦  «                             ¦   «         }|j        |u sJ ‚g Št          |t	          ‰¦  «        ‰¬¦  «        }|                     ¦   «         \  }}|d         d         }	|                     |	¦  «        }
|	                     |
¦  «        \  }}}|dk    sJ ‚t          t          t          ||	z  t          ¬¦  «        j                             ¦   «         ¦  «        ¦  «        Št          ˆˆfd„t          t!          ‰¦  «        ¦  «        D ¦   «         ¦  «        }d|z
  }||g}g }|D ]Å}|                     ¦   «         Š‰j        |u sJ ‚ | j                             t	          ‰¦  «        ¦  «        j        ˆˆfd„|                     ¦   «         D ¦   «         Ž }|                     ¦   «                              t          ¦  «        }|                     |¦  «        }|                     |¦  «         ŒÆ|S )zñ
    Perform the step in the prime decomposition algorithm where we have determined
    the quotient ``ZK/I`` is _not_ a field, and we want to perform a non-trivial
    factorization of *I* by locating an idempotent element of ``ZK/I``.
    r   )Úpowersr   r¶   c              3   ó:   •K  — | ]}‰|         ‰|         z  V — Œd S rA   rW   )r~   r›   r€   Úalpha_powerss     €€r   rŸ   z,_prime_decomp_split_ideal.<locals>.<genexpr>°  s0   øè è € Ð;Ð;¨ˆq�Œt�L ”OÑ#Ð;Ð;Ð;Ð;Ð;Ð;r   c                 ó\   •— g | ](}‰|z                        t          ‰¦  «        ¬ ¦  «        ‘Œ)S rµ   )Úcolumnr   )r~   r¡   r&   r!   s     €€r   r�   z-_prime_decomp_split_ideal.<locals>.<listcomp>·  s>   ø€ ð 0
ð 0
ð 0
Ø.0ˆQ�‰V�OŠO¥2 a¡5¤5ˆOÑ)Ô)ð0
ð 0
ð 0
r   )r5   Ú	to_parentÚmoduler   r   r»   ÚquoÚgcdexrl   rm   r   r   ÚrepÚto_listr«   r�   rª   r}   rˆ   rÅ   Úbasis_elementsÚcolumnspacerÆ   Úappend)r^   r!   rÍ   rË   r    r"   rÑ   r½   r¾   Úm1Úm2ÚUÚVr   Úeps1Úeps2ÚidempsÚfactorsÚepsr–   r“   ÚHr€   rÖ   r&   s    `                    @@@r   Ú_prime_decomp_split_idealrì   –  s  øøøø€ ð Œ8�rŠ>ˆ>˜aœh¨"˜n˜n°´¸Q°°°Ð>ð
 ˆAˆa‰DŒD�NŠNÑÔ€EØŒ<˜1ÐÐÐÐà€LÝ�e�R ™UœU¨<Ð8Ñ8Ô8€Að �]Š]‰_Œ_�F€BˆØ	ˆAŒˆqŒ€BØ	
�Šˆr‰Œ€BØ�hŠh�r‰lŒl�G€A€qˆ!à�Š6ˆ6ˆ6ˆ6Ý�X•d˜1˜r™6­"Ð-Ñ-Ô-Ô1×9Ò9Ñ;Ô;Ñ<Ô<Ñ=Ô=€AÝÐ;Ð;Ð;Ð;Ð;­Uµ3°q±6´6©]¬]Ð;Ñ;Ô;Ñ;Ô;€DØˆt‰8€DØ�Dˆ\€FØ€GØð ð ˆØ�MŠM‰OŒOˆØŒx˜2ˆ~ˆ~ˆ~ˆ~Ø-ˆAŒH×Ò¥ 1¡¤Ñ&Ô&Ô-ð 0
ð 0
ð 0
ð 0
ð 0
Ø46×4EÒ4EÑ4GÔ4Gð0
ñ 0
ô 0
ð ˆð �MŠM‰OŒO×&Ò&¥rÑ*Ô*ˆØ×$Ò$ QÑ'Ô'ˆØ�Š�qÑÔÐÐØ€Nr   c                 óp  — |€|€t          d¦  «        ‚|�t          |¦  «         |€|j        j        }i }|�|€t	          ||¬¦  «        \  }}|                     ¦   «         }||z  }|| z  dk    rt          | |¦  «        S |p$|                     | ¦  «        pt          || ¦  «        }|g}g }	|r‰| 	                    ¦   «         }
t          |
| |¦  «        \  }}|j        dk    r't          |
| |¦  «        }|	                     |¦  «         n-t          |
| |||¦  «        \  }}|                     ||g¦  «         |°‰|	S )a¬  
    Compute the decomposition of rational prime *p* in a number field.

    Explanation
    ===========

    Ordinarily this should be accessed through the
    :py:meth:`~.AlgebraicField.primes_above` method of an
    :py:class:`~.AlgebraicField`.

    Examples
    ========

    >>> from sympy import Poly, QQ
    >>> from sympy.abc import x, theta
    >>> T = Poly(x ** 3 + x ** 2 - 2 * x + 8)
    >>> K = QQ.algebraic_field((T, theta))
    >>> print(K.primes_above(2))
    [[ (2, x**2 + 1) e=1, f=1 ], [ (2, (x**2 + 3*x + 2)/2) e=1, f=1 ],
     [ (2, (3*x**2 + 3*x)/2) e=1, f=1 ]]

    Parameters
    ==========

    p : int
        The rational prime whose decomposition is desired.

    T : :py:class:`~.Poly`, optional
        Monic irreducible polynomial defining the number field $K$ in which to
        factor. NOTE: at least one of *T* or *ZK* must be provided.

    ZK : :py:class:`~.Submodule`, optional
        The maximal order for $K$, if already known.
        NOTE: at least one of *T* or *ZK* must be provided.

    dK : int, optional
        The discriminant of the field $K$, if already known.

    radical : :py:class:`~.Submodule`, optional
        The nilradical mod *p* in the integers of $K$, if already known.

    Returns
    =======

    List of :py:class:`~.PrimeIdeal` instances.

    References
    ==========

    .. [1] Cohen, H. *A Course in Computational Algebraic Number Theory.*
       (See Algorithm 6.2.9.)

    Nz)At least one of T or ZK must be provided.)Úradicalsr   r   )Ú
ValueErrorr   r5   r6   r   Údiscriminantr¿   Úgetr   ÚpoprÎ   r2   rÒ   rá   rì   Úextend)r!   r6   r    ÚdKÚradicalrî   ÚdTÚ	f_squaredÚstackÚprimesr^   rÍ   rË   r’   ÚI1ÚI2s                   r   Úprime_decomprü   À  sd  € ðn 	€y�R�ZÝÐDÑEÔEÐEØ	€~Ý2°2Ñ6Ô6Ð6Ø€yØŒIŒKˆØ€HØ	€z�R�ZÝ˜1 xÐ0Ñ0Ô0‰ˆˆBØ	
�ŠÑ	Ô	€BØ�b‘€IØ�1�}˜ÒÐÝ& q¨"Ñ-Ô-Ð-ØÐC˜Ÿš a™œÐCÕ,<¸RÀÑ,CÔ,C€GØˆI€EØ€FØ
ð #Ø�IŠI‰KŒKˆÝ+¨A¨q°"Ñ5Ô5‰ˆˆ1ØŒ3�!Š8ˆ8Ý+¨A¨q°"Ñ5Ô5ˆAØ�MŠM˜!ÑÔÐÐå.¨q°!°Q¸¸2Ñ>Ô>‰FˆB�Ø�LŠL˜"˜b˜Ñ"Ô"Ð"ð ð #ð €Mr   )NN)NNNN)&rt   Úsympy.polys.polytoolsr   Úsympy.polys.domains.finitefieldr   Ú!sympy.polys.domains.rationalfieldr   Úsympy.polys.domains.integerringr   Ú!sympy.polys.matrices.domainmatrixr   Úsympy.polys.polyerrorsr   Úsympy.polys.polyutilsr	   Úsympy.utilities.decoratorr
   Úbasisr   r   Ú
exceptionsr   Úmodulesr   r   Ú	utilitiesr   r   r   r   rZ   r]   r²   r¿   rÎ   rÒ   rì   rü   rW   r   r   ú<module>r	     sö  ðØ %Ð %à &Ð &Ð &Ð &Ð &Ð &Ø .Ð .Ð .Ð .Ð .Ð .Ø 0Ð 0Ð 0Ð 0Ð 0Ð 0Ø .Ð .Ð .Ð .Ð .Ð .Ø :Ð :Ð :Ð :Ð :Ð :Ø 1Ð 1Ð 1Ð 1Ð 1Ð 1Ø 2Ð 2Ð 2Ð 2Ð 2Ð 2Ø ,Ð ,Ð ,Ð ,Ð ,Ð ,Ø .Ð .Ð .Ð .Ð .Ð .Ð .Ð .Ø &Ð &Ð &Ð &Ð &Ð &Ø 6Ð 6Ð 6Ð 6Ð 6Ð 6Ð 6Ð 6Ø :Ð :Ð :Ð :Ð :Ð :Ð :Ð :ð,ð ,ð ,ð0yBð yBð yBð yBð yBÐ!ñ yBô yBð yBðx	+ð +ð +ð\ ðUð Uñ „ðUðpBð Bð Bð BðJð ð ð&2ð 2ð 2ðj'ð 'ð 'ð:'ð 'ð 'ðT ðOð Oð Oñ „ðOð Oð Or   