diff --git a/graphs/dependency.dot b/graphs/dependency.dot index eccb285..4708428 100644 --- a/graphs/dependency.dot +++ b/graphs/dependency.dot @@ -40,6 +40,15 @@ digraph theorem_deps { mfvs_lift_m [label="mfvs_lift_m", color="#38761d", fillcolor="#d9ead3", style="filled", fontcolor="#222222", tooltip="mfvs_lift_m theory/Metaterm.v https://arxiv.org/html/2312.13270v1", shape=ellipse]; mfvs_close_m [label="mfvs_close_m", color="#38761d", fillcolor="#d9ead3", style="filled", fontcolor="#222222", tooltip="mfvs_close_m theory/Metaterm.v https://arxiv.org/html/2312.13270v1", shape=ellipse]; mfvs_open_m [label="mfvs_open_m", color="#38761d", fillcolor="#d9ead3", style="filled", fontcolor="#222222", tooltip="mfvs_open_m theory/Metaterm.v https://arxiv.org/html/2312.13270v1", shape=ellipse]; + of_trm_plug [label="of_trm_plug", color="#38761d", fillcolor="#d9ead3", style="filled", fontcolor="#222222", tooltip="of_trm_plug theory/Metaterm.v https://arxiv.org/html/2312.13270v1", shape=ellipse]; + mred_of_red1 [label="mred_of_red1", color="#38761d", fillcolor="#d9ead3", style="filled", fontcolor="#222222", tooltip="mred_of_red1 theory/Metaterm.v https://arxiv.org/html/2312.13270v1", shape=ellipse]; + mred_context [label="mred_context", color="#38761d", fillcolor="#d9ead3", style="filled", fontcolor="#222222", tooltip="mred_context theory/Metaterm.v https://arxiv.org/html/2312.13270v1", shape=ellipse]; + mred_term_context [label="mred_term_context", color="#38761d", fillcolor="#d9ead3", style="filled", fontcolor="#222222", tooltip="mred_term_context theory/Metaterm.v https://arxiv.org/html/2312.13270v1", shape=ellipse]; + of_trm_moccurs [label="of_trm_moccurs", color="#38761d", fillcolor="#d9ead3", style="filled", fontcolor="#222222", tooltip="of_trm_moccurs theory/Metaterm.v https://arxiv.org/html/2312.13270v1", shape=ellipse]; + of_trm_moccurs0 [label="of_trm_moccurs0", color="#38761d", fillcolor="#d9ead3", style="filled", fontcolor="#222222", tooltip="of_trm_moccurs0 theory/Metaterm.v https://arxiv.org/html/2312.13270v1", shape=ellipse]; + mred_B_intro [label="mred_B_intro", color="#38761d", fillcolor="#d9ead3", style="filled", fontcolor="#222222", tooltip="mred_B_intro theory/Metaterm.v https://arxiv.org/html/2312.13270v1", shape=ellipse]; + mred_gc_intro [label="mred_gc_intro", color="#38761d", fillcolor="#d9ead3", style="filled", fontcolor="#222222", tooltip="mred_gc_intro theory/Metaterm.v https://arxiv.org/html/2312.13270v1", shape=ellipse]; + mred_r_intro [label="mred_r_intro", color="#38761d", fillcolor="#d9ead3", style="filled", fontcolor="#222222", tooltip="mred_r_intro theory/Metaterm.v https://arxiv.org/html/2312.13270v1", shape=ellipse]; Plus_red1_context [label="Plus_red1_context", color="#38761d", fillcolor="#d9ead3", style="filled", fontcolor="#222222", tooltip="Plus_red1_context theory/Metatheory.v https://arxiv.org/html/2312.13270v1", shape=ellipse]; occurs_count_zero [label="occurs_count_zero", color="#38761d", fillcolor="#d9ead3", style="filled", fontcolor="#222222", tooltip="occurs_count_zero theory/Metatheory.v https://arxiv.org/html/2312.13270v1", shape=ellipse]; occurs_count_false [label="occurs_count_false", color="#38761d", fillcolor="#d9ead3", style="filled", fontcolor="#222222", tooltip="occurs_count_false theory/Metatheory.v https://arxiv.org/html/2312.13270v1", shape=ellipse]; @@ -58,6 +67,12 @@ digraph theorem_deps { lemma_2_3_beta_sim [label="lemma_2_3_beta_sim", color="#38761d", fillcolor="#d9ead3", style="rounded,filled", fontcolor="#222222", tooltip="lemma_2_3_beta_sim (section 2.3) theory/Metatheory.v https://arxiv.org/html/2312.13270v1", shape=box]; Plus_trans [label="Plus_trans", color="#38761d", fillcolor="#d9ead3", style="filled", fontcolor="#222222", tooltip="Plus_trans theory/Metatheory.v https://arxiv.org/html/2312.13270v1", shape=ellipse]; Plus_step_trans [label="Plus_step_trans", color="#38761d", fillcolor="#d9ead3", style="filled", fontcolor="#222222", tooltip="Plus_step_trans theory/Metatheory.v https://arxiv.org/html/2312.13270v1", shape=ellipse]; + isubst_meta_in [label="isubst_meta_in", color="#38761d", fillcolor="#d9ead3", style="filled", fontcolor="#222222", tooltip="isubst_meta_in theory/NamedMeta.v https://arxiv.org/html/2312.13270v1", shape=ellipse]; + isubst_meta_notin [label="isubst_meta_notin", color="#38761d", fillcolor="#d9ead3", style="filled", fontcolor="#222222", tooltip="isubst_meta_notin theory/NamedMeta.v https://arxiv.org/html/2312.13270v1", shape=ellipse]; + eqC_in_Es [label="eqC_in_Es", color="#38761d", fillcolor="#d9ead3", style="filled", fontcolor="#222222", tooltip="eqC_in_Es theory/NamedMeta.v https://arxiv.org/html/2312.13270v1", shape=ellipse]; + Es_refl_any [label="Es_refl_any", color="#38761d", fillcolor="#d9ead3", style="filled", fontcolor="#222222", tooltip="Es_refl_any theory/NamedMeta.v https://arxiv.org/html/2312.13270v1", shape=ellipse]; + Es_sym_any [label="Es_sym_any", color="#38761d", fillcolor="#d9ead3", style="filled", fontcolor="#222222", tooltip="Es_sym_any theory/NamedMeta.v https://arxiv.org/html/2312.13270v1", shape=ellipse]; + Es_trans_any [label="Es_trans_any", color="#38761d", fillcolor="#d9ead3", style="filled", fontcolor="#222222", tooltip="Es_trans_any theory/NamedMeta.v https://arxiv.org/html/2312.13270v1", shape=ellipse]; par_red1_iff [label="par_red1_iff", color="#38761d", fillcolor="#d9ead3", style="filled", fontcolor="#222222", tooltip="par_red1_iff theory/Parallel.v https://arxiv.org/html/2312.13270v1", shape=ellipse]; red1_in_par [label="red1_in_par", color="#38761d", fillcolor="#d9ead3", style="filled", fontcolor="#222222", tooltip="red1_in_par theory/Parallel.v https://arxiv.org/html/2312.13270v1", shape=ellipse]; par_context [label="par_context", color="#38761d", fillcolor="#d9ead3", style="filled", fontcolor="#222222", tooltip="par_context theory/Parallel.v https://arxiv.org/html/2312.13270v1", shape=ellipse]; @@ -138,6 +153,8 @@ digraph theorem_deps { steps_complete -> enumerate_complete; of_trm_lift -> of_trm_open; mfvs_lift_m -> mfvs_open_m; + of_trm_plug -> mred_term_context; + of_trm_moccurs -> of_trm_moccurs0; occurs_count_zero -> occurs_count_pos; occurs_count_false -> occurs_count_zfill_plug; occurs_lift_self -> occurs_count_zfill_plug; diff --git a/graphs/dependency.png b/graphs/dependency.png index e26f6ea..eace39f 100644 Binary files a/graphs/dependency.png and b/graphs/dependency.png differ diff --git a/graphs/dependency.svg b/graphs/dependency.svg index 1de2e31..72ccbcc 100644 --- a/graphs/dependency.svg +++ b/graphs/dependency.svg @@ -4,19 +4,19 @@ - - + + theorem_deps - -Milner's Lambda-Calculus with Partial Substitutions - theorem dependency (M4) -proved -    -stated -    -planned -    -blocked + +Milner's Lambda-Calculus with Partial Substitutions - theorem dependency (M4) +proved +    +stated +    +planned +    +blocked fvs_lift @@ -42,16 +42,16 @@ - + fvs_zplug_lift - + fvs_zplug_lift - + fvs_lift->fvs_zplug_lift @@ -144,61 +144,61 @@ - + open_rec_zplug_lift - + open_rec_zplug_lift - + open_rec_occurs_false->open_rec_zplug_lift - + full_comp_aux - + full_comp_aux - + open_rec_occurs_false->full_comp_aux - - + + - + subst_notin - + subst_notin - + open_rec_occurs_false->subst_notin - + full_comp_aux_sub - + full_comp_aux_sub - + open_rec_occurs_false->full_comp_aux_sub @@ -213,7 +213,7 @@ - + close_rec_notin->subst_notin @@ -264,16 +264,16 @@ - + subst_lc_self - + subst_lc_self - + subst_fvar_self->subst_lc_self @@ -288,16 +288,16 @@ - + subst_other - + subst_other - + subst_fvar_other->subst_other @@ -330,16 +330,16 @@ - + star_red_sub_full_comp - + star_red_sub_full_comp - + Plus_to_Star->star_red_sub_full_comp @@ -512,380 +512,527 @@ - + +of_trm_plug + + +of_trm_plug + + + + + +mred_term_context + + +mred_term_context + + + + + +of_trm_plug->mred_term_context + + + + + +mred_of_red1 + + +mred_of_red1 + + + + + +mred_context + + +mred_context + + + + + +of_trm_moccurs + + +of_trm_moccurs + + + + + +of_trm_moccurs0 + + +of_trm_moccurs0 + + + + + +of_trm_moccurs->of_trm_moccurs0 + + + + + +mred_B_intro + + +mred_B_intro + + + + + +mred_gc_intro + + +mred_gc_intro + + + + + +mred_r_intro + + +mred_r_intro + + + + + Plus_red1_context - + Plus_red1_context - + lemma_2_3_beta_sim - + lemma_2_3_beta_sim - + Plus_red1_context->lemma_2_3_beta_sim - + occurs_count_zero - + occurs_count_zero - + occurs_count_pos - + occurs_count_pos - + occurs_count_zero->occurs_count_pos - + occurs_count_zero->full_comp_aux - + occurs_count_zero->full_comp_aux_sub - + occurs_count_false - + occurs_count_false - + occurs_count_zfill_plug - + occurs_count_zfill_plug - + occurs_count_false->occurs_count_zfill_plug - + occurs_lift_self - - -occurs_lift_self + + +occurs_lift_self - + occurs_lift_self->occurs_count_zfill_plug - - + + - + occurs_lift_self->open_rec_zplug_lift - - + + - + zdecs_nonempty - + zdecs_nonempty - + zdecs_nonempty->full_comp_aux - + zdecs_nonempty->full_comp_aux_sub - + occurs_count_zfill_plug->full_comp_aux - + occurs_count_zfill_plug->full_comp_aux_sub - + open_rec_zplug_lift->full_comp_aux - + open_rec_zplug_lift->full_comp_aux_sub - + lemma_2_2_full_comp - + lemma_2_2_full_comp - + full_comp_aux->lemma_2_2_full_comp - + lemma_2_2_full_comp->lemma_2_3_beta_sim - + red1_root_fv - + red1_root_fv - + fvs_zplug_lift->red1_root_fv - + plug_fv_mono - + plug_fv_mono - + red1r_fv - + red1r_fv - + plug_fv_mono->red1r_fv - + red1_root_fv->red1r_fv - + lemma_2_1_fv_preserved - + lemma_2_1_fv_preserved - + red1r_fv->lemma_2_1_fv_preserved - + gen_fv_preserved - + gen_fv_preserved - + lemma_2_1_fv_preserved->gen_fv_preserved - + corpus_fv_preserved - + corpus_fv_preserved - + lemma_2_1_fv_preserved->corpus_fv_preserved - + Plus_trans - - -Plus_trans + + +Plus_trans - + Plus_step_trans - - -Plus_step_trans + + +Plus_step_trans + + + + + +isubst_meta_in + + +isubst_meta_in + + + + + +isubst_meta_notin + + +isubst_meta_notin + + + + + +eqC_in_Es + + +eqC_in_Es + + + + + +Es_refl_any + + +Es_refl_any + + + + + +Es_sym_any + + +Es_sym_any + + + + + +Es_trans_any + + +Es_trans_any - + par_red1_iff - - -par_red1_iff + + +par_red1_iff - + par_to_red1_or_eq - - -par_to_red1_or_eq + + +par_to_red1_or_eq - + par_red1_iff->par_to_red1_or_eq - - + + - + red1_or_eq_to_par - - -red1_or_eq_to_par + + +red1_or_eq_to_par - + par_red1_iff->red1_or_eq_to_par - - + + - + red1_in_par - - -red1_in_par + + +red1_in_par - + par_context - - -par_context + + +par_context - + par_reflexive - - -par_reflexive + + +par_reflexive - + gen_list_length - - -gen_list_length + + +gen_list_length - + check_term_true - + check_term_true - + check_all_true - + check_all_true - + check_term_true->check_all_true @@ -897,124 +1044,124 @@ - + gen_sound - + gen_sound - + gen_complete - + gen_complete - + zdecs_sound - + zdecs_sound - + zdecs_sound->full_comp_aux - + root_steps_sound - + root_steps_sound - + zdecs_sound->root_steps_sound - + zdecs_sound->full_comp_aux_sub - + zdecs_complete - + zdecs_complete - + root_steps_complete - + root_steps_complete - + zdecs_complete->root_steps_complete - + positions_at - + positions_at - + steps_sound - + steps_sound - + positions_at->steps_sound - + root_steps_sound->steps_sound - + steps_complete - + steps_complete - + root_steps_complete->steps_complete @@ -1026,160 +1173,160 @@ - + steps_sound->gen_sound - + steps_sound_red1 - + steps_sound_red1 - + steps_sound->steps_sound_red1 - + has_red_spec - + has_red_spec - + steps_sound->has_red_spec - + corpus_sound - + corpus_sound - + steps_sound->corpus_sound - + steps_sound_red1->check_term_true - + steps_sound_red1->gen_fv_preserved - + nf_iff_steps_nil - + nf_iff_steps_nil - + steps_sound_red1->nf_iff_steps_nil - + steps_sound_red1->corpus_fv_preserved - + positions_hole - + positions_hole - + root_steps_in_steps - + root_steps_in_steps - + positions_hole->root_steps_in_steps - + root_steps_in_steps->steps_complete - + plug_comp - + plug_comp - + plug_comp->steps_complete - + positions_comp - + positions_comp - + positions_comp->steps_complete - + at_ctx_comp - + at_ctx_comp - + at_ctx_comp->steps_complete @@ -1191,415 +1338,415 @@ - + steps_complete->gen_complete - + steps_complete->has_red_spec - + steps_complete->nf_iff_steps_nil - + corpus_complete - + corpus_complete - + steps_complete->corpus_complete - + has_red_f - + has_red_f - + has_red_f->has_red_spec - + has_red_spec->check_term_true - + red1_dec - + red1_dec - + has_red_spec->red1_dec - + corpus_decides - + corpus_decides - + has_red_spec->corpus_decides - + normal_form_iff_nf - + normal_form_iff_nf - + nf_iff_steps_nil->normal_form_iff_nf - + nf_dec - + nf_dec - + nf_iff_steps_nil->nf_dec - + open_rec_app - - -open_rec_app + + +open_rec_app - + open_rec_lam - - -open_rec_lam + + +open_rec_lam - + open_rec_esub - - -open_rec_esub + + +open_rec_esub - + close_rec_app - - -close_rec_app + + +close_rec_app - + close_rec_lam - - -close_rec_lam + + +close_rec_lam - + close_rec_esub - - -close_rec_esub + + +close_rec_esub - + subst_app - - -subst_app + + +subst_app - + subst_lam - - -subst_lam + + +subst_lam - + subst_esub - - -subst_esub + + +subst_esub - + open_rec_lc_atom - - -open_rec_lc_atom + + +open_rec_lc_atom - + open_rec_lc - - -open_rec_lc + + +open_rec_lc - + open_rec_lc_atom->open_rec_lc - - + + - + red_sub_root_to_red1 - - -red_sub_root_to_red1 + + +red_sub_root_to_red1 - + red_sub_to_red1 - - -red_sub_to_red1 + + +red_sub_to_red1 - + red_sub_root_to_red1->red_sub_to_red1 - - + + - + red_sub_context - - -red_sub_context + + +red_sub_context - + Star_red_sub_context - - -Star_red_sub_context + + +Star_red_sub_context - + red_sub_context->Star_red_sub_context - - + + - + red_sub_gc - + red_sub_gc - + red_sub_gc->full_comp_aux_sub - + red_gc_to_red_sub - + red_gc_to_red_sub - + red_sub_gc->red_gc_to_red_sub - + red_sub_r - + red_sub_r - + red_sub_r->full_comp_aux_sub - + occurs_zfill - - -occurs_zfill + + +occurs_zfill - + zfill_occurs0 - - -zfill_occurs0 + + +zfill_occurs0 - + occurs_zfill->zfill_occurs0 - - + + - + R_Gc_disjoint - - -R_Gc_disjoint + + +R_Gc_disjoint - + zfill_occurs0->R_Gc_disjoint - - + + - + plus_red_sub_full_comp - + plus_red_sub_full_comp - + full_comp_aux_sub->plus_red_sub_full_comp - + plus_red_sub_full_comp->star_red_sub_full_comp - + es_count_plug_mono - - -es_count_plug_mono + + +es_count_plug_mono - + red_gc_measure - - -red_gc_measure + + +red_gc_measure - + es_count_plug_mono->red_gc_measure - - + + - + red_gc_terminates - - -red_gc_terminates + + +red_gc_terminates - + red_gc_measure->red_gc_terminates - - + + diff --git a/graphs/index.txt b/graphs/index.txt index 8e8e42a..1bdbd77 100644 --- a/graphs/index.txt +++ b/graphs/index.txt @@ -1,4 +1,27 @@ status milestone kind name file +proved M0 infra Es_refl_any theory/NamedMeta.v +proved M0 infra Es_sym_any theory/NamedMeta.v +proved M0 infra Es_trans_any theory/NamedMeta.v +proved M0 infra eqC_in_Es theory/NamedMeta.v +proved M0 infra isubst_meta_in theory/NamedMeta.v +proved M0 infra isubst_meta_notin theory/NamedMeta.v +proved M0 infra mfvs_close_m theory/Metaterm.v +proved M0 infra mfvs_lift_m theory/Metaterm.v +proved M0 infra mfvs_open_m theory/Metaterm.v +proved M0 infra mred_B_intro theory/Metaterm.v +proved M0 infra mred_context theory/Metaterm.v +proved M0 infra mred_gc_intro theory/Metaterm.v +proved M0 infra mred_of_red1 theory/Metaterm.v +proved M0 infra mred_r_intro theory/Metaterm.v +proved M0 infra mred_term_context theory/Metaterm.v +proved M0 infra of_trm_close theory/Metaterm.v +proved M0 infra of_trm_fvs theory/Metaterm.v +proved M0 infra of_trm_injective theory/Metaterm.v +proved M0 infra of_trm_lift theory/Metaterm.v +proved M0 infra of_trm_moccurs theory/Metaterm.v +proved M0 infra of_trm_moccurs0 theory/Metaterm.v +proved M0 infra of_trm_open theory/Metaterm.v +proved M0 infra of_trm_plug theory/Metaterm.v proved M1 infra at_ctx_comp theory/Reduction.v proved M1 infra close_rec_fvar theory/Binding.v proved M1 infra close_rec_fvs theory/Binding.v diff --git a/graphs/theorems.json b/graphs/theorems.json index e2477fd..1ed9d7a 100644 --- a/graphs/theorems.json +++ b/graphs/theorems.json @@ -373,6 +373,100 @@ "mfvs_lift_m" ] }, + { + "id": "of_trm_plug", + "label": "of_trm_plug", + "kind": "infra", + "status": "proved", + "milestone": "M0", + "section": "", + "file": "theory/Metaterm.v", + "depends": [] + }, + { + "id": "mred_of_red1", + "label": "mred_of_red1", + "kind": "infra", + "status": "proved", + "milestone": "M0", + "section": "", + "file": "theory/Metaterm.v", + "depends": [] + }, + { + "id": "mred_context", + "label": "mred_context", + "kind": "infra", + "status": "proved", + "milestone": "M0", + "section": "", + "file": "theory/Metaterm.v", + "depends": [] + }, + { + "id": "mred_term_context", + "label": "mred_term_context", + "kind": "infra", + "status": "proved", + "milestone": "M0", + "section": "", + "file": "theory/Metaterm.v", + "depends": [ + "of_trm_plug" + ] + }, + { + "id": "of_trm_moccurs", + "label": "of_trm_moccurs", + "kind": "infra", + "status": "proved", + "milestone": "M0", + "section": "", + "file": "theory/Metaterm.v", + "depends": [] + }, + { + "id": "of_trm_moccurs0", + "label": "of_trm_moccurs0", + "kind": "infra", + "status": "proved", + "milestone": "M0", + "section": "", + "file": "theory/Metaterm.v", + "depends": [ + "of_trm_moccurs" + ] + }, + { + "id": "mred_B_intro", + "label": "mred_B_intro", + "kind": "infra", + "status": "proved", + "milestone": "M0", + "section": "", + "file": "theory/Metaterm.v", + "depends": [] + }, + { + "id": "mred_gc_intro", + "label": "mred_gc_intro", + "kind": "infra", + "status": "proved", + "milestone": "M0", + "section": "", + "file": "theory/Metaterm.v", + "depends": [] + }, + { + "id": "mred_r_intro", + "label": "mred_r_intro", + "kind": "infra", + "status": "proved", + "milestone": "M0", + "section": "", + "file": "theory/Metaterm.v", + "depends": [] + }, { "id": "Plus_red1_context", "label": "Plus_red1_context", @@ -582,6 +676,66 @@ "file": "theory/Metatheory.v", "depends": [] }, + { + "id": "isubst_meta_in", + "label": "isubst_meta_in", + "kind": "infra", + "status": "proved", + "milestone": "M0", + "section": "", + "file": "theory/NamedMeta.v", + "depends": [] + }, + { + "id": "isubst_meta_notin", + "label": "isubst_meta_notin", + "kind": "infra", + "status": "proved", + "milestone": "M0", + "section": "", + "file": "theory/NamedMeta.v", + "depends": [] + }, + { + "id": "eqC_in_Es", + "label": "eqC_in_Es", + "kind": "infra", + "status": "proved", + "milestone": "M0", + "section": "", + "file": "theory/NamedMeta.v", + "depends": [] + }, + { + "id": "Es_refl_any", + "label": "Es_refl_any", + "kind": "infra", + "status": "proved", + "milestone": "M0", + "section": "", + "file": "theory/NamedMeta.v", + "depends": [] + }, + { + "id": "Es_sym_any", + "label": "Es_sym_any", + "kind": "infra", + "status": "proved", + "milestone": "M0", + "section": "", + "file": "theory/NamedMeta.v", + "depends": [] + }, + { + "id": "Es_trans_any", + "label": "Es_trans_any", + "kind": "infra", + "status": "proved", + "milestone": "M0", + "section": "", + "file": "theory/NamedMeta.v", + "depends": [] + }, { "id": "par_red1_iff", "label": "par_red1_iff", diff --git a/scripts/audit.sh b/scripts/audit.sh index 54a8cac..7ad07f4 100755 --- a/scripts/audit.sh +++ b/scripts/audit.sh @@ -35,7 +35,7 @@ done < <(find theory -name '*.v' -print0 2>/dev/null) echo "== Print Assumptions ==" WORK="$(mktemp -d ./.audit-work.XXXXXX)" cp theory/*.v "$WORK"/ -for f in ExecReducer Binding Reduction Metatheory Closure Subsystem Substitution Parallel Metaterm Tests Random Enumerate; do +for f in ExecReducer Binding Reduction Metatheory Closure Subsystem Substitution Parallel Metaterm NamedMeta Tests Random Enumerate; do echo "-- $f" out="$(rocq compile -Q "$WORK" LambdaSub "$WORK/$f.v" 2>&1 || true)" echo "$out" diff --git a/theory/NamedMeta.v b/theory/NamedMeta.v new file mode 100644 index 0000000..25640d4 --- /dev/null +++ b/theory/NamedMeta.v @@ -0,0 +1,106 @@ +From Stdlib Require Import List Bool Arith Lia PeanoNat. +Import ListNotations. + +Definition atom := nat. + +Inductive ntrm : Type := +| NVar : atom -> ntrm +| NApp : ntrm -> ntrm -> ntrm +| NLam : atom -> ntrm -> ntrm +| NESub : ntrm -> atom -> ntrm -> ntrm +| NMVar : atom -> list atom -> ntrm. + +Fixpoint nfv (t : ntrm) : list atom := + match t with + | NVar x => [x] + | NApp a b => nfv a ++ nfv b + | NLam x a => filter (fun y => negb (Nat.eqb y x)) (nfv a) + | NESub a x b => filter (fun y => negb (Nat.eqb y x)) (nfv a) ++ nfv b + | NMVar _ d => d + end. + +Definition isubst_meta (X : atom) (d : list atom) (x : atom) (v : ntrm) : ntrm := + if existsb (Nat.eqb x) d then NESub (NMVar X d) x v else NMVar X d. + +Lemma isubst_meta_in : forall X d x v, In x d -> isubst_meta X d x v = NESub (NMVar X d) x v. +Proof. + intros X d x v H. unfold isubst_meta. + destruct (existsb (Nat.eqb x) d) eqn:E; [reflexivity |]. + assert (Hex : existsb (Nat.eqb x) d = true) + by (apply existsb_exists; exists x; split; [exact H | apply Nat.eqb_refl]). + rewrite Hex in E. discriminate E. +Qed. + +Lemma isubst_meta_notin : forall X d x v, ~ In x d -> isubst_meta X d x v = NMVar X d. +Proof. + intros X d x v H. unfold isubst_meta. + destruct (existsb (Nat.eqb x) d) eqn:E; [| reflexivity]. + exfalso. apply existsb_exists in E. destruct E as [y [Hy HE]]. + apply Nat.eqb_eq in HE. subst y. apply H. exact Hy. +Qed. + +Inductive nctx : Type := +| nHole : nctx +| nAppL : nctx -> ntrm -> nctx +| nAppR : ntrm -> nctx -> nctx +| nLam : atom -> nctx -> nctx +| nESubL : nctx -> atom -> ntrm -> nctx +| nESubR : ntrm -> atom -> nctx -> nctx. + +Fixpoint nplug (C : nctx) (t : ntrm) : ntrm := + match C with + | nHole => t + | nAppL C1 u => NApp (nplug C1 t) u + | nAppR u C1 => NApp u (nplug C1 t) + | nLam x C1 => NLam x (nplug C1 t) + | nESubL C1 x u => NESub (nplug C1 t) x u + | nESubR t1 x C1 => NESub t1 x (nplug C1 t) + end. + +Fixpoint is_subst_chain (C : nctx) : bool := + match C with + | nHole => true + | nESubL C1 _ _ => is_subst_chain C1 + | _ => false + end. + +Inductive Es : ntrm -> ntrm -> Prop := +| Es_refl : forall t, Es t t +| Es_sym : forall t u, Es t u -> Es u t +| Es_trans : forall t u v, Es t u -> Es u v -> Es t v +| Es_C : forall t x u y v, + y <> x -> ~ In y (nfv u) -> ~ In x (nfv v) -> + Es (NESub (NESub t x u) y v) (NESub (NESub t y v) x u). + +Inductive nred : ntrm -> ntrm -> Prop := +| nred_B : forall t x u, nred (NApp (NLam x t) u) (NESub t x u) +| nred_Gc : forall t x u, ~ In x (nfv t) -> nred (NESub t x u) t +| nred_RX : forall C X d x u phi, + In x d -> + In x phi -> + (forall y, In y (nfv u) -> In y phi) -> + is_subst_chain C = false -> + nred (NESub (nplug C (NMVar X d)) x u) + (NESub (nplug C (NESub (NMVar X d) x u)) x u) +| nred_ctx : forall C t t', nred t t' -> nred (nplug C t) (nplug C t'). + +Lemma eqC_in_Es : forall t x u y v, + y <> x -> ~ In y (nfv u) -> ~ In x (nfv v) -> + Es (NESub (NESub t x u) y v) (NESub (NESub t y v) x u). +Proof. intros. apply Es_C; assumption. Qed. + +Lemma Es_refl_any : forall t, Es t t. +Proof. intros. apply Es_refl. Qed. + +Lemma Es_sym_any : forall t u, Es t u -> Es u t. +Proof. intros. apply Es_sym. exact H. Qed. + +Lemma Es_trans_any : forall t u v, Es t u -> Es u v -> Es t v. +Proof. intros. apply Es_trans with (u := u); assumption. Qed. + +Print Assumptions isubst_meta_in. +Print Assumptions isubst_meta_notin. +Print Assumptions eqC_in_Es. +Print Assumptions Es_refl_any. +Print Assumptions Es_sym_any. +Print Assumptions Es_trans_any.