1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| The HELM team. *)
8 (* ||A|| http://helm.cs.unibo.it *)
10 (* \ / This file is distributed under the terms of the *)
11 (* v GNU General Public License Version 2 *)
13 (**************************************************************************)
15 include "pts_dummy/ext.ma".
17 (* ARITIES ********************************************************************)
19 (* An arity is a normal term representing the functional structure of a term.
20 * Arities can be freely applied as lon as the result is typable in λ→.
21 * we encode an arity with a family of meta-linguistic functions typed by λ→
22 * Such a family contains one member for each type of λ→
25 (* type of arity members ******************************************************)
27 (* the type of an arity member *)
28 inductive MEM: Type[0] ≝
30 | FUN: MEM → MEM → MEM
33 definition pred ≝ λC. match C with
38 definition decidable_MEq: ∀C1,C2:MEM. (C1 = C2) + (C1 ≠ C2).
42 | #B2 #A2 #_ #_ @inr @nmk #false destruct
44 | #B1 #A1 #IHB1 #IHA1 #C2 elim C2 -C2
45 [ @inr @nmk #false destruct
46 | #B2 #A2 #_ #_ elim (IHB1 B2) -IHB1 #HB
47 [ elim (IHA1 A2) - IHA1 #HA
48 [ /2/ | @inr @nmk #false destruct elim HA /2/ ]
49 | @inr @nmk #false destruct elim HB /2/
53 lemma fun_neq_sym: ∀A,C,B. pred C ≠ A → C ≠ FUN B A.
54 #A #C #B #HA elim HA -HA #HA @nmk #H @HA -HA >H //
57 (* arity members **************************************************************)
59 (* the arity members of type TOP *)
60 inductive Top: Type[0] ≝
64 (* the arity members of type A *)
65 let rec Mem A ≝ match A with
67 | FUN B A ⇒ Mem B → Mem A
70 (* the members of the arity "sort" *)
71 let rec sort_mem A ≝ match A return λA. Mem A with
73 | FUN B A ⇒ λ_.sort_mem A
76 (* arities ********************************************************************)
78 (* the type of arities *)
79 definition Arity ≝ ∀A. Mem A.
81 (* the arity "sort" *)
82 definition sort ≝ λA. sort_mem A.
84 (* the arity "constant" *)
85 definition const: ∀B. Mem B → Arity.
86 #B #x #A. elim (decidable_MEq B A) #H [ elim H @x | @(sort_mem A) ]
89 (* application of arities *)
90 definition aapp: MEM → Arity → Arity → Arity ≝ λB,a,b,C. a (FUN B C) (b B).
92 (* abstraction of arities *)
93 definition aabst: (Arity → Arity) → Arity ≝
94 λf,C. match C return λC. Mem C with
96 | FUN B A ⇒ λx. f (const B x) A
99 (* extensional equality of arity members **************************************)
101 (* Extensional equality of arity members (extensional equalty of functions).
102 * The functions may not respect extensional equality so reflexivity fails
103 * in general but may hold for specific arity members.
105 let rec ameq A ≝ match A return λA. Mem A → Mem A → Prop with
106 [ TOP ⇒ λa1,a2. a1 = a2
107 | FUN B A ⇒ λa1,a2. ∀b1,b2. ameq B b1 b2 → ameq A (a1 b1) (a2 b2)
111 "extensional equality (arity member)"
112 'Eq1 A a1 a2 = (ameq A a1 a2).
114 (* reflexivity of extensional equality for an arity member *)
115 definition invariant_mem ≝ λA,m. m ≅^A m.
118 "invariance (arity member)"
119 'Invariant1 a A = (invariant_mem A a).
123 "invariance (arity member with implicit type)"
124 'Invariant a = (invariant_mem ? a).
126 lemma symmetric_ameq: ∀A. symmetric ? (ameq A).
130 lemma transitive_ameq: ∀A. transitive ? (ameq A).
134 lemma invariant_sort_mem: ∀A. ! sort_mem A.
135 #A elim A normalize //
138 axiom const_eq: ∀A,x. const A x A ≅^A x.
140 axiom const_neq: ∀A,B,x. A ≠ B → const A x B ≅^B (sort_mem B).
142 (* extensional equality of arities ********************************************)
144 definition aeq: Arity → Arity → Prop ≝ λa1,a2. ∀A. a1 A ≅^A a2 A.
147 "extensional equality (arity)"
148 'Eq a1 a2 = (aeq a1 a2).
150 definition invariant: Arity → Prop ≝ λa. a ≅ a.
154 'Invariant a = (invariant a).
156 lemma symmetric_aeq: symmetric … aeq.
159 lemma transitive_aeq: transitive … aeq.
162 lemma const_comp: ∀A,x1,x2. x1 ≅^A x2 → const … x1 ≅ const … x2.
163 #A #x1 #x2 #Hx #C elim (decidable_MEq A C) #H
164 [ <H @transitive_ameq; [2: @const_eq | skip ]
165 @transitive_ameq; [2: @Hx | skip ]
167 | @transitive_ameq; [2: @(const_neq … H) | skip ]
168 @transitive_ameq; [2: @invariant_sort_mem | skip ]
173 lemma aapp_comp: ∀C,a1,a2,b1,b2. a1 ≅ a2 → b1 ≅ b2 → aapp C a1 b1 ≅ aapp C a2 b2.
174 #C #a1 #a2 #b1 #b2 #Ha #Hb #D @(Ha (FUN C D)) //
177 lemma aabst_comp: ∀f1,f2. (∀a1,a2. a1 ≅ a2 → f1 a1 ≅ f2 a2) →
179 #f1 #f2 #H #C elim C -C // #B #A #_ #_ #b1 #b2 #Hb @H /2/
182 lemma invariant_sort: ! sort.
186 (* "is a constant arity" *)
187 definition isc ≝ λa,A. const ? (a A) ≅ a.
189 lemma isc_sort: ∀A. isc sort A.
190 #A #C elim (decidable_MEq A C) #H [ <H // | /2 by const_neq/ ].
193 lemma isc_aapp: ∀B,A,b,a. ! b B → isc a A → isc (aapp B a b) (pred A).
194 #B #A #b #a #Hb #Ha #C elim (decidable_MEq (pred A) C) #H [ >H // ]
195 @transitive_ameq; [2: @(const_neq … H) | skip ]
196 lapply (transitive_ameq ????? (Ha (FUN B C))) -Ha [3: #Ha @Ha // |2: skip ]
197 @symmetric_ameq @const_neq /2/
200 (* extensional equality of arity contexts *************************************)
202 definition aceq ≝ λE1,E2. all2 … aeq E1 E2.
205 "extensional equality (arity context)"
206 'Eq E1 E2 = (aceq E1 E2).
208 definition invariant_env: list Arity → Prop ≝ λE. E ≅ E.
211 "invariance (arity context)"
212 'Invariant E = (invariant_env E).
214 lemma symmetric_aceq: symmetric … aceq.
217 lemma nth_sort_comp: ∀E1,E2. E1 ≅ E2 →
218 ∀i. nth i ? E1 sort ≅ nth i ? E2 sort.
219 #E1 #E2 #H #i @(all2_nth … aeq) //