_gr – generic rings (unstable interface)

Note

This module provides a preliminary experimental interface for FLINT’s generic rings. This is largely untested and the interface should be considered unstable. In future the generic rings code will be integrated with the rest of python-flint and this module may be removed. For now it provides access to many FLINT types that are not wrapped yet in the rest of python-flint.

The generic rings module provides access to the generic rings interface in FLINT. Usage of this interface consists of creating a context object to represent a particular domain and then using that context object to create elements of that domain. For example to create a context for polynomials in two variables over the Gaussian integers \(\mathbb{Z}[i][x,y]\) we would do:

>>> from flint.types._gr import gr_fmpzi_ctx, gr_gr_mpoly_ctx
>>> ctx = gr_gr_mpoly_ctx.new(gr_fmpzi_ctx, ["x", "y"])
>>> ctx.gens()
[x, y]

# XXX: gens_recursive not available in FLINT < 3.1
# >>> ctx.gens_recursive()
# [I, x, y]
# >>> I, x, y = ctx.gens_recursive()

>>> x, y = ctx.gens()
>>> p = (x + y)**2
>>> p
x^2 + 2*x*y + y^2

Some domains such as gr_fmpzi_ctx are global and do not need to be created. Others such as gr_gr_mpoly_ctx are created using gr_ctx.new().

class flint.types._gr.gr_ctx(*args, **kwargs)

Base class for all gr contexts.

This class should not be instantiated directly. Instead, use one of the derived classes, e.g. gr_nmod_ctx or gr_fmpz_ctx.

abs(self, x) gr
abs_ge(self, x, y) bool | None
abs_gt(self, x, y) bool | None
abs_le(self, x, y) bool | None
abs_lt(self, x, y) bool | None
add(self, x, y) gr

Returns \(x + y\)

arg(self, x) gr
ceil(self, x) gr
cmp(self, x, y) int

Returns: - -1 if x < y - 0 if x = y - 1 if x > y

cmpabs(self, x, y) int

Returns: - -1 if \(|x| < |y|\) - 0 if \(|x| = |y|\) - 1 if \(|x| > |y|\)

conj(self, x) gr
csgn(self, x) gr
denominator(self, x) gr

Return a denominator q such that x = p / q. For typical fraction fields, the denominator will be minimal and canonical. However, some rings may return an arbitrary denominator as long as the numerator matches. The default implementations simply returns q = 1.

div(self, x, y) gr

Returns the quotient \(x/y\)

div_nonunique(self, x, y) gr

Returns an arbitrary solution \(q\) of the equation \(x = qy\).

divexact(self, x, y) gr

Returns the quotient \(x/y\), assuming that the quotient is exact in the current context.

divide(self, x, y) gr
divides(self, d, x) bool | None

Returns whether \(d | x\); that is, whether there is an element \(q\) such that \(x = qd\).

equal(self, x, y) bool | None

Returns whether the elements \(x\) and \(y\) are equal.

euclidean_div(self, x, y) gr
euclidean_divrem(self, x, y) tuple[gr, gr]
euclidean_rem(self, x, y) gr
factor(self, x) tuple[gr, list[tuple[gr, int]]]
Given an element of the context, this returns a factorization (c, f, e):

x = c f₁^e₁ ··· fₙ^eₙ, where fₖ will be irreducible or prime depending on the ring.

The prefactor c stores a unit, sign or coefficient. Note that c is an element of the same ring as x.

floor(self, x) gr
gcd(self, x, y) gr

Returns a greatest common divisor (GCD) of \(x\) and \(y\). Since the GCD is unique only up to multiplication by a unit, an implementation-defined representative is chosen.

ge(self, x, y) bool | None
gen(self) gr

Return the generator of the domain (if available).

>>> from flint.types._gr import gr_fmpzi_ctx, gr_fq_ctx
>>> ctx = gr_fmpzi_ctx
>>> ctx.gen()
I
>>> ctx = gr_fq_ctx.new(5, 2)
>>> ctx.gen()
a
gens(self) list[gr]

Return the top-level generators of the domain

# XXX: Does not work with FLINT < 3.1

# >>> from flint.types._gr import gr_fmpzi_ctx, gr_gr_mpoly_ctx # >>> ctx = gr_gr_mpoly_ctx.new(gr_fmpzi_ctx, [‘x’, ‘y’]) # >>> ctx.gens() # [x, y] # >>> gr_fmpzi_ctx.gens() # [I] # >>> ctx.gens_recursive() # [I, x, y]

