Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
d34dfee
change rule
jiangsy Jul 17, 2025
ae82906
add code from pr-some-contra
jiangsy Jul 17, 2025
7327870
look at syntactic props
jiangsy Jul 21, 2025
08f6270
copy PER from feature/per_subtyping
jiangsy Jul 21, 2025
f1f6cf5
identify broken things in per lemmas
jiangsy Jul 21, 2025
800bc35
fix per_elem_subtyping
jiangsy Jul 21, 2025
fbf7f12
existential destruction keeps the original name
jiangsy May 15, 2025
d176e10
fix per_subtyp_refl from feature/per_subtyping
jiangsy Jul 21, 2025
5ffac91
fix per_subtyp_trans from feature/per_subtyping
jiangsy Jul 21, 2025
ae25b31
identify broken props in completeness
jiangsy Jul 22, 2025
869e5cd
port ltac changes
jiangsy Jul 22, 2025
fb88602
stuck
jiangsy Jul 22, 2025
78b56ed
update the comment
jiangsy Jul 22, 2025
027d51e
add one more premise to subtyp_pi
jiangsy Jul 22, 2025
79464bf
emmm suddenly looks good?
jiangsy Jul 22, 2025
e8341a1
indeed looks good
jiangsy Jul 22, 2025
eacac79
read_typ_per_subtyp_nf_subtyp is wrong
jiangsy Jul 23, 2025
6622455
update the comment
jiangsy Jul 23, 2025
bc52879
update comments
jiangsy Jul 25, 2025
d2b2335
completeness_subcontext cannot be proved by a simple syntactic proof
jiangsy Aug 22, 2025
561759f
completeness_subtyp should/could be stated in a simpler form
jiangsy Aug 23, 2025
481b330
some comments on read_typ_per_subtyp_nf_subtyp
jiangsy Aug 24, 2025
d710a30
reorg files
jiangsy Aug 25, 2025
ab2c5d9
change per_bot and per_top to weak_cong
jiangsy Aug 25, 2025
d2ff68b
a few simple props of the new PER
jiangsy Aug 26, 2025
3f08701
define a weak realizability that accommodate subtyping
jiangsy Aug 27, 2025
e1c86fa
some issue about realize_per_univ_elem_gen
jiangsy Aug 28, 2025
08a617f
reverse the subtyping seems to work
jiangsy Aug 28, 2025
478b1a1
the other case breaks with the new direction
jiangsy Aug 28, 2025
0e5ad36
mark some discussion
jiangsy Aug 29, 2025
8a8863c
add realize_per_univ_elem_gen''
jiangsy Aug 30, 2025
5579559
seems good
jiangsy Aug 30, 2025
b3d7f0b
typo fix
jiangsy Aug 30, 2025
ba8553d
cannot readback the annotation of lambda
jiangsy Aug 30, 2025
67bb64c
hope this one can work
jiangsy Aug 30, 2025
ffa34c4
some ocmments
jiangsy Aug 30, 2025
dfd5658
sync
jiangsy Sep 1, 2025
b209d0a
realize_per_univ_elem_gen_ver_ref finally good
jiangsy Sep 1, 2025
858582c
remove previous attempts
jiangsy Sep 1, 2025
38ce10b
minor renaming
jiangsy Sep 1, 2025
e0f5211
clean realize_per_univ_elem_gen_sub
jiangsy Sep 1, 2025
1bb51b5
copy completeness to wcompleteness
jiangsy Sep 5, 2025
068767e
completeness cases
jiangsy Sep 5, 2025
fd1449b
mark
jiangsy Sep 5, 2025
ad6dfab
read_typ_per_subtyp_nf_subtyp still unprovable?
jiangsy Sep 5, 2025
d9ebc83
rename read_typ_per_subtyp_nf_subtyp to wrealize_persub_gen
jiangsy Sep 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.vscode

