Domains

Here we document the various implemented ground domains. There are three types: abstract domains, concrete domains, and “implementation domains”. Abstract domains cannot be (usefully) instantiated at all, and just collect together functionality shared by many other domains. Concrete domains are those meant to be instantiated and used. In some cases, there are various possible ways to implement the data type the domain provides. For example, depending on what libraries are available on the system, the integers are implemented either using the python built-in integers, or using gmpy. Note that various aliases are created automatically depending on the libraries available. As such e.g. ZZ always refers to the most efficient implementation of the integer ring available.

Abstract Domains

class diofant.domains.domain.Domain[source]

Represents an abstract domain.

convert(element, base=None)[source]

Convert element to self.dtype.

convert_from(element, base)[source]

Convert element to self.dtype given the base domain.

frac_field(*symbols, **kwargs)[source]

Return a fraction field, i.e. \(K(X)\).

abstract from_expr(expr)[source]

Convert Diofant’s expression expr to dtype.

get_exact()[source]

Get an associated exact domain.

poly_ring(*symbols, **kwargs)[source]

Return a polynomial ring, i.e. \(K[X]\).

abstract to_expr(element)[source]

Convert domain element to Diofant expression.

unify(K1, symbols=())[source]

Construct a minimal domain that contains elements of self and K1.

Known domains (from smallest to largest):

  • GF(p)

  • ZZ

  • QQ

  • RR(prec, tol)

  • CC(prec, tol)

  • ALG(a, b, c)

  • K[x, y, z]

  • K(x, y, z)

  • EX

class diofant.domains.field.Field[source]

Represents a field domain.

div(a, b)[source]

Division of a and b, implies __truediv__.

exquo(a, b)[source]

Exact quotient of a and b, implies __truediv__.

property field

Return a field associated with self.

gcd(a, b)[source]

Return GCD of a and b.

This definition of GCD over fields allows to clear denominators in \(primitive()\).

>>> QQ.gcd(QQ(2, 3), QQ(4, 9))
2/9
>>> gcd(Rational(2, 3), Rational(4, 9))
2/9
>>> primitive(2*x/3 + Rational(4, 9))
(2/9, 3*x + 2)
quo(a, b)[source]

Quotient of a and b, implies __truediv__.

rem(a, b)[source]

Remainder of a and b, implies nothing.

class diofant.domains.ring.CommutativeRing[source]

Represents a ring domain.

abstract property characteristic

Return the characteristic of this ring.

cofactors(a, b)[source]

Return GCD and cofactors of a and b.

div(a, b)[source]

Division of a and b, implies __divmod__.

exquo(a, b)[source]

Exact quotient of a and b, implies __floordiv__.

half_gcdex(a, b)[source]

Half extended GCD of a and b.

invert(a, b)[source]

Return inversion of a mod b.

is_normal(a)[source]

Return True if a is unit normal.

lcm(a, b)[source]

Return LCM of a and b.

quo(a, b)[source]

Quotient of a and b, implies __floordiv__.

rem(a, b)[source]

Remainder of a and b, implies __mod__.

property ring

Return a ring associated with self.

class diofant.domains.simpledomain.SimpleDomain[source]

Base class for simple domains, e.g. ZZ, QQ.

inject(*gens)[source]

Inject generators into this domain.

class diofant.domains.compositedomain.CompositeDomain[source]

Base class for composite domains, e.g. ZZ[x], ZZ(X).

inject(*symbols, front=False)[source]

Inject generators into this domain.

class diofant.domains.characteristiczero.CharacteristicZero[source]

Domain that has infinite number of elements.

Concrete Domains

class diofant.domains.IntegerModRing(order, dom)[source]

General class for quotient rings over integers.

class diofant.domains.FiniteField(order, dom, modulus=None)[source]

General class for finite fields.

class diofant.domains.IntegerRing[source]

General class for integer rings.

property field

Return a field associated with self.

abstract finite_field(p)[source]

Return a finite field.

abstract finite_ring(n)[source]

Return a finite ring.

class diofant.domains.RationalField[source]

General class for rational fields.

algebraic_field(*extension)[source]

Return an algebraic field, i.e. \(\mathbb{Q}(\alpha, \ldots)\).

class diofant.domains.AlgebraicField(dom, *ext)[source]

A class for representing algebraic number fields.

algebraic_field(*extension)[source]

Return an algebraic field, i.e. \(\mathbb{Q}(\alpha, \ldots)\).

