Alloy Specification Language

Table of Contents

1. Introduction

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

1.1. Key Characteristics

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

2. Alloy vs TLA+ vs Lean4

diagram-formal-methods-comparison.png

3. Core Concepts

3.1. Signatures and Relations

verified · pilot-annotation-pass · 2026-10-08
sig Node {
    edges: set Node
}

sig Graph {
    nodes: set Node
}

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

4. Bounded Model Checking

corrected · pilot-annotation-pass · 2026-10-08

diagram-alloy-solver-flow.png

5. Integration with Scheme

diagram-alloy-scheme-integration.png

6. Example: Redirect Termination

corrected · pilot-annotation-pass · 2026-10-08

Checking whether a web redirect chain always terminates.

6.1. 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

Running this check in the Alloy Analyzer finds a counterexample at scope 10: two URLs redirecting to each other. The model never restricts redirect to be acyclic, so an instance with a loop is valid, and the assertion fails. A model that actually proves termination needs an added fact ruling out cycles:

fact acyclicRedirects {
    all m: RedirectMap | no u: URL | u in u.^(m.redirect)
}

Verified: adding this fact to the model makes the check return UNSAT (no counterexample) at the same scope.

7. Resources