summaryrefslogtreecommitdiff
path: root/theories7/Wellfounded/Lexicographic_Exponentiation.v
blob: 17f6d6502fa2dc763c6a9a2963819edaf5f107b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
(************************************************************************)
(*  v      *   The Coq Proof Assistant  /  The Coq Development Team     *)
(* <O___,, * CNRS-Ecole Polytechnique-INRIA Futurs-Universite Paris Sud *)
(*   \VV/  **************************************************************)
(*    //   *      This file is distributed under the terms of the       *)
(*         *       GNU Lesser General Public License Version 2.1        *)
(************************************************************************)

(*i $Id: Lexicographic_Exponentiation.v,v 1.1.2.1 2004/07/16 19:31:41 herbelin Exp $ i*)

(** Author: Cristina Cornes

    From : Constructing Recursion Operators in Type Theory                
           L. Paulson  JSC (1986) 2, 325-355  *)

Require Eqdep.
Require PolyList.
Require PolyListSyntax.
Require Relation_Operators.
Require Transitive_Closure.

Section Wf_Lexicographic_Exponentiation.
Variable A:Set.
Variable leA: A->A->Prop.

Notation Power := (Pow A leA).
Notation Lex_Exp := (lex_exp A leA).
Notation ltl := (Ltl A leA).
Notation Descl := (Desc A leA).

Notation List := (list A).
Notation Nil := (nil A).
(* useless but symmetric *)
Notation Cons := (cons 1!A).
Notation "<< x , y >>" := (exist List Descl x y) (at level 0)
  V8only (at level 0, x,y at level 100).

V7only[
Syntax constr
  level 1:
    List [ (list A) ] -> ["List"]
  | Nil  [ (nil A) ] -> ["Nil"]
  | Cons [ (cons A) ] -> ["Cons"]
  ;
  level 10:
    Cons2 [ (cons A $e $l) ] -> ["Cons " $e:L " " $l:L ].

Syntax constr
  level 1:
  pair_sig [ (exist (list A) Desc $e $d) ] -> ["<<" $e:L "," $d:L ">>"].
].
Hints Resolve d_one d_nil  t_step.

Lemma left_prefix : (x,y,z:List)(ltl x^y z)-> (ltl x z).
Proof.
 Induction x.
 Induction z.
 Simpl;Intros H.
 Inversion_clear H. 
 Simpl;Intros;Apply (Lt_nil A leA).
 Intros a l HInd.
 Simpl.
 Intros.
 Inversion_clear H.
 Apply (Lt_hd A leA);Auto with sets.
 Apply (Lt_tl A leA).
 Apply (HInd y y0);Auto with sets.
Qed.


Lemma  right_prefix : 
  (x,y,z:List)(ltl x y^z)-> (ltl x y) \/ (EX y':List | x=(y^y') /\ (ltl y' z)).
Proof.
 Intros x y;Generalize x.
 Elim y;Simpl.
 Right.
 Exists x0 ;Auto with sets.
 Intros.
 Inversion H0.
 Left;Apply (Lt_nil A leA).
 Left;Apply (Lt_hd A leA);Auto with sets.
 Generalize (H x1 z H3) .
 Induction 1.
 Left;Apply (Lt_tl A leA);Auto with sets.
 Induction 1.
 Induction 1;Intros.
 Rewrite -> H8.
 Right;Exists x2 ;Auto with sets.
Qed.



Lemma desc_prefix: (x:List)(a:A)(Descl x^(Cons a Nil))->(Descl x).
Proof.
 Intros.
 Inversion H.
 Generalize (app_cons_not_nil H1); Induction 1. 
 Cut (x^(Cons a Nil))=(Cons x0 Nil); Auto with sets.
 Intro.
 Generalize (app_eq_unit H0) .
 Induction 1; Induction 1; Intros.
 Rewrite -> H4; Auto with sets.
 Discriminate H5.
 Generalize (app_inj_tail H0) .
 Induction 1; Intros.
 Rewrite <- H4; Auto with sets.
Qed.

Lemma desc_tail: (x:List)(a,b:A)
          (Descl (Cons b (x^(Cons a Nil))))-> (clos_trans A leA a b).
Proof.
 Intro.
 Apply rev_ind with  A:=A
             P:=[x:List](a,b:A)
          (Descl (Cons b (x^(Cons a Nil))))-> (clos_trans A leA a b).
 Intros.

 Inversion  H.
 Cut (Cons b (Cons a Nil))= ((Nil^(Cons b Nil))^ (Cons a Nil)); Auto with sets; Intro.
 Generalize H0.
 Intro.
 Generalize (app_inj_tail 2!(l^(Cons y Nil)) 3!(Nil^(Cons b Nil)) H4);
 Induction 1.
 Intros.

 Generalize (app_inj_tail H6); Induction 1; Intros.
 Generalize H1.
 Rewrite <- H10; Rewrite <- H7; Intro.
 Apply (t_step A leA); Auto with sets.



 Intros.
 Inversion H0.
 Generalize  (app_cons_not_nil H3); Intro.
 Elim H1.

 Generalize H0.
 Generalize (app_comm_cons (l^(Cons x0 Nil)) (Cons a Nil) b); Induction 1.
 Intro.
 Generalize (desc_prefix (Cons b (l^(Cons x0 Nil))) a H5); Intro.
 Generalize (H x0 b H6).
 Intro.
 Apply t_trans with A:=A  y:=x0; Auto with sets.

 Apply  t_step.
 Generalize H1.
 Rewrite -> H4; Intro.

 Generalize (app_inj_tail H8); Induction 1.
 Intros.
 Generalize H2; Generalize (app_comm_cons l (Cons x0 Nil) b).
 Intro.
 Generalize H10.
 Rewrite ->H12; Intro.
 Generalize (app_inj_tail H13); Induction 1.
 Intros.
 Rewrite <- H11; Rewrite <- H16; Auto with sets.
Qed.


Lemma dist_aux : (z:List)(Descl z)->(x,y:List)z=(x^y)->(Descl x)/\ (Descl y).
Proof.
 Intros z D.
 Elim D.
 Intros.
 Cut (x^y)=Nil;Auto with sets; Intro.
 Generalize (app_eq_nil H0) ; Induction 1.
 Intros.
 Rewrite -> H2;Rewrite -> H3; Split;Apply d_nil.

 Intros.
 Cut (x0^y)=(Cons x Nil); Auto with sets.
 Intros E.
 Generalize (app_eq_unit E); Induction 1.
 Induction 1;Intros.
 Rewrite -> H2;Rewrite -> H3; Split.
 Apply d_nil.

 Apply d_one.

 Induction 1; Intros.
 Rewrite -> H2;Rewrite -> H3; Split.
 Apply d_one.

 Apply d_nil.

 Do 5 Intro.
 Intros Hind.
 Do 2 Intro.
 Generalize x0 .
 Apply rev_ind with A:=A 
      P:=[y0:List]
          (x0:List)
          ((l^(Cons y Nil))^(Cons x Nil))=(x0^y0)->(Descl x0)/\(Descl y0).

 Intro.
 Generalize (app_nil_end x1) ; Induction 1; Induction 1.
 Split. Apply d_conc; Auto with sets.

 Apply d_nil.

 Do 3 Intro.
 Generalize x1 .
 Apply rev_ind with 
  A:=A 
  P:=[l0:List]
     (x1:A)
      (x0:List)
       ((l^(Cons y Nil))^(Cons x Nil))=(x0^(l0^(Cons x1 Nil)))
         ->(Descl x0)/\(Descl (l0^(Cons x1 Nil))).


 Simpl.
 Split.
 Generalize (app_inj_tail H2) ;Induction 1.
 Induction 1;Auto with sets.

 Apply d_one.
 Do 5 Intro.
 Generalize (app_ass x4 (l1^(Cons x2 Nil)) (Cons x3 Nil)) .
 Induction 1.
 Generalize (app_ass x4 l1 (Cons x2 Nil)) ;Induction 1.
 Intro E.
 Generalize (app_inj_tail E) .
 Induction 1;Intros.
 Generalize (app_inj_tail H6) ;Induction 1;Intros.
 Rewrite <- H7;  Rewrite <- H10; Generalize H6.
 Generalize (app_ass x4 l1 (Cons x2 Nil)); Intro E1.
 Rewrite -> E1.
 Intro.
 Generalize (Hind x4 (l1^(Cons x2 Nil))  H11) .
 Induction 1;Split.
 Auto with sets.

 Generalize H14.
 Rewrite <- H10; Intro.
 Apply d_conc;Auto with sets.
Qed.



Lemma dist_Desc_concat : (x,y:List)(Descl x^y)->(Descl x)/\(Descl y).
Proof.
  Intros.
  Apply (dist_aux (x^y) H x y); Auto with sets.
Qed.


Lemma desc_end:(a,b:A)(x:List) 
   (Descl x^(Cons a Nil)) /\ (ltl x^(Cons a Nil) (Cons b Nil))
     -> (clos_trans A leA a b). 

Proof.
 Intros a b x.
 Case x.
 Simpl.
 Induction 1.
 Intros.
 Inversion H1;Auto with sets.
 Inversion H3.

 Induction 1.
 Generalize (app_comm_cons l (Cons a Nil) a0).
 Intros E; Rewrite <- E; Intros.
 Generalize (desc_tail l a a0 H0); Intro.
 Inversion H1.
 Apply t_trans with y:=a0 ;Auto with sets.

 Inversion H4.
Qed.




Lemma  ltl_unit: (x:List)(a,b:A)
 (Descl (x^(Cons a Nil))) -> (ltl x^(Cons a Nil) (Cons b Nil))
               -> (ltl x (Cons b Nil)).
Proof.
 Intro.
 Case x.
 Intros;Apply (Lt_nil A leA).

 Simpl;Intros.
 Inversion_clear H0.
 Apply (Lt_hd A leA  a b);Auto with sets.
 
 Inversion_clear H1.
Qed.


Lemma acc_app: 
    (x1,x2:List)(y1:(Descl x1^x2))
     (Acc Power Lex_Exp (exist List Descl (x1^x2)  y1))
     ->(x:List)
        (y:(Descl x))
         (ltl x (x1^x2))->(Acc Power Lex_Exp (exist List Descl x y)).
Proof.
 Intros.
 Apply (Acc_inv Power Lex_Exp (exist List Descl (x1^x2) y1)).
 Auto with sets.

 Unfold lex_exp ;Simpl;Auto with sets.
Qed.


Theorem wf_lex_exp :
  (well_founded A leA)->(well_founded Power Lex_Exp).
Proof.
 Unfold 2 well_founded .
 Induction a;Intros x y.
 Apply Acc_intro.
 Induction y0.
 Unfold 1 lex_exp ;Simpl.
 Apply rev_ind with A:=A P:=[x:List]
                            (x0:List)
                             (y:(Descl x0))
                              (ltl x0 x)
                               ->(Acc Power Lex_Exp (exist List Descl x0 y)) .
 Intros.
 Inversion_clear H0.

 Intro.
 Generalize (well_founded_ind A (clos_trans A leA) (wf_clos_trans A leA H)).
 Intros GR.
 Apply GR with P:=[x0:A]
                  (l:List)
                   ((x1:List)
                     (y:(Descl x1))
                      (ltl x1 l)
                       ->(Acc Power Lex_Exp (exist List Descl x1 y)))
                    ->(x1:List)
                       (y:(Descl x1))
                        (ltl x1 (l^(Cons x0 Nil)))
                         ->(Acc Power Lex_Exp (exist List Descl x1 y)) .
 Intro;Intros HInd; Intros.
 Generalize (right_prefix x2 l (Cons x1 Nil) H1) .
 Induction 1.
 Intro; Apply (H0 x2 y1 H3).

 Induction 1.
 Intro;Induction 1.
 Clear  H4  H2.
 Intro;Generalize y1 ;Clear  y1.
 Rewrite -> H2.
 Apply rev_ind with A:=A P:=[x3:List]
                            (y1:(Descl (l^x3)))
                             (ltl x3 (Cons x1 Nil))
                              ->(Acc Power Lex_Exp
                                  (exist List Descl (l^x3) y1)) .
 Intros.
 Generalize (app_nil_end l) ;Intros Heq.
 Generalize y1 .
 Clear  y1.
 Rewrite <- Heq.
 Intro.
 Apply Acc_intro.
 Induction y2.
 Unfold 1 lex_exp .
 Simpl;Intros x4 y3. Intros.
 Apply (H0 x4 y3);Auto with sets.

 Intros. 
 Generalize (dist_Desc_concat l (l0^(Cons x4 Nil)) y1) .
 Induction 1.
 Intros.
 Generalize (desc_end x4 x1 l0  (conj ? ? H8 H5)) ; Intros.
 Generalize y1 .
 Rewrite <- (app_ass l l0 (Cons x4 Nil)); Intro.
 Generalize (HInd x4 H9 (l^l0)) ; Intros HInd2.
 Generalize (ltl_unit l0 x4 x1 H8 H5); Intro.
 Generalize (dist_Desc_concat (l^l0) (Cons x4 Nil) y2) .
 Induction 1;Intros.
 Generalize (H4 H12 H10); Intro.
 Generalize (Acc_inv Power Lex_Exp (exist List Descl (l^l0) H12) H14) .
 Generalize (acc_app l l0 H12 H14).
 Intros f g.
 Generalize (HInd2 f);Intro.
 Apply Acc_intro.
 Induction y3.
 Unfold 1 lex_exp ;Simpl; Intros.
 Apply H15;Auto with sets.
Qed.


End Wf_Lexicographic_Exponentiation.