X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=weblib%2Ftutorial%2Fchapter4.ma;h=b358f823245894dc6803ce927dafbe7943013ed1;hb=df8e8b840c36a1a789ec7bebc47c3cc8aca4f663;hp=a0a5a938d1785d58bf1422016caad88e5089c7f7;hpb=3443885ee60fbcb90e2d106e67d3b7f7e3c59bad;p=helm.git diff --git a/weblib/tutorial/chapter4.ma b/weblib/tutorial/chapter4.ma index a0a5a938d..b358f8232 100644 --- a/weblib/tutorial/chapter4.ma +++ b/weblib/tutorial/chapter4.ma @@ -1,126 +1,200 @@ +include "basics/logic.ma". +(**** a subset of A is just an object of type A→Prop ****) -(**************************************************************************) -(* ___ *) -(* ||M|| *) -(* ||A|| A project by Andrea Asperti *) -(* ||T|| *) -(* ||I|| Developers: *) -(* ||T|| The HELM team. *) -(* ||A|| http://helm.cs.unibo.it *) -(* \ / *) -(* \ / This file is distributed under the terms of the *) -(* v GNU General Public License Version 2 *) -(* *) -(**************************************************************************) - -include "arithmetics/nat.ma". -include "basics/lists/list.ma". -include "basics/sets.ma". - -definition word ≝ λS:DeqSet.list S. - -notation "ϵ" non associative with precedence 90 for @{ 'epsilon }. -interpretation "epsilon" 'epsilon = (nil ?). - -(* concatenation *) -definition cat : ∀S,l1,l2,w.Prop ≝ - λS.λl1,l2.λw:word S.∃w1,w2.w1 @ w2 = w ∧ l1 w1 ∧ l2 w2. -notation "a · b" non associative with precedence 60 for @{ 'middot $a $b}. -interpretation "cat lang" 'middot a b = (cat ? a b). - -let rec flatten (S : DeqSet) (l : list (word S)) on l : word S ≝ -match l with [ nil ⇒ [ ] | cons w tl ⇒ w @ flatten ? tl ]. - -let rec conjunct (S : DeqSet) (l : list (word S)) (r : word S → Prop) on l: Prop ≝ -match l with [ nil ⇒ True | cons w tl ⇒ r w ∧ conjunct ? tl r ]. - -(* kleene's star *) -definition star ≝ λS.λl.λw:word S.∃lw.flatten ? lw = w ∧ conjunct ? lw l. -notation "a ^ *" non associative with precedence 90 for @{ 'star $a}. -interpretation "star lang" 'star l = (star ? l). - -lemma cat_ext_l: ∀S.∀A,B,C:word S →Prop. - A =1 C → A · B =1 C · B. -#S #A #B #C #H #w % * #w1 * #w2 * * #eqw #inw1 #inw2 -cases (H w1) /6/ +definition empty_set ≝ λA:Type[0].λa:A.False. +notation "\emptyv" non associative with precedence 90 for @{'empty_set}. +interpretation "empty set" 'empty_set = (empty_set ?). + +definition singleton ≝ λA.λx,a:A.x=a. +(* notation "{x}" non associative with precedence 90 for @{'sing_lang $x}. *) +interpretation "singleton" 'singl x = (singleton ? x). + +definition union : ∀A:Type[0].∀P,Q.A → Prop ≝ λA,P,Q,a.P a ∨ Q a. +interpretation "union" 'union a b = (union ? a b). + +definition intersection : ∀A:Type[0].∀P,Q.A→Prop ≝ λA,P,Q,a.P a ∧ Q a. +interpretation "intersection" 'intersects a b = (intersection ? a b). + +definition complement ≝ λU:Type[0].λA:U → Prop.λw.¬ A w. +interpretation "complement" 'not a = (complement ? a). + +definition substraction := λU:Type[0].λA,B:U → Prop.λw.A w ∧ ¬ B w. +interpretation "substraction" 'minus a b = (substraction ? a b). + +definition subset: ∀A:Type[0].∀P,Q:A→Prop.Prop ≝ λA,P,Q.∀a:A.(P a → Q a). +interpretation "subset" 'subseteq a b = (subset ? a b). + +(* extensional equality *) +definition eqP ≝ λA:Type[0].λP,Q:A → Prop.∀a:A.P a ↔ Q a. +notation "A =1 B" non associative with precedence 45 for @{'eqP $A $B}. +interpretation "extensional equality" 'eqP a b = (eqP ? a b). + +lemma eqP_sym: ∀U.∀A,B:U →Prop. + A =1 B → B =1 A. +#U #A #B #eqAB #a @iff_sym @eqAB qed. + +lemma eqP_trans: ∀U.∀A,B,C:U →Prop. + A =1 B → B =1 C → A =1 C. +#U #A #B #C #eqAB #eqBC #a @iff_trans // qed. + +lemma eqP_union_r: ∀U.∀A,B,C:U →Prop. + A =1 C → A ∪ B =1 C ∪ B. +#U #A #B #C #eqAB #a @iff_or_r @eqAB qed. + +lemma eqP_union_l: ∀U.∀A,B,C:U →Prop. + B =1 C → A ∪ B =1 A ∪ C. +#U #A #B #C #eqBC #a @iff_or_l @eqBC qed. + +lemma eqP_intersect_r: ∀U.∀A,B,C:U →Prop. + A =1 C → A ∩ B =1 C ∩ B. +#U #A #B #C #eqAB #a @iff_and_r @eqAB qed. + +lemma eqP_intersect_l: ∀U.∀A,B,C:U →Prop. + B =1 C → A ∩ B =1 A ∩ C. +#U #A #B #C #eqBC #a @iff_and_l @eqBC qed. + +lemma eqP_substract_r: ∀U.∀A,B,C:U →Prop. + A =1 C → A - B =1 C - B. +#U #A #B #C #eqAB #a @iff_and_r @eqAB qed. + +lemma eqP_substract_l: ∀U.∀A,B,C:U →Prop. + B =1 C → A - B =1 A - C. +#U #A #B #C #eqBC #a @iff_and_l /2/ qed. + +(* set equalities *) +lemma union_empty_r: ∀U.∀A:U→Prop. + A ∪ ∅ =1 A. +#U #A #w % [* // normalize #abs @False_ind /2/ | /2/] qed. -lemma cat_ext_r: ∀S.∀A,B,C:word S →Prop. - B =1 C → A · B =1 A · C. -#S #A #B #C #H #w % * #w1 * #w2 * * #eqw #inw1 #inw2 -cases (H w2) /6/ +lemma union_comm : ∀U.∀A,B:U →Prop. + A ∪ B =1 B ∪ A. +#U #A #B #a % * /2/ qed. + +lemma union_assoc: ∀U.∀A,B,C:U → Prop. + A ∪ B ∪ C =1 A ∪ (B ∪ C). +#S #A #B #C #w % [* [* /3/ | /3/] | * [/3/ | * /3/] +qed. + +lemma cap_comm : ∀U.∀A,B:U →Prop. + A ∩ B =1 B ∩ A. +#U #A #B #a % * /2/ qed. + +lemma union_idemp: ∀U.∀A:U →Prop. + A ∪ A =1 A. +#U #A #a % [* // | /2/] qed. + +lemma cap_idemp: ∀U.∀A:U →Prop. + A ∩ A =1 A. +#U #A #a % [* // | /2/] qed. + +(*distributivities *) + +lemma distribute_intersect : ∀U.∀A,B,C:U→Prop. + (A ∪ B) ∩ C =1 (A ∩ C) ∪ (B ∩ C). +#U #A #B #C #w % [* * /3/ | * * /3/] qed. -lemma distr_cat_r: ∀S.∀A,B,C:word S →Prop. - (A ∪ B) · C =1 A · C ∪ B · C. -#S #A #B #C #w % - [* #w1 * #w2 * * #eqw * /6/ |* * #w1 * #w2 * * /6/] +lemma distribute_substract : ∀U.∀A,B,C:U→Prop. + (A ∪ B) - C =1 (A - C) ∪ (B - C). +#U #A #B #C #w % [* * /3/ | * * /3/] qed. -lemma espilon_in_star: ∀S.∀A:word S → Prop. - A^* ϵ. -#S #A @(ex_intro … [ ]) normalize /2/ +(* substraction *) +lemma substract_def:∀U.∀A,B:U→Prop. A-B =1 A ∩ ¬B. +#U #A #B #w normalize /2/ qed. -lemma cat_to_star:∀S.∀A:word S → Prop. - ∀w1,w2. A w1 → A^* w2 → A^* (w1@w2). -#S #A #w1 #w2 #Aw * #l * #H #H1 @(ex_intro … (w1::l)) -% normalize /2/ -qed. +include "basics/types.ma". +include "basics/bool.ma". -lemma fix_star: ∀S.∀A:word S → Prop. - A^* =1 A · A^* ∪ {ϵ}. -#S #A #w % - [* #l generalize in match w; -w cases l [normalize #w * /2/] - #w1 #tl #w * whd in ⊢ ((??%?)→?); #eqw whd in ⊢ (%→?); * - #w1A #cw1 %1 @(ex_intro … w1) @(ex_intro … (flatten S tl)) - % /2/ whd @(ex_intro … tl) /2/ - |* [2: whd in ⊢ (%→?); #eqw Type[0]; + eqb: carr → carr → bool; + eqb_true: ∀x,y. (eqb x y = true) ↔ (x = y) +}. -lemma star_fix_eps : ∀S.∀A:word S → Prop. - A^* =1 (A - {ϵ}) · A^* ∪ {ϵ}. -#S #A #w % - [* #l elim l - [* whd in ⊢ ((??%?)→?); #eqw #_ %2 (\P eqa) >(\P eqb) // + |#H destruct normalize >(\b (refl … a2)) >(\b (refl … b2)) // + ] qed. +definition DeqProd ≝ λA,B:DeqSet. + mk_DeqSet (A×B) (eq_pairs A B) (eq_pairs_true A B). + +unification hint 0 ≔ C1,C2; + T1 ≟ carr C1, + T2 ≟ carr C2, + X ≟ DeqProd C1 C2 +(* ---------------------------------------- *) ⊢ + T1×T2 ≡ carr X. + +unification hint 0 ≔ T1,T2,p1,p2; + X ≟ DeqProd T1 T2 +(* ---------------------------------------- *) ⊢ + eq_pairs T1 T2 p1 p2 ≡ eqb X p1 p2. + +example hint2: ∀b1,b2. + 〈b1,true〉==〈false,b2〉=true → 〈b1,true〉=〈false,b2〉. +#b1 #b2 #H @(\P H). \ No newline at end of file