<s> """<STR_LIT>""" <EOL> from __future__ import print_function , division <EOL> from sympy . polys . polyerrors import CoercionFailed <EOL> from sympy . core . compatibility import reduce <EOL> class Ideal ( object ) : <EOL> """<STR_LIT>""" <EOL> def _contains_elem ( self , x ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def _contains_ideal ( self , I ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def _quotient ( self , J ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def _intersect ( self , J ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def is_whole_ring ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def is_zero ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def _equals ( self , J ) : <EOL> """<STR_LIT>""" <EOL> return self . _contains_ideal ( J ) and J . _contains_ideal ( self ) <EOL> def is_prime ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def is_maximal ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def is_radical ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def is_primary ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def is_principal ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def radical ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def depth ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def height ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def __init__ ( self , ring ) : <EOL> self . ring = ring <EOL> def _check_ideal ( self , J ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( J , Ideal ) or J . ring != self . ring : <EOL> raise ValueError ( <EOL> '<STR_LIT>' % ( self . ring , J ) ) <EOL> def contains ( self , elem ) : <EOL> """<STR_LIT>""" <EOL> return self . _contains_elem ( self . ring . convert ( elem ) ) <EOL> def subset ( self , other ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( other , Ideal ) : <EOL> return self . _contains_ideal ( other ) <EOL> return all ( self . _contains_elem ( x ) for x in other ) <EOL> def quotient ( self , J , ** opts ) : <EOL> r"""<STR_LIT>""" <EOL> self . _check_ideal ( J ) <EOL> return self . _quotient ( J , ** opts ) <EOL> def intersect ( self , J ) : <EOL> """<STR_LIT>""" <EOL> self . _check_ideal ( J ) <EOL> return self . _intersect ( J ) <EOL> def saturate ( self , J ) : <EOL> r"""<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def union ( self , J ) : <EOL> """<STR_LIT>""" <EOL> self . _check_ideal ( J ) <EOL> return self . _union ( J ) <EOL> def product ( self , J ) : <EOL> """<STR_LIT>""" <EOL> self . _check_ideal ( J ) <EOL> return self . _product ( J ) <EOL> def reduce_element ( self , x ) : <EOL> """<STR_LIT>""" <EOL> return x <EOL> def __add__ ( self , e ) : <EOL> if not isinstance ( e , Ideal ) : <EOL> R = self . ring . quotient_ring ( self ) <EOL> if isinstance ( e , R . dtype ) : <EOL> return e <EOL> if isinstance ( e , R . ring . dtype ) : <EOL> return R ( e ) <EOL> return R . convert ( e ) <EOL> self . _check_ideal ( e ) <EOL> return self . union ( e ) <EOL> __radd__ = __add__ <EOL> def __mul__ ( self , e ) : <EOL> if not isinstance ( e , Ideal ) : <EOL> try : <EOL> e = self . ring . ideal ( e ) <EOL> except CoercionFailed : <EOL> return NotImplemented <EOL> self . _check_ideal ( e ) <EOL> return self . product ( e ) <EOL> __rmul__ = __mul__ <EOL> def __pow__ ( self , exp ) : <EOL> if exp < <NUM_LIT:0> : <EOL> raise NotImplementedError <EOL> return reduce ( lambda x , y : x * y , [ self ] * exp , self . ring . ideal ( <NUM_LIT:1> ) ) <EOL> def __eq__ ( self , e ) : <EOL> if not isinstance ( e , Ideal ) or e . ring != self . ring : <EOL> return False <EOL> return self . _equals ( e ) <EOL> def __ne__ ( self , e ) : <EOL> return not ( self == e ) <EOL> class ModuleImplementedIdeal ( Ideal ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , ring , module ) : <EOL> Ideal . __init__ ( self , ring ) <EOL> self . _module = module <EOL> def _contains_elem ( self , x ) : <EOL> return self . _module . contains ( [ x ] ) <EOL> def _contains_ideal ( self , J ) : <EOL> if not isinstance ( J , ModuleImplementedIdeal ) : <EOL> raise NotImplementedError <EOL> return self . _module . is_submodule ( J . _module ) <EOL> def _intersect ( self , J ) : <EOL> if not isinstance ( J , ModuleImplementedIdeal ) : <EOL> raise NotImplementedError <EOL> return self . __class__ ( self . ring , self . _module . intersect ( J . _module ) ) <EOL> def _quotient ( self , J , ** opts ) : <EOL> if not isinstance ( J , ModuleImplementedIdeal ) : <EOL> raise NotImplementedError <EOL> return self . _module . module_quotient ( J . _module , ** opts ) <EOL> def _union ( self , J ) : <EOL> if not isinstance ( J , ModuleImplementedIdeal ) : <EOL> raise NotImplementedError <EOL> return self . __class__ ( self . ring , self . _module . union ( J . _module ) ) <EOL> @ property <EOL> def gens ( self ) : <EOL> """<STR_LIT>""" <EOL> return ( x [ <NUM_LIT:0> ] for x in self . _module . gens ) <EOL> def is_zero ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _module . is_zero ( ) <EOL> def is_whole_ring ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _module . is_full_module ( ) <EOL> def __repr__ ( self ) : <EOL> from sympy import sstr <EOL> return '<STR_LIT:<>' + '<STR_LIT:U+002C>' . join ( sstr ( x ) for [ x ] in self . _module . gens ) + '<STR_LIT:>>' <EOL> def _product ( self , J ) : <EOL> if not isinstance ( J , ModuleImplementedIdeal ) : <EOL> raise NotImplementedError <EOL> return self . __class__ ( self . ring , self . _module . submodule ( <EOL> * [ [ x * y ] for [ x ] in self . _module . gens for [ y ] in J . _module . gens ] ) ) <EOL> def in_terms_of_generators ( self , e ) : <EOL> """<STR_LIT>""" <EOL> return self . _module . in_terms_of_generators ( [ e ] ) <EOL> def reduce_element ( self , x , ** options ) : <EOL> return self . _module . reduce_element ( [ x ] , ** options ) [ <NUM_LIT:0> ] </s>
