MPlusA
MPlusA is a Python library for calculations in tropical algebra (also known as (min, +) and (max, +) algebra). For the full list of the library's capabilities refer to the documentation.
Contributing
The library is open for all contributions. If you want to contribute to its development, please refer to the guidelines to verify the code standards before making a pull request. Developments from all areas of tropical mathematics are welcome.
Installation
The easiest way to install the library is to use pip.
pip install mplusa
The only automatically installed dependency is NumPy. Otherwise the library does make use of Matplotlib for visualisations but it is not a required dependency and needs to be installed separately in case the user wants to use these capabilities.
Examples
For the full list of the library's capabilities, refer to the documentation documentation. This section is only meant to highlight the core features of the library.
Basic operations
# import maxplus instead of minplus to use the (max, +) semiring
from mplusa import minplus as mpa
import numpy as np
print(mpa.add(3, 5, 89)) # -> 3
print(mpa.mult(4, 8, 9)) # -> 21
print(mpa.power(10, 89)) # -> 890
print(mpa.modulo(10, 3)) # -> 1
A = np.array([
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
])
B = np.array([
[9, 8, 7],
[6, 5, 4],
[3, 2, 1],
])
print(mpa.add_matrices(A, B)) # -> [[1, 2, 3], [4, 5, 4], [3, 2, 1]]
print(mpa.mult_matrices(A, B)) # -> [[6, 5, 4], [9, 8, 7], [12, 11, 10]]
print(mpa.power_matrix(A, 3)) # -> [[3, 4, 5], [6, 7, 8], [9, 10, 11]]
print(mpa.modulo_matrices(A, np.array([[1, 2, 3]]).T)) # -> [[0, 0, 0], [0, 1, 0], [1, 2, 0]]
Matrix-specific operations
# import maxplus instead of minplus to use the (max, +) semiring
from mplusa import minplus as mpa
import numpy as np
A = np.array([
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
])
print(mpa.kleene_star(A)) # -> [[0, 2, 3], [4, 0, 6], [7, 8, 0]]
print(mpa.kleene_star_series(A)) # -> all the matrices generated during kleene star
print(mpa.kleene_plus(A)) # -> [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
print(mpa.kleene_plus_series(A)) # -> all the matrices generated during kleene plus
print(mpa.tdet(A)) # -> 15
print(mpa.is_matrix_singular(A)) # -> True
print(mpa.matrix_rank_tropical(A)) # -> 1
# This function takes an argument func which accepts the following methods:
# 1. mpa.power_algorithm (the default value)
# 2. mpa.karp_algorihtm
print(mpa.eigenvalue(A)) # -> 1
# This function takes an argument func which accepts the following methods:
# 1. mpa.power_algorithm (the default value)
# 2. mpa.kleene_star_algorithm
# 3. mpa.modified_kleene_star_algorithm
print(mpa.eigenvector(A)) # -> [[0], [3], [6]]
Polynomials
# import maxplus instead of minplus to use the (max, +) semiring
from mplusa import minplus as mpa
import numpy as np
p = mpa.MultivariatePolynomial(np.array([
[1, np.inf, 15],
[5, 0, np.inf],
[5, 4, 3],
]))
print(p) # -> (1) + (∞ * b) + (15 * b^2) + (5 * a) + (0 * a * b) + (∞ * a * b^2) + (5 * a^2) + (4 * a^2 * b) + (3 * a^2 * b^2)
print(p(8, 5)) # -> 1
print(p.get_linear_hyperplanes()) # -> [[1, 0, 0, 1], [15, 0, 2, 1], [5, 1, 0, 1], [0, 1, 1, 1], [5, 2, 0, 1], [4, 2, 1, 1], [3, 2, 2, 1]]
# A polynomial with one variable
p = mpa.Polynomial(5, 8, 9)
print(p) # -> (5) + (8 * a) + (9 * a^2)
print(p(8)) # -> 5
print(p.get_linear_hyperplanes()) # -> [[5, 0, 1], [8, 1, 1], [9, 2, 1]]
print(p.get_line_intersections()) # -> [(-2.0, 5.0)]
print(p.get_roots()) # -> ([-2.0], [1]) where the first value is the root and the latter is its corresponding rank
Geometry and visualizations
# import maxplus instead of minplus to use the (max, +) semiring
from mplusa import minplus as mpa
import numpy as np
# For visualizations matplotlib is required and is imported inside of the submodule
# By default drawing polytopes and hyperplanes won't display the figure and that is
# why it is imported here; it's not necessary if a figure is displayed using show=True
import matplotlib.pyplot as plt
# NOTE: the library uses the first element in a point for projections; it should usually be 0
p = mpa.geometry.Polytope2D((0, 1, 2), (0, 3, 3), (0, 4, 5))
print(p.vertices) # -> [[0, 1, 2], [0, 3, 3], [0, 4, 5]]
print(p.pseudovertices) # -> [[0, 2, 3], [0, 4, 4]]
print(p.edges) # -> [[[0, 1, 2], [0, 3, 3]], [[0, 3, 3], [0, 4, 5]], [[0, 4, 5], [0, 1, 2]]]
print(p.get_all_line_segments()) # -> point by point edges (including pseudovertices)
mpa.visualize.hasse_diagram(p)
mpa.visualize.draw_polytope2D(p, show=True)
for hyperplane in p.get_hyperplanes():
mpa.visualize.draw_hyperplane2d(hyperplane)
plt.show()
Metadata
Release files for mplusa 0.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mplusa-0.0.5.tar.gz | 22.4 kB | Without provenance | Details for mplusa-0.0.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mplusa-0.0.5-py3-none-any.whl | Python 3 | none | any | Details for mplusa-0.0.5-py3-none-any.whl |
Total release size: 46.8 kB
Release files / mplusa-0.0.5.tar.gz
| Download URL | mplusa-0.0.5.tar.gz |
|---|---|
| Size | 22.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e432599a4548dcce511d558c308152b8147cd5dde41511c7b4a46af3fa77718a
|
|
BLAKE2b-256 checksum How to use checksums |
9b9391d5156ef4a2efb67102da9c27074bbf2af74acefd57c345149ec80a6b05
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Release files / mplusa-0.0.5-py3-none-any.whl
| Download URL | mplusa-0.0.5-py3-none-any.whl |
|---|---|
| Size | 24.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ac536d310b95b9cf9dce6b12c252303f50552209ebeffa972130bf981a97d767
|
|
BLAKE2b-256 checksum How to use checksums |
078ed2e135db29dccb7112d7c9b3c8f5d4f2b26574312b8224bee21aea5f6e18
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Security for mplusa 0.0.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.