2 ||M|| This file is part of HELM, an Hypertextual, Electronic
3 ||A|| Library of Mathematics, developed at the Computer Science
4 ||T|| Department of the University of Bologna, Italy.
8 \ / This file is distributed under the terms of the
9 \ / GNU General Public License Version 2
10 V_______________________________________________________________ *)
12 include "basics/logic.ma".
15 inductive void : Type[0] ≝.
18 inductive unit : Type[0] ≝ it: unit.
21 inductive Sum (A,B:Type[0]) : Type[0] ≝
25 interpretation "Disjoint union" 'plus A B = (Sum A B).
28 inductive option (A:Type[0]) : Type[0] ≝
30 | Some : A → option A.
33 inductive Sig (A:Type[0]) (f:A→Type[0]) : Type[0] ≝
34 dp: ∀a:A.(f a)→Sig A f.
36 interpretation "Sigma" 'sigma x = (Sig ? x).
40 record Prod (A,B:Type[0]) : Type[0] ≝ {
45 interpretation "Pair construction" 'pair x y = (mk_Prod ? ? x y).
47 interpretation "Product" 'product x y = (Prod x y).
49 interpretation "pair pi1" 'pi1 = (fst ? ?).
50 interpretation "pair pi2" 'pi2 = (snd ? ?).
51 interpretation "pair pi1" 'pi1a x = (fst ? ? x).
52 interpretation "pair pi2" 'pi2a x = (snd ? ? x).
53 interpretation "pair pi1" 'pi1b x y = (fst ? ? x y).
54 interpretation "pair pi2" 'pi2b x y = (snd ? ? x y).
56 notation "π1" with precedence 10 for @{ (proj1 ??) }.
57 notation "π2" with precedence 10 for @{ (proj2 ??) }.
59 (* Yeah, I probably ought to do something more general... *)
60 notation "hvbox(\langle term 19 a, break term 19 b, break term 19 c\rangle)"
61 with precedence 90 for @{ 'triple $a $b $c}.
62 interpretation "Triple construction" 'triple x y z = (mk_Prod ? ? (mk_Prod ? ? x y) z).
64 notation "hvbox(\langle term 19 a, break term 19 b, break term 19 c, break term 19 d\rangle)"
65 with precedence 90 for @{ 'quadruple $a $b $c $d}.
66 interpretation "Quadruple construction" 'quadruple w x y z = (mk_Prod ? ? (mk_Prod ? ? w x) (mk_Prod ? ? y z)).
69 theorem eq_pair_fst_snd: ∀A,B.∀p:A × B.
70 p = 〈 \fst p, \snd p 〉.
71 #A #B #p (cases p) // qed.
73 lemma fst_eq : ∀A,B.∀a:A.∀b:B. \fst 〈a,b〉 = a.
76 lemma snd_eq : ∀A,B.∀a:A.∀b:B. \snd 〈a,b〉 = b.
79 notation > "hvbox('let' 〈ident x,ident y〉 ≝ t 'in' s)"
81 for @{ match $t with [ mk_Prod ${ident x} ${ident y} ⇒ $s ] }.
83 notation < "hvbox('let' \nbsp hvbox(〈ident x,ident y〉 \nbsp≝ break t \nbsp 'in' \nbsp) break s)"
85 for @{ match $t with [ mk_Prod (${ident x}:$X) (${ident y}:$Y) ⇒ $s ] }.
87 (* Also extracts an equality proof (useful when not using Russell). *)
88 notation > "hvbox('let' 〈ident x,ident y〉 'as' ident E ≝ t 'in' s)"
90 for @{ match $t return λx.x = $t → ? with [ mk_Prod ${ident x} ${ident y} ⇒
91 λ${ident E}.$s ] (refl ? $t) }.
93 notation < "hvbox('let' \nbsp hvbox(〈ident x,ident y〉 \nbsp 'as'\nbsp ident E\nbsp ≝ break t \nbsp 'in' \nbsp) break s)"
95 for @{ match $t return λ${ident k}:$X.$eq $T $k $t → ? with [ mk_Prod (${ident x}:$U) (${ident y}:$W) ⇒
96 λ${ident E}:$e.$s ] ($refl $T $t) }.
98 notation > "hvbox('let' 〈ident x,ident y,ident z〉 'as' ident E ≝ t 'in' s)"
100 for @{ match $t return λx.x = $t → ? with [ mk_Prod ${fresh xy} ${ident z} ⇒
101 match ${fresh xy} return λx. ? = $t → ? with [ mk_Prod ${ident x} ${ident y} ⇒
102 λ${ident E}.$s ] ] (refl ? $t) }.
104 notation < "hvbox('let' \nbsp hvbox(〈ident x,ident y,ident z〉 \nbsp'as'\nbsp ident E\nbsp ≝ break t \nbsp 'in' \nbsp) break s)"
106 for @{ match $t return λ${ident x}.$eq $T $x $t → $U with [ mk_Prod (${fresh xy}:$V) (${ident z}:$Z) ⇒
107 match ${fresh xy} return λ${ident y}. $eq $R $r $t → ? with [ mk_Prod (${ident x}:$L) (${ident y}:$I) ⇒
108 λ${ident E}:$J.$s ] ] ($refl $A $t) }.
110 notation > "hvbox('let' 〈ident w,ident x,ident y,ident z〉 ≝ t 'in' s)"
112 for @{ match $t with [ mk_Prod ${fresh wx} ${fresh yz} ⇒ match ${fresh wx} with [ mk_Prod ${ident w} ${ident x} ⇒ match ${fresh yz} with [ pair ${ident y} ${ident z} ⇒ $s ] ] ] }.
114 notation > "hvbox('let' 〈ident x,ident y,ident z〉 ≝ t 'in' s)"
116 for @{ match $t with [ mk_Prod ${fresh xy} ${ident z} ⇒ match ${fresh xy} with [ mk_Prod ${ident x} ${ident y} ⇒ $s ] ] }.
118 (* This appears to upset automation (previously provable results require greater
119 depth or just don't work), so use example rather than lemma to prevent it
121 example contract_pair : ∀A,B.∀e:A×B. (let 〈a,b〉 ≝ e in 〈a,b〉) = e.
124 lemma extract_pair : ∀A,B,C,D. ∀u:A×B. ∀Q:A → B → C×D. ∀x,y.
125 ((let 〈a,b〉 ≝ u in Q a b) = 〈x,y〉) →
126 ∃a,b. 〈a,b〉 = u ∧ Q a b = 〈x,y〉.
127 #A #B #C #D * #a #b #Q #x #y normalize #E1 %{a} %{b} % try @refl @E1 qed.
129 lemma breakup_pair : ∀A,B,C:Type[0].∀x. ∀R:C → Prop. ∀P:A → B → C.
130 R (P (\fst x) (\snd x)) → R (let 〈a,b〉 ≝ x in P a b).
131 #A #B #C *; normalize /2/
134 (* Is this necessary?
140 ∀P: A×B → C → C' → Prop.
141 (∀lft, rgt. p = 〈lft,rgt〉 → P 〈lft,rgt〉 (T lft rgt) (T' lft rgt)) →
142 P p (let 〈lft, rgt〉 ≝ p in T lft rgt) (let 〈lft, rgt〉 ≝ p in T' lft rgt).
145 (* Useful for avoiding destruct's full normalization. *)
146 lemma pair_eq1: ∀A,B. ∀a1,a2:A. ∀b1,b2:B. 〈a1,b1〉 = 〈a2,b2〉 → a1 = a2.
147 #A #B #a1 #a2 #b1 #b2 #H destruct //
150 lemma pair_eq2: ∀A,B. ∀a1,a2:A. ∀b1,b2:B. 〈a1,b1〉 = 〈a2,b2〉 → b1 = b2.
151 #A #B #a1 #a2 #b1 #b2 #H destruct //
154 lemma pair_destruct_1:
155 ∀A,B.∀a:A.∀b:B.∀c. 〈a,b〉 = c → a = \fst c.
159 lemma pair_destruct_2:
160 ∀A,B.∀a:A.∀b:B.∀c. 〈a,b〉 = c → b = \snd c.