Ticket #14165: 14165_add_subfield.patch

File 14165_add_subfield.patch, 2.5 KB (added by mmarco, 8 years ago)
  • sage/rings/qqbar.py

    # HG changeset patch
    # User Miguel Marco <mmarco@unizar.es>
    # Date 1361548433 -3600
    # Node ID e351ad3334247e107d7fb1295784eae5fc1f7e75
    # Parent  4165f8bda699431898adbf05935057353bf49661
    Trac #14165: add subfield mehod to QQbar and AA
    
    diff --git a/sage/rings/qqbar.py b/sage/rings/qqbar.py
    a b  
    637637        """
    638638        return AlgebraicPolynomialTracker(poly)
    639639
     640    def subfield(self, numbers, name='a'):
     641        """
     642        Computes the number field generated by the numbers passed.
     643
     644        INPUT:
     645
     646            - ``numbers`` -- an element of self, or a list or tuple of them.
     647
     648            - ``name`` -- (default: 'a') a string with the name of the generator of the resulting field.
     649
     650        OUTPUT:
     651
     652            - a tuple, whose first entry is a number field F, and the second is a list with the elements passed expressed in F.
     653
     654        EXAMPLES::
     655
     656            sage: a=QQbar(sqrt(2))
     657            sage: a
     658            1.414213562373095?
     659            sage: b=QQbar(3^(1/3))
     660            sage: b
     661            1.442249570307409?
     662            sage: QQbar.subfield([a,b],'t')
     663            (Number Field in t with defining polynomial x^6 - 6*x^4 - 6*x^3 + 12*x^2 - 36*x + 1,
     664            [-48/755*t^5 - 27/755*t^4 + 64/151*t^3 + 468/755*t^2 - 879/755*t + 1092/755,
     665            -48/755*t^5 - 27/755*t^4 + 64/151*t^3 + 468/755*t^2 - 124/755*t + 1092/755])
     666            sage: [ap,bp]=QQbar.subfield([a,b],'t')[1]
     667            sage: QQbar(ap)
     668            1.414213562373095?
     669            sage: QQbar(bp)==b
     670            True
     671
     672        """
     673        if not isinstance(numbers,(list,tuple)):
     674            return self.subfield([numbers],name)
     675        elif len(numbers)==1:
     676            F=NumberField(numbers[0].minpoly(),name,embedding=numbers[0])
     677            return (F,[G.gen()])
     678        l=list(numbers)
     679        cuerpos=[NumberField(l[i].minpoly(),name+str(i),embedding=l[i]) for i in range(len(l))]
     680        F=cuerpos.pop(0)
     681        gens=[F.gen()]
     682        while len(cuerpos)>0:
     683            F2=cuerpos.pop(0)
     684            if F2.gen() in QQ:
     685                gens.append(F(QQ(F2.gen())))
     686            else:
     687                extension=F.composite_fields(F2,name,both_maps=True)
     688                h1=extension[0][1]
     689                h2=extension[0][2]
     690                gens=map(h1,gens)
     691                gens.append(h2(F2.gen()))
     692                F=extension[0][0]
     693        return (F,gens)
     694
    640695class AlgebraicRealField(_uniq_alg_r, AlgebraicField_common):
    641696    r"""
    642697    The field of algebraic reals.