ó
    Š*£h3  ã                   óê   • S r SSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r
  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  S rS rS r\S 5       r\ " S S5      5       r\S 5       rS r\SS j5       rg)z'Utilities for algebraic number theory. é    )Úsympify)Ú	factorint)ÚQQ)ÚZZ)ÚDMRankError)Úminpoly)ÚIntervalPrinter)Úpublic)Úlambdify)Úmpc                 ó–   • [        U [        5      =(       d3    [        R                  " U 5      =(       d    [        R                  " U 5      $ )zÕ
Test whether an argument is of an acceptable type to be used as a rational
number.

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

Returns ``True`` on any argument of type ``int``, :ref:`ZZ`, or :ref:`QQ`.

See Also
========

is_int

)Ú
isinstanceÚintr   Úof_typer   ©Úcs    Ú_/home/mande/repo/quber/.venv/lib/python3.13/site-packages/sympy/polys/numberfields/utilities.pyÚis_ratr      s+   € ô, �aœÓ×?¤§¢¨A£×?´"·*²*¸Q³-Ð?ó    c                 ó\   • [        U [        5      =(       d    [        R                  " U 5      $ )zÂ
Test whether an argument is of an acceptable type to be used as an integer.

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

Returns ``True`` on any argument of type ``int`` or :ref:`ZZ`.

See Also
========

is_rat

)r   r   r   r   r   s    r   Úis_intr   )   s   € ô$ �aœÓ×.¤§¢¨A£Ð.r   c                 óH   • [        U 5      nUR                  UR                  4$ )z�
Given any argument on which :py:func:`~.is_rat` is ``True``, return the
numerator and denominator of this number.

See Also
========

is_rat

)r   Ú	numeratorÚdenominator)r   Úrs     r   Úget_num_denomr   >   s    € ô 	ˆ1‹€AØ�;‰;˜Ÿ™Ð%Ð%r   c                 ó   • U S-  S;  a  [        S5      eU S:X  a  0 SS04$ U S:X  a  0 0 4$ [        U 5      n0 n0 nSnUR                  5        H;  u  pVUS-  S:X  a&  SX%'   US-  S:X  a  US-  nUS:¼  a  US-
  S-  X5'   M2  M4  US-  X5'   M=     SU;   nU(       d	  US-  S:X  a-  US   nUS:”  d   eUS:X  a  US	 OUS-
  US'   U(       a  SOSUS'   X#4$ )a‡  
Extract a fundamental discriminant from an integer *a*.

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

Given any rational integer *a* that is 0 or 1 mod 4, write $a = d f^2$,
where $d$ is either 1 or a fundamental discriminant, and return a pair
of dictionaries ``(D, F)`` giving the prime factorizations of $d$ and $f$
respectively, in the same format returned by :py:func:`~.factorint`.

A fundamental discriminant $d$ is different from unity, and is either
1 mod 4 and squarefree, or is 0 mod 4 and such that $d/4$ is squarefree
and 2 or 3 mod 4. This is the same as being the discriminant of some
quadratic field.

Examples
========

>>> from sympy.polys.numberfields.utilities import extract_fundamental_discriminant
>>> print(extract_fundamental_discriminant(-432))
({3: 1, -1: 1}, {2: 2, 3: 1})

For comparison:

>>> from sympy import factorint
>>> print(factorint(-432))
{2: 4, 3: 3, -1: 1}

Parameters
==========

a: int, must be 0 or 1 mod 4

Returns
=======

Pair ``(D, F)``  of dictionaries.

Raises
======

ValueError
    If *a* is not 0 or 1 mod 4.

References
==========

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

é   )r   é   zATo extract fundamental discriminant, number must be 0 or 1 mod 4.r   r   é   é   )Ú
ValueErrorr   Úitems)	ÚaÚ	a_factorsÚDÚFÚnum_3_mod_4ÚpÚeÚevenÚe2s	            r   Ú extract_fundamental_discriminantr-   M   s  € ðl 	ˆ1�u�FÓÜÐ\Ó]Ð]ØˆAƒvØ�A�q�6ˆzÐØˆAƒvØ�2ˆvˆÜ˜!“€IØ
€AØ
€Að €KØ—‘Ö!‰ˆØˆq‰5�A‹:ØˆA‰DØ�1‰u˜‹zØ˜qÑ �Ø�A‹vØ˜A™ !‘|�“ñ ð ˜‘6ˆA‹Dñ "ð �‰6€DÞˆ{˜Q‰ !Ó#Øˆq‰TˆØ�A‹vˆˆvØ�‹7Ø�!‘à˜‘6ˆAˆa‰DÞ‰q˜aˆˆ!‰Øˆ4€Kr   c                   ó@   • \ rS rSrSrSS jrS rS rS rS r	S	 r
S
rg)ÚAlgIntPowersé¦   a  
Compute the powers of an algebraic integer.

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

