Ë
    täi°]  ã                   ó  — 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%y)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}| j                  «       sd}n%| j                  «       sd}n| j                  «       sd}|�t        ||z   «      ‚y)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      ún/Volumes/fast/ai/experiments/MLX_z-image/.venv/lib/python3.12/site-packages/sympy/polys/numberfields/primes.pyÚ*_check_formal_conditions_for_maximal_orderr      s\   € ð D€FØ€DØ×-Ñ-Ô/Ø8‰Ø×(Ñ(Ô*Ø/‰Ø×(Ñ(Ô*Ø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y)Ú
PrimeIdealz8
    A prime ideal in a ring of algebraic integers.
    Nc                 ó¦   — t        |«       || _        || _        || _        || _        d| _        |�|| _        y| j                  ||z  «      | _        y)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__.   sN   € ô$ 	3°2Ô6ØˆŒØˆŒØˆŒ
ØˆŒØ ˆÔØ�m�ˆ�¨¯©¸¸B¹Ó)?ˆ�r   c                 ó�   — | j                   rd| j                  › d�S d| j                  › d| j                  j                  «       › d�S )NÚ(Ú)ú, )Úis_inertr!   r"   Úas_expr©r'   s    r   Ú__str__zPrimeIdeal.__str__H   sB   € Ø�=Š=Ø�t—v‘v�h˜a�=Ð Ø�4—6‘6�(˜"˜TŸZ™Z×/Ñ/Ó1Ð2°!Ð4Ð4r   c                 óH   — | 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‰v˜Ÿ™Ÿ™Ñ"Ð"r   c                 óŠ  — |xs* | j                   j                  j                  j                  }| j                  | j
                  | j                  | j                  f\  }}}}t        |j                  |¬«      j                  «       «      }|j                  dkD  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Ñ!1×!5Ñ!5ˆ	ØŸ™ §¡¨T¯V©V°T·V±VÐ;‰ˆˆ5�!�QÜ˜Ÿ™¨)˜Ó4×<Ñ<Ó>Ó?ˆ	Ø�;‰;˜Š?Ø˜I˜; b¨¯©¨Ð6ˆIØ�1�#�R˜	�{ !Ð$ˆÙØˆKØ�D�6˜˜Q˜C˜t A 3 bÐ)Ð)r   c                 ó"   — | j                  «       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ƒ   s>   € ðn �F‰F�T—W‘WÑ˜tŸz™z¨D¯G©GÑ3Ñ3ˆà$ˆÔØ#ˆÔØˆr   c                 óp   — t        |t        «      r!| j                  «       |j                  «       k(  S t        S rA   )Ú
isinstancer   rG   ÚNotImplemented©r'   Úothers     r   Ú__eq__zPrimeIdeal.__eq__À   s/   € Ü�eœZÔ(Ø×$Ñ$Ó&¨%×*<Ñ*<Ó*>Ñ>Ð>ÜÐr   c                 ó(   — | j                  «       |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                 ó(   — | j                  «       |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‰wˆr   c                 ó   — | S rA   © r/   s    r   Ú_first_powerzPrimeIdeal._first_poweræ   s   € Øˆr   c                 ó”   — | j                   €1t        | 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é   s;   € ð  ×ÑÐ$Ü 4°T·V±V¸d¿j¹j¸\È4Ï7É7Ó 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                 ó@   — | j                  «       j                  |«      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Ð6r   c                 óŽ   — | j                   j                  j                  |«      }| 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*  s8   € ð2 �g‰g�n‰n×-Ñ-¨aÓ0ˆØ×!Ñ! #Ó&ˆØ�z‰z‹|Ðr   c                 óä   — | j                   j                  j                  |«      }| j                  |«      }|j	                  t        t        |j                  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  sP   € ð2 �g‰g�n‰n×1Ñ1°!Ó4ˆØ×!Ñ! #Ó&ˆØ�‰œt¤H¨S¯Z©Z¯_©_Ó->Ó$?Ó@Ó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   )   sx   „ ñó@ò45ð
 ñ#ó ð#ó)*òVò;òzò
