Skip to main content

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 from s0 by applying delta zero 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 with delta.

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 delta must 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.15

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tstate 0.1.15
File Size Uploaded
tstate-0.1.15.tar.gz 20.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tstate 0.1.15
File Interpreter ABI Platform
tstate-0.1.15-py3-none-any.whl Python 3 none any Details

Total release size: 25.5 kB

Release files / tstate-0.1.15.tar.gz

Download URL tstate-0.1.15.tar.gz
Size 20.3 kB
Tags Source
SHA-256 checksum
How to use checksums
bfd0fefc0ab71f8cf7e2500383085df6031b8ab9241e7b226e0a98dc01eb2db7
BLAKE2b-256 checksum
How to use checksums
dbfa12885b70c1df193f01408d7ea6adb8b7e9bf57fbdbd02454b5d59cf7a06f
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

Release files / tstate-0.1.15-py3-none-any.whl

Download URL tstate-0.1.15-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1947f7128b8a629a6af9f4ee64e3583228fc4c97de67fd9cf7d52f19cfc950d5
BLAKE2b-256 checksum
How to use checksums
f8e6d7fb2b83af43e1f6c975aaabe45988e106c10db2c61517633ff85e71cf78
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

Release history Release notifications | RSS feed

0.1.22

2 release files

0.1.21

2 release files

0.1.20

2 release files

0.1.19

2 release files

0.1.18

2 release files

0.1.17

2 release files

0.1.16

2 release files

This release

0.1.15 This release

2 release files

0.1.6

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page