greater(self, x, y)
greater_equal(self, x, y)
gt(self, x, y) bool | None
has_real_prec

gr_ctx.has_real_prec: bool | None

True if the domain has real precision (can be None if unknown).

See also real_prec.

i(self) gr

Return the imaginary unit of the domain (if available).

>>> from flint.types._gr import gr_fmpzi_ctx
>>> ctx = gr_fmpzi_ctx
>>> ctx.i()
I
im(self, x) gr
imag(self, x)
inv(self, x) gr

Returns the multiplicative inverse of \(x\) in the present ring, if such an element exists.

is_algebraically_closed

gr_ctx.is_algebraically_closed: bool | None

True if the domain is algebraically closed (can be None if unknown).

>>> from flint.types._gr import gr_complex_qqbar_ctx, gr_real_qqbar_ctx
>>> R1 = gr_complex_qqbar_ctx.new()
>>> R2 = gr_real_qqbar_ctx.new()
>>> R1.is_algebraically_closed, R2.is_algebraically_closed
(True, False)
is_canonical

gr_ctx.is_canonical: bool | None

True if elements of the domain are always canonical.

is_commutative_ring

gr_ctx.is_commutative_ring: bool | None

True if the domain is a commutative ring (can be None if unknown).

is_exact

gr_ctx.is_exact: bool | None

True if the domain is exact (can be None if unknown).

>>> from flint.types._gr import gr_fmpz_ctx, gr_real_float_arf_ctx
>>> R1 = gr_fmpz_ctx
>>> R2 = gr_real_float_arf_ctx.new(10)
>>> R1.is_exact, R2.is_exact
(True, False)
is_field

gr_ctx.is_field: bool | None

True if the domain is a field (can be None if unknown).

>>> from flint.types._gr import gr_fmpz_ctx, gr_fmpq_ctx
>>> R1 = gr_fmpz_ctx
>>> R2 = gr_fmpq_ctx
>>> R1.is_field, R2.is_field
(False, True)
is_finite

gr_ctx.is_finite: bool | None

True if the domain is finite (can be None if unknown).

>>> from flint.types._gr import gr_fmpz_ctx, gr_nmod_ctx
>>> R1 = gr_fmpz_ctx
>>> R2 = gr_nmod_ctx.new(5)
>>> R1.is_finite, R2.is_finite
(False, True)
is_finite_characteristic

gr_ctx.is_finite_characteristic: bool | None

True if the domain has finite characteristic (can be None if unknown).

>>> from flint.types._gr import gr_nmod_ctx, gr_fmpz_ctx
>>> R1 = gr_nmod_ctx.new(5)
>>> R2 = gr_fmpz_ctx
>>> R1.is_finite_characteristic, R2.is_finite_characteristic
(True, False)
is_integral_domain

gr_ctx.is_integral_domain: bool | None

True if the domain is an integral domain (can be None if unknown).

>>> from flint.types._gr import gr_nmod_ctx
>>> R1 = gr_nmod_ctx.new(5)
>>> R2 = gr_nmod_ctx.new(6)
>>> R1.is_integral_domain, R2.is_integral_domain
(True, False)
is_invertible(self, x) bool | None

Returns whether \(x\) has a multiplicative inverse in the present ring, i.e. whether \(x\) is a unit.

is_multiplicative_group

gr_ctx.is_multiplicative_group: bool | None

True if the domain is a multiplicative group (can be None if unknown).

is_neg_one(self, x) bool | None

Returns whether x is equal to the ring element -1.

>>> from flint.types._gr import gr_real_arb_ctx
>>> ctx = gr_real_arb_ctx.new(10)
>>> ctx.is_neg_one(ctx(1))
False
>>> ctx.is_neg_one(ctx(-1))
True
>>> ctx.is_neg_one(ctx("[-1 +/- 0.1]"))
is_one(self, x) bool | None

Returns whether x is equal to the ring element 1.

>>> from flint.types._gr import gr_real_arb_ctx
>>> ctx = gr_real_arb_ctx.new(10)
>>> ctx.is_one(ctx(0))
False
>>> ctx.is_one(ctx(1))
True
>>> ctx.is_one(ctx("[1 +/- 0.1]"))
is_ordered_ring

gr_ctx.is_ordered_ring: bool | None

True if the domain is an ordered ring (can be None if unknown).

