### Navigation

- index
- modules |
- next |
- previous |
- Polynomial Rings »
- Univariate Polynomials and Polynomial Rings »

# Univariate polynomials over number fields.

Univariate polynomials over number fields.

AUTHOR:

- Luis Felipe Tabera Alonso (2014-02): initial version.

EXAMPLES:

Define a polynomial over an absolute number field and perform basic operations with them:

    sage: N.<a> = NumberField(x^2-2)
    sage: K.<x> = N[]
    sage: f = x - a
    sage: g = x^3 - 2*a + 1
    sage: f*(x + a)
    x^2 - 2
    sage: f + g
    x^3 + x - 3*a + 1
    sage: g // f
    x^2 + a*x + 2
    sage: g % f
    1
    sage: factor(x^3 - 2*a*x^2 - 2*x + 4*a)
    (x - 2*a) * (x - a) * (x + a)
    sage: gcd(f, x - a)
    x - a

Polynomials are aware of embeddings of the underlying field:

    sage: x = var('x')
    sage: Q7 = Qp(7)
    sage: r1 = Q7(3 + 7 + 2*7^2 + 6*7^3 + 7^4 + 2*7^5 + 7^6 + 2*7^7 + 4*7^8 +\
             6*7^9 + 6*7^10 + 2*7^11 + 7^12 + 7^13 + 2*7^15 + 7^16 + 7^17 +\
             4*7^18 + 6*7^19)
    sage: N.<b> = NumberField(x^2-2, embedding = r1)
    sage: K.<t> = N[]
    sage: f = t^3-2*t+1
    sage: f(r1)
    1 + O(7^20)

We can also construct polynomials over relative number fields:

    sage: N.<i, s2> = QQ[I, sqrt(2)]
    sage: K.<x> = N[]
    sage: f = x - s2
    sage: g = x^3 - 2*i*x^2 + s2*x
    sage: f*(x + s2)
    x^2 - 2
    sage: f + g
    x^3 - 2*I*x^2 + (sqrt2 + 1)*x - sqrt2
    sage: g // f
    x^2 + (-2*I + sqrt2)*x - 2*sqrt2*I + sqrt2 + 2
    sage: g % f
    -4*I + 2*sqrt2 + 2
    sage: factor(i*x^4 - 2*i*x^2 + 9*i)
    (I) * (x - I + sqrt2) * (x + I - sqrt2) * (x - I - sqrt2) * (x + I + sqrt2)
    sage: gcd(f, x-i)
    1

class `sage.rings.polynomial.polynomial_number_field.``Polynomial_absolute_number_field_dense`(parent, x=None, check=True, is_gen=False, construct=False)

  Bases: `sage.rings.polynomial.polynomial_element_generic.Polynomial_generic_dense_field`

  Class of dense univariate polynomials over an absolute number field.

  `gcd`(other)

    Compute the monic gcd of two univariate polynomials using PARI.

    INPUT:

    - `other` – a polynomial with the same parent as `self`.

    OUTPUT:

    - The monic gcd of `self` and `other`.

    EXAMPLES:

        sage: N.<a> = NumberField(x^3-1/2, 'a')
        sage: R.<r> = N['r']
        sage: f = (5/4*a^2 - 2*a + 4)*r^2 + (5*a^2 - 81/5*a - 17/2)*r + 4/5*a^2 + 24*a + 6
        sage: g = (5/4*a^2 - 2*a + 4)*r^2 + (-11*a^2 + 79/5*a - 7/2)*r - 4/5*a^2 - 24*a - 6
        sage: gcd(f, g**2)
        r - 60808/96625*a^2 - 69936/96625*a - 149212/96625
        sage: R = QQ[I]['x']
        sage: f = R.random_element(2)
        sage: g = f + 1
        sage: h = R.random_element(2).monic()
        sage: f *=h
        sage: g *=h
        sage: gcd(f, g) - h
        0
        sage: f.gcd(g) - h
        0

    TESTS:

    Test for degree one extensions:

        sage: x = var('x')
        sage: N = NumberField(x-3, 'a')
        sage: a = N.gen()
        sage: R = N[x]
        sage: f = R.random_element()
        sage: g1 = R.random_element()
        sage: g2 = g1*R.random_element() + 1
        sage: g1 *= f
        sage: g2 *= f
        sage: d = gcd(g1, g2)
        sage: f.monic() - d
        0
        sage: d.parent() is R
        True

    Test for coercion with other rings and force weird variables to test PARI behavior:

        sage: r = var('r')
        sage: N = NumberField(r^2 - 2, 'r')
        sage: a = N.gen()
        sage: R = N['r']
        sage: r = R.gen()
        sage: f = N.random_element(4)*r + 1
        sage: g = ZZ['r']([1, 2, 3, 4, 5, 6, 7]); g
        7*r^6 + 6*r^5 + 5*r^4 + 4*r^3 + 3*r^2 + 2*r + 1
        sage: gcd(f, g) == gcd(g, f)
        True
        sage: h = f.gcd(g); h
        1
        sage: h.parent()
        Univariate Polynomial Ring in r over Number Field in r with defining polynomial r^2 - 2
        sage: gcd([a*r+2, r^2-2])
        r + r

