Skip to content

Commit 54f9e9f

Browse files
committed
fix errors with rasimpl
1 parent 8f1f508 commit 54f9e9f

File tree

17 files changed

+182
-190
lines changed

17 files changed

+182
-190
lines changed

theories/AutoSubst/AstRasimpl.v

Lines changed: 64 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -224,18 +224,6 @@ Fixpoint apply_subst (s : quoted_subst) (n : quoted_nat) : quoted_term :=
224224
| qsubst_wk r, n => qatom (tRel (unquote_nat (apply_ren (quoted_wk_to_quoted_ren (unpack_quoted_wk r)) n)))
225225
end.
226226

227-
Definition eval_ren_term r t :=
228-
match t with
229-
| qsubst s t => qsubst (qsubst_comp (qsubst_ren r) s) t
230-
| qren r' t => qren (qren_comp r r') t
231-
| qwk r' t => qren (qren_comp r (quoted_wk_to_quoted_ren (unpack_quoted_wk r'))) t
232-
| qatom _ =>
233-
match test_qren_id r with
234-
| is_qren_id => t
235-
| not_qren_id r => qren r t
236-
end
237-
end.
238-
239227
Definition eval_subst_compr s r :=
240228
match eval_subst_compr_c s r with
241229
| esr_id_l r => qsubst_ren r
@@ -259,6 +247,18 @@ Definition eval_subst_rcomp r s :=
259247
| ers_other r s => qsubst_rcomp r s
260248
end.
261249

250+
Definition eval_ren_term r t :=
251+
match t with
252+
| qsubst s t => qsubst (eval_subst_rcomp r s) t
253+
| qren r' t => qren (eval_ren (qren_comp r r')) t
254+
| qwk r' t => qren (eval_ren (qren_comp r (quoted_wk_to_quoted_ren (unpack_quoted_wk r')))) t
255+
| qatom _ =>
256+
match test_qren_id r with
257+
| is_qren_id => t
258+
| not_qren_id r => qren r t
259+
end
260+
end.
261+
262262
Fixpoint eval_subst (s : quoted_subst) : quoted_subst :=
263263
match s with
264264
| qsubst_comp u v =>
@@ -412,21 +412,6 @@ Proof.
412412
end; intros [=].
413413
Qed.
414414

415-
Lemma eval_ren_term_sound {r t} :
416-
unquote_term t = unquote_term (eval_term t) ->
417-
ren_term (unquote_ren r) (unquote_term t) = unquote_term (eval_ren_term (eval_ren r) (eval_term t)).
418-
Proof.
419-
intros eval_term_sound.
420-
rewrite eval_ren_sound, eval_term_sound.
421-
unfold eval_ren_term; cbn.
422-
remember (eval_term _) as et eqn:e in *; destruct et; cbn.
423-
+ remember (eval_ren _) as rr eqn:er; destruct test_qren_id.
424-
* cbn; now asimpl.
425-
* subst. now cbn.
426-
+ now rewrite renRen_term.
427-
+ destruct (eval_term_no_qwk _ _ (symmetry e)).
428-
+ now rewrite rinstInst'_term, substSubst_term.
429-
Qed.
430415

431416
Lemma eval_subst_compr_sound r es :
432417
unquote_ren r >> unquote_subst es =1 unquote_subst (eval_subst_compr es (eval_ren r)).
@@ -481,6 +466,24 @@ Proof.
481466
intro. rewrite eval_ren_sound. reflexivity.
482467
Qed.
483468

