Reference docs for the Poly Domains#

This page lists the reference documentation for the domains in the polys module. For a general introduction to the polys module it is recommended to read 模块的基本功能 instead. For an introductory explanation of the what the domain system is and how it is used it is recommended to read Introducing the Domains of the poly module. This page lists the reference docs for the Domain class and its subclasses (the specific domains such as ZZ) as well as the classes that represent the domain elements.

领域#

Here we document the various implemented ground domains (see Introducing the Domains of the poly module for more of an explanation). There are three types of Domain subclass: 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 the polynomial manipulation algorithms. 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.

抽象域#

class sympy.polys.domains.domain.Domain[源代码]#

Superclass for all domains in the polys domains system.

See Introducing the Domains of the poly module for an introductory explanation of the domains system.

The Domain class is an abstract base class for all of the concrete domain types. There are many different Domain subclasses each of which has an associated dtype which is a class representing the elements of the domain. The coefficients of a Poly are elements of a domain which must be a subclass of Domain.

实例

The most common example domains are the integers ZZ and the rationals QQ.

>>> from sympy import Poly, symbols, Domain
>>> x, y = symbols('x, y')
>>> p = Poly(x**2 + y)
>>> p
Poly(x**2 + y, x, y, domain='ZZ')
>>> p.domain
ZZ
>>> isinstance(p.domain, Domain)
True
>>> Poly(x**2 + y/2)
Poly(x**2 + 1/2*y, x, y, domain='QQ')

The domains can be used directly in which case the domain object e.g. (ZZ or QQ) can be used as a constructor for elements of dtype.

>>> from sympy import ZZ, QQ
>>> ZZ(2)
2
>>> ZZ.dtype  
<class 'int'>
>>> type(ZZ(2))  
<class 'int'>
>>> QQ(1, 2)
1/2
>>> type(QQ(1, 2))  
<class 'sympy.polys.domains.pythonrational.PythonRational'>

The corresponding domain elements can be used with the arithmetic operations +,-,*,** and depending on the domain some combination of /,//,% might be usable. For example in ZZ both // (floor division) and % (modulo division) can be used but / (true division) cannot. Since QQ is a Field its elements can be used with / but // and % should not be used. Some domains have a gcd() method.

>>> ZZ(2) + ZZ(3)
5
>>> ZZ(5) // ZZ(2)
2
>>> ZZ(5) % ZZ(2)
1
>>> QQ(1, 2) / QQ(2, 3)
3/4
>>> ZZ.gcd(ZZ(4), ZZ(2))
2
>>> QQ.gcd(QQ(2,7), QQ(5,3))
1/21
>>> ZZ.is_Field
False
>>> QQ.is_Field
True

There are also many other domains including:

  1. GF(p) for finite fields of prime order.

  2. RR for real (floating point) numbers.

  3. CC for complex (floating point) numbers.

  4. QQ<a> for algebraic number fields.

  5. K[x] for polynomial rings.

  6. K(x) for rational function fields.

  7. EX for arbitrary expressions.

Each domain is represented by a domain object and also an implementation class (dtype) for the elements of the domain. For example the K[x] domains are represented by a domain object which is an instance of PolynomialRing and the elements are always instances of PolyElement. The implementation class represents particular types of mathematical expressions in a way that is more efficient than a normal SymPy expression which is of type Expr. The domain methods from_sympy() and to_sympy() are used to convert from Expr to a domain element and vice versa.

>>> from sympy import Symbol, ZZ, Expr
>>> x = Symbol('x')
>>> K = ZZ[x]           # polynomial ring domain
>>> K
ZZ[x]
>>> type(K)             # class of the domain
<class 'sympy.polys.domains.polynomialring.PolynomialRing'>
>>> K.dtype             # class of the elements
<class 'sympy.polys.rings.PolyElement'>
>>> p_expr = x**2 + 1   # Expr
>>> p_expr
x**2 + 1
>>> type(p_expr)
<class 'sympy.core.add.Add'>
>>> isinstance(p_expr, Expr)
True
>>> p_domain = K.from_sympy(p_expr)
>>> p_domain            # domain element
x**2 + 1
>>> type(p_domain)
<class 'sympy.polys.rings.PolyElement'>
>>> K.to_sympy(p_domain) == p_expr
True

The convert_from() method is used to convert domain elements from one domain to another.

>>> from sympy import ZZ, QQ
>>> ez = ZZ(2)
>>> eq = QQ.convert_from(ez, ZZ)
>>> type(ez)  
<class 'int'>
>>> type(eq)  
<class 'sympy.polys.domains.pythonrational.PythonRational'>

Elements from different domains should not be mixed in arithmetic or other operations: they should be converted to a common domain first. The domain method unify() is used to find a domain that can represent all the elements of two given domains.

>>> from sympy import ZZ, QQ, symbols
>>> x, y = symbols('x, y')
>>> ZZ.unify(QQ)
QQ
>>> ZZ[x].unify(QQ)
QQ[x]
>>> ZZ[x].unify(QQ[y])
QQ[x,y]

If a domain is a Ring then is might have an associated Field and vice versa. The get_field() and get_ring() methods will find or create the associated domain.

>>> from sympy import ZZ, QQ, Symbol
>>> x = Symbol('x')
>>> ZZ.has_assoc_Field
True
>>> ZZ.get_field()
QQ
>>> QQ.has_assoc_Ring
True
>>> QQ.get_ring()
ZZ
>>> K = QQ[x]
>>> K
QQ[x]
>>> K.get_field()
QQ(x)

参见

DomainElement

abstract base class for domain elements

construct_domain

construct a minimal domain for some expressions

abs(a)[源代码]#

绝对值 a ,暗示 __abs__ .

add(a, b)[源代码]#

总和 ab ,暗示 __add__ .

alg_field_from_poly(poly, alias=None, root_index=-1)[源代码]#

Convenience method to construct an algebraic extension on a root of a polynomial, chosen by root index.

参数:

poly : Poly

The polynomial whose root generates the extension.

alias : str, optional (default=None)

Symbol name for the generator of the extension. E.g. "alpha" or "theta".

root_index : int, optional (default=-1)

Specifies which root of the polynomial is desired. The ordering is as defined by the ComplexRootOf class. The default of -1 selects the most natural choice in the common cases of quadratic and cyclotomic fields (the square root on the positive real or imaginary axis, resp. \(\mathrm{e}^{2\pi i/n}\)).

实例

>>> from sympy import QQ, Poly
>>> from sympy.abc import x
>>> f = Poly(x**2 - 2)
>>> K = QQ.alg_field_from_poly(f)
>>> K.ext.minpoly == f
True
>>> g = Poly(8*x**3 - 6*x - 1)
>>> L = QQ.alg_field_from_poly(g, "alpha")
>>> L.ext.minpoly == g
True
>>> L.to_sympy(L([1, 1, 1]))
alpha**2 + alpha + 1
algebraic_field(*extension, alias=None)[源代码]#

返回一个代数域,即。 \(K(\alpha, \ldots)\) .

almosteq(a, b, tolerance=None)[源代码]#

检查是否 ab 几乎相等。

characteristic()[源代码]#

返回此域的特征。

cofactors(a, b)[源代码]#

返回的GCD和辅因子 ab .

convert(element, base=None)[源代码]#

转换 elementself.dtype .

convert_from(element, base)[源代码]#

转换 elementself.dtype 给定基域。

cyclotomic_field(n, ss=False, alias='zeta', gen=None, root_index=-1)[源代码]#

Convenience method to construct a cyclotomic field.

参数:

n :内景

Construct the nth cyclotomic field.

ss : boolean, optional (default=False)

If True, append n as a subscript on the alias string.

alias : str, optional (default="zeta")

Symbol name for the generator.

gen : Symbol, optional (default=None)

Desired variable for the cyclotomic polynomial that defines the field. If None, a dummy variable will be used.

root_index : int, optional (default=-1)

Specifies which root of the polynomial is desired. The ordering is as defined by the ComplexRootOf class. The default of -1 selects the root \(\mathrm{e}^{2\pi i/n}\).

实例

>>> from sympy import QQ, latex
>>> K = QQ.cyclotomic_field(5)
>>> K.to_sympy(K([-1, 1]))
1 - zeta
>>> L = QQ.cyclotomic_field(7, True)
>>> a = L.to_sympy(L([-1, 1]))
>>> print(a)
1 - zeta7
>>> print(latex(a))
1 - \zeta_{7}
denom(a)[源代码]#

返回的分母 a .

div(a, b)[源代码]#

Quotient and remainder for a and b. Analogue of divmod(a, b)

参数:

a: domain element

The dividend

b: domain element

The divisor

返回:

(q, r): tuple of domain elements

The quotient and remainder

加薪:

ZeroDivisionError: when the divisor is zero.

解释

This is essentially the same as divmod(a, b) except that is more consistent when working over some Field domains such as QQ. When working over an arbitrary Domain the div() method should be used instead of divmod.

The key invariant is that if q, r = K.div(a, b) then a == b*q + r.

The result of K.div(a, b) is the same as the tuple (K.quo(a, b), K.rem(a, b)) except that if both quotient and remainder are needed then it is more efficient to use div().

实例

We can use K.div instead of divmod for floor division and remainder.

>>> from sympy import ZZ, QQ
>>> ZZ.div(ZZ(5), ZZ(2))
(2, 1)

If K is a Field then the division is always exact with a remainder of zero.

>>> QQ.div(QQ(5), QQ(2))
(5/2, 0)

笔记

If gmpy is installed then the gmpy.mpq type will be used as the dtype for QQ. The gmpy.mpq type defines divmod in a way that is undesirable so div() should be used instead of divmod.

>>> a = QQ(1)
>>> b = QQ(3, 2)
>>> a               
mpq(1,1)
>>> b               
mpq(3,2)
>>> divmod(a, b)    
(mpz(0), mpq(1,1))
>>> QQ.div(a, b)    
(mpq(2,3), mpq(0,1))

Using // or % with QQ will lead to incorrect results so div() should be used instead.

参见

quo

Analogue of a // b

rem

Analogue of a % b

exquo

Analogue of a / b

drop(*symbols)[源代码]#

Drop generators from this domain.

dtype: type | None = None#

The type (class) of the elements of this Domain:

>>> from sympy import ZZ, QQ, Symbol
>>> ZZ.dtype
<class 'int'>
>>> z = ZZ(2)
>>> z
2
>>> type(z)
<class 'int'>
>>> type(z) == ZZ.dtype
True

Every domain has an associated dtype ("datatype") which is the class of the associated domain elements.

参见

of_type

evalf(a, prec=None, **options)[源代码]#

返回的数值近似值 a .

exquo(a, b)[源代码]#

Exact quotient of a and b. Analogue of a / b.

参数:

a: domain element

The dividend

b: domain element

The divisor

返回:

q: domain element

The exact quotient

加薪:

ExactQuotientFailed: if exact division is not possible.

ZeroDivisionError: when the divisor is zero.

解释

This is essentially the same as a / b except that an error will be raised if the division is inexact (if there is any remainder) and the result will always be a domain element. When working in a Domain that is not a Field (e.g. ZZ or K[x]) exquo should be used instead of /.

The key invariant is that if q = K.exquo(a, b) (and exquo does not raise an exception) then a == b*q.

实例

We can use K.exquo instead of / for exact division.

>>> from sympy import ZZ
>>> ZZ.exquo(ZZ(4), ZZ(2))
2
>>> ZZ.exquo(ZZ(5), ZZ(2))
Traceback (most recent call last):
    ...
ExactQuotientFailed: 2 does not divide 5 in ZZ

Over a Field such as QQ, division (with nonzero divisor) is always exact so in that case / can be used instead of exquo().

>>> from sympy import QQ
>>> QQ.exquo(QQ(5), QQ(2))
5/2
>>> QQ(5) / QQ(2)
5/2

笔记

Since the default dtype for ZZ is int (or mpz) division as a / b should not be used as it would give a float which is not a domain element.

>>> ZZ(4) / ZZ(2) 
2.0
>>> ZZ(5) / ZZ(2) 
2.5

On the other hand with \(SYMPY_GROUND_TYPES=flint\) elements of ZZ are flint.fmpz and division would raise an exception:

>>> ZZ(4) / ZZ(2) 
Traceback (most recent call last):
...
TypeError: unsupported operand type(s) for /: 'fmpz' and 'fmpz'

Using / with ZZ will lead to incorrect results so exquo() should be used instead.

参见

quo

Analogue of a // b

rem

Analogue of a % b

div

Analogue of divmod(a, b)

exsqrt(a)[源代码]#

Principal square root of a within the domain if a is square.

解释

The implementation of this method should return an element b in the domain such that b * b == a, or None if there is no such b. For inexact domains like RR and CC, a tiny difference in this equality can be tolerated. The choice of a "principal" square root should follow a consistent rule whenever possible.

参见

sqrt, is_square

frac_field(*symbols, order=LexOrder())[源代码]#

返回一个分数字段,即。 \(K(X)\) .

from_AlgebraicField(a, K0)[源代码]#

将代数数转换为 dtype .

from_ComplexField(a, K0)[源代码]#

将复杂元素转换为 dtype .

from_ExpressionDomain(a, K0)[源代码]#

转换为 EX 对象到 dtype .

from_ExpressionRawDomain(a, K0)[源代码]#

转换为 EX 对象到 dtype .

from_FF(a, K0)[源代码]#

转换 ModularInteger(int)dtype .

from_FF_gmpy(a, K0)[源代码]#

转换 ModularInteger(mpz)dtype .

from_FF_python(a, K0)[源代码]#

转换 ModularInteger(int)dtype .

