---
title: "Specifying Correctness: Safety, Liveness and Invariants"
description: "Before anything can be proved, the claim has to be written down. A safety property says nothing bad ever happens and is refuted by a finite trace; a liveness property says something good eventually do"
canonical: https://lightmysky.com/learn/computing/specifying-correctness-safety-liveness-and-invariants-mt_4_KaoDSHZF
source: https://lightmysky.com/learn/computing/specifying-correctness-safety-liveness-and-invariants-mt_4_KaoDSHZF.md
retrieved: 2026-09-12
---

> **Agent view.** This is the Markdown twin of the page, for tools and assistants.
> When to use this site, and the call that answers each job: https://lightmysky.com/agent-instructions.md
> API description (OpenAPI 3.1): https://lightmysky.com/openapi.json · Authentication: https://lightmysky.com/auth.md
> Pricing: https://lightmysky.com/pricing.md · Catalog: https://lightmysky.com/llms.txt · Full catalog: https://lightmysky.com/llms-full.txt
> Every machine-readable file on this domain: https://lightmysky.com/.well-known/ai-catalog.json
> Ask for Markdown with `Accept: text/markdown`, a `.md` address, or `?mode=agent`.

# Specifying Correctness: Safety, Liveness and Invariants

Before anything can be proved, the claim has to be written down. A safety property says nothing bad ever happens and is refuted by a finite trace; a liveness property says something good eventually does and is not. An invariant is the safety property a proof actually uses.

Subject: Computing · Area: Software Engineering · Ages 22 to 24
Page: https://lightmysky.com/learn/computing/specifying-correctness-safety-liveness-and-invariants-mt_4_KaoDSHZF

## Ready when they can

- Classify stated properties as safety or liveness and say what a counterexample to each looks like
- Write an invariant for a small algorithm and check that every step preserves it
- Say why a specification that only forbids things can be satisfied by doing nothing

## Lesson: Forbid the bad, demand the good

After finding a valid schedule, you need words for what valid means. Safety says nothing bad ever happens, and one finite trace showing the bad thing refutes it. Liveness says something good eventually happens, and no finite snapshot refutes it, since the good thing could still arrive later.

**Example.** Take a lock. Safety: two holders never hold it at once, refuted by one trace with both holding. Liveness: every requester eventually gets it, refuted only by a whole infinite wait, never by one snapshot of someone queueing.

An invariant is the safety property proofs actually use: true at the start and preserved by every step. Check each step keeps it true and induction covers all runs. If one step breaks it, the proof fails, so fix the step or choose a weaker claim that survives.

A specification that only forbids things is satisfied by doing nothing: never crash and never send holds of a dead program. Always pair safety with the liveness that demands progress, or your proof may bless an idle system.

**Recap.** Safety is refuted by one trace, liveness needs forever, invariants bridge to proof.

## Practice

8 questions on this page, each with its working shown.

## Needs first

- [SAT Solvers and What Makes Search Practical](https://lightmysky.com/learn/computing/sat-solvers-and-what-makes-search-practical-mt_d46m2LD443)
- [Property-Based Testing](https://lightmysky.com/learn/computing/property-based-testing-mt_QqCNKT06IY)

## Opens up

- [Model Checking and the State-Space Explosion](https://lightmysky.com/learn/computing/model-checking-and-the-state-space-explosion-mt__pgZ0PzEZo)
