Skip to main content

A minimalistic symbolic package.

Project description

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.abstract import scalar
>>> x = scalar.Scalar("x")
>>> y = scalar.Scalar("y")
>>> expr1 = x + 3 * y
>>> print(expr1)
(x + (3 * y))

You can easily replace the symbols by the desired value.

>>> expr2 = expr1.replace_by_name(x=5, y=2)
>>> print(expr2)
(5 + (3 * 2))

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

>>> expr2.eval()
11

Notice that we also got a warning (No libsl provided, defaulting to 'math'). This is because evaluating an expression requires a actual library implementation, name 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.scalar import default
>>> expr2.eval(libscalar=default)
11

The cool thing about this is that you can use a different implementation but let's not get too much ahead of ourselves.

Mathematical functions are available in the lib module.

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

(Functions are named according to the python math module). Again, this is a symbolic expression until evaluated.

>>> expr3.eval()
2.6327476856711

Two other implementations are provided: NumPy and SymPy:

>>> from symbolite.impl.scalar import numpy as libscalar
>>> expr3.eval(libscalar=libscalar)
2.6327476856711
>>> from symbolite.impl.scalar import sympy as libscalar
>>> expr3.eval(libscalar=libscalar)
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 evaluate an expression. However, when using an implementation like SymPy that contains a Scalar object you can still evaluate.

>>> from symbolite.impl.scalar import sympy as libscalar
>>> (3. * scalar.cos(x).eval(libscalar=libscalar))
3.0*cos(x)

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

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

symbolite-0.2.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

symbolite-0.2-py3-none-any.whl (16.7 kB view details)

Uploaded Python 3

File details

Details for the file symbolite-0.2.tar.gz.

File metadata

  • Download URL: symbolite-0.2.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.1

File hashes

Hashes for symbolite-0.2.tar.gz
Algorithm Hash digest
SHA256 4acf1003835403f6f3b0c58d75f09b71eb27f890aee7e3bac2f101e83e6197f8
MD5 826cb7b2310bf22be893629f366dc396
BLAKE2b-256 c02db2efd0d984d3dfe6885efea52f92d16afba5ccc071ff168d261a8fccac1b

See more details on using hashes here.

File details

Details for the file symbolite-0.2-py3-none-any.whl.

File metadata

  • Download URL: symbolite-0.2-py3-none-any.whl
  • Upload date:
  • Size: 16.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.1

File hashes

Hashes for symbolite-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5f25b40bac5a0e22734d549211381592b332e10e04c034862ba41340a48dd66c
MD5 696edaa9f43d0f3f85c28a13e2d6973c
BLAKE2b-256 24090e9ea0bb3e7966e58c1892d6a04a724dc055440d60aeedf8aa8ef746811c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page