See also
A lot of different program analysis techniques rely on the concept of a lattice. What the hell is a lattice?
Partial ordering
Let’s say we have a set
- Reflexivity:
- Transitivity:
- Anti-symmetry:
We call
See also: Partial orders in the abstract
Lattices: meet and join
Lets say we have a subset
- Join
returns the least upper bound between items in the lattice. is an upper bound of items in , such that any other upper bound is even larger. or is the upper bound between and . - The element
is the greatest element. . - We’re moving through the lattice in the direction of the gap: up!
- In domain theory, we use least upper bounds (lubs) to order recursive function invocations and provide a concrete upper bound on their denotations.
- If an imperative statement is a function from state to state, in the limit, what does a while loop’s function behavior loop like? That limit is the least upper bound of infinitely many recursive invocations of the loop.
- Meet
returns the greatest lower bound between items in the lattice. is an upper bound on items in , such that any other upper bound is even larger. or is the upper bound between and . - The element
is the least element. . - We’re moving through the lattice in the direction of the gap: down!
- In dataflow analysis, we use a meet semilattice—a lattice but with only the meet operation—to combine dataflow information at CFG intersection points.
- In this context, larger values denote more precise analyses.
- For instance, in constant propagation,
, indicating no precision on what constants the value could be, and , indicating a variable with the possibility of “the most precision”: being unanalyzed so far!
Notation
Sometimes, we use
for join and for meet. Interchangeable, mostly
To make sure that join and meet have agreeing behavior, we enforce a rule called absorption:
Note that the meaning of
In general, what you can rely on is that in
Also note that
In a complete lattice, every subset of
Semi-lattices
With semilattices, you only have one of these operations, either join or meet.