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.

abs(a)[source]

Absolute value of a, implies __abs__.

cofactors(a, b)[source]

Returns GCD and cofactors of a and b.

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]

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

from_FF_gmpy(a, K0)[source]

Convert ModularInteger(mpz) to dtype.

from_FF_python(a, K0)[source]

Convert ModularInteger(int) to dtype.

from_FractionField(a, K0)[source]

Convert a rational function to dtype.

from_PolynomialRing(a, K0)[source]

Convert a polynomial to dtype.

get_exact()[source]

Returns an exact domain associated with self.

half_gcdex(a, b)[source]

Half extended GCD of a and b.

is_negative(a)[source]

Returns True if a is negative.

is_nonnegative(a)[source]

Returns True if a is non-negative.

is_nonpositive(a)[source]

Returns True if a is non-positive.

is_one(a)[source]

Returns True if a is one.

is_positive(a)[source]

Returns True if a is positive.

map(seq)[source]

Rersively apply self to all elements of seq.

of_type(element)[source]

Check if a is of type dtype.

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

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

unify(K1, symbols=None)[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__.

gcd(a, b)[source]

Returns 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)
get_field()[source]

Returns a field associated with self.

get_ring()[source]

Returns a ring associated with self.

lcm(a, b)[source]

Returns LCM of a and b.

>>> QQ.lcm(QQ(2, 3), QQ(4, 9))
4/3
>>> lcm(Rational(2, 3), Rational(4, 9))
4/3
quo(a, b)[source]

Quotient of a and b, implies __truediv__.

rem(a, b)[source]

Remainder of a and b, implies nothing.

revert(a)[source]

Returns a**(-1) if possible.

class diofant.domains.ring.Ring[source]

Represents a ring domain.

denom(a)[source]

Returns denominator of \(a\).

div(a, b)[source]

Division of a and b, implies __divmod__.

exquo(a, b)[source]

Exact quotient of a and b, implies __floordiv__.

get_ring()[source]

Returns a ring associated with self.

invert(a, b)[source]

Returns inversion of a mod b.

numer(a)[source]

Returns numerator of a.

quo(a, b)[source]

Quotient of a and b, implies __floordiv__.

rem(a, b)[source]

Remainder of a and b, implies __mod__.

revert(a)[source]

Returns a**(-1) if possible.

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)[source]

Inject generators into this domain.

Concrete Domains

class diofant.domains.FiniteField(mod, dom, symmetric=True)[source]

General class for finite fields.

characteristic()[source]

Return the characteristic of this domain.

from_FF_gmpy(a, K0=None)[source]

Convert ModularInteger(mpz) to dtype.

from_FF_python(a, K0=None)[source]

Convert ModularInteger(int) to dtype.

from_QQ_gmpy(a, K0=None)[source]

Convert GMPY’s mpq to dtype.

from_QQ_python(a, K0=None)[source]

Convert Python’s Fraction to dtype.

from_RealField(a, K0)[source]

Convert mpmath’s mpf to dtype.

from_ZZ_gmpy(a, K0=None)[source]

Convert GMPY’s mpz to dtype.

from_ZZ_python(a, K0=None)[source]

Convert Python’s int to dtype.

from_diofant(a)[source]

Convert Diofant’s Integer to Diofant’s Integer.

get_field()[source]

Returns a field associated with self.

to_diofant(a)[source]

Convert a to a Diofant object.

class diofant.domains.IntegerRing[source]

General class for integer rings.

algebraic_field(*extension)[source]

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

from_AlgebraicField(a, K0)[source]

Convert a ANP object to dtype.

get_field()[source]

Returns a field associated with self.

log(a, b)[source]

Returns b-base logarithm of a.

class diofant.domains.PolynomialRing(domain_or_ring, symbols=None, order=None)[source]

A class for representing multivariate polynomial rings.

factorial(a)[source]

Returns factorial of \(a\).

from_AlgebraicField(a, K0)[source]

Convert an algebraic number to dtype.

from_FractionField(a, K0)[source]

Convert a rational function to dtype.

from_PolynomialRing(a, K0)[source]

Convert a polynomial to dtype.

from_QQ_gmpy(a, K0)[source]

Convert a GMPY \(mpq\) object to \(dtype\).

from_QQ_python(a, K0)[source]

Convert a Python \(Fraction\) object to \(dtype\).

from_RealField(a, K0)[source]

Convert a mpmath \(mpf\) object to \(dtype\).

from_ZZ_gmpy(a, K0)[source]

Convert a GMPY \(mpz\) object to \(dtype\).

from_ZZ_python(a, K0)[source]

Convert a Python \(int\) object to \(dtype\).

from_diofant(a)[source]

Convert Diofant’s expression to \(dtype\).

gcd(a, b)[source]

Returns GCD of \(a\) and \(b\).

gcdex(a, b)[source]

Extended GCD of \(a\) and \(b\).

get_field()[source]

Returns a field associated with \(self\).

is_negative(a)[source]

Returns True if \(LC(a)\) is negative.

is_nonnegative(a)[source]

Returns True if \(LC(a)\) is non-negative.

is_nonpositive(a)[source]

Returns True if \(LC(a)\) is non-positive.

is_positive(a)[source]

Returns True if \(LC(a)\) is positive.

lcm(a, b)[source]

Returns LCM of \(a\) and \(b\).

to_diofant(a)[source]

Convert \(a\) to a Diofant object.

class diofant.domains.RationalField[source]

General class for rational fields.

algebraic_field(*extension)[source]

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