from_FractionField(a, K0)[源代码]#

将有理函数转换为 dtype .

from_GlobalPolynomialRing(a, K0)[源代码]#

将多项式转换为 dtype .

from_MonogenicFiniteExtension(a, K0)[源代码]#

Convert an ExtensionElement to dtype.

from_PolynomialRing(a, K0)[源代码]#

将多项式转换为 dtype .

from_QQ_gmpy(a, K0)[源代码]#

转换GMPY mpq 对象到 dtype .

from_QQ_python(a, K0)[源代码]#

转换Python Fraction 对象到 dtype .

from_RealField(a, K0)[源代码]#

将实际元素对象转换为 dtype .

from_ZZ_gmpy(a, K0)[源代码]#

转换GMPY mpz 对象到 dtype .

from_ZZ_python(a, K0)[源代码]#

转换Python int 对象到 dtype .

from_sympy(a)[源代码]#

Convert a SymPy expression to an element of this domain.

参数:

表达式:表达式

A normal SymPy expression of type Expr.

返回:

a: domain element

An element of this Domain.

解释

See to_sympy() for explanation and examples.

gcd(a, b)[源代码]#

返回的GCD ab .

gcdex(a, b)[源代码]#

扩展GCD ab .

get_exact()[源代码]#

返回与关联的精确域 self .

get_field()[源代码]#

返回与关联的字段 self .

get_ring()[源代码]#

返回与关联的环 self .

half_gcdex(a, b)[源代码]#

半扩展GCD ab .

has_assoc_Field = False#

Boolean flag indicating if the domain has an associated Field.

>>> from sympy import ZZ
>>> ZZ.has_assoc_Field
True
>>> ZZ.get_field()
QQ
has_assoc_Ring = False#

Boolean flag indicating if the domain has an associated Ring.

>>> from sympy import QQ
>>> QQ.has_assoc_Ring
True
>>> QQ.get_ring()
ZZ

参见

is_Field, get_ring

inject(*symbols)[源代码]#

将生成器注入此域。

invert(a, b)[源代码]#

返回的倒数 a mod b ,意味着什么。

is_Field = False#

Boolean flag indicating if the domain is a Field.

>>> from sympy import ZZ, QQ
>>> ZZ.is_Field
False
>>> QQ.is_Field
True
is_PID = False#

Boolean flag indicating if the domain is a principal ideal domain.

>>> from sympy import ZZ
>>> ZZ.has_assoc_Field
True
>>> ZZ.get_field()
QQ
is_Ring = False#

Boolean flag indicating if the domain is a Ring.

>>> from sympy import ZZ
>>> ZZ.is_Ring
True

Basically every Domain represents a ring so this flag is not that useful.

is_negative(a)[源代码]#

返回true a 是否定的。

is_nonnegative(a)[源代码]#

返回true a 是非负的。

is_nonpositive(a)[源代码]#

返回true a 是非阳性。

is_one(a)[源代码]#

返回true a 是一个。

is_positive(a)[源代码]#

返回true a 是肯定的。

is_square(a)[源代码]#

Returns whether a is a square in the domain.

解释

Returns True if there is an element b in the domain such that b * b == a, otherwise returns False. For inexact domains like RR and CC, a tiny difference in this equality can be tolerated.

参见

exsqrt

is_zero(a)[源代码]#

返回true a 是零。

lcm(a, b)[源代码]#

返回的LCM ab .

log(a, b)[源代码]#

返回的b基对数 a .

map(seq)[源代码]#

重新应用 self 所有元素 seq .

mul(a, b)[源代码]#

产品 ab ,暗示 __mul__ .

n(a, prec=None, **options)[源代码]#

返回的数值近似值 a .

neg(a)[源代码]#

返回 a 否定,意味着 __neg__ .

numer(a)[源代码]#

返回的分子 a .

of_type(element)[源代码]#

检查是否 a 属于类型 dtype .

old_frac_field(*symbols, **kwargs)[源代码]#

返回一个分数字段,即。 \(K(X)\) .

old_poly_ring(*symbols, **kwargs)[源代码]#

返回多项式环,即。 \(K[X]\) .

one: Any = None#

The one element of the Domain:

>>> from sympy import QQ
>>> QQ.one
1
>>> QQ.of_type(QQ.one)
True

参见

of_type, zero

poly_ring(*symbols, order=LexOrder())[源代码]#

返回多项式环,即。 \(K[X]\) .

pos(a)[源代码]#

返回 a 肯定,意味着 __pos__ .

pow(a, b)[源代码]#

提高 a 给力 b ,暗示 __pow__ .

quo(a, b)[源代码]#

Quotient of a and b. Analogue of a // b.

K.quo(a, b) is equivalent to K.div(a, b)[0]. See div() for more explanation.

参见

rem

Analogue of a % b

div

Analogue of divmod(a, b)

exquo

Analogue of a / b

rem(a, b)[源代码]#

Modulo division of a and b. Analogue of a % b.

K.rem(a, b) is equivalent to K.div(a, b)[1]. See div() for more explanation.

参见

quo

Analogue of a // b

div

Analogue of divmod(a, b)

exquo

Analogue of a / b

revert(a)[源代码]#

返回 a**(-1) 如果可能的话。

sqrt(a)[源代码]#

Returns a (possibly inexact) square root of a.

解释

There is no universal definition of "inexact square root" for all domains. It is not recommended to implement this method for domains other then ZZ.

参见

exsqrt

sub(a, b)[源代码]#

差异性 ab ,暗示 __sub__ .

to_sympy(a)[源代码]#

Convert domain element a to a SymPy expression (Expr).

参数:

a: domain element

An element of this Domain.

返回:

expr: Expr

A normal SymPy expression of type Expr.

解释

Convert a Domain element a to Expr. Most public SymPy functions work with objects of type Expr. The elements of a Domain have a different internal representation. It is not possible to mix domain elements with Expr so each domain has to_sympy() and from_sympy() methods to convert its domain elements to and from Expr.

实例

Construct an element of the QQ domain and then convert it to Expr.

>>> from sympy import QQ, Expr
>>> q_domain = QQ(2)
>>> q_domain
2
>>> q_expr = QQ.to_sympy(q_domain)
>>> q_expr
2

Although the printed forms look similar these objects are not of the same type.

>>> isinstance(q_domain, Expr)
False
>>> isinstance(q_expr, Expr)
True

Construct an element of K[x] and convert to Expr.

>>> from sympy import Symbol
>>> x = Symbol('x')
>>> K = QQ[x]
>>> x_domain = K.gens[0]  # generator x as a domain element
>>> p_domain = x_domain**2/3 + 1
>>> p_domain
1/3*x**2 + 1
>>> p_expr = K.to_sympy(p_domain)
>>> p_expr
x**2/3 + 1

The from_sympy() method is used for the opposite conversion from a normal SymPy expression to a domain element.

>>> p_domain == p_expr
False
>>> K.from_sympy(p_expr) == p_domain
True
>>> K.to_sympy(p_domain) == p_expr
True
>>> K.from_sympy(K.to_sympy(p_domain)) == p_domain
True
>>> K.to_sympy(K.from_sympy(p_expr)) == p_expr
True

The from_sympy() method makes it easier to construct domain elements interactively.

>>> from sympy import Symbol
>>> x = Symbol('x')
>>> K = QQ[x]
>>> K.from_sympy(x**2/3 + 1)
1/3*x**2 + 1
property tp#

Alias for dtype

unify(K1, symbols=None)[源代码]#

构造一个包含元素的最小域 K0K1 .

已知域(从最小到最大):

  • GF(p)

  • ZZ

  • QQ

  • RR(prec, tol)

  • CC(prec, tol)

  • ALG(a, b, c)

  • K[x, y, z]

  • K(x, y, z)

  • EX

unify_composite(K1)[源代码]#

Unify two domains where at least one is composite.

zero: Any = None#

The zero element of the Domain:

>>> from sympy import QQ
>>> QQ.zero
0
>>> QQ.of_type(QQ.zero)
True

参见

of_type, one

class sympy.polys.domains.domainelement.DomainElement[源代码]#

Represents an element of a domain.

Mix in this trait into a class whose instances should be recognized as elements of a domain. Method parent() gives that domain.

parent()[源代码]#

Get the domain associated with self

实例

>>> from sympy import ZZ, symbols
>>> x, y = symbols('x, y')
>>> K = ZZ[x,y]
>>> p = K(x)**2 + K(y)**2
>>> p
x**2 + y**2
>>> p.parent()
ZZ[x,y]

笔记

This is used by convert() to identify the domain associated with a domain element.

class sympy.polys.domains.field.Field[源代码]#

表示字段域。

div(a, b)[源代码]#

分部 ab ,暗示 __truediv__ .

exquo(a, b)[源代码]#

精确商 ab ,暗示 __truediv__ .

gcd(a, b)[源代码]#

返回的GCD ab .

GCD在字段上的定义允许清除 \(primitive()\) .

实例

>>> from sympy.polys.domains import QQ
>>> from sympy import S, gcd, primitive
>>> from sympy.abc import x
>>> QQ.gcd(QQ(2, 3), QQ(4, 9))
2/9
>>> gcd(S(2)/3, S(4)/9)
2/9
>>> primitive(2*x/3 + S(4)/9)
(2/9, 3*x + 2)
get_field()[源代码]#

返回与关联的字段 self .

get_ring()[源代码]#

返回与关联的环 self .

is_unit(a)[源代码]#

Return true if a is a invertible

lcm(a, b)[源代码]#

返回的LCM ab .

>>> from sympy.polys.domains import QQ
>>> from sympy import S, lcm
>>> QQ.lcm(QQ(2, 3), QQ(4, 9))
4/3
>>> lcm(S(2)/3, S(4)/9)
4/3
quo(a, b)[源代码]#

ab ,暗示 __truediv__ .

rem(a, b)[源代码]#

剩余 ab ,没有任何含义。

revert(a)[源代码]#

返回 a**(-1) 如果可能的话。

class sympy.polys.domains.ring.Ring[源代码]#

表示环域。

denom(a)[源代码]#

返回的分母 \(a\) .

div(a, b)[源代码]#

分部 ab ,暗示 __divmod__ .

exquo(a, b)[源代码]#

精确商 ab ,暗示 __floordiv__ .

free_module(rank)[源代码]#

生成一个自由的秩模块 rank 过度自我。

>>> from sympy.abc import x
>>> from sympy import QQ
>>> QQ.old_poly_ring(x).free_module(2)
QQ[x]**2
get_ring()[源代码]#

返回与关联的环 self .

ideal(*gens)[源代码]#

产生一种理想 self .

>>> from sympy.abc import x
>>> from sympy import QQ
>>> QQ.old_poly_ring(x).ideal(x**2)
<x**2>
invert(a, b)[源代码]#

返回的倒数 a mod b .

numer(a)[源代码]#

返回的分子 a .

quo(a, b)[源代码]#

ab ,暗示 __floordiv__ .

quotient_ring(e)[源代码]#

形成一个商环 self .

在这里 e 可以是理想的,也可以是可接受的。

>>> from sympy.abc import x
>>> from sympy import QQ
>>> QQ.old_poly_ring(x).quotient_ring(QQ.old_poly_ring(x).ideal(x**2))
QQ[x]/<x**2>
>>> QQ.old_poly_ring(x).quotient_ring([x**2])
QQ[x]/<x**2>

除法运算符已为此过载:

>>> QQ.old_poly_ring(x)/[x**2]
QQ[x]/<x**2>
rem(a, b)[源代码]#

剩余 ab ,暗示 __mod__ .

revert(a)[源代码]#

返回 a**(-1) 如果可能的话。

class sympy.polys.domains.simpledomain.SimpleDomain[源代码]#

简单域的基类,例如ZZ、QQ。

inject(*gens)[源代码]#

将生成器注入此域。

class sympy.polys.domains.compositedomain.CompositeDomain[源代码]#

复合域的基类,例如ZZ [x] X,ZZ。

drop(*symbols)[源代码]#

Drop generators from this domain.

get_exact()[源代码]#

Returns an exact version of this domain.

inject(*symbols)[源代码]#

将生成器注入此域。

property is_Exact#

Returns True if this domain is exact.

set_domain(domain)[源代码]#

Set the ground domain of this domain.

GF(p)#

class sympy.polys.domains.FiniteField(mod, symmetric=True)[源代码]#

Finite field of prime order GF(p)

A GF(p) domain represents a finite field \(\mathbb{F}_p\) of prime order as Domain in the domain system (see Introducing the Domains of the poly module).

A Poly created from an expression with integer coefficients will have the domain ZZ. However, if the modulus=p option is given then the domain will be a finite field instead.

>>> from sympy import Poly, Symbol
>>> x = Symbol('x')
>>> p = Poly(x**2 + 1)
>>> p
Poly(x**2 + 1, x, domain='ZZ')
>>> p.domain
ZZ
>>> p2 = Poly(x**2 + 1, modulus=2)
>>> p2
Poly(x**2 + 1, x, modulus=2)
>>> p2.domain
GF(2)

It is possible to factorise a polynomial over GF(p) using the modulus argument to factor() or by specifying the domain explicitly. The domain can also be given as a string.

>>> from sympy import factor, GF
>>> factor(x**2 + 1)
x**2 + 1
>>> factor(x**2 + 1, modulus=2)
(x + 1)**2
>>> factor(x**2 + 1, domain=GF(2))
(x + 1)**2
>>> factor(x**2 + 1, domain='GF(2)')
(x + 1)**2

It is also possible to use GF(p) with the cancel() and gcd() functions.

