-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathChallenge.lean
More file actions
361 lines (291 loc) · 14.7 KB
/
Copy pathChallenge.lean
File metadata and controls
361 lines (291 loc) · 14.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
/-
Copyright (c) 2026 Lars Warren Ericson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Lars Warren Ericson.
-/
import Mathlib.Data.Finset.Basic
import Mathlib.Data.Set.Basic
import Mathlib.Order.Basic
/-!
# Scott 1982, Theorem 7.2 (Palomar statement of record)
Ground truth for the wording is Scott 1982, Theorem 7.2
(`sources/Domains_for_Denotational_Semantics.pdf`). That theorem begins:
> If \(\mathbf{A}\), \(\mathbf{B}\), and \(\mathbf{C}\) are information systems,
> then so is \(\mathbf{A} \to \mathbf{B}\), and the approximable mappings
> \(f : \mathbf{A} \to \mathbf{B}\) are exactly the elements
> \(f \in |\mathbf{A} \to \mathbf{B}|\).
The compared declaration is that first sentence. Definition 7.1 supplies the
function-space information system: tokens are consistent pairs \((u,v)\),
consistency is Scott's 7.1(iii), and entailment is the constructive witness
form of 7.1(iv). The remaining `apply` / `curry` clauses of the same numbered
theorem are proved in `Scott1982/Theorem72.lean` and are not Comparator
targets.
This file imports Mathlib only. The choice-free `Finset` union `∪'` and
`decidableEq_finset` are restated here so the Challenge import closure
contains no project-local source. The proofs live in `Scott1982/*` and are
compared against this file by Comparator via `Solution.lean`.
The compared theorem is restricted to information systems whose token types
have `DecidableEq`, which is required to form the `Finset` operations used
in Definitions 2.1, 5.1, and 7.1.
-/
namespace Scott1982.Constructive
variable {α : Type*} [DecidableEq α]
/-- Choice-free commutativity of `insert` (mathlib's `Finset.insert_comm` is choice-tainted).
Needed to fold `insert` over a `Multiset`. -/
theorem insert_comm' (a b : α) (s : Finset α) :
insert a (insert b s) = insert b (insert a s) := by
sorry
instance instLeftCommutativeInsert :
LeftCommutative (insert : α → Finset α → Finset α) := ⟨insert_comm'⟩
/-- Choice-free binary union of finite sets, obtained by folding `insert` over the second
argument's underlying multiset. Definitionally equal in content to `u ∪ v`, but — unlike
mathlib's `(· ∪ ·)` — free of any `Classical.choice` dependency. -/
def funion (u v : Finset α) : Finset α := Multiset.foldr insert u v.1
@[inherit_doc] infixl:65 " ∪' " => funion
omit [DecidableEq α] in
/-- If mutual subset holds, the finsets are equal. -/
theorem decidableEq_finset_eq_of_subset (s t : Finset α) (h : s ⊆ t ∧ t ⊆ s) : s = t := by
sorry
omit [DecidableEq α] in
/-- Mutual subset is required for finset equality in this decidable instance. -/
theorem decidableEq_finset_false_of_ne (s t : Finset α) (h : ¬(s ⊆ t ∧ t ⊆ s)) (heq : s = t) :
False := by
sorry
/-- Choice-free decidable equality for `Finset`.
mathlib's `Finset.decidableEq` goes through `Multiset` quotients and pulls
`Classical.choice`; this version uses only decidable membership and subset. -/
def decidableEq_finset {α : Type*} [DecidableEq α] : DecidableEq (Finset α) :=
fun s t =>
if h : s ⊆ t ∧ t ⊆ s then
isTrue (decidableEq_finset_eq_of_subset s t h)
else
isFalse (decidableEq_finset_false_of_ne s t h)
end Scott1982.Constructive
namespace Scott1982
open Scott1982.Constructive
universe u v
/-- **Definition 2.1 (Scott 1982).** An information system on tokens `α`. -/
structure InfoSys (α : Type u) [DecidableEq α] where
bot : α
Con : Set (Finset α)
Ent : Finset α → α → Prop
con_subset : ∀ {u v : Finset α}, u ∈ Con → v ⊆ u → v ∈ Con
con_sing : ∀ a : α, {a} ∈ Con
ent_con : ∀ {u : Finset α} {a : α}, Ent u a → insert a u ∈ Con
ent_bot : ∀ {u : Finset α}, u ∈ Con → Ent u bot
ent_refl : ∀ {u : Finset α} {a : α}, u ∈ Con → a ∈ u → Ent u a
ent_trans : ∀ {u v : Finset α} {c : α},
v ∈ Con → u ∈ Con → (∀ y ∈ u, Ent v y) → Ent u c → Ent v c
namespace InfoSys
variable {α : Type u} [DecidableEq α] (sys : InfoSys α)
/-- **Definition 3.1.** An element of `|A|`. -/
structure Element where
carrier : Set α
consistent : ∀ Y : Finset α, (Y : Set α) ⊆ carrier → Y ∈ sys.Con
closed : ∀ (Y : Finset α) (a : α), (Y : Set α) ⊆ carrier → sys.Ent Y a → a ∈ carrier
/-- Extensional equality of elements. -/
theorem Element.ext {x y : sys.Element} (h : x.carrier = y.carrier) : x = y := by
sorry
/-- Reflexivity of the carrier-inclusion order. -/
theorem element_le_refl (x : sys.Element) : x.carrier ⊆ x.carrier := by
sorry
/-- Transitivity of the carrier-inclusion order. -/
theorem element_le_trans (x y z : sys.Element)
(hxy : x.carrier ⊆ y.carrier) (hyz : y.carrier ⊆ z.carrier) :
x.carrier ⊆ z.carrier := by
sorry
/-- Antisymmetry of the carrier-inclusion order. -/
theorem element_le_antisymm (x y : sys.Element)
(hxy : x.carrier ⊆ y.carrier) (hyx : y.carrier ⊆ x.carrier) :
x = y := by
sorry
instance : PartialOrder sys.Element where
le x y := x.carrier ⊆ y.carrier
le_refl := element_le_refl sys
le_trans := element_le_trans sys
le_antisymm := element_le_antisymm sys
/-- Empty set is consistent (subset of any singleton). -/
theorem con_empty : (∅ : Finset α) ∈ sys.Con := by
sorry
/-- **Definition 2.2.** Set-level entailment. -/
def EntSet (u v : Finset α) : Prop := ∀ X ∈ v, sys.Ent u X
end InfoSys
namespace InfoSys
variable {α : Type u} {β : Type v} [DecidableEq α] [DecidableEq β]
/-- **Definition 5.1.** Approximable mapping. -/
structure ApproximableMap (A : InfoSys α) (B : InfoSys β) where
rel : Finset α → Finset β → Prop
rel_dom : ∀ {u v}, rel u v → u ∈ A.Con
rel_cod : ∀ {u v}, rel u v → v ∈ B.Con
empty_rel : rel ∅ ∅
union_right : ∀ {u v v'}, rel u v → rel u v' → rel u (v ∪' v')
mono : ∀ {u u' v v'},
rel u v → A.EntSet u' u → B.EntSet v v' → u' ∈ A.Con → v' ∈ B.Con → rel u' v'
/-- Token type of the function space `A → B` (Scott 7.1(i)). -/
def FunToken (A : InfoSys α) (B : InfoSys β) : Type _ :=
{p : Finset α × Finset β // p.1 ∈ A.Con ∧ p.2 ∈ B.Con}
instance (A : InfoSys α) (B : InfoSys β) : DecidableEq (FunToken A B) :=
fun p q =>
match decidableEq_finset p.val.1 q.val.1, decidableEq_finset p.val.2 q.val.2 with
| isTrue h1, isTrue h2 => isTrue (Subtype.ext (Prod.ext h1 h2))
| isFalse n1, _ =>
isFalse fun h => n1 (congrArg (fun r : FunToken A B => r.val.1) h)
| isTrue _, isFalse n2 =>
isFalse fun h => n2 (congrArg (fun r : FunToken A B => r.val.2) h)
variable (A : InfoSys α) (B : InfoSys β)
/-- The empty pair is a function-space token. -/
theorem funBot_property : (∅ : Finset α) ∈ A.Con ∧ (∅ : Finset β) ∈ B.Con := by
sorry
/-- Left-commutativity of input-component union (needed to fold `funion`). -/
theorem funion_left_comm (a b c : Finset α) :
a ∪' (b ∪' c) = b ∪' (a ∪' c) := by
sorry
/-- Left-commutativity of output-component union (needed to fold `funion`). -/
theorem funion_left_comm' (a b c : Finset β) :
a ∪' (b ∪' c) = b ∪' (a ∪' c) := by
sorry
instance instLeftCommutativeFunInput :
LeftCommutative fun p : FunToken A B => (funion p.val.1 : Finset α → Finset α) :=
⟨fun p q s => funion_left_comm p.val.1 q.val.1 s⟩
instance instLeftCommutativeFunOutput :
LeftCommutative fun p : FunToken A B => (funion p.val.2 : Finset β → Finset β) :=
⟨fun p q s => funion_left_comm' p.val.2 q.val.2 s⟩
/-- Function-space bottom `Δ_{A→B} = (∅, ∅)` (Scott 7.1(ii)). -/
def funBot : FunToken A B :=
⟨(∅, ∅), funBot_property A B⟩
/-- Union of input components of a finite set of function-space tokens. -/
def funInputUnion (s : Finset (FunToken A B)) : Finset α :=
Multiset.foldr (fun p : FunToken A B => funion p.val.1) (∅ : Finset α) s.1
/-- Union of output components of a finite set of function-space tokens. -/
def funOutputUnion (s : Finset (FunToken A B)) : Finset β :=
Multiset.foldr (fun p : FunToken A B => funion p.val.2) (∅ : Finset β) s.1
/-- Consistency for the function space (Scott 7.1(iii)). -/
def FunCon (w : Finset (FunToken A B)) : Prop :=
∀ s ⊆ w, funInputUnion A B s ∈ A.Con → funOutputUnion A B s ∈ B.Con
/-- Entailment for the function space (Scott 7.1(iv), constructive witness form). -/
def FunEnt (w : Finset (FunToken A B)) (p : FunToken A B) : Prop :=
FunCon A B w ∧
∃ s ⊆ w, (∀ q ∈ s, A.EntSet p.val.1 q.val.1) ∧
B.EntSet (funOutputUnion A B s) p.val.2
/-- Downward closure of function-space consistency. -/
theorem functionSystem_con_subset {w w' : Finset (FunToken A B)}
(hw : FunCon A B w) (hw' : w' ⊆ w) : FunCon A B w' := by
sorry
/-- Singletons are consistent in the function space. -/
theorem functionSystem_con_sing (p : FunToken A B) : FunCon A B {p} := by
sorry
/-- Adding an entailed function-space token preserves consistency. -/
theorem functionSystem_ent_con {w : Finset (FunToken A B)} {p : FunToken A B}
(hEnt : FunEnt A B w p) : FunCon A B (insert p w) := by
sorry
/-- The function-space bottom is entailed by every consistent set. -/
theorem functionSystem_ent_bot {w : Finset (FunToken A B)} (hw : FunCon A B w) :
FunEnt A B w (funBot A B) := by
sorry
/-- Function-space entailment is reflexive on members. -/
theorem functionSystem_ent_refl {w : Finset (FunToken A B)} {p : FunToken A B}
(hw : FunCon A B w) (hp : p ∈ w) : FunEnt A B w p := by
sorry
/-- Function-space entailment is transitive. -/
theorem functionSystem_ent_trans {u v : Finset (FunToken A B)} {c : FunToken A B}
(hv : FunCon A B v) (hu : FunCon A B u)
(hEnts : ∀ y ∈ u, FunEnt A B v y) (hEnt : FunEnt A B u c) :
FunEnt A B v c := by
sorry
/-- **Definition 7.1.** The function-space information system `A → B`. -/
def functionSystem : InfoSys (FunToken A B) where
bot := funBot A B
Con := {w | FunCon A B w}
Ent := FunEnt A B
con_subset := functionSystem_con_subset A B
con_sing := functionSystem_con_sing A B
ent_con := functionSystem_ent_con A B
ent_bot := functionSystem_ent_bot A B
ent_refl := functionSystem_ent_refl A B
ent_trans := functionSystem_ent_trans A B
/-- Consistency of a packaged function-space token. -/
theorem mkFunToken_property (u : Finset α) (v : Finset β) (hu : u ∈ A.Con) (hv : v ∈ B.Con) :
u ∈ A.Con ∧ v ∈ B.Con := by
sorry
/-- Package a consistent pair as a function-space token. -/
def mkFunToken (u : Finset α) (v : Finset β) (hu : u ∈ A.Con) (hv : v ∈ B.Con) :
FunToken A B :=
⟨(u, v), mkFunToken_property A B u v hu hv⟩
/-- Consistency of the token-set of an approximable map. -/
theorem approxMap_toElement_consistent (f : ApproximableMap A B)
(Y : Finset (FunToken A B))
(hY : (Y : Set (FunToken A B)) ⊆ {p : FunToken A B | f.rel p.val.1 p.val.2}) :
Y ∈ (functionSystem A B).Con := by
sorry
/-- Deductive closure of the token-set of an approximable map. -/
theorem approxMap_toElement_closed (f : ApproximableMap A B)
(Y : Finset (FunToken A B)) (p : FunToken A B)
(hY : (Y : Set (FunToken A B)) ⊆ {p : FunToken A B | f.rel p.val.1 p.val.2})
(hEnt : (functionSystem A B).Ent Y p) :
p ∈ {q : FunToken A B | f.rel q.val.1 q.val.2} := by
sorry
/-- Approximable map as an element of `|A → B|`. -/
def approxMap_toElement (f : ApproximableMap A B) : (functionSystem A B).Element where
carrier := {p : FunToken A B | f.rel p.val.1 p.val.2}
consistent := approxMap_toElement_consistent A B f
closed := approxMap_toElement_closed A B f
/-- Domain of the relation recovered from a function-space element. -/
theorem element_toApproxMap_rel_dom (x : (functionSystem A B).Element) :
∀ {u : Finset α} {v : Finset β},
(∃ (hu : u ∈ A.Con) (hv : v ∈ B.Con), mkFunToken A B u v hu hv ∈ x.carrier) →
u ∈ A.Con :=
fun ⟨hu, _, _⟩ => hu
/-- Codomain of the relation recovered from a function-space element. -/
theorem element_toApproxMap_rel_cod (x : (functionSystem A B).Element) :
∀ {u : Finset α} {v : Finset β},
(∃ (hu : u ∈ A.Con) (hv : v ∈ B.Con), mkFunToken A B u v hu hv ∈ x.carrier) →
v ∈ B.Con :=
fun ⟨_, hv, _⟩ => hv
/-- The empty pair is related. -/
theorem element_toApproxMap_empty_rel (x : (functionSystem A B).Element) :
∃ (hu : (∅ : Finset α) ∈ A.Con) (hv : (∅ : Finset β) ∈ B.Con),
mkFunToken A B ∅ ∅ hu hv ∈ x.carrier := by
sorry
/-- Output-union of two related pairs remains related. -/
theorem element_toApproxMap_union_right (x : (functionSystem A B).Element) :
∀ {u : Finset α} {v v' : Finset β},
(∃ (hu : u ∈ A.Con) (hv : v ∈ B.Con), mkFunToken A B u v hu hv ∈ x.carrier) →
(∃ (hu : u ∈ A.Con) (hv : v' ∈ B.Con), mkFunToken A B u v' hu hv ∈ x.carrier) →
∃ (hu : u ∈ A.Con) (hv : v ∪' v' ∈ B.Con),
mkFunToken A B u (v ∪' v') hu hv ∈ x.carrier := by
sorry
/-- The recovered relation is monotone for entailment. -/
theorem element_toApproxMap_mono (x : (functionSystem A B).Element) :
∀ {u u' : Finset α} {v v' : Finset β},
(∃ (hu : u ∈ A.Con) (hv : v ∈ B.Con), mkFunToken A B u v hu hv ∈ x.carrier) →
A.EntSet u' u → B.EntSet v v' → u' ∈ A.Con → v' ∈ B.Con →
∃ (hu : u' ∈ A.Con) (hv : v' ∈ B.Con),
mkFunToken A B u' v' hu hv ∈ x.carrier := by
sorry
/-- Element of `|A → B|` as an approximable map. -/
def element_toApproxMap (x : (functionSystem A B).Element) : ApproximableMap A B where
rel u v := ∃ (hu : u ∈ A.Con) (hv : v ∈ B.Con), mkFunToken A B u v hu hv ∈ x.carrier
rel_dom := element_toApproxMap_rel_dom A B x
rel_cod := element_toApproxMap_rel_cod A B x
empty_rel := element_toApproxMap_empty_rel A B x
union_right := element_toApproxMap_union_right A B x
mono := element_toApproxMap_mono A B x
/-- Round-trip: every approximable map is recovered from its element. -/
theorem element_toApproxMap_approxMap_toElement (f : ApproximableMap A B) :
element_toApproxMap A B (approxMap_toElement A B f) = f := by
sorry
/-- Round-trip: every function-space element is recovered from its map. -/
theorem approxMap_toElement_element_toApproxMap (x : (functionSystem A B).Element) :
approxMap_toElement A B (element_toApproxMap A B x) = x := by
sorry
/-- **Theorem 7.2, first sentence (Scott 1982).** Approximable maps `A → B` are
exactly the elements of the Definition 7.1 function-space system `|A → B|`. -/
theorem theorem_7_2 {α : Type u} {β : Type v} [DecidableEq α] [DecidableEq β]
(A : InfoSys α) (B : InfoSys β) :
(∀ f : ApproximableMap A B,
element_toApproxMap A B (approxMap_toElement A B f) = f) ∧
(∀ x : (functionSystem A B).Element,
approxMap_toElement A B (element_toApproxMap A B x) = x) := by
sorry
end InfoSys
end Scott1982