>>> from flint.types._gr import gr_fmpz_ctx, gr_nmod_ctx
>>> R1 = gr_fmpz_ctx
>>> R2 = gr_nmod_ctx.new(5)
>>> R1.is_ordered_ring, R2.is_ordered_ring
(True, None)
is_ring

gr_ctx.is_ring: bool | None

True if the domain is a ring (can be None if unknown).

is_square(self, x) bool | None

Returns whether x is a perfect square in the context.

is_unique_factorization_domain

gr_ctx.is_unique_factorization_domain: bool | None

True if the domain is a unique factorization domain (can be None if unknown).

>>> from flint.types._gr import gr_fmpz_ctx
>>> R1 = gr_fmpz_ctx
>>> R1.is_unique_factorization_domain
True
is_zero(self, x) bool | None

Returns whether x is equal to the ring element 0.

>>> from flint.types._gr import gr_real_arb_ctx
>>> ctx = gr_real_arb_ctx.new(10)
>>> ctx.is_zero(ctx(0))
True
>>> ctx.is_zero(ctx(1))
False
>>> ctx.is_zero(ctx("[0 +/- 0.1]"))
lcm(self, x, y) gr

Returns a least common multiple (LCM) of x and y. Since the LCM is unique only up to multiplication by a unit, an implementation-defined representative is chosen.

le(self, x, y) bool | None
less(self, x, y)
less_equal(self, x, y)
lt(self, x, y) bool | None
max(self, x, y) gr
maximum(self, x, y)
min(self, x, y) gr
minimum(self, x, y)
mul(self, x, y) gr
multiply(self, x, y)
neg(self, x) gr

Returns \(-x\).

>>> from flint.types._gr import gr_complex_acb_ctx, gr_real_arb_ctx
>>> arb = gr_real_arb_ctx.new(53); acb = gr_complex_acb_ctx.new(106)
>>> c = acb("2 + I").sqrt(); c
([1.4553466902253548081226618397097 +/- 3.48e-32] + [0.3435607497225124641385657439146 +/- 5.23e-32]*I)
>>> acb.neg(c)
([-1.4553466902253548081226618397097 +/- 3.48e-32] + [-0.3435607497225124641385657439146 +/- 5.23e-32]*I)
neg_inf(self) gr

Return the negative infinity element of the domain (if available).

>>> from flint.types._gr import gr_real_float_arf_ctx
>>> ctx = gr_real_float_arf_ctx.new(10)
>>> ctx.neg_inf()
-inf
negative(self, x)
new(self)

Create a context of a given type.

This method should be called on a derived class:

>>> from flint.types._gr import gr_real_float_arf_ctx
>>> ctx10 = gr_real_float_arf_ctx.new(10)
>>> ctx10
gr_real_float_arf_ctx(10)
>>> ctx10.real_prec
10
>>> ctx10(2).sqrt()  # 10 bits
1.414
>>> ctx100 = gr_real_float_arf_ctx.new(100)
>>> ctx100(2).sqrt()  # 100 bits
1.414213562373095048801688724209
nint(self, x) gr
not_equal(self, x, y)
numerator(self, x) gr

Return a numerator p such that x = p / q. For typical fraction fields, the denominator will be minimal and canonical. However, some rings may return an arbitrary denominator as long as the numerator matches. The default implementations simply returns p = x.

one(self) gr

Return the one element of the domain.

>>> from flint.types._gr import gr_fmpz_ctx
>>> ctx = gr_fmpz_ctx
>>> ctx.one()
1
pos_inf(self) gr

Return the positive infinity element of the domain (if available).

>>> from flint.types._gr import gr_real_float_arf_ctx
>>> ctx = gr_real_float_arf_ctx.new(10)
>>> ctx.pos_inf()
+inf
pow(self, x, y) gr

Returns the power x^y, the interpretation of which depends on the ring when y ∉ ℤ

re(self, x) gr
real(self, x)
real_prec

gr_ctx.real_prec: int

Real precision of the domain.

>>> from flint.types._gr import gr_real_float_arf_ctx
>>> ctx = gr_real_float_arf_ctx.new(10)
>>> ctx.real_prec
10
>>> ctx.real_prec = 20
>>> ctx.real_prec
20
rsqrt(self, x) gr

Returns the reciprocal square root of \(x\).

sgn(self, x) gr
sqrt(self, x) gr

Returns the square root of \(x\).

sub(self, x, y) gr
trunc(self, x) gr
uinf(self) gr

Return the unsigned infinity element of the domain (if available).

