Number Field generators

65 views
Skip to first unread message

Jason Grout

unread,
Feb 16, 2008, 6:28:10 AM2/16/08
to sage-...@googlegroups.com
Is the following output for b.gens() correct?

sage: NumberField([x,x^2-3],'a')
Number Field in a0 with defining polynomial x over its base field
sage: b=NumberField([x,x^2-3],'a')
sage: b.gens()
(0, 0)

To contrast:

sage: c=NumberField([x^2-3, x^2-2],'a')
sage: c.gens()
(a0, a1)


Also, this blows up:

sage: c=NumberField([x^2-3, x],'a')
---------------------------------------------------------------------------
<class 'sage.libs.pari.gen.PariError'> Traceback (most recent call last)

/home/grout/sage/<ipython console> in <module>()

/home/grout/sage/local/lib/python2.5/site-packages/sage/rings/number_field/number_field.py
in NumberField(polynomial, name, check, names, cache)
243
244 if isinstance(polynomial, (list, tuple)):
--> 245 return NumberFieldTower(polynomial, name)
246
247 name = sage.structure.parent_gens.normalize_names(1, name)

/home/grout/sage/local/lib/python2.5/site-packages/sage/rings/number_field/number_field.py
in NumberFieldTower(v, names, check)
411 # return z
412 #else:
--> 413 return w.extension(f, name, check=check)
414
415

/home/grout/sage/local/lib/python2.5/site-packages/sage/rings/number_field/number_field.py
in extension(self, poly, name, names, check)
1813 if name is None:
1814 raise TypeError, "the variable name must be specified."
-> 1815 return NumberField_relative(self, poly, str(name),
check=check)
1816
1817 def factor_integer(self, n):

/home/grout/sage/local/lib/python2.5/site-packages/sage/rings/number_field/number_field.py
in __init__(self, base, polynomial, name, latex_name, names, check)
3110
3111 if check:
-> 3112 if not polynomial_y.is_irreducible():
3113 raise ValueError, "defining polynomial (%s)
must be irreducible"%polynomial
3114

/home/grout/sage/polynomial_element.pyx in
sage.rings.polynomial.polynomial_element.Polynomial.is_irreducible()

/home/grout/sage/polynomial_element.pyx in
sage.rings.polynomial.polynomial_element.Polynomial.factor()

/home/grout/sage/gen.pyx in sage.libs.pari.gen._pari_trap()

<class 'sage.libs.pari.gen.PariError'>: (8)
sage: c=NumberField([x^2-3, x-1],'a')
---------------------------------------------------------------------------
<class 'sage.libs.pari.gen.PariError'> Traceback (most recent call last)

/home/grout/sage/<ipython console> in <module>()

/home/grout/sage/local/lib/python2.5/site-packages/sage/rings/number_field/number_field.py
in NumberField(polynomial, name, check, names, cache)
243
244 if isinstance(polynomial, (list, tuple)):
--> 245 return NumberFieldTower(polynomial, name)
246
247 name = sage.structure.parent_gens.normalize_names(1, name)

/home/grout/sage/local/lib/python2.5/site-packages/sage/rings/number_field/number_field.py
in NumberFieldTower(v, names, check)
411 # return z
412 #else:
--> 413 return w.extension(f, name, check=check)
414
415

/home/grout/sage/local/lib/python2.5/site-packages/sage/rings/number_field/number_field.py
in extension(self, poly, name, names, check)
1813 if name is None:
1814 raise TypeError, "the variable name must be specified."
-> 1815 return NumberField_relative(self, poly, str(name),
check=check)
1816
1817 def factor_integer(self, n):

/home/grout/sage/local/lib/python2.5/site-packages/sage/rings/number_field/number_field.py
in __init__(self, base, polynomial, name, latex_name, names, check)
3110
3111 if check:
-> 3112 if not polynomial_y.is_irreducible():
3113 raise ValueError, "defining polynomial (%s)
must be irreducible"%polynomial
3114

/home/grout/sage/polynomial_element.pyx in
sage.rings.polynomial.polynomial_element.Polynomial.is_irreducible()

/home/grout/sage/polynomial_element.pyx in
sage.rings.polynomial.polynomial_element.Polynomial.factor()

/home/grout/sage/gen.pyx in sage.libs.pari.gen._pari_trap()

<class 'sage.libs.pari.gen.PariError'>: (8)

-Jason

John Cremona

unread,
Feb 16, 2008, 7:27:13 AM2/16/08
to sage-...@googlegroups.com
Are you sure you mean to give NumberField() two polynomials, one of
which (x) defines the trivial extension? You are only giving one name
so I rpresume what you mean (to define a quadratic field) is


