X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=weblib%2Ftutorial%2Fchapter4.ma;h=be8ddaa594212f9b0dacba4a7d7ddb8c81a23982;hb=a2ba04cd90e76937720b16e37cb12a39b46181e3;hp=1be877197f9cff9659a5e5573d508e9af1e2ef2d;hpb=f848433620419e71cd19ec0b4f58c717ac50f85e;p=helm.git diff --git a/weblib/tutorial/chapter4.ma b/weblib/tutorial/chapter4.ma index 1be877197..be8ddaa59 100644 --- a/weblib/tutorial/chapter4.ma +++ b/weblib/tutorial/chapter4.ma @@ -1,7 +1,9 @@ -(* In this Chapter we shall develop a naif theory of sets represented as characteristic -predicates over some universe codeA/code, that is as objects of type A→Prop. *) +(* In this Chapter we shall develop a naif theory of sets represented as +characteristic predicates over some universe codeA/code, that is as objects of type +A→Prop. *) -include "basics/logic.ma". +include "basics/types.ma". +include "basics/bool.ma". (**** For instance the empty set is defined by the always function predicate *) @@ -12,7 +14,7 @@ interpretation "empty set" 'empty_set = (empty_set ?). (* Similarly, a singleton set contaning containing an element a, is defined by by the characteristic function asserting equality with a *) -definition singleton ≝ λA.λx,a:A.xa title="leibnitz's equality" href="cic:/fakeuri.def(1)"=/aa. +definition singleton ≝ λA.λx,a:A.xa title="leibnitz's equality" href="cic:/fakeuri.def(1)"=/aspan class="error" title="Parse error: [term] expected after [sym=] (in [term])"/spana. (* notation "{x}" non associative with precedence 90 for @{'sing_lang $x}. *) interpretation "singleton" 'singl x = (singleton ? x). @@ -25,7 +27,7 @@ conjunction and negation *) definition union : ∀A:Type[0].∀P,Q.A → Prop ≝ λA,P,Q,a.P a a title="logical or" href="cic:/fakeuri.def(1)"∨/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 a title="logical and" href="cic:/fakeuri.def(1)"∧/a Q a. +definition intersection : ∀A:Type[0].∀P,Q.A→Prop ≝ λA,P,Q,a.P a a title="logical and" href="cic:/fakeuri.def(1)"∧/aspan class="error" title="Parse error: [term] expected after [sym∧] (in [term])"/span Q a. interpretation "intersection" 'intersects a b = (intersection ? a b). definition complement ≝ λU:Type[0].λA:U → Prop.λw.a title="logical not" href="cic:/fakeuri.def(1)"¬/a A w. @@ -43,7 +45,7 @@ interpretation "subset" 'subseteq a b = (subset ? a b). (* Two sets are equals if and only if they have the same elements, that is, if the two characteristic functions are extensionally equivalent: *) -definition eqP ≝ λA:Type[0].λP,Q:A → Prop.∀a:A.P a a title="iff" href="cic:/fakeuri.def(1)"↔/a Q a. +definition eqP ≝ λA:Type[0].λP,Q:A → Prop.∀a:A.P a a title="iff" href="cic:/fakeuri.def(1)"↔/aspan class="error" title="Parse error: [term] expected after [sym↔] (in [term])"/span Q a. notation "A =1 B" non associative with precedence 45 for @{'eqP $A $B}. interpretation "extensional equality" 'eqP a b = (eqP ? a b). @@ -63,7 +65,7 @@ lemma eqP_trans: ∀U.∀A,B,C:U →Prop. with respect to eqP: *) lemma eqP_union_r: ∀U.∀A,B,C:U →Prop. - A a title="extensional equality" href="cic:/fakeuri.def(1)"=/a1 C → A a title="union" href="cic:/fakeuri.def(1)"∪/a B a title="extensional equality" href="cic:/fakeuri.def(1)"=/a1 C a title="union" href="cic:/fakeuri.def(1)"∪/a B. + A a title="extensional equality" href="cic:/fakeuri.def(1)"=/aspan class="error" title="Parse error: NUMBER '1' or [term] expected after [sym=] (in [term])"/span1 C → A a title="union" href="cic:/fakeuri.def(1)"∪/a B a title="extensional equality" href="cic:/fakeuri.def(1)"=/a1 C a title="union" href="cic:/fakeuri.def(1)"∪/a B. #U #A #B #C #eqAB #a @a href="cic:/matita/basics/logic/iff_or_r.def(2)"iff_or_r/a @eqAB qed. lemma eqP_union_l: ∀U.∀A,B,C:U →Prop. @@ -75,7 +77,7 @@ lemma eqP_intersect_r: ∀U.∀A,B,C:U →Prop. #U #A #B #C #eqAB #a @a href="cic:/matita/basics/logic/iff_and_r.def(2)"iff_and_r/a @eqAB qed. lemma eqP_intersect_l: ∀U.∀A,B,C:U →Prop. - B a title="extensional equality" href="cic:/fakeuri.def(1)"=/a1 C → A a title="intersection" href="cic:/fakeuri.def(1)"∩/a B a title="extensional equality" href="cic:/fakeuri.def(1)"=/a1 A a title="intersection" href="cic:/fakeuri.def(1)"∩/a C. + B a title="extensional equality" href="cic:/fakeuri.def(1)"=/a1 C → A a title="intersection" href="cic:/fakeuri.def(1)"∩/aspan class="error" title="Parse error: [term] expected after [sym∩] (in [term])"/span B a title="extensional equality" href="cic:/fakeuri.def(1)"=/a1 A a title="intersection" href="cic:/fakeuri.def(1)"∩/a C. #U #A #B #C #eqBC #a @a href="cic:/matita/basics/logic/iff_and_l.def(2)"iff_and_l/a @eqBC qed. lemma eqP_substract_r: ∀U.∀A,B,C:U →Prop. @@ -86,9 +88,9 @@ lemma eqP_substract_l: ∀U.∀A,B,C:U →Prop. B a title="extensional equality" href="cic:/fakeuri.def(1)"=/a1 C → A a title="substraction" href="cic:/fakeuri.def(1)"-/a B a title="extensional equality" href="cic:/fakeuri.def(1)"=/a1 A a title="substraction" href="cic:/fakeuri.def(1)"-/a C. #U #A #B #C #eqBC #a @a href="cic:/matita/basics/logic/iff_and_l.def(2)"iff_and_l/a /span class="autotactic"2span class="autotrace" trace a href="cic:/matita/basics/logic/iff_not.def(4)"iff_not/a/span/span/ qed. -(* We can now prove several properties of the previous set-theoretic -operations. In particular, union is commutative and associative, and -the empty set is an identity element: *) +(* We can now prove several properties of the previous set-theoretic operations. +In particular, union is commutative and associative, and the empty set is an +identity element: *) lemma union_empty_r: ∀U.∀A:U→Prop. A a title="union" href="cic:/fakeuri.def(1)"∪/a a title="empty set" href="cic:/fakeuri.def(1)"∅/a a title="extensional equality" href="cic:/fakeuri.def(1)"=/a1 A. @@ -101,10 +103,10 @@ lemma union_comm : ∀U.∀A,B:U →Prop. lemma union_assoc: ∀U.∀A,B,C:U → Prop. A a title="union" href="cic:/fakeuri.def(1)"∪/a B a title="union" href="cic:/fakeuri.def(1)"∪/a C a title="extensional equality" href="cic:/fakeuri.def(1)"=/a1 A a title="union" href="cic:/fakeuri.def(1)"∪/a (B a title="union" href="cic:/fakeuri.def(1)"∪/a C). -#S #A #B #C #w % [* [* /span class="autotactic"3span class="autotrace" trace a href="cic:/matita/basics/logic/Or.con(0,1,2)"or_introl/a, a href="cic:/matita/basics/logic/Or.con(0,2,2)"or_intror/a/span/span/ | /span class="autotactic"3span class="autotrace" trace a href="cic:/matita/basics/logic/Or.con(0,2,2)"or_intror/a/span/span/] | * [/span class="autotactic"3span class="autotrace" trace a href="cic:/matita/basics/logic/Or.con(0,1,2)"or_introl/a/span/span/ | * /span class="autotactic"3span class="autotrace" trace a href="cic:/matita/basics/logic/Or.con(0,1,2)"or_introl/a, a href="cic:/matita/basics/logic/Or.con(0,2,2)"or_intror/a/span/span/] +#S #A #B #C #w % [* [* /span class="autotactic"3span class="autotrace" trace a href="cic:/matita/basics/logic/Or.con(0,1,2)"or_introl/a, a href="cic:/matita/basics/logic/Or.con(0,2,2)"or_intror/a/span/span/ | /span class="autotactic"3span class="autotrace" trace a href="cic:/matita/basics/logic/Or.con(0,1,2)"or_introl/a, a href="cic:/matita/basics/logic/Or.con(0,2,2)"or_intror/a/span/span/ ] | * [/span class="autotactic"3span class="autotrace" trace a href="cic:/matita/basics/logic/Or.con(0,1,2)"or_introl/a/span/span/ | * /span class="autotactic"3span class="autotrace" trace a href="cic:/matita/basics/logic/Or.con(0,1,2)"or_introl/a, a href="cic:/matita/basics/logic/Or.con(0,2,2)"or_intror/a/span/span/] qed. -(* In the same way we prove commutativity and associativity for set +(* In the same way we prove commutativity and associativity for set interesection *) lemma cap_comm : ∀U.∀A,B:U →Prop. @@ -126,9 +128,8 @@ lemma cap_idemp: ∀U.∀A:U →Prop. A a title="intersection" href="cic:/fakeuri.def(1)"∩/a A a title="extensional equality" href="cic:/fakeuri.def(1)"=/a1 A. #U #A #a % [* // | /span class="autotactic"2span class="autotrace" trace a href="cic:/matita/basics/logic/And.con(0,1,2)"conj/a/span/span/] qed. -(* We conclude our examples with a couple of distributivity theorems, -and a characterization of substraction in terms of interesection and -complementation. *) +(* We conclude our examples with a couple of distributivity theorems, and a +characterization of substraction in terms of interesection and complementation. *) lemma distribute_intersect : ∀U.∀A,B,C:U→Prop. (A a title="union" href="cic:/fakeuri.def(1)"∪/a B) a title="intersection" href="cic:/fakeuri.def(1)"∩/a C a title="extensional equality" href="cic:/fakeuri.def(1)"=/a1 (A a title="intersection" href="cic:/fakeuri.def(1)"∩/a C) a title="union" href="cic:/fakeuri.def(1)"∪/a (B a title="intersection" href="cic:/fakeuri.def(1)"∩/a C). @@ -144,92 +145,174 @@ lemma substract_def:∀U.∀A,B:U→Prop. Aa title="substraction" href="cic:/fa #U #A #B #w normalize /span class="autotactic"2span class="autotrace" trace a href="cic:/matita/basics/logic/And.con(0,1,2)"conj/a/span/span/ qed. -(****** DeqSet: a set with a decidbale equality ******) +(* In several situation it is important to assume to have a decidable equality +between elements of a set U, namely a boolean function eqb: U→U→bool such that +for any pair of elements a and b in U, (eqb x y) is true if and only if x=y. +A set equipped with such an equality is called a DeqSet: *) record DeqSet : Type[1] ≝ { carr :> Type[0]; - eqb: carr → carr → bool; - eqb_true: ∀x,y. (eqb x y = true) ↔ (x = y) + eqb: carr → carr → a href="cic:/matita/basics/bool/bool.ind(1,0,0)"bool/a; + eqb_true: ∀x,y. (eqb x y a title="leibnitz's equality" href="cic:/fakeuri.def(1)"=/a a href="cic:/matita/basics/bool/bool.con(0,1,0)"true/a) a title="iff" href="cic:/fakeuri.def(1)"↔/a (x a title="leibnitz's equality" href="cic:/fakeuri.def(1)"=/a y) }. +(* We use the notation == to denote the decidable equality, to distinguish it +from the propositional equality. In particular, a term of the form a==b is a +boolean, while a=b is a proposition. *) + notation "a == b" non associative with precedence 45 for @{ 'eqb $a $b }. interpretation "eqb" 'eqb a b = (eqb ? a b). +(* It is convenient to have a simple way to reflect a proof of the fact +that (eqb a b) is true into a proof of the proposition (a = b); to this aim, +we introduce two operators "\P" and "\b". *) + notation "\P H" non associative with precedence 90 for @{(proj1 … (eqb_true ???) $H)}. notation "\b H" non associative with precedence 90 for @{(proj2 … (eqb_true ???) $H)}. -lemma eqb_false: ∀S:DeqSet.∀a,b:S. - (eqb ? a b) = false ↔ a ≠ b. +(* If H:eqb a b = true, then \P H: a = b, and conversely if h:a = b, then +\b h: eqb a b = true. Let us see an example of their use: the following +statement asserts that we can reflect a proof that eqb a b is false into +a proof of the proposition a ≠ b. *) + +lemma eqb_false: ∀S:a href="cic:/matita/tutorial/chapter4/DeqSet.ind(1,0,0)"DeqSet/a.∀a,b:S. + (a href="cic:/matita/tutorial/chapter4/eqb.fix(0,0,3)"eqb/a ? a b) a title="leibnitz's equality" href="cic:/fakeuri.def(1)"=/a a href="cic:/matita/basics/bool/bool.con(0,2,0)"false/a a title="iff" href="cic:/fakeuri.def(1)"↔/a a a title="leibnitz's non-equality" href="cic:/fakeuri.def(1)"≠/a b. + +(* We start the proof introducing the hypothesis, and then split the "if" and +"only if" cases *) + #S #a #b % #H - [@(not_to_not … not_eq_true_false) #H1 (\P eqa) >(\P eqb) // - |#H destruct normalize >(\b (refl … a2)) >(\b (refl … b2)) // + [#H cases (a href="cic:/matita/basics/bool/andb_true.def(5)"andb_true/a …H) normalize #eqa #eqb >(\P eqa) >(\P eqb) // + |#H destruct normalize >(\b (a href="cic:/matita/basics/logic/eq.con(0,1,2)"refl/a … a2)) >(\b (a href="cic:/matita/basics/logic/eq.con(0,1,2)"refl/a … 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 +definition DeqProd ≝ λA,B:a href="cic:/matita/tutorial/chapter4/DeqSet.ind(1,0,0)"DeqSet/a. + a href="cic:/matita/tutorial/chapter4/DeqSet.con(0,1,0)"mk_DeqSet/a (Aa title="Product" href="cic:/fakeuri.def(1)"×/aB) (a href="cic:/matita/tutorial/chapter4/eq_pairs.def(4)"eq_pairs/a A B) (a href="cic:/matita/tutorial/chapter4/eq_pairs_true.def(6)"eq_pairs_true/a A B). + +(* Having an unification problem of the kind T1×T2 = carr X, what kind +of hint can we give to the system? We expect T1 to be the carrier of a +DeqSet C1, T2 to be the carrier of a DeqSet C2, and X to be DeqProd C1 C2. +This is expressed by the following hint: *) + +unification hint 0 a href="cic:/fakeuri.def(1)" title="hint_decl_Type1"≔/a C1,C2; + T1 ≟ a href="cic:/matita/tutorial/chapter4/carr.fix(0,0,2)"carr/a C1, + T2 ≟ a href="cic:/matita/tutorial/chapter4/carr.fix(0,0,2)"carr/a C2, + X ≟ a href="cic:/matita/tutorial/chapter4/DeqProd.def(7)"DeqProd/a C1 C2 (* ---------------------------------------- *) ⊢ - T1×T2 ≡ carr X. + T1a title="Product" href="cic:/fakeuri.def(1)"×/aT2 ≡ a href="cic:/matita/tutorial/chapter4/carr.fix(0,0,2)"carr/a X. -unification hint 0 ≔ T1,T2,p1,p2; - X ≟ DeqProd T1 T2 +unification hint 0 a href="cic:/fakeuri.def(1)" title="hint_decl_Type0"≔/a T1,T2,p1,p2; + X ≟ a href="cic:/matita/tutorial/chapter4/DeqProd.def(7)"DeqProd/a T1 T2 (* ---------------------------------------- *) ⊢ - eq_pairs T1 T2 p1 p2 ≡ eqb X p1 p2. + a href="cic:/matita/tutorial/chapter4/eq_pairs.def(4)"eq_pairs/a T1 T2 p1 p2 ≡ a href="cic:/matita/tutorial/chapter4/eqb.fix(0,0,3)"eqb/a X p1 p2. example hint2: ∀b1,b2. - 〈b1,true〉==〈false,b2〉=true → 〈b1,true〉=〈false,b2〉. + a title="Pair construction" href="cic:/fakeuri.def(1)"〈/ab1,a href="cic:/matita/basics/bool/bool.con(0,1,0)"true/a〉a title="eqb" href="cic:/fakeuri.def(1)"=/a=a title="Pair construction" href="cic:/fakeuri.def(1)"〈/aa href="cic:/matita/basics/bool/bool.con(0,2,0)"false/a,b2〉a title="leibnitz's equality" href="cic:/fakeuri.def(1)"=/aa href="cic:/matita/basics/bool/bool.con(0,1,0)"true/a → a title="Pair construction" href="cic:/fakeuri.def(1)"〈/ab1,a href="cic:/matita/basics/bool/bool.con(0,1,0)"true/a〉a title="leibnitz's equality" href="cic:/fakeuri.def(1)"=/aa title="Pair construction" href="cic:/fakeuri.def(1)"〈/aa href="cic:/matita/basics/bool/bool.con(0,2,0)"false/a,b2〉. #b1 #b2 #H @(\P H). \ No newline at end of file