N

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

N

N(num: int | float | complex | str | Decimal, relative_error: float | None = None) -> Expression

Create a new Symbolica number from an int, a float, or a string. A floating point number is kept as a float with the same precision as the input, but it can also be converted to the smallest rational number given a relative_error.

Examples

e = N(1) / 2
print(e)  # 1/2
print(N(1/3))
print(N(0.33, 0.1))
print(N('0.333`3'))
print(N(Decimal('0.1234')))
3.3333333333333331e-1
1/3
3.33e-1
1.2340e-1

Parameters

  • num (int | float | complex | str | Decimal) The value to convert into a Symbolica number.
  • relative_error (float | None) The maximum relative error used when converting floating-point input to a rational number.