11import BoltLean.Ltl.Basic
22
33namespace Trace
4+ /-- Returns a formula that accepts the value of predicate number `v`,
5+ at the given position,
6+ i.e. it returns the variable x_v if x_v is true,
7+ and ¬x_v otherwise. -/
48 def get_exact_var (pos: Vector Bool n) (v: Fin n): Formula n :=
59 Formula.Var v (not pos[v])
610
7- /-- Auxiliary function for constructing a formula that is true on t and only on t-/
11+ /-- Construct a formula that accepts the value of all predicates listed in `l`
12+ at the given position.
13+ To build the `exact` function, this function is called with `List.finRange n`,
14+ but having `l` as a free parameter makes proofs easier.-/
815 def exact_at_pos (pos: Vector Bool n) (l: List (Fin n)): Formula n :=
916 let all_var := l.map (get_exact_var pos)
10- all_var.foldr ( fun phi psi => phi .And psi) Formula.True
17+ all_var.foldr Formula .And Formula.True
1118
19+ /-- Return a formula that accepts `t` and rejects all other traces.-/
1220 def exact (t: Trace n) : Formula n :=
1321 match t with
1422 | .nil => Formula.False.Globally
@@ -41,9 +49,8 @@ namespace Trace
4149 . exact ih
4250
4351 -- Soundness
44- /-- Taking the `And` of a list of formulas and evaluating is the same as
45- evaluating and taking the `And`.
46- -/
52+ /-- Lemma: Taking the `And` of a list of formulas and evaluating is the same as
53+ evaluating and taking the Boolean `And`.-/
4754 theorem foldr_and_aux (l: List (Formula n)) (t: Trace n):
4855 (l.foldr Formula.And Formula.True).accepts t
4956 → ∀ f ∈ l, f.accepts t := by
@@ -62,6 +69,7 @@ namespace Trace
6269 simp [*] at he
6370 cases t <;> simp at he <;> apply ih he.right f h_in
6471
72+ /-- Lemma: If `exact_at_pos pos l` accepts, then `get_exact_var pos v` also accepts for all `v ∈ l`-/
6573 theorem exact_at_pos_accepts_all (pos pos': Vector Bool n) (t: Trace n) (l: List (Fin n)) :
6674 (exact_at_pos pos l).accepts (pos' :: t) → ∀ v ∈ l, (get_exact_var pos v).accepts (pos' :: t) := by
6775 intro h v hv
@@ -83,6 +91,7 @@ namespace Trace
8391 apply h1
8492 exact h2
8593
94+ /-- Lemma: If `exact t` accepts `t'`, then `t` and `t'` have the same head.-/
8695 theorem exact_accepts_head (h h': Vector Bool n) (t t': Trace n):
8796 (exact (h::t)).accepts (h'::t') → h = h' := by
8897 simp [exact, Formula.accepts]
@@ -93,6 +102,7 @@ namespace Trace
93102 simp [get_exact_var] at h1
94103 rw [h1]
95104
105+ /-- Lemma: If `exact t` accepts `t'`, then `t` and `t'` have the same tail.-/
96106 theorem exact_accepts_cons (h h': Vector Bool n) (t t': Trace n):
97107 (exact (h::t)).accepts (h'::t') → (exact t).accepts t' := by
98108 intro hyp
@@ -104,6 +114,7 @@ namespace Trace
104114 simp at h2
105115 exact h2
106116
117+ /-- Lemma: `exact` of the empty trace does not accept non-empty traces.-/
107118 theorem exact_nil_not_accepts_cons (h: Vector Bool n) (t: Trace n):
108119 ¬ (exact []).accepts (h :: t) := by
109120 intro h1
@@ -139,7 +150,7 @@ namespace Trace
139150 assumption
140151
141152
142- /-- Correctness of `t.exact` -/
153+ /-- Correctness and soundness of `t.exact` -/
143154 theorem exact_correct (t t': Trace n):
144155 t.exact.accepts t' ↔ t = t' := by
145156 constructor
@@ -162,12 +173,14 @@ namespace Trace
162173
163174end Trace
164175
165-
176+ /-- Given a list of traces, construct a formula that accepts
177+ exactly these traces, and no other. -/
166178def UpperBoundFormula (ts: List (Trace n)) : Formula n :=
167179 let fs := ts.map Trace.exact
168180 fs.foldr Formula.Or Formula.False
169181
170-
182+ /-- Lemma: If all formulas in a list accept `t`,
183+ then the `Or` of this list also accepts `t`.-/
171184theorem foldr_or_aux (l: List (Formula n)) (t: Trace n):
172185 ∀ f ∈ l, f.accepts t → (l.foldr Formula.Or Formula.False).accepts t := by
173186 induction l with
@@ -186,6 +199,9 @@ theorem foldr_or_aux (l: List (Formula n)) (t: Trace n):
186199 cases t <;> simp <;> right <;> apply ih f h_in he
187200
188201
202+
203+ /-- Lemma: If the `Or` of a list of formulas accepts `t`,
204+ then some formula in the list accepts `t`.-/
189205theorem foldr_or_aux_rev (l: List (Formula n)) (t: Trace n):
190206 (l.foldr Formula.Or Formula.False).accepts t → ∃ f ∈ l, f.accepts t := by
191207 intro h
@@ -221,8 +237,9 @@ theorem list_map_contains (l: List α) (f: α → β):
221237 exact h2
222238
223239
224- /-- Theorem X (TODO) from the paper:
225- For any disjoint set of positive and negative examples, there exists a formula that accepts the positive rand rejects the negatives.
240+ /-- Theorem:
241+ For any disjoint set of positive and negative examples,
242+ there exists a formula that accepts all the positive and rejects the negatives.
226243-/
227244theorem UpperBound (pos: List (Trace n)) (neg: List (Trace n)) (h: ∀ t ∈ pos, ∀ t'∈ neg, t ≠ t') :
228245 exists (phi: Formula n), (∀ t ∈ pos, phi.accepts t) ∧ (∀t ∈ neg, ¬ phi.accepts t):= by
0 commit comments