
    gA+                     Z    d Z ddlmZ ddlmZ  G d de          Z G d de          ZdS )	z-Computations with ideals of polynomial rings.    )CoercionFailed)IntegerPowerablec                       e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZeZd ZeZ d Z!d Z"d Z#d  Z$d!S )"Ideala  
    Abstract base class for ideals.

    Do not instantiate - use explicit constructors in the ring class instead:

    >>> from sympy import QQ
    >>> from sympy.abc import x
    >>> QQ.old_poly_ring(x).ideal(x+1)
    <x + 1>

    Attributes

    - ring - the ring this ideal belongs to

    Non-implemented methods:

    - _contains_elem
    - _contains_ideal
    - _quotient
    - _intersect
    - _union
    - _product
    - is_whole_ring
    - is_zero
    - is_prime, is_maximal, is_primary, is_radical
    - is_principal
    - height, depth
    - radical

    Methods that likely should be overridden in subclasses:

    - reduce_element
    c                     t           )z&Implementation of element containment.NotImplementedErrorselfxs     S/var/www/html/ai-engine/env/lib/python3.11/site-packages/sympy/polys/agca/ideals.py_contains_elemzIdeal._contains_elem*       !!    c                     t           )z$Implementation of ideal containment.r   )r   Is     r   _contains_idealzIdeal._contains_ideal.   r   r   c                     t           )z!Implementation of ideal quotient.r   r   Js     r   	_quotientzIdeal._quotient2   r   r   c                     t           )z%Implementation of ideal intersection.r   r   s     r   
