| 1 |
(** * Homotopy Propositions *) |
| 2 |
(** A homotopy proposition, or hProp, is a subsingleton type, i.e., a |
| 3 |
type with at most one inhabitant. The property of being an hProp, |
| 4 |
i.e., being irrelevant when considering propositional equality |
| 5 |
([eq]) of terms, comes up frequently. Since it is frequently |
| 6 |
automatically inferrable from the structure of the type, we make a |
| 7 |
typeclass for it. *) |
| 8 |
Class IsHProp T := allpath_hprop : forall x y : T, x = y. |
| 9 |
|
| 10 |
Notation IsHPropRel R := (forall x y, IsHProp (R x y)). |
| 11 |
|
| 12 |
Ltac hprop_destruct_trivial_step := |
| 13 |
match goal with |
| 14 |
| [ H : unit |- _ ] => destruct H |
| 15 |
| [ H : True |- _ ] => destruct H |
| 16 |
| [ H : False |- _ ] => destruct H |
| 17 |
| [ H : Empty_set |- _ ] => destruct H |
| 18 |
| [ H : prod _ _ |- _ ] => destruct H |
| 19 |
| [ H : and _ _ |- _ ] => destruct H |
| 20 |
| [ H : sigT _ |- _ ] => destruct H |
| 21 |
| [ H : sig _ |- _ ] => destruct H |
| 22 |
| [ H : ex _ |- _ ] => destruct H |
| 23 |
| [ H : forall x y : ?A, x = y, x0 : ?A, x1 : ?A |- _ ] |
| 24 |
=> destruct (H x0 x1) |
| 25 |
| [ H : forall a0 (x y : _), x = y, x0 : ?A, x1 : ?A |- _ ] |
| 26 |
=> destruct (H _ x0 x1) |
| 27 |
end. |
| 28 |
Ltac hprop_destruct_trivial := repeat hprop_destruct_trivial_step. |
| 29 |
|
| 30 |
Ltac pre_hprop := |
| 31 |
repeat (intros |
| 32 |
|| subst |
| 33 |
|| hprop_destruct_trivial |
| 34 |
|| split |
| 35 |
|| unfold IsHProp in * |
| 36 |
|| hnf ). |
| 37 |
|
| 38 |
Ltac solve_hprop_transparent_with tac := |
| 39 |
pre_hprop; |
| 40 |
try solve [ reflexivity |
| 41 |
| decide equality; eauto with nocore |
| 42 |
| tac ]. |
| 43 |
|
| 44 |
Ltac solve_hprop_transparent := solve_hprop_transparent_with fail. |
| 45 |
|
| 46 |
Local Hint Extern 0 => solve [ solve_hprop_transparent ] : typeclass_instances. |
| 47 |
|
| 48 |
Global Instance ishprop_unit : IsHProp unit. exact _. Defined. |
| 49 |
Global Instance ishprop_True : IsHProp True. exact _. Defined. |
| 50 |
Global Instance ishprop_Empty_set : IsHProp Empty_set. exact _. Defined. |
| 51 |
Global Instance ishprop_False : IsHProp False. exact _. Defined. |
| 52 |
Global Instance ishprop_prod {A B} `{IsHProp A, IsHProp B} : IsHProp (A * B). exact _. Defined. |
| 53 |
Global Instance ishprop_and {A B : Prop} `{IsHProp A, IsHProp B} : IsHProp (A /\ B). exact _. Defined. |
| 54 |
Global Instance ishprop_sigT {A P} `{IsHProp A, forall a : A, IsHProp (P a)} : IsHProp (@sigT A P). exact _. Defined. |
| 55 |
Global Instance ishprop_sig {A} {P : A -> Prop} `{IsHProp A, forall a : A, IsHProp (P a)} : IsHProp (@sig A P). exact _. Defined. |
| 56 |
|
| 57 |
|
| 58 |
(** Tactics to eliminate proofs of type [x = x :> T] when [T] is an hProp. *) |
| 59 |
Ltac eliminate_hprop_eq_helper proof_of_eq hprop_hyp := |
| 60 |
assert (eq_refl = proof_of_eq) by apply hprop_hyp; |
| 61 |
subst proof_of_eq. |
| 62 |
Ltac eliminate_hprop_eq_at T := |
| 63 |
let hprop_hyp := constr:(_ : IsHPropRel (@eq T)) in |
| 64 |
repeat match goal with |
| 65 |
| [ H : ?x = ?x :> T |- _ ] => eliminate_hprop_eq_helper H hprop_hyp |
| 66 |
end. |
| 67 |
Ltac eliminate_hprop_eq := |
| 68 |
repeat match goal with |
| 69 |
| [ H : ?x = ?x :> ?T |- _ ] => clear H || (progress eliminate_hprop_eq_at T) |
| 70 |
end. |