sage: NumberField([x^2-3],'a')
Number Field in a with defining polynomial x^2 - 3
sage: F=NumberField([x^2-3],'a')
sage: F.gens()
(a,)

On 16/02/2008, Jason Grout <jason...@creativetrax.com> wrote:
>
> Is the following output for b.gens() correct?
>
> sage: NumberField([x,x^2-3],'a')
> Number Field in a0 with defining polynomial x over its base field
> sage: b=NumberField([x,x^2-3],'a')
> sage: b.gens()
> (0, 0)
>
> To contrast:
>
> sage: c=NumberField([x^2-3, x^2-2],'a')
> sage: c.gens()
> (a0, a1)
>
>
> Also, this blows up:
>
> sage: c=NumberField([x^2-3, x],'a')

The problem here is that x is triggering a an error in the
irreducibility test, which is a little bizarre since of course x is
irreducible.

So the real issue is: why is x allowed to determine an absolute number
field (base Q) but not a relative one? My guess is that this is a
side-effect of the differing code being used to test irreducibility in
the two cases,

Personally, I think that trivial extensions should be allowed and
treated just as non-trivial ones. I have recently had to define
extensions of the ring ZZ, and find this awkward:

sage: R=ZZ.extension(x^2+5,'a')
sage: R.gens()
[1, a]
sage: S=ZZ.extension(x+5,'b')
sage: S.gens()
[1]

In the latter case I need S to remember the polynomial used to
generaite it and would expect its gens() to include (in this case) -5.

On the same topic, R and S above have no defining_polynomial() method.
I'll try to fix that if it looks easy.

John


--
John Cremona

Jason Grout

unread,
Feb 16, 2008, 2:55:34 PM2/16/08
to sage-...@googlegroups.com
John Cremona wrote:
> Are you sure you mean to give NumberField() two polynomials, one of
> which (x) defines the trivial extension? You are only giving one name
> so I rpresume what you mean (to define a quadratic field) is
>
>
> sage: NumberField([x^2-3],'a')
> Number Field in a with defining polynomial x^2 - 3
> sage: F=NumberField([x^2-3],'a')
> sage: F.gens()
> (a,)

Yes, I'd like to get the quadratic extension. I know I can do this
without the x; my question was about why it didn't work the way I was
trying (and why it was complaining that x was not irreducible), but I
didn't know if I was naively doing something wrong either.

What I'm trying to do is get a number field that has all the roots of a
(not necessarily irreducible) polynomial. I was trying to automatically
construct a field that contained the eigenvalues of a matrix. But when
calling NumberField on the list of irreducible factors of the
characteristic polynomial, things were blowing or not making sense to me
if there was a linear factor somewhere.

Is there an easier way to get an extension that contains all the roots
of a given polynomial (which may not be irreducible)? I tried the
following, but it didn't work; should it?

sage: a=QQ['x']; x=a.gen()
sage: b=(x^2-2)*(x^2-3)
sage: b.root_field('y')
---------------------------------------------------------------------------
<type 'exceptions.ValueError'> Traceback (most recent call last)

/home/grout/<ipython console> in <module>()

/home/grout/polynomial_element.pyx in
sage.rings.polynomial.polynomial_element.Polynomial.root_field()

/home/grout/sage/local/lib/python2.5/site-packages/sage/rings/number_field/number_field.py
in NumberField(polynomial, name, check, names, cache)

274 K = NumberField_quadratic(polynomial, name, check)
275 else:
--> 276 K = NumberField_absolute(polynomial, name, None, check)
277
278 if cache:

/home/grout/sage/local/lib/python2.5/site-packages/sage/rings/number_field/number_field.py
in __init__(self, polynomial, name, latex_name, check)
2466
2467 def __init__(self, polynomial, name, latex_name=None,
check=True):
-> 2468 NumberField_generic.__init__(self, polynomial, name,
latex_name, check)
2469 self._element_class =
number_field_element.NumberFieldElement_absolute
2470

/home/grout/sage/local/lib/python2.5/site-packages/sage/rings/number_field/number_field.py
in __init__(self, polynomial, name, latex_name, check)
621 if check:
622 if not polynomial.is_irreducible():
--> 623 raise ValueError, "defining polynomial (%s) must
be irreducible"%polynomial
624 if not polynomial.parent().base_ring() == QQ:
625 raise TypeError, "polynomial must be defined
over rational field"

<type 'exceptions.ValueError'>: defining polynomial (x^4 - 5*x^2 + 6)
must be irreducible

Thanks!

Jason

John Cremona

unread,
Feb 16, 2008, 3:11:17 PM2/16/08
to sage-...@googlegroups.com
I agree that this would be a useful funtion to have. I would call it
splitting_field() with a description similar to that of root_field()
-- whose docstring does not say that self should be irreducible,
though in fact it must.

