2014-08-12 00:35:25 +00:00
|
|
|
-- Copyright (c) 2014 Microsoft Corporation. All rights reserved.
|
|
|
|
-- Released under Apache 2.0 license as described in the file LICENSE.
|
2014-11-09 01:56:37 +00:00
|
|
|
-- Authors: Jeremy Avigad, Floris van Doorn
|
2014-08-12 00:35:25 +00:00
|
|
|
-- Ported from Coq HoTT
|
2014-11-09 01:56:37 +00:00
|
|
|
|
|
|
|
import .path .logic data.nat.basic data.empty data.unit data.sigma .equiv
|
|
|
|
open path nat sigma unit
|
2014-11-19 01:51:58 +00:00
|
|
|
set_option pp.universes true
|
2014-08-12 00:35:25 +00:00
|
|
|
|
|
|
|
-- Truncation levels
|
|
|
|
-- -----------------
|
|
|
|
|
2014-11-06 22:26:23 +00:00
|
|
|
-- TODO: make everything universe polymorphic
|
|
|
|
|
2014-11-09 01:56:37 +00:00
|
|
|
-- TODO: everything definition with a hprop as codomain can be a theorem?
|
2014-08-12 00:35:25 +00:00
|
|
|
|
2014-11-09 01:56:37 +00:00
|
|
|
/- truncation indices -/
|
2014-08-12 00:35:25 +00:00
|
|
|
|
2014-11-05 01:34:18 +00:00
|
|
|
namespace truncation
|
|
|
|
|
2014-11-19 01:51:58 +00:00
|
|
|
inductive trunc_index : Type₁ :=
|
2014-11-09 01:56:37 +00:00
|
|
|
minus_two : trunc_index,
|
|
|
|
trunc_S : trunc_index → trunc_index
|
|
|
|
|
2014-11-30 03:08:37 +00:00
|
|
|
postfix `.+1`:(max+1) := trunc_index.trunc_S
|
|
|
|
postfix `.+2`:(max+1) := λn, (n .+1 .+1)
|
2014-11-09 01:56:37 +00:00
|
|
|
notation `-2` := trunc_index.minus_two
|
|
|
|
notation `-1` := (-2.+1)
|
|
|
|
|
|
|
|
namespace trunc_index
|
|
|
|
definition add (n m : trunc_index) : trunc_index :=
|
|
|
|
trunc_index.rec_on m n (λ k l, l .+1)
|
|
|
|
|
|
|
|
definition leq (n m : trunc_index) : Type₁ :=
|
|
|
|
trunc_index.rec_on n (λm, unit) (λ n p m, trunc_index.rec_on m (λ p, empty) (λ m q p, p m) p) m
|
|
|
|
end trunc_index
|
|
|
|
|
|
|
|
-- Coq calls this `-2+`, but `+2+` looks more natural, since trunc_index_add 0 0 = 2
|
2014-11-09 22:22:42 +00:00
|
|
|
infix `+2+`:65 := trunc_index.add
|
2014-11-09 01:56:37 +00:00
|
|
|
|
|
|
|
notation x <= y := trunc_index.leq x y
|
|
|
|
notation x ≤ y := trunc_index.leq x y
|
|
|
|
|
|
|
|
namespace trunc_index
|
|
|
|
definition succ_le {n m : trunc_index} (H : n ≤ m) : n.+1 ≤ m.+1 := H
|
|
|
|
definition succ_le_cancel {n m : trunc_index} (H : n.+1 ≤ m.+1) : n ≤ m := H
|
|
|
|
definition minus_two_le (n : trunc_index) : -2 ≤ n := star
|
|
|
|
definition not_succ_le_minus_two {n : trunc_index} (H : n .+1 ≤ -2) : empty := H
|
|
|
|
end trunc_index
|
|
|
|
|
|
|
|
definition nat_to_trunc_index [coercion] (n : nat) : trunc_index :=
|
|
|
|
nat.rec_on n (-1.+1) (λ n k, k.+1)
|
|
|
|
|
|
|
|
/- truncated types -/
|
|
|
|
|
|
|
|
/-
|
|
|
|
Just as in Coq HoTT we define an internal version of contractibility and is_trunc, but we only
|
|
|
|
use `is_trunc` and `is_contr`
|
|
|
|
-/
|
|
|
|
|
2014-11-09 22:22:42 +00:00
|
|
|
structure contr_internal (A : Type) :=
|
2014-11-19 01:51:58 +00:00
|
|
|
(center : A) (contr : Π(a : A), center ≈ a)
|
2014-11-09 01:56:37 +00:00
|
|
|
|
2014-11-09 22:22:42 +00:00
|
|
|
definition is_trunc_internal (n : trunc_index) : Type → Type :=
|
2014-11-19 01:51:58 +00:00
|
|
|
trunc_index.rec_on n (λA, contr_internal A)
|
|
|
|
(λn trunc_n A, (Π(x y : A), trunc_n (x ≈ y)))
|
2014-11-09 01:56:37 +00:00
|
|
|
|
2014-11-09 22:22:42 +00:00
|
|
|
structure is_trunc [class] (n : trunc_index) (A : Type) :=
|
2014-11-19 01:51:58 +00:00
|
|
|
(to_internal : is_trunc_internal n A)
|
2014-11-09 01:56:37 +00:00
|
|
|
|
|
|
|
-- should this be notation or definitions?
|
|
|
|
notation `is_contr` := is_trunc -2
|
|
|
|
notation `is_hprop` := is_trunc -1
|
2014-12-04 00:28:32 +00:00
|
|
|
notation `is_hset` := is_trunc (nat_to_trunc_index nat.zero)
|
2014-11-09 01:56:37 +00:00
|
|
|
-- definition is_contr := is_trunc -2
|
|
|
|
-- definition is_hprop := is_trunc -1
|
|
|
|
-- definition is_hset := is_trunc 0
|
|
|
|
|
2014-11-09 22:22:42 +00:00
|
|
|
variables {A B : Type}
|
2014-11-09 01:56:37 +00:00
|
|
|
|
|
|
|
-- maybe rename to is_trunc_succ.mk
|
2014-12-02 04:12:57 +00:00
|
|
|
definition is_trunc_succ (A : Type) (n : trunc_index) [H : ∀x y : A, is_trunc n (x ≈ y)]
|
2014-11-09 01:56:37 +00:00
|
|
|
: is_trunc n.+1 A :=
|
2014-11-26 02:04:06 +00:00
|
|
|
is_trunc.mk (λ x y, !is_trunc.to_internal)
|
2014-11-09 01:56:37 +00:00
|
|
|
|
|
|
|
-- maybe rename to is_trunc_succ.elim
|
2014-12-02 04:12:57 +00:00
|
|
|
definition succ_is_trunc (n : trunc_index) [H : is_trunc (n.+1) A] (x y : A) : is_trunc n (x ≈ y) :=
|
2014-11-26 02:04:06 +00:00
|
|
|
is_trunc.mk (!is_trunc.to_internal x y)
|
2014-11-09 01:56:37 +00:00
|
|
|
|
|
|
|
/- contractibility -/
|
|
|
|
|
|
|
|
definition is_contr.mk (center : A) (contr : Π(a : A), center ≈ a) : is_contr A :=
|
|
|
|
is_trunc.mk (contr_internal.mk center contr)
|
|
|
|
|
2014-11-09 22:22:42 +00:00
|
|
|
definition center (A : Type) [H : is_contr A] : A :=
|
2014-11-26 02:04:06 +00:00
|
|
|
@contr_internal.center A !is_trunc.to_internal
|
2014-11-09 01:56:37 +00:00
|
|
|
|
|
|
|
definition contr [H : is_contr A] (a : A) : !center ≈ a :=
|
2014-11-26 02:04:06 +00:00
|
|
|
@contr_internal.contr A !is_trunc.to_internal a
|
2014-11-09 01:56:37 +00:00
|
|
|
|
|
|
|
definition path_contr [H : is_contr A] (x y : A) : x ≈ y :=
|
|
|
|
contr x⁻¹ ⬝ (contr y)
|
|
|
|
|
2014-11-09 22:22:42 +00:00
|
|
|
definition path2_contr {A : Type} [H : is_contr A] {x y : A} (p q : x ≈ y) : p ≈ q :=
|
2014-11-09 01:56:37 +00:00
|
|
|
have K : ∀ (r : x ≈ y), path_contr x y ≈ r, from (λ r, path.rec_on r !concat_Vp),
|
|
|
|
K p⁻¹ ⬝ K q
|
|
|
|
|
2014-11-09 22:22:42 +00:00
|
|
|
definition contr_paths_contr [instance] {A : Type} [H : is_contr A] (x y : A) : is_contr (x ≈ y) :=
|
2014-11-09 01:56:37 +00:00
|
|
|
is_contr.mk !path_contr (λ p, !path2_contr)
|
|
|
|
|
|
|
|
/- truncation is upward close -/
|
|
|
|
|
|
|
|
-- n-types are also (n+1)-types
|
2014-11-09 22:22:42 +00:00
|
|
|
definition trunc_succ [instance] (A : Type) (n : trunc_index) [H : is_trunc n A] : is_trunc (n.+1) A :=
|
2014-11-09 01:56:37 +00:00
|
|
|
trunc_index.rec_on n
|
|
|
|
(λ A (H : is_contr A), !is_trunc_succ)
|
|
|
|
(λ n IH A (H : is_trunc (n.+1) A), @is_trunc_succ _ _ (λ x y, IH _ !succ_is_trunc))
|
|
|
|
A H
|
|
|
|
--in the proof the type of H is given explicitly to make it available for class inference
|
|
|
|
|
|
|
|
|
2014-11-09 22:22:42 +00:00
|
|
|
definition trunc_leq (A : Type) (n m : trunc_index) (Hnm : n ≤ m)
|
2014-11-09 01:56:37 +00:00
|
|
|
[Hn : is_trunc n A] : is_trunc m A :=
|
|
|
|
have base : ∀k A, k ≤ -2 → is_trunc k A → (is_trunc -2 A), from
|
|
|
|
λ k A, trunc_index.cases_on k
|
|
|
|
(λh1 h2, h2)
|
|
|
|
(λk h1 h2, empty.elim (is_trunc -2 A) (trunc_index.not_succ_le_minus_two h1)),
|
|
|
|
have step : Π (m : trunc_index)
|
2014-11-09 22:22:42 +00:00
|
|
|
(IHm : Π (n : trunc_index) (A : Type), n ≤ m → is_trunc n A → is_trunc m A)
|
|
|
|
(n : trunc_index) (A : Type)
|
2014-11-09 01:56:37 +00:00
|
|
|
(Hnm : n ≤ m .+1) (Hn : is_trunc n A), is_trunc m .+1 A, from
|
|
|
|
λm IHm n, trunc_index.rec_on n
|
|
|
|
(λA Hnm Hn, @trunc_succ A m (IHm -2 A star Hn))
|
|
|
|
(λn IHn A Hnm (Hn : is_trunc n.+1 A),
|
|
|
|
@is_trunc_succ A m (λx y, IHm n (x≈y) (trunc_index.succ_le_cancel Hnm) !succ_is_trunc)),
|
|
|
|
trunc_index.rec_on m base step n A Hnm Hn
|
|
|
|
|
|
|
|
-- the following cannot be instances in their current form, because it is looping
|
2014-11-09 22:22:42 +00:00
|
|
|
definition trunc_contr (A : Type) (n : trunc_index) [H : is_contr A] : is_trunc n A :=
|
2014-11-09 01:56:37 +00:00
|
|
|
trunc_index.rec_on n H _
|
|
|
|
|
2014-11-09 22:22:42 +00:00
|
|
|
definition trunc_hprop (A : Type) (n : trunc_index) [H : is_hprop A]
|
2014-11-09 01:56:37 +00:00
|
|
|
: is_trunc (n.+1) A :=
|
|
|
|
trunc_leq A -1 (n.+1) star
|
|
|
|
|
2014-11-09 22:22:42 +00:00
|
|
|
definition trunc_hset (A : Type) (n : trunc_index) [H : is_hset A]
|
2014-11-09 01:56:37 +00:00
|
|
|
: is_trunc (n.+2) A :=
|
|
|
|
trunc_leq A 0 (n.+2) star
|
|
|
|
|
|
|
|
/- hprops -/
|
|
|
|
|
|
|
|
definition is_hprop.elim [H : is_hprop A] (x y : A) : x ≈ y :=
|
|
|
|
@center _ !succ_is_trunc
|
2014-11-05 01:34:18 +00:00
|
|
|
|
2014-11-09 22:22:42 +00:00
|
|
|
definition contr_inhabited_hprop {A : Type} [H : is_hprop A] (x : A) : is_contr A :=
|
2014-11-09 01:56:37 +00:00
|
|
|
is_contr.mk x (λy, !is_hprop.elim)
|
2014-11-05 01:34:18 +00:00
|
|
|
|
2014-11-09 01:56:37 +00:00
|
|
|
--Coq has the following as instance, but doesn't look too useful
|
2014-11-09 22:22:42 +00:00
|
|
|
definition hprop_inhabited_contr {A : Type} (H : A → is_contr A) : is_hprop A :=
|
2014-11-09 01:56:37 +00:00
|
|
|
@is_trunc_succ A -2
|
|
|
|
(λx y,
|
|
|
|
have H2 [visible] : is_contr A, from H x,
|
|
|
|
!contr_paths_contr)
|
2014-11-05 01:34:18 +00:00
|
|
|
|
2014-11-09 22:22:42 +00:00
|
|
|
definition is_hprop.mk {A : Type} (H : ∀x y : A, x ≈ y) : is_hprop A :=
|
2014-11-09 01:56:37 +00:00
|
|
|
hprop_inhabited_contr (λ x, is_contr.mk x (H x))
|
2014-11-05 01:34:18 +00:00
|
|
|
|
2014-11-09 01:56:37 +00:00
|
|
|
/- hsets -/
|
2014-11-05 01:34:18 +00:00
|
|
|
|
2014-11-09 22:22:42 +00:00
|
|
|
definition is_hset.mk (A : Type) (H : ∀(x y : A) (p q : x ≈ y), p ≈ q) : is_hset A :=
|
2014-11-09 01:56:37 +00:00
|
|
|
@is_trunc_succ _ _ (λ x y, is_hprop.mk (H x y))
|
2014-08-12 00:35:25 +00:00
|
|
|
|
2014-11-09 01:56:37 +00:00
|
|
|
definition is_hset.elim [H : is_hset A] ⦃x y : A⦄ (p q : x ≈ y) : p ≈ q :=
|
|
|
|
@is_hprop.elim _ !succ_is_trunc p q
|
2014-11-05 01:34:18 +00:00
|
|
|
|
2014-11-09 01:56:37 +00:00
|
|
|
/- instances -/
|
2014-11-05 01:34:18 +00:00
|
|
|
|
2014-11-09 22:22:42 +00:00
|
|
|
definition contr_basedpaths [instance] {A : Type} (a : A) : is_contr (Σ(x : A), a ≈ x) :=
|
2014-11-09 01:56:37 +00:00
|
|
|
is_contr.mk (dpair a idp) (λp, sigma.rec_on p (λ b q, path.rec_on q idp))
|
2014-11-05 01:34:18 +00:00
|
|
|
|
2014-11-20 18:37:02 +00:00
|
|
|
-- definition is_trunc_is_hprop [instance] {n : trunc_index} : is_hprop (is_trunc n A) := sorry
|
2014-11-05 01:34:18 +00:00
|
|
|
|
2014-11-09 01:56:37 +00:00
|
|
|
definition unit_contr [instance] : is_contr unit :=
|
|
|
|
is_contr.mk star (λp, unit.rec_on p idp)
|
2014-11-05 01:34:18 +00:00
|
|
|
|
2014-11-09 01:56:37 +00:00
|
|
|
definition empty_hprop [instance] : is_hprop empty :=
|
|
|
|
is_hprop.mk (λx, !empty.elim x)
|
2014-11-06 22:26:23 +00:00
|
|
|
|
2014-11-09 01:56:37 +00:00
|
|
|
/- truncated universe -/
|
2014-11-06 22:26:23 +00:00
|
|
|
|
2014-11-09 01:56:37 +00:00
|
|
|
structure trunctype (n : trunc_index) :=
|
2014-11-09 22:22:42 +00:00
|
|
|
(trunctype_type : Type) (is_trunc_trunctype_type : is_trunc n trunctype_type)
|
2014-11-09 01:56:37 +00:00
|
|
|
coercion trunctype.trunctype_type
|
2014-11-05 01:34:18 +00:00
|
|
|
|
2014-11-09 01:56:37 +00:00
|
|
|
notation n `-Type` := trunctype n
|
2014-11-09 22:22:42 +00:00
|
|
|
notation `hprop` := -1-Type
|
|
|
|
notation `hset` := 0-Type
|
2014-11-05 01:34:18 +00:00
|
|
|
|
2014-11-09 01:56:37 +00:00
|
|
|
definition hprop.mk := @trunctype.mk -1
|
|
|
|
definition hset.mk := @trunctype.mk 0
|
2014-11-05 01:34:18 +00:00
|
|
|
|
2014-11-09 01:56:37 +00:00
|
|
|
--what does the following line in Coq do?
|
|
|
|
--Canonical Structure default_TruncType := fun n T P => (@BuildTruncType n T P).
|
2014-11-05 01:34:18 +00:00
|
|
|
|
2014-11-09 01:56:37 +00:00
|
|
|
/- interaction with equivalences -/
|
2014-11-05 01:34:18 +00:00
|
|
|
|
2014-11-09 01:56:37 +00:00
|
|
|
section
|
2014-11-26 04:30:52 +00:00
|
|
|
open is_equiv equiv
|
2014-11-05 01:34:18 +00:00
|
|
|
|
2014-11-09 01:56:37 +00:00
|
|
|
--should we remove the following two theorems as they are special cases of "trunc_equiv"
|
2014-11-26 04:30:52 +00:00
|
|
|
definition equiv_preserves_contr (f : A → B) [Hf : is_equiv f] [HA: is_contr A] : (is_contr B) :=
|
|
|
|
is_contr.mk (f (center A)) (λp, moveR_M f !contr)
|
2014-11-06 23:54:18 +00:00
|
|
|
|
2014-11-26 04:30:52 +00:00
|
|
|
theorem contr_equiv (H : A ≃ B) [HA: is_contr A] : is_contr B :=
|
|
|
|
@equiv_preserves_contr _ _ (to_fun H) (to_is_equiv H) _
|
2014-11-06 23:54:18 +00:00
|
|
|
|
2014-11-09 01:56:37 +00:00
|
|
|
definition contr_equiv_contr [HA : is_contr A] [HB : is_contr B] : A ≃ B :=
|
2014-11-26 04:30:52 +00:00
|
|
|
equiv.mk
|
2014-11-09 01:56:37 +00:00
|
|
|
(λa, center B)
|
2014-11-26 04:30:52 +00:00
|
|
|
(is_equiv.adjointify (λa, center B) (λb, center A) contr contr)
|
2014-11-06 23:54:18 +00:00
|
|
|
|
2014-11-26 04:30:52 +00:00
|
|
|
definition trunc_equiv (n : trunc_index) (f : A → B) [H : is_equiv f] [HA : is_trunc n A]
|
2014-11-09 01:56:37 +00:00
|
|
|
: is_trunc n B :=
|
|
|
|
trunc_index.rec_on n
|
2014-11-26 04:30:52 +00:00
|
|
|
(λA (HA : is_contr A) B f (H : is_equiv f), !equiv_preserves_contr)
|
|
|
|
(λn IH A (HA : is_trunc n.+1 A) B f (H : is_equiv f), @is_trunc_succ _ _ (λ x y : B,
|
2014-11-09 01:56:37 +00:00
|
|
|
IH (f⁻¹ x ≈ f⁻¹ y) !succ_is_trunc (x ≈ y) ((ap (f⁻¹))⁻¹) !inv_closed))
|
|
|
|
A HA B f H
|
2014-11-06 23:54:18 +00:00
|
|
|
|
2014-11-09 01:56:37 +00:00
|
|
|
definition trunc_equiv' (n : trunc_index) (f : A ≃ B) [HA : is_trunc n A] : is_trunc n B :=
|
2014-11-26 04:30:52 +00:00
|
|
|
trunc_equiv n (to_fun f)
|
2014-08-12 00:35:25 +00:00
|
|
|
|
2014-11-09 01:56:37 +00:00
|
|
|
definition isequiv_iff_hprop [HA : is_hprop A] [HB : is_hprop B] (f : A → B) (g : B → A)
|
2014-11-26 04:30:52 +00:00
|
|
|
: is_equiv f :=
|
|
|
|
is_equiv.adjointify f g (λb, !is_hprop.elim) (λa, !is_hprop.elim)
|
2014-11-06 22:26:23 +00:00
|
|
|
|
2014-11-09 01:56:37 +00:00
|
|
|
-- definition equiv_iff_hprop_uncurried [HA : is_hprop A] [HB : is_hprop B] : (A ↔ B) → (A ≃ B) := sorry
|
2014-11-06 22:26:23 +00:00
|
|
|
|
2014-11-09 01:56:37 +00:00
|
|
|
definition equiv_iff_hprop [HA : is_hprop A] [HB : is_hprop B] (f : A → B) (g : B → A) : A ≃ B :=
|
2014-11-26 04:30:52 +00:00
|
|
|
equiv.mk f (isequiv_iff_hprop f g)
|
2014-11-09 01:56:37 +00:00
|
|
|
end
|
2014-11-06 22:26:23 +00:00
|
|
|
|
2014-11-12 21:31:44 +00:00
|
|
|
/- interaction with the Unit type -/
|
|
|
|
|
|
|
|
-- A contractible type is equivalent to [Unit]. *)
|
|
|
|
definition equiv_contr_unit [H : is_contr A] : A ≃ unit :=
|
2014-11-26 04:30:52 +00:00
|
|
|
equiv.mk (λ (x : A), ⋆)
|
|
|
|
(is_equiv.mk (λ (u : unit), center A)
|
2014-11-12 21:31:44 +00:00
|
|
|
(λ (u : unit), unit.rec_on u idp)
|
|
|
|
(λ (x : A), contr x)
|
|
|
|
(λ (x : A), (!ap_const)⁻¹))
|
|
|
|
|
2014-11-09 01:56:37 +00:00
|
|
|
-- TODO: port "Truncated morphisms"
|
2014-11-06 22:26:23 +00:00
|
|
|
|
2014-11-05 01:34:18 +00:00
|
|
|
end truncation
|