Dijkstra’s non-deterministic Guarded Command Language from afar

Arnav Kumar

March 17th, 2026

What is a non-deterministic language?

Intro to the Guarded Command Language (GCL)

Guarded Command Sets

⟨guard⟩ ::= ⟨boolean expression⟩
⟨guarded list⟩ ::= ⟨statement⟩ {; ⟨statement⟩}
⟨guarded command⟩ ::= ⟨guard⟩ → ⟨guarded list⟩
⟨guarded command set⟩ ::= ⟨guarded command⟩ {□ ⟨guarded command⟩}

Alternative Statements

⟨alternative construct⟩ ::= if ⟨guarded command set⟩ fi

Repetitive Statements

⟨repetitive construct⟩ ::= do ⟨guarded command set⟩ od

Examples: Sorting 4 numbers

// want a, b, c, d a permutation of A, B, C, D
// such that a ≤ b ≤ c ≤ d

a, b, c, d := A, B, C, D;

do (a < b) → a, b := b, a
 □ (b < c) → b, c := c, b
 □ (c < d) → c, d := d, c
od

Examples: Argmax of a function

// suppose f : {1 .. k} → Int
// want m such that f(m) ≥ f(i) for all i ∈ {1 .. k}

m := 1;
i := 1;

do i ≤ k → if f(i) ≤ f(m) → i := i + 1
            □ f(i) ≥ f(m) → k := i; i := i + 1
           fi
od

Example: GCD

// want g such that g = GCD(X, Y) for X, Y ∈ Nat

x, y := X, Y

do (x > y) → x := x - y
 □ (y > x) → y := y - x
od

g := x

Applications

Learn More

Dijkstra, Edsger W. ["EWD472: Guarded commands, non-determinacy and formal. derivation of programs"](http://www.cs.utexas.edu/users/EWD/ewd04xx/EWD472.PDF) (PDF). Retrieved March 14, 2026.

Also take a look at the Promela wikipedia and the SPIN model checker webpage