+
    iP                     P   R t ^ RIHt ^ RIt^ RIHt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Ht ^ R
IHtHtHtHt ^ RIHt ^ RIHtHtHtHt ^ RI H!t! ^ RI"H#t#  ! R R]4      t$RR lt%R t&RR lt'RR lt(RR lt)RR lt*RR lt+RR lt,]#RRR^RR/R l4       t-R# ) z
Compute Galois groups of polynomials.

We use algorithms from [1], with some modifications to use lookup tables for
resolvents.

References
==========

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

)defaultdictN)Dummysymbols)	is_square)ZZ)
dup_random)dup_eval)dup_discriminant)dup_factor_listdup_irreducible_p)GaloisGroupExceptionget_resolvent_by_lookupdefine_resolvents	Resolvent)coeff_search)Polypoly_from_exprPolificationFailedComputationFailed)	dup_sqf_p)publicc                       ] tR t^#tRtR# )MaxTriesException N)__name__
__module____qualname____firstlineno____static_attributes__r       څ/Users/tonyclaw/.openclaw/workspace/skills/math-calculator/venv/lib/python3.14/site-packages/sympy/polys/numberfields/galoisgroups.pyr   r   #   s    r   r   c                  a \        R4      pV P                  4       pVf   \        4       pVP                  V P                  4       V'       d   / o^p^pV3R lp	\        V4       EFk  p
V'       d   V	! X4      p\        V4      p\        R V 4       4      pW,           X8  d7   V^8X  d   V^,          pV^,
          pM	V^,          pV	! V4      p\        V4      p\        ^4      .V Uu. uF  p\        V4      NK  	  up,           pMK\        V
^,          ^,           V4      p\        P                  ! ^V^,
          4      p\        VV) V\        4      p\        WP                  4      p\        V P                  VV,
          4      V4      pVP                  V9  g   EK7  \!        VP                  P#                  4       \        4      '       g   EKh  VV3u # 	  \$        hu upi )a  
Given a univariate, monic, irreducible polynomial over the integers, find
another such polynomial defining the same number field.

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

See Alg 6.3.4 of [1].

Parameters
==========

T : Poly
    The given polynomial
max_coeff : int
    When choosing a transformation as part of the process,
    keep the coeffs between plus and minus this.
max_tries : int
    Consider at most this many transformations.
history : set, None, optional (default=None)
    Pass a set of ``Poly.rep``'s in order to prevent any of these
    polynomials from being returned as the polynomial ``U`` i.e. the
    transformation of the given polynomial *T*. The given poly *T* will
    automatically be added to this set, before we try to find a new one.
fixed_order : bool, default True
    If ``True``, work through candidate transformations A(x) in a fixed
    order, from small coeffs to large, resulting in deterministic behavior.
    If ``False``, the A(x) are chosen randomly, while still working our way
    up from small coefficients to larger ones.

Returns
=======

Pair ``(A, U)``

    ``A`` and ``U`` are ``Poly``, ``A`` is the
    transformation, and ``U`` is the transformed polynomial that defines
    the same number field as *T*. The polynomial ``A`` maps the roots of
    *T* to the roots of ``U``.

Raises
======

MaxTriesException
    if could not find a polynomial before exceeding *max_tries*.

Xc                 J   < SP                  V \        V ^4      4      pVSV &   V# )   )getr   )degreegencoeff_generatorss   & r    get_coeff_generator9tschirnhausen_transformation.<locals>.get_coeff_generatorc   s,    ""6<+BC#& 
r   c              3   8   "   T F  p\        V4      x  K  	  R # 5i)N)abs).0cs   & r    	<genexpr>/tschirnhausen_transformation.<locals>.<genexpr>x   s     +FqCFFFs   )r   r&   setaddreprangenextmaxr   minrandomrandintr   r   r'   	resultantr   to_listr   )T	max_coeff	max_trieshistoryfixed_orderr"   ndeg_coeff_sumcurrent_degreer)   ir'   coeffsmr.   aCdAUr(   s   &&&&&               @r    tschirnhausen_transformationrL   '   s   b 	c
A	
A%KK
 9  &n5C#YF+F++A!M1!Q&!Q&M%2Q%6N"a'N).9cA&1&Q2a5&11A AqD1Hi(Aq!a%(A1qb!R(AEENQU#Q'55Iaeemmor$B$Ba4KM N  2s   (Gc                    \        V \        4      '       d   V P                  4       M\        V \        4      p\        V4      # )z?Convenience to check if a Poly or dup has square discriminant. )
isinstancer   discriminantr	   r   r   )r<   rI   s   & r    has_square_discrP      s.    &q$//5Ea5LAQ<r   Fc                h    ^ RI Hp \        V 4      '       d   VP                  R3# VP                  R3# )zj
Compute the Galois group of a polynomial of degree 3.

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

