Tropical (min-plus and max-plus) matrix algebra in pure Python — no imports, single file. It runs unchanged on CPython, in the browser, and on a NumWorks calculator.
In your browser. Open the online NumWorks simulator, go to the Python app, add a script named tropmat, and paste in the file. Good for a quick try; the simulator's storage resets on reload.
On a physical NumWorks. At my.numworks.com, sign in (or connect over USB), add the tropmat script, and send it to the device.
On your computer. With CPython or MicroPython, run it from the folder holding the file:
>>> import tropmat >>> tropmat.poster_selftest() # prints 10 passes >>> B = tropmat.kinesin_B(3, 1, 2) >>> tropmat.max_cycle_mean(B) # the period lambda >>> tropmat.eigenvector(B) # the gait >>> tropmat.kinesin_report(3, 1, 2) # full stepping-model summary
Matrices are lists of lists of floats; float('inf') and float('-inf') are the semiring zeros. Pass a semiring (MINPLUS or MAXPLUS) where one is required.
| core | |
|---|---|
| mmul(A, B, S) | matrix product in semiring S; minmul / maxmul are shortcuts |
| mvmul(A, x, S) | matrix–vector product; iterate x(k) = A ⊗ x(k−1) |
| mpow(A, e, S) | e-th power (binary exponentiation) |
| closure(A, S) | Kleene star; shortest_paths / critical_paths wrap it |
| from_native(s) | parse a "[[..],[..]]" string into a matrix; show prints one |
| spectral (max-plus) | |
| max_cycle_mean(A) | the eigenvalue λ via Karp's algorithm (alias eigenvalue) |
| min_cycle_mean(A) | the min-plus counterpart |
| eigenvector(A, node) | (λ, v) with A ⊗ v = λ ⊗ v; node picks the critical class |
| critical_nodes(A) | indices lying on a maximum-mean cycle |
| check_eig(A) | numerically verify the eigen-relation |
| structure & dynamics | |
| is_irreducible(A) | strong connectivity (the Perron–Frobenius hypothesis) |
| ldiv(A, b) | residuation: greatest x with A ⊗ x ≤ b |
| orbit(A, x0, steps) | iterate the max-plus dynamics; transient finds cyclicity |
| kinesin model | |
| kinesin_B(tf, tg, tD) | the recurrent 2×2 block B |
| kinesin_report(tf, tg, tD) | B, λ, regime, robustness gap, head offset |
| poster_selftest() | 10 checks reproducing the poster's deductions |