A small package for doing commutator algebra
Project description
Commutation Station for Operator Elimination
A proof assistant tool for the busy physicist, to be used in evaluating large commutator expressions. This package does symbolic algebra on noncommutative objects.
Example usage:
Creating Expressions from Operators
from commutation import *
from fractions import Fraction
a = Operator('a','S^x_a')
b = Operator('b','S^z_b')
c = Operator('c','S^z_c')
d = Operator('d','S^z_d')
# building everything up from elementary operators
x = a-9*b*c + a*b*a
print(x)
# +1 a -9 b c +1 a b a
Complicated substitutions
x = a*b*b*b*a*c*a*a*c*a*b + 1
y = x.substitute(a*b,c+d)
print(x) # +1 a b b b a c a a c a b +1
print(y) # +1 c b b a c a a c c +1 c b b a c a a c d +1 d b b a c a a c c +1 d b b a c a a c d +1
Factorisations
xx = 7*a*b*b + Fraction(4,5)*a*c*b*b + a*d*b*b + a*c*a*a*b*b + 3*a*b*b
fr, ba = xx.factor('right')
print(str(fr) + ' * [' + str(ba) + ' ] = ' +str(fr*ba)) # +1 a * [ +10 b b +4/5 c b b +1 d b b +1 c a a b b ] = +10 a b b +4/5 a c b b +1 a d b b +1 a c a a b b
fr, ba = xx.factor()
print('['+str(fr) + ' ] * ' + str(ba) + ' = ' +str(fr*ba)) # [ +10 a +4/5 a c +1 a d +1 a c a a ] * +1 b b = +10 a b b +4/5 a c b b +1 a d b b +1 a c a a b b
Commutators
ca = CommutatorAlgebra()
az = Operator('az','S^z_a')
ap = Operator('a⁺','S^+_a')
am = Operator('a⁻','S^-_a')
KA = Operator('KA', 'K_A', scalar=True)
# note the funky bracket sequence - set_commutator actually returns a function
ca.set_commutator(az,ap)(ap)
ca.set_commutator(az,am)(-1*am)
ca.set_commutator(ap,am)(2*az)
# there are two modes: move_left and move_right
# Note that pathological commutators will make these fall into recursion loops...
xpr = Expression(az*ap*az*az*am)
ca.move_right(xpr, az)
xpr.collect()
print(xpr) # +1 a⁺ a⁻ az az az -2 a⁺ a⁻ az az +1 a⁺ a⁻ az
xpr = Expression(az*ap*az*az*am)
ca.move_left(xpr, am)
xpr.collect()
print(xpr) # +1 a⁻ az a⁺ az az -2 a⁻ az a⁺ az +2 az az az az -1 a⁻ a⁺ az az +1 a⁻ az a⁺ -4 az az az +2 a⁻ a⁺ az +2 az az -1 a⁻ a⁺
# these will warn you if you add an unknown operator...
xpr2 = Expression(az*ap*am*c*am)
ca.move_right(xpr2, az) # UserWarning: Non-scalar operator "c" is not in the commutator database, assuming it commutes...
xpr2.collect()
print(xpr2) # +1 a⁺ a⁻ c a⁻ az -1 a⁺ a⁻ c a⁻
# # ... but scalars are fine.
xpr3 = Expression(az*ap*am*KA*am)
ca.move_right(xpr3, az)
xpr3.collect()
print(xpr3) # +1 a⁺ a⁻ KA a⁻ az -1 a⁺ a⁻ KA a⁻
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file commutation-1.5.0.tar.gz.
File metadata
- Download URL: commutation-1.5.0.tar.gz
- Upload date:
- Size: 20.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
af6d726fed37968a21e149aee78981f2b600ce111c38e0c782b2e10e0fa98d25
|
|
| MD5 |
4b94d059a3c5f8f47277d6fd1e0be15c
|
|
| BLAKE2b-256 |
aad85017705fef58ea8c2b25c9e1693afbb9fa1b722f2269409f4760f368404d
|
Provenance
The following attestation bundles were made for commutation-1.5.0.tar.gz:
Publisher:
python-publish.yml on Spuriosity1/Commutation
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
commutation-1.5.0.tar.gz -
Subject digest:
af6d726fed37968a21e149aee78981f2b600ce111c38e0c782b2e10e0fa98d25 - Sigstore transparency entry: 245706135
- Sigstore integration time:
-
Permalink:
Spuriosity1/Commutation@ce4b1daf0ba89dcac70d3acfc59775f1ab3d8de3 -
Branch / Tag:
refs/tags/v1.5.0 - Owner: https://github.com/Spuriosity1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@ce4b1daf0ba89dcac70d3acfc59775f1ab3d8de3 -
Trigger Event:
release
-
Statement type:
File details
Details for the file commutation-1.5.0-py3-none-any.whl.
File metadata
- Download URL: commutation-1.5.0-py3-none-any.whl
- Upload date:
- Size: 21.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e35a02964d2b8846683b73e8041ef835c2772d373d2a9c5209abb31c724db36
|
|
| MD5 |
26819bd9be68848c6a132e9d8ff3e6b2
|
|
| BLAKE2b-256 |
d5cd4141506f7a556b1126fb22c69744256ea89932af6adbbfb0eb8d73bd5b8d
|
Provenance
The following attestation bundles were made for commutation-1.5.0-py3-none-any.whl:
Publisher:
python-publish.yml on Spuriosity1/Commutation
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
commutation-1.5.0-py3-none-any.whl -
Subject digest:
9e35a02964d2b8846683b73e8041ef835c2772d373d2a9c5209abb31c724db36 - Sigstore transparency entry: 245706143
- Sigstore integration time:
-
Permalink:
Spuriosity1/Commutation@ce4b1daf0ba89dcac70d3acfc59775f1ab3d8de3 -
Branch / Tag:
refs/tags/v1.5.0 - Owner: https://github.com/Spuriosity1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@ce4b1daf0ba89dcac70d3acfc59775f1ab3d8de3 -
Trigger Event:
release
-
Statement type: