]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/nlibrary/topology/igft.ma
...
[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 impedicative 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 occurr 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` (Leibnitz 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 lable: 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 function case 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 types.
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` of `G` 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.…`. Coercions are also hidden by the system
214 when it displays a term.
215
216 In this particular case, the coercion `S` allows to write
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. *)
234 (* ncheck C. *)
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 some sort of type inference, thus writing
243 `I ? a` is enough: since the second argument of `I` is typed by the 
244 first one, the first one can be inferred just computing the type of `a`.
245
246 D*) 
247
248 (* ncheck (∀A:Ax.∀a:A.I ? a). *)
249
250 (*D
251
252 This is still not completely satisfactory, since you have always type 
253 `?`; to fix this minor issue we have to introduce the notational
254 support built in Matita.
255
256 Notation for I and C
257 --------------------
258
259 Matita is quipped with a quite complex notational support,
260 allowing the user to define and use mathematical notations 
261 ([From Notation to Semantics: There and Back Again][1]). 
262
263 Since notations are usually ambiguous (e.g. the frequent overloading of 
264 symbols) Matita distinguishes between the term level, the 
265 content level, and the presentation level, allowing multiple 
266 mappings between the content and the term level. 
267
268 The mapping between the presentation level (i.e. what is typed on the 
269 keyboard and what is displayed in the sequent window) and the content
270 level is defined with the `notation` command. When followed by
271 `>`, it defines an input (only) notation.   
272
273 D*)
274
275 notation > "𝐈 term 90 a" non associative with precedence 70 for @{ 'I $a }.
276 notation > "𝐂 term 90 a term 90 i" non associative with precedence 70 for @{ 'C $a $i }.
277
278 (*D
279
280 The first notation defines the writing `𝐈 a` where `a` is a generic
281 term of precedence 90, the maximum one. This high precedence forces
282 parentheses around any term of a lower precedence. For example `𝐈 x`
283 would be accepted, since identifiers have precedence 90, but
284 `𝐈 f x` would be interpreted as `(𝐈 f) x`. In the latter case, parentheses
285 have to be put around `f x`, thus the accepted writing would be `𝐈 (f x)`.
286
287 To obtain the `𝐈` is enough to type `I` and then cycle between its
288 similar symbols with ALT-L. The same for `𝐂`. Notations cannot use
289 regular letters or the round parentheses, thus their variants (like the 
290 bold ones) have to be used.
291
292 The first notation associates `𝐈 a` with `'I $a` where `'I` is a 
293 new content element to which a term `$a` is passed.
294
295 Content elements have to be interpreted, and possibly multiple, 
296 incompatible, interpretations can be defined.
297
298 D*)
299
300 interpretation "I" 'I a = (I ? a).
301 interpretation "C" 'C a i = (C ? a i).
302
303 (*D
304
305 The `interpretation` command allows to define the mapping between
306 the content level and the terms level. Here we associate the `I` and
307 `C` projections of the Axiom set record, where the Axiom set is an implicit 
308 argument `?` to be inferred by the system.
309
310 Interpretation are bi-directional, thus when displaying a term like 
311 `C _ a i`, the system looks for a presentation for the content element
312 `'C a i`. 
313
314 D*)
315
316 notation < "𝐈  \sub( ❨a❩ )" non associative with precedence 70 for @{ 'I $a }.
317 notation < "𝐂 \sub( ❨a,\emsp i❩ )" non associative with precedence 70 for @{ 'C $a $i }.
318
319 (*D
320
321 For output purposes we can define more complex notations, for example
322 we can put bold parentheses around the arguments of `𝐈` and `𝐂`, decreasing
323 the size of the arguments and lowering their baseline (i.e. putting them
324 as subscript), separating them with a comma followed by a little space.
325
326 The first (technical) definition
327 --------------------------------
328
329 Before defining the cover relation as an inductive predicate, one
330 has to notice that the infinity rule uses, in its hypotheses, the 
331 cover relation between two subsets, while the inductive predicate 
332 we are going to define relates an element and a subset.
333
334 An option would be to unfold the definition of cover between subsets,
335 but we prefer to define the abstract notion of cover between subsets
336 (so that we can attach a (ambiguous) notation to it).
337
338 Anyway, to ease the understanding of the definition of the cover relation 
339 between subsets, we first define the inductive predicate unfolding the 
340 definition, and we later refine it with.
341
342 D*)
343
344 ninductive xcover (A : Ax) (U : Ω^A) : A → CProp[0] ≝ 
345 | xcreflexivity : ∀a:A. a ∈ U → xcover A U a
346 | xcinfinity    : ∀a:A.∀i:𝐈 a. (∀y.y ∈ 𝐂 a i → xcover A U y) → xcover A U a.
347
348 (*D
349
350 We defined the xcover (x will be removed in the final version of the 
351 definition) as an inductive predicate. The arity of the inductive
352 predicate has to be carefully analyzed:
353
354 >  (A : Ax) (U : Ω^A) : A → CProp[0]
355
356 The syntax separates with `:` abstractions that are fixed for every
357 constructor (introduction rule) and abstractions that can change. In that 
358 case the parameter `U` is abstracted once and forall in front of every 
359 constructor, and every occurrence of the inductive predicate is applied to
360 `U` in a consistent way. Arguments abstracted on the right of `:` are not
361 constant, for example the xcinfinity constructor introduces `a ◃ U`,
362 but under the assumption that (for every y) `y ◃ U`. In that rule, the left
363 had side of the predicate changes, thus it has to be abstracted (in the arity
364 of the inductive predicate) on the right of `:`.
365
366 D*)
367
368 (* ncheck xcreflexivity. *)
369
370 (*D
371
372 We want now to abstract out `(∀y.y ∈ 𝐂 a i → xcover A U y)` and define
373 a notion `cover_set` to which a notation `𝐂 a i ◃ U` can be attached.
374
375 This notion has to be abstracted over the cover relation (whose
376 type is the arity of the inductive `xcover` predicate just defined).
377
378 Then it has to be abstracted over the arguments of that cover relation,
379 i.e. the axiom set and the set U, and the subset (in that case `𝐂 a i`)
380 sitting on the left hand side of `◃`. 
381
382 D*)
383
384 ndefinition cover_set : 
385   ∀cover: ∀A:Ax.Ω^A → A → CProp[0]. ∀A:Ax.∀C,U:Ω^A. CProp[0] 
386 ≝ 
387   λcover.                           λA,    C,U.     ∀y.y ∈ C → cover A U y.
388
389 (*D
390
391 The `ndefinition` command takes a name, a type and body (of that type).
392 The type can be omitted, and in that case it is inferred by the system.
393 If the type is given, the system uses it to infer implicit arguments
394 of the body. In that case all types are left implicit in the body.
395
396 We now define the notation `a ◃ b`. Here the keywork `hvbox`
397 and `break` tell the system how to wrap text when it does not
398 fit the screen (they can be safely ignore for the scope of
399 this tutorial). We also add an interpretation for that notation, 
400 where the (abstracted) cover relation is implicit. The system
401 will not be able to infer it from the other arguments `C` and `U`
402 and will thus prompt the user for it. This is also why we named this 
403 interpretation `covers set temp`: we will later define another 
404 interpretation in which the cover relation is the one we are going to 
405 define.
406
407 D*)
408
409 notation "hvbox(a break ◃ b)" non associative with precedence 45
410 for @{ 'covers $a $b }.
411
412 interpretation "covers set temp" 'covers C U = (cover_set ?? C U).
413
414 (*D
415
416 The cover relation
417 ------------------
418
419 We can now define the cover relation using the `◃` notation for 
420 the premise of infinity. 
421
422 D*)
423
424 ninductive cover (A : Ax) (U : Ω^A) : A → CProp[0] ≝ 
425 | creflexivity : ∀a. a ∈ U → cover ? U a
426 | cinfinity    : ∀a. ∀i. 𝐂 a i ◃ U → cover ? U a.
427 (** screenshot "cover". *) 
428 napply cover;
429 nqed.
430
431 (*D
432
433 Note that the system accepts the definition
434 but prompts the user for the relation the `cover_set` notion is
435 abstracted on.
436
437
438
439 The horizontal line separates the hypotheses from the conclusion.
440 The `napply cover` command tells the system that the relation
441 it is looking for is exactly our first context entry (i.e. the inductive
442 predicate we are defining, up to α-conversion); while the `nqed` command
443 ends a definition or proof.
444
445 We can now define the interpretation for the cover relation between an
446 element and a subset fist, then between two subsets (but this time
447 we fixed the relation `cover_set` is abstracted on).
448
449 D*)
450
451 interpretation "covers" 'covers a U = (cover ? U a).
452 interpretation "covers set" 'covers a U = (cover_set cover ? a U).
453
454 (*D
455
456 We will proceed similarly for the fish relation, but before going
457 on it is better to give a short introduction to the proof mode of Matita.
458 We define again the `cover_set` term, but this time we will build
459 its body interactively. In the λ-calculus Matita is based on, CIC, proofs
460 and terms share the same syntax, and it is thus possible to use the
461 commands devoted to build proof term to build regular definitions.
462 A tentative semantics for the proof mode commands (called tactics)
463 in terms of sequent calculus rules are given in the
464 <a href="#appendix">appendix</a>.
465
466 D*)
467
468 ndefinition xcover_set : 
469   ∀c: ∀A:Ax.Ω^A → A → CProp[0]. ∀A:Ax.∀C,U:Ω^A. CProp[0]. 
470                          (** screenshot "xcover-set-1". *)
471 #cover; #A; #C; #U;      (** screenshot "xcover-set-2". *) 
472 napply (∀y:A.y ∈ C → ?); (** screenshot "xcover-set-3". *)
473 napply cover;            (** screenshot "xcover-set-4". *)
474 ##[ napply A;
475 ##| napply U;
476 ##| napply y;
477 ##]
478 nqed.
479
480 (*D[xcover-set-1]
481 The system asks for a proof of the full statement, in an empty context.
482
483 The `#` command is the ∀-introduction rule, it gives a name to an 
484 assumption putting it in the context, and generates a λ-abstraction
485 in the proof term.
486
487 D[xcover-set-2]
488 We have now to provide a proposition, and we exhibit it. We left
489 a part of it implicit; since the system cannot infer it it will
490 ask it later. Note that the type of `∀y:A.y ∈ C → ?` is a proposition
491 whenever `?` is.
492
493 D[xcover-set-3]
494 The proposition we want to provide is an application of the
495 cover relation we have abstracted in the context. The command
496 `napply`, if the given term has not the expected type (in that
497 case it is a product versus a proposition) it applies it to as many 
498 implicit arguments as necessary (in that case `? ? ?`).
499
500 D[xcover-set-4]
501 The system will now ask in turn the three implicit arguments 
502 passed to cover. The syntax `##[` allows to start a branching
503 to tackle every sub proof individually, otherwise every command
504 is applied to every subrpoof. The command `##|` switches to the next
505 subproof and `##]` ends the branching.  
506 D*)
507
508 (*D
509
510 The fish relation
511 -----------------
512
513 The definition of fish works exactly the same way as for cover, except 
514 that it is defined as a coinductive proposition.
515 D*)
516
517 ndefinition fish_set ≝ λf:∀A:Ax.Ω^A → A → CProp[0].
518  λA,U,V.
519   ∃a.a ∈ V ∧ f A U a.
520
521 (* a \ltimes b *)
522 notation "hvbox(a break ⋉ b)" non associative with precedence 45
523 for @{ 'fish $a $b }. 
524
525 interpretation "fish set temp" 'fish A U = (fish_set ?? U A).
526
527 ncoinductive fish (A : Ax) (F : Ω^A) : A → CProp[0] ≝ 
528 | cfish : ∀a. a ∈ F → (∀i:𝐈 a .𝐂  a i ⋉ F) → fish A F a.
529 napply fish;
530 nqed.
531
532 interpretation "fish set" 'fish A U = (fish_set fish ? U A).
533 interpretation "fish" 'fish a U = (fish ? U a).
534
535 (*D
536
537 Introction rule for fish
538 ------------------------
539
540 Matita is able to generate elimination rules for inductive types,
541 but not introduction rules for the coinductive case. 
542
543 D*)
544
545 (* ncheck cover_rect_CProp0. *) 
546
547 (*D
548
549 We thus have to define the introduction rule for fish by corecursion.
550 Here we again use the proof mode of Matita to exhibit the body of the
551 corecursive function.
552
553 D*)
554
555 nlet corec fish_rec (A:Ax) (U: Ω^A)
556  (P: Ω^A) (H1: P ⊆ U)
557   (H2: ∀a:A. a ∈ P → ∀j: 𝐈 a. 𝐂 a j ≬ P): ∀a:A. ∀p: a ∈ P. a ⋉ U ≝ ?.
558                                        (** screenshot "def-fish-rec-1".   *)
559 #a; #p; napply cfish;                  (** screenshot "def-fish-rec-2".   *)
560 ##[ nchange in H1 with (∀b.b∈P → b∈U); (** screenshot "def-fish-rec-2-1". *) 
561     napply H1;                         (** screenshot "def-fish-rec-3".   *) 
562     nassumption;
563 ##| #i; ncases (H2 a p i);             (** screenshot "def-fish-rec-5".   *) 
564     #x; *; #xC; #xP;                   (** screenshot "def-fish-rec-5-1". *) 
565     @;                                 (** screenshot "def-fish-rec-6".   *)
566     ##[ napply x
567     ##| @;                             (** screenshot "def-fish-rec-7".   *)
568         ##[ napply xC; 
569         ##| napply (fish_rec ? U P);   (** screenshot "def-fish-rec-9".   *)
570             nassumption;
571         ##]
572     ##]
573 ##]
574 nqed.
575
576 (*D
577 D[def-fish-rec-1]
578 Note the first item of the context, it is the corecursive function we are 
579 defining. This item allows to perform the recursive call, but we will be
580 allowed to do such call only after having generated a constructor of
581 the fish coinductive type.
582
583 We introduce `a` and `p`, and then return the fish constructor `cfish`.
584 Since the constructor accepts two arguments, the system asks for them.
585
586 D[def-fish-rec-2]
587 The first one is a proof that `a ∈ U`. This can be proved using `H1` and `p`.
588 With the `nchange` tactic we change `H1` into an equivalent form (this step
589 can be skipped, since the system would be able to unfold the definition
590 of inclusion by itself)
591
592 D[def-fish-rec-2-1]
593 It is now clear that `H1` can be applied. Again `napply` adds two 
594 implicit arguments to `H1 ? ?`, obtaining a proof of `? ∈ U` given a proof
595 that `? ∈ P`. Thanks to unification, the system understands that `?` is actually
596 `a`, and it asks a proof that `a ∈ P`.
597
598 D[def-fish-rec-3]
599 The `nassumption` tactic looks for the required proof in the context, and in
600 that cases finds it in the last context position. 
601
602 We move now to the second branch of the proof, corresponding to the second
603 argument of the `cfish` constructor.
604
605 We introduce `i` and then we destruct `H2 a p i`, that being a proof
606 of an overlap predicate, give as an element and a proof that it is 
607 both in `𝐂 a i` and `P`.
608
609 D[def-fish-rec-5]
610 We then introduce `x`, break the conjunction (the `*;` command is the
611 equivalent of `ncases` but operates on the first hypothesis that can
612 be introduced. We then introduce the two sides of the conjunction.
613
614 D[def-fish-rec-5-1]
615 The goal is now the existence of an a point in `𝐂 a i` fished by `U`.
616 We thus need to use the introduction rule for the existential quantifier.
617 In CIC it is a defined notion, that is an inductive type with just
618 one constructor (one introduction rule) holding the witness and the proof
619 that the witness satisfies a proposition.
620
621 > ncheck Ex.
622
623 Instead of trying to remember the name of the constructor, that should
624 be used as the argument of `napply`, we can ask the system to find by
625 itself the constructor name and apply it with the `@` tactic. 
626 Note that some inductive predicates, like the disjunction, have multiple
627 introduction rules, and thus `@` can be followed by a number identifying
628 the constructor.
629
630 D[def-fish-rec-6]
631 After choosing `x` as the witness, we have to prove a conjunction,
632 and we again apply the introduction rule for the inductively defined
633 predicate `∧`.
634
635 D[def-fish-rec-7]
636 The left hand side of the conjunction is trivial to prove, since it 
637 is already in the context. The right hand side needs to perform
638 the co-recursive call.
639
640 D[def-fish-rec-9]
641 The co-recursive call needs some arguments, but all of them live
642 in the context. Instead of explicitly mention them, we use the
643 `nassumption` tactic, that simply tries to apply every context item.
644
645 D*)
646
647 (*D
648
649 Subset of covered/fished points
650 -------------------------------
651
652 We now have to define the subset of `S` of points covered by `U`.
653 We also define a prefix notation for it. Remember that the precedence
654 of the prefix form of a symbol has to be lower than the precedence 
655 of its infix form.
656
657 D*)
658
659 ndefinition coverage : ∀A:Ax.∀U:Ω^A.Ω^A ≝ λA,U.{ a | a ◃ U }.
660
661 notation "◃U" non associative with precedence 55 for @{ 'coverage $U }.
662
663 interpretation "coverage cover" 'coverage U = (coverage ? U).
664
665 (*D
666
667 Here we define the equation characterizing the cover relation. 
668 In the igft.ma file we proved that `◃U` is the minimum solution for
669 such equation, the interested reader should be able to reply the proof
670 with Matita.
671
672 D*)
673
674 ndefinition cover_equation : ∀A:Ax.∀U,X:Ω^A.CProp[0] ≝  λA,U,X. 
675   ∀a.a ∈ X ↔ (a ∈ U ∨ ∃i:𝐈 a.∀y.y ∈ 𝐂 a i → y ∈ X).  
676
677 ntheorem coverage_cover_equation : ∀A,U. cover_equation A U (◃U).
678 #A; #U; #a; @; #H;
679 ##[ nelim H; #b; 
680     ##[ #bU; @1; nassumption;
681     ##| #i; #CaiU; #IH; @2; @ i; #c; #cCbi; ncases (IH ? cCbi);
682         ##[ #E; @; napply E;
683         ##| #_; napply CaiU; nassumption; ##] ##]
684 ##| ncases H; ##[ #E; @; nassumption]
685     *; #j; #Hj; @2 j; #w; #wC; napply Hj; nassumption;
686 ##]
687 nqed. 
688
689 ntheorem coverage_min_cover_equation : 
690   ∀A,U,W. cover_equation A U W → ◃U ⊆ W.
691 #A; #U; #W; #H; #a; #aU; nelim aU; #b;
692 ##[ #bU; ncases (H b); #_; #H1; napply H1; @1; nassumption;
693 ##| #i; #CbiU; #IH; ncases (H b); #_; #H1; napply H1; @2; @i; napply IH;
694 ##]
695 nqed.
696
697 (*D
698
699 We similarly define the subset of point fished by `F`, the 
700 equation characterizing `⋉F` and prove that fish is
701 the biggest solution for such equation.
702
703 D*) 
704
705 notation "⋉F" non associative with precedence 55
706 for @{ 'fished $F }.
707
708 ndefinition fished : ∀A:Ax.∀F:Ω^A.Ω^A ≝ λA,F.{ a | a ⋉ F }.
709
710 interpretation "fished fish" 'fished F = (fished ? F).
711
712 ndefinition fish_equation : ∀A:Ax.∀F,X:Ω^A.CProp[0] ≝ λA,F,X.
713   ∀a. a ∈ X ↔ a ∈ F ∧ ∀i:𝐈 a.∃y.y ∈ 𝐂 a i ∧ y ∈ X. 
714   
715 ntheorem fished_fish_equation : ∀A,F. fish_equation A F (⋉F).
716 #A; #F; #a; @; (* *; non genera outtype che lega a *) #H; ncases H;
717 ##[ #b; #bF; #H2; @ bF; #i; ncases (H2 i); #c; *; #cC; #cF; @c; @ cC;
718     napply cF;  
719 ##| #aF; #H1; @ aF; napply H1;
720 ##]
721 nqed.
722
723 ntheorem fished_max_fish_equation : ∀A,F,G. fish_equation A F G → G ⊆ ⋉F.
724 #A; #F; #G; #H; #a; #aG; napply (fish_rec … aG);
725 #b; ncases (H b); #H1; #_; #bG; ncases (H1 bG); #E1; #E2; nassumption; 
726 nqed. 
727
728 (*D
729
730 Part 2, the new set of axioms
731 -----------------------------
732
733 Since the name of objects (record included) has to unique
734 within the same script, we prefix every field name
735 in the new definition of the axiom set with `n`.
736
737 D*)
738
739 nrecord nAx : Type[2] ≝ { 
740   nS:> setoid; 
741   nI: nS → Type[0];
742   nD: ∀a:nS. nI a → Type[0];
743   nd: ∀a:nS. ∀i:nI a. nD a i → nS
744 }.
745
746 (*D
747
748 We again define a notation for the projections, making the 
749 projected record an implicit argument. Note that since we already have
750 a notation for `𝐈` we just add another interpretation for it. The
751 system, looking at the argument of `𝐈`, will be able to use
752 the correct interpretation. 
753
754 D*)
755
756 notation "𝐃 \sub ( ❨a,\emsp i❩ )" non associative with precedence 70 for @{ 'D $a $i }.
757 notation "𝐝 \sub ( ❨a,\emsp i,\emsp j❩ )" non associative with precedence 70 for @{ 'd $a $i $j}.
758
759 notation > "𝐃 term 90 a term 90 i" non associative with precedence 70 for @{ 'D $a $i }.
760 notation > "𝐝 term 90 a term 90 i term 90 j" non associative with precedence 70 for @{ 'd $a $i $j}.
761
762 interpretation "D" 'D a i = (nD ? a i).
763 interpretation "d" 'd a i j = (nd ? a i j).
764 interpretation "new I" 'I a = (nI ? a).
765
766 (*D
767
768 The paper defines the image as
769
770 > Im[d(a,i)] = { d(a,i,j) | j : D(a,i) }
771
772 but this not so formal notation poses some problems. The image is
773 often used as the left hand side of the ⊆ predicate
774
775 > Im[d(a,i)] ⊆ V
776
777 Of course this writing is interpreted by the authors as follows 
778
779 > ∀j:D(a,i). d(a,i,j) ∈ V
780
781 If we need to use the image to define 𝐂 (a subset of S) we are obliged to
782 form a subset, i.e. to place a single variable `{ here | … }`.
783
784 > Im[d(a,i)] = { y | ∃j:D(a,i). y = d(a,i,j) }
785
786 This poses no theoretical problems, since `S` is a setoid and thus equipped
787 with an equality.
788
789 Unless we difene two different images, one for stating the image is ⊆ of
790 something and another one to define 𝐂, we end up using always the latter.
791 Thus the statement `Im[d(a,i)] ⊆ V` unfolds to
792
793 > ∀x:S. ( ∃j.x = d(a,i,j) ) → x ∈ V
794
795 That up to rewriting with the equation defining `x` is what we mean. The 
796 technical problem arises when `V` is a complex construction that has to
797 be proved extensional (i.e. ∀x,y. x = y → x ∈ V → y ∈ V).
798
799 D*)
800
801 ndefinition image ≝ λA:nAx.λa:A.λi. { x | ∃j:𝐃 a i. x = 𝐝 a i j }.
802
803 notation > "𝐈𝐦  [𝐝 term 90 a term 90 i]" non associative with precedence 70 for @{ 'Im $a $i }.
804 notation "𝐈𝐦  [𝐝 \sub ( ❨a,\emsp i❩ )]" non associative with precedence 70 for @{ 'Im $a $i }.
805
806 interpretation "image" 'Im a i = (image ? a i).
807
808 (*D
809
810 Thanks to our definition of image, we ca trivially a function mapping a
811 new axiom set to an old one and viceversa. Note that in the second
812 definition, when defining 𝐝, the projection of the Σ type is inlined
813 (constructed on the fly by `*;`) while in the paper it was named `fst`.
814
815 D*)
816
817 ndefinition Ax_of_nAx : nAx → Ax.
818 #A; @ A (nI ?); #a; #i; napply (𝐈𝐦 [𝐝 a i]);
819 nqed.
820
821 ndefinition nAx_of_Ax : Ax → nAx.
822 #A; @ A (I ?);
823 ##[ #a; #i; napply (Σx:A.x ∈ 𝐂 a i);
824 ##| #a; #i; *; #x; #_; napply x;
825 ##]
826 nqed.
827
828 (*D
829
830 We then define the inductive type of ordinals, parametrized over an axiom
831 set. We also attach some notations to the constructors.
832
833 D*)
834
835 ninductive Ord (A : nAx) : Type[0] ≝ 
836  | oO : Ord A
837  | oS : Ord A → Ord A
838  | oL : ∀a:A.∀i.∀f:𝐃 a i → Ord A. Ord A.
839
840 notation "0" non associative with precedence 90 for @{ 'oO }.
841 notation "Λ term 90 f" non associative with precedence 50 for @{ 'oL $f }.
842 notation "x+1" non associative with precedence 50 for @{'oS $x }.
843
844 interpretation "ordinals Zero" 'oO = (oO ?).
845 interpretation "ordinals Lambda" 'oL f = (oL ? ? ? f).
846 interpretation "ordinals Succ" 'oS x = (oS ? x).
847
848 (*D
849
850 The dfinition of `U_x` is by recursion over the ordinal `x`. 
851 We thus define a recursive function. The `on x` directive tells
852 the system on which argument the function is (structurally) recursive.
853
854 In the `oS` case we use a local definition to name the recursive call
855 since it is used twice.
856
857 Note that Matita does not support notation in the left hand side
858 of a pattern match, and thus the names of the constructors have to 
859 be spelled out verbatim.
860
861 D*)
862
863 nlet rec famU (A : nAx) (U : Ω^A) (x : Ord A) on x : Ω^A ≝ 
864   match x with
865   [ oO ⇒ U
866   | oS y ⇒ let U_n ≝ famU A U y in U_n ∪ { x | ∃i.𝐈𝐦[𝐝 x i] ⊆ U_n} 
867   | oL a i f ⇒ { x | ∃j.x ∈ famU A U (f j) } ].
868   
869 notation < "term 90 U \sub (term 90 x)" non associative with precedence 50 for @{ 'famU $U $x }.
870 notation > "U ⎽ term 90 x" non associative with precedence 50 for @{ 'famU $U $x }.
871
872 interpretation "famU" 'famU U x = (famU ? U x).
873
874 (*D
875
876 We attach as the input notation for U_x the similar `U⎽x` where underscore,
877 that is a character valid for identifier names, has been replaced by `⎽` that is
878 not. The symbol `⎽` can act as a separator, and can be typed as an alternative
879 for `_` (i.e. pressing ALT-L after `_`). 
880
881 The notion ◃(U) has to be defined as the subset of of y 
882 belonging to U_x for some x. Moreover, we have to define the notion
883 of cover between sets again, since the one defined at the beginning
884 of the tutorial works only for the old axiom set definition.
885
886 D*)
887   
888 ndefinition ord_coverage : ∀A:nAx.∀U:Ω^A.Ω^A ≝ λA,U.{ y | ∃x:Ord A. y ∈ famU ? U x }.
889
890 ndefinition ord_cover_set ≝ λc:∀A:nAx.Ω^A → Ω^A.λA,C,U.
891   ∀y.y ∈ C → y ∈ c A U.
892
893 interpretation "coverage new cover" 'coverage U = (ord_coverage ? U).
894 interpretation "new covers set" 'covers a U = (ord_cover_set ord_coverage ? a U).
895 interpretation "new covers" 'covers a U = (mem ? (ord_coverage ? U) a).
896
897 (*D
898
899 Before proving that this cover relation validates the reflexivity and infinity
900 rules, we prove this little technical lemma that is used in the proof for the 
901 infinity rule.
902
903 D*)
904
905 nlemma ord_subset: ∀A:nAx.∀a:A.∀i,f,U.∀j:𝐃 a i. U⎽(f j) ⊆ U⎽(Λ f).
906 #A; #a; #i; #f; #U; #j; #b; #bUf; @ j; nassumption;
907 nqed.
908
909 (*D
910
911 The proof of infinity uses the following form of the Axiom of choice,
912 that cannot be prove inside Matita, since the existential quantifier
913 lives in the sort of predicative propositions while the sigma in the conclusion
914 lives in the sort of data types, and thus the former cannot be eliminated
915 to provide the second.
916
917 D*)
918
919 naxiom AC : ∀A,a,i,U.
920   (∀j:𝐃 a i.∃x:Ord A.𝐝 a i j ∈ U⎽x) → (Σf.∀j:𝐃 a i.𝐝 a i j ∈ U⎽(f j)).
921
922 (*D
923
924 In the proof of infinity, we have to rewrite under the ∈ predicate.
925 It is clearly possible to show that U⎽x is an extensional set:
926
927 > a = b → a ∈ U⎽x → b ∈ U⎽x
928
929 Anyway this proof in non trivial induction over x, that requires 𝐈 and 𝐃 to be
930 declared as morphisms. This poses to problem, but goes out of the scope of the 
931 tutorial and we thus assume it.
932
933 D*)
934
935 naxiom U_x_is_ext: ∀A:nAx.∀a,b:A.∀x.∀U. a = b → b ∈ U⎽x → a ∈ U⎽x.
936
937 (*D
938
939 The reflexivity proof is trivial, it is enough to provide the ordinal 0
940 as a witness, then ◃(U) reduces to U by definition, hence the conclusion.
941
942 D*)
943 ntheorem new_coverage_reflexive: ∀A:nAx.∀U:Ω^A.∀a. a ∈ U → a ◃ U.
944 #A; #U; #a; #H; @ (0); napply H;
945 nqed.
946
947 (*D
948
949 We now proceed with the proof of the infinity rule.
950
951 D*)
952
953 alias symbol "covers" = "new covers set".
954 alias symbol "covers" = "new covers".
955 alias symbol "covers" = "new covers set".
956 alias symbol "covers" = "new covers".
957 alias symbol "covers" = "new covers set".
958 alias symbol "covers" = "new covers".
959 alias symbol "covers" = "new covers set".
960 alias symbol "covers" = "new covers".
961 ntheorem new_coverage_infinity:
962   ∀A:nAx.∀U:Ω^A.∀a:A. (∃i:𝐈 a. 𝐈𝐦[𝐝 a i] ◃ U) → a ◃ U.
963 #A; #U; #a;                                   (** screenshot "n-cov-inf-1". *)  
964 *; #i; #H; nnormalize in H;                   (** screenshot "n-cov-inf-2". *)
965 ncut (∀y:𝐃 a i.∃x:Ord A.𝐝 a i y ∈ U⎽x); ##[    (** screenshot "n-cov-inf-3". *)
966   #z; napply H; @ z; napply #; ##] #H';       (** screenshot "n-cov-inf-4". *)
967 ncases (AC … H'); #f; #Hf;                    (** screenshot "n-cov-inf-5". *)
968 ncut (∀j.𝐝 a i j ∈ U⎽(Λ f));
969   ##[ #j; napply (ord_subset … f … (Hf j));##] #Hf';(** screenshot "n-cov-inf-6". *)
970 @ (Λ f+1);                                    (** screenshot "n-cov-inf-7". *)
971 @2;                                           (** screenshot "n-cov-inf-8". *) 
972 @i; #x; *; #d; #Hd;                           (** screenshot "n-cov-inf-9". *)  
973 napply (U_x_is_ext … Hd); napply Hf';
974 nqed.
975
976 (*D
977 D[n-cov-inf-1]
978 We eliminate the existential, obtaining an `i` and a proof that the 
979 image of d(a,i) is covered by U. The `nnormalize` tactic computes the normal
980 form of `H`, thus expands the definition of cover between sets.
981
982 D[n-cov-inf-2]
983 The paper proof considers `H` implicitly substitutes the equation assumed
984 by `H` in its conclusion. In Matita this step is not completely trivia.
985 We thus assert (`ncut`) the nicer form of `H`.
986
987 D[n-cov-inf-3]
988 After introducing `z`, `H` can be applied (choosing `𝐝 a i z` as `y`). 
989 What is the left to prove is that `∃j: 𝐃 a j. 𝐝 a i z = 𝐝 a i j`, that 
990 becomes trivial is `j` is chosen to be `z`. In the command `napply #`,
991 the `#` is a standard notation for the reflexivity property of the equality. 
992
993 D[n-cov-inf-4]
994 Under `H'` the axiom of choice `AC` can be eliminated, obtaining the `f` and 
995 its property. Note that the axiom `AC` was abstracted over `A,a,i,U` before
996 assuming `(∀j:𝐃 a i.∃x:Ord A.𝐝 a i j ∈ U⎽x)`. Thus the term that can be eliminated
997 is `AC ???? H'` where the system is able to infer every `?`. Matita provides
998 a facility to specify a number of `?` in a compact way, i.e. `…`. The system
999 expand `…` first to zero, then one, then two, three and finally four question 
1000 marks, "guessing" how may of them are needed. 
1001
1002 D[n-cov-inf-5]
1003 The paper proof does now a forward reasoning step, deriving (by the ord_subset 
1004 lemma we proved above) `Hf'` i.e. 𝐝 a i j ∈ U⎽(Λf).
1005
1006 D[n-cov-inf-6]
1007 To prove that `a◃U` we have to exhibit the ordinal x such that `a ∈ U⎽x`.
1008
1009 D[n-cov-inf-7]
1010 The definition of `U⎽(…+1)` expands to the union of two sets, and proving
1011 that `a ∈ X ∪ Y` is defined as proving that `a` is in `X` or `Y`. Applying
1012 the second constructor `@2;` of the disjunction, we are left to prove that `a` 
1013 belongs to the right hand side.
1014
1015 D[n-cov-inf-8]
1016 We thus provide `i`, introduce the element being in the image and we are
1017 left to prove that it belongs to `U_(Λf)`. In the meanwhile, since belonging 
1018 to the image means that there exists an object in the domain… we eliminate the
1019 existential, obtaining `d` (of type `𝐃 a i`) and the equation defining `x`.  
1020
1021 D[n-cov-inf-9]
1022 We just need to use the equational definition of `x` to obtain a conclusion
1023 that can be proved with `Hf'`. We assumed that `U⎽x` is extensional for
1024 every `x`, thus we are allowed to use `Hd` and close the proof.
1025
1026 D*)
1027
1028 (*D
1029
1030 The next proof is that ◃(U) is mininal. The hardest part of the proof
1031 is to prepare the goal for the induction. The desiderata is to prove
1032 `U⎽o ⊆ V` by induction on `o`, but the conclusion of the lemma is,
1033 unfolding all definitions:
1034
1035 > ∀x. x ∈ { y | ∃o:Ord A.y ∈ U⎽o } → x ∈ V
1036
1037 D*)
1038
1039 nlemma new_coverage_min :  
1040   ∀A:nAx.∀U:Ω^A.∀V.U ⊆ V → (∀a:A.∀i.𝐈𝐦[𝐝 a i] ⊆ V → a ∈ V) → ◃U ⊆ V.
1041 #A; #U; #V; #HUV; #Im;#b;                       (** screenshot "n-cov-min-2". *)
1042 *; #o;                                          (** screenshot "n-cov-min-3". *)
1043 ngeneralize in match b; nchange with (U⎽o ⊆ V); (** screenshot "n-cov-min-4". *)
1044 nelim o;                                        (** screenshot "n-cov-min-5". *) 
1045 ##[ #b; #bU0; napply HUV; napply bU0;
1046 ##| #p; #IH; napply subseteq_union_l; ##[ nassumption; ##]
1047     #x; *; #i; #H; napply (Im ? i); napply (subseteq_trans … IH); napply H;
1048 ##| #a; #i; #f; #IH; #x; *; #d; napply IH; ##]
1049 nqed.
1050
1051 (*D
1052 D[n-cov-min-2]
1053 After all the introductions, event the element hidden in the ⊆ definition,
1054 we have to eliminate the existential quantifier, obtaining the ordinal `o`
1055
1056 D[n-cov-min-3]
1057 What is left is almost right, but the element `b` is already in the
1058 context. We thus generalize every occurrence of `b` in 
1059 the current goal, obtaining `∀c.c ∈ U⎽o → c ∈ V` that is `U⎽o ⊆ V`.
1060
1061 D[n-cov-min-4]
1062 We then proceed by induction on `o` obtaining the following goals
1063
1064 D[n-cov-min-5]
1065 All of them can be proved using simple set theoretic arguments,
1066 the induction hypothesis and the assumption `Im`.
1067
1068 D*)
1069
1070
1071 (*D
1072
1073 The notion `F⎽x` is again defined by recursion over the ordinal `x`.
1074
1075 D*)
1076
1077 nlet rec famF (A: nAx) (F : Ω^A) (x : Ord A) on x : Ω^A ≝ 
1078   match x with
1079   [ oO ⇒ F
1080   | oS o ⇒ let F_o ≝ famF A F o in F_o ∩ { x | ∀i:𝐈 x.∃j:𝐃 x i.𝐝 x i j ∈ F_o } 
1081   | oL a i f ⇒ { x | ∀j:𝐃 a i.x ∈ famF A F (f j) }
1082   ].
1083
1084 interpretation "famF" 'famU U x = (famF ? U x).
1085
1086 ndefinition ord_fished : ∀A:nAx.∀F:Ω^A.Ω^A ≝ λA,F.{ y | ∀x:Ord A. y ∈ F⎽x }.
1087
1088 interpretation "fished new fish" 'fished U = (ord_fished ? U).
1089 interpretation "new fish" 'fish a U = (mem ? (ord_fished ? U) a).
1090
1091 (*D
1092
1093 The proof of compatibility uses this little result, that we 
1094 proved outside the mail proof. 
1095
1096 D*)
1097 nlemma co_ord_subset: ∀A:nAx.∀F:Ω^A.∀a,i.∀f:𝐃 a i → Ord A.∀j. F⎽(Λ f) ⊆ F⎽(f j).
1098 #A; #F; #a; #i; #f; #j; #x; #H; napply H;
1099 nqed.
1100
1101 (*D
1102
1103 We assume the dual of the axiom of choice, as in the paper proof.
1104
1105 D*)
1106 naxiom AC_dual: ∀A:nAx.∀a:A.∀i,F. 
1107  (∀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.
1108
1109 (*D
1110
1111 Proving the anti-reflexivity property is simple, since the
1112 assumption `a ⋉ F` states that for every ordinal `x` (and thus also 0)
1113 `a ∈ F⎽x`. If `x` is choosen to be `0`, we obtain the thesis.
1114
1115 D*)
1116 ntheorem new_fish_antirefl: ∀A:nAx.∀F:Ω^A.∀a. a ⋉ F → a ∈ F.
1117 #A; #F; #a; #H; nlapply (H 0); #aFo; napply aFo;
1118 nqed.
1119
1120 (*D
1121
1122 We now prove the compatibility property for the new fish relation.
1123
1124 D*)
1125 ntheorem new_fish_compatible: 
1126  ∀A:nAx.∀F:Ω^A.∀a. a ⋉ F → ∀i:𝐈 a.∃j:𝐃 a i.𝐝 a i j ⋉ F.
1127 #A; #F; #a; #aF; #i; nnormalize;               (** screenshot "n-f-compat-1". *)
1128 napply AC_dual; #f;                            (** screenshot "n-f-compat-2". *)
1129 nlapply (aF (Λf+1)); #aLf;                     (** screenshot "n-f-compat-3". *)
1130 nchange in aLf with 
1131   (a ∈ F⎽(Λ f) ∧ ∀i:𝐈 a.∃j:𝐃 a i.𝐝 a i j ∈ F⎽(Λ f)); (** screenshot "n-f-compat-4". *)
1132 ncases aLf; #_; #H; nlapply (H i);                 (** screenshot "n-f-compat-5". *)
1133 *; #j; #Hj; @j;                                    (** screenshot "n-f-compat-6". *)
1134 napply (co_ord_subset … Hj);
1135 nqed.
1136
1137 (*D
1138 D[n-f-compat-1]
1139 After reducing to normal form the goal, we obseve it is exactly the conlusion of
1140 the dual axiom of choice we just assumed. We thus apply it ad introduce the 
1141 fcuntion `f`.
1142
1143 D[n-f-compat-2]
1144 The hypothesis `aF` states that `a⋉F⎽x` for every `x`, and we choose `Λf+1`.
1145
1146 D[n-f-compat-3]
1147 Since F_(Λf+1) is defined by recursion and we actually have a concrete input
1148 `Λf+1` for that recursive function, it can compute. Anyway, using the `nnormalize`
1149 tactic would reduce too much (both the `+1` and the `Λf` steps would be prformed);
1150 we thus explicitly give a convertible type for that hypothesis, corresponding 
1151 the computation of the `+1` step, plus the unfolding of `∩`.
1152
1153 D[n-f-compat-4]
1154 We are interested in the right hand side of `aLf`, an in particular to
1155 its intance where the generic index in `𝐈 a` is `i`.
1156
1157 D[n-f-compat-5]
1158 We then eliminate the existential, obtaining `j` and its property `Hj`. We provide
1159 the same witness 
1160
1161 D[n-f-compat-6]
1162 What is left to prove is exactly the `co_ord_subset` lemma we factored out
1163 of the main proof.
1164
1165 D*)
1166
1167 (*D
1168
1169 The proof that `⋉(F)` is maximal is exactly the dual one of the
1170 minimality of `◃(U)`. Thus the main problem is to obtain `G ⊆ F⎽o`
1171 before doing the induction over `o`.
1172
1173 Note that `G` is assumed to be of type `𝛀^A`, that means an extensional
1174 subset of `S`, while `Ω^A` means just a subset (note that the former is bold). 
1175
1176 D*)
1177 ntheorem max_new_fished: 
1178   ∀A:nAx.∀G:𝛀^A.∀F:Ω^A.G ⊆ F → (∀a.a ∈ G → ∀i.𝐈𝐦[𝐝 a i] ≬ G) → G ⊆ ⋉F.
1179 #A; #G; #F; #GF; #H; #b; #HbG; #o; 
1180 ngeneralize in match HbG; ngeneralize in match b;
1181 nchange with (G ⊆ F⎽o);
1182 nelim o;
1183 ##[ napply GF;
1184 ##| #p; #IH; napply (subseteq_intersection_r … IH);
1185     #x; #Hx; #i; ncases (H … Hx i); #c; *; *; #d; #Ed; #cG;
1186     @d; napply IH;                                (** screenshot "n-f-max-1". *)
1187     alias symbol "prop2" = "prop21".
1188     napply (. Ed^-1‡#); napply cG;    
1189 ##| #a; #i; #f; #Hf; nchange with (G ⊆ { y | ∀x. y ∈ F⎽(f x) }); 
1190     #b; #Hb; #d; napply (Hf d); napply Hb;
1191 ##]
1192 nqed.
1193
1194 (*D
1195 D[n-f-max-1]
1196 Here the situacion look really similar to the one of the dual proof where 
1197 we had to apply the assumption `U_x_is_ext`, but here the set is just `G`
1198 not `F_x`. Since we assumed `G` to be extensional we can employ the facilities
1199 Matita provides to perform rewriting in the general setting of setoids.
1200
1201 The lemma `.` simply triggers the mechanism, and the given argument has to
1202 mimick the context under which the rewriting has to happen. In that case
1203 we want to rewrite to the left of the binary morphism `∈`. The infix notation
1204 to represent the context of a binary morphism is `‡`. The right hand side 
1205 has to be left untouched, and the identity rewriting step is represented with 
1206 `#` (actually a reflexivity proof for the subterm identified by the context). 
1207
1208 We want to rewrite the left hand side using `Ed` right-to-left (the default
1209 is left-to-right). We thus write `Ed^-1`, that is a proof that `𝐝 x i d = c`. 
1210
1211 The complete command is `napply (. Ed^-1‡#)` that has to be read like:
1212
1213 > perform some rewritings under a binary morphism, 
1214 > on the right do nothing, 
1215 > on the left rewrite with Ed right-to-left.
1216
1217 After the rewriting step the goal is exactly the `cG` assumption.
1218
1219 D*)
1220
1221
1222 (*D
1223 <div id="appendix" class="anchor"></div>
1224 Appendix: tactics explanation
1225 -----------------------------
1226
1227 In this appendix we try to give a description of tactics
1228 in terms of sequent calculus rules annotated with proofs.
1229 The `:` separator has to be read as _is a proof of_, in the spirit
1230 of the Curry-Howard isomorphism.
1231
1232                   Γ ⊢  f  :  A1 → … → An → B    Γ ⊢ ?1 : A1 … ?n  :  An 
1233     napply f;    ⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼
1234                            Γ ⊢ (f ?1 … ?n )  :  B
1235  
1236                    Γ ⊢  ?  :  F → B       Γ ⊢ f  :  F 
1237     nlapply f;    ⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼
1238                              Γ ⊢ (? f)  :  B
1239
1240
1241                  Γ; x : T  ⊢ ?  :  P(x) 
1242     #x;      ⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼
1243                 Γ ⊢ λx:T.?  :  ∀x:T.P(x)
1244
1245                        
1246                        Γ ⊢ ?_i  :  args_i → P(k_i args_i)          
1247     ncases x;   ⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼
1248                 Γ ⊢ match x with [ k1 args1 ⇒ ?_1 | … | kn argsn ⇒ ?_n ]  :  P(x)                    
1249
1250
1251                       Γ ⊢ ?i  :  ∀t. P(t) → P(k_i … t …)          
1252     nelim x;   ⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼
1253                    Γ ⊢ (T_rect_CProp0 ?_1 … ?_n)  :  P(x)                    
1254
1255 Where `T_rect_CProp0` is the induction principle for the 
1256 inductive type `T`.
1257
1258
1259                           Γ ⊢ ?  :  Q     Q ≡ P          
1260     nchange with Q;   ⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼
1261                           Γ ⊢ ?  :  P                    
1262
1263 Where the equivalence relation between types `≡` keeps into account
1264 β-reduction, δ-reduction (definition unfolding), ζ-reduction (local
1265 definition unfolding), ι-reduction (pattern matching simplification),
1266 μ-reduction (recursive function computation) and ν-reduction (co-fixpoint
1267 computation).
1268
1269
1270                                Γ; H : Q; Δ ⊢ ?  :  G     Q ≡ P          
1271     nchange in H with Q; ⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼
1272                                Γ; H : P; Δ ⊢ ?  :  G                    
1273
1274
1275                                Γ; H : Q; Δ ⊢ ?  :  G     P →* Q           
1276     nnormalize in H; ⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼
1277                                Γ; H : P; Δ ⊢ ?  :  G                    
1278
1279 Where `Q` is the normal form of `P` considering βδζιμν-reduction steps.
1280
1281
1282                        Γ ⊢ ?  :  Q     P →* Q          
1283     nnormalize; ⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼
1284                        Γ ⊢ ?  :  P                    
1285
1286
1287                     Γ ⊢ ?_2  :  T → G    Γ ⊢ ?_1  :  T
1288     ncut T;   ⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼
1289                                Γ ⊢ (?_2 ?_1)  :  G                    
1290
1291
1292                                 Γ ⊢ ?  :  ∀x.P(x)
1293     ngeneralize in match t; ⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼
1294                                 Γ ⊢ (? t)  :  P(t)
1295                                 
1296 D*)
1297
1298
1299 (*D
1300
1301 <date>
1302 Last updated: $Date$
1303 </date>
1304
1305 [1]: http://upsilon.cc/~zack/research/publications/notation.pdf 
1306 [2]: http://matita.cs.unibo.it
1307 [3]: http://www.cs.unibo.it/~tassi/smallcc.pdf
1308 [4]: http://www.inria.fr/rrrt/rr-0530.html
1309
1310 D*)