class `sage.rings.polynomial.polynomial_number_field.``Polynomial_relative_number_field_dense`(parent, x=None, check=True, is_gen=False, construct=False)

  Bases: `sage.rings.polynomial.polynomial_element_generic.Polynomial_generic_dense_field`

  Class of dense univariate polynomials over a relative number field.

  `gcd`(other)

    Compute the monic gcd of two polynomials.

    Currently, the method checks corner cases in which one of the polynomials is zero or a constant. Then, computes an absolute extension and performs the computations there.

    INPUT:

    - `other` – a polynomial with the same parent as `self`.

    OUTPUT:

    - The monic gcd of `self` and `other`.

    See `Polynomial_absolute_number_field_dense.gcd()` for more details.

    EXAMPLES:

        sage: N = QQ[sqrt(2), sqrt(3)]
        sage: s2, s3 = N.gens()
        sage: x = polygen(N)
        sage: f = x^4 - 5*x^2 +6
        sage: g = x^3 + (-2*s2 + s3)*x^2 + (-2*s3*s2 + 2)*x + 2*s3
        sage: gcd(f, g)
        x^2 + (-sqrt2 + sqrt3)*x - sqrt3*sqrt2
        sage: f.gcd(g)
        x^2 + (-sqrt2 + sqrt3)*x - sqrt3*sqrt2

    TESTS:

        sage: x = var('x')
        sage: R = NumberField([x^2-2, x^2-3], 'a')[x]
        sage: f = R.random_element()
        sage: g1 = R.random_element()
        sage: g2 = R.random_element()*g1+1
        sage: g1 *= f
        sage: g2 *= f
        sage: f.monic() - g1.gcd(g2)
        0

    Test for degree one extensions:

        sage: R = NumberField([x-2,x+1,x-3],'a')[x]
        sage: f = R.random_element(2)
        sage: g1 = R.random_element(2)
        sage: g2 = R.random_element(2)*g1+1
        sage: g1 *= f
        sage: g2 *= f
        sage: d = gcd(g1, g2)
        sage: d - f.monic()
        0
        sage: d.parent() is R
        True

    Test for hardcoded variables:

        sage: R = N['sqrt2sqrt3']
        sage: x = R.gen()
        sage: f = x^2 - 2
        sage: g1 = x^2 - s3
        sage: g2 = x - s2
        sage: gcd(f, g1)
        1
        sage: gcd(f, g2)
        sqrt2sqrt3 - sqrt2

### Navigation

- index
- modules |
- next |
- previous |
- Polynomial Rings »
- Univariate Polynomials and Polynomial Rings »