blog-static/content/blog/03_spa_agda_fixed_height.md
Danila Fedorin 826a16eb66 Start working on part 3
Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
2024-06-27 22:26:01 -07:00

3.4 KiB

title series description date draft tags
Implementing and Verifying "Static Program Analysis" in Agda, Part 3: Lattices of Finite Height Static Program Analysis in Agda In this post, I describe the class of finite-height lattices, and prove that lattices we've alread seen are in that class 2024-05-30T19:37:01-07:00 true
Agda
Programming Languages

In the previous post, I introduced the class of finite-height lattices: lattices where chains made from elements and the less-than operator < can only be so long. As a first example, [natural numbers form a lattice]({{< relref "01_spa_agda_lattices#natural-numbers" >}}), but they are not a finite-height lattice; the following chain can be made infinitely long:

{{< latex >}} 0 < 1 < 2 < ... {{< /latex >}}

There isn't a "biggest natural number"! On the other hand, we've seen that our [sign lattice]({{< relref "01_spa_agda_lattices#sign-lattice" >}}) has a finite height; the longest chain we can make is three elements long; I showed one such chain (there are many chains of length three) in [the previous post]({{< relref "02_spa_agda_combining_lattices#sign-length-three" >}}), but here it is again:

{{< latex >}} \bot < + < \top {{< /latex >}}

It's also true that the [Cartesian product lattice (L_1 \times L_2)]({{< relref "02_spa_agda_combining_lattices#the-cartesian-product-lattice" >}}) has a finite height, as long as L_1 and L_2 are themselves finite-height lattices. In the specific case where both L_1 and L_2 are the sign lattice ((L_1 = L_2 = \text{Sign} )) we can observe that the longest chains have five elements. The following is one example:

{{< latex >}} (\bot, \bot) < (\bot, +) < (\bot, \top) < (+, \top) < (\top, \top) {{< /latex >}}

The fact that L_1 and L_2 are themselves finite-height lattices is important; if either one of them is not, we can easily construct an infinite chain of the products. If we allowed L_2 to be natural numbers, we'd end up with infinite chains like this one:

{{< latex >}} (\bot, 0) < (\bot, 1) < (\bot, 2) < ... {{< /latex >}}

Another lattice that has a finite height under certain conditions is [the map lattice]({{< relref "02_spa_agda_combining_lattices#the-map-lattice" >}}). The "under certain conditions" part is important; we can easily construct an infinite chain of map lattice elements in general:

{{< latex >}} { a : 1 } < { a : 1, b : 1 } < { a: 1, b: 1, c: 1 } < ... {{< /latex >}}

As long as we have infinite keys to choose from, we can always keep adding new keys to make bigger and bigger maps. But if we fix the keys in the map -- say, we use only a and b -- then suddenly our heights are once again fixed. In fact, for the two keys I just picked, one longest chain is remarkably similar to the product chain above.

{{< latex >}} {a: \bot, a: \bot} < {a: \bot, b: +} < {a: \bot, b: \top} < {a: +, b: \top} < {a: \top, b: \top} {{< /latex >}}

The class of finite-height lattices is important for static program analysis, because it ensures that out our analyses don't take infinite time. Though there's an intuitive connection ("finite lattices mean finite execution"), the details of why the former is needed for the latter are nuanced. We'll talk about them in a subsequent post.

In the meantime, let's dig deeper into the notion of finite height, and the Agda proofs of the properties I've introduced thus far.

{{< todo >}} The rest of this. {{< /todo >}}