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]

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

from_expr(element)[source]

Convert Diofant’s expression to dtype.

get_exact()[source]

Returns an exact domain 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.

map(seq)[source]

Rersively apply self to all elements of seq.

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

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

to_expr(element)[source]

Convert 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__.

field

Returns a field associated with self.

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)
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.

ring

Returns a ring associated with self.

class diofant.domains.ring.Ring[source]

Represents a ring domain.

cofactors(a, b)[source]

Returns 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]

Returns inversion of a mod b.

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.

ring

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

Inject generators into this domain.

class diofant.domains.characteristiczero.CharacteristicZero[source]

Domain that has infinite number of elements.

characteristic

Return the characteristic of this domain.

Concrete Domains

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

General class for finite fields.

characteristic

Return the characteristic of this domain.

from_expr(a)[source]

Convert Diofant’s Integer to dtype.

to_expr(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)\).

field

Returns a field associated with self.

from_expr(a)[source]

Convert Diofant’s Integer to dtype.

to_expr(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_expr(a)[source]

Convert Diofant’s Integer to dtype.

log(a, b)[source]

Returns b-base logarithm of a.

to_expr(a)[source]

Convert a to a Diofant object.

class diofant.domains.AlgebraicField[source]

A class for representing algebraic number fields.

algebraic_field(*extension)[source]

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

from_expr(a)[source]

Convert Diofant’s expression to dtype.

is_negative(a)[source]

Returns True if a is negative.

is_positive(a)[source]

Returns True if a is positive.

ring

Returns a ring associated with self.

to_expr(a)[source]

Convert a to a Diofant object.

class diofant.domains.RealAlgebraicField[source]

A class for representing real algebraic number fields.

is_negative(a)[source]

Returns True if a is negative.

is_positive(a)[source]

Returns True if a is positive.

class diofant.domains.ComplexAlgebraicField[source]

A class for representing complex algebraic number fields.

class diofant.polys.rings.PolynomialRing[source]

A class for representing multivariate polynomial rings.

add(*objs)[source]

Add a sequence of polynomials or containers of polynomials.

Examples

>>> R, x = ring("x", ZZ)
>>> R.add([x**2 + 2*i + 3 for i in range(4)])
4*x**2 + 24
>>> _.factor_list()
(4, [(x**2 + 6, 1)])
drop(*gens)[source]

Remove specified generators from this ring.

drop_to_ground(*gens)[source]

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

factorial(a)[source]

Returns factorial of a.

field

Returns a field associated with self.

from_expr(expr)[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.

index(gen)[source]

Compute index of gen in self.gens.

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.

monomial_basis(i)[source]

Return the ith-basis element.

mul(*objs)[source]

Multiply a sequence of polynomials or containers of polynomials.

Examples

>>> R, x = ring("x", ZZ)
>>> R.mul([x**2 + 2*i + 3 for i in range(4)])
x**8 + 24*x**6 + 206*x**4 + 744*x**2 + 945
>>> _.factor_list()
(1, [(x**2 + 3, 1), (x**2 + 5, 1), (x**2 + 7, 1), (x**2 + 9, 1)])
to_expr(a)[source]

Convert a to a Diofant object.

class diofant.polys.fields.FractionField[source]

A class for representing multivariate rational function fields.

factorial(a)[source]

Returns factorial of a.

from_expr(expr)[source]

Convert Diofant’s expression to dtype.

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.

ring

Returns a field associated with self.

to_expr(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_expr(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.

lcm(a, b)[source]

Returns LCM of a and b.

to_expr(element)[source]

Convert element to Diofant number.

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.

from_expr(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.

lcm(a, b)[source]

Returns LCM of a and b.

to_expr(element)[source]

Convert element to Diofant number.

class diofant.domains.ExpressionDomain[source]

A class for arbitrary expressions.

class Expression(ex)[source]

An arbitrary expression.

dtype

alias of ExpressionDomain.Expression

from_expr(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)
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
ring

Returns a ring associated with self.

to_expr(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’s integers.

class diofant.domains.PythonIntegerRing[source]

Integer ring based on Python’s integers.

class diofant.domains.GMPYIntegerRing[source]

Integer ring based on GMPY’s integers.

class diofant.domains.PythonRationalField[source]

Rational field based on Python’s rationals.

class diofant.domains.GMPYRationalField[source]

Rational field based on GMPY’s rationals.