>>> from sympy import cancel, gcd
>>> cancel((x**2 + 1)/(x + 1))
(x**2 + 1)/(x + 1)
>>> cancel((x**2 + 1)/(x + 1), domain=GF(2))
x + 1
>>> gcd(x**2 + 1, x + 1)
1
>>> gcd(x**2 + 1, x + 1, domain=GF(2))
x + 1

When using the domain directly GF(p) can be used as a constructor to create instances which then support the operations +,-,*,**,/

>>> from sympy import GF
>>> K = GF(5)
>>> K
GF(5)
>>> x = K(3)
>>> y = K(2)
>>> x
3 mod 5
>>> y
2 mod 5
>>> x * y
1 mod 5
>>> x / y
4 mod 5

笔记

It is also possible to create a GF(p) domain of non-prime order but the resulting ring is not a field: it is just the ring of the integers modulo n.

>>> K = GF(9)
>>> z = K(3)
>>> z
3 mod 9
>>> z**2
0 mod 9

It would be good to have a proper implementation of prime power fields (GF(p**n)) but these are not yet implemented in SymPY.

characteristic()[源代码]#

返回此域的特征。

exsqrt(a)[源代码]#

Square root modulo p of a if it is a quadratic residue.

解释

Always returns the square root that is no larger than p // 2.

from_FF(a, K0=None)[源代码]#

转换 ModularInteger(int)dtype .

from_FF_gmpy(a, K0=None)[源代码]#

转换 ModularInteger(mpz)dtype .

from_FF_python(a, K0=None)[源代码]#

转换 ModularInteger(int)dtype .

from_QQ(a, K0=None)[源代码]#

转换Python的 Fractiondtype .

from_QQ_gmpy(a, K0=None)[源代码]#

转换GMPY mpqdtype .

from_QQ_python(a, K0=None)[源代码]#

转换Python的 Fractiondtype .

from_RealField(a, K0)[源代码]#

转换mpmath mpfdtype .

from_ZZ(a, K0=None)[源代码]#

转换Python的 intdtype .

from_ZZ_gmpy(a, K0=None)[源代码]#

转换GMPY mpzdtype .

from_ZZ_python(a, K0=None)[源代码]#

转换Python的 intdtype .

from_sympy(a)[源代码]#

将SymPy的整数转换为SymPy的整数 Integer .

get_field()[源代码]#

返回与关联的字段 self .

is_negative(a)[源代码]#

返回true a 是否定的。

is_nonnegative(a)[源代码]#

返回true a 是非负的。

is_nonpositive(a)[源代码]#

返回true a 是非阳性。

is_positive(a)[源代码]#

返回true a 是肯定的。

is_square(a)[源代码]#

Returns True if a is a quadratic residue modulo p.

to_int(a)[源代码]#

Convert val to a Python int object.

to_sympy(a)[源代码]#

转换 a 对一个同一物体。

class sympy.polys.domains.PythonFiniteField(mod, symmetric=True)[源代码]#

基于Python整数的有限域。

class sympy.polys.domains.GMPYFiniteField(mod, symmetric=True)[源代码]#

基于GMPY整数的有限域。

ZZ#

The ZZ domain represents the integers \(\mathbb{Z}\) as a Domain in the domain system (see Introducing the Domains of the poly module).

By default a Poly created from an expression with integer coefficients will have the domain ZZ:

>>> from sympy import Poly, Symbol
>>> x = Symbol('x')
>>> p = Poly(x**2 + 1)
>>> p
Poly(x**2 + 1, x, domain='ZZ')
>>> p.domain
ZZ

The corresponding field of fractions is the domain of the rationals QQ. Conversely ZZ is the ring of integers of QQ:

>>> from sympy import ZZ, QQ
>>> ZZ.get_field()
QQ
>>> QQ.get_ring()
ZZ

When using the domain directly ZZ can be used as a constructor to create instances which then support the operations +,-,*,**,//,% (true division / should not be used with ZZ - see the exquo() domain method):

>>> x = ZZ(5)
>>> y = ZZ(2)
>>> x // y  # floor division
2
>>> x % y   # modulo division (remainder)
1

The gcd() method can be used to compute the gcd of any two elements:

>>> ZZ.gcd(ZZ(10), ZZ(2))
2

There are two implementations of ZZ in SymPy. If gmpy or gmpy2 is installed then ZZ will be implemented by GMPYIntegerRing and the elements will be instances of the gmpy.mpz type. Otherwise if gmpy and gmpy2 are not installed then ZZ will be implemented by PythonIntegerRing which uses Python's standard builtin int type. With larger integers gmpy can be more efficient so it is preferred when available.

class sympy.polys.domains.IntegerRing[源代码]#

The domain ZZ representing the integers \(\mathbb{Z}\).

The IntegerRing class represents the ring of integers as a Domain in the domain system. IntegerRing is a super class of PythonIntegerRing and GMPYIntegerRing one of which will be the implementation for ZZ depending on whether or not gmpy or gmpy2 is installed.

参见

Domain

algebraic_field(*extension, alias=None)[源代码]#

返回一个代数域,即。 \(\mathbb{{Q}}(\alpha, \ldots)\) .

参数:

*extension : One or more Expr.

Generators of the extension. These should be expressions that are algebraic over \(\mathbb{Q}\).

alias : str, Symbol, None, optional (default=None)

If provided, this will be used as the alias symbol for the primitive element of the returned AlgebraicField.

返回:

AlgebraicField

A Domain representing the algebraic field extension.

实例

>>> from sympy import ZZ, sqrt
>>> ZZ.algebraic_field(sqrt(2))
QQ<sqrt(2)>
exsqrt(a)[源代码]#

Non-negative square root of a if a is a square.

参见

is_square

factorial(a)[源代码]#

Compute factorial of a.

from_AlgebraicField(a, K0)[源代码]#

Convert a ANP object to ZZ.

See convert().

from_EX(a, K0)[源代码]#

Convert Expression to GMPY's mpz.

from_FF(a, K0)[源代码]#

Convert ModularInteger(int) to GMPY's mpz.

from_FF_gmpy(a, K0)[源代码]#

Convert ModularInteger(mpz) to GMPY's mpz.

from_FF_python(a, K0)[源代码]#

Convert ModularInteger(int) to GMPY's mpz.

from_QQ(a, K0)[源代码]#

Convert Python's Fraction to GMPY's mpz.

from_QQ_gmpy(a, K0)[源代码]#

Convert GMPY mpq to GMPY's mpz.

from_QQ_python(a, K0)[源代码]#

Convert Python's Fraction to GMPY's mpz.

from_RealField(a, K0)[源代码]#

Convert mpmath's mpf to GMPY's mpz.

from_ZZ(a, K0)[源代码]#

Convert Python's int to GMPY's mpz.

from_ZZ_gmpy(a, K0)[源代码]#

Convert GMPY's mpz to GMPY's mpz.

from_ZZ_python(a, K0)[源代码]#

Convert Python's int to GMPY's mpz.

from_sympy(a)[源代码]#

Convert SymPy's Integer to dtype.

gcd(a, b)[源代码]#

Compute GCD of a and b.

gcdex(a, b)[源代码]#

Compute extended GCD of a and b.

get_field()[源代码]#

Return the associated field of fractions QQ

返回:

QQ:

The associated field of fractions QQ, a Domain representing the rational numbers \(\mathbb{Q}\).

实例

>>> from sympy import ZZ
>>> ZZ.get_field()
QQ
is_square(a)[源代码]#

Return True if a is a square.

解释

An integer is a square if and only if there exists an integer b such that b * b == a.

lcm(a, b)[源代码]#

Compute LCM of a and b.

log(a, b)[源代码]#

Logarithm of a to the base b.

参数:

a: number

b: number

返回:

\(\\lfloor\log(a, b)\\rfloor\):

Floor of the logarithm of a to the base b

实例

>>> from sympy import ZZ
>>> ZZ.log(ZZ(8), ZZ(2))
3
>>> ZZ.log(ZZ(9), ZZ(2))
3

笔记

This function uses math.log which is based on float so it will fail for large integer arguments.

sqrt(a)[源代码]#

Compute square root of a.

to_sympy(a)[源代码]#

转换 a 对一个同一物体。

class sympy.polys.domains.PythonIntegerRing[源代码]#

基于Python的整数环 int 类型。

This will be used as ZZ if gmpy and gmpy2 are not installed. Elements are instances of the standard Python int type.

class sympy.polys.domains.GMPYIntegerRing[源代码]#

基于GMPY的整数环 mpz 类型。

This will be the implementation of ZZ if gmpy or gmpy2 is installed. Elements will be of type gmpy.mpz.

factorial(a)[源代码]#

Compute factorial of a.

from_FF_gmpy(a, K0)[源代码]#

Convert ModularInteger(mpz) to GMPY's mpz.

from_FF_python(a, K0)[源代码]#

Convert ModularInteger(int) to GMPY's mpz.

from_QQ(a, K0)[源代码]#

Convert Python's Fraction to GMPY's mpz.

from_QQ_gmpy(a, K0)[源代码]#

Convert GMPY mpq to GMPY's mpz.

from_QQ_python(a, K0)[源代码]#

Convert Python's Fraction to GMPY's mpz.

from_RealField(a, K0)[源代码]#

Convert mpmath's mpf to GMPY's mpz.

from_ZZ_gmpy(a, K0)[源代码]#

Convert GMPY's mpz to GMPY's mpz.

from_ZZ_python(a, K0)[源代码]#

Convert Python's int to GMPY's mpz.

from_sympy(a)[源代码]#

Convert SymPy's Integer to dtype.

gcd(a, b)[源代码]#

Compute GCD of a and b.

gcdex(a, b)[源代码]#

Compute extended GCD of a and b.

lcm(a, b)[源代码]#

Compute LCM of a and b.

sqrt(a)[源代码]#

Compute square root of a.

to_sympy(a)[源代码]#

转换 a 对一个同一物体。

QQ#

The QQ domain represents the rationals \(\mathbb{Q}\) as a Domain in the domain system (see Introducing the Domains of the poly module).

By default a Poly created from an expression with rational coefficients will have the domain QQ:

>>> from sympy import Poly, Symbol
>>> x = Symbol('x')
>>> p = Poly(x**2 + x/2)
>>> p
Poly(x**2 + 1/2*x, x, domain='QQ')
>>> p.domain
QQ

The corresponding ring of integers is the Domain of the integers ZZ. Conversely QQ is the field of fractions of ZZ:

>>> from sympy import ZZ, QQ
>>> QQ.get_ring()
ZZ
>>> ZZ.get_field()
QQ

When using the domain directly QQ can be used as a constructor to create instances which then support the operations +,-,*,**,/ (true division / is always possible for nonzero divisors in QQ):

>>> x = QQ(5)
>>> y = QQ(2)
>>> x / y  # true division
5/2

There are two implementations of QQ in SymPy. If gmpy or gmpy2 is installed then QQ will be implemented by GMPYRationalField and the elements will be instances of the gmpy.mpq type. Otherwise if gmpy and gmpy2 are not installed then QQ will be implemented by PythonRationalField which is a pure Python class as part of sympy. The gmpy implementation is preferred because it is significantly faster.

class sympy.polys.domains.RationalField[源代码]#

Abstract base class for the domain QQ.

The RationalField class represents the field of rational numbers \(\mathbb{Q}\) as a Domain in the domain system. RationalField is a superclass of PythonRationalField and GMPYRationalField one of which will be the implementation for QQ depending on whether either of gmpy or gmpy2 is installed or not.

参见

Domain

algebraic_field(*extension, alias=None)[源代码]#

返回一个代数域,即。 \(\mathbb{{Q}}(\alpha, \ldots)\) .

参数:

*extension : One or more Expr

Generators of the extension. These should be expressions that are algebraic over \(\mathbb{Q}\).

alias : str, Symbol, None, optional (default=None)

If provided, this will be used as the alias symbol for the primitive element of the returned AlgebraicField.

返回:

AlgebraicField

A Domain representing the algebraic field extension.

实例

>>> from sympy import QQ, sqrt
>>> QQ.algebraic_field(sqrt(2))
QQ<sqrt(2)>
denom(a)[源代码]#

返回的分母 a .

div(a, b)[源代码]#

分部 ab ,暗示 __truediv__ .

exquo(a, b)[源代码]#

精确商 ab ,暗示 __truediv__ .

exsqrt(a)[源代码]#

Non-negative square root of a if a is a square.

参见

is_square

from_AlgebraicField(a, K0)[源代码]#

Convert a ANP object to QQ.

See convert()

from_GaussianRationalField(a, K0)[源代码]#

Convert a GaussianElement object to dtype.

from_QQ(a, K0)[源代码]#

转换Python Fraction 对象到 dtype .

from_QQ_gmpy(a, K0)[源代码]#

转换GMPY mpq 对象到 dtype .

from_QQ_python(a, K0)[源代码]#

转换Python Fraction 对象到 dtype .

from_RealField(a, K0)[源代码]#

转换mpmath mpf 对象到 dtype .

from_ZZ(a, K0)[源代码]#

转换Python int 对象到 dtype .

from_ZZ_gmpy(a, K0)[源代码]#

转换GMPY mpz 对象到 dtype .

from_ZZ_python(a, K0)[源代码]#

转换Python int 对象到 dtype .

from_sympy(a)[源代码]#

Convert SymPy's Integer to dtype.

get_ring()[源代码]#

Returns ring associated with self.

is_square(a)[源代码]#

Return True if a is a square.

解释

A rational number is a square if and only if there exists a rational number b such that b * b == a.

numer(a)[源代码]#

返回的分子 a .

quo(a, b)[源代码]#

ab ,暗示 __truediv__ .

rem(a, b)[源代码]#

