tpt-zero-formal

Rust

Runtime building blocks for formal verification, design-by-contract, and probabilistic computing in Rust — zero external dependencies, no_std by default, panic-free.

0 stars0 forks0 watchersApache License 2.0

Languages

Rust100.0%
README

tpt-zero-formal

Runtime building blocks for formal verification, design-by-contract, and probabilistic computing in Rust — the bridge between high-assurance TPT languages (tpt-telos, tpt-eidos) and safe, mathematically sound Rust execution, and the foundational math for tpt-augur.

Rust's borrow checker prevents memory-safety issues, but not logical ones: dividing by zero, state-machine violations, out-of-bounds indices. And probabilistic/AI systems need rigorous, deterministic, sound math primitives that standard crates don't provide in a no_std context. tpt-zero-formal provides lightweight, zero-external-dependency primitives that make verification explicit, ergonomic, and mathematically sound.

Part of the wider tpt-zero-* ecosystem (tpt-zero-bytes, tpt-zero-text, tpt-zero-formal) — search tpt-zero on crates.io to see every crate in the family.

Target audience: developers using tpt-eidos/tpt-telos, safety-critical systems engineers (DO-178C, ISO 26262), and architects building formally verified microservices and AI systems.

Design principles

  • Zero external production dependencies. Every crate below depends only on core (and, opt-in, alloc) and on its sibling crates in this workspace — never on an outside crate.
  • no_std by default. std is an opt-in feature per crate.
  • Panic-free by default. Fallible operations return Result; violation checks in the design-by-contract crates are feature-gated so verification builds and production builds can differ deliberately, not accidentally.

Crates

Every crate is fully implemented either way — the split below is about what ships to crates.io under the tpt-zero- name versus what stays an internal-only, publish = false implementation detail (prefixed out-zero- instead, precisely so it's obvious at a glance in crates/ which is which). A crate is published only if it's a real, well-tested implementation and no existing crate already covers the same concept and is zero-dependency and no_std — otherwise it's better served by depending on that existing crate directly.

Design-by-Contract & Verification

Published:

CratePurpose
tpt-zero-invariantTraits/macros asserting state-machine invariants
tpt-zero-fsmZero-allocation, strongly-typed Finite State Machine builder
tpt-zero-ghostGhost state markers / phantom types for verification state
tpt-zero-smt-liteBasic SMT-style boolean/integer constraint helpers

Internal-only (not published — a zero-dep/no_std equivalent already exists, or the crate is too thin to stand alone):

CratePurposeClosest existing alternative
out-zero-contractrequires! / ensures! macros for design-by-contract programmingcontracts
out-zero-boundedZero-cost wrapper types guaranteeing numeric bounds, e.g. BoundedInt<0, 100>bounded-integer
out-zero-safe-castPanic-free, explicitly verified numeric casting traitsaz
out-zero-precondPrecondition checking with detailed error reportingcontracts
out-zero-postcondPostcondition validation and result verificationcontracts
out-zero-loop-invLoop invariant checking for iterative algorithms(thin wrapper over debug_assert!)

Probabilistic & Statistical Computing

Published (all 8 — no zero-dep/no_std equivalent stack exists on crates.io):

CratePurpose
tpt-zero-probLightweight probabilistic types (Dist<f64>) and statistical helpers
tpt-zero-statsCore statistical functions (mean, variance, std dev, percentiles)
tpt-zero-randDeterministic, seedable PRNGs (Xorshift, PCG)
tpt-zero-distCommon probability distributions (Normal, Uniform, Bernoulli, Poisson)
tpt-zero-samplerEfficient sampling algorithms for probabilistic inference
tpt-zero-bayesBayesian inference primitives and conjugate priors
tpt-zero-monte-carloMonte Carlo simulation utilities with variance reduction
tpt-zero-markovMarkov chain representations and transition matrix operations

Linear Algebra & Tensor Operations

Published (all 6 — nalgebra/ndarray/num-dual cover the same concepts but none are zero-dependency):

CratePurpose
tpt-zero-tensorFixed-rank tensor types for multi-dimensional data
tpt-zero-linalgCore linear algebra operations (dot/cross product, norms)
tpt-zero-decompMatrix decompositions (LU, QR, Cholesky)
tpt-zero-solverLinear system solvers (Gaussian elimination, iterative methods)
tpt-zero-eigenEigenvalue/eigenvector computation for small matrices
tpt-zero-gradAutomatic differentiation primitives for gradient computation

Type-Level & Compile-Time Verification

Published:

CratePurpose
tpt-zero-witnessWitness types that carry proofs of properties

Internal-only (not published — a zero-dep/no_std equivalent already exists, or the crate is too thin to stand alone):

CratePurposeClosest existing alternative
out-zero-type-levelType-level arithmetic/constraints using const genericstypenum
out-zero-phantomAdvanced phantom-type patterns for zero-cost abstractions(thin wrapper over PhantomData)
out-zero-refinementRefinement types encoding predicates in the type systemrefinement
out-zero-newtypeSafe newtype wrappers with automatic derivationderive_more / nutype
out-zero-assert-constCompile-time assertion utilities for const contextsstatic_assertions

Building

cargo build --workspace
cargo test --workspace
cargo clippy --workspace --all-targets --all-features -- -D warnings

Every crate also builds with --no-default-features (pure core, no alloc).

MSRV

Rust 1.85 (edition 2024).

License

Dual-licensed under MIT or Apache-2.0, at your option.