Skip to main content

A minimalistic symbolic package.

Project description

symbolite-array: an array extension from symbolite


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.

This extension allows you to use arrays

>>> from symbolite.abstract import array
>>> arr = array.Array("arr")
>>> expr1 = arr + 1
>>> print(expr1)
(arr + 1)

and you can get one item.

>>> from symbolite.abstract import array
>>> arr = array.Array("arr")
>>> expr2 = arr[1] + 1
>>> print(expr2)
(arr[1] + 1)

You can easily replace the symbols by the desired value.

>>> expr3 = expr2.replace_by_name(arr=(1, 2, 3))
>>> print(expr3)
((1, 2, 3)[1] + 1)

and evaluate:

>>> print(expr3.eval())
3

Included in this library are implementations for sum and prod, in the default implementation (based on python's math), NumPy, and SciPy. In SciPy, Array is also mapped to SciPy's IndexedBase.

Vectorizing expresion

If you have an expression with a number of scalars, you can convert it into an expresion using a vector with scalar symbols occuping specific places within the array.

>>> from symbolite.abstract import scalar
>>> x = scalar.Scalar("x")
>>> y = scalar.Scalar("y")
>>> print(array.vectorize(x + scalar.cos(y), ("x", "y")))
(arr[0] + libscalar.cos(arr[1]))

The first argument is the expression and the second list (in order) the scalars to be replaced by the array. You can also use a dictionary mapping scalars names to indices

>>> print(array.vectorize(x + scalar.cos(y), dict(x=3, y=5)))
(arr[3] + libscalar.cos(arr[5]))

If you want to replace all scalars automatically, auto

>>> from symbolite.abstract import scalar
>>> x = scalar.Scalar("x")
>>> y = scalar.Scalar("y")
>>> names, vexpr = array.auto_vectorize(x + scalar.cos(y))
>>> print(names) # names are given in the order of the array.
('x', 'y')
>>> print(vexpr)
(arr[0] + libscalar.cos(arr[1]))

Installing:

pip install -U symbolite-array

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

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

Source Distribution

symbolite-array-0.1.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

symbolite_array-0.1-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file symbolite-array-0.1.tar.gz.

File metadata

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

File hashes

Hashes for symbolite-array-0.1.tar.gz
Algorithm Hash digest
SHA256 1f4741eb98cc6bbf185403c1c690cb6a6999944e81056bac7ab2bef5684e1b0b
MD5 74cf739a4db2162c416d30dd1b25dbea
BLAKE2b-256 2f1a694c8ad6ce174a56549719a25437592340eb26f285627674e0d6dc1bb841

See more details on using hashes here.

Provenance

File details

Details for the file symbolite_array-0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for symbolite_array-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4fc79686ab9354ecff0987e488f4fbb33ec30b3fe2abb58eaa18b31683f34d00
MD5 44e6d69781dd81aa5cc75a0ccce7f40a
BLAKE2b-256 6c768b3d15fc643a079062bcde90224acca755d08607749e31ead622b4d78cc7

See more details on using hashes here.

Provenance

Supported by

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