+
    i3                         R t ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RI	H
t
 ^ RIHt ^ RIHt ^ RIHt ^ R	IHt ^ R
IHt R tR tR t]R 4       t] ! R R4      4       t]R 4       tR t]RR l4       tR# )z'Utilities for algebraic number theory. )sympify)	factorint)QQ)ZZ)DMRankError)minpoly)IntervalPrinter)public)lambdify)mpc                    \        V \        4      ;'       g5    \        P                  ! V 4      ;'       g    \        P                  ! V 4      # )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   &ڂ/Users/tonyclaw/.openclaw/workspace/skills/math-calculator/venv/lib/python3.14/site-packages/sympy/polys/numberfields/utilities.pyis_ratr      s1    , a??A??"**Q-?    c                ^    \        V \        4      ;'       g    \        P                  ! V 4      # )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    \        V 4      pVP                  VP                  3# )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                   V ^,          R9  d   \        R4      hV ^ 8X  d   / ^ ^/3# V ^8X  d   / / 3# \        V 4      p/ p/ p^ pVP                  4        FV  w  rVV^,          ^8X  d9   ^W%&   V^,          ^8X  d
   V^,          pV^8  d   V^,
          ^,          W5&   KI  KK  V^,          W5&   KX  	  ^V9   pV'       g   V^,          ^8X  d9   V^,          pV^ 8  g   Q hV^8X  d   V^ MV^,
          V^&   V'       d   ^M^V^&   W#3# )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)

zATo extract fundamental discriminant, number must be 0 or 1 mod 4.)       )
ValueErrorr   items)	a	a_factorsDFnum_3_mod_4peevene2s	   &        r    extract_fundamental_discriminantr*   M   s   l 	1uF\]]AvAq6zAv2v!I
A
A K!q5A:AD1uzq AvA!|  6AD " 6D{Q!#qTAvv7!6AaDqa!4Kr   c                   L   a  ] tR t^t o RtR
R ltR tR tR tR t	R t
R	tV tR# )AlgIntPowersa  
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                    Wn         W n        VP                  4       V n        \	        VP
                  P                  4       4       Uu. uF  q3) V ,          NK  	  upRR .V n        V P                  V n        R# u upi )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)selfr/   r0   r   s   &&& r   __init__AlgIntPowers.__init__   se     4<QUU]]_4M N4Mqd4M NsPR ST&& !Os   A8c                F    V P                   f   V# WP                   ,          # N)r0   )r8   exps   &&r   redAlgIntPowers.red   s    ll*sBll0BBr   c                $    V P                  V4      # r<   )r>   )r8   others   &&r   __rmod__AlgIntPowers.__rmod__   s    xxr   c           
        V P                   pW8:  d   R # V P                  pV P                  pV^ ,          p\        V^,           V^,           4       F  pWF^,
          V,
          ,          V^,
          ,          pTP	                  V^ ,          V,          V ,          .\        ^V4       Uu. uFB  qV^,
          V,
          ,          V^,
          ,          WX,          V,          ,           V ,          NKD  	  up,           4       K  	  Wn         R # u upi r<   )r7   r2   r6   rangeappend)	r8   r'   mr2   r   r   kbis	   &&       r   compute_up_throughAlgIntPowers.compute_up_through   s    OO66FF  aDqsAaCAA#a%1AHH1a$=B1a[#=Hqs1uXac]QT!V+t33[#  ! 	#s   'ADc                    V P                   pV^ 8  d   \        R4      hW8  d$   \        V4       Uu. uF  q3V8X  d   ^M^ NK  	  up# V P                  V4       V P                  W,
          ,          # u upi )r   zExponent must be non-negative.)r2   r   rE   rK   r6   )r8   r'   r2   rJ   s   &&  r   getAlgIntPowers.get   sk    FFq5=>>U05a91aAQ&99##A&''.. :s   A2c                $    V P                  V4      # r<   )rN   )r8   items   &&r   __getitem__AlgIntPowers.__getitem__  s    xx~r   )r/   r7   r0   r2   r6   r<   )__name__
__module____qualname____firstlineno____doc__r9   r>   rB   rK   rN   rR   __static_attributes____classdictcell__)__classdict__s   @r   r,   r,      s/     %N!&C/ r   r,   c              #  x  "   TpV.V ,          p W8X  g   W9   g	   V) V9   d   VR,          x  V ^,
          pW4,          V) 8X  d   V^,          pK  W4;;,          ^,          uu&   \        V^,           V 4       F  pWV&   K	  	  \        V 4       F  pW4,          ^ 8w  g   K   K  	  V^,          pV.V ,          pK  5i)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.

NNN)rE   )rG   RR0r   jrJ   s   &&    r   coeff_searchra     s     J 
B	
aA
7afaA$JEdqbjFA		q1uaAaD !qAtqy  FAaAs   BB: B:c                "   V P                   w  rV P                  V P                  WP                  4      4      pVP	                  4       w  rEVRV \        \        V4      4      8w  d   \        R4      hVRVR13,          pVP                  4       pV# )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 rankr]   )	shapehstackeyedomainrreftuplerE   r   inv)Mr2   r   Maugr^   pivotsABs   &       r   supplement_a_subspacero   =  s    F 77DA 88AEE!XX&'D		IAbqzU58_$566
 	
!QR%A	A
 Hr   Nc                B   \        V 4      p V P                  '       d   W 3# V P                  '       g   \        R4      h\	        R	V R\        4       R7      p\        V RR7      pVP                  RR7      p\        P                  Rrv V'       gZ   V! 4       p V F-  w  rWP                  8:  g   K  V P                  V	8:  g   K*  Rp K@  	  \        ;P                  ^,          un	        Ka   V\        n	        Ve   VP                  XX	WR7      w  rXX	3#   T\        n	        i ; i)
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 supportedmpmath)modulesprinterT)polys)sqfF)epsfast )r   is_Rationalis_realNotImplementedErrorr
   r   r   	intervalsr   dpsr!   rI   refine_root)
algrv   rw   funcpolyr|   r}   doner!   rI   s
   &&&       r   isolater     s    N #,C
z[[[!9; 	; BX7HID3d#D4(I&C!:#%%1*D "
 !  
1#9q6M s   D D .D &D D)NF)rX   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
   rq   r   r   r   r   r*   r,   ra   ro   r   rx   r   r   <module>r      s    - & + 0 . 7 4 5 , - @2/*& U Up [ [ [| 4 4nTn E Er   