Skip to content

Commit

Permalink
Update PER
Browse files Browse the repository at this point in the history
  • Loading branch information
Ailrun committed Apr 17, 2024
1 parent 3cae815 commit 47fa52f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 142 deletions.
19 changes: 9 additions & 10 deletions theories/Core/Semantic/PER.v
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
From Coq Require Import Lia PeanoNat Relations Program.Wf.
From Coq Require Import Lia PeanoNat Relations.
From Equations Require Import Equations.

From Mcltt Require Import Base Domain Evaluate Readback Syntax System.

Definition in_dom_rel {A} (R : relation A) := R.
Expand Down Expand Up @@ -53,7 +55,7 @@ Section Per_univ_elem_core_def.
| per_univ_elem_core_pi :
`{ forall (in_rel : relation domain)
(out_rel : forall {c c'}, {{ Dom c ≈ c' ∈ in_rel }} -> relation domain)
(equiv_a_a' : {{ DF a ≈ a' ∈ per_univ_elem_core ↘ in_rel}}),
(equiv_a_a' : {{ DF a ≈ a' ∈ per_univ_elem_core ↘ in_rel }}),
(forall {c c'} (equiv_c_c' : {{ Dom c ≈ c' ∈ in_rel }}),
rel_mod_eval per_univ_elem_core B d{{{ p ↦ c }}} B' d{{{ p' ↦ c' }}} (out_rel equiv_c_c')) ->
(elem_rel = fun f f' => forall {c c'} (equiv_c_c' : in_rel c c'),
Expand All @@ -66,12 +68,9 @@ End Per_univ_elem_core_def.

Global Hint Constructors per_univ_elem_core : mcltt.

Definition per_univ_like (R : domain -> domain -> relation domain -> Prop) := fun a a' => exists R', {{ DF a ≈ a' ∈ R ↘ R' }}.
#[global]
Transparent per_univ_like.

Program Fixpoint per_univ_elem (i : nat) {wf lt i} : domain -> domain -> relation domain -> Prop := Per_univ_def.per_univ_elem i (fun _ lt_j_i => per_univ_like (per_univ_elem _ lt_j_i)).
Definition per_univ (i : nat) : relation domain := per_univ_like (per_univ_elem i).
Equations per_univ_elem (i : nat) : domain -> domain -> relation domain -> Prop by wf i :=
| i => per_univ_elem_core i (fun j lt_j_i a a' => exists R', per_univ_elem j a a' R').
Definition per_univ (i : nat) : relation domain := fun a a' => exists R', per_univ_elem i a a' R'.

Definition rel_typ (i : nat) (A : typ) (p : env) (A' : typ) (p' : env) R' := rel_mod_eval (per_univ_elem i) A p A' p' R'.

Expand All @@ -82,8 +81,8 @@ Inductive per_ctx_env : ctx -> ctx -> relation env -> Prop :=
| per_ctx_env_cons :
`{ forall (tail_rel : relation env)
(head_rel : forall {p p'}, {{ Dom p ≈ p' ∈ tail_rel }} -> relation domain)
(equiv_Γ_Γ' : {{ EF Γ ≈ Γ' ∈ per_ctx_env ↘ tail_rel }})
(rel_A_A' : forall {p p'} (equiv_p_p' : {{ Dom p ≈ p' ∈ tail_rel }}), rel_typ i A p A' p' (head_rel equiv_p_p')),
(equiv_Γ_Γ' : {{ EF Γ ≈ Γ' ∈ per_ctx_env ↘ tail_rel }}),
(forall {p p'} (equiv_p_p' : {{ Dom p ≈ p' ∈ tail_rel }}), rel_typ i A p A' p' (head_rel equiv_p_p')) ->
(Env = fun p p' => exists (equiv_p_drop_p'_drop : {{ Dom p ↯ ≈ p' ↯ ∈ tail_rel }}),
{{ Dom ~(p 0) ≈ ~(p' 0) ∈ head_rel equiv_p_drop_p'_drop }}) ->
{{ EF Γ, A ≈ Γ', A' ∈ per_ctx_env ↘ Env }} }
Expand Down
167 changes: 35 additions & 132 deletions theories/Core/Semantic/PERLemmas.v
Original file line number Diff line number Diff line change
@@ -1,141 +1,44 @@
From Coq Require Import Lia PeanoNat Relations Program.Equality.
From Mcltt Require Import Base Domain Evaluate LibTactics PER Readback Syntax System.

(* Lemma per_univ_univ : forall {i j j'}, *)
(* j < i -> *)
(* j = j' -> *)
(* {{ Dom 𝕌@j ≈ 𝕌@j' ∈ per_univ i }}. *)
(* Proof with solve [mauto]. *)
(* intros * lt_j_i eq_j_j'. *)
(* eexists... *)
(* Unshelve. *)
(* all: assumption. *)
(* Qed. *)

(* Lemma per_univ_nat : forall {i}, *)
(* {{ Dom ℕ ≈ ℕ ∈ per_univ i }}. *)
(* Proof with solve [mauto]. *)
(* intros *. *)
(* eexists... *)
(* Qed. *)

(* Lemma per_univ_pi_lem : forall {i a a' B p B' p'} *)
(* (equiv_a_a' : {{ Dom a ≈ a' ∈ per_univ i }}), *)
(* (forall {c c'}, *)
(* {{ Dom c ≈ c' ∈ per_elem equiv_a_a' }} -> *)
(* rel_mod_eval (per_univ i) B d{{{ p ↦ c }}} B' d{{{ p' ↦ c' }}}) -> *)
(* exists (rel_B_B'_template : forall {c c'}, *)
(* {{ Dom c ≈ c' ∈ per_elem equiv_a_a' }} -> *)
(* rel_mod_eval (Per_univ_def.per_univ_template i) B d{{{ p ↦ c }}} B' d{{{ p' ↦ c' }}}), *)
(* (forall c c' (equiv_c_c' : {{ Dom c ≈ c' ∈ per_elem equiv_a_a' }}) *)
(* b b' (eval_B : {{ ⟦ B ⟧ p ↦ c ↘ b }}) (eval_B' : {{ ⟦ B' ⟧ p' ↦ c' ↘ b' }}), *)
(* Per_univ_def.per_univ_check i (@per_univ_base i) (rel_mod_eval_equiv (rel_B_B'_template equiv_c_c') eval_B eval_B')). *)
(* Proof with solve [mauto]. *)
(* intros * rel_B_B'. *)
(* unshelve epose (rel_B_B'_template := _ : forall {c c'}, *)
(* {{ Dom c ≈ c' ∈ per_elem equiv_a_a' }} -> *)
(* rel_mod_eval (Per_univ_def.per_univ_template i) B d{{{ p ↦ c }}} B' d{{{ p' ↦ c' }}}). *)
(* { *)
(* intros * equiv_c_c'. *)
(* econstructor; destruct (rel_B_B' _ _ equiv_c_c') as [? ? ?]; only 1-2: solve [mauto]. *)
(* intros b b' eval_B eval_B'. *)
(* eapply ex_proj1, rel_mod_eval_equiv... *)
(* } *)
(* simpl in rel_B_B'_template. *)
(* exists rel_B_B'_template. *)
(* intros *. *)
(* unfold rel_B_B'_template; simpl. *)
(* destruct (rel_B_B' _ _ equiv_c_c') as [? ? ?]. *)
(* eapply ex_proj2. *)
(* Qed. *)

(* Lemma per_univ_pi : forall {i a a' B p B' p'} *)
(* (equiv_a_a' : {{ Dom a ≈ a' ∈ per_univ i }}), *)
(* (forall {c c'}, *)
(* {{ Dom c ≈ c' ∈ per_elem equiv_a_a' }} -> *)
(* rel_mod_eval (per_univ i) B d{{{ p ↦ c }}} B' d{{{ p' ↦ c' }}}) -> *)
(* {{ Dom Π a p B ≈ Π a' p' B' ∈ per_univ i }}. *)
(* Proof with solve [mauto]. *)
(* intros *; destruct equiv_a_a' as [equiv_a_a'_template equiv_a_a'_check]; intro rel_B_B'. *)
(* eassert (H_per_univ_pi_lem : _). *)
(* { eapply per_univ_pi_lem... } *)
(* destruct H_per_univ_pi_lem as [rel_B_B'_template rel_B_B'_check]. *)
(* eexists; econstructor... *)
(* Qed. *)

(* Lemma per_univ_neut : forall {i m m' a a'}, *)
(* {{ Dom m ≈ m' ∈ per_bot }} -> *)
(* {{ Dom ⇑ a m ≈ ⇑ a' m' ∈ per_univ i }}. *)
(* Proof with solve [mauto]. *)
(* intros * equiv_m_m'. *)
(* eexists... *)
(* Unshelve. *)
(* all: assumption. *)
(* Qed. *)

(* Lemma per_univ_ind : forall i P, *)
(* (forall j j', j < i -> j = j' -> {{ Dom 𝕌@j ≈ 𝕌@j' ∈ P }}) -> *)
(* {{ Dom ℕ ≈ ℕ ∈ P }} -> *)
(* (forall a a' B p B' p' *)
(* (equiv_a_a' : {{ Dom a ≈ a' ∈ per_univ i }}), *)
(* {{ Dom a ≈ a' ∈ P }} -> *)
(* (forall c c', *)
(* {{ Dom c ≈ c' ∈ per_elem equiv_a_a' }} -> *)
(* rel_mod_eval (per_univ i) B d{{{ p ↦ c}}} B' d{{{ p' ↦ c'}}}) -> *)
(* (forall {c c'} (equiv_c_c' : {{ Dom c ≈ c' ∈ per_elem equiv_a_a' }}), *)
(* rel_mod_eval P B d{{{ p ↦ c}}} B' d{{{ p' ↦ c'}}}) -> *)
(* {{ Dom Π a p B ≈ Π a' p' B' ∈ P }}) -> *)
(* (forall m m' a a', {{ Dom m ≈ m' ∈ per_bot }} -> {{ Dom ⇑ a m ≈ ⇑ a' m' ∈ P }}) -> *)
(* forall d d', {{ Dom d ≈ d' ∈ per_univ i }} -> {{ Dom d ≈ d' ∈ P }}. *)
(* Proof with solve [mauto]. *)
(* intros * Huniv Hnat Hpi Hneut d d' [equiv_d_d'_template equiv_d_d'_check]. *)
(* induction equiv_d_d'_check; only 1-2,4: solve [mauto]. *)
(* unshelve epose (equiv_a_a'_real := _ : {{ Dom a ≈ a' ∈ per_univ i }}). *)
(* { econstructor... } *)
(* eapply Hpi with (equiv_a_a' := equiv_a_a'_real); subst equiv_a_a'_real; [solve [mauto]| |]; *)
(* intros * equiv_c_c'; unfold per_elem, Per_univ_def.per_elem in equiv_c_c'; destruct (rel_B_B' _ _ equiv_c_c'). *)
(* - econstructor; only 1-2: solve [mauto]. *)
(* intros b b' eval_B eval_B'. *)
(* econstructor; apply H. *)
(* Unshelve. *)
(* 3-5: eassumption. *)
(* - econstructor; only 1-2: solve [mauto]. *)
(* intros b b' eval_B eval_B'. *)
(* eapply H0; solve [mauto]. *)
(* Qed. *)
From Equations Require Import Equations.

Lemma per_univ_sym : forall m m' i,
{{ Dom m ≈ m' ∈ per_univ i }} ->
{{ Dom m' ≈ m ∈ per_univ i }}
with per_elem_sym : forall m m' i R R'
{{ Dom m ≈ m' ∈ per_univ i }} -> {{ Dom m' ≈ m ∈ per_univ i }}
with per_elem_sym : forall m m' i R R' a a'
(equiv_m_m' : {{ DF m ≈ m' ∈ per_univ_elem i ↘ R }})
(equiv_m'_m : {{ DF m' ≈ m ∈ per_univ_elem i ↘ R' }}),
{{ Dom m ≈ m' ∈ R }} ->
{{ Dom m' ≈ m ∈ R' }}.
{{ Dom a ≈ a' ∈ R }} <-> {{ Dom a' ≈ a ∈ R' }}.
Proof with mauto.
- intros.
destruct H as [per_elem Hper_univ].
unfold in_dom_fun_rel in *.
dependent induction Hper_univ; try solve [subst; eexists; econstructor; mauto].
+ fold per_univ_elem in equiv_a_a'.
(* eexists; econstructor... *)
(* + *)
(* unfold per_univ, Per_univ_def.per_univ, in_dom_rel in *. *)
(* destruct H as [equiv_a_a' Hcheck]. *)
(* dependent induction Hcheck; subst. *)
(* + eexists. *)
(* eapply Per_univ_def.per_univ_check_univ. *)
(* Unshelve. all: auto. *)
(* + eexists. *)
(* econstructor. *)
(* + destruct IHHcheck. *)
(* assert (Per_univ_def.per_univ_template i d{{{ Π a' p' B'}}} d{{{ Π a p B}}}). *)
(* { eapply (@Per_univ_def.per_univ_template_pi i _ _ _ _ _ _ (per_univ i) (fun _ _ => per_elem) (ex_intro _ x H1)). *)
(* intros. *)
(* unfold in_dom_rel, per_elem, Per_univ_def.per_elem in *. *)
(* } *)
all: intros *; try split.
1: intro Hper_univ.
2-3: intro Hper_elem.
- destruct Hper_univ as [per_elem equiv_m_m'].
autorewrite with per_univ_elem in equiv_m_m'.
dependent induction equiv_m_m'; subst; only 1-2,4: solve [eexists; econstructor; mauto].
(* Pi case *)
destruct IHequiv_m_m' as [in_rel' IHequiv_a_a'].
rewrite <- per_univ_elem_equation_1 in H, equiv_a_a'.
(* (* One attempt *) *)
(* unshelve epose (out_rel' := _ : forall c' c : domain, {{ Dom c' ≈ c ∈ in_rel' }} -> relation domain). *)
(* { *)
(* intros * equiv_c'_c. *)
(* assert (equiv_c_c' : {{ Dom c ≈ c' ∈ in_rel }}) by (erewrite per_elem_sym; eassumption). *)
(* assert (rel_mod_eval (per_univ_elem i) B d{{{ p ↦ c }}} B' d{{{ p' ↦ c' }}} (out_rel c c' equiv_c_c')) by mauto. *)
(* (* Failure point *) *)
(* destruct_last. *)
(* } *)

(* (* The other *) *)
(* assert (exists (out_rel' : forall c' c : domain, {{ Dom c' ≈ c ∈ in_rel' }} -> relation domain), *)
(* forall (c' c : domain) (equiv_c'_c : {{ Dom c' ≈ c ∈ in_rel' }}), *)
(* rel_mod_eval (per_univ_elem i) B' d{{{ p' ↦ c' }}} B d{{{ p ↦ c }}} (out_rel' c' c equiv_c'_c)). *)
(* { *)
(* (* This "eexists" is problematic *) *)
(* eexists. *)
(* econstructor. *)
(* * eassumption. *)
(* * intros. *)
(* intros. *)
(* assert (equiv_c_c' : {{ Dom c ≈ c' ∈ in_rel }}) by (erewrite per_elem_sym; eassumption). *)
(* assert (rel_mod_eval (per_univ_elem i) B d{{{ p ↦ c }}} B' d{{{ p' ↦ c' }}} (out_rel c c' equiv_c_c')) by mauto. *)
(* destruct_last. *)
(* econstructor; try eassumption. *)
(* } *)

0 comments on commit 47fa52f

Please sign in to comment.