3 Matita Tutorial: inductively generated formal topologies
4 ========================================================
6 This is a not so short introduction to Matita, based on
7 the formalization of the paper
9 > Between formal topology and game theory: an
10 > explicit solution for the conditions for an
11 > inductive generation of formal topologies
13 by S.Berardi and S. Valentini. The tutorial is by Enrico Tassi.
20 buttons, PG-interaction-model, sequent window, script window
22 The library, inclusion of `sets/sets.ma`, notation defined: Ω^A.
23 Symbols (see menu: View ▹ TeX/UTF-8 Table):
30 Virtuals, ALT-L, for example `I` changes into `𝕀`, finally `𝐈`.
32 The standard library and the `include` command
33 ----------------------------------------------
35 Some basic notions, like subset, membership, intersection and union
36 are part of the standard library of Matita.
38 These notions come with
39 some notation attached to them:
44 - Ω^A, that is the type of the subsets of A, `\Omega ^ A`
46 The `include` command tells Matita to load a part of the library,
47 in particular the part that we will use can be loaded as follows:
51 include "sets/sets.ma".
55 nlemma subseteq_intersection_l: ∀A.∀U,V,W:Ω^A.U ⊆ W ∨ V ⊆ W → U ∩ V ⊆ W.
56 #A; #U; #V; #W; *; #H; #x; *; #xU; #xV; napply H; nassumption;
59 nlemma subseteq_union_l: ∀A.∀U,V,W:Ω^A.U ⊆ W → V ⊆ W → U ∪ V ⊆ W.
60 #A; #U; #V; #W; #H; #H1; #x; *; #Hx; ##[ napply H; ##| napply H1; ##] nassumption;
63 nlemma subseteq_intersection_r: ∀A.∀U,V,W:Ω^A.W ⊆ U → W ⊆ V → W ⊆ U ∩ V.
64 #A; #U; #V; #W; #H1; #H2; #x; #Hx; @; ##[ napply H1; ##| napply H2; ##] nassumption;
70 Some basic results that we will use are also part of the sets library:
72 - subseteq\_union\_l: ∀A.∀U,V,W:Ω^A.U ⊆ W → V ⊆ W → U ∪ V ⊆ W
73 - subseteq\_intersection\_r: ∀A.∀U,V,W:Ω^A.W ⊆ U → W ⊆ V → W ⊆ U ∩ V
78 records, projections, types of projections..
82 nrecord Ax : Type[1] ≝ {
90 Note that the field `S` was declared with `:>` instead of a simple `:`.
91 This declares the `S` projection to be a coercion. A coercion is
92 a function case the system automatically inserts when it is needed.
93 In that case, the projection `S` has type `Ax → setoid`, and whenever
94 the expected type of a term is `setoid` while its type is `Ax`, the
95 system inserts the coercion around it, to make the whole term well types.
97 When formalizing an algebraic structure, declaring the carrier as a
98 coercion is a common practice, since it allows to write statements like
100 ∀G:Group.∀x:G.x * x^-1 = 1
102 The quantification over `x` of type `G` is illtyped, since `G` is a term
103 (of type `Group`) and thus not a type. Since the carrier projection
104 `carr` of `G` is a coercion, that maps a `Group` into the type of
105 its elements, the system automatically inserts `carr` around `G`,
106 obtaining `…∀x: carr G.…`. Coercions are also hidden by the system
107 when it displays a term.
109 In this particular case, the coercion `S` allows to write
113 Since `A` is not a type, but it can be turned into a `setoid` by `S`
114 and a `setoid` can be turned into a type by its `carr` projection, the
115 composed coercion `carr ∘ S` is silently inserted.
120 Something that is not still satisfactory, in that the dependent type
121 of `I` and `C` are abstracted over the Axiom set. To obtain the
122 precise type of a term, you can use the `ncheck` command as follows.
131 One would like to write `I a` and not `I A a` under a context where
132 `A` is an axiom set and `a` has type `S A` (or thanks to the coercion
133 mecanism simply `A`). In Matita, a question mark represents an implicit
134 argument, i.e. a missing piece of information the system is asked to
135 infer. Matita performs some sort of type inference, thus writing
136 `I ? a` is enough: since the second argument of `I` is typed by the
137 first one, the first one can be inferred just computing the type of `a`.
141 (* ncheck (∀A:Ax.∀a:A.I ? a). *)
145 This is still not completely satisfactory, since you have always type
146 `?`; to fix this minor issue we have to introduce the notational
147 support built in Matita.
152 Matita is quipped with a quite complex notational support,
153 allowing the user to define and use mathematical notations
154 ([From Notation to Semantics: There and Back Again][1]).
156 Since notations are usually ambiguous (e.g. the frequent overloading of
157 symbols) Matita distinguishes between the term level, the
158 content level, and the presentation level, allowing multiple
159 mappings between the contenet and the term level.
161 The mapping between the presentation level (i.e. what is typed on the
162 keyboard and what is displayed in the sequent window) and the content
163 level is defined with the `notation` command. When followed by
164 `>`, it defines an input (only) notation.
168 notation > "𝐈 term 90 a" non associative with precedence 70 for @{ 'I $a }.
169 notation > "𝐂 term 90 a term 90 i" non associative with precedence 70 for @{ 'C $a $i }.
173 The forst notation defines the writing `𝐈 a` where `a` is a generic
174 term of precedence 90, the maximum one. This high precedence forces
175 parentheses around any term of a lower precedence. For example `𝐈 x`
176 would be accepted, since identifiers have precedence 90, but
177 `𝐈 f x` would be interpreted as `(𝐈 f) x`. In the latter case, parentheses
178 have to be put around `f x`, thus the accepted writing would be `𝐈 (f x)`.
180 To obtain the `𝐈` is enough to type `I` and then cycle between its
181 similar symbols with ALT-L. The same for `𝐂`. Notations cannot use
182 regular letters or the round parentheses, thus their variants (like the
183 bold ones) have to be used.
185 The first notation associates `𝐈 a` with `'I $a` where `'I` is a
186 new content element to which a term `$a` is passed.
188 Content elements have to be interpreted, and possibly multiple,
189 incompatible, interpretations can be defined.
193 interpretation "I" 'I a = (I ? a).
194 interpretation "C" 'C a i = (C ? a i).
198 The `interpretation` command allows to define the mapping between
199 the content level and the terms level. Here we associate the `I` and
200 `C` projections of the Axiom set record, where the Axiom set is an implicit
201 argument `?` to be inferred by the system.
203 Interpretation are bi-directional, thus when displaying a term like
204 `C _ a i`, the system looks for a presentation for the content element
209 notation < "𝐈 \sub( ❨a❩ )" non associative with precedence 70 for @{ 'I $a }.
210 notation < "𝐂 \sub( ❨a,\emsp i❩ )" non associative with precedence 70 for @{ 'C $a $i }.
214 For output purposes we can define more complex notations, for example
215 we can put bold parenteses around the arguments of `𝐈` and `𝐂`, decreasing
216 the size of the arguments and lowering their baseline (i.e. putting them
217 as subscript), separating them with a comma followed by a little space.
219 The first (technical) definition
220 --------------------------------
226 ndefinition cover_set :
227 ∀c: ∀A:Ax.Ω^A → A → CProp[0]. ∀A:Ax.∀C,U:Ω^A. CProp[0]
229 λc: ∀A:Ax.Ω^A → A → CProp[0]. λA,C,U.∀y.y ∈ C → c A U y.
231 ndefinition cover_set_interactive :
232 ∀c: ∀A:Ax.Ω^A → A → CProp[0]. ∀A:Ax.∀C,U:Ω^A. CProp[0].
233 #cover; #A; #C; #U; napply (∀y:A.y ∈ C → ?); napply cover;
241 notation "hvbox(a break ◃ b)" non associative with precedence 45
242 for @{ 'covers $a $b }.
244 interpretation "covers set temp" 'covers C U = (cover_set ?? C U).
246 ninductive cover (A : Ax) (U : Ω^A) : A → CProp[0] ≝
247 | creflexivity : ∀a:A. a ∈ U → cover ? U a
248 | cinfinity : ∀a:A.∀i:𝐈 a. 𝐂 a i ◃ U → cover ? U a.
252 interpretation "covers" 'covers a U = (cover ? U a).
253 (* interpretation "covers set" 'covers a U = (cover_set cover ? a U). *)
255 ndefinition fish_set ≝ λf:∀A:Ax.Ω^A → A → CProp[0].
260 notation "hvbox(a break ⋉ b)" non associative with precedence 45
261 for @{ 'fish $a $b }.
263 interpretation "fish set temp" 'fish A U = (fish_set ?? U A).
265 ncoinductive fish (A : Ax) (F : Ω^A) : A → CProp[0] ≝
266 | cfish : ∀a. a ∈ F → (∀i:𝐈 a .𝐂 a i ⋉ F) → fish A F a.
270 interpretation "fish set" 'fish A U = (fish_set fish ? U A).
271 interpretation "fish" 'fish a U = (fish ? U a).
273 nlet corec fish_rec (A:Ax) (U: Ω^A)
275 (H2: ∀a:A. a ∈ P → ∀j: 𝐈 a. 𝐂 a j ≬ P):
276 ∀a:A. ∀p: a ∈ P. a ⋉ U ≝ ?.
277 #a; #p; napply cfish; (** screenshot "def-fish-rec". *)
278 ##[ napply H1; napply p;
279 ##| #i; ncases (H2 a p i); #x; *; #xC; #xP; @; ##[napply x]
280 @; ##[ napply xC ] napply (fish_rec ? U P); nassumption;
284 notation "◃U" non associative with precedence 55
285 for @{ 'coverage $U }.
287 ndefinition coverage : ∀A:Ax.∀U:Ω^A.Ω^A ≝ λA,U.{ a | a ◃ U }.
289 interpretation "coverage cover" 'coverage U = (coverage ? U).
291 ndefinition cover_equation : ∀A:Ax.∀U,X:Ω^A.CProp[0] ≝ λA,U,X.
292 ∀a.a ∈ X ↔ (a ∈ U ∨ ∃i:𝐈 a.∀y.y ∈ 𝐂 a i → y ∈ X).
294 ntheorem coverage_cover_equation : ∀A,U. cover_equation A U (◃U).
296 ##[ nelim H; #b; (* manca clear *)
297 ##[ #bU; @1; nassumption;
298 ##| #i; #CaiU; #IH; @2; @ i; #c; #cCbi; ncases (IH ? cCbi);
300 ##| #_; napply CaiU; nassumption; ##] ##]
301 ##| ncases H; ##[ #E; @; nassumption]
302 *; #j; #Hj; @2 j; #w; #wC; napply Hj; nassumption;
306 ntheorem coverage_min_cover_equation :
307 ∀A,U,W. cover_equation A U W → ◃U ⊆ W.
308 #A; #U; #W; #H; #a; #aU; nelim aU; #b;
309 ##[ #bU; ncases (H b); #_; #H1; napply H1; @1; nassumption;
310 ##| #i; #CbiU; #IH; ncases (H b); #_; #H1; napply H1; @2; @i; napply IH;
314 notation "⋉F" non associative with precedence 55
317 ndefinition fished : ∀A:Ax.∀F:Ω^A.Ω^A ≝ λA,F.{ a | a ⋉ F }.
319 interpretation "fished fish" 'fished F = (fished ? F).
321 ndefinition fish_equation : ∀A:Ax.∀F,X:Ω^A.CProp[0] ≝ λA,F,X.
322 ∀a. a ∈ X ↔ a ∈ F ∧ ∀i:𝐈 a.∃y.y ∈ 𝐂 a i ∧ y ∈ X.
324 ntheorem fised_fish_equation : ∀A,F. fish_equation A F (⋉F).
325 #A; #F; #a; @; (* bug, fare case sotto diverso da farlo sopra *) #H; ncases H;
326 ##[ #b; #bF; #H2; @ bF; #i; ncases (H2 i); #c; *; #cC; #cF; @c; @ cC;
328 ##| #aF; #H1; @ aF; napply H1;
332 ntheorem fised_max_fish_equation : ∀A,F,G. fish_equation A F G → G ⊆ ⋉F.
333 #A; #F; #G; #H; #a; #aG; napply (fish_rec … aG);
334 #b; ncases (H b); #H1; #_; #bG; ncases (H1 bG); #E1; #E2; nassumption;
337 nrecord nAx : Type[2] ≝ {
338 nS:> setoid; (*Type[0];*)
340 nD: ∀a:nS. nI a → Type[0];
341 nd: ∀a:nS. ∀i:nI a. nD a i → nS
345 TYPE f A → B, g : B → A, f ∘ g = id, g ∘ g = id.
350 notation "𝐃 \sub ( ❨a,\emsp i❩ )" non associative with precedence 70 for @{ 'D $a $i }.
351 notation "𝐝 \sub ( ❨a,\emsp i,\emsp j❩ )" non associative with precedence 70 for @{ 'd $a $i $j}.
353 notation > "𝐃 term 90 a term 90 i" non associative with precedence 70 for @{ 'D $a $i }.
354 notation > "𝐝 term 90 a term 90 i term 90 j" non associative with precedence 70 for @{ 'd $a $i $j}.
356 interpretation "D" 'D a i = (nD ? a i).
357 interpretation "d" 'd a i j = (nd ? a i j).
358 interpretation "new I" 'I a = (nI ? a).
360 ndefinition image ≝ λA:nAx.λa:A.λi. { x | ∃j:𝐃 a i. x = 𝐝 a i j }.
362 notation > "𝐈𝐦 [𝐝 term 90 a term 90 i]" non associative with precedence 70 for @{ 'Im $a $i }.
363 notation "𝐈𝐦 [𝐝 \sub ( ❨a,\emsp i❩ )]" non associative with precedence 70 for @{ 'Im $a $i }.
365 interpretation "image" 'Im a i = (image ? a i).
367 ndefinition Ax_of_nAx : nAx → Ax.
368 #A; @ A (nI ?); #a; #i; napply (𝐈𝐦 [𝐝 a i]);
371 ninductive sigma (A : Type[0]) (P : A → CProp[0]) : Type[0] ≝
372 sig_intro : ∀x:A.P x → sigma A P.
374 interpretation "sigma" 'sigma \eta.p = (sigma ? p).
376 ndefinition nAx_of_Ax : Ax → nAx.
378 ##[ #a; #i; napply (Σx:A.x ∈ 𝐂 a i);
379 ##| #a; #i; *; #x; #_; napply x;
383 ninductive Ord (A : nAx) : Type[0] ≝
386 | oL : ∀a:A.∀i.∀f:𝐃 a i → Ord A. Ord A.
388 notation "Λ term 90 f" non associative with precedence 50 for @{ 'oL $f }.
389 notation "x+1" non associative with precedence 50 for @{'oS $x }.
391 interpretation "ordinals Lambda" 'oL f = (oL ? ? ? f).
392 interpretation "ordinals Succ" 'oS x = (oS ? x).
394 nlet rec famU (A : nAx) (U : Ω^A) (x : Ord A) on x : Ω^A ≝
397 | oS y ⇒ let Un ≝ famU A U y in Un ∪ { x | ∃i.𝐈𝐦[𝐝 x i] ⊆ Un}
398 | oL a i f ⇒ { x | ∃j.x ∈ famU A U (f j) } ].
400 notation < "term 90 U \sub (term 90 x)" non associative with precedence 50 for @{ 'famU $U $x }.
401 notation > "U ⎽ term 90 x" non associative with precedence 50 for @{ 'famU $U $x }.
403 interpretation "famU" 'famU U x = (famU ? U x).
405 ndefinition ord_coverage : ∀A:nAx.∀U:Ω^A.Ω^A ≝ λA,U.{ y | ∃x:Ord A. y ∈ famU ? U x }.
407 ndefinition ord_cover_set ≝ λc:∀A:nAx.Ω^A → Ω^A.λA,C,U.
408 ∀y.y ∈ C → y ∈ c A U.
410 interpretation "coverage new cover" 'coverage U = (ord_coverage ? U).
411 interpretation "new covers set" 'covers a U = (ord_cover_set ord_coverage ? a U).
412 interpretation "new covers" 'covers a U = (mem ? (ord_coverage ? U) a).
414 ntheorem new_coverage_reflexive:
415 ∀A:nAx.∀U:Ω^A.∀a. a ∈ U → a ◃ U.
416 #A; #U; #a; #H; @ (oO A); napply H;
420 ∀A:nAx.∀a:A.∀i,f,U.∀j:𝐃 a i.U⎽(f j) ⊆ U⎽(Λ f).
421 #A; #a; #i; #f; #U; #j; #b; #bUf; @ j; nassumption;
424 naxiom AC : ∀A,a,i,U.(∀j:𝐃 a i.∃x:Ord A.𝐝 a i j ∈ U⎽x) → (Σf.∀j:𝐃 a i.𝐝 a i j ∈ U⎽(f j)).
426 naxiom setoidification :
427 ∀A:nAx.∀a,b:A.∀U.a=b → b ∈ U → a ∈ U.
433 <div id="figure1" class="img" ><img src="figure1.png"/>foo</div>
437 alias symbol "covers" = "new covers".
438 alias symbol "covers" = "new covers set".
439 alias symbol "covers" = "new covers".
440 alias symbol "covers" = "new covers set".
441 alias symbol "covers" = "new covers".
442 alias symbol "covers" = "new covers set".
443 alias symbol "covers" = "new covers".
444 alias symbol "covers" = "new covers set".
445 alias symbol "covers" = "new covers".
446 ntheorem new_coverage_infinity:
447 ∀A:nAx.∀U:Ω^A.∀a:A. (∃i:𝐈 a. 𝐈𝐦[𝐝 a i] ◃ U) → a ◃ U.
448 #A; #U; #a;(** screenshot "figure1". *)
449 *; #i; #H; nnormalize in H;
450 ncut (∀y:𝐃 a i.∃x:Ord A.𝐝 a i y ∈ U⎽x); ##[
451 #y; napply H; @ y; napply #; ##] #H';
452 ncases (AC … H'); #f; #Hf;
453 ncut (∀j.𝐝 a i j ∈ U⎽(Λ f));
454 ##[ #j; napply (ord_subset … f … (Hf j));##] #Hf';
455 @ ((Λ f)+1); @2; nwhd; @i; #x; *; #d; #Hd;
456 napply (setoidification … Hd); napply Hf';
459 nlemma new_coverage_min :
460 ∀A:nAx.∀U:qpowerclass A.∀V.U ⊆ V → (∀a:A.∀i.𝐈𝐦[𝐝 a i] ⊆ V → a ∈ V) → ◃(pc ? U) ⊆ V.
461 #A; #U; #V; #HUV; #Im; #b; *; #o; ngeneralize in match b; nchange with ((pc ? U)⎽o ⊆ V);
463 ##[ #b; #bU0; napply HUV; napply bU0;
464 ##| #p; #IH; napply subseteq_union_l; ##[ nassumption; ##]
465 #x; *; #i; #H; napply (Im ? i); napply (subseteq_trans … IH); napply H;
466 ##| #a; #i; #f; #IH; #x; *; #d; napply IH; ##]
469 nlet rec famF (A: nAx) (F : Ω^A) (x : Ord A) on x : Ω^A ≝
472 | oS o ⇒ let Fo ≝ famF A F o in Fo ∩ { x | ∀i:𝐈 x.∃j:𝐃 x i.𝐝 x i j ∈ Fo }
473 | oL a i f ⇒ { x | ∀j:𝐃 a i.x ∈ famF A F (f j) }
476 interpretation "famF" 'famU U x = (famF ? U x).
478 ndefinition ord_fished : ∀A:nAx.∀F:Ω^A.Ω^A ≝ λA,F.{ y | ∀x:Ord A. y ∈ F⎽x }.
480 interpretation "fished new fish" 'fished U = (ord_fished ? U).
481 interpretation "new fish" 'fish a U = (mem ? (ord_fished ? U) a).
483 ntheorem new_fish_antirefl:
484 ∀A:nAx.∀F:Ω^A.∀a. a ⋉ F → a ∈ F.
485 #A; #F; #a; #H; nlapply (H (oO ?)); #aFo; napply aFo;
488 nlemma co_ord_subset:
489 ∀A:nAx.∀F:Ω^A.∀a,i.∀f:𝐃 a i → Ord A.∀j. F⎽(Λ f) ⊆ F⎽(f j).
490 #A; #F; #a; #i; #f; #j; #x; #H; napply H;
494 ∀A:nAx.∀a:A.∀i,F. (∀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.
497 ntheorem new_fish_compatible:
498 ∀A:nAx.∀F:Ω^A.∀a. a ⋉ F → ∀i:𝐈 a.∃j:𝐃 a i.𝐝 a i j ⋉ F.
499 #A; #F; #a; #aF; #i; nnormalize;
501 nlapply (aF (Λf+1)); #aLf;
502 nchange in aLf with (a ∈ F⎽(Λ f) ∧ ∀i:𝐈 a.∃j:𝐃 a i.𝐝 a i j ∈ F⎽(Λ f));
503 ncut (∃j:𝐃 a i.𝐝 a i j ∈ F⎽(f j));##[
504 ncases aLf; #_; #H; nlapply (H i); *; #j; #Hj; @j; napply Hj;##] #aLf';
508 ntheorem max_new_fished:
509 ∀A:nAx.∀G,F:Ω^A.G ⊆ F → (∀a.a ∈ G → ∀i.𝐈𝐦[𝐝 a i] ≬ G) → G ⊆ ⋉F.
510 #A; #G; #F; #GF; #H; #b; #HbG; #o; ngeneralize in match HbG; ngeneralize in match b;
511 nchange with (G ⊆ F⎽o);
514 ##| #p; #IH; napply (subseteq_intersection_r … IH);
515 #x; #Hx; #i; ncases (H … Hx i); #c; *; *; #d; #Ed; #cG;
516 @d; napply IH; napply (setoidification … Ed^-1); napply cG;
517 ##| #a; #i; #f; #Hf; nchange with (G ⊆ { y | ∀x. y ∈ F⎽(f x) });
518 #b; #Hb; #d; napply (Hf d); napply Hb;
524 [1]: http://upsilon.cc/~zack/research/publications/notation.pdf