_intersectzIdeal._intersect6   r   r   c                     t           )z*Return True if ``self`` is the whole ring.r   r   s    r   is_whole_ringzIdeal.is_whole_ring:   r   r   c                     t           )z*Return True if ``self`` is the zero ideal.r   r   s    r   is_zerozIdeal.is_zero>   r   r   c                 V    |                      |          o|                     |           S )z!Implementation of ideal equality.)r   r   s     r   _equalszIdeal._equalsB   s)    ##A&&B1+<+<T+B+BBr   c                     t           )z)Return True if ``self`` is a prime ideal.r   r   s    r   is_primezIdeal.is_primeF   r   r   c                     t           )z+Return True if ``self`` is a maximal ideal.r   r   s    r   
is_maximalzIdeal.is_maximalJ   r   r   c                     t           )z+Return True if ``self`` is a radical ideal.r   r   s    r   
is_radicalzIdeal.is_radicalN   r   r   c                     t           )z+Return True if ``self`` is a primary ideal.r   r   s    r   
is_primaryzIdeal.is_primaryR   r   r   c                     t           )z-Return True if ``self`` is a principal ideal.r   r   s    r   is_principalzIdeal.is_principalV   r   r   c                     t           )z Compute the radical of ``self``.r   r   s    r   radicalzIdeal.radicalZ   r   r   c                     t           )zCompute the depth of ``self``.r   r   s    r   depthzIdeal.depth^   r   r   c                     t           )zCompute the height of ``self``.r   r   s    r   heightzIdeal.heightb   r   r   c                     || _         d S N)ring)r   r3   s     r   __init__zIdeal.__init__j   s    			r   c                     t          |t                    r|j        | j        k    rt          d| j        d|          dS )z.Helper to check ``J`` is an ideal of our ring.zJ must be an ideal of z, got N)
isinstancer   r3   
ValueErrorr   s     r   _check_idealzIdeal._check_idealm   sR    !U## 	Eqv':':*6:iiiCE E E (;':r   c                 \    |                      | j                            |                    S )aD  
        Return True if ``elem`` is an element of this ideal.

        Examples
        ========

        >>> from sympy.abc import x
        >>> from sympy import QQ
        >>> QQ.old_poly_ring(x).ideal(x+1, x-1).contains(3)
        True
        >>> QQ.old_poly_ring(x).ideal(x**2, x**3).contains(x)
        False
        )r   r3   convert)r   elems     r   containszIdeal.containss   s(     ""49#4#4T#:#:;;;r   c                      t          |t                    r                     |          S t           fd|D                       S )a  
        Returns True if ``other`` is is a subset of ``self``.

        Here ``other`` may be an ideal.

        Examples
        ========

        >>> from sympy.abc import x
        >>> from sympy import QQ
        >>> I = QQ.old_poly_ring(x).ideal(x+1)
        >>> I.subset([x**2 - 1, x**2 + 2*x + 1])
        True
        >>> I.subset([x**2 + 1, x + 1])
        False
        >>> I.subset(QQ.old_poly_ring(x).ideal(x**2 - 1))
        True
        c              3   B   K   | ]}                     |          V  d S r2   )r   .0r   r   s     r   	<genexpr>zIdeal.subset.<locals>.<genexpr>   s1      99a4&&q))999999r   )r6   r   r   all)r   others   ` r   subsetzIdeal.subset   sN    & eU## 	/''...99995999999r   c                 H    |                      |            | j        |fi |S )a~  
        Compute the ideal quotient of ``self`` by ``J``.

        That is, if ``self`` is the ideal `I`, compute the set
        `I : J = \{x \in R | xJ \subset I \}`.

        Examples
        ========

        >>> from sympy.abc import x, y
        >>> from sympy import QQ
        >>> R = QQ.old_poly_ring(x, y)
        >>> R.ideal(x*y).quotient(R.ideal(x))
        <y>
        )r8   r   r   r   optss      r   quotientzIdeal.quotient   s2      	!t~a((4(((r   c                 V    |                      |           |                     |          S )a  
        Compute the intersection of self with ideal J.

        Examples
        ========

        >>> from sympy.abc import x, y
        >>> from sympy import QQ
        >>> R = QQ.old_poly_ring(x, y)
        >>> R.ideal(x).intersect(R.ideal(y))
        <x*y>
        )r8   r   r   s     r   	intersectzIdeal.intersect   s*     	!q!!!r   c                     t           )z
        Compute the ideal saturation of ``self`` by ``J``.

        That is, if ``self`` is the ideal `I`, compute the set
        `I : J^\infty = \{x \in R | xJ^n \subset I \text{ for some } n\}`.
        r   r   s     r   saturatezIdeal.saturate   s
     "!r   c                 V    |                      |           |                     |          S )aD  
        Compute the ideal generated by the union of ``self`` and ``J``.

        Examples
        ========

        >>> from sympy.abc import x
        >>> from sympy import QQ
        >>> QQ.old_poly_ring(x).ideal(x**2 - 1).union(QQ.old_poly_ring(x).ideal((x+1)**2)) == QQ.old_poly_ring(x).ideal(x+1)
        True
        )r8   _unionr   s     r   unionzIdeal.union   s(     	!{{1~~r   c                 V    |                      |           |                     |          S )a  
        Compute the ideal product of ``self`` and ``J``.

        That is, compute the ideal generated by products `xy`, for `x` an element
        of ``self`` and `y \in J`.

        Examples
        ========

        >>> from sympy.abc import x, y
        >>> from sympy import QQ
        >>> QQ.old_poly_ring(x, y).ideal(x).product(QQ.old_poly_ring(x, y).ideal(y))
        <x*y>
        )r8   _productr   s     r   productzIdeal.product   s*     	!}}Qr   c                     |S )z
        Reduce the element ``x`` of our ring modulo the ideal ``self``.

        Here "reduce" has no specific meaning: it could return a unique normal
        form, simplify the expression a bit, or just do nothing.
         r
   s     r   reduce_elementzIdeal.reduce_element   s	     r   c                 V   t          |t                    sk| j                            |           }t          ||j                  r|S t          ||j        j                  r ||          S |                    |          S |                     |           |                     |          S r2   )r6   r   r3   quotient_ringdtyper:   r8   rO   )r   eRs      r   __add__zIdeal.__add__   s    !U## 	 	''--A!QW%% !QV\** qtt99Q<<!zz!}}r   c                     t          |t                    s3	 | j                            |          }n# t          $ r
 t
          cY S w xY w|                     |           |                     |          S r2   )r6   r   r3   idealr   NotImplementedr8   rR   r   rY   s     r   __mul__zIdeal.__mul__   sy    !U## 	&&IOOA&&! & & &%%%%&!||As   2 AAc                 6    | j                             d          S N   )r3   r]   r   s    r   _zeroth_powerzIdeal._zeroth_power	  s    yq!!!r   c                     | dz  S rb   rT   r   s    r   _first_powerzIdeal._first_power  s     axr   c                 z    t          |t                    r|j        | j        k    rdS |                     |          S )NF)r6   r   r3   r    r_   s     r   __eq__zIdeal.__eq__  s7    !U## 	qv':':5||Ar   c                     | |k     S r2   rT   r_   s     r   __ne__zIdeal.__ne__  s    AIr   N)%__name__
__module____qualname____doc__r   r   r   r   r   r   r    r"   r$   r&   r(   r*   r,   r.   r0   r4   r8   r<   rD   rH   rJ   rL   rO   rR   rU   r[   __radd__r`   __rmul__rd   rf   rh   rj   rT   r   r   r   r      s          D" " "" " "" " "" " "" " "" " "C C C" " "" " "" " "" " "" " "" " "" " "" " "  E E E< < < : : :.) ) )&" " " " " "       $  	 	 	 H   H" " "  
  
    r   r   c                   p    e Zd ZdZd Zd Zd Zd Zd Zd Z	e