from_AlgebraicField(a, K0)[source]

Convert a ANP object to dtype.

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

A class for representing algebraic number fields.

algebraic_field(*extension)[source]

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

denom(a)[source]

Returns denominator of a.

dtype

alias of diofant.polys.polyclasses.ANP

from_QQ_gmpy(a, K0)[source]

Convert a GMPY mpq object to dtype.

from_QQ_python(a, K0)[source]

Convert a Python Fraction object to dtype.

from_RealField(a, K0)[source]

Convert a mpmath mpf object to dtype.

from_ZZ_gmpy(a, K0)[source]

Convert a GMPY mpz object to dtype.

from_ZZ_python(a, K0)[source]

Convert a Python int object to dtype.

from_diofant(a)[source]

Convert Diofant’s expression to dtype.

get_ring()[source]

Returns a ring associated with self.

is_negative(a)[source]

Returns True if a is negative.

is_nonnegative(a)[source]

Returns True if a is non-negative.

is_nonpositive(a)[source]

Returns True if a is non-positive.

is_positive(a)[source]

Returns True if a is positive.

numer(a)[source]

Returns numerator of a.

to_diofant(a)[source]

Convert a to a Diofant object.

class diofant.domains.FractionField(domain_or_field, symbols=None, order=None)[source]

A class for representing multivariate rational function fields.

denom(a)[source]

Returns denominator of a.

factorial(a)[source]

Returns factorial of \(a\).

from_FractionField(a, K0)[source]

Convert a rational function to dtype.

from_PolynomialRing(a, K0)[source]

Convert a polynomial to dtype.

from_QQ_gmpy(a, K0)[source]

Convert a GMPY \(mpq\) object to \(dtype\).

from_QQ_python(a, K0)[source]

Convert a Python \(Fraction\) object to \(dtype\).

from_RealField(a, K0)[source]

Convert a mpmath \(mpf\) object to \(dtype\).

from_ZZ_gmpy(a, K0)[source]

Convert a GMPY \(mpz\) object to \(dtype\).

from_ZZ_python(a, K0)[source]

Convert a Python \(int\) object to \(dtype\).

from_diofant(a)[source]

Convert Diofant’s expression to \(dtype\).

get_ring()[source]

Returns a field associated with \(self\).

is_negative(a)[source]

Returns True if \(LC(a)\) is negative.

is_nonnegative(a)[source]

Returns True if \(LC(a)\) is non-negative.

is_nonpositive(a)[source]

Returns True if \(LC(a)\) is non-positive.

is_positive(a)[source]

Returns True if \(LC(a)\) is positive.

numer(a)[source]

Returns numerator of a.

to_diofant(a)[source]

Convert \(a\) to a Diofant object.

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.

from_diofant(expr)[source]

Convert Diofant’s number to dtype.

gcd(a, b)[source]

Returns GCD of a and b.

get_exact()[source]

Returns an exact domain associated with self.

get_ring()[source]

Returns a ring associated with self.

lcm(a, b)[source]

Returns LCM of a and b.

to_diofant(element)[source]

Convert element to Diofant number.

to_rational(element, limit=True)[source]

Convert a real number to rational number.

class diofant.domains.ExpressionDomain[source]

A class for arbitrary expressions.

class Expression(ex)[source]

An arbitrary expression.

denom(a)[source]

Returns denominator of a.

dtype

alias of ExpressionDomain.Expression

from_AlgebraicField(a, K0)[source]

Convert a ANP object to dtype.

from_ExpressionDomain(a, K0)[source]

Convert a EX object to dtype.

from_FractionField(a, K0)[source]

Convert a DMF object to dtype.

from_PolynomialRing(a, K0)[source]

Convert a DMP object to dtype.

from_QQ_gmpy(a, K0)[source]

Convert a GMPY mpq object to dtype.

from_QQ_python(a, K0)[source]

Convert a Python Fraction object to dtype.

from_RealField(a, K0)[source]

Convert a mpmath mpf object to dtype.

from_ZZ_gmpy(a, K0)[source]

Convert a GMPY mpz object to dtype.

from_ZZ_python(a, K0)[source]

Convert a Python int object to dtype.

from_diofant(a)[source]

Convert Diofant’s expression to dtype.

gcd(a, b)[source]

Returns 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)
get_field()[source]

Returns a field associated with self.

get_ring()[source]

Returns a ring associated with self.

is_negative(a)[source]

Returns True if a is negative.

is_nonnegative(a)[source]

Returns True if a is non-negative.

is_nonpositive(a)[source]

Returns True if a is non-positive.

is_positive(a)[source]

Returns True if a is positive.

lcm(a, b)[source]

Returns LCM of a and b.

>>> QQ.lcm(QQ(2, 3), QQ(4, 9))
4/3
>>> lcm(Rational(2, 3), Rational(4, 9))
4/3
numer(a)[source]

Returns numerator of a.

to_diofant(a)[source]

Convert a to a Diofant object.

Implementation Domains

class diofant.domains.PythonFiniteField(mod, symmetric=True)[source]

Finite field based on Python’s integers.

class diofant.domains.GMPYFiniteField(mod, symmetric=True)[source]

Finite field based on GMPY integers.

class diofant.domains.PythonIntegerRing[source]

Integer ring based on Python’s int type.

class diofant.domains.GMPYIntegerRing[source]

Integer ring based on GMPY’s mpz type.

class diofant.domains.PythonRationalField[source]

Rational field based on Python rational number type.

class diofant.domains.GMPYRationalField[source]

Rational field based on GMPY mpq class.