469+
Lemma eval_ren_term_sound {r t} :
470+
unquote_term t = unquote_term (eval_term t) ->
471+
ren_term (unquote_ren r) (unquote_term t) = unquote_term (eval_ren_term (eval_ren r) (eval_term t)).
472+
Proof.
473+
intros eval_term_sound.
474+
rewrite eval_ren_sound, eval_term_sound.
475+
unfold eval_ren_term.
476+
remember (eval_term _) as et eqn:e in *; destruct et.
477+
+ cbn; remember (eval_ren _) as rr eqn:er; destruct test_qren_id.
478+
* cbn; now asimpl.
479+
* subst. now cbn.
480+
+ cbn -[eval_ren].
481+
rewrite <-(eval_ren_sound (qren_comp _ _)).
482+
cbn; now rewrite renRen_term.
483+
+ destruct (eval_term_no_qwk _ _ (symmetry e)).
484+
+ cbn -[eval_subst_rcomp].
485+
now rewrite <- eval_subst_rcomp_sound, substRen_term, <-eval_ren_sound.
486+
Qed.
484487

485488
Fixpoint eval_subst_sound s :
486489
pointwise_relation _ eq (unquote_subst s) (unquote_subst (eval_subst s))
@@ -667,6 +670,22 @@ with quote_term t :=
667670
| _ => constr:(qatom t)
668671
end.
669672