+ð €Hò+ð €Hòòò!ò((ò$7ò6ó:Br   r   c                 óÖ  — t        |«       |j                  «       }|D �cg c]#  }|j                  |«      j                  | ¬«      ‘Œ% }} t	        j
                  d|j                  ft        | «      «      j                  |Ž }|j                  «       ddd…f   j                  «       }|j                  |j                  |j                  t        «      z  |j                  ¬«      }|S c c}w )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.)

    ©Úmodulusr   N©r:   )r   Úendomorphism_ringÚinner_endomorphismÚmatrixr   Úzerosr2   r   ÚvstackÚ	nullspaceÚ	transposer5   Ú
convert_tor   r:   )	r!   r>   r    ÚEÚgÚmatricesÚBr4   Úbetas	            r   rZ   rZ   e  sÄ   € ô< /¨rÔ2Ø
×ÑÓ€AÙCGÓHÁ4¸a�×$Ñ$ QÓ'×.Ñ.°qÐ.Õ9À4€HÐHØ3Œ×Ñ˜A˜rŸt™t˜9¤b¨£eÓ,×3Ñ3°XÐ>€Að 	
�‰‹�aš�dÑ×%Ñ%Ó'€AØ�9‰9�R—Y‘Y §¡¬bÓ!1Ñ1¸¿¹ˆ9ÓB€DØ€Kùò Is    (C&c                 ód  — |j                   |j                  }}|j                  |j                  |j                  }}}|j                  t        «      j                  «       | j                  z  |z  | j                  z  }|j                  t        «      }|j                  «       }||z  dk7  ry|j                  «       }	||z  |j                  «       z  }
|
|z  dk(  }d}	 ||z  }t        |«      D ]Z  }|j                  |dd…|f   |¬«      }||	z  }|j                  |«      j                  «       }t        |«      D ]  }||   |||f<   Œ Œ\ ||dz
  |dz
  f   j                  |z  dk7  r	 |S ||z  }|r	 |j                  t        «      }n|j                  t        «      }|dz  }ŒÆ# t         $ r Y |S w xY w)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   Nr{   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‰C�—‘€r€AØ�d‰d�B—I‘I˜rŸx™xˆ!€q€Aà	�‰”RÓ×ÑÓ §¡Ñ)¨AÑ-°·±Ñ7€Að 	
�‰”RÓ€AØ	�‰‹€AØˆ1�u�‚zØà�=‰=‹?€Dà	ˆQ‰�!—%‘%“'Ñ€AØ˜a™% 1™*ÐØ	€AØ
ð �‰Eˆä�q–ˆAØ—	‘	˜!šA˜q˜D™'¨�	Ó+ˆAØ�‰IˆAà—‘˜Q“×$Ñ$Ó&ˆAÜ˜1–X�Ø˜A™$��!�Q�$’ñ ð ð ˆQ�‰U�A˜‘Eˆ\‰?×"Ñ" QÑ&¨!Ò+Øð €Hð �‰Eˆñ ðØ—L‘L¤Ó$‘ð
 —‘œRÓ ˆAØ	ˆQ‰ˆð7 øô, "ò Øð
 €Hðús   Å1F" Æ"	F/Æ.F/Nc                 ó   ‡— t        |«       |j                  }|j                  }t        ˆfd„| D «       «      r|j	                  «       S |€:|�‰|z  }n2t        |j                  | «      j                  j                  «       «      }|j                  «       }|dd D �cg c]  }‰|z  ‘Œ	 }	}|	| z  }	t        t        |	«      d«      }