Uses Prop 6.3.5 of [1].

)S3TransitiveSubgroupsTF)sympy.combinatorics.galoisrR   rP   A3S3)r<   r>   	randomizerR   s   &&& r    _galois_group_degree_3rW      s9     A0?0B0B"%%t, 4'**E24r   c           	         ^ RI Hp ^ RIHp \	        R4      pV^ ,          V^,          ,          V^,          V^,          ,          ,           pV! ^4      V! ^4      ! ^ ^4      V! ^4      ! ^ ^4      .p\        WeV4      pV^ ,          V^,          ^,          ,          V^,          V^,          ^,          ,          ,           V^,          V^,          ^,          ,          ,           V^,          V^ ,          ^,          ,          ,           p	V! ^4      V! ^4      ! ^ ^4      .p
\        4       p\        V4       EFQ  pV^ 8  d   \        WVV'       * R7      w  rVP                  V RR7      w  rp\        V\        4      '       g   KN  \        V 4      pVf)   V'       d   VP                  R3u # VP                  R3u # V'       d   VP                  R3u # W,          pV	P!                  \#        VV! V4      4      RR7      pV
 Uu. uF  pVV,          V,          NK  	  pp\        VVV4      pVP                  V 4      w  p p\%        V\        4      pV^ 8X  d   EK#  \'        V4      '       d   VP(                  R3u # VP*                  R3u # 	  \,        hu upi )	z
Compute the Galois group of a polynomial of degree 4.

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

Follows Alg 6.3.7 of [1], using a pure root approximation approach.

PermutationS4TransitiveSubgroupszX0 X1 X2 X3r>   r?   r@   T)find_integer_rootFsimultaneous) sympy.combinatorics.permutationsrZ   rS   r\   r   r   r1   r4   rL   eval_for_polyr   r   rP   A4S4Vsubszipr	   r   C4D4r   )r<   r>   rV   rZ   r\   r"   F1s1R1F2_pres2_prer?   rD   _R_dupi0sq_discsigmaF2taus2R2rI   s   &&&                    r    "_galois_group_degree_4_root_approxrx      sP    =@A
 
1adQqT!A$Y	BAAq!Aq!
B
 