673+
674+
(** Results markings *)
675+
676+
Definition subst_term' := subst_term.
677+
Definition ren_term' := ren_term.
678+
679+
Ltac mark_result t :=
680+
lazymatch t with
681+
| subst_term ?σ ?t => constr:(subst_term' σ t)
682+
| ren_term ?ρ ?t => constr:(ren_term' ρ t)
683+
| _ => t
684+
end.
685+
686+
Hint Unfold subst_term' : asimpl_post_unfold.
687+
Hint Unfold ren_term' : asimpl_post_unfold.
688+
670689
(** Unfoldings **)
671690

672691
#[export] Hint Unfold
@@ -689,7 +708,7 @@ Declare Reduction asimpl_cbn_term :=
689708
unquote_subst eval_subst eval_subst_compr_c eval_subst_comp_c
690709
eval_subst_rcomp_c apply_subst quoted_wk_to_quoted_ren
691710
unquote_nat dfst dsnd unpack_quoted_wk unquote_wk pack_quoted_wk
692-
ren_term subst_term scons
711+
ren_term subst_term ren_term' subst_term' scons
693712
eval_subst_compr eval_subst_rcomp
694713
].
695714

@@ -700,7 +719,11 @@ Declare Reduction asimpl_unfold_term :=
700719
let q := quote_term t in
701720
let s := eval asimpl_cbn_term in (unquote_term (eval_term q)) in
702721
let s := eval asimpl_unfold_term in s in
703-
exact (MkSimplTm t s (eval_term_sound q))
722+
first [
723+
constr_eq_strict t s ;
724+
let s := mark_result s in
725+
exact (MkSimplTm t s eq_refl) |
726+
exact (MkSimplTm t s (eval_term_sound q)) ]
704727
: typeclass_instances.
705728

706729
Class SubstSimplification (r s : nat -> term) := MkSimplSubst {
@@ -712,20 +735,19 @@ Arguments autosubst_simpl_csubst r {s _}.
712735
Hint Mode SubstSimplification + - : typeclass_instances.
713736

714737
#[export] Hint Extern 10 (SubstSimplification ?r _) =>
738+
let r := eval unfold subst_term', ren_term' in r in
715739
let q := quote_subst r in
716740
let s := eval asimpl_cbn_term in (unquote_subst (eval_subst q)) in
717741
let s := eval asimpl_unfold_term in s in
718742
exact (MkSimplSubst r s (eval_subst_sound q))
719743
: typeclass_instances.
720744

721745

722-
723-
Lemma autosubst_simpl_term_wk :
724-
forall Γ Δ r t s,
725-
TermSimplification (@Ren1_well_wk _ _ ren_term Γ Δ r t) s ->
726-
@Ren1_well_wk _ _ ren_term Γ Δ r t = s.
746+
Lemma autosubst_simpl_term_wk Γ Δ r t s :
747+
TermSimplification (@Ren1_well_wk Γ Δ r t) s ->
748+
@Ren1_well_wk Γ Δ r t = s.
727749
Proof.
728-
intros Γ Δ r t s H.
750+
intros H.
729751
apply autosubst_simpl_term, _.
730752
Qed.
731753

@@ -788,8 +810,12 @@ Ltac debug_term_simplification_hint :=
788810
let q0 := fresh "q" in pose (q0 := q) ;
789811
let s := eval asimpl_cbn_term in (unquote_term (eval_term q)) in
790812
let s := eval asimpl_unfold_term in s in
791-
let s0 := fresh "s" in pose (s0 := s) ;
792-
let result0 := fresh "res" in
793-
try pose (result0 := MkSimplTm t s (eval_term_sound q))
813+
first [
814+
constr_eq_strict t s ;
815+
let s := mark_result s in
816+
let result0 := fresh "res" in
817+
try pose (result0 := MkSimplTm t s eq_refl) |
818+
let result0 := fresh "res" in
819+
try pose (result0 := MkSimplTm t s (eval_term_sound q)) ]
794820
end.
795821

theories/AutoSubst/Extra.v

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ Notation arr A B := (tProd A B⟨↑⟩).
6262
Notation comp A f g := (tLambda A (tApp f⟨↑⟩ (tApp g⟨↑⟩ (tRel 0)))).
6363
Notation idterm A := (tLambda A (tRel 0)).
6464

65+
Definition elimSuccHypTy P :=
66+
tProd tNat (arr P P[tSucc (tRel 0)]⇑).
67+
68+
6569

6670
Equations Derive NoConfusion EqDec for sort.
6771
Equations Derive NoConfusion Subterm EqDec for term.

theories/AutoSubst/RAsimpl.v

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ Ltac quote_ren r :=
218218
**)
219219

220220
Create HintDb asimpl_unfold.
221+
Create HintDb asimpl_post_unfold.
221222

222223
(* Common *)
223224
#[export] Hint Unfold
@@ -288,7 +289,8 @@ Ltac rasimpl'_outermost :=
288289
Ltac rasimpl :=
289290
aunfold ;
290291
repeat rasimpl' ;
291-
repeat rasimpl'_outermost.
292+
repeat rasimpl'_outermost;
293+
autounfold with asimpl_post_unfold.
292294

293295
(* Taken from core.minimize *)
294296
Ltac minimize_in h :=

theories/Decidability/Completeness.v

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ Section RedImplemComplete.
139139
[now econstructor| now eapply not_whne_can ; tea ; eapply isType_whnf | now cbn in *].
140140
Qed.
141141

142-
Ltac termInvContradiction Hty :=
142+
Ltac termInvContradiction Hty :=
143143
eapply termGen' in Hty; cbn in Hty; prod_hyp_splitter; subst;
144-
now match goal with
144+
now match goal with
145145
| [H : [_ |-[de] _ : _] |- _] =>
146146
eapply termGen' in H; cbn in H; prod_hyp_splitter; subst;
147147
now match goal with
@@ -206,15 +206,15 @@ Section RedImplemComplete.
206206
eapply IH.
207207
+ do 2 red; cbn.
208208
left; constructor; eapply zip_ored; constructor.
209-
+ cbn.
209+
+ cbn.
210210
eapply well_typed_zip in Hty as (?&[??Hu]).
211211
eapply Hu, RedConvTeC, subject_reduction ; tea.
212212
now do 2 econstructor.
213213
- cbn in *; split; [|easy].
214214
eapply IH.
215215
+ do 2 red; cbn.
216216
left; constructor; eapply zip_ored; constructor.
217-
+ cbn.
217+
+ cbn.
218218
eapply well_typed_zip in Hty as (?&[??Hu]).
219219
eapply Hu, RedConvTeC, subject_reduction ; tea.
220220
now do 2 econstructor.
@@ -270,7 +270,7 @@ Section RedImplemComplete.
270270
eapply whred_det ; tea.
271271
all: now eapply red_sound, def_graph_sound.
272272
Qed.
273-
273+
274274
Corollary wh_red_complete_whnf_ty Γ A A' :
275275
[Γ |-[de] A] ->
276276
[A ⤳* A'] ->
@@ -281,7 +281,7 @@ Section RedImplemComplete.
281281
eapply subject_reduction_type in Hred ; tea.
282282
now eapply wh_red_complete_whnf_class.
283283
Qed.
284-
284+
285285
Corollary wh_red_complete_whnf_tm Γ A t t' :
286286
[Γ |-[de] t : A] ->
287287
[t ⤳* t'] ->
@@ -344,15 +344,15 @@ Proof.
344344
all: inversion e.
345345
Qed.
346346

347-
(* The combinator rec throws in a return branch with a type
348-
necessarily convertible to the exception errors type, but the syntactic
347+
(* The combinator rec throws in a return branch with a type
348+
necessarily convertible to the exception errors type, but the syntactic
349349
mismatch between the 2 types prevents `rec_graph` from `apply`ing.
350350
This tactic fixes the type in the return branch to what's expected
351351
syntactically. *)
352352
Ltac patch_rec_ret :=
353353
try (unfold rec;
354-
match goal with
355-
| |- orec_graph _ (_rec _ (fun _ : ?Bx => _)) ?hBa =>
354+
match goal with
355+
| |- orec_graph _ (_rec _ (fun _ : ?Bx => _)) ?hBa =>
356356
let Ba := type of hBa in change Bx with Ba
357357
end).
358358

@@ -363,12 +363,12 @@ Context `{!TypingSubst (ta := de)} `{!TypeReductionComplete (ta := de)} `{!TypeC
363363
Let PTyEq (Γ : context) (A B : term) :=
364364
forall v, graph _conv (ty_state;Γ;v;A;B) ok.
365365
Let PTyRedEq (Γ : context) (A B : term) :=
366-
forall v, graph _conv (ty_red_state;Γ;v;A;B) ok.
366+
forall v, graph _conv (ty_red_state;Γ;v;A;B) ok.
367367
Let PNeEq (Γ : context) (A t u : term) :=
368368
forall v, graph _conv (ne_state;Γ;v;t;u) (success A).
369369
Let PNeRedEq (Γ : context) (A t u : term) :=
370370
forall v, graph _conv (ne_red_state;Γ;v;t;u) (success A).
371-
Let PTmEq (Γ : context) (A t u : term) :=
371+
Let PTmEq (Γ : context) (A t u : term) :=
372372
graph _conv (tm_state;Γ;A;t;u) ok.
373373
Let PTmRedEq (Γ : context) (A t u : term) :=
374374
graph _conv (tm_red_state;Γ;A;t;u) ok.
@@ -491,7 +491,7 @@ Proof.
491491
econstructor.
492492
1: exact (ihe tt).
493493
econstructor.
494-
1: do 2 erewrite <- Weakening.wk1_ren_on; exact (ihP tt).
494+
1: do 2 erewrite <- WeakeningLemmas.wk1_ren_on; exact (ihP tt).
495495
econstructor.
496496
1: exact ihhr.
497497
cbn; patch_rec_ret; econstructor.
@@ -700,7 +700,7 @@ Proof.
700700
1: exact g0.
701701
econstructor.
702702
1: exact g.
703-
now constructor.
703+
now constructor.
704704
- now constructor.
705705
- econstructor.
706706
1: exact (g0 tt whnf_tEmpty).
@@ -744,7 +744,7 @@ Proof.
744744
econstructor.
745745
1: exact g3.
746746
econstructor.
747-
1: erewrite <- 2!(Weakening.wk1_ren_on) ; exact (g2 tt).
747+
1: erewrite <- 2!(WeakeningLemmas.wk1_ren_on) ; exact (g2 tt).
748748
econstructor.
749749
1: exact g1.
750750
econstructor.

0 commit comments

Comments
 (0)