floating-levels/theories/properties.v
2025-05-30 18:09:34 -04:00

291 lines
7.6 KiB
Coq
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Require Import Autosubst2.syntax
Autosubst2.core Autosubst2.unscoped typing ssreflect List ssrbool.
From Hammer Require Import Tactics.
Section ren.
Variables (T : Set).
Definition ren_ok (ξ : nat -> nat) (Γ Δ : list T) :=
forall i A, lookup i Δ A -> lookup (ξ i) Γ A.
Lemma ren_comp ξ ψ (Γ Δ : list T) Ξ :
ren_ok ξ Γ Δ ->
ren_ok ψ Δ Ξ ->
ren_ok (funcomp ξ ψ) Γ Ξ.
Proof using. sfirstorder unfold:ren_ok. Qed.
Lemma ren_shift (A : T) Γ :
ren_ok S (A :: Γ) Γ.
Proof using. hauto lq:on ctrs:lookup inv:lookup unfold:ren_ok. Qed.
Lemma ren_ext i ξ Γ Δ (A : T) :
ren_ok ξ Γ Δ ->
lookup i Γ A ->
ren_ok (scons i ξ) Γ (A :: Δ).
Proof using. qauto l:on unfold:ren_ok inv:lookup. Qed.
Lemma ren_up ξ (A : T) Γ Δ :
ren_ok ξ Γ Δ ->
ren_ok (upRen_Tm_Tm ξ) (A :: Γ) (A :: Δ).
Proof using.
rewrite /upRen_Tm_Tm.
move => h. apply ren_ext. apply : ren_comp; eauto. apply ren_shift.
apply here.
Qed.
End ren.
Arguments ren_ok {T}.
Definition bool_leb a b :=
match a,b with
| true, false => false
| _,_ => true
end.
Lemma bool_leb_refl a : bool_leb a a.
Proof. case : a => //=. Qed.
Lemma bool_le_spec a b : Bool.reflect (Bool.le a b) (bool_leb a b).
Proof. hauto l:on inv:bool ctrs:Bool.reflect. Qed.
Module Liftable.
Lemma lookup_fixed i Γ A :
lookup i Γ (, A) ->
lookup i (fixed_ctx Γ) (squash ).
Proof.
elim : Γ i A => //=.
- hauto lq:on inv:lookup.
- hauto lq:on inv:lookup ctrs:lookup.
Qed.
Lemma lookup_fixed' i Γ :
lookup i (fixed_ctx Γ) ->
exists A 0, squash 0 = /\ lookup i Γ (0, A).
Proof.
elim : Γ i => //=.
- hauto lq:on inv:lookup.
- hauto lq:on inv:lookup ctrs:lookup.
Qed.
Lemma fixed_ren_ok ξ Γ Δ :
ren_ok ξ Γ Δ ->
ren_ok ξ (fixed_ctx Γ) (fixed_ctx Δ).
Proof.
rewrite /ren_ok.
move => h i / lookup_fixed' [A][0][?]hi. subst.
apply : lookup_fixed; eauto.
Qed.
Lemma renaming ξ Φ Ψ a :
liftable Ψ a ->
ren_ok ξ Φ Ψ ->
liftable Φ (ren_Tm ξ a).
Proof.
elim : a ξ Φ Ψ => //=; hauto l:on use:ren_up unfold:ren_ok.
Qed.
Fixpoint ctx_leq Φ Ψ :=
match Φ, Ψ with
| nil, nil => true
| ::Φ, '::Ψ => bool_leb ' && ctx_leq Φ Ψ
| _, _ => false
end.
Lemma ctx_leq_lookup Φ Ψ i 1 :
ctx_leq Φ Ψ ->
lookup i Ψ 1 ->
exists 0, lookup i Φ 0 /\
Bool.le 0 1.
Proof.
move => + h. move : Φ.
elim : i Ψ 1 / h.
- move => A Γ Ψ h.
case : Ψ h => //=.
move => B Ψ.
case : bool_le_spec => //=.
sfirstorder ctrs:lookup.
- move => i Γ A B hi ihi Ψ.
case : Ψ => //=.
move => C Ψ.
case : bool_le_spec => //=.
hauto lq:on ctrs:lookup.
Qed.
Lemma narrowing Φ Ψ a :
ctx_leq Φ Ψ ->
liftable Ψ a ->
liftable Φ a.
Proof.
elim : a Φ Ψ => //=.
- move => n Φ Ψ.
move : ctx_leq_lookup; repeat move/[apply].
move => [1 [h0 h1]].
suff : 1 = false by congruence.
hauto q:on inv:bool.
- sfirstorder.
- sfirstorder.
- sfirstorder.
Qed.
End Liftable.
Definition lvl_leb a b :=
match a, b with
| Fixed 0, Fixed 1 => Bool.eqb 0 1
| Floating 0, Floating 1 => bool_leb 0 1
| _,_ => false
end.
Lemma lvl_leb_refl a : lvl_leb a a.
Proof. destruct a,b; sfirstorder use:Bool.eqb_reflx, bool_leb_refl. Qed.
Module Typing.
Inductive ctx_fleq : list bool -> ctx -> ctx -> Prop :=
| FL_Nil : ctx_fleq nil nil nil
| FL_ConsFixed Φ Γ Δ A :
ctx_fleq Φ Γ Δ ->
ctx_fleq (false :: Φ) (A :: Γ) (A :: Δ)
| FL_ConsFloat Φ Γ Δ 0 1 A :
ctx_fleq Φ Γ Δ ->
lvl_leb 0 1 ->
ctx_fleq (true :: Φ) ((0, A) :: Γ) ((1, A) :: Δ).
Lemma ctx_fleq_fixed Φ Γ Δ :
ctx_fleq Φ Γ Δ ->
ctx_fleq (fixed_ctx Γ) Γ Δ.
Proof.
move => h. elim : Φ Γ Δ/ h => //=.
- constructor.
- move => Φ Γ Δ [ B].
move => h0 h1.
destruct => //=; constructor; eauto using lvl_leb_refl.
- move => Φ Γ Δ 0 1 A hctx ihctx h0.
destruct 0, 1 => //=.
simpl in h0.
move : h0. case : Bool.eqb_spec => //= ? _. subst.
by constructor.
by constructor.
Qed.
Lemma renaming ξ Γ Δ a A :
Δ a ;; A ->
ren_ok ξ Γ Δ ->
Γ ren_Tm ξ a ;; A.
Proof.
move => h. move : ξ Γ.
elim : Δ a A / h.
- hauto lq:on ctrs:Wt unfold:ren_ok.
- hauto lq:on ctrs:Wt unfold:ren_ok.
- hauto lq:on ctrs:Wt use:ren_up.
- move => Γ 0 a b A B hb ihb ha iha hl ξ Δ .
have ? : liftable (fixed_ctx Δ) (ren_Tm ξ a) by
qauto l:on use:Liftable.renaming, Liftable.fixed_ren_ok.
hauto lq:on ctrs:Wt.
- hauto lq:on ctrs:Wt use:ren_up.
Qed.
Lemma ctx_fleq_lookup i Φ (Γ Δ : ctx) A :
ctx_fleq Φ Γ Δ ->
lookup i Φ false ->
lookup i Γ A ->
lookup i Δ A.
Proof.
move => h. move : A i.
elim : Φ Γ Δ / h => //=; sauto.
Qed.
Lemma ctx_fleq_fixed_eq Φ Γ Δ :
ctx_fleq Φ Γ Δ ->
fixed_ctx Γ = fixed_ctx Δ.
Proof.
move => h. elim : Φ Γ Δ / h => //=.
- hauto lq:on.
- move => Φ Γ Δ 0 1 h ih h0 h1.
f_equal => //.
move {h0 ih h}.
hauto lq:on inv:Level.
Qed.
Lemma upgrading_liftable Φ Γ Δ a A :
Γ a ;; A ->
liftable Φ a ->
ctx_fleq Φ Γ Δ ->
Δ a ;; A.
Proof.
move => h. move : Φ Δ.
elim : Γ a A /h.
- move => Γ i 0 A h hi Φ Δ /= h0 h1.
econstructor; eauto.
eauto using ctx_fleq_lookup.
- hauto lq:on ctrs:Wt.
- move => Γ a A B ha iha Φ Δ hla hleq /=.
constructor. apply : iha => /=; cycle 1; eauto.
by constructor.
- move => Γ 0 a b A B hb ihb ha iha hla Φ Δ /= hlb hctx.
apply : T_App; eauto.
apply : iha; eauto.
sfirstorder use:ctx_fleq_fixed.
erewrite <- ctx_fleq_fixed_eq; eauto.
- move => Γ 0 b A B hb ihb Δ /=.
move => h0 h1. constructor. apply : ihb; eauto.
simpl. by constructor.
Qed.
Definition or_lvl (a : bool) l :=
match l with
| Fixed => Fixed
| Floating => Floating (a || )
end.
Definition or_ctx (a : bool) : ctx -> ctx := map (fun '(,A) => (or_lvl a , A)).
Lemma or_fixed_ctx (Γ : ctx) :
fixed_ctx (or_ctx Γ) = fixed_ctx Γ.
Proof.
elim : Γ => //=.
- case => //=.
move => 0 _ Γ.
move => h0. f_equal => //.
destruct 0 => //=.
Qed.
Definition or_ctx_lookup 0 i Γ A :
lookup i Γ (, A) ->
lookup i (or_ctx 0 Γ) (or_lvl 0 , A).
Proof.
elim : Γ i A; sauto.
Qed.
Lemma upgrading Γ a A :
Γ a ;; A ->
or_ctx Γ a ;; A.
Proof.
move => h. elim : Γ a A /h.
- move => Γ i 0 A h hi.
move /(or_ctx_lookup ) in hi.
apply T_Var with (0 := or_lvl 0); eauto.
destruct 0, => //=.
- hauto lq:on ctrs:Wt.
- move => Γ a A B /= ha iha.
rewrite Bool.orb_diag in iha.
hauto lq:on ctrs:Wt.
- move => Γ 0 a b A B hb ihb ha iha hla.
econstructor; eauto.
+ apply : upgrading_liftable. apply ha. eauto. clear.
elim : Γ => //=.
* constructor.
* case => //= 0 A Γ h0.
destruct 0 => //=.
by constructor.
constructor => //.
clear. sauto lq:on.
+ by rewrite or_fixed_ctx.
- hauto lq:on ctrs:Wt.
Qed.
End Typing.