>>> from flint.types._gr import gr_complex_extended_ca_ctx
>>> ctx = gr_complex_extended_ca_ctx.new()
>>> ctx.uinf()
UnsignedInfinity
undefined(self) gr

Return the undefined element of the domain (if available).

>>> from flint.types._gr import gr_real_float_arf_ctx
>>> ctx = gr_real_float_arf_ctx.new(10)
>>> ctx.undefined()
nan
unknown(self) gr

Return the unknown element of the domain (if available).

>>> from flint.types._gr import gr_real_float_arf_ctx
>>> ctx = gr_real_float_arf_ctx.new(10)
>>> ctx.unknown()
nan
zero(self) gr

Return the zero element of the domain.

>>> from flint.types._gr import gr_fmpz_ctx
>>> ctx = gr_fmpz_ctx
>>> ctx.zero()
0
class flint.types._gr.gr_scalar_ctx

Base class for all scalar contexts.

class flint.types._gr.gr_poly_ctx

Base class for dense univariate polynomial contexts.

class flint.types._gr.gr_mpoly_ctx

Base class for dense multivariate polynomial contexts.

class flint.types._gr._gr_fmpz_ctx

Context for arbitrary precision integers, \(\mathbb{Z}\).

static new() _gr_fmpz_ctx

The global context for arbitrary precision integers.

>>> from flint.types._gr import gr_fmpz_ctx as Z
>>> Z
gr_fmpz_ctx
>>> Z(10)
10
>>> Z(10) + Z(20)
30
>>> Z(10) * Z(20)
200
>>> Z(10) / Z(20)
Traceback (most recent call last):
    ...
AssertionError: Failed to divide gr objects
>>> Z(10).factor()
(1, [(2, 1), (5, 1)])
>>> Z(9).sqrt()
3
class flint.types._gr._gr_fmpq_ctx

Context for arbitrary precision rationals, \(\mathbb{Q}\).

static new() _gr_fmpq_ctx

The global context for arbitrary precision rationals.

>>> from flint.types._gr import gr_fmpq_ctx as Q
>>> Q
gr_fmpq_ctx
>>> Q(2) / 3
2/3
class flint.types._gr._gr_fmpzi_ctx

Context for Gaussian integers, \(\mathbb{Z}[i]\).

static new() _gr_fmpzi_ctx

The global context for Gaussian integers.

>>> from flint.types._gr import gr_fmpzi_ctx as ZI
>>> ZI
gr_fmpzi_ctx
>>> ZI.i()
I
>>> ZI.gen()
I
>>> I = ZI.i()
>>> (2 + 3*I) ** 2
(-5+12*I)
class flint.types._gr._gr_fexpr_ctx

Context for symbolic expressions.

static new() _gr_fexpr_ctx

The global context for symbolic expressions.

>>> from flint.types._gr import gr_fexpr_ctx as EX
>>> EX
gr_fexpr_ctx
>>> (EX(1) + EX(2)) / 3
Div(Add(1, 2), 3)
class flint.types._gr.gr_nmod_ctx

Context for integers modulo \(n\), \(\mathbb{Z}/n\mathbb{Z}\).

The modulus \(n\) must be word-sized. Use gr_fmpz_mod_ctx for arbitrary precision modulus.

is_prime

gr_nmod_ctx.is_prime: bool

modulus(self)
static new(ulong n) gr_nmod_ctx

Create a new context for integers modulo \(n\).

>>> from flint.types._gr import gr_nmod_ctx
>>> Z5 = gr_nmod_ctx.new(5)
>>> Z5
gr_nmod_ctx(5)
>>> Z5(2) + Z5(3)
0
>>> Z5.modulus()
5
>>> Z5.is_prime
True
class flint.types._gr.gr_fmpz_mod_ctx

Context for integers modulo \(n\), \(\mathbb{Z}/n\mathbb{Z}\).

The modulus \(n\) can be arbitrary precision. See also gr_nmod_ctx for word-sized modulus.

is_prime

gr_fmpz_mod_ctx.is_prime: bool

modulus(self)
static new(n) gr_fmpz_mod_ctx

Create a new context for integers modulo \(n\).

>>> from flint.types._gr import gr_fmpz_mod_ctx
>>> Z64 = gr_fmpz_mod_ctx.new(2**64 + 1)
>>> Z64
gr_fmpz_mod_ctx(18446744073709551617)
>>> Z64(2)**64 + 2
1
>>> Z64.is_prime
False
>>> Z64.modulus()
18446744073709551617
class flint.types._gr.gr_fq_ctx

