Skip to main content

Package CodeStyle License PyVersion CI Lint

symbolite: a minimalistic symbolic python package


Symbolite allows you to create symbolic mathematical expressions. Just create a symbol (or more) and operate with them as you will normally do in Python.

>>> from symbolite import Symbol, substitute, translate
>>> x = Symbol("x")
>>> y = Symbol("y")
>>> expr1 = x + 3 * y
>>> print(expr1)
x + 3 * y

An expression is just an unnamed Symbol. You can easily replace the symbols by the desired value.

>>> expr2 = substitute(expr1, {x: 5, y: 2})
>>> print(expr2)
5 + 3 * 2

The output is still a symbolic expression, which you can translate:

>>> translate(expr2)
11

Notice that we also got a warning (No libsl provided, defaulting to Python standard library.). This is because translating an expression requires an actual library implementation, named usually as libsl. The default one just uses python's math module.

You can avoid this warning by explicitely providing an libsl implementation.

>>> from symbolite.impl import libstd
>>> translate(expr2, libstd)
11

You can also import it with the right name and it will be found

>>> from symbolite.impl import libstd as libsl
>>> translate(expr2)
11

In addition to the Symbol class, there is also a Scalar and Vector classes to represent integer, floats or complex numbers, and an array of those.

>>> from symbolite import real, Vector
>>> x = Scalar("x")
>>> y = Scalar("y")
>>> v = Vector("v")
>>> expr1 = x + 3 * y
>>> print(expr1)
x + 3 * y
>>> print(2 * v)
2 * v

Mathematical functions that operate on scalars are available in the scalar module.

>>> from symbolite import real
>>> expr3 = 3. * scalar.cos(0.5)
>>> print(expr3)
3.0 * scalar.cos(0.5)

Mathematical functions that operate on vectors are available in the vector module.

>>> from symbolite import vector
>>> expr4 = 3. * vector.sum((1, 2, 3))
>>> print(expr4)
3.0 * vector.sum((1, 2, 3))

Notice that functions are named according to the python math module. Again, this is a symbolic expression until translated.

>>> translate(expr3)
2.6327476856711
>>> translate(expr4)
18.0

Three other implementations are provided: NumPy, SymPy, JAX.

>>> from symbolite.impl import libnumpy
>>> translate(expr3, libsl=libnumpy)
np.float64(2.6327476856711183)
>>> from symbolite.impl import libsympy
>>> translate(expr3, libsl=libsympy)
2.6327476856711

(notice that the way that the different libraries round and display may vary)

In general, all symbols must be replaced by values in order to translate an expression. However, when using an implementation like SymPy that contains a Scalar object you can still translate.

>>> from symbolite.impl import libsympy as libsl
>>> translate(3. * scalar.cos(x), libsl)
3.0*cos(x)

which is actually a SymPy expression with a SymPy symbol (x).

And by the way, checkout vectorize and auto_vectorize functions in the vector module.

We provide a simple way to call user defined functions.

>>> from symbolite import UserFunction
>>> def abs_times_two(x: float) -> float:
...     return 2 * abs(x)
>>> uf = UserFunction.from_function(abs_times_two)
>>> uf
UserFunction(name='abs_times_two', namespace='user')
>>> translate(uf(-1))
2

and you can register implementations for other backends:

>>> def np_abs_times_two(x: float) -> float:
...     return 2 * np.abs(x)
>>> uf.register_impl(libnumpy, np_abs_times_two)
>>> translate(uf(-1), libnumpy)
2

Installing:

pip install -U symbolite

FAQ

Q: Is symbolite a replacement for SymPy?

A: No

Q: Does it aim to be a replacement for SymPy in the future?

A: No

Metadata

Release files for symbolite 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for symbolite 1.1.1
File Size Uploaded
symbolite-1.1.1.tar.gz 31.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for symbolite 1.1.1
File Interpreter ABI Platform
symbolite-1.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 94.2 kB

Release files / symbolite-1.1.1.tar.gz

Download URL symbolite-1.1.1.tar.gz
Size 31.4 kB
Tags Source
SHA-256 checksum
How to use checksums
1b56d4daea8bd31d06c857bcdf496435d6f67a634a1e547be787987b1a4c46de
BLAKE2b-256 checksum
How to use checksums
48ccf2523d88bf292a48084bfb830b9dee994999684e90c50bd7b49ba82ebf41
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / symbolite-1.1.1-py3-none-any.whl

Download URL symbolite-1.1.1-py3-none-any.whl
Size 62.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
76f0745fd7c95e15b9b303f4243e370e028321c6389058845ff5253b84c22db5
BLAKE2b-256 checksum
How to use checksums
5ec61c7aa35d6932182e4dc89f4d6cbdbf5b0b6c1557fca2fa09cab0768f3e6b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

1.1.1 This release

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.4

2 release files

0.3

2 release files

0.2

2 release files

0.1.1

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page