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/sign-lattice

Sign Lattice

5. Exercise 1: Sign Lattice (20 tests)

Goal: Implement the 5-element sign domain and abstract arithmetic.

Time: ~20 minutes

File to edit: exercises/sign-lattice/starter/sign_domain.ml

The sign lattice

         Top           "could be anything"
        / | \
     Neg Zero Pos      "definitely negative / zero / positive"
        \ | /
        Bot             "unreachable"

What to implement (in order)

#FunctionHint
1bottomReturn Bot
2topReturn Top
3join a bLeast upper bound — if a = b return it, otherwise Top (handle Bot/Top first)
4meet a bGreatest lower bound — dual of join
5leq a ba ⊑ b means join a b = b (or: Bot ⊑ everything, everything ⊑ Top)
6equal a bStructural equality
7widen a bFor finite domains, widen = join
8to_string"Bot", "Neg", "Zero", "Pos", "Top"
9alpha_int nn > 0 → Pos, n = 0 → Zero, n < 0 → Neg
10–14abstract_neg, abstract_add, abstract_sub, abstract_mul, abstract_divSee the arithmetic tables in the slides

Run tests

dune runtest modules/module4-abstract-interpretation/exercises/sign-lattice/

Hint for arithmetic: Handle Bot first (anything with Bot returns Bot), then Top cases, then the 9 concrete combinations (Neg/Zero/Pos × Neg/Zero/Pos).