剩余 ab ,没有任何含义。

to_sympy(a)[源代码]#

转换 a 对一个同一物体。

class sympy.polys.domains.PythonRationalField[源代码]#

Rational field based on MPQ.

This will be used as QQ if gmpy and gmpy2 are not installed. Elements are instances of MPQ.

class sympy.polys.domains.GMPYRationalField[源代码]#

Rational field based on GMPY's mpq type.

This will be the implementation of QQ if gmpy or gmpy2 is installed. Elements will be of type gmpy.mpq.

denom(a)[源代码]#

返回的分母 a .

div(a, b)[源代码]#

分部 ab ,暗示 __truediv__ .

exquo(a, b)[源代码]#

精确商 ab ,暗示 __truediv__ .

factorial(a)[源代码]#

Returns factorial of a.

from_GaussianRationalField(a, K0)[源代码]#

Convert a GaussianElement object to dtype.

from_QQ_gmpy(a, K0)[源代码]#

转换GMPY mpq 对象到 dtype .

from_QQ_python(a, K0)[源代码]#

转换Python Fraction 对象到 dtype .

from_RealField(a, K0)[源代码]#

转换mpmath mpf 对象到 dtype .

from_ZZ_gmpy(a, K0)[源代码]#

转换GMPY mpz 对象到 dtype .

from_ZZ_python(a, K0)[源代码]#

转换Python int 对象到 dtype .

from_sympy(a)[源代码]#

Convert SymPy's Integer to dtype.

get_ring()[源代码]#

Returns ring associated with self.

numer(a)[源代码]#

返回的分子 a .

quo(a, b)[源代码]#

ab ,暗示 __truediv__ .

rem(a, b)[源代码]#

剩余 ab ,没有任何含义。

to_sympy(a)[源代码]#

转换 a 对一个同一物体。

class sympy.external.pythonmpq.PythonMPQ(numerator, denominator=None)[源代码]#

Rational number implementation that is intended to be compatible with gmpy2's mpq.

Also slightly faster than fractions.Fraction.

PythonMPQ should be treated as immutable although no effort is made to prevent mutation (since that might slow down calculations).

MPQ#

The MPQ type is either PythonMPQ or otherwise the mpq type from gmpy2.

Gaussian domains#

The Gaussian domains ZZ_I and QQ_I share common superclasses GaussianElement for the domain elements and GaussianDomain for the domains themselves.

class sympy.polys.domains.gaussiandomains.GaussianDomain[源代码]#

Base class for Gaussian domains.

from_AlgebraicField(a, K0)[源代码]#

Convert an element from ZZ<I> or QQ<I> to self.dtype.

from_QQ(a, K0)[源代码]#

Convert a GMPY mpq to self.dtype.

from_QQ_gmpy(a, K0)[源代码]#

Convert a GMPY mpq to self.dtype.

from_QQ_python(a, K0)[源代码]#

Convert a QQ_python element to self.dtype.

from_ZZ(a, K0)[源代码]#

Convert a ZZ_python element to self.dtype.

from_ZZ_gmpy(a, K0)[源代码]#

Convert a GMPY mpz to self.dtype.

from_ZZ_python(a, K0)[源代码]#

Convert a ZZ_python element to self.dtype.

from_sympy(a)[源代码]#

Convert a SymPy object to self.dtype.

inject(*gens)[源代码]#

将生成器注入此域。

is_negative(element)[源代码]#

Returns False for any GaussianElement.

is_nonnegative(element)[源代码]#

Returns False for any GaussianElement.

is_nonpositive(element)[源代码]#

Returns False for any GaussianElement.

is_positive(element)[源代码]#

Returns False for any GaussianElement.

to_sympy(a)[源代码]#

转换 a 对一个同一物体。

class sympy.polys.domains.gaussiandomains.GaussianElement(x, y=0)[源代码]#

Base class for elements of Gaussian type domains.

classmethod new(x, y)[源代码]#

Create a new GaussianElement of the same domain.

parent()[源代码]#

The domain that this is an element of (ZZ_I or QQ_I)

quadrant()[源代码]#

Return quadrant index 0-3.

0 is included in quadrant 0.

ZZ_I#

class sympy.polys.domains.gaussiandomains.GaussianIntegerRing[源代码]#

Ring of Gaussian integers ZZ_I

The ZZ_I domain represents the Gaussian integers \(\mathbb{Z}[i]\) as a Domain in the domain system (see Introducing the Domains of the poly module).

By default a Poly created from an expression with coefficients that are combinations of integers and I (\(\sqrt{-1}\)) will have the domain ZZ_I.

>>> from sympy import Poly, Symbol, I
>>> x = Symbol('x')
>>> p = Poly(x**2 + I)
>>> p
Poly(x**2 + I, x, domain='ZZ_I')
>>> p.domain
ZZ_I

The ZZ_I domain can be used to factorise polynomials that are reducible over the Gaussian integers.

>>> from sympy import factor
>>> factor(x**2 + 1)
x**2 + 1
>>> factor(x**2 + 1, domain='ZZ_I')
(x - I)*(x + I)

The corresponding field of fractions is the domain of the Gaussian rationals QQ_I. Conversely ZZ_I is the ring of integers of QQ_I.

>>> from sympy import ZZ_I, QQ_I
>>> ZZ_I.get_field()
QQ_I
>>> QQ_I.get_ring()
ZZ_I

When using the domain directly ZZ_I can be used as a constructor.

>>> ZZ_I(3, 4)
(3 + 4*I)
>>> ZZ_I(5)
(5 + 0*I)

The domain elements of ZZ_I are instances of GaussianInteger which support the rings operations +,-,*,**.

>>> z1 = ZZ_I(5, 1)
>>> z2 = ZZ_I(2, 3)
>>> z1
(5 + 1*I)
>>> z2
(2 + 3*I)
>>> z1 + z2
(7 + 4*I)
>>> z1 * z2
(7 + 17*I)
>>> z1 ** 2
(24 + 10*I)

