Skip to main content

A library for calculations in tropical and arctic semirings.

Reason this release was yanked:

It contains mistakes

Project description

MPlusA


MPlusA is a small Python library for tropical algebra (also known as $(\min, +)$ and $(\max, +)$ algebra). It provides the definitions of basic operations on numbers and NumPy arrays, as well as a basic implementation of tropical polynomials.

Any improvements or fixes are always welcome.

How to use

After having installed the library one can import one of the two modules the package consists of (minplus and maxplus) and use the full array of its capabilities. The functions are essentially the same between the modules. The list below is a full list of the library's capabilities.

add(*args) -> Real Tropical addition. Essentially an alias for Python's min function. mult(*args) -> Real Tropical multiplication. Essentially an alias for Python's sum function. add_matrices(A : np.ndarray, B : np.ndarray) -> np.ndarray Tropical addition of NumPy arrays. The summed matrices have to be of the same shape. mult_matrices(A : np.ndarray, B : np.ndarray) -> np.ndarray Tropical multiplication of NumPy arrays. The multiplied matrices have to be of sizes MxN and NxP and their order matters. The result is of shape MxP. modulo(a : Real, t : int) -> Real Tropical modulo operator. It can be understood as the difference between the number $a$ and $t^k$ where $k$ is the largest integer that satisfies $a \geq t^k$. modulo_matrices(A : np.ndarray, b : np.ndarray) -> np.ndarray Tropical modulo operator for NumPy arrays. The input matrices should be of size MxN and Mx1. The result is an MxN matrix. power(a : real, k : int) -> Real Tropical power operator. Applies the multiplication k times. power_matrix(A : np.ndarray, k : int) -> np.ndarray Tropical power operator for NumPy arrays. It multiplies the matrix k times. unit_matrix(width : int, height : int) -> np.ndarray Creates a tropical unit matrix of given width and height. star(A : np.ndarray) -> np.ndarray Definition of a unique operator of tropical algebra, usually denoted as $\mathbf{A}^*$. It returns the value to which an infinite recursive sum of matrices converges. The input matrix has to be square and the series created in the process of calculating the value needs to be convergent. Polynomial(*coefficients) This is a class that implements basic single-variable tropical polynomials. Calling an object of this class allows to take a value the polynomial takes at a given point, it also implements function get_hypersurface which returns a list of its roots.

Example code

import numpy as np
from mplusa import minplus

# Basic operators
s = minplus.add(10, 6, 4, 13)  # -> 4
p = minplus.mult(10, 5, 8)  # -> 23
mod = minplus.modulo(p, s)  # -> 3

# NumPy arrays
A = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
B = np.array([[9, 8, 7], [6, 5, 4], [3, 2, 1]])
S = minplus.add_matrices(A, B)  # -> [[1, 2, 3], [4, 5, 4], [3, 2, 1]]
P = minplus.mult_matrices(A, B)  # -> [[6, 5, 4], [9, 8, 7], [12, 11, 10]]

Bibliography

  1. A. Obuchowicz, K. A. D'Souza, Z. A. Banaszak. An Algebraic Approach to Modelling and Performance Optimisation of a Traffic Route System. International Journal of Applied Mathematics and Computer Science, vol. 8, no. 2, pp. 335-365, June 1998.
  2. D. Speyer, B. Sturmfels. "Tropical Mathematics". Mathematics Magazine, vol. 82, no. 3, pp. 163-173, June 2009, doi: https://doi.org/10.4169%2F193009809x468760.

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

mplusa-0.0.1.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

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

mplusa-0.0.1-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file mplusa-0.0.1.tar.gz.

File metadata

  • Download URL: mplusa-0.0.1.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.2

File hashes

Hashes for mplusa-0.0.1.tar.gz
Algorithm Hash digest
SHA256 b8e16d27d689a14fcfc5fa591d2e4bed418f11ed36c42f393a41861a9e36de6b
MD5 06dbdfabaf8400065c4b30b52e5c1f08
BLAKE2b-256 d1606d5d61dc062d11dfee7c021ccf209d5961bb7897748e62ec134779c4fc51

See more details on using hashes here.

File details

Details for the file mplusa-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: mplusa-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.2

File hashes

Hashes for mplusa-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6fb22969a1a76f95f9b4c97bec20c653530d6055af0e5cb52511e1d2cc3544d0
MD5 c08651f0e6c7b354ff452481aa59fe12
BLAKE2b-256 ca153e1a3940475c8941bcb8949397ed26fec95a9f3dcc58514ac9e93b8c3412

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