Guarded Command Language
The Guarded Command Language (GCL) is a programming language defined by Edsger Dijkstra for predicate transformer semantics in EWD472.[src] It combines programming concepts in a compact way.[src] It makes it easier to develop a program and its proof hand-in-hand, with the proof ideas leading the way; moreover, parts of a program can actually be calculated.[src] An important property of GCL is nondeterminism.[src] For example, in the if-statement, several alternatives may be true, and the choice is made at runtime, when the if-statement is executed.[src] This frees the programmer from having to make unnecessary choices and is an aid in the formal development of programs.[src] GCL includes the multiple assignment statement.[src] For example, execution of the statement is done by first evaluating the righthand side values and then storing them in the lefthand variables.[src] Thus, this statement swaps the values of and .[src] The following books discuss the development of programs using GCL: * * * * *[src]
The Guarded Command Language (GCL) is a programming language defined by Edsger Dijkstra for predicate transformer semantics in EWD472.[src] It combines programming concepts in a compact way.[src] It makes it easier to develop a program and its proof hand-in-hand, with the proof ideas leading the way; moreover, parts of a program can actually be calculated.[src] An important property of GCL is nondeterminism.[src] For example, in the if-statement, several alternatives may be true, and the choice is made at runtime, when the if-statement is executed.[src] This frees the programmer from having to make unnecessary choices and is an aid in the formal development of programs.[src] GCL includes the multiple assignment statement.[src] For example, execution of the statement is done by first evaluating the righthand side values and then storing them in the lefthand variables.[src] Thus, this statement swaps the values of and .[src] The following books discuss the development of programs using GCL: ==Guarded command== A guarded command consists of a boolean condition or guard, and a statement "guarded" by it.[src] The statement is only executed if the guard is true, so when reasoning about the statement, the condition can be assumed true.[src] This makes it easier to prove the program meets a specification.[src] ===Syntax=== A guarded command is a statement of the form G → S, where G is a proposition, called the guard S is a statement ===Semantics=== If G evaluates to true, S is eligible to be executed.[src] In most GCL constructs, multiple guarded commands may have guards that are true, and exactly one of them is chosen arbitrarily to be executed.[src] If G is false, S will not be executed.[src] ==skip and abort== skip and abort are important statements in the guarded command language.[src] abort is the undefined instruction: do anything.[src] It does not even need to terminate.[src] It is used to describe the program when formulating a proof, in which case the proof usually fails.[src] skip is the empty instruction: do nothing.[src] It is often used when the syntax requires a statement but the state should not change.[src] ===Syntax=== skip abort ===Semantics=== skip: do nothing abort: do anything ==Assignment== Assigns values to variables.[src] ===Syntax=== v := E or v , v , ..., v := E , E , ..., E where v are program variables E are expressions of the same data type as their corresponding variables ==Catenation== Statements are separated by one semicolon (;) ==Selection: if== The selection (often called the "conditional statement" or "if statement") is a list of guarded commands, of which one is chosen to execute.[src] If more than one guard is true, one statement whose guard is true is arbitrarily chosen to be executed.[src] If no guard is true, the result is undefined, that is, equivalent to abort.[src] Because at least one of the guards must be true, the empty statement skip is often needed.[src] The statement if fi has no guarded commands, so there is never a true guard.[src] Hence, if fi is equivalent to abort.[src] ===Syntax=== if G0 → S0 □ G1 → S1 ...[src] □ Gn → Sn fi ===Semantics=== Upon execution of a selection, the guards are evaluated.[src] If none of the guards is true, then the selection aborts, otherwise one of the clauses with a true guard is chosen arbitrarily and its statement is executed.[src] ===Implementation=== GCL does not specify an implementation.[src] Since guards cannot have side effects and the choice of clause is arbitrary, an implementation may evaluate the guards in any sequence and choose the first true clause, for example.[src] ===Examples=== ====Simple==== In pseudocode: if a a := a - b and b := b - a in such a way that a≥0 and b≥0 remains true.[src] ====Extended Euclidean algorithm==== a, b, x, y, u, v := A, B, 1, 0, 0, 1; do b ≠ 0 → q, r := a div b, a mod b; a, b, x, y, u, v := b, r, u, v, x - q*u, y - q*v od This repetition ends when b = 0, in which case the variables hold the solution to Bézout's identity: xA + yB = gcd(A,B) .[src] ====Non-deterministic sort==== do a>b → a, b := b, a □ b>c → b, c := c, b □ c>d → c, d := d, c od The program keeps on permuting elements while one of them is greater than its successor.[src] This non-deterministic bubble sort is not more efficient than its deterministic version, but easier to prove: it will not stop while the elements are not sorted and that each step it sorts at least 2 elements.[src] ====Arg max==== x, y = 1, 1; do x≠n → if f(x) ≤ f(y) → x := x+1 □ f(x) ≥ f(y) → y := x; x := x+1 fi od This algorithm finds the value 1 ≤ y ≤ n for which a given integer function f is maximal.[src] Not only the computation but also the final state is not necessarily uniquely determined.[src] PullDownGuard → y := 0 PullUpGuard → y := 1 PullDownGuard and PullUpGuard here are functions of the logic gate's inputs, which describe when the gate pulls the output down or up, respectively.[src] Unlike classical circuit evaluation models, the repetition for a set of guarded commands (corresponding to an asynchronous circuit) can accurately describe all possible dynamic behaviors of that circuit.[src] Depending on the model one is willing to live with for the electrical circuit elements, additional restrictions on the guarded commands may be necessary for a guarded-command description to be entirely satisfactory.[src] Common restrictions include stability, non-interference, and absence of self-invalidating commands.[src]
53 sentences · 53 cited inline · 0 references stored
References
No reference rows published for this article.
Cite this article
MLA
"Guarded Command Language." encyclopegia.org, 2025, https://encyclopegia.org/wiki/guarded-command-language. Accessed 25 November 2026.
Chicago
"Guarded Command Language." encyclopegia.org. Accessed November 25, 2026. https://encyclopegia.org/wiki/guarded-command-language.
APA
encyclopegia.org. (2025). Guarded Command Language. Retrieved November 25, 2026, from https://encyclopegia.org/wiki/guarded-command-language
Accessed November 25, 2026 · CC BY-SA 4.0 · citation page · JSON