Both floor (//) and modulo (%) division work with GaussianInteger (see the div() method).

>>> z3, z4 = ZZ_I(5), ZZ_I(1, 3)
>>> z3 // z4  # floor division
(1 + -1*I)
>>> z3 % z4   # modulo division (remainder)
(1 + -2*I)
>>> (z3//z4)*z4 + z3%z4 == z3
True

True division (/) in ZZ_I gives an element of QQ_I. The exquo() method can be used to divide in ZZ_I when exact division is possible.

>>> z1 / z2
(1 + -1*I)
>>> ZZ_I.exquo(z1, z2)
(1 + -1*I)
>>> z3 / z4
(1/2 + -3/2*I)
>>> ZZ_I.exquo(z3, z4)
Traceback (most recent call last):
    ...
ExactQuotientFailed: (1 + 3*I) does not divide (5 + 0*I) in ZZ_I

The gcd() method can be used to compute the gcd of any two elements.

>>> ZZ_I.gcd(ZZ_I(10), ZZ_I(2))
(2 + 0*I)
>>> ZZ_I.gcd(ZZ_I(5), ZZ_I(2, 1))
(2 + 1*I)
dtype[源代码]#

GaussianInteger 的别名

from_GaussianIntegerRing(a, K0)[源代码]#

Convert a ZZ_I element to ZZ_I.

from_GaussianRationalField(a, K0)[源代码]#

Convert a QQ_I element to ZZ_I.

gcd(a, b)[源代码]#

Greatest common divisor of a and b over ZZ_I.

get_field()[源代码]#

返回与关联的字段 self .

get_ring()[源代码]#

返回与关联的环 self .

lcm(a, b)[源代码]#

Least common multiple of a and b over ZZ_I.

normalize(d, *args)[源代码]#

Return first quadrant element associated with d.

Also multiply the other arguments by the same power of i.

class sympy.polys.domains.gaussiandomains.GaussianInteger(x, y=0)[源代码]#

Gaussian integer: domain element for ZZ_I

>>> from sympy import ZZ_I
>>> z = ZZ_I(2, 3)
>>> z
(2 + 3*I)
>>> type(z)
<class 'sympy.polys.domains.gaussiandomains.GaussianInteger'>

QQ_I#

class sympy.polys.domains.gaussiandomains.GaussianRationalField[源代码]#

Field of Gaussian rationals QQ_I

The QQ_I domain represents the Gaussian rationals \(\mathbb{Q}(i)\) as a Domain in the domain system (see Introducing the Domains of the poly module).

By default a Poly created from an expression with coefficients that are combinations of rationals and I (\(\sqrt{-1}\)) will have the domain QQ_I.

>>> from sympy import Poly, Symbol, I
>>> x = Symbol('x')
>>> p = Poly(x**2 + I/2)
>>> p
Poly(x**2 + I/2, x, domain='QQ_I')
>>> p.domain
QQ_I

The polys option gaussian=True can be used to specify that the domain should be QQ_I even if the coefficients do not contain I or are all integers.

>>> Poly(x**2)
Poly(x**2, x, domain='ZZ')
>>> Poly(x**2 + I)
Poly(x**2 + I, x, domain='ZZ_I')
>>> Poly(x**2/2)
Poly(1/2*x**2, x, domain='QQ')
>>> Poly(x**2, gaussian=True)
Poly(x**2, x, domain='QQ_I')
>>> Poly(x**2 + I, gaussian=True)
Poly(x**2 + I, x, domain='QQ_I')
>>> Poly(x**2/2, gaussian=True)
Poly(1/2*x**2, x, domain='QQ_I')

The QQ_I domain can be used to factorise polynomials that are reducible over the Gaussian rationals.

>>> from sympy import factor, QQ_I
>>> factor(x**2/4 + 1)
(x**2 + 4)/4
>>> factor(x**2/4 + 1, domain='QQ_I')
(x - 2*I)*(x + 2*I)/4
>>> factor(x**2/4 + 1, domain=QQ_I)
(x - 2*I)*(x + 2*I)/4

It is also possible to specify the QQ_I domain explicitly with polys functions like apart().

>>> from sympy import apart
>>> apart(1/(1 + x**2))
1/(x**2 + 1)
>>> apart(1/(1 + x**2), domain=QQ_I)
I/(2*(x + I)) - I/(2*(x - I))

The corresponding ring of integers is the domain of the Gaussian integers ZZ_I. Conversely QQ_I is the field of fractions of ZZ_I.

>>> from sympy import ZZ_I, QQ_I, QQ
>>> ZZ_I.get_field()
QQ_I
>>> QQ_I.get_ring()
ZZ_I

When using the domain directly QQ_I can be used as a constructor.

>>> QQ_I(3, 4)
(3 + 4*I)
>>> QQ_I(5)
(5 + 0*I)
>>> QQ_I(QQ(2, 3), QQ(4, 5))
(2/3 + 4/5*I)

The domain elements of QQ_I are instances of GaussianRational which support the field operations +,-,*,**,/.

>>> z1 = QQ_I(5, 1)
>>> z2 = QQ_I(2, QQ(1, 2))
>>> z1
(5 + 1*I)
>>> z2
(2 + 1/2*I)
>>> z1 + z2
(7 + 3/2*I)
>>> z1 * z2
(19/2 + 9/2*I)
>>> z2 ** 2
(15/4 + 2*I)

True division (/) in QQ_I gives an element of QQ_I and is always exact.

>>> z1 / z2
(42/17 + -2/17*I)
>>> QQ_I.exquo(z1, z2)
(42/17 + -2/17*I)
>>> z1 == (z1/z2)*z2
True

Both floor (//) and modulo (%) division can be used with GaussianRational (see div()) but division is always exact so there is no remainder.

>>> z1 // z2
(42/17 + -2/17*I)
>>> z1 % z2
(0 + 0*I)
>>> QQ_I.div(z1, z2)
((42/17 + -2/17*I), (0 + 0*I))
>>> (z1//z2)*z2 + z1%z2 == z1
True
as_AlgebraicField()[源代码]#

Get equivalent domain as an AlgebraicField.

denom(a)[源代码]#

Get the denominator of a.

dtype[源代码]#

GaussianRational 的别名

from_ComplexField(a, K0)[源代码]#

Convert a ComplexField element to QQ_I.

from_GaussianIntegerRing(a, K0)[源代码]#

Convert a ZZ_I element to QQ_I.

from_GaussianRationalField(a, K0)[源代码]#

Convert a QQ_I element to QQ_I.

get_field()[源代码]#

返回与关联的字段 self .

get_ring()[源代码]#

返回与关联的环 self .

numer(a)[源代码]#

Get the numerator of a.

class sympy.polys.domains.gaussiandomains.GaussianRational(x, y=0)[源代码]#

Gaussian rational: domain element for QQ_I

>>> from sympy import QQ_I, QQ
>>> z = QQ_I(QQ(2, 3), QQ(4, 5))
>>> z
(2/3 + 4/5*I)
>>> type(z)
<class 'sympy.polys.domains.gaussiandomains.GaussianRational'>

QQ<a>#

class sympy.polys.domains.AlgebraicField(dom, *ext, alias=None)[源代码]#

Algebraic number field QQ<a>

A QQ<a> domain represents an algebraic number field \(\mathbb{Q}(a)\) as a Domain in the domain system (see Introducing the Domains of the poly module).

A Poly created from an expression involving algebraic numbers will treat the algebraic numbers as generators if the generators argument is not specified.

>>> from sympy import Poly, Symbol, sqrt
>>> x = Symbol('x')
>>> Poly(x**2 + sqrt(2))
Poly(x**2 + (sqrt(2)), x, sqrt(2), domain='ZZ')

That is a multivariate polynomial with sqrt(2) treated as one of the generators (variables). If the generators are explicitly specified then sqrt(2) will be considered to be a coefficient but by default the EX domain is used. To make a Poly with a QQ<a> domain the argument extension=True can be given.

>>> Poly(x**2 + sqrt(2), x)
Poly(x**2 + sqrt(2), x, domain='EX')
>>> Poly(x**2 + sqrt(2), x, extension=True)
Poly(x**2 + sqrt(2), x, domain='QQ<sqrt(2)>')

A generator of the algebraic field extension can also be specified explicitly which is particularly useful if the coefficients are all rational but an extension field is needed (e.g. to factor the polynomial).

>>> Poly(x**2 + 1)
Poly(x**2 + 1, x, domain='ZZ')
>>> Poly(x**2 + 1, extension=sqrt(2))
Poly(x**2 + 1, x, domain='QQ<sqrt(2)>')

It is possible to factorise a polynomial over a QQ<a> domain using the extension argument to factor() or by specifying the domain explicitly.

>>> from sympy import factor, QQ
>>> factor(x**2 - 2)
x**2 - 2
>>> factor(x**2 - 2, extension=sqrt(2))
(x - sqrt(2))*(x + sqrt(2))
>>> factor(x**2 - 2, domain='QQ<sqrt(2)>')
(x - sqrt(2))*(x + sqrt(2))
>>> factor(x**2 - 2, domain=QQ.algebraic_field(sqrt(2)))
(x - sqrt(2))*(x + sqrt(2))

The extension=True argument can be used but will only create an extension that contains the coefficients which is usually not enough to factorise the polynomial.

>>> p = x**3 + sqrt(2)*x**2 - 2*x - 2*sqrt(2)
>>> factor(p)                         # treats sqrt(2) as a symbol
(x + sqrt(2))*(x**2 - 2)
>>> factor(p, extension=True)
(x - sqrt(2))*(x + sqrt(2))**2
>>> factor(x**2 - 2, extension=True)  # all rational coefficients
x**2 - 2

It is also possible to use QQ<a> with the cancel() and gcd() functions.

>>> from sympy import cancel, gcd
>>> cancel((x**2 - 2)/(x - sqrt(2)))
(x**2 - 2)/(x - sqrt(2))
>>> cancel((x**2 - 2)/(x - sqrt(2)), extension=sqrt(2))
x + sqrt(2)
>>> gcd(x**2 - 2, x - sqrt(2))
1
>>> gcd(x**2 - 2, x - sqrt(2), extension=sqrt(2))
x - sqrt(2)

When using the domain directly QQ<a> can be used as a constructor to create instances which then support the operations +,-,*,**,/. The algebraic_field() method is used to construct a particular QQ<a> domain. The from_sympy() method can be used to create domain elements from normal SymPy expressions.

>>> K = QQ.algebraic_field(sqrt(2))
>>> K
QQ<sqrt(2)>
>>> xk = K.from_sympy(3 + 4*sqrt(2))
>>> xk  
ANP([4, 3], [1, 0, -2], QQ)

Elements of QQ<a> are instances of ANP which have limited printing support. The raw display shows the internal representation of the element as the list [4, 3] representing the coefficients of 1 and sqrt(2) for this element in the form a * sqrt(2) + b * 1 where a and b are elements of QQ. The minimal polynomial for the generator (x**2 - 2) is also shown in the DUP representation as the list [1, 0, -2]. We can use to_sympy() to get a better printed form for the elements and to see the results of operations.

>>> xk = K.from_sympy(3 + 4*sqrt(2))
>>> yk = K.from_sympy(2 + 3*sqrt(2))
>>> xk * yk  
ANP([17, 30], [1, 0, -2], QQ)
>>> K.to_sympy(xk * yk)
17*sqrt(2) + 30
>>> K.to_sympy(xk + yk)
5 + 7*sqrt(2)
>>> K.to_sympy(xk ** 2)
24*sqrt(2) + 41
>>> K.to_sympy(xk / yk)
sqrt(2)/14 + 9/7

Any expression representing an algebraic number can be used to generate a QQ<a> domain provided its minimal polynomial can be computed. The function minpoly() function is used for this.

>>> from sympy import exp, I, pi, minpoly
>>> g = exp(2*I*pi/3)
>>> g
exp(2*I*pi/3)
>>> g.is_algebraic
True
>>> minpoly(g, x)
x**2 + x + 1
>>> factor(x**3 - 1, extension=g)
(x - 1)*(x - exp(2*I*pi/3))*(x + 1 + exp(2*I*pi/3))

It is also possible to make an algebraic field from multiple extension elements.

>>> K = QQ.algebraic_field(sqrt(2), sqrt(3))
>>> K
QQ<sqrt(2) + sqrt(3)>
>>> p = x**4 - 5*x**2 + 6
>>> factor(p)
(x**2 - 3)*(x**2 - 2)
>>> factor(p, domain=K)
(x - sqrt(2))*(x + sqrt(2))*(x - sqrt(3))*(x + sqrt(3))
>>> factor(p, extension=[sqrt(2), sqrt(3)])
(x - sqrt(2))*(x + sqrt(2))*(x - sqrt(3))*(x + sqrt(3))

Multiple extension elements are always combined together to make a single primitive element. In the case of [sqrt(2), sqrt(3)] the primitive element chosen is sqrt(2) + sqrt(3) which is why the domain displays as QQ<sqrt(2) + sqrt(3)>. The minimal polynomial for the primitive element is computed using the primitive_element() function.

>>> from sympy import primitive_element
>>> primitive_element([sqrt(2), sqrt(3)], x)
(x**4 - 10*x**2 + 1, [1, 1])
>>> minpoly(sqrt(2) + sqrt(3), x)
x**4 - 10*x**2 + 1

The extension elements that generate the domain can be accessed from the domain using the ext and orig_ext attributes as instances of AlgebraicNumber. The minimal polynomial for the primitive element as a DMP instance is available as mod.

>>> K = QQ.algebraic_field(sqrt(2), sqrt(3))
>>> K
QQ<sqrt(2) + sqrt(3)>
>>> K.ext
sqrt(2) + sqrt(3)
>>> K.orig_ext
(sqrt(2), sqrt(3))
>>> K.mod  
DMP_Python([1, 0, -10, 0, 1], QQ)

The discriminant of the field can be obtained from the discriminant() method, and an integral basis from the integral_basis() method. The latter returns a list of ANP instances by default, but can be made to return instances of Expr or AlgebraicNumber by passing a fmt argument. The maximal order, or ring of integers, of the field can also be obtained from the maximal_order() method, as a Submodule.

>>> zeta5 = exp(2*I*pi/5)
>>> K = QQ.algebraic_field(zeta5)
>>> K
QQ<exp(2*I*pi/5)>
>>> K.discriminant()
125
>>> K = QQ.algebraic_field(sqrt(5))
>>> K
QQ<sqrt(5)>
>>> K.integral_basis(fmt='sympy')
[1, 1/2 + sqrt(5)/2]
>>> K.maximal_order()
Submodule[[2, 0], [1, 1]]/2

The factorization of a rational prime into prime ideals of the field is computed by the primes_above() method, which returns a list of PrimeIdeal instances.

>>> zeta7 = exp(2*I*pi/7)
>>> K = QQ.algebraic_field(zeta7)
>>> K
QQ<exp(2*I*pi/7)>
>>> K.primes_above(11)
[(11, _x**3 + 5*_x**2 + 4*_x - 1), (11, _x**3 - 4*_x**2 - 5*_x - 1)]

The Galois group of the Galois closure of the field can be computed (when the minimal polynomial of the field is of sufficiently small degree).

>>> K.galois_group(by_name=True)[0]
S6TransitiveSubgroups.C6

笔记

It is not currently possible to generate an algebraic extension over any domain other than QQ. Ideally it would be possible to generate extensions like QQ(x)(sqrt(x**2 - 2)). This is equivalent to the quotient ring QQ(x)[y]/(y**2 - x**2 + 2) and there are two implementations of this kind of quotient ring/extension in the QuotientRing and MonogenicFiniteExtension classes. Each of those implementations needs some work to make them fully usable though.

algebraic_field(*extension, alias=None)[源代码]#

返回一个代数域,即。 \(\mathbb{{Q}}(\alpha, \ldots)\) .

denom(a)[源代码]#

返回的分母 a .

discriminant()[源代码]#

Get the discriminant of the field.

dtype[源代码]#

ANP 的别名

ext#

Primitive element used for the extension.

>>> from sympy import QQ, sqrt
>>> K = QQ.algebraic_field(sqrt(2), sqrt(3))
>>> K.ext
sqrt(2) + sqrt(3)
from_AlgebraicField(a, K0)[源代码]#

将AlgebraicField元素“a”转换为另一个AlgebraicField

from_GaussianIntegerRing(a, K0)[源代码]#

将GaussianInteger元素“a”转换为 dtype .

from_GaussianRationalField(a, K0)[源代码]#

将高斯有理数元素“a”转换为 dtype .

from_QQ(a, K0)[源代码]#

转换Python Fraction 对象到 dtype .

from_QQ_gmpy(a, K0)[源代码]#

转换GMPY mpq 对象到 dtype .

from_QQ_python(a, K0)[源代码]#

转换Python Fraction 对象到 dtype .

from_RealField(a, K0)[源代码]#

转换mpmath mpf 对象到 dtype .

from_ZZ(a, K0)[源代码]#

转换Python int 对象到 dtype .

from_ZZ_gmpy(a, K0)[源代码]#

转换GMPY mpz 对象到 dtype .

from_ZZ_python(a, K0)[源代码]#

转换Python int 对象到 dtype .

from_sympy(a)[源代码]#

将SymPy的表达式转换为 dtype .

galois_group(by_name=False, max_tries=30, randomize=False)[源代码]#

Compute the Galois group of the Galois closure of this field.

实例

If the field is Galois, the order of the group will equal the degree of the field:

>>> from sympy import QQ
>>> from sympy.abc import x
>>> k = QQ.alg_field_from_poly(x**4 + 1)
>>> G, _ = k.galois_group()
>>> G.order()
4

If the field is not Galois, then its Galois closure is a proper extension, and the order of the Galois group will be greater than the degree of the field:

>>> k = QQ.alg_field_from_poly(x**4 - 2)
>>> G, _ = k.galois_group()
>>> G.order()
8
get_ring()[源代码]#

返回与关联的环 self .

integral_basis(fmt=None)[源代码]#

Get an integral basis for the field.

参数:

fmt : str, None, optional (default=None)

If None, return a list of ANP instances. If "sympy", convert each element of the list to an Expr, using self.to_sympy(). If "alg", convert each element of the list to an AlgebraicNumber, using self.to_alg_num().

实例

>>> from sympy import QQ, AlgebraicNumber, sqrt
>>> alpha = AlgebraicNumber(sqrt(5), alias='alpha')
>>> k = QQ.algebraic_field(alpha)
>>> B0 = k.integral_basis()
>>> B1 = k.integral_basis(fmt='sympy')
>>> B2 = k.integral_basis(fmt='alg')
>>> print(B0[1])  
ANP([mpq(1,2), mpq(1,2)], [mpq(1,1), mpq(0,1), mpq(-5,1)], QQ)
>>> print(B1[1])
1/2 + alpha/2
>>> print(B2[1])
alpha/2 + 1/2

In the last two cases we get legible expressions, which print somewhat differently because of the different types involved:

>>> print(type(B1[1]))
<class 'sympy.core.add.Add'>
>>> print(type(B2[1]))
<class 'sympy.core.numbers.AlgebraicNumber'>
is_negative(a)[源代码]#

返回true a 是否定的。

is_nonnegative(a)[源代码]#

返回true a 是非负的。

is_nonpositive(a)[源代码]#

返回true a 是非阳性。

is_positive(a)[源代码]#

返回true a 是肯定的。

maximal_order()[源代码]#

Compute the maximal order, or ring of integers, of the field.

返回:

Submodule.

mod#

Minimal polynomial for the primitive element of the extension.

>>> from sympy import QQ, sqrt
>>> K = QQ.algebraic_field(sqrt(2))
>>> K.mod
DMP([1, 0, -2], QQ)
numer(a)[源代码]#

返回的分子 a .

orig_ext#

Original elements given to generate the extension.

>>> from sympy import QQ, sqrt
>>> K = QQ.algebraic_field(sqrt(2), sqrt(3))
>>> K.orig_ext
(sqrt(2), sqrt(3))
primes_above(p)[源代码]#

Compute the prime ideals lying above a given rational prime p.

to_alg_num(a)[源代码]#

Convert a of dtype to an AlgebraicNumber.

to_sympy(a)[源代码]#

Convert a of dtype to a SymPy object.

RR#

class sympy.polys.domains.RealField(prec=53, dps=None, tol=None)[源代码]#

达到给定精度的实数。

almosteq(a, b, tolerance=None)[源代码]#

检查是否 ab 几乎相等。

exsqrt(a)[源代码]#

Non-negative square root for a >= 0 and None otherwise.

解释

The square root may be slightly inaccurate due to floating point rounding error.

from_sympy(expr)[源代码]#

将SymPy的号码转换为 dtype .

gcd(a, b)[源代码]#

返回的GCD ab .

get_exact()[源代码]#

返回与关联的精确域 self .

get_ring()[源代码]#

返回与关联的环 self .

is_square(a)[源代码]#

Returns True if a >= 0 and False otherwise.

lcm(a, b)[源代码]#

返回的LCM ab .

to_rational(element, limit=True)[源代码]#

把实数转换成有理数。

to_sympy(element)[源代码]#

转换 element 对交响乐号码。

class sympy.polys.domains.mpelements.RealElement(val=(0, 0, 0, 0), **kwargs)[源代码]#

An element of a real domain.

CC#

class sympy.polys.domains.ComplexField(prec=53, dps=None, tol=None)[源代码]#

Complex numbers up to the given precision.

almosteq(a, b, tolerance=None)[源代码]#

检查是否 ab 几乎相等。

exsqrt(a)[源代码]#

Returns the principal complex square root of a.

解释

The argument of the principal square root is always within \((-\frac{\pi}{2}, \frac{\pi}{2}]\). The square root may be slightly inaccurate due to floating point rounding error.

from_sympy(expr)[源代码]#

将SymPy的号码转换为 dtype .

gcd(a, b)[源代码]#

返回的GCD ab .

get_exact()[源代码]#

返回与关联的精确域 self .

get_ring()[源代码]#

返回与关联的环 self .

is_negative(element)[源代码]#

Returns False for any ComplexElement.

is_nonnegative(element)[源代码]#

Returns False for any ComplexElement.

is_nonpositive(element)[源代码]#

Returns False for any ComplexElement.

is_positive(element)[源代码]#

Returns False for any ComplexElement.

is_square(a)[源代码]#

Returns True. Every complex number has a complex square root.

lcm(a, b)[源代码]#

返回的LCM ab .

to_sympy(element)[源代码]#

转换 element 对交响乐号码。

class sympy.polys.domains.mpelements.ComplexElement(real=0, imag=0)[源代码]#

An element of a complex domain.

K[x]#

class sympy.polys.domains.PolynomialRing(domain_or_ring, symbols=None, order=None)[源代码]#

一个表示多元多项式环的类。

factorial(a)[源代码]#

返回的阶乘 \(a\) .

from_AlgebraicField(a, K0)[源代码]#

将代数数转换为 dtype .

from_ComplexField(a, K0)[源代码]#

转换mpmath \(mpf\) 对象到 \(dtype\) .

from_FractionField(a, K0)[源代码]#

将有理函数转换为 dtype .

from_GaussianIntegerRing(a, K0)[源代码]#

转换为 \(GaussianInteger\) 对象到 \(dtype\) .

from_GaussianRationalField(a, K0)[源代码]#

转换为 \(GaussianRational\) 对象到 \(dtype\) .

from_GlobalPolynomialRing(a, K0)[源代码]#

Convert from old poly ring to dtype.

from_PolynomialRing(a, K0)[源代码]#

将多项式转换为 dtype .

from_QQ(a, K0)[源代码]#

转换Python \(Fraction\) 对象到 \(dtype\) .

from_QQ_gmpy(a, K0)[源代码]#

转换GMPY \(mpq\) 对象到 \(dtype\) .

from_QQ_python(a, K0)[源代码]#

转换Python \(Fraction\) 对象到 \(dtype\) .

from_RealField(a, K0)[源代码]#

转换mpmath \(mpf\) 对象到 \(dtype\) .

from_ZZ(a, K0)[源代码]#

转换Python \(int\) 对象到 \(dtype\) .

from_ZZ_gmpy(a, K0)[源代码]#

转换GMPY \(mpz\) 对象到 \(dtype\) .

from_ZZ_python(a, K0)[源代码]#

转换Python \(int\) 对象到 \(dtype\) .

from_sympy(a)[源代码]#

将SymPy的表达式转换为 \(dtype\) .

gcd(a, b)[源代码]#

返回的GCD \(a\)\(b\) .

gcdex(a, b)[源代码]#

扩展GCD \(a\)\(b\) .

get_field()[源代码]#

返回与关联的字段 \(self\) .

is_negative(a)[源代码]#

返回true \(LC(a)\) 是否定的。

is_nonnegative(a)[源代码]#

返回true \(LC(a)\) 是非负的。

is_nonpositive(a)[源代码]#

返回true \(LC(a)\) 是非阳性。

is_positive(a)[源代码]#

返回true \(LC(a)\) 是肯定的。

is_unit(a)[源代码]#

Returns True if a is a unit of self

lcm(a, b)[源代码]#

返回的LCM \(a\)\(b\) .

to_sympy(a)[源代码]#

转换 \(a\) 对一个同一物体。

K(x)#

class sympy.polys.domains.FractionField(domain_or_field, symbols=None, order=None)[源代码]#

一个表示多元有理函数域的类。

denom(a)[源代码]#

返回的分母 a .

factorial(a)[源代码]#

Returns factorial of a.

from_AlgebraicField(a, K0)[源代码]#

将代数数转换为 dtype .

from_ComplexField(a, K0)[源代码]#

转换mpmath mpf 对象到 dtype .

from_FractionField(a, K0)[源代码]#

将有理函数转换为 dtype .

from_GaussianIntegerRing(a, K0)[源代码]#

Convert a GaussianInteger object to dtype.

from_GaussianRationalField(a, K0)[源代码]#

转换为 GaussianRational 对象到 dtype .

from_PolynomialRing(a, K0)[源代码]#

将多项式转换为 dtype .

from_QQ(a, K0)[源代码]#

转换Python Fraction 对象到 dtype .

from_QQ_gmpy(a, K0)[源代码]#

转换GMPY mpq 对象到 dtype .

from_QQ_python(a, K0)[源代码]#

转换Python Fraction 对象到 dtype .

from_RealField(a, K0)[源代码]#

转换mpmath mpf 对象到 dtype .

from_ZZ(a, K0)[源代码]#

转换Python int 对象到 dtype .

from_ZZ_gmpy(a, K0)[源代码]#

转换GMPY mpz 对象到 dtype .

from_ZZ_python(a, K0)[源代码]#

转换Python int 对象到 dtype .

from_sympy(a)[源代码]#

将SymPy的表达式转换为 dtype .

get_ring()[源代码]#

返回与关联的字段 self .

is_negative(a)[源代码]#

Returns True if LC(a) is negative.

is_nonnegative(a)[源代码]#

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

is_nonpositive(a)[源代码]#

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

is_positive(a)[源代码]#

Returns True if LC(a) is positive.

numer(a)[源代码]#

返回的分子 a .

to_sympy(a)[源代码]#

转换 a 对一个同一物体。

EX#

class sympy.polys.domains.ExpressionDomain[源代码]#

用于任意表达式的类。

class Expression(ex)[源代码]#

武断的表达。

denom(a)[源代码]#

返回的分母 a .

dtype[源代码]#

Expression 的别名

from_AlgebraicField(a, K0)[源代码]#

Convert an ANP object to dtype.

from_ComplexField(a, K0)[源代码]#

Convert a mpmath mpc object to dtype.

from_ExpressionDomain(a, K0)[源代码]#

转换为 EX 对象到 dtype .

from_FractionField(a, K0)[源代码]#

转换为 DMF 对象到 dtype .

from_GaussianIntegerRing(a, K0)[源代码]#

转换为 GaussianRational 对象到 dtype .

from_GaussianRationalField(a, K0)[源代码]#

转换为 GaussianRational 对象到 dtype .

from_PolynomialRing(a, K0)[源代码]#

转换为 DMP 对象到 dtype .

from_QQ(a, K0)[源代码]#

转换Python Fraction 对象到 dtype .

from_QQ_gmpy(a, K0)[源代码]#

转换GMPY mpq 对象到 dtype .

from_QQ_python(a, K0)[源代码]#

转换Python Fraction 对象到 dtype .

from_RealField(a, K0)[源代码]#

转换mpmath mpf 对象到 dtype .

from_ZZ(a, K0)[源代码]#

转换Python int 对象到 dtype .

from_ZZ_gmpy(a, K0)[源代码]#

转换GMPY mpz 对象到 dtype .

from_ZZ_python(a, K0)[源代码]#

转换Python int 对象到 dtype .

from_sympy(a)[源代码]#

将SymPy的表达式转换为 dtype .

get_field()[源代码]#

返回与关联的字段 self .

get_ring()[源代码]#

返回与关联的环 self .

is_negative(a)[源代码]#

返回true a 是否定的。

is_nonnegative(a)[源代码]#

返回true a 是非负的。

is_nonpositive(a)[源代码]#

返回true a 是非阳性。

is_positive(a)[源代码]#

返回true a 是肯定的。

numer(a)[源代码]#

返回的分子 a .

to_sympy(a)[源代码]#

转换 a 对一个同一物体。

class ExpressionDomain.Expression(ex)[源代码]#

武断的表达。

Quotient ring#

class sympy.polys.domains.quotientring.QuotientRing(ring, ideal)[源代码]#

表示(交换)商环的类。

通常不应该手动实例化它,而是在构造中使用基环中的构造函数。

>>> from sympy.abc import x
>>> from sympy import QQ
>>> I = QQ.old_poly_ring(x).ideal(x**3 + 1)
>>> QQ.old_poly_ring(x).quotient_ring(I)
QQ[x]/<x**3 + 1>

可以使用较短的版本:

>>> QQ.old_poly_ring(x)/I
QQ[x]/<x**3 + 1>
>>> QQ.old_poly_ring(x)/[x**3 + 1]
QQ[x]/<x**3 + 1>

属性:

  • 环-基环

  • 基本理想-用来形成商的理想

Sparse polynomials#

稀疏多项式用字典表示。

sympy.polys.rings.ring(symbols, domain, order=LexOrder())[源代码]#

构造多项式环返回 (ring, x_1, ..., x_n) .

参数:

符号 :结构

Symbol/Expr或str序列,Symbol/Expr(非空)

: Domain 或者强制的

秩序 : MonomialOrder 或者强制的,可选的,默认为 lex

实例

>>> from sympy.polys.rings import ring
>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.orderings import lex
>>> R, x, y, z = ring("x,y,z", ZZ, lex)
>>> R
Polynomial ring in x, y, z over ZZ with lex order
>>> x + y + z
x + y + z
>>> type(_)
<class 'sympy.polys.rings.PolyElement'>
sympy.polys.rings.xring(symbols, domain, order=LexOrder())[源代码]#

构造多项式环返回 (ring, (x_1, ..., x_n)) .

参数:

符号 :结构

Symbol/Expr或str序列,Symbol/Expr(非空)

: Domain 或者强制的

秩序 : MonomialOrder 或者强制的,可选的,默认为 lex

实例

>>> from sympy.polys.rings import xring
>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.orderings import lex
>>> R, (x, y, z) = xring("x,y,z", ZZ, lex)
>>> R
Polynomial ring in x, y, z over ZZ with lex order
>>> x + y + z
x + y + z
>>> type(_)
<class 'sympy.polys.rings.PolyElement'>
sympy.polys.rings.vring(symbols, domain, order=LexOrder())[源代码]#

构造多项式环并注入 x_1, ..., x_n 在全局命名空间中。

参数:

符号 :结构

Symbol/Expr或str序列,Symbol/Expr(非空)

: Domain 或者强制的

秩序 : MonomialOrder 或者强制的,可选的,默认为 lex

实例

>>> from sympy.polys.rings import vring
>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.orderings import lex
>>> vring("x,y,z", ZZ, lex)
Polynomial ring in x, y, z over ZZ with lex order
>>> x + y + z # noqa:
x + y + z
>>> type(_)
<class 'sympy.polys.rings.PolyElement'>
sympy.polys.rings.sring(exprs, *symbols, **options)[源代码]#

构造一个从选项和输入表达式派生生成器和域的环。

参数:

专家 : Expr 或序列 Expr (可解释)

符号 : sequence of Symbol/Expr

选项 : keyword arguments understood by Options

实例

>>> from sympy import sring, symbols
>>> x, y, z = symbols("x,y,z")
>>> R, f = sring(x + 2*y + 3*z)
>>> R
Polynomial ring in x, y, z over ZZ with lex order
>>> f
x + 2*y + 3*z
>>> type(_)
<class 'sympy.polys.rings.PolyElement'>
class sympy.polys.rings.PolyRing(symbols, domain, order=LexOrder())[源代码]#

多元分布多项式环。

add(*objs)[源代码]#

添加多项式序列或多项式容器。

实例

>>> from sympy.polys.rings import ring
>>> from sympy.polys.domains import ZZ
>>> 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)])
add_gens(symbols)[源代码]#

添加元素 symbols 作为发电机 self

compose(other)[源代码]#

添加的生成器 otherself

drop(*gens)[源代码]#

从该环上拆下指定的发电机。

drop_to_ground(*gens)[源代码]#

从环中删除指定的生成器并将其注入其域。

index(gen)[源代码]#

计算的索引 gen 在里面 self.gens .

monomial_basis(i)[源代码]#

返回第i个基元素。

mul(*objs)[源代码]#

将多项式序列或多项式容器相乘。

实例

>>> from sympy.polys.rings import ring
>>> from sympy.polys.domains import ZZ
>>> 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)])
symmetric_poly(n)[源代码]#