class diofant.domains.RealAlgebraicField(dom, *ext)[source]

A class for representing real algebraic number fields.

class diofant.domains.ComplexAlgebraicField(dom, *ext)[source]

A class for representing complex algebraic number fields.

class diofant.polys.rings.PolynomialRing(domain, symbols, order=<diofant.polys.orderings.LexOrder object>)[source]

Return a multivariate polynomial ring.

drop(*gens)[source]

Remove specified generators from this ring.

eject(*gens)[source]

Remove specified generators from the ring and inject them into its domain.

property field

Returns a field associated with self.

gcdex(a, b)[source]

Extended GCD of a and b.

half_gcdex(a, b)[source]

Half extended GCD of a and b.

index(gen)[source]

Compute index of gen in self.gens.

class diofant.polys.univar.UnivarPolynomialRing(domain, symbols, order=<diofant.polys.orderings.LexOrder object>)[source]

A class for representing univariate polynomial rings.

dispersionset(p, q=None)[source]

Compute the dispersion set of two polynomials.

For two polynomials \(f(x)\) and \(g(x)\) with \(\deg f > 0\) and \(\deg g > 0\) the dispersion set \(\operatorname{J}(f, g)\) is defined as:

\[\begin{split}\operatorname{J}(f, g) & := \{a \in \mathbb{N}_0 | \gcd(f(x), g(x+a)) \neq 1\} \\ & = \{a \in \mathbb{N}_0 | \deg \gcd(f(x), g(x+a)) \geq 1\}\end{split}\]

For a single polynomial one defines \(\operatorname{J}(f) := \operatorname{J}(f, f)\).

Examples

Note that the definition of the dispersion is not symmetric:

>>> R, x = ring('x', QQ)
>>> fp = x**4 - 3*x**2 + 1
>>> gp = fp.shift(-3)
>>> R.dispersionset(fp, gp)
{2, 3, 4}
>>> R.dispersionset(gp, fp)
set()

Computing the dispersion also works over field extensions:

>>> R, x = ring('x', QQ.algebraic_field(sqrt(5)))
>>> fp = x**2 + sqrt(5)*x - 1
>>> gp = x**2 + (2 + sqrt(5))*x + sqrt(5)
>>> R.dispersionset(fp, gp)
{2}
>>> R.dispersionset(gp, fp)
{1, 4}

We can even perform the computations for polynomials having symbolic coefficients:

>>> D, a = ring('a', QQ)
>>> R, x = ring('x', D)
>>> fp = 4*x**4 + (4*a + 8)*x**3 + (a**2 + 6*a + 4)*x**2 + (a**2 + 2*a)*x
>>> R.dispersionset(fp)
{0, 1}

References

class diofant.polys.fields.FractionField(domain, symbols, order=<diofant.polys.orderings.LexOrder object>)[source]

A class for representing multivariate rational function fields.

class diofant.domains.RealField(prec=53, dps=None, tol=None)[source]

Real numbers up to the given precision.

almosteq(a, b, tolerance=None)[source]

Check if a and b are almost equal.

to_rational(element, limit=True)[source]

Convert a real number to rational number.

class diofant.domains.ComplexField(prec=53, dps=None, tol=None)[source]

Complex numbers up to the given precision.

almosteq(a, b, tolerance=None)[source]

Check if a and b are almost equal.

class diofant.domains.ExpressionDomain[source]

A class for arbitrary expressions.

class Expression(ex)[source]

A class for elements of ExpressionDomain.

dtype[source]

alias of Expression

Implementation Domains

class diofant.domains.finitefield.PythonFiniteField(order, modulus=None)[source]

Finite field based on Python’s integers.

class diofant.domains.finitefield.GMPYFiniteField(order, modulus=None)[source]

Finite field based on GMPY’s integers.

class diofant.domains.integerring.PythonIntegerRing[source]

Integer ring based on Python’s integers.

class diofant.domains.integerring.GMPYIntegerRing[source]

Integer ring based on GMPY’s integers.

class diofant.domains.rationalfield.PythonRationalField[source]

Rational field based on Python’s rationals.

class diofant.domains.rationalfield.GMPYRationalField[source]

Rational field based on GMPY’s rationals.

Domain Elements

class diofant.domains.finitefield.ModularInteger(rep)[source]

A class representing a modular integer.

property is_primitive

Test if this is a primitive element.

class diofant.domains.finitefield.GaloisFieldElement(rep)[source]

A class representing a Galois field element.