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