IMP: a simple imperative language
Before we begin, we need to define a simple imperative language used by the book, termed IMP. This language features assignment of numerical expressions to mutable reference locations.
Imp’s syntax:
c
is “commands”
Who cares about denotational semantics
- It can handle a bunch of PLs (though not parallelism and “fairness”)
- We can compare what different PLs can do; if they can represent similar programs
- We want to directly define what commands are equivalent.
A denotational semantics for IMP
In the operational semantics for IMP, the single-step evaluation relation on arithmetic exprs (a
/Aexp
) (exprs of metavar c
) is defined as a function that takes a command and a state and returns a natural number. The relation on booleans returns a Bool
, and the relation on commands returns a new state, where a state
In this setting, let the denotation (i.e., meaning) of an arithmetic expression
Similarly, a boolean expression
On the brackets
Denotational semantics girlies love their double brackets
. This is to denote that the expression inside the double brackets shouldn’t be evaluated—essentially a kind of quasiquoting that can also contain metavariables!
To actually define these functions, we do induction.
Notice that we define partial functions via set/relation on pairs syntax.
For commands
Composition is a little funky. Let’s say we have two statements
For if statements, the function depends on if the boolean is true or not:
For while loops, things get a little dicey. For a while expression while
’s denotation in terms of if
, giving us an equation for the denotational semantics of
This gives us an equation that we can solve to figure out what
With this, we can then define a function
So now we no longer have recursion, but generating “layers” or “stages” of whiles.
Proving this is equivalent with operational semantics
For
Complete partial orders and continuous functions
From this point on, notes are moved to denotational semantics and domain theory since I need to synthesize hella different documents to figure out what’s going on lmao