Skip to main content

Sympy Lie Algebra extensions powered by rust.

Project description

liesym

Lie Algebras using Sympy and backend powered by Rust's pyO3 and ndarray

Overview

In an effort to supply python with the same computer algebra software (CAS) capabilities, SymPy was written. This python library is well written and allows an open source alternative to proprietary choices like Mathematica/WolframLanguage and Maple. Due to the nature of how SymPy was written, certain symbolic calculation can be extremely unoptimized in python. Even using numpy could offer little speed ups as it is not geared towards rational numbers (fractions). Sympy does currently offer a liealgebras module, but due to the performance limitations, certain tradeoffs had to be made such as locking the basis for the classic lie algebras in favor of speed. This is a fair trade off, but would require anyone using a different basis to hand calculate the representations of the algebra all over again. An alternative to solve this problem would be to use a compiled backend that supports generics (and isn't a pain to build with python).

Rust has good python binding support through py03 and allows easy communication through numpy using rust-numpy as well as numpy like api inside rust using ndarray.

Install

pip install liesym

Examples

See also example notebook

import liesym as ls
from sympy import Matrix

Cartan Matrix

A3 = ls.A(3)
print(A3.cartan_matrix)
Matrix([[2, -1, 0], [-1, 2, -1], [0, -1, 2]])

Positive Roots

A3.positive_roots
[Matrix([[1, 0, 1]]),
 Matrix([[-1, 1, 1]]),
 Matrix([[1, 1, -1]]),
 Matrix([[-1, 2, -1]]),
 Matrix([[0, -1, 2]]),
 Matrix([[2, -1, 0]])]

Simple Roots

A3.simple_roots
[Matrix([[1, -1, 0, 0]]), Matrix([[0, 1, -1, 0]]), Matrix([[0, 0, 1, -1]])]

Fundamental Weights

A3.fundamental_weights # Orthogonal Basis
[Matrix([[3/4, -1/4, -1/4, -1/4]]),
 Matrix([[1/2, 1/2, -1/2, -1/2]]),
 Matrix([[1/4, 1/4, 1/4, -3/4]])]

Dimension of representation

print("Dim | Rep (Omega)")
print("---------")
for i in A3.fundamental_weights:
    print(" ", A3.dim(i), "|", A3.to_omega(i))
Dim | Rep (Omega)
---------
  4 | Matrix([[1, 0, 0]])
  6 | Matrix([[0, 1, 0]])
  4 | Matrix([[0, 0, 1]])

Name of rep

Commonly in literature (especially physics), names of the reps are the dimension rather than the matrix rep.

A3.dim_name(Matrix([[0, 0, 1]]))

$\displaystyle \bar{4}$

A3.irrep_lookup(r"\bar{4}")

$\displaystyle \left[\begin{matrix}0 & 0 & 1\end{matrix}\right]$

Tensor product decomps

The decomp of irreps from a product of irreps

results = A3.tensor_product_decomposition([
    Matrix([[1,0,0]]),
    Matrix([[1,0,0]]),
])

for i in results:
    print("Rep:", A3.to_omega(i),"Dim Name:", A3.dim_name(i))
Rep: Matrix([[0, 1, 0]]) Dim Name: 6
Rep: Matrix([[2, 0, 0]]) Dim Name: \bar{10}

Repo Layout

If you are new to how python and rust are tied together with py03, below is a simple top level layout of this repository. When the rust code is build into a lib binary, it is put into into ./liesym so it can be imported in ./liesym/__init__.py

.
├── Cargo.toml          # rust config file
├── README.md           # you are here
├── liesym              # python module
├── notebooks           # jupyter notebooks
├── src                 # rust source code
├── tests               # python tests
└── ...                 # other stuff

Docs

Read the documentation at https://npapapietro.github.io/liesym/

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

liesym-0.4.1.tar.gz (28.9 kB view hashes)

Uploaded Source

Built Distributions

liesym-0.4.1-cp39-cp39-win_amd64.whl (286.4 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

liesym-0.4.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.2 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

liesym-0.4.1-cp39-cp39-macosx_10_15_x86_64.whl (397.9 kB view hashes)

Uploaded CPython 3.9 macOS 10.15+ x86-64

liesym-0.4.1-cp38-cp38-win_amd64.whl (286.0 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

liesym-0.4.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.1 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

liesym-0.4.1-cp38-cp38-macosx_10_15_x86_64.whl (397.7 kB view hashes)

Uploaded CPython 3.8 macOS 10.15+ x86-64

liesym-0.4.1-cp37-cp37m-win_amd64.whl (286.1 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

liesym-0.4.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

liesym-0.4.1-cp37-cp37m-macosx_10_15_x86_64.whl (398.1 kB view hashes)

Uploaded CPython 3.7m macOS 10.15+ x86-64

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