@@ -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-
239227Definition 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+
262262Fixpoint eval_subst (s : quoted_subst) : quoted_subst :=
263263 match s with
264264 | qsubst_comp u v =>
@@ -412,21 +412,6 @@ Proof.
412412 end; intros [=].
413413Qed .
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
431416Lemma 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.
482467Qed .
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
485488Fixpoint 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
706729Class SubstSimplification (r s : nat -> term) := MkSimplSubst {
@@ -712,20 +735,19 @@ Arguments autosubst_simpl_csubst r {s _}.
712735Hint 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.
727749Proof .
728- intros Γ Δ r t s H.
750+ intros H.
729751 apply autosubst_simpl_term, _.
730752Qed .
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
0 commit comments