modelparameters.sympy.polys package

Subpackages

Submodules

modelparameters.sympy.polys.compatibility module

Compatibility interface between dense and sparse polys.

class modelparameters.sympy.polys.compatibility.IPolys[source]

Bases: object

clone(symbols=None, domain=None, order=None)[source]
dmp_LC(f)[source]
dmp_TC(f)[source]
dmp_abs(f)[source]
dmp_add(f, g)[source]
dmp_add_ground(f, c)[source]
dmp_add_mul(f, g, h)[source]
dmp_add_term(f, c, i)[source]
dmp_cancel(f, g, include=True)[source]
dmp_clear_denoms(f, convert=False)[source]
dmp_compose(f, g)[source]
dmp_content(f)[source]
dmp_degree(f)[source]
dmp_degree_in(f, j)[source]
dmp_diff(f, m)[source]
dmp_diff_eval_in(f, m, a, j)[source]
dmp_diff_in(f, m, j)[source]
dmp_discriminant(f)[source]
dmp_div(f, g)[source]
dmp_euclidean_prs(f, g)[source]
dmp_eval(f, a)[source]
dmp_eval_in(f, a, j)[source]
dmp_eval_tail(f, A)[source]
dmp_expand(polys)[source]
dmp_exquo(f, g)[source]
dmp_exquo_ground(f, c)[source]
dmp_ext_factor(f)[source]
dmp_factor_list(f)[source]
dmp_factor_list_include(f)[source]
dmp_ff_div(f, g)[source]
dmp_ff_lcm(f, g)[source]
dmp_ff_prs_gcd(f, g)[source]
dmp_gcd(f, g)[source]
dmp_gcdex(f, g)[source]
dmp_gf_factor(f)[source]
dmp_gf_sqf_list(f, all=False)[source]
dmp_gf_sqf_part(f)[source]
dmp_gff_list(f)[source]
dmp_ground_LC(f)[source]
dmp_ground_TC(f)[source]
dmp_ground_content(f)[source]
dmp_ground_extract(f, g)[source]
dmp_ground_monic(f)[source]
dmp_ground_primitive(f)[source]
dmp_ground_trunc(f, p)[source]
dmp_half_gcdex(f, g)[source]
dmp_inner_gcd(f, g)[source]
dmp_inner_subresultants(f, g)[source]
dmp_integrate(f, m)[source]
dmp_integrate_in(f, m, j)[source]
dmp_invert(f, g)[source]
dmp_irreducible_p(f)[source]
dmp_l1_norm(f)[source]
dmp_lcm(f, g)[source]
dmp_lift(f)[source]
dmp_max_norm(f)[source]
dmp_mul(f, g)[source]
dmp_mul_ground(f, c)[source]
dmp_mul_term(f, c, i)[source]
dmp_neg(f)[source]
dmp_pdiv(f, g)[source]
dmp_pexquo(f, g)[source]
dmp_pow(f, n)[source]
dmp_pquo(f, g)[source]
dmp_prem(f, g)[source]
dmp_primitive(f)[source]
dmp_primitive_prs(f, g)[source]
dmp_prs_resultant(f, g)[source]
dmp_qq_collins_resultant(f, g)[source]
dmp_qq_heu_gcd(f, g)[source]
dmp_quo(f, g)[source]
dmp_quo_ground(f, c)[source]
dmp_rem(f, g)[source]
dmp_resultant(f, g)[source]
dmp_rr_div(f, g)[source]
dmp_rr_lcm(f, g)[source]
dmp_rr_prs_gcd(f, g)[source]
dmp_sqf_list(f, all=False)[source]
dmp_sqf_list_include(f, all=False)[source]
dmp_sqf_norm(f)[source]
dmp_sqf_p(f)[source]
dmp_sqf_part(f)[source]
dmp_sqr(f)[source]
dmp_sub(f, g)[source]
dmp_sub_ground(f, c)[source]
dmp_sub_mul(f, g, h)[source]
dmp_sub_term(f, c, i)[source]
dmp_subresultants(f, g)[source]
dmp_trial_division(f, factors)[source]
dmp_trunc(f, g)[source]
dmp_zz_collins_resultant(f, g)[source]
dmp_zz_diophantine(F, c, A, d, p)[source]
dmp_zz_factor(f)[source]
dmp_zz_heu_gcd(f, g)[source]
dmp_zz_mignotte_bound(f)[source]
dmp_zz_modular_resultant(f, g, p)[source]
dmp_zz_wang(f, mod=None, seed=None)[source]
dmp_zz_wang_hensel_lifting(f, H, LC, A, p)[source]
dmp_zz_wang_lead_coeffs(f, T, cs, E, H, A)[source]
dmp_zz_wang_non_divisors(E, cs, ct)[source]
domain = None
domain_new(element)[source]
drop(gen)[source]
dup_LC(f)[source]
dup_TC(f)[source]
dup_abs(f)[source]
dup_add(f, g)[source]
dup_add_ground(f, c)[source]
dup_add_mul(f, g, h)[source]
dup_add_term(f, c, i)[source]
dup_cancel(f, g, include=True)[source]
dup_clear_denoms(f, convert=False)[source]
dup_compose(f, g)[source]
dup_content(f)[source]
dup_count_complex_roots(f, inf=None, sup=None, exclude=None)[source]
dup_count_real_roots(f, inf=None, sup=None)[source]
dup_cyclotomic_p(f, irreducible=False)[source]
dup_decompose(f)[source]
dup_degree(f)[source]
dup_diff(f, m)[source]
dup_discriminant(f)[source]
dup_div(f, g)[source]
dup_euclidean_prs(f, g)[source]
dup_eval(f, a)[source]
dup_expand(polys)[source]
dup_exquo(f, g)[source]
dup_exquo_ground(f, c)[source]
dup_ext_factor(f)[source]
dup_extract(f, g)[source]
dup_factor_list(f)[source]
dup_factor_list_include(f)[source]
dup_ff_div(f, g)[source]
dup_ff_lcm(f, g)[source]
dup_ff_prs_gcd(f, g)[source]
dup_gcd(f, g)[source]
dup_gcdex(f, g)[source]
dup_gf_factor(f)[source]
dup_gf_sqf_list(f, all=False)[source]
dup_gf_sqf_part(f)[source]
dup_gff_list(f)[source]
dup_half_gcdex(f, g)[source]
dup_inner_gcd(f, g)[source]
dup_inner_isolate_negative_roots(f, inf=None, sup=None, eps=None, fast=False, mobius=False)[source]
dup_inner_isolate_positive_roots(f, eps=None, inf=None, sup=None, fast=False, mobius=False)[source]
dup_inner_isolate_real_roots(f, eps=None, fast=False)[source]
dup_inner_refine_real_root(f, M, eps=None, steps=None, disjoint=None, fast=False, mobius=False)[source]
dup_inner_subresultants(f, g)[source]
dup_integrate(f, m)[source]
dup_invert(f, g)[source]
dup_irreducible_p(f)[source]
dup_isolate_all_roots(f, eps=None, inf=None, sup=None, fast=False)[source]
dup_isolate_all_roots_sqf(f, eps=None, inf=None, sup=None, fast=False, blackbox=False)[source]
dup_isolate_complex_roots_sqf(f, eps=None, inf=None, sup=None, blackbox=False)[source]
dup_isolate_real_roots(f, eps=None, inf=None, sup=None, basis=False, fast=False)[source]
dup_isolate_real_roots_list(polys, eps=None, inf=None, sup=None, strict=False, basis=False, fast=False)[source]
dup_isolate_real_roots_sqf(f, eps=None, inf=None, sup=None, fast=False, blackbox=False)[source]
dup_l1_norm(f)[source]
dup_lcm(f, g)[source]
dup_lshift(f, n)[source]
dup_max_norm(f)[source]
dup_mirror(f)[source]
dup_monic(f)[source]
dup_mul(f, g)[source]
dup_mul_ground(f, c)[source]
dup_mul_term(f, c, i)[source]
dup_neg(f)[source]
dup_outer_refine_real_root(f, s, t, eps=None, steps=None, disjoint=None, fast=False)[source]
dup_pdiv(f, g)[source]
dup_pexquo(f, g)[source]
dup_pow(f, n)[source]
dup_pquo(f, g)[source]
dup_prem(f, g)[source]
dup_primitive(f)[source]
dup_primitive_prs(f, g)[source]
dup_prs_resultant(f, g)[source]
dup_qq_heu_gcd(f, g)[source]
dup_quo(f, g)[source]
dup_quo_ground(f, c)[source]
dup_real_imag(f)[source]
dup_refine_real_root(f, s, t, eps=None, steps=None, disjoint=None, fast=False)[source]
dup_rem(f, g)[source]
dup_resultant(f, g)[source]
dup_revert(f, n)[source]
dup_root_lower_bound(f)[source]
dup_root_upper_bound(f)[source]
dup_rr_div(f, g)[source]
dup_rr_lcm(f, g)[source]
dup_rr_prs_gcd(f, g)[source]
dup_rshift(f, n)[source]
dup_scale(f, a)[source]
dup_shift(f, a)[source]
dup_sign_variations(f)[source]
dup_sqf_list(f, all=False)[source]
dup_sqf_list_include(f, all=False)[source]
dup_sqf_norm(f)[source]
dup_sqf_p(f)[source]
dup_sqf_part(f)[source]
dup_sqr(f)[source]
dup_step_refine_real_root(f, M, fast=False)[source]
dup_sturm(f)[source]
dup_sub(f, g)[source]
dup_sub_ground(f, c)[source]
dup_sub_mul(f, g, h)[source]
dup_sub_term(f, c, i)[source]
dup_subresultants(f, g)[source]
dup_transform(f, p, q)[source]
dup_trial_division(f, factors)[source]
dup_trunc(f, p)[source]
dup_zz_cyclotomic_factor(f)[source]
dup_zz_cyclotomic_poly(n)[source]
dup_zz_diophantine(F, m, p)[source]
dup_zz_factor(f)[source]
dup_zz_factor_sqf(f)[source]
dup_zz_hensel_lift(p, f, f_list, l)[source]
dup_zz_hensel_step(m, f, g, h, s, t)[source]
dup_zz_heu_gcd(f, g)[source]
dup_zz_irreducible_p(f)[source]
dup_zz_mignotte_bound(f)[source]
dup_zz_zassenhaus(f)[source]
fateman_poly_F_1()[source]
fateman_poly_F_2()[source]
fateman_poly_F_3()[source]
from_dense(element)[source]
from_dict(d)[source]
from_gf_dense(element)[source]
gens = None
gf_LC(f)[source]
gf_Qmatrix(f)[source]
gf_TC(f)[source]
gf_add(f, g)[source]
gf_add_ground(f, a)[source]
gf_add_mul(f, g, h)[source]
gf_berlekamp(f)[source]
gf_cofactors(f, g)[source]
gf_compose(f, g)[source]
gf_compose_mod(g, h, f)[source]
gf_ddf_shoup(f)[source]
gf_ddf_zassenhaus(f)[source]
gf_degree(f)[source]
gf_diff(f)[source]
gf_div(f, g)[source]
gf_edf_shoup(f, n)[source]
gf_edf_zassenhaus(f, n)[source]
gf_eval(f, a)[source]
gf_expand(F)[source]
gf_exquo(f, g)[source]
gf_factor(f)[source]
gf_factor_sqf(f, method=None)[source]
gf_from_dict(f)[source]
gf_from_int_poly(f)[source]
gf_gcd(f, g)[source]
gf_gcdex(f, g)[source]
gf_irred_p_ben_or(f)[source]
gf_irred_p_rabin(f)[source]
gf_irreducible(n)[source]
gf_irreducible_p(f)[source]
gf_lcm(f, g)[source]
gf_lshift(f, n)[source]
gf_monic(f)[source]
gf_mul(f, g)[source]
gf_mul_ground(f, a)[source]
gf_multi_eval(f, A)[source]
gf_neg(f)[source]
gf_normal(f)[source]
gf_pow(f, n)[source]
gf_pow_mod(f, n, g)[source]
gf_quo(f, g)[source]
gf_quo_ground(f, a)[source]
gf_random(n)[source]
gf_rem(f, g)[source]
gf_rshift(f, n)[source]
gf_shoup(f)[source]
gf_sqf_list(f, all=False)[source]
gf_sqf_p(f)[source]
gf_sqf_part(f)[source]
gf_sqr(f)[source]
gf_strip(f)[source]
gf_sub(f, g)[source]
gf_sub_ground(f, a)[source]
gf_sub_mul(f, g, h)[source]
gf_to_dict(f, symmetric=True)[source]
gf_to_int_poly(f, symmetric=True)[source]
gf_trace_map(a, b, c, n, f)[source]
gf_trunc(f)[source]
gf_zassenhaus(f)[source]
ground_new(element)[source]
ngens = None
order = None
symbols = None
to_dense(element)[source]
to_gf_dense(element)[source]
to_ground()[source]
wrap(element)[source]

modelparameters.sympy.polys.constructor module

Tools for constructing domains for expressions.

modelparameters.sympy.polys.constructor.construct_domain(obj, **args)[source]

Construct a minimal domain for the list of coefficients.

modelparameters.sympy.polys.densearith module

Arithmetics for dense recursive polynomials in K[x] or K[X].

modelparameters.sympy.polys.densearith.dmp_abs(f, u, K)[source]

Make all coefficients positive in K[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> R.dmp_abs(x**2*y - x)
x**2*y + x
modelparameters.sympy.polys.densearith.dmp_add(f, g, u, K)[source]

Add dense polynomials in K[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> R.dmp_add(x**2 + y, x**2*y + x)
x**2*y + x**2 + x + y
modelparameters.sympy.polys.densearith.dmp_add_ground(f, c, u, K)[source]

Add an element of the ground domain to f.

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> R.dmp_add_ground(x**3 + 2*x**2 + 3*x + 4, ZZ(4))
x**3 + 2*x**2 + 3*x + 8
modelparameters.sympy.polys.densearith.dmp_add_mul(f, g, h, u, K)[source]

Returns f + g*h where f, g, h are in K[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> R.dmp_add_mul(x**2 + y, x, x + 2)
2*x**2 + 2*x + y
modelparameters.sympy.polys.densearith.dmp_add_term(f, c, i, u, K)[source]

Add c(x_2..x_u)*x_0**i to f in K[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> R.dmp_add_term(x*y + 1, 2, 2)
2*x**2 + x*y + 1
modelparameters.sympy.polys.densearith.dmp_div(f, g, u, K)[source]

Polynomial division with remainder in K[X].

Examples

>>> from ..polys import ring, ZZ, QQ
>>> R, x,y = ring("x,y", ZZ)
>>> R.dmp_div(x**2 + x*y, 2*x + 2)
(0, x**2 + x*y)
>>> R, x,y = ring("x,y", QQ)
>>> R.dmp_div(x**2 + x*y, 2*x + 2)
(1/2*x + 1/2*y - 1/2, -y + 1)
modelparameters.sympy.polys.densearith.dmp_expand(polys, u, K)[source]

Multiply together several polynomials in K[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> R.dmp_expand([x**2 + y**2, x + 1])
x**3 + x**2 + x*y**2 + y**2
modelparameters.sympy.polys.densearith.dmp_exquo(f, g, u, K)[source]

Returns polynomial quotient in K[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> f = x**2 + x*y
>>> g = x + y
>>> h = 2*x + 2
>>> R.dmp_exquo(f, g)
x
>>> R.dmp_exquo(f, h)
Traceback (most recent call last):
...
ExactQuotientFailed: [[2], [2]] does not divide [[1], [1, 0], []]
modelparameters.sympy.polys.densearith.dmp_exquo_ground(f, c, u, K)[source]

Exact quotient by a constant in K[X].

Examples

>>> from ..polys import ring, QQ
>>> R, x,y = ring("x,y", QQ)
>>> R.dmp_exquo_ground(x**2*y + 2*x, QQ(2))
1/2*x**2*y + x
modelparameters.sympy.polys.densearith.dmp_ff_div(f, g, u, K)[source]

Polynomial division with remainder over a field.

Examples

>>> from ..polys import ring, QQ
>>> R, x,y = ring("x,y", QQ)
>>> R.dmp_ff_div(x**2 + x*y, 2*x + 2)
(1/2*x + 1/2*y - 1/2, -y + 1)
modelparameters.sympy.polys.densearith.dmp_l1_norm(f, u, K)[source]

Returns l1 norm of a polynomial in K[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> R.dmp_l1_norm(2*x*y - x - 3)
6
modelparameters.sympy.polys.densearith.dmp_max_norm(f, u, K)[source]

Returns maximum norm of a polynomial in K[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> R.dmp_max_norm(2*x*y - x - 3)
3
modelparameters.sympy.polys.densearith.dmp_mul(f, g, u, K)[source]

Multiply dense polynomials in K[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> R.dmp_mul(x*y + 1, x)
x**2*y + x
modelparameters.sympy.polys.densearith.dmp_mul_ground(f, c, u, K)[source]

Multiply f by a constant value in K[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> R.dmp_mul_ground(2*x + 2*y, ZZ(3))
6*x + 6*y
modelparameters.sympy.polys.densearith.dmp_mul_term(f, c, i, u, K)[source]

Multiply f by c(x_2..x_u)*x_0**i in K[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> R.dmp_mul_term(x**2*y + x, 3*y, 2)
3*x**4*y**2 + 3*x**3*y
modelparameters.sympy.polys.densearith.dmp_neg(f, u, K)[source]

Negate a polynomial in K[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> R.dmp_neg(x**2*y - x)
-x**2*y + x
modelparameters.sympy.polys.densearith.dmp_pdiv(f, g, u, K)[source]

Polynomial pseudo-division in K[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> R.dmp_pdiv(x**2 + x*y, 2*x + 2)
(2*x + 2*y - 2, -4*y + 4)
modelparameters.sympy.polys.densearith.dmp_pexquo(f, g, u, K)[source]

Polynomial pseudo-quotient in K[X].

Examples

>>> from ..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
>>> R.dmp_pexquo(f, g)
2*x
>>> R.dmp_pexquo(f, h)
Traceback (most recent call last):
...
ExactQuotientFailed: [[2], [2]] does not divide [[1], [1, 0], []]
modelparameters.sympy.polys.densearith.dmp_pow(f, n, u, K)[source]

Raise f to the n-th power in K[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> R.dmp_pow(x*y + 1, 3)
x**3*y**3 + 3*x**2*y**2 + 3*x*y + 1
modelparameters.sympy.polys.densearith.dmp_pquo(f, g, u, K)[source]

Polynomial exact pseudo-quotient in K[X].

Examples

>>> from ..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
>>> R.dmp_pquo(f, g)
2*x
>>> R.dmp_pquo(f, h)
2*x + 2*y - 2
modelparameters.sympy.polys.densearith.dmp_prem(f, g, u, K)[source]

Polynomial pseudo-remainder in K[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> R.dmp_prem(x**2 + x*y, 2*x + 2)
-4*y + 4
modelparameters.sympy.polys.densearith.dmp_quo(f, g, u, K)[source]

Returns exact polynomial quotient in K[X].

Examples

>>> from ..polys import ring, ZZ, QQ
>>> R, x,y = ring("x,y", ZZ)
>>> R.dmp_quo(x**2 + x*y, 2*x + 2)
0
>>> R, x,y = ring("x,y", QQ)
>>> R.dmp_quo(x**2 + x*y, 2*x + 2)
1/2*x + 1/2*y - 1/2
modelparameters.sympy.polys.densearith.dmp_quo_ground(f, c, u, K)[source]

Quotient by a constant in K[X].

Examples

>>> from ..polys import ring, ZZ, QQ
>>> R, x,y = ring("x,y", ZZ)
>>> R.dmp_quo_ground(2*x**2*y + 3*x, ZZ(2))
x**2*y + x
>>> R, x,y = ring("x,y", QQ)
>>> R.dmp_quo_ground(2*x**2*y + 3*x, QQ(2))
x**2*y + 3/2*x
modelparameters.sympy.polys.densearith.dmp_rem(f, g, u, K)[source]

Returns polynomial remainder in K[X].

Examples

>>> from ..polys import ring, ZZ, QQ
>>> R, x,y = ring("x,y", ZZ)
>>> R.dmp_rem(x**2 + x*y, 2*x + 2)
x**2 + x*y
>>> R, x,y = ring("x,y", QQ)
>>> R.dmp_rem(x**2 + x*y, 2*x + 2)
-y + 1
modelparameters.sympy.polys.densearith.dmp_rr_div(f, g, u, K)[source]

Multivariate division with remainder over a ring.

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> R.dmp_rr_div(x**2 + x*y, 2*x + 2)
(0, x**2 + x*y)
modelparameters.sympy.polys.densearith.dmp_sqr(f, u, K)[source]

Square dense polynomials in K[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> R.dmp_sqr(x**2 + x*y + y**2)
x**4 + 2*x**3*y + 3*x**2*y**2 + 2*x*y**3 + y**4
modelparameters.sympy.polys.densearith.dmp_sub(f, g, u, K)[source]

Subtract dense polynomials in K[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> R.dmp_sub(x**2 + y, x**2*y + x)
-x**2*y + x**2 - x + y
modelparameters.sympy.polys.densearith.dmp_sub_ground(f, c, u, K)[source]

Subtract an element of the ground domain from f.

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> R.dmp_sub_ground(x**3 + 2*x**2 + 3*x + 4, ZZ(4))
x**3 + 2*x**2 + 3*x
modelparameters.sympy.polys.densearith.dmp_sub_mul(f, g, h, u, K)[source]

Returns f - g*h where f, g, h are in K[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> R.dmp_sub_mul(x**2 + y, x, x + 2)
-2*x + y
modelparameters.sympy.polys.densearith.dmp_sub_term(f, c, i, u, K)[source]

Subtract c(x_2..x_u)*x_0**i from f in K[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> R.dmp_sub_term(2*x**2 + x*y + 1, 2, 2)
x*y + 1
modelparameters.sympy.polys.densearith.dup_abs(f, K)[source]

Make all coefficients positive in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_abs(x**2 - 1)
x**2 + 1
modelparameters.sympy.polys.densearith.dup_add(f, g, K)[source]

Add dense polynomials in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_add(x**2 - 1, x - 2)
x**2 + x - 3
modelparameters.sympy.polys.densearith.dup_add_ground(f, c, K)[source]

Add an element of the ground domain to f.

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_add_ground(x**3 + 2*x**2 + 3*x + 4, ZZ(4))
x**3 + 2*x**2 + 3*x + 8
modelparameters.sympy.polys.densearith.dup_add_mul(f, g, h, K)[source]

Returns f + g*h where f, g, h are in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_add_mul(x**2 - 1, x - 2, x + 2)
2*x**2 - 5
modelparameters.sympy.polys.densearith.dup_add_term(f, c, i, K)[source]

Add c*x**i to f in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_add_term(x**2 - 1, ZZ(2), 4)
2*x**4 + x**2 - 1
modelparameters.sympy.polys.densearith.dup_div(f, g, K)[source]

Polynomial division with remainder in K[x].

Examples

>>> from ..polys import ring, ZZ, QQ
>>> R, x = ring("x", ZZ)
>>> R.dup_div(x**2 + 1, 2*x - 4)
(0, x**2 + 1)
>>> R, x = ring("x", QQ)
>>> R.dup_div(x**2 + 1, 2*x - 4)
(1/2*x + 1, 5)
modelparameters.sympy.polys.densearith.dup_expand(polys, K)[source]

Multiply together several polynomials in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_expand([x**2 - 1, x, 2])
2*x**3 - 2*x
modelparameters.sympy.polys.densearith.dup_exquo(f, g, K)[source]

Returns polynomial quotient in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_exquo(x**2 - 1, x - 1)
x + 1
>>> R.dup_exquo(x**2 + 1, 2*x - 4)
Traceback (most recent call last):
...
ExactQuotientFailed: [2, -4] does not divide [1, 0, 1]
modelparameters.sympy.polys.densearith.dup_exquo_ground(f, c, K)[source]

Exact quotient by a constant in K[x].

Examples

>>> from ..polys import ring, QQ
>>> R, x = ring("x", QQ)
>>> R.dup_exquo_ground(x**2 + 2, QQ(2))
1/2*x**2 + 1
modelparameters.sympy.polys.densearith.dup_ff_div(f, g, K)[source]

Polynomial division with remainder over a field.

Examples

>>> from ..polys import ring, QQ
>>> R, x = ring("x", QQ)
>>> R.dup_ff_div(x**2 + 1, 2*x - 4)
(1/2*x + 1, 5)
modelparameters.sympy.polys.densearith.dup_l1_norm(f, K)[source]

Returns l1 norm of a polynomial in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_l1_norm(2*x**3 - 3*x**2 + 1)
6
modelparameters.sympy.polys.densearith.dup_lshift(f, n, K)[source]

Efficiently multiply f by x**n in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_lshift(x**2 + 1, 2)
x**4 + x**2
modelparameters.sympy.polys.densearith.dup_max_norm(f, K)[source]

Returns maximum norm of a polynomial in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_max_norm(-x**2 + 2*x - 3)
3
modelparameters.sympy.polys.densearith.dup_mul(f, g, K)[source]

Multiply dense polynomials in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_mul(x - 2, x + 2)
x**2 - 4
modelparameters.sympy.polys.densearith.dup_mul_ground(f, c, K)[source]

Multiply f by a constant value in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_mul_ground(x**2 + 2*x - 1, ZZ(3))
3*x**2 + 6*x - 3
modelparameters.sympy.polys.densearith.dup_mul_term(f, c, i, K)[source]

Multiply f by c*x**i in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_mul_term(x**2 - 1, ZZ(3), 2)
3*x**4 - 3*x**2
modelparameters.sympy.polys.densearith.dup_neg(f, K)[source]

Negate a polynomial in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_neg(x**2 - 1)
-x**2 + 1
modelparameters.sympy.polys.densearith.dup_pdiv(f, g, K)[source]

Polynomial pseudo-division in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_pdiv(x**2 + 1, 2*x - 4)
(2*x + 4, 20)
modelparameters.sympy.polys.densearith.dup_pexquo(f, g, K)[source]

Polynomial pseudo-quotient in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_pexquo(x**2 - 1, 2*x - 2)
2*x + 2
>>> R.dup_pexquo(x**2 + 1, 2*x - 4)
Traceback (most recent call last):
...
ExactQuotientFailed: [2, -4] does not divide [1, 0, 1]
modelparameters.sympy.polys.densearith.dup_pow(f, n, K)[source]

Raise f to the n-th power in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_pow(x - 2, 3)
x**3 - 6*x**2 + 12*x - 8
modelparameters.sympy.polys.densearith.dup_pquo(f, g, K)[source]

Polynomial exact pseudo-quotient in K[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_pquo(x**2 - 1, 2*x - 2)
2*x + 2
>>> R.dup_pquo(x**2 + 1, 2*x - 4)
2*x + 4
modelparameters.sympy.polys.densearith.dup_prem(f, g, K)[source]

Polynomial pseudo-remainder in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_prem(x**2 + 1, 2*x - 4)
20
modelparameters.sympy.polys.densearith.dup_quo(f, g, K)[source]

Returns exact polynomial quotient in K[x].

Examples

>>> from ..polys import ring, ZZ, QQ
>>> R, x = ring("x", ZZ)
>>> R.dup_quo(x**2 + 1, 2*x - 4)
0
>>> R, x = ring("x", QQ)
>>> R.dup_quo(x**2 + 1, 2*x - 4)
1/2*x + 1
modelparameters.sympy.polys.densearith.dup_quo_ground(f, c, K)[source]

Quotient by a constant in K[x].

Examples

>>> from ..polys import ring, ZZ, QQ
>>> R, x = ring("x", ZZ)
>>> R.dup_quo_ground(3*x**2 + 2, ZZ(2))
x**2 + 1
>>> R, x = ring("x", QQ)
>>> R.dup_quo_ground(3*x**2 + 2, QQ(2))
3/2*x**2 + 1
modelparameters.sympy.polys.densearith.dup_rem(f, g, K)[source]

Returns polynomial remainder in K[x].

Examples

>>> from ..polys import ring, ZZ, QQ
>>> R, x = ring("x", ZZ)
>>> R.dup_rem(x**2 + 1, 2*x - 4)
x**2 + 1
>>> R, x = ring("x", QQ)
>>> R.dup_rem(x**2 + 1, 2*x - 4)
5
modelparameters.sympy.polys.densearith.dup_rr_div(f, g, K)[source]

Univariate division with remainder over a ring.

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_rr_div(x**2 + 1, 2*x - 4)
(0, x**2 + 1)
modelparameters.sympy.polys.densearith.dup_rshift(f, n, K)[source]

Efficiently divide f by x**n in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_rshift(x**4 + x**2, 2)
x**2 + 1
>>> R.dup_rshift(x**4 + x**2 + 2, 2)
x**2 + 1
modelparameters.sympy.polys.densearith.dup_sqr(f, K)[source]

Square dense polynomials in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_sqr(x**2 + 1)
x**4 + 2*x**2 + 1
modelparameters.sympy.polys.densearith.dup_sub(f, g, K)[source]

Subtract dense polynomials in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_sub(x**2 - 1, x - 2)
x**2 - x + 1
modelparameters.sympy.polys.densearith.dup_sub_ground(f, c, K)[source]

Subtract an element of the ground domain from f.

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_sub_ground(x**3 + 2*x**2 + 3*x + 4, ZZ(4))
x**3 + 2*x**2 + 3*x
modelparameters.sympy.polys.densearith.dup_sub_mul(f, g, h, K)[source]

Returns f - g*h where f, g, h are in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_sub_mul(x**2 - 1, x - 2, x + 2)
3
modelparameters.sympy.polys.densearith.dup_sub_term(f, c, i, K)[source]

Subtract c*x**i from f in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_sub_term(2*x**4 + x**2 - 1, ZZ(2), 4)
x**2 - 1

modelparameters.sympy.polys.densebasic module

Basic tools for dense recursive polynomials in K[x] or K[X].

modelparameters.sympy.polys.densebasic.dmp_LC(f, K)

Return leading coefficient of f.

Examples

>>> from .domains import ZZ
>>> from .densebasic import poly_LC
>>> poly_LC([], ZZ)
0
>>> poly_LC([ZZ(1), ZZ(2), ZZ(3)], ZZ)
1
modelparameters.sympy.polys.densebasic.dmp_TC(f, K)

Return trailing coefficient of f.

Examples

>>> from .domains import ZZ
>>> from .densebasic import poly_TC
>>> poly_TC([], ZZ)
0
>>> poly_TC([ZZ(1), ZZ(2), ZZ(3)], ZZ)
3
modelparameters.sympy.polys.densebasic.dmp_apply_pairs(f, g, h, args, u, K)[source]

Apply h to pairs of coefficients of f and g.

Examples

>>> from .domains import ZZ
>>> from .densebasic import dmp_apply_pairs
>>> h = lambda x, y, z: 2*x + y - z
>>> dmp_apply_pairs([[1], [2, 3]], [[3], [2, 1]], h, (1,), 1, ZZ)
[[4], [5, 6]]
modelparameters.sympy.polys.densebasic.dmp_convert(f, u, K0, K1)[source]

Convert the ground domain of f from K0 to K1.

Examples

>>> from .rings import ring
>>> from .domains import ZZ
>>> from .densebasic import dmp_convert
>>> R, x = ring("x", ZZ)
>>> dmp_convert([[R(1)], [R(2)]], 1, R.to_domain(), ZZ)
[[1], [2]]
>>> dmp_convert([[ZZ(1)], [ZZ(2)]], 1, ZZ, R.to_domain())
[[1], [2]]
modelparameters.sympy.polys.densebasic.dmp_copy(f, u)[source]

Create a new copy of a polynomial f in K[X].

Examples

>>> from .domains import ZZ
>>> from .densebasic import dmp_copy
>>> f = ZZ.map([[1], [1, 2]])
>>> dmp_copy(f, 1)
[[1], [1, 2]]
modelparameters.sympy.polys.densebasic.dmp_deflate(f, u, K)[source]

Map x_i**m_i to y_i in a polynomial in K[X].

Examples

>>> from .domains import ZZ
>>> from .densebasic import dmp_deflate
>>> f = ZZ.map([[1, 0, 0, 2], [], [3, 0, 0, 4]])
>>> dmp_deflate(f, 1, ZZ)
((2, 3), [[1, 2], [3, 4]])
modelparameters.sympy.polys.densebasic.dmp_degree(f, u)[source]

Return the leading degree of f in x_0 in K[X].

Note that the degree of 0 is negative infinity (the SymPy object -oo).

Examples

>>> from .domains import ZZ
>>> from .densebasic import dmp_degree
>>> dmp_degree([[[]]], 2)
-oo
>>> f = ZZ.map([[2], [1, 2, 3]])
>>> dmp_degree(f, 1)
1
modelparameters.sympy.polys.densebasic.dmp_degree_in(f, j, u)[source]

Return the leading degree of f in x_j in K[X].

Examples

>>> from .domains import ZZ
>>> from .densebasic import dmp_degree_in
>>> f = ZZ.map([[2], [1, 2, 3]])
>>> dmp_degree_in(f, 0, 1)
1
>>> dmp_degree_in(f, 1, 1)
2
modelparameters.sympy.polys.densebasic.dmp_degree_list(f, u)[source]

Return a list of degrees of f in K[X].

Examples

>>> from .domains import ZZ
>>> from .densebasic import dmp_degree_list
>>> f = ZZ.map([[1], [1, 2, 3]])
>>> dmp_degree_list(f, 1)
(1, 2)
modelparameters.sympy.polys.densebasic.dmp_eject(f, u, K, front=False)[source]

Convert f from K[X,Y] to K[X][Y].

Examples

>>> from .domains import ZZ
>>> from .densebasic import dmp_eject
>>> dmp_eject([[[1]], [[1], [2]]], 2, ZZ['x', 'y'])
[1, x + 2]
modelparameters.sympy.polys.densebasic.dmp_exclude(f, u, K)[source]

Exclude useless levels from f.

Return the levels excluded, the new excluded f, and the new u.

Examples

>>> from .domains import ZZ
>>> from .densebasic import dmp_exclude
>>> f = ZZ.map([[[1]], [[1], [2]]])
>>> dmp_exclude(f, 2, ZZ)
([2], [[1], [1, 2]], 1)
modelparameters.sympy.polys.densebasic.dmp_from_dict(f, u, K)[source]

Create a K[X] polynomial from a dict.

Examples

>>> from .domains import ZZ
>>> from .densebasic import dmp_from_dict
>>> dmp_from_dict({(0, 0): ZZ(3), (0, 1): ZZ(2), (2, 1): ZZ(1)}, 1, ZZ)
[[1, 0], [], [2, 3]]
>>> dmp_from_dict({}, 0, ZZ)
[]
modelparameters.sympy.polys.densebasic.dmp_from_sympy(f, u, K)[source]

Convert the ground domain of f from SymPy to K.

Examples

>>> from .. import S
>>> from .domains import ZZ
>>> from .densebasic import dmp_from_sympy
>>> dmp_from_sympy([[S(1)], [S(2)]], 1, ZZ) == [[ZZ(1)], [ZZ(2)]]
True
modelparameters.sympy.polys.densebasic.dmp_ground(c, u)[source]

Return a multivariate constant.

Examples

>>> from .densebasic import dmp_ground
>>> dmp_ground(3, 5)
[[[[[[3]]]]]]
>>> dmp_ground(1, -1)
1
modelparameters.sympy.polys.densebasic.dmp_ground_LC(f, u, K)[source]

Return the ground leading coefficient.

Examples

>>> from .domains import ZZ
>>> from .densebasic import dmp_ground_LC
>>> f = ZZ.map([[[1], [2, 3]]])
>>> dmp_ground_LC(f, 2, ZZ)
1
modelparameters.sympy.polys.densebasic.dmp_ground_TC(f, u, K)[source]

Return the ground trailing coefficient.

Examples

>>> from .domains import ZZ
>>> from .densebasic import dmp_ground_TC
>>> f = ZZ.map([[[1], [2, 3]]])
>>> dmp_ground_TC(f, 2, ZZ)
3
modelparameters.sympy.polys.densebasic.dmp_ground_nth(f, N, u, K)[source]

Return the ground n-th coefficient of f in K[x].

Examples

>>> from .domains import ZZ
>>> from .densebasic import dmp_ground_nth
>>> f = ZZ.map([[1], [2, 3]])
>>> dmp_ground_nth(f, (0, 1), 1, ZZ)
2
modelparameters.sympy.polys.densebasic.dmp_ground_p(f, c, u)[source]

Return True if f is constant in K[X].

Examples

>>> from .densebasic import dmp_ground_p
>>> dmp_ground_p([[[3]]], 3, 2)
True
>>> dmp_ground_p([[[4]]], None, 2)
True
modelparameters.sympy.polys.densebasic.dmp_grounds(c, n, u)[source]

Return a list of multivariate constants.

Examples

>>> from .domains import ZZ
>>> from .densebasic import dmp_grounds
>>> dmp_grounds(ZZ(4), 3, 2)
[[[[4]]], [[[4]]], [[[4]]]]
>>> dmp_grounds(ZZ(4), 3, -1)
[4, 4, 4]
modelparameters.sympy.polys.densebasic.dmp_include(f, J, u, K)[source]

Include useless levels in f.

Examples

>>> from .domains import ZZ
>>> from .densebasic import dmp_include
>>> f = ZZ.map([[1], [1, 2]])
>>> dmp_include(f, [2], 1, ZZ)
[[[1]], [[1], [2]]]
modelparameters.sympy.polys.densebasic.dmp_inflate(f, M, u, K)[source]

Map y_i to x_i**k_i in a polynomial in K[X].

Examples

>>> from .domains import ZZ
>>> from .densebasic import dmp_inflate
>>> f = ZZ.map([[1, 2], [3, 4]])
>>> dmp_inflate(f, (2, 3), 1, ZZ)
[[1, 0, 0, 2], [], [3, 0, 0, 4]]
modelparameters.sympy.polys.densebasic.dmp_inject(f, u, K, front=False)[source]

Convert f from K[X][Y] to K[X,Y].

Examples

>>> from .rings import ring
>>> from .domains import ZZ
>>> from .densebasic import dmp_inject
>>> R, x,y = ring("x,y", ZZ)
>>> dmp_inject([R(1), x + 2], 0, R.to_domain())
([[[1]], [[1], [2]]], 2)
>>> dmp_inject([R(1), x + 2], 0, R.to_domain(), front=True)
([[[1]], [[1, 2]]], 2)
modelparameters.sympy.polys.densebasic.dmp_list_terms(f, u, K, order=None)[source]

List all non-zero terms from f in the given order order.

Examples

>>> from .domains import ZZ
>>> from .densebasic import dmp_list_terms
>>> f = ZZ.map([[1, 1], [2, 3]])
>>> dmp_list_terms(f, 1, ZZ)
[((1, 1), 1), ((1, 0), 1), ((0, 1), 2), ((0, 0), 3)]
>>> dmp_list_terms(f, 1, ZZ, order='grevlex')
[((1, 1), 1), ((1, 0), 1), ((0, 1), 2), ((0, 0), 3)]
modelparameters.sympy.polys.densebasic.dmp_multi_deflate(polys, u, K)[source]

Map x_i**m_i to y_i in a set of polynomials in K[X].

Examples

>>> from .domains import ZZ
>>> from .densebasic import dmp_multi_deflate
>>> f = ZZ.map([[1, 0, 0, 2], [], [3, 0, 0, 4]])
>>> g = ZZ.map([[1, 0, 2], [], [3, 0, 4]])
>>> dmp_multi_deflate((f, g), 1, ZZ)
((2, 1), ([[1, 0, 0, 2], [3, 0, 0, 4]], [[1, 0, 2], [3, 0, 4]]))
modelparameters.sympy.polys.densebasic.dmp_negative_p(f, u, K)[source]

Return True if LC(f) is negative.

Examples

>>> from .domains import ZZ
>>> from .densebasic import dmp_negative_p
>>> dmp_negative_p([[ZZ(1)], [-ZZ(1)]], 1, ZZ)
False
>>> dmp_negative_p([[-ZZ(1)], [ZZ(1)]], 1, ZZ)
True
modelparameters.sympy.polys.densebasic.dmp_nest(f, l, K)[source]

Return a multivariate value nested l-levels.

Examples

>>> from .domains import ZZ
>>> from .densebasic import dmp_nest
>>> dmp_nest([[ZZ(1)]], 2, ZZ)
[[[[1]]]]
modelparameters.sympy.polys.densebasic.dmp_normal(f, u, K)[source]

Normalize a multivariate polynomial in the given domain.

Examples

>>> from .domains import ZZ
>>> from .densebasic import dmp_normal
>>> dmp_normal([[], [0, 1.5, 2]], 1, ZZ)
[[1, 2]]
modelparameters.sympy.polys.densebasic.dmp_nth(f, n, u, K)[source]

Return the n-th coefficient of f in K[x].

Examples

>>> from .domains import ZZ
>>> from .densebasic import dmp_nth
>>> f = ZZ.map([[1], [2], [3]])
>>> dmp_nth(f, 0, 1, ZZ)
[3]
>>> dmp_nth(f, 4, 1, ZZ)
[]
modelparameters.sympy.polys.densebasic.dmp_one(u, K)[source]

Return a multivariate one over K.

Examples

>>> from .domains import ZZ
>>> from .densebasic import dmp_one
>>> dmp_one(2, ZZ)
[[[1]]]
modelparameters.sympy.polys.densebasic.dmp_one_p(f, u, K)[source]

Return True if f is one in K[X].

Examples

>>> from .domains import ZZ
>>> from .densebasic import dmp_one_p
>>> dmp_one_p([[[ZZ(1)]]], 2, ZZ)
True
modelparameters.sympy.polys.densebasic.dmp_permute(f, P, u, K)[source]

Return a polynomial in K[x_{P(1)},..,x_{P(n)}].

Examples

>>> from .domains import ZZ
>>> from .densebasic import dmp_permute
>>> f = ZZ.map([[[2], [1, 0]], []])
>>> dmp_permute(f, [1, 0, 2], 2, ZZ)
[[[2], []], [[1, 0], []]]
>>> dmp_permute(f, [1, 2, 0], 2, ZZ)
[[[1], []], [[2, 0], []]]
modelparameters.sympy.polys.densebasic.dmp_positive_p(f, u, K)[source]

Return True if LC(f) is positive.

Examples

>>> from .domains import ZZ
>>> from .densebasic import dmp_positive_p
>>> dmp_positive_p([[ZZ(1)], [-ZZ(1)]], 1, ZZ)
True
>>> dmp_positive_p([[-ZZ(1)], [ZZ(1)]], 1, ZZ)
False
modelparameters.sympy.polys.densebasic.dmp_raise(f, l, u, K)[source]

Return a multivariate polynomial raised l-levels.

Examples

>>> from .domains import ZZ
>>> from .densebasic import dmp_raise
>>> f = ZZ.map([[], [1, 2]])
>>> dmp_raise(f, 2, 1, ZZ)
[[[[]]], [[[1]], [[2]]]]
modelparameters.sympy.polys.densebasic.dmp_slice(f, m, n, u, K)[source]

Take a continuous subsequence of terms of f in K[X].

modelparameters.sympy.polys.densebasic.dmp_slice_in(f, m, n, j, u, K)[source]

Take a continuous subsequence of terms of f in x_j in K[X].

modelparameters.sympy.polys.densebasic.dmp_strip(f, u)[source]

Remove leading zeros from f in K[X].

Examples

>>> from .densebasic import dmp_strip
>>> dmp_strip([[], [0, 1, 2], [1]], 1)
[[0, 1, 2], [1]]
modelparameters.sympy.polys.densebasic.dmp_swap(f, i, j, u, K)[source]

Transform K[..x_i..x_j..] to K[..x_j..x_i..].

Examples

>>> from .domains import ZZ
>>> from .densebasic import dmp_swap
>>> f = ZZ.map([[[2], [1, 0]], []])
>>> dmp_swap(f, 0, 1, 2, ZZ)
[[[2], []], [[1, 0], []]]
>>> dmp_swap(f, 1, 2, 2, ZZ)
[[[1], [2, 0]], [[]]]
>>> dmp_swap(f, 0, 2, 2, ZZ)
[[[1, 0]], [[2, 0], []]]
modelparameters.sympy.polys.densebasic.dmp_terms_gcd(f, u, K)[source]

Remove GCD of terms from f in K[X].

Examples

>>> from .domains import ZZ
>>> from .densebasic import dmp_terms_gcd
>>> f = ZZ.map([[1, 0], [1, 0, 0], [], []])
>>> dmp_terms_gcd(f, 1, ZZ)
((2, 1), [[1], [1, 0]])
modelparameters.sympy.polys.densebasic.dmp_to_dict(f, u, K=None, zero=False)[source]

Convert a K[X] polynomial to a dict``.

Examples

>>> from .densebasic import dmp_to_dict
>>> dmp_to_dict([[1, 0], [], [2, 3]], 1)
{(0, 0): 3, (0, 1): 2, (2, 1): 1}
>>> dmp_to_dict([], 0)
{}
modelparameters.sympy.polys.densebasic.dmp_to_tuple(f, u)[source]

Convert f into a nested tuple of tuples.

This is needed for hashing. This is similar to dmp_copy().

Examples

>>> from .domains import ZZ
>>> from .densebasic import dmp_to_tuple
>>> f = ZZ.map([[1], [1, 2]])
>>> dmp_to_tuple(f, 1)
((1,), (1, 2))
modelparameters.sympy.polys.densebasic.dmp_true_LT(f, u, K)[source]

Return the leading term c * x_1**n_1 ... x_k**n_k.

Examples

>>> from .domains import ZZ
>>> from .densebasic import dmp_true_LT
>>> f = ZZ.map([[4], [2, 0], [3, 0, 0]])
>>> dmp_true_LT(f, 1, ZZ)
((2, 0), 4)
modelparameters.sympy.polys.densebasic.dmp_validate(f, K=None)[source]

Return the number of levels in f and recursively strip it.

Examples

>>> from .densebasic import dmp_validate
>>> dmp_validate([[], [0, 1, 2], [1]])
([[1, 2], [1]], 1)
>>> dmp_validate([[1], 1])
Traceback (most recent call last):
...
ValueError: invalid data structure for a multivariate polynomial
modelparameters.sympy.polys.densebasic.dmp_zero(u)[source]

Return a multivariate zero.

Examples

>>> from .densebasic import dmp_zero
>>> dmp_zero(4)
[[[[[]]]]]
modelparameters.sympy.polys.densebasic.dmp_zero_p(f, u)[source]

Return True if f is zero in K[X].

Examples

>>> from .densebasic import dmp_zero_p
>>> dmp_zero_p([[[[[]]]]], 4)
True
>>> dmp_zero_p([[[[[1]]]]], 4)
False
modelparameters.sympy.polys.densebasic.dmp_zeros(n, u, K)[source]

Return a list of multivariate zeros.

Examples

>>> from .domains import ZZ
>>> from .densebasic import dmp_zeros
>>> dmp_zeros(3, 2, ZZ)
[[[[]]], [[[]]], [[[]]]]
>>> dmp_zeros(3, -1, ZZ)
[0, 0, 0]
modelparameters.sympy.polys.densebasic.dup_LC(f, K)

Return leading coefficient of f.

Examples

>>> from .domains import ZZ
>>> from .densebasic import poly_LC
>>> poly_LC([], ZZ)
0
>>> poly_LC([ZZ(1), ZZ(2), ZZ(3)], ZZ)
1
modelparameters.sympy.polys.densebasic.dup_TC(f, K)

Return trailing coefficient of f.

Examples

>>> from .domains import ZZ
>>> from .densebasic import poly_TC
>>> poly_TC([], ZZ)
0
>>> poly_TC([ZZ(1), ZZ(2), ZZ(3)], ZZ)
3
modelparameters.sympy.polys.densebasic.dup_apply_pairs(f, g, h, args, K)[source]

Apply h to pairs of coefficients of f and g.

Examples

>>> from .domains import ZZ
>>> from .densebasic import dup_apply_pairs
>>> h = lambda x, y, z: 2*x + y - z
>>> dup_apply_pairs([1, 2, 3], [3, 2, 1], h, (1,), ZZ)
[4, 5, 6]
modelparameters.sympy.polys.densebasic.dup_convert(f, K0, K1)[source]

Convert the ground domain of f from K0 to K1.

Examples

>>> from .rings import ring
>>> from .domains import ZZ
>>> from .densebasic import dup_convert
>>> R, x = ring("x", ZZ)
>>> dup_convert([R(1), R(2)], R.to_domain(), ZZ)
[1, 2]
>>> dup_convert([ZZ(1), ZZ(2)], ZZ, R.to_domain())
[1, 2]
modelparameters.sympy.polys.densebasic.dup_copy(f)[source]

Create a new copy of a polynomial f in K[x].

Examples

>>> from .domains import ZZ
>>> from .densebasic import dup_copy
>>> f = ZZ.map([1, 2, 3, 0])
>>> dup_copy([1, 2, 3, 0])
[1, 2, 3, 0]
modelparameters.sympy.polys.densebasic.dup_deflate(f, K)[source]

Map x**m to y in a polynomial in K[x].

Examples

>>> from .domains import ZZ
>>> from .densebasic import dup_deflate
>>> f = ZZ.map([1, 0, 0, 1, 0, 0, 1])
>>> dup_deflate(f, ZZ)
(3, [1, 1, 1])
modelparameters.sympy.polys.densebasic.dup_degree(f)[source]

Return the leading degree of f in K[x].

Note that the degree of 0 is negative infinity (the SymPy object -oo).

Examples

>>> from .domains import ZZ
>>> from .densebasic import dup_degree
>>> f = ZZ.map([1, 2, 0, 3])
>>> dup_degree(f)
3
modelparameters.sympy.polys.densebasic.dup_from_dict(f, K)[source]

Create a K[x] polynomial from a dict.

Examples

>>> from .domains import ZZ
>>> from .densebasic import dup_from_dict
>>> dup_from_dict({(0,): ZZ(7), (2,): ZZ(5), (4,): ZZ(1)}, ZZ)
[1, 0, 5, 0, 7]
>>> dup_from_dict({}, ZZ)
[]
modelparameters.sympy.polys.densebasic.dup_from_raw_dict(f, K)[source]

Create a K[x] polynomial from a raw dict.

Examples

>>> from .domains import ZZ
>>> from .densebasic import dup_from_raw_dict
>>> dup_from_raw_dict({0: ZZ(7), 2: ZZ(5), 4: ZZ(1)}, ZZ)
[1, 0, 5, 0, 7]
modelparameters.sympy.polys.densebasic.dup_from_sympy(f, K)[source]

Convert the ground domain of f from SymPy to K.

Examples

>>> from .. import S
>>> from .domains import ZZ
>>> from .densebasic import dup_from_sympy
>>> dup_from_sympy([S(1), S(2)], ZZ) == [ZZ(1), ZZ(2)]
True
modelparameters.sympy.polys.densebasic.dup_inflate(f, m, K)[source]

Map y to x**m in a polynomial in K[x].

Examples

>>> from .domains import ZZ
>>> from .densebasic import dup_inflate
>>> f = ZZ.map([1, 1, 1])
>>> dup_inflate(f, 3, ZZ)
[1, 0, 0, 1, 0, 0, 1]
modelparameters.sympy.polys.densebasic.dup_multi_deflate(polys, K)[source]

Map x**m to y in a set of polynomials in K[x].

Examples

>>> from .domains import ZZ
>>> from .densebasic import dup_multi_deflate
>>> f = ZZ.map([1, 0, 2, 0, 3])
>>> g = ZZ.map([4, 0, 0])
>>> dup_multi_deflate((f, g), ZZ)
(2, ([1, 2, 3], [4, 0]))
modelparameters.sympy.polys.densebasic.dup_normal(f, K)[source]

Normalize univariate polynomial in the given domain.

Examples

>>> from .domains import ZZ
>>> from .densebasic import dup_normal
>>> dup_normal([0, 1.5, 2, 3], ZZ)
[1, 2, 3]
modelparameters.sympy.polys.densebasic.dup_nth(f, n, K)[source]

Return the n-th coefficient of f in K[x].

Examples

>>> from .domains import ZZ
>>> from .densebasic import dup_nth
>>> f = ZZ.map([1, 2, 3])
>>> dup_nth(f, 0, ZZ)
3
>>> dup_nth(f, 4, ZZ)
0
modelparameters.sympy.polys.densebasic.dup_random(n, a, b, K)[source]

Return a polynomial of degree n with coefficients in [a, b].

Examples

>>> from .domains import ZZ
>>> from .densebasic import dup_random
>>> dup_random(3, -10, 10, ZZ) 
[-2, -8, 9, -4]
modelparameters.sympy.polys.densebasic.dup_reverse(f)[source]

Compute x**n * f(1/x), i.e.: reverse f in K[x].

Examples

>>> from .domains import ZZ
>>> from .densebasic import dup_reverse
>>> f = ZZ.map([1, 2, 3, 0])
>>> dup_reverse(f)
[3, 2, 1]
modelparameters.sympy.polys.densebasic.dup_slice(f, m, n, K)[source]

Take a continuous subsequence of terms of f in K[x].

modelparameters.sympy.polys.densebasic.dup_strip(f)[source]

Remove leading zeros from f in K[x].

Examples

>>> from .densebasic import dup_strip
>>> dup_strip([0, 0, 1, 2, 3, 0])
[1, 2, 3, 0]
modelparameters.sympy.polys.densebasic.dup_terms_gcd(f, K)[source]

Remove GCD of terms from f in K[x].

Examples

>>> from .domains import ZZ
>>> from .densebasic import dup_terms_gcd
>>> f = ZZ.map([1, 0, 1, 0, 0])
>>> dup_terms_gcd(f, ZZ)
(2, [1, 0, 1])
modelparameters.sympy.polys.densebasic.dup_to_dict(f, K=None, zero=False)[source]

Convert K[x] polynomial to a dict.

Examples

>>> from .densebasic import dup_to_dict
>>> dup_to_dict([1, 0, 5, 0, 7])
{(0,): 7, (2,): 5, (4,): 1}
>>> dup_to_dict([])
{}
modelparameters.sympy.polys.densebasic.dup_to_raw_dict(f, K=None, zero=False)[source]

Convert a K[x] polynomial to a raw dict.

Examples

>>> from .densebasic import dup_to_raw_dict
>>> dup_to_raw_dict([1, 0, 5, 0, 7])
{0: 7, 2: 5, 4: 1}
modelparameters.sympy.polys.densebasic.dup_to_tuple(f)[source]

Convert f into a tuple.

This is needed for hashing. This is similar to dup_copy().

Examples

>>> from .domains import ZZ
>>> from .densebasic import dup_copy
>>> f = ZZ.map([1, 2, 3, 0])
>>> dup_copy([1, 2, 3, 0])
[1, 2, 3, 0]
modelparameters.sympy.polys.densebasic.poly_LC(f, K)[source]

Return leading coefficient of f.

Examples

>>> from .domains import ZZ
>>> from .densebasic import poly_LC
>>> poly_LC([], ZZ)
0
>>> poly_LC([ZZ(1), ZZ(2), ZZ(3)], ZZ)
1
modelparameters.sympy.polys.densebasic.poly_TC(f, K)[source]

Return trailing coefficient of f.

Examples

>>> from .domains import ZZ
>>> from .densebasic import poly_TC
>>> poly_TC([], ZZ)
0
>>> poly_TC([ZZ(1), ZZ(2), ZZ(3)], ZZ)
3

modelparameters.sympy.polys.densetools module

Advanced tools for dense recursive polynomials in K[x] or K[X].

modelparameters.sympy.polys.densetools.dmp_clear_denoms(f, u, K0, K1=None, convert=False)[source]

Clear denominators, i.e. transform K_0 to K_1.

Examples

>>> from ..polys import ring, QQ
>>> R, x,y = ring("x,y", QQ)
>>> f = QQ(1,2)*x + QQ(1,3)*y + 1
>>> R.dmp_clear_denoms(f, convert=False)
(6, 3*x + 2*y + 6)
>>> R.dmp_clear_denoms(f, convert=True)
(6, 3*x + 2*y + 6)
modelparameters.sympy.polys.densetools.dmp_compose(f, g, u, K)[source]

Evaluate functional composition f(g) in K[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> R.dmp_compose(x*y + 2*x + y, y)
y**2 + 3*y
modelparameters.sympy.polys.densetools.dmp_diff(f, m, u, K)[source]

m-th order derivative in x_0 of a polynomial in K[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> f = x*y**2 + 2*x*y + 3*x + 2*y**2 + 3*y + 1
>>> R.dmp_diff(f, 1)
y**2 + 2*y + 3
>>> R.dmp_diff(f, 2)
0
modelparameters.sympy.polys.densetools.dmp_diff_eval_in(f, m, a, j, u, K)[source]

Differentiate and evaluate a polynomial in x_j at a in K[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> f = x*y**2 + 2*x*y + 3*x + 2*y**2 + 3*y + 1
>>> R.dmp_diff_eval_in(f, 1, 2, 0)
y**2 + 2*y + 3
>>> R.dmp_diff_eval_in(f, 1, 2, 1)
6*x + 11
modelparameters.sympy.polys.densetools.dmp_diff_in(f, m, j, u, K)[source]

m-th order derivative in x_j of a polynomial in K[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> f = x*y**2 + 2*x*y + 3*x + 2*y**2 + 3*y + 1
>>> R.dmp_diff_in(f, 1, 0)
y**2 + 2*y + 3
>>> R.dmp_diff_in(f, 1, 1)
2*x*y + 2*x + 4*y + 3
modelparameters.sympy.polys.densetools.dmp_eval(f, a, u, K)[source]

Evaluate a polynomial at x_0 = a in K[X] using the Horner scheme.

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> R.dmp_eval(2*x*y + 3*x + y + 2, 2)
5*y + 8
modelparameters.sympy.polys.densetools.dmp_eval_in(f, a, j, u, K)[source]

Evaluate a polynomial at x_j = a in K[X] using the Horner scheme.

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> f = 2*x*y + 3*x + y + 2
>>> R.dmp_eval_in(f, 2, 0)
5*y + 8
>>> R.dmp_eval_in(f, 2, 1)
7*x + 4
modelparameters.sympy.polys.densetools.dmp_eval_tail(f, A, u, K)[source]

Evaluate a polynomial at x_j = a_j, ... in K[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> f = 2*x*y + 3*x + y + 2
>>> R.dmp_eval_tail(f, [2])
7*x + 4
>>> R.dmp_eval_tail(f, [2, 2])
18
modelparameters.sympy.polys.densetools.dmp_ground_content(f, u, K)[source]

Compute the GCD of coefficients of f in K[X].

Examples

>>> from ..polys import ring, ZZ, QQ
>>> R, x,y = ring("x,y", ZZ)
>>> f = 2*x*y + 6*x + 4*y + 12
>>> R.dmp_ground_content(f)
2
>>> R, x,y = ring("x,y", QQ)
>>> f = 2*x*y + 6*x + 4*y + 12
>>> R.dmp_ground_content(f)
2
modelparameters.sympy.polys.densetools.dmp_ground_extract(f, g, u, K)[source]

Extract common content from a pair of polynomials in K[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> R.dmp_ground_extract(6*x*y + 12*x + 18, 4*x*y + 8*x + 12)
(2, 3*x*y + 6*x + 9, 2*x*y + 4*x + 6)
modelparameters.sympy.polys.densetools.dmp_ground_monic(f, u, K)[source]

Divide all coefficients by LC(f) in K[X].

Examples

>>> from ..polys import ring, ZZ, QQ
>>> R, x,y = ring("x,y", ZZ)
>>> f = 3*x**2*y + 6*x**2 + 3*x*y + 9*y + 3
>>> R.dmp_ground_monic(f)
x**2*y + 2*x**2 + x*y + 3*y + 1
>>> R, x,y = ring("x,y", QQ)
>>> f = 3*x**2*y + 8*x**2 + 5*x*y + 6*x + 2*y + 3
>>> R.dmp_ground_monic(f)
x**2*y + 8/3*x**2 + 5/3*x*y + 2*x + 2/3*y + 1
modelparameters.sympy.polys.densetools.dmp_ground_primitive(f, u, K)[source]

Compute content and the primitive form of f in K[X].

Examples

>>> from ..polys import ring, ZZ, QQ
>>> R, x,y = ring("x,y", ZZ)
>>> f = 2*x*y + 6*x + 4*y + 12
>>> R.dmp_ground_primitive(f)
(2, x*y + 3*x + 2*y + 6)
>>> R, x,y = ring("x,y", QQ)
>>> f = 2*x*y + 6*x + 4*y + 12
>>> R.dmp_ground_primitive(f)
(2, x*y + 3*x + 2*y + 6)
modelparameters.sympy.polys.densetools.dmp_ground_trunc(f, p, u, K)[source]

Reduce a K[X] polynomial modulo a constant p in K.

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> f = 3*x**2*y + 8*x**2 + 5*x*y + 6*x + 2*y + 3
>>> R.dmp_ground_trunc(f, ZZ(3))
-x**2 - x*y - y
modelparameters.sympy.polys.densetools.dmp_integrate(f, m, u, K)[source]

Computes the indefinite integral of f in x_0 in K[X].

Examples

>>> from ..polys import ring, QQ
>>> R, x,y = ring("x,y", QQ)
>>> R.dmp_integrate(x + 2*y, 1)
1/2*x**2 + 2*x*y
>>> R.dmp_integrate(x + 2*y, 2)
1/6*x**3 + x**2*y
modelparameters.sympy.polys.densetools.dmp_integrate_in(f, m, j, u, K)[source]

Computes the indefinite integral of f in x_j in K[X].

Examples

>>> from ..polys import ring, QQ
>>> R, x,y = ring("x,y", QQ)
>>> R.dmp_integrate_in(x + 2*y, 1, 0)
1/2*x**2 + 2*x*y
>>> R.dmp_integrate_in(x + 2*y, 1, 1)
x*y + y**2
modelparameters.sympy.polys.densetools.dmp_lift(f, u, K)[source]

Convert algebraic coefficients to integers in K[X].

Examples

>>> from ..polys import ring, QQ
>>> from .. import I
>>> K = QQ.algebraic_field(I)
>>> R, x = ring("x", K)
>>> f = x**2 + K([QQ(1), QQ(0)])*x + K([QQ(2), QQ(0)])
>>> R.dmp_lift(f)
x**8 + 2*x**6 + 9*x**4 - 8*x**2 + 16
modelparameters.sympy.polys.densetools.dmp_revert(f, g, u, K)[source]

Compute f**(-1) mod x**n using Newton iteration.

Examples

>>> from ..polys import ring, QQ
>>> R, x,y = ring("x,y", QQ)
modelparameters.sympy.polys.densetools.dmp_trunc(f, p, u, K)[source]

Reduce a K[X] polynomial modulo a polynomial p in K[Y].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> f = 3*x**2*y + 8*x**2 + 5*x*y + 6*x + 2*y + 3
>>> g = (y - 1).drop(x)
>>> R.dmp_trunc(f, g)
11*x**2 + 11*x + 5
modelparameters.sympy.polys.densetools.dup_clear_denoms(f, K0, K1=None, convert=False)[source]

Clear denominators, i.e. transform K_0 to K_1.

Examples

>>> from ..polys import ring, QQ
>>> R, x = ring("x", QQ)
>>> f = QQ(1,2)*x + QQ(1,3)
>>> R.dup_clear_denoms(f, convert=False)
(6, 3*x + 2)
>>> R.dup_clear_denoms(f, convert=True)
(6, 3*x + 2)
modelparameters.sympy.polys.densetools.dup_compose(f, g, K)[source]

Evaluate functional composition f(g) in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_compose(x**2 + x, x - 1)
x**2 - x
modelparameters.sympy.polys.densetools.dup_content(f, K)[source]

Compute the GCD of coefficients of f in K[x].

Examples

>>> from ..polys import ring, ZZ, QQ
>>> R, x = ring("x", ZZ)
>>> f = 6*x**2 + 8*x + 12
>>> R.dup_content(f)
2
>>> R, x = ring("x", QQ)
>>> f = 6*x**2 + 8*x + 12
>>> R.dup_content(f)
2
modelparameters.sympy.polys.densetools.dup_decompose(f, K)[source]

Computes functional decomposition of f in K[x].

Given a univariate polynomial f with coefficients in a field of characteristic zero, returns list [f_1, f_2, ..., f_n], where:

f = f_1 o f_2 o ... f_n = f_1(f_2(... f_n))

and f_2, ..., f_n are monic and homogeneous polynomials of at least second degree.

Unlike factorization, complete functional decompositions of polynomials are not unique, consider examples:

  1. f o g = f(x + b) o (g - b)

  2. x**n o x**m = x**m o x**n

  3. T_n o T_m = T_m o T_n

where T_n and T_m are Chebyshev polynomials.

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_decompose(x**4 - 2*x**3 + x**2)
[x**2, x**2 - x]

References

  1. [Kozen89]

modelparameters.sympy.polys.densetools.dup_diff(f, m, K)[source]

m-th order derivative of a polynomial in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_diff(x**3 + 2*x**2 + 3*x + 4, 1)
3*x**2 + 4*x + 3
>>> R.dup_diff(x**3 + 2*x**2 + 3*x + 4, 2)
6*x + 4
modelparameters.sympy.polys.densetools.dup_eval(f, a, K)[source]

Evaluate a polynomial at x = a in K[x] using Horner scheme.

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_eval(x**2 + 2*x + 3, 2)
11
modelparameters.sympy.polys.densetools.dup_extract(f, g, K)[source]

Extract common content from a pair of polynomials in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_extract(6*x**2 + 12*x + 18, 4*x**2 + 8*x + 12)
(2, 3*x**2 + 6*x + 9, 2*x**2 + 4*x + 6)
modelparameters.sympy.polys.densetools.dup_integrate(f, m, K)[source]

Computes the indefinite integral of f in K[x].

Examples

>>> from ..polys import ring, QQ
>>> R, x = ring("x", QQ)
>>> R.dup_integrate(x**2 + 2*x, 1)
1/3*x**3 + x**2
>>> R.dup_integrate(x**2 + 2*x, 2)
1/12*x**4 + 1/3*x**3
modelparameters.sympy.polys.densetools.dup_mirror(f, K)[source]

Evaluate efficiently the composition f(-x) in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_mirror(x**3 + 2*x**2 - 4*x + 2)
-x**3 + 2*x**2 + 4*x + 2
modelparameters.sympy.polys.densetools.dup_monic(f, K)[source]

Divide all coefficients by LC(f) in K[x].

Examples

>>> from ..polys import ring, ZZ, QQ
>>> R, x = ring("x", ZZ)
>>> R.dup_monic(3*x**2 + 6*x + 9)
x**2 + 2*x + 3
>>> R, x = ring("x", QQ)
>>> R.dup_monic(3*x**2 + 4*x + 2)
x**2 + 4/3*x + 2/3
modelparameters.sympy.polys.densetools.dup_primitive(f, K)[source]

Compute content and the primitive form of f in K[x].

Examples

>>> from ..polys import ring, ZZ, QQ
>>> R, x = ring("x", ZZ)
>>> f = 6*x**2 + 8*x + 12
>>> R.dup_primitive(f)
(2, 3*x**2 + 4*x + 6)
>>> R, x = ring("x", QQ)
>>> f = 6*x**2 + 8*x + 12
>>> R.dup_primitive(f)
(2, 3*x**2 + 4*x + 6)
modelparameters.sympy.polys.densetools.dup_real_imag(f, K)[source]

Return bivariate polynomials f1 and f2, such that f = f1 + f2*I.

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> R.dup_real_imag(x**3 + x**2 + x + 1)
(x**3 + x**2 - 3*x*y**2 + x - y**2 + 1, 3*x**2*y + 2*x*y - y**3 + y)
modelparameters.sympy.polys.densetools.dup_revert(f, n, K)[source]

Compute f**(-1) mod x**n using Newton iteration.

This function computes first 2**n terms of a polynomial that is a result of inversion of a polynomial modulo x**n. This is useful to efficiently compute series expansion of 1/f.

Examples

>>> from ..polys import ring, QQ
>>> R, x = ring("x", QQ)
>>> f = -QQ(1,720)*x**6 + QQ(1,24)*x**4 - QQ(1,2)*x**2 + 1
>>> R.dup_revert(f, 8)
61/720*x**6 + 5/24*x**4 + 1/2*x**2 + 1
modelparameters.sympy.polys.densetools.dup_scale(f, a, K)[source]

Evaluate efficiently composition f(a*x) in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_scale(x**2 - 2*x + 1, ZZ(2))
4*x**2 - 4*x + 1
modelparameters.sympy.polys.densetools.dup_shift(f, a, K)[source]

Evaluate efficiently Taylor shift f(x + a) in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_shift(x**2 - 2*x + 1, ZZ(2))
x**2 + 2*x + 1
modelparameters.sympy.polys.densetools.dup_sign_variations(f, K)[source]

Compute the number of sign variations of f in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_sign_variations(x**4 - x**2 - x + 1)
2
modelparameters.sympy.polys.densetools.dup_transform(f, p, q, K)[source]

Evaluate functional transformation q**n * f(p/q) in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_transform(x**2 - 2*x + 1, x**2 + 1, x - 1)
x**4 - 2*x**3 + 5*x**2 - 4*x + 4
modelparameters.sympy.polys.densetools.dup_trunc(f, p, K)[source]

Reduce a K[x] polynomial modulo a constant p in K.

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_trunc(2*x**3 + 3*x**2 + 5*x + 7, ZZ(3))
-x**3 - x + 1

modelparameters.sympy.polys.dispersion module

modelparameters.sympy.polys.dispersion.dispersion(p, q=None, *gens, **args)[source]

Compute the dispersion of polynomials.

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

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

and for a single polynomial operatorname{dis}(f) := operatorname{dis}(f, f). Note that we make the definition max{} := -infty.

Examples

>>> from .. import poly
>>> from .dispersion import dispersion, dispersionset
>>> from ..abc import x

Dispersion set and dispersion of a simple polynomial:

>>> fp = poly((x - 3)*(x + 3), x)
>>> sorted(dispersionset(fp))
[0, 6]
>>> dispersion(fp)
6

Note that the definition of the dispersion is not symmetric:

>>> fp = poly(x**4 - 3*x**2 + 1, x)
>>> gp = fp.shift(-3)
>>> sorted(dispersionset(fp, gp))
[2, 3, 4]
>>> dispersion(fp, gp)
4
>>> sorted(dispersionset(gp, fp))
[]
>>> dispersion(gp, fp)
-oo

The maximum of an empty set is defined to be -infty as seen in this example.

Computing the dispersion also works over field extensions:

>>> from .. import sqrt
>>> fp = poly(x**2 + sqrt(5)*x - 1, x, domain='QQ<sqrt(5)>')
>>> gp = poly(x**2 + (2 + sqrt(5))*x + sqrt(5), x, domain='QQ<sqrt(5)>')
>>> sorted(dispersionset(fp, gp))
[2]
>>> sorted(dispersionset(gp, fp))
[1, 4]

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

>>> from ..abc import a
>>> fp = poly(4*x**4 + (4*a + 8)*x**3 + (a**2 + 6*a + 4)*x**2 + (a**2 + 2*a)*x, x)
>>> sorted(dispersionset(fp))
[0, 1]

See also

dispersionset

References

  1. [ManWright94]

  2. [Koepf98]

  3. [Abramov71]

  4. [Man93]

modelparameters.sympy.polys.dispersion.dispersionset(p, q=None, *gens, **args)[source]

Compute the dispersion set of two polynomials.

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

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

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

Examples

>>> from .. import poly
>>> from .dispersion import dispersion, dispersionset
>>> from ..abc import x

Dispersion set and dispersion of a simple polynomial:

>>> fp = poly((x - 3)*(x + 3), x)
>>> sorted(dispersionset(fp))
[0, 6]
>>> dispersion(fp)
6

Note that the definition of the dispersion is not symmetric:

>>> fp = poly(x**4 - 3*x**2 + 1, x)
>>> gp = fp.shift(-3)
>>> sorted(dispersionset(fp, gp))
[2, 3, 4]
>>> dispersion(fp, gp)
4
>>> sorted(dispersionset(gp, fp))
[]
>>> dispersion(gp, fp)
-oo

Computing the dispersion also works over field extensions:

>>> from .. import sqrt
>>> fp = poly(x**2 + sqrt(5)*x - 1, x, domain='QQ<sqrt(5)>')
>>> gp = poly(x**2 + (2 + sqrt(5))*x + sqrt(5), x, domain='QQ<sqrt(5)>')
>>> sorted(dispersionset(fp, gp))
[2]
>>> sorted(dispersionset(gp, fp))
[1, 4]

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

>>> from ..abc import a
>>> fp = poly(4*x**4 + (4*a + 8)*x**3 + (a**2 + 6*a + 4)*x**2 + (a**2 + 2*a)*x, x)
>>> sorted(dispersionset(fp))
[0, 1]

See also

dispersion

References

  1. [ManWright94]

  2. [Koepf98]

  3. [Abramov71]

  4. [Man93]

modelparameters.sympy.polys.distributedmodules module

Sparse distributed elements of free modules over multivariate (generalized) polynomial rings.

This code and its data structures are very much like the distributed polynomials, except that the first “exponent” of the monomial is a module generator index. That is, the multi-exponent (i, e_1, ..., e_n) represents the “monomial” x_1^{e_1} cdots x_n^{e_n} f_i of the free module F generated by f_1, ldots, f_r over (a localization of) the ring K[x_1, ldots, x_n]. A module element is simply stored as a list of terms ordered by the monomial order. Here a term is a pair of a multi-exponent and a coefficient. In general, this coefficient should never be zero (since it can then be omitted). The zero module element is stored as an empty list.

The main routines are sdm_nf_mora and sdm_groebner which can be used to compute, respectively, weak normal forms and standard bases. They work with arbitrary (not necessarily global) monomial orders.

In general, product orders have to be used to construct valid monomial orders for modules. However, lex can be used as-is.

Note that the “level” (number of variables, i.e. parameter u+1 in distributedpolys.py) is never needed in this code.

The main reference for this file is [SCA], “A Singular Introduction to Commutative Algebra”.

modelparameters.sympy.polys.distributedmodules.sdm_LC(f, K)[source]

Returns the leading coeffcient of f.

modelparameters.sympy.polys.distributedmodules.sdm_LM(f)[source]

Returns the leading monomial of f.

Only valid if f ne 0.

Examples

>>> from .distributedmodules import sdm_LM, sdm_from_dict
>>> from ..polys import QQ, lex
>>> dic = {(1, 2, 3): QQ(1), (4, 0, 0): QQ(1), (4, 0, 1): QQ(1)}
>>> sdm_LM(sdm_from_dict(dic, lex))
(4, 0, 1)
modelparameters.sympy.polys.distributedmodules.sdm_LT(f)[source]

Returns the leading term of f.

Only valid if f ne 0.

Examples

>>> from .distributedmodules import sdm_LT, sdm_from_dict
>>> from ..polys import QQ, lex
>>> dic = {(1, 2, 3): QQ(1), (4, 0, 0): QQ(2), (4, 0, 1): QQ(3)}
>>> sdm_LT(sdm_from_dict(dic, lex))
((4, 0, 1), 3)
modelparameters.sympy.polys.distributedmodules.sdm_add(f, g, O, K)[source]

Add two module elements f, g.

Addition is done over the ground field K, monomials are ordered according to O.

Examples

All examples use lexicographic order.

(xy f_1) + (f_2) = f_2 + xy f_1

>>> from .distributedmodules import sdm_add
>>> from ..polys import lex, QQ
>>> sdm_add([((1, 1, 1), QQ(1))], [((2, 0, 0), QQ(1))], lex, QQ)
[((2, 0, 0), 1), ((1, 1, 1), 1)]

(xy f_1) + (-xy f_1) = 0`

>>> sdm_add([((1, 1, 1), QQ(1))], [((1, 1, 1), QQ(-1))], lex, QQ)
[]

(f_1) + (2f_1) = 3f_1

>>> sdm_add([((1, 0, 0), QQ(1))], [((1, 0, 0), QQ(2))], lex, QQ)
[((1, 0, 0), 3)]

(yf_1) + (xf_1) = xf_1 + yf_1

>>> sdm_add([((1, 0, 1), QQ(1))], [((1, 1, 0), QQ(1))], lex, QQ)
[((1, 1, 0), 1), ((1, 0, 1), 1)]
modelparameters.sympy.polys.distributedmodules.sdm_deg(f)[source]

Degree of f.

This is the maximum of the degrees of all its monomials. Invalid if f is zero.

Examples

>>> from .distributedmodules import sdm_deg
>>> sdm_deg([((1, 2, 3), 1), ((10, 0, 1), 1), ((2, 3, 4), 4)])
7
modelparameters.sympy.polys.distributedmodules.sdm_ecart(f)[source]

Compute the ecart of f.

This is defined to be the difference of the total degree of f and the total degree of the leading monomial of f [SCA, defn 2.3.7].

Invalid if f is zero.

Examples

>>> from .distributedmodules import sdm_ecart
>>> sdm_ecart([((1, 2, 3), 1), ((1, 0, 1), 1)])
0
>>> sdm_ecart([((2, 2, 1), 1), ((1, 5, 1), 1)])
3
modelparameters.sympy.polys.distributedmodules.sdm_from_dict(d, O)[source]

Create an sdm from a dictionary.

Here O is the monomial order to use.

>>> from .distributedmodules import sdm_from_dict
>>> from ..polys import QQ, lex
>>> dic = {(1, 1, 0): QQ(1), (1, 0, 0): QQ(2), (0, 1, 0): QQ(0)}
>>> sdm_from_dict(dic, lex)
[((1, 1, 0), 1), ((1, 0, 0), 2)]
modelparameters.sympy.polys.distributedmodules.sdm_from_vector(vec, O, K, **opts)[source]

Create an sdm from an iterable of expressions.

Coefficients are created in the ground field K, and terms are ordered according to monomial order O. Named arguments are passed on to the polys conversion code and can be used to specify for example generators.

Examples

>>> from .distributedmodules import sdm_from_vector
>>> from ..abc import x, y, z
>>> from ..polys import QQ, lex
>>> sdm_from_vector([x**2+y**2, 2*z], lex, QQ)
[((1, 0, 0, 1), 2), ((0, 2, 0, 0), 1), ((0, 0, 2, 0), 1)]
modelparameters.sympy.polys.distributedmodules.sdm_groebner(G, NF, O, K, extended=False)[source]

Compute a minimal standard basis of G with respect to order O.

The algorithm uses a normal form NF, for example sdm_nf_mora. The ground field is assumed to be K, and monomials ordered according to O.

Let N denote the submodule generated by elements of G. A standard basis for N is a subset S of N, such that in(S) = in(N), where for any subset X of F, in(X) denotes the submodule generated by the initial forms of elements of X. [SCA, defn 2.3.2]

A standard basis is called minimal if no subset of it is a standard basis.

One may show that standard bases are always generating sets.

Minimal standard bases are not unique. This algorithm computes a deterministic result, depending on the particular order of G.

If extended=True, also compute the transition matrix from the initial generators to the groebner basis. That is, return a list of coefficient vectors, expressing the elements of the groebner basis in terms of the elements of G.

This functions implements the “sugar” strategy, see

Giovini et al: “One sugar cube, please” OR Selection strategies in Buchberger algorithm.

modelparameters.sympy.polys.distributedmodules.sdm_monomial_deg(M)[source]

Return the total degree of M.

Examples

For example, the total degree of x^2 y f_5 is 3:

>>> from .distributedmodules import sdm_monomial_deg
>>> sdm_monomial_deg((5, 2, 1))
3
modelparameters.sympy.polys.distributedmodules.sdm_monomial_divides(A, B)[source]

Does there exist a (polynomial) monomial X such that XA = B?

Examples

Positive examples:

In the following examples, the monomial is given in terms of x, y and the generator(s), f_1, f_2 etc. The tuple form of that monomial is used in the call to sdm_monomial_divides. Note: the generator appears last in the expression but first in the tuple and other factors appear in the same order that they appear in the monomial expression.

A = f_1 divides B = f_1

>>> from .distributedmodules import sdm_monomial_divides
>>> sdm_monomial_divides((1, 0, 0), (1, 0, 0))
True

A = f_1 divides B = x^2 y f_1

>>> sdm_monomial_divides((1, 0, 0), (1, 2, 1))
True

A = xy f_5 divides B = x^2 y f_5

>>> sdm_monomial_divides((5, 1, 1), (5, 2, 1))
True

Negative examples:

A = f_1 does not divide B = f_2

>>> sdm_monomial_divides((1, 0, 0), (2, 0, 0))
False

A = x f_1 does not divide B = f_1

>>> sdm_monomial_divides((1, 1, 0), (1, 0, 0))
False

A = xy^2 f_5 does not divide B = y f_5

>>> sdm_monomial_divides((5, 1, 2), (5, 0, 1))
False
modelparameters.sympy.polys.distributedmodules.sdm_monomial_lcm(A, B)[source]

Return the “least common multiple” of A and B.

IF A = M e_j and B = N e_j, where M and N are polynomial monomials, this returns lcm(M, N) e_j. Note that A and B involve distinct monomials.

Otherwise the result is undefined.

>>> from .distributedmodules import sdm_monomial_lcm
>>> sdm_monomial_lcm((1, 2, 3), (1, 0, 5))
(1, 2, 5)
modelparameters.sympy.polys.distributedmodules.sdm_monomial_mul(M, X)[source]

Multiply tuple X representing a monomial of K[X] into the tuple M representing a monomial of F.

Examples

Multiplying xy^3 into x f_1 yields x^2 y^3 f_1:

>>> from .distributedmodules import sdm_monomial_mul
>>> sdm_monomial_mul((1, 1, 0), (1, 3))
(1, 2, 3)
modelparameters.sympy.polys.distributedmodules.sdm_mul_term(f, term, O, K)[source]

Multiply a distributed module element f by a (polynomial) term term.

Multiplication of coefficients is done over the ground field K, and monomials are ordered according to O.

Examples

0 f_1 = 0

>>> from .distributedmodules import sdm_mul_term
>>> from ..polys import lex, QQ
>>> sdm_mul_term([((1, 0, 0), QQ(1))], ((0, 0), QQ(0)), lex, QQ)
[]

x 0 = 0

>>> sdm_mul_term([], ((1, 0), QQ(1)), lex, QQ)
[]

(x) (f_1) = xf_1

>>> sdm_mul_term([((1, 0, 0), QQ(1))], ((1, 0), QQ(1)), lex, QQ)
[((1, 1, 0), 1)]

(2xy) (3x f_1 + 4y f_2) = 8xy^2 f_2 + 6x^2y f_1

>>> f = [((2, 0, 1), QQ(4)), ((1, 1, 0), QQ(3))]
>>> sdm_mul_term(f, ((1, 1), QQ(2)), lex, QQ)
[((2, 1, 2), 8), ((1, 2, 1), 6)]
modelparameters.sympy.polys.distributedmodules.sdm_nf_buchberger(f, G, O, K, phantom=None)[source]

Compute a weak normal form of f with respect to G and order O.

The ground field is assumed to be K, and monomials ordered according to O.

This is the standard Buchberger algorithm for computing weak normal forms with respect to global monomial orders [SCA, algorithm 1.6.10].

If phantom is not None, it should be a pair of “phantom” arguments on which to perform the same computations as on f, G, both results are then returned.

modelparameters.sympy.polys.distributedmodules.sdm_nf_buchberger_reduced(f, G, O, K)[source]

Compute a reduced normal form of f with respect to G and order O.

The ground field is assumed to be K, and monomials ordered according to O.

In contrast to weak normal forms, reduced normal forms are unique, but their computation is more expensive.

This is the standard Buchberger algorithm for computing reduced normal forms with respect to global monomial orders [SCA, algorithm 1.6.11].

The pantom option is not supported, so this normal form cannot be used as a normal form for the “extended” groebner algorithm.

modelparameters.sympy.polys.distributedmodules.sdm_nf_mora(f, G, O, K, phantom=None)[source]

Compute a weak normal form of f with respect to G and order O.

The ground field is assumed to be K, and monomials ordered according to O.

Weak normal forms are defined in [SCA, defn 2.3.3]. They are not unique. This function deterministically computes a weak normal form, depending on the order of G.

The most important property of a weak normal form is the following: if R is the ring associated with the monomial ordering (if the ordering is global, we just have R = K[x_1, ldots, x_n], otherwise it is a certain localization thereof), I any ideal of R and G a standard basis for I, then for any f in R, we have f in I if and only if NF(f | G) = 0.

This is the generalized Mora algorithm for computing weak normal forms with respect to arbitrary monomial orders [SCA, algorithm 2.3.9].

If phantom is not None, it should be a pair of “phantom” arguments on which to perform the same computations as on f, G, both results are then returned.

modelparameters.sympy.polys.distributedmodules.sdm_sort(f, O)[source]

Sort terms in f using the given monomial order O.

modelparameters.sympy.polys.distributedmodules.sdm_spoly(f, g, O, K, phantom=None)[source]

Compute the generalized s-polynomial of f and g.

The ground field is assumed to be K, and monomials ordered according to O.

This is invalid if either of f or g is zero.

If the leading terms of f and g involve different basis elements of F, their s-poly is defined to be zero. Otherwise it is a certain linear combination of f and g in which the leading terms cancel. See [SCA, defn 2.3.6] for details.

If phantom is not None, it should be a pair of module elements on which to perform the same operation(s) as on f and g. The in this case both results are returned.

Examples

>>> from .distributedmodules import sdm_spoly
>>> from ..polys import QQ, lex
>>> f = [((2, 1, 1), QQ(1)), ((1, 0, 1), QQ(1))]
>>> g = [((2, 3, 0), QQ(1))]
>>> h = [((1, 2, 3), QQ(1))]
>>> sdm_spoly(f, h, lex, QQ)
[]
>>> sdm_spoly(f, g, lex, QQ)
[((1, 2, 1), 1)]
modelparameters.sympy.polys.distributedmodules.sdm_strip(f)[source]

Remove terms with zero coefficients from f in K[X].

modelparameters.sympy.polys.distributedmodules.sdm_to_dict(f)[source]

Make a dictionary from a distributed polynomial.

modelparameters.sympy.polys.distributedmodules.sdm_to_vector(f, gens, K, n=None)[source]

Convert sdm f into a list of polynomial expressions.

The generators for the polynomial ring are specified via gens. The rank of the module is guessed, or passed via n. The ground field is assumed to be K.

Examples

>>> from .distributedmodules import sdm_to_vector
>>> from ..abc import x, y, z
>>> from ..polys import QQ, lex
>>> f = [((1, 0, 0, 1), QQ(2)), ((0, 2, 0, 0), QQ(1)), ((0, 0, 2, 0), QQ(1))]
>>> sdm_to_vector(f, [x, y, z], QQ)
[x**2 + y**2, 2*z]
modelparameters.sympy.polys.distributedmodules.sdm_zero()[source]

Return the zero module element.

modelparameters.sympy.polys.euclidtools module

Euclidean algorithms, GCDs, LCMs and polynomial remainder sequences.

modelparameters.sympy.polys.euclidtools.dmp_cancel(f, g, u, K, include=True)[source]

Cancel common factors in a rational function f/g.

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> R.dmp_cancel(2*x**2 - 2, x**2 - 2*x + 1)
(2*x + 2, x - 1)
modelparameters.sympy.polys.euclidtools.dmp_content(f, u, K)[source]

Returns GCD of multivariate coefficients.

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y, = ring("x,y", ZZ)
>>> R.dmp_content(2*x*y + 6*x + 4*y + 12)
2*y + 6
modelparameters.sympy.polys.euclidtools.dmp_discriminant(f, u, K)[source]

Computes discriminant of a polynomial in K[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y,z,t = ring("x,y,z,t", ZZ)
>>> R.dmp_discriminant(x**2*y + x*z + t)
-4*y*t + z**2
modelparameters.sympy.polys.euclidtools.dmp_euclidean_prs(f, g, u, K)[source]

Euclidean polynomial remainder sequence (PRS) in K[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
modelparameters.sympy.polys.euclidtools.dmp_ff_lcm(f, g, u, K)[source]

Computes polynomial LCM over a field in K[X].

Examples

>>> from ..polys import ring, QQ
>>> R, x,y, = ring("x,y", QQ)
>>> f = QQ(1,4)*x**2 + x*y + y**2
>>> g = QQ(1,2)*x**2 + x*y
>>> R.dmp_ff_lcm(f, g)
x**3 + 4*x**2*y + 4*x*y**2
modelparameters.sympy.polys.euclidtools.dmp_ff_prs_gcd(f, g, u, K)[source]

Computes polynomial GCD using subresultants over a field.

Returns (h, cff, cfg) such that a = gcd(f, g), cff = quo(f, h), and cfg = quo(g, h).

Examples

>>> from ..polys import ring, QQ
>>> R, x,y, = ring("x,y", QQ)
>>> f = QQ(1,2)*x**2 + x*y + QQ(1,2)*y**2
>>> g = x**2 + x*y
>>> R.dmp_ff_prs_gcd(f, g)
(x + y, 1/2*x + 1/2*y, x)
modelparameters.sympy.polys.euclidtools.dmp_gcd(f, g, u, K)[source]

Computes polynomial GCD of f and g in K[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y, = ring("x,y", ZZ)
>>> f = x**2 + 2*x*y + y**2
>>> g = x**2 + x*y
>>> R.dmp_gcd(f, g)
x + y
modelparameters.sympy.polys.euclidtools.dmp_gcdex(f, g, u, K)[source]

Extended Euclidean algorithm in F[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
modelparameters.sympy.polys.euclidtools.dmp_half_gcdex(f, g, u, K)[source]

Half extended Euclidean algorithm in F[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
modelparameters.sympy.polys.euclidtools.dmp_inner_gcd(f, g, u, K)[source]

Computes polynomial GCD and cofactors of f and g in K[X].

Returns (h, cff, cfg) such that a = gcd(f, g), cff = quo(f, h), and cfg = quo(g, h).

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y, = ring("x,y", ZZ)
>>> f = x**2 + 2*x*y + y**2
>>> g = x**2 + x*y
>>> R.dmp_inner_gcd(f, g)
(x + y, x + y, x)
modelparameters.sympy.polys.euclidtools.dmp_inner_subresultants(f, g, u, K)[source]

Subresultant PRS algorithm in K[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> f = 3*x**2*y - y**3 - 4
>>> g = x**2 + x*y**3 - 9
>>> a = 3*x*y**4 + y**3 - 27*y + 4
>>> b = -3*y**10 - 12*y**7 + y**6 - 54*y**4 + 8*y**3 + 729*y**2 - 216*y + 16
>>> prs = [f, g, a, b]
>>> sres = [[1], [1], [3, 0, 0, 0, 0], [-3, 0, 0, -12, 1, 0, -54, 8, 729, -216, 16]]
>>> R.dmp_inner_subresultants(f, g) == (prs, sres)
True
modelparameters.sympy.polys.euclidtools.dmp_invert(f, g, u, K)[source]

Compute multiplicative inverse of f modulo g in F[X].

Examples

>>> from ..polys import ring, QQ
>>> R, x = ring("x", QQ)
modelparameters.sympy.polys.euclidtools.dmp_lcm(f, g, u, K)[source]

Computes polynomial LCM of f and g in K[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y, = ring("x,y", ZZ)
>>> f = x**2 + 2*x*y + y**2
>>> g = x**2 + x*y
>>> R.dmp_lcm(f, g)
x**3 + 2*x**2*y + x*y**2
modelparameters.sympy.polys.euclidtools.dmp_primitive(f, u, K)[source]

Returns multivariate content and a primitive polynomial.

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y, = ring("x,y", ZZ)
>>> R.dmp_primitive(2*x*y + 6*x + 4*y + 12)
(2*y + 6, x + 2)
modelparameters.sympy.polys.euclidtools.dmp_primitive_prs(f, g, u, K)[source]

Primitive polynomial remainder sequence (PRS) in K[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
modelparameters.sympy.polys.euclidtools.dmp_prs_resultant(f, g, u, K)[source]

Resultant algorithm in K[X] using subresultant PRS.

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> f = 3*x**2*y - y**3 - 4
>>> g = x**2 + x*y**3 - 9
>>> a = 3*x*y**4 + y**3 - 27*y + 4
>>> b = -3*y**10 - 12*y**7 + y**6 - 54*y**4 + 8*y**3 + 729*y**2 - 216*y + 16
>>> res, prs = R.dmp_prs_resultant(f, g)
>>> res == b             # resultant has n-1 variables
False
>>> res == b.drop(x)
True
>>> prs == [f, g, a, b]
True
modelparameters.sympy.polys.euclidtools.dmp_qq_collins_resultant(f, g, u, K0)[source]

Collins’s modular resultant algorithm in Q[X].

Examples

>>> from ..polys import ring, QQ
>>> R, x,y = ring("x,y", QQ)
>>> f = QQ(1,2)*x + y + QQ(2,3)
>>> g = 2*x*y + x + 3
>>> R.dmp_qq_collins_resultant(f, g)
-2*y**2 - 7/3*y + 5/6
modelparameters.sympy.polys.euclidtools.dmp_qq_heu_gcd(f, g, u, K0)[source]

Heuristic polynomial GCD in Q[X].

Returns (h, cff, cfg) such that a = gcd(f, g), cff = quo(f, h), and cfg = quo(g, h).

Examples

>>> from ..polys import ring, QQ
>>> R, x,y, = ring("x,y", QQ)
>>> f = QQ(1,4)*x**2 + x*y + y**2
>>> g = QQ(1,2)*x**2 + x*y
>>> R.dmp_qq_heu_gcd(f, g)
(x + 2*y, 1/4*x + 1/2*y, 1/2*x)
modelparameters.sympy.polys.euclidtools.dmp_resultant(f, g, u, K, includePRS=False)[source]

Computes resultant of two polynomials in K[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> f = 3*x**2*y - y**3 - 4
>>> g = x**2 + x*y**3 - 9
>>> R.dmp_resultant(f, g)
-3*y**10 - 12*y**7 + y**6 - 54*y**4 + 8*y**3 + 729*y**2 - 216*y + 16
modelparameters.sympy.polys.euclidtools.dmp_rr_lcm(f, g, u, K)[source]

Computes polynomial LCM over a ring in K[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y, = ring("x,y", ZZ)
>>> f = x**2 + 2*x*y + y**2
>>> g = x**2 + x*y
>>> R.dmp_rr_lcm(f, g)
x**3 + 2*x**2*y + x*y**2
modelparameters.sympy.polys.euclidtools.dmp_rr_prs_gcd(f, g, u, K)[source]

Computes polynomial GCD using subresultants over a ring.

Returns (h, cff, cfg) such that a = gcd(f, g), cff = quo(f, h), and cfg = quo(g, h).

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y, = ring("x,y", ZZ)
>>> f = x**2 + 2*x*y + y**2
>>> g = x**2 + x*y
>>> R.dmp_rr_prs_gcd(f, g)
(x + y, x + y, x)
modelparameters.sympy.polys.euclidtools.dmp_subresultants(f, g, u, K)[source]

Computes subresultant PRS of two polynomials in K[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> f = 3*x**2*y - y**3 - 4
>>> g = x**2 + x*y**3 - 9
>>> a = 3*x*y**4 + y**3 - 27*y + 4
>>> b = -3*y**10 - 12*y**7 + y**6 - 54*y**4 + 8*y**3 + 729*y**2 - 216*y + 16
>>> R.dmp_subresultants(f, g) == [f, g, a, b]
True
modelparameters.sympy.polys.euclidtools.dmp_zz_collins_resultant(f, g, u, K)[source]

Collins’s modular resultant algorithm in Z[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> f = x + y + 2
>>> g = 2*x*y + x + 3
>>> R.dmp_zz_collins_resultant(f, g)
-2*y**2 - 5*y + 1
modelparameters.sympy.polys.euclidtools.dmp_zz_heu_gcd(f, g, u, K)[source]

Heuristic polynomial GCD in Z[X].

Given univariate polynomials f and g in Z[X], returns their GCD and cofactors, i.e. polynomials h, cff and cfg such that:

h = gcd(f, g), cff = quo(f, h) and cfg = quo(g, h)

The algorithm is purely heuristic which means it may fail to compute the GCD. This will be signaled by raising an exception. In this case you will need to switch to another GCD method.

The algorithm computes the polynomial GCD by evaluating polynomials f and g at certain points and computing (fast) integer GCD of those evaluations. The polynomial GCD is recovered from the integer image by interpolation. The evaluation proces reduces f and g variable by variable into a large integer. The final step is to verify if the interpolated polynomial is the correct GCD. This gives cofactors of the input polynomials as a side effect.

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y, = ring("x,y", ZZ)
>>> f = x**2 + 2*x*y + y**2
>>> g = x**2 + x*y
>>> R.dmp_zz_heu_gcd(f, g)
(x + y, x + y, x)

References

  1. [Liao95]

modelparameters.sympy.polys.euclidtools.dmp_zz_modular_resultant(f, g, p, u, K)[source]

Compute resultant of f and g modulo a prime p.

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> f = x + y + 2
>>> g = 2*x*y + x + 3
>>> R.dmp_zz_modular_resultant(f, g, 5)
-2*y**2 + 1
modelparameters.sympy.polys.euclidtools.dup_cancel(f, g, K, include=True)[source]

Cancel common factors in a rational function f/g.

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_cancel(2*x**2 - 2, x**2 - 2*x + 1)
(2*x + 2, x - 1)
modelparameters.sympy.polys.euclidtools.dup_discriminant(f, K)[source]

Computes discriminant of a polynomial in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_discriminant(x**2 + 2*x + 3)
-8
modelparameters.sympy.polys.euclidtools.dup_euclidean_prs(f, g, K)[source]

Euclidean polynomial remainder sequence (PRS) in K[x].

Examples

>>> from ..polys import ring, QQ
>>> R, x = ring("x", QQ)
>>> f = x**8 + x**6 - 3*x**4 - 3*x**3 + 8*x**2 + 2*x - 5
>>> g = 3*x**6 + 5*x**4 - 4*x**2 - 9*x + 21
>>> prs = R.dup_euclidean_prs(f, g)
>>> prs[0]
x**8 + x**6 - 3*x**4 - 3*x**3 + 8*x**2 + 2*x - 5
>>> prs[1]
3*x**6 + 5*x**4 - 4*x**2 - 9*x + 21
>>> prs[2]
-5/9*x**4 + 1/9*x**2 - 1/3
>>> prs[3]
-117/25*x**2 - 9*x + 441/25
>>> prs[4]
233150/19773*x - 102500/6591
>>> prs[5]
-1288744821/543589225
modelparameters.sympy.polys.euclidtools.dup_ff_lcm(f, g, K)[source]

Computes polynomial LCM over a field in K[x].

Examples

>>> from ..polys import ring, QQ
>>> R, x = ring("x", QQ)
>>> f = QQ(1,2)*x**2 + QQ(7,4)*x + QQ(3,2)
>>> g = QQ(1,2)*x**2 + x
>>> R.dup_ff_lcm(f, g)
x**3 + 7/2*x**2 + 3*x
modelparameters.sympy.polys.euclidtools.dup_ff_prs_gcd(f, g, K)[source]

Computes polynomial GCD using subresultants over a field.

Returns (h, cff, cfg) such that a = gcd(f, g), cff = quo(f, h), and cfg = quo(g, h).

Examples

>>> from ..polys import ring, QQ
>>> R, x = ring("x", QQ)
>>> R.dup_ff_prs_gcd(x**2 - 1, x**2 - 3*x + 2)
(x - 1, x + 1, x - 2)
modelparameters.sympy.polys.euclidtools.dup_gcd(f, g, K)[source]

Computes polynomial GCD of f and g in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_gcd(x**2 - 1, x**2 - 3*x + 2)
x - 1
modelparameters.sympy.polys.euclidtools.dup_gcdex(f, g, K)[source]

Extended Euclidean algorithm in F[x].

Returns (s, t, h) such that h = gcd(f, g) and s*f + t*g = h.

Examples

>>> from ..polys import ring, QQ
>>> R, x = ring("x", QQ)
>>> f = x**4 - 2*x**3 - 6*x**2 + 12*x + 15
>>> g = x**3 + x**2 - 4*x - 4
>>> R.dup_gcdex(f, g)
(-1/5*x + 3/5, 1/5*x**2 - 6/5*x + 2, x + 1)
modelparameters.sympy.polys.euclidtools.dup_half_gcdex(f, g, K)[source]

Half extended Euclidean algorithm in F[x].

Returns (s, h) such that h = gcd(f, g) and s*f = h (mod g).

Examples

>>> from ..polys import ring, QQ
>>> R, x = ring("x", QQ)
>>> f = x**4 - 2*x**3 - 6*x**2 + 12*x + 15
>>> g = x**3 + x**2 - 4*x - 4
>>> R.dup_half_gcdex(f, g)
(-1/5*x + 3/5, x + 1)
modelparameters.sympy.polys.euclidtools.dup_inner_gcd(f, g, K)[source]

Computes polynomial GCD and cofactors of f and g in K[x].

Returns (h, cff, cfg) such that a = gcd(f, g), cff = quo(f, h), and cfg = quo(g, h).

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_inner_gcd(x**2 - 1, x**2 - 3*x + 2)
(x - 1, x + 1, x - 2)
modelparameters.sympy.polys.euclidtools.dup_inner_subresultants(f, g, K)[source]

Subresultant PRS algorithm in K[x].

Computes the subresultant polynomial remainder sequence (PRS) and the non-zero scalar subresultants of f and g. By [1] Thm. 3, these are the constants ‘-c’ (- to optimize computation of sign). The first subdeterminant is set to 1 by convention to match the polynomial and the scalar subdeterminants. If ‘deg(f) < deg(g)’, the subresultants of ‘(g,f)’ are computed.

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_inner_subresultants(x**2 + 1, x**2 - 1)
([x**2 + 1, x**2 - 1, -2], [1, 1, 4])

References

[1] W.S. Brown, The Subresultant PRS Algorithm. ACM Transaction of Mathematical Software 4 (1978) 237-249

modelparameters.sympy.polys.euclidtools.dup_invert(f, g, K)[source]

Compute multiplicative inverse of f modulo g in F[x].

Examples

>>> from ..polys import ring, QQ
>>> R, x = ring("x", QQ)
>>> f = x**2 - 1
>>> g = 2*x - 1
>>> h = x - 1
>>> R.dup_invert(f, g)
-4/3
>>> R.dup_invert(f, h)
Traceback (most recent call last):
...
NotInvertible: zero divisor
modelparameters.sympy.polys.euclidtools.dup_lcm(f, g, K)[source]

Computes polynomial LCM of f and g in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_lcm(x**2 - 1, x**2 - 3*x + 2)
x**3 - 2*x**2 - x + 2
modelparameters.sympy.polys.euclidtools.dup_primitive_prs(f, g, K)[source]

Primitive polynomial remainder sequence (PRS) in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> f = x**8 + x**6 - 3*x**4 - 3*x**3 + 8*x**2 + 2*x - 5
>>> g = 3*x**6 + 5*x**4 - 4*x**2 - 9*x + 21
>>> prs = R.dup_primitive_prs(f, g)
>>> prs[0]
x**8 + x**6 - 3*x**4 - 3*x**3 + 8*x**2 + 2*x - 5
>>> prs[1]
3*x**6 + 5*x**4 - 4*x**2 - 9*x + 21
>>> prs[2]
-5*x**4 + x**2 - 3
>>> prs[3]
13*x**2 + 25*x - 49
>>> prs[4]
4663*x - 6150
>>> prs[5]
1
modelparameters.sympy.polys.euclidtools.dup_prs_resultant(f, g, K)[source]

Resultant algorithm in K[x] using subresultant PRS.

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_prs_resultant(x**2 + 1, x**2 - 1)
(4, [x**2 + 1, x**2 - 1, -2])
modelparameters.sympy.polys.euclidtools.dup_qq_heu_gcd(f, g, K0)[source]

Heuristic polynomial GCD in Q[x].

Returns (h, cff, cfg) such that a = gcd(f, g), cff = quo(f, h), and cfg = quo(g, h).

Examples

>>> from ..polys import ring, QQ
>>> R, x = ring("x", QQ)
>>> f = QQ(1,2)*x**2 + QQ(7,4)*x + QQ(3,2)
>>> g = QQ(1,2)*x**2 + x
>>> R.dup_qq_heu_gcd(f, g)
(x + 2, 1/2*x + 3/4, 1/2*x)
modelparameters.sympy.polys.euclidtools.dup_resultant(f, g, K, includePRS=False)[source]

Computes resultant of two polynomials in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_resultant(x**2 + 1, x**2 - 1)
4
modelparameters.sympy.polys.euclidtools.dup_rr_lcm(f, g, K)[source]

Computes polynomial LCM over a ring in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_rr_lcm(x**2 - 1, x**2 - 3*x + 2)
x**3 - 2*x**2 - x + 2
modelparameters.sympy.polys.euclidtools.dup_rr_prs_gcd(f, g, K)[source]

Computes polynomial GCD using subresultants over a ring.

Returns (h, cff, cfg) such that a = gcd(f, g), cff = quo(f, h), and cfg = quo(g, h).

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_rr_prs_gcd(x**2 - 1, x**2 - 3*x + 2)
(x - 1, x + 1, x - 2)
modelparameters.sympy.polys.euclidtools.dup_subresultants(f, g, K)[source]

Computes subresultant PRS of two polynomials in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_subresultants(x**2 + 1, x**2 - 1)
[x**2 + 1, x**2 - 1, -2]
modelparameters.sympy.polys.euclidtools.dup_zz_heu_gcd(f, g, K)[source]

Heuristic polynomial GCD in Z[x].

Given univariate polynomials f and g in Z[x], returns their GCD and cofactors, i.e. polynomials h, cff and cfg such that:

h = gcd(f, g), cff = quo(f, h) and cfg = quo(g, h)

The algorithm is purely heuristic which means it may fail to compute the GCD. This will be signaled by raising an exception. In this case you will need to switch to another GCD method.

The algorithm computes the polynomial GCD by evaluating polynomials f and g at certain points and computing (fast) integer GCD of those evaluations. The polynomial GCD is recovered from the integer image by interpolation. The final step is to verify if the result is the correct GCD. This gives cofactors as a side effect.

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_zz_heu_gcd(x**2 - 1, x**2 - 3*x + 2)
(x - 1, x + 1, x - 2)

References

  1. [Liao95]

modelparameters.sympy.polys.factortools module

Polynomial factorization routines in characteristic zero.

modelparameters.sympy.polys.factortools.dmp_ext_factor(f, u, K)[source]

Factor multivariate polynomials over algebraic number fields.

modelparameters.sympy.polys.factortools.dmp_factor_list(f, u, K0)[source]

Factor polynomials into irreducibles in K[X].

modelparameters.sympy.polys.factortools.dmp_factor_list_include(f, u, K)[source]

Factor polynomials into irreducibles in K[X].

modelparameters.sympy.polys.factortools.dmp_gf_factor(f, u, K)[source]

Factor multivariate polynomials over finite fields.

modelparameters.sympy.polys.factortools.dmp_irreducible_p(f, u, K)[source]

Returns True if f has no factors over its domain.

modelparameters.sympy.polys.factortools.dmp_trial_division(f, factors, u, K)[source]

Determine multiplicities of factors using trial division.

modelparameters.sympy.polys.factortools.dmp_zz_diophantine(F, c, A, d, p, u, K)[source]

Wang/EEZ: Solve multivariate Diophantine equations.

modelparameters.sympy.polys.factortools.dmp_zz_factor(f, u, K)[source]

Factor (non square-free) polynomials in Z[X].

Given a multivariate polynomial f in Z[x] computes its complete factorization f_1, …, f_n into irreducibles over integers:

f = content(f) f_1**k_1 ... f_n**k_n

The factorization is computed by reducing the input polynomial into a primitive square-free polynomial and factoring it using Enhanced Extended Zassenhaus (EEZ) algorithm. Trial division is used to recover the multiplicities of factors.

The result is returned as a tuple consisting of:

(content(f), [(f_1, k_1), ..., (f_n, k_n))

Consider polynomial f = 2*(x**2 - y**2):

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)

>>> R.dmp_zz_factor(2*x**2 - 2*y**2)
(2, [(x - y, 1), (x + y, 1)])

In result we got the following factorization:

f = 2 (x - y) (x + y)

References

  1. [Gathen99]

modelparameters.sympy.polys.factortools.dmp_zz_mignotte_bound(f, u, K)[source]

Mignotte bound for multivariate polynomials in K[X].

modelparameters.sympy.polys.factortools.dmp_zz_wang(f, u, K, mod=None, seed=None)[source]

Factor primitive square-free polynomials in Z[X].

Given a multivariate polynomial f in Z[x_1,…,x_n], which is primitive and square-free in x_1, computes factorization of f into irreducibles over integers.

The procedure is based on Wang’s Enhanced Extended Zassenhaus algorithm. The algorithm works by viewing f as a univariate polynomial in Z[x_2,…,x_n][x_1], for which an evaluation mapping is computed:

x_2 -> a_2, ..., x_n -> a_n

where a_i, for i = 2, …, n, are carefully chosen integers. The mapping is used to transform f into a univariate polynomial in Z[x_1], which can be factored efficiently using Zassenhaus algorithm. The last step is to lift univariate factors to obtain true multivariate factors. For this purpose a parallel Hensel lifting procedure is used.

The parameter seed is passed to _randint and can be used to seed randint (when an integer) or (for testing purposes) can be a sequence of numbers.

References

  1. [Wang78]

  2. [Geddes92]

modelparameters.sympy.polys.factortools.dmp_zz_wang_hensel_lifting(f, H, LC, A, p, u, K)[source]

Wang/EEZ: Parallel Hensel lifting algorithm.

modelparameters.sympy.polys.factortools.dmp_zz_wang_lead_coeffs(f, T, cs, E, H, A, u, K)[source]

Wang/EEZ: Compute correct leading coefficients.

modelparameters.sympy.polys.factortools.dmp_zz_wang_non_divisors(E, cs, ct, K)[source]

Wang/EEZ: Compute a set of valid divisors.

modelparameters.sympy.polys.factortools.dmp_zz_wang_test_points(f, T, ct, A, u, K)[source]

Wang/EEZ: Test evaluation points for suitability.

modelparameters.sympy.polys.factortools.dup_cyclotomic_p(f, K, irreducible=False)[source]

Efficiently test if f is a cyclotomic polnomial.

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> f = x**16 + x**14 - x**10 + x**8 - x**6 + x**2 + 1
>>> R.dup_cyclotomic_p(f)
False
>>> g = x**16 + x**14 - x**10 - x**8 - x**6 + x**2 + 1
>>> R.dup_cyclotomic_p(g)
True
modelparameters.sympy.polys.factortools.dup_ext_factor(f, K)[source]

Factor univariate polynomials over algebraic number fields.

modelparameters.sympy.polys.factortools.dup_factor_list(f, K0)[source]

Factor polynomials into irreducibles in K[x].

modelparameters.sympy.polys.factortools.dup_factor_list_include(f, K)[source]

Factor polynomials into irreducibles in K[x].

modelparameters.sympy.polys.factortools.dup_gf_factor(f, K)[source]

Factor univariate polynomials over finite fields.

modelparameters.sympy.polys.factortools.dup_irreducible_p(f, K)[source]

Returns True if f has no factors over its domain.

modelparameters.sympy.polys.factortools.dup_trial_division(f, factors, K)[source]

Determine multiplicities of factors using trial division.

modelparameters.sympy.polys.factortools.dup_zz_cyclotomic_factor(f, K)[source]

Efficiently factor polynomials x**n - 1 and x**n + 1 in Z[x].

Given a univariate polynomial f in Z[x] returns a list of factors of f, provided that f is in the form x**n - 1 or x**n + 1 for n >= 1. Otherwise returns None.

Factorization is performed using using cyclotomic decomposition of f, which makes this method much faster that any other direct factorization approach (e.g. Zassenhaus’s).

References

  1. [Weisstein09]

modelparameters.sympy.polys.factortools.dup_zz_cyclotomic_poly(n, K)[source]

Efficiently generate n-th cyclotomic polnomial.

modelparameters.sympy.polys.factortools.dup_zz_diophantine(F, m, p, K)[source]

Wang/EEZ: Solve univariate Diophantine equations.

modelparameters.sympy.polys.factortools.dup_zz_factor(f, K)[source]

Factor (non square-free) polynomials in Z[x].

Given a univariate polynomial f in Z[x] computes its complete factorization f_1, …, f_n into irreducibles over integers:

f = content(f) f_1**k_1 ... f_n**k_n

The factorization is computed by reducing the input polynomial into a primitive square-free polynomial and factoring it using Zassenhaus algorithm. Trial division is used to recover the multiplicities of factors.

The result is returned as a tuple consisting of:

(content(f), [(f_1, k_1), ..., (f_n, k_n))

Consider polynomial f = 2*x**4 - 2:

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)

>>> R.dup_zz_factor(2*x**4 - 2)
(2, [(x - 1, 1), (x + 1, 1), (x**2 + 1, 1)])

In result we got the following factorization:

f = 2 (x - 1) (x + 1) (x**2 + 1)

Note that this is a complete factorization over integers, however over Gaussian integers we can factor the last term.

By default, polynomials x**n - 1 and x**n + 1 are factored using cyclotomic decomposition to speedup computations. To disable this behaviour set cyclotomic=False.

References

  1. [Gathen99]

modelparameters.sympy.polys.factortools.dup_zz_factor_sqf(f, K)[source]

Factor square-free (non-primitive) polyomials in Z[x].

modelparameters.sympy.polys.factortools.dup_zz_hensel_lift(p, f, f_list, l, K)[source]

Multifactor Hensel lifting in Z[x].

Given a prime p, polynomial f over Z[x] such that lc(f) is a unit modulo p, monic pair-wise coprime polynomials f_i over Z[x] satisfying:

f = lc(f) f_1 ... f_r (mod p)

and a positive integer l, returns a list of monic polynomials F_1, F_2, …, F_r satisfying:

f = lc(f) F_1 ... F_r (mod p**l)

F_i = f_i (mod p), i = 1..r

References

  1. [Gathen99]

modelparameters.sympy.polys.factortools.dup_zz_hensel_step(m, f, g, h, s, t, K)[source]

One step in Hensel lifting in Z[x].

Given positive integer m and Z[x] polynomials f, g, h, s and t such that:

f == g*h (mod m)
s*g + t*h == 1 (mod m)

lc(f) is not a zero divisor (mod m)
lc(h) == 1

deg(f) == deg(g) + deg(h)
deg(s) < deg(h)
deg(t) < deg(g)

returns polynomials G, H, S and T, such that:

f == G*H (mod m**2)
S*G + T**H == 1 (mod m**2)

References

  1. [Gathen99]

modelparameters.sympy.polys.factortools.dup_zz_irreducible_p(f, K)[source]

Test irreducibility using Eisenstein’s criterion.

modelparameters.sympy.polys.factortools.dup_zz_mignotte_bound(f, K)[source]

Mignotte bound for univariate polynomials in K[x].

modelparameters.sympy.polys.factortools.dup_zz_zassenhaus(f, K)[source]

Factor primitive square-free polynomials in Z[x].

modelparameters.sympy.polys.fglmtools module

Implementation of matrix FGLM Groebner basis conversion algorithm.

modelparameters.sympy.polys.fglmtools.matrix_fglm(F, ring, O_to)[source]

Converts the reduced Groebner basis F of a zero-dimensional ideal w.r.t. O_from to a reduced Groebner basis w.r.t. O_to.

References

J.C. Faugere, P. Gianni, D. Lazard, T. Mora (1994). Efficient Computation of Zero-dimensional Groebner Bases by Change of Ordering

modelparameters.sympy.polys.fields module

Sparse rational function fields.

modelparameters.sympy.polys.fields.field(symbols, domain, order=LexOrder())[source]

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

modelparameters.sympy.polys.fields.sfield(exprs, *symbols, **options)[source]

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

Parameters:
  • exprs (Expr or sequence of Expr (sympifiable)) –

  • symbols (sequence of Symbol/Expr) –

  • options (keyword arguments understood by Options) –

Examples

>>> from ..core import symbols
>>> from ..functions import exp, log
>>> from .fields import 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)
modelparameters.sympy.polys.fields.vfield(symbols, domain, order=LexOrder())[source]

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

modelparameters.sympy.polys.fields.xfield(symbols, domain, order=LexOrder())[source]

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

modelparameters.sympy.polys.galoistools module

Dense univariate polynomials with coefficients in Galois fields.

modelparameters.sympy.polys.galoistools.csolve_prime(f, p, e=1)[source]

Solutions of f(x) congruent 0 mod(p**e).

Examples

>>> from .galoistools import csolve_prime
>>> csolve_prime([1, 1, 7], 3, 1)
[1]
>>> csolve_prime([1, 1, 7], 3, 2)
[1, 4, 7]

Solutions [7, 4, 1] (mod 3**2) are generated by _raise_mod_power() from solution [1] (mod 3).

modelparameters.sympy.polys.galoistools.gf_LC(f, K)[source]

Return the leading coefficient of f.

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_LC
>>> gf_LC([3, 0, 1], ZZ)
3
modelparameters.sympy.polys.galoistools.gf_Qbasis(Q, p, K)[source]

Compute a basis of the kernel of Q.

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_Qmatrix, gf_Qbasis
>>> gf_Qbasis(gf_Qmatrix([1, 0, 0, 0, 1], 5, ZZ), 5, ZZ)
[[1, 0, 0, 0], [0, 0, 1, 0]]
>>> gf_Qbasis(gf_Qmatrix([3, 2, 4], 5, ZZ), 5, ZZ)
[[1, 0]]
modelparameters.sympy.polys.galoistools.gf_Qmatrix(f, p, K)[source]

Calculate Berlekamp’s Q matrix.

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_Qmatrix
>>> gf_Qmatrix([3, 2, 4], 5, ZZ)
[[1, 0],
 [3, 4]]
>>> gf_Qmatrix([1, 0, 0, 0, 1], 5, ZZ)
[[1, 0, 0, 0],
 [0, 4, 0, 0],
 [0, 0, 1, 0],
 [0, 0, 0, 4]]
modelparameters.sympy.polys.galoistools.gf_TC(f, K)[source]

Return the trailing coefficient of f.

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_TC
>>> gf_TC([3, 0, 1], ZZ)
1
modelparameters.sympy.polys.galoistools.gf_add(f, g, p, K)[source]

Add polynomials in GF(p)[x].

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_add
>>> gf_add([3, 2, 4], [2, 2, 2], 5, ZZ)
[4, 1]
modelparameters.sympy.polys.galoistools.gf_add_ground(f, a, p, K)[source]

Compute f + a where f in GF(p)[x] and a in GF(p).

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_add_ground
>>> gf_add_ground([3, 2, 4], 2, 5, ZZ)
[3, 2, 1]
modelparameters.sympy.polys.galoistools.gf_add_mul(f, g, h, p, K)[source]

Returns f + g*h where f, g, h in GF(p)[x].

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_add_mul
>>> gf_add_mul([3, 2, 4], [2, 2, 2], [1, 4], 5, ZZ)
[2, 3, 2, 2]
modelparameters.sympy.polys.galoistools.gf_berlekamp(f, p, K)[source]

Factor a square-free f in GF(p)[x] for small p.

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_berlekamp
>>> gf_berlekamp([1, 0, 0, 0, 1], 5, ZZ)
[[1, 0, 2], [1, 0, 3]]
modelparameters.sympy.polys.galoistools.gf_cofactors(f, g, p, K)[source]

Compute polynomial GCD and cofactors in GF(p)[x].

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_cofactors
>>> gf_cofactors(ZZ.map([3, 2, 4]), ZZ.map([2, 2, 3]), 5, ZZ)
([1, 3], [3, 3], [2, 1])
modelparameters.sympy.polys.galoistools.gf_compose(f, g, p, K)[source]

Compute polynomial composition f(g) in GF(p)[x].

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_compose
>>> gf_compose([3, 2, 4], [2, 2, 2], 5, ZZ)
[2, 4, 0, 3, 0]
modelparameters.sympy.polys.galoistools.gf_compose_mod(g, h, f, p, K)[source]

Compute polynomial composition g(h) in GF(p)[x]/(f).

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_compose_mod
>>> gf_compose_mod(ZZ.map([3, 2, 4]), ZZ.map([2, 2, 2]), ZZ.map([4, 3]), 5, ZZ)
[4]
modelparameters.sympy.polys.galoistools.gf_crt(U, M, K=None)[source]

Chinese Remainder Theorem.

Given a set of integer residues u_0,...,u_n and a set of co-prime integer moduli m_0,...,m_n, returns an integer u, such that u = u_i mod m_i for i = ``0,...,n.

As an example consider a set of residues U = [49, 76, 65] and a set of moduli M = [99, 97, 95]. Then we have:

>>> from .domains import ZZ
>>> from .galoistools import gf_crt
>>> from ..ntheory.modular import solve_congruence

>>> gf_crt([49, 76, 65], [99, 97, 95], ZZ)
639985

This is the correct result because:

>>> [639985 % m for m in [99, 97, 95]]
[49, 76, 65]

Note: this is a low-level routine with no error checking.

See also

sympy.ntheory.modular.crt

a higher level crt routine

sympy.ntheory.modular.solve_congruence

modelparameters.sympy.polys.galoistools.gf_crt1(M, K)[source]

First part of the Chinese Remainder Theorem.

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_crt1
>>> gf_crt1([99, 97, 95], ZZ)
(912285, [9215, 9405, 9603], [62, 24, 12])
modelparameters.sympy.polys.galoistools.gf_crt2(U, M, p, E, S, K)[source]

Second part of the Chinese Remainder Theorem.

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_crt2
>>> U = [49, 76, 65]
>>> M = [99, 97, 95]
>>> p = 912285
>>> E = [9215, 9405, 9603]
>>> S = [62, 24, 12]
>>> gf_crt2(U, M, p, E, S, ZZ)
639985
modelparameters.sympy.polys.galoistools.gf_csolve(f, n)[source]

To solve f(x) congruent 0 mod(n).

n is divided into canonical factors and f(x) cong 0 mod(p**e) will be solved for each factor. Applying the Chinese Remainder Theorem to the results returns the final answers.

Examples

Solve [1, 1, 7] congruent 0 mod(189):

>>> from .galoistools import gf_csolve
>>> gf_csolve([1, 1, 7], 189)
[13, 49, 76, 112, 139, 175]

References

[1] ‘An introduction to the Theory of Numbers’ 5th Edition by Ivan Niven,

Zuckerman and Montgomery.

modelparameters.sympy.polys.galoistools.gf_ddf_shoup(f, p, K)[source]

Kaltofen-Shoup: Deterministic Distinct Degree Factorization

Given a monic square-free polynomial f in GF(p)[x], computes partial distinct degree factorization f_1,...,f_d of f where deg(f_i) != deg(f_j) for i != j. The result is returned as a list of pairs (f_i, e_i) where deg(f_i) > 0 and e_i > 0 is an argument to the equal degree factorization routine.

This algorithm is an improved version of Zassenhaus algorithm for large deg(f) and modulus p (especially for deg(f) ~ lg(p)).

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_ddf_shoup, gf_from_dict
>>> f = gf_from_dict({6: ZZ(1), 5: ZZ(-1), 4: ZZ(1), 3: ZZ(1), 1: ZZ(-1)}, 3, ZZ)
>>> gf_ddf_shoup(f, 3, ZZ)
[([1, 1, 0], 1), ([1, 1, 0, 1, 2], 2)]

References

  1. [Kaltofen98]

  2. [Shoup95]

  3. [Gathen92]

modelparameters.sympy.polys.galoistools.gf_ddf_zassenhaus(f, p, K)[source]

Cantor-Zassenhaus: Deterministic Distinct Degree Factorization

Given a monic square-free polynomial f in GF(p)[x], computes partial distinct degree factorization f_1 ... f_d of f where deg(f_i) != deg(f_j) for i != j. The result is returned as a list of pairs (f_i, e_i) where deg(f_i) > 0 and e_i > 0 is an argument to the equal degree factorization routine.

Consider the polynomial x**15 - 1 in GF(11)[x]:

>>> from .domains import ZZ
>>> from .galoistools import gf_from_dict

>>> f = gf_from_dict({15: ZZ(1), 0: ZZ(-1)}, 11, ZZ)

Distinct degree factorization gives:

>>> from .galoistools import gf_ddf_zassenhaus

>>> gf_ddf_zassenhaus(f, 11, ZZ)
[([1, 0, 0, 0, 0, 10], 1), ([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 2)]

which means x**15 - 1 = (x**5 - 1) (x**10 + x**5 + 1). To obtain factorization into irreducibles, use equal degree factorization procedure (EDF) with each of the factors.

References

  1. [Gathen99]

  2. [Geddes92]

modelparameters.sympy.polys.galoistools.gf_degree(f)[source]

Return the leading degree of f.

Examples

>>> from .galoistools import gf_degree
>>> gf_degree([1, 1, 2, 0])
3
>>> gf_degree([])
-1
modelparameters.sympy.polys.galoistools.gf_diff(f, p, K)[source]

Differentiate polynomial in GF(p)[x].

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_diff
>>> gf_diff([3, 2, 4], 5, ZZ)
[1, 2]
modelparameters.sympy.polys.galoistools.gf_div(f, g, p, K)[source]

Division with remainder in GF(p)[x].

Given univariate polynomials f and g with coefficients in a finite field with p elements, returns polynomials q and r (quotient and remainder) such that f = q*g + r.

Consider polynomials x**3 + x + 1 and x**2 + x in GF(2):

>>> from .domains import ZZ
>>> from .galoistools import gf_div, gf_add_mul

>>> gf_div(ZZ.map([1, 0, 1, 1]), ZZ.map([1, 1, 0]), 2, ZZ)
([1, 1], [1])

As result we obtained quotient x + 1 and remainder 1, thus:

>>> gf_add_mul(ZZ.map([1]), ZZ.map([1, 1]), ZZ.map([1, 1, 0]), 2, ZZ)
[1, 0, 1, 1]

References

  1. [Monagan93]

  2. [Gathen99]

modelparameters.sympy.polys.galoistools.gf_edf_shoup(f, n, p, K)[source]

Gathen-Shoup: Probabilistic Equal Degree Factorization

Given a monic square-free polynomial f in GF(p)[x] and integer n such that n divides deg(f), returns all irreducible factors f_1,...,f_d of f, each of degree n. This is a complete factorization over Galois fields.

This algorithm is an improved version of Zassenhaus algorithm for large deg(f) and modulus p (especially for deg(f) ~ lg(p)).

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_edf_shoup
>>> gf_edf_shoup(ZZ.map([1, 2837, 2277]), 1, 2917, ZZ)
[[1, 852], [1, 1985]]

References

  1. [Shoup91]

  2. [Gathen92]

modelparameters.sympy.polys.galoistools.gf_edf_zassenhaus(f, n, p, K)[source]

Cantor-Zassenhaus: Probabilistic Equal Degree Factorization

Given a monic square-free polynomial f in GF(p)[x] and an integer n, such that n divides deg(f), returns all irreducible factors f_1,...,f_d of f, each of degree n. EDF procedure gives complete factorization over Galois fields.

Consider the square-free polynomial f = x**3 + x**2 + x + 1 in GF(5)[x]. Let’s compute its irreducible factors of degree one:

>>> from .domains import ZZ
>>> from .galoistools import gf_edf_zassenhaus

>>> gf_edf_zassenhaus([1,1,1,1], 1, 5, ZZ)
[[1, 1], [1, 2], [1, 3]]

References

  1. [Gathen99]

  2. [Geddes92]

modelparameters.sympy.polys.galoistools.gf_eval(f, a, p, K)[source]

Evaluate f(a) in GF(p) using Horner scheme.

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_eval
>>> gf_eval([3, 2, 4], 2, 5, ZZ)
0
modelparameters.sympy.polys.galoistools.gf_expand(F, p, K)[source]

Expand results of factor() in GF(p)[x].

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_expand
>>> gf_expand([([3, 2, 4], 1), ([2, 2], 2), ([3, 1], 3)], 5, ZZ)
[4, 3, 0, 3, 0, 1, 4, 1]
modelparameters.sympy.polys.galoistools.gf_exquo(f, g, p, K)[source]

Compute polynomial quotient in GF(p)[x].

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_exquo
>>> gf_exquo(ZZ.map([1, 0, 3, 2, 3]), ZZ.map([2, 2, 2]), 5, ZZ)
[3, 2, 4]
>>> gf_exquo(ZZ.map([1, 0, 1, 1]), ZZ.map([1, 1, 0]), 2, ZZ)
Traceback (most recent call last):
...
ExactQuotientFailed: [1, 1, 0] does not divide [1, 0, 1, 1]
modelparameters.sympy.polys.galoistools.gf_factor(f, p, K)[source]

Factor (non square-free) polynomials in GF(p)[x].

Given a possibly non square-free polynomial f in GF(p)[x], returns its complete factorization into irreducibles:

f_1(x)**e_1 f_2(x)**e_2 ... f_d(x)**e_d

where each f_i is a monic polynomial and gcd(f_i, f_j) == 1, for i != j. The result is given as a tuple consisting of the leading coefficient of f and a list of factors of f with their multiplicities.

The algorithm proceeds by first computing square-free decomposition of f and then iteratively factoring each of square-free factors.

Consider a non square-free polynomial f = (7*x + 1) (x + 2)**2 in GF(11)[x]. We obtain its factorization into irreducibles as follows:

>>> from .domains import ZZ
>>> from .galoistools import gf_factor

>>> gf_factor(ZZ.map([5, 2, 7, 2]), 11, ZZ)
(5, [([1, 2], 1), ([1, 8], 2)])

We arrived with factorization f = 5 (x + 2) (x + 8)**2. We didn’t recover the exact form of the input polynomial because we requested to get monic factors of f and its leading coefficient separately.

Square-free factors of f can be factored into irreducibles over GF(p) using three very different methods:

Berlekamp

efficient for very small values of p (usually p < 25)

Cantor-Zassenhaus

efficient on average input and with “typical” p

Shoup-Kaltofen-Gathen

efficient with very large inputs and modulus

If you want to use a specific factorization method, instead of the default one, set GF_FACTOR_METHOD with one of berlekamp, zassenhaus or shoup values.

References

  1. [Gathen99]

modelparameters.sympy.polys.galoistools.gf_factor_sqf(f, p, K, method=None)[source]

Factor a square-free polynomial f in GF(p)[x].

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_factor_sqf
>>> gf_factor_sqf(ZZ.map([3, 2, 4]), 5, ZZ)
(3, [[1, 1], [1, 3]])
modelparameters.sympy.polys.galoistools.gf_frobenius_map(f, g, b, p, K)[source]

compute gf_pow_mod(f, p, g, p, K) using the Frobenius map

Parameters:
  • f (polynomials in GF(p)[x]) –

  • g (polynomials in GF(p)[x]) –

  • b (frobenius monomial base) –

  • p (prime number) –

  • K (domain) –

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_frobenius_monomial_base, gf_frobenius_map
>>> f = ZZ.map([2, 1 , 0, 1])
>>> g = ZZ.map([1, 0, 2, 1])
>>> p = 5
>>> b = gf_frobenius_monomial_base(g, p, ZZ)
>>> r = gf_frobenius_map(f, g, b, p, ZZ)
>>> gf_frobenius_map(f, g, b, p, ZZ)
[4, 0, 3]
modelparameters.sympy.polys.galoistools.gf_frobenius_monomial_base(g, p, K)[source]

return the list of x**(i*p) mod g in Z_p for i = 0, .., n - 1 where n = gf_degree(g)

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_frobenius_monomial_base
>>> g = ZZ.map([1, 0, 2, 1])
>>> gf_frobenius_monomial_base(g, 5, ZZ)
[[1], [4, 4, 2], [1, 2]]
modelparameters.sympy.polys.galoistools.gf_from_dict(f, p, K)[source]

Create a GF(p)[x] polynomial from a dict.

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_from_dict
>>> gf_from_dict({10: ZZ(4), 4: ZZ(33), 0: ZZ(-1)}, 5, ZZ)
[4, 0, 0, 0, 0, 0, 3, 0, 0, 0, 4]
modelparameters.sympy.polys.galoistools.gf_from_int_poly(f, p)[source]

Create a GF(p)[x] polynomial from Z[x].

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_from_int_poly
>>> gf_from_int_poly([7, -2, 3], 5)
[2, 3, 3]
modelparameters.sympy.polys.galoistools.gf_gcd(f, g, p, K)[source]

Euclidean Algorithm in GF(p)[x].

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_gcd
>>> gf_gcd(ZZ.map([3, 2, 4]), ZZ.map([2, 2, 3]), 5, ZZ)
[1, 3]
modelparameters.sympy.polys.galoistools.gf_gcdex(f, g, p, K)[source]

Extended Euclidean Algorithm in GF(p)[x].

Given polynomials f and g in GF(p)[x], computes polynomials s, t and h, such that h = gcd(f, g) and s*f + t*g = h. The typical application of EEA is solving polynomial diophantine equations.

Consider polynomials f = (x + 7) (x + 1), g = (x + 7) (x**2 + 1) in GF(11)[x]. Application of Extended Euclidean Algorithm gives:

>>> from .domains import ZZ
>>> from .galoistools import gf_gcdex, gf_mul, gf_add

>>> s, t, g = gf_gcdex(ZZ.map([1, 8, 7]), ZZ.map([1, 7, 1, 7]), 11, ZZ)
>>> s, t, g
([5, 6], [6], [1, 7])

As result we obtained polynomials s = 5*x + 6 and t = 6, and additionally gcd(f, g) = x + 7. This is correct because:

>>> S = gf_mul(s, ZZ.map([1, 8, 7]), 11, ZZ)
>>> T = gf_mul(t, ZZ.map([1, 7, 1, 7]), 11, ZZ)

>>> gf_add(S, T, 11, ZZ) == [1, 7]
True

References

  1. [Gathen99]

modelparameters.sympy.polys.galoistools.gf_int(a, p)[source]

Coerce a mod p to an integer in the range [-p/2, p/2].

Examples

>>> from .galoistools import gf_int
>>> gf_int(2, 7)
2
>>> gf_int(5, 7)
-2
modelparameters.sympy.polys.galoistools.gf_irred_p_ben_or(f, p, K)[source]

Ben-Or’s polynomial irreducibility test over finite fields.

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_irred_p_ben_or
>>> gf_irred_p_ben_or(ZZ.map([1, 4, 2, 2, 3, 2, 4, 1, 4, 0, 4]), 5, ZZ)
True
>>> gf_irred_p_ben_or(ZZ.map([3, 2, 4]), 5, ZZ)
False
modelparameters.sympy.polys.galoistools.gf_irred_p_rabin(f, p, K)[source]

Rabin’s polynomial irreducibility test over finite fields.

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_irred_p_rabin
>>> gf_irred_p_rabin(ZZ.map([1, 4, 2, 2, 3, 2, 4, 1, 4, 0, 4]), 5, ZZ)
True
>>> gf_irred_p_rabin(ZZ.map([3, 2, 4]), 5, ZZ)
False
modelparameters.sympy.polys.galoistools.gf_irreducible(n, p, K)[source]

Generate random irreducible polynomial of degree n in GF(p)[x].

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_irreducible
>>> gf_irreducible(10, 5, ZZ) 
[1, 4, 2, 2, 3, 2, 4, 1, 4, 0, 4]
modelparameters.sympy.polys.galoistools.gf_irreducible_p(f, p, K)[source]

Test irreducibility of a polynomial f in GF(p)[x].

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_irreducible_p
>>> gf_irreducible_p(ZZ.map([1, 4, 2, 2, 3, 2, 4, 1, 4, 0, 4]), 5, ZZ)
True
>>> gf_irreducible_p(ZZ.map([3, 2, 4]), 5, ZZ)
False
modelparameters.sympy.polys.galoistools.gf_lcm(f, g, p, K)[source]

Compute polynomial LCM in GF(p)[x].

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_lcm
>>> gf_lcm(ZZ.map([3, 2, 4]), ZZ.map([2, 2, 3]), 5, ZZ)
[1, 2, 0, 4]
modelparameters.sympy.polys.galoistools.gf_lshift(f, n, K)[source]

Efficiently multiply f by x**n.

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_lshift
>>> gf_lshift([3, 2, 4], 4, ZZ)
[3, 2, 4, 0, 0, 0, 0]
modelparameters.sympy.polys.galoistools.gf_monic(f, p, K)[source]

Compute LC and a monic polynomial in GF(p)[x].

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_monic
>>> gf_monic(ZZ.map([3, 2, 4]), 5, ZZ)
(3, [1, 4, 3])
modelparameters.sympy.polys.galoistools.gf_mul(f, g, p, K)[source]

Multiply polynomials in GF(p)[x].

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_mul
>>> gf_mul([3, 2, 4], [2, 2, 2], 5, ZZ)
[1, 0, 3, 2, 3]
modelparameters.sympy.polys.galoistools.gf_mul_ground(f, a, p, K)[source]

Compute f * a where f in GF(p)[x] and a in GF(p).

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_mul_ground
>>> gf_mul_ground([3, 2, 4], 2, 5, ZZ)
[1, 4, 3]
modelparameters.sympy.polys.galoistools.gf_multi_eval(f, A, p, K)[source]

Evaluate f(a) for a in [a_1, ..., a_n].

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_multi_eval
>>> gf_multi_eval([3, 2, 4], [0, 1, 2, 3, 4], 5, ZZ)
[4, 4, 0, 2, 0]
modelparameters.sympy.polys.galoistools.gf_neg(f, p, K)[source]

Negate a polynomial in GF(p)[x].

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_neg
>>> gf_neg([3, 2, 1, 0], 5, ZZ)
[2, 3, 4, 0]
modelparameters.sympy.polys.galoistools.gf_normal(f, p, K)[source]

Normalize all coefficients in K.

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_normal
>>> gf_normal([5, 10, 21, -3], 5, ZZ)
[1, 2]
modelparameters.sympy.polys.galoistools.gf_pow(f, n, p, K)[source]

Compute f**n in GF(p)[x] using repeated squaring.

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_pow
>>> gf_pow([3, 2, 4], 3, 5, ZZ)
[2, 4, 4, 2, 2, 1, 4]
modelparameters.sympy.polys.galoistools.gf_pow_mod(f, n, g, p, K)[source]

Compute f**n in GF(p)[x]/(g) using repeated squaring.

Given polynomials f and g in GF(p)[x] and a non-negative integer n, efficiently computes f**n (mod g) i.e. the remainder of f**n from division by g, using the repeated squaring algorithm.

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_pow_mod
>>> gf_pow_mod(ZZ.map([3, 2, 4]), 3, ZZ.map([1, 1]), 5, ZZ)
[]

References

  1. [Gathen99]

modelparameters.sympy.polys.galoistools.gf_quo(f, g, p, K)[source]

Compute exact quotient in GF(p)[x].

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_quo
>>> gf_quo(ZZ.map([1, 0, 1, 1]), ZZ.map([1, 1, 0]), 2, ZZ)
[1, 1]
>>> gf_quo(ZZ.map([1, 0, 3, 2, 3]), ZZ.map([2, 2, 2]), 5, ZZ)
[3, 2, 4]
modelparameters.sympy.polys.galoistools.gf_quo_ground(f, a, p, K)[source]

Compute f/a where f in GF(p)[x] and a in GF(p).

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_quo_ground
>>> gf_quo_ground(ZZ.map([3, 2, 4]), ZZ(2), 5, ZZ)
[4, 1, 2]
modelparameters.sympy.polys.galoistools.gf_random(n, p, K)[source]

Generate a random polynomial in GF(p)[x] of degree n.

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_random
>>> gf_random(10, 5, ZZ) 
[1, 2, 3, 2, 1, 1, 1, 2, 0, 4, 2]
modelparameters.sympy.polys.galoistools.gf_rem(f, g, p, K)[source]

Compute polynomial remainder in GF(p)[x].

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_rem
>>> gf_rem(ZZ.map([1, 0, 1, 1]), ZZ.map([1, 1, 0]), 2, ZZ)
[1]
modelparameters.sympy.polys.galoistools.gf_rshift(f, n, K)[source]

Efficiently divide f by x**n.

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_rshift
>>> gf_rshift([1, 2, 3, 4, 0], 3, ZZ)
([1, 2], [3, 4, 0])
modelparameters.sympy.polys.galoistools.gf_shoup(f, p, K)[source]

Factor a square-free f in GF(p)[x] for large p.

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_shoup
>>> gf_shoup(ZZ.map([1, 4, 3]), 5, ZZ)
[[1, 1], [1, 3]]
modelparameters.sympy.polys.galoistools.gf_sqf_list(f, p, K, all=False)[source]

Return the square-free decomposition of a GF(p)[x] polynomial.

Given a polynomial f in GF(p)[x], returns the leading coefficient of f and a square-free decomposition f_1**e_1 f_2**e_2 ... f_k**e_k such that all f_i are monic polynomials and (f_i, f_j) for i != j are co-prime and e_1 ... e_k are given in increasing order. All trivial terms (i.e. f_i = 1) aren’t included in the output.

Consider polynomial f = x**11 + 1 over GF(11)[x]:

>>> from .domains import ZZ

>>> from .galoistools import (
...     gf_from_dict, gf_diff, gf_sqf_list, gf_pow,
... )
... 

>>> f = gf_from_dict({11: ZZ(1), 0: ZZ(1)}, 11, ZZ)

Note that f'(x) = 0:

>>> gf_diff(f, 11, ZZ)
[]

This phenomenon doesn’t happen in characteristic zero. However we can still compute square-free decomposition of f using gf_sqf():

>>> gf_sqf_list(f, 11, ZZ)
(1, [([1, 1], 11)])

We obtained factorization f = (x + 1)**11. This is correct because:

>>> gf_pow([1, 1], 11, 11, ZZ) == f
True

References

  1. [Geddes92]

modelparameters.sympy.polys.galoistools.gf_sqf_p(f, p, K)[source]

Return True if f is square-free in GF(p)[x].

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_sqf_p
>>> gf_sqf_p(ZZ.map([3, 2, 4]), 5, ZZ)
True
>>> gf_sqf_p(ZZ.map([2, 4, 4, 2, 2, 1, 4]), 5, ZZ)
False
modelparameters.sympy.polys.galoistools.gf_sqf_part(f, p, K)[source]

Return square-free part of a GF(p)[x] polynomial.

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_sqf_part
>>> gf_sqf_part(ZZ.map([1, 1, 3, 0, 1, 0, 2, 2, 1]), 5, ZZ)
[1, 4, 3]
modelparameters.sympy.polys.galoistools.gf_sqr(f, p, K)[source]

Square polynomials in GF(p)[x].

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_sqr
>>> gf_sqr([3, 2, 4], 5, ZZ)
[4, 2, 3, 1, 1]
modelparameters.sympy.polys.galoistools.gf_strip(f)[source]

Remove leading zeros from f.

Examples

>>> from .galoistools import gf_strip
>>> gf_strip([0, 0, 0, 3, 0, 1])
[3, 0, 1]
modelparameters.sympy.polys.galoistools.gf_sub(f, g, p, K)[source]

Subtract polynomials in GF(p)[x].

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_sub
>>> gf_sub([3, 2, 4], [2, 2, 2], 5, ZZ)
[1, 0, 2]
modelparameters.sympy.polys.galoistools.gf_sub_ground(f, a, p, K)[source]

Compute f - a where f in GF(p)[x] and a in GF(p).

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_sub_ground
>>> gf_sub_ground([3, 2, 4], 2, 5, ZZ)
[3, 2, 2]
modelparameters.sympy.polys.galoistools.gf_sub_mul(f, g, h, p, K)[source]

Compute f - g*h where f, g, h in GF(p)[x].

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_sub_mul
>>> gf_sub_mul([3, 2, 4], [2, 2, 2], [1, 4], 5, ZZ)
[3, 3, 2, 1]
modelparameters.sympy.polys.galoistools.gf_to_dict(f, p, symmetric=True)[source]

Convert a GF(p)[x] polynomial to a dict.

Examples

>>> from .galoistools import gf_to_dict
>>> gf_to_dict([4, 0, 0, 0, 0, 0, 3, 0, 0, 0, 4], 5)
{0: -1, 4: -2, 10: -1}
>>> gf_to_dict([4, 0, 0, 0, 0, 0, 3, 0, 0, 0, 4], 5, symmetric=False)
{0: 4, 4: 3, 10: 4}
modelparameters.sympy.polys.galoistools.gf_to_int_poly(f, p, symmetric=True)[source]

Convert a GF(p)[x] polynomial to Z[x].

Examples

>>> from .galoistools import gf_to_int_poly
>>> gf_to_int_poly([2, 3, 3], 5)
[2, -2, -2]
>>> gf_to_int_poly([2, 3, 3], 5, symmetric=False)
[2, 3, 3]
modelparameters.sympy.polys.galoistools.gf_trace_map(a, b, c, n, f, p, K)[source]

Compute polynomial trace map in GF(p)[x]/(f).

Given a polynomial f in GF(p)[x], polynomials a, b, c in the quotient ring GF(p)[x]/(f) such that b = c**t (mod f) for some positive power t of p, and a positive integer n, returns a mapping:

a -> a**t**n, a + a**t + a**t**2 + ... + a**t**n (mod f)

In factorization context, b = x**p mod f and c = x mod f. This way we can efficiently compute trace polynomials in equal degree factorization routine, much faster than with other methods, like iterated Frobenius algorithm, for large degrees.

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_trace_map
>>> gf_trace_map([1, 2], [4, 4], [1, 1], 4, [3, 2, 4], 5, ZZ)
([1, 3], [1, 3])

References

  1. [Gathen92]

modelparameters.sympy.polys.galoistools.gf_trunc(f, p)[source]

Reduce all coefficients modulo p.

Examples

>>> from .galoistools import gf_trunc
>>> gf_trunc([7, -2, 3], 5)
[2, 3, 3]
modelparameters.sympy.polys.galoistools.gf_value(f, a)[source]

Value of polynomial ‘f’ at ‘a’ in field R.

Examples

>>> from .galoistools import gf_value
>>> gf_value([1, 7, 2, 4], 11)
2204
modelparameters.sympy.polys.galoistools.gf_zassenhaus(f, p, K)[source]

Factor a square-free f in GF(p)[x] for medium p.

Examples

>>> from .domains import ZZ
>>> from .galoistools import gf_zassenhaus
>>> gf_zassenhaus(ZZ.map([1, 4, 3]), 5, ZZ)
[[1, 1], [1, 3]]
modelparameters.sympy.polys.galoistools.linear_congruence(a, b, m)[source]

Returns the values of x satisfying a*x congruent b mod(m)

Here m is positive integer and a, b are natural numbers. This function returns only those values of x which are distinct mod(m).

Examples

>>> from .galoistools import linear_congruence
>>> linear_congruence(3, 12, 15)
[4, 9, 14]

There are 3 solutions distinct mod(15) since gcd(a, m) = gcd(3, 15) = 3.

Reference 1) Wikipedia http://en.wikipedia.org/wiki/Linear_congruence_theorem

modelparameters.sympy.polys.groebnertools module

Groebner bases algorithms.

modelparameters.sympy.polys.groebnertools.Num(f)[source]
modelparameters.sympy.polys.groebnertools.Polyn(f)[source]
modelparameters.sympy.polys.groebnertools.Sign(f)[source]
modelparameters.sympy.polys.groebnertools.cp_cmp(c, d)[source]

Compare two critical pairs c and d.

c < d iff
  • lbp(c[0], _, Num(c[2]) < lbp(d[0], _, Num(d[2])) (this

corresponds to um_c * f_c and um_d * f_d)

or
  • lbp(c[0], _, Num(c[2]) >< lbp(d[0], _, Num(d[2])) and

lbp(c[3], _, Num(c[5])) < lbp(d[3], _, Num(d[5])) (this corresponds to vm_c * g_c and vm_d * g_d)

c > d otherwise

modelparameters.sympy.polys.groebnertools.cp_key(c, ring)[source]

Key for comparing critical pairs.

modelparameters.sympy.polys.groebnertools.critical_pair(f, g, ring)[source]

Compute the critical pair corresponding to two labeled polynomials.

A critical pair is a tuple (um, f, vm, g), where um and vm are terms such that um * f - vm * g is the S-polynomial of f and g (so, wlog assume um * f > vm * g). For performance sake, a critical pair is represented as a tuple (Sign(um * f), um, f, Sign(vm * g), vm, g), since um * f creates a new, relatively expensive object in memory, whereas Sign(um * f) and um are lightweight and f (in the tuple) is a reference to an already existing object in memory.

modelparameters.sympy.polys.groebnertools.f5_reduce(f, B)[source]

F5-reduce a labeled polynomial f by B.

Continously searches for non-zero labeled polynomial h in B, such that the leading term lt_h of h divides the leading term lt_f of f and Sign(lt_h * h) < Sign(f). If such a labeled polynomial h is found, f gets replaced by f - lt_f / lt_h * h. If no such h can be found or f is 0, f is no further F5-reducible and f gets returned.

A polynomial that is reducible in the usual sense need not be F5-reducible, e.g.:

>>> from .groebnertools import lbp, sig, f5_reduce, Polyn
>>> from ..polys import ring, QQ, lex
>>> R, x,y,z = ring("x,y,z", QQ, lex)
>>> f = lbp(sig((1, 1, 1), 4), x, 3)
>>> g = lbp(sig((0, 0, 0), 2), x, 2)
>>> Polyn(f).rem([Polyn(g)])
0
>>> f5_reduce(f, [g])
(((1, 1, 1), 4), x, 3)
modelparameters.sympy.polys.groebnertools.groebner(seq, ring, method=None)[source]

Computes Groebner basis for a set of polynomials in K[X].

Wrapper around the (default) improved Buchberger and the other algorithms for computing Groebner bases. The choice of algorithm can be changed via method argument or setup() from sympy.polys.polyconfig, where method can be either buchberger or f5b.

modelparameters.sympy.polys.groebnertools.groebner_gcd(f, g)[source]

Computes GCD of two polynomials using Groebner bases.

modelparameters.sympy.polys.groebnertools.groebner_lcm(f, g)[source]

Computes LCM of two polynomials using Groebner bases.

The LCM is computed as the unique generater of the intersection of the two ideals generated by f and g. The approach is to compute a Groebner basis with respect to lexicographic ordering of t*f and (1 - t)*g, where t is an unrelated variable and then filtering out the solution that doesn’t contain t.

References

  1. [Cox97]

modelparameters.sympy.polys.groebnertools.is_groebner(G, ring)[source]

Check if G is a Groebner basis.

modelparameters.sympy.polys.groebnertools.is_minimal(G, ring)[source]

Checks if G is a minimal Groebner basis.

modelparameters.sympy.polys.groebnertools.is_reduced(G, ring)[source]

Checks if G is a reduced Groebner basis.

modelparameters.sympy.polys.groebnertools.is_rewritable_or_comparable(sign, num, B)[source]

Check if a labeled polynomial is redundant by checking if its signature and number imply rewritability or comparability.

(sign, num) is comparable if there exists a labeled polynomial h in B, such that sign[1] (the index) is less than Sign(h)[1] and sign[0] is divisible by the leading monomial of h.

(sign, num) is rewritable if there exists a labeled polynomial h in B, such thatsign[1] is equal to Sign(h)[1], num < Num(h) and sign[0] is divisible by Sign(h)[0].

modelparameters.sympy.polys.groebnertools.lbp(signature, polynomial, number)[source]
modelparameters.sympy.polys.groebnertools.lbp_cmp(f, g)[source]

Compare two labeled polynomials.

f < g iff
  • Sign(f) < Sign(g)

or
  • Sign(f) == Sign(g) and Num(f) > Num(g)

f > g otherwise

modelparameters.sympy.polys.groebnertools.lbp_key(f)[source]

Key for comparing two labeled polynomials.

modelparameters.sympy.polys.groebnertools.lbp_mul_term(f, cx)[source]

Multiply a labeled polynomial with a term.

The product of a labeled polynomial (s, p, k) by a monomial is defined as (m * s, m * p, k).

modelparameters.sympy.polys.groebnertools.lbp_sub(f, g)[source]

Subtract labeled polynomial g from f.

The signature and number of the difference of f and g are signature and number of the maximum of f and g, w.r.t. lbp_cmp.

modelparameters.sympy.polys.groebnertools.red_groebner(G, ring)[source]

Compute reduced Groebner basis, from BeckerWeispfenning93, p. 216

Selects a subset of generators, that already generate the ideal and computes a reduced Groebner basis for them.

modelparameters.sympy.polys.groebnertools.s_poly(cp)[source]

Compute the S-polynomial of a critical pair.

The S-polynomial of a critical pair cp is cp[1] * cp[2] - cp[4] * cp[5].

modelparameters.sympy.polys.groebnertools.sig(monomial, index)[source]
modelparameters.sympy.polys.groebnertools.sig_cmp(u, v, order)[source]

Compare two signatures by extending the term order to K[X]^n.

u < v iff
  • the index of v is greater than the index of u

or
  • the index of v is equal to the index of u and u[0] < v[0] w.r.t. order

u > v otherwise

modelparameters.sympy.polys.groebnertools.sig_key(s, order)[source]

Key for comparing two signatures.

s = (m, k), t = (n, l)

s < t iff [k > l] or [k == l and m < n] s > t otherwise

modelparameters.sympy.polys.groebnertools.sig_mult(s, m)[source]

Multiply a signature by a monomial.

The product of a signature (m, i) and a monomial n is defined as (m * t, i).

modelparameters.sympy.polys.groebnertools.spoly(p1, p2, ring)[source]

Compute LCM(LM(p1), LM(p2))/LM(p1)*p1 - LCM(LM(p1), LM(p2))/LM(p2)*p2 This is the S-poly provided p1 and p2 are monic

modelparameters.sympy.polys.heuristicgcd module

Heuristic polynomial GCD algorithm (HEUGCD).

modelparameters.sympy.polys.heuristicgcd.heugcd(f, g)[source]

Heuristic polynomial GCD in Z[X].

Given univariate polynomials f and g in Z[X], returns their GCD and cofactors, i.e. polynomials h, cff and cfg such that:

h = gcd(f, g), cff = quo(f, h) and cfg = quo(g, h)

The algorithm is purely heuristic which means it may fail to compute the GCD. This will be signaled by raising an exception. In this case you will need to switch to another GCD method.

The algorithm computes the polynomial GCD by evaluating polynomials f and g at certain points and computing (fast) integer GCD of those evaluations. The polynomial GCD is recovered from the integer image by interpolation. The evaluation proces reduces f and g variable by variable into a large integer. The final step is to verify if the interpolated polynomial is the correct GCD. This gives cofactors of the input polynomials as a side effect.

Examples

>>> from .heuristicgcd import heugcd
>>> from ..polys import ring, ZZ
>>> R, x,y, = ring("x,y", ZZ)
>>> f = x**2 + 2*x*y + y**2
>>> g = x**2 + x*y
>>> h, cff, cfg = heugcd(f, g)
>>> h, cff, cfg
(x + y, x + y, x)
>>> cff*h == f
True
>>> cfg*h == g
True

References

  1. [Liao95]

modelparameters.sympy.polys.modulargcd module

modelparameters.sympy.polys.modulargcd.func_field_modgcd(f, g)[source]

Compute the GCD of two polynomials f and g in mathbb Q(alpha)[x_0, ldots, x_{n-1}] using a modular algorithm.

The algorithm first computes the primitive associate check m_{alpha}(z) of the minimal polynomial m_{alpha} in mathbb{Z}[z] and the primitive associates of f and g in mathbb{Z}[x_1, ldots, x_{n-1}][z]/(check m_{alpha})[x_0]. Then it computes the GCD in mathbb Q(x_1, ldots, x_{n-1})[z]/(m_{alpha}(z))[x_0]. This is done by calculating the GCD in mathbb{Z}_p(x_1, ldots, x_{n-1})[z]/(check m_{alpha}(z))[x_0] for suitable primes p and then reconstructing the coefficients with the Chinese Remainder Theorem and Rational Reconstuction. The GCD over mathbb{Z}_p(x_1, ldots, x_{n-1})[z]/(check m_{alpha}(z))[x_0] is computed with a recursive subroutine, which evaluates the polynomials at x_{n-1} = a for suitable evaluation points a in mathbb Z_p and then calls itself recursively until the ground domain does no longer contain any parameters. For mathbb{Z}_p[z]/(check m_{alpha}(z))[x_0] the Euclidean Algorithm is used. The results of those recursive calls are then interpolated and Rational Function Reconstruction is used to obtain the correct coefficients. The results, both in mathbb Q(x_1, ldots, x_{n-1})[z]/(m_{alpha}(z))[x_0] and mathbb{Z}_p(x_1, ldots, x_{n-1})[z]/(check m_{alpha}(z))[x_0], are verified by a fraction free trial division.

Apart from the above GCD computation some GCDs in mathbb Q(alpha)[x_1, ldots, x_{n-1}] have to be calculated, because treating the polynomials as univariate ones can result in a spurious content of the GCD. For this func_field_modgcd is called recursively.

Parameters:
  • f (PolyElement) – polynomials in mathbb Q(alpha)[x_0, ldots, x_{n-1}]

  • g (PolyElement) – polynomials in mathbb Q(alpha)[x_0, ldots, x_{n-1}]

Returns:

  • h (PolyElement) – monic GCD of the polynomials f and g

  • cff (PolyElement) – cofactor of f, i.e. frac f h

  • cfg (PolyElement) – cofactor of g, i.e. frac g h

Examples

>>> from .modulargcd import func_field_modgcd
>>> from ..polys import AlgebraicField, QQ, ring
>>> from .. import sqrt
>>> A = AlgebraicField(QQ, sqrt(2))
>>> R, x = ring('x', A)
>>> f = x**2 - 2
>>> g = x + sqrt(2)
>>> h, cff, cfg = func_field_modgcd(f, g)
>>> h == x + sqrt(2)
True
>>> cff * h == f
True
>>> cfg * h == g
True
>>> R, x, y = ring('x, y', A)
>>> f = x**2 + 2*sqrt(2)*x*y + 2*y**2
>>> g = x + sqrt(2)*y
>>> h, cff, cfg = func_field_modgcd(f, g)
>>> h == x + sqrt(2)*y
True
>>> cff * h == f
True
>>> cfg * h == g
True
>>> f = x + sqrt(2)*y
>>> g = x + y
>>> h, cff, cfg = func_field_modgcd(f, g)
>>> h == R.one
True
>>> cff * h == f
True
>>> cfg * h == g
True

References

  1. [Hoeij04]

modelparameters.sympy.polys.modulargcd.modgcd_bivariate(f, g)[source]

Computes the GCD of two polynomials in mathbb{Z}[x, y] using a modular algorithm.

The algorithm computes the GCD of two bivariate integer polynomials f and g by calculating the GCD in mathbb{Z}_p[x, y] for suitable primes p and then reconstructing the coefficients with the Chinese Remainder Theorem. To compute the bivariate GCD over mathbb{Z}_p, the polynomials f ; mathrm{mod} , p and g ; mathrm{mod} , p are evaluated at y = a for certain a in mathbb{Z}_p and then their univariate GCD in mathbb{Z}_p[x] is computed. Interpolating those yields the bivariate GCD in mathbb{Z}_p[x, y]. To verify the result in mathbb{Z}[x, y], trial division is done, but only for candidates which are very likely the desired GCD.

Parameters:
  • f (PolyElement) – bivariate integer polynomial

  • g (PolyElement) – bivariate integer polynomial

Returns:

  • h (PolyElement) – GCD of the polynomials f and g

  • cff (PolyElement) – cofactor of f, i.e. frac{f}{h}

  • cfg (PolyElement) – cofactor of g, i.e. frac{g}{h}

Examples

>>> from .modulargcd import modgcd_bivariate
>>> from ..polys import ring, ZZ
>>> R, x, y = ring("x, y", ZZ)
>>> f = x**2 - y**2
>>> g = x**2 + 2*x*y + y**2
>>> h, cff, cfg = modgcd_bivariate(f, g)
>>> h, cff, cfg
(x + y, x - y, x + y)
>>> cff * h == f
True
>>> cfg * h == g
True
>>> f = x**2*y - x**2 - 4*y + 4
>>> g = x + 2
>>> h, cff, cfg = modgcd_bivariate(f, g)
>>> h, cff, cfg
(x + 2, x*y - x - 2*y + 2, 1)
>>> cff * h == f
True
>>> cfg * h == g
True

References

  1. [Monagan00]

modelparameters.sympy.polys.modulargcd.modgcd_multivariate(f, g)[source]

Compute the GCD of two polynomials in mathbb{Z}[x_0, ldots, x_{k-1}] using a modular algorithm.

The algorithm computes the GCD of two multivariate integer polynomials f and g by calculating the GCD in mathbb{Z}_p[x_0, ldots, x_{k-1}] for suitable primes p and then reconstructing the coefficients with the Chinese Remainder Theorem. To compute the multivariate GCD over mathbb{Z}_p the recursive subroutine _modgcd_multivariate_p is used. To verify the result in mathbb{Z}[x_0, ldots, x_{k-1}], trial division is done, but only for candidates which are very likely the desired GCD.

Parameters:
  • f (PolyElement) – multivariate integer polynomial

  • g (PolyElement) – multivariate integer polynomial

Returns:

  • h (PolyElement) – GCD of the polynomials f and g

  • cff (PolyElement) – cofactor of f, i.e. frac{f}{h}

  • cfg (PolyElement) – cofactor of g, i.e. frac{g}{h}

Examples

>>> from .modulargcd import modgcd_multivariate
>>> from ..polys import ring, ZZ
>>> R, x, y = ring("x, y", ZZ)
>>> f = x**2 - y**2
>>> g = x**2 + 2*x*y + y**2
>>> h, cff, cfg = modgcd_multivariate(f, g)
>>> h, cff, cfg
(x + y, x - y, x + y)
>>> cff * h == f
True
>>> cfg * h == g
True
>>> R, x, y, z = ring("x, y, z", ZZ)
>>> f = x*z**2 - y*z**2
>>> g = x**2*z + z
>>> h, cff, cfg = modgcd_multivariate(f, g)
>>> h, cff, cfg
(z, x*z - y*z, x**2 + 1)
>>> cff * h == f
True
>>> cfg * h == g
True

References

  1. [Monagan00]

  2. [Brown71]

See also

_modgcd_multivariate_p

modelparameters.sympy.polys.modulargcd.modgcd_univariate(f, g)[source]

Computes the GCD of two polynomials in mathbb{Z}[x] using a modular algorithm.

The algorithm computes the GCD of two univariate integer polynomials f and g by computing the GCD in mathbb{Z}_p[x] for suitable primes p and then reconstructing the coefficients with the Chinese Remainder Theorem. Trial division is only made for candidates which are very likely the desired GCD.

Parameters:
  • f (PolyElement) – univariate integer polynomial

  • g (PolyElement) – univariate integer polynomial

Returns:

  • h (PolyElement) – GCD of the polynomials f and g

  • cff (PolyElement) – cofactor of f, i.e. frac{f}{h}

  • cfg (PolyElement) – cofactor of g, i.e. frac{g}{h}

Examples

>>> from .modulargcd import modgcd_univariate
>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> f = x**5 - 1
>>> g = x - 1
>>> h, cff, cfg = modgcd_univariate(f, g)
>>> h, cff, cfg
(x - 1, x**4 + x**3 + x**2 + x + 1, 1)
>>> cff * h == f
True
>>> cfg * h == g
True
>>> f = 6*x**2 - 6
>>> g = 2*x**2 + 4*x + 2
>>> h, cff, cfg = modgcd_univariate(f, g)
>>> h, cff, cfg
(2*x + 2, 3*x - 3, x + 1)
>>> cff * h == f
True
>>> cfg * h == g
True

References

  1. [Monagan00]

modelparameters.sympy.polys.monomials module

Tools and arithmetics for monomials of distributed polynomials.

class modelparameters.sympy.polys.monomials.Monomial(monom, gens=None)[source]

Bases: PicklableWithSlots

Class representing a monomial, i.e. a product of powers.

as_expr(*gens)[source]

Convert a monomial instance to a SymPy expression.

exponents
gcd(other)[source]

Greatest common divisor of monomials.

gens
lcm(other)[source]

Least common multiple of monomials.

rebuild(exponents, gens=None)[source]
modelparameters.sympy.polys.monomials.itermonomials(variables, degree)[source]

Generate a set of monomials of the given total degree or less.

Given a set of variables V and a total degree N generate a set of monomials of degree at most N. The total number of monomials is huge and is given by the following formula:

\[\frac{(\#V + N)!}{\#V! N!}\]

For example if we would like to generate a dense polynomial of a total degree N = 50 in 5 variables, assuming that exponents and all of coefficients are 32-bit long and stored in an array we would need almost 80 GiB of memory! Fortunately most polynomials, that we will encounter, are sparse.

Examples

Consider monomials in variables x and y:

>>> from .monomials import itermonomials
>>> from .orderings import monomial_key
>>> from ..abc import x, y

>>> sorted(itermonomials([x, y], 2), key=monomial_key('grlex', [y, x]))
[1, x, y, x**2, x*y, y**2]

>>> sorted(itermonomials([x, y], 3), key=monomial_key('grlex', [y, x]))
[1, x, y, x**2, x*y, y**2, x**3, x**2*y, x*y**2, y**3]

modelparameters.sympy.polys.numberfields module

Computational algebraic field theory.

modelparameters.sympy.polys.numberfields.field_isomorphism(a, b, **args)[source]

Construct an isomorphism between two number fields.

modelparameters.sympy.polys.numberfields.isolate(alg, eps=None, fast=False)[source]

Give a rational isolating interval for an algebraic number.

modelparameters.sympy.polys.numberfields.minimal_polynomial(ex, x=None, **args)[source]

Computes the minimal polynomial of an algebraic element.

Parameters:
  • ex (algebraic element expression) –

  • x (independent variable of the minimal polynomial) –

  • Options

  • =======

  • compose (if True _minpoly_compose is used, if False the groebner algorithm) –

  • polys (if True returns a Poly object) –

  • domain (ground domain) –

Notes

By default compose=True, the minimal polynomial of the subexpressions of ex are computed, then the arithmetic operations on them are performed using the resultant and factorization. If compose=False, a bottom-up algorithm is used with groebner. The default algorithm stalls less frequently.

If no ground domain is given, it will be generated automatically from the expression.

Examples

>>> from .. import minimal_polynomial, sqrt, solve, QQ
>>> from ..abc import x, y
>>> minimal_polynomial(sqrt(2), x)
x**2 - 2
>>> minimal_polynomial(sqrt(2), x, domain=QQ.algebraic_field(sqrt(2)))
x - sqrt(2)
>>> minimal_polynomial(sqrt(2) + sqrt(3), x)
x**4 - 10*x**2 + 1
>>> minimal_polynomial(solve(x**3 + x + 3)[0], x)
x**3 + x + 3
>>> minimal_polynomial(sqrt(y), x)
x**2 - y
modelparameters.sympy.polys.numberfields.minpoly(ex, x=None, **args)

Computes the minimal polynomial of an algebraic element.

Parameters:
  • ex (algebraic element expression) –

  • x (independent variable of the minimal polynomial) –

  • Options

  • =======

  • compose (if True _minpoly_compose is used, if False the groebner algorithm) –

  • polys (if True returns a Poly object) –

  • domain (ground domain) –

Notes

By default compose=True, the minimal polynomial of the subexpressions of ex are computed, then the arithmetic operations on them are performed using the resultant and factorization. If compose=False, a bottom-up algorithm is used with groebner. The default algorithm stalls less frequently.

If no ground domain is given, it will be generated automatically from the expression.

Examples

>>> from .. import minimal_polynomial, sqrt, solve, QQ
>>> from ..abc import x, y
>>> minimal_polynomial(sqrt(2), x)
x**2 - 2
>>> minimal_polynomial(sqrt(2), x, domain=QQ.algebraic_field(sqrt(2)))
x - sqrt(2)
>>> minimal_polynomial(sqrt(2) + sqrt(3), x)
x**4 - 10*x**2 + 1
>>> minimal_polynomial(solve(x**3 + x + 3)[0], x)
x**3 + x + 3
>>> minimal_polynomial(sqrt(y), x)
x**2 - y
modelparameters.sympy.polys.numberfields.primitive_element(extension, x=None, **args)[source]

Construct a common number field for all extensions.

modelparameters.sympy.polys.numberfields.to_number_field(extension, theta=None, **args)[source]

Express extension in the field generated by theta.

modelparameters.sympy.polys.orderings module

Definitions of monomial orderings.

modelparameters.sympy.polys.orthopolys module

Efficient functions for generating orthogonal polynomials.

modelparameters.sympy.polys.orthopolys.chebyshevt_poly(n, x=None, **args)[source]

Generates Chebyshev polynomial of the first kind of degree n in x.

modelparameters.sympy.polys.orthopolys.chebyshevu_poly(n, x=None, **args)[source]

Generates Chebyshev polynomial of the second kind of degree n in x.

modelparameters.sympy.polys.orthopolys.hermite_poly(n, x=None, **args)[source]

Generates Hermite polynomial of degree n in x.

modelparameters.sympy.polys.orthopolys.jacobi_poly(n, a, b, x=None, **args)[source]

Generates Jacobi polynomial of degree n in x.

modelparameters.sympy.polys.orthopolys.laguerre_poly(n, x=None, alpha=None, **args)[source]

Generates Laguerre polynomial of degree n in x.

modelparameters.sympy.polys.orthopolys.legendre_poly(n, x=None, **args)[source]

Generates Legendre polynomial of degree n in x.

modelparameters.sympy.polys.partfrac module

Algorithms for partial fraction decomposition of rational functions.

modelparameters.sympy.polys.partfrac.apart(f, x=None, full=False, **options)[source]

Compute partial fraction decomposition of a rational function.

Given a rational function f, computes the partial fraction decomposition of f. Two algorithms are available: One is based on the undertermined coefficients method, the other is Bronstein’s full partial fraction decomposition algorithm.

The undetermined coefficients method (selected by full=False) uses polynomial factorization (and therefore accepts the same options as factor) for the denominator. Per default it works over the rational numbers, therefore decomposition of denominators with non-rational roots (e.g. irrational, complex roots) is not supported by default (see options of factor).

Bronstein’s algorithm can be selected by using full=True and allows a decomposition of denominators with non-rational roots. A human-readable result can be obtained via doit() (see examples below).

Examples

>>> from .partfrac import apart
>>> from ..abc import x, y

By default, using the undetermined coefficients method:

>>> apart(y/(x + 2)/(x + 1), x)
-y/(x + 2) + y/(x + 1)

The undetermined coefficients method does not provide a result when the denominators roots are not rational:

>>> apart(y/(x**2 + x + 1), x)
y/(x**2 + x + 1)

You can choose Bronstein’s algorithm by setting full=True:

>>> apart(y/(x**2 + x + 1), x, full=True)
RootSum(_w**2 + _w + 1, Lambda(_a, (-2*_a*y/3 - y/3)/(-_a + x)))

Calling doit() yields a human-readable result:

>>> apart(y/(x**2 + x + 1), x, full=True).doit()
(-y/3 - 2*y*(-1/2 - sqrt(3)*I/2)/3)/(x + 1/2 + sqrt(3)*I/2) + (-y/3 -
    2*y*(-1/2 + sqrt(3)*I/2)/3)/(x + 1/2 - sqrt(3)*I/2)
modelparameters.sympy.polys.partfrac.apart_list(f, x=None, dummies=None, **options)[source]

Compute partial fraction decomposition of a rational function and return the result in structured form.

Given a rational function f compute the partial fraction decomposition of f. Only Bronstein’s full partial fraction decomposition algorithm is supported by this method. The return value is highly structured and perfectly suited for further algorithmic treatment rather than being human-readable. The function returns a tuple holding three elements:

  • The first item is the common coefficient, free of the variable x used for decomposition. (It is an element of the base field K.)

  • The second item is the polynomial part of the decomposition. This can be the zero polynomial. (It is an element of K[x].)

  • The third part itself is a list of quadruples. Each quadruple has the following elements in this order:

    • The (not necessarily irreducible) polynomial D whose roots w_i appear in the linear denominator of a bunch of related fraction terms. (This item can also be a list of explicit roots. However, at the moment apart_list never returns a result this way, but the related assemble_partfrac_list function accepts this format as input.)

    • The numerator of the fraction, written as a function of the root w

    • The linear denominator of the fraction excluding its power exponent, written as a function of the root w.

    • The power to which the denominator has to be raised.

On can always rebuild a plain expression by using the function assemble_partfrac_list.

Examples

A first example:

>>> from .partfrac import apart_list, assemble_partfrac_list
>>> from ..abc import x, t
>>> f = (2*x**3 - 2*x) / (x**2 - 2*x + 1)
>>> pfd = apart_list(f)
>>> pfd
(1,
Poly(2*x + 4, x, domain='ZZ'),
[(Poly(_w - 1, _w, domain='ZZ'), Lambda(_a, 4), Lambda(_a, -_a + x), 1)])
>>> assemble_partfrac_list(pfd)
2*x + 4 + 4/(x - 1)

Second example:

>>> f = (-2*x - 2*x**2) / (3*x**2 - 6*x)
>>> pfd = apart_list(f)
>>> pfd
(-1,
Poly(2/3, x, domain='QQ'),
[(Poly(_w - 2, _w, domain='ZZ'), Lambda(_a, 2), Lambda(_a, -_a + x), 1)])
>>> assemble_partfrac_list(pfd)
-2/3 - 2/(x - 2)

Another example, showing symbolic parameters:

>>> pfd = apart_list(t/(x**2 + x + t), x)
>>> pfd
(1,
Poly(0, x, domain='ZZ[t]'),
[(Poly(_w**2 + _w + t, _w, domain='ZZ[t]'),
Lambda(_a, -2*_a*t/(4*t - 1) - t/(4*t - 1)),
Lambda(_a, -_a + x),
1)])
>>> assemble_partfrac_list(pfd)
RootSum(_w**2 + _w + t, Lambda(_a, (-2*_a*t/(4*t - 1) - t/(4*t - 1))/(-_a + x)))

This example is taken from Bronstein’s original paper:

>>> f = 36 / (x**5 - 2*x**4 - 2*x**3 + 4*x**2 + x - 2)
>>> pfd = apart_list(f)
>>> pfd
(1,
Poly(0, x, domain='ZZ'),
[(Poly(_w - 2, _w, domain='ZZ'), Lambda(_a, 4), Lambda(_a, -_a + x), 1),
(Poly(_w**2 - 1, _w, domain='ZZ'), Lambda(_a, -3*_a - 6), Lambda(_a, -_a + x), 2),
(Poly(_w + 1, _w, domain='ZZ'), Lambda(_a, -4), Lambda(_a, -_a + x), 1)])
>>> assemble_partfrac_list(pfd)
-4/(x + 1) - 3/(x + 1)**2 - 9/(x - 1)**2 + 4/(x - 2)

References

  1. [Bronstein93]

modelparameters.sympy.polys.partfrac.assemble_partfrac_list(partial_list)[source]

Reassemble a full partial fraction decomposition from a structured result obtained by the function apart_list.

Examples

This example is taken from Bronstein’s original paper:

>>> from .partfrac import apart_list, assemble_partfrac_list
>>> from ..abc import x, y
>>> f = 36 / (x**5 - 2*x**4 - 2*x**3 + 4*x**2 + x - 2)
>>> pfd = apart_list(f)
>>> pfd
(1,
Poly(0, x, domain='ZZ'),
[(Poly(_w - 2, _w, domain='ZZ'), Lambda(_a, 4), Lambda(_a, -_a + x), 1),
(Poly(_w**2 - 1, _w, domain='ZZ'), Lambda(_a, -3*_a - 6), Lambda(_a, -_a + x), 2),
(Poly(_w + 1, _w, domain='ZZ'), Lambda(_a, -4), Lambda(_a, -_a + x), 1)])
>>> assemble_partfrac_list(pfd)
-4/(x + 1) - 3/(x + 1)**2 - 9/(x - 1)**2 + 4/(x - 2)

If we happen to know some roots we can provide them easily inside the structure:

>>> pfd = apart_list(2/(x**2-2))
>>> pfd
(1,
Poly(0, x, domain='ZZ'),
[(Poly(_w**2 - 2, _w, domain='ZZ'),
Lambda(_a, _a/2),
Lambda(_a, -_a + x),
1)])
>>> pfda = assemble_partfrac_list(pfd)
>>> pfda
RootSum(_w**2 - 2, Lambda(_a, _a/(-_a + x)))/2
>>> pfda.doit()
-sqrt(2)/(2*(x + sqrt(2))) + sqrt(2)/(2*(x - sqrt(2)))
>>> from .. import Dummy, Poly, Lambda, sqrt
>>> a = Dummy("a")
>>> pfd = (1, Poly(0, x, domain='ZZ'), [([sqrt(2),-sqrt(2)], Lambda(a, a/2), Lambda(a, -a + x), 1)])
>>> assemble_partfrac_list(pfd)
-sqrt(2)/(2*(x + sqrt(2))) + sqrt(2)/(2*(x - sqrt(2)))

See also

apart, apart_list

modelparameters.sympy.polys.polyclasses module

OO layer for several polynomial representations.

class modelparameters.sympy.polys.polyclasses.ANP(rep, mod, dom)[source]

Bases: PicklableWithSlots, CantSympify

Dense Algebraic Number Polynomials over a field.

LC()[source]

Returns the leading coefficient of f.

TC()[source]

Returns the trailing coefficient of f.

add(g)[source]
div(g)[source]
dom
exquo(g)
classmethod from_list(rep, mod, dom)[source]
property is_ground

Returns True if f is an element of the ground domain.

property is_one

Returns True if f is a unit algebraic number.

property is_zero

Returns True if f is a zero algebraic number.

mod
mul(g)[source]
neg()[source]
classmethod one(mod, dom)[source]
per(rep, mod=None, dom=None)[source]
pow(n)[source]

Raise f to a non-negative power n.

quo(g)[source]
rem(g)[source]
rep
sub(g)[source]
to_dict()[source]

Convert f to a dict representation with native coefficients.

to_list()[source]

Convert f to a list representation with native coefficients.

to_sympy_dict()[source]

Convert f to a dict representation with SymPy coefficients.

to_sympy_list()[source]

Convert f to a list representation with SymPy coefficients.

to_tuple()[source]

Convert f to a tuple representation with native coefficients.

This is needed for hashing.

unify(g)[source]

Unify representations of two algebraic numbers.

classmethod zero(mod, dom)[source]
class modelparameters.sympy.polys.polyclasses.DMF(rep, dom, lev=None, ring=None)[source]

Bases: PicklableWithSlots, CantSympify

Dense Multivariate Fractions over K.

add(g)[source]

Add two multivariate fractions f and g.

cancel()[source]

Remove common factors from f.num and f.den.

den
denom()[source]

Returns the denominator of f.

dom
exquo(g)

Computes quotient of fractions f and g.

frac_unify(g)[source]

Unify representations of two multivariate fractions.

half_per(rep, kill=False)[source]

Create a DMP out of the given representation.

invert(check=True)[source]

Computes inverse of a fraction f.

property is_one

Returns True if f is a unit fraction.

property is_zero

Returns True if f is a zero fraction.

lev
mul(g)[source]

Multiply two multivariate fractions f and g.

neg()[source]

Negate all coefficients in f.

classmethod new(rep, dom, lev=None, ring=None)[source]
num
numer()[source]

Returns the numerator of f.

classmethod one(lev, dom, ring=None)[source]
per(num, den, cancel=True, kill=False, ring=None)[source]

Create a DMF out of the given representation.

poly_unify(g)[source]

Unify a multivariate fraction and a polynomial.

pow(n)[source]

Raise f to a non-negative power n.

quo(g)[source]

Computes quotient of fractions f and g.

ring
sub(g)[source]

Subtract two multivariate fractions f and g.

classmethod zero(lev, dom, ring=None)[source]
class modelparameters.sympy.polys.polyclasses.DMP(rep, dom, lev=None, ring=None)[source]

Bases: PicklableWithSlots, CantSympify

Dense Multivariate Polynomials over K.

LC()[source]

Returns the leading coefficient of f.

TC()[source]

Returns the trailing coefficient of f.

abs()[source]

Make all coefficients in f positive.

add(g)[source]

Add two multivariate polynomials f and g.

add_ground(c)[source]

Add an element of the ground domain to f.

all_coeffs()[source]

Returns all coefficients from f.

all_monoms()[source]

Returns all monomials from f.

all_terms()[source]

Returns all terms from a f.

cancel(g, include=True)[source]

Cancel common factors in a rational function f/g.

clear_denoms()[source]

Clear denominators, but keep the ground domain.

coeffs(order=None)[source]

Returns all non-zero coefficients from f in lex order.

cofactors(g)[source]

Returns GCD of f and g and their cofactors.

compose(g)[source]

Computes functional composition of f and g.

content()[source]

Returns GCD of polynomial coefficients.

convert(dom)[source]

Convert the ground domain of f.

count_complex_roots(inf=None, sup=None)[source]

Return the number of complex roots of f in [inf, sup].

count_real_roots(inf=None, sup=None)[source]

Return the number of real roots of f in [inf, sup].

decompose()[source]

Computes functional decomposition of f.

deflate()[source]

Reduce degree of f by mapping x_i^m to y_i.

degree(j=0)[source]

Returns the leading degree of f in x_j.

degree_list()[source]

Returns a list of degrees of f.

diff(m=1, j=0)[source]

Computes the m-th order derivative of f in x_j.

discriminant()[source]

Computes discriminant of f.

div(g)[source]

Polynomial division with remainder of f and g.

dom
eject(dom, front=False)[source]

Eject selected generators into the ground domain.

eq(g, strict=False)[source]
eval(a, j=0)[source]

Evaluates f at the given point a in x_j.

exclude()[source]

Remove useless generators from f.

Returns the removed generators and the new excluded f.

Examples

>>> from .polyclasses import DMP
>>> from .domains import ZZ
>>> DMP([[[ZZ(1)]], [[ZZ(1)], [ZZ(2)]]], ZZ).exclude()
([2], DMP([[1], [1, 2]], ZZ, None))
exquo(g)[source]

Computes polynomial exact quotient of f and g.

exquo_ground(c)[source]

Exact quotient of f by a an element of the ground domain.

factor_list()[source]

Returns a list of irreducible factors of f.

factor_list_include()[source]

Returns a list of irreducible factors of f.

classmethod from_dict(rep, lev, dom)[source]

Construct and instance of cls from a dict representation.

classmethod from_list(rep, lev, dom)[source]

Create an instance of cls given a list of native coefficients.

classmethod from_monoms_coeffs(monoms, coeffs, lev, dom, ring=None)[source]
classmethod from_sympy_list(rep, lev, dom)[source]

Create an instance of cls given a list of SymPy coefficients.

gcd(g)[source]

Returns polynomial GCD of f and g.

gcdex(g)[source]

Extended Euclidean algorithm, if univariate.

gff_list()[source]

Computes greatest factorial factorization of f.

half_gcdex(g)[source]

Half extended Euclidean algorithm, if univariate.

homogeneous_order()[source]

Returns the homogeneous order of f.

homogenize(s)[source]

Return homogeneous polynomial of f

inject(front=False)[source]

Inject ground domain generators into f.

integrate(m=1, j=0)[source]

Computes the m-th order indefinite integral of f in x_j.

intervals(all=False, eps=None, inf=None, sup=None, fast=False, sqf=False)[source]

Compute isolating intervals for roots of f.

invert(g)[source]

Invert f modulo g, if possible.

property is_cyclotomic

Returns True if f is a cyclotomic polynomial.

property is_ground

Returns True if f is an element of the ground domain.

property is_homogeneous

Returns True if f is a homogeneous polynomial.

property is_irreducible

Returns True if f has no factors over its domain.

property is_linear

Returns True if f is linear in all its variables.

property is_monic

Returns True if the leading coefficient of f is one.

property is_monomial

Returns True if f is zero or has only one term.

property is_one

Returns True if f is a unit polynomial.

property is_primitive

Returns True if the GCD of the coefficients of f is one.

property is_quadratic

Returns True if f is quadratic in all its variables.

property is_sqf

Returns True if f is a square-free polynomial.

property is_zero

Returns True if f is a zero polynomial.

l1_norm()[source]

Returns l1 norm of f.

lcm(g)[source]

Returns polynomial LCM of f and g.

lev
lift()[source]

Convert algebraic coefficients to rationals.

max_norm()[source]

Returns maximum norm of f.

monic()[source]

Divides all coefficients by LC(f).

monoms(order=None)[source]

Returns all non-zero monomials from f in lex order.

mul(g)[source]

Multiply two multivariate polynomials f and g.

mul_ground(c)[source]

Multiply f by a an element of the ground domain.

ne(g, strict=False)[source]
neg()[source]

Negate all coefficients in f.

nth(*N)[source]

Returns the n-th coefficient of f.

classmethod one(lev, dom, ring=None)[source]
pdiv(g)[source]

Polynomial pseudo-division of f and g.

per(rep, dom=None, kill=False, ring=None)[source]

Create a DMP out of the given representation.

permute(P)[source]

Returns a polynomial in K[x_{P(1)}, …, x_{P(n)}].

Examples

>>> from .polyclasses import DMP
>>> from .domains import ZZ
>>> DMP([[[ZZ(2)], [ZZ(1), ZZ(0)]], [[]]], ZZ).permute([1, 0, 2])
DMP([[[2], []], [[1, 0], []]], ZZ, None)
>>> DMP([[[ZZ(2)], [ZZ(1), ZZ(0)]], [[]]], ZZ).permute([1, 2, 0])
DMP([[[1], []], [[2, 0], []]], ZZ, None)
pexquo(g)[source]

Polynomial exact pseudo-quotient of f and g.

pow(n)[source]

Raise f to a non-negative power n.

pquo(g)[source]

Polynomial pseudo-quotient of f and g.

prem(g)[source]

Polynomial pseudo-remainder of f and g.

primitive()[source]

Returns content and a primitive form of f.

quo(g)[source]

Computes polynomial quotient of f and g.

quo_ground(c)[source]

Quotient of f by a an element of the ground domain.

refine_root(s, t, eps=None, steps=None, fast=False)[source]

Refine an isolating interval to the given precision.

eps should be a rational number.

rem(g)[source]

Computes polynomial remainder of f and g.

rep
resultant(g, includePRS=False)[source]

Computes resultant of f and g via PRS.

revert(n)[source]

Compute f**(-1) mod x**n.

ring
shift(a)[source]

Efficiently compute Taylor shift f(x + a).

slice(m, n, j=0)[source]

Take a continuous subsequence of terms of f.

sqf_list(all=False)[source]

Returns a list of square-free factors of f.

sqf_list_include(all=False)[source]

Returns a list of square-free factors of f.

sqf_norm()[source]

Computes square-free norm of f.

sqf_part()[source]

Computes square-free part of f.

sqr()[source]

Square a multivariate polynomial f.

sturm()[source]

Computes the Sturm sequence of f.

sub(g)[source]

Subtract two multivariate polynomials f and g.

sub_ground(c)[source]

Subtract an element of the ground domain from f.

subresultants(g)[source]

Computes subresultant PRS sequence of f and g.

terms(order=None)[source]

Returns all non-zero terms from f in lex order.

terms_gcd()[source]

Remove GCD of terms from the polynomial f.

to_dict(zero=False)[source]

Convert f to a dict representation with native coefficients.

to_exact()[source]

Make the ground domain exact.

to_field()[source]

Make the ground domain a field.

to_ring()[source]

Make the ground domain a ring.

to_sympy_dict(zero=False)[source]

Convert f to a dict representation with SymPy coefficients.

to_tuple()[source]

Convert f to a tuple representation with native coefficients.

This is needed for hashing.

total_degree()[source]

Returns the total degree of f.

transform(p, q)[source]

Evaluate functional transformation q**n * f(p/q).

trunc(p)[source]

Reduce f modulo a constant p.

unify(g)[source]

Unify representations of two multivariate polynomials.

classmethod zero(lev, dom, ring=None)[source]
class modelparameters.sympy.polys.polyclasses.GenericPoly[source]

Bases: PicklableWithSlots

Base class for low-level polynomial representations.

ground_to_exact()[source]

Make the ground domain exact.

ground_to_field()[source]

Make the ground domain a field.

ground_to_ring()[source]

Make the ground domain a ring.

modelparameters.sympy.polys.polyclasses.init_normal_ANP(rep, mod, dom)[source]
modelparameters.sympy.polys.polyclasses.init_normal_DMF(num, den, lev, dom)[source]
modelparameters.sympy.polys.polyclasses.init_normal_DMP(rep, lev, dom)[source]

modelparameters.sympy.polys.polyconfig module

Configuration utilities for polynomial manipulation algorithms.

modelparameters.sympy.polys.polyconfig.configure()[source]

Initialized configuration of polys module.

modelparameters.sympy.polys.polyconfig.query(key)[source]

Ask for a value of the given configuration item.

modelparameters.sympy.polys.polyconfig.setup(key, value=None)[source]

Assign a value to (or reset) a configuration item.

modelparameters.sympy.polys.polyconfig.using(**kwargs)[source]

modelparameters.sympy.polys.polyerrors module

Definitions of common exceptions for polys module.

exception modelparameters.sympy.polys.polyerrors.BasePolynomialError[source]

Bases: Exception

Base class for polynomial related exceptions.

new(*args)[source]
exception modelparameters.sympy.polys.polyerrors.CoercionFailed[source]

Bases: BasePolynomialError

exception modelparameters.sympy.polys.polyerrors.ComputationFailed(func, nargs, exc)[source]

Bases: BasePolynomialError

exception modelparameters.sympy.polys.polyerrors.DomainError[source]

Bases: BasePolynomialError

exception modelparameters.sympy.polys.polyerrors.EvaluationFailed[source]

Bases: BasePolynomialError

exception modelparameters.sympy.polys.polyerrors.ExactQuotientFailed(f, g, dom=None)[source]

Bases: BasePolynomialError

new(f, g)[source]
exception modelparameters.sympy.polys.polyerrors.ExtraneousFactors[source]

Bases: BasePolynomialError

exception modelparameters.sympy.polys.polyerrors.FlagError[source]

Bases: OptionError

exception modelparameters.sympy.polys.polyerrors.GeneratorsError[source]

Bases: BasePolynomialError

exception modelparameters.sympy.polys.polyerrors.GeneratorsNeeded[source]

Bases: GeneratorsError

exception modelparameters.sympy.polys.polyerrors.HeuristicGCDFailed[source]

Bases: BasePolynomialError

exception modelparameters.sympy.polys.polyerrors.HomomorphismFailed[source]

Bases: BasePolynomialError

exception modelparameters.sympy.polys.polyerrors.IsomorphismFailed[source]

Bases: BasePolynomialError

exception modelparameters.sympy.polys.polyerrors.MultivariatePolynomialError[source]

Bases: PolynomialError

exception modelparameters.sympy.polys.polyerrors.NotAlgebraic[source]

Bases: BasePolynomialError

exception modelparameters.sympy.polys.polyerrors.NotInvertible[source]

Bases: BasePolynomialError

exception modelparameters.sympy.polys.polyerrors.NotReversible[source]

Bases: BasePolynomialError

exception modelparameters.sympy.polys.polyerrors.OperationNotSupported(poly, func)[source]

Bases: BasePolynomialError

exception modelparameters.sympy.polys.polyerrors.OptionError[source]

Bases: BasePolynomialError

exception modelparameters.sympy.polys.polyerrors.PolificationFailed(opt, origs, exprs, seq=False)[source]

Bases: PolynomialError

exception modelparameters.sympy.polys.polyerrors.PolynomialDivisionFailed(f, g, domain)[source]

Bases: BasePolynomialError

exception modelparameters.sympy.polys.polyerrors.PolynomialError[source]

Bases: BasePolynomialError

exception modelparameters.sympy.polys.polyerrors.RefinementFailed[source]

Bases: BasePolynomialError

exception modelparameters.sympy.polys.polyerrors.UnificationFailed[source]

Bases: BasePolynomialError

exception modelparameters.sympy.polys.polyerrors.UnivariatePolynomialError[source]

Bases: PolynomialError

modelparameters.sympy.polys.polyfuncs module

High-level polynomials manipulation functions.

modelparameters.sympy.polys.polyfuncs.horner(f, *gens, **args)[source]

Rewrite a polynomial in Horner form.

Among other applications, evaluation of a polynomial at a point is optimal when it is applied using the Horner scheme ([1]).

Examples

>>> from .polyfuncs import horner
>>> from ..abc import x, y, a, b, c, d, e
>>> horner(9*x**4 + 8*x**3 + 7*x**2 + 6*x + 5)
x*(x*(x*(9*x + 8) + 7) + 6) + 5
>>> horner(a*x**4 + b*x**3 + c*x**2 + d*x + e)
e + x*(d + x*(c + x*(a*x + b)))
>>> f = 4*x**2*y**2 + 2*x**2*y + 2*x*y**2 + x*y
>>> horner(f, wrt=x)
x*(x*y*(4*y + 2) + y*(2*y + 1))
>>> horner(f, wrt=y)
y*(x*y*(4*x + 2) + x*(2*x + 1))

References

[1] - http://en.wikipedia.org/wiki/Horner_scheme

modelparameters.sympy.polys.polyfuncs.interpolate(data, x)[source]

Construct an interpolating polynomial for the data points.

Examples

>>> from .polyfuncs import interpolate
>>> from ..abc import x

A list is interpreted as though it were paired with a range starting from 1:

>>> interpolate([1, 4, 9, 16], x)
x**2

This can be made explicit by giving a list of coordinates:

>>> interpolate([(1, 1), (2, 4), (3, 9)], x)
x**2

The (x, y) coordinates can also be given as keys and values of a dictionary (and the points need not be equispaced):

>>> interpolate([(-1, 2), (1, 2), (2, 5)], x)
x**2 + 1
>>> interpolate({-1: 2, 1: 2, 2: 5}, x)
x**2 + 1
modelparameters.sympy.polys.polyfuncs.rational_interpolate(data, degnum, X=x)[source]

Returns a rational interpolation, where the data points are element of any integral domain.

The first argument contains the data (as a list of coordinates). The degnum argument is the degree in the numerator of the rational function. Setting it too high will decrease the maximal degree in the denominator for the same amount of data.

Example:

>>> from .polyfuncs import rational_interpolate
>>> data = [(1, -210), (2, -35), (3, 105), (4, 231), (5, 350), (6, 465)]
>>> rational_interpolate(data, 2)
(105*x**2 - 525)/(x + 1)

Values do not need to be integers:

>>> from .. import sympify
>>> x = [1, 2, 3, 4, 5, 6]
>>> y = sympify("[-1, 0, 2, 22/5, 7, 68/7]")
>>> rational_interpolate(zip(x, y), 2)
(3*x**2 - 7*x + 2)/(x + 1)

The symbol for the variable can be changed if needed: >>> from .. import symbols >>> z = symbols(‘z’) >>> rational_interpolate(data, 2, X=z) (105*z**2 - 525)/(z + 1)

References

Algorithm is adapted from:

http://axiom-wiki.newsynthesis.org/RationalInterpolation

modelparameters.sympy.polys.polyfuncs.symmetrize(F, *gens, **args)[source]

Rewrite a polynomial in terms of elementary symmetric polynomials.

A symmetric polynomial is a multivariate polynomial that remains invariant under any variable permutation, i.e., if f = f(x_1, x_2, ..., x_n), then f = f(x_{i_1}, x_{i_2}, ..., x_{i_n}), where (i_1, i_2, ..., i_n) is a permutation of (1, 2, ..., n) (an element of the group S_n).

Returns a tuple of symmetric polynomials (f1, f2, ..., fn) such that f = f1 + f2 + ... + fn.

Examples

>>> from .polyfuncs import symmetrize
>>> from ..abc import x, y
>>> symmetrize(x**2 + y**2)
(-2*x*y + (x + y)**2, 0)
>>> symmetrize(x**2 + y**2, formal=True)
(s1**2 - 2*s2, 0, [(s1, x + y), (s2, x*y)])
>>> symmetrize(x**2 - y**2)
(-2*x*y + (x + y)**2, -2*y**2)
>>> symmetrize(x**2 - y**2, formal=True)
(s1**2 - 2*s2, -2*y**2, [(s1, x + y), (s2, x*y)])
modelparameters.sympy.polys.polyfuncs.viete(f, roots=None, *gens, **args)[source]

Generate Viete’s formulas for f.

Examples

>>> from .polyfuncs import viete
>>> from .. import symbols
>>> x, a, b, c, r1, r2 = symbols('x,a:c,r1:3')
>>> viete(a*x**2 + b*x + c, [r1, r2], x)
[(r1 + r2, -b/a), (r1*r2, c/a)]

modelparameters.sympy.polys.polymatrix module

class modelparameters.sympy.polys.polymatrix.MutablePolyDenseMatrix(*args, **kwargs)[source]

Bases: MutableDenseMatrix

A mutable matrix of objects from poly module or to operate with them.

>>> from .polymatrix import PolyMatrix
>>> from .. import Symbol, Poly, ZZ
>>> x = Symbol('x')
>>> pm1 = PolyMatrix([[Poly(x**2, x), Poly(-x, x)], [Poly(x**3, x), Poly(-1 + x, x)]])
>>> v1 = PolyMatrix([[1, 0], [-1, 0]])
>>> pm1*v1
Matrix([
[    Poly(x**2 + x, x, domain='ZZ'), Poly(0, x, domain='ZZ')],
[Poly(x**3 - x + 1, x, domain='ZZ'), Poly(0, x, domain='ZZ')]])
>>> pm1.ring
ZZ[x]
>>> v1*pm1
Matrix([
[ Poly(x**2, x, domain='ZZ'), Poly(-x, x, domain='ZZ')],
[Poly(-x**2, x, domain='ZZ'),  Poly(x, x, domain='ZZ')]])
>>> pm2 = PolyMatrix([[Poly(x**2, x, domain='QQ'), Poly(0, x, domain='QQ'), Poly(1, x, domain='QQ'),             Poly(x**3, x, domain='QQ'), Poly(0, x, domain='QQ'), Poly(-x**3, x, domain='QQ')]])
>>> v2 = PolyMatrix([1, 0, 0, 0, 0, 0], ring=ZZ)
>>> v2.ring
ZZ
>>> pm2*v2
Matrix([[Poly(x**2, x, domain='QQ')]])
modelparameters.sympy.polys.polymatrix.MutablePolyMatrix

alias of MutablePolyDenseMatrix

modelparameters.sympy.polys.polymatrix.PolyMatrix

alias of MutablePolyDenseMatrix

modelparameters.sympy.polys.polyoptions module

Options manager for Poly and public API functions.

class modelparameters.sympy.polys.polyoptions.Options(gens, args, flags=None, strict=False)[source]

Bases: dict

Options manager for polynomial manipulation module.

Examples

>>> from .polyoptions import Options
>>> from .polyoptions import build_options
>>> from ..abc import x, y, z
>>> Options((x, y, z), {'domain': 'ZZ'})
{'auto': False, 'domain': ZZ, 'gens': (x, y, z)}
>>> build_options((x, y, z), {'domain': 'ZZ'})
{'auto': False, 'domain': ZZ, 'gens': (x, y, z)}

Options

  • Expand — boolean option

  • Gens — option

  • Wrt — option

  • Sort — option

  • Order — option

  • Field — boolean option

  • Greedy — boolean option

  • Domain — option

  • Split — boolean option

  • Gaussian — boolean option

  • Extension — option

  • Modulus — option

  • Symmetric — boolean option

  • Strict — boolean option

Flags

  • Auto — boolean flag

  • Frac — boolean flag

  • Formal — boolean flag

  • Polys — boolean flag

  • Include — boolean flag

  • All — boolean flag

  • Gen — flag

  • Series — boolean flag

property all
property args
property auto
clone(updates={})[source]

Clone self and update specified options.

property composite
property domain
property expand
property extension
property field
property flags
property formal
property frac
property gaussian
property gen
property gens
property greedy
property include
property method
property modulus
property options
property order
property polys
property series
property sort
property split
property strict
property symbols
property symmetric
property wrt

modelparameters.sympy.polys.polyquinticconst module

Solving solvable quintics - An implementation of DS Dummit’s paper

Paper : http://www.ams.org/journals/mcom/1991-57-195/S0025-5718-1991-1079014-X/S0025-5718-1991-1079014-X.pdf

Mathematica notebook: http://www.emba.uvm.edu/~ddummit/quintics/quintics.nb

class modelparameters.sympy.polys.polyquinticconst.PolyQuintic(poly)[source]

Bases: object

Special functions for solvable quintics

property F
T(theta, d)[source]
property a
property b
property c
property f20
l0(theta)[source]
property o
order(theta, d)[source]
uv(theta, d)[source]
property zeta

modelparameters.sympy.polys.polyroots module

Algorithms for computing symbolic roots of polynomials.

modelparameters.sympy.polys.polyroots.roots(f, *gens, **flags)[source]

Computes symbolic roots of a univariate polynomial.

Given a univariate polynomial f with symbolic coefficients (or a list of the polynomial’s coefficients), returns a dictionary with its roots and their multiplicities.

Only roots expressible via radicals will be returned. To get a complete set of roots use RootOf class or numerical methods instead. By default cubic and quartic formulas are used in the algorithm. To disable them because of unreadable output set cubics=False or quartics=False respectively. If cubic roots are real but are expressed in terms of complex numbers (casus irreducibilis [1]) the trig flag can be set to True to have the solutions returned in terms of cosine and inverse cosine functions.

To get roots from a specific domain set the filter flag with one of the following specifiers: Z, Q, R, I, C. By default all roots are returned (this is equivalent to setting filter='C').

By default a dictionary is returned giving a compact result in case of multiple roots. However to get a list containing all those roots set the multiple flag to True; the list will have identical roots appearing next to each other in the result. (For a given Poly, the all_roots method will give the roots in sorted numerical order.)

Examples

>>> from .. import Poly, roots
>>> from ..abc import x, y
>>> roots(x**2 - 1, x)
{-1: 1, 1: 1}
>>> p = Poly(x**2-1, x)
>>> roots(p)
{-1: 1, 1: 1}
>>> p = Poly(x**2-y, x, y)
>>> roots(Poly(p, x))
{-sqrt(y): 1, sqrt(y): 1}
>>> roots(x**2 - y, x)
{-sqrt(y): 1, sqrt(y): 1}
>>> roots([1, 0, -1])
{-1: 1, 1: 1}

References

  1. http://en.wikipedia.org/wiki/Cubic_function#Trigonometric_.28and_hyperbolic.29_method

modelparameters.sympy.polys.polytools module

User-friendly public interface to polynomial functions.

class modelparameters.sympy.polys.polytools.GroebnerBasis(F, *gens, **args)[source]

Bases: Basic

Represents a reduced Groebner basis.

property args

Returns a tuple of arguments of ‘self’.

Examples

>>> from .. import cot
>>> from ..abc import x, y
>>> cot(x).args
(x,)
>>> cot(x).args[0]
x
>>> (x*y).args
(x, y)
>>> (x*y).args[1]
y

Notes

Never use self._args, always use self.args. Only use _args in __new__ when creating a new function. Don’t override .args() from Basic (so that it’s easy to change the interface in the future if needed).

contains(poly)[source]

Check if poly belongs the ideal generated by self.

Examples

>>> from .. import groebner
>>> from ..abc import x, y
>>> f = 2*x**3 + y**3 + 3*y
>>> G = groebner([x**2 + y**2 - 1, x*y - 2])
>>> G.contains(f)
True
>>> G.contains(f + 1)
False
default_assumptions = {}
property domain
property exprs
fglm(order)[source]

Convert a Groebner basis from one ordering to another.

The FGLM algorithm converts reduced Groebner bases of zero-dimensional ideals from one ordering to another. This method is often used when it is infeasible to compute a Groebner basis with respect to a particular ordering directly.

Examples

>>> from ..abc import x, y
>>> from .. import groebner
>>> F = [x**2 - 3*y - x + 1, y**2 - 2*x + y - 1]
>>> G = groebner(F, x, y, order='grlex')
>>> list(G.fglm('lex'))
[2*x - y**2 - y + 1, y**4 + 2*y**3 - 3*y**2 - 16*y + 7]
>>> list(groebner(F, x, y, order='lex'))
[2*x - y**2 - y + 1, y**4 + 2*y**3 - 3*y**2 - 16*y + 7]

References

J.C. Faugere, P. Gianni, D. Lazard, T. Mora (1994). Efficient Computation of Zero-dimensional Groebner Bases by Change of Ordering

property gens
property is_zero_dimensional

Checks if the ideal generated by a Groebner basis is zero-dimensional.

The algorithm checks if the set of monomials not divisible by the leading monomial of any element of F is bounded.

References

David A. Cox, John B. Little, Donal O’Shea. Ideals, Varieties and Algorithms, 3rd edition, p. 230

property order
property polys
reduce(expr, auto=True)[source]

Reduces a polynomial modulo a Groebner basis.

Given a polynomial f and a set of polynomials G = (g_1, ..., g_n), computes a set of quotients q = (q_1, ..., q_n) and the remainder r such that f = q_1*f_1 + ... + q_n*f_n + r, where r vanishes or r is a completely reduced polynomial with respect to G.

Examples

>>> from .. import groebner, expand
>>> from ..abc import x, y
>>> f = 2*x**4 - x**2 + y**3 + y**2
>>> G = groebner([x**3 - x, y**3 - y])
>>> G.reduce(f)
([2*x, 1], x**2 + y**2 + y)
>>> Q, r = _
>>> expand(sum(q*g for q, g in zip(Q, G)) + r)
2*x**4 - x**2 + y**3 + y**2
>>> _ == f
True
modelparameters.sympy.polys.polytools.LC(f, *gens, **args)[source]

Return the leading coefficient of f.

Examples

>>> from .. import LC
>>> from ..abc import x, y
>>> LC(4*x**2 + 2*x*y**2 + x*y + 3*y)
4
modelparameters.sympy.polys.polytools.LM(f, *gens, **args)[source]

Return the leading monomial of f.

Examples

>>> from .. import LM
>>> from ..abc import x, y
>>> LM(4*x**2 + 2*x*y**2 + x*y + 3*y)
x**2
modelparameters.sympy.polys.polytools.LT(f, *gens, **args)[source]

Return the leading term of f.

Examples

>>> from .. import LT
>>> from ..abc import x, y
>>> LT(4*x**2 + 2*x*y**2 + x*y + 3*y)
4*x**2
class modelparameters.sympy.polys.polytools.Poly(rep, *gens, **args)[source]

Bases: Expr

Generic class for representing and operating on polynomial expressions. Subclasses Expr class.

Examples

>>> from .. import Poly
>>> from ..abc import x, y

Create a univariate polynomial:

>>> Poly(x*(x**2 + x - 1)**2)
Poly(x**5 + 2*x**4 - x**3 - 2*x**2 + x, x, domain='ZZ')

Create a univariate polynomial with specific domain:

>>> from .. import sqrt
>>> Poly(x**2 + 2*x + sqrt(3), domain='R')
Poly(1.0*x**2 + 2.0*x + 1.73205080756888, x, domain='RR')

Create a multivariate polynomial:

>>> Poly(y*x**2 + x*y + 1)
Poly(x**2*y + x*y + 1, x, y, domain='ZZ')

Create a univariate polynomial, where y is a constant:

>>> Poly(y*x**2 + x*y + 1,x)
Poly(y*x**2 + y*x + 1, x, domain='ZZ[y]')

You can evaluate the above polynomial as a function of y:

>>> Poly(y*x**2 + x*y + 1,x).eval(2)
6*y + 1

See also

sympy.core.expr.Expr

EC(order=None)[source]

Returns the last non-zero coefficient of f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**3 + 2*x**2 + 3*x, x).EC()
3
EM(order=None)[source]

Returns the last non-zero monomial of f.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(4*x**2 + 2*x*y**2 + x*y + 3*y, x, y).EM()
x**0*y**1
ET(order=None)[source]

Returns the last non-zero term of f.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(4*x**2 + 2*x*y**2 + x*y + 3*y, x, y).ET()
(x**0*y**1, 3)
LC(order=None)[source]

Returns the leading coefficient of f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(4*x**3 + 2*x**2 + 3*x, x).LC()
4
LM(order=None)[source]

Returns the leading monomial of f.

The Leading monomial signifies the monomial having the highest power of the principal generator in the expression f.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(4*x**2 + 2*x*y**2 + x*y + 3*y, x, y).LM()
x**2*y**0
LT(order=None)[source]

Returns the leading term of f.

The Leading term signifies the term having the highest power of the principal generator in the expression f along with its coefficient.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(4*x**2 + 2*x*y**2 + x*y + 3*y, x, y).LT()
(x**2*y**0, 4)
TC()[source]

Returns the trailing coefficient of f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**3 + 2*x**2 + 3*x, x).TC()
0
abs()[source]

Make all coefficients in f positive.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 - 1, x).abs()
Poly(x**2 + 1, x, domain='ZZ')
add(g)[source]

Add two polynomials f and g.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 + 1, x).add(Poly(x - 2, x))
Poly(x**2 + x - 1, x, domain='ZZ')
>>> Poly(x**2 + 1, x) + Poly(x - 2, x)
Poly(x**2 + x - 1, x, domain='ZZ')
add_ground(coeff)[source]

Add an element of the ground domain to f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x + 1).add_ground(2)
Poly(x + 3, x, domain='ZZ')
all_coeffs()[source]

Returns all coefficients from a univariate polynomial f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**3 + 2*x - 1, x).all_coeffs()
[1, 0, 2, -1]
all_monoms()[source]

Returns all monomials from a univariate polynomial f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**3 + 2*x - 1, x).all_monoms()
[(3,), (2,), (1,), (0,)]

See also

all_terms

all_roots(multiple=True, radicals=True)[source]

Return a list of real and complex roots with multiplicities.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(2*x**3 - 7*x**2 + 4*x + 4).all_roots()
[-1/2, 2, 2]
>>> Poly(x**3 + x + 1).all_roots()
[CRootOf(x**3 + x + 1, 0),
 CRootOf(x**3 + x + 1, 1),
 CRootOf(x**3 + x + 1, 2)]
all_terms()[source]

Returns all terms from a univariate polynomial f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**3 + 2*x - 1, x).all_terms()
[((3,), 1), ((2,), 0), ((1,), 2), ((0,), -1)]
property args

Don’t mess up with the core.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 + 1, x).args
(x**2 + 1,)
as_dict(native=False, zero=False)[source]

Switch to a dict representation.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(x**2 + 2*x*y**2 - y, x, y).as_dict()
{(0, 1): -1, (1, 2): 2, (2, 0): 1}
as_expr(*gens)[source]

Convert a Poly instance to an Expr instance.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> f = Poly(x**2 + 2*x*y**2 - y, x, y)
>>> f.as_expr()
x**2 + 2*x*y**2 - y
>>> f.as_expr({x: 5})
10*y**2 - y + 25
>>> f.as_expr(5, 6)
379
as_list(native=False)[source]

Switch to a list representation.

cancel(g, include=False)[source]

Cancel common factors in a rational function f/g.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(2*x**2 - 2, x).cancel(Poly(x**2 - 2*x + 1, x))
(1, Poly(2*x + 2, x, domain='ZZ'), Poly(x - 1, x, domain='ZZ'))
>>> Poly(2*x**2 - 2, x).cancel(Poly(x**2 - 2*x + 1, x), include=True)
(Poly(2*x + 2, x, domain='ZZ'), Poly(x - 1, x, domain='ZZ'))
clear_denoms(convert=False)[source]

Clear denominators, but keep the ground domain.

Examples

>>> from .. import Poly, S, QQ
>>> from ..abc import x
>>> f = Poly(x/2 + S(1)/3, x, domain=QQ)
>>> f.clear_denoms()
(6, Poly(3*x + 2, x, domain='QQ'))
>>> f.clear_denoms(convert=True)
(6, Poly(3*x + 2, x, domain='ZZ'))
coeff(x, n=1, right=False)[source]

Returns the coefficient from the term(s) containing x**n. If n is zero then all terms independent of x will be returned.

When x is noncommutative, the coefficient to the left (default) or right of x can be returned. The keyword ‘right’ is ignored when x is commutative.

See also

as_coefficient

separate the expression into a coefficient and factor

as_coeff_Add

separate the additive constant from an expression

as_coeff_Mul

separate the multiplicative constant from an expression

as_independent

separate x-dependent terms/factors from others

sympy.polys.polytools.coeff_monomial

efficiently find the single coefficient of a monomial in Poly

sympy.polys.polytools.nth

like coeff_monomial but powers of monomial terms are used

Examples

>>> from .. import symbols
>>> from ..abc import x, y, z

You can select terms that have an explicit negative in front of them:

>>> (-x + 2*y).coeff(-1)
x
>>> (x - 2*y).coeff(-1)
2*y

You can select terms with no Rational coefficient:

>>> (x + 2*y).coeff(1)
x
>>> (3 + 2*x + 4*x**2).coeff(1)
0

You can select terms independent of x by making n=0; in this case expr.as_independent(x)[0] is returned (and 0 will be returned instead of None):

>>> (3 + 2*x + 4*x**2).coeff(x, 0)
3
>>> eq = ((x + 1)**3).expand() + 1
>>> eq
x**3 + 3*x**2 + 3*x + 2
>>> [eq.coeff(x, i) for i in reversed(range(4))]
[1, 3, 3, 2]
>>> eq -= 2
>>> [eq.coeff(x, i) for i in reversed(range(4))]
[1, 3, 3, 0]

You can select terms that have a numerical term in front of them:

>>> (-x - 2*y).coeff(2)
-y
>>> from .. import sqrt
>>> (x + sqrt(2)*x).coeff(sqrt(2))
x

The matching is exact:

>>> (3 + 2*x + 4*x**2).coeff(x)
2
>>> (3 + 2*x + 4*x**2).coeff(x**2)
4
>>> (3 + 2*x + 4*x**2).coeff(x**3)
0
>>> (z*(x + y)**2).coeff((x + y)**2)
z
>>> (z*(x + y)**2).coeff(x + y)
0

In addition, no factoring is done, so 1 + z*(1 + y) is not obtained from the following:

>>> (x + z*(x + x*y)).coeff(x)
1

If such factoring is desired, factor_terms can be used first:

>>> from .. import factor_terms
>>> factor_terms(x + z*(x + x*y)).coeff(x)
z*(y + 1) + 1
>>> n, m, o = symbols('n m o', commutative=False)
>>> n.coeff(n)
1
>>> (3*n).coeff(n)
3
>>> (n*m + m*n*m).coeff(n) # = (1 + m)*n*m
1 + m
>>> (n*m + m*n*m).coeff(n, right=True) # = (1 + m)*n*m
m

If there is more than one possible coefficient 0 is returned:

>>> (n*m + m*n).coeff(n)
0

If there is only one possible coefficient, it is returned:

>>> (n*m + x*m*n).coeff(m*n)
x
>>> (n*m + x*m*n).coeff(m*n, right=1)
1
coeff_monomial(monom)[source]

Returns the coefficient of monom in f if there, else None.

Examples

>>> from .. import Poly, exp
>>> from ..abc import x, y
>>> p = Poly(24*x*y*exp(8) + 23*x, x, y)
>>> p.coeff_monomial(x)
23
>>> p.coeff_monomial(y)
0
>>> p.coeff_monomial(x*y)
24*exp(8)

Note that Expr.coeff() behaves differently, collecting terms if possible; the Poly must be converted to an Expr to use that method, however:

>>> p.as_expr().coeff(x)
24*y*exp(8) + 23
>>> p.as_expr().coeff(y)
24*x*exp(8)
>>> p.as_expr().coeff(x*y)
24*exp(8)

See also

nth

more efficient query using exponents of the monomial’s generators

coeffs(order=None)[source]

Returns all non-zero coefficients from f in lex order.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**3 + 2*x + 3, x).coeffs()
[1, 2, 3]
cofactors(g)[source]

Returns the GCD of f and g and their cofactors.

Returns polynomials (h, cff, cfg) such that h = gcd(f, g), and cff = quo(f, h) and cfg = quo(g, h) are, so called, cofactors of f and g.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 - 1, x).cofactors(Poly(x**2 - 3*x + 2, x))
(Poly(x - 1, x, domain='ZZ'),
 Poly(x + 1, x, domain='ZZ'),
 Poly(x - 2, x, domain='ZZ'))
compose(g)[source]

Computes the functional composition of f and g.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 + x, x).compose(Poly(x - 1, x))
Poly(x**2 - x, x, domain='ZZ')
content()[source]

Returns the GCD of polynomial coefficients.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(6*x**2 + 8*x + 12, x).content()
2
count_roots(inf=None, sup=None)[source]

Return the number of roots of f in [inf, sup] interval.

Examples

>>> from .. import Poly, I
>>> from ..abc import x
>>> Poly(x**4 - 4, x).count_roots(-3, 3)
2
>>> Poly(x**4 - 4, x).count_roots(0, 1 + 3*I)
1
decompose()[source]

Computes a functional decomposition of f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**4 + 2*x**3 - x - 1, x, domain='ZZ').decompose()
[Poly(x**2 - x - 1, x, domain='ZZ'), Poly(x**2 + x, x, domain='ZZ')]
default_assumptions = {'commutative': True}
deflate()[source]

Reduce degree of f by mapping x_i**m to y_i.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(x**6*y**2 + x**3 + 1, x, y).deflate()
((3, 2), Poly(x**2*y + x + 1, x, y, domain='ZZ'))
degree(gen=0)[source]

Returns degree of f in x_j.

The degree of 0 is negative infinity.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(x**2 + y*x + 1, x, y).degree()
2
>>> Poly(x**2 + y*x + y, x, y).degree(y)
1
>>> Poly(0, x).degree()
-oo
degree_list()[source]

Returns a list of degrees of f.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(x**2 + y*x + 1, x, y).degree_list()
(2, 1)
diff(*specs, **kwargs)[source]

Computes partial derivative of f.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(x**2 + 2*x + 1, x).diff()
Poly(2*x + 2, x, domain='ZZ')
>>> Poly(x*y**2 + x, x, y).diff((0, 0), (1, 1))
Poly(2*x*y, x, y, domain='ZZ')
discriminant()[source]

Computes the discriminant of f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 + 2*x + 3, x).discriminant()
-8
dispersion(g=None)[source]

Compute the dispersion of polynomials.

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

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

and for a single polynomial operatorname{dis}(f) := operatorname{dis}(f, f).

Examples

>>> from .. import poly
>>> from .dispersion import dispersion, dispersionset
>>> from ..abc import x

Dispersion set and dispersion of a simple polynomial:

>>> fp = poly((x - 3)*(x + 3), x)
>>> sorted(dispersionset(fp))
[0, 6]
>>> dispersion(fp)
6

Note that the definition of the dispersion is not symmetric:

>>> fp = poly(x**4 - 3*x**2 + 1, x)
>>> gp = fp.shift(-3)
>>> sorted(dispersionset(fp, gp))
[2, 3, 4]
>>> dispersion(fp, gp)
4
>>> sorted(dispersionset(gp, fp))
[]
>>> dispersion(gp, fp)
-oo

Computing the dispersion also works over field extensions:

>>> from .. import sqrt
>>> fp = poly(x**2 + sqrt(5)*x - 1, x, domain='QQ<sqrt(5)>')
>>> gp = poly(x**2 + (2 + sqrt(5))*x + sqrt(5), x, domain='QQ<sqrt(5)>')
>>> sorted(dispersionset(fp, gp))
[2]
>>> sorted(dispersionset(gp, fp))
[1, 4]

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

>>> from ..abc import a
>>> fp = poly(4*x**4 + (4*a + 8)*x**3 + (a**2 + 6*a + 4)*x**2 + (a**2 + 2*a)*x, x)
>>> sorted(dispersionset(fp))
[0, 1]

See also

dispersionset

References

  1. [ManWright94]

  2. [Koepf98]

  3. [Abramov71]

  4. [Man93]

dispersionset(g=None)[source]

Compute the dispersion set of two polynomials.

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

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

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

Examples

>>> from .. import poly
>>> from .dispersion import dispersion, dispersionset
>>> from ..abc import x

Dispersion set and dispersion of a simple polynomial:

>>> fp = poly((x - 3)*(x + 3), x)
>>> sorted(dispersionset(fp))
[0, 6]
>>> dispersion(fp)
6

Note that the definition of the dispersion is not symmetric:

>>> fp = poly(x**4 - 3*x**2 + 1, x)
>>> gp = fp.shift(-3)
>>> sorted(dispersionset(fp, gp))
[2, 3, 4]
>>> dispersion(fp, gp)
4
>>> sorted(dispersionset(gp, fp))
[]
>>> dispersion(gp, fp)
-oo

Computing the dispersion also works over field extensions:

>>> from .. import sqrt
>>> fp = poly(x**2 + sqrt(5)*x - 1, x, domain='QQ<sqrt(5)>')
>>> gp = poly(x**2 + (2 + sqrt(5))*x + sqrt(5), x, domain='QQ<sqrt(5)>')
>>> sorted(dispersionset(fp, gp))
[2]
>>> sorted(dispersionset(gp, fp))
[1, 4]

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

>>> from ..abc import a
>>> fp = poly(4*x**4 + (4*a + 8)*x**3 + (a**2 + 6*a + 4)*x**2 + (a**2 + 2*a)*x, x)
>>> sorted(dispersionset(fp))
[0, 1]

See also

dispersion

References

  1. [ManWright94]

  2. [Koepf98]

  3. [Abramov71]

  4. [Man93]

div(g, auto=True)[source]

Polynomial division with remainder of f by g.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 + 1, x).div(Poly(2*x - 4, x))
(Poly(1/2*x + 1, x, domain='QQ'), Poly(5, x, domain='QQ'))
>>> Poly(x**2 + 1, x).div(Poly(2*x - 4, x), auto=False)
(Poly(0, x, domain='ZZ'), Poly(x**2 + 1, x, domain='ZZ'))
property domain

Get the ground domain of self.

eject(*gens)[source]

Eject selected generators into the ground domain.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> f = Poly(x**2*y + x*y**3 + x*y + 1, x, y)
>>> f.eject(x)
Poly(x*y**3 + (x**2 + x)*y + 1, y, domain='ZZ[x]')
>>> f.eject(y)
Poly(y*x**2 + (y**3 + y)*x + 1, x, domain='ZZ[y]')
eq(g, strict=False)[source]
eval(x, a=None, auto=True)[source]

Evaluate f at a in the given variable.

Examples

>>> from .. import Poly
>>> from ..abc import x, y, z
>>> Poly(x**2 + 2*x + 3, x).eval(2)
11
>>> Poly(2*x*y + 3*x + y + 2, x, y).eval(x, 2)
Poly(5*y + 8, y, domain='ZZ')
>>> f = Poly(2*x*y + 3*x + y + 2*z, x, y, z)
>>> f.eval({x: 2})
Poly(5*y + 2*z + 6, y, z, domain='ZZ')
>>> f.eval({x: 2, y: 5})
Poly(2*z + 31, z, domain='ZZ')
>>> f.eval({x: 2, y: 5, z: 7})
45
>>> f.eval((2, 5))
Poly(2*z + 31, z, domain='ZZ')
>>> f(2, 5)
Poly(2*z + 31, z, domain='ZZ')
exclude()[source]

Remove unnecessary generators from f.

Examples

>>> from .. import Poly
>>> from ..abc import a, b, c, d, x
>>> Poly(a + x, a, b, c, d, x).exclude()
Poly(a + x, a, x, domain='ZZ')
exquo(g, auto=True)[source]

Computes polynomial exact quotient of f by g.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 - 1, x).exquo(Poly(x - 1, x))
Poly(x + 1, x, domain='ZZ')
>>> Poly(x**2 + 1, x).exquo(Poly(2*x - 4, x))
Traceback (most recent call last):
...
ExactQuotientFailed: 2*x - 4 does not divide x**2 + 1
exquo_ground(coeff)[source]

Exact quotient of f by a an element of the ground domain.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(2*x + 4).exquo_ground(2)
Poly(x + 2, x, domain='ZZ')
>>> Poly(2*x + 3).exquo_ground(2)
Traceback (most recent call last):
...
ExactQuotientFailed: 2 does not divide 3 in ZZ
factor_list()[source]

Returns a list of irreducible factors of f.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> f = 2*x**5 + 2*x**4*y + 4*x**3 + 4*x**2*y + 2*x + 2*y
>>> Poly(f).factor_list()
(2, [(Poly(x + y, x, y, domain='ZZ'), 1),
     (Poly(x**2 + 1, x, y, domain='ZZ'), 2)])
factor_list_include()[source]

Returns a list of irreducible factors of f.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> f = 2*x**5 + 2*x**4*y + 4*x**3 + 4*x**2*y + 2*x + 2*y
>>> Poly(f).factor_list_include()
[(Poly(2*x + 2*y, x, y, domain='ZZ'), 1),
 (Poly(x**2 + 1, x, y, domain='ZZ'), 2)]
property free_symbols

Free symbols of a polynomial expression.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(x**2 + 1).free_symbols
{x}
>>> Poly(x**2 + y).free_symbols
{x, y}
>>> Poly(x**2 + y, x).free_symbols
{x, y}
property free_symbols_in_domain

Free symbols of the domain of self.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(x**2 + 1).free_symbols_in_domain
set()
>>> Poly(x**2 + y).free_symbols_in_domain
set()
>>> Poly(x**2 + y, x).free_symbols_in_domain
{y}
classmethod from_dict(rep, *gens, **args)[source]

Construct a polynomial from a dict.

classmethod from_expr(rep, *gens, **args)[source]

Construct a polynomial from an expression.

classmethod from_list(rep, *gens, **args)[source]

Construct a polynomial from a list.

classmethod from_poly(rep, *gens, **args)[source]

Construct a polynomial from a polynomial.

gcd(g)[source]

Returns the polynomial GCD of f and g.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 - 1, x).gcd(Poly(x**2 - 3*x + 2, x))
Poly(x - 1, x, domain='ZZ')
gcdex(g, auto=True)[source]

Extended Euclidean algorithm of f and g.

Returns (s, t, h) such that h = gcd(f, g) and s*f + t*g = h.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> f = x**4 - 2*x**3 - 6*x**2 + 12*x + 15
>>> g = x**3 + x**2 - 4*x - 4
>>> Poly(f).gcdex(Poly(g))
(Poly(-1/5*x + 3/5, x, domain='QQ'),
 Poly(1/5*x**2 - 6/5*x + 2, x, domain='QQ'),
 Poly(x + 1, x, domain='QQ'))
property gen

Return the principal generator.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 + 1, x).gen
x
gens
get_domain()[source]

Get the ground domain of f.

get_modulus()[source]

Get the modulus of f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 + 1, modulus=2).get_modulus()
2
gff_list()[source]

Computes greatest factorial factorization of f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> f = x**5 + 2*x**4 - x**3 - 2*x**2
>>> Poly(f).gff_list()
[(Poly(x, x, domain='ZZ'), 1), (Poly(x + 2, x, domain='ZZ'), 4)]
ground_roots()[source]

Compute roots of f by factorization in the ground domain.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**6 - 4*x**4 + 4*x**3 - x**2).ground_roots()
{0: 2, 1: 2}
half_gcdex(g, auto=True)[source]

Half extended Euclidean algorithm of f and g.

Returns (s, h) such that h = gcd(f, g) and s*f = h (mod g).

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> f = x**4 - 2*x**3 - 6*x**2 + 12*x + 15
>>> g = x**3 + x**2 - 4*x - 4
>>> Poly(f).half_gcdex(Poly(g))
(Poly(-1/5*x + 3/5, x, domain='QQ'), Poly(x + 1, x, domain='QQ'))
has_only_gens(*gens)[source]

Return True if Poly(f, *gens) retains ground domain.

Examples

>>> from .. import Poly
>>> from ..abc import x, y, z
>>> Poly(x*y + 1, x, y, z).has_only_gens(x, y)
True
>>> Poly(x*y + z, x, y, z).has_only_gens(x, y)
False
homogeneous_order()[source]

Returns the homogeneous order of f.

A homogeneous polynomial is a polynomial whose all monomials with non-zero coefficients have the same total degree. This degree is the homogeneous order of f. If you only want to check if a polynomial is homogeneous, then use Poly.is_homogeneous().

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> f = Poly(x**5 + 2*x**3*y**2 + 9*x*y**4)
>>> f.homogeneous_order()
5
homogenize(s)[source]

Returns the homogeneous polynomial of f.

A homogeneous polynomial is a polynomial whose all monomials with non-zero coefficients have the same total degree. If you only want to check if a polynomial is homogeneous, then use Poly.is_homogeneous(). If you want not only to check if a polynomial is homogeneous but also compute its homogeneous order, then use Poly.homogeneous_order().

Examples

>>> from .. import Poly
>>> from ..abc import x, y, z
>>> f = Poly(x**5 + 2*x**2*y**2 + 9*x*y**3)
>>> f.homogenize(z)
Poly(x**5 + 2*x**2*y**2*z + 9*x*y**3*z, x, y, z, domain='ZZ')
inject(front=False)[source]

Inject ground domain generators into f.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> f = Poly(x**2*y + x*y**3 + x*y + 1, x)
>>> f.inject()
Poly(x**2*y + x*y**3 + x*y + 1, x, y, domain='ZZ')
>>> f.inject(front=True)
Poly(y**3*x + y*x**2 + y*x + 1, y, x, domain='ZZ')
integrate(*specs, **args)[source]

Computes indefinite integral of f.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(x**2 + 2*x + 1, x).integrate()
Poly(1/3*x**3 + x**2 + x, x, domain='QQ')
>>> Poly(x*y**2 + x, x, y).integrate((0, 1), (1, 0))
Poly(1/2*x**2*y**2 + 1/2*x**2, x, y, domain='QQ')
intervals(all=False, eps=None, inf=None, sup=None, fast=False, sqf=False)[source]

Compute isolating intervals for roots of f.

For real roots the Vincent-Akritas-Strzebonski (VAS) continued fractions method is used.

References:

1. Alkiviadis G. Akritas and Adam W. Strzebonski: A Comparative Study of Two Real Root Isolation Methods . Nonlinear Analysis: Modelling and Control, Vol. 10, No. 4, 297-304, 2005. 2. Alkiviadis G. Akritas, Adam W. Strzebonski and Panagiotis S. Vigklas: Improving the Performance of the Continued Fractions Method Using new Bounds of Positive Roots. Nonlinear Analysis: Modelling and Control, Vol. 13, No. 3, 265-279, 2008.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 - 3, x).intervals()
[((-2, -1), 1), ((1, 2), 1)]
>>> Poly(x**2 - 3, x).intervals(eps=1e-2)
[((-26/15, -19/11), 1), ((19/11, 26/15), 1)]
invert(g, auto=True)[source]

Invert f modulo g when possible.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 - 1, x).invert(Poly(2*x - 1, x))
Poly(-4/3, x, domain='QQ')
>>> Poly(x**2 - 1, x).invert(Poly(x - 1, x))
Traceback (most recent call last):
...
NotInvertible: zero divisor
is_Poly = True
is_commutative = True
property is_cyclotomic

Returns True if f is a cyclotomic polnomial.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> f = x**16 + x**14 - x**10 + x**8 - x**6 + x**2 + 1
>>> Poly(f).is_cyclotomic
False
>>> g = x**16 + x**14 - x**10 - x**8 - x**6 + x**2 + 1
>>> Poly(g).is_cyclotomic
True
property is_ground

Returns True if f is an element of the ground domain.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(x, x).is_ground
False
>>> Poly(2, x).is_ground
True
>>> Poly(y, x).is_ground
True
property is_homogeneous

Returns True if f is a homogeneous polynomial.

A homogeneous polynomial is a polynomial whose all monomials with non-zero coefficients have the same total degree. If you want not only to check if a polynomial is homogeneous but also compute its homogeneous order, then use Poly.homogeneous_order().

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(x**2 + x*y, x, y).is_homogeneous
True
>>> Poly(x**3 + x*y, x, y).is_homogeneous
False
property is_irreducible

Returns True if f has no factors over its domain.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 + x + 1, x, modulus=2).is_irreducible
True
>>> Poly(x**2 + 1, x, modulus=2).is_irreducible
False
property is_linear

Returns True if f is linear in all its variables.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(x + y + 2, x, y).is_linear
True
>>> Poly(x*y + 2, x, y).is_linear
False
property is_monic

Returns True if the leading coefficient of f is one.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x + 2, x).is_monic
True
>>> Poly(2*x + 2, x).is_monic
False
property is_monomial

Returns True if f is zero or has only one term.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(3*x**2, x).is_monomial
True
>>> Poly(3*x**2 + 1, x).is_monomial
False
property is_multivariate

Returns True if f is a multivariate polynomial.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(x**2 + x + 1, x).is_multivariate
False
>>> Poly(x*y**2 + x*y + 1, x, y).is_multivariate
True
>>> Poly(x*y**2 + x*y + 1, x).is_multivariate
False
>>> Poly(x**2 + x + 1, x, y).is_multivariate
True
property is_one

Returns True if f is a unit polynomial.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(0, x).is_one
False
>>> Poly(1, x).is_one
True
property is_primitive

Returns True if GCD of the coefficients of f is one.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(2*x**2 + 6*x + 12, x).is_primitive
False
>>> Poly(x**2 + 3*x + 6, x).is_primitive
True
property is_quadratic

Returns True if f is quadratic in all its variables.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(x*y + 2, x, y).is_quadratic
True
>>> Poly(x*y**2 + 2, x, y).is_quadratic
False
property is_sqf

Returns True if f is a square-free polynomial.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 - 2*x + 1, x).is_sqf
False
>>> Poly(x**2 - 1, x).is_sqf
True
property is_univariate

Returns True if f is a univariate polynomial.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(x**2 + x + 1, x).is_univariate
True
>>> Poly(x*y**2 + x*y + 1, x, y).is_univariate
False
>>> Poly(x*y**2 + x*y + 1, x).is_univariate
True
>>> Poly(x**2 + x + 1, x, y).is_univariate
False
property is_zero

Returns True if f is a zero polynomial.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(0, x).is_zero
True
>>> Poly(1, x).is_zero
False
l1_norm()[source]

Returns l1 norm of f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(-x**2 + 2*x - 3, x).l1_norm()
6
lcm(g)[source]

Returns polynomial LCM of f and g.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 - 1, x).lcm(Poly(x**2 - 3*x + 2, x))
Poly(x**3 - 2*x**2 - x + 2, x, domain='ZZ')
length()[source]

Returns the number of non-zero terms in f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 + 2*x - 1).length()
3
lift()[source]

Convert algebraic coefficients to rationals.

Examples

>>> from .. import Poly, I
>>> from ..abc import x
>>> Poly(x**2 + I*x + 1, x, extension=I).lift()
Poly(x**4 + 3*x**2 + 1, x, domain='QQ')
ltrim(gen)[source]

Remove dummy generators from the “left” of f.

Examples

>>> from .. import Poly
>>> from ..abc import x, y, z
>>> Poly(y**2 + y*z**2, x, y, z).ltrim(y)
Poly(y**2 + y*z**2, y, z, domain='ZZ')
max_norm()[source]

Returns maximum norm of f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(-x**2 + 2*x - 3, x).max_norm()
3
monic(auto=True)[source]

Divides all coefficients by LC(f).

Examples

>>> from .. import Poly, ZZ
>>> from ..abc import x
>>> Poly(3*x**2 + 6*x + 9, x, domain=ZZ).monic()
Poly(x**2 + 2*x + 3, x, domain='QQ')
>>> Poly(3*x**2 + 4*x + 2, x, domain=ZZ).monic()
Poly(x**2 + 4/3*x + 2/3, x, domain='QQ')
monoms(order=None)[source]

Returns all non-zero monomials from f in lex order.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(x**2 + 2*x*y**2 + x*y + 3*y, x, y).monoms()
[(2, 0), (1, 2), (1, 1), (0, 1)]

See also

all_monoms

mul(g)[source]

Multiply two polynomials f and g.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 + 1, x).mul(Poly(x - 2, x))
Poly(x**3 - 2*x**2 + x - 2, x, domain='ZZ')
>>> Poly(x**2 + 1, x)*Poly(x - 2, x)
Poly(x**3 - 2*x**2 + x - 2, x, domain='ZZ')
mul_ground(coeff)[source]

Multiply f by a an element of the ground domain.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x + 1).mul_ground(2)
Poly(2*x + 2, x, domain='ZZ')
ne(g, strict=False)[source]
neg()[source]

Negate all coefficients in f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 - 1, x).neg()
Poly(-x**2 + 1, x, domain='ZZ')
>>> -Poly(x**2 - 1, x)
Poly(-x**2 + 1, x, domain='ZZ')
classmethod new(rep, *gens)[source]

Construct Poly instance from raw representation.

nroots(n=15, maxsteps=50, cleanup=True)[source]

Compute numerical approximations of roots of f.

Parameters:
  • calculate (n ... the number of digits to) –

  • do (maxsteps ... the maximum number of iterations to) –

  • maxsteps (If the accuracy n cannot be reached in) –

  • an (it will raise) –

  • maxsteps. (exception. You need to rerun with higher) –

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 - 3).nroots(n=15)
[-1.73205080756888, 1.73205080756888]
>>> Poly(x**2 - 3).nroots(n=30)
[-1.73205080756887729352744634151, 1.73205080756887729352744634151]
nth(*N)[source]

Returns the n-th coefficient of f where N are the exponents of the generators in the term of interest.

Examples

>>> from .. import Poly, sqrt
>>> from ..abc import x, y
>>> Poly(x**3 + 2*x**2 + 3*x, x).nth(2)
2
>>> Poly(x**3 + 2*x*y**2 + y**2, x, y).nth(1, 2)
2
>>> Poly(4*sqrt(x)*y)
Poly(4*y*(sqrt(x)), y, sqrt(x), domain='ZZ')
>>> _.nth(1, 1)
4

See also

coeff_monomial

nth_power_roots_poly(n)[source]

Construct a polynomial with n-th powers of roots of f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> f = Poly(x**4 - x**2 + 1)
>>> f.nth_power_roots_poly(2)
Poly(x**4 - 2*x**3 + 3*x**2 - 2*x + 1, x, domain='ZZ')
>>> f.nth_power_roots_poly(3)
Poly(x**4 + 2*x**2 + 1, x, domain='ZZ')
>>> f.nth_power_roots_poly(4)
Poly(x**4 + 2*x**3 + 3*x**2 + 2*x + 1, x, domain='ZZ')
>>> f.nth_power_roots_poly(12)
Poly(x**4 - 4*x**3 + 6*x**2 - 4*x + 1, x, domain='ZZ')
property one

Return one polynomial with self’s properties.

pdiv(g)[source]

Polynomial pseudo-division of f by g.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 + 1, x).pdiv(Poly(2*x - 4, x))
(Poly(2*x + 4, x, domain='ZZ'), Poly(20, x, domain='ZZ'))
per(rep, gens=None, remove=None)[source]

Create a Poly out of the given representation.

Examples

>>> from .. import Poly, ZZ
>>> from ..abc import x, y
>>> from .polyclasses import DMP
>>> a = Poly(x**2 + 1)
>>> a.per(DMP([ZZ(1), ZZ(1)], ZZ), gens=[y])
Poly(y + 1, y, domain='ZZ')
pexquo(g)[source]

Polynomial exact pseudo-quotient of f by g.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 - 1, x).pexquo(Poly(2*x - 2, x))
Poly(2*x + 2, x, domain='ZZ')
>>> Poly(x**2 + 1, x).pexquo(Poly(2*x - 4, x))
Traceback (most recent call last):
...
ExactQuotientFailed: 2*x - 4 does not divide x**2 + 1
pow(n)[source]

Raise f to a non-negative power n.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x - 2, x).pow(3)
Poly(x**3 - 6*x**2 + 12*x - 8, x, domain='ZZ')
>>> Poly(x - 2, x)**3
Poly(x**3 - 6*x**2 + 12*x - 8, x, domain='ZZ')
pquo(g)[source]

Polynomial pseudo-quotient of f by g.

See the Caveat note in the function prem(f, g).

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 + 1, x).pquo(Poly(2*x - 4, x))
Poly(2*x + 4, x, domain='ZZ')
>>> Poly(x**2 - 1, x).pquo(Poly(2*x - 2, x))
Poly(2*x + 2, x, domain='ZZ')
prem(g)[source]

Polynomial pseudo-remainder of f by g.

Caveat: The function prem(f, g, x) can be safely used to compute

in Z[x] _only_ subresultant polynomial remainder sequences (prs’s).

To safely compute Euclidean and Sturmian prs’s in Z[x] employ anyone of the corresponding functions found in the module polys.subresultants_qq_zz. The functions in the module with suffix _pg compute prs’s in Z[x] employing rem(f, g, x), whereas the functions with suffix _amv compute prs’s in Z[x] employing rem_z(f, g, x).

The function rem_z(f, g, x) differs from prem(f, g, x) in that to compute the remainder polynomials in Z[x] it premultiplies the divident times the absolute value of the leading coefficient of the divisor raised to the power degree(f, x) - degree(g, x) + 1.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 + 1, x).prem(Poly(2*x - 4, x))
Poly(20, x, domain='ZZ')
primitive()[source]

Returns the content and a primitive form of f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(2*x**2 + 8*x + 12, x).primitive()
(2, Poly(x**2 + 4*x + 6, x, domain='ZZ'))
quo(g, auto=True)[source]

Computes polynomial quotient of f by g.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 + 1, x).quo(Poly(2*x - 4, x))
Poly(1/2*x + 1, x, domain='QQ')
>>> Poly(x**2 - 1, x).quo(Poly(x - 1, x))
Poly(x + 1, x, domain='ZZ')
quo_ground(coeff)[source]

Quotient of f by a an element of the ground domain.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(2*x + 4).quo_ground(2)
Poly(x + 2, x, domain='ZZ')
>>> Poly(2*x + 3).quo_ground(2)
Poly(x + 1, x, domain='ZZ')
rat_clear_denoms(g)[source]

Clear denominators in a rational function f/g.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> f = Poly(x**2/y + 1, x)
>>> g = Poly(x**3 + y, x)
>>> p, q = f.rat_clear_denoms(g)
>>> p
Poly(x**2 + y, x, domain='ZZ[y]')
>>> q
Poly(y*x**3 + y**2, x, domain='ZZ[y]')
real_roots(multiple=True, radicals=True)[source]

Return a list of real roots with multiplicities.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(2*x**3 - 7*x**2 + 4*x + 4).real_roots()
[-1/2, 2, 2]
>>> Poly(x**3 + x + 1).real_roots()
[CRootOf(x**3 + x + 1, 0)]
refine_root(s, t, eps=None, steps=None, fast=False, check_sqf=False)[source]

Refine an isolating interval of a root to the given precision.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 - 3, x).refine_root(1, 2, eps=1e-2)
(19/11, 26/15)
rem(g, auto=True)[source]

Computes the polynomial remainder of f by g.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 + 1, x).rem(Poly(2*x - 4, x))
Poly(5, x, domain='ZZ')
>>> Poly(x**2 + 1, x).rem(Poly(2*x - 4, x), auto=False)
Poly(x**2 + 1, x, domain='ZZ')
reorder(*gens, **args)[source]

Efficiently apply new order of generators.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(x**2 + x*y**2, x, y).reorder(y, x)
Poly(y**2*x + x**2, y, x, domain='ZZ')
rep
replace(x, y=None)[source]

Replace x with y in generators list.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(x**2 + 1, x).replace(x, y)
Poly(y**2 + 1, y, domain='ZZ')
resultant(g, includePRS=False)[source]

Computes the resultant of f and g via PRS.

If includePRS=True, it includes the subresultant PRS in the result. Because the PRS is used to calculate the resultant, this is more efficient than calling subresultants() separately.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> f = Poly(x**2 + 1, x)
>>> f.resultant(Poly(x**2 - 1, x))
4
>>> f.resultant(Poly(x**2 - 1, x), includePRS=True)
(4, [Poly(x**2 + 1, x, domain='ZZ'), Poly(x**2 - 1, x, domain='ZZ'),
     Poly(-2, x, domain='ZZ')])
retract(field=None)[source]

Recalculate the ground domain of a polynomial.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> f = Poly(x**2 + 1, x, domain='QQ[y]')
>>> f
Poly(x**2 + 1, x, domain='QQ[y]')
>>> f.retract()
Poly(x**2 + 1, x, domain='ZZ')
>>> f.retract(field=True)
Poly(x**2 + 1, x, domain='QQ')
revert(n)[source]

Compute f**(-1) mod x**n.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(1, x).revert(2)
Poly(1, x, domain='ZZ')
>>> Poly(1 + x, x).revert(1)
Poly(1, x, domain='ZZ')
>>> Poly(x**2 - 1, x).revert(1)
Traceback (most recent call last):
...
NotReversible: only unity is reversible in a ring
>>> Poly(1/x, x).revert(1)
Traceback (most recent call last):
...
PolynomialError: 1/x contains an element of the generators set
root(index, radicals=True)[source]

Get an indexed root of a polynomial.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> f = Poly(2*x**3 - 7*x**2 + 4*x + 4)
>>> f.root(0)
-1/2
>>> f.root(1)
2
>>> f.root(2)
2
>>> f.root(3)
Traceback (most recent call last):
...
IndexError: root index out of [-3, 2] range, got 3
>>> Poly(x**5 + x + 1).root(0)
CRootOf(x**3 - x**2 + 1, 0)
set_domain(domain)[source]

Set the ground domain of f.

set_modulus(modulus)[source]

Set the modulus of f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(5*x**2 + 2*x - 1, x).set_modulus(2)
Poly(x**2 + 1, x, modulus=2)
shift(a)[source]

Efficiently compute Taylor shift f(x + a).

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 - 2*x + 1, x).shift(2)
Poly(x**2 + 2*x + 1, x, domain='ZZ')
slice(x, m, n=None)[source]

Take a continuous subsequence of terms of f.

sqf_list(all=False)[source]

Returns a list of square-free factors of f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> f = 2*x**5 + 16*x**4 + 50*x**3 + 76*x**2 + 56*x + 16
>>> Poly(f).sqf_list()
(2, [(Poly(x + 1, x, domain='ZZ'), 2),
     (Poly(x + 2, x, domain='ZZ'), 3)])
>>> Poly(f).sqf_list(all=True)
(2, [(Poly(1, x, domain='ZZ'), 1),
     (Poly(x + 1, x, domain='ZZ'), 2),
     (Poly(x + 2, x, domain='ZZ'), 3)])
sqf_list_include(all=False)[source]

Returns a list of square-free factors of f.

Examples

>>> from .. import Poly, expand
>>> from ..abc import x
>>> f = expand(2*(x + 1)**3*x**4)
>>> f
2*x**7 + 6*x**6 + 6*x**5 + 2*x**4
>>> Poly(f).sqf_list_include()
[(Poly(2, x, domain='ZZ'), 1),
 (Poly(x + 1, x, domain='ZZ'), 3),
 (Poly(x, x, domain='ZZ'), 4)]
>>> Poly(f).sqf_list_include(all=True)
[(Poly(2, x, domain='ZZ'), 1),
 (Poly(1, x, domain='ZZ'), 2),
 (Poly(x + 1, x, domain='ZZ'), 3),
 (Poly(x, x, domain='ZZ'), 4)]
sqf_norm()[source]

Computes square-free norm of f.

Returns s, f, r, such that g(x) = f(x-sa) and r(x) = Norm(g(x)) is a square-free polynomial over K, where a is the algebraic extension of the ground domain.

Examples

>>> from .. import Poly, sqrt
>>> from ..abc import x
>>> s, f, r = Poly(x**2 + 1, x, extension=[sqrt(3)]).sqf_norm()
>>> s
1
>>> f
Poly(x**2 - 2*sqrt(3)*x + 4, x, domain='QQ<sqrt(3)>')
>>> r
Poly(x**4 - 4*x**2 + 16, x, domain='QQ')
sqf_part()[source]

Computes square-free part of f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**3 - 3*x - 2, x).sqf_part()
Poly(x**2 - x - 2, x, domain='ZZ')
sqr()[source]

Square a polynomial f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x - 2, x).sqr()
Poly(x**2 - 4*x + 4, x, domain='ZZ')
>>> Poly(x - 2, x)**2
Poly(x**2 - 4*x + 4, x, domain='ZZ')
sturm(auto=True)[source]

Computes the Sturm sequence of f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**3 - 2*x**2 + x - 3, x).sturm()
[Poly(x**3 - 2*x**2 + x - 3, x, domain='QQ'),
 Poly(3*x**2 - 4*x + 1, x, domain='QQ'),
 Poly(2/9*x + 25/9, x, domain='QQ'),
 Poly(-2079/4, x, domain='QQ')]
sub(g)[source]

Subtract two polynomials f and g.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 + 1, x).sub(Poly(x - 2, x))
Poly(x**2 - x + 3, x, domain='ZZ')
>>> Poly(x**2 + 1, x) - Poly(x - 2, x)
Poly(x**2 - x + 3, x, domain='ZZ')
sub_ground(coeff)[source]

Subtract an element of the ground domain from f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x + 1).sub_ground(2)
Poly(x - 1, x, domain='ZZ')
subresultants(g)[source]

Computes the subresultant PRS of f and g.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 + 1, x).subresultants(Poly(x**2 - 1, x))
[Poly(x**2 + 1, x, domain='ZZ'),
 Poly(x**2 - 1, x, domain='ZZ'),
 Poly(-2, x, domain='ZZ')]
terms(order=None)[source]

Returns all non-zero terms from f in lex order.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(x**2 + 2*x*y**2 + x*y + 3*y, x, y).terms()
[((2, 0), 1), ((1, 2), 2), ((1, 1), 1), ((0, 1), 3)]

See also

all_terms

terms_gcd()[source]

Remove GCD of terms from the polynomial f.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(x**6*y**2 + x**3*y, x, y).terms_gcd()
((3, 1), Poly(x**3*y + 1, x, y, domain='ZZ'))
termwise(func, *gens, **args)[source]

Apply a function to all terms of f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> def func(k, coeff):
...     k = k[0]
...     return coeff//10**(2-k)
>>> Poly(x**2 + 20*x + 400).termwise(func)
Poly(x**2 + 2*x + 4, x, domain='ZZ')
to_exact()[source]

Make the ground domain exact.

Examples

>>> from .. import Poly, RR
>>> from ..abc import x
>>> Poly(x**2 + 1.0, x, domain=RR).to_exact()
Poly(x**2 + 1, x, domain='QQ')
to_field()[source]

Make the ground domain a field.

Examples

>>> from .. import Poly, ZZ
>>> from ..abc import x
>>> Poly(x**2 + 1, x, domain=ZZ).to_field()
Poly(x**2 + 1, x, domain='QQ')
to_ring()[source]

Make the ground domain a ring.

Examples

>>> from .. import Poly, QQ
>>> from ..abc import x
>>> Poly(x**2 + 1, domain=QQ).to_ring()
Poly(x**2 + 1, x, domain='ZZ')
total_degree()[source]

Returns the total degree of f.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(x**2 + y*x + 1, x, y).total_degree()
2
>>> Poly(x + y**5, x, y).total_degree()
5
transform(p, q)[source]

Efficiently evaluate the functional transformation q**n * f(p/q).

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 - 2*x + 1, x).transform(Poly(x + 1, x), Poly(x - 1, x))
Poly(4, x, domain='ZZ')
trunc(p)[source]

Reduce f modulo a constant p.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(2*x**3 + 3*x**2 + 5*x + 7, x).trunc(3)
Poly(-x**3 - x + 1, x, domain='ZZ')
unify(g)[source]

Make f and g belong to the same domain.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> f, g = Poly(x/2 + 1), Poly(2*x + 1)
>>> f
Poly(1/2*x + 1, x, domain='QQ')
>>> g
Poly(2*x + 1, x, domain='ZZ')
>>> F, G = f.unify(g)
>>> F
Poly(1/2*x + 1, x, domain='QQ')
>>> G
Poly(2*x + 1, x, domain='QQ')
property unit

Return unit polynomial with self’s properties.

property zero

Return zero polynomial with self’s properties.

class modelparameters.sympy.polys.polytools.PurePoly(rep, *gens, **args)[source]

Bases: Poly

Class for representing pure polynomials.

default_assumptions = {'commutative': True}
property free_symbols

Free symbols of a polynomial.

Examples

>>> from .. import PurePoly
>>> from ..abc import x, y
>>> PurePoly(x**2 + 1).free_symbols
set()
>>> PurePoly(x**2 + y).free_symbols
set()
>>> PurePoly(x**2 + y, x).free_symbols
{y}
gens
is_commutative = True
rep
modelparameters.sympy.polys.polytools.cancel(f, *gens, **args)[source]

Cancel common factors in a rational function f.

Examples

>>> from .. import cancel, sqrt, Symbol
>>> from ..abc import x
>>> A = Symbol('A', commutative=False)
>>> cancel((2*x**2 - 2)/(x**2 - 2*x + 1))
(2*x + 2)/(x - 1)
>>> cancel((sqrt(3) + sqrt(15)*A)/(sqrt(2) + sqrt(10)*A))
sqrt(6)/2
modelparameters.sympy.polys.polytools.cofactors(f, g, *gens, **args)[source]

Compute GCD and cofactors of f and g.

Returns polynomials (h, cff, cfg) such that h = gcd(f, g), and cff = quo(f, h) and cfg = quo(g, h) are, so called, cofactors of f and g.

Examples

>>> from .. import cofactors
>>> from ..abc import x
>>> cofactors(x**2 - 1, x**2 - 3*x + 2)
(x - 1, x + 1, x - 2)
modelparameters.sympy.polys.polytools.compose(f, g, *gens, **args)[source]

Compute functional composition f(g).

Examples

>>> from .. import compose
>>> from ..abc import x
>>> compose(x**2 + x, x - 1)
x**2 - x
modelparameters.sympy.polys.polytools.content(f, *gens, **args)[source]

Compute GCD of coefficients of f.

Examples

>>> from .. import content
>>> from ..abc import x
>>> content(6*x**2 + 8*x + 12)
2
modelparameters.sympy.polys.polytools.count_roots(f, inf=None, sup=None)[source]

Return the number of roots of f in [inf, sup] interval.

If one of inf or sup is complex, it will return the number of roots in the complex rectangle with corners at inf and sup.

Examples

>>> from .. import count_roots, I
>>> from ..abc import x
>>> count_roots(x**4 - 4, -3, 3)
2
>>> count_roots(x**4 - 4, 0, 1 + 3*I)
1
modelparameters.sympy.polys.polytools.decompose(f, *gens, **args)[source]

Compute functional decomposition of f.

Examples

>>> from .. import decompose
>>> from ..abc import x
>>> decompose(x**4 + 2*x**3 - x - 1)
[x**2 - x - 1, x**2 + x]
modelparameters.sympy.polys.polytools.degree(f, *gens, **args)[source]

Return the degree of f in the given variable.

The degree of 0 is negative infinity.

Examples

>>> from .. import degree
>>> from ..abc import x, y
>>> degree(x**2 + y*x + 1, gen=x)
2
>>> degree(x**2 + y*x + 1, gen=y)
1
>>> degree(0, x)
-oo
modelparameters.sympy.polys.polytools.degree_list(f, *gens, **args)[source]

Return a list of degrees of f in all variables.

Examples

>>> from .. import degree_list
>>> from ..abc import x, y
>>> degree_list(x**2 + y*x + 1)
(2, 1)
modelparameters.sympy.polys.polytools.discriminant(f, *gens, **args)[source]

Compute discriminant of f.

Examples

>>> from .. import discriminant
>>> from ..abc import x
>>> discriminant(x**2 + 2*x + 3)
-8
modelparameters.sympy.polys.polytools.div(f, g, *gens, **args)[source]

Compute polynomial division of f and g.

Examples

>>> from .. import div, ZZ, QQ
>>> from ..abc import x
>>> div(x**2 + 1, 2*x - 4, domain=ZZ)
(0, x**2 + 1)
>>> div(x**2 + 1, 2*x - 4, domain=QQ)
(x/2 + 1, 5)
modelparameters.sympy.polys.polytools.exquo(f, g, *gens, **args)[source]

Compute polynomial exact quotient of f and g.

Examples

>>> from .. import exquo
>>> from ..abc import x
>>> exquo(x**2 - 1, x - 1)
x + 1
>>> exquo(x**2 + 1, 2*x - 4)
Traceback (most recent call last):
...
ExactQuotientFailed: 2*x - 4 does not divide x**2 + 1
modelparameters.sympy.polys.polytools.factor(f, *gens, **args)[source]

Compute the factorization of expression, f, into irreducibles. (To factor an integer into primes, use factorint.)

There two modes implemented: symbolic and formal. If f is not an instance of Poly and generators are not specified, then the former mode is used. Otherwise, the formal mode is used.

In symbolic mode, factor() will traverse the expression tree and factor its components without any prior expansion, unless an instance of Add is encountered (in this case formal factorization is used). This way factor() can handle large or symbolic exponents.

By default, the factorization is computed over the rationals. To factor over other domain, e.g. an algebraic or finite field, use appropriate options: extension, modulus or domain.

Examples

>>> from .. import factor, sqrt
>>> from ..abc import x, y
>>> factor(2*x**5 + 2*x**4*y + 4*x**3 + 4*x**2*y + 2*x + 2*y)
2*(x + y)*(x**2 + 1)**2
>>> factor(x**2 + 1)
x**2 + 1
>>> factor(x**2 + 1, modulus=2)
(x + 1)**2
>>> factor(x**2 + 1, gaussian=True)
(x - I)*(x + I)
>>> factor(x**2 - 2, extension=sqrt(2))
(x - sqrt(2))*(x + sqrt(2))
>>> factor((x**2 - 1)/(x**2 + 4*x + 4))
(x - 1)*(x + 1)/(x + 2)**2
>>> factor((x**2 + 4*x + 4)**10000000*(x**2 + 1))
(x + 2)**20000000*(x**2 + 1)

By default, factor deals with an expression as a whole:

>>> eq = 2**(x**2 + 2*x + 1)
>>> factor(eq)
2**(x**2 + 2*x + 1)

If the deep flag is True then subexpressions will be factored:

>>> factor(eq, deep=True)
2**((x + 1)**2)

See also

sympy.ntheory.factor_.factorint

modelparameters.sympy.polys.polytools.factor_list(f, *gens, **args)[source]

Compute a list of irreducible factors of f.

Examples

>>> from .. import factor_list
>>> from ..abc import x, y
>>> factor_list(2*x**5 + 2*x**4*y + 4*x**3 + 4*x**2*y + 2*x + 2*y)
(2, [(x + y, 1), (x**2 + 1, 2)])
modelparameters.sympy.polys.polytools.gcd(f, g=None, *gens, **args)[source]

Compute GCD of f and g.

Examples

>>> from .. import gcd
>>> from ..abc import x
>>> gcd(x**2 - 1, x**2 - 3*x + 2)
x - 1
modelparameters.sympy.polys.polytools.gcd_list(seq, *gens, **args)[source]

Compute GCD of a list of polynomials.

Examples

>>> from .. import gcd_list
>>> from ..abc import x
>>> gcd_list([x**3 - 1, x**2 - 1, x**2 - 3*x + 2])
x - 1
modelparameters.sympy.polys.polytools.gcdex(f, g, *gens, **args)[source]

Extended Euclidean algorithm of f and g.

Returns (s, t, h) such that h = gcd(f, g) and s*f + t*g = h.

Examples

>>> from .. import gcdex
>>> from ..abc import x
>>> gcdex(x**4 - 2*x**3 - 6*x**2 + 12*x + 15, x**3 + x**2 - 4*x - 4)
(-x/5 + 3/5, x**2/5 - 6*x/5 + 2, x + 1)
modelparameters.sympy.polys.polytools.gff(f, *gens, **args)[source]

Compute greatest factorial factorization of f.

modelparameters.sympy.polys.polytools.gff_list(f, *gens, **args)[source]

Compute a list of greatest factorial factors of f.

Note that the input to ff() and rf() should be Poly instances to use the definitions here.

Examples

>>> from .. import gff_list, ff, Poly
>>> from ..abc import x
>>> f = Poly(x**5 + 2*x**4 - x**3 - 2*x**2, x)
>>> gff_list(f)
[(Poly(x, x, domain='ZZ'), 1), (Poly(x + 2, x, domain='ZZ'), 4)]
>>> (ff(Poly(x), 1)*ff(Poly(x + 2), 4)).expand() == f
True
>>> f = Poly(x**12 + 6*x**11 - 11*x**10 - 56*x**9 + 220*x**8 + 208*x**7 -         1401*x**6 + 1090*x**5 + 2715*x**4 - 6720*x**3 - 1092*x**2 + 5040*x, x)
>>> gff_list(f)
[(Poly(x**3 + 7, x, domain='ZZ'), 2), (Poly(x**2 + 5*x, x, domain='ZZ'), 3)]
>>> ff(Poly(x**3 + 7, x), 2)*ff(Poly(x**2 + 5*x, x), 3) == f
True
modelparameters.sympy.polys.polytools.groebner(F, *gens, **args)[source]

Computes the reduced Groebner basis for a set of polynomials.

Use the order argument to set the monomial ordering that will be used to compute the basis. Allowed orders are lex, grlex and grevlex. If no order is specified, it defaults to lex.

For more information on Groebner bases, see the references and the docstring of solve_poly_system().

Examples

Example taken from [1].

>>> from .. import groebner
>>> from ..abc import x, y
>>> F = [x*y - 2*y, 2*y**2 - x**2]
>>> groebner(F, x, y, order='lex')
GroebnerBasis([x**2 - 2*y**2, x*y - 2*y, y**3 - 2*y], x, y,
              domain='ZZ', order='lex')
>>> groebner(F, x, y, order='grlex')
GroebnerBasis([y**3 - 2*y, x**2 - 2*y**2, x*y - 2*y], x, y,
              domain='ZZ', order='grlex')
>>> groebner(F, x, y, order='grevlex')
GroebnerBasis([y**3 - 2*y, x**2 - 2*y**2, x*y - 2*y], x, y,
              domain='ZZ', order='grevlex')

By default, an improved implementation of the Buchberger algorithm is used. Optionally, an implementation of the F5B algorithm can be used. The algorithm can be set using method flag or with the setup() function from polys.polyconfig:

>>> F = [x**2 - x - 1, (2*x - 1) * y - (x**10 - (1 - x)**10)]
>>> groebner(F, x, y, method='buchberger')
GroebnerBasis([x**2 - x - 1, y - 55], x, y, domain='ZZ', order='lex')
>>> groebner(F, x, y, method='f5b')
GroebnerBasis([x**2 - x - 1, y - 55], x, y, domain='ZZ', order='lex')

References

  1. [Buchberger01]

  2. [Cox97]

modelparameters.sympy.polys.polytools.ground_roots(f, *gens, **args)[source]

Compute roots of f by factorization in the ground domain.

Examples

>>> from .. import ground_roots
>>> from ..abc import x
>>> ground_roots(x**6 - 4*x**4 + 4*x**3 - x**2)
{0: 2, 1: 2}
modelparameters.sympy.polys.polytools.half_gcdex(f, g, *gens, **args)[source]

Half extended Euclidean algorithm of f and g.

Returns (s, h) such that h = gcd(f, g) and s*f = h (mod g).

Examples

>>> from .. import half_gcdex
>>> from ..abc import x
>>> half_gcdex(x**4 - 2*x**3 - 6*x**2 + 12*x + 15, x**3 + x**2 - 4*x - 4)
(-x/5 + 3/5, x + 1)
modelparameters.sympy.polys.polytools.intervals(F, all=False, eps=None, inf=None, sup=None, strict=False, fast=False, sqf=False)[source]

Compute isolating intervals for roots of f.

Examples

>>> from .. import intervals
>>> from ..abc import x
>>> intervals(x**2 - 3)
[((-2, -1), 1), ((1, 2), 1)]
>>> intervals(x**2 - 3, eps=1e-2)
[((-26/15, -19/11), 1), ((19/11, 26/15), 1)]
modelparameters.sympy.polys.polytools.invert(f, g, *gens, **args)[source]

Invert f modulo g when possible.

Examples

>>> from .. import invert, S
>>> from ..core.numbers import mod_inverse
>>> from ..abc import x
>>> invert(x**2 - 1, 2*x - 1)
-4/3
>>> invert(x**2 - 1, x - 1)
Traceback (most recent call last):
...
NotInvertible: zero divisor

For more efficient inversion of Rationals, use the mod_inverse function:

>>> mod_inverse(3, 5)
2
>>> (S(2)/5).invert(S(7)/3)
5/2

See also

sympy.core.numbers.mod_inverse

modelparameters.sympy.polys.polytools.is_zero_dimensional(F, *gens, **args)[source]

Checks if the ideal generated by a Groebner basis is zero-dimensional.

The algorithm checks if the set of monomials not divisible by the leading monomial of any element of F is bounded.

References

David A. Cox, John B. Little, Donal O’Shea. Ideals, Varieties and Algorithms, 3rd edition, p. 230

modelparameters.sympy.polys.polytools.lcm(f, g=None, *gens, **args)[source]

Compute LCM of f and g.

Examples

>>> from .. import lcm
>>> from ..abc import x
>>> lcm(x**2 - 1, x**2 - 3*x + 2)
x**3 - 2*x**2 - x + 2
modelparameters.sympy.polys.polytools.lcm_list(seq, *gens, **args)[source]

Compute LCM of a list of polynomials.

Examples

>>> from .. import lcm_list
>>> from ..abc import x
>>> lcm_list([x**3 - 1, x**2 - 1, x**2 - 3*x + 2])
x**5 - x**4 - 2*x**3 - x**2 + x + 2
modelparameters.sympy.polys.polytools.monic(f, *gens, **args)[source]

Divide all coefficients of f by LC(f).

Examples

>>> from .. import monic
>>> from ..abc import x
>>> monic(3*x**2 + 4*x + 2)
x**2 + 4*x/3 + 2/3
modelparameters.sympy.polys.polytools.nroots(f, n=15, maxsteps=50, cleanup=True)[source]

Compute numerical approximations of roots of f.

Examples

>>> from .. import nroots
>>> from ..abc import x
>>> nroots(x**2 - 3, n=15)
[-1.73205080756888, 1.73205080756888]
>>> nroots(x**2 - 3, n=30)
[-1.73205080756887729352744634151, 1.73205080756887729352744634151]
modelparameters.sympy.polys.polytools.nth_power_roots_poly(f, n, *gens, **args)[source]

Construct a polynomial with n-th powers of roots of f.

Examples

>>> from .. import nth_power_roots_poly, factor, roots
>>> from ..abc import x
>>> f = x**4 - x**2 + 1
>>> g = factor(nth_power_roots_poly(f, 2))
>>> g
(x**2 - x + 1)**2
>>> R_f = [ (r**2).expand() for r in roots(f) ]
>>> R_g = roots(g).keys()
>>> set(R_f) == set(R_g)
True
modelparameters.sympy.polys.polytools.parallel_poly_from_expr(exprs, *gens, **args)[source]

Construct polynomials from expressions.

modelparameters.sympy.polys.polytools.pdiv(f, g, *gens, **args)[source]

Compute polynomial pseudo-division of f and g.

Examples

>>> from .. import pdiv
>>> from ..abc import x
>>> pdiv(x**2 + 1, 2*x - 4)
(2*x + 4, 20)
modelparameters.sympy.polys.polytools.pexquo(f, g, *gens, **args)[source]

Compute polynomial exact pseudo-quotient of f and g.

Examples

>>> from .. import pexquo
>>> from ..abc import x
>>> pexquo(x**2 - 1, 2*x - 2)
2*x + 2
>>> pexquo(x**2 + 1, 2*x - 4)
Traceback (most recent call last):
...
ExactQuotientFailed: 2*x - 4 does not divide x**2 + 1
modelparameters.sympy.polys.polytools.poly(expr, *gens, **args)[source]

Efficiently transform an expression into a polynomial.

Examples

>>> from .. import poly
>>> from ..abc import x
>>> poly(x*(x**2 + x - 1)**2)
Poly(x**5 + 2*x**4 - x**3 - 2*x**2 + x, x, domain='ZZ')
modelparameters.sympy.polys.polytools.poly_from_expr(expr, *gens, **args)[source]

Construct a polynomial from an expression.

modelparameters.sympy.polys.polytools.pquo(f, g, *gens, **args)[source]

Compute polynomial pseudo-quotient of f and g.

Examples

>>> from .. import pquo
>>> from ..abc import x
>>> pquo(x**2 + 1, 2*x - 4)
2*x + 4
>>> pquo(x**2 - 1, 2*x - 1)
2*x + 1
modelparameters.sympy.polys.polytools.prem(f, g, *gens, **args)[source]

Compute polynomial pseudo-remainder of f and g.

Examples

>>> from .. import prem
>>> from ..abc import x
>>> prem(x**2 + 1, 2*x - 4)
20
modelparameters.sympy.polys.polytools.primitive(f, *gens, **args)[source]

Compute content and the primitive form of f.

Examples

>>> from .polytools import primitive
>>> from ..abc import x
>>> primitive(6*x**2 + 8*x + 12)
(2, 3*x**2 + 4*x + 6)
>>> eq = (2 + 2*x)*x + 2

Expansion is performed by default:

>>> primitive(eq)
(2, x**2 + x + 1)

Set expand to False to shut this off. Note that the extraction will not be recursive; use the as_content_primitive method for recursive, non-destructive Rational extraction.

>>> primitive(eq, expand=False)
(1, x*(2*x + 2) + 2)
>>> eq.as_content_primitive()
(2, x*(x + 1) + 1)
modelparameters.sympy.polys.polytools.quo(f, g, *gens, **args)[source]

Compute polynomial quotient of f and g.

Examples

>>> from .. import quo
>>> from ..abc import x
>>> quo(x**2 + 1, 2*x - 4)
x/2 + 1
>>> quo(x**2 - 1, x - 1)
x + 1
modelparameters.sympy.polys.polytools.real_roots(f, multiple=True)[source]

Return a list of real roots with multiplicities of f.

Examples

>>> from .. import real_roots
>>> from ..abc import x
>>> real_roots(2*x**3 - 7*x**2 + 4*x + 4)
[-1/2, 2, 2]
modelparameters.sympy.polys.polytools.reduced(f, G, *gens, **args)[source]

Reduces a polynomial f modulo a set of polynomials G.

Given a polynomial f and a set of polynomials G = (g_1, ..., g_n), computes a set of quotients q = (q_1, ..., q_n) and the remainder r such that f = q_1*g_1 + ... + q_n*g_n + r, where r vanishes or r is a completely reduced polynomial with respect to G.

Examples

>>> from .. import reduced
>>> from ..abc import x, y
>>> reduced(2*x**4 + y**2 - x**2 + y**3, [x**3 - x, y**3 - y])
([2*x, 1], x**2 + y**2 + y)
modelparameters.sympy.polys.polytools.refine_root(f, s, t, eps=None, steps=None, fast=False, check_sqf=False)[source]

Refine an isolating interval of a root to the given precision.

Examples

>>> from .. import refine_root
>>> from ..abc import x
>>> refine_root(x**2 - 3, 1, 2, eps=1e-2)
(19/11, 26/15)
modelparameters.sympy.polys.polytools.rem(f, g, *gens, **args)[source]

Compute polynomial remainder of f and g.

Examples

>>> from .. import rem, ZZ, QQ
>>> from ..abc import x
>>> rem(x**2 + 1, 2*x - 4, domain=ZZ)
x**2 + 1
>>> rem(x**2 + 1, 2*x - 4, domain=QQ)
5
modelparameters.sympy.polys.polytools.resultant(f, g, *gens, **args)[source]

Compute resultant of f and g.

Examples

>>> from .. import resultant
>>> from ..abc import x
>>> resultant(x**2 + 1, x**2 - 1)
4
modelparameters.sympy.polys.polytools.sqf(f, *gens, **args)[source]

Compute square-free factorization of f.

Examples

>>> from .. import sqf
>>> from ..abc import x
>>> sqf(2*x**5 + 16*x**4 + 50*x**3 + 76*x**2 + 56*x + 16)
2*(x + 1)**2*(x + 2)**3
modelparameters.sympy.polys.polytools.sqf_list(f, *gens, **args)[source]

Compute a list of square-free factors of f.

Examples

>>> from .. import sqf_list
>>> from ..abc import x
>>> sqf_list(2*x**5 + 16*x**4 + 50*x**3 + 76*x**2 + 56*x + 16)
(2, [(x + 1, 2), (x + 2, 3)])
modelparameters.sympy.polys.polytools.sqf_norm(f, *gens, **args)[source]

Compute square-free norm of f.

Returns s, f, r, such that g(x) = f(x-sa) and r(x) = Norm(g(x)) is a square-free polynomial over K, where a is the algebraic extension of the ground domain.

Examples

>>> from .. import sqf_norm, sqrt
>>> from ..abc import x
>>> sqf_norm(x**2 + 1, extension=[sqrt(3)])
(1, x**2 - 2*sqrt(3)*x + 4, x**4 - 4*x**2 + 16)
modelparameters.sympy.polys.polytools.sqf_part(f, *gens, **args)[source]

Compute square-free part of f.

Examples

>>> from .. import sqf_part
>>> from ..abc import x
>>> sqf_part(x**3 - 3*x - 2)
x**2 - x - 2
modelparameters.sympy.polys.polytools.sturm(f, *gens, **args)[source]

Compute Sturm sequence of f.

Examples

>>> from .. import sturm
>>> from ..abc import x
>>> sturm(x**3 - 2*x**2 + x - 3)
[x**3 - 2*x**2 + x - 3, 3*x**2 - 4*x + 1, 2*x/9 + 25/9, -2079/4]
modelparameters.sympy.polys.polytools.subresultants(f, g, *gens, **args)[source]

Compute subresultant PRS of f and g.

Examples

>>> from .. import subresultants
>>> from ..abc import x
>>> subresultants(x**2 + 1, x**2 - 1)
[x**2 + 1, x**2 - 1, -2]
modelparameters.sympy.polys.polytools.terms_gcd(f, *gens, **args)[source]

Remove GCD of terms from f.

If the deep flag is True, then the arguments of f will have terms_gcd applied to them.

If a fraction is factored out of f and f is an Add, then an unevaluated Mul will be returned so that automatic simplification does not redistribute it. The hint clear, when set to False, can be used to prevent such factoring when all coefficients are not fractions.

Examples

>>> from .. import terms_gcd, cos
>>> from ..abc import x, y
>>> terms_gcd(x**6*y**2 + x**3*y, x, y)
x**3*y*(x**3*y + 1)

The default action of polys routines is to expand the expression given to them. terms_gcd follows this behavior:

>>> terms_gcd((3+3*x)*(x+x*y))
3*x*(x*y + x + y + 1)

If this is not desired then the hint expand can be set to False. In this case the expression will be treated as though it were comprised of one or more terms:

>>> terms_gcd((3+3*x)*(x+x*y), expand=False)
(3*x + 3)*(x*y + x)

In order to traverse factors of a Mul or the arguments of other functions, the deep hint can be used:

>>> terms_gcd((3 + 3*x)*(x + x*y), expand=False, deep=True)
3*x*(x + 1)*(y + 1)
>>> terms_gcd(cos(x + x*y), deep=True)
cos(x*(y + 1))

Rationals are factored out by default:

>>> terms_gcd(x + y/2)
(2*x + y)/2

Only the y-term had a coefficient that was a fraction; if one does not want to factor out the 1/2 in cases like this, the flag clear can be set to False:

>>> terms_gcd(x + y/2, clear=False)
x + y/2
>>> terms_gcd(x*y/2 + y**2, clear=False)
y*(x/2 + y)

The clear flag is ignored if all coefficients are fractions:

>>> terms_gcd(x/3 + y/2, clear=False)
(2*x + 3*y)/6

See also

sympy.core.exprtools.gcd_terms, sympy.core.exprtools.factor_terms

modelparameters.sympy.polys.polytools.trunc(f, p, *gens, **args)[source]

Reduce f modulo a constant p.

Examples

>>> from .. import trunc
>>> from ..abc import x
>>> trunc(2*x**3 + 3*x**2 + 5*x + 7, 3)
-x**3 - x + 1

modelparameters.sympy.polys.polyutils module

Useful utilities for higher level polynomial classes.

class modelparameters.sympy.polys.polyutils.PicklableWithSlots[source]

Bases: object

Mixin class that allows to pickle objects with __slots__.

Examples

First define a class that mixes PicklableWithSlots in:

>>> from .polyutils import PicklableWithSlots
>>> class Some(PicklableWithSlots):
...     __slots__ = ['foo', 'bar']
...
...     def __init__(self, foo, bar):
...         self.foo = foo
...         self.bar = bar

To make pickle happy in doctest we have to use this hack:

>>> from ..core.compatibility import builtins
>>> builtins.Some = Some

Next lets see if we can create an instance, pickle it and unpickle:

>>> some = Some('abc', 10)
>>> some.foo, some.bar
('abc', 10)

>>> from pickle import dumps, loads
>>> some2 = loads(dumps(some))

>>> some2.foo, some2.bar
('abc', 10)
modelparameters.sympy.polys.polyutils.basic_from_dict(rep, *gens)

Convert a multinomial form into an expression.

modelparameters.sympy.polys.polyutils.dict_from_basic(expr, **args)

Transform an expression into a multinomial form.

modelparameters.sympy.polys.polyutils.dict_from_expr(expr, **args)[source]

Transform an expression into a multinomial form.

modelparameters.sympy.polys.polyutils.expr_from_dict(rep, *gens)[source]

Convert a multinomial form into an expression.

modelparameters.sympy.polys.polyutils.parallel_dict_from_basic(exprs, **args)

Transform expressions into a multinomial form.

modelparameters.sympy.polys.polyutils.parallel_dict_from_expr(exprs, **args)[source]

Transform expressions into a multinomial form.

modelparameters.sympy.polys.rationaltools module

Tools for manipulation of rational expressions.

modelparameters.sympy.polys.rationaltools.together(expr, deep=False)[source]

Denest and combine rational expressions using symbolic methods.

This function takes an expression or a container of expressions and puts it (them) together by denesting and combining rational subexpressions. No heroic measures are taken to minimize degree of the resulting numerator and denominator. To obtain completely reduced expression use cancel(). However, together() can preserve as much as possible of the structure of the input expression in the output (no expansion is performed).

A wide variety of objects can be put together including lists, tuples, sets, relational objects, integrals and others. It is also possible to transform interior of function applications, by setting deep flag to True.

By definition, together() is a complement to apart(), so apart(together(expr)) should return expr unchanged. Note however, that together() uses only symbolic methods, so it might be necessary to use cancel() to perform algebraic simplification and minimise degree of the numerator and denominator.

Examples

>>> from .. import together, exp
>>> from ..abc import x, y, z
>>> together(1/x + 1/y)
(x + y)/(x*y)
>>> together(1/x + 1/y + 1/z)
(x*y + x*z + y*z)/(x*y*z)
>>> together(1/(x*y) + 1/y**2)
(x + y)/(x*y**2)
>>> together(1/(1 + 1/x) + 1/(1 + 1/y))
(x*(y + 1) + y*(x + 1))/((x + 1)*(y + 1))
>>> together(exp(1/x + 1/y))
exp(1/y + 1/x)
>>> together(exp(1/x + 1/y), deep=True)
exp((x + y)/(x*y))
>>> together(1/exp(x) + 1/(x*exp(x)))
(x + 1)*exp(-x)/x
>>> together(1/exp(2*x) + 1/(x*exp(3*x)))
(x*exp(x) + 1)*exp(-3*x)/x

modelparameters.sympy.polys.ring_series module

Power series evaluation and manipulation using sparse Polynomials

Implementing a new function

There are a few things to be kept in mind when adding a new function here:

- The implementation should work on all possible input domains/rings.
  Special cases include the ``EX`` ring and a constant term in the series
  to be expanded. There can be two types of constant terms in the series:

    + A constant value or symbol.
    + A term of a multivariate series not involving the generator, with
      respect to which the series is to expanded.

  Strictly speaking, a generator of a ring should not be considered a
  constant. However, for series expansion both the cases need similar
  treatment (as the user doesn't care about inner details), i.e, use an
  addition formula to separate the constant part and the variable part (see
  rs_sin for reference).

- All the algorithms used here are primarily designed to work for Taylor
  series (number of iterations in the algo equals the required order).
  Hence, it becomes tricky to get the series of the right order if a
  Puiseux series is input. Use rs_puiseux? in your function if your
  algorithm is not designed to handle fractional powers.

Extending rs_series

To make a function work with rs_series you need to do two things:

- Many sure it works with a constant term (as explained above).
- If the series contains constant terms, you might need to extend its ring.
  You do so by adding the new terms to the rings as generators.
  ``PolyRing.compose`` and ``PolyRing.add_gens`` are two functions that do
  so and need to be called every time you expand a series containing a
  constant term.

Look at rs_sin and rs_series for further reference.

modelparameters.sympy.polys.ring_series.mul_xin(p, i, n)[source]

Return p*x_i**n.

x_i is the ith variable in p.

modelparameters.sympy.polys.ring_series.pow_xin(p, i, n)[source]
>>> from .domains import QQ
>>> from .rings import ring
>>> from .ring_series import pow_xin
>>> R, x, y = ring('x, y', QQ)
>>> p = x**QQ(2,5) + x + x**QQ(2,3)
>>> index = p.ring.gens.index(x)
>>> pow_xin(p, index, 15)
x**15 + x**10 + x**6
modelparameters.sympy.polys.ring_series.rs_LambertW(p, x, prec)[source]

Calculate the series expansion of the principal branch of the Lambert W function.

Examples

>>> from .domains import QQ
>>> from .rings import ring
>>> from .ring_series import rs_LambertW
>>> R, x, y = ring('x, y', QQ)
>>> rs_LambertW(x + x*y, x, 3)
-x**2*y**2 - 2*x**2*y - x**2 + x*y + x

See also

LambertW

modelparameters.sympy.polys.ring_series.rs_asin(p, x, prec)[source]

Arcsine of a series

Return the series expansion of the asin of p, about 0.

Examples

>>> from .domains import QQ
>>> from .rings import ring
>>> from .ring_series import rs_asin
>>> R, x, y = ring('x, y', QQ)
>>> rs_asin(x, x, 8)
5/112*x**7 + 3/40*x**5 + 1/6*x**3 + x

See also

asin

modelparameters.sympy.polys.ring_series.rs_atan(p, x, prec)[source]

The arctangent of a series

Return the series expansion of the atan of p, about 0.

Examples

>>> from .domains import QQ
>>> from .rings import ring
>>> from .ring_series import rs_atan
>>> R, x, y = ring('x, y', QQ)
>>> rs_atan(x + x*y, x, 4)
-1/3*x**3*y**3 - x**3*y**2 - x**3*y - 1/3*x**3 + x*y + x

See also

atan

modelparameters.sympy.polys.ring_series.rs_atanh(p, x, prec)[source]

Hyperbolic arctangent of a series

Return the series expansion of the atanh of p, about 0.

Examples

>>> from .domains import QQ
>>> from .rings import ring
>>> from .ring_series import rs_atanh
>>> R, x, y = ring('x, y', QQ)
>>> rs_atanh(x + x*y, x, 4)
1/3*x**3*y**3 + x**3*y**2 + x**3*y + 1/3*x**3 + x*y + x

See also

atanh

modelparameters.sympy.polys.ring_series.rs_compose_add(p1, p2)[source]

compute the composed sum prod(p2(x - beta) for beta root of p1)

Examples

>>> from .domains import QQ
>>> from .rings import ring
>>> from .ring_series import rs_compose_add
>>> R, x = ring('x', QQ)
>>> f = x**2 - 2
>>> g = x**2 - 3
>>> rs_compose_add(f, g)
x**4 - 10*x**2 + 1

References

A. Bostan, P. Flajolet, B. Salvy and E. Schost “Fast Computation with Two Algebraic Numbers”, (2002) Research Report 4579, Institut National de Recherche en Informatique et en Automatique

modelparameters.sympy.polys.ring_series.rs_cos(p, x, prec)[source]

Cosine of a series

Return the series expansion of the cos of p, about 0.

Examples

>>> from .domains import QQ
>>> from .rings import ring
>>> from .ring_series import rs_cos
>>> R, x, y = ring('x, y', QQ)
>>> rs_cos(x + x*y, x, 4)
-1/2*x**2*y**2 - x**2*y - 1/2*x**2 + 1
>>> rs_cos(x + x*y, x, 4)/x**QQ(7, 5)
-1/2*x**(3/5)*y**2 - x**(3/5)*y - 1/2*x**(3/5) + x**(-7/5)

See also

cos

modelparameters.sympy.polys.ring_series.rs_cos_sin(p, x, prec)[source]

Return the tuple (rs_cos(p, x, prec), rs_sin(p, x, prec)).

Is faster than calling rs_cos and rs_sin separately

modelparameters.sympy.polys.ring_series.rs_cosh(p, x, prec)[source]

Hyperbolic cosine of a series

Return the series expansion of the cosh of p, about 0.

Examples

>>> from .domains import QQ
>>> from .rings import ring
>>> from .ring_series import rs_cosh
>>> R, x, y = ring('x, y', QQ)
>>> rs_cosh(x + x*y, x, 4)
1/2*x**2*y**2 + x**2*y + 1/2*x**2 + 1

See also

cosh

modelparameters.sympy.polys.ring_series.rs_cot(p, x, prec)[source]

Cotangent of a series

Return the series expansion of the cot of p, about 0.

Examples

>>> from .domains import QQ
>>> from .rings import ring
>>> from .ring_series import rs_cot
>>> R, x, y = ring('x, y', QQ)
>>> rs_cot(x, x, 6)
-2/945*x**5 - 1/45*x**3 - 1/3*x + x**(-1)

See also

cot

modelparameters.sympy.polys.ring_series.rs_diff(p, x)[source]

Return partial derivative of p with respect to x.

Parameters:

x (PolyElement with respect to which p is differentiated.) –

Examples

>>> from .domains import QQ
>>> from .rings import ring
>>> from .ring_series import rs_diff
>>> R, x, y = ring('x, y', QQ)
>>> p = x + x**2*y**3
>>> rs_diff(p, x)
2*x*y**3 + 1
modelparameters.sympy.polys.ring_series.rs_exp(p, x, prec)[source]

Exponentiation of a series modulo O(x**prec)

Examples

>>> from .domains import QQ
>>> from .rings import ring
>>> from .ring_series import rs_exp
>>> R, x = ring('x', QQ)
>>> rs_exp(x**2, x, 7)
1/6*x**6 + 1/2*x**4 + x**2 + 1
modelparameters.sympy.polys.ring_series.rs_fun(p, f, *args)[source]

Function of a multivariate series computed by substitution.

The case with f method name is used to compute rs_tan and rs_nth_root of a multivariate series:

rs_fun(p, tan, iv, prec)

tan series is first computed for a dummy variable _x, i.e, rs_tan(_x, iv, prec). Then we substitute _x with p to get the desired series

Parameters:
  • p (PolyElement The multivariate series to be expanded.) –

  • f (ring_series function to be applied on p.) –

  • args[-2] (PolyElement with respect to which, the series is to be expanded.) –

  • args[-1] (Required order of the expanded series.) –

Examples

>>> from .domains import QQ
>>> from .rings import ring
>>> from .ring_series import rs_fun, _tan1
>>> R, x, y = ring('x, y', QQ)
>>> p = x + x*y + x**2*y + x**3*y**2
>>> rs_fun(p, _tan1, x, 4)
1/3*x**3*y**3 + 2*x**3*y**2 + x**3*y + 1/3*x**3 + x**2*y + x*y + x
modelparameters.sympy.polys.ring_series.rs_hadamard_exp(p1, inverse=False)[source]

Return sum f_i/i!*x**i from sum f_i*x**i, where x is the first variable.

If invers=True return sum f_i*i!*x**i

Examples

>>> from .domains import QQ
>>> from .rings import ring
>>> from .ring_series import rs_hadamard_exp
>>> R, x = ring('x', QQ)
>>> p = 1 + x + x**2 + x**3
>>> rs_hadamard_exp(p)
1/6*x**3 + 1/2*x**2 + x + 1
modelparameters.sympy.polys.ring_series.rs_integrate(p, x)[source]

Integrate p with respect to x.

Parameters:

x (PolyElement with respect to which p is integrated.) –

Examples

>>> from .domains import QQ
>>> from .rings import ring
>>> from .ring_series import rs_integrate
>>> R, x, y = ring('x, y', QQ)
>>> p = x + x**2*y**3
>>> rs_integrate(p, x)
1/3*x**3*y**3 + 1/2*x**2
modelparameters.sympy.polys.ring_series.rs_is_puiseux(p, x)[source]

Test if p is Puiseux series in x.

Raise an exception if it has a negative power in x.

Examples

>>> from .domains import QQ
>>> from .rings import ring
>>> from .ring_series import rs_is_puiseux
>>> R, x = ring('x', QQ)
>>> p = x**QQ(2,5) + x**QQ(2,3) + x
>>> rs_is_puiseux(p, x)
True
modelparameters.sympy.polys.ring_series.rs_log(p, x, prec)[source]

The Logarithm of p modulo O(x**prec).

Notes

Truncation of integral dx p**-1*d p/dx is used.

Examples

>>> from .domains import QQ
>>> from .rings import ring
>>> from .ring_series import rs_log
>>> R, x = ring('x', QQ)
>>> rs_log(1 + x, x, 8)
1/7*x**7 - 1/6*x**6 + 1/5*x**5 - 1/4*x**4 + 1/3*x**3 - 1/2*x**2 + x
>>> rs_log(x**QQ(3, 2) + 1, x, 5)
1/3*x**(9/2) - 1/2*x**3 + x**(3/2)
modelparameters.sympy.polys.ring_series.rs_min_pow(expr, series_rs, a)[source]

Find the minimum power of a in the series expansion of expr

modelparameters.sympy.polys.ring_series.rs_mul(p1, p2, x, prec)[source]

Return the product of the given two series, modulo O(x**prec).

x is the series variable or its position in the generators.

Examples

>>> from .domains import QQ
>>> from .rings import ring
>>> from .ring_series import rs_mul
>>> R, x = ring('x', QQ)
>>> p1 = x**2 + 2*x + 1
>>> p2 = x + 1
>>> rs_mul(p1, p2, x, 3)
3*x**2 + 3*x + 1
modelparameters.sympy.polys.ring_series.rs_newton(p, x, prec)[source]

Compute the truncated Newton sum of the polynomial p

Examples

>>> from .domains import QQ
>>> from .rings import ring
>>> from .ring_series import rs_newton
>>> R, x = ring('x', QQ)
>>> p = x**2 - 2
>>> rs_newton(p, x, 5)
8*x**4 + 4*x**2 + 2
modelparameters.sympy.polys.ring_series.rs_nth_root(p, n, x, prec)[source]

Multivariate series expansion of the nth root of p.

Parameters:
  • n (p**(1/n) is returned.) –

  • x (PolyElement) –

  • prec (Order of the expanded series.) –

Notes

The result of this function is dependent on the ring over which the polynomial has been defined. If the answer involves a root of a constant, make sure that the polynomial is over a real field. It can not yet handle roots of symbols.

Examples

>>> from .domains import QQ, RR
>>> from .rings import ring
>>> from .ring_series import rs_nth_root
>>> R, x, y = ring('x, y', QQ)
>>> rs_nth_root(1 + x + x*y, -3, x, 3)
2/9*x**2*y**2 + 4/9*x**2*y + 2/9*x**2 - 1/3*x*y - 1/3*x + 1
>>> R, x, y = ring('x, y', RR)
>>> rs_nth_root(3 + x + x*y, 3, x, 2)
0.160249952256379*x*y + 0.160249952256379*x + 1.44224957030741
modelparameters.sympy.polys.ring_series.rs_pow(p1, n, x, prec)[source]

Return p1**n modulo O(x**prec)

Examples

>>> from .domains import QQ
>>> from .rings import ring
>>> from .ring_series import rs_pow
>>> R, x = ring('x', QQ)
>>> p = x + 1
>>> rs_pow(p, 4, x, 3)
6*x**2 + 4*x + 1
modelparameters.sympy.polys.ring_series.rs_puiseux(f, p, x, prec)[source]

Return the puiseux series for f(p, x, prec).

To be used when function f is implemented only for regular series.

Examples

>>> from .domains import QQ
>>> from .rings import ring
>>> from .ring_series import rs_puiseux, rs_exp
>>> R, x = ring('x', QQ)
>>> p = x**QQ(2,5) + x**QQ(2,3) + x
>>> rs_puiseux(rs_exp,p, x, 1)
1/2*x**(4/5) + x**(2/3) + x**(2/5) + 1
modelparameters.sympy.polys.ring_series.rs_puiseux2(f, p, q, x, prec)[source]

Return the puiseux series for f(p, q, x, prec).

To be used when function f is implemented only for regular series.

modelparameters.sympy.polys.ring_series.rs_series(expr, a, prec)[source]

Return the series expansion of an expression about 0.

Parameters:
  • expr (Expr) –

  • a (Symbol with respect to which expr is to be expanded) –

  • prec (order of the series expansion) –

  • much (Currently supports multivariate Taylor series expansion. This is) –

  • operations. (faster that Sympy's series method as it uses sparse polynomial) –

  • series (It automatically creates the simplest ring required to represent the) –

  • sring. (expansion through repeated calls to) –

Examples

>>> from .ring_series import rs_series
>>> from ..functions import sin, cos, exp, tan
>>> from ..core import symbols
>>> from .domains import QQ
>>> a, b, c = symbols('a, b, c')
>>> rs_series(sin(a) + exp(a), a, 5)
1/24*a**4 + 1/2*a**2 + 2*a + 1
>>> series = rs_series(tan(a + b)*cos(a + c), a, 2)
>>> series.as_expr()
-a*sin(c)*tan(b) + a*cos(c)*tan(b)**2 + a*cos(c) + cos(c)*tan(b)
>>> series = rs_series(exp(a**QQ(1,3) + a**QQ(2, 5)), a, 1)
>>> series.as_expr()
a**(11/15) + a**(4/5)/2 + a**(2/5) + a**(2/3)/2 + a**(1/3) + 1
modelparameters.sympy.polys.ring_series.rs_series_from_list(p, c, x, prec, concur=1)[source]

Return a series sum c[n]*p**n modulo O(x**prec).

It reduces the number of multiplications by summing concurrently.

ax = [1, p, p**2, .., p**(J - 1)] s = sum(c[i]*ax[i] for i in range(r, (r + 1)*J))*p**((K - 1)*J) with K >= (n + 1)/J

Examples

>>> from .domains import QQ
>>> from .rings import ring
>>> from .ring_series import rs_series_from_list, rs_trunc
>>> R, x = ring('x', QQ)
>>> p = x**2 + x + 1
>>> c = [1, 2, 3]
>>> rs_series_from_list(p, c, x, 4)
6*x**3 + 11*x**2 + 8*x + 6
>>> rs_trunc(1 + 2*p + 3*p**2, x, 4)
6*x**3 + 11*x**2 + 8*x + 6
>>> pc = R.from_list(list(reversed(c)))
>>> rs_trunc(pc.compose(x, p), x, 4)
6*x**3 + 11*x**2 + 8*x + 6

See also

sympy.polys.ring.compose

modelparameters.sympy.polys.ring_series.rs_series_inversion(p, x, prec)[source]

Multivariate series inversion 1/p modulo O(x**prec).

Examples

>>> from .domains import QQ
>>> from .rings import ring
>>> from .ring_series import rs_series_inversion
>>> R, x, y = ring('x, y', QQ)
>>> rs_series_inversion(1 + x*y**2, x, 4)
-x**3*y**6 + x**2*y**4 - x*y**2 + 1
>>> rs_series_inversion(1 + x*y**2, y, 4)
-x*y**2 + 1
>>> rs_series_inversion(x + x**2, x, 4)
x**3 - x**2 + x - 1 + x**(-1)
modelparameters.sympy.polys.ring_series.rs_series_reversion(p, x, n, y)[source]

Reversion of a series.

p is a series with O(x**n) of the form p = a*x + f(x) where a is a number different from 0.

f(x) = sum( a_k*x_k, k in range(2, n))

a_k : Can depend polynomially on other variables, not indicated. x : Variable with name x. y : Variable with name y.

Solve p = y, that is, given a*x + f(x) - y = 0, find the solution x = r(y) up to O(y**n)

Algorithm:

If r_i is the solution at order i, then: a*r_i + f(r_i) - y = O(y**(i + 1))

and if r_(i + 1) is the solution at order i + 1, then: a*r_(i + 1) + f(r_(i + 1)) - y = O(y**(i + 2))

We have, r_(i + 1) = r_i + e, such that, a*e + f(r_i) = O(y**(i + 2)) or e = -f(r_i)/a

So we use the recursion relation: r_(i + 1) = r_i - f(r_i)/a with the boundary condition: r_1 = y

Examples

>>> from .domains import QQ
>>> from .rings import ring
>>> from .ring_series import rs_series_reversion, rs_trunc
>>> R, x, y, a, b = ring('x, y, a, b', QQ)
>>> p = x - x**2 - 2*b*x**2 + 2*a*b*x**2
>>> p1 = rs_series_reversion(p, x, 3, y); p1
-2*y**2*a*b + 2*y**2*b + y**2 + y
>>> rs_trunc(p.compose(x, p1), y, 3)
y
modelparameters.sympy.polys.ring_series.rs_sin(p, x, prec)[source]

Sine of a series

Return the series expansion of the sin of p, about 0.

Examples

>>> from .domains import QQ
>>> from .rings import ring
>>> from .ring_series import rs_sin
>>> R, x, y = ring('x, y', QQ)
>>> rs_sin(x + x*y, x, 4)
-1/6*x**3*y**3 - 1/2*x**3*y**2 - 1/2*x**3*y - 1/6*x**3 + x*y + x
>>> rs_sin(x**QQ(3, 2) + x*y**QQ(7, 5), x, 4)
-1/2*x**(7/2)*y**(14/5) - 1/6*x**3*y**(21/5) + x**(3/2) + x*y**(7/5)

See also

sin

modelparameters.sympy.polys.ring_series.rs_sinh(p, x, prec)[source]

Hyperbolic sine of a series

Return the series expansion of the sinh of p, about 0.

Examples

>>> from .domains import QQ
>>> from .rings import ring
>>> from .ring_series import rs_sinh
>>> R, x, y = ring('x, y', QQ)
>>> rs_sinh(x + x*y, x, 4)
1/6*x**3*y**3 + 1/2*x**3*y**2 + 1/2*x**3*y + 1/6*x**3 + x*y + x

See also

sinh

modelparameters.sympy.polys.ring_series.rs_square(p1, x, prec)[source]

Square the series modulo O(x**prec)

Examples

>>> from .domains import QQ
>>> from .rings import ring
>>> from .ring_series import rs_square
>>> R, x = ring('x', QQ)
>>> p = x**2 + 2*x + 1
>>> rs_square(p, x, 3)
6*x**2 + 4*x + 1
modelparameters.sympy.polys.ring_series.rs_subs(p, rules, x, prec)[source]

Substitution with truncation according to the mapping in rules.

Return a series with precision prec in the generator x

Note that substitutions are not done one after the other

>>> from .domains import QQ
>>> from .rings import ring
>>> from .ring_series import rs_subs
>>> R, x, y = ring('x, y', QQ)
>>> p = x**2 + y**2
>>> rs_subs(p, {x: x+ y, y: x+ 2*y}, x, 3)
2*x**2 + 6*x*y + 5*y**2
>>> (x + y)**2 + (x + 2*y)**2
2*x**2 + 6*x*y + 5*y**2

which differs from

>>> rs_subs(rs_subs(p, {x: x+ y}, x, 3), {y: x+ 2*y}, x, 3)
5*x**2 + 12*x*y + 8*y**2
Parameters:
  • p (PolyElement Input series.) –

  • rules (dict with substitution mappings.) –

  • x (PolyElement in which the series truncation is to be done.) –

  • prec (Integer order of the series after truncation.) –

Examples

>>> from .domains import QQ
>>> from .rings import ring
>>> from .ring_series import rs_subs
>>> R, x, y = ring('x, y', QQ)
>>> rs_subs(x**2+y**2, {y: (x+y)**2}, x, 3)
 6*x**2*y**2 + x**2 + 4*x*y**3 + y**4
modelparameters.sympy.polys.ring_series.rs_tan(p, x, prec)[source]

Tangent of a series.

Return the series expansion of the tan of p, about 0.

>>> from .domains import QQ
>>> from .rings import ring
>>> from .ring_series import rs_tan
>>> R, x, y = ring('x, y', QQ)
>>> rs_tan(x + x*y, x, 4)
1/3*x**3*y**3 + x**3*y**2 + x**3*y + 1/3*x**3 + x*y + x

See also

_tan1, tan

modelparameters.sympy.polys.ring_series.rs_tanh(p, x, prec)[source]

Hyperbolic tangent of a series

Return the series expansion of the tanh of p, about 0.

Examples

>>> from .domains import QQ
>>> from .rings import ring
>>> from .ring_series import rs_tanh
>>> R, x, y = ring('x, y', QQ)
>>> rs_tanh(x + x*y, x, 4)
-1/3*x**3*y**3 - x**3*y**2 - x**3*y - 1/3*x**3 + x*y + x

See also

tanh

modelparameters.sympy.polys.ring_series.rs_trunc(p1, x, prec)[source]

Truncate the series in the x variable with precision prec, that is, modulo O(x**prec)

Examples

>>> from .domains import QQ
>>> from .rings import ring
>>> from .ring_series import rs_trunc
>>> R, x = ring('x', QQ)
>>> p = x**10 + x**5 + x + 1
>>> rs_trunc(p, x, 12)
x**10 + x**5 + x + 1
>>> rs_trunc(p, x, 10)
x**5 + x + 1

modelparameters.sympy.polys.rings module

Sparse polynomial rings.

modelparameters.sympy.polys.rings.ring(symbols, domain, order=LexOrder())[source]

Construct a polynomial ring returning (ring, x_1, ..., x_n).

Parameters:
  • symbols (str, Symbol/Expr or sequence of str, Symbol/Expr (non-empty)) –

  • domain (Domain or coercible) –

  • order (Order or coercible, optional, defaults to lex) –

Examples

>>> from .rings import ring
>>> from .domains import ZZ
>>> from .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'>
modelparameters.sympy.polys.rings.sring(exprs, *symbols, **options)[source]

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

Parameters:
  • exprs (Expr or sequence of Expr (sympifiable)) –

  • symbols (sequence of Symbol/Expr) –

  • options (keyword arguments understood by Options) –

Examples

>>> from ..core import symbols
>>> from .rings import sring
>>> from .domains import ZZ
>>> from .orderings import lex
>>> 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'>
modelparameters.sympy.polys.rings.vring(symbols, domain, order=LexOrder())[source]

Construct a polynomial ring and inject x_1, ..., x_n into the global namespace.

Parameters:
  • symbols (str, Symbol/Expr or sequence of str, Symbol/Expr (non-empty)) –

  • domain (Domain or coercible) –

  • order (Order or coercible, optional, defaults to lex) –

Examples

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

Construct a polynomial ring returning (ring, (x_1, ..., x_n)).

Parameters:
  • symbols (str, Symbol/Expr or sequence of str, Symbol/Expr (non-empty)) –

  • domain (Domain or coercible) –

  • order (Order or coercible, optional, defaults to lex) –

Examples

>>> from .rings import xring
>>> from .domains import ZZ
>>> from .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'>

modelparameters.sympy.polys.rootisolation module

Real and complex root isolation and refinement algorithms.

class modelparameters.sympy.polys.rootisolation.ComplexInterval(a, b, I, Q, F1, F2, f1, f2, dom, conj=False)[source]

Bases: object

A fully qualified representation of a complex isolation interval. The printed form is shown as (x1, y1) x (x2, y2): the southwest x northeast coordinates of the interval’s rectangle.

as_tuple()[source]

Return tuple representation of complex isolating interval.

property ax

Return x coordinate of south-western corner.

property ay

Return y coordinate of south-western corner.

property bx

Return x coordinate of north-eastern corner.

property by

Return y coordinate of north-eastern corner.

property center

Return the center of the complex isolating interval.

conjugate()[source]

This complex interval really is located in lower half-plane.

property dx

Return width of the complex isolating interval.

property dy

Return height of the complex isolating interval.

is_disjoint(other)[source]

Return True if two isolation intervals are disjoint.

refine()[source]

Perform one step of complex root refinement algorithm.

refine_disjoint(other)[source]

Refine an isolating interval until it is disjoint with another one.

refine_size(dx, dy=None)[source]

Refine an isolating interval until it is of sufficiently small size.

refine_step(steps=1)[source]

Perform several steps of complex root refinement algorithm.

class modelparameters.sympy.polys.rootisolation.RealInterval(data, f, dom)[source]

Bases: object

A fully qualified representation of a real isolation interval.

property a

Return the position of the left end.

as_tuple()[source]

Return tuple representation of real isolating interval.

property b

Return the position of the right end.

property center

Return the center of the real isolating interval.

property dx

Return width of the real isolating interval.

is_disjoint(other)[source]

Return True if two isolation intervals are disjoint.

refine()[source]

Perform one step of real root refinement algorithm.

refine_disjoint(other)[source]

Refine an isolating interval until it is disjoint with another one.

refine_size(dx)[source]

Refine an isolating interval until it is of sufficiently small size.

refine_step(steps=1)[source]

Perform several steps of real root refinement algorithm.

modelparameters.sympy.polys.rootisolation.dup_count_complex_roots(f, K, inf=None, sup=None, exclude=None)[source]

Count all roots in [u + v*I, s + t*I] rectangle using Collins-Krandick algorithm.

modelparameters.sympy.polys.rootisolation.dup_count_real_roots(f, K, inf=None, sup=None)[source]

Returns the number of distinct real roots of f in [inf, sup].

modelparameters.sympy.polys.rootisolation.dup_inner_isolate_negative_roots(f, K, inf=None, sup=None, eps=None, fast=False, mobius=False)[source]

Iteratively compute disjoint negative root isolation intervals.

modelparameters.sympy.polys.rootisolation.dup_inner_isolate_positive_roots(f, K, eps=None, inf=None, sup=None, fast=False, mobius=False)[source]

Iteratively compute disjoint positive root isolation intervals.

modelparameters.sympy.polys.rootisolation.dup_inner_isolate_real_roots(f, K, eps=None, fast=False)[source]

Internal function for isolation positive roots up to given precision.

References:

1. Alkiviadis G. Akritas and Adam W. Strzebonski: A Comparative Study of Two Real Root Isolation Methods . Nonlinear Analysis: Modelling and Control, Vol. 10, No. 4, 297-304, 2005. 2. Alkiviadis G. Akritas, Adam W. Strzebonski and Panagiotis S. Vigklas: Improving the Performance of the Continued Fractions Method Using new Bounds of Positive Roots. Nonlinear Analysis: Modelling and Control, Vol. 13, No. 3, 265-279, 2008.

modelparameters.sympy.polys.rootisolation.dup_inner_refine_real_root(f, M, K, eps=None, steps=None, disjoint=None, fast=False, mobius=False)[source]

Refine a positive root of f given a Mobius transform or an interval.

modelparameters.sympy.polys.rootisolation.dup_isolate_all_roots(f, K, eps=None, inf=None, sup=None, fast=False)[source]

Isolate real and complex roots of a non-square-free polynomial f.

modelparameters.sympy.polys.rootisolation.dup_isolate_all_roots_sqf(f, K, eps=None, inf=None, sup=None, fast=False, blackbox=False)[source]

Isolate real and complex roots of a square-free polynomial f.

modelparameters.sympy.polys.rootisolation.dup_isolate_complex_roots_sqf(f, K, eps=None, inf=None, sup=None, blackbox=False)[source]

Isolate complex roots of a square-free polynomial using Collins-Krandick algorithm.

modelparameters.sympy.polys.rootisolation.dup_isolate_real_roots(f, K, eps=None, inf=None, sup=None, basis=False, fast=False)[source]

Isolate real roots using Vincent-Akritas-Strzebonski (VAS) continued fractions approach.

References:

1. Alkiviadis G. Akritas and Adam W. Strzebonski: A Comparative Study of Two Real Root Isolation Methods. Nonlinear Analysis: Modelling and Control, Vol. 10, No. 4, 297-304, 2005. 2. Alkiviadis G. Akritas, Adam W. Strzebonski and Panagiotis S. Vigklas: Improving the Performance of the Continued Fractions Method Using New Bounds of Positive Roots. Nonlinear Analysis: Modelling and Control, Vol. 13, No. 3, 265-279, 2008.

modelparameters.sympy.polys.rootisolation.dup_isolate_real_roots_list(polys, K, eps=None, inf=None, sup=None, strict=False, basis=False, fast=False)[source]

Isolate real roots of a list of square-free polynomial using Vincent-Akritas-Strzebonski (VAS) CF approach.

References:

1. Alkiviadis G. Akritas and Adam W. Strzebonski: A Comparative Study of Two Real Root Isolation Methods. Nonlinear Analysis: Modelling and Control, Vol. 10, No. 4, 297-304, 2005. 2. Alkiviadis G. Akritas, Adam W. Strzebonski and Panagiotis S. Vigklas: Improving the Performance of the Continued Fractions Method Using New Bounds of Positive Roots. Nonlinear Analysis: Modelling and Control, Vol. 13, No. 3, 265-279, 2008.

modelparameters.sympy.polys.rootisolation.dup_isolate_real_roots_sqf(f, K, eps=None, inf=None, sup=None, fast=False, blackbox=False)[source]

Isolate real roots of a square-free polynomial using the Vincent-Akritas-Strzebonski (VAS) CF approach.

References:

1. Alkiviadis G. Akritas and Adam W. Strzebonski: A Comparative Study of Two Real Root Isolation Methods. Nonlinear Analysis: Modelling and Control, Vol. 10, No. 4, 297-304, 2005. 2. Alkiviadis G. Akritas, Adam W. Strzebonski and Panagiotis S. Vigklas: Improving the Performance of the Continued Fractions Method Using New Bounds of Positive Roots. Nonlinear Analysis: Modelling and Control, Vol. 13, No. 3, 265-279, 2008.

modelparameters.sympy.polys.rootisolation.dup_outer_refine_real_root(f, s, t, K, eps=None, steps=None, disjoint=None, fast=False)[source]

Refine a positive root of f given an interval (s, t).

modelparameters.sympy.polys.rootisolation.dup_refine_real_root(f, s, t, K, eps=None, steps=None, disjoint=None, fast=False)[source]

Refine real root’s approximating interval to the given precision.

modelparameters.sympy.polys.rootisolation.dup_root_lower_bound(f, K)[source]

Compute the LMQ lower bound for the positive roots of f; LMQ (Local Max Quadratic) was developed by Akritas-Strzebonski-Vigklas.

Reference:

Alkiviadis G. Akritas: “Linear and Quadratic Complexity Bounds on the

Values of the Positive Roots of Polynomials” Journal of Universal Computer Science, Vol. 15, No. 3, 523-537, 2009.

modelparameters.sympy.polys.rootisolation.dup_root_upper_bound(f, K)[source]

Compute the LMQ upper bound for the positive roots of f; LMQ (Local Max Quadratic) was developed by Akritas-Strzebonski-Vigklas.

Reference:

Alkiviadis G. Akritas: “Linear and Quadratic Complexity Bounds on the

Values of the Positive Roots of Polynomials” Journal of Universal Computer Science, Vol. 15, No. 3, 523-537, 2009.

modelparameters.sympy.polys.rootisolation.dup_step_refine_real_root(f, M, K, fast=False)[source]

One step of positive real root refinement algorithm.

modelparameters.sympy.polys.rootisolation.dup_sturm(f, K)[source]

Computes the Sturm sequence of f in F[x].

Given a univariate, square-free polynomial f(x) returns the associated Sturm sequence f_0(x), ..., f_n(x) defined by:

f_0(x), f_1(x) = f(x), f'(x)
f_n = -rem(f_{n-2}(x), f_{n-1}(x))

Examples

>>> from ..polys import ring, QQ
>>> R, x = ring("x", QQ)
>>> R.dup_sturm(x**3 - 2*x**2 + x - 3)
[x**3 - 2*x**2 + x - 3, 3*x**2 - 4*x + 1, 2/9*x + 25/9, -2079/4]

References

  1. [Davenport88]

modelparameters.sympy.polys.rootoftools module

Implementation of RootOf class and related tools.

modelparameters.sympy.polys.rootoftools.CRootOf

alias of ComplexRootOf

class modelparameters.sympy.polys.rootoftools.ComplexRootOf(f, x, index=None, radicals=False, expand=True)[source]

Bases: RootOf

Represents an indexed complex root of a polynomial.

Roots of a univariate polynomial separated into disjoint real or complex intervals and indexed in a fixed order. Currently only rational coefficients are allowed. Can be imported as CRootOf.

classmethod all_roots(poly, radicals=True)[source]

Get real and complex roots of a polynomial.

property args

Returns a tuple of arguments of ‘self’.

Examples

>>> from .. import cot
>>> from ..abc import x, y
>>> cot(x).args
(x,)
>>> cot(x).args[0]
x
>>> (x*y).args
(x, y)
>>> (x*y).args[1]
y

Notes

Never use self._args, always use self.args. Only use _args in __new__ when creating a new function. Don’t override .args() from Basic (so that it’s easy to change the interface in the future if needed).

default_assumptions = {'commutative': True, 'complex': True}
eval_rational(tol)[source]

Return a Rational approximation to self with the tolerance tol.

This method uses bisection, which is very robust and it will always converge. The returned Rational instance will be at most ‘tol’ from the exact root.

The following example first obtains Rational approximation to 1e-7 accuracy for all roots of the 4-th order Legendre polynomial, and then evaluates it to 5 decimal digits (so all digits will be correct including rounding):

>>> from .. import S, legendre_poly, Symbol
>>> x = Symbol("x")
>>> p = legendre_poly(4, x, polys=True)
>>> roots = [r.eval_rational(S(1)/10**7) for r in p.real_roots()]
>>> roots = [str(r.n(5)) for r in roots]
>>> roots
['-0.86114', '-0.33998', '0.33998', '0.86114']
property expr
property free_symbols

Return from the atoms of self those which are free symbols.

For most expressions, all symbols are free symbols. For some classes this is not true. e.g. Integrals use Symbols for the dummy variables which are bound variables, so Integral has a method to return all symbols except those. Derivative keeps track of symbols with respect to which it will perform a derivative; those are bound variables, too, so it has its own free_symbols method.

Any other method that uses bound variables should implement a free_symbols method.

index
is_commutative = True
is_complex = True
is_number = True
classmethod real_roots(poly, radicals=True)[source]

Get real roots of a polynomial.

class modelparameters.sympy.polys.rootoftools.RootOf(f, x, index=None, radicals=True, expand=True)[source]

Bases: Expr

Represents a root of a univariate polynomial.

Base class for roots of different kinds of polynomials. Only complex roots are currently supported.

default_assumptions = {}
poly
class modelparameters.sympy.polys.rootoftools.RootSum(expr, func=None, x=None, auto=True, quadratic=False)[source]

Bases: Expr

Represents a sum of all roots of a univariate polynomial.

property args

Returns a tuple of arguments of ‘self’.

Examples

>>> from .. import cot
>>> from ..abc import x, y
>>> cot(x).args
(x,)
>>> cot(x).args[0]
x
>>> (x*y).args
(x, y)
>>> (x*y).args[1]
y

Notes

Never use self._args, always use self.args. Only use _args in __new__ when creating a new function. Don’t override .args() from Basic (so that it’s easy to change the interface in the future if needed).

auto
default_assumptions = {}
doit(**hints)[source]

Evaluate objects that are not evaluated by default like limits, integrals, sums and products. All objects of this kind will be evaluated recursively, unless some species were excluded via ‘hints’ or unless the ‘deep’ hint was set to ‘False’.

>>> from .. import Integral
>>> from ..abc import x
>>> 2*Integral(x, x)
2*Integral(x, x)
>>> (2*Integral(x, x)).doit()
x**2
>>> (2*Integral(x, x)).doit(deep=False)
2*Integral(x, x)
property expr
property free_symbols

Return from the atoms of self those which are free symbols.

For most expressions, all symbols are free symbols. For some classes this is not true. e.g. Integrals use Symbols for the dummy variables which are bound variables, so Integral has a method to return all symbols except those. Derivative keeps track of symbols with respect to which it will perform a derivative; those are bound variables, too, so it has its own free_symbols method.

Any other method that uses bound variables should implement a free_symbols method.

fun
property is_commutative
classmethod new(poly, func, auto=True)[source]

Construct new RootSum instance.

poly
modelparameters.sympy.polys.rootoftools.rootof(f, x, index=None, radicals=True, expand=True)[source]

An indexed root of a univariate polynomial.

Returns either a ComplexRootOf object or an explicit expression involving radicals.

Parameters:
  • f (Expr) – Univariate polynomial.

  • x (Symbol, optional) – Generator for f.

  • index (int or Integer) –

  • radicals (bool) – Return a radical expression if possible.

  • expand (bool) – Expand f.

modelparameters.sympy.polys.solvers module

Low-level linear systems solver.

class modelparameters.sympy.polys.solvers.RawMatrix(*args, **kwargs)[source]

Bases: MutableDenseMatrix

is_zero()[source]

Checks if a matrix is a zero matrix.

A matrix is zero if every element is zero. A matrix need not be square to be considered zero. The empty matrix is zero by the principle of vacuous truth. For a matrix that may or may not be zero (e.g. contains a symbol), this will be None

Examples

>>> from .. import Matrix, zeros
>>> from ..abc import x
>>> a = Matrix([[0, 0], [0, 0]])
>>> b = zeros(3, 4)
>>> c = Matrix([[0, 1], [0, 0]])
>>> d = Matrix([])
>>> e = Matrix([[x, 0], [0, 0]])
>>> a.is_zero
True
>>> b.is_zero
True
>>> c.is_zero
False
>>> d.is_zero
True
>>> e.is_zero
modelparameters.sympy.polys.solvers.eqs_to_matrix(eqs, ring)[source]

Transform from equations to matrix form.

modelparameters.sympy.polys.solvers.solve_lin_sys(eqs, ring, _raw=True)[source]

Solve a system of linear equations.

If _raw is False, the keys and values in the returned dictionary will be of type Expr (and the unit of the field will be removed from the keys) otherwise the low-level polys types will be returned, e.g. PolyElement: PythonRational.

modelparameters.sympy.polys.specialpolys module

Functions for generating interesting polynomials, e.g. for benchmarking.

modelparameters.sympy.polys.specialpolys.cyclotomic_poly(n, x=None, **args)[source]

Generates cyclotomic polynomial of order n in x.

modelparameters.sympy.polys.specialpolys.interpolating_poly(n, x, X='x', Y='y')[source]

Construct Lagrange interpolating polynomial for n data points.

modelparameters.sympy.polys.specialpolys.random_poly(x, n, inf, sup, domain=ZZ, polys=False)[source]

Return a polynomial of degree n with coefficients in [inf, sup].

modelparameters.sympy.polys.specialpolys.swinnerton_dyer_poly(n, x=None, **args)[source]

Generates n-th Swinnerton-Dyer polynomial in x.

modelparameters.sympy.polys.specialpolys.symmetric_poly(n, *gens, **args)[source]

Generates symmetric polynomial of order n.

modelparameters.sympy.polys.sqfreetools module

Square-free decomposition algorithms and related tools.

modelparameters.sympy.polys.sqfreetools.dmp_gf_sqf_list(f, u, K, all=False)[source]

Compute square-free decomposition of f in GF(p)[X].

modelparameters.sympy.polys.sqfreetools.dmp_gf_sqf_part(f, K)[source]

Compute square-free part of f in GF(p)[X].

modelparameters.sympy.polys.sqfreetools.dmp_gff_list(f, u, K)[source]

Compute greatest factorial factorization of f in K[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
modelparameters.sympy.polys.sqfreetools.dmp_sqf_list(f, u, K, all=False)[source]

Return square-free decomposition of a polynomial in K[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> f = x**5 + 2*x**4*y + x**3*y**2
>>> R.dmp_sqf_list(f)
(1, [(x + y, 2), (x, 3)])
>>> R.dmp_sqf_list(f, all=True)
(1, [(1, 1), (x + y, 2), (x, 3)])
modelparameters.sympy.polys.sqfreetools.dmp_sqf_list_include(f, u, K, all=False)[source]

Return square-free decomposition of a polynomial in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> f = x**5 + 2*x**4*y + x**3*y**2
>>> R.dmp_sqf_list_include(f)
[(1, 1), (x + y, 2), (x, 3)]
>>> R.dmp_sqf_list_include(f, all=True)
[(1, 1), (x + y, 2), (x, 3)]
modelparameters.sympy.polys.sqfreetools.dmp_sqf_norm(f, u, K)[source]

Square-free norm of f in K[X], useful over algebraic domains.

Returns s, f, r, such that g(x) = f(x-sa) and r(x) = Norm(g(x)) is a square-free polynomial over K, where a is the algebraic extension of K.

Examples

>>> from ..polys import ring, QQ
>>> from .. import I
>>> K = QQ.algebraic_field(I)
>>> R, x, y = ring("x,y", K)
>>> _, X, Y = ring("x,y", QQ)
>>> s, f, r = R.dmp_sqf_norm(x*y + y**2)
>>> s == 1
True
>>> f == x*y + y**2 + K([QQ(-1), QQ(0)])*y
True
>>> r == X**2*Y**2 + 2*X*Y**3 + Y**4 + Y**2
True
modelparameters.sympy.polys.sqfreetools.dmp_sqf_p(f, u, K)[source]

Return True if f is a square-free polynomial in K[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> R.dmp_sqf_p(x**2 + 2*x*y + y**2)
False
>>> R.dmp_sqf_p(x**2 + y**2)
True
modelparameters.sympy.polys.sqfreetools.dmp_sqf_part(f, u, K)[source]

Returns square-free part of a polynomial in K[X].

Examples

>>> from ..polys import ring, ZZ
>>> R, x,y = ring("x,y", ZZ)
>>> R.dmp_sqf_part(x**3 + 2*x**2*y + x*y**2)
x**2 + x*y
modelparameters.sympy.polys.sqfreetools.dup_gf_sqf_list(f, K, all=False)[source]

Compute square-free decomposition of f in GF(p)[x].

modelparameters.sympy.polys.sqfreetools.dup_gf_sqf_part(f, K)[source]

Compute square-free part of f in GF(p)[x].

modelparameters.sympy.polys.sqfreetools.dup_gff_list(f, K)[source]

Compute greatest factorial factorization of f in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_gff_list(x**5 + 2*x**4 - x**3 - 2*x**2)
[(x, 1), (x + 2, 4)]
modelparameters.sympy.polys.sqfreetools.dup_sqf_list(f, K, all=False)[source]

Return square-free decomposition of a polynomial in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> f = 2*x**5 + 16*x**4 + 50*x**3 + 76*x**2 + 56*x + 16
>>> R.dup_sqf_list(f)
(2, [(x + 1, 2), (x + 2, 3)])
>>> R.dup_sqf_list(f, all=True)
(2, [(1, 1), (x + 1, 2), (x + 2, 3)])
modelparameters.sympy.polys.sqfreetools.dup_sqf_list_include(f, K, all=False)[source]

Return square-free decomposition of a polynomial in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> f = 2*x**5 + 16*x**4 + 50*x**3 + 76*x**2 + 56*x + 16
>>> R.dup_sqf_list_include(f)
[(2, 1), (x + 1, 2), (x + 2, 3)]
>>> R.dup_sqf_list_include(f, all=True)
[(2, 1), (x + 1, 2), (x + 2, 3)]
modelparameters.sympy.polys.sqfreetools.dup_sqf_norm(f, K)[source]

Square-free norm of f in K[x], useful over algebraic domains.

Returns s, f, r, such that g(x) = f(x-sa) and r(x) = Norm(g(x)) is a square-free polynomial over K, where a is the algebraic extension of K.

Examples

>>> from ..polys import ring, QQ
>>> from .. import sqrt
>>> K = QQ.algebraic_field(sqrt(3))
>>> R, x = ring("x", K)
>>> _, X = ring("x", QQ)
>>> s, f, r = R.dup_sqf_norm(x**2 - 2)
>>> s == 1
True
>>> f == x**2 + K([QQ(-2), QQ(0)])*x + 1
True
>>> r == X**4 - 10*X**2 + 1
True
modelparameters.sympy.polys.sqfreetools.dup_sqf_p(f, K)[source]

Return True if f is a square-free polynomial in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_sqf_p(x**2 - 2*x + 1)
False
>>> R.dup_sqf_p(x**2 - 1)
True
modelparameters.sympy.polys.sqfreetools.dup_sqf_part(f, K)[source]

Returns square-free part of a polynomial in K[x].

Examples

>>> from ..polys import ring, ZZ
>>> R, x = ring("x", ZZ)
>>> R.dup_sqf_part(x**3 - 3*x - 2)
x**2 - x - 2

modelparameters.sympy.polys.subresultants_qq_zz module

This module contains functions for the computation of Euclidean, generalized Sturmian and (modified) subresultant polynomial remainder sequences (prs’s).

The pseudo-remainder function prem() of sympy is _not_ used by any of the functions in the module.

Instead of prem() we use the function

rem_z().

Included is also the function quo_z().

1. Theoretical background:

Consider the polynomials f, g ∈ Z[x] of degrees deg(f) = n and deg(g) = m with n ≥ m.

Definition 1:

The sign sequence of a polynomial remainder sequence (prs) is the sequence of signs of the leading coefficients of its polynomials.

Sign sequences can be computed with the function:

sign_seq(poly_seq, x)

Definition 2:

A polynomial remainder sequence (prs) is called complete if the degree difference between any two consecutive polynomials is 1; otherwise, it called incomplete.

It is understood that f, g belong to the sequences mentioned in the two definitions.

1A. Euclidean and subresultant prs’s:

The subresultant prs of f, g is a sequence of polynomials in Z[x] analogous to the Euclidean prs, the sequence obtained by applying on f, g Euclid’s algorithm for polynomial greatest common divisors (gcd) in Q[x].

The subresultant prs differs from the Euclidean prs in that the coefficients of each polynomial in the former sequence are determinants — also referred to as subresultants — of appropriately selected sub-matrices of sylvester1(f, g, x), Sylvester’s matrix of 1840 of dimensions (n + m) × (n + m).

Recall that the determinant of sylvester1(f, g, x) itself is called the resultant of f, g and serves as a criterion of whether the two polynomials have common roots or not.

In sympy the resultant is computed with the function resultant(f, g, x). This function does _not_ evaluate the determinant of sylvester(f, g, x, 1); instead, it returns the last member of the subresultant prs of f, g, multiplied (if needed) by an appropriate power of -1; see the caveat below.

Caveat: If Df = degree(f, x) and Dg = degree(g, x), then:

resultant(f, g, x) = (-1)**(Df*Dg) * resultant(g, f, x).

For complete prs’s the sign sequence of the Euclidean prs of f, g is identical to the sign sequence of the subresultant prs of f, g and the coefficients of one sequence are easily computed from the coefficients of the other.

For incomplete prs’s the polynomials in the subresultant prs, generally differ in sign from those of the Euclidean prs, and — unlike the case of complete prs’s — it is not at all obvious how to compute the coefficients of one sequence from the coefficients of the other.

1B. Sturmian and modified subresultant prs’s:

For the same polynomials f, g ∈ Z[x] mentioned above, their ``modified’’ subresultant prs is a sequence of polynomials similar to the Sturmian prs, the sequence obtained by applying in Q[x] Sturm’s algorithm on f, g.

The two sequences differ in that the coefficients of each polynomial in the modified subresultant prs are the determinants — also referred to as modified subresultants — of appropriately selected sub-matrices of sylvester2(f, g, x), Sylvester’s matrix of 1853 of dimensions 2n × 2n.

The determinant of sylvester2 itself is called the modified resultant of f, g and it also can serve as a criterion of whether the two polynomials have common roots or not.

For complete prs’s the sign sequence of the Sturmian prs of f, g is identical to the sign sequence of the modified subresultant prs of f, g and the coefficients of one sequence are easily computed from the coefficients of the other.

For incomplete prs’s the polynomials in the modified subresultant prs, generally differ in sign from those of the Sturmian prs, and — unlike the case of complete prs’s — it is not at all obvious how to compute the coefficients of one sequence from the coefficients of the other.

As Sylvester pointed out, the coefficients of the polynomial remainders obtained as (modified) subresultants are the smallest possible without introducing rationals and without computing (integer) greatest common divisors.

1C. On terminology:

Whence the terminology? Well generalized Sturmian prs’s are ``modifications’’ of Euclidean prs’s; the hint came from the title of the Pell-Gordon paper of 1917.

In the literature one also encounters the name ``non signed’’ and ``signed’’ prs for Euclidean and Sturmian prs respectively.

Likewise ``non signed’’ and ``signed’’ subresultant prs for subresultant and modified subresultant prs respectively.

2. Functions in the module:

No function utilizes sympy’s function prem().

2A. Matrices:

The functions sylvester(f, g, x, method=1) and sylvester(f, g, x, method=2) compute either Sylvester matrix. They can be used to compute (modified) subresultant prs’s by direct determinant evaluation.

The function bezout(f, g, x, method=’prs’) provides a matrix of smaller dimensions than either Sylvester matrix. It is the function of choice for computing (modified) subresultant prs’s by direct determinant evaluation.

sylvester(f, g, x, method=1) sylvester(f, g, x, method=2) bezout(f, g, x, method=’prs’)

The following identity holds:

bezout(f, g, x, method=’prs’) = backward_eye(deg(f))*bezout(f, g, x, method=’bz’)*backward_eye(deg(f))

2B. Subresultant and modified subresultant prs’s by

determinant evaluation:

Instead of utilizing the Sylvester matrices, we employ the Bezout matrix of smaller dimensions.

subresultants_bezout(f, g, x) modified_subresultants_bezout(f, g, x)

2C. Subresultant prs’s by ONE determinant evaluation:

All three functions in this section evaluate one determinant per remainder polynomial; this is the determinant of an appropriately selected sub-matrix of sylvester1(f, g, x), Sylvester’s matrix of 1840.

To compute the remainder polynomials the function subresultants_rem(f, g, x) employs rem(f, g, x). By contrast, the other two functions implement Van Vleck’s ideas of 1900 and compute the remainder polynomials by trinagularizing sylvester2(f, g, x), Sylvester’s matrix of 1853.

subresultants_rem(f, g, x) subresultants_vv(f, g, x) subresultants_vv_2(f, g, x).

2E. Euclidean, Sturmian prs’s in Q[x]:

euclid_q(f, g, x) sturm_q(f, g, x)

2F. Euclidean, Sturmian and (modified) subresultant prs’s P-G:

All functions in this section are based on the Pell-Gordon (P-G) theorem of 1917. Computations are done in Q[x], employing the function rem(f, g, x) for the computation of the remainder polynomials.

euclid_pg(f, g, x) sturm pg(f, g, x) subresultants_pg(f, g, x) modified_subresultants_pg(f, g, x)

2G. Euclidean, Sturmian and (modified) subresultant prs’s A-M-V:

All functions in this section are based on the Akritas-Malaschonok- Vigklas (A-M-V) theorem of 2015. Computations are done in Z[x], employing the function rem_z(f, g, x) for the computation of the remainder polynomials.

euclid_amv(f, g, x) sturm_amv(f, g, x) subresultants_amv(f, g, x) modified_subresultants_amv(f, g, x)

2Ga. Exception:

subresultants_amv_q(f, g, x)

This function employs rem(f, g, x) for the computation of the remainder polynomials, despite the fact that it implements the A-M-V Theorem.

It is included in our module in order to show that theorems P-G and A-M-V can be implemented utilizing either the function rem(f, g, x) or the function rem_z(f, g, x).

For clearly historical reasons — since the Collins-Brown-Traub coefficients-reduction factor β_i was not available in 1917 — we have implemented the Pell-Gordon theorem with the function rem(f, g, x) and the A-M-V Theorem with the function rem_z(f, g, x).

modelparameters.sympy.polys.subresultants_qq_zz.backward_eye(n)[source]

Returns the backward identity matrix of dimensions n x n.

Needed to “turn” the Bezout matrices so that the leading coefficients are first. See docstring of the function bezout(p, q, x, method=’bz’).

modelparameters.sympy.polys.subresultants_qq_zz.bezout(p, q, x, method='bz')[source]

The input polynomials p, q are in Z[x] or in Q[x]. Let mx = max( degree(p, x) , degree(q, x) ).

The default option bezout(p, q, x, method=’bz’) returns Bezout’s symmetric matrix of p and q, of dimensions (mx) x (mx). The determinant of this matrix is equal to the determinant of sylvester2, Sylvester’s matrix of 1853, whose dimensions are (2*mx) x (2*mx); however the subresultants of these two matrices may differ.

The other option, bezout(p, q, x, ‘prs’), is of interest to us in this module because it returns a matrix equivalent to sylvester2. In this case all subresultants of the two matrices are identical.

Both the subresultant polynomial remainder sequence (prs) and the modified subresultant prs of p and q can be computed by evaluating determinants of appropriately selected submatrices of bezout(p, q, x, ‘prs’) — one determinant per coefficient of the remainder polynomials.

The matrices bezout(p, q, x, ‘bz’) and bezout(p, q, x, ‘prs’) are related by the formula

bezout(p, q, x, ‘prs’) = backward_eye(deg(p)) * bezout(p, q, x, ‘bz’) * backward_eye(deg(p)),

where backward_eye() is the backward identity function.

References:

1. G.M.Diaz-Toca,L.Gonzalez-Vega: Various New Expressions for Subresultants and Their Applications. Appl. Algebra in Engin., Communic. and Comp., Vol. 15, 233–266, 2004.

modelparameters.sympy.polys.subresultants_qq_zz.compute_sign(base, expo)[source]

base != 0 and expo >= 0 are integers;

returns the sign of base**expo without evaluating the power itself!

modelparameters.sympy.polys.subresultants_qq_zz.correct_sign(deg_f, deg_g, s1, rdel, cdel)[source]

Used in various subresultant prs algorithms.

Evaluates the determinant, (a.k.a. subresultant) of a properly selected submatrix of s1, Sylvester’s matrix of 1840, to get the correct sign and value of the leading coefficient of a given polynomial remainder.

deg_f, deg_g are the degrees of the original polynomials p, q for which the matrix s1 = sylvester(p, q, x, 1) was constructed.

rdel denotes the expected degree of the remainder; it is the number of rows to be deleted from each group of rows in s1 as described in the reference below.

cdel denotes the expected degree minus the actual degree of the remainder; it is the number of columns to be deleted — starting with the last column forming the square matrix — from the matrix resulting after the row deletions.

References:

Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``Sturm Sequences and Modified Subresultant Polynomial Remainder Sequences.’’ Serdica Journal of Computing, Vol. 8, No 1, 29–46, 2014.

modelparameters.sympy.polys.subresultants_qq_zz.create_ma(deg_f, deg_g, row1, row2, col_num)[source]

Creates a ``small’’ matrix M to be triangularized.

deg_f, deg_g are the degrees of the divident and of the divisor polynomials respectively, deg_g > deg_f.

The coefficients of the divident poly are the elements in row2 and those of the divisor poly are the elements in row1.

col_num defines the number of columns of the matrix M.

modelparameters.sympy.polys.subresultants_qq_zz.euclid_amv(f, g, x)[source]

f, g are polynomials in Z[x] or Q[x]. It is assumed that degree(f, x) >= degree(g, x).

Computes the Euclidean sequence of p and q in Z[x] or Q[x].

If the Euclidean sequence is complete the coefficients of the polynomials in the sequence are subresultants. That is, they are determinants of appropriately selected submatrices of sylvester1, Sylvester’s matrix of 1840. In this case the Euclidean sequence coincides with the subresultant prs, of the polynomials p, q.

If the Euclidean sequence is incomplete the signs of the coefficients of the polynomials in the sequence may differ from the signs of the coefficients of the corresponding polynomials in the subresultant prs; however, the absolute values are the same.

To compute the coefficients, no determinant evaluation takes place. Instead, polynomial divisions in Z[x] or Q[x] are performed, using the function rem_z(f, g, x); the coefficients of the remainders computed this way become subresultants with the help of the Collins-Brown-Traub formula for coefficient reduction.

References:

1. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``A Basic Result on the Theory of Subresultants.’’ Submitted for publication.

2. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``Subresultant Polynomial remainder Sequences Obtained by Polynomial Divisions in Q[x] or in Z[x].’’ Submitted for publication.

modelparameters.sympy.polys.subresultants_qq_zz.euclid_pg(p, q, x)[source]

p, q are polynomials in Z[x] or Q[x]. It is assumed that degree(p, x) >= degree(q, x).

Computes the Euclidean sequence of p and q in Z[x] or Q[x].

If the Euclidean sequence is complete the coefficients of the polynomials in the sequence are subresultants. That is, they are determinants of appropriately selected submatrices of sylvester1, Sylvester’s matrix of 1840. In this case the Euclidean sequence coincides with the subresultant prs of the polynomials p, q.

If the Euclidean sequence is incomplete the signs of the coefficients of the polynomials in the sequence may differ from the signs of the coefficients of the corresponding polynomials in the subresultant prs; however, the absolute values are the same.

To compute the Euclidean sequence, no determinant evaluation takes place. We first compute the (generalized) Sturm sequence of p and q using sturm_pg(p, q, x, 1), in which case the coefficients are (in absolute value) equal to subresultants. Then we change the signs of the remainders in the Sturm sequence according to the pattern “-, -, +, +, -, -, +, +,…” ; see Lemma 1 in the 1st reference or Theorem 3 in the 2nd reference as well as the function sturm_pg(p, q, x).

References:

1. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``A Basic Result on the Theory of Subresultants.’’ Submitted for publication.

2. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``On the Remainders Obtained in Finding the Greatest Common Divisor of Two Polynomials.’’ Serdica Journal of Computing, to appear.

3. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``Subresultant Polynomial Remainder Sequences Obtained by Polynomial Divisions in Q[x] or in Z[x].’’ Submitted for publication.

modelparameters.sympy.polys.subresultants_qq_zz.euclid_q(p, q, x)[source]

p, q are polynomials in Z[x] or Q[x]. It is assumed that degree(p, x) >= degree(q, x).

Computes the Euclidean sequence of p and q in Q[x]. Polynomial divisions in Q[x] are performed, using the function rem(p, q, x).

The coefficients of the polynomials in the Euclidean sequence can be uniquely determined from the corresponding coefficients of the polynomials found either in:

  1. the ``modified’’ subresultant polynomial remainder sequence,

(references 1, 2)

or in

  1. the subresultant polynomial remainder sequence (references 3).

References:

1. Pell A. J., R. L. Gordon. The Modified Remainders Obtained in Finding the Highest Common Factor of Two Polynomials. Annals of MatheMatics, Second Series, 18 (1917), No. 4, 188–193.

2. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``Sturm Sequences and Modified Subresultant Polynomial Remainder Sequences.’’ Serdica Journal of Computing, Vol. 8, No 1, 29–46, 2014.

3. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``A Basic Result on the Theory of Subresultants.’’ Submitted for publication.

modelparameters.sympy.polys.subresultants_qq_zz.final_touches(s2, r, deg_g)[source]

s2 is sylvester2, r is the row pointer in s2, deg_g is the degree of the poly last inserted in s2.

After a gcd of degree > 0 has been found with Van Vleck’s method, and was inserted into s2, if its last term is not in the last column of s2, then it is inserted as many times as needed, rotated right by one each time, until the condition is met.

modelparameters.sympy.polys.subresultants_qq_zz.find_degree(M, deg_f)[source]

Finds the degree of the poly corresponding (after triangularization) to the _last_ row of the ``small’’ matrix M, created by create_ma().

deg_f is the degree of the divident poly. If _last_ row is all 0’s returns None.

modelparameters.sympy.polys.subresultants_qq_zz.modified_subresultants_amv(p, q, x)[source]

p, q are polynomials in Z[x] or Q[x]. It is assumed that degree(p, x) >= degree(q, x).

Computes the modified subresultant prs of p and q in Z[x] or Q[x], from the subresultant prs of p and q. The coefficients of the polynomials in the two sequences differ only in sign and the factor LC(p)**( deg(p)- deg(q)) as stated in Theorem 2 of the reference.

The coefficients of the polynomials in the output sequence are modified subresultants. That is, they are determinants of appropriately selected submatrices of sylvester2, Sylvester’s matrix of 1853.

If the modified subresultant prs is complete, and LC( p ) > 0, it coincides with the (generalized) Sturm’s sequence of the polynomials p, q.

References:

1. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ‘‘On the Remainders Obtained in Finding the Greatest Common Divisor of Two Polynomials.’’ Serdica Journal of Computing, to appear.

modelparameters.sympy.polys.subresultants_qq_zz.modified_subresultants_bezout(p, q, x)[source]

The input polynomials p, q are in Z[x] or in Q[x]. It is assumed that degree(p, x) >= degree(q, x).

Computes the modified subresultant polynomial remainder sequence of p, q by evaluating determinants of appropriately selected submatrices of bezout(p, q, x, ‘prs’). The dimensions of the latter are deg(p) x deg(p).

Each coefficient is computed by evaluating the determinant of the corresponding submatrix of bezout(p, q, x, ‘prs’).

bezout(p, q, x, ‘prs’) is used instead of sylvester(p, q, x, 2), Sylvester’s matrix of 1853, because the dimensions of the latter are 2*deg(p) x 2*deg(p).

If the modified subresultant prs is complete, and LC( p ) > 0, the output coincides with the (generalized) Sturm’s sequence of the polynomials p, q.

References:

1. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``Sturm Sequences and Modified Subresultant Polynomial Remainder Sequences.’’ Serdica Journal of Computing, Vol. 8, No 1, 29–46, 2014.

2. G.M.Diaz-Toca,L.Gonzalez-Vega: Various New Expressions for Subresultants and Their Applications. Appl. Algebra in Engin., Communic. and Comp., Vol. 15, 233–266, 2004.

modelparameters.sympy.polys.subresultants_qq_zz.modified_subresultants_pg(p, q, x)[source]

p, q are polynomials in Z[x] or Q[x]. It is assumed that degree(p, x) >= degree(q, x).

Computes the ``modified’’ subresultant prs of p and q in Z[x] or Q[x]; the coefficients of the polynomials in the sequence are ``modified’’ subresultants. That is, they are determinants of appropriately selected submatrices of sylvester2, Sylvester’s matrix of 1853.

To compute the coefficients, no determinant evaluation takes place. Instead, polynomial divisions in Q[x] are performed, using the function rem(p, q, x); the coefficients of the remainders computed this way become ``modified’’ subresultants with the help of the Pell-Gordon Theorem of 1917.

If the ``modified’’ subresultant prs is complete, and LC( p ) > 0, it coincides with the (generalized) Sturm sequence of the polynomials p, q.

References:

1. Pell A. J., R. L. Gordon. The Modified Remainders Obtained in Finding the Highest Common Factor of Two Polynomials. Annals of MatheMatics, Second Series, 18 (1917), No. 4, 188–193.

2. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``Sturm Sequences and Modified Subresultant Polynomial Remainder Sequences.’’ Serdica Journal of Computing, Vol. 8, No 1, 29–46, 2014.

modelparameters.sympy.polys.subresultants_qq_zz.pivot(M, i, j)[source]

M is a matrix, and M[i, j] specifies the pivot element.

All elements below M[i, j], in the j-th column, will be zeroed, if they are not already 0, according to Dodgson-Bareiss’ integer preserving transformations.

References:

1. Akritas, A. G.: ``A new method for computing polynomial greatest common divisors and polynomial remainder sequences.’’ Numerische MatheMatik 52, 119-127, 1988.

2. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``On a Theorem by Van Vleck Regarding Sturm Sequences.’’ Serdica Journal of Computing, 7, No 4, 101–134, 2013.

modelparameters.sympy.polys.subresultants_qq_zz.process_bezout_output(poly_seq, x)[source]

poly_seq is a polynomial remainder sequence computed either by subresultants_bezout or by modified_subresultants_bezout.

This function removes from poly_seq all zero polynomials as well as all those whose degree is equal to the degree of a previous polynomial in poly_seq, as we scan it from left to right.

modelparameters.sympy.polys.subresultants_qq_zz.quo_z(p, q, x)[source]

Intended mainly for p, q polynomials in Z[x] so that, on dividing p by q, the quotient will also be in Z[x]. (However, it also works fine for polynomials in Q[x].) It is assumed that degree(p, x) >= degree(q, x).

It premultiplies p by the _absolute_ value of the leading coefficient of q, raised to the power deg(p) - deg(q) + 1 and then performs polynomial division in Q[x], using the function quo(p, q, x).

By contrast the function pquo(p, q, x) does _not_ use the absolute value of the leading coefficient of q.

See also function rem_z(p, q, x) for additional comments and references.

modelparameters.sympy.polys.subresultants_qq_zz.rem_z(p, q, x)[source]

Intended mainly for p, q polynomials in Z[x] so that, on dividing p by q, the remainder will also be in Z[x]. (However, it also works fine for polynomials in Q[x].) It is assumed that degree(p, x) >= degree(q, x).

It premultiplies p by the _absolute_ value of the leading coefficient of q, raised to the power deg(p) - deg(q) + 1 and then performs polynomial division in Q[x], using the function rem(p, q, x).

By contrast the function prem(p, q, x) does _not_ use the absolute value of the leading coefficient of q. This results not only in ``messing up the signs’’ of the Euclidean and Sturmian prs’s as mentioned in the second reference, but also in violation of the main results of the first and third references — Theorem 4 and Theorem 1 respectively. Theorems 4 and 1 establish a one-to-one correspondence between the Euclidean and the Sturmian prs of p, q, on one hand, and the subresultant prs of p, q, on the other.

References:

1. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``On the Remainders Obtained in Finding the Greatest Common Divisor of Two Polynomials.’’ Serdica Journal of Computing, to appear.

  1. http://planetMath.org/sturmstheorem

3. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``A Basic Result on the Theory of Subresultants.’’ Submitted for publication.

modelparameters.sympy.polys.subresultants_qq_zz.rotate_l(L, k)[source]

Rotates left by k. L is a row of a matrix or a list.

modelparameters.sympy.polys.subresultants_qq_zz.rotate_r(L, k)[source]

Rotates right by k. L is a row of a matrix or a list.

modelparameters.sympy.polys.subresultants_qq_zz.row2poly(row, deg, x)[source]

Converts the row of a matrix to a poly of degree deg and variable x. Some entries at the beginning and/or at the end of the row may be zero.

modelparameters.sympy.polys.subresultants_qq_zz.sign_seq(poly_seq, x)[source]

Given a sequence of polynomials poly_seq, it returns the sequence of signs of the leading coefficients of the polynomials in poly_seq.

modelparameters.sympy.polys.subresultants_qq_zz.sturm_amv(p, q, x, method=0)[source]

p, q are polynomials in Z[x] or Q[x]. It is assumed that degree(p, x) >= degree(q, x).

Computes the (generalized) Sturm sequence of p and q in Z[x] or Q[x]. If q = diff(p, x, 1) it is the usual Sturm sequence.

  1. If method == 0, default, the remainder coefficients of the sequence are (in absolute value) ``modified’’ subresultants, which for non-monic polynomials are greater than the coefficients of the corresponding subresultants by the factor Abs(LC(p)**( deg(p)- deg(q))).

  2. If method == 1, the remainder coefficients of the sequence are (in absolute value) subresultants, which for non-monic polynomials are smaller than the coefficients of the corresponding ``modified’’ subresultants by the factor Abs( LC(p)**( deg(p)- deg(q)) ).

If the Sturm sequence is complete, method=0 and LC( p ) > 0, then the coefficients of the polynomials in the sequence are ``modified’’ subresultants. That is, they are determinants of appropriately selected submatrices of sylvester2, Sylvester’s matrix of 1853. In this case the Sturm sequence coincides with the ``modified’’ subresultant prs, of the polynomials p, q.

If the Sturm sequence is incomplete and method=0 then the signs of the coefficients of the polynomials in the sequence may differ from the signs of the coefficients of the corresponding polynomials in the ``modified’’ subresultant prs; however, the absolute values are the same.

To compute the coefficients, no determinant evaluation takes place. Instead, we first compute the euclidean sequence of p and q using euclid_amv(p, q, x) and then: (a) change the signs of the remainders in the Euclidean sequence according to the pattern “-, -, +, +, -, -, +, +,…” (see Lemma 1 in the 1st reference or Theorem 3 in the 2nd reference) and (b) if method=0, assuming deg(p) > deg(q), we multiply the remainder coefficients of the Euclidean sequence times the factor Abs( LC(p)**( deg(p)- deg(q)) ) to make them modified subresultants. See also the function sturm_pg(p, q, x).

References:

1. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``A Basic Result on the Theory of Subresultants.’’ Submitted for publication.

2. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``On the Remainders Obtained in Finding the Greatest Common Divisor of Two Polynomials.’’ Serdica Journal of Computing, to appear.

3. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``Subresultant Polynomial Remainder Sequences Obtained by Polynomial Divisions in Q[x] or in Z[x].’’ Submitted for publication.

modelparameters.sympy.polys.subresultants_qq_zz.sturm_pg(p, q, x, method=0)[source]

p, q are polynomials in Z[x] or Q[x]. It is assumed that degree(p, x) >= degree(q, x).

Computes the (generalized) Sturm sequence of p and q in Z[x] or Q[x]. If q = diff(p, x, 1) it is the usual Sturm sequence.

  1. If method == 0, default, the remainder coefficients of the sequence are (in absolute value) ``modified’’ subresultants, which for non-monic polynomials are greater than the coefficients of the corresponding subresultants by the factor Abs(LC(p)**( deg(p)- deg(q))).

  2. If method == 1, the remainder coefficients of the sequence are (in absolute value) subresultants, which for non-monic polynomials are smaller than the coefficients of the corresponding ``modified’’ subresultants by the factor Abs(LC(p)**( deg(p)- deg(q))).

If the Sturm sequence is complete, method=0 and LC( p ) > 0, the coefficients of the polynomials in the sequence are ``modified’’ subresultants. That is, they are determinants of appropriately selected submatrices of sylvester2, Sylvester’s matrix of 1853. In this case the Sturm sequence coincides with the ``modified’’ subresultant prs, of the polynomials p, q.

If the Sturm sequence is incomplete and method=0 then the signs of the coefficients of the polynomials in the sequence may differ from the signs of the coefficients of the corresponding polynomials in the ``modified’’ subresultant prs; however, the absolute values are the same.

To compute the coefficients, no determinant evaluation takes place. Instead, polynomial divisions in Q[x] are performed, using the function rem(p, q, x); the coefficients of the remainders computed this way become (``modified’’) subresultants with the help of the Pell-Gordon Theorem of 1917. See also the function euclid_pg(p, q, x).

References:

1. Pell A. J., R. L. Gordon. The Modified Remainders Obtained in Finding the Highest Common Factor of Two Polynomials. Annals of MatheMatics, Second Series, 18 (1917), No. 4, 188–193.

2. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``Sturm Sequences and Modified Subresultant Polynomial Remainder Sequences.’’ Serdica Journal of Computing, Vol. 8, No 1, 29–46, 2014.

modelparameters.sympy.polys.subresultants_qq_zz.sturm_q(p, q, x)[source]

p, q are polynomials in Z[x] or Q[x]. It is assumed that degree(p, x) >= degree(q, x).

Computes the (generalized) Sturm sequence of p and q in Q[x]. Polynomial divisions in Q[x] are performed, using the function rem(p, q, x).

The coefficients of the polynomials in the Sturm sequence can be uniquely determined from the corresponding coefficients of the polynomials found either in:

  1. the ``modified’’ subresultant prs, (references 1, 2)

or in

  1. the subresultant prs (reference 3).

References:

1. Pell A. J., R. L. Gordon. The Modified Remainders Obtained in Finding the Highest Common Factor of Two Polynomials. Annals of MatheMatics, Second Series, 18 (1917), No. 4, 188–193.

2 Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``Sturm Sequences and Modified Subresultant Polynomial Remainder Sequences.’’ Serdica Journal of Computing, Vol. 8, No 1, 29–46, 2014.

3. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``A Basic Result on the Theory of Subresultants.’’ Submitted for publication.

modelparameters.sympy.polys.subresultants_qq_zz.subresultants_amv(f, g, x)[source]

p, q are polynomials in Z[x] or Q[x]. It is assumed that degree(f, x) >= degree(g, x).

Computes the subresultant prs of p and q in Z[x] or Q[x]; the coefficients of the polynomials in the sequence are subresultants. That is, they are determinants of appropriately selected submatrices of sylvester1, Sylvester’s matrix of 1840.

To compute the coefficients, no determinant evaluation takes place. Instead, polynomial divisions in Z[x] or Q[x] are performed, using the function rem_z(p, q, x); the coefficients of the remainders computed this way become subresultants with the help of the Akritas-Malaschonok-Vigklas Theorem of 2015 and the Collins-Brown- Traub formula for coefficient reduction.

If the subresultant prs is complete, then it coincides with the Euclidean sequence of the polynomials p, q.

References:

1. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``A Basic Result on the Theory of Subresultants.’’ Submitted for publication.

2. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``Subresultant Polynomial remainder Sequences Obtained by Polynomial Divisions in Q[x] or in Z[x].’’ Submitted for publication.

modelparameters.sympy.polys.subresultants_qq_zz.subresultants_amv_q(p, q, x)[source]

p, q are polynomials in Z[x] or Q[x]. It is assumed that degree(p, x) >= degree(q, x).

Computes the subresultant prs of p and q in Q[x]; the coefficients of the polynomials in the sequence are subresultants. That is, they are determinants of appropriately selected submatrices of sylvester1, Sylvester’s matrix of 1840.

To compute the coefficients, no determinant evaluation takes place. Instead, polynomial divisions in Q[x] are performed, using the function rem(p, q, x); the coefficients of the remainders computed this way become subresultants with the help of the Akritas-Malaschonok-Vigklas Theorem of 2015.

If the subresultant prs is complete, then it coincides with the Euclidean sequence of the polynomials p, q.

References:

1. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``A Basic Result on the Theory of Subresultants.’’ Submitted for publication.

2. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``Subresultant Polynomial remainder Sequences Obtained by Polynomial Divisions in Q[x] or in Z[x].’’ Submitted for publication.

modelparameters.sympy.polys.subresultants_qq_zz.subresultants_bezout(p, q, x)[source]

The input polynomials p, q are in Z[x] or in Q[x]. It is assumed that degree(p, x) >= degree(q, x).

Computes the subresultant polynomial remainder sequence of p, q by evaluating determinants of appropriately selected submatrices of bezout(p, q, x, ‘prs’). The dimensions of the latter are deg(p) x deg(p).

Each coefficient is computed by evaluating the determinant of the corresponding submatrix of bezout(p, q, x, ‘prs’).

bezout(p, q, x, ‘prs) is used instead of sylvester(p, q, x, 1), Sylvester’s matrix of 1840, because the dimensions of the latter are (deg(p) + deg(q)) x (deg(p) + deg(q)).

If the subresultant prs is complete, then the output coincides with the Euclidean sequence of the polynomials p, q.

References:

1. G.M.Diaz-Toca,L.Gonzalez-Vega: Various New Expressions for Subresultants and Their Applications. Appl. Algebra in Engin., Communic. and Comp., Vol. 15, 233–266, 2004.

modelparameters.sympy.polys.subresultants_qq_zz.subresultants_pg(p, q, x)[source]

p, q are polynomials in Z[x] or Q[x]. It is assumed that degree(p, x) >= degree(q, x).

Computes the subresultant prs of p and q in Z[x] or Q[x], from the modified subresultant prs of p and q.

The coefficients of the polynomials in these two sequences differ only in sign and the factor LC(p)**( deg(p)- deg(q)) as stated in Theorem 2 of the reference.

The coefficients of the polynomials in the output sequence are subresultants. That is, they are determinants of appropriately selected submatrices of sylvester1, Sylvester’s matrix of 1840.

If the subresultant prs is complete, then it coincides with the Euclidean sequence of the polynomials p, q.

References:

1. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ‘‘On the Remainders Obtained in Finding the Greatest Common Divisor of Two Polynomials.’’ Serdica Journal of Computing, to appear.

modelparameters.sympy.polys.subresultants_qq_zz.subresultants_rem(p, q, x)[source]

p, q are polynomials in Z[x] or Q[x]. It is assumed that degree(p, x) >= degree(q, x).

Computes the subresultant prs of p and q in Z[x] or Q[x]; the coefficients of the polynomials in the sequence are subresultants. That is, they are determinants of appropriately selected submatrices of sylvester1, Sylvester’s matrix of 1840.

To compute the coefficients polynomial divisions in Q[x] are performed, using the function rem(p, q, x). The coefficients of the remainders computed this way become subresultants by evaluating one subresultant per remainder — that of the leading coefficient. This way we obtain the correct sign and value of the leading coefficient of the remainder and we easily ``force’’ the rest of the coefficients to become subresultants.

If the subresultant prs is complete, then it coincides with the Euclidean sequence of the polynomials p, q.

References:

1. Akritas, A. G.:``Three New Methods for Computing Subresultant Polynomial Remainder Sequences (PRS’s).’’ Serdica Journal of Computing, to appear.

modelparameters.sympy.polys.subresultants_qq_zz.subresultants_vv(p, q, x, method=0)[source]

p, q are polynomials in Z[x] (intended) or Q[x]. It is assumed that degree(p, x) >= degree(q, x).

Computes the subresultant prs of p, q by triangularizing, in Z[x] or in Q[x], all the smaller matrices encountered in the process of triangularizing sylvester2, Sylvester’s matrix of 1853; see references 1 and 2 for Van Vleck’s method. With each remainder, sylvester2 gets updated and is prepared to be printed if requested.

If sylvester2 has small dimensions and you want to see the final, triangularized matrix use this version with method=1; otherwise, use either this version with method=0 (default) or the faster version, subresultants_vv_2(p, q, x), where sylvester2 is used implicitly.

Sylvester’s matrix sylvester1 is also used to compute one subresultant per remainder; namely, that of the leading coefficient, in order to obtain the correct sign and to force the remainder coefficients to become subresultants.

If the subresultant prs is complete, then it coincides with the Euclidean sequence of the polynomials p, q.

If the final, triangularized matrix s2 is printed, then:
  1. if deg(p) - deg(q) > 1 or deg( gcd(p, q) ) > 0, several of the last rows in s2 will remain unprocessed;

  2. if deg(p) - deg(q) == 0, p will not appear in the final matrix.

References:

1. Akritas, A. G.: ``A new method for computing polynomial greatest common divisors and polynomial remainder sequences.’’ Numerische MatheMatik 52, 119-127, 1988.

2. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``On a Theorem by Van Vleck Regarding Sturm Sequences.’’ Serdica Journal of Computing, 7, No 4, 101–134, 2013.

3. Akritas, A. G.:``Three New Methods for Computing Subresultant Polynomial Remainder Sequences (PRS’s).’’ Serdica Journal of Computing, to appear.

modelparameters.sympy.polys.subresultants_qq_zz.subresultants_vv_2(p, q, x)[source]

p, q are polynomials in Z[x] (intended) or Q[x]. It is assumed that degree(p, x) >= degree(q, x).

Computes the subresultant prs of p, q by triangularizing, in Z[x] or in Q[x], all the smaller matrices encountered in the process of triangularizing sylvester2, Sylvester’s matrix of 1853; see references 1 and 2 for Van Vleck’s method.

If the sylvester2 matrix has big dimensions use this version, where sylvester2 is used implicitly. If you want to see the final, triangularized matrix sylvester2, then use the first version, subresultants_vv(p, q, x, 1).

sylvester1, Sylvester’s matrix of 1840, is also used to compute one subresultant per remainder; namely, that of the leading coefficient, in order to obtain the correct sign and to ``force’’ the remainder coefficients to become subresultants.

If the subresultant prs is complete, then it coincides with the Euclidean sequence of the polynomials p, q.

References:

1. Akritas, A. G.: ``A new method for computing polynomial greatest common divisors and polynomial remainder sequences.’’ Numerische MatheMatik 52, 119-127, 1988.

2. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``On a Theorem by Van Vleck Regarding Sturm Sequences.’’ Serdica Journal of Computing, 7, No 4, 101–134, 2013.

3. Akritas, A. G.:``Three New Methods for Computing Subresultant Polynomial Remainder Sequences (PRS’s).’’ Serdica Journal of Computing, to appear.

modelparameters.sympy.polys.subresultants_qq_zz.sylvester(f, g, x, method=1)[source]

The input polynomials f, g are in Z[x] or in Q[x]. Let mx = max( degree(f, x) , degree(g, x) ).

  1. If method = 1 (default), computes sylvester1, Sylvester’s matrix of 1840

    of dimension (m + n) x (m + n). The determinants of properly chosen submatrices of this matrix (a.k.a. subresultants) can be used to compute the coefficients of the Euclidean PRS of f, g.

  2. If method = 2, computes sylvester2, Sylvester’s matrix of 1853

    of dimension (2*mx) x (2*mx). The determinants of properly chosen submatrices of this matrix (a.k.a. ``modified’’ subresultants) can be used to compute the coefficients of the Sturmian PRS of f, g.

Applications of these Matrices can be found in the references below. Especially, for applications of sylvester2, see the first reference!!

References:

1. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``On a Theorem by Van Vleck Regarding Sturm Sequences. Serdica Journal of Computing, Vol. 7, No 4, 101–134, 2013.

2. Akritas, A. G., G.I. Malaschonok and P.S. Vigklas: ``Sturm Sequences and Modified Subresultant Polynomial Remainder Sequences.’’ Serdica Journal of Computing, Vol. 8, No 1, 29–46, 2014.

Module contents

Polynomial manipulation algorithms and algebraic objects.

class modelparameters.sympy.polys.AlgebraicField(dom, *ext)[source]

Bases: Field, CharacteristicZero, SimpleDomain

A class for representing algebraic number fields.

algebraic_field(*extension)[source]

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

denom(a)[source]

Returns denominator of a.

dtype

alias of ANP

from_QQ_gmpy(a, K0)[source]

Convert a GMPY mpq object to dtype.

from_QQ_python(a, K0)[source]

Convert a Python Fraction object to dtype.

from_RealField(a, K0)[source]

Convert a mpmath mpf object to dtype.

from_ZZ_gmpy(a, K0)[source]

Convert a GMPY mpz object to dtype.

from_ZZ_python(a, K0)[source]

Convert a Python int object to dtype.

from_sympy(a)[source]

Convert SymPy’s expression to dtype.

get_ring()[source]

Returns a ring associated with self.

has_assoc_Field = True
has_assoc_Ring = False
is_Algebraic = True
is_AlgebraicField = True
is_Numerical = True
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.

new(element)[source]
numer(a)[source]

Returns numerator of a.

to_sympy(a)[source]

Convert a to a SymPy object.

exception modelparameters.sympy.polys.BasePolynomialError[source]

Bases: Exception

Base class for polynomial related exceptions.

new(*args)[source]
modelparameters.sympy.polys.CRootOf

alias of ComplexRootOf

exception modelparameters.sympy.polys.CoercionFailed[source]

Bases: BasePolynomialError

class modelparameters.sympy.polys.ComplexField(prec=53, dps=None, tol=None)[source]

Bases: Field, CharacteristicZero, SimpleDomain

Complex numbers up to the given precision.

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

Check if a and b are almost equal.

property dps
from_ComplexField(element, base)[source]

Convert a complex element to dtype.

from_QQ_gmpy(element, base)[source]

Convert a GMPY mpq object to dtype.

from_QQ_python(element, base)[source]

Convert a Python Fraction object to dtype.

from_RealField(element, base)[source]

Convert a real element object to dtype.

from_ZZ_gmpy(element, base)[source]

Convert a GMPY mpz object to dtype.

from_ZZ_python(element, base)[source]

Convert a Python int object to dtype.

from_sympy(expr)[source]

Convert SymPy’s number to dtype.

gcd(a, b)[source]

Returns GCD of a and b.

get_exact()[source]

Returns an exact domain associated with self.

get_ring()[source]

Returns a ring associated with self.

has_assoc_Field = True
has_assoc_Ring = False
property has_default_precision
is_CC = True
is_ComplexField = True
is_Exact = False
is_Numerical = True
lcm(a, b)[source]

Returns LCM of a and b.

property precision
rep = 'CC'
to_sympy(element)[source]

Convert element to SymPy number.

property tolerance
class modelparameters.sympy.polys.ComplexRootOf(f, x, index=None, radicals=False, expand=True)[source]

Bases: RootOf

Represents an indexed complex root of a polynomial.

Roots of a univariate polynomial separated into disjoint real or complex intervals and indexed in a fixed order. Currently only rational coefficients are allowed. Can be imported as CRootOf.

classmethod all_roots(poly, radicals=True)[source]

Get real and complex roots of a polynomial.

property args

Returns a tuple of arguments of ‘self’.

Examples

>>> from .. import cot
>>> from ..abc import x, y
>>> cot(x).args
(x,)
>>> cot(x).args[0]
x
>>> (x*y).args
(x, y)
>>> (x*y).args[1]
y

Notes

Never use self._args, always use self.args. Only use _args in __new__ when creating a new function. Don’t override .args() from Basic (so that it’s easy to change the interface in the future if needed).

default_assumptions = {'commutative': True, 'complex': True}
eval_rational(tol)[source]

Return a Rational approximation to self with the tolerance tol.

This method uses bisection, which is very robust and it will always converge. The returned Rational instance will be at most ‘tol’ from the exact root.

The following example first obtains Rational approximation to 1e-7 accuracy for all roots of the 4-th order Legendre polynomial, and then evaluates it to 5 decimal digits (so all digits will be correct including rounding):

>>> from .. import S, legendre_poly, Symbol
>>> x = Symbol("x")
>>> p = legendre_poly(4, x, polys=True)
>>> roots = [r.eval_rational(S(1)/10**7) for r in p.real_roots()]
>>> roots = [str(r.n(5)) for r in roots]
>>> roots
['-0.86114', '-0.33998', '0.33998', '0.86114']
property expr
property free_symbols

Return from the atoms of self those which are free symbols.

For most expressions, all symbols are free symbols. For some classes this is not true. e.g. Integrals use Symbols for the dummy variables which are bound variables, so Integral has a method to return all symbols except those. Derivative keeps track of symbols with respect to which it will perform a derivative; those are bound variables, too, so it has its own free_symbols method.

Any other method that uses bound variables should implement a free_symbols method.

index
is_commutative = True
is_complex = True
is_number = True
classmethod real_roots(poly, radicals=True)[source]

Get real roots of a polynomial.

exception modelparameters.sympy.polys.ComputationFailed(func, nargs, exc)[source]

Bases: BasePolynomialError

class modelparameters.sympy.polys.Domain[source]

Bases: object

Represents an abstract domain.

abs(a)[source]

Absolute value of a, implies __abs__.

add(a, b)[source]

Sum of a and b, implies __add__.

algebraic_field(*extension)[source]

Returns an algebraic field, i.e. K(alpha, ldots).

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

Check if a and b are almost equal.

characteristic()[source]

Return the characteristic of this domain.

cofactors(a, b)[source]

Returns GCD and cofactors of a and b.

convert(element, base=None)[source]

Convert element to self.dtype.

convert_from(element, base)[source]

Convert element to self.dtype given the base domain.

denom(a)[source]

Returns denominator of a.

div(a, b)[source]

Division of a and b, implies something.

dtype = None
evalf(a, prec=None, **options)[source]

Returns numerical approximation of a.

exquo(a, b)[source]

Exact quotient of a and b, implies something.

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

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

from_AlgebraicField(a, K0)[source]

Convert an algebraic number to dtype.

from_ComplexField(a, K0)[source]

Convert a complex element to dtype.

from_ExpressionDomain(a, K0)[source]

Convert a EX object to dtype.

from_FF_gmpy(a, K0)[source]

Convert ModularInteger(mpz) to dtype.

from_FF_python(a, K0)[source]

Convert ModularInteger(int) to dtype.

from_FractionField(a, K0)[source]

Convert a rational function to dtype.

from_GeneralizedPolynomialRing(a, K0)[source]
from_GlobalPolynomialRing(a, K0)[source]

Convert a polynomial to dtype.

from_PolynomialRing(a, K0)[source]

Convert a polynomial to dtype.

from_QQ_gmpy(a, K0)[source]

Convert a GMPY mpq object to dtype.

from_QQ_python(a, K0)[source]

Convert a Python Fraction object to dtype.

from_RealField(a, K0)[source]

Convert a real element object to dtype.

from_ZZ_gmpy(a, K0)[source]

Convert a GMPY mpz object to dtype.

from_ZZ_python(a, K0)[source]

Convert a Python int object to dtype.

from_sympy(a)[source]

Convert a SymPy object to dtype.

gcd(a, b)[source]

Returns GCD of a and b.

gcdex(a, b)[source]

Extended GCD of a and b.

get_exact()[source]

Returns an exact domain associated with self.

get_field()[source]

Returns a field associated with self.

get_ring()[source]

Returns a ring associated with self.

half_gcdex(a, b)[source]

Half extended GCD of a and b.

has_CharacteristicZero = False
property has_Field
property has_Ring
has_assoc_Field = False
has_assoc_Ring = False
imag(a)[source]
inject(*symbols)[source]

Inject generators into this domain.

invert(a, b)[source]

Returns inversion of a mod b, implies something.

is_Algebraic = False
is_AlgebraicField = False
is_CC = False
is_ComplexField = False
is_Composite = False
is_EX = False
is_Exact = True
is_FF = False
is_Field = False
is_FiniteField = False
is_Frac = False
is_FractionField = False
is_IntegerRing = False
is_Numerical = False
is_PID = False
is_Poly = False
is_PolynomialRing = False
is_QQ = False
is_RR = False
is_RationalField = False
is_RealField = False
is_Ring = False
is_Simple = False
is_SymbolicDomain = False
is_ZZ = False
is_negative(a)[source]

Returns True if a is negative.

is_nonnegative(a)[source]

Returns True if a is non-negative.

is_nonpositive(a)[source]

Returns True if a is non-positive.

is_one(a)[source]

Returns True if a is one.

is_positive(a)[source]

Returns True if a is positive.

is_zero(a)[source]

Returns True if a is zero.

lcm(a, b)[source]

Returns LCM of a and b.

log(a, b)[source]

Returns b-base logarithm of a.

map(seq)[source]

Rersively apply self to all elements of seq.

mul(a, b)[source]

Product of a and b, implies __mul__.

n(a, prec=None, **options)

Returns numerical approximation of a.

neg(a)[source]

Returns a negated, implies __neg__.

new(*args)[source]
normal(*args)[source]
numer(a)[source]

Returns numerator of a.

of_type(element)[source]

Check if a is of type dtype.

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

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

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

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

one = None
poly_ring(*symbols, **kwargs)[source]

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

pos(a)[source]

Returns a positive, implies __pos__.

pow(a, b)[source]

Raise a to power b, implies __pow__.

quo(a, b)[source]

Quotient of a and b, implies something.

real(a)[source]
rem(a, b)[source]

Remainder of a and b, implies __mod__.

rep = None
revert(a)[source]

Returns a**(-1) if possible.

sqrt(a)[source]

Returns square root of a.

sub(a, b)[source]

Difference of a and b, implies __sub__.

to_sympy(a)[source]

Convert a to a SymPy object.

property tp
unify(K1, symbols=None)[source]

Construct a minimal domain that contains elements of K0 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

unify_with_symbols(K1, symbols)[source]
zero = None
exception modelparameters.sympy.polys.DomainError[source]

Bases: BasePolynomialError

exception modelparameters.sympy.polys.EvaluationFailed[source]

Bases: BasePolynomialError

exception modelparameters.sympy.polys.ExactQuotientFailed(f, g, dom=None)[source]

Bases: BasePolynomialError

new(f, g)[source]
class modelparameters.sympy.polys.ExpressionDomain[source]

Bases: Field, CharacteristicZero, SimpleDomain

A class for arbitrary expressions.

class Expression(ex)[source]

Bases: PicklableWithSlots

An arbitrary expression.

as_expr()[source]
denom()[source]
ex
gcd(g)[source]
lcm(g)[source]
numer()[source]
simplify(ex)[source]
denom(a)[source]

Returns denominator of a.

dtype

alias of Expression

from_ExpressionDomain(a, K0)[source]

Convert a EX object to dtype.

from_FractionField(a, K0)[source]

Convert a DMF object to dtype.

from_PolynomialRing(a, K0)[source]

Convert a DMP object to dtype.

from_QQ_gmpy(a, K0)[source]

Convert a GMPY mpq object to dtype.

from_QQ_python(a, K0)[source]

Convert a Python Fraction object to dtype.

from_RealField(a, K0)[source]

Convert a mpmath mpf object to dtype.

from_ZZ_gmpy(a, K0)[source]

Convert a GMPY mpz object to dtype.

from_ZZ_python(a, K0)[source]

Convert a Python int object to dtype.

from_sympy(a)[source]

Convert SymPy’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().

>>> from ..domains import QQ
>>> from ... import S, gcd, primitive
>>> from ...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()[source]

Returns a field associated with self.

get_ring()[source]

Returns a ring associated with self.

has_assoc_Field = True
has_assoc_Ring = False
is_EX = True
is_SymbolicDomain = True
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.

>>> from ..domains import QQ
>>> from ... import S, lcm
>>> QQ.lcm(QQ(2, 3), QQ(4, 9))
4/3
>>> lcm(S(2)/3, S(4)/9)
4/3
numer(a)[source]

Returns numerator of a.

one = EX(1)
rep = 'EX'
to_sympy(a)[source]

Convert a to a SymPy object.

zero = EX(0)
exception modelparameters.sympy.polys.ExtraneousFactors[source]

Bases: BasePolynomialError

modelparameters.sympy.polys.FF

alias of PythonFiniteField

modelparameters.sympy.polys.FF_gmpy

alias of GMPYFiniteField

modelparameters.sympy.polys.FF_python

alias of PythonFiniteField

class modelparameters.sympy.polys.FiniteField(mod, dom=None, symmetric=True)[source]

Bases: Field, SimpleDomain

General class for finite fields.

characteristic()[source]

Return the characteristic of this domain.

dom = None
from_FF_gmpy(a, K0=None)[source]

Convert ModularInteger(mpz) to dtype.

from_FF_python(a, K0=None)[source]

Convert ModularInteger(int) to dtype.

from_QQ_gmpy(a, K0=None)[source]

Convert GMPY’s mpq to dtype.

from_QQ_python(a, K0=None)[source]

Convert Python’s Fraction to dtype.

from_RealField(a, K0)[source]

Convert mpmath’s mpf to dtype.

from_ZZ_gmpy(a, K0=None)[source]

Convert GMPY’s mpz to dtype.

from_ZZ_python(a, K0=None)[source]

Convert Python’s int to dtype.

from_sympy(a)[source]

Convert SymPy’s Integer to SymPy’s Integer.

get_field()[source]

Returns a field associated with self.

has_assoc_Field = True
has_assoc_Ring = False
is_FF = True
is_FiniteField = True
is_Numerical = True
mod = None
rep = 'FF'
to_sympy(a)[source]

Convert a to a SymPy object.

exception modelparameters.sympy.polys.FlagError[source]

Bases: OptionError

class modelparameters.sympy.polys.FractionField(domain_or_field, symbols=None, order=None)[source]

Bases: Field, CompositeDomain

A class for representing multivariate rational function fields.

denom(a)[source]

Returns denominator of a.

factorial(a)[source]

Returns factorial of a.

from_AlgebraicField(a, K0)[source]

Convert an algebraic number to dtype.

from_FractionField(a, K0)[source]

Convert a rational function to dtype.

from_PolynomialRing(a, K0)[source]

Convert a polynomial to dtype.

from_QQ_gmpy(a, K0)[source]

Convert a GMPY mpq object to dtype.

from_QQ_python(a, K0)[source]

Convert a Python Fraction object to dtype.

from_RealField(a, K0)[source]

Convert a mpmath mpf object to dtype.

from_ZZ_gmpy(a, K0)[source]

Convert a GMPY mpz object to dtype.

from_ZZ_python(a, K0)[source]

Convert a Python int object to dtype.

from_sympy(a)[source]

Convert SymPy’s expression to dtype.

get_ring()[source]

Returns a field associated with self.

has_assoc_Field = True
has_assoc_Ring = True
is_Frac = True
is_FractionField = True
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.

new(element)[source]
numer(a)[source]

Returns numerator of a.

property one
property order
to_sympy(a)[source]

Convert a to a SymPy object.

property zero
modelparameters.sympy.polys.GF

alias of PythonFiniteField

class modelparameters.sympy.polys.GMPYFiniteField(mod, symmetric=True)[source]

Bases: FiniteField

Finite field based on GMPY integers.

alias = 'FF_gmpy'
class modelparameters.sympy.polys.GMPYIntegerRing[source]

Bases: IntegerRing

Integer ring based on GMPY’s mpz type.

alias = 'ZZ_gmpy'
dtype

alias of GMPYInteger

factorial(a)[source]

Compute factorial of a.

from_FF_gmpy(a, K0)[source]

Convert ModularInteger(mpz) to GMPY’s mpz.

from_FF_python(a, K0)[source]

Convert ModularInteger(int) to GMPY’s mpz.

from_QQ_gmpy(a, K0)[source]

Convert GMPY mpq to GMPY’s mpz.

from_QQ_python(a, K0)[source]

Convert Python’s Fraction to GMPY’s mpz.

from_RealField(a, K0)[source]

Convert mpmath’s mpf to GMPY’s mpz.

from_ZZ_gmpy(a, K0)[source]

Convert GMPY’s mpz to GMPY’s mpz.

from_ZZ_python(a, K0)[source]

Convert Python’s int to GMPY’s mpz.

from_sympy(a)[source]

Convert SymPy’s Integer to dtype.

gcd(a, b)[source]

Compute GCD of a and b.

gcdex(a, b)[source]

Compute extended GCD of a and b.

lcm(a, b)[source]

Compute LCM of a and b.

one = <modelparameters.sympy.polys.domains.groundtypes.GMPYInteger object>
sqrt(a)[source]

Compute square root of a.

to_sympy(a)[source]

Convert a to a SymPy object.

tp

alias of GMPYInteger

zero = <modelparameters.sympy.polys.domains.groundtypes.GMPYInteger object>
class modelparameters.sympy.polys.GMPYRationalField[source]

Bases: RationalField

Rational field based on GMPY mpq class.

alias = 'QQ_gmpy'
denom(a)[source]

Returns denominator of a.

div(a, b)[source]

Division of a and b, implies __div__.

dtype

alias of GMPYRational

exquo(a, b)[source]

Exact quotient of a and b, implies __div__.

factorial(a)[source]

Returns factorial of a.

from_QQ_gmpy(a, K0)[source]

Convert a GMPY mpq object to dtype.

from_QQ_python(a, K0)[source]

Convert a Python Fraction object to dtype.

from_RealField(a, K0)[source]

Convert a mpmath mpf object to dtype.

from_ZZ_gmpy(a, K0)[source]

Convert a GMPY mpz object to dtype.

from_ZZ_python(a, K0)[source]

Convert a Python int object to dtype.

from_sympy(a)[source]

Convert SymPy’s Integer to dtype.

get_ring()[source]

Returns ring associated with self.

numer(a)[source]

Returns numerator of a.

one = <modelparameters.sympy.polys.domains.groundtypes.GMPYRational object>
quo(a, b)[source]

Quotient of a and b, implies __div__.

rem(a, b)[source]

Remainder of a and b, implies nothing.

to_sympy(a)[source]

Convert a to a SymPy object.

tp

alias of GMPYRational

zero = <modelparameters.sympy.polys.domains.groundtypes.GMPYRational object>
exception modelparameters.sympy.polys.GeneratorsError[source]

Bases: BasePolynomialError

exception modelparameters.sympy.polys.GeneratorsNeeded[source]

Bases: GeneratorsError

class modelparameters.sympy.polys.GroebnerBasis(F, *gens, **args)[source]

Bases: Basic

Represents a reduced Groebner basis.

property args

Returns a tuple of arguments of ‘self’.

Examples

>>> from .. import cot
>>> from ..abc import x, y
>>> cot(x).args
(x,)
>>> cot(x).args[0]
x
>>> (x*y).args
(x, y)
>>> (x*y).args[1]
y

Notes

Never use self._args, always use self.args. Only use _args in __new__ when creating a new function. Don’t override .args() from Basic (so that it’s easy to change the interface in the future if needed).

contains(poly)[source]

Check if poly belongs the ideal generated by self.

Examples

>>> from .. import groebner
>>> from ..abc import x, y
>>> f = 2*x**3 + y**3 + 3*y
>>> G = groebner([x**2 + y**2 - 1, x*y - 2])
>>> G.contains(f)
True
>>> G.contains(f + 1)
False
default_assumptions = {}
property domain
property exprs
fglm(order)[source]

Convert a Groebner basis from one ordering to another.

The FGLM algorithm converts reduced Groebner bases of zero-dimensional ideals from one ordering to another. This method is often used when it is infeasible to compute a Groebner basis with respect to a particular ordering directly.

Examples

>>> from ..abc import x, y
>>> from .. import groebner
>>> F = [x**2 - 3*y - x + 1, y**2 - 2*x + y - 1]
>>> G = groebner(F, x, y, order='grlex')
>>> list(G.fglm('lex'))
[2*x - y**2 - y + 1, y**4 + 2*y**3 - 3*y**2 - 16*y + 7]
>>> list(groebner(F, x, y, order='lex'))
[2*x - y**2 - y + 1, y**4 + 2*y**3 - 3*y**2 - 16*y + 7]

References

J.C. Faugere, P. Gianni, D. Lazard, T. Mora (1994). Efficient Computation of Zero-dimensional Groebner Bases by Change of Ordering

property gens
property is_zero_dimensional

Checks if the ideal generated by a Groebner basis is zero-dimensional.

The algorithm checks if the set of monomials not divisible by the leading monomial of any element of F is bounded.

References

David A. Cox, John B. Little, Donal O’Shea. Ideals, Varieties and Algorithms, 3rd edition, p. 230

property order
property polys
reduce(expr, auto=True)[source]

Reduces a polynomial modulo a Groebner basis.

Given a polynomial f and a set of polynomials G = (g_1, ..., g_n), computes a set of quotients q = (q_1, ..., q_n) and the remainder r such that f = q_1*f_1 + ... + q_n*f_n + r, where r vanishes or r is a completely reduced polynomial with respect to G.

Examples

>>> from .. import groebner, expand
>>> from ..abc import x, y
>>> f = 2*x**4 - x**2 + y**3 + y**2
>>> G = groebner([x**3 - x, y**3 - y])
>>> G.reduce(f)
([2*x, 1], x**2 + y**2 + y)
>>> Q, r = _
>>> expand(sum(q*g for q, g in zip(Q, G)) + r)
2*x**4 - x**2 + y**3 + y**2
>>> _ == f
True
exception modelparameters.sympy.polys.HeuristicGCDFailed[source]

Bases: BasePolynomialError

exception modelparameters.sympy.polys.HomomorphismFailed[source]

Bases: BasePolynomialError

class modelparameters.sympy.polys.IntegerRing[source]

Bases: Ring, CharacteristicZero, SimpleDomain

General class for integer rings.

algebraic_field(*extension)[source]

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

from_AlgebraicField(a, K0)[source]

Convert a ANP object to dtype.

get_field()[source]

Returns a field associated with self.

has_assoc_Field = True
has_assoc_Ring = True
is_IntegerRing = True
is_Numerical = True
is_PID = True
is_ZZ = True
log(a, b)[source]

Returns b-base logarithm of a.

rep = 'ZZ'
exception modelparameters.sympy.polys.IsomorphismFailed[source]

Bases: BasePolynomialError

modelparameters.sympy.polys.LC(f, *gens, **args)[source]

Return the leading coefficient of f.

Examples

>>> from .. import LC
>>> from ..abc import x, y
>>> LC(4*x**2 + 2*x*y**2 + x*y + 3*y)
4
modelparameters.sympy.polys.LM(f, *gens, **args)[source]

Return the leading monomial of f.

Examples

>>> from .. import LM
>>> from ..abc import x, y
>>> LM(4*x**2 + 2*x*y**2 + x*y + 3*y)
x**2
modelparameters.sympy.polys.LT(f, *gens, **args)[source]

Return the leading term of f.

Examples

>>> from .. import LT
>>> from ..abc import x, y
>>> LT(4*x**2 + 2*x*y**2 + x*y + 3*y)
4*x**2
class modelparameters.sympy.polys.Monomial(monom, gens=None)[source]

Bases: PicklableWithSlots

Class representing a monomial, i.e. a product of powers.

as_expr(*gens)[source]

Convert a monomial instance to a SymPy expression.

exponents
gcd(other)[source]

Greatest common divisor of monomials.

gens
lcm(other)[source]

Least common multiple of monomials.

rebuild(exponents, gens=None)[source]
exception modelparameters.sympy.polys.MultivariatePolynomialError[source]

Bases: PolynomialError

exception modelparameters.sympy.polys.NotAlgebraic[source]

Bases: BasePolynomialError

exception modelparameters.sympy.polys.NotInvertible[source]

Bases: BasePolynomialError

exception modelparameters.sympy.polys.NotReversible[source]

Bases: BasePolynomialError

exception modelparameters.sympy.polys.OperationNotSupported(poly, func)[source]

Bases: BasePolynomialError

exception modelparameters.sympy.polys.OptionError[source]

Bases: BasePolynomialError

class modelparameters.sympy.polys.Options(gens, args, flags=None, strict=False)[source]

Bases: dict

Options manager for polynomial manipulation module.

Examples

>>> from .polyoptions import Options
>>> from .polyoptions import build_options
>>> from ..abc import x, y, z
>>> Options((x, y, z), {'domain': 'ZZ'})
{'auto': False, 'domain': ZZ, 'gens': (x, y, z)}
>>> build_options((x, y, z), {'domain': 'ZZ'})
{'auto': False, 'domain': ZZ, 'gens': (x, y, z)}

Options

  • Expand — boolean option

  • Gens — option

  • Wrt — option

  • Sort — option

  • Order — option

  • Field — boolean option

  • Greedy — boolean option

  • Domain — option

  • Split — boolean option

  • Gaussian — boolean option

  • Extension — option

  • Modulus — option

  • Symmetric — boolean option

  • Strict — boolean option

Flags

  • Auto — boolean flag

  • Frac — boolean flag

  • Formal — boolean flag

  • Polys — boolean flag

  • Include — boolean flag

  • All — boolean flag

  • Gen — flag

  • Series — boolean flag

property all
property args
property auto
clone(updates={})[source]

Clone self and update specified options.

property composite
property domain
property expand
property extension
property field
property flags
property formal
property frac
property gaussian
property gen
property gens
property greedy
property include
property method
property modulus
property options
property order
property polys
property series
property sort
property split
property strict
property symbols
property symmetric
property wrt
exception modelparameters.sympy.polys.PolificationFailed(opt, origs, exprs, seq=False)[source]

Bases: PolynomialError

class modelparameters.sympy.polys.Poly(rep, *gens, **args)[source]

Bases: Expr

Generic class for representing and operating on polynomial expressions. Subclasses Expr class.

Examples

>>> from .. import Poly
>>> from ..abc import x, y

Create a univariate polynomial:

>>> Poly(x*(x**2 + x - 1)**2)
Poly(x**5 + 2*x**4 - x**3 - 2*x**2 + x, x, domain='ZZ')

Create a univariate polynomial with specific domain:

>>> from .. import sqrt
>>> Poly(x**2 + 2*x + sqrt(3), domain='R')
Poly(1.0*x**2 + 2.0*x + 1.73205080756888, x, domain='RR')

Create a multivariate polynomial:

>>> Poly(y*x**2 + x*y + 1)
Poly(x**2*y + x*y + 1, x, y, domain='ZZ')

Create a univariate polynomial, where y is a constant:

>>> Poly(y*x**2 + x*y + 1,x)
Poly(y*x**2 + y*x + 1, x, domain='ZZ[y]')

You can evaluate the above polynomial as a function of y:

>>> Poly(y*x**2 + x*y + 1,x).eval(2)
6*y + 1

See also

sympy.core.expr.Expr

EC(order=None)[source]

Returns the last non-zero coefficient of f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**3 + 2*x**2 + 3*x, x).EC()
3
EM(order=None)[source]

Returns the last non-zero monomial of f.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(4*x**2 + 2*x*y**2 + x*y + 3*y, x, y).EM()
x**0*y**1
ET(order=None)[source]

Returns the last non-zero term of f.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(4*x**2 + 2*x*y**2 + x*y + 3*y, x, y).ET()
(x**0*y**1, 3)
LC(order=None)[source]

Returns the leading coefficient of f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(4*x**3 + 2*x**2 + 3*x, x).LC()
4
LM(order=None)[source]

Returns the leading monomial of f.

The Leading monomial signifies the monomial having the highest power of the principal generator in the expression f.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(4*x**2 + 2*x*y**2 + x*y + 3*y, x, y).LM()
x**2*y**0
LT(order=None)[source]

Returns the leading term of f.

The Leading term signifies the term having the highest power of the principal generator in the expression f along with its coefficient.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(4*x**2 + 2*x*y**2 + x*y + 3*y, x, y).LT()
(x**2*y**0, 4)
TC()[source]

Returns the trailing coefficient of f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**3 + 2*x**2 + 3*x, x).TC()
0
abs()[source]

Make all coefficients in f positive.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 - 1, x).abs()
Poly(x**2 + 1, x, domain='ZZ')
add(g)[source]

Add two polynomials f and g.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 + 1, x).add(Poly(x - 2, x))
Poly(x**2 + x - 1, x, domain='ZZ')
>>> Poly(x**2 + 1, x) + Poly(x - 2, x)
Poly(x**2 + x - 1, x, domain='ZZ')
add_ground(coeff)[source]

Add an element of the ground domain to f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x + 1).add_ground(2)
Poly(x + 3, x, domain='ZZ')
all_coeffs()[source]

Returns all coefficients from a univariate polynomial f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**3 + 2*x - 1, x).all_coeffs()
[1, 0, 2, -1]
all_monoms()[source]

Returns all monomials from a univariate polynomial f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**3 + 2*x - 1, x).all_monoms()
[(3,), (2,), (1,), (0,)]

See also

all_terms

all_roots(multiple=True, radicals=True)[source]

Return a list of real and complex roots with multiplicities.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(2*x**3 - 7*x**2 + 4*x + 4).all_roots()
[-1/2, 2, 2]
>>> Poly(x**3 + x + 1).all_roots()
[CRootOf(x**3 + x + 1, 0),
 CRootOf(x**3 + x + 1, 1),
 CRootOf(x**3 + x + 1, 2)]
all_terms()[source]

Returns all terms from a univariate polynomial f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**3 + 2*x - 1, x).all_terms()
[((3,), 1), ((2,), 0), ((1,), 2), ((0,), -1)]
property args

Don’t mess up with the core.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 + 1, x).args
(x**2 + 1,)
as_dict(native=False, zero=False)[source]

Switch to a dict representation.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(x**2 + 2*x*y**2 - y, x, y).as_dict()
{(0, 1): -1, (1, 2): 2, (2, 0): 1}
as_expr(*gens)[source]

Convert a Poly instance to an Expr instance.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> f = Poly(x**2 + 2*x*y**2 - y, x, y)
>>> f.as_expr()
x**2 + 2*x*y**2 - y
>>> f.as_expr({x: 5})
10*y**2 - y + 25
>>> f.as_expr(5, 6)
379
as_list(native=False)[source]

Switch to a list representation.

cancel(g, include=False)[source]

Cancel common factors in a rational function f/g.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(2*x**2 - 2, x).cancel(Poly(x**2 - 2*x + 1, x))
(1, Poly(2*x + 2, x, domain='ZZ'), Poly(x - 1, x, domain='ZZ'))
>>> Poly(2*x**2 - 2, x).cancel(Poly(x**2 - 2*x + 1, x), include=True)
(Poly(2*x + 2, x, domain='ZZ'), Poly(x - 1, x, domain='ZZ'))
clear_denoms(convert=False)[source]

Clear denominators, but keep the ground domain.

Examples

>>> from .. import Poly, S, QQ
>>> from ..abc import x
>>> f = Poly(x/2 + S(1)/3, x, domain=QQ)
>>> f.clear_denoms()
(6, Poly(3*x + 2, x, domain='QQ'))
>>> f.clear_denoms(convert=True)
(6, Poly(3*x + 2, x, domain='ZZ'))
coeff(x, n=1, right=False)[source]

Returns the coefficient from the term(s) containing x**n. If n is zero then all terms independent of x will be returned.

When x is noncommutative, the coefficient to the left (default) or right of x can be returned. The keyword ‘right’ is ignored when x is commutative.

See also

as_coefficient

separate the expression into a coefficient and factor

as_coeff_Add

separate the additive constant from an expression

as_coeff_Mul

separate the multiplicative constant from an expression

as_independent

separate x-dependent terms/factors from others

sympy.polys.polytools.coeff_monomial

efficiently find the single coefficient of a monomial in Poly

sympy.polys.polytools.nth

like coeff_monomial but powers of monomial terms are used

Examples

>>> from .. import symbols
>>> from ..abc import x, y, z

You can select terms that have an explicit negative in front of them:

>>> (-x + 2*y).coeff(-1)
x
>>> (x - 2*y).coeff(-1)
2*y

You can select terms with no Rational coefficient:

>>> (x + 2*y).coeff(1)
x
>>> (3 + 2*x + 4*x**2).coeff(1)
0

You can select terms independent of x by making n=0; in this case expr.as_independent(x)[0] is returned (and 0 will be returned instead of None):

>>> (3 + 2*x + 4*x**2).coeff(x, 0)
3
>>> eq = ((x + 1)**3).expand() + 1
>>> eq
x**3 + 3*x**2 + 3*x + 2
>>> [eq.coeff(x, i) for i in reversed(range(4))]
[1, 3, 3, 2]
>>> eq -= 2
>>> [eq.coeff(x, i) for i in reversed(range(4))]
[1, 3, 3, 0]

You can select terms that have a numerical term in front of them:

>>> (-x - 2*y).coeff(2)
-y
>>> from .. import sqrt
>>> (x + sqrt(2)*x).coeff(sqrt(2))
x

The matching is exact:

>>> (3 + 2*x + 4*x**2).coeff(x)
2
>>> (3 + 2*x + 4*x**2).coeff(x**2)
4
>>> (3 + 2*x + 4*x**2).coeff(x**3)
0
>>> (z*(x + y)**2).coeff((x + y)**2)
z
>>> (z*(x + y)**2).coeff(x + y)
0

In addition, no factoring is done, so 1 + z*(1 + y) is not obtained from the following:

>>> (x + z*(x + x*y)).coeff(x)
1

If such factoring is desired, factor_terms can be used first:

>>> from .. import factor_terms
>>> factor_terms(x + z*(x + x*y)).coeff(x)
z*(y + 1) + 1
>>> n, m, o = symbols('n m o', commutative=False)
>>> n.coeff(n)
1
>>> (3*n).coeff(n)
3
>>> (n*m + m*n*m).coeff(n) # = (1 + m)*n*m
1 + m
>>> (n*m + m*n*m).coeff(n, right=True) # = (1 + m)*n*m
m

If there is more than one possible coefficient 0 is returned:

>>> (n*m + m*n).coeff(n)
0

If there is only one possible coefficient, it is returned:

>>> (n*m + x*m*n).coeff(m*n)
x
>>> (n*m + x*m*n).coeff(m*n, right=1)
1
coeff_monomial(monom)[source]

Returns the coefficient of monom in f if there, else None.

Examples

>>> from .. import Poly, exp
>>> from ..abc import x, y
>>> p = Poly(24*x*y*exp(8) + 23*x, x, y)
>>> p.coeff_monomial(x)
23
>>> p.coeff_monomial(y)
0
>>> p.coeff_monomial(x*y)
24*exp(8)

Note that Expr.coeff() behaves differently, collecting terms if possible; the Poly must be converted to an Expr to use that method, however:

>>> p.as_expr().coeff(x)
24*y*exp(8) + 23
>>> p.as_expr().coeff(y)
24*x*exp(8)
>>> p.as_expr().coeff(x*y)
24*exp(8)

See also

nth

more efficient query using exponents of the monomial’s generators

coeffs(order=None)[source]

Returns all non-zero coefficients from f in lex order.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**3 + 2*x + 3, x).coeffs()
[1, 2, 3]
cofactors(g)[source]

Returns the GCD of f and g and their cofactors.

Returns polynomials (h, cff, cfg) such that h = gcd(f, g), and cff = quo(f, h) and cfg = quo(g, h) are, so called, cofactors of f and g.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 - 1, x).cofactors(Poly(x**2 - 3*x + 2, x))
(Poly(x - 1, x, domain='ZZ'),
 Poly(x + 1, x, domain='ZZ'),
 Poly(x - 2, x, domain='ZZ'))
compose(g)[source]

Computes the functional composition of f and g.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 + x, x).compose(Poly(x - 1, x))
Poly(x**2 - x, x, domain='ZZ')
content()[source]

Returns the GCD of polynomial coefficients.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(6*x**2 + 8*x + 12, x).content()
2
count_roots(inf=None, sup=None)[source]

Return the number of roots of f in [inf, sup] interval.

Examples

>>> from .. import Poly, I
>>> from ..abc import x
>>> Poly(x**4 - 4, x).count_roots(-3, 3)
2
>>> Poly(x**4 - 4, x).count_roots(0, 1 + 3*I)
1
decompose()[source]

Computes a functional decomposition of f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**4 + 2*x**3 - x - 1, x, domain='ZZ').decompose()
[Poly(x**2 - x - 1, x, domain='ZZ'), Poly(x**2 + x, x, domain='ZZ')]
default_assumptions = {'commutative': True}
deflate()[source]

Reduce degree of f by mapping x_i**m to y_i.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(x**6*y**2 + x**3 + 1, x, y).deflate()
((3, 2), Poly(x**2*y + x + 1, x, y, domain='ZZ'))
degree(gen=0)[source]

Returns degree of f in x_j.

The degree of 0 is negative infinity.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(x**2 + y*x + 1, x, y).degree()
2
>>> Poly(x**2 + y*x + y, x, y).degree(y)
1
>>> Poly(0, x).degree()
-oo
degree_list()[source]

Returns a list of degrees of f.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(x**2 + y*x + 1, x, y).degree_list()
(2, 1)
diff(*specs, **kwargs)[source]

Computes partial derivative of f.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(x**2 + 2*x + 1, x).diff()
Poly(2*x + 2, x, domain='ZZ')
>>> Poly(x*y**2 + x, x, y).diff((0, 0), (1, 1))
Poly(2*x*y, x, y, domain='ZZ')
discriminant()[source]

Computes the discriminant of f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 + 2*x + 3, x).discriminant()
-8
dispersion(g=None)[source]

Compute the dispersion of polynomials.

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

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

and for a single polynomial operatorname{dis}(f) := operatorname{dis}(f, f).

Examples

>>> from .. import poly
>>> from .dispersion import dispersion, dispersionset
>>> from ..abc import x

Dispersion set and dispersion of a simple polynomial:

>>> fp = poly((x - 3)*(x + 3), x)
>>> sorted(dispersionset(fp))
[0, 6]
>>> dispersion(fp)
6

Note that the definition of the dispersion is not symmetric:

>>> fp = poly(x**4 - 3*x**2 + 1, x)
>>> gp = fp.shift(-3)
>>> sorted(dispersionset(fp, gp))
[2, 3, 4]
>>> dispersion(fp, gp)
4
>>> sorted(dispersionset(gp, fp))
[]
>>> dispersion(gp, fp)
-oo

Computing the dispersion also works over field extensions:

>>> from .. import sqrt
>>> fp = poly(x**2 + sqrt(5)*x - 1, x, domain='QQ<sqrt(5)>')
>>> gp = poly(x**2 + (2 + sqrt(5))*x + sqrt(5), x, domain='QQ<sqrt(5)>')
>>> sorted(dispersionset(fp, gp))
[2]
>>> sorted(dispersionset(gp, fp))
[1, 4]

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

>>> from ..abc import a
>>> fp = poly(4*x**4 + (4*a + 8)*x**3 + (a**2 + 6*a + 4)*x**2 + (a**2 + 2*a)*x, x)
>>> sorted(dispersionset(fp))
[0, 1]

See also

dispersionset

References

  1. [ManWright94]

  2. [Koepf98]

  3. [Abramov71]

  4. [Man93]

dispersionset(g=None)[source]

Compute the dispersion set of two polynomials.

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

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

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

Examples

>>> from .. import poly
>>> from .dispersion import dispersion, dispersionset
>>> from ..abc import x

Dispersion set and dispersion of a simple polynomial:

>>> fp = poly((x - 3)*(x + 3), x)
>>> sorted(dispersionset(fp))
[0, 6]
>>> dispersion(fp)
6

Note that the definition of the dispersion is not symmetric:

>>> fp = poly(x**4 - 3*x**2 + 1, x)
>>> gp = fp.shift(-3)
>>> sorted(dispersionset(fp, gp))
[2, 3, 4]
>>> dispersion(fp, gp)
4
>>> sorted(dispersionset(gp, fp))
[]
>>> dispersion(gp, fp)
-oo

Computing the dispersion also works over field extensions:

>>> from .. import sqrt
>>> fp = poly(x**2 + sqrt(5)*x - 1, x, domain='QQ<sqrt(5)>')
>>> gp = poly(x**2 + (2 + sqrt(5))*x + sqrt(5), x, domain='QQ<sqrt(5)>')
>>> sorted(dispersionset(fp, gp))
[2]
>>> sorted(dispersionset(gp, fp))
[1, 4]

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

>>> from ..abc import a
>>> fp = poly(4*x**4 + (4*a + 8)*x**3 + (a**2 + 6*a + 4)*x**2 + (a**2 + 2*a)*x, x)
>>> sorted(dispersionset(fp))
[0, 1]

See also

dispersion

References

  1. [ManWright94]

  2. [Koepf98]

  3. [Abramov71]

  4. [Man93]

div(g, auto=True)[source]

Polynomial division with remainder of f by g.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 + 1, x).div(Poly(2*x - 4, x))
(Poly(1/2*x + 1, x, domain='QQ'), Poly(5, x, domain='QQ'))
>>> Poly(x**2 + 1, x).div(Poly(2*x - 4, x), auto=False)
(Poly(0, x, domain='ZZ'), Poly(x**2 + 1, x, domain='ZZ'))
property domain

Get the ground domain of self.

eject(*gens)[source]

Eject selected generators into the ground domain.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> f = Poly(x**2*y + x*y**3 + x*y + 1, x, y)
>>> f.eject(x)
Poly(x*y**3 + (x**2 + x)*y + 1, y, domain='ZZ[x]')
>>> f.eject(y)
Poly(y*x**2 + (y**3 + y)*x + 1, x, domain='ZZ[y]')
eq(g, strict=False)[source]
eval(x, a=None, auto=True)[source]

Evaluate f at a in the given variable.

Examples

>>> from .. import Poly
>>> from ..abc import x, y, z
>>> Poly(x**2 + 2*x + 3, x).eval(2)
11
>>> Poly(2*x*y + 3*x + y + 2, x, y).eval(x, 2)
Poly(5*y + 8, y, domain='ZZ')
>>> f = Poly(2*x*y + 3*x + y + 2*z, x, y, z)
>>> f.eval({x: 2})
Poly(5*y + 2*z + 6, y, z, domain='ZZ')
>>> f.eval({x: 2, y: 5})
Poly(2*z + 31, z, domain='ZZ')
>>> f.eval({x: 2, y: 5, z: 7})
45
>>> f.eval((2, 5))
Poly(2*z + 31, z, domain='ZZ')
>>> f(2, 5)
Poly(2*z + 31, z, domain='ZZ')
exclude()[source]

Remove unnecessary generators from f.

Examples

>>> from .. import Poly
>>> from ..abc import a, b, c, d, x
>>> Poly(a + x, a, b, c, d, x).exclude()
Poly(a + x, a, x, domain='ZZ')
exquo(g, auto=True)[source]

Computes polynomial exact quotient of f by g.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 - 1, x).exquo(Poly(x - 1, x))
Poly(x + 1, x, domain='ZZ')
>>> Poly(x**2 + 1, x).exquo(Poly(2*x - 4, x))
Traceback (most recent call last):
...
ExactQuotientFailed: 2*x - 4 does not divide x**2 + 1
exquo_ground(coeff)[source]

Exact quotient of f by a an element of the ground domain.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(2*x + 4).exquo_ground(2)
Poly(x + 2, x, domain='ZZ')
>>> Poly(2*x + 3).exquo_ground(2)
Traceback (most recent call last):
...
ExactQuotientFailed: 2 does not divide 3 in ZZ
factor_list()[source]

Returns a list of irreducible factors of f.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> f = 2*x**5 + 2*x**4*y + 4*x**3 + 4*x**2*y + 2*x + 2*y
>>> Poly(f).factor_list()
(2, [(Poly(x + y, x, y, domain='ZZ'), 1),
     (Poly(x**2 + 1, x, y, domain='ZZ'), 2)])
factor_list_include()[source]

Returns a list of irreducible factors of f.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> f = 2*x**5 + 2*x**4*y + 4*x**3 + 4*x**2*y + 2*x + 2*y
>>> Poly(f).factor_list_include()
[(Poly(2*x + 2*y, x, y, domain='ZZ'), 1),
 (Poly(x**2 + 1, x, y, domain='ZZ'), 2)]
property free_symbols

Free symbols of a polynomial expression.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(x**2 + 1).free_symbols
{x}
>>> Poly(x**2 + y).free_symbols
{x, y}
>>> Poly(x**2 + y, x).free_symbols
{x, y}
property free_symbols_in_domain

Free symbols of the domain of self.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(x**2 + 1).free_symbols_in_domain
set()
>>> Poly(x**2 + y).free_symbols_in_domain
set()
>>> Poly(x**2 + y, x).free_symbols_in_domain
{y}
classmethod from_dict(rep, *gens, **args)[source]

Construct a polynomial from a dict.

classmethod from_expr(rep, *gens, **args)[source]

Construct a polynomial from an expression.

classmethod from_list(rep, *gens, **args)[source]

Construct a polynomial from a list.

classmethod from_poly(rep, *gens, **args)[source]

Construct a polynomial from a polynomial.

gcd(g)[source]

Returns the polynomial GCD of f and g.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 - 1, x).gcd(Poly(x**2 - 3*x + 2, x))
Poly(x - 1, x, domain='ZZ')
gcdex(g, auto=True)[source]

Extended Euclidean algorithm of f and g.

Returns (s, t, h) such that h = gcd(f, g) and s*f + t*g = h.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> f = x**4 - 2*x**3 - 6*x**2 + 12*x + 15
>>> g = x**3 + x**2 - 4*x - 4
>>> Poly(f).gcdex(Poly(g))
(Poly(-1/5*x + 3/5, x, domain='QQ'),
 Poly(1/5*x**2 - 6/5*x + 2, x, domain='QQ'),
 Poly(x + 1, x, domain='QQ'))
property gen

Return the principal generator.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 + 1, x).gen
x
gens
get_domain()[source]

Get the ground domain of f.

get_modulus()[source]

Get the modulus of f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 + 1, modulus=2).get_modulus()
2
gff_list()[source]

Computes greatest factorial factorization of f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> f = x**5 + 2*x**4 - x**3 - 2*x**2
>>> Poly(f).gff_list()
[(Poly(x, x, domain='ZZ'), 1), (Poly(x + 2, x, domain='ZZ'), 4)]
ground_roots()[source]

Compute roots of f by factorization in the ground domain.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**6 - 4*x**4 + 4*x**3 - x**2).ground_roots()
{0: 2, 1: 2}
half_gcdex(g, auto=True)[source]

Half extended Euclidean algorithm of f and g.

Returns (s, h) such that h = gcd(f, g) and s*f = h (mod g).

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> f = x**4 - 2*x**3 - 6*x**2 + 12*x + 15
>>> g = x**3 + x**2 - 4*x - 4
>>> Poly(f).half_gcdex(Poly(g))
(Poly(-1/5*x + 3/5, x, domain='QQ'), Poly(x + 1, x, domain='QQ'))
has_only_gens(*gens)[source]

Return True if Poly(f, *gens) retains ground domain.

Examples

>>> from .. import Poly
>>> from ..abc import x, y, z
>>> Poly(x*y + 1, x, y, z).has_only_gens(x, y)
True
>>> Poly(x*y + z, x, y, z).has_only_gens(x, y)
False
homogeneous_order()[source]

Returns the homogeneous order of f.

A homogeneous polynomial is a polynomial whose all monomials with non-zero coefficients have the same total degree. This degree is the homogeneous order of f. If you only want to check if a polynomial is homogeneous, then use Poly.is_homogeneous().

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> f = Poly(x**5 + 2*x**3*y**2 + 9*x*y**4)
>>> f.homogeneous_order()
5
homogenize(s)[source]

Returns the homogeneous polynomial of f.

A homogeneous polynomial is a polynomial whose all monomials with non-zero coefficients have the same total degree. If you only want to check if a polynomial is homogeneous, then use Poly.is_homogeneous(). If you want not only to check if a polynomial is homogeneous but also compute its homogeneous order, then use Poly.homogeneous_order().

Examples

>>> from .. import Poly
>>> from ..abc import x, y, z
>>> f = Poly(x**5 + 2*x**2*y**2 + 9*x*y**3)
>>> f.homogenize(z)
Poly(x**5 + 2*x**2*y**2*z + 9*x*y**3*z, x, y, z, domain='ZZ')
inject(front=False)[source]

Inject ground domain generators into f.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> f = Poly(x**2*y + x*y**3 + x*y + 1, x)
>>> f.inject()
Poly(x**2*y + x*y**3 + x*y + 1, x, y, domain='ZZ')
>>> f.inject(front=True)
Poly(y**3*x + y*x**2 + y*x + 1, y, x, domain='ZZ')
integrate(*specs, **args)[source]

Computes indefinite integral of f.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(x**2 + 2*x + 1, x).integrate()
Poly(1/3*x**3 + x**2 + x, x, domain='QQ')
>>> Poly(x*y**2 + x, x, y).integrate((0, 1), (1, 0))
Poly(1/2*x**2*y**2 + 1/2*x**2, x, y, domain='QQ')
intervals(all=False, eps=None, inf=None, sup=None, fast=False, sqf=False)[source]

Compute isolating intervals for roots of f.

For real roots the Vincent-Akritas-Strzebonski (VAS) continued fractions method is used.

References:

1. Alkiviadis G. Akritas and Adam W. Strzebonski: A Comparative Study of Two Real Root Isolation Methods . Nonlinear Analysis: Modelling and Control, Vol. 10, No. 4, 297-304, 2005. 2. Alkiviadis G. Akritas, Adam W. Strzebonski and Panagiotis S. Vigklas: Improving the Performance of the Continued Fractions Method Using new Bounds of Positive Roots. Nonlinear Analysis: Modelling and Control, Vol. 13, No. 3, 265-279, 2008.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 - 3, x).intervals()
[((-2, -1), 1), ((1, 2), 1)]
>>> Poly(x**2 - 3, x).intervals(eps=1e-2)
[((-26/15, -19/11), 1), ((19/11, 26/15), 1)]
invert(g, auto=True)[source]

Invert f modulo g when possible.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 - 1, x).invert(Poly(2*x - 1, x))
Poly(-4/3, x, domain='QQ')
>>> Poly(x**2 - 1, x).invert(Poly(x - 1, x))
Traceback (most recent call last):
...
NotInvertible: zero divisor
is_Poly = True
is_commutative = True
property is_cyclotomic

Returns True if f is a cyclotomic polnomial.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> f = x**16 + x**14 - x**10 + x**8 - x**6 + x**2 + 1
>>> Poly(f).is_cyclotomic
False
>>> g = x**16 + x**14 - x**10 - x**8 - x**6 + x**2 + 1
>>> Poly(g).is_cyclotomic
True
property is_ground

Returns True if f is an element of the ground domain.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(x, x).is_ground
False
>>> Poly(2, x).is_ground
True
>>> Poly(y, x).is_ground
True
property is_homogeneous

Returns True if f is a homogeneous polynomial.

A homogeneous polynomial is a polynomial whose all monomials with non-zero coefficients have the same total degree. If you want not only to check if a polynomial is homogeneous but also compute its homogeneous order, then use Poly.homogeneous_order().

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(x**2 + x*y, x, y).is_homogeneous
True
>>> Poly(x**3 + x*y, x, y).is_homogeneous
False
property is_irreducible

Returns True if f has no factors over its domain.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 + x + 1, x, modulus=2).is_irreducible
True
>>> Poly(x**2 + 1, x, modulus=2).is_irreducible
False
property is_linear

Returns True if f is linear in all its variables.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(x + y + 2, x, y).is_linear
True
>>> Poly(x*y + 2, x, y).is_linear
False
property is_monic

Returns True if the leading coefficient of f is one.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x + 2, x).is_monic
True
>>> Poly(2*x + 2, x).is_monic
False
property is_monomial

Returns True if f is zero or has only one term.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(3*x**2, x).is_monomial
True
>>> Poly(3*x**2 + 1, x).is_monomial
False
property is_multivariate

Returns True if f is a multivariate polynomial.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(x**2 + x + 1, x).is_multivariate
False
>>> Poly(x*y**2 + x*y + 1, x, y).is_multivariate
True
>>> Poly(x*y**2 + x*y + 1, x).is_multivariate
False
>>> Poly(x**2 + x + 1, x, y).is_multivariate
True
property is_one

Returns True if f is a unit polynomial.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(0, x).is_one
False
>>> Poly(1, x).is_one
True
property is_primitive

Returns True if GCD of the coefficients of f is one.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(2*x**2 + 6*x + 12, x).is_primitive
False
>>> Poly(x**2 + 3*x + 6, x).is_primitive
True
property is_quadratic

Returns True if f is quadratic in all its variables.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(x*y + 2, x, y).is_quadratic
True
>>> Poly(x*y**2 + 2, x, y).is_quadratic
False
property is_sqf

Returns True if f is a square-free polynomial.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 - 2*x + 1, x).is_sqf
False
>>> Poly(x**2 - 1, x).is_sqf
True
property is_univariate

Returns True if f is a univariate polynomial.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(x**2 + x + 1, x).is_univariate
True
>>> Poly(x*y**2 + x*y + 1, x, y).is_univariate
False
>>> Poly(x*y**2 + x*y + 1, x).is_univariate
True
>>> Poly(x**2 + x + 1, x, y).is_univariate
False
property is_zero

Returns True if f is a zero polynomial.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(0, x).is_zero
True
>>> Poly(1, x).is_zero
False
l1_norm()[source]

Returns l1 norm of f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(-x**2 + 2*x - 3, x).l1_norm()
6
lcm(g)[source]

Returns polynomial LCM of f and g.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 - 1, x).lcm(Poly(x**2 - 3*x + 2, x))
Poly(x**3 - 2*x**2 - x + 2, x, domain='ZZ')
length()[source]

Returns the number of non-zero terms in f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 + 2*x - 1).length()
3
lift()[source]

Convert algebraic coefficients to rationals.

Examples

>>> from .. import Poly, I
>>> from ..abc import x
>>> Poly(x**2 + I*x + 1, x, extension=I).lift()
Poly(x**4 + 3*x**2 + 1, x, domain='QQ')
ltrim(gen)[source]

Remove dummy generators from the “left” of f.

Examples

>>> from .. import Poly
>>> from ..abc import x, y, z
>>> Poly(y**2 + y*z**2, x, y, z).ltrim(y)
Poly(y**2 + y*z**2, y, z, domain='ZZ')
max_norm()[source]

Returns maximum norm of f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(-x**2 + 2*x - 3, x).max_norm()
3
monic(auto=True)[source]

Divides all coefficients by LC(f).

Examples

>>> from .. import Poly, ZZ
>>> from ..abc import x
>>> Poly(3*x**2 + 6*x + 9, x, domain=ZZ).monic()
Poly(x**2 + 2*x + 3, x, domain='QQ')
>>> Poly(3*x**2 + 4*x + 2, x, domain=ZZ).monic()
Poly(x**2 + 4/3*x + 2/3, x, domain='QQ')
monoms(order=None)[source]

Returns all non-zero monomials from f in lex order.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(x**2 + 2*x*y**2 + x*y + 3*y, x, y).monoms()
[(2, 0), (1, 2), (1, 1), (0, 1)]

See also

all_monoms

mul(g)[source]

Multiply two polynomials f and g.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 + 1, x).mul(Poly(x - 2, x))
Poly(x**3 - 2*x**2 + x - 2, x, domain='ZZ')
>>> Poly(x**2 + 1, x)*Poly(x - 2, x)
Poly(x**3 - 2*x**2 + x - 2, x, domain='ZZ')
mul_ground(coeff)[source]

Multiply f by a an element of the ground domain.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x + 1).mul_ground(2)
Poly(2*x + 2, x, domain='ZZ')
ne(g, strict=False)[source]
neg()[source]

Negate all coefficients in f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 - 1, x).neg()
Poly(-x**2 + 1, x, domain='ZZ')
>>> -Poly(x**2 - 1, x)
Poly(-x**2 + 1, x, domain='ZZ')
classmethod new(rep, *gens)[source]

Construct Poly instance from raw representation.

nroots(n=15, maxsteps=50, cleanup=True)[source]

Compute numerical approximations of roots of f.

Parameters:
  • calculate (n ... the number of digits to) –

  • do (maxsteps ... the maximum number of iterations to) –

  • maxsteps (If the accuracy n cannot be reached in) –

  • an (it will raise) –

  • maxsteps. (exception. You need to rerun with higher) –

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 - 3).nroots(n=15)
[-1.73205080756888, 1.73205080756888]
>>> Poly(x**2 - 3).nroots(n=30)
[-1.73205080756887729352744634151, 1.73205080756887729352744634151]
nth(*N)[source]

Returns the n-th coefficient of f where N are the exponents of the generators in the term of interest.

Examples

>>> from .. import Poly, sqrt
>>> from ..abc import x, y
>>> Poly(x**3 + 2*x**2 + 3*x, x).nth(2)
2
>>> Poly(x**3 + 2*x*y**2 + y**2, x, y).nth(1, 2)
2
>>> Poly(4*sqrt(x)*y)
Poly(4*y*(sqrt(x)), y, sqrt(x), domain='ZZ')
>>> _.nth(1, 1)
4

See also

coeff_monomial

nth_power_roots_poly(n)[source]

Construct a polynomial with n-th powers of roots of f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> f = Poly(x**4 - x**2 + 1)
>>> f.nth_power_roots_poly(2)
Poly(x**4 - 2*x**3 + 3*x**2 - 2*x + 1, x, domain='ZZ')
>>> f.nth_power_roots_poly(3)
Poly(x**4 + 2*x**2 + 1, x, domain='ZZ')
>>> f.nth_power_roots_poly(4)
Poly(x**4 + 2*x**3 + 3*x**2 + 2*x + 1, x, domain='ZZ')
>>> f.nth_power_roots_poly(12)
Poly(x**4 - 4*x**3 + 6*x**2 - 4*x + 1, x, domain='ZZ')
property one

Return one polynomial with self’s properties.

pdiv(g)[source]

Polynomial pseudo-division of f by g.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 + 1, x).pdiv(Poly(2*x - 4, x))
(Poly(2*x + 4, x, domain='ZZ'), Poly(20, x, domain='ZZ'))
per(rep, gens=None, remove=None)[source]

Create a Poly out of the given representation.

Examples

>>> from .. import Poly, ZZ
>>> from ..abc import x, y
>>> from .polyclasses import DMP
>>> a = Poly(x**2 + 1)
>>> a.per(DMP([ZZ(1), ZZ(1)], ZZ), gens=[y])
Poly(y + 1, y, domain='ZZ')
pexquo(g)[source]

Polynomial exact pseudo-quotient of f by g.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 - 1, x).pexquo(Poly(2*x - 2, x))
Poly(2*x + 2, x, domain='ZZ')
>>> Poly(x**2 + 1, x).pexquo(Poly(2*x - 4, x))
Traceback (most recent call last):
...
ExactQuotientFailed: 2*x - 4 does not divide x**2 + 1
pow(n)[source]

Raise f to a non-negative power n.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x - 2, x).pow(3)
Poly(x**3 - 6*x**2 + 12*x - 8, x, domain='ZZ')
>>> Poly(x - 2, x)**3
Poly(x**3 - 6*x**2 + 12*x - 8, x, domain='ZZ')
pquo(g)[source]

Polynomial pseudo-quotient of f by g.

See the Caveat note in the function prem(f, g).

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 + 1, x).pquo(Poly(2*x - 4, x))
Poly(2*x + 4, x, domain='ZZ')
>>> Poly(x**2 - 1, x).pquo(Poly(2*x - 2, x))
Poly(2*x + 2, x, domain='ZZ')
prem(g)[source]

Polynomial pseudo-remainder of f by g.

Caveat: The function prem(f, g, x) can be safely used to compute

in Z[x] _only_ subresultant polynomial remainder sequences (prs’s).

To safely compute Euclidean and Sturmian prs’s in Z[x] employ anyone of the corresponding functions found in the module polys.subresultants_qq_zz. The functions in the module with suffix _pg compute prs’s in Z[x] employing rem(f, g, x), whereas the functions with suffix _amv compute prs’s in Z[x] employing rem_z(f, g, x).

The function rem_z(f, g, x) differs from prem(f, g, x) in that to compute the remainder polynomials in Z[x] it premultiplies the divident times the absolute value of the leading coefficient of the divisor raised to the power degree(f, x) - degree(g, x) + 1.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 + 1, x).prem(Poly(2*x - 4, x))
Poly(20, x, domain='ZZ')
primitive()[source]

Returns the content and a primitive form of f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(2*x**2 + 8*x + 12, x).primitive()
(2, Poly(x**2 + 4*x + 6, x, domain='ZZ'))
quo(g, auto=True)[source]

Computes polynomial quotient of f by g.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 + 1, x).quo(Poly(2*x - 4, x))
Poly(1/2*x + 1, x, domain='QQ')
>>> Poly(x**2 - 1, x).quo(Poly(x - 1, x))
Poly(x + 1, x, domain='ZZ')
quo_ground(coeff)[source]

Quotient of f by a an element of the ground domain.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(2*x + 4).quo_ground(2)
Poly(x + 2, x, domain='ZZ')
>>> Poly(2*x + 3).quo_ground(2)
Poly(x + 1, x, domain='ZZ')
rat_clear_denoms(g)[source]

Clear denominators in a rational function f/g.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> f = Poly(x**2/y + 1, x)
>>> g = Poly(x**3 + y, x)
>>> p, q = f.rat_clear_denoms(g)
>>> p
Poly(x**2 + y, x, domain='ZZ[y]')
>>> q
Poly(y*x**3 + y**2, x, domain='ZZ[y]')
real_roots(multiple=True, radicals=True)[source]

Return a list of real roots with multiplicities.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(2*x**3 - 7*x**2 + 4*x + 4).real_roots()
[-1/2, 2, 2]
>>> Poly(x**3 + x + 1).real_roots()
[CRootOf(x**3 + x + 1, 0)]
refine_root(s, t, eps=None, steps=None, fast=False, check_sqf=False)[source]

Refine an isolating interval of a root to the given precision.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 - 3, x).refine_root(1, 2, eps=1e-2)
(19/11, 26/15)
rem(g, auto=True)[source]

Computes the polynomial remainder of f by g.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 + 1, x).rem(Poly(2*x - 4, x))
Poly(5, x, domain='ZZ')
>>> Poly(x**2 + 1, x).rem(Poly(2*x - 4, x), auto=False)
Poly(x**2 + 1, x, domain='ZZ')
reorder(*gens, **args)[source]

Efficiently apply new order of generators.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(x**2 + x*y**2, x, y).reorder(y, x)
Poly(y**2*x + x**2, y, x, domain='ZZ')
rep
replace(x, y=None)[source]

Replace x with y in generators list.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(x**2 + 1, x).replace(x, y)
Poly(y**2 + 1, y, domain='ZZ')
resultant(g, includePRS=False)[source]

Computes the resultant of f and g via PRS.

If includePRS=True, it includes the subresultant PRS in the result. Because the PRS is used to calculate the resultant, this is more efficient than calling subresultants() separately.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> f = Poly(x**2 + 1, x)
>>> f.resultant(Poly(x**2 - 1, x))
4
>>> f.resultant(Poly(x**2 - 1, x), includePRS=True)
(4, [Poly(x**2 + 1, x, domain='ZZ'), Poly(x**2 - 1, x, domain='ZZ'),
     Poly(-2, x, domain='ZZ')])
retract(field=None)[source]

Recalculate the ground domain of a polynomial.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> f = Poly(x**2 + 1, x, domain='QQ[y]')
>>> f
Poly(x**2 + 1, x, domain='QQ[y]')
>>> f.retract()
Poly(x**2 + 1, x, domain='ZZ')
>>> f.retract(field=True)
Poly(x**2 + 1, x, domain='QQ')
revert(n)[source]

Compute f**(-1) mod x**n.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(1, x).revert(2)
Poly(1, x, domain='ZZ')
>>> Poly(1 + x, x).revert(1)
Poly(1, x, domain='ZZ')
>>> Poly(x**2 - 1, x).revert(1)
Traceback (most recent call last):
...
NotReversible: only unity is reversible in a ring
>>> Poly(1/x, x).revert(1)
Traceback (most recent call last):
...
PolynomialError: 1/x contains an element of the generators set
root(index, radicals=True)[source]

Get an indexed root of a polynomial.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> f = Poly(2*x**3 - 7*x**2 + 4*x + 4)
>>> f.root(0)
-1/2
>>> f.root(1)
2
>>> f.root(2)
2
>>> f.root(3)
Traceback (most recent call last):
...
IndexError: root index out of [-3, 2] range, got 3
>>> Poly(x**5 + x + 1).root(0)
CRootOf(x**3 - x**2 + 1, 0)
set_domain(domain)[source]

Set the ground domain of f.

set_modulus(modulus)[source]

Set the modulus of f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(5*x**2 + 2*x - 1, x).set_modulus(2)
Poly(x**2 + 1, x, modulus=2)
shift(a)[source]

Efficiently compute Taylor shift f(x + a).

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 - 2*x + 1, x).shift(2)
Poly(x**2 + 2*x + 1, x, domain='ZZ')
slice(x, m, n=None)[source]

Take a continuous subsequence of terms of f.

sqf_list(all=False)[source]

Returns a list of square-free factors of f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> f = 2*x**5 + 16*x**4 + 50*x**3 + 76*x**2 + 56*x + 16
>>> Poly(f).sqf_list()
(2, [(Poly(x + 1, x, domain='ZZ'), 2),
     (Poly(x + 2, x, domain='ZZ'), 3)])
>>> Poly(f).sqf_list(all=True)
(2, [(Poly(1, x, domain='ZZ'), 1),
     (Poly(x + 1, x, domain='ZZ'), 2),
     (Poly(x + 2, x, domain='ZZ'), 3)])
sqf_list_include(all=False)[source]

Returns a list of square-free factors of f.

Examples

>>> from .. import Poly, expand
>>> from ..abc import x
>>> f = expand(2*(x + 1)**3*x**4)
>>> f
2*x**7 + 6*x**6 + 6*x**5 + 2*x**4
>>> Poly(f).sqf_list_include()
[(Poly(2, x, domain='ZZ'), 1),
 (Poly(x + 1, x, domain='ZZ'), 3),
 (Poly(x, x, domain='ZZ'), 4)]
>>> Poly(f).sqf_list_include(all=True)
[(Poly(2, x, domain='ZZ'), 1),
 (Poly(1, x, domain='ZZ'), 2),
 (Poly(x + 1, x, domain='ZZ'), 3),
 (Poly(x, x, domain='ZZ'), 4)]
sqf_norm()[source]

Computes square-free norm of f.

Returns s, f, r, such that g(x) = f(x-sa) and r(x) = Norm(g(x)) is a square-free polynomial over K, where a is the algebraic extension of the ground domain.

Examples

>>> from .. import Poly, sqrt
>>> from ..abc import x
>>> s, f, r = Poly(x**2 + 1, x, extension=[sqrt(3)]).sqf_norm()
>>> s
1
>>> f
Poly(x**2 - 2*sqrt(3)*x + 4, x, domain='QQ<sqrt(3)>')
>>> r
Poly(x**4 - 4*x**2 + 16, x, domain='QQ')
sqf_part()[source]

Computes square-free part of f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**3 - 3*x - 2, x).sqf_part()
Poly(x**2 - x - 2, x, domain='ZZ')
sqr()[source]

Square a polynomial f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x - 2, x).sqr()
Poly(x**2 - 4*x + 4, x, domain='ZZ')
>>> Poly(x - 2, x)**2
Poly(x**2 - 4*x + 4, x, domain='ZZ')
sturm(auto=True)[source]

Computes the Sturm sequence of f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**3 - 2*x**2 + x - 3, x).sturm()
[Poly(x**3 - 2*x**2 + x - 3, x, domain='QQ'),
 Poly(3*x**2 - 4*x + 1, x, domain='QQ'),
 Poly(2/9*x + 25/9, x, domain='QQ'),
 Poly(-2079/4, x, domain='QQ')]
sub(g)[source]

Subtract two polynomials f and g.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 + 1, x).sub(Poly(x - 2, x))
Poly(x**2 - x + 3, x, domain='ZZ')
>>> Poly(x**2 + 1, x) - Poly(x - 2, x)
Poly(x**2 - x + 3, x, domain='ZZ')
sub_ground(coeff)[source]

Subtract an element of the ground domain from f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x + 1).sub_ground(2)
Poly(x - 1, x, domain='ZZ')
subresultants(g)[source]

Computes the subresultant PRS of f and g.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 + 1, x).subresultants(Poly(x**2 - 1, x))
[Poly(x**2 + 1, x, domain='ZZ'),
 Poly(x**2 - 1, x, domain='ZZ'),
 Poly(-2, x, domain='ZZ')]
terms(order=None)[source]

Returns all non-zero terms from f in lex order.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(x**2 + 2*x*y**2 + x*y + 3*y, x, y).terms()
[((2, 0), 1), ((1, 2), 2), ((1, 1), 1), ((0, 1), 3)]

See also

all_terms

terms_gcd()[source]

Remove GCD of terms from the polynomial f.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(x**6*y**2 + x**3*y, x, y).terms_gcd()
((3, 1), Poly(x**3*y + 1, x, y, domain='ZZ'))
termwise(func, *gens, **args)[source]

Apply a function to all terms of f.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> def func(k, coeff):
...     k = k[0]
...     return coeff//10**(2-k)
>>> Poly(x**2 + 20*x + 400).termwise(func)
Poly(x**2 + 2*x + 4, x, domain='ZZ')
to_exact()[source]

Make the ground domain exact.

Examples

>>> from .. import Poly, RR
>>> from ..abc import x
>>> Poly(x**2 + 1.0, x, domain=RR).to_exact()
Poly(x**2 + 1, x, domain='QQ')
to_field()[source]

Make the ground domain a field.

Examples

>>> from .. import Poly, ZZ
>>> from ..abc import x
>>> Poly(x**2 + 1, x, domain=ZZ).to_field()
Poly(x**2 + 1, x, domain='QQ')
to_ring()[source]

Make the ground domain a ring.

Examples

>>> from .. import Poly, QQ
>>> from ..abc import x
>>> Poly(x**2 + 1, domain=QQ).to_ring()
Poly(x**2 + 1, x, domain='ZZ')
total_degree()[source]

Returns the total degree of f.

Examples

>>> from .. import Poly
>>> from ..abc import x, y
>>> Poly(x**2 + y*x + 1, x, y).total_degree()
2
>>> Poly(x + y**5, x, y).total_degree()
5
transform(p, q)[source]

Efficiently evaluate the functional transformation q**n * f(p/q).

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(x**2 - 2*x + 1, x).transform(Poly(x + 1, x), Poly(x - 1, x))
Poly(4, x, domain='ZZ')
trunc(p)[source]

Reduce f modulo a constant p.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> Poly(2*x**3 + 3*x**2 + 5*x + 7, x).trunc(3)
Poly(-x**3 - x + 1, x, domain='ZZ')
unify(g)[source]

Make f and g belong to the same domain.

Examples

>>> from .. import Poly
>>> from ..abc import x
>>> f, g = Poly(x/2 + 1), Poly(2*x + 1)
>>> f
Poly(1/2*x + 1, x, domain='QQ')
>>> g
Poly(2*x + 1, x, domain='ZZ')
>>> F, G = f.unify(g)
>>> F
Poly(1/2*x + 1, x, domain='QQ')
>>> G
Poly(2*x + 1, x, domain='QQ')
property unit

Return unit polynomial with self’s properties.

property zero

Return zero polynomial with self’s properties.

exception modelparameters.sympy.polys.PolynomialDivisionFailed(f, g, domain)[source]

Bases: BasePolynomialError

exception modelparameters.sympy.polys.PolynomialError[source]

Bases: BasePolynomialError

class modelparameters.sympy.polys.PolynomialRing(domain_or_ring, symbols=None, order=None)[source]

Bases: Ring, CompositeDomain

A class for representing multivariate polynomial rings.

factorial(a)[source]

Returns factorial of a.

from_AlgebraicField(a, K0)[source]

Convert an algebraic number to dtype.

from_FractionField(a, K0)[source]

Convert a rational function to dtype.

from_PolynomialRing(a, K0)[source]

Convert a polynomial to dtype.

from_QQ_gmpy(a, K0)[source]

Convert a GMPY mpq object to dtype.

from_QQ_python(a, K0)[source]

Convert a Python Fraction object to dtype.

from_RealField(a, K0)[source]

Convert a mpmath mpf object to dtype.

from_ZZ_gmpy(a, K0)[source]

Convert a GMPY mpz object to dtype.

from_ZZ_python(a, K0)[source]

Convert a Python int object to dtype.

from_sympy(a)[source]

Convert SymPy’s expression to dtype.

gcd(a, b)[source]

Returns GCD of a and b.

gcdex(a, b)[source]

Extended GCD of a and b.

get_field()[source]

Returns a field associated with self.

has_assoc_Field = True
has_assoc_Ring = True
is_Poly = True
is_PolynomialRing = True
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.

new(element)[source]
property one
property order
to_sympy(a)[source]

Convert a to a SymPy object.

property zero
class modelparameters.sympy.polys.PurePoly(rep, *gens, **args)[source]

Bases: Poly

Class for representing pure polynomials.

default_assumptions = {'commutative': True}
property free_symbols

Free symbols of a polynomial.

Examples

>>> from .. import PurePoly
>>> from ..abc import x, y
>>> PurePoly(x**2 + 1).free_symbols
set()
>>> PurePoly(x**2 + y).free_symbols
set()
>>> PurePoly(x**2 + y, x).free_symbols
{y}
gens
is_commutative = True
rep
class modelparameters.sympy.polys.PythonFiniteField(mod, symmetric=True)[source]

Bases: FiniteField

Finite field based on Python’s integers.

alias = 'FF_python'
class modelparameters.sympy.polys.PythonIntegerRing[source]

Bases: IntegerRing

Integer ring based on Python’s int type.

alias = 'ZZ_python'
dtype

alias of int

factorial(a)[source]

Compute factorial of a.

from_FF_gmpy(a, K0)[source]

Convert ModularInteger(mpz) to Python’s int.

from_FF_python(a, K0)[source]

Convert ModularInteger(int) to Python’s int.

from_QQ_gmpy(a, K0)[source]

Convert GMPY’s mpq to Python’s int.

from_QQ_python(a, K0)[source]

Convert Python’s Fraction to Python’s int.

from_RealField(a, K0)[source]

Convert mpmath’s mpf to Python’s int.

from_ZZ_gmpy(a, K0)[source]

Convert GMPY’s mpz to Python’s int.

from_ZZ_python(a, K0)[source]

Convert Python’s int to Python’s int.

from_sympy(a)[source]

Convert SymPy’s Integer to dtype.

gcd(a, b)[source]

Compute GCD of a and b.

gcdex(a, b)[source]

Compute extended GCD of a and b.

lcm(a, b)[source]

Compute LCM of a and b.

one = 1
sqrt(a)[source]

Compute square root of a.

to_sympy(a)[source]

Convert a to a SymPy object.

zero = 0
class modelparameters.sympy.polys.PythonRationalField[source]

Bases: RationalField

Rational field based on Python rational number type.

alias = 'QQ_python'
denom(a)[source]

Returns denominator of a.

dtype

alias of PythonRational

from_QQ_gmpy(a, K0)[source]

Convert a GMPY mpq object to dtype.

from_QQ_python(a, K0)[source]

Convert a Python Fraction object to dtype.

from_RealField(a, K0)[source]

Convert a mpmath mpf object to dtype.

from_ZZ_gmpy(a, K0)[source]

Convert a GMPY mpz object to dtype.

from_ZZ_python(a, K0)[source]

Convert a Python int object to dtype.

from_sympy(a)[source]

Convert SymPy’s Rational to dtype.

get_ring()[source]

Returns ring associated with self.

numer(a)[source]

Returns numerator of a.

one = 1
to_sympy(a)[source]

Convert a to a SymPy object.

zero = 0
modelparameters.sympy.polys.QQ_gmpy

alias of GMPYRationalField

modelparameters.sympy.polys.QQ_python

alias of PythonRationalField

class modelparameters.sympy.polys.RationalField[source]

Bases: Field, CharacteristicZero, SimpleDomain

General class for rational fields.

algebraic_field(*extension)[source]

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

from_AlgebraicField(a, K0)[source]

Convert a ANP object to dtype.

has_assoc_Field = True
has_assoc_Ring = True
is_Numerical = True
is_QQ = True
is_RationalField = True
rep = 'QQ'
class modelparameters.sympy.polys.RealField(prec=53, dps=None, tol=None)[source]

Bases: Field, CharacteristicZero, SimpleDomain

Real numbers up to the given precision.

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

Check if a and b are almost equal.

property dps
from_ComplexField(element, base)[source]

Convert a complex element to dtype.

from_QQ_gmpy(element, base)[source]

Convert a GMPY mpq object to dtype.

from_QQ_python(element, base)[source]

Convert a Python Fraction object to dtype.

from_RealField(element, base)[source]

Convert a real element object to dtype.

from_ZZ_gmpy(element, base)[source]

Convert a GMPY mpz object to dtype.

from_ZZ_python(element, base)[source]

Convert a Python int object to dtype.

from_sympy(expr)[source]

Convert SymPy’s number to dtype.

gcd(a, b)[source]

Returns GCD of a and b.

get_exact()[source]

Returns an exact domain associated with self.

get_ring()[source]

Returns a ring associated with self.

has_assoc_Field = True
has_assoc_Ring = False
property has_default_precision
is_Exact = False
is_Numerical = True
is_PID = False
is_RR = True
is_RealField = True
lcm(a, b)[source]

Returns LCM of a and b.

property precision
rep = 'RR'
to_rational(element, limit=True)[source]

Convert a real number to rational number.

to_sympy(element)[source]

Convert element to SymPy number.

property tolerance
exception modelparameters.sympy.polys.RefinementFailed[source]

Bases: BasePolynomialError

class modelparameters.sympy.polys.RootOf(f, x, index=None, radicals=True, expand=True)[source]

Bases: Expr

Represents a root of a univariate polynomial.

Base class for roots of different kinds of polynomials. Only complex roots are currently supported.

default_assumptions = {}
poly
class modelparameters.sympy.polys.RootSum(expr, func=None, x=None, auto=True, quadratic=False)[source]

Bases: Expr

Represents a sum of all roots of a univariate polynomial.

property args

Returns a tuple of arguments of ‘self’.

Examples

>>> from .. import cot
>>> from ..abc import x, y
>>> cot(x).args
(x,)
>>> cot(x).args[0]
x
>>> (x*y).args
(x, y)
>>> (x*y).args[1]
y

Notes

Never use self._args, always use self.args. Only use _args in __new__ when creating a new function. Don’t override .args() from Basic (so that it’s easy to change the interface in the future if needed).

auto
default_assumptions = {}
doit(**hints)[source]

Evaluate objects that are not evaluated by default like limits, integrals, sums and products. All objects of this kind will be evaluated recursively, unless some species were excluded via ‘hints’ or unless the ‘deep’ hint was set to ‘False’.

>>> from .. import Integral
>>> from ..abc import x
>>> 2*Integral(x, x)
2*Integral(x, x)
>>> (2*Integral(x, x)).doit()
x**2
>>> (2*Integral(x, x)).doit(deep=False)
2*Integral(x, x)
property expr
property free_symbols

Return from the atoms of self those which are free symbols.

For most expressions, all symbols are free symbols. For some classes this is not true. e.g. Integrals use Symbols for the dummy variables which are bound variables, so Integral has a method to return all symbols except those. Derivative keeps track of symbols with respect to which it will perform a derivative; those are bound variables, too, so it has its own free_symbols method.

Any other method that uses bound variables should implement a free_symbols method.

fun
property is_commutative
classmethod new(poly, func, auto=True)[source]

Construct new RootSum instance.

poly
exception modelparameters.sympy.polys.UnificationFailed[source]

Bases: BasePolynomialError

exception modelparameters.sympy.polys.UnivariatePolynomialError[source]

Bases: PolynomialError

modelparameters.sympy.polys.ZZ_gmpy

alias of GMPYIntegerRing

modelparameters.sympy.polys.ZZ_python

alias of PythonIntegerRing

modelparameters.sympy.polys.apart(f, x=None, full=False, **options)[source]

Compute partial fraction decomposition of a rational function.

Given a rational function f, computes the partial fraction decomposition of f. Two algorithms are available: One is based on the undertermined coefficients method, the other is Bronstein’s full partial fraction decomposition algorithm.

The undetermined coefficients method (selected by full=False) uses polynomial factorization (and therefore accepts the same options as factor) for the denominator. Per default it works over the rational numbers, therefore decomposition of denominators with non-rational roots (e.g. irrational, complex roots) is not supported by default (see options of factor).

Bronstein’s algorithm can be selected by using full=True and allows a decomposition of denominators with non-rational roots. A human-readable result can be obtained via doit() (see examples below).

Examples

>>> from .partfrac import apart
>>> from ..abc import x, y

By default, using the undetermined coefficients method:

>>> apart(y/(x + 2)/(x + 1), x)
-y/(x + 2) + y/(x + 1)

The undetermined coefficients method does not provide a result when the denominators roots are not rational:

>>> apart(y/(x**2 + x + 1), x)
y/(x**2 + x + 1)

You can choose Bronstein’s algorithm by setting full=True:

>>> apart(y/(x**2 + x + 1), x, full=True)
RootSum(_w**2 + _w + 1, Lambda(_a, (-2*_a*y/3 - y/3)/(-_a + x)))

Calling doit() yields a human-readable result:

>>> apart(y/(x**2 + x + 1), x, full=True).doit()
(-y/3 - 2*y*(-1/2 - sqrt(3)*I/2)/3)/(x + 1/2 + sqrt(3)*I/2) + (-y/3 -
    2*y*(-1/2 + sqrt(3)*I/2)/3)/(x + 1/2 - sqrt(3)*I/2)
modelparameters.sympy.polys.apart_list(f, x=None, dummies=None, **options)[source]

Compute partial fraction decomposition of a rational function and return the result in structured form.

Given a rational function f compute the partial fraction decomposition of f. Only Bronstein’s full partial fraction decomposition algorithm is supported by this method. The return value is highly structured and perfectly suited for further algorithmic treatment rather than being human-readable. The function returns a tuple holding three elements:

  • The first item is the common coefficient, free of the variable x used for decomposition. (It is an element of the base field K.)

  • The second item is the polynomial part of the decomposition. This can be the zero polynomial. (It is an element of K[x].)

  • The third part itself is a list of quadruples. Each quadruple has the following elements in this order:

    • The (not necessarily irreducible) polynomial D whose roots w_i appear in the linear denominator of a bunch of related fraction terms. (This item can also be a list of explicit roots. However, at the moment apart_list never returns a result this way, but the related assemble_partfrac_list function accepts this format as input.)

    • The numerator of the fraction, written as a function of the root w

    • The linear denominator of the fraction excluding its power exponent, written as a function of the root w.

    • The power to which the denominator has to be raised.

On can always rebuild a plain expression by using the function assemble_partfrac_list.

Examples

A first example:

>>> from .partfrac import apart_list, assemble_partfrac_list
>>> from ..abc import x, t
>>> f = (2*x**3 - 2*x) / (x**2 - 2*x + 1)
>>> pfd = apart_list(f)
>>> pfd
(1,
Poly(2*x + 4, x, domain='ZZ'),
[(Poly(_w - 1, _w, domain='ZZ'), Lambda(_a, 4), Lambda(_a, -_a + x), 1)])
>>> assemble_partfrac_list(pfd)
2*x + 4 + 4/(x - 1)

Second example:

>>> f = (-2*x - 2*x**2) / (3*x**2 - 6*x)
>>> pfd = apart_list(f)
>>> pfd
(-1,
Poly(2/3, x, domain='QQ'),
[(Poly(_w - 2, _w, domain='ZZ'), Lambda(_a, 2), Lambda(_a, -_a + x), 1)])
>>> assemble_partfrac_list(pfd)
-2/3 - 2/(x - 2)

Another example, showing symbolic parameters:

>>> pfd = apart_list(t/(x**2 + x + t), x)
>>> pfd
(1,
Poly(0, x, domain='ZZ[t]'),
[(Poly(_w**2 + _w + t, _w, domain='ZZ[t]'),
Lambda(_a, -2*_a*t/(4*t - 1) - t/(4*t - 1)),
Lambda(_a, -_a + x),
1)])
>>> assemble_partfrac_list(pfd)
RootSum(_w**2 + _w + t, Lambda(_a, (-2*_a*t/(4*t - 1) - t/(4*t - 1))/(-_a + x)))

This example is taken from Bronstein’s original paper:

>>> f = 36 / (x**5 - 2*x**4 - 2*x**3 + 4*x**2 + x - 2)
>>> pfd = apart_list(f)
>>> pfd
(1,
Poly(0, x, domain='ZZ'),
[(Poly(_w - 2, _w, domain='ZZ'), Lambda(_a, 4), Lambda(_a, -_a + x), 1),
(Poly(_w**2 - 1, _w, domain='ZZ'), Lambda(_a, -3*_a - 6), Lambda(_a, -_a + x), 2),
(Poly(_w + 1, _w, domain='ZZ'), Lambda(_a, -4), Lambda(_a, -_a + x), 1)])
>>> assemble_partfrac_list(pfd)
-4/(x + 1) - 3/(x + 1)**2 - 9/(x - 1)**2 + 4/(x - 2)

References

  1. [Bronstein93]

modelparameters.sympy.polys.assemble_partfrac_list(partial_list)[source]

Reassemble a full partial fraction decomposition from a structured result obtained by the function apart_list.

Examples

This example is taken from Bronstein’s original paper:

>>> from .partfrac import apart_list, assemble_partfrac_list
>>> from ..abc import x, y
>>> f = 36 / (x**5 - 2*x**4 - 2*x**3 + 4*x**2 + x - 2)
>>> pfd = apart_list(f)
>>> pfd
(1,
Poly(0, x, domain='ZZ'),
[(Poly(_w - 2, _w, domain='ZZ'), Lambda(_a, 4), Lambda(_a, -_a + x), 1),
(Poly(_w**2 - 1, _w, domain='ZZ'), Lambda(_a, -3*_a - 6), Lambda(_a, -_a + x), 2),
(Poly(_w + 1, _w, domain='ZZ'), Lambda(_a, -4), Lambda(_a, -_a + x), 1)])
>>> assemble_partfrac_list(pfd)
-4/(x + 1) - 3/(x + 1)**2 - 9/(x - 1)**2 + 4/(x - 2)

If we happen to know some roots we can provide them easily inside the structure:

>>> pfd = apart_list(2/(x**2-2))
>>> pfd
(1,
Poly(0, x, domain='ZZ'),
[(Poly(_w**2 - 2, _w, domain='ZZ'),
Lambda(_a, _a/2),
Lambda(_a, -_a + x),
1)])
>>> pfda = assemble_partfrac_list(pfd)
>>> pfda
RootSum(_w**2 - 2, Lambda(_a, _a/(-_a + x)))/2
>>> pfda.doit()
-sqrt(2)/(2*(x + sqrt(2))) + sqrt(2)/(2*(x - sqrt(2)))
>>> from .. import Dummy, Poly, Lambda, sqrt
>>> a = Dummy("a")
>>> pfd = (1, Poly(0, x, domain='ZZ'), [([sqrt(2),-sqrt(2)], Lambda(a, a/2), Lambda(a, -a + x), 1)])
>>> assemble_partfrac_list(pfd)
-sqrt(2)/(2*(x + sqrt(2))) + sqrt(2)/(2*(x - sqrt(2)))

See also

apart, apart_list

modelparameters.sympy.polys.cancel(f, *gens, **args)[source]

Cancel common factors in a rational function f.

Examples

>>> from .. import cancel, sqrt, Symbol
>>> from ..abc import x
>>> A = Symbol('A', commutative=False)
>>> cancel((2*x**2 - 2)/(x**2 - 2*x + 1))
(2*x + 2)/(x - 1)
>>> cancel((sqrt(3) + sqrt(15)*A)/(sqrt(2) + sqrt(10)*A))
sqrt(6)/2
modelparameters.sympy.polys.chebyshevt_poly(n, x=None, **args)[source]

Generates Chebyshev polynomial of the first kind of degree n in x.

modelparameters.sympy.polys.chebyshevu_poly(n, x=None, **args)[source]

Generates Chebyshev polynomial of the second kind of degree n in x.

modelparameters.sympy.polys.cofactors(f, g, *gens, **args)[source]

Compute GCD and cofactors of f and g.

Returns polynomials (h, cff, cfg) such that h = gcd(f, g), and cff = quo(f, h) and cfg = quo(g, h) are, so called, cofactors of f and g.

Examples

>>> from .. import cofactors
>>> from ..abc import x
>>> cofactors(x**2 - 1, x**2 - 3*x + 2)
(x - 1, x + 1, x - 2)
modelparameters.sympy.polys.compose(f, g, *gens, **args)[source]

Compute functional composition f(g).

Examples

>>> from .. import compose
>>> from ..abc import x
>>> compose(x**2 + x, x - 1)
x**2 - x
modelparameters.sympy.polys.construct_domain(obj, **args)[source]

Construct a minimal domain for the list of coefficients.

modelparameters.sympy.polys.content(f, *gens, **args)[source]

Compute GCD of coefficients of f.

Examples

>>> from .. import content
>>> from ..abc import x
>>> content(6*x**2 + 8*x + 12)
2
modelparameters.sympy.polys.count_roots(f, inf=None, sup=None)[source]

Return the number of roots of f in [inf, sup] interval.

If one of inf or sup is complex, it will return the number of roots in the complex rectangle with corners at inf and sup.

Examples

>>> from .. import count_roots, I
>>> from ..abc import x
>>> count_roots(x**4 - 4, -3, 3)
2
>>> count_roots(x**4 - 4, 0, 1 + 3*I)
1
modelparameters.sympy.polys.cyclotomic_poly(n, x=None, **args)[source]

Generates cyclotomic polynomial of order n in x.

modelparameters.sympy.polys.decompose(f, *gens, **args)[source]

Compute functional decomposition of f.

Examples

>>> from .. import decompose
>>> from ..abc import x
>>> decompose(x**4 + 2*x**3 - x - 1)
[x**2 - x - 1, x**2 + x]
modelparameters.sympy.polys.degree(f, *gens, **args)[source]

Return the degree of f in the given variable.

The degree of 0 is negative infinity.

Examples

>>> from .. import degree
>>> from ..abc import x, y
>>> degree(x**2 + y*x + 1, gen=x)
2
>>> degree(x**2 + y*x + 1, gen=y)
1
>>> degree(0, x)
-oo
modelparameters.sympy.polys.degree_list(f, *gens, **args)[source]

Return a list of degrees of f in all variables.

Examples

>>> from .. import degree_list
>>> from ..abc import x, y
>>> degree_list(x**2 + y*x + 1)
(2, 1)
modelparameters.sympy.polys.discriminant(f, *gens, **args)[source]

Compute discriminant of f.

Examples

>>> from .. import discriminant
>>> from ..abc import x
>>> discriminant(x**2 + 2*x + 3)
-8
modelparameters.sympy.polys.div(f, g, *gens, **args)[source]

Compute polynomial division of f and g.

Examples

>>> from .. import div, ZZ, QQ
>>> from ..abc import x
>>> div(x**2 + 1, 2*x - 4, domain=ZZ)
(0, x**2 + 1)
>>> div(x**2 + 1, 2*x - 4, domain=QQ)
(x/2 + 1, 5)
modelparameters.sympy.polys.exquo(f, g, *gens, **args)[source]

Compute polynomial exact quotient of f and g.

Examples

>>> from .. import exquo
>>> from ..abc import x
>>> exquo(x**2 - 1, x - 1)
x + 1
>>> exquo(x**2 + 1, 2*x - 4)
Traceback (most recent call last):
...
ExactQuotientFailed: 2*x - 4 does not divide x**2 + 1
modelparameters.sympy.polys.factor(f, *gens, **args)[source]

Compute the factorization of expression, f, into irreducibles. (To factor an integer into primes, use factorint.)

There two modes implemented: symbolic and formal. If f is not an instance of Poly and generators are not specified, then the former mode is used. Otherwise, the formal mode is used.

In symbolic mode, factor() will traverse the expression tree and factor its components without any prior expansion, unless an instance of Add is encountered (in this case formal factorization is used). This way factor() can handle large or symbolic exponents.

By default, the factorization is computed over the rationals. To factor over other domain, e.g. an algebraic or finite field, use appropriate options: extension, modulus or domain.

Examples

>>> from .. import factor, sqrt
>>> from ..abc import x, y
>>> factor(2*x**5 + 2*x**4*y + 4*x**3 + 4*x**2*y + 2*x + 2*y)
2*(x + y)*(x**2 + 1)**2
>>> factor(x**2 + 1)
x**2 + 1
>>> factor(x**2 + 1, modulus=2)
(x + 1)**2
>>> factor(x**2 + 1, gaussian=True)
(x - I)*(x + I)
>>> factor(x**2 - 2, extension=sqrt(2))
(x - sqrt(2))*(x + sqrt(2))
>>> factor((x**2 - 1)/(x**2 + 4*x + 4))
(x - 1)*(x + 1)/(x + 2)**2
>>> factor((x**2 + 4*x + 4)**10000000*(x**2 + 1))
(x + 2)**20000000*(x**2 + 1)

By default, factor deals with an expression as a whole:

>>> eq = 2**(x**2 + 2*x + 1)
>>> factor(eq)
2**(x**2 + 2*x + 1)

If the deep flag is True then subexpressions will be factored:

>>> factor(eq, deep=True)
2**((x + 1)**2)

See also

sympy.ntheory.factor_.factorint

modelparameters.sympy.polys.factor_list(f, *gens, **args)[source]

Compute a list of irreducible factors of f.

Examples

>>> from .. import factor_list
>>> from ..abc import x, y
>>> factor_list(2*x**5 + 2*x**4*y + 4*x**3 + 4*x**2*y + 2*x + 2*y)
(2, [(x + y, 1), (x**2 + 1, 2)])
modelparameters.sympy.polys.field(symbols, domain, order=LexOrder())[source]

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

modelparameters.sympy.polys.field_isomorphism(a, b, **args)[source]

Construct an isomorphism between two number fields.

modelparameters.sympy.polys.gcd(f, g=None, *gens, **args)[source]

Compute GCD of f and g.

Examples

>>> from .. import gcd
>>> from ..abc import x
>>> gcd(x**2 - 1, x**2 - 3*x + 2)
x - 1
modelparameters.sympy.polys.gcd_list(seq, *gens, **args)[source]

Compute GCD of a list of polynomials.

Examples

>>> from .. import gcd_list
>>> from ..abc import x
>>> gcd_list([x**3 - 1, x**2 - 1, x**2 - 3*x + 2])
x - 1
modelparameters.sympy.polys.gcdex(f, g, *gens, **args)[source]

Extended Euclidean algorithm of f and g.

Returns (s, t, h) such that h = gcd(f, g) and s*f + t*g = h.

Examples

>>> from .. import gcdex
>>> from ..abc import x
>>> gcdex(x**4 - 2*x**3 - 6*x**2 + 12*x + 15, x**3 + x**2 - 4*x - 4)
(-x/5 + 3/5, x**2/5 - 6*x/5 + 2, x + 1)
modelparameters.sympy.polys.gff(f, *gens, **args)[source]

Compute greatest factorial factorization of f.

modelparameters.sympy.polys.gff_list(f, *gens, **args)[source]

Compute a list of greatest factorial factors of f.

Note that the input to ff() and rf() should be Poly instances to use the definitions here.

Examples

>>> from .. import gff_list, ff, Poly
>>> from ..abc import x
>>> f = Poly(x**5 + 2*x**4 - x**3 - 2*x**2, x)
>>> gff_list(f)
[(Poly(x, x, domain='ZZ'), 1), (Poly(x + 2, x, domain='ZZ'), 4)]
>>> (ff(Poly(x), 1)*ff(Poly(x + 2), 4)).expand() == f
True
>>> f = Poly(x**12 + 6*x**11 - 11*x**10 - 56*x**9 + 220*x**8 + 208*x**7 -         1401*x**6 + 1090*x**5 + 2715*x**4 - 6720*x**3 - 1092*x**2 + 5040*x, x)
>>> gff_list(f)
[(Poly(x**3 + 7, x, domain='ZZ'), 2), (Poly(x**2 + 5*x, x, domain='ZZ'), 3)]
>>> ff(Poly(x**3 + 7, x), 2)*ff(Poly(x**2 + 5*x, x), 3) == f
True
modelparameters.sympy.polys.groebner(F, *gens, **args)[source]

Computes the reduced Groebner basis for a set of polynomials.

Use the order argument to set the monomial ordering that will be used to compute the basis. Allowed orders are lex, grlex and grevlex. If no order is specified, it defaults to lex.

For more information on Groebner bases, see the references and the docstring of solve_poly_system().

Examples

Example taken from [1].

>>> from .. import groebner
>>> from ..abc import x, y
>>> F = [x*y - 2*y, 2*y**2 - x**2]
>>> groebner(F, x, y, order='lex')
GroebnerBasis([x**2 - 2*y**2, x*y - 2*y, y**3 - 2*y], x, y,
              domain='ZZ', order='lex')
>>> groebner(F, x, y, order='grlex')
GroebnerBasis([y**3 - 2*y, x**2 - 2*y**2, x*y - 2*y], x, y,
              domain='ZZ', order='grlex')
>>> groebner(F, x, y, order='grevlex')
GroebnerBasis([y**3 - 2*y, x**2 - 2*y**2, x*y - 2*y], x, y,
              domain='ZZ', order='grevlex')

By default, an improved implementation of the Buchberger algorithm is used. Optionally, an implementation of the F5B algorithm can be used. The algorithm can be set using method flag or with the setup() function from polys.polyconfig:

>>> F = [x**2 - x - 1, (2*x - 1) * y - (x**10 - (1 - x)**10)]
>>> groebner(F, x, y, method='buchberger')
GroebnerBasis([x**2 - x - 1, y - 55], x, y, domain='ZZ', order='lex')
>>> groebner(F, x, y, method='f5b')
GroebnerBasis([x**2 - x - 1, y - 55], x, y, domain='ZZ', order='lex')

References

  1. [Buchberger01]

  2. [Cox97]

modelparameters.sympy.polys.ground_roots(f, *gens, **args)[source]

Compute roots of f by factorization in the ground domain.

Examples

>>> from .. import ground_roots
>>> from ..abc import x
>>> ground_roots(x**6 - 4*x**4 + 4*x**3 - x**2)
{0: 2, 1: 2}
modelparameters.sympy.polys.half_gcdex(f, g, *gens, **args)[source]

Half extended Euclidean algorithm of f and g.

Returns (s, h) such that h = gcd(f, g) and s*f = h (mod g).

Examples

>>> from .. import half_gcdex
>>> from ..abc import x
>>> half_gcdex(x**4 - 2*x**3 - 6*x**2 + 12*x + 15, x**3 + x**2 - 4*x - 4)
(-x/5 + 3/5, x + 1)
modelparameters.sympy.polys.hermite_poly(n, x=None, **args)[source]

Generates Hermite polynomial of degree n in x.

modelparameters.sympy.polys.horner(f, *gens, **args)[source]

Rewrite a polynomial in Horner form.

Among other applications, evaluation of a polynomial at a point is optimal when it is applied using the Horner scheme ([1]).

Examples

>>> from .polyfuncs import horner
>>> from ..abc import x, y, a, b, c, d, e
>>> horner(9*x**4 + 8*x**3 + 7*x**2 + 6*x + 5)
x*(x*(x*(9*x + 8) + 7) + 6) + 5
>>> horner(a*x**4 + b*x**3 + c*x**2 + d*x + e)
e + x*(d + x*(c + x*(a*x + b)))
>>> f = 4*x**2*y**2 + 2*x**2*y + 2*x*y**2 + x*y
>>> horner(f, wrt=x)
x*(x*y*(4*y + 2) + y*(2*y + 1))
>>> horner(f, wrt=y)
y*(x*y*(4*x + 2) + x*(2*x + 1))

References

[1] - http://en.wikipedia.org/wiki/Horner_scheme

modelparameters.sympy.polys.interpolate(data, x)[source]

Construct an interpolating polynomial for the data points.

Examples

>>> from .polyfuncs import interpolate
>>> from ..abc import x

A list is interpreted as though it were paired with a range starting from 1:

>>> interpolate([1, 4, 9, 16], x)
x**2

This can be made explicit by giving a list of coordinates:

>>> interpolate([(1, 1), (2, 4), (3, 9)], x)
x**2

The (x, y) coordinates can also be given as keys and values of a dictionary (and the points need not be equispaced):

>>> interpolate([(-1, 2), (1, 2), (2, 5)], x)
x**2 + 1
>>> interpolate({-1: 2, 1: 2, 2: 5}, x)
x**2 + 1
modelparameters.sympy.polys.interpolating_poly(n, x, X='x', Y='y')[source]

Construct Lagrange interpolating polynomial for n data points.

modelparameters.sympy.polys.intervals(F, all=False, eps=None, inf=None, sup=None, strict=False, fast=False, sqf=False)[source]

Compute isolating intervals for roots of f.

Examples

>>> from .. import intervals
>>> from ..abc import x
>>> intervals(x**2 - 3)
[((-2, -1), 1), ((1, 2), 1)]
>>> intervals(x**2 - 3, eps=1e-2)
[((-26/15, -19/11), 1), ((19/11, 26/15), 1)]
modelparameters.sympy.polys.invert(f, g, *gens, **args)[source]

Invert f modulo g when possible.

Examples

>>> from .. import invert, S
>>> from ..core.numbers import mod_inverse
>>> from ..abc import x
>>> invert(x**2 - 1, 2*x - 1)
-4/3
>>> invert(x**2 - 1, x - 1)
Traceback (most recent call last):
...
NotInvertible: zero divisor

For more efficient inversion of Rationals, use the mod_inverse function:

>>> mod_inverse(3, 5)
2
>>> (S(2)/5).invert(S(7)/3)
5/2

See also

sympy.core.numbers.mod_inverse

modelparameters.sympy.polys.is_zero_dimensional(F, *gens, **args)[source]

Checks if the ideal generated by a Groebner basis is zero-dimensional.

The algorithm checks if the set of monomials not divisible by the leading monomial of any element of F is bounded.

References

David A. Cox, John B. Little, Donal O’Shea. Ideals, Varieties and Algorithms, 3rd edition, p. 230

modelparameters.sympy.polys.isolate(alg, eps=None, fast=False)[source]

Give a rational isolating interval for an algebraic number.

modelparameters.sympy.polys.itermonomials(variables, degree)[source]

Generate a set of monomials of the given total degree or less.

Given a set of variables V and a total degree N generate a set of monomials of degree at most N. The total number of monomials is huge and is given by the following formula:

\[\frac{(\#V + N)!}{\#V! N!}\]

For example if we would like to generate a dense polynomial of a total degree N = 50 in 5 variables, assuming that exponents and all of coefficients are 32-bit long and stored in an array we would need almost 80 GiB of memory! Fortunately most polynomials, that we will encounter, are sparse.

Examples

Consider monomials in variables x and y:

>>> from .monomials import itermonomials
>>> from .orderings import monomial_key
>>> from ..abc import x, y

>>> sorted(itermonomials([x, y], 2), key=monomial_key('grlex', [y, x]))
[1, x, y, x**2, x*y, y**2]

>>> sorted(itermonomials([x, y], 3), key=monomial_key('grlex', [y, x]))
[1, x, y, x**2, x*y, y**2, x**3, x**2*y, x*y**2, y**3]
modelparameters.sympy.polys.jacobi_poly(n, a, b, x=None, **args)[source]

Generates Jacobi polynomial of degree n in x.

modelparameters.sympy.polys.laguerre_poly(n, x=None, alpha=None, **args)[source]

Generates Laguerre polynomial of degree n in x.

modelparameters.sympy.polys.lcm(f, g=None, *gens, **args)[source]

Compute LCM of f and g.

Examples

>>> from .. import lcm
>>> from ..abc import x
>>> lcm(x**2 - 1, x**2 - 3*x + 2)
x**3 - 2*x**2 - x + 2
modelparameters.sympy.polys.lcm_list(seq, *gens, **args)[source]

Compute LCM of a list of polynomials.

Examples

>>> from .. import lcm_list
>>> from ..abc import x
>>> lcm_list([x**3 - 1, x**2 - 1, x**2 - 3*x + 2])
x**5 - x**4 - 2*x**3 - x**2 + x + 2
modelparameters.sympy.polys.legendre_poly(n, x=None, **args)[source]

Generates Legendre polynomial of degree n in x.

modelparameters.sympy.polys.minimal_polynomial(ex, x=None, **args)[source]

Computes the minimal polynomial of an algebraic element.

Parameters:
  • ex (algebraic element expression) –

  • x (independent variable of the minimal polynomial) –

  • Options

  • =======

  • compose (if True _minpoly_compose is used, if False the groebner algorithm) –

  • polys (if True returns a Poly object) –

  • domain (ground domain) –

Notes

By default compose=True, the minimal polynomial of the subexpressions of ex are computed, then the arithmetic operations on them are performed using the resultant and factorization. If compose=False, a bottom-up algorithm is used with groebner. The default algorithm stalls less frequently.

If no ground domain is given, it will be generated automatically from the expression.

Examples

>>> from .. import minimal_polynomial, sqrt, solve, QQ
>>> from ..abc import x, y
>>> minimal_polynomial(sqrt(2), x)
x**2 - 2
>>> minimal_polynomial(sqrt(2), x, domain=QQ.algebraic_field(sqrt(2)))
x - sqrt(2)
>>> minimal_polynomial(sqrt(2) + sqrt(3), x)
x**4 - 10*x**2 + 1
>>> minimal_polynomial(solve(x**3 + x + 3)[0], x)
x**3 + x + 3
>>> minimal_polynomial(sqrt(y), x)
x**2 - y
modelparameters.sympy.polys.minpoly(ex, x=None, **args)

Computes the minimal polynomial of an algebraic element.

Parameters:
  • ex (algebraic element expression) –

  • x (independent variable of the minimal polynomial) –

  • Options

  • =======

  • compose (if True _minpoly_compose is used, if False the groebner algorithm) –

  • polys (if True returns a Poly object) –

  • domain (ground domain) –

Notes

By default compose=True, the minimal polynomial of the subexpressions of ex are computed, then the arithmetic operations on them are performed using the resultant and factorization. If compose=False, a bottom-up algorithm is used with groebner. The default algorithm stalls less frequently.

If no ground domain is given, it will be generated automatically from the expression.

Examples

>>> from .. import minimal_polynomial, sqrt, solve, QQ
>>> from ..abc import x, y
>>> minimal_polynomial(sqrt(2), x)
x**2 - 2
>>> minimal_polynomial(sqrt(2), x, domain=QQ.algebraic_field(sqrt(2)))
x - sqrt(2)
>>> minimal_polynomial(sqrt(2) + sqrt(3), x)
x**4 - 10*x**2 + 1
>>> minimal_polynomial(solve(x**3 + x + 3)[0], x)
x**3 + x + 3
>>> minimal_polynomial(sqrt(y), x)
x**2 - y
modelparameters.sympy.polys.monic(f, *gens, **args)[source]

Divide all coefficients of f by LC(f).

Examples

>>> from .. import monic
>>> from ..abc import x
>>> monic(3*x**2 + 4*x + 2)
x**2 + 4*x/3 + 2/3
modelparameters.sympy.polys.nroots(f, n=15, maxsteps=50, cleanup=True)[source]

Compute numerical approximations of roots of f.

Examples

>>> from .. import nroots
>>> from ..abc import x
>>> nroots(x**2 - 3, n=15)
[-1.73205080756888, 1.73205080756888]
>>> nroots(x**2 - 3, n=30)
[-1.73205080756887729352744634151, 1.73205080756887729352744634151]
modelparameters.sympy.polys.nth_power_roots_poly(f, n, *gens, **args)[source]

Construct a polynomial with n-th powers of roots of f.

Examples

>>> from .. import nth_power_roots_poly, factor, roots
>>> from ..abc import x
>>> f = x**4 - x**2 + 1
>>> g = factor(nth_power_roots_poly(f, 2))
>>> g
(x**2 - x + 1)**2
>>> R_f = [ (r**2).expand() for r in roots(f) ]
>>> R_g = roots(g).keys()
>>> set(R_f) == set(R_g)
True
modelparameters.sympy.polys.parallel_poly_from_expr(exprs, *gens, **args)[source]

Construct polynomials from expressions.

modelparameters.sympy.polys.pdiv(f, g, *gens, **args)[source]

Compute polynomial pseudo-division of f and g.

Examples

>>> from .. import pdiv
>>> from ..abc import x
>>> pdiv(x**2 + 1, 2*x - 4)
(2*x + 4, 20)
modelparameters.sympy.polys.pexquo(f, g, *gens, **args)[source]

Compute polynomial exact pseudo-quotient of f and g.

Examples

>>> from .. import pexquo
>>> from ..abc import x
>>> pexquo(x**2 - 1, 2*x - 2)
2*x + 2
>>> pexquo(x**2 + 1, 2*x - 4)
Traceback (most recent call last):
...
ExactQuotientFailed: 2*x - 4 does not divide x**2 + 1
modelparameters.sympy.polys.poly(expr, *gens, **args)[source]

Efficiently transform an expression into a polynomial.

Examples

>>> from .. import poly
>>> from ..abc import x
>>> poly(x*(x**2 + x - 1)**2)
Poly(x**5 + 2*x**4 - x**3 - 2*x**2 + x, x, domain='ZZ')
modelparameters.sympy.polys.poly_from_expr(expr, *gens, **args)[source]

Construct a polynomial from an expression.

modelparameters.sympy.polys.pquo(f, g, *gens, **args)[source]

Compute polynomial pseudo-quotient of f and g.

Examples

>>> from .. import pquo
>>> from ..abc import x
>>> pquo(x**2 + 1, 2*x - 4)
2*x + 4
>>> pquo(x**2 - 1, 2*x - 1)
2*x + 1
modelparameters.sympy.polys.prem(f, g, *gens, **args)[source]

Compute polynomial pseudo-remainder of f and g.

Examples

>>> from .. import prem
>>> from ..abc import x
>>> prem(x**2 + 1, 2*x - 4)
20
modelparameters.sympy.polys.primitive(f, *gens, **args)[source]

Compute content and the primitive form of f.

Examples

>>> from .polytools import primitive
>>> from ..abc import x
>>> primitive(6*x**2 + 8*x + 12)
(2, 3*x**2 + 4*x + 6)
>>> eq = (2 + 2*x)*x + 2

Expansion is performed by default:

>>> primitive(eq)
(2, x**2 + x + 1)

Set expand to False to shut this off. Note that the extraction will not be recursive; use the as_content_primitive method for recursive, non-destructive Rational extraction.

>>> primitive(eq, expand=False)
(1, x*(2*x + 2) + 2)
>>> eq.as_content_primitive()
(2, x*(x + 1) + 1)
modelparameters.sympy.polys.primitive_element(extension, x=None, **args)[source]

Construct a common number field for all extensions.

modelparameters.sympy.polys.quo(f, g, *gens, **args)[source]

Compute polynomial quotient of f and g.

Examples

>>> from .. import quo
>>> from ..abc import x
>>> quo(x**2 + 1, 2*x - 4)
x/2 + 1
>>> quo(x**2 - 1, x - 1)
x + 1
modelparameters.sympy.polys.random_poly(x, n, inf, sup, domain=ZZ, polys=False)[source]

Return a polynomial of degree n with coefficients in [inf, sup].

modelparameters.sympy.polys.rational_interpolate(data, degnum, X=x)[source]

Returns a rational interpolation, where the data points are element of any integral domain.

The first argument contains the data (as a list of coordinates). The degnum argument is the degree in the numerator of the rational function. Setting it too high will decrease the maximal degree in the denominator for the same amount of data.

Example:

>>> from .polyfuncs import rational_interpolate
>>> data = [(1, -210), (2, -35), (3, 105), (4, 231), (5, 350), (6, 465)]
>>> rational_interpolate(data, 2)
(105*x**2 - 525)/(x + 1)

Values do not need to be integers:

>>> from .. import sympify
>>> x = [1, 2, 3, 4, 5, 6]
>>> y = sympify("[-1, 0, 2, 22/5, 7, 68/7]")
>>> rational_interpolate(zip(x, y), 2)
(3*x**2 - 7*x + 2)/(x + 1)

The symbol for the variable can be changed if needed: >>> from .. import symbols >>> z = symbols(‘z’) >>> rational_interpolate(data, 2, X=z) (105*z**2 - 525)/(z + 1)

References

Algorithm is adapted from:

http://axiom-wiki.newsynthesis.org/RationalInterpolation

modelparameters.sympy.polys.real_roots(f, multiple=True)[source]

Return a list of real roots with multiplicities of f.

Examples

>>> from .. import real_roots
>>> from ..abc import x
>>> real_roots(2*x**3 - 7*x**2 + 4*x + 4)
[-1/2, 2, 2]
modelparameters.sympy.polys.reduced(f, G, *gens, **args)[source]

Reduces a polynomial f modulo a set of polynomials G.

Given a polynomial f and a set of polynomials G = (g_1, ..., g_n), computes a set of quotients q = (q_1, ..., q_n) and the remainder r such that f = q_1*g_1 + ... + q_n*g_n + r, where r vanishes or r is a completely reduced polynomial with respect to G.

Examples

>>> from .. import reduced
>>> from ..abc import x, y
>>> reduced(2*x**4 + y**2 - x**2 + y**3, [x**3 - x, y**3 - y])
([2*x, 1], x**2 + y**2 + y)
modelparameters.sympy.polys.refine_root(f, s, t, eps=None, steps=None, fast=False, check_sqf=False)[source]

Refine an isolating interval of a root to the given precision.

Examples

>>> from .. import refine_root
>>> from ..abc import x
>>> refine_root(x**2 - 3, 1, 2, eps=1e-2)
(19/11, 26/15)
modelparameters.sympy.polys.rem(f, g, *gens, **args)[source]

Compute polynomial remainder of f and g.

Examples

>>> from .. import rem, ZZ, QQ
>>> from ..abc import x
>>> rem(x**2 + 1, 2*x - 4, domain=ZZ)
x**2 + 1
>>> rem(x**2 + 1, 2*x - 4, domain=QQ)
5
modelparameters.sympy.polys.resultant(f, g, *gens, **args)[source]

Compute resultant of f and g.

Examples

>>> from .. import resultant
>>> from ..abc import x
>>> resultant(x**2 + 1, x**2 - 1)
4
modelparameters.sympy.polys.ring(symbols, domain, order=LexOrder())[source]

Construct a polynomial ring returning (ring, x_1, ..., x_n).

Parameters:
  • symbols (str, Symbol/Expr or sequence of str, Symbol/Expr (non-empty)) –

  • domain (Domain or coercible) –

  • order (Order or coercible, optional, defaults to lex) –

Examples

>>> from .rings import ring
>>> from .domains import ZZ
>>> from .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'>
modelparameters.sympy.polys.rootof(f, x, index=None, radicals=True, expand=True)[source]

An indexed root of a univariate polynomial.

Returns either a ComplexRootOf object or an explicit expression involving radicals.

Parameters:
  • f (Expr) – Univariate polynomial.

  • x (Symbol, optional) – Generator for f.

  • index (int or Integer) –

  • radicals (bool) – Return a radical expression if possible.

  • expand (bool) – Expand f.

modelparameters.sympy.polys.roots(f, *gens, **flags)[source]

Computes symbolic roots of a univariate polynomial.

Given a univariate polynomial f with symbolic coefficients (or a list of the polynomial’s coefficients), returns a dictionary with its roots and their multiplicities.

Only roots expressible via radicals will be returned. To get a complete set of roots use RootOf class or numerical methods instead. By default cubic and quartic formulas are used in the algorithm. To disable them because of unreadable output set cubics=False or quartics=False respectively. If cubic roots are real but are expressed in terms of complex numbers (casus irreducibilis [1]) the trig flag can be set to True to have the solutions returned in terms of cosine and inverse cosine functions.

To get roots from a specific domain set the filter flag with one of the following specifiers: Z, Q, R, I, C. By default all roots are returned (this is equivalent to setting filter='C').

By default a dictionary is returned giving a compact result in case of multiple roots. However to get a list containing all those roots set the multiple flag to True; the list will have identical roots appearing next to each other in the result. (For a given Poly, the all_roots method will give the roots in sorted numerical order.)

Examples

>>> from .. import Poly, roots
>>> from ..abc import x, y
>>> roots(x**2 - 1, x)
{-1: 1, 1: 1}
>>> p = Poly(x**2-1, x)
>>> roots(p)
{-1: 1, 1: 1}
>>> p = Poly(x**2-y, x, y)
>>> roots(Poly(p, x))
{-sqrt(y): 1, sqrt(y): 1}
>>> roots(x**2 - y, x)
{-sqrt(y): 1, sqrt(y): 1}
>>> roots([1, 0, -1])
{-1: 1, 1: 1}

References

  1. http://en.wikipedia.org/wiki/Cubic_function#Trigonometric_.28and_hyperbolic.29_method

modelparameters.sympy.polys.sfield(exprs, *symbols, **options)[source]

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

Parameters:
  • exprs (Expr or sequence of Expr (sympifiable)) –

  • symbols (sequence of Symbol/Expr) –

  • options (keyword arguments understood by Options) –

Examples

>>> from ..core import symbols
>>> from ..functions import exp, log
>>> from .fields import 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)
modelparameters.sympy.polys.sqf(f, *gens, **args)[source]

Compute square-free factorization of f.

Examples

>>> from .. import sqf
>>> from ..abc import x
>>> sqf(2*x**5 + 16*x**4 + 50*x**3 + 76*x**2 + 56*x + 16)
2*(x + 1)**2*(x + 2)**3
modelparameters.sympy.polys.sqf_list(f, *gens, **args)[source]

Compute a list of square-free factors of f.

Examples

>>> from .. import sqf_list
>>> from ..abc import x
>>> sqf_list(2*x**5 + 16*x**4 + 50*x**3 + 76*x**2 + 56*x + 16)
(2, [(x + 1, 2), (x + 2, 3)])
modelparameters.sympy.polys.sqf_norm(f, *gens, **args)[source]

Compute square-free norm of f.

Returns s, f, r, such that g(x) = f(x-sa) and r(x) = Norm(g(x)) is a square-free polynomial over K, where a is the algebraic extension of the ground domain.

Examples

>>> from .. import sqf_norm, sqrt
>>> from ..abc import x
>>> sqf_norm(x**2 + 1, extension=[sqrt(3)])
(1, x**2 - 2*sqrt(3)*x + 4, x**4 - 4*x**2 + 16)
modelparameters.sympy.polys.sqf_part(f, *gens, **args)[source]

Compute square-free part of f.

Examples

>>> from .. import sqf_part
>>> from ..abc import x
>>> sqf_part(x**3 - 3*x - 2)
x**2 - x - 2
modelparameters.sympy.polys.sring(exprs, *symbols, **options)[source]

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

Parameters:
  • exprs (Expr or sequence of Expr (sympifiable)) –

  • symbols (sequence of Symbol/Expr) –

  • options (keyword arguments understood by Options) –

Examples

>>> from ..core import symbols
>>> from .rings import sring
>>> from .domains import ZZ
>>> from .orderings import lex
>>> 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'>
modelparameters.sympy.polys.sturm(f, *gens, **args)[source]

Compute Sturm sequence of f.

Examples

>>> from .. import sturm
>>> from ..abc import x
>>> sturm(x**3 - 2*x**2 + x - 3)
[x**3 - 2*x**2 + x - 3, 3*x**2 - 4*x + 1, 2*x/9 + 25/9, -2079/4]
modelparameters.sympy.polys.subresultants(f, g, *gens, **args)[source]

Compute subresultant PRS of f and g.

Examples

>>> from .. import subresultants
>>> from ..abc import x
>>> subresultants(x**2 + 1, x**2 - 1)
[x**2 + 1, x**2 - 1, -2]
modelparameters.sympy.polys.swinnerton_dyer_poly(n, x=None, **args)[source]

Generates n-th Swinnerton-Dyer polynomial in x.

modelparameters.sympy.polys.symmetric_poly(n, *gens, **args)[source]

Generates symmetric polynomial of order n.

modelparameters.sympy.polys.symmetrize(F, *gens, **args)[source]

Rewrite a polynomial in terms of elementary symmetric polynomials.

A symmetric polynomial is a multivariate polynomial that remains invariant under any variable permutation, i.e., if f = f(x_1, x_2, ..., x_n), then f = f(x_{i_1}, x_{i_2}, ..., x_{i_n}), where (i_1, i_2, ..., i_n) is a permutation of (1, 2, ..., n) (an element of the group S_n).

Returns a tuple of symmetric polynomials (f1, f2, ..., fn) such that f = f1 + f2 + ... + fn.

Examples

>>> from .polyfuncs import symmetrize
>>> from ..abc import x, y
>>> symmetrize(x**2 + y**2)
(-2*x*y + (x + y)**2, 0)
>>> symmetrize(x**2 + y**2, formal=True)
(s1**2 - 2*s2, 0, [(s1, x + y), (s2, x*y)])
>>> symmetrize(x**2 - y**2)
(-2*x*y + (x + y)**2, -2*y**2)
>>> symmetrize(x**2 - y**2, formal=True)
(s1**2 - 2*s2, -2*y**2, [(s1, x + y), (s2, x*y)])
modelparameters.sympy.polys.terms_gcd(f, *gens, **args)[source]

Remove GCD of terms from f.

If the deep flag is True, then the arguments of f will have terms_gcd applied to them.

If a fraction is factored out of f and f is an Add, then an unevaluated Mul will be returned so that automatic simplification does not redistribute it. The hint clear, when set to False, can be used to prevent such factoring when all coefficients are not fractions.

Examples

>>> from .. import terms_gcd, cos
>>> from ..abc import x, y
>>> terms_gcd(x**6*y**2 + x**3*y, x, y)
x**3*y*(x**3*y + 1)

The default action of polys routines is to expand the expression given to them. terms_gcd follows this behavior:

>>> terms_gcd((3+3*x)*(x+x*y))
3*x*(x*y + x + y + 1)

If this is not desired then the hint expand can be set to False. In this case the expression will be treated as though it were comprised of one or more terms:

>>> terms_gcd((3+3*x)*(x+x*y), expand=False)
(3*x + 3)*(x*y + x)

In order to traverse factors of a Mul or the arguments of other functions, the deep hint can be used:

>>> terms_gcd((3 + 3*x)*(x + x*y), expand=False, deep=True)
3*x*(x + 1)*(y + 1)
>>> terms_gcd(cos(x + x*y), deep=True)
cos(x*(y + 1))

Rationals are factored out by default:

>>> terms_gcd(x + y/2)
(2*x + y)/2

Only the y-term had a coefficient that was a fraction; if one does not want to factor out the 1/2 in cases like this, the flag clear can be set to False:

>>> terms_gcd(x + y/2, clear=False)
x + y/2
>>> terms_gcd(x*y/2 + y**2, clear=False)
y*(x/2 + y)

The clear flag is ignored if all coefficients are fractions:

>>> terms_gcd(x/3 + y/2, clear=False)
(2*x + 3*y)/6

See also

sympy.core.exprtools.gcd_terms, sympy.core.exprtools.factor_terms

modelparameters.sympy.polys.to_number_field(extension, theta=None, **args)[source]

Express extension in the field generated by theta.

modelparameters.sympy.polys.together(expr, deep=False)[source]

Denest and combine rational expressions using symbolic methods.

This function takes an expression or a container of expressions and puts it (them) together by denesting and combining rational subexpressions. No heroic measures are taken to minimize degree of the resulting numerator and denominator. To obtain completely reduced expression use cancel(). However, together() can preserve as much as possible of the structure of the input expression in the output (no expansion is performed).

A wide variety of objects can be put together including lists, tuples, sets, relational objects, integrals and others. It is also possible to transform interior of function applications, by setting deep flag to True.

By definition, together() is a complement to apart(), so apart(together(expr)) should return expr unchanged. Note however, that together() uses only symbolic methods, so it might be necessary to use cancel() to perform algebraic simplification and minimise degree of the numerator and denominator.

Examples

>>> from .. import together, exp
>>> from ..abc import x, y, z
>>> together(1/x + 1/y)
(x + y)/(x*y)
>>> together(1/x + 1/y + 1/z)
(x*y + x*z + y*z)/(x*y*z)
>>> together(1/(x*y) + 1/y**2)
(x + y)/(x*y**2)
>>> together(1/(1 + 1/x) + 1/(1 + 1/y))
(x*(y + 1) + y*(x + 1))/((x + 1)*(y + 1))
>>> together(exp(1/x + 1/y))
exp(1/y + 1/x)
>>> together(exp(1/x + 1/y), deep=True)
exp((x + y)/(x*y))
>>> together(1/exp(x) + 1/(x*exp(x)))
(x + 1)*exp(-x)/x
>>> together(1/exp(2*x) + 1/(x*exp(3*x)))
(x*exp(x) + 1)*exp(-3*x)/x
modelparameters.sympy.polys.trunc(f, p, *gens, **args)[source]

Reduce f modulo a constant p.

Examples

>>> from .. import trunc
>>> from ..abc import x
>>> trunc(2*x**3 + 3*x**2 + 5*x + 7, 3)
-x**3 - x + 1
modelparameters.sympy.polys.vfield(symbols, domain, order=LexOrder())[source]

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

modelparameters.sympy.polys.viete(f, roots=None, *gens, **args)[source]

Generate Viete’s formulas for f.

Examples

>>> from .polyfuncs import viete
>>> from .. import symbols
>>> x, a, b, c, r1, r2 = symbols('x,a:c,r1:3')
>>> viete(a*x**2 + b*x + c, [r1, r2], x)
[(r1 + r2, -b/a), (r1*r2, c/a)]
modelparameters.sympy.polys.vring(symbols, domain, order=LexOrder())[source]

Construct a polynomial ring and inject x_1, ..., x_n into the global namespace.

Parameters:
  • symbols (str, Symbol/Expr or sequence of str, Symbol/Expr (non-empty)) –

  • domain (Domain or coercible) –

  • order (Order or coercible, optional, defaults to lex) –

Examples

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

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

modelparameters.sympy.polys.xring(symbols, domain, order=LexOrder())[source]

Construct a polynomial ring returning (ring, (x_1, ..., x_n)).

Parameters:
  • symbols (str, Symbol/Expr or sequence of str, Symbol/Expr (non-empty)) –

  • domain (Domain or coercible) –

  • order (Order or coercible, optional, defaults to lex) –

Examples

>>> from .rings import xring
>>> from .domains import ZZ
>>> from .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'>