The Science of Programming

Chapter-by-chapter notes on David Gries' book, plus the overview hub.

Choose a concept, then work through an example

17 guides in this section. Each article states its audience and assumptions, explains specialized terms, and gives a worked example or practical exercise.

Technical topics distinguish toy models from product behavior. Leadership topics distinguish context-dependent frameworks from evidence and personal claims.

01·Overview & HubConnect a specification to an algorithm through predicates, weakest preconditions, invariants, and termination. 02·Foundations — Correctness & PropositionsRead propositions, equivalence, and implication as precise statements about program behavior. 03·Predicates, States & QuantificationUse predicates, quantifiers, and capture-free substitution to specify arrays and state. 04·The Predicate Transformer wpCompute entry requirements backward from a desired output while keeping termination and definedness explicit. 05·Basic Commands & the Assignment AxiomTranslate assignment and sequencing into predicates, including parallel assignment and array updates. 06·The Alternative Command (IF)Understand guard coverage and correctness for every enabled nondeterministic branch. 07·The Iterative Command (DO) & InvariantsProve a loop by establishing and preserving its invariant and showing a decreasing well-founded measure. 08·Developing Programs & InvariantsInvent an invariant from the required result and use it to choose safe state updates. 09·Worked ExamplesConnect array sums, division, search, maxima, power, GCD, and partitioning to their complete contracts. 10·A Natural Deduction Proof SystemBuild proofs with explicit assumptions, valid inference rules, and correctly discharged scopes. 11·The Procedure CallUse procedure contracts while preserving old input values, frame conditions, and parameter-mode assumptions. 12·Bound Functions & TerminationChoose genuinely decreasing measures and recognize invalid termination examples. 13·Iteration instead of RecursionTranslate a recurrence into an iterative accumulator or explicit stack with a clear invariant. 14·Efficiency — Strengthening InvariantsOptimize through maintained relations without changing numeric or observable semantics accidentally. 15·Two Larger DevelopmentsDerive intersection and sorted-matrix search from shrinking candidate regions. 16·Inverting ProgramsUnderstand reversible mappings on explicit domains and why overwritten information may prevent undo. 17·Documentation & Historical NotesDocument the specification, invariant, frame, and progress argument that readers need to maintain correct code.

Find a guide

17 guides

The Science of Programming — Gries, Distilled

Connect a specification to an algorithm through predicates, weakest preconditions, invariants, and termination.

Preconditions and postconditions · Predicates and state · Hoare triples and total correctness · Weakest preconditions · Loop invariants · Variants and well-founded orders

Foundations — Why Correctness, and the Logic of Propositions

Read propositions, equivalence, and implication as precise statements about program behavior.

Predicates and state · Quantifiers and implication · Preconditions and postconditions · Hoare triples and total correctness

Predicates, States & Quantification

Use predicates, quantifiers, and capture-free substitution to specify arrays and state.

Predicates and state · Quantifiers and implication · Substitution without capture · Preconditions and postconditions · Aliasing and frame conditions

The Predicate Transformer wp

Compute entry requirements backward from a desired output while keeping termination and definedness explicit.

Weakest preconditions · Substitution without capture · Hoare triples and total correctness · Predicates and state · Guarded commands and nondeterminism

Basic Commands & the Assignment Axiom

Translate assignment and sequencing into predicates, including parallel assignment and array updates.

Weakest preconditions · Substitution without capture · Aliasing and frame conditions · Preconditions and postconditions

The Alternative Command — Guarded Selection (IF)

Understand guard coverage and correctness for every enabled nondeterministic branch.

Guarded commands and nondeterminism · Weakest preconditions · Predicates and state · Preconditions and postconditions

The Iterative Command — Loops, Invariants & Bounds

Prove a loop by establishing and preserving its invariant and showing a decreasing well-founded measure.

Loop invariants · Variants and well-founded orders · Hoare triples and total correctness · Preconditions and postconditions · Guarded commands and nondeterminism

Developing Programs — Goal-Oriented Construction & Inventing Invariants

Invent an invariant from the required result and use it to choose safe state updates.

Preconditions and postconditions · Loop invariants · Variants and well-founded orders · Weakest preconditions

Worked Examples — From Specification to Correct Program

Connect array sums, division, search, maxima, power, GCD, and partitioning to their complete contracts.

Preconditions and postconditions · Loop invariants · Variants and well-founded orders · Guarded commands and nondeterminism · Complexity and workload assumptions

A Natural Deduction Proof System

Build proofs with explicit assumptions, valid inference rules, and correctly discharged scopes.

Predicates and state · Quantifiers and implication · Hoare triples and total correctness · Guarded commands and nondeterminism

The Procedure Call

Use procedure contracts while preserving old input values, frame conditions, and parameter-mode assumptions.

Preconditions and postconditions · Aliasing and frame conditions · Hoare triples and total correctness · Recursion and induction · Substitution without capture

Bound Functions & Termination

Choose genuinely decreasing measures and recognize invalid termination examples.

Variants and well-founded orders · Loop invariants · Quantifiers and implication · Complexity and workload assumptions

Iteration Instead of Recursion

Translate a recurrence into an iterative accumulator or explicit stack with a clear invariant.

Recursion and induction · Loop invariants · Variants and well-founded orders · Aliasing and frame conditions · Complexity and workload assumptions

Efficiency — Strengthening Invariants

Optimize through maintained relations without changing numeric or observable semantics accidentally.

Refinement and observational equivalence · Loop invariants · Complexity and workload assumptions · Preconditions and postconditions

Two Larger Developments

Derive intersection and sorted-matrix search from shrinking candidate regions.

Loop invariants · Variants and well-founded orders · Preconditions and postconditions · Quantifiers and implication · Complexity and workload assumptions

Inverting Programs

Understand reversible mappings on explicit domains and why overwritten information may prevent undo.

Program inversion and lost information · Preconditions and postconditions · Aliasing and frame conditions · Variants and well-founded orders

Documenting Programs & Historical Notes

Document the specification, invariant, frame, and progress argument that readers need to maintain correct code.

Preconditions and postconditions · Loop invariants · Variants and well-founded orders · Hoare triples and total correctness · Refinement and observational equivalence