d             Zd	 Zd
 Zd Zd Zd Zd ZdS )ModuleImplementedIdealzs
    Ideal implementation relying on the modules code.

    Attributes:

    - _module - the underlying module
    c                 J    t                               | |           || _        d S r2   )r   r4   _module)r   r3   modules      r   r4   zModuleImplementedIdeal.__init__#  s!    tT"""r   c                 8    | j                             |g          S r2   )rt   r<   r
   s     r   r   z%ModuleImplementedIdeal._contains_elem'  s    |$$aS)))r   c                 x    t          |t                    st          | j                            |j                  S r2   )r6   rr   r	   rt   is_submoduler   s     r   r   z&ModuleImplementedIdeal._contains_ideal*  s3    !344 	&%%|((333r   c                     t          |t                    st          |                     | j        | j                            |j                            S r2   )r6   rr   r	   	__class__r3   rt   rJ   r   s     r   r   z!ModuleImplementedIdeal._intersect/  sC    !344 	&%%~~di)?)?	)J)JKKKr   c                 j    t          |t                    st           | j        j        |j        fi |S r2   )r6   rr   r	   rt   module_quotientrF   s      r   r   z ModuleImplementedIdeal._quotient4  s:    !344 	&%%+t|+AI>>>>>r   c                     t          |t                    st          |                     | j        | j                            |j                            S r2   )r6   rr   r	   rz   r3   rt   rO   r   s     r   rN   zModuleImplementedIdeal._union9  sC    !344 	&%%~~di););AI)F)FGGGr   c                 .    d | j         j        D             S )aB  
        Return generators for ``self``.

        Examples
        ========

        >>> from sympy import QQ
        >>> from sympy.abc import x, y
        >>> list(QQ.old_poly_ring(x, y).ideal(x, y, x**2 + y).gens)
        [DMP_Python([[1], []], QQ), DMP_Python([[1, 0]], QQ), DMP_Python([[1], [], [1, 0]], QQ)]
        c              3   &   K   | ]}|d          V  dS )r   NrT   )r@   r   s     r   rA   z.ModuleImplementedIdeal.gens.<locals>.<genexpr>K  s&      00!000000r   rt   gensr   s    r   r   zModuleImplementedIdeal.gens>  s     10dl/0000r   c                 4    | j                                         S )a%  
        Return True if ``self`` is the zero ideal.

        Examples
        ========

        >>> from sympy.abc import x
        >>> from sympy import QQ
        >>> QQ.old_poly_ring(x).ideal(x).is_zero()
        False
        >>> QQ.old_poly_ring(x).ideal().is_zero()
        True
        )rt   r   r   s    r   r   zModuleImplementedIdeal.is_zeroM  s     |##%%%r   c                 4    | j                                         S )a  
        Return True if ``self`` is the whole ring, i.e. one generator is a unit.

        Examples
        ========

        >>> from sympy.abc import x
        >>> from sympy import QQ, ilex
        >>> QQ.old_poly_ring(x).ideal(x).is_whole_ring()
        False
        >>> QQ.old_poly_ring(x).ideal(3).is_whole_ring()
        True
        >>> QQ.old_poly_ring(x, order=ilex).ideal(2 + x).is_whole_ring()
        True
        )rt   is_full_moduler   s    r   r   z$ModuleImplementedIdeal.is_whole_ring]  s      |**,,,r   c                      ddl m  fd j        j        D             }dd                    fd|D                       z   dz   S )Nr   )sstrc                 H    g | ]\  }j                             |          S rT   )r3   to_sympyr?   s     r   