Return the elementary symmetric polynomial of degree n over this ring's generators.

class sympy.polys.rings.PolyElement[源代码]#

多元分布多项式环的元素。

almosteq(p2, tolerance=None)[源代码]#

多项式的近似相等检验。

cancel(g)[源代码]#

消去有理函数中的公因式 f/g .

实例

>>> from sympy.polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> (2*x**2 - 2).cancel(x**2 - 2*x + 1)
(2*x + 2, x - 1)
coeff(element)[源代码]#

返回给定单项式旁边的系数。

参数:

要素 :聚元素(带 is_monomial = True )或1

实例

>>> from sympy.polys.rings import ring
>>> from sympy.polys.domains import ZZ
>>> _, x, y, z = ring("x,y,z", ZZ)
>>> f = 3*x**2*y - x*y*z + 7*z**3 + 23
>>> f.coeff(x**2*y)
3
>>> f.coeff(x*y)
0
>>> f.coeff(1)
23
coeff_wrt(x, deg)[源代码]#

Coefficient of self with respect to x**deg.

Treating self as a univariate polynomial in x this finds the coefficient of x**deg as a polynomial in the other generators.

参数:

x : generator or generator index

The generator or generator index to compute the expression for.

deg : int

The degree of the monomial to compute the expression for.