Context for finite fields, \(\mathbb{F}_q\) where \(q = p^d\).

The characteristic \(p\) must be a prime number and the degree \(d\) must be positive. The characteristic \(p\) can be arbitrary precision. Use gr_fq_nmod_ctx for word-sized characteristic. For very small characteristic, use gr_fq_zech_ctx.

characteristic(self)
degree(self)
static new(p, d, name=None) gr_fq_ctx

Create a new context for finite fields.

>>> from flint.types._gr import gr_fq_ctx
>>> F9 = gr_fq_ctx.new(3, 2)
>>> F9
gr_fq_ctx(3, 2)
>>> F9(2) + F9(3)
2
>>> F9.characteristic()
3
>>> F9.degree()
2
>>> F9.gen()
a
>>> a = F9.gen()
>>> (1 + a) ** 2 + a
a+2
class flint.types._gr.gr_fq_nmod_ctx

Context for finite fields, \(\mathbb{F}_q\) where \(q = p^d\).

The characteristic \(p\) must be a prime number and the degree \(d\) must be positive. The characteristic \(p\) must be word-sized. Use gr_fq_ctx for arbitrary precision characteristic. For very small characteristic, use gr_fq_zech_ctx.

characteristic(self)
degree(self)
static new(p, d, name=None) gr_fq_nmod_ctx

Create a new context for finite fields.

# XXX: Does not work with FLINT < 3.1 # >>> from flint.types._gr import gr_fq_nmod_ctx # >>> F9 = gr_fq_nmod_ctx.new(3, 2) # >>> F9 # gr_fq_nmod_ctx(3, 2) # >>> F9(2) + F9(3) # 2 # >>> F9.characteristic() # 3 # >>> F9.degree() # 2 # >>> F9.gen() # a # >>> a = F9.gen() # >>> (1 + a) ** 2 + a # a+2

class flint.types._gr.gr_fq_zech_ctx

Context for finite fields, \(\mathbb{F}_q\) where \(q = p^d\).

The characteristic \(p\) must be a prime number and the degree \(d\) must be positive. The characteristic \(p\) must be small. Use gr_nmod_ctx for word-sized characteristic and gr_fq_ctx for arbitrary precision characteristic.

Warning

This type is possibly not working correctly. Use with caution.

characteristic(self)
degree(self)
static new(p, d, name=None) gr_fq_zech_ctx

Create a new context for finite fields with small characteristic.

# XXX: Does not work with FLINT < 3.1 # >>> from flint.types._gr import gr_fq_zech_ctx # >>> F9 = gr_fq_zech_ctx.new(3, 2) # >>> F9 # gr_fq_zech_ctx(3, 2) # >>> F9(2) + F9(3) # XXX: Is this correct? # a^4 # >>> F9.characteristic() # 3 # >>> F9.degree() # 2 # >>> F9.gen() # a^1 # >>> a = F9.gen() # >>> (1 + a) ** 2 + a # doctest: +SKIP # a+2

class flint.types._gr.gr_nf_ctx

Context for number fields, \(\mathbb{Q}(\alpha)\).

The number field is defined by a minimal polynomial \(f(x)\) in \(\mathbb{Q}[x]\) and represents the field \(\mathbb{Q}(\alpha)\) where \(\alpha\) is a root of \(f(x)\). The minimal polynomial \(f(x)\) must be irreducible.

modulus(self)
static new(poly) gr_nf_ctx

Create a new context for number fields.

>>> from flint.types._gr import gr_nf_ctx
>>> Qa = gr_nf_ctx.new([-2, 0, 1])
>>> Qa
gr_nf_ctx(x^2 + (-2))
>>> Qa.modulus()
x^2 + (-2)
>>> a = Qa.gen()
>>> a
a
>>> a**2
2
>>> (1 + a) ** 2
2*a+3
>>> (1 + a) / 2
1/2*a+1/2
class flint.types._gr.gr_nf_fmpz_poly_ctx

Context for number fields, \(\mathbb{Q}(\alpha)\).

The number field is defined by a minimal polynomial \(f(x)\) in \(\mathbb{Z}[x]\) and represents the ring \(\mathbb{Z}[\alpha]\) where \(\alpha\) is a root of \(f(x)\). The minimal polynomial \(f(x)\) must be irreducible.

modulus(self)
static new(poly) gr_nf_fmpz_poly_ctx

Create a new context for number fields.