Given an algebraic integer $\theta$ by its monic irreducible polynomial
``T`` over :ref:`ZZ`, this class computes representations of arbitrarily
high powers of $\theta$, as :ref:`ZZ`-linear combinations over
$\{1, \theta, \ldots, \theta^{n-1}\}$, where $n = \deg(T)$.

The representations are computed using the linear recurrence relations for
powers of $\theta$, derived from the polynomial ``T``. See [1], Sec. 4.2.2.

Optionally, the representations may be reduced with respect to a modulus.

Examples
========

>>> from sympy import Poly, cyclotomic_poly
>>> from sympy.polys.numberfields.utilities import AlgIntPowers
>>> T = Poly(cyclotomic_poly(5))
>>> zeta_pow = AlgIntPowers(T)
>>> print(zeta_pow[0])
[1, 0, 0, 0]
>>> print(zeta_pow[1])
[0, 1, 0, 0]
>>> print(zeta_pow[4])  # doctest: +SKIP
[-1, -1, -1, -1]
>>> print(zeta_pow[24])  # doctest: +SKIP
[-1, -1, -1, -1]

References
==========

.. [1] Cohen, H. *A Course in Computational Algebraic Number Theory.*

Nc                 óò   • Xl         X l        UR                  5       U l        [	        UR
                  R                  5       5       Vs/ s H  o3* U -  PM
     snSS /U l        U R                  U l        gs  snf )zí
Parameters
==========

T : :py:class:`~.Poly`
    The monic irreducible polynomial over :ref:`ZZ` defining the
    algebraic integer.

modulus : int, None, optional
    If not ``None``, all representations will be reduced w.r.t. this.

Néÿÿÿÿ)	ÚTÚmodulusÚdegreeÚnÚreversedÚrepÚto_listÚpowers_n_and_upÚ
max_so_far)Úselfr3   r4   r   s       r   Ú__init__ÚAlgIntPowers.__init__Ï   sc   € ð ŒØŒØ—‘“ˆŒÜ4<¸Q¿U¹U¿]¹]»_Ô4MÓ NÒ4M¨q  d¤Ñ4MÑ NÈsÐPRÐ SÐTˆÔØŸ&™&ˆ�ùò !Os   ÁA4c                 ó<   • U R                   c  U$ XR                   -  $ ©N)r4   )r<   Úexps     r   ÚredÚAlgIntPowers.redâ   s   € Ø—l‘lÑ*ˆsÐB°·l±lÑ0BÐBr   c                 ó$   • U R                  U5      $ r@   )rB   )r<   Úothers     r   Ú__rmod__ÚAlgIntPowers.__rmod__å   s   € Ø�x‰x˜‹Ðr   c           
      ón  • U R                   nX::  a  g U R                  nU R                  nUS   n[        US-   US-   5       He  nXFS-
  U-
     US-
     nUR	                  US   U-  U -  /[        SU5       Vs/ s H  o„US-
  U-
     US-
     XX   U-  -   U -  PM      sn-   5        Mg     Xl         g s  snf )Nr   r   )r;   r6   r:   ÚrangeÚappend)	r<   r*   Úmr6   r   r   ÚkÚbÚis	            r   Úcompute_up_throughÚAlgIntPowers.compute_up_throughè   sË   € Ø�O‰OˆØ‹6�6Ø�F‰FˆØ× Ñ ˆØˆa‰DˆÜ�q˜‘s˜A˜a™C–ˆAØ�A‘#�a‘%‘˜˜1™‘ˆAØ�H‰HØ�1‘�a‘˜$‘�Ü=BÀ1Àa¼[ó#Ú=H¸�q˜‘s˜1‘u‘X˜a ™c‘] Q¡T¨!¡VÑ+¨tÔ3¹[ñ#ñ öñ !ð �ùò	#s   Á9%B2c                 óÚ   • U R                   nUS:  a  [        S5      eX:  a#  [        U5       Vs/ s H  o3U:X  a  SOSPM     sn$ U R                  U5        U R                  X-
     $ s  snf )Nr   zExponent must be non-negative.r   )r6   r"   rI   rO   r:   )r<   r*   r6   rN   s       r   ÚgetÚAlgIntPowers.get÷   sk   € Ø�F‰FˆØˆq‹5ÜÐ=Ó>Ð>Ø‹UÜ05°a´Ó9²¨1˜a›‘A QÒ&±Ñ9Ð9à×#Ñ# AÔ&Ø×'Ñ'¨©Ñ.Ð.ùò :s   °A(c                 ó$   • U R                  U5      $ r@   )rR   )r<   Úitems     r   Ú__getitem__ÚAlgIntPowers.__getitem__  s   € Ø�x‰x˜‹~Ðr   )r3   r;   r4   r6   r:   r@   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r=   rB   rF   rO   rR   rV   Ú__static_attributes__© r   r   r/   r/   ¦   s'   † ñ%ôN!ò&Còòò/õr   r/   c              #   ó&  #   • UnU/U -  n X:X  d  X;   d  U* U;   a  USS v •  U S-
  nX4   U* :X  a  US-  nX4   U* :X  a  M  X4==   S-  ss'   [        US-   U 5       H  nXU'   M	     [        U 5       H  nX4   S:w  d  M    O   US-  nU/U -  nM…  7f)a÷  
