tstate
tstate is a Python library that computes the set of states reachable from a given set of initial states in a state machine. A state machine is described by an initial set of states and a successor function that maps each state to a set of successor states. The reachable set is the collection of every state that can be reached from an initial state by applying the successor function zero or more times. tstate returns the reachable set, the set of cycles in the state graph, the set of attractors, and the set of symmetries of the successor function. tstate uses only the Python standard library. tstate is the mathematical foundation of The Mark Intelligence Group's stack.
tstate is a name; it is not an abbreviation.
tstate is a standalone library. The only runtime dependency is the Python standard library. No other program in The Mark Intelligence Group's stack is required to use tstate.
What problem tstate solves
The Mark Intelligence Group's stack produces eight independent kinds of verifiable claim about a computer system. tstate contributes the first: a claim about which states a system can reach.
A reachability claim is the mathematical substrate of several other programs. state-substrate attests to files that hold the state. twin-fabric compares a model of behavior against observed behavior, which is a claim about which states follow which. aesn executes commands that move the system between states. Without a canonical definition of "reachable", each of those programs would have to invent one, and each invention would differ in the edge cases.
Existing implementations disagree on three points. First, whether a path that returns to its own starting state counts as a cycle. Second, whether an attractor includes states with no outgoing transitions. Third, whether the reachable set includes the initial states themselves.
tstate's purpose within the stack is to provide the single canonical definition that every other program uses. The reachable set, the set of cycles, the set of attractors, and the set of symmetries are each returned with one agreed meaning.
tstate's importance within the stack is that it is the mathematical foundation. Every claim in the stack that begins with "the system can reach ..." reduces to a reachability question of the kind tstate answers.
What tstate provides
Four functions:
reachable(s0, delta)returns the set of states reachable froms0by applyingdeltazero or more times.cycles(s0, delta)returns every simple cycle in the reachable set.attractors(s0, delta)returns every closed subset of the reachable set.symmetries(s0, delta)returns every automorphism of the state graph that commutes withdelta.
The mathematical model
Let S be a set of hashable values. Let S0 be a finite subset of S. Let
delta: S -> P(S) be a function that maps each state to a set of states. The
reachable set is:
Reach(S0, delta) = union over n >= 0 of delta^n(S0)
where delta^0(S0) = S0 and delta^(n+1)(S0) = union of delta(s) for s in delta^n(S0).
A cycle is a path s_0 -> s_1 -> ... -> s_k -> s_0 where k >= 1.
An attractor is a subset A of Reach such that no successor of any element of
A lies outside A.
A symmetry is a bijection sigma: S -> S such that for every state s,
delta(sigma(s)) = sigma(delta(s)).
Installation
pip install tstate
Usage
from tstate import reachable, cycles, attractors
def delta(s):
return {(s + 1) % 3, s}
R = reachable({0}, delta)
assert R == frozenset({0, 1, 2})
C = cycles({0}, delta)
assert (0, 1, 2, 0) in C
A = attractors({0}, delta)
assert frozenset({0, 1, 2}) in A
A second example: verifying that a two-leader state is unreachable in a simple leader-election protocol.
from tstate import reachable
def delta(state):
leader, voters = state
out = {(leader, voters)}
for v in voters:
if v != leader:
out.add((v, voters))
return out
R = reachable({("A", ("A", "B", "C"))}, delta)
two_leaders = [s for s in R if len({s[0]}) > 1]
assert not two_leaders
Known limitations
- States must be hashable. Unhashable states raise an error.
- Memory usage grows linearly with the size of the reachable set.
- Traversal is single-threaded.
- The successor function
deltamust be pure: it must not modify state outside the values passed to it. - Only deterministic transitions are supported. Probabilistic transitions are not modeled.
Relationship to The Mark Intelligence Group's stack
tstate is the mathematical foundation of The Mark Intelligence Group's stack. The abstractions in the other programs reduce to reachability in the sense defined above. Formal specification: docs/SPEC.md. Relationship model: docs/STACK.md.
License
See LICENSE.
Metadata
Release files for tstate 0.1.17
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| tstate-0.1.17.tar.gz | 20.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tstate-0.1.17-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 25.5 kB
Release files / tstate-0.1.17.tar.gz
| Download URL | tstate-0.1.17.tar.gz |
|---|---|
| Size | 20.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
68fa6a078e29b860ceac307fa66f0338a307f7cc7d0515ad6cb29d6229171d79
|
|
BLAKE2b-256 checksum How to use checksums |
9b7e54fedf03e5770f7cb9cc9f153d42952e41ecae7f0b1bde2358e3f99e667a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 29, 2026.
Transparency logRelease files / tstate-0.1.17-py3-none-any.whl
| Download URL | tstate-0.1.17-py3-none-any.whl |
|---|---|
| Size | 5.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
11152f892efe601cbe94fa6231cdde7957188b13e2ea69f43c985669c72d298b
|
|
BLAKE2b-256 checksum How to use checksums |
cff217b01f38e7189b4213b48bf11e3cfa050f372f9a0b1d325afb02b03d44fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 29, 2026.
Transparency log