# Dune outputs
_build
*.opam
Expand Down
94 changes: 84 additions & 10 deletions theories/Core/Completeness.v
Original file line number Diff line number Diff line change
@@ -1,32 +1,106 @@
From Mctt Require Import LibTactics.
From Mctt.Core Require Import Base.
From Mctt.Core.Completeness Require Export FundamentalTheorem.
From Mctt.Core.Semantic Require Import Realizability.
From Mctt.Core.WCompleteness Require Export FundamentalTheorem.
From Mctt.Core.Semantic Require Import WRealizability.
From Mctt.Core.Semantic Require Export NbE.
From Mctt.Core.Syntactic Require Export SystemOpt.
From Mctt.Core.Syntactic.WCong Require Import Definitions Lemmas.
From Mctt.Core.Syntactic Require Export SystemOpt Corollaries CtxSub.
Import Domain_Notations.


Theorem completeness : forall {Γ M M' A},
{{ Γ ⊢ M ≈ M' : A }} ->
exists W, nbe Γ M A W /\ nbe Γ M' A W.
exists W W', nbe Γ M A W /\ nbe Γ M' A W' /\ {{ ⊢nf W ≈≈ W' }}.
Proof with mautosolve.
intros * [env_relΓ]%completeness_fundamental_exp_eq.
destruct_conjs.
assert (exists p p', initial_env Γ p /\ initial_env Γ p' /\ {{ Dom p ≈ p' ∈ env_relΓ }}) as [p] by (eauto using per_ctx_then_per_env_initial_env).
assert (exists ρ ρ', initial_env Γ ρ /\ initial_env Γ ρ' /\ {{ Dom ρ ≈≈ ρ' ∈ env_relΓ }}) as [ρ] by (eauto using per_ctx_then_per_env_initial_env).
destruct_conjs.
functional_initial_env_rewrite_clear.
(on_all_hyp: destruct_rel_by_assumption env_relΓ).
rename x into elem_rel.
destruct_by_head rel_typ.
functional_eval_rewrite_clear.
destruct_by_head rel_exp.
unshelve epose proof (per_elem_then_per_top _ _ (length Γ)) as [? []]; shelve_unifiable...
unshelve epose proof (per_elem_then_per_top _ _ (length Γ)) as [? [? [? []]]]; shelve_unifiable; mauto 3.
exists x, x0; repeat split; mauto 3.
Qed.

Lemma completeness_ty : forall {Γ i A A'},
{{ Γ ⊢ A ≈ A' : Type@i }} ->
exists W, nbe_ty Γ A W /\ nbe_ty Γ A' W.
exists W W', nbe_ty Γ A W /\ nbe_ty Γ A' W' /\ {{ ⊢nf W ≈≈ W' }} .
Proof.
intros * [? [?%nbe_type_to_nbe_ty ?%nbe_type_to_nbe_ty]]%completeness.
mauto 3.
intros. apply completeness in H as [W [W' []]]; mauto 3.
destruct_all.
apply nbe_type_to_nbe_ty in H.
apply nbe_type_to_nbe_ty in H0.
do 2 eexists; repeat split; mauto 3.
Qed.

Lemma completeness_subtyp : forall {Γ A A'},
{{ Γ ⊢ A ⊆ A' }} ->
exists W W', nbe_ty Γ A W /\ nbe_ty Γ A' W' /\ {{ ⊢snf W ⊆ W' }}.
Proof.
intros * HA.
eapply completeness_fundamental_subtyp in HA as [env_relΓ].
destruct_conjs.
assert (exists ρ ρ', initial_env Γ ρ /\ initial_env Γ ρ' /\ {{ Dom ρ ≈≈ ρ' ∈ env_relΓ }}) as [ρ] by (eauto using per_ctx_then_per_env_initial_env).
destruct_conjs.
functional_initial_env_rewrite_clear.
(on_all_hyp: destruct_rel_by_assumption env_relΓ).
destruct_by_head rel_typ.
functional_eval_rewrite_clear.
destruct_by_head rel_exp.
functional_eval_rewrite_clear.
handle_per_univ_elem_irrel.
(on_all_hyp: fun H => epose proof (per_univ_then_per_top_typ H (length Γ)); destruct_all).
functional_read_rewrite_clear. clear_dups.
do 2 eexists.
repeat split; only 1-2: econstructor; try eassumption.
- eapply wrealize_persub_gen; mauto 3.
Abort.

(* Lemma completeness_subtyp' : forall {Γ A A'},
{{ Γ ⊢ A ⊆ A' }} ->
forall Γ',
{{ ⊢ Γ' ⊆ Γ }} ->
exists W W', nbe_ty Γ' A W /\ nbe_ty Γ A' W' /\ {{ ⊢anf W ⊆ W' }}.
Proof.
intros * HA. induction HA; intros.
- admit.
- admit.
- admit.
- admit.
Admitted. *)


(* Lemma completeness_subtyp : forall {Γ A A'},
{{ Γ ⊢ A ⊆ A' }} ->
forall Γ',
{{ ⊢ Γ' ⊆ Γ }} ->
exists W W', nbe_ty Γ' A W /\ nbe_ty Γ A' W' /\ {{ ⊢anf W ⊆ W' }}.
Proof.
intros * HA ? HG.
assert {{ Γ' ⊢ A ⊆ A' }} as HA' by mauto 3.
eapply completeness_fundamental_subtyp in HA as [env_relΓ].
eapply completeness_fundamental_subtyp in HA' as [env_relΓ'].
destruct_conjs.
eapply completeness_fundamental_ctx_subtyp in HG.
assert (exists ρ ρ', initial_env Γ' ρ /\ initial_env Γ' ρ' /\ {{ Dom ρ ≈ ρ' ∈ env_relΓ' }}) as [ρ] by (eauto using per_ctx_then_per_env_initial_env).
destruct_conjs.
functional_initial_env_rewrite_clear.
assert {{ Dom ρ ≈ ρ ∈ env_relΓ }} by (eapply per_ctx_env_subtyping; mauto 2).
(on_all_hyp: destruct_rel_by_assumption env_relΓ).
(on_all_hyp: destruct_rel_by_assumption env_relΓ').
destruct_by_head rel_typ.
functional_eval_rewrite_clear.
destruct_by_head rel_exp.
functional_eval_rewrite_clear.
handle_per_univ_elem_irrel.
(on_all_hyp: fun H => epose proof (per_univ_then_per_top_typ H (length Γ')); destruct_all).
functional_read_rewrite_clear. clear_dups.
do 2 eexists.
repeat split; only 1-2: econstructor; try eassumption.
- admit. (* initial_env Γ p, which is false *) (* We need a relation between initial environments of super/sub-context pair *)
- erewrite <- per_ctx_subtyp_respects_length; mautosolve.
- admit. (* {{ ⊢anf ~ ?W ⊆ ~ ?W' }} *)
Abort. *)
10 changes: 3 additions & 7 deletions theories/Core/Completeness/FunctionCases.v
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ Proof.
eexists_rel_exp_with (max i j).
intros.
(on_all_hyp: destruct_rel_by_assumption env_relΓ).
rename x0 into in_rel.
destruct_by_head rel_typ.
destruct_by_head rel_exp.
eexists; split; econstructor; mauto.
Expand Down Expand Up @@ -229,13 +228,12 @@ Proof with intuition.
intros.
assert (equiv_p'_p' : env_relΓ ρ' ρ') by (etransitivity; [symmetry |]; eassumption).
(on_all_hyp: destruct_rel_by_assumption env_relΓ).
rename x2 into in_rel.
destruct_by_head rel_typ.
destruct_by_head rel_exp.
handle_per_univ_elem_irrel.
assert (in_rel m1 m2) by (etransitivity; [| symmetry]; eassumption).
assert (in_rel m1 m'2) by intuition.
(on_all_hyp: destruct_rel_by_assumption in_rel).
assert (in_rel0 m1 m2) by (etransitivity; [| symmetry]; eassumption).
assert (in_rel0 m1 m'2) by intuition.
(on_all_hyp: destruct_rel_by_assumption in_rel0).
handle_per_univ_elem_irrel.
eexists.
split; econstructor; mauto...
Expand All @@ -259,7 +257,6 @@ Proof with mautosolve.
intros.
(on_all_hyp: destruct_rel_by_assumption env_relΓ).
(on_all_hyp: destruct_rel_by_assumption env_relΔ).
rename x0 into in_rel.
destruct_by_head rel_typ.
handle_per_univ_elem_irrel.
destruct_by_head rel_exp.
Expand Down Expand Up @@ -307,7 +304,6 @@ Proof with mautosolve.
eexists_rel_exp_of_pi.
intros.
(on_all_hyp: destruct_rel_by_assumption env_relΓ).
rename x into in_rel.
destruct_by_head rel_typ.
destruct_by_head rel_exp.
do 2 eexists.
Expand Down
19 changes: 19 additions & 0 deletions theories/Core/Completeness/LogicalRelation/Lemmas.v
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,22 @@ Qed.

#[export]
Hint Resolve rel_typ_implies_rel_exp : mctt.

Lemma rel_exp_clean_inversion : forall {Γ env_rel A M M'},
{{ EF Γ ≈ Γ ∈ per_ctx_env ↘ env_rel }} ->
{{ Γ ⊨ M ≈ M' : A }} ->
exists i,
forall ρ ρ' (equiv_ρ_ρ' : {{ Dom ρ ≈ ρ' ∈ env_rel }}),
exists (elem_rel : relation domain),
rel_typ i A ρ A ρ' elem_rel /\ rel_exp M ρ M' ρ' elem_rel.
Proof.
intros * ? [].
destruct_conjs.
handle_per_ctx_env_irrel.
eexists.
eassumption.
Qed.

Ltac invert_rel_exp H :=
(unshelve (epose proof (rel_exp_clean_inversion _ H); deex); shelve_unifiable; [eassumption |]; clear H)
+ dependent destruction H.
1 change: 0 additions & 1 deletion theories/Core/Completeness/NatCases.v
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ Proof.
eexists; split; mauto.
econstructor; mauto.
per_univ_elem_econstructor; mauto.
reflexivity.
Qed.

#[export]
Expand Down
3 changes: 2 additions & 1 deletion theories/Core/Completeness/SubstitutionCases.v
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ Proof with mautosolve.
(on_all_hyp: destruct_rel_by_assumption env_relΔ).
destruct_by_head rel_typ.
invert_rel_typ_body_nouip.
destruct_by_head rel_exp...
destruct_by_head rel_exp.
econstructor; mauto 3.
Qed.

#[export]
Expand Down
43 changes: 30 additions & 13 deletions theories/Core/Completeness/SubtypingCases.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ From Coq Require Import Morphisms_Relations RelationClasses.

From Mctt Require Import LibTactics.
From Mctt.Core Require Import Base.
From Mctt.Core.Completeness Require Import LogicalRelation FunctionCases.
From Mctt.Core.Completeness Require Import LogicalRelation FunctionCases UniverseCases.
Import Domain_Notations.

Lemma subtyp_refl : forall Γ M M' i,
Expand Down Expand Up @@ -71,15 +71,18 @@ Proof.
Qed.

Lemma subtyp_pi : forall Γ A A' B B' i,
{{ Γ ⊨ A ≈ A' : Type@i }} ->
{{ Γ ⊨ A' ⊆ A }} ->
{{ Γ , A ⊨ B : Type@i }} ->
{{ Γ , A' ⊨ B ⊆ B' }} ->
{{ Γ ⊨ Π A B ⊆ Π A' B' }}.
Proof.
intros * [env_relΓ] [env_relΓA' [? [k]]].
intros * [env_relΓ [HΓ [i]]] [env_relΓA]%rel_exp_of_typ_inversion [env_relΓA' [HΓA' [k]]].
destruct_conjs.
pose env_relΓ.
pose env_relΓA.
pose env_relΓA'.
match_by_head (per_ctx_env env_relΓA') invert_per_ctx_env.
match_by_head (per_ctx_env env_relΓA) invert_per_ctx_env.
handle_per_ctx_env_irrel.
eexists_subtyp.
intros.
Expand All @@ -95,36 +98,44 @@ Proof.
assert_fails (unify ρ ρ0);
rename ρ0 into ρ'
end.
rename x0 into head_rel.

assert (forall c c', head_rel ρ ρ' equiv_ρ_ρ' c c' -> env_relΓA' d{{{ ρ ↦ c }}} d{{{ ρ' ↦ c' }}}) as HΓA'
by (intros; apply_relation_equivalence; unshelve eexists; eassumption).

(** The proofs for the next two assertions are basically the same *)
assert (forall c c', head_rel0 ρ ρ' equiv_ρ_ρ' c c' -> env_relΓA d{{{ ρ ↦ c }}} d{{{ ρ' ↦ c' }}}) as HΓA
by (intros; apply_relation_equivalence; unshelve eexists; eassumption).

(** with contra-variant subtyping, the following two cases are no longer similar *)
exvar (relation domain)
ltac:(fun R => assert ({{ DF Π m0 ρ B ≈ Π m1 ρ' B ∈ per_univ_elem (Nat.max i k) ↘ R }})).
ltac:(fun R => assert ({{ DF Π a0 ρ B ≈ Π a ρ' B ∈ per_univ_elem (Nat.max i (Nat.max i0 k)) ↘ R }})).
{
intros.
per_univ_elem_econstructor; [| | solve_refl].
- etransitivity; [| symmetry]; mauto using per_univ_elem_cumu_max_left.
- eapply rel_exp_pi_core; [| reflexivity].
intros.
assert (env_relΓA' d{{{ ρ ↦ c }}} d{{{ ρ' ↦ c' }}}) as equiv_ρc_ρ'c' by (apply HΓA'; intuition).
assert (env_relΓA d{{{ ρ ↦ c }}} d{{{ ρ' ↦ c' }}}) as equiv_ρc_ρ'c'. {
eapply HΓA; intuition.
}
apply_relation_equivalence.
(on_all_hyp: fun H => destruct (H _ _ equiv_ρc_ρ'c')).
destruct_conjs.
destruct_by_head rel_typ.
econstructor; mauto using per_univ_elem_cumu_max_right.
econstructor; mauto using per_univ_elem_cumu_max_right, per_univ_elem_cumu_max_left.
destruct H13 as [].
eexists.
eapply per_univ_elem_cumu_max_right.
eapply per_univ_elem_cumu_max_left. mauto.
}
exvar (relation domain)
ltac:(fun R => assert ({{ DF Π a0 ρ B' ≈ Π a ρ' B' ∈ per_univ_elem (Nat.max i k) ↘ R }})).
ltac:(fun R => assert ({{ DF Π a3 ρ B' ≈ Π a2 ρ' B' ∈ per_univ_elem (Nat.max i (Nat.max i0 k)) ↘ R }})).
{
intros.
per_univ_elem_econstructor; [| | solve_refl].
- etransitivity; [symmetry |]; mauto using per_univ_elem_cumu_max_left.
- eapply rel_exp_pi_core; [| reflexivity].
intros.
assert (env_relΓA' d{{{ ρ ↦ c }}} d{{{ ρ' ↦ c' }}}) as equiv_ρc_ρ'c' by (apply HΓA'; intuition).
assert (env_relΓA' d{{{ ρ ↦ c }}} d{{{ ρ' ↦ c' }}}) as equiv_ρc_ρ'c' by (eapply HΓA'; intuition).
apply_relation_equivalence.
(on_all_hyp: fun H => destruct (H _ _ equiv_ρc_ρ'c')).
destruct_conjs.
Expand All @@ -133,8 +144,13 @@ Proof.
}

do 2 eexists.
repeat split; econstructor; mauto 2.
econstructor; only 3-4: try (saturate_refl; mautosolve 2).
repeat split; econstructor; mauto 2.
econstructor; only 3-4: try (saturate_refl; mautosolve 3).
- eauto using per_univ_elem_cumu_max_left.
eapply per_subtyp_trans with (A2:=a).
eapply per_subtyp_cumu_left; mauto 3.
eapply per_subtyp_cumu_left.
eapply per_subtyp_refl2; mauto 3.
- eauto using per_univ_elem_cumu_max_left.
- intros.
assert (env_relΓA' d{{{ ρ ↦ c }}} d{{{ ρ' ↦ c' }}}) as equiv_ρc_ρ'c' by (apply HΓA'; intuition).
Expand All @@ -143,7 +159,8 @@ Proof.
destruct_conjs.
destruct_by_head rel_exp.
simplify_evals.
mauto 2 using per_subtyp_cumu_right.
mauto 3 using per_subtyp_cumu_right.
- etransitivity; [symmetry|]; mauto 3.
Qed.

#[export]
Expand Down
3 changes: 0 additions & 3 deletions theories/Core/Completeness/UniverseCases.v
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ Proof.
intros.
eexists; split; eauto.
econstructor; mauto.
per_univ_elem_econstructor; eauto.
unfold per_univ.
reflexivity.
Qed.

#[export]
Expand Down
16 changes: 15 additions & 1 deletion theories/Core/Semantic/PER/CoreTactics.v
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,30 @@ From Mctt.Core Require Import Base.
From Mctt.Core.Semantic Require Import PER.Definitions.
Import Domain_Notations.

Hint Extern 1 (?R <~> ?R) => reflexivity : mctt.
Hint Extern 1 (?R <∙> ?R) => reflexivity : mctt.

(* this is specific for destruct_rel_by_assumption,
so H must have shape forall c c' (c ≈ c' ∈ rel ), P *)
Ltac deex_destruct_rel H H' :=
match type of H with
| forall _ _ _, exists _, _ =>
let H'' := fresh "H" in
pose proof (H _ _ H') as H''; deex_once_in H''
| _ => destruct (H _ _ H') as []
end.

Ltac destruct_rel_by_assumption in_rel H :=
repeat
match goal with
| H' : {{ Dom ^?c ≈ ^?c' ∈ ?in_rel0 }} |- _ =>
unify in_rel0 in_rel;
destruct (H _ _ H') as [];
deex_destruct_rel H H';
destruct_all;
mark_with H' 1
end;
unmark_all_with 1.

Ltac destruct_rel_mod_eval :=
repeat
match goal with
Expand Down
3 changes: 2 additions & 1 deletion theories/Core/Semantic/PER/Definitions.v
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ Inductive per_subtyp : nat -> domain -> domain -> Prop :=
{{ Sub 𝕌@i <: 𝕌@j at k }} )
| per_subtyp_pi :
`( forall (in_rel : relation domain) elem_rel elem_rel',
{{ DF a ≈ a' ∈ per_univ_elem i ↘ in_rel }} ->
{{ Sub a' <: a at i }} ->
{{ DF a' ≈ a' ∈ per_univ_elem i ↘ in_rel }} ->
(forall c c' b b',
{{ Dom c ≈ c' ∈ in_rel }} ->
{{ ⟦ B ⟧ ρ ↦ c ↘ b }} ->
Expand Down
Loading
Loading