>>> from flint.types._gr import gr_nf_fmpz_poly_ctx
>>> Qa = gr_nf_fmpz_poly_ctx.new([-2, 0, 1])
>>> Qa
gr_nf_fmpz_poly_ctx(x^2 + (-2))
>>> Qa.modulus()
x^2 + (-2)
>>> a = Qa.gen()
>>> a
a
>>> a**2
2
>>> (1 + a) ** 2
2*a+3
class flint.types._gr.gr_real_qqbar_ctx

Context for real algebraic numbers, \(\mathbb{R} \cap \overline{\mathbb{Q}}\).

The real algebraic numbers are a subset of the real numbers that are roots of non-zero polynomials with integer coefficients. See gr_complex_qqbar_ctx for the full algebraic closure of the rationals. See gr_nf_ctx for number fields with a single generator.

limits(self)
static new(deg_limit=-1, bits_limit=-1) gr_real_qqbar_ctx

Create a new context for real algebraic numbers.

>>> from flint.types._gr import gr_real_qqbar_ctx
>>> R = gr_real_qqbar_ctx.new()
>>> R
gr_real_qqbar_ctx(-1, -1)
>>> R(2).sqrt()
Root a = 1.41421 of a^2-2
class flint.types._gr.gr_complex_qqbar_ctx

Context for algebraic numbers, \(\overline{\mathbb{Q}}\).

The algebraic numbers are a field that contains the rationals and all roots of non-zero polynomials with integer coefficients. See gr_real_qqbar_ctx for the real algebraic numbers, gr_nf_ctx for number fields with a single generator.

limits(self)
static new(deg_limit=-1, bits_limit=-1) gr_complex_qqbar_ctx

Create a new context for algebraic numbers.

>>> from flint.types._gr import gr_complex_qqbar_ctx
>>> C = gr_complex_qqbar_ctx.new()
>>> C
gr_complex_qqbar_ctx(-1, -1)
>>> C(-2).sqrt()
Root a = 1.41421*I of a^2+2
class flint.types._gr.gr_real_ca_ctx

Context for calcium exact real numbers, \(\mathbb{R}\).

static new(**options) gr_real_ca_ctx

Create a new context for calcium exact real numbers.

>>> from flint.types._gr import gr_real_ca_ctx
>>> R = gr_real_ca_ctx.new()
>>> R
gr_real_ca_ctx({})
>>> R(2).sqrt()
1.41421 {a where a = 1.41421 [a^2-2=0]}
class flint.types._gr.gr_complex_ca_ctx

Context for calcium exact complex numbers, \(\mathbb{C}\).

static new(**options) gr_complex_ca_ctx

Create a new context for calcium exact complex numbers.

>>> from flint.types._gr import gr_complex_ca_ctx
>>> C = gr_complex_ca_ctx.new()
>>> C
gr_complex_ca_ctx({})
>>> C(2).sqrt()
1.41421 {a where a = 1.41421 [a^2-2=0]}
class flint.types._gr.gr_real_algebraic_ca_ctx

Context for calcium exact real algebraic numbers, \(\mathbb{R} \cap \overline{\mathbb{Q}}\).

static new(**options) gr_real_algebraic_ca_ctx

Create a new context for calcium exact real algebraic numbers.

>>> from flint.types._gr import gr_real_algebraic_ca_ctx
>>> R = gr_real_algebraic_ca_ctx.new()
>>> R
gr_real_algebraic_ca_ctx({})
>>> R(2).sqrt()
1.41421 {a where a = 1.41421 [a^2-2=0]}
class flint.types._gr.gr_complex_algebraic_ca_ctx

Context for calcium exact complex algebraic numbers, \(\overline{\mathbb{Q}}\).

static new(**options) gr_complex_algebraic_ca_ctx

Create a new context for calcium exact complex algebraic numbers.

>>> from flint.types._gr import gr_complex_algebraic_ca_ctx
>>> C = gr_complex_algebraic_ca_ctx.new()
>>> C
gr_complex_algebraic_ca_ctx({})
>>> C(2).sqrt()
1.41421 {a where a = 1.41421 [a^2-2=0]}
class flint.types._gr.gr_complex_extended_ca_ctx

Context for calcium exact extended complex numbers, \(\mathbb{C} \cup \{\infty\}\).

static new(**options) gr_complex_extended_ca_ctx

Create a new context for calcium exact extended complex numbers.

