Ticket #6457: trac_6457-ideal_intersection.patch

File trac_6457-ideal_intersection.patch, 1.8 KB (added by davidloeffler, 10 years ago)

patch against 4.1.alpha2

  • sage/rings/number_field/number_field_ideal.py

    #6457: intersection of ideals in a number field
    
    diff -r 3ebf91bde442 sage/rings/number_field/number_field_ideal.py
    a b  
    639639                self.__integral_split = (self*denominator, denominator)
    640640            return self.__integral_split
    641641
     642    def intersection(self, other):
     643        r"""
     644        Return the intersection of self and other.
     645
     646        EXAMPLE::
     647
     648            sage: K.<a> = QuadraticField(-11)
     649            sage: p = K.ideal((a + 1)/2); q = K.ideal((a + 3)/2)
     650            sage: p.intersection(q) == q.intersection(p) == K.ideal(a-2)
     651            True
     652
     653        An example with non-principal ideals::
     654
     655            sage: L.<a> = NumberField(x^3 - 7)
     656            sage: p = L.ideal(a^2 + a + 1, 2)
     657            sage: q = L.ideal(a+1)
     658            sage: p.intersection(q) == L.ideal(8, 2*a + 2)
     659            True
     660
     661        A relative example::
     662
     663            sage: L.<a,b> = NumberField([x^2 + 11, x^2 - 5])
     664            sage: A = L.ideal([15, (-3/2*b + 7/2)*a - 8])
     665            sage: B = L.ideal([6, (-1/2*b + 1)*a - b - 5/2])
     666            sage: A.intersection(B) == L.ideal(-1/2*a - 3/2*b - 1)
     667            True
     668        """
     669        other = self.number_field().ideal(other)
     670        mod = self.free_module().intersection(other.free_module())
     671        L = self.number_field()
     672        if L.is_absolute():
     673            elts = [L(x.list()) for x in mod.gens()]
     674        else:
     675            elts = [sum([x[i] * L.absolute_generator()**i for i in xrange(L.absolute_degree())]) for x in mod.gens()]
     676        return L.ideal(elts)
     677
    642678    def is_integral(self):
    643679        """
    644680        Return True if this ideal is integral.