+
    ‹°³j!  ã                   ó€   € ^ RI Ht ^ RIHtHt ^ RIHt ^ RIHt ^ RI	H
t
HtHt ^ RIHt R tRR ltR	 tRR
 ltR tR# )é    )Úprod©ÚgcdÚgcdext©Úisprime)ÚZZ)Úgf_crtÚgf_crt1Úgf_crt2)Úas_intc                ó0   € W^,          8:  d   V # W,
          # )z¼Return the residual mod m such that it is within half of the modulus.

>>> from sympy.ntheory.modular import symmetric_residue
>>> symmetric_residue(1, 6)
1
>>> symmetric_residue(4, 6)
-2
© )ÚaÚms   &&ÚV/home/luca/screen-checking/.venv/lib/python3.14/site-packages/sympy/ntheory/modular.pyÚsymmetric_residuer   
   s   € ð 	��F„{ØˆØ�5€Ló    c                ó2  a€ V'       d3   \        \        \        V 4      4      p \        \        \        V4      4      p\        W\        4      o\        V 4      pV'       d}   \        ;QJ d(    V3R l\        W4       4       F  '       d   K   RM	  RM! V3R l\        W4       4       4      '       g+   \        \        \        W4      4      RRRV/ oSf   S# Sw  opV'       d!   \        \        SV4      4      \        V4      3# \        S4      \        V4      3# )aÇ  Chinese Remainder Theorem.

The moduli in m are assumed to be pairwise coprime.  The output
is then an integer f, such that f = v_i mod m_i for each pair out
of v and m. If ``symmetric`` is False a positive integer will be
returned, else \|f\| will be less than or equal to the LCM of the
moduli, and thus f may be negative.

If the moduli are not co-prime the correct result will be returned
if/when the test of the result is found to be incorrect. This result
will be None if there is no solution.

The keyword ``check`` can be set to False if it is known that the moduli
are coprime.

Examples
========

As an example consider a set of residues ``U = [49, 76, 65]``
and a set of moduli ``M = [99, 97, 95]``. Then we have::

   >>> from sympy.ntheory.modular import crt

   >>> crt([99, 97, 95], [49, 76, 65])
   (639985, 912285)

This is the correct result because::

   >>> [639985 % m for m in [99, 97, 95]]
   [49, 76, 65]

If the moduli are not co-prime, you may receive an incorrect result
if you use ``check=False``:

   >>> crt([12, 6, 17], [3, 4, 2], check=False)
   (954, 1224)
   >>> [954 % m for m in [12, 6, 17]]
   [6, 0, 2]
   >>> crt([12, 6, 17], [3, 4, 2]) is None
   True
   >>> crt([3, 6], [2, 5])
   (5, 6)

Note: the order of gf_crt's arguments is reversed relative to crt,
and that solve_congruence takes residue, modulus pairs.

Programmer's note: rather than checking that all pairs of moduli share
no GCD (an O(n**2) test) and rather than factoring all moduli and seeing
that there is no factor in common, a check that the result gives the
indicated residuals is performed -- an O(n) operation.

See Also
========

solve_congruence
sympy.polys.galoistools.gf_crt : low level crt routine used by this routine
c              3   óL   <"  € T F  w  rW,          SV,          8H  x € K  	  R # 5i©Nr   )Ú.0Úvr   Úresults   &  €r   Ú	<genexpr>Úcrt.<locals>.<genexpr>Z   s   øé € Ð=±9©4¨1�1•5˜F Q�JÖ&³9ùs   ƒ!$FTÚcheckÚ	symmetric)ÚlistÚmapr   r
   r	   r   ÚallÚzipÚsolve_congruenceÚintr   )r   r   r   r   Úmmr   s   &&&& @r   Úcrtr&      sÓ   ø€ ÷t Ü””V˜Q“Ó ˆÜ””V˜Q“Ó ˆä�Aœ"Ó€FÜ	ˆa‹€Bçß‹sÔ=´3°q´9Ó=�s�sŠsÔ=´3°q´9Ó=×=Ò=Ü%¤t¬C°«I£ð 6Øð6Ø+4ñ6ˆFàŠ~Ø�Ø‰JˆF�BçÜÔ$ V¨RÓ0Ó1´3°r³7Ð:Ð:Üˆv‹;œ˜B›ÐÐr   c                ó"   € \        V \        4      # )aß  First part of Chinese Remainder Theorem, for multiple application.

