Series

Symbolica documentation for getting started, symbolic expressions, numerical evaluation, pattern matching, and APIs in Python and Rust.

Series

Series()

A series expansion class.

Supports standard arithmetic operations, such as addition and multiplication.

Examples

x = S('x')
s = E("(1-cos(x))/sin(x)").series(x, 0, 4) * x
print(s)

Methods

Name Description
__add__ Add another series or expression to this series, returning the result.
__getitem__ Get the coefficient of the term with exponent exp.
__iter__ Iterate over the terms of the series, yielding pairs of exponent and coefficient.
__mul__ Multiply another series or expression to this series, returning the result.
__neg__ Negate the series.
__pow__ Raise the series to the power of exp, returning the result.
__radd__ Add two series together, returning the result.
__rmul__ Multiply two series together, returning the result.
__rsub__ Subtract self from other, returning the result.
__rtruediv__ Divide other by self, returning the result.
__str__ Print the series in a human-readable format.
__sub__ Subtract other from self, returning the result.
__truediv__ Divide self by other, returning the result.
_repr_html_ Convert the series into an HTML representation.
_repr_latex_ Convert the series into a LaTeX representation.
_repr_pretty_ Convert the series into a pretty string representation.
cos Compute the cosine of the series, returning the result.
exp Compute the exponential of the series, returning the result.
format Convert the series into a human-readable string.
formatted Convert the series into a rich display object, with tunable settings.
get_absolute_order Get the absolute order.
get_coefficient Get the coefficient of the term with exponent exp
get_ramification Get the ramification.
get_relative_order Get the relative order.
get_trailing_exponent Get the trailing exponent; the exponent of the first non-zero term.
log Compute the natural logarithm of the series, returning the result.
pow Raise the series to the power of num/den, returning the result.
shift Shift the series by e units of the ramification.
sin Compute the sine of the series, returning the result.
spow Raise the series to the power of exp, returning the result.
to_expression Convert the series to an expression.
to_latex Convert the series into a LaTeX string.

__add__

Series.__add__(other: Series | Expression) -> Series

Add another series or expression to this series, returning the result.

Parameters

  • other (Series | Expression) The other operand to combine or compare with.

__getitem__

Series.__getitem__(expr: Expression | int) -> Expression

Get the coefficient of the term with exponent exp

Parameters

  • expr (Expression | int) The expression to operate on.

__iter__

Series.__iter__() -> Iterator[tuple[Expression, Expression]]

Iterate over the terms of the series, yielding pairs of exponent and coefficient.

__mul__

Series.__mul__(other: Series | Expression) -> Series

Multiply another series or expression to this series, returning the result.

Parameters

  • other (Series | Expression) The other operand to combine or compare with.

__neg__

Series.__neg__() -> Series

Negate the series.

__pow__

Series.__pow__(exp: int) -> Series

Raise the series to the power of exp, returning the result.

Parameters

  • exp (int) The exponent.

__radd__

Series.__radd__(other: Expression) -> Series

Add two series together, returning the result.

Parameters

  • other (Expression) The other operand to combine or compare with.

__rmul__

Series.__rmul__(other: Expression) -> Series

Multiply two series together, returning the result.

Parameters

  • other (Expression) The other operand to combine or compare with.

__rsub__

Series.__rsub__(other: Expression) -> Series

Subtract self from other, returning the result.

Parameters

  • other (Expression) The other operand to combine or compare with.

__rtruediv__

Series.__rtruediv__(other: Expression) -> Series

Divide other by self, returning the result.

Parameters

  • other (Expression) The other operand to combine or compare with.

__str__

Series.__str__() -> str

Print the series in a human-readable format.

__sub__

Series.__sub__(other: Series | Expression) -> Series

Subtract other from self, returning the result.

Parameters

  • other (Series | Expression) The other operand to combine or compare with.

__truediv__

Series.__truediv__(other: Series | Expression) -> Series

Divide self by other, returning the result.

