2014-12-22 20:33:29 +00:00
|
|
|
/-
|
|
|
|
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Module: data.subtype
|
|
|
|
Author: Leonardo de Moura, Jeremy Avigad
|
|
|
|
-/
|
|
|
|
|
2014-09-03 23:00:38 +00:00
|
|
|
open decidable
|
2014-08-15 03:12:54 +00:00
|
|
|
|
2014-12-09 20:40:09 +00:00
|
|
|
set_option structure.proj_mk_thm true
|
|
|
|
|
2014-11-16 22:19:35 +00:00
|
|
|
structure subtype {A : Type} (P : A → Prop) :=
|
|
|
|
tag :: (elt_of : A) (has_property : P elt_of)
|
2014-08-15 03:12:54 +00:00
|
|
|
|
2015-02-26 00:20:44 +00:00
|
|
|
notation `{` binders `|` r:(scoped:1 P, subtype P) `}` := r
|
2014-08-15 03:12:54 +00:00
|
|
|
|
|
|
|
namespace subtype
|
2014-10-09 14:13:06 +00:00
|
|
|
variables {A : Type} {P : A → Prop}
|
2014-08-15 03:12:54 +00:00
|
|
|
|
2014-09-02 02:04:15 +00:00
|
|
|
theorem tag_irrelevant {a : A} (H1 H2 : P a) : tag a H1 = tag a H2 :=
|
|
|
|
rfl
|
2014-08-15 03:12:54 +00:00
|
|
|
|
|
|
|
theorem tag_eq {a1 a2 : A} {H1 : P a1} {H2 : P a2} (H3 : a1 = a2) : tag a1 H1 = tag a2 H2 :=
|
2014-09-05 01:41:06 +00:00
|
|
|
eq.subst H3 (take H2, tag_irrelevant H1 H2) H2
|
2014-08-15 03:12:54 +00:00
|
|
|
|
2014-11-16 22:19:35 +00:00
|
|
|
protected theorem equal {a1 a2 : {x | P x}} : ∀(H : elt_of a1 = elt_of a2), a1 = a2 :=
|
2014-09-04 22:03:59 +00:00
|
|
|
destruct a1 (take x1 H1, destruct a2 (take x2 H2 H, tag_eq H))
|
2014-08-15 03:12:54 +00:00
|
|
|
|
2014-11-16 22:19:35 +00:00
|
|
|
protected definition is_inhabited [instance] {a : A} (H : P a) : inhabited {x | P x} :=
|
2014-09-04 23:36:06 +00:00
|
|
|
inhabited.mk (tag a H)
|
2014-08-22 00:54:50 +00:00
|
|
|
|
2015-02-24 23:25:02 +00:00
|
|
|
protected definition has_decidable_eq [instance] [H : decidable_eq A] : decidable_eq {x | P x} :=
|
2014-11-16 22:19:35 +00:00
|
|
|
take a1 a2 : {x | P x},
|
2014-09-08 05:22:04 +00:00
|
|
|
have H1 : (a1 = a2) ↔ (elt_of a1 = elt_of a2), from
|
|
|
|
iff.intro (assume H, eq.subst H rfl) (assume H, equal H),
|
2014-12-16 03:17:51 +00:00
|
|
|
decidable_of_decidable_of_iff _ (iff.symm H1)
|
2014-08-22 00:54:50 +00:00
|
|
|
end subtype
|