>>> from flint.types._gr import gr_complex_extended_ca_ctx
>>> C = gr_complex_extended_ca_ctx.new()
>>> C
gr_complex_extended_ca_ctx({})
>>> C(1) / 0
UnsignedInfinity
class flint.types._gr.gr_real_float_arf_ctx

Context for arbitrary precision approximate real numbers, \(\mathbb{R}\).

static new(prec) gr_real_float_arf_ctx

Create a new context for arbitrary precision approximate real numbers.

>>> from flint.types._gr import gr_real_float_arf_ctx
>>> R = gr_real_float_arf_ctx.new(10)
>>> R
gr_real_float_arf_ctx(10)
>>> R(2).sqrt()
1.414
>>> R.real_prec = 20
>>> R(2).sqrt()
1.414213
class flint.types._gr.gr_complex_float_acf_ctx

Context for arbitrary precision approximate complex numbers, \(\mathbb{C}\).

static new(prec) gr_complex_float_acf_ctx

Create a new context for arbitrary precision approximate complex numbers.

>>> from flint.types._gr import gr_complex_float_acf_ctx
>>> C = gr_complex_float_acf_ctx.new(10)
>>> C
gr_complex_float_acf_ctx(10)
>>> C(-2).sqrt()
1.414*I
>>> C.real_prec = 20
>>> C(-2).sqrt()
1.414213*I
class flint.types._gr.gr_real_arb_ctx

Context for Arb arbitrary precision real ball arithmetic, \(\mathbb{R}\).

static new(prec) gr_real_arb_ctx

Create a new context for arbitrary precision real ball arithmetic.

>>> from flint.types._gr import gr_real_arb_ctx
>>> R = gr_real_arb_ctx.new(10)
>>> R
gr_real_arb_ctx(10)
>>> R(2).sqrt()
[1.41 +/- 6.02e-3]
>>> R.real_prec = 20
>>> R(2).sqrt()
[1.41421 +/- 5.09e-6]
class flint.types._gr.gr_complex_acb_ctx

Context for Arb arbitrary precision complex ball arithmetic, \(\mathbb{C}\).

static new(prec) gr_complex_acb_ctx

Create a new context for arbitrary precision complex ball arithmetic.

>>> from flint.types._gr import gr_complex_acb_ctx
>>> C = gr_complex_acb_ctx.new(10)
>>> C
gr_complex_acb_ctx(10)
>>> C(-2).sqrt()
[1.41 +/- 6.02e-3]*I
>>> C.real_prec = 20
>>> C(-2).sqrt()
[1.41421 +/- 5.09e-6]*I
class flint.types._gr.gr_gr_poly_ctx

Context for dense univariate polynomial rings, \(\mathbb{D}[x]\).

base_ring
static new(base_ring) gr_gr_poly_ctx

Create a new context for dense univariate polynomial rings.

>>> from flint.types._gr import gr_fmpz_ctx, gr_gr_poly_ctx
>>> Z = gr_fmpz_ctx
>>> R = gr_gr_poly_ctx.new(Z)
>>> R
gr_gr_poly_ctx(gr_fmpz_ctx)
>>> R.base_ring
gr_fmpz_ctx
>>> R.gen()
x
>>> x = R.gen()
>>> (1 + x) ** 2
1 + 2*x + x^2
class flint.types._gr.gr_gr_mpoly_ctx

Context for dense multivariate polynomial rings, \(\mathbb{D}[x, y, ...]\).

base_ring
names
static new(base_ring, names, order=None) gr_gr_mpoly_ctx

Create a new context for dense multivariate polynomial rings.

# >>> from flint.types._gr import gr_fmpzi_ctx, gr_gr_mpoly_ctx # >>> ZI = gr_fmpzi_ctx # >>> R = gr_gr_mpoly_ctx.new(ZI, [‘x’, ‘y’]) # >>> R # gr_gr_mpoly_ctx(gr_fmpzi_ctx, (‘x’, ‘y’), Ordering.lex) # >>> R.base_ring # gr_fmpzi_ctx # >>> R.names # (‘x’, ‘y’) # >>> R.nvars # 2 # >>> R.order # <Ordering.lex: ‘lex’> # >>> R.gens() # [x, y] # >>> I, [x, y] = ZI.gen(), R.gens() # >>> (I + x + y) ** 2 # x^2 + 2*x*y + (2*I)*x + y^2 + (2*I)*y - 1

nvars
order
class flint.types._gr.gr_series_ctx

Context for series with precision \(n\), \(\mathbb{D}[[x]]\).

