
    \h                     $    S r SSKJr  SrS rS rg)z-Heuristic polynomial GCD algorithm (HEUGCD).    )HeuristicGCDFailed   c                    U R                   UR                   :X  a%  U R                   R                  R                  (       d   eU R                   nUR                  S   nUR                  nU R	                  U5      u  pPnU R                  5       nUR                  5       nU" S[        Xg5      -  S-   5      n[        [        USUR                  U5      -  5      S[        U[        U R                  5      -  U[        UR                  5      -  5      -  S-   5      n	[        S[        5       GH  n
U R                  X95      nUR                  X95      nU(       Ga[  U(       GaS  UR                  S:X  a  UR                  X5      u  pnO[!        X5      u  pn[#        XU5      nUR%                  5       S   nU R'                  U5      u  nnU(       d3  UR'                  U5      u  nnU(       d  UR)                  U5      nUUU4s  $ [#        XU5      nU R'                  U5      u  nnU(       d2  UR'                  U5      u  nnU(       d  UR)                  U5      nXU4s  $ [#        XU5      nUR'                  U5      u  nnU(       d3  U R'                  U5      u  nnU(       d  UR)                  U5      nUUU4s  $ SU	-  UR                  UR                  U	5      5      -  S-  n	GM     [+        S	5      e)
a  
Heuristic polynomial GCD in ``Z[X]``.

Given univariate polynomials ``f`` and ``g`` in ``Z[X]``, returns
their GCD and cofactors, i.e. polynomials ``h``, ``cff`` and ``cfg``
such that::

      h = gcd(f, g), cff = quo(f, h) and cfg = quo(g, h)

The algorithm is purely heuristic which means it may fail to compute
the GCD. This will be signaled by raising an exception. In this case
you will need to switch to another GCD method.

The algorithm computes the polynomial GCD by evaluating polynomials
``f`` and ``g`` at certain points and computing (fast) integer GCD
of those evaluations. The polynomial GCD is recovered from the integer
image by interpolation. The evaluation process reduces f and g variable
by variable into a large integer. The final step is to verify if the
interpolated polynomial is the correct GCD. This gives cofactors of
the input polynomials as a side effect.

Examples
========

>>> from sympy.polys.heuristicgcd import heugcd
>>> from sympy.polys import ring, ZZ

>>> R, x,y, = ring("x,y", ZZ)

>>> f = x**2 + 2*x*y + y**2
>>> g = x**2 + x*y

>>> h, cff, cfg = heugcd(f, g)
>>> h, cff, cfg
(x + y, x + y, x)

>>> cff*h == f
True
>>> cfg*h == g
True

References
==========

.. [1] [Liao95]_

          c      r   iB  ii  zno luck)ringdomainis_ZZgensextract_groundmax_normminmaxsqrtabsLCrangeHEU_GCD_MAXevaluatengens	cofactorsheugcd_gcd_interpolate	primitivediv
mul_groundr   )fgr   x0r   gcdf_normg_normBxiffgghcffcfgcff_rcfg_s                      P/var/www/auris/envauris/lib/python3.13/site-packages/sympy/polys/heuristicgcd.pyr   r      sn   ` 66QVV 3 33366D	1B[[F  #ICAZZ\FZZ\FqV$$r)*AC2fkk!n$%c&CI%CI%' ')*+	,A 1k"ZZZZ"zzQ$..r6$Rn t,Aa AeeAhGD!%%(aS)AdD=("340C55:DAq%%(aS)A4<'"340C55:DAq%%(aS)AdC<'!Gfkk&++a.11U:Y #\ Y
''    c                    UR                   SpCUR                  S:X  a9  U (       a1  X-  nXQS-  :  a  XQ-  nX-
  U-  n U(       a  XSU4'   US-  nU (       a  M1  OaU (       aZ  U R                  U5      nX-
  R                  U5      n U(       a!  UR	                  5        H  u  pgXsU4U-   '   M     US-  nU (       a  MZ  UR
                  S:  a  U* $ U$ )z-Interpolate polynomial GCD from integer GCD. r   r   r   )zeror   trunc_ground
quo_ground	itertermsr   )r+   r'   r   r    r(   r!   monomcoeffs           r1   r   r   x   s    99aq zzQA6z1611A 1$FA a q!A""1%A $%KKMLE&+qdUlO %2FA a 	ttaxr		r2   N)__doc__
polyerrorsr   r   r   r    r2   r1   <module>r=      s    3 *o(br2   