Built with Alectryon, running Coq+SerAPI v8.18.0+0.18.3. Bubbles () indicate interactive fragments: hover for details, tap to reveal contents. Use Ctrl+↑Ctrl+↓ to navigate, Ctrl+🖱️ to focus. On Mac, use ⌘ instead of Ctrl.
(* -*- mode: coq; mode: visual-line -*- *)
[Loading ML file number_string_notation_plugin.cmxs (using legacy method) ... done]
LocalOpen Scope trunc_scope.LocalOpen Scope path_scope.(** * Decidability *)(** ** Definitions *)(* NB: This has to come after our definition of [not] (which is in [Overture]), so that it refers to our [not] rather than the one in [Coq.Logic]. *)ClassDecidable (A : Type) :=
dec : A + (~ A).Arguments dec A {_}.(** The [decide_type] and [decide] tactic allow to automatically provedecidable claims using previously written decision procedures thatcompute. *)Ltacdecide_type A :=
letK := (evalhnfin (dec A)) inmatch K with
| inl ?Z => exact Z
| inr ?Z => exact Z
end.Ltacdecide :=
match goal with
| [|- ?A] => decide_type A
end.ClassDecidablePaths (A : Type) :=
dec_paths : forall (xy : A), Decidable (x = y).Global Existing Instancedec_paths.ClassStableP := stable : ~~P -> P.
P: Type Decidable0: Decidable P
Stable P
P: Type Decidable0: Decidable P
Stable P
P: Type Decidable0: Decidable P dn: ~~ P p: P
P
P: Type Decidable0: Decidable P dn: ~~ P n: ~ P
P
P: Type Decidable0: Decidable P dn: ~~ P p: P
P
assumption.
P: Type Decidable0: Decidable P dn: ~~ P n: ~ P
P
apply Empty_rect,dn,n.Qed.
P: Type
Stable (~ P)
P: Type
Stable (~ P)
P: Type nnnp: ~~ ~ P p: P
Empty
exact (nnnp (funnp => np p)).Defined.(** Because [vm_compute] evaluates terms in [PROP] eagerly and does not remove dead code we need the decide_rel hack. Suppose we have [(x = y) =def (f x = f y)], now: bool_decide (x = y) -> bool_decide (f x = f y) -> ... As we see, the dead code [f x] and [f y] is actually evaluated, which is of course an utter waste. Therefore we introduce decide_rel and bool_decide_rel. bool_decide_rel (=) x y -> bool_decide_rel (fun a b => f a = f b) x y -> ... Now the definition of equality remains under a lambda and our problem does not occur anymore!*)Definitiondecide_rel {AB} (R : A -> B -> Type)
{dec : forallxy, Decidable (R x y)} (x : A) (y : B)
: Decidable (R x y)
:= dec x y.(** ** Decidable hprops *)(** Contractible types are decidable. *)Global Instancedecidable_contrX `{Contr X} : Decidable X
:= inl (center X).(** Thus, hprops have decidable equality. *)Global Instancedecidablepaths_hpropX `{IsHProp X} : DecidablePaths X
:= funxy => dec (x = y).(** Empty types are trivial. *)Global Instancedecidable_empty : Decidable Empty
:= inr idmap.(** ** Transfer along equivalences *)
A, B: Type f: A -> B H: IsEquiv f
Decidable A -> Decidable B
A, B: Type f: A -> B H: IsEquiv f
Decidable A -> Decidable B
A, B: Type f: A -> B H: IsEquiv f a: A
Decidable B
A, B: Type f: A -> B H: IsEquiv f na: ~ A
Decidable B
A, B: Type f: A -> B H: IsEquiv f a: A
Decidable B
exact (inl (f a)).
A, B: Type f: A -> B H: IsEquiv f na: ~ A
Decidable B
exact (inr (funb => na (f^-1 b))).Defined.Definitiondecidable_equiv' (A : Type) {B : Type} (f : A <~> B)
: Decidable A -> Decidable B
:= decidable_equiv A f.
A, B: Type f: A -> B H: IsEquiv f
DecidablePaths A -> DecidablePaths B
A, B: Type f: A -> B H: IsEquiv f
DecidablePaths A -> DecidablePaths B
A, B: Type f: A -> B H: IsEquiv f d: DecidablePaths A x, y: B
Decidable (x = y)
A, B: Type f: A -> B H: IsEquiv f d: DecidablePaths A x, y: B e: f^-1 x = f^-1 y
Decidable (x = y)
A, B: Type f: A -> B H: IsEquiv f d: DecidablePaths A x, y: B ne: f^-1 x <> f^-1 y
Decidable (x = y)
A, B: Type f: A -> B H: IsEquiv f d: DecidablePaths A x, y: B e: f^-1 x = f^-1 y
Decidable (x = y)
A, B: Type f: A -> B H: IsEquiv f d: DecidablePaths A x, y: B e: f^-1 x = f^-1 y
x = y
exact ((eisretr f x)^ @ ap f e @ eisretr f y).
A, B: Type f: A -> B H: IsEquiv f d: DecidablePaths A x, y: B ne: f^-1 x <> f^-1 y
Decidable (x = y)
A, B: Type f: A -> B H: IsEquiv f d: DecidablePaths A x, y: B ne: f^-1 x <> f^-1 y p: x = y
Empty
apply ne, ap, p.Defined.Definitiondecidablepaths_equiv' (A : Type) {B : Type} (f : A <~> B)
: DecidablePaths A -> DecidablePaths B
:= decidablepaths_equiv A f.(** ** Hedberg's theorem: any type with decidable equality is a set. *)(** A weakly constant function is one all of whose values are equal (in a specified way). *)ClassWeaklyConstant {AB} (f : A -> B) :=
wconst : forallxy, f x = f y.(** Any map that factors through an hprop is weakly constant. *)
A, B, P: Type IsHProp0: IsHProp P f: A -> P g: P -> B
WeaklyConstant (g o f)
A, B, P: Type IsHProp0: IsHProp P f: A -> P g: P -> B
WeaklyConstant (g o f)
intros x y; apply (ap g), path_ishprop.Defined.(** A type is collapsible if it admits a weakly constant endomap. *)ClassCollapsible (A : Type) :=
{ collapse : A -> A ;
wconst_collapse : WeaklyConstant collapse
}.Global Existing Instancewconst_collapse.ClassPathCollapsible (A : Type) :=
path_coll : forall (xy : A), Collapsible (x = y).Global Existing Instancepath_coll.
A: Type H: Decidable A
Collapsible A
A: Type H: Decidable A
Collapsible A
A: Type H: Decidable A a: A
Collapsible A
A: Type H: Decidable A na: ~ A
Collapsible A
A: Type H: Decidable A a: A
Collapsible A
A: Type H: Decidable A a: A
WeaklyConstant (const a)
intros x y; reflexivity.
A: Type H: Decidable A na: ~ A
Collapsible A
A: Type H: Decidable A na: ~ A
WeaklyConstant idmap
intros x y; destruct (na x).Defined.
A: Type H: DecidablePaths A
PathCollapsible A
A: Type H: DecidablePaths A
PathCollapsible A
intros x y; exact _.Defined.(** We give this a relatively high-numbered priority so that in deducing [IsHProp -> IsHSet] Coq doesn't detour via [DecidablePaths]. *)
A: Type H: PathCollapsible A
IsHSet A
A: Type H: PathCollapsible A
IsHSet A
A: Type H: PathCollapsible A
is_mere_relation A paths
A: Type H: PathCollapsible A x, y: A
IsHProp (x = y)
A: Type H: PathCollapsible A x, y: A
forallp : x = y, p = (collapse 1)^ @ collapse p
A: Type H: PathCollapsible A x, y: A h: forallp : x = y, p = (collapse 1)^ @ collapse p
IsHProp (x = y)
A: Type H: PathCollapsible A x, y: A
forallp : x = y, p = (collapse 1)^ @ collapse p
intros []; symmetry; byapply concat_Vp.
A: Type H: PathCollapsible A x, y: A h: forallp : x = y, p = (collapse 1)^ @ collapse p
IsHProp (x = y)
A: Type H: PathCollapsible A x, y: A h: forallp : x = y, p = (collapse 1)^ @ collapse p p, q: x = y
p = q
A: Type H: PathCollapsible A x, y: A h: forallp : x = y, p = (collapse 1)^ @ collapse p p, q: x = y