|
D ]A  }t        d„ t        ||	«      D «       «      }|j                  |«      |z  }|‰z  dk7  sŒ<|‰z  c S  yc c}w )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   óF   •K  — | ]  }|‰z  j                  d «      –— Œ y­w)r   N)Úequiv)Ú.0r…   r!   s     €r   Ú	<genexpr>z_two_elt_rep.<locals>.<genexpr>  s   øè ø€ Ð
*¡T ˆA�‰E�=‰=˜×¡Tùs   ƒ!Nr   c              3   ó,   K  — | ]  \  }}||z  –— Œ y ­wrA   rW   )rœ   ÚciÚbetais      r   r�   z_two_elt_rep.<locals>.<genexpr>'  s   è ø€ Ð;©l¡  U�B�u•H©lùs   ‚r   )r   r5   r6   ÚallÚzeroÚabsÚsubmodule_from_gensr~   r‹   Úbasis_element_pullbacksr   ÚlenÚsumÚzipÚnorm)r>   r    r!   r#   ÚNpÚpbr6   ÚomegaÚomrˆ   Úsearchr—   r"   r2   s     `           r   Ú_two_elt_repr¯   ì  s  ø€ ôP /¨rÔ2Ø	�‰€BØ
�‰€Aô Ó
*¡TÓ
*Ô*Ø�w‰w‹yÐà	€zØˆ=Ø�A‘‰Bä�R×+Ñ+¨DÓ1×8Ñ8×<Ñ<Ó>Ó?ˆBà×&Ñ&Ó(€EØ   ™9Ó%™9�RˆAˆb‹D˜9€DÐ%ØˆD�L€DÜœ#˜d›) QÓ'€FÛˆÜÑ;¬c°!°T¬lÓ;Ó;ˆð �J‰J�q‹M˜RÑˆØˆq‰5�A‹:à˜1‘9Òñ ùò &s   ÂDc                 óÀ  — |j                   j                  }t        || ¬«      }|j                  «       \  }}t	        |«      dk(  r=|d   d   dk(  r2t        || |j                   j                  «       |j                  d«      gS |D ��cg c]J  \  }}t        || |j                   j                  t        |t        ¬«      «      |j                  «       |«      ‘ŒL c}}S c c}}w )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``.
    ry   r   r   ©Údomain)r5   r6   r   Úfactor_listr¦   r   r¢   r2   Úelement_from_polyr   Údegree)r!   r    r6   ÚT_barÚlcÚflÚtr&   s           r   Ú_prime_decomp_easy_caserº   1  sÉ   € ð 	�	‰	�‰€AÜ�˜AÔ€EØ×ÑÓ �F€BˆÜ
ˆ2ƒw�!‚|˜˜1™˜a™ AšÜ˜2˜q "§)¡)§.¡.Ó"2°B·D±D¸!Ó<Ð=Ð=ñ ôñ ‘��1ô �r˜1Ø—y‘y×2Ñ2´4¸Ä"Ô3EÓFØ—x‘x“z 1õ&ð òð ùó s   ÂACc                 ó,  ‡— | j                   }|j                  \  }}|dk(  r|j                  |t        «      }n,|j	                  |j                  |t        «      dd…df   «      }|j                  d   |k  r6t        |j                  t        ‰«      «      «      j                  t        «      }|j                  |«      }|j                  «        |j                  |«      }t        |ˆfd„«      }|j                  ‰¬«      }	|	j                  «       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   ry   )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‰7�D€A€qð 	ˆA‚vØ�E‰E�!”R‹L‰à�H‰H�Q—U‘U˜1œb“\¢! Q $Ñ'Ó(ˆØ‡w�wˆq�z�A‚~Ü! !§,¡,¬r°!«uÓ"5Ó6×AÑAÄ"ÓEˆà
× Ñ  Ó#€Að
 ×ÑÔØ	×Ñ˜Ó€Aä
˜QÓ 2Ó
3€CØ�
‰
˜1ˆ
Ó€AØ×ÑÔ Ð Ð Øˆaˆ4€Kr   c                 óB  — | j                   j                  \  }}||z
  }|j                   | j                   z  }t        |j                  d   «      D �cg c]&  }|j                  |dd…|f   |j                  ¬«      ‘Œ( }}t        ||||¬«      }	t        |||	|«      S c c}w )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

    r   Nr{   )r#   )r~   r¾   rŒ   r5   r:   r¯   r   )
r^   r!   r    Úmr2   r#   rÆ   r–   r>   r"   s
             r   Ú_prime_decomp_maximal_idealrÌ   y  s“   € ð* �8‰8�>‰>�D€A€qØ	ˆA‰€AØ
