Alloy Specification Language

Table of Contents

Introduction

Alloy is a lightweight formal specification language for software modeling, based on first-order relational logic with transitive closure.

Key Characteristics

  • Declarative relational modeling
  • Bounded model checking (SAT-based)
  • Automatic counterexample generation
  • Small scope hypothesis

Alloy vs TLA+ vs Lean4

diagram-formal-methods-comparison.png

Core Concepts

Signatures and Relations

sig Node {
    edges: set Node
}

sig Graph {
    nodes: set Node
}

fact acyclic {
    no n: Node | n in n.^edges
}

State Machine Pattern

diagram-alloy-state-machine.png

Bounded Model Checking

diagram-alloy-solver-flow.png

Integration with Scheme

diagram-alloy-scheme-integration.png

Example: Redirect Termination

Proving that a web redirect chain always terminates.

Model

sig URL {}
sig RedirectMap {
    redirect: URL -> lone URL
}

pred terminates[m: RedirectMap] {
    no u: URL | u in u.^(m.redirect)
}

assert AllRedirectsTerminate {
    all m: RedirectMap | terminates[m]
}

check AllRedirectsTerminate for 10

Resources

Author: Jason Walsh

jwalsh@nexus

Last Updated: 2026-05-19 20:36:44

build: 2026-05-19 23:12 | sha: 5cfabd4