]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/nlibrary/topology/igft.ma
Preparing for 0.5.9 release.
[helm.git] / helm / software / matita / nlibrary / topology / igft.ma
1 (*D
2
3 Inductively generated formal topologies in Matita
4 ================================================= 
5
6 This is a not so short introduction to [Matita][2], based on
7 the formalization of the paper
8
9 > Between formal topology and game theory: an
10 > explicit solution for the conditions for an
11 > inductive generation of formal topologies
12
13 by Stefano Berardi and Silvio Valentini. 
14
15 The tutorial and the formalization are by Enrico Tassi.
16
17 The reader should be familiar with inductively generated
18 formal topologies and have some basic knowledge of type theory and λ-calculus.  
19
20 A considerable part of this tutorial is devoted to explain how to define 
21 notations that resemble the ones used in the original paper. We believe
22 this is an important part of every formalization, not only from the aesthetic 
23 point of view, but also from the practical point of view. Being 
24 consistent allows to follow the paper in a pedantic way, and hopefully
25 to make the formalization (at least the definitions and proved
26 statements) readable to the author of the paper. 
27
28 The formalization uses the "new generation" version of Matita
29 (that will be named 1.x when finally released). 
30 Last stable release of the "old" system is named 0.5.7; the ng system
31 is coexisting with the old one in all development release 
32 (named "nightly builds" in the download page of Matita) 
33 with a version strictly greater than 0.5.7.
34
35 To read this tutorial in HTML format, you need a decent browser
36 equipped with a unicode capable font. Use the PDF format if some
37 symbols are not displayed correctly.
38
39 Orienteering
40 ------------
41
42 The graphical interface of Matita is composed of three windows:
43 the script window, on the left, is where you type; the sequent
44 window on the top right is where the system shows you the ongoing proof;
45 the error window, on the bottom right, is where the system complains.
46 On the top of the script window five buttons drive the processing of
47 the proof script. From left to right they request the system to:
48
49 - go back to the beginning of the script
50 - go back one step
51 - go to the current cursor position
52 - advance one step
53 - advance to the end of the script
54
55 When the system processes a command, it locks the part of the script
56 corresponding to the command, such that you cannot edit it anymore 
57 (without going back). Locked parts are coloured in blue.
58
59 The sequent window is hyper textual, i.e. you can click on symbols
60 to jump to their definition, or switch between different notations
61 for the same expression (for example, equality has two notations,
62 one of them makes the type of the arguments explicit).  
63
64 Everywhere in the script you can use the `ncheck (term).` command to
65 ask for the type a given term. If you do that in the middle of a proof,
66 the term is assumed to live in the current proof context (i.e. can use
67 variables introduced so far).
68
69 To ease the typing of mathematical symbols, the script window
70 implements two unusual input facilities:
71
72 - some TeX symbols can be typed using their TeX names, and are 
73   automatically converted to UTF-8 characters. For a list of 
74   the supported TeX names, see the menu: View ▹ TeX/UTF-8 Table.
75   Moreover some ASCII-art is understood as well, like `=>` and `->`
76   to mean double or single arrows.
77   Here we recall some of these "shortcuts":
78
79   - ∀ can be typed with `\forall`
80   - λ can be typed with `\lambda`
81   - ≝ can be typed with `\def` or `:=`
82   - → can be typed with `\to` or `->`
83   
84 - some symbols have variants, like the ≤ relation and ≼, ≰, ⋠.
85   The user can cycle between variants typing one of them and then
86   pressing ALT-L. Note that also letters do have variants, for
87   example W has Ω, 𝕎 and 𝐖, L has Λ, 𝕃, and 𝐋, F has Φ, … 
88   Variants are listed in the aforementioned TeX/UTF-8 table. 
89
90 The syntax of terms (and types) is the one of the λ-calculus CIC
91 on which Matita is based. The main syntactical difference w.r.t. 
92 the usual mathematical notation is the function application, written
93 `(f x y)` in place of `f(x,y)`. 
94
95 Pressing `F1` opens the Matita manual.
96
97 CIC (as [implemented in Matita][3]) in a nutshell
98 ------------------------------------------------- 
99
100 CIC is a full and functional Pure Type System (all products do exist,
101 and their sort is is determined by the target) with an impredicative sort
102 Prop and a predicative sort Type. It features both dependent types and 
103 polymorphism like the [Calculus of Constructions][4]. Proofs and terms share
104 the same syntax, and they can occur in types. 
105
106 The environment used for in the typing judgement can be populated with
107 well typed definitions or theorems, (co)inductive types validating positivity
108 conditions and recursive functions provably total by simple syntactical 
109 analysis (recursive calls are allowed only on structurally smaller subterms). 
110 Co-recursive 
111 functions can be defined as well, and must satisfy the dual condition, i.e.
112 performing the recursive call only after having generated a constructor (a piece
113 of output).
114
115 The CIC λ-calculus is equipped with a pattern matching construct (match) on inductive
116 types defined in the environment. This construct, together with the possibility to
117 definable total recursive functions, allows to define eliminators (or constructors)
118 for (co)inductive types. 
119
120 Types are compare up to conversion. Since types may depend on terms, conversion
121 involves β-reduction, δ-reduction (definition unfolding), ζ-reduction (local
122 definition unfolding), ι-reduction (pattern matching simplification),
123 μ-reduction (recursive function computation) and ν-reduction (co-fixpoint
124 computation).
125
126 Since we are going to formalize constructive and predicative mathematics
127 in an intensional type theory like CIC, we try to establish some terminology. 
128 Type is the sort of sets equipped with the `Id` equality (i.e. an intensional,
129 not quotiented set). 
130
131 We write `Type[i]` to mention a Type in the predicative hierarchy 
132 of types. To ease the comprehension we will use `Type[0]` for sets, 
133 and `Type[1]` for classes. The index `i` is just a label: constraints among
134 universes are declared by the user. The standard library defines
135
136 > Type[0] < Type[1] < Type[2]
137
138 Matita implements a variant of CIC in which constructive and predicative proposition
139 are distinguished from predicative data types.
140
141 <object class="img" data="igft-CIC-universes.svg" type="image/svg+xml" width="400px"/>
142
143 For every `Type[i]` there is a corresponding level of predicative
144 propositions `CProp[i]` (the C initial is due to historical reasons, and
145 stands for constructive). 
146 A predicative proposition cannot be eliminated toward
147 `Type[j]` unless it holds no computational content (i.e. it is an inductive proposition
148 with 0 or 1 constructors with propositional arguments, like `Id` and `And` 
149 but not like `Or`). 
150
151 The distinction between predicative propositions and predicative data types
152 is a peculiarity of Matita (for example in CIC as implemented by Coq they are the
153 same). The additional restriction of not allowing the elimination of a CProp
154 toward a Type makes the theory of Matita minimal in the following sense: 
155
156 <object class="img" data="igft-minimality-CIC.svg" type="image/svg+xml" width="600px"/>
157
158 Theorems proved in CIC as implemented in Matita can be reused in a classical 
159 and impredicative framework (i.e. forcing Matita to collapse the hierarchy of 
160 constructive propositions and assuming the excluded middle on them). 
161 Alternatively, one can decide to collapse predicative propositions and 
162 predicative data types recovering the Axiom of Choice in the sense of Martin Löf 
163 (i.e. ∃ really holds a witness and can be eliminated to inhabit a type).
164
165 This implementation of CIC is the result of the collaboration with Maietti M.,
166 Sambin G. and Valentini S. of the University of Padua.
167
168 Formalization choices
169 ---------------------
170
171 There are many different ways of formalizing the same piece of mathematics
172 in CIC, depending on what our interests are. There is usually a trade-off 
173 between the possibility of reuse the formalization we did and its complexity.
174
175 In this work, our decisions mainly regarded the following two areas
176
177 - Axiom of Choice: controlled use or not
178 - Equality: Id or not
179
180 ### Axiom of Choice
181
182 In this paper it is clear that the author is interested in using the Axiom
183 of Choice, thus choosing to identify ∃ and Σ (i.e. working in the 
184 leftmost box of the graph "Coq's CIC (work in CProp)") would be a safe decision 
185 (that is, the author of the paper would not complain we formalized something
186 different from what he had in mind).
187
188 Anyway, we may benefit from the minimality of CIC as implemented in Matita,
189 "asking" the type system to ensure we do no use the Axiom of Choice elsewhere
190 in the proof (by mistake or as a shortcut). If we identify ∃ and Σ from the
191 very beginning, the system will not complain if we use the Axiom of Choice at all.
192 Moreover, the elimination of an inductive type (like ∃) is a so common operation
193 that the syntax chosen for the elimination command is very compact and non 
194 informative, hard to spot for a human being 
195 (in fact it is just two characters long!). 
196
197 We decided to formalize the whole paper without identifying
198 CProp and Type and assuming the Axiom of Choice as a real axiom 
199 (i.e. a black hole with no computational content, a function with no body). 
200
201 It is clear that this approach give us full control on when/where we really use
202 the Axiom of Choice. But, what are we loosing? What happens to the computational
203 content of the proofs if the Axiom of Choice gives no content back? 
204
205 It really
206 depends on when we actually look at the computational content of the proof and 
207 we "run" that program. We can extract the content and run it before or after 
208 informing the system that our propositions are actually code (i.e. identifying
209 ∃ and Σ). If we run the program before, as soon as the computation reaches the 
210 Axiom of Choice it stops, giving no output. If we tell the system that CProp and
211 Type are the same, we can exhibit a body for the Axiom of Choice (i.e. a projection)
212 and the extracted code would compute an output. 
213
214 Note that the computational
215 content is there even if the Axiom of Choice is an axiom, the difference is
216 just that we cannot use it (the typing rules inhibit the elimination of the 
217 existential). This is possible only thanks to the minimality of CIC as implemented
218 in Matita. 
219
220 ### Equality
221
222 What we have to decide here is which models we admit. The paper does not
223 mention quotiented sets, thus using an intensional equality is enough
224 to capture the intended content of the paper. Nevertheless, the formalization
225 cannot be reused in a concrete example where the (families of) sets
226 that will build the axiom set are quotiented.
227
228 Matita gives support for setoid rewriting under a context built with
229 non dependent morphisms. As we will detail later, if we assume a generic
230 equality over the carrier of our axiom set, a non trivial inductive
231 construction over the ordinals has to be proved to respect extensionality
232 (i.e. if the input is an extensional set, also the output is).
233 The proof requires to rewrite under the context formed by the family of sets 
234 `I` and `D`, that have a dependent type. Declaring them as dependently typed
235 morphisms is possible, but Matita does not provide an adequate support for them,
236 and would thus need more effort than formalizing the whole paper. 
237
238 Anyway, in a preliminary attempt of formalization, we tried the setoid approach,
239 reaching the end of the formalization, but we had to assume the proof
240 of the extensionality of the `U_x` construction (while there is no
241 need to assume the same property for `F_x`!). 
242
243 The current version of the formalization uses `Id`. 
244
245 The standard library and the `include` command
246 ----------------------------------------------
247
248 Some basic notions, like subset, membership, intersection and union
249 are part of the standard library of Matita.
250
251 These notions come with some standard notation attached to them:
252
253 - A ∪ B can be typed with `A \cup B`
254 - A ∩ B can be typed with `A \cap B` 
255 - A ≬ B can be typed with `A \between B`
256 - x ∈ A can be typed with `x \in A` 
257 - Ω^A, that is the type of the subsets of A, can be typed with `\Omega ^ A` 
258
259 The `include` command tells Matita to load a part of the library, 
260 in particular the part that we will use can be loaded as follows: 
261
262 D*)
263
264 include "sets/sets.ma".
265
266 (*D
267
268 Some basic results that we will use are also part of the sets library:
269
270 - subseteq\_union\_l: ∀A.∀U,V,W:Ω^A.U ⊆ W → V ⊆ W → U ∪ V ⊆ W
271 - subseteq\_intersection\_r: ∀A.∀U,V,W:Ω^A.W ⊆ U → W ⊆ V → W ⊆ U ∩ V
272
273 Defining Axiom set
274 ------------------
275
276 A set of axioms is made of a set `S`, a family of sets `I` and a 
277 family `C` of subsets of `S` indexed by elements `a` of `S` 
278 and elements of `I(a)`.
279
280 It is desirable to state theorems like "for every set of axioms, …"
281 without explicitly mentioning S, I and C. To do that, the three 
282 components have to be grouped into a record (essentially a dependently
283 typed tuple). The system is able to generate the projections
284 of the record automatically, and they are named as the fields of
285 the record. So, given an axiom set `A` we can obtain the set
286 with `S A`, the family of sets with `I A` and the family of subsets
287 with `C A`.
288
289 D*)
290
291 nrecord Ax : Type[1] ≝ { 
292   S :> Type[0];
293   I :  S → Type[0];
294   C :  ∀a:S. I a → Ω^S
295 }.
296
297 (*D
298
299 Forget for a moment the `:>` that will be detailed later, and focus on
300 the record definition. It is made of a list of pairs: a name, followed
301 by `:` and the its type. It is a dependently typed tuple, thus
302 already defined names (fields) can be used in the types that follow. 
303
304 Note that the field `S` was declared with `:>` instead of a simple `:`.
305 This declares the `S` projection to be a coercion. A coercion is 
306 a "cast" function the system automatically inserts when it is needed.
307 In that case, the projection `S` has type `Ax → setoid`, and whenever
308 the expected type of a term is `setoid` while its type is `Ax`, the 
309 system inserts the coercion around it, to make the whole term well typed.
310
311 When formalizing an algebraic structure, declaring the carrier as a 
312 coercion is a common practice, since it allows to write statements like
313
314     ∀G:Group.∀x:G.x * x^-1 = 1 
315
316 The quantification over `x` of type `G` is ill-typed, since `G` is a term
317 (of type `Group`) and thus not a type. Since the carrier projection 
318 `carr` is a coercion, that maps a `Group` into the type of 
319 its elements, the system automatically inserts `carr` around `G`, 
320 obtaining `…∀x: carr G.…`. 
321
322 Coercions are hidden by the system when it displays a term.
323 In this particular case, the coercion `S` allows to write (and read):
324
325     ∀A:Ax.∀a:A.…
326
327 Since `A` is not a type, but it can be turned into a `setoid` by `S`
328 and a `setoid` can be turned into a type by its `carr` projection, the 
329 composed coercion `carr ∘ S` is silently inserted.
330
331 Implicit arguments
332 ------------------
333
334 Something that is not still satisfactory, is that the dependent type
335 of `I` and `C` are abstracted over the Axiom set. To obtain the
336 precise type of a term, you can use the `ncheck` command as follows.
337
338 D*) 
339
340 (** ncheck I. *) (* shows: ∀A:Ax.A → Type[0] *)
341 (** ncheck C. *) (* shows: ∀A:Ax.∀a:A.A → I A a → Ω^A *)
342
343 (*D
344
345 One would like to write `I a` and not `I A a` under a context where
346 `A` is an axiom set and `a` has type `S A` (or thanks to the coercion
347 mechanism simply `A`). In Matita, a question mark represents an implicit
348 argument, i.e. a missing piece of information the system is asked to
349 infer. Matita performs Hindley-Milner-style type inference, thus writing
350 `I ? a` is enough: since the second argument of `I` is typed by the 
351 first one, the first (omitted) argument can be inferred just 
352 computing the type of `a` (that is `A`).
353
354 D*) 
355
356 (** ncheck (∀A:Ax.∀a:A.I ? a). *) (* shows: ∀A:Ax.∀a:A.I A a *)
357
358 (*D
359
360 This is still not completely satisfactory, since you have always to type 
361 `?`; to fix this minor issue we have to introduce the notational
362 support built in Matita.
363
364 Notation for I and C
365 --------------------
366
367 Matita is quipped with a quite complex notational support,
368 allowing the user to define and use mathematical notations 
369 ([From Notation to Semantics: There and Back Again][1]). 
370
371 Since notations are usually ambiguous (e.g. the frequent overloading of 
372 symbols) Matita distinguishes between the term level, the 
373 content level, and the presentation level, allowing multiple 
374 mappings between the content and the term level. 
375
376 The mapping between the presentation level (i.e. what is typed on the 
377 keyboard and what is displayed in the sequent window) and the content
378 level is defined with the `notation` command. When followed by
379 `>`, it defines an input (only) notation.   
380
381 D*)
382
383 notation > "𝐈 term 90 a" non associative with precedence 70 for @{ 'I $a }.
384 notation > "𝐂 term 90 a term 90 i" non associative with precedence 70 for @{ 'C $a $i }.
385
386 (*D
387
388 The first notation defines the writing `𝐈 a` where `a` is a generic
389 term of precedence 90, the maximum one. This high precedence forces
390 parentheses around any term of a lower precedence. For example `𝐈 x`
391 would be accepted, since identifiers have precedence 90, but
392 `𝐈 f x` would be interpreted as `(𝐈 f) x`. In the latter case, parentheses
393 have to be put around `f x`, thus the accepted writing would be `𝐈 (f x)`.
394
395 To obtain the `𝐈` is enough to type `I` and then cycle between its
396 similar symbols with ALT-L. The same for `𝐂`. Notations cannot use
397 regular letters or the round parentheses, thus their variants (like the 
398 bold ones) have to be used.
399
400 The first notation associates `𝐈 a` with `'I $a` where `'I` is a 
401 new content element to which a term `$a` is passed.
402
403 Content elements have to be interpreted, and possibly multiple, 
404 incompatible, interpretations can be defined.
405
406 D*)
407
408 interpretation "I" 'I a = (I ? a).
409 interpretation "C" 'C a i = (C ? a i).
410
411 (*D
412
413 The `interpretation` command allows to define the mapping between
414 the content level and the terms level. Here we associate the `I` and
415 `C` projections of the Axiom set record, where the Axiom set is an implicit 
416 argument `?` to be inferred by the system.
417
418 Interpretation are bi-directional, thus when displaying a term like 
419 `C _ a i`, the system looks for a presentation for the content element
420 `'C a i`. 
421
422 D*)
423
424 notation < "𝐈  \sub( ❨a❩ )" non associative with precedence 70 for @{ 'I $a }.
425 notation < "𝐂 \sub( ❨a,\emsp i❩ )" non associative with precedence 70 for @{ 'C $a $i }.
426
427 (*D
428
429 For output purposes we can define more complex notations, for example
430 we can put bold parentheses around the arguments of `𝐈` and `𝐂`, decreasing
431 the size of the arguments and lowering their baseline (i.e. putting them
432 as subscript), separating them with a comma followed by a little space.
433
434 The first (technical) definition
435 --------------------------------
436
437 Before defining the cover relation as an inductive predicate, one
438 has to notice that the infinity rule uses, in its hypotheses, the 
439 cover relation between two subsets, while the inductive predicate 
440 we are going to define relates an element and a subset.
441
442                     a ∈ U                i ∈ I(a)    C(a,i) ◃ U
443     (reflexivity) ⎼⎼⎼⎼⎼⎼⎼⎼⎼  (infinity) ⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼
444                     a ◃ U                       a ◃ U
445
446 An option would be to unfold the definition of cover between subsets,
447 but we prefer to define the abstract notion of cover between subsets
448 (so that we can attach a (ambiguous) notation to it).
449
450 Anyway, to ease the understanding of the definition of the cover relation 
451 between subsets, we first define the inductive predicate unfolding the 
452 definition, and we later refine it with.
453
454 D*)
455
456 ninductive xcover (A : Ax) (U : Ω^A) : A → CProp[0] ≝ 
457 | xcreflexivity : ∀a:A. a ∈ U → xcover A U a
458 | xcinfinity    : ∀a:A.∀i:𝐈 a. (∀y.y ∈ 𝐂 a i → xcover A U y) → xcover A U a.
459
460 (*D
461
462 We defined the xcover (x will be removed in the final version of the 
463 definition) as an inductive predicate. The arity of the inductive
464 predicate has to be carefully analyzed:
465
466 >  (A : Ax) (U : Ω^A) : A → CProp[0]
467
468 The syntax separates with `:` abstractions that are fixed for every
469 constructor (introduction rule) and abstractions that can change. In that 
470 case the parameter `U` is abstracted once and for all in front of every 
471 constructor, and every occurrence of the inductive predicate is applied to
472 `U` in a consistent way. Arguments abstracted on the right of `:` are not
473 constant, for example the xcinfinity constructor introduces `a ◃ U`,
474 but under the assumption that (for every y) `y ◃ U`. In that rule, the left
475 had side of the predicate changes, thus it has to be abstracted (in the arity
476 of the inductive predicate) on the right of `:`.
477
478 The intuition Valentini suggests is that we are defining the unary predicate
479 "being covered by U" (i.e. `_ ◃ U`) and not "being covered" (i.e. `_ ◃ _`).
480 Unluckily, the syntax of Matita forces us to abstract `U` first, and
481 we will make it the second argument of the predicate using 
482 the notational support Matita offers.
483
484 D*)
485
486 (** ncheck xcreflexivity. *) (* shows: ∀A:Ax.∀U:Ω^A.∀a:A.a∈U → xcover A U a *)
487
488 (*D
489
490 We want now to abstract out `(∀y.y ∈ 𝐂 a i → xcover A U y)` and define
491 a notion `cover_set` to which a notation `𝐂 a i ◃ U` can be attached.
492
493 This notion has to be abstracted over the cover relation (whose
494 type is the arity of the inductive `xcover` predicate just defined).
495
496 Then it has to be abstracted over the arguments of that cover relation,
497 i.e. the axiom set and the set `U`, and the subset (in that case `𝐂 a i`)
498 sitting on the left hand side of `◃`. 
499
500 D*)
501
502 ndefinition cover_set : 
503   ∀cover: ∀A:Ax.Ω^A → A → CProp[0]. ∀A:Ax.∀C,U:Ω^A. CProp[0] 
504 ≝ 
505   λcover.                           λA,    C,U.     ∀y.y ∈ C → cover A U y.
506
507 (*D
508
509 The `ndefinition` command takes a name, a type and body (of that type).
510 The type can be omitted, and in that case it is inferred by the system.
511 If the type is given, the system uses it to infer implicit arguments
512 of the body. In that case all types are left implicit in the body.
513
514 We now define the notation `a ◃ b`. Here the keywork `hvbox`
515 and `break` tell the system how to wrap text when it does not
516 fit the screen (they can be safely ignored for the scope of
517 this tutorial). We also add an interpretation for that notation, 
518 where the (abstracted) cover relation is implicit. The system
519 will not be able to infer it from the other arguments `C` and `U`
520 and will thus prompt the user for it. This is also why we named this 
521 interpretation `covers set temp`: we will later define another 
522 interpretation in which the cover relation is the one we are going to 
523 define.
524
525 D*)
526
527 notation "hvbox(a break ◃ b)" non associative with precedence 45
528 for @{ 'covers $a $b }.
529
530 interpretation "covers set temp" 'covers C U = (cover_set ?? C U).
531
532 (*D
533
534 The cover relation
535 ------------------
536
537 We can now define the cover relation using the `◃` notation for 
538 the premise of infinity. 
539
540 D*)
541
542 ninductive cover (A : Ax) (U : Ω^A) : A → CProp[0] ≝ 
543 | creflexivity : ∀a. a ∈ U → cover A U a
544 | cinfinity    : ∀a. ∀i. 𝐂 a i ◃ U → cover A U a.
545 (** screenshot "cover". *) 
546 napply cover;
547 nqed.
548
549 (*D
550
551 Note that the system accepts the definition
552 but prompts the user for the relation the `cover_set` notion is
553 abstracted on.
554
555
556
557 The horizontal line separates the hypotheses from the conclusion.
558 The `napply cover` command tells the system that the relation
559 it is looking for is exactly our first context entry (i.e. the inductive
560 predicate we are defining, up to α-conversion); while the `nqed` command
561 ends a definition or proof.
562
563 We can now define the interpretation for the cover relation between an
564 element and a subset first, then between two subsets (but this time
565 we fix the relation `cover_set` is abstracted on).
566
567 D*)
568
569 interpretation "covers" 'covers a U = (cover ? U a).
570 interpretation "covers set" 'covers a U = (cover_set cover ? a U).
571
572 (*D
573
574 We will proceed similarly for the fish relation, but before going
575 on it is better to give a short introduction to the proof mode of Matita.
576 We define again the `cover_set` term, but this time we build
577 its body interactively. In the λ-calculus Matita is based on, CIC, proofs
578 and terms share the same syntax, and it is thus possible to use the
579 commands devoted to build proof term also to build regular definitions.
580 A tentative semantics for the proof mode commands (called tactics)
581 in terms of sequent calculus rules are given in the
582 <a href="#appendix">appendix</a>.
583
584 D*)
585
586 ndefinition xcover_set : 
587   ∀c: ∀A:Ax.Ω^A → A → CProp[0]. ∀A:Ax.∀C,U:Ω^A. CProp[0]. 
588                          (** screenshot "xcover-set-1". *)
589 #cover; #A; #C; #U;      (** screenshot "xcover-set-2". *) 
590 napply (∀y:A.y ∈ C → ?); (** screenshot "xcover-set-3". *)
591 napply cover;            (** screenshot "xcover-set-4". *)
592 ##[ napply A;
593 ##| napply U;
594 ##| napply y;
595 ##]
596 nqed.
597
598 (*D[xcover-set-1]
599 The system asks for a proof of the full statement, in an empty context.
600
601 The `#` command is the ∀-introduction rule, it gives a name to an 
602 assumption putting it in the context, and generates a λ-abstraction
603 in the proof term.
604
605 D[xcover-set-2]
606 We have now to provide a proposition, and we exhibit it. We left
607 a part of it implicit; since the system cannot infer it it will
608 ask for it later. 
609 Note that the type of `∀y:A.y ∈ C → ?` is a proposition
610 whenever `?` is a proposition.
611
612 D[xcover-set-3]
613 The proposition we want to provide is an application of the
614 cover relation we have abstracted in the context. The command
615 `napply`, if the given term has not the expected type (in that
616 case it is a product versus a proposition) it applies it to as many 
617 implicit arguments as necessary (in that case `? ? ?`).
618
619 D[xcover-set-4]
620 The system will now ask in turn the three implicit arguments 
621 passed to cover. The syntax `##[` allows to start a branching
622 to tackle every sub proof individually, otherwise every command
623 is applied to every subproof. The command `##|` switches to the next
624 subproof and `##]` ends the branching.  
625 D*)
626
627 (*D
628
629 The fish relation
630 -----------------
631
632 The definition of fish works exactly the same way as for cover, except 
633 that it is defined as a coinductive proposition.
634 D*)
635
636 ndefinition fish_set ≝ λf:∀A:Ax.Ω^A → A → CProp[0].
637  λA,U,V.
638   ∃a.a ∈ V ∧ f A U a.
639
640 (* a \ltimes b *)
641 notation "hvbox(a break ⋉ b)" non associative with precedence 45
642 for @{ 'fish $a $b }. 
643
644 interpretation "fish set temp" 'fish A U = (fish_set ?? U A).
645
646 ncoinductive fish (A : Ax) (F : Ω^A) : A → CProp[0] ≝ 
647 | cfish : ∀a. a ∈ F → (∀i:𝐈 a .𝐂  a i ⋉ F) → fish A F a.
648 napply fish;
649 nqed.
650
651 interpretation "fish set" 'fish A U = (fish_set fish ? U A).
652 interpretation "fish" 'fish a U = (fish ? U a).
653
654 (*D
655
656 Introduction rule for fish
657 ---------------------------
658
659 Matita is able to generate elimination rules for inductive types
660 D*)
661
662 (** ncheck cover_rect_CProp0. *) 
663
664 (*D
665
666 but not introduction rules for the coinductive case. 
667
668                    P ⊆ U   (∀x,j.x ∈ P → C(x,j) ≬ P)   a ∈ P
669     (fish intro) ⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼
670                                    a ⋉ U
671
672 We thus have to define the introduction rule for fish by co-recursion.
673 Here we again use the proof mode of Matita to exhibit the body of the
674 corecursive function.
675
676 D*)
677
678 nlet corec fish_rec (A:Ax) (U: Ω^A)
679  (P: Ω^A) (H1: P ⊆ U)
680   (H2: ∀a:A. a ∈ P → ∀j: 𝐈 a. 𝐂 a j ≬ P): ∀a:A. ∀p: a ∈ P. a ⋉ U ≝ ?.
681                                        (** screenshot "def-fish-rec-1".   *)
682 #a; #a_in_P; napply cfish;                  (** screenshot "def-fish-rec-2".   *)
683 ##[ nchange in H1 with (∀b.b∈P → b∈U); (** screenshot "def-fish-rec-2-1". *) 
684     napply H1;                         (** screenshot "def-fish-rec-3".   *) 
685     nassumption;
686 ##| #i; ncases (H2 a a_in_P i);             (** screenshot "def-fish-rec-5".   *) 
687     #x; *; #xC; #xP;                   (** screenshot "def-fish-rec-5-1". *) 
688     @;                                 (** screenshot "def-fish-rec-6".   *)
689     ##[ napply x
690     ##| @;                             (** screenshot "def-fish-rec-7".   *)
691         ##[ napply xC; 
692         ##| napply (fish_rec ? U P);   (** screenshot "def-fish-rec-9".   *)
693             nassumption;
694         ##]
695     ##]
696 ##]
697 nqed.
698
699 (*D
700 D[def-fish-rec-1]
701 Note the first item of the context, it is the corecursive function we are 
702 defining. This item allows to perform the recursive call, but we will be
703 allowed to do such call only after having generated a constructor of
704 the fish coinductive type.
705
706 We introduce `a` and `p`, and then return the fish constructor `cfish`.
707 Since the constructor accepts two arguments, the system asks for them.
708
709 D[def-fish-rec-2]
710 The first one is a proof that `a ∈ U`. This can be proved using `H1` and `p`.
711 With the `nchange` tactic we change `H1` into an equivalent form (this step
712 can be skipped, since the system would be able to unfold the definition
713 of inclusion by itself)
714
715 D[def-fish-rec-2-1]
716 It is now clear that `H1` can be applied. Again `napply` adds two 
717 implicit arguments to `H1 ? ?`, obtaining a proof of `? ∈ U` given a proof
718 that `? ∈ P`. Thanks to unification, the system understands that `?` is actually
719 `a`, and it asks a proof that `a ∈ P`.
720
721 D[def-fish-rec-3]
722 The `nassumption` tactic looks for the required proof in the context, and in
723 that cases finds it in the last context position. 
724
725 We move now to the second branch of the proof, corresponding to the second
726 argument of the `cfish` constructor.
727
728 We introduce `i` and then we destruct `H2 a p i`, that being a proof
729 of an overlap predicate, give as an element and a proof that it is 
730 both in `𝐂 a i` and `P`.
731
732 D[def-fish-rec-5]
733 We then introduce `x`, break the conjunction (the `*;` command is the
734 equivalent of `ncases` but operates on the first hypothesis that can
735 be introduced). We then introduce the two sides of the conjunction.
736
737 D[def-fish-rec-5-1]
738 The goal is now the existence of a point in `𝐂 a i` fished by `U`.
739 We thus need to use the introduction rule for the existential quantifier.
740 In CIC it is a defined notion, that is an inductive type with just
741 one constructor (one introduction rule) holding the witness and the proof
742 that the witness satisfies a proposition.
743
744 > ncheck Ex. 
745
746 Instead of trying to remember the name of the constructor, that should
747 be used as the argument of `napply`, we can ask the system to find by
748 itself the constructor name and apply it with the `@` tactic. 
749 Note that some inductive predicates, like the disjunction, have multiple
750 introduction rules, and thus `@` can be followed by a number identifying
751 the constructor.
752
753 D[def-fish-rec-6]
754 After choosing `x` as the witness, we have to prove a conjunction,
755 and we again apply the introduction rule for the inductively defined
756 predicate `∧`.
757
758 D[def-fish-rec-7]
759 The left hand side of the conjunction is trivial to prove, since it 
760 is already in the context. The right hand side needs to perform
761 the co-recursive call.
762
763 D[def-fish-rec-9]
764 The co-recursive call needs some arguments, but all of them are
765 in the context. Instead of explicitly mention them, we use the
766 `nassumption` tactic, that simply tries to apply every context item.
767
768 D*)
769
770 (*D
771
772 Subset of covered/fished points
773 -------------------------------
774
775 We now have to define the subset of `S` of points covered by `U`.
776 We also define a prefix notation for it. Remember that the precedence
777 of the prefix form of a symbol has to be higher than the precedence 
778 of its infix form.
779
780 D*)
781
782 ndefinition coverage : ∀A:Ax.∀U:Ω^A.Ω^A ≝ λA,U.{ a | a ◃ U }.
783
784 notation "◃U" non associative with precedence 55 for @{ 'coverage $U }.
785
786 interpretation "coverage cover" 'coverage U = (coverage ? U).
787
788 (*D
789
790 Here we define the equation characterizing the cover relation. 
791 Even if it is not part of the paper, we proved that `◃(U)` is 
792 the minimum solution for
793 such equation, the interested reader should be able to reply the proof
794 with Matita.
795
796 D*)
797
798 ndefinition cover_equation : ∀A:Ax.∀U,X:Ω^A.CProp[0] ≝  λA,U,X. 
799   ∀a.a ∈ X ↔ (a ∈ U ∨ ∃i:𝐈 a.∀y.y ∈ 𝐂 a i → y ∈ X).  
800
801 ntheorem coverage_cover_equation : ∀A,U. cover_equation A U (◃U).
802 #A; #U; #a; @; #H;
803 ##[ nelim H; #b; 
804     ##[ #bU; @1; nassumption;
805     ##| #i; #CaiU; #IH; @2; @ i; #c; #cCbi; ncases (IH ? cCbi);
806         ##[ #E; @; napply E;
807         ##| #_; napply CaiU; nassumption; ##] ##]
808 ##| ncases H; ##[ #E; @; nassumption]
809     *; #j; #Hj; @2 j; #w; #wC; napply Hj; nassumption;
810 ##]
811 nqed. 
812
813 ntheorem coverage_min_cover_equation : 
814   ∀A,U,W. cover_equation A U W → ◃U ⊆ W.
815 #A; #U; #W; #H; #a; #aU; nelim aU; #b;
816 ##[ #bU; ncases (H b); #_; #H1; napply H1; @1; nassumption;
817 ##| #i; #CbiU; #IH; ncases (H b); #_; #H1; napply H1; @2; @i; napply IH;
818 ##]
819 nqed.
820
821 (*D
822
823 We similarly define the subset of points "fished" by `F`, the 
824 equation characterizing `⋉(F)` and prove that fish is
825 the biggest solution for such equation.
826
827 D*) 
828
829 notation "⋉F" non associative with precedence 55
830 for @{ 'fished $F }.
831
832 ndefinition fished : ∀A:Ax.∀F:Ω^A.Ω^A ≝ λA,F.{ a | a ⋉ F }.
833
834 interpretation "fished fish" 'fished F = (fished ? F).
835
836 ndefinition fish_equation : ∀A:Ax.∀F,X:Ω^A.CProp[0] ≝ λA,F,X.
837   ∀a. a ∈ X ↔ a ∈ F ∧ ∀i:𝐈 a.∃y.y ∈ 𝐂 a i ∧ y ∈ X. 
838   
839 ntheorem fished_fish_equation : ∀A,F. fish_equation A F (⋉F).
840 #A; #F; #a; @; (* *; non genera outtype che lega a *) #H; ncases H;
841 ##[ #b; #bF; #H2; @ bF; #i; ncases (H2 i); #c; *; #cC; #cF; @c; @ cC;
842     napply cF;  
843 ##| #aF; #H1; @ aF; napply H1;
844 ##]
845 nqed.
846
847 ntheorem fished_max_fish_equation : ∀A,F,G. fish_equation A F G → G ⊆ ⋉F.
848 #A; #F; #G; #H; #a; #aG; napply (fish_rec … aG);
849 #b; ncases (H b); #H1; #_; #bG; ncases (H1 bG); #E1; #E2; nassumption; 
850 nqed. 
851
852 (*D
853
854 Part 2, the new set of axioms
855 -----------------------------
856
857 Since the name of defined objects (record included) has to be unique
858 within the same file, we prefix every field name
859 in the new definition of the axiom set with `n`.
860
861 D*)
862
863 nrecord nAx : Type[1] ≝ { 
864   nS:> Type[0]; 
865   nI: nS → Type[0];
866   nD: ∀a:nS. nI a → Type[0];
867   nd: ∀a:nS. ∀i:nI a. nD a i → nS
868 }.
869
870 (*D
871
872 We again define a notation for the projections, making the 
873 projected record an implicit argument. Note that, since we already have
874 a notation for `𝐈`, we just add another interpretation for it. The
875 system, looking at the argument of `𝐈`, will be able to choose
876 the correct interpretation. 
877
878 D*)
879
880 notation "𝐃 \sub ( ❨a,\emsp i❩ )" non associative with precedence 70 for @{ 'D $a $i }.
881 notation "𝐝 \sub ( ❨a,\emsp i,\emsp j❩ )" non associative with precedence 70 for @{ 'd $a $i $j}.
882
883 notation > "𝐃 term 90 a term 90 i" non associative with precedence 70 for @{ 'D $a $i }.
884 notation > "𝐝 term 90 a term 90 i term 90 j" non associative with precedence 70 for @{ 'd $a $i $j}.
885
886 interpretation "D" 'D a i = (nD ? a i).
887 interpretation "d" 'd a i j = (nd ? a i j).
888 interpretation "new I" 'I a = (nI ? a).
889
890 (*D
891
892 The first result the paper presents to motivate the new formulation
893 of the axiom set is the possibility to define and old axiom set
894 starting from a new one and vice versa. The key definition for
895 such construction is the image of d(a,i).
896 The paper defines the image as
897
898 > Im[d(a,i)] = { d(a,i,j) | j : D(a,i) }
899
900 but this not so formal notation poses some problems. The image is
901 often used as the left hand side of the ⊆ predicate
902
903 > Im[d(a,i)] ⊆ V
904
905 Of course this writing is interpreted by the authors as follows 
906
907 > ∀j:D(a,i). d(a,i,j) ∈ V
908
909 If we need to use the image to define `𝐂 ` (a subset of `S`) we are obliged to
910 form a subset, i.e. to place a single variable `{ here | … }` of type `S`.
911
912 > Im[d(a,i)] = { y | ∃j:D(a,i). y = d(a,i,j) }
913
914 This poses no theoretical problems, since `S` is a Type and thus 
915 equipped with the `Id` equality. If `S` was a setoid, here the equality
916 would have been the one of the setoid.
917
918 Unless we define two different images, one for stating that the image is ⊆ of
919 something and another one to define `𝐂`, we end up using always the latter.
920 Thus the statement `Im[d(a,i)] ⊆ V` unfolds to
921
922 > ∀x:S. ( ∃j.x = d(a,i,j) ) → x ∈ V
923
924 That, up to rewriting with the equation defining `x`, is what we mean.
925 Since we decided to use `Id` the rewriting always work (the elimination
926 principle for `Id` is Leibnitz's equality, that is quantified over
927 the context. 
928
929 The problem that arises if we decide to make `S` a setoid is that 
930 `V` has to be extensional w.r.t. the equality of `S` (i.e. the characteristic
931 functional proposition has to quotient its input with a relation bigger
932 than the one of `S`.
933
934 > ∀x,y:S. x = y → x ∈ V → y ∈ V
935
936 If `V` is a complex construction, the proof may not be trivial.
937
938 D*)
939
940 include "logic/equality.ma".
941
942 ndefinition image ≝ λA:nAx.λa:A.λi. { x | ∃j:𝐃 a i. x = 𝐝 a i j }.
943
944 notation > "𝐈𝐦  [𝐝 term 90 a term 90 i]" non associative with precedence 70 for @{ 'Im $a $i }.
945 notation < "𝐈𝐦  [𝐝 \sub ( ❨a,\emsp i❩ )]" non associative with precedence 70 for @{ 'Im $a $i }.
946
947 interpretation "image" 'Im a i = (image ? a i).
948
949 (*D
950
951 Thanks to our definition of image, we can define a function mapping a
952 new axiom set to an old one and vice versa. Note that in the second
953 definition, when we give the `𝐝` component, the projection of the 
954 Σ-type is inlined (constructed on the fly by `*;`) 
955 while in the paper it was named `fst`.
956
957 D*)
958
959 ndefinition Ax_of_nAx : nAx → Ax.
960 #A; @ A (nI ?); #a; #i; napply (𝐈𝐦 [𝐝 a i]);
961 nqed.
962
963 ndefinition nAx_of_Ax : Ax → nAx.
964 #A; @ A (I ?);
965 ##[ #a; #i; napply (Σx:A.x ∈ 𝐂 a i);
966 ##| #a; #i; *; #x; #_; napply x;
967 ##]
968 nqed.
969
970 (*D
971
972 We now prove that the two function above form a retraction pair for
973 the `C` component of the axiom set. To prove that we face a little
974 problem since CIC is not equipped with η-conversion. This means that
975 the followin does not hold (where `A` is an axiom set).
976
977 > A = (S A, I A, C A)
978
979 This can be proved only under a pattern mach over `A`, that means
980 that the resulting computation content of the proof is a program
981 that computes something only if `A` is a concrete axiom set.
982
983 To state the lemma we have to drop notation, and explicitly
984 give the axiom set in input to the `C` projection.
985
986 D*)
987
988 nlemma Ax_nAx_equiv : 
989   ∀A:Ax. ∀a,i. C (Ax_of_nAx (nAx_of_Ax A)) a i ⊆ C A a i ∧
990                C A a i ⊆ C (Ax_of_nAx (nAx_of_Ax A)) a i.               
991 #A; #a; #i; @; #b; #H;                               (** screenshot "retr-1". *)
992 ##[  ncases A in a i b H; #S; #I; #C; #a; #i; #b; #H;(** screenshot "retr-2". *)
993      nchange in a with S; nwhd in H;                 (** screenshot "retr-3". *) 
994      ncases H; #x; #E; nrewrite > E; nwhd in x;      (** screenshot "retr-4". *)              
995      ncases x; #b; #Hb; nnormalize; nassumption;
996 ##|  ncases A in a i b H; #S; #I; #C; #a; #i; #b; #H; @;
997      ##[ @ b; nassumption;
998      ##| nnormalize; @; ##]
999 ##]
1000 nqed.
1001
1002 (*D
1003 D[retr-1]
1004 Look for example the type of `a`. The command `nchange in a with A`
1005 would fail because of the missing η-conversion rule. We have thus
1006 to pattern match over `A` and introduce its pieces.
1007
1008 D[retr-2]
1009 Now the system accepts that the type of `a` is the fist component
1010 of the axiom set, now called `S`. Unfolding definitions in `H` we discover
1011 there is still some work to do.
1012
1013 D[retr-3]
1014 To use the equation defining `b` we have to eliminate `H`. Unfolding
1015 definitions in `x` tell us there is still something to do. The `nrewrite`
1016 tactic is a shortcut for the elimination principle of the equality.
1017 It accepts an additional argument `<` or `>` to rewrite left-to-right
1018 or right-to-left. 
1019
1020 D[retr-4]
1021 We defined `𝐝` to be the first projection of `x`, thus we have to
1022 eliminate `x` to actually compute `𝐝`. 
1023
1024 The remaining part of the proof it not interesting and poses no
1025 new problems.
1026
1027 D*)
1028
1029 (*D
1030
1031 We then define the inductive type of ordinals, parametrized over an axiom
1032 set. We also attach some notations to the constructors.
1033
1034 D*)
1035
1036 ninductive Ord (A : nAx) : Type[0] ≝ 
1037  | oO : Ord A
1038  | oS : Ord A → Ord A
1039  | oL : ∀a:A.∀i.∀f:𝐃 a i → Ord A. Ord A.
1040
1041 notation "0" non associative with precedence 90 for @{ 'oO }.
1042 notation "x+1" non associative with precedence 50 for @{'oS $x }.
1043 notation "Λ term 90 f" non associative with precedence 50 for @{ 'oL $f }.
1044
1045 interpretation "ordinals Zero" 'oO = (oO ?).
1046 interpretation "ordinals Succ" 'oS x = (oS ? x).
1047 interpretation "ordinals Lambda" 'oL f = (oL ? ? ? f).
1048
1049 (*D
1050
1051 The definition of `U⎽x` is by recursion over the ordinal `x`. 
1052 We thus define a recursive function using the `nlet rec` command. 
1053 The `on x` directive tells
1054 the system on which argument the function is (structurally) recursive.
1055
1056 In the `oS` case we use a local definition to name the recursive call
1057 since it is used twice.
1058
1059 Note that Matita does not support notation in the left hand side
1060 of a pattern match, and thus the names of the constructors have to 
1061 be spelled out verbatim.
1062
1063 D*)
1064
1065 nlet rec famU (A : nAx) (U : Ω^A) (x : Ord A) on x : Ω^A ≝ 
1066   match x with
1067   [ oO ⇒ U
1068   | oS y ⇒ let U_n ≝ famU A U y in U_n ∪ { x | ∃i.𝐈𝐦[𝐝 x i] ⊆ U_n} 
1069   | oL a i f ⇒ { x | ∃j.x ∈ famU A U (f j) } ].
1070   
1071 notation < "term 90 U \sub (term 90 x)" non associative with precedence 50 for @{ 'famU $U $x }.
1072 notation > "U ⎽ term 90 x" non associative with precedence 50 for @{ 'famU $U $x }.
1073
1074 interpretation "famU" 'famU U x = (famU ? U x).
1075
1076 (*D
1077
1078 We attach as the input notation for U_x the similar `U⎽x` where underscore,
1079 that is a character valid for identifier names, has been replaced by `⎽` that is
1080 not. The symbol `⎽` can act as a separator, and can be typed as an alternative
1081 for `_` (i.e. pressing ALT-L after `_`). 
1082
1083 The notion ◃(U) has to be defined as the subset of elements `y`  
1084 belonging to `U⎽x` for some `x`. Moreover, we have to define the notion
1085 of cover between sets again, since the one defined at the beginning
1086 of the tutorial works only for the old axiom set.
1087
1088 D*)
1089   
1090 ndefinition ord_coverage : ∀A:nAx.∀U:Ω^A.Ω^A ≝ 
1091   λA,U.{ y | ∃x:Ord A. y ∈ famU ? U x }.
1092
1093 ndefinition ord_cover_set ≝ λc:∀A:nAx.Ω^A → Ω^A.λA,C,U.
1094   ∀y.y ∈ C → y ∈ c A U.
1095
1096 interpretation "coverage new cover" 'coverage U = (ord_coverage ? U).
1097 interpretation "new covers set" 'covers a U = (ord_cover_set ord_coverage ? a U).
1098 interpretation "new covers" 'covers a U = (mem ? (ord_coverage ? U) a).
1099
1100 (*D
1101
1102 Before proving that this cover relation validates the reflexivity and infinity
1103 rules, we prove this little technical lemma that is used in the proof for the 
1104 infinity rule.
1105
1106 D*)
1107
1108 nlemma ord_subset: ∀A:nAx.∀a:A.∀i,f,U.∀j:𝐃 a i. U⎽(f j) ⊆ U⎽(Λ f).
1109 #A; #a; #i; #f; #U; #j; #b; #bUf; @ j; nassumption;
1110 nqed.
1111
1112 (*D
1113
1114 The proof of infinity uses the following form of the Axiom of Choice,
1115 that cannot be proved inside Matita, since the existential quantifier
1116 lives in the sort of predicative propositions while the sigma in the conclusion
1117 lives in the sort of data types, and thus the former cannot be eliminated
1118 to provide the witness for the second.
1119
1120 D*)
1121
1122 naxiom AC : ∀A,a,i,U.
1123   (∀j:𝐃 a i.∃x:Ord A.𝐝 a i j ∈ U⎽x) → (Σf.∀j:𝐃 a i.𝐝 a i j ∈ U⎽(f j)).
1124
1125 (*D
1126
1127 Note that, if we will decide later to identify ∃ and Σ, `AC` is
1128 trivially provable
1129
1130 D*)
1131
1132 nlemma AC_exists_is_sigma : ∀A,a,i,U.
1133   (∀j:𝐃 a i.Σx:Ord A.𝐝 a i j ∈ U⎽x) → (Σf.∀j:𝐃 a i.𝐝 a i j ∈ U⎽(f j)).
1134 #A; #a; #i; #U; #H; @;
1135 ##[ #j; ncases (H j); #x; #_; napply x;
1136 ##| #j; ncases (H j); #x; #Hx; napply Hx; ##]
1137 nqed. 
1138
1139 (*D
1140
1141 In case we made `S` a setoid, the following property has to be proved
1142
1143 > nlemma U_x_is_ext: ∀A:nAx.∀a,b:A.∀x.∀U. a = b → b ∈ U⎽x → a ∈ U⎽x.
1144
1145 Anyway this proof is a non trivial induction over x, that requires `𝐈` and `𝐃` to be
1146 declared as morphisms. 
1147
1148 D*)
1149
1150
1151 (*D
1152
1153 The reflexivity proof is trivial, it is enough to provide the ordinal `0`
1154 as a witness, then `◃(U)` reduces to `U` by definition, 
1155 hence the conclusion. Note that `0` is between `(` and `)` to
1156 make it clear that it is a term (an ordinal) and not the number
1157 of the constructor we want to apply (that is the first and only one
1158 of the existential inductive type).
1159
1160 D*)
1161 ntheorem new_coverage_reflexive: ∀A:nAx.∀U:Ω^A.∀a. a ∈ U → a ◃ U.
1162 #A; #U; #a; #H; @ (0); napply H;
1163 nqed.
1164
1165 (*D
1166
1167 We now proceed with the proof of the infinity rule.
1168
1169 D*)
1170
1171 alias symbol "covers" (instance 3) = "new covers set".
1172 ntheorem new_coverage_infinity:
1173   ∀A:nAx.∀U:Ω^A.∀a:A. (∃i:𝐈 a. 𝐈𝐦[𝐝 a i] ◃ U) → a ◃ U.
1174 #A; #U; #a;                                   (** screenshot "n-cov-inf-1". *)  
1175 *; #i; #H; nnormalize in H;                   (** screenshot "n-cov-inf-2". *)
1176 ncut (∀y:𝐃 a i.∃x:Ord A.𝐝 a i y ∈ U⎽x); ##[    (** screenshot "n-cov-inf-3". *)
1177   #z; napply H; @ z; @; ##] #H';              (** screenshot "n-cov-inf-4". *)
1178 ncases (AC … H'); #f; #Hf;                    (** screenshot "n-cov-inf-5". *)
1179 ncut (∀j.𝐝 a i j ∈ U⎽(Λ f));
1180   ##[ #j; napply (ord_subset … f … (Hf j));##] #Hf';(** screenshot "n-cov-inf-6". *)
1181 @ (Λ f+1);                                    (** screenshot "n-cov-inf-7". *)
1182 @2;                                           (** screenshot "n-cov-inf-8". *) 
1183 @i; #x; *; #d; #Hd;                           (** screenshot "n-cov-inf-9". *)  
1184 nrewrite > Hd; napply Hf';
1185 nqed.
1186
1187 (*D
1188 D[n-cov-inf-1]
1189 We eliminate the existential, obtaining an `i` and a proof that the 
1190 image of `𝐝 a i` is covered by U. The `nnormalize` tactic computes the normal
1191 form of `H`, thus expands the definition of cover between sets.
1192
1193 D[n-cov-inf-2]
1194 When the paper proof considers `H`, it implicitly substitutes assumed 
1195 equation defining `y` in its conclusion. 
1196 In Matita this step is not completely trivial.
1197 We thus assert (`ncut`) the nicer form of `H` and prove it.
1198
1199 D[n-cov-inf-3]
1200 After introducing `z`, `H` can be applied (choosing `𝐝 a i z` as `y`). 
1201 What is the left to prove is that `∃j: 𝐃 a j. 𝐝 a i z = 𝐝 a i j`, that 
1202 becomes trivial if `j` is chosen to be `z`. 
1203
1204 D[n-cov-inf-4]
1205 Under `H'` the axiom of choice `AC` can be eliminated, obtaining the `f` and 
1206 its property. Note that the axiom `AC` was abstracted over `A,a,i,U` before
1207 assuming `(∀j:𝐃 a i.∃x:Ord A.𝐝 a i j ∈ U⎽x)`. Thus the term that can be eliminated
1208 is `AC ???? H'` where the system is able to infer every `?`. Matita provides
1209 a facility to specify a number of `?` in a compact way, i.e. `…`. The system
1210 expand `…` first to zero, then one, then two, three and finally four question 
1211 marks, "guessing" how may of them are needed. 
1212
1213 D[n-cov-inf-5]
1214 The paper proof does now a forward reasoning step, deriving (by the ord_subset 
1215 lemma we proved above) `Hf'` i.e. 𝐝 a i j ∈ U⎽(Λf).
1216
1217 D[n-cov-inf-6]
1218 To prove that `a◃U` we have to exhibit the ordinal x such that `a ∈ U⎽x`.
1219
1220 D[n-cov-inf-7]
1221 The definition of `U⎽(…+1)` expands to the union of two sets, and proving
1222 that `a ∈ X ∪ Y` is, by definition, equivalent to prove that `a` is in `X` or `Y`. 
1223 Applying the second constructor `@2;` of the disjunction, 
1224 we are left to prove that `a` belongs to the right hand side of the union.
1225
1226 D[n-cov-inf-8]
1227 We thus provide `i` as the witness of the existential, introduce the 
1228 element being in the image and we are
1229 left to prove that it belongs to `U⎽(Λf)`. In the meanwhile, since belonging 
1230 to the image means that there exists an object in the domain …, we eliminate the
1231 existential, obtaining `d` (of type `𝐃 a i`) and the equation defining `x`.  
1232
1233 D[n-cov-inf-9]
1234 We just need to use the equational definition of `x` to obtain a conclusion
1235 that can be proved with `Hf'`. We assumed that `U⎽x` is extensional for
1236 every `x`, thus we are allowed to use `Hd` and close the proof.
1237
1238 D*)
1239
1240 (*D
1241
1242 The next proof is that ◃(U) is minimal. The hardest part of the proof
1243 is to prepare the goal for the induction. The desiderata is to prove
1244 `U⎽o ⊆ V` by induction on `o`, but the conclusion of the lemma is,
1245 unfolding all definitions:
1246
1247 > ∀x. x ∈ { y | ∃o:Ord A.y ∈ U⎽o } → x ∈ V
1248
1249 D*)
1250
1251 nlemma new_coverage_min :  
1252   ∀A:nAx.∀U:Ω^A.∀V.U ⊆ V → (∀a:A.∀i.𝐈𝐦[𝐝 a i] ⊆ V → a ∈ V) → ◃U ⊆ V.
1253 #A; #U; #V; #HUV; #Im;#b;                       (** screenshot "n-cov-min-2". *)
1254 *; #o;                                          (** screenshot "n-cov-min-3". *)
1255 ngeneralize in match b; nchange with (U⎽o ⊆ V); (** screenshot "n-cov-min-4". *)
1256 nelim o;                                        (** screenshot "n-cov-min-5". *) 
1257 ##[ napply HUV; 
1258 ##| #p; #IH; napply subseteq_union_l; ##[ nassumption; ##]
1259     #x; *; #i; #H; napply (Im ? i); napply (subseteq_trans … IH); napply H;
1260 ##| #a; #i; #f; #IH; #x; *; #d; napply IH; ##]
1261 nqed.
1262
1263 (*D
1264 D[n-cov-min-2]
1265 After all the introductions, event the element hidden in the ⊆ definition,
1266 we have to eliminate the existential quantifier, obtaining the ordinal `o`
1267
1268 D[n-cov-min-3]
1269 What is left is almost right, but the element `b` is already in the
1270 context. We thus generalize every occurrence of `b` in 
1271 the current goal, obtaining `∀c.c ∈ U⎽o → c ∈ V` that is `U⎽o ⊆ V`.
1272
1273 D[n-cov-min-4]
1274 We then proceed by induction on `o` obtaining the following goals
1275
1276 D[n-cov-min-5]
1277 All of them can be proved using simple set theoretic arguments,
1278 the induction hypothesis and the assumption `Im`.
1279
1280 D*)
1281
1282
1283 (*D
1284
1285 The notion `F⎽x` is again defined by recursion over the ordinal `x`.
1286
1287 D*)
1288
1289 nlet rec famF (A: nAx) (F : Ω^A) (x : Ord A) on x : Ω^A ≝ 
1290   match x with
1291   [ oO ⇒ F
1292   | oS o ⇒ let F_o ≝ famF A F o in F_o ∩ { x | ∀i:𝐈 x.∃j:𝐃 x i.𝐝 x i j ∈ F_o } 
1293   | oL a i f ⇒ { x | ∀j:𝐃 a i.x ∈ famF A F (f j) }
1294   ].
1295
1296 interpretation "famF" 'famU U x = (famF ? U x).
1297
1298 ndefinition ord_fished : ∀A:nAx.∀F:Ω^A.Ω^A ≝ λA,F.{ y | ∀x:Ord A. y ∈ F⎽x }.
1299
1300 interpretation "fished new fish" 'fished U = (ord_fished ? U).
1301 interpretation "new fish" 'fish a U = (mem ? (ord_fished ? U) a).
1302
1303 (*D
1304
1305 The proof of compatibility uses this little result, that we 
1306 proved outside the main proof. 
1307
1308 D*)
1309 nlemma co_ord_subset: ∀A:nAx.∀F:Ω^A.∀a,i.∀f:𝐃 a i → Ord A.∀j. F⎽(Λ f) ⊆ F⎽(f j).
1310 #A; #F; #a; #i; #f; #j; #x; #H; napply H;
1311 nqed.
1312
1313 (*D
1314
1315 We assume the dual of the axiom of choice, as in the paper proof.
1316
1317 D*)
1318 naxiom AC_dual: ∀A:nAx.∀a:A.∀i,F. 
1319  (∀f:𝐃 a i → Ord A.∃x:𝐃 a i.𝐝 a i x ∈ F⎽(f x))
1320     → ∃j:𝐃 a i.∀x:Ord A.𝐝 a i j ∈ F⎽x.
1321
1322 (*D
1323
1324 Proving the anti-reflexivity property is simple, since the
1325 assumption `a ⋉ F` states that for every ordinal `x` (and thus also 0)
1326 `a ∈ F⎽x`. If `x` is choose to be `0`, we obtain the thesis.
1327
1328 D*)
1329 ntheorem new_fish_antirefl: ∀A:nAx.∀F:Ω^A.∀a. a ⋉ F → a ∈ F.
1330 #A; #F; #a; #H; nlapply (H 0); #aFo; napply aFo;
1331 nqed.
1332
1333 (*D
1334
1335 We now prove the compatibility property for the new fish relation.
1336
1337 D*)
1338 ntheorem new_fish_compatible: 
1339  ∀A:nAx.∀F:Ω^A.∀a. a ⋉ F → ∀i:𝐈 a.∃j:𝐃 a i.𝐝 a i j ⋉ F.
1340 #A; #F; #a; #aF; #i; nnormalize;               (** screenshot "n-f-compat-1". *)
1341 napply AC_dual; #f;                            (** screenshot "n-f-compat-2". *)
1342 nlapply (aF (Λf+1)); #aLf;                     (** screenshot "n-f-compat-3". *)
1343 nchange in aLf with 
1344   (a ∈ F⎽(Λ f) ∧ ∀i:𝐈 a.∃j:𝐃 a i.𝐝 a i j ∈ F⎽(Λ f)); (** screenshot "n-f-compat-4". *)
1345 ncases aLf; #_; #H; nlapply (H i);                 (** screenshot "n-f-compat-5". *)
1346 *; #j; #Hj; @j;                                    (** screenshot "n-f-compat-6". *)
1347 napply (co_ord_subset … Hj);
1348 nqed.
1349
1350 (*D
1351 D[n-f-compat-1]
1352 After reducing to normal form the goal, we observe it is exactly the conclusion of
1353 the dual axiom of choice we just assumed. We thus apply it ad introduce the 
1354 fcuntion `f`.
1355
1356 D[n-f-compat-2]
1357 The hypothesis `aF` states that `a⋉F⎽x` for every `x`, and we choose `Λf+1`.
1358
1359 D[n-f-compat-3]
1360 Since F_(Λf+1) is defined by recursion and we actually have a concrete input
1361 `Λf+1` for that recursive function, it can be computed. 
1362 Anyway, using the `nnormalize`
1363 tactic would reduce too much (both the `+1` and the `Λf` steps would be performed);
1364 we thus explicitly give a convertible type for that hypothesis, corresponding 
1365 the computation of the `+1` step, plus the unfolding the definition of
1366 the intersection.
1367
1368 D[n-f-compat-4]
1369 We are interested in the right hand side of `aLf`, an in particular to
1370 its intance where the generic index in `𝐈 a` is `i`.
1371
1372 D[n-f-compat-5]
1373 We then eliminate the existential, obtaining `j` and its property `Hj`. We provide
1374 the same witness 
1375
1376 D[n-f-compat-6]
1377 What is left to prove is exactly the `co_ord_subset` lemma we factored out
1378 of the main proof.
1379
1380 D*)
1381
1382 (*D
1383
1384 The proof that `⋉(F)` is maximal is exactly the dual one of the
1385 minimality of `◃(U)`. Thus the main problem is to obtain `G ⊆ F⎽o`
1386 before doing the induction over `o`.
1387
1388 D*)
1389 ntheorem max_new_fished: 
1390   ∀A:nAx.∀G:Ω^A.∀F:Ω^A.G ⊆ F → (∀a.a ∈ G → ∀i.𝐈𝐦[𝐝 a i] ≬ G) → G ⊆ ⋉F.
1391 #A; #G; #F; #GF; #H; #b; #HbG; #o; 
1392 ngeneralize in match HbG; ngeneralize in match b;
1393 nchange with (G ⊆ F⎽o);
1394 nelim o;
1395 ##[ napply GF;
1396 ##| #p; #IH; napply (subseteq_intersection_r … IH);
1397     #x; #Hx; #i; ncases (H … Hx i); #c; *; *; #d; #Ed; #cG;
1398     @d; napply IH;                                 (** screenshot "n-f-max-1". *)
1399     nrewrite < Ed; napply cG;    
1400 ##| #a; #i; #f; #Hf; nchange with (G ⊆ { y | ∀x. y ∈ F⎽(f x) }); 
1401     #b; #Hb; #d; napply (Hf d); napply Hb;
1402 ##]
1403 nqed.
1404
1405
1406 (*D
1407
1408 D[n-f-max-1]
1409 Note that here the right hand side of `∈` is `G` and not `F⎽p` as
1410 in the dual proof. If `S` was declare to be a setoid, to finish this proof
1411 would be enough to assume `G` extensional, and no proof of the
1412 extensionality of `F⎽p` is required. 
1413
1414 <div id="appendix" class="anchor"></div>
1415 Appendix: tactics explanation
1416 -----------------------------
1417
1418 In this appendix we try to give a description of tactics
1419 in terms of sequent calculus rules annotated with proofs.
1420 The `:` separator has to be read as _is a proof of_, in the spirit
1421 of the Curry-Howard isomorphism.
1422
1423                   Γ ⊢  f  :  A_1 → … → A_n → B     Γ ⊢ ?_i  :  A_i 
1424     napply f;    ⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼
1425                            Γ ⊢ (f ?_1 … ?_n )  :  B
1426  
1427                    Γ ⊢  ?  :  F → B       Γ ⊢ f  :  F 
1428     nlapply f;    ⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼
1429                              Γ ⊢ (? f)  :  B
1430
1431
1432                  Γ; x : T  ⊢ ?  :  P(x) 
1433     #x;      ⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼
1434                 Γ ⊢ λx:T.?  :  ∀x:T.P(x)
1435
1436                        
1437                        Γ ⊢ ?_i  :  args_i → P(k_i args_i)          
1438     ncases x;   ⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼
1439                 Γ ⊢ match x with [ k1 args1 ⇒ ?_1 | … | kn argsn ⇒ ?_n ]  :  P(x)                    
1440
1441
1442                       Γ ⊢ ?i  :  ∀t. P(t) → P(k_i … t …)          
1443     nelim x;   ⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼
1444                    Γ ⊢ (T_rect_CProp0 ?_1 … ?_n)  :  P(x)                    
1445
1446 Where `T_rect_CProp0` is the induction principle for the 
1447 inductive type `T`.
1448
1449
1450                           Γ ⊢ ?  :  Q     Q ≡ P          
1451     nchange with Q;   ⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼
1452                           Γ ⊢ ?  :  P                    
1453
1454 Where the equivalence relation between types `≡` keeps into account
1455 β-reduction, δ-reduction (definition unfolding), ζ-reduction (local
1456 definition unfolding), ι-reduction (pattern matching simplification),
1457 μ-reduction (recursive function computation) and ν-reduction (co-fixpoint
1458 computation).
1459
1460
1461                                Γ; H : Q; Δ ⊢ ?  :  G     Q ≡ P          
1462     nchange in H with Q; ⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼
1463                                Γ; H : P; Δ ⊢ ?  :  G                    
1464
1465
1466                                Γ; H : Q; Δ ⊢ ?  :  G     P →* Q           
1467     nnormalize in H; ⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼
1468                                Γ; H : P; Δ ⊢ ?  :  G                    
1469
1470 Where `Q` is the normal form of `P` considering βδζιμν-reduction steps.
1471
1472
1473                        Γ ⊢ ?  :  Q     P →* Q          
1474     nnormalize; ⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼
1475                        Γ ⊢ ?  :  P                    
1476
1477
1478                     Γ ⊢ ?_2  :  T → G    Γ ⊢ ?_1  :  T
1479     ncut T;   ⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼
1480                                Γ ⊢ (?_2 ?_1)  :  G                    
1481
1482
1483                                 Γ ⊢ ?  :  ∀x.P(x)
1484     ngeneralize in match t; ⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼
1485                                 Γ ⊢ (? t)  :  P(t)
1486                                 
1487 D*)
1488
1489
1490 (*D
1491
1492 <date>
1493 Last updated: $Date$
1494 </date>
1495
1496 [1]: http://upsilon.cc/~zack/research/publications/notation.pdf 
1497 [2]: http://matita.cs.unibo.it
1498 [3]: http://www.cs.unibo.it/~tassi/smallcc.pdf
1499 [4]: http://www.inria.fr/rrrt/rr-0530.html
1500
1501 D*)