base_ring
static new(base_ring, prec) gr_series_ctx

Create a new context for series with precision \(n\).

>>> from flint.types._gr import gr_fmpz_ctx, gr_series_ctx
>>> Z = gr_fmpz_ctx
>>> R = gr_series_ctx.new(Z, 10)
>>> R
gr_series_ctx(gr_fmpz_ctx, 10)
>>> R.base_ring
gr_fmpz_ctx
>>> R.prec
10
>>> x = R.gen()
>>> 1 / (1 - x)
1 + x + x^2 + x^3 + x^4 + x^5 + x^6 + x^7 + x^8 + x^9 + O(x^10)
prec
class flint.types._gr.gr

Type of elements of gr_ctx domains.

arg(self) gr

Return the argument of the element.

>>> from flint.types._gr import gr_complex_acb_ctx
>>> C = gr_complex_acb_ctx.new(10)
>>> (1 + C.i()).arg()
[0.785 +/- 6.45e-4]
conjugate(self) gr

Return complex conjugate of the element.

>>> from flint.types._gr import gr_fmpzi_ctx as ZI
>>> I = ZI.gen()
>>> (1 + I).conjugate()
(1-I)
csgn(self) gr

Return the complex sign of the element.

>>> from flint.types._gr import gr_complex_acb_ctx
>>> C = gr_complex_acb_ctx.new(10)
>>> (1 + C.i()).csgn()
1
ctx

ctx: flint.types._gr.gr_ctx

denom(self) gr

Return the denominator of the element.

>>> from flint.types._gr import gr_fmpq_ctx as Q
>>> q = Q(2) / 3
>>> q
2/3
>>> q.denom()
3

See also numer().

factor(self)

Return the factorization of the element.

>>> from flint.types._gr import gr_fmpz_ctx as Z
>>> Z(12).factor()
(1, [(2, 2), (3, 1)])
gcd(self, other)

Return the greatest common divisor of two elements.

>>> from flint.types._gr import gr_fmpz_ctx as Z
>>> Z(4).gcd(Z(6))
2
imag

gr.imag: gr

Return the imaginary part of the element.

>>> from flint.types._gr import gr_fmpzi_ctx as ZI
>>> I = ZI.gen()
>>> (1 + I).imag
1
is_neg_one(self)

Return whether the element is negative one (may return None).

>>> from flint.types._gr import gr_fmpz_ctx as Z
>>> Z(-1).is_neg_one()
True
is_one(self)

Return whether the element is one (may return None).

>>> from flint.types._gr import gr_fmpz_ctx as Z
>>> Z(1).is_one()
True
is_square(self)

Return whether the element is a square (may return None).

>>> from flint.types._gr import gr_fmpq_ctx as Q
>>> Q(2).is_square()
False
>>> Q(4).is_square()
True
>>> Q(4).sqrt()
2
is_zero(self)

Return whether the element is zero (may return None).

>>> from flint.types._gr import gr_fmpz_ctx as Z
>>> Z(0).is_zero()
True
lcm(self, other)

Return the least common multiple of two elements.

>>> from flint.types._gr import gr_fmpz_ctx as Z
>>> Z(4).lcm(Z(6))
12
numer(self) gr

Return the numerator of the element.

>>> from flint.types._gr import gr_fmpq_ctx as Q
>>> q = Q(2) / 3
>>> q
2/3
>>> q.numer()
2

See also denom().

parent(self) gr_ctx

Return the parent context.

>>> from flint.types._gr import gr_complex_acb_ctx
>>> acb = gr_complex_acb_ctx.new(53)
>>> x = acb("2")
>>> x.parent()
gr_complex_acb_ctx(53)
real

gr.real: gr

Return the real part of the element.

>>> from flint.types._gr import gr_fmpzi_ctx as ZI
>>> I = ZI.gen()
>>> (1 + I).real
1
rsqrt(self)

Return the reciprocal square root of the element if it exists.

>>> from flint.types._gr import gr_fmpq_ctx as Q
>>> Q(4).rsqrt()
1/2
sgn(self) gr

Return the sign of the element.

>>> from flint.types._gr import gr_fmpq_ctx as Q
>>> Q(2).sgn()
1
>>> Q(-2).sgn()
-1
>>> Q(0).sgn()
0
sqrt(self)

Return the square root of the element if it exists.

>>> from flint.types._gr import gr_fmpz_ctx as Z
>>> Z(4).sqrt()
2