RationalPolynomial

RationalPolynomial

RationalPolynomial()

A Symbolica rational polynomial.

Methods

Name Description
__add__ Add two rational polynomials self and rhs, returning the result.
__copy__ Copy the rational polynomial.
__eq__ Check if two rational polynomials are equal.
__floordiv__ Divide the polynomial self by rhs, rounding down, returning the result.
__ge__ Check if the polynomial is greater than or equal to an integer.
__gt__ Check if the rational polynomial is greater than an integer.
__le__ Check if the rational polynomial is less than or equal to an integer.
__lt__ Check if the rational polynomial is less than an integer.
__mul__ Multiply two rational polynomials self and rhs, returning the result.
__ne__ Check if two rational polynomials are not equal.
__neg__ Negate the rational polynomial.
__new__ Create a new rational polynomial from a numerator and denominator polynomial.
__str__ Print the rational polynomial in a human-readable format.
__sub__ Subtract rational polynomials rhs from self, returning the result.
__truediv__ Divide the rational polynomial self by rhs if possible, returning the result.
apart Compute the partial fraction decomposition in x
denominator Get the denominator.
derivative Take a derivative in x.
gcd Compute the greatest common divisor (GCD) of two rational polynomials.
get_variables Get the list of variables in the internal ordering of the polynomial.
numerator Get the numerator.
parse Parse a rational polynomial from a string
to_expression Convert the polynomial to an expression.
to_finite_field Convert the coefficients of the rational polynomial to a finite field with prime prime.
to_latex Convert the rational polynomial into a LaTeX string.

__add__

RationalPolynomial.__add__(rhs: RationalPolynomial) -> RationalPolynomial

Add two rational polynomials self and rhs, returning the result.

__copy__

RationalPolynomial.__copy__() -> RationalPolynomial

Copy the rational polynomial.

__eq__

RationalPolynomial.__eq__(rhs: Polynomial | int) -> bool

Check if two rational polynomials are equal.

__floordiv__

RationalPolynomial.__floordiv__(rhs: Polynomial) -> Polynomial

Divide the polynomial self by rhs, rounding down, returning the result.

__ge__

RationalPolynomial.__ge__(rhs: int) -> bool

Check if the polynomial is greater than or equal to an integer.

__gt__

RationalPolynomial.__gt__(rhs: int) -> bool

Check if the rational polynomial is greater than an integer.

__le__

RationalPolynomial.__le__(rhs: int) -> bool

Check if the rational polynomial is less than or equal to an integer.

__lt__

RationalPolynomial.__lt__(rhs: int) -> bool

Check if the rational polynomial is less than an integer.

__mul__

RationalPolynomial.__mul__(rhs: RationalPolynomial) -> RationalPolynomial

Multiply two rational polynomials self and rhs, returning the result.

__ne__

RationalPolynomial.__ne__(rhs: Polynomial | int) -> bool

Check if two rational polynomials are not equal.

__neg__

RationalPolynomial.__neg__() -> RationalPolynomial

Negate the rational polynomial.

__new__

RationalPolynomial.__new__(num: Polynomial, den: Polynomial) -> RationalPolynomial

Create a new rational polynomial from a numerator and denominator polynomial.

__str__

RationalPolynomial.__str__() -> str

Print the rational polynomial in a human-readable format.

__sub__

RationalPolynomial.__sub__(rhs: RationalPolynomial) -> RationalPolynomial

Subtract rational polynomials rhs from self, returning the result.

__truediv__

RationalPolynomial.__truediv__(rhs: RationalPolynomial) -> RationalPolynomial

Divide the rational polynomial self by rhs if possible, returning the result.

apart

RationalPolynomial.apart(x: Optional[Expression] = None) -> List[RationalPolynomial]

Compute the partial fraction decomposition in x.

If None is passed, the expression will be decomposed in all variables which involves a potentially expensive Groebner basis computation.

Examples

from symbolica import *
x = S('x')
p = E('1/((x+y)*(x^2+x*y+1)(x+1))').to_rational_polynomial()
for pp in p.apart(x):
    print(pp)

denominator

RationalPolynomial.denominator() -> Polynomial

Get the denominator.

derivative

RationalPolynomial.derivative(x: Expression) -> RationalPolynomial

Take a derivative in x.

Examples

from symbolica import *
x = S('x')
p = E('1/((x+y)*(x^2+x*y+1)(x+1))').to_rational_polynomial()
print(p.derivative(x))

gcd

RationalPolynomial.gcd(rhs: RationalPolynomial) -> RationalPolynomial

Compute the greatest common divisor (GCD) of two rational polynomials.

get_variables

RationalPolynomial.get_variables() -> Sequence[Expression]

Get the list of variables in the internal ordering of the polynomial.

numerator

RationalPolynomial.numerator() -> Polynomial

Get the numerator.

parse

RationalPolynomial.parse(
    input: str,
    vars: Sequence[str],
    default_namespace: str | None = None,
) -> RationalPolynomial

Parse a rational polynomial from a string. The list of all the variables must be provided.

If this requirements is too strict, use Expression.to_polynomial() instead.

Examples

e = RationalPolynomial.parse('(3/4*x^2+y+y*4)/(1+x)', ['x', 'y'])

Raises

  • ValueError: If the input is not a valid Symbolica rational polynomial.

to_expression

RationalPolynomial.to_expression() -> Expression

Convert the polynomial to an expression.

Examples

from symbolica import *
e = E('(x*y+2*x+x^2)/(x^7+y+1)')
p = e.to_polynomial()
print((e - p.to_expression()).expand())

to_finite_field

RationalPolynomial.to_finite_field(prime: int) -> FiniteFieldRationalPolynomial

Convert the coefficients of the rational polynomial to a finite field with prime prime.

to_latex

RationalPolynomial.to_latex() -> str

Convert the rational polynomial into a LaTeX string.