Work on this exercise locally

This web app is a reference guide — you can read instructions, browse starter code, and view tests here. To actually complete the exercise, you need to work in your local development environment.

1Clone the repo: git clone https://github.com/weihaoqu/program-analysis-bootcamp-student
2Edit the starter file in your editor (VS Code, Vim, etc.) — replace failwith "TODO" with your implementation.
3Run the tests: dune runtest modules/module4-abstract-interpretation/exercises/galois-connections

Galois Connections

7. Exercise 3: Galois Connections (Optional, 16 tests)

This exercise is optional. It covers the theoretical foundations of abstract interpretation (Galois connections, adjunction, monotonicity). Completing it will deepen your understanding but is not required for Exercise 4 or the lab. Skip to Exercise 4 if you prefer.

Goal: Formalize the alpha/gamma pair for the sign domain and verify soundness properties (adjunction, monotonicity).

Time: ~25 minutes

File to edit: exercises/galois-connections/starter/galois.ml

Also read: exercises/galois-connections/starter/worksheet.md (guided questions — fill in on paper or in the file)

Key ideas

  • alpha (abstraction): maps a set of integers to the best sign

    • alpha({1, 2, 3}) = Pos
    • alpha({-1, 0, 5}) = Top
    • alpha({}) = Bot
  • gamma (concretization): maps a sign to a representative set

    • gamma(Zero) = {0} (exact)
    • gamma(Pos) = {1, 2, 3, ...} (representative, not exhaustive)
  • Adjunction: alpha(c) ⊑ a iff c ⊆ gamma(a)

What to implement

#FunctionHint
1sign_leq a bSame as Exercise 1's leq
2sign_equal a bStructural equality
3sign_to_stringSame as Exercise 1
4alpha_int nSingle integer → sign
5alpha setFold over the set, joining signs. Empty set → Bot
6gamma_repr signReturn (representative_set, is_exact). Bot → ({}, true), Zero → ({0}, true), Pos → ({1,2,3}, false)
7in_gamma n signIs concrete value n in the concretization of sign?
8verify_adjunction set signCheck: sign_leq (alpha set) sign iff IntSet.subset set (gamma_set sign) — but gamma is infinite, so use in_gamma for each element
9verify_alpha_monotone s1 s2If s1 ⊆ s2 then alpha(s1) ⊑ alpha(s2)

Run tests

dune runtest modules/module4-abstract-interpretation/exercises/galois-connections/