DecimalComplex

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

DecimalComplex

class DecimalComplex

A complex number with Python Decimal components.

Use decimal strings or Decimal inputs to preserve digits beyond binary64. The constructor retains the supplied components without rounding to the ambient Decimal context. complex(z) explicitly converts to binary64 and can lose precision. Nonfinite components and booleans are rejected.

Examples

from decimal import Decimal
from symbolica.community.hepkit import oneloop
z = oneloop.DecimalComplex("1.25", "-0.5")
assert z.real == Decimal("1.25")
assert z.imag == Decimal("-0.5")

Attributes

Name Description
imag Imaginary component as a Decimal, without conversion to a Python float.
real Real component as a Decimal, without conversion to a Python float.

imag

DecimalComplex.imag: Decimal

Imaginary component as a Decimal, without conversion to a Python float.

Examples

from decimal import Decimal
from symbolica.community.hepkit import oneloop
z = oneloop.DecimalComplex("1.25", "-0.5")
assert z.imag == Decimal("-0.5")

real

DecimalComplex.real: Decimal

Real component as a Decimal, without conversion to a Python float.

Examples

from decimal import Decimal
from symbolica.community.hepkit import oneloop
z = oneloop.DecimalComplex("1.25", "-0.5")
assert z.real == Decimal("1.25")

Methods

Name Description
__complex__ Convert both components to a built-in complex number; precision beyond binary64 is lost.
__init__ Construct finite real and imaginary Decimal components; omitted imaginary part is zero.
__repr__ Show both Decimal components for inspection.

__complex__

DecimalComplex.__complex__() -> complex

Convert both components to a built-in complex number; precision beyond binary64 is lost.

Examples

from decimal import Decimal
from symbolica.community.hepkit import oneloop
z = oneloop.DecimalComplex("1.25", "-0.5")
assert complex(z) == complex(1.25, -0.5)

__init__

DecimalComplex.__init__(
    real: int | float | str | Decimal,
    imag: int | float | str | Decimal | None = None,
) -> None

Construct finite real and imaginary Decimal components; omitted imaginary part is zero.

Examples

from decimal import Decimal
from symbolica.community.hepkit import oneloop
z = oneloop.DecimalComplex("1.25", "-0.5")
assert complex(z) == 1.25 - 0.5j

Parameters

  • real (int, float, str or Decimal) Real component. A float preserves its binary approximation; use a string for an exact decimal input.
  • imag (int, float, str, Decimal or None, optional) Imaginary component; None means zero.

__repr__

DecimalComplex.__repr__() -> str

Show both Decimal components for inspection.

Examples

from decimal import Decimal
from symbolica.community.hepkit import oneloop
z = oneloop.DecimalComplex("1.25", "-0.5")
text = repr(z)