Parameters

  • other (Series | Expression) The other operand to combine or compare with.

_repr_html_

Series._repr_html_() -> str

Convert the series into an HTML representation.

_repr_latex_

Series._repr_latex_() -> str

Convert the series into a LaTeX representation.

_repr_pretty_

Series._repr_pretty_(pretty, cycle: bool)

Convert the series into a pretty string representation.

cos

Series.cos() -> Series

Compute the cosine of the series, returning the result.

exp

Series.exp() -> Series

Compute the exponential of the series, returning the result.

format

Series.format(
    mode: PrintMode = PrintMode.Symbolica,
    max_line_length: int | None = 80,
    indentation: int = 4,
    fill_indented_lines: bool = True,
    terms_on_new_line: bool = False,
    color_top_level_sum: bool = True,
    color_builtin_symbols: bool = True,
    bracket_level_colors: Sequence[int] | None = [244, 25, 97, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60],
    print_ring: bool = True,
    symmetric_representation_for_finite_field: bool = False,
    explicit_rational_polynomial: bool = False,
    number_thousands_separator: str | None = None,
    multiplication_operator: str = '*',
    double_star_for_exponentiation: bool = False,
    function_brackets: tuple[str, str] = ('(', ')'),
    num_exp_as_superscript: bool = True,
    precision: int | None = None,
    show_namespaces: bool = False,
    hide_namespace: str | None = None,
    include_attributes: bool = False,
    max_terms: int | None = None,
    custom_print_mode: dict[str, int | str | dict[str | int, Any]] | None = None,
) -> str

Convert the series into a human-readable string.

Parameters

  • mode (PrintMode) The mode that controls how the input is interpreted or formatted.
  • max_line_length (int | None) The preferred maximum line length before wrapping.
  • indentation (int) The number of spaces used for wrapped lines.
  • fill_indented_lines (bool) Whether wrapped lines should be padded to the configured indentation.
  • terms_on_new_line (bool) Whether wrapped output should place terms on separate lines.
  • color_top_level_sum (bool) Whether top-level sums should be colorized.
  • color_builtin_symbols (bool) Whether built-in symbols should be colorized.
  • bracket_level_colors (Sequence[int] | None) The colors assigned to successive nested bracket levels.
  • print_ring (bool) Whether the coefficient ring should be included in the printed output.
  • symmetric_representation_for_finite_field (bool) Whether finite-field elements should be printed using symmetric representatives.
  • explicit_rational_polynomial (bool) Whether rational polynomials should be printed explicitly as numerator and denominator.
  • number_thousands_separator (str | None) The separator inserted between groups of digits in printed integers.
  • multiplication_operator (str) The string used to print multiplication.
  • double_star_for_exponentiation (bool) Whether exponentiation should be printed as ** instead of ^.
  • function_brackets (tuple[str, str]) The opening and closing brackets used when printing function arguments.
  • num_exp_as_superscript (bool) Whether small integer exponents should be printed as superscripts.
  • precision (int | None) The decimal precision used when printing numeric coefficients.
  • show_namespaces (bool) Whether namespaces should be included in the formatted output.
  • hide_namespace (str | None) A namespace prefix to omit from printed symbol names.
  • include_attributes (bool) Whether symbol attributes should be included in the printed output.
  • max_terms (int | None) The maximum number of terms to print before truncating the output.
  • custom_print_mode (dict[str, int | str | dict[str | int, Any]] | None) Custom print data passed through to custom print callbacks.

formatted