返回:

PolyElement

The coefficient of x**deg as a polynomial in the same ring.

实例

>>> from sympy.polys import ring, ZZ
>>> R, x, y, z = ring("x, y, z", ZZ)
>>> p = 2*x**4 + 3*y**4 + 10*z**2 + 10*x*z**2
>>> deg = 2
>>> p.coeff_wrt(2, deg) # Using the generator index
10*x + 10
>>> p.coeff_wrt(z, deg) # Using the generator
10*x + 10
>>> p.coeff(z**2) # shows the difference between coeff and coeff_wrt
10

参见

coeff, coeffs

coeffs(order=None)[源代码]#

多项式系数的有序列表。

参数:

秩序 : MonomialOrder 或者强制的,可选的

实例

>>> from sympy.polys.rings import ring
>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.orderings import lex, grlex
>>> _, x, y = ring("x, y", ZZ, lex)
>>> f = x*y**7 + 2*x**2*y**3
>>> f.coeffs()
[2, 1]
>>> f.coeffs(grlex)
[1, 2]
const()[源代码]#

Returns the constant coefficient.

content()[源代码]#

返回多项式系数的GCD。

copy()[源代码]#

返回多项式self的副本。

多项式是可变的;如果一个人对保存一个多项式感兴趣,并且打算使用就地操作,那么就可以复制多项式。这种方法复制得很浅。

实例

>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.rings import ring
>>> R, x, y = ring('x, y', ZZ)
>>> p = (x + y)**2
>>> p1 = p.copy()
>>> p2 = p
>>> p[R.zero_monom] = 3
>>> p
x**2 + 2*x*y + y**2 + 3
>>> p1
x**2 + 2*x*y + y**2
>>> p2
x**2 + 2*x*y + y**2 + 3
degree(x=None)[源代码]#

x 或主变量。

Note that the degree of 0 is negative infinity (float('-inf'))

degrees()[源代码]#

在所有变量中包含前导度数的元组。

Note that the degree of 0 is negative infinity (float('-inf'))

diff(x)[源代码]#

计算偏导数 x .

实例

>>> from sympy.polys.rings import ring
>>> from sympy.polys.domains import ZZ
>>> _, x, y = ring("x,y", ZZ)
>>> p = x + x**2*y**3
>>> p.diff(x)
2*x*y**3 + 1
div(fv)[源代码]#

除法算法,参见 [CLO] 第64页。

fv多项式数组

返回qv,r,使self=sum(fv [i] *质量标准 [i] )+r型

要求所有多项式不是Laurent多项式。

实例

>>> from sympy.polys.rings import ring
>>> from sympy.polys.domains import ZZ
>>> _, x, y = ring('x, y', ZZ)
>>> f = x**3
>>> f0 = x - y**2
>>> f1 = x - y
>>> qv, r = f.div((f0, f1))
>>> qv[0]
x**2 + x*y**2 + y**4
>>> qv[1]
0
>>> r
y**6
imul_num(c)[源代码]#

如果p不是生成元之一,则将多项式p与系数环中的一个元素同位相乘;否则,不进行就地乘法

实例

>>> from sympy.polys.rings import ring
>>> from sympy.polys.domains import ZZ
>>> _, x, y = ring('x, y', ZZ)
>>> p = x + y**2
>>> p1 = p.imul_num(3)
>>> p1
3*x + 3*y**2
>>> p1 is p
True
>>> p = x
>>> p1 = p.imul_num(3)
>>> p1
3*x
>>> p1 is p
False
itercoeffs()[源代码]#

多项式系数上的迭代器。

itermonoms()[源代码]#

多项式单项式上的迭代器。

iterterms()[源代码]#

多项式项上的迭代器。

leading_expv()[源代码]#

根据单项式的顺序引导单项式元组。

实例

>>> from sympy.polys.rings import ring
>>> from sympy.polys.domains import ZZ
>>> _, x, y, z = ring('x, y, z', ZZ)
>>> p = x**4 + x**3*y + x**2*z**2 + z**7
>>> p.leading_expv()
(4, 0, 0)
leading_monom()[源代码]#

作为多项式元素的前导单项式。

实例

>>> from sympy.polys.rings import ring
>>> from sympy.polys.domains import ZZ
>>> _, x, y = ring('x, y', ZZ)
>>> (3*x*y + y**2).leading_monom()
x*y
leading_term()[源代码]#

作为多项式元素的前导项。

实例

>>> from sympy.polys.rings import ring
>>> from sympy.polys.domains import ZZ
>>> _, x, y = ring('x, y', ZZ)
>>> (3*x*y + y**2).leading_term()
3*x*y
listcoeffs()[源代码]#

多项式系数的无序列表。

listmonoms()[源代码]#

多项式单项式的无序列表。

listterms()[源代码]#

多项式项的无序列表。

monic()[源代码]#

将所有系数除以前导系数。

monoms(order=None)[源代码]#

多项式单项式的有序列表。

参数:

秩序 : MonomialOrder 或者强制的,可选的

实例

>>> from sympy.polys.rings import ring
>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.orderings import lex, grlex
>>> _, x, y = ring("x, y", ZZ, lex)
>>> f = x*y**7 + 2*x**2*y**3
>>> f.monoms()
[(2, 3), (1, 7)]
>>> f.monoms(grlex)
[(1, 7), (2, 3)]
pdiv(g, x=None)[源代码]#

Computes the pseudo-division of the polynomial self with respect to g.

The pseudo-division algorithm is used to find the pseudo-quotient q and pseudo-remainder r such that m*f = g*q + r, where m represents the multiplier and f is the dividend polynomial.

The pseudo-quotient q and pseudo-remainder r are polynomials in the variable x, with the degree of r with respect to x being strictly less than the degree of g with respect to x.

The multiplier m is defined as LC(g, x) ^ (deg(f, x) - deg(g, x) + 1), where LC(g, x) represents the leading coefficient of g.

It is important to note that in the context of the prem method, multivariate polynomials in a ring, such as R[x,y,z], are treated as univariate polynomials with coefficients that are polynomials, such as R[x,y][z]. When dividing f by g with respect to the variable z, the pseudo-quotient q and pseudo-remainder r satisfy m*f = g*q + r, where deg(r, z) < deg(g, z) and m = LC(g, z)^(deg(f, z) - deg(g, z) + 1).

In this function, the pseudo-remainder r can be obtained using the prem method, the pseudo-quotient q can be obtained using the pquo method, and the function pdiv itself returns a tuple (q, r).

参数:

g : PolyElement

The polynomial to divide self by.

x : generator or generator index, optional

The main variable of the polynomials and default is first generator.

返回:

PolyElement

The pseudo-division polynomial (tuple of q and r).

加薪:

ZeroDivisionError : If g is the zero polynomial.

实例

>>> from sympy.polys import ring, ZZ
>>> R, x, y = ring("x, y", ZZ)
>>> f = x**2 + x*y
>>> g = 2*x + 2
>>> f.pdiv(g) # first generator is chosen by default if it is not given
(2*x + 2*y - 2, -4*y + 4)
>>> f.div(g) # shows the difference between pdiv and div
(0, x**2 + x*y)
>>> f.pdiv(g, y) # generator is given
(2*x**3 + 2*x**2*y + 6*x**2 + 2*x*y + 8*x + 4, 0)
>>> f.pdiv(g, 1) # generator index is given
(2*x**3 + 2*x**2*y + 6*x**2 + 2*x*y + 8*x + 4, 0)

参见

prem

Computes only the pseudo-remainder more efficiently than \(f.pdiv(g)[1]\).

pquo

Returns only the pseudo-quotient.

pexquo

Returns only an exact pseudo-quotient having no remainder.

div

Returns quotient and remainder of f and g polynomials.

pexquo(g, x=None)[源代码]#

Polynomial exact pseudo-quotient in multivariate polynomial ring.

实例

>>> from sympy.polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> f = x**2 + x*y
>>> g = 2*x + 2*y
>>> h = 2*x + 2
>>> f.pexquo(g)
2*x
>>> f.exquo(g) # shows the differnce between pexquo and exquo
Traceback (most recent call last):
...
ExactQuotientFailed: 2*x + 2*y does not divide x**2 + x*y
>>> f.pexquo(h)
Traceback (most recent call last):
...
ExactQuotientFailed: 2*x + 2 does not divide x**2 + x*y
pquo(g, x=None)[源代码]#

Polynomial pseudo-quotient in multivariate polynomial ring.

实例

>>> from sympy.polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> f = x**2 + x*y
>>> g = 2*x + 2*y
>>> h = 2*x + 2
>>> f.pquo(g)
2*x
>>> f.quo(g) # shows the difference between pquo and quo
0
>>> f.pquo(h)
2*x + 2*y - 2
>>> f.quo(h) # shows the difference between pquo and quo
0
prem(g, x=None)[源代码]#

Pseudo-remainder of the polynomial self with respect to g.

The pseudo-quotient q and pseudo-remainder r with respect to z when dividing f by g satisfy m*f = g*q + r, where deg(r,z) < deg(g,z) and m = LC(g,z)**(deg(f,z) - deg(g,z)+1).

See pdiv() for explanation of pseudo-division.

参数:

g : PolyElement

The polynomial to divide self by.

x : generator or generator index, optional

The main variable of the polynomials and default is first generator.

返回:

PolyElement

The pseudo-remainder polynomial.

加薪:

ZeroDivisionError : If g is the zero polynomial.

实例

>>> from sympy.polys import ring, ZZ
>>> R, x, y = ring("x, y", ZZ)
>>> f = x**2 + x*y
>>> g = 2*x + 2
>>> f.prem(g) # first generator is chosen by default if it is not given
-4*y + 4
>>> f.rem(g) # shows the differnce between prem and rem
x**2 + x*y
>>> f.prem(g, y) # generator is given
0
>>> f.prem(g, 1) # generator index is given
0
primitive()[源代码]#

返回内容和原始多项式。

square()[源代码]#

多项式的平方

实例

>>> from sympy.polys.rings import ring
>>> from sympy.polys.domains import ZZ
>>> _, x, y = ring('x, y', ZZ)
>>> p = x + y**2
>>> p.square()
x**2 + 2*x*y**2 + y**4
strip_zero()[源代码]#

消除系数为零的单项式。

subresultants(g, x=None)[源代码]#

Computes the subresultant PRS of two polynomials self and g.

参数:

g : PolyElement

The second polynomial.

x : generator or generator index

The variable with respect to which the subresultant sequence is computed.

返回:

R : list

Returns a list polynomials representing the subresultant PRS.

实例

>>> from sympy.polys import ring, ZZ
>>> R, x, y = ring("x, y", ZZ)
>>> f = x**2*y + x*y
>>> g = x + y
>>> f.subresultants(g) # first generator is chosen by default if not given
[x**2*y + x*y, x + y, y**3 - y**2]
>>> f.subresultants(g, 0) # generator index is given
[x**2*y + x*y, x + y, y**3 - y**2]
>>> f.subresultants(g, y) # generator is given
[x**2*y + x*y, x + y, x**3 + x**2]
symmetrize()[源代码]#

Rewrite self in terms of elementary symmetric polynomials.

返回:

Triple (p, r, m)

p is a PolyElement that represents our attempt to express self as a function of elementary symmetric polynomials. Each variable in p stands for one of the elementary symmetric polynomials. The correspondence is given by m.

r is the remainder.

m is a list of pairs, giving the mapping from variables in p to elementary symmetric polynomials.

The triple satisfies the equation p.compose(m) + r == self. If the remainder r is zero, self is symmetric. If it is nonzero, we were not able to represent self as symmetric.

解释

If this PolyElement belongs to a ring of \(n\) variables, we can try to write it as a function of the elementary symmetric polynomials on \(n\) variables. We compute a symmetric part, and a remainder for any part we were not able to symmetrize.

实例

>>> from sympy.polys.rings import ring
>>> from sympy.polys.domains import ZZ
>>> R, x, y = ring("x,y", ZZ)
>>> f = x**2 + y**2
>>> f.symmetrize()
(x**2 - 2*y, 0, [(x, x + y), (y, x*y)])
>>> f = x**2 - y**2
>>> f.symmetrize()
(x**2 - 2*y, -2*y**2, [(x, x + y), (y, x*y)])

工具书类

[R783]

Lauer, E. Algorithms for symmetrical polynomials, Proc. 1976 ACM Symp. on Symbolic and Algebraic Computing, NY 242-247. https://dl.acm.org/doi/pdf/10.1145/800205.806342

tail_degree(x=None)[源代码]#

尾度数 x 或主变量。

Note that the degree of 0 is negative infinity (float('-inf'))

tail_degrees()[源代码]#

包含所有变量尾度数的元组。

Note that the degree of 0 is negative infinity (float('-inf'))

terms(order=None)[源代码]#

多项式项的有序列表。

参数:

秩序 : MonomialOrder 或者强制的,可选的

实例

>>> from sympy.polys.rings import ring
>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.orderings import lex, grlex
>>> _, x, y = ring("x, y", ZZ, lex)
>>> f = x*y**7 + 2*x**2*y**3
>>> f.terms()
[((2, 3), 2), ((1, 7), 1)]
>>> f.terms(grlex)
[((1, 7), 1), ((2, 3), 2)]

Sparse rational functions#

稀疏多项式用字典表示。