Generate coefficients for searching through polynomials.

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

Lead coeff is always non-negative. Explore all combinations with coeffs
bounded in absolute value before increasing the bound. Skip the all-zero
list, and skip any repeats. See examples.

Examples
========

>>> from sympy.polys.numberfields.utilities import coeff_search
>>> cs = coeff_search(2, 1)
>>> C = [next(cs) for i in range(13)]
>>> print(C)
[[1, 1], [1, 0], [1, -1], [0, 1], [2, 2], [2, 1], [2, 0], [2, -1], [2, -2],
 [1, 2], [1, -2], [0, 2], [3, 3]]

Parameters
==========

m : int
    Length of coeff list.
R : int
    Initial max abs val for coeffs (will increase as search proceeds).

Returns
=======

generator
    Infinite generator of lists of coefficients.

Nr   r   )rI   )rK   ÚRÚR0r   ÚjrN   s         r   Úcoeff_searchrc     sº   é € ðJ 
€BØ	
ˆˆa‰€AØ
Ø‹7�a“f   a£Ø‘A�$ŠJØ�‰EˆØ‰d�q�b‹jØ�‰FˆAð ‰d�q�b�jà	‹�‰	‹Ü�q˜1‘u˜a–ˆAØˆa‹Dñ !ä�q–ˆAØ‰t�q�yÙñ ð �‰FˆAØ��a‘ˆAñ ùs   ‚>BÁ:BÂ Bc                 ó  • U R                   u  pU R                  U R                  XR                  5      5      nUR	                  5       u  pEUSU [        [        U5      5      :w  a  [        S5      eUSS2US24   nUR                  5       nU$ )a¸  
Extend a basis for a subspace to a basis for the whole space.

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

Given an $n \times r$ matrix *M* of rank $r$ (so $r \leq n$), this function
computes an invertible $n \times n$ matrix $B$ such that the first $r$
columns of $B$ equal *M*.

This operation can be interpreted as a way of extending a basis for a
subspace, to give a basis for the whole space.

To be precise, suppose you have an $n$-dimensional vector space $V$, with
basis $\{v_1, v_2, \ldots, v_n\}$, and an $r$-dimensional subspace $W$ of
$V$, spanned by a basis $\{w_1, w_2, \ldots, w_r\}$, where the $w_j$ are
given as linear combinations of the $v_i$. If the columns of *M* represent
the $w_j$ as such linear combinations, then the columns of the matrix $B$
computed by this function give a new basis $\{u_1, u_2, \ldots, u_n\}$ for
$V$, again relative to the $\{v_i\}$ basis, and such that $u_j = w_j$
for $1 \leq j \leq r$.

Examples
========

Note: The function works in terms of columns, so in these examples we
print matrix transposes in order to make the columns easier to inspect.

>>> from sympy.polys.matrices import DM
>>> from sympy import QQ, FF
>>> from sympy.polys.numberfields.utilities import supplement_a_subspace
>>> M = DM([[1, 7, 0], [2, 3, 4]], QQ).transpose()
>>> print(supplement_a_subspace(M).to_Matrix().transpose())
Matrix([[1, 7, 0], [2, 3, 4], [1, 0, 0]])

>>> M2 = M.convert_to(FF(7))
>>> print(M2.to_Matrix().transpose())
Matrix([[1, 0, 0], [2, 3, -3]])
>>> print(supplement_a_subspace(M2).to_Matrix().transpose())
Matrix([[1, 0, 0], [2, 3, -3], [0, 1, 0]])

Parameters
==========

M : :py:class:`~.DomainMatrix`
    The columns give the basis for the subspace.

Returns
=======

:py:class:`~.DomainMatrix`
    This matrix is invertible and its first $r$ columns equal *M*.

Raises
======

DMRankError
    If *M* was not of maximal rank.

References
==========

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

NzM was not of maximal rank)	ÚshapeÚhstackÚeyeÚdomainÚrrefÚtuplerI   r   Úinv)ÚMr6   r   ÚMaugr`   ÚpivotsÚAÚBs           r   Úsupplement_a_subspacerq   =  s   € ðF �7‰7�D€Að �8‰8�A—E‘E˜!ŸX™XÓ&Ó'€DØ—	‘	“�I€AØˆbˆq€z”Uœ5 ›8“_Ó$ÜÐ5Ó6Ð6ð
 	
Š!ˆQ‰Rˆ%‰€AØ	�‰‹€Að
 €Hr   Nc                 ó   • [        U 5      n U R                  (       a  X 4$ U R                  (       d  [        S5      e[	        SU S[        5       S9n[        U SS9nUR                  SS9n[        R                  Spv U(       dY  U" 5       n U H*  u  p‰X€R                  ::  d  M  U R                  U	::  d  M(  Sn  O   [        =R                  S	-  sl	        U(       d  MY  U[        l	        Ub  UR                  WW	XS
9u  p‰WW	4$ ! U[        l	        f = f)aª  
Find a rational isolating interval for a real algebraic number.

Examples
========

>>> from sympy import isolate, sqrt, Rational
>>> print(isolate(sqrt(2)))  # doctest: +SKIP
(1, 2)
>>> print(isolate(sqrt(2), eps=Rational(1, 100)))
(24/17, 17/12)

Parameters
==========

alg : str, int, :py:class:`~.Expr`
    The algebraic number to be isolated. Must be a real number, to use this
    particular function. However, see also :py:meth:`.Poly.intervals`,
    which isolates complex roots when you pass ``all=True``.
eps : positive element of :ref:`QQ`, None, optional (default=None)
    Precision to be passed to :py:meth:`.Poly.refine_root`
fast : boolean, optional (default=False)
    Say whether fast refinement procedure should be used.
    (Will be passed to :py:meth:`.Poly.refine_root`.)

Returns
=======

Pair of rational numbers defining an isolating interval for the given
algebraic number.

See Also
========

.Poly.intervals

z+complex algebraic numbers are not supportedr^   Úmpmath)ÚmodulesÚprinterT)Úpolys)ÚsqfFr    )ÚepsÚfast)r   Úis_RationalÚis_realÚNotImplementedErrorr   r	   r   Ú	intervalsr   Údpsr$   rM   Úrefine_root)
Úalgrx   ry   ÚfuncÚpolyr}   r~   Údoner$   rM   s
             r   Úisolater„   ”  s÷   € ôN �#‹,€Cà
‡‡ØˆzÐØ�[�[Ü!Ø9ó;ð 	;ô �B˜ X´Ó7HÑI€Dä�3˜dÑ#€DØ—‘ 4�Ð(€Iä—‘˜ˆðÞÙ“&ˆCã!‘�ØŸ™•: #§%¡%¨1¥*Ø�DÙñ "ô
 —’˜!‘•÷ �$ð ŒŒà
�Ø×Ñ  1¨#ÐÐ9‰ˆàˆqˆ6€Møð Œ�ús   Á;"D  Â!D  Â3&D  Ä D)NF)r\   Úsympy.core.sympifyr   Úsympy.ntheory.factor_r   Ú!sympy.polys.domains.rationalfieldr   Úsympy.polys.domains.integerringr   Úsympy.polys.matrices.exceptionsr   Ú sympy.polys.numberfields.minpolyr   Úsympy.printing.lambdareprr	   Úsympy.utilities.decoratorr
   Úsympy.utilities.lambdifyr   rs   r   r   r   r   r-   r/   rc   rq   r„   r^   r   r   Ú<module>rŽ      sœ   ðÙ -å &Ý +Ý 0Ý .Ý 7Ý 4Ý 5Ý ,Ý -å ò@ò2/ò*&ð ñUó ðUðp ÷[ð [ó ð[ð| ñ4ó ð4ònTðn óEó ñEr   