Series.formatted(
    max_terms: int | None = None,
    mode: PrintMode = PrintMode.Symbolica,
    max_line_length: int | None = 80,
    indentation: int = 4,
    fill_indented_lines: bool = True,
    terms_on_new_line: bool = False,
    color_top_level_sum: bool = True,
    color_builtin_symbols: bool = True,
    bracket_level_colors: Sequence[int] | None = [244, 25, 97, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60],
    print_ring: bool = True,
    symmetric_representation_for_finite_field: bool = False,
    explicit_rational_polynomial: bool = False,
    number_thousands_separator: str | None = None,
    multiplication_operator: str = '*',
    double_star_for_exponentiation: bool = False,
    function_brackets: tuple[str, str] = ('(', ')'),
    num_exp_as_superscript: bool = True,
    precision: int | None = None,
    show_namespaces: bool = False,
    hide_namespace: str | None = None,
    include_attributes: bool = False,
    custom_print_mode: dict[str, int | str | dict[str | int, Any]] | None = None,
) -> FormattedOutput

Convert the series into a rich display object, with tunable settings.

Parameters

  • max_terms (int | None) The maximum number of terms to print before truncating the output.
  • mode (PrintMode) The mode that controls how the input is interpreted or formatted.
  • max_line_length (int | None) The preferred maximum line length before wrapping.
  • indentation (int) The number of spaces used for wrapped lines.
  • fill_indented_lines (bool) Whether wrapped lines should be padded to the configured indentation.
  • terms_on_new_line (bool) Whether wrapped output should place terms on separate lines.
  • color_top_level_sum (bool) Whether top-level sums should be colorized.
  • color_builtin_symbols (bool) Whether built-in symbols should be colorized.
  • bracket_level_colors (Sequence[int] | None) The colors assigned to successive nested bracket levels.
  • print_ring (bool) Whether the coefficient ring should be included in the printed output.
  • symmetric_representation_for_finite_field (bool) Whether finite-field elements should be printed using symmetric representatives.
  • explicit_rational_polynomial (bool) Whether rational polynomials should be printed explicitly as numerator and denominator.
  • number_thousands_separator (str | None) The separator inserted between groups of digits in printed integers.
  • multiplication_operator (str) The string used to print multiplication.
  • double_star_for_exponentiation (bool) Whether exponentiation should be printed as ** instead of ^.
  • function_brackets (tuple[str, str]) The opening and closing brackets used when printing function arguments.
  • num_exp_as_superscript (bool) Whether small integer exponents should be printed as superscripts.
  • precision (int | None) The decimal precision used when printing numeric coefficients.
  • show_namespaces (bool) Whether namespaces should be included in the formatted output.
  • hide_namespace (str | None) A namespace prefix to omit from printed symbol names.
  • include_attributes (bool) Whether symbol attributes should be included in the printed output.
  • custom_print_mode (dict[str, int | str | dict[str | int, Any]] | None) Custom print data passed through to custom print callbacks.

get_absolute_order

Series.get_absolute_order() -> tuple[int, int]

Get the absolute order.

get_coefficient

Series.get_coefficient(exp: Expression | int) -> Expression

Get the coefficient of the term with exponent exp. Alternatively, use series[exp].

Parameters

  • exp (Expression | int) The exponent whose coefficient should be returned.

get_ramification

Series.get_ramification() -> int

Get the ramification.

get_relative_order

Series.get_relative_order() -> tuple[int, int]

Get the relative order.

get_trailing_exponent

Series.get_trailing_exponent() -> tuple[int, int]

Get the trailing exponent; the exponent of the first non-zero term.

log

Series.log() -> Series

Compute the natural logarithm of the series, returning the result.

pow

Series.pow(num: int, den: int = 1) -> Series

Raise the series to the power of num/den, returning the result.

Parameters

  • num (int) The numerator of the rational exponent.
  • den (int) The denominator of the rational exponent.

shift

Series.shift(e: int) -> Series

Shift the series by e units of the ramification.

Parameters

  • e (int) The shift measured in units of the series ramification.

sin

Series.sin() -> Series

Compute the sine of the series, returning the result.

spow

Series.spow(exp: Series) -> Series

Raise the series to the power of exp, returning the result.

Parameters

  • exp (Series) The series exponent.

to_expression

Series.to_expression() -> Expression

Convert the series to an expression

to_latex

Series.to_latex() -> str

Convert the series into a LaTeX string.