sympy.polys.fields.field(symbols, domain, order=LexOrder())[源代码]#

Construct new rational function field returning (field, x1, ..., xn).

sympy.polys.fields.xfield(symbols, domain, order=LexOrder())[源代码]#

Construct new rational function field returning (field, (x1, ..., xn)).

sympy.polys.fields.vfield(symbols, domain, order=LexOrder())[源代码]#

Construct new rational function field and inject generators into global namespace.

sympy.polys.fields.sfield(exprs, *symbols, **options)[源代码]#

Construct a field deriving generators and domain from options and input expressions.

参数:

exprs : py:class:\(~.Expr\) or sequence of Expr (sympifiable)

symbols : sequence of Symbol/Expr

options : keyword arguments understood by Options

实例

>>> from sympy import exp, log, symbols, sfield
>>> x = symbols("x")
>>> K, f = sfield((x*log(x) + 4*x**2)*exp(1/x + log(x)/3)/x**2)
>>> K
Rational function field in x, exp(1/x), log(x), x**(1/3) over ZZ with lex order
>>> f
(4*x**2*(exp(1/x)) + x*(exp(1/x))*(log(x)))/((x**(1/3))**5)
class sympy.polys.fields.FracField(symbols, domain, order=LexOrder())[源代码]#

Multivariate distributed rational function field.

class sympy.polys.fields.FracElement(numer, denom=None)[源代码]#

Element of multivariate distributed rational function field.

diff(x)[源代码]#

计算偏导数 x .

实例

>>> from sympy.polys.fields import field
>>> from sympy.polys.domains import ZZ
>>> _, x, y, z = field("x,y,z", ZZ)
>>> ((x**2 + y)/(z + 1)).diff(x)
2*x/(z + 1)

Dense polynomials#

class sympy.polys.polyclasses.DMP(rep, dom, lev=None)[源代码]#

稠密多元多项式 \(K\) .

LC()[源代码]#

返回的前导系数 f .

TC()[源代码]#

返回的尾随系数 f .

abs()[源代码]#

使所有系数 f 肯定的。

add(g)[源代码]#

加两个多元多项式 fg .

add_ground(c)[源代码]#

将一个基域元素添加到 f .

all_coeffs()[源代码]#

返回所有系数 f .

all_monoms()[源代码]#

返回来自的所有单项式 f .

all_terms()[源代码]#

返回来自 f .

cancel(g, include=True)[源代码]#

消去有理函数中的公因式 f/g .

cauchy_lower_bound()[源代码]#

Computes the Cauchy lower bound on the nonzero roots of f.

cauchy_upper_bound()[源代码]#

Computes the Cauchy upper bound on the roots of f.

clear_denoms()[源代码]#

清除分母,但保留基域。

coeffs(order=None)[源代码]#

返回所有非零系数 f 以法律程序。

cofactors(g)[源代码]#

返回的GCD fg 以及它们的辅助因子。

compose(g)[源代码]#

计算 fg .

content()[源代码]#

返回多项式系数的GCD。

convert(dom)[源代码]#

Convert f to a DMP over the new domain.

count_complex_roots(inf=None, sup=None)[源代码]#

返回 f 在里面 [inf, sup] .

count_real_roots(inf=None, sup=None)[源代码]#

返回的实根数 f 在里面 [inf, sup] .

decompose()[源代码]#

计算函数分解 f .

deflate()[源代码]#

降低 \(f\) 通过映射 \(x_i^m\)\(y_i\) .

degree(j=0)[源代码]#

返回的前导度数 f 在里面 x_j .

degree_list()[源代码]#

返回的度数列表 f .

diff(m=1, j=0)[源代码]#

计算 m -的一阶导数 f 在里面 x_j .

discriminant()[源代码]#

计算判别式 f .

div(g)[源代码]#

余数多项式除法 fg .

eject(dom, front=False)[源代码]#

将选定的发电机发射到地面区域。

eval(a, j=0)[源代码]#

评估 f 在给定点 a 在里面 x_j .

exclude()[源代码]#

把无用的发电机从 f .

返回移除的生成器和排除的新生成器 f .

实例

>>> from sympy.polys.polyclasses import DMP
>>> from sympy.polys.domains import ZZ
>>> DMP([[[ZZ(1)]], [[ZZ(1)], [ZZ(2)]]], ZZ).exclude()
([2], DMP_Python([[1], [1, 2]], ZZ))
exquo(g)[源代码]#

计算多项式精确商 fg .

exquo_ground(c)[源代码]#

精确商 f 通过一个基域的元素。

factor_list()[源代码]#

返回的不可约因子的列表 f .

factor_list_include()[源代码]#

返回的不可约因子的列表 f .

classmethod from_list(rep, lev, dom)[源代码]#

创建的实例 cls 给出一个本地系数的列表。

classmethod from_sympy_list(rep, lev, dom)[源代码]#

创建的实例 cls 给出了一个sypy系数的列表。

gcd(g)[源代码]#

返回的多项式GCD fg .

gcdex(g)[源代码]#

扩展欧几里德算法,如果是单变量的。

gff_list()[源代码]#

计算的最大因式分解 f .

ground_new(coeff)[源代码]#

Construct a new ground instance of f.

half_gcdex(g)[源代码]#

半扩展欧几里德算法,如果是单变量的。

homogeneous_order()[源代码]#

返回的同构顺序 f .

homogenize(s)[源代码]#

返回的齐次多项式 f

inject(front=False)[源代码]#

将地域发生器注入 f .

integrate(m=1, j=0)[源代码]#

计算 m -的一阶不定积分 f 在里面 x_j .

intervals(all=False, eps=None, inf=None, sup=None, fast=False, sqf=False)[源代码]#

计算根的隔离间隔 f .

invert(g)[源代码]#

使转化 fg ,如果可能的话。

property is_cyclotomic#

返回 True 如果 f 是一个分圆多项式。

property is_ground#

返回 True 如果 f 是地域的一个元素。

property is_homogeneous#

返回 True 如果 f 是一个齐次多项式。

property is_irreducible#

返回 True 如果 f 在它的领域内没有任何因素。

property is_linear#

返回 True 如果 f 所有变量都是线性的。

property is_monic#

返回 True 如果 f 是一个。

property is_monomial#

返回 True 如果 f 为零或只有一个项。

property is_one#

返回 True 如果 f 是单位多项式。

property is_primitive#

返回 True 如果 f 是一个。

property is_quadratic#

返回 True 如果 f 所有变量都是二次的。

property is_sqf#

返回 True 如果 f 是一个无平方多项式。

property is_zero#

返回 True 如果 f 是一个零多项式。

l1_norm()[源代码]#

返回的l1范数 f .

l2_norm_squared()[源代码]#

Return squared l2 norm of f.

lcm(g)[源代码]#

返回的多项式LCM fg .

lift()[源代码]#

将代数系数转换为有理数。

max_norm()[源代码]#

返回最大范数 f .

mignotte_sep_bound_squared()[源代码]#

Computes the squared Mignotte bound on root separations of f.

monic()[源代码]#

将所有系数除以 LC(f) .

monoms(order=None)[源代码]#

从返回所有非零单项式 f 以法律程序。

mul(g)[源代码]#

两个多元多项式相乘 fg .

mul_ground(c)[源代码]#

乘法 f 通过一个基域的元素。

neg()[源代码]#

取中的所有系数 f .

norm()[源代码]#

计算 Norm(f) .

nth(*N)[源代码]#

返回 n -th系数 f .

pdiv(g)[源代码]#

多项式伪除法 fg .

permute(P)[源代码]#

返回一个多项式 \(K[x_{{P(1)}}, ..., x_{{P(n)}}]\) .

实例

>>> from sympy.polys.polyclasses import DMP
>>> from sympy.polys.domains import ZZ
>>> DMP([[[ZZ(2)], [ZZ(1), ZZ(0)]], [[]]], ZZ).permute([1, 0, 2])
DMP_Python([[[2], []], [[1, 0], []]], ZZ)
>>> DMP([[[ZZ(2)], [ZZ(1), ZZ(0)]], [[]]], ZZ).permute([1, 2, 0])
DMP_Python([[[1], []], [[2, 0], []]], ZZ)
pexquo(g)[源代码]#

多项式精确伪商 fg .

pow(n)[源代码]#

提高 f 非负幂 n .

pquo(g)[源代码]#

多项式伪商 fg .

prem(g)[源代码]#

多项式伪余数 fg .

primitive()[源代码]#

返回内容和 f .

quo(g)[源代码]#

计算的多项式商 fg .

quo_ground(c)[源代码]#

f 通过一个基域的元素。

refine_root(s, t, eps=None, steps=None, fast=False)[源代码]#

将隔离间隔细化到给定的精度。

eps 应该是有理数。

rem(g)[源代码]#

计算的多项式余数 fg .

property rep#

Get the representation of f.

resultant(g, includePRS=False)[源代码]#

计算的结果 fg 通过PRS。

revert(n)[源代码]#

计算 f**(-1) 国防部 x**n .

shift(a)[源代码]#

有效计算泰勒位移 f(x + a) .

slice(m, n, j=0)[源代码]#

取连续的子项序列 f .

sqf_list(all=False)[源代码]#

返回无平方因子的列表 f .

sqf_list_include(all=False)[源代码]#

返回无平方因子的列表 f .

sqf_norm()[源代码]#

计算平方自由范数 f .

sqf_part()[源代码]#

计算的平方自由部分 f .

sqr()[源代码]#

多元多项式平方 f .

sturm()[源代码]#

计算的Sturm序列 f .

sub(g)[源代码]#

减去两个多元多项式 fg .

sub_ground(c)[源代码]#

从中减去基域的一个元素 f .

subresultants(g)[源代码]#

计算的子结果PRS序列 fg .

terms(order=None)[源代码]#

从返回所有非零项 f 以法律程序。

terms_gcd()[源代码]#

从多项式中删除项的GCD f .

to_best()[源代码]#

Convert to DUP_Flint if possible.

This method should be used when the domain or level is changed and it potentially becomes possible to convert from DMP_Python to DUP_Flint.

to_dict(zero=False)[源代码]#

转换 f 以本机系数表示dict。

to_exact()[源代码]#

使地面域精确。

to_field()[源代码]#

使地面域成为一个场。

to_list()[源代码]#

转换 f 到具有本机系数的列表表示。

to_ring()[源代码]#

把地域变成一个环。

to_sympy_dict(zero=False)[源代码]#

转换 f 对具有共系数的dict表示。

to_sympy_list()[源代码]#

转换 f 一个具有共系数的列表表示。

to_tuple()[源代码]#

转换 f 到具有本机系数的元组表示。

这是哈希所需的。

total_degree()[源代码]#

返回 f .

transform(p, q)[源代码]#

评估功能转换 q**n * f(p/q) .

trunc(p)[源代码]#

减少 f 模a常数 p .

unify_DMP(g)[源代码]#

Unify and return DMP instances of f and g.

class sympy.polys.polyclasses.DMF(rep, dom, lev=None)[源代码]#

稠密多元分数 \(K\) .

add(g)[源代码]#

两个多元分数相加 fg .

add_ground(c)[源代码]#

将一个基域元素添加到 f .

cancel()[源代码]#

从中删除常见因素 f.numf.den .

denom()[源代码]#

返回的分母 f .

exquo(g)[源代码]#

计算分数的商 fg .

frac_unify(g)[源代码]#

统一表示两个多元分数。

half_per(rep, kill=False)[源代码]#

从给定的表示形式创建一个DMP。

invert(check=True)[源代码]#

计算分数的倒数 f .

property is_one#

返回 True 如果 f 是单位分数。

property is_zero#

返回 True 如果 f 是零分数。

mul(g)[源代码]#

两个多元分数相乘 fg .

neg()[源代码]#

取中的所有系数 f .

numer()[源代码]#

返回的分子 f .

per(num, den, cancel=True, kill=False)[源代码]#

从给定的表示形式创建DMF。

poly_unify(g)[源代码]#

统一多元分式和多项式。

pow(n)[源代码]#

提高 f 非负幂 n .

quo(g)[源代码]#

计算分数的商 fg .

sub(g)[源代码]#

减去两个多元分数 fg .

class sympy.polys.polyclasses.ANP(rep, mod, dom)[源代码]#

域上的稠密代数数多项式。

LC()[源代码]#

返回的前导系数 f .

TC()[源代码]#

返回的尾随系数 f .

add_ground(c)[源代码]#

将一个基域元素添加到 f .

convert(dom)[源代码]#

Convert f to a ANP over a new domain.

property is_ground#

返回 True 如果 f 是地域的一个元素。

property is_one#

返回 True 如果 f 数是代数单位。

property is_zero#

返回 True 如果 f 是一个零代数数。

mod_to_list()[源代码]#

Return f.mod as a list with native coefficients.

mul_ground(c)[源代码]#

Multiply f by an element of the ground domain.

pow(n)[源代码]#

提高 f 非负幂 n .

quo_ground(c)[源代码]#

Quotient of f by an element of the ground domain.

sub_ground(c)[源代码]#

从中减去基域的一个元素 f .

to_dict()[源代码]#

转换 f 以本机系数表示dict。

to_list()[源代码]#

转换 f 到具有本机系数的列表表示。

to_sympy_dict()[源代码]#

转换 f 对具有共系数的dict表示。

to_sympy_list()[源代码]#

转换 f 一个具有共系数的列表表示。

to_tuple()[源代码]#

转换 f 到具有本机系数的元组表示。

这是哈希所需的。

unify(g)[源代码]#

统一两个代数数的表示。

unify_ANP(g)[源代码]#

Unify and return DMP instances of f and g.