<listcomp>z3ModuleImplementedIdeal.__repr__.<locals>.<listcomp>q  s+    CCC#1	""1%%CCCr   <,c              3   .   K   | ]} |          V  d S r2   rT   )r@   gr   s     r   rA   z2ModuleImplementedIdeal.__repr__.<locals>.<genexpr>r  s+      44!dd1gg444444r   >)sympy.printing.strr   rt   r   join)r   r   r   s   ` @r   __repr__zModuleImplementedIdeal.__repr__o  se    ++++++CCCC1BCCCSXX4444t444444s::r   c                     t          t                    st          |                     | j         | j        j        fd| j        j        D                        S )Nc                 B    g | ]\  }j         j        D ]
\  }||z  gS rT   r   )r@   r   yr   s      r   r   z3ModuleImplementedIdeal._product.<locals>.<listcomp>y  s4    KKKAINKKSaqseKKKKr   )r6   rr   r	   rz   r3   rt   	submoduler   r   s    `r   rQ   zModuleImplementedIdeal._productu  se    !344 	&%%~~di)?)?KKKKt|0KKK*M N N 	Nr   c                 8    | j                             |g          S )aX  
        Express ``e`` in terms of the generators of ``self``.

        Examples
        ========

        >>> from sympy.abc import x
        >>> from sympy import QQ
        >>> I = QQ.old_poly_ring(x).ideal(x**2 + 1, x)
        >>> I.in_terms_of_generators(1)  # doctest: +SKIP
        [DMP_Python([1], QQ), DMP_Python([-1, 0], QQ)]
        )rt   in_terms_of_generatorsr_   s     r   r   z-ModuleImplementedIdeal.in_terms_of_generators{  s     |22A3777r   c                 6     | j         j        |gfi |d         S )Nr   )rt   rU   )r   r   optionss      r   rU   z%ModuleImplementedIdeal.reduce_element  s&    *t|*A3::'::1==r   N)rk   rl   rm   rn   r4   r   r   r   r   rN   propertyr   r   r   r   rQ   r   rU   rT   r   r   rr   rr     s           * * *4 4 4
L L L
? ? ?
H H H
 1 1 X1& & & - - -$; ; ;N N N8 8 8> > > > >r   rr   N)rn   sympy.polys.polyerrorsr   sympy.polys.polyutilsr   r   rr   rT   r   r   <module>r      s    3 3 1 1 1 1 1 1 2 2 2 2 2 2P P P P P P P Pfq> q> q> q> q>U q> q> q> q> q>r   