Lean migration: Phase 7 (Sign + Constant analyses, executable)
- Spa.Showable: port of Showable.agda (quoted strings, map format) for output parity - Spa.Analysis.Utils: eval_combine₂ - Spa.Lattice.AboveBelow.le_cases: order of the flat lattice by cases - Spa.Analysis.Sign / Spa.Analysis.Constant: the four monotonicity POSTULATES from the Agda files are now proved theorems (via le_cases); interpretations, evaluator validity, analyze_correct per analysis - Main + lake exe spa: runs both analyses on the Agda test program; constant analysis folds unknown=0, sign analysis gives unknown=⊤ Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
47
lean/Spa/Showable.lean
Normal file
47
lean/Spa/Showable.lean
Normal file
@@ -0,0 +1,47 @@
|
||||
/-
|
||||
Port of `Showable.agda` (plus the `Showable` instances that lived on
|
||||
`Lattice/Map.agda` and `Lattice/AboveBelow.agda`).
|
||||
|
||||
Lean has `ToString`, but its `String` instance does not quote (the Agda one
|
||||
does), so to reproduce the Agda output exactly we port the class as-is.
|
||||
-/
|
||||
import Spa.Lattice.FiniteMap
|
||||
import Spa.Lattice.AboveBelow
|
||||
|
||||
namespace Spa
|
||||
|
||||
/-- Agda: `Showable` (`show` is a Lean keyword, hence `show'`). -/
|
||||
class Showable (α : Type*) where
|
||||
show' : α → String
|
||||
|
||||
export Showable (show')
|
||||
|
||||
instance : Showable String := ⟨fun s => "\"" ++ s ++ "\""⟩
|
||||
|
||||
instance : Showable ℕ := ⟨toString⟩
|
||||
|
||||
instance : Showable ℤ := ⟨toString⟩
|
||||
|
||||
instance {n : ℕ} : Showable (Fin n) := ⟨fun i => toString i.val⟩
|
||||
|
||||
instance {α β : Type*} [Showable α] [Showable β] : Showable (α × β) :=
|
||||
⟨fun p => "(" ++ show' p.1 ++ ", " ++ show' p.2 ++ ")"⟩
|
||||
|
||||
instance : Showable PUnit := ⟨fun _ => "()"⟩
|
||||
|
||||
/-- Agda: the `Showable` instance of `Lattice/AboveBelow.agda`. -/
|
||||
instance {α : Type*} [Showable α] : Showable (AboveBelow α) :=
|
||||
⟨fun
|
||||
| .bot => "⊥"
|
||||
| .top => "⊤"
|
||||
| .mk x => show' x⟩
|
||||
|
||||
/-- Agda: the `Showable` instance of `Lattice/Map.agda` (inherited by
|
||||
`FiniteMap`). -/
|
||||
instance {α β : Type*} {ks : List α} [Showable α] [Showable β] :
|
||||
Showable (FiniteMap α β ks) :=
|
||||
⟨fun fm =>
|
||||
"{" ++ fm.val.foldr (fun p rest => show' p.1 ++ " ↦ " ++ show' p.2 ++ ", " ++ rest) ""
|
||||
++ "}"⟩
|
||||
|
||||
end Spa
|
||||
Reference in New Issue
Block a user