�	‰	�A—H‘HÑ€AÜ8=¸a¿g¹gÀa¹jÔ8IÓJÑ8I°1ˆB�I‰I�aš˜1˜‘g R§X¡XˆIÕ.Ð8I€DÐJÜ˜˜r 1¨Ô*€EÜ�b˜!˜U AÓ&Ð&ùò Ks   Á+Bc                 ó  ‡‡— | j                   |k(  r|j                   |u r|j                   |u sJ ‚ |d«      j                  «       }|j                  |u sJ ‚g Št        |t	        |«      ‰¬«      }|j                  «       \  }}|d   d   }	|j                  |	«      }
|	j                  |
«      \  }}}|dk(  sJ ‚t        t        t        ||	z  t        ¬«      j                  j                  «       «      «      Št        ˆˆfd„t        t!        ‰«      «      D «       «      }d|z
  }||g}g }|D ]Ð  }|j                  «       }|j                  |u sJ ‚ | j"                  j%                  t	        |«      «      j&                  |j)                  «       D �cg c]   }||z  j+                  t	        |«      ¬«      ‘Œ" c}Ž }|j-                  «       j%                  t        «      }|j/                  |«      }|j1                  |«       ŒÒ |S c c}w )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   ó4   •K  — | ]  }‰|   ‰|   z  –— Œ y ­wrA   rW   )rœ   r˜   r„   Úalpha_powerss     €€r   r�   z,_prime_decomp_split_ideal.<locals>.<genexpr>°  s   øè ø€ Ð;©]¨ˆq�‰t�L ‘OÕ#©]ùs   ƒ)r5   Ú	to_parentÚmoduler   r   r³   ÚquoÚgcdexrl   rm   r   r   ÚrepÚto_listr§   rŒ   r¦   r~   rƒ   rÀ   Úbasis_elementsÚcolumnÚcolumnspacerÁ   Úappend)r^   r!   rÈ   rÆ   r    r"   rË   r·   r¸   Úm1Úm2ÚUÚVr…   Úeps1Úeps2ÚidempsÚfactorsÚepsr&   r­   r“   r�   ÚHr„   rÐ   s                           @@r   Ú_prime_decomp_split_idealrå   –  sÄ  ù€ ð �8‰8�rŠ>˜aŸh™h¨"™n°·±¸Q±Ð>Ð>ñ
 ˆa‹D�N‰NÓ€EØ�<‰<˜1ÑÐÐà€LÜ�eœR ›U¨<Ô8€Að �]‰]‹_�F€BˆØ	ˆA‰ˆq‰€BØ	
�‰ˆr‹€BØ�h‰h�r‹l�G€A€qˆ!à�Š6€Mˆ6ÜŒX”d˜1˜r™6¬"Ô-×1Ñ1×9Ñ9Ó;Ó<Ó=€AÜÔ;¬U´3°q³6¬]Ó;Ó;€DØˆt‰8€DØ�Dˆ\€FØ€GÛˆØ�M‰M‹OˆØ�x‰x˜2‰~Ðˆ~Ø-ˆA�H‰H×Ñ¤ 1£Ó&×-Ñ-Ø46×4EÑ4EÔ4Gó0
Ù4G¨bˆQ�‰V�O‰O¤2 a£5ˆOÕ)Ð4Gñ0
ð ˆð �M‰M‹O×&Ñ&¤rÓ*ˆØ×$Ñ$ QÓ'ˆØ�‰�qÕð ð €Nùò0
s   Æ%G>
c                 ó,  — |€|€t        d«      ‚|�t        |«       |€|j                  j                  }i }|�|€t	        ||¬«      \  }}|j                  «       }||z  }|| z  dk7  rt        | |«      S |xs |j                  | «      xs t        || «      }|g}g }	|rv|j                  «       }
t        |
| |«      \  }}|j                  dk(  rt        |
| |«      }|	j                  |«       n%t        |
| |||«      \  }}|j                  ||g«       |rŒv|	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.)

    z)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õ   À  s'  € ðn 	€y�R�ZÜÐDÓEÐEØ	€~Ü2°2Ô6Ø€yØ�I‰I�K‰KˆØ€HØ	€z�R�ZÜ˜1 xÔ0‰ˆˆBØ	
�‰Ó	€BØ�b‘€IØ�1�}˜ÒÜ& q¨"Ó-Ð-ØÒC˜Ÿ™ a›ÒCÔ,<¸RÀÓ,C€GØˆI€EØ€FÙ
Ø�I‰I‹KˆÜ+¨A¨q°"Ó5‰ˆˆ1Ø�3‰3�!Š8Ü+¨A¨q°"Ó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Ý .Ý :Ý 1Ý 2Ý ,ß .Ý &ß 6ß :ò,ô0yBÐ!ô yBòx	+ð\ ñUó ðUópBòJò&2òj'ò:'ðT òOó ñOr   