Skip to content

Denotational semantics of IMP

11 fully proved

IMP

DefinitionOne-step unfolding functional of a while loop#✓fully proved

Given a Boolean expression \(b\) (the guard) and a binary relation \(B\) on states (the body relation), the functional sends a relation \(R\) on states to the relation that relates \(s\) to \(s'\) exactly when either \(b\) evaluates to false in \(s\) and \(s' = s\), or \(b\) evaluates to true in \(s\) and there is a state \(m\) with \(B\) relating \(s\) to \(m\) and \(R\) relating \(m\) to \(s'\).

def whileFun (guard : BExp) (body : State → State → Prop)
    (R : State → State → Prop) : State → State → Prop :=
  fun s s' => (guard.eval s = false ∧ s' = s) ∨
    (guard.eval s = true ∧ ∃ m, body s m ∧ R m s')
Uses 3 · Used by 6

TheoremMonotonicity of the while-loop unfolding functional#✓fully proved

Let \(b\) be a Boolean expression, \(B\) a binary relation on states, and \(\Phi\) the one-step unfolding functional of a while loop with guard \(b\) and body relation \(B\). Then \(\Phi\) is monotone for inclusion of relations: for all relations \(R_1\) and \(R_2\) on states with \(R_1 \subseteq R_2\), we have \(\Phi(R_1) \subseteq \Phi(R_2)\).

theorem whileFun_mono {guard : BExp} {body : State → State → Prop} :
    Monotone (whileFun guard body)
Uses 4 · Used by 1

DefinitionThe while-loop functional as a monotone map#✓fully proved

For a boolean guard \(b\) and a relation \(B\) between states (the body denotation), this is the map \(\Phi\) on relations between states, ordered by inclusion, where \(\Phi(R)\) relates \(s\) to \(s'\) exactly when either \(b\) is false in \(s\) and \(s' = s\), or \(b\) is true in \(s\) and there is a state \(m\) with \(B(s, m)\) and \(R(m, s')\). The map \(\Phi\) is monotone: \(R_1 \subseteq R_2\) implies \(\Phi(R_1) \subseteq \Phi(R_2)\).

def whileOrderHom (guard : BExp) (body : State → State → Prop) :
    (State → State → Prop) →o (State → State → Prop) :=
  ⟨whileFun guard body, whileFun_mono⟩
Uses 4 · Used by 3

DefinitionRelational denotational semantics of IMP#✓fully proved

The denotation of an IMP command is a binary relation on states, defined by recursion on the command. The command \(\mathtt{skip}\) relates \(s\) to \(s'\) iff \(s' = s\). For a variable identifier \(x\) and an arithmetic expression \(a\), the assignment \(x := a\) relates \(s\) to \(s'\) iff \(s'\) is \(s\) with \(x\) updated to the value of \(a\) in \(s\). The sequence \(c_1; c_2\) relates \(s\) to \(s'\) iff there is a state \(m\) such that \(c_1\) relates \(s\) to \(m\) and \(c_2\) relates \(m\) to \(s'\). For a Boolean expression \(b\), the conditional \(\mathtt{if}\ b\ \mathtt{then}\ t\ \mathtt{else}\ e\) relates \(s\) to \(s'\) iff either \(b\) evaluates to true in \(s\) and \(t\) relates \(s\) to \(s'\), or \(b\) evaluates to false in \(s\) and \(e\) relates \(s\) to \(s'\). The denotation of \(\mathtt{while}\ b\ \mathtt{do}\ c\) is the least fixed point, for inclusion of relations, of the one-step unfolding functional of a while loop with guard \(b\) and body relation the denotation of \(c\).

def Denote : Cmd → State → State → Prop
  | .skip => fun s s' => s' = s
  | .assign n a => fun s s' => s' = Function.update s n (a.eval s)
  | .seq c₁ c₂ => fun s s' => ∃ m, Denote c₁ s m ∧ Denote c₂ m s'
  | .ite b t e => fun s s' =>
      (b.eval s = true ∧ Denote t s s') ∨ (b.eval s = false ∧ Denote e s s')
  | .while b c => (whileOrderHom b (Denote c)).lfp
Uses 7 · Used by 9

Denotations and big-step semantics

TheoremThe while denotation is a fixed point#✓fully proved

Let \(b\) be a Boolean expression and \(c\) an IMP command, let \(W\) be the relational denotation of \(\mathtt{while}\ b\ \mathtt{do}\ c\), and let \(\Phi\) be the one-step unfolding functional of a while loop with guard \(b\) and body relation the denotation of \(c\). Then \(W = \Phi(W)\).

theorem while_eq {b : BExp} {c : Cmd} :
    Denote (.while b c) = whileFun b (Denote c) (Denote (.while b c))
Uses 6 · Used by 1

TheoremUnfolding equation for the while denotation#✓fully proved

For every Boolean expression \(b\), IMP command \(c\) and states \(s\) and \(s'\), the relational denotation of \(\mathtt{while}\ b\ \mathtt{do}\ c\) relates \(s\) to \(s'\) if and only if either \(b\) evaluates to false in \(s\) and \(s' = s\), or \(b\) evaluates to true in \(s\) and there is a state \(m\) such that the denotation of \(c\) relates \(s\) to \(m\) and the denotation of the loop relates \(m\) to \(s'\).

theorem while_iff {b : BExp} {c : Cmd} {s s' : State} :
    Denote (.while b c) s s' ↔
      (b.eval s = false ∧ s' = s) ∨
        (b.eval s = true ∧ ∃ m, Denote c s m ∧ Denote (.while b c) m s')
Uses 7 · Used by 1

TheoremPark induction for while loops#✓fully proved

Let \(b\) be a Boolean expression, \(c\) an IMP command and \(P\) a binary relation on states, and let \(\Phi\) be the one-step unfolding functional of a while loop with guard \(b\) and body relation the denotation of \(c\). If \(\Phi(P) \subseteq P\), then for all states \(s\) and \(s'\) related by the relational denotation of \(\mathtt{while}\ b\ \mathtt{do}\ c\), \(P\) relates \(s\) to \(s'\).

theorem while_ind {b : BExp} {c : Cmd} {P : State → State → Prop}
    (hP : ∀ s s', whileFun b (Denote c) P s s' → P s s')
    {s s' : State} (h : Denote (.while b c) s s') : P s s'
Uses 6 · Used by 1

TheoremDenotational executions are big-step executions#✓fully proved

For every IMP command \(c\) and all states \(s\) and \(s'\), if the relational denotation of \(c\) relates \(s\) to \(s'\), then executing \(c\) from \(s\) terminates in \(s'\) according to the big-step semantics.

theorem bigStep_of_denote {c : Cmd} {s s' : State} (h : Denote c s s') :
    BigStep c s s'
Uses 10 · Used by 1

TheoremBig-step executions are denotational executions#✓fully proved

For every IMP command \(c\) and all states \(s\) and \(s'\), if executing \(c\) from \(s\) terminates in \(s'\) according to the big-step semantics, then the relational denotation of \(c\) relates \(s\) to \(s'\).

theorem denote_of_bigStep {c : Cmd} {s s' : State} (h : BigStep c s s') :
    Denote c s s'
Uses 9 · Used by 1

TheoremAgreement of the denotational and big-step semantics of IMP#✓fully proved

For every IMP command \(c\) and all states \(s\) and \(s'\), the relational denotation of \(c\) relates \(s\) to \(s'\) if and only if executing \(c\) from \(s\) terminates in \(s'\) according to the big-step semantics.

theorem iff_bigStep {c : Cmd} {s s' : State} :
    Denote c s s' ↔ BigStep c s s'
Uses 6 · Used by 3

TheoremThe denotational semantics of IMP is deterministic#✓fully proved

For every IMP command \(c\) and all states \(s\), \(s_1\) and \(s_2\), if the relational denotation of \(c\) relates \(s\) to \(s_1\) and \(s\) to \(s_2\), then \(s_1 = s_2\).

The proof goes through the agreement with the deterministic big-step semantics.

theorem deterministic {c : Cmd} {s s₁ s₂ : State}
    (h₁ : Denote c s s₁) (h₂ : Denote c s s₂) : s₁ = s₂
Uses 6

The dependency explorer needs JavaScript and its graph data.

Download the complete graph data.