Examples
========

>>> from sympy.ntheory.modular import crt, crt1, crt2
>>> m = [99, 97, 95]
>>> v = [49, 76, 65]

The following two codes have the same result.

>>> crt(m, v)
(639985, 912285)

>>> mm, e, s = crt1(m)
>>> crt2(m, v, mm, e, s)
(639985, 912285)

However, it is faster when we want to fix ``m`` and
compute for multiple ``v``, i.e. the following cases:

>>> mm, e, s = crt1(m)
>>> vs = [[52, 21, 37], [19, 46, 76]]
>>> for v in vs:
...     print(crt2(m, v, mm, e, s))
(397042, 912285)
(803206, 912285)

See Also
========

sympy.polys.galoistools.gf_crt1 : low level crt routine used by this routine
sympy.ntheory.modular.crt
sympy.ntheory.modular.crt2

)r   r	   )r   s   &r   Úcrt1r(   f   s   € ôL �1”b‹>Ðr   c                ó    € \        WW#V\        4      pV'       d    \        \        Wb4      4      \        V4      3# \        V4      \        V4      3# )a�  Second part of Chinese Remainder Theorem, for multiple application.

See ``crt1`` for usage.

Examples
========

>>> from sympy.ntheory.modular import crt1, crt2
>>> mm, e, s = crt1([18, 42, 6])
>>> crt2([18, 42, 6], [0, 0, 0], mm, e, s)
(0, 4536)

See Also
========

sympy.polys.galoistools.gf_crt2 : low level crt routine used by this routine
sympy.ntheory.modular.crt
sympy.ntheory.modular.crt1

)r   r	   r$   r   )r   r   r%   ÚeÚsr   r   s   &&&&&& r   Úcrt2r,   �   sD   € ô, �Q˜2 !¤RÓ(€FçÜÔ$ VÓ0Ó1´3°r³7Ð:Ð:Üˆv‹;œ˜B›ÐÐr   c                 ó®  € R pT pVP                  RR4      pVP                  RR4      '       dÜ   V UUu. uF  w  rV\        V4      \        V4      3NK  	  ppp/ pV F)  w  rVWV,          pWg9   d   WWV,          8w  d    R# K%  WWV&   K+  	  VP                  4        UUu. uF  w  reWV3NK
  	  ppp?\        ;QJ d    R V 4       F  '       d   K   RM	  RM! R V 4       4      '       d#   \	        \        V!  4      w  rV\        WeVRR7      # R	pV F  p	V! W‰4      pVf    R# Vw  r¦W¦,          p
K   	  V'       d   \        X
X4      V3# X
X3# u uppi u uppi )
aŽ  Compute the integer ``n`` that has the residual ``ai`` when it is
divided by ``mi`` where the ``ai`` and ``mi`` are given as pairs to
this function: ((a1, m1), (a2, m2), ...). If there is no solution,
return None. Otherwise return ``n`` and its modulus.

The ``mi`` values need not be co-prime. If it is known that the moduli are
not co-prime then the hint ``check`` can be set to False (default=True) and
the check for a quicker solution via crt() (valid when the moduli are
co-prime) will be skipped.

If the hint ``symmetric`` is True (default is False), the value of ``n``
will be within 1/2 of the modulus, possibly negative.

Examples
========

>>> from sympy.ntheory.modular import solve_congruence

What number is 2 mod 3, 3 mod 5 and 2 mod 7?

>>> solve_congruence((2, 3), (3, 5), (2, 7))
(23, 105)
>>> [23 % m for m in [3, 5, 7]]
[2, 3, 2]

If you prefer to work with all remainder in one list and
all moduli in another, send the arguments like this:

>>> solve_congruence(*zip((2, 3, 2), (3, 5, 7)))
(23, 105)

The moduli need not be co-prime; in this case there may or
may not be a solution:

>>> solve_congruence((2, 3), (4, 6)) is None
True

>>> solve_congruence((2, 3), (5, 6))
(5, 6)

The symmetric flag will make the result be within 1/2 of the modulus:

>>> solve_congruence((2, 3), (5, 6), symmetric=True)
(-1, 6)

See Also
========

crt : high level routine implementing the Chinese Remainder Theorem

c                ó  € V w  r#Vw  rEY4V,
          Tr‡p\        WgV4      p	WgV3 U
u. uF  qªV	,          NK  	  up
w  rgpV^8w  d    \        Wh4      w  r›pV	^8w  d   R# W{,          pW#V,          ,           W8,          rÖWm3# u up
i )zÑReturn the tuple (a, m) which satisfies the requirement
that n = a + i*m satisfy n = a1 + j*m1 and n = a2 = k*m2.