In the meantim you should be able to work with what is available as follows:

sage: QQx.<x>=QQ[]
sage: f=(x^2-2)*(x^2-3)
sage: F=NumberField([p for p,n in f.factor()],'a')
sage: F2=F.absolute_field('b')
sage: F2.structure()

(Isomorphism from Number Field in b with defining polynomial x^4 -
10*x^2 + 1 to Number Field in a0 with defining polynomial x^2 - 3 over
its base field,
Isomorphism from Number Field in a0 with defining polynomial x^2 - 3
over its base field to Number Field in b with defining polynomial x^4
- 10*x^2 + 1)

Here F is first defined as a relative extension, with generators a0,a1
satisfying the equations:

sage: a0,a1=F.gens()
sage: a0^2, a1^2
(3, 2)

then F2 is the associated absolute field, with F2.structure() giving
maps from each of these into the other.

sage: F2toF, FtoF2=F2.structure()
sage: FtoF2(a0)
-1/2*b^3 + 11/2*b
sage: FtoF2(a0).minpoly()
x^2 - 3
sage: FtoF2(a1)
-1/2*b^3 + 9/2*b
sage: FtoF2(a1).minpoly()
x^2 - 2

John


--
John Cremona

Carl Witty

unread,
Feb 17, 2008, 12:49:44 PM2/17/08
to sage-devel
On Feb 16, 11:55 am, Jason Grout <jason-s...@creativetrax.com> wrote:
> What I'm trying to do is get a number field that has all the roots of a
> (not necessarily irreducible) polynomial.

There is code to do this embedded in qqbar.py.

sage: x = polygen(QQ)
sage: b = (x^2-2)*(x^2-3)
sage: rts = b.roots(ring=QQbar, multiplicities=False)
sage: from sage.rings.qqbar import qq_generator
sage: gen = qq_generator
sage: for r in rts:
....: r.exactify()
....: gen = gen.union(r._exact_field())
....:
sage: gen
Number Field in a with defining polynomial y^4 - 4*y^2 + 1 with a in
[0.51763809020504147 .. 0.51763809020504159]
sage: gen._field
Number Field in a with defining polynomial y^4 - 4*y^2 + 1
sage: [gen(r._exact_value()) for r in rts]
[a^2 - 2, a^3 - 3*a, -a^3 + 3*a, -a^2 + 2]

Carl

John Cremona

unread,
Feb 17, 2008, 1:18:54 PM2/17/08
to sage-...@googlegroups.com
Thanks, Carl -- I had been thinking that in Magma I would have done
just this using its AlgebraicallyClosedField, but did not realise that
we had this in Sage too. Now I'll go and look at what it has....

OK, so the first thing I tried (sorry) caused a crash. I'll file a
ticket for this: #2194

John


--
John Cremona

Carl Witty

unread,
Feb 17, 2008, 2:16:45 PM2/17/08
to sage-devel
On Feb 17, 10:18 am, "John Cremona" <john.crem...@gmail.com> wrote:
> Thanks, Carl -- I had been thinking that in Magma I would have done
> just this using its AlgebraicallyClosedField, but did not realise that
> we had this in Sage too. Now I'll go and look at what it has....
>
> OK, so the first thing I tried (sorry) caused a crash. I'll file a
> ticket for this: #2194
>
> John

Thanks for the report. I've attached a patch for this problem to the
ticket.

Carl

John Cremona

unread,
Feb 17, 2008, 3:10:49 PM2/17/08
to sage-...@googlegroups.com
...and I have given it a positive review. If only life were always
this easy. Thanks!

John

On 17/02/2008, Carl Witty <cwi...@newtonlabs.com> wrote:
>


--
John Cremona

Jason Grout

unread,
Feb 19, 2008, 10:53:17 PM2/19/08
to sage-...@googlegroups.com
John Cremona wrote:
> I agree that this would be a useful funtion to have. I would call it
> splitting_field() with a description similar to that of root_field()
> -- whose docstring does not say that self should be irreducible,
> though in fact it must.


I've created tickets #2217, #2219, and #2220 from the things you
mentioned in this message. I think I covered everything you mentioned
and I think that I didn't duplicate things. Feel free to change the
tickets if I didn't do something right.

Thanks for all your help!

Jason

John Cremona

unread,
Feb 20, 2008, 4:17:24 AM2/20/08
to sage-...@googlegroups.com
Thanks. I added a comment to #2220.

John


--
John Cremona

Jason Grout

unread,
Feb 20, 2008, 9:43:16 AM2/20/08
to sage-...@googlegroups.com
John Cremona wrote:
> Thanks. I added a comment to #2220.


Thank you very much for the clarification on that ticket!

Jason

Reply all
Reply to author
Forward
0 new messages