2"	B
 qT!A$'\AaD1qL(1Q4!a<7!A$qtQw,FFAAq!F
 eG9q5/8?@IMKDA ''T'B"## "!$: 9@*--t4 </22E:< )++T22  [[Qa)[=)/0#eCioo0r1b!&&q)q!UB'6Q<<),,e44),,e44] `  1s   ;Jc                x   ^ RI Hp \        4       p\        V4       F<  p\	        V ^ 4      p\        V\        4      '       d    M\        WVV'       * R7      w  rpK>  	  \        h\        V\        4      p\        \        V^,           U	U
u. uF  w  r\        V	4      ^,
          .V
,          NK!  	  up
p	. 4      4      pV^.8X  d.   \        V 4      '       d   VP                  R3# VP                  R3# V. RO8X  d   VP                   R3# V. RO8X  d   VP"                  R3# V^^.8X  g   Q hVP$                  R3# u up
p	i )z
Compute the Galois group of a polynomial of degree 4.

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

Based on Alg 6.3.6 of [1], but uses resolvent coeff lookup.

r[   r]   TFr$   r$      )   r|   r|   )rS   r\   r1   r4   r   r   r   rL   r   r
   sortedsumlenrP   rc   rd   rh   re   ri   )r<   r>   rV   r\   r?   rD   rp   ro   flreLs   &&&         r    _galois_group_degree_4_lookupr      s@    AeG9'1-UB+A4;<EG1	    
	#Bs%'U%*TQQ!qU	 	A 	QCx4CA4F4F&))40 	4'**E2	4 	I~%((%00I~%''..A;;!$$e,,s   %D6c           	        ^ RI Hp ^ RIHp \	        R4      p\        4       pVR,          w  rxp	VP                  ! V!  p\        WuV	4      p
\        4       pRp\        V4       EFt  pV^ 8  d   \        WVV'       * R7      w  r\        V ^4      p\        V\        4      '       g   KD  V'       gb   \        V 4      p\        V\        4      '       d)   V'       d   VP                   R3u # VP"                  R3u # V'       g   VP$                  R3u # RpV
P'                  V 4      pVP)                  4        F  w  pp\+        VV\        4      '       d   K   M	  TpV^ ,          V^,          ^,          ,          V^,          V^,          ^,          ,          ,           V^,          V^,          ^,          ,          ,           V^,          V^,          ^,          ,          ,           V^,          V^ ,          ^,          ,          ,           pV! ^4      V! ^4      ! ^ ^4      ! ^^4      .pXpV	V,          pVP-                  \/        VV! V4      4      RR7      pV Uu. uF  pVV,          V,          NK  	  pp\        VVV4      pVP1                  V 4      w  p p\3        V\        4      pV^ 8X  d   EKF  \5        V4      '       d   VP6                  R3u # VP8                  R3u # 	  \:        hu upi )	z
Compute the Galois group of a polynomial of degree 5.

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

Based on Alg 6.3.9 of [1], but uses a hybrid approach, combining resolvent
coeff lookup, with root approximation.

S5TransitiveSubgroupsrY   zX0,X1,X2,X3,X4Fr]   Tr_   )   r$   )rS   r   ra   rZ   r   r   as_exprr   r1   r4   rL   r   r   r   rP   r   A5S5M20 round_roots_to_integers_for_polyitemsr   rf   rg   rb   r	   r   C5D5r   )r<   r>   rV   r   rZ   X5resF51ro   s51R51r?   reached_second_stagerD   R51_duprr   rounded_rootspermutation_indexcandidate_rootr"   rm   rn   rq   rs   rt   ru   rv   rw   rp   rI   s   &&&                           r    _galois_group_degree_5_hybridr   )  s    A<	!	"B

Cf+KCC
++r
C
CS
!CeG 9q5/8?@IMKDA *!Q/"%%
 $%a(G "--<C.1148 @366>@ -11599  $ <<Q? 2?1D1D1F-~G^R88 2G 1adAg!QqT1W,qtAaD!G|;ad1Q47lJQqTRSTURVXYRY\YNN1a A&

 B[[Qa)[=)/0#eCioo0r1b!&&q)q!UB'6Q<<),,d33),,d33m p  1s   K c                B   ^ RI Hp T p\        4       p\        V4       F<  p\	        V ^4      p\        V\        4      '       d    M\        WVV'       * R7      w  rK>  	  \        h\        V 4      p	\        V\        4      '       d%   V	'       d   VP                  R3# VP                  R3# V	'       g   VP                  R3# \        V\        P                  ! V4      R7      P!                  4       ^,          p
\#        V
4      ^8X  d   VP$                  R3# VP&                  R3# )z
Compute the Galois group of a polynomial of degree 5.

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

Based on Alg 6.3.9 of [1], but uses resolvent coeff lookup, plus
factorization over an algebraic extension.

r   r]   TF)domain)rS   r   r1   r4   r   r   r   rL   r   rP   r   r   r   r   r   alg_field_from_polyfactor_listr   r   r   )r<   r>   rV   r   _Tr?   rD   rp   ro   rr   r   s   &&&        r    (_galois_group_degree_5_lookup_ext_factorr   z  s
    A	
BeG9'1-UB+A4;<EG1	   a G##4;&))40 	8+..6	8 %))511
 
b//3	4	@	@	B1	EB
2w!|%(($//%(($//r   c                   ^ RI Hp \        4       p\        V4       F<  p\	        V ^4      p\        V\        4      '       d    M\        WVV'       * R7      w  rpK>  	  \        h\        V\        4      p\        \        4      p	V^,           F-  w  rV	\        V
4      ^,
          ,          P                  V
4       K/  	  \        \        V	P!                  4        UUu. uF  w  rV.\        V4      ,          NK  	  upp. 4      4      p\#        V 4      pV. RO8X  d>   V	^,          ^ ,          p\#        V4      '       d   VP$                  R3# VP&                  R3# V^^.8X  dO   V	^,          w  pp\#        V4      ;'       g    \#        V4      pV'       d   VP(                  R3# VP*                  R3# V^^.8X  dT   V'       d   VP,                  R3# V	^,          ^ ,          p\#        V4      '       d   VP.                  R3# VP0                  R3# V. RO8X  d%   V'       d   VP2                  R3# VP4                  R3# V^^.8X  d%   V'       d   VP6                  R3# VP8                  R3# V. RO8X  d   VP:                  R3# V^.8X  g   Q h\        4       p\        V4       F<  p\	        V ^4      p\        V\        4      '       d    M\        WVV'       * R7      w  rpK>  	  \        h\#        V 4      p\=        V\        4      '       d%   V'       d   VP>                  R3# VP@                  R3# V'       d   VPB                  R3# VPD                  R3# u uppi )z
Compute the Galois group of a polynomial of degree 6.

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

Based on Alg 6.3.10 of [1], but uses resolvent coeff lookup.

)S6TransitiveSubgroupsr]   FT)r$   r|      rz   )r$   r$   r$   r   )#rS   r   r1   r4   r   r   r   rL   r   r
   r   listr   appendr}   r~   r   rP   C6D6G18G36mS4pA4xC2S4xC2rc   S4mPSL2F5PGL2F5rU   r   A6S6G36pG72)r<   r>   rV   r   r?   rD   rp   ro   r   factors_by_degr   rI   ffr   T_has_sq_discf1f2
any_squares   &&&               r    _galois_group_degree_6_lookupr     sM    A eG9'1-UB+A4;<EG1	   		#B !&N1s1vz"))!,  	s#1#7#7#9#9%!c"g#9	 	A $A&MI~Aq!5DR5H5H&))51 	8+..6	8 
q!f"B$R(??OB,?
6@&**E2 	:+00%8	: 
q!f)--t44"1%B<KB<O<O*00%8 ?/55u=? 
i4A&))40 	9+//7	9 
q!f8E&--t4 	<+22E:	< 
l	%((%008O8 eG9'1-UB+A4;<EG1	   #A&M##4A&))40 	8+..6	8 7D&++T2 	9+//7	9ss   Mby_namer>   rV   c                   T;'       g    . pT;'       g    / p \        V .VO5/ VB w  rgTP                  YTR7      #   \         d   p\        R^T4      hRp?ii ; i)al
  
Compute the Galois group for polynomials *f* up to degree 6.

Examples
========

>>> from sympy import galois_group
>>> from sympy.abc import x
>>> f = x**4 + 1
>>> G, alt = galois_group(f)
>>> print(G)
PermutationGroup([
(0 1)(2 3),
(0 2)(1 3)])

The group is returned along with a boolean, indicating whether it is
contained in the alternating group $A_n$, where $n$ is the degree of *T*.
Along with other group properties, this can help determine which group it
is:

>>> alt
True
>>> G.order()
4

Alternatively, the group can be returned by name:

>>> G_name, _ = galois_group(f, by_name=True)
>>> print(G_name)
S4TransitiveSubgroups.V

The group itself can then be obtained by calling the name's
``get_perm_group()`` method:

>>> G_name.get_perm_group()
PermutationGroup([
(0 1)(2 3),
(0 2)(1 3)])

Group names are values of the enum classes
:py:class:`sympy.combinatorics.galois.S1TransitiveSubgroups`,
:py:class:`sympy.combinatorics.galois.S2TransitiveSubgroups`,
etc.

Parameters
==========

f : Expr
    Irreducible polynomial over :ref:`ZZ` or :ref:`QQ`, whose Galois group
    is to be determined.
gens : optional list of symbols
    For converting *f* to Poly, and will be passed on to the
    :py:func:`~.poly_from_expr` function.
by_name : bool, default False
    If ``True``, the Galois group will be returned by name.
    Otherwise it will be returned as a :py:class:`~.PermutationGroup`.
max_tries : int, default 30
    Make at most this many attempts in those steps that involve
    generating Tschirnhausen transformations.
randomize : bool, default False
    If ``True``, then use random coefficients when generating Tschirnhausen
    transformations. Otherwise try transformations in a fixed order. Both
    approaches start with small coefficients and degrees and work upward.
args : optional
    For converting *f* to Poly, and will be passed on to the
    :py:func:`~.poly_from_expr` function.

Returns
=======

Pair ``(G, alt)``
    The first element ``G`` indicates the Galois group. It is an instance
    of one of the :py:class:`sympy.combinatorics.galois.S1TransitiveSubgroups`
    :py:class:`sympy.combinatorics.galois.S2TransitiveSubgroups`, etc. enum
    classes if *by_name* was ``True``, and a :py:class:`~.PermutationGroup`
    if ``False``.

    The second element is a boolean, saying whether the group is contained
    in the alternating group $A_n$ ($n$ the degree of *T*).

Raises
======

ValueError
    if *f* is of an unsupported degree.

MaxTriesException
    if could not complete before exceeding *max_tries* in those steps
    that involve generating Tschirnhausen transformations.

See Also
========

.Poly.galois_group

galois_groupN)r   r>   rV   )r   r   r   r   )	fr   r>   rV   gensargsFoptexcs	   &$$$*,   r    r   r     st    D ::2D::2D81D1D1 >>'$-  / /  83778s   > A	AA)
      NT)r   F).__doc__collectionsr   r8   sympy.core.symbolr   r   sympy.ntheory.primetestr   sympy.polys.domainsr   sympy.polys.densebasicr   sympy.polys.densetoolsr   sympy.polys.euclidtoolsr	   sympy.polys.factortoolsr
   r   *sympy.polys.numberfields.galois_resolventsr   r   r   r   "sympy.polys.numberfields.utilitiesr   sympy.polys.polytoolsr   r   r   r   sympy.polys.sqfreetoolsr   sympy.utilitiesr   r   rL   rP   rW   rx   r   r   r   r   r   r   r   r    <module>r      s    $  , - " - + 4 F  <J J - ", hV4Tn(-VNb*0ZZ9z j/5 j/B j/% j/ j/r   