-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathEqualWithRelation.v
729 lines (656 loc) · 21.5 KB
/
EqualWithRelation.v
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
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
Require Import Coq.Strings.String.
Require Import PeanoNat.
Require Export SystemFR.SizeLemmas.
Require Export SystemFR.StarLemmas.
Require Export SystemFR.FVLemmasEval.
Open Scope list_scope.
Inductive equal_with_relation tag rel: tree -> tree -> Prop :=
| EWRTVar:
forall X X',
lookup PeanoNat.Nat.eq_dec rel X = Some X' ->
lookup PeanoNat.Nat.eq_dec (swap rel) X' = Some X ->
equal_with_relation tag rel (fvar X tag) (fvar X' tag)
| EWRFVar:
forall X tag',
tag <> tag' ->
equal_with_relation tag rel (fvar X tag') (fvar X tag')
| EWRLVar:
forall i tag',
equal_with_relation tag rel (lvar i tag') (lvar i tag')
| EWRNoTypeErr:
equal_with_relation tag rel notype_err notype_err
| EWRErr:
forall T1 T2,
equal_with_relation tag rel T1 T2 ->
equal_with_relation tag rel (err T1) (err T2)
| EWRUU:
equal_with_relation tag rel uu uu
| EWRTSize:
forall t t',
equal_with_relation tag rel t t' ->
equal_with_relation tag rel (tsize t) (tsize t')
| EWRNoTypeLambda:
forall t t',
equal_with_relation tag rel t t' ->
equal_with_relation tag rel (notype_lambda t) (notype_lambda t')
| EWRLambda:
forall T T' t t',
equal_with_relation tag rel T T' ->
equal_with_relation tag rel t t' ->
equal_with_relation tag rel (lambda T t) (lambda T' t')
| EWRApp:
forall t1 t1' t2 t2',
equal_with_relation tag rel t1 t1' ->
equal_with_relation tag rel t2 t2' ->
equal_with_relation tag rel (app t1 t2) (app t1' t2')
| EWRForallInst:
forall t1 t1' t2 t2',
equal_with_relation tag rel t1 t1' ->
equal_with_relation tag rel t2 t2' ->
equal_with_relation tag rel (forall_inst t1 t2) (forall_inst t1' t2')
| EWRPP:
forall t1 t1' t2 t2',
equal_with_relation tag rel t1 t1' ->
equal_with_relation tag rel t2 t2' ->
equal_with_relation tag rel (pp t1 t2) (pp t1' t2')
| EWRPi1:
forall t t',
equal_with_relation tag rel t t' ->
equal_with_relation tag rel (pi1 t) (pi1 t')
| EWRPi2:
forall t t',
equal_with_relation tag rel t t' ->
equal_with_relation tag rel (pi2 t) (pi2 t')
| EWRBecause:
forall t1 t1' t2 t2',
equal_with_relation tag rel t1 t1' ->
equal_with_relation tag rel t2 t2' ->
equal_with_relation tag rel (because t1 t2) (because t1' t2')
| EWRGetProof:
forall t1 t1' t2 t2',
equal_with_relation tag rel t1 t1' ->
equal_with_relation tag rel t2 t2' ->
equal_with_relation tag rel (get_refinement_witness t1 t2) (get_refinement_witness t1' t2')
| EWRTrue:
equal_with_relation tag rel ttrue ttrue
| EWRFalse:
equal_with_relation tag rel tfalse tfalse
| EWRIte:
forall t1 t1' t2 t2' t3 t3',
equal_with_relation tag rel t1 t1' ->
equal_with_relation tag rel t2 t2' ->
equal_with_relation tag rel t3 t3' ->
equal_with_relation tag rel (ite t1 t2 t3) (ite t1' t2' t3')
| EWRRecognizer:
forall r t t',
equal_with_relation tag rel t t' ->
equal_with_relation tag rel (boolean_recognizer r t) (boolean_recognizer r t')
| EWRZero:
equal_with_relation tag rel zero zero
| EWRSucc:
forall t t',
equal_with_relation tag rel t t' ->
equal_with_relation tag rel (succ t) (succ t')
| EWRMatch:
forall t1 t1' t2 t2' t3 t3',
equal_with_relation tag rel t1 t1' ->
equal_with_relation tag rel t2 t2' ->
equal_with_relation tag rel t3 t3' ->
equal_with_relation tag rel (tmatch t1 t2 t3) (tmatch t1' t2' t3')
| EWRUnaryPrimitive:
forall o t1 t1',
equal_with_relation tag rel t1 t1' ->
equal_with_relation tag rel (unary_primitive o t1) (unary_primitive o t1')
| EWRBinaryPrimitive:
forall o t1 t1' t2 t2',
equal_with_relation tag rel t1 t1' ->
equal_with_relation tag rel t2 t2' ->
equal_with_relation tag rel (binary_primitive o t1 t2) (binary_primitive o t1' t2')
| EWRNoTypeLet:
forall t1 t1' t2 t2',
equal_with_relation tag rel t1 t1' ->
equal_with_relation tag rel t2 t2' ->
equal_with_relation tag rel (notype_tlet t1 t2) (notype_tlet t1' t2')
| EWRLet:
forall T T' t1 t1' t2 t2',
equal_with_relation tag rel T T' ->
equal_with_relation tag rel t1 t1' ->
equal_with_relation tag rel t2 t2' ->
equal_with_relation tag rel (tlet t1 T t2) (tlet t1' T' t2')
| EWRRefl:
forall t1 t1' t2 t2',
equal_with_relation tag rel t1 t1' ->
equal_with_relation tag rel t2 t2' ->
equal_with_relation tag rel (trefl t1 t2) (trefl t1' t2')
| EWRTypeAbs:
forall t t',
equal_with_relation tag rel t t' ->
equal_with_relation tag rel (type_abs t) (type_abs t')
| EWRTypeInst:
forall t t' T T',
equal_with_relation tag rel T T' ->
equal_with_relation tag rel t t' ->
equal_with_relation tag rel (type_inst t T) (type_inst t' T')
| EWRFix:
forall t t' T T',
equal_with_relation tag rel T T' ->
equal_with_relation tag rel t t' ->
equal_with_relation tag rel (tfix T t) (tfix T' t')
| EWRNoTypeFix:
forall t t',
equal_with_relation tag rel t t' ->
equal_with_relation tag rel (notype_tfix t) (notype_tfix t')
| EWRFold:
forall t t' T T',
equal_with_relation tag rel T T' ->
equal_with_relation tag rel t t' ->
equal_with_relation tag rel (tfold T t) (tfold T' t')
| EWRUnfold:
forall t t',
equal_with_relation tag rel t t' ->
equal_with_relation tag rel (tunfold t) (tunfold t')
| EWRUnfoldIn:
forall t1 t1' t2 t2',
equal_with_relation tag rel t1 t1' ->
equal_with_relation tag rel t2 t2' ->
equal_with_relation tag rel (tunfold_in t1 t2) (tunfold_in t1' t2')
| EWRUnfoldPosIn:
forall t1 t1' t2 t2',
equal_with_relation tag rel t1 t1' ->
equal_with_relation tag rel t2 t2' ->
equal_with_relation tag rel (tunfold_pos_in t1 t2) (tunfold_pos_in t1' t2')
| EWRLeft:
forall t t',
equal_with_relation tag rel t t' ->
equal_with_relation tag rel (tleft t) (tleft t')
| EWRRight:
forall t t',
equal_with_relation tag rel t t' ->
equal_with_relation tag rel (tright t) (tright t')
| EWRSumMatch:
forall t1 t1' t2 t2' t3 t3',
equal_with_relation tag rel t1 t1' ->
equal_with_relation tag rel t2 t2' ->
equal_with_relation tag rel t3 t3' ->
equal_with_relation tag rel (sum_match t1 t2 t3) (sum_match t1' t2' t3')
| EWRTypeCheck:
forall t t' T T',
equal_with_relation tag rel t t' ->
equal_with_relation tag rel T T' ->
equal_with_relation tag rel (typecheck t T) (typecheck t' T')
| EWRUnit:
equal_with_relation tag rel T_unit T_unit
| EWRBool:
equal_with_relation tag rel T_bool T_bool
| EWRNat:
equal_with_relation tag rel T_nat T_nat
| EWRRefine:
forall t t' T T',
equal_with_relation tag rel T T' ->
equal_with_relation tag rel t t' ->
equal_with_relation tag rel (T_refine T t) (T_refine T' t')
| EWRTypeRefine:
forall A A' B B',
equal_with_relation tag rel A A' ->
equal_with_relation tag rel B B' ->
equal_with_relation tag rel (T_type_refine A B) (T_type_refine A' B')
| EWRProd:
forall A A' B B',
equal_with_relation tag rel A A' ->
equal_with_relation tag rel B B' ->
equal_with_relation tag rel (T_prod A B) (T_prod A' B')
| EWRArrow:
forall A A' B B',
equal_with_relation tag rel A A' ->
equal_with_relation tag rel B B' ->
equal_with_relation tag rel (T_arrow A B) (T_arrow A' B')
| EWRSum:
forall A A' B B',
equal_with_relation tag rel A A' ->
equal_with_relation tag rel B B' ->
equal_with_relation tag rel (T_sum A B) (T_sum A' B')
| EWRIntersection:
forall A A' B B',
equal_with_relation tag rel A A' ->
equal_with_relation tag rel B B' ->
equal_with_relation tag rel (T_intersection A B) (T_intersection A' B')
| EWRUnion:
forall A A' B B',
equal_with_relation tag rel A A' ->
equal_with_relation tag rel B B' ->
equal_with_relation tag rel (T_union A B) (T_union A' B')
| EWRTop:
equal_with_relation tag rel T_top T_top
| EWRBot:
equal_with_relation tag rel T_bot T_bot
| EWREqual:
forall t1 t1' t2 t2',
equal_with_relation tag rel t1 t1' ->
equal_with_relation tag rel t2 t2' ->
equal_with_relation tag rel (T_equiv t1 t2) (T_equiv t1' t2')
| EWRForall:
forall A A' B B',
equal_with_relation tag rel A A' ->
equal_with_relation tag rel B B' ->
equal_with_relation tag rel (T_forall A B) (T_forall A' B')
| EWRExists:
forall A A' B B',
equal_with_relation tag rel A A' ->
equal_with_relation tag rel B B' ->
equal_with_relation tag rel (T_exists A B) (T_exists A' B')
| EWRAbs:
forall T T',
equal_with_relation tag rel T T' ->
equal_with_relation tag rel (T_abs T) (T_abs T')
| EWRTRec:
forall n T0 Ts n' T0' Ts',
equal_with_relation tag rel n n' ->
equal_with_relation tag rel T0 T0' ->
equal_with_relation tag rel Ts Ts' ->
equal_with_relation tag rel (T_rec n T0 Ts) (T_rec n' T0' Ts')
.
#[export]
Hint Constructors equal_with_relation: equal_with_relation.
Lemma equal_with_relation_deterministic:
forall tag rel t t1,
equal_with_relation tag rel t t1 ->
forall t2,
equal_with_relation tag rel t t2 ->
t1 = t2.
Proof.
induction 1; inversion 1;
repeat step || instantiate_any; eauto with equal_with_relation.
Qed.
Ltac equal_with_relation_deterministic :=
match goal with
| H1: equal_with_relation ?tag ?rel ?t ?t1,
H2: equal_with_relation ?tag ?rel ?t ?t2 |- _ =>
pose proof (equal_with_relation_deterministic _ _ _ _ H1 _ H2); clear H1
end.
Lemma equal_with_erased_term1:
forall t1 t2 rel,
equal_with_relation type_var rel t1 t2 ->
is_erased_term t1 ->
t1 = t2.
Proof.
induction 1; steps.
Qed.
Lemma equal_with_erased_term2:
forall t1 t2 rel,
equal_with_relation type_var rel t1 t2 ->
is_erased_term t2 ->
t1 = t2.
Proof.
induction 1; steps.
Qed.
Ltac equal_with_erased :=
match goal with
| H1: equal_with_relation type_var ?rel ?t1 ?t2,
H2: is_erased_term ?t1 |- _ =>
poseNew (Mark t2 "is_erased");
unshelve epose proof (equal_with_erased_term1 t1 t2 rel H1 H2)
| H1: equal_with_relation type_var ?rel ?t1 ?t2,
H2: is_erased_term ?t2 |- _ =>
poseNew (Mark t1 "is_erased");
unshelve epose proof (equal_with_erased_term2 t1 t2 rel H1 H2)
end.
Lemma equal_with_relation_swap:
forall t1 t2 tag rel,
equal_with_relation tag rel t1 t2 ->
equal_with_relation tag (swap rel) t2 t1.
Proof.
induction 1; repeat step || rewrite swap_twice in * || constructor.
Qed.
Lemma equal_with_relation_refl:
forall t tag rel,
pfv t tag = nil ->
equal_with_relation tag rel t t.
Proof.
induction t; repeat step || list_utils || destruct_tag;
try solve [ unfold singleton in *; unfold add in *; steps ];
eauto 6 with equal_with_relation.
Qed.
Lemma equal_with_relation_refl2:
forall t tag rel,
(forall x, x ∈ pfv t tag -> lookup PeanoNat.Nat.eq_dec rel x = Some x) ->
(forall x, x ∈ pfv t tag -> lookup PeanoNat.Nat.eq_dec (swap rel) x = Some x) ->
equal_with_relation tag rel t t.
Proof.
induction t;
repeat light || destruct_match || constructor || list_utils || apply_any.
Qed.
Lemma equal_with_relation_topen:
forall tag rel t1 t2,
equal_with_relation tag rel t1 t2 ->
forall x y k,
(x ∈ pfv t1 tag -> False) ->
(y ∈ pfv t2 tag -> False) ->
equal_with_relation tag ((x,y) :: rel)
(topen k t1 (fvar x tag))
(topen k t2 (fvar y tag)).
Proof.
induction 1; repeat step || constructor || list_utils || apply_any.
Qed.
Lemma equal_with_relation_open:
forall tag rel t1 t2,
equal_with_relation tag rel t1 t2 ->
forall x y k,
(x ∈ pfv t1 tag -> False) ->
(y ∈ pfv t2 tag -> False) ->
equal_with_relation tag ((x,y) :: rel)
(open k t1 (fvar x tag))
(open k t2 (fvar y tag)).
Proof.
induction 1; repeat step || constructor || list_utils || apply_any.
Qed.
Lemma equal_with_relation_open2:
forall tag rel t1 t2,
equal_with_relation tag rel t1 t2 ->
forall k v1 v2,
equal_with_relation tag rel v1 v2 ->
equal_with_relation tag rel (open k t1 v1) (open k t2 v2).
Proof.
induction 1; repeat step; eauto 6 with equal_with_relation.
Qed.
Lemma equal_with_relation_size:
forall tag rel t1 t2,
equal_with_relation tag rel t1 t2 ->
type_nodes t1 = type_nodes t2.
Proof.
induction 1; steps.
Qed.
Lemma equal_with_relation_pfv:
forall T T' tag rel X,
equal_with_relation tag rel T T' ->
X ∈ pfv T tag ->
exists X',
X' ∈ pfv T' tag /\
lookup PeanoNat.Nat.eq_dec rel X = Some X' /\
lookup PeanoNat.Nat.eq_dec (swap rel) X' = Some X.
Proof.
induction 1;
repeat match goal with
| H1: equal_with_relation ?tag ?rel ?T ?T',
H2: ?X ∈ pfv ?T ?tag,
H3: forall _ _ _, _ -> _ -> _ |- _ => pose proof (H3 _ _ _ H1 H2); clear H3
| _ => step || list_utils || destruct_tag
end;
try solve [ eexists; repeat step || list_utils; eauto ].
Qed.
Ltac t_equal_with_relation_pfv :=
match goal with
| H1: equal_with_relation ?tag ?rel ?T ?T',
H2: ?X ∈ pfv ?T ?tag |- _ =>
poseNew (Mark H1 "equal_with_relation_pfv");
pose proof (equal_with_relation_pfv _ _ _ _ _ H1 H2)
end.
Lemma equal_with_relation_pfv2:
forall tag rel T T' X',
equal_with_relation tag rel T T' ->
X' ∈ pfv T' tag ->
exists X,
X ∈ pfv T tag /\
lookup PeanoNat.Nat.eq_dec rel X = Some X' /\
lookup PeanoNat.Nat.eq_dec (swap rel) X' = Some X.
Proof.
intros.
apply equal_with_relation_swap in H.
repeat step || t_equal_with_relation_pfv || eexists || rewrite swap_twice in *; eauto.
Qed.
Ltac t_equal_with_relation_pfv2 :=
match goal with
| H1: equal_with_relation ?tag ?rel ?T ?T',
H2: ?X ∈ pfv ?T' ?tag |- _ =>
poseNew (Mark H1 "equal_with_relation_pfv2");
pose proof (equal_with_relation_pfv2 _ _ _ _ _ H1 H2)
| _ => t_equal_with_relation_pfv
end.
Lemma equal_with_relation_pfv_nil:
forall T T' rel tag,
equal_with_relation tag rel T T' ->
pfv T tag = nil ->
pfv T' tag = nil.
Proof.
induction 1; repeat step || list_utils || unfold singleton, add in *.
Qed.
Lemma equal_with_relation_pfv_nil2:
forall T T' rel tag,
equal_with_relation tag rel T T' ->
pfv T' tag = nil ->
pfv T tag = nil.
Proof.
induction 1; repeat step || list_utils || unfold singleton, add in *.
Qed.
Ltac t_ewr_nil :=
match goal with
| H1: equal_with_relation ?tag ?rel ?T ?T',
H2: pfv ?T _ = nil |- _ =>
poseNew (Mark T' "ewr_nil");
pose proof (equal_with_relation_pfv_nil _ _ _ _ H1 H2)
| H1: equal_with_relation ?tag ?rel ?T ?T',
H2: pfv ?T' _ = nil |- _ =>
poseNew (Mark T "ewr_nil2");
pose proof (equal_with_relation_pfv_nil2 _ _ _ _ H1 H2)
end.
Lemma equal_with_relation_value:
forall tag rel v1 v2,
equal_with_relation tag rel v1 v2 ->
cbv_value v1 ->
cbv_value v2.
Proof.
induction 1; repeat step || step_inversion cbv_value;
eauto with values.
Qed.
Lemma equal_with_relation_value2:
forall tag rel v1 v2,
equal_with_relation tag rel v1 v2 ->
cbv_value v2 ->
cbv_value v1.
Proof.
induction 1; repeat step || step_inversion cbv_value;
eauto with values.
Qed.
Lemma equal_with_relation_build_nat:
forall n t rel tag,
equal_with_relation tag rel t (build_nat n) ->
t = build_nat n.
Proof.
induction n;
repeat steps || step_inversion equal_with_relation.
apply IHn in H2; steps.
Qed.
Lemma equal_with_relation_build_nat2:
forall n t rel tag,
equal_with_relation tag rel (build_nat n) t ->
t = build_nat n.
Proof.
induction n;
repeat steps || step_inversion equal_with_relation.
apply IHn in H1; steps.
Qed.
Ltac t_ewr_value :=
match goal with
| H1: equal_with_relation _ _ ?v ?v2, H2: cbv_value ?v |- _ =>
poseNew (Mark v2 "ewr_value");
pose proof (equal_with_relation_value _ _ _ _ H1 H2)
| H1: equal_with_relation _ _ ?v1 ?v, H2: cbv_value ?v |- _ =>
poseNew (Mark v1 "ewr_value");
pose proof (equal_with_relation_value2 _ _ _ _ H1 H2)
end.
Lemma equal_with_relation_tsize:
forall tag rel t1 t2,
equal_with_relation tag rel t1 t2 ->
tsize_semantics t1 = tsize_semantics t2.
Proof.
induction 1; steps.
Qed.
Lemma equal_with_relation_pair:
forall tag rel t1 t2,
equal_with_relation tag rel t1 t2 ->
is_pair t1 = is_pair t2.
Proof.
induction 1; steps.
Qed.
Lemma equal_with_relation_lambda:
forall tag rel t1 t2,
equal_with_relation tag rel t1 t2 ->
is_lambda t1 = is_lambda t2.
Proof.
induction 1; steps.
Qed.
Lemma equal_with_relation_succ:
forall tag rel t1 t2,
equal_with_relation tag rel t1 t2 ->
is_succ t1 = is_succ t2.
Proof.
induction 1; steps.
Qed.
Lemma equal_with_relation_nat:
forall tag rel n,
equal_with_relation tag rel (build_nat n) (build_nat n).
Proof.
induction n; repeat step || constructor.
Qed.
Lemma equal_with_relation_pair_refl:
forall tag rel t,
equal_with_relation tag rel (is_pair t) (is_pair t).
Proof.
destruct t; repeat step.
Qed.
Lemma equal_with_relation_succ_refl:
forall tag rel t,
equal_with_relation tag rel (is_succ t) (is_succ t).
Proof.
destruct t; repeat step.
Qed.
Lemma equal_with_relation_lambda_refl:
forall tag rel t,
equal_with_relation tag rel (is_lambda t) (is_lambda t).
Proof.
destruct t; repeat step.
Qed.
Lemma equal_with_relation_scbv_step:
forall tag rel t1 t2,
equal_with_relation tag rel t1 t2 ->
forall t1',
t1 ~> t1' ->
exists t2',
t2 ~> t2' /\
equal_with_relation tag rel t1' t2'.
Proof.
induction 1; inversion 1;
repeat step || t_ewr_nil || t_ewr_value || instantiate_any ||
step_inversion equal_with_relation ||
apply equal_with_relation_open2 ||
eapply_anywhere equal_with_relation_build_nat2 ||
(erewrite equal_with_relation_tsize by eauto) ||
(erewrite equal_with_relation_lambda by eauto) ||
(erewrite equal_with_relation_succ by eauto) ||
(erewrite equal_with_relation_pair by eauto) ||
(eexists; split; [ solve [ eauto with smallstep ] | idtac ]);
eauto with equal_with_relation;
eauto using equal_with_relation_nat with smallstep;
eauto using equal_with_relation_pair_refl with smallstep;
eauto using equal_with_relation_lambda_refl with smallstep;
eauto using equal_with_relation_succ_refl with smallstep.
Qed.
Ltac equal_with_relation_scbv_step :=
match goal with
| H1: equal_with_relation _ ?rel ?t1 ?t2, H2: ?t1 ~> ?t1' |- _ =>
poseNew (Mark (H1,H2) "ewr_scbv_step");
pose proof (equal_with_relation_scbv_step _ _ _ _ H1 _ H2)
end.
Lemma equal_with_relation_star:
forall t1 t1',
t1 ~>* t1' ->
forall tag rel t2,
equal_with_relation tag rel t1 t2 ->
exists t2',
t2 ~>* t2' /\
equal_with_relation tag rel t1' t2'.
Proof.
induction 1;
repeat match goal with
| _ => step || equal_with_relation_scbv_step
| H1: forall _ _ _, equal_with_relation _ _ _ _ -> _,
H2: equal_with_relation _ _ _ _ |- _ => apply H1 in H2
end; eauto with smallstep star.
Qed.
Lemma equal_with_relation_star2:
forall tag rel t1 t2 t2',
t2 ~>* t2' ->
equal_with_relation tag rel t1 t2 ->
exists t1',
t1 ~>* t1' /\
equal_with_relation tag rel t1' t2'.
Proof.
intros.
apply equal_with_relation_swap in H0.
eapply equal_with_relation_star in H0; try eassumption; steps.
eexists; split; eauto.
apply equal_with_relation_swap in H2;
repeat step || rewrite swap_twice in *.
Qed.
Ltac t_ewr_star :=
match goal with
| H1: equal_with_relation _ ?rel ?t1 ?t2, H2: ?t1 ~>* ?t1' |- _ =>
poseNew (Mark 0 "ewr_star");
pose proof (equal_with_relation_star _ _ _ H2 _ _ H1)
| H1: equal_with_relation _ ?rel ?t1 ?t2, H2: ?t2 ~>* ?t2' |- _ =>
poseNew (Mark 0 "ewr_star");
pose proof (equal_with_relation_star2 _ _ _ _ _ H2 H1)
end.
Ltac equal_with_relation_scbv_step_back :=
match goal with
| H1: equal_with_relation _ ?rel ?t1 ?t2, H2: ?t2 ~> ?t2' |- _ =>
poseNew (Mark (H1,H2) "ewr_scbv_step");
unshelve epose proof (equal_with_relation_scbv_step _ (swap rel) t2 t1 _ _ H2);
eauto using equal_with_relation_swap
end.
Lemma equal_with_relation_irred:
forall tag rel T1 T2,
equal_with_relation tag rel T1 T2 ->
irred T1 ->
irred T2.
Proof.
unfold irred; repeat step || equal_with_relation_scbv_step_back;
eauto.
Qed.
Lemma equal_with_relation_irred_back:
forall tag rel T1 T2,
equal_with_relation tag rel T1 T2 ->
irred T2 ->
irred T1.
Proof.
intros; eauto using equal_with_relation_irred, equal_with_relation_swap.
Qed.
Lemma equal_with_relation_erased_term:
forall tag rel t1 t2,
equal_with_relation tag rel t1 t2 ->
is_erased_term t1 ->
is_erased_term t2.
Proof.
induction 1; steps.
Qed.
Lemma equal_with_relation_erased_type:
forall tag rel T1 T2,
equal_with_relation tag rel T1 T2 ->
is_erased_type T1 ->
is_erased_type T2.
Proof.
induction 1; steps; eauto using equal_with_relation_erased_term.
Qed.
Lemma equal_with_relation_erased_type_back:
forall tag rel T1 T2,
equal_with_relation tag rel T1 T2 ->
is_erased_type T2 ->
is_erased_type T1.
Proof.
eauto using equal_with_relation_swap, equal_with_relation_erased_type.
Qed.
#[export]
Hint Immediate equal_with_relation_erased_term: erased.
#[export]
Hint Immediate equal_with_relation_erased_type: erased.
#[export]
Hint Immediate equal_with_relation_erased_type_back: erased.