References
==========

.. [1] https://en.wikipedia.org/wiki/Method_of_successive_substitution
Nr   )Úc1Úc2Úa1Úm1Úa2Úm2r   ÚbÚcÚgÚiÚinv_aÚ_r   s   &&            r   ÚcombineÚ!solve_congruence.<locals>.combineà   sŠ   € ð ‰ˆØ‰ˆØ˜2•g˜rˆaˆÜ��a‹LˆØ"#¨¡Ó+¡˜A�a—4�4¡Ñ+‰ˆˆaØ�Œ6Ü  ›,‰KˆA�aØ�AŒvÙØ�JˆAØ�q•D�y˜"�$ˆ1Øˆtˆùò ,s   ¦A<r   Fr   TNc              3   ó<   "  € T F  w  r\        V4      x € K  	  R # 5ir   r   )r   Úrr   s   &  r   r   Ú#solve_congruence.<locals>.<genexpr>  s   é € Ð)¡b™d˜aŒw�q�zˆz£bùs   ‚)r   r   )r   é   )Úgetr   Úitemsr!   r   r"   r&   r   )Úremainder_modulus_pairsÚhintr;   Úrmr   r>   r   ÚuniqÚrvÚrmiÚns   *,         r   r#   r#   ¬   sF  € òhð, 
!€BØ—‘˜ eÓ,€Ià‡x�x�˜×ÒÙ13Ô4±©¨Œv�a‹yœ& ›)Ó$±ˆÑ4ð ˆÛ‰DˆAØ�FˆAØŒyØ˜Q�”<ÚÙØ�‹Gñ ð "&§¡¤Ô.¡™˜ˆq‹f¡ˆÑ.Ø÷
 ‹3Ñ)¡bÓ)�3�3Š3Ñ)¡bÓ)×)Ò)Üœ˜R™“>‰DˆAÜ�q y¸Ô>Ð>à	€BÛˆÙ�RÓˆØŠ:ÚØ‰ˆØ�EŠñ ÷ Ü$ Q¨Ó*¨AÐ-Ð-Ø�!ˆtˆùóS 5ùó* /s   µ!EÂEN)FT)F)Úmathr   Úsympy.external.gmpyr   r   Úsympy.ntheory.primetestr   Úsympy.polys.domainsr	   Úsympy.polys.galoistoolsr
   r   r   Úsympy.utilities.miscr   r   r&   r(   r,   r#   r   r   r   Ú<module>rP      s7   ðÝ ç +Ý +Ý "ß <Ñ <Ý 'òôK ò\&ôR ô:wr   