2014-08-15 03:12:54 +00:00
|
|
|
-- Copyright (c) 2014 Microsoft Corporation. All rights reserved.
|
|
|
|
-- Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
-- Author: Leonardo de Moura, Jeremy Avigad
|
|
|
|
|
2014-08-28 01:39:55 +00:00
|
|
|
import logic.classes.inhabited logic.core.eq
|
2014-08-15 03:12:54 +00:00
|
|
|
|
2014-09-03 23:00:38 +00:00
|
|
|
open inhabited
|
2014-08-20 02:32:44 +00:00
|
|
|
|
2014-08-15 03:12:54 +00:00
|
|
|
inductive sigma {A : Type} (B : A → Type) : Type :=
|
2014-08-22 22:46:10 +00:00
|
|
|
dpair : Πx : A, B x → sigma B
|
2014-08-15 03:12:54 +00:00
|
|
|
|
|
|
|
notation `Σ` binders `,` r:(scoped P, sigma P) := r
|
|
|
|
|
|
|
|
namespace sigma
|
|
|
|
section
|
|
|
|
parameters {A : Type} {B : A → Type}
|
|
|
|
|
2014-09-04 22:03:59 +00:00
|
|
|
abbreviation dpr1 (p : Σ x, B x) : A := rec (λ a b, a) p
|
|
|
|
abbreviation dpr2 {A : Type} {B : A → Type} (p : Σ x, B x) : B (dpr1 p) := rec (λ a b, b) p
|
2014-08-15 03:12:54 +00:00
|
|
|
|
2014-09-04 23:36:06 +00:00
|
|
|
theorem dpr1_dpair (a : A) (b : B a) : dpr1 (dpair a b) = a := rfl
|
|
|
|
theorem dpr2_dpair (a : A) (b : B a) : dpr2 (dpair a b) = b := rfl
|
2014-08-15 03:12:54 +00:00
|
|
|
|
|
|
|
-- TODO: remove prefix when we can protect it
|
|
|
|
theorem sigma_destruct {P : sigma B → Prop} (p : sigma B) (H : ∀a b, P (dpair a b)) : P p :=
|
2014-09-04 22:03:59 +00:00
|
|
|
rec H p
|
2014-08-15 03:12:54 +00:00
|
|
|
|
|
|
|
theorem dpair_ext (p : sigma B) : dpair (dpr1 p) (dpr2 p) = p :=
|
2014-09-02 02:44:04 +00:00
|
|
|
sigma_destruct p (take a b, rfl)
|
2014-08-15 03:12:54 +00:00
|
|
|
|
|
|
|
-- Note that we give the general statment explicitly, to help the unifier
|
2014-09-04 23:36:06 +00:00
|
|
|
theorem dpair_eq {a1 a2 : A} {b1 : B a1} {b2 : B a2} (H1 : a1 = a2) (H2 : eq.rec_on H1 b1 = b2) :
|
2014-08-15 03:12:54 +00:00
|
|
|
dpair a1 b1 = dpair a2 b2 :=
|
2014-09-04 23:36:06 +00:00
|
|
|
(show ∀(b2 : B a2) (H1 : a1 = a2) (H2 : eq.rec_on H1 b1 = b2), dpair a1 b1 = dpair a2 b2, from
|
2014-09-04 22:03:59 +00:00
|
|
|
eq.rec
|
2014-08-15 03:12:54 +00:00
|
|
|
(take (b2' : B a1),
|
2014-08-22 22:46:10 +00:00
|
|
|
assume (H1' : a1 = a1),
|
2014-09-04 23:36:06 +00:00
|
|
|
assume (H2' : eq.rec_on H1' b1 = b2'),
|
2014-08-22 22:46:10 +00:00
|
|
|
show dpair a1 b1 = dpair a1 b2', from
|
|
|
|
calc
|
2014-09-05 01:41:06 +00:00
|
|
|
dpair a1 b1 = dpair a1 (eq.rec_on H1' b1) : {eq.symm (eq.rec_on_id H1' b1)}
|
2014-08-22 22:46:10 +00:00
|
|
|
... = dpair a1 b2' : {H2'}) H1)
|
2014-08-15 03:12:54 +00:00
|
|
|
b2 H1 H2
|
|
|
|
|
2014-09-05 05:31:52 +00:00
|
|
|
theorem equal [protected] {p1 p2 : Σx : A, B x} :
|
2014-09-04 23:36:06 +00:00
|
|
|
∀(H1 : dpr1 p1 = dpr1 p2) (H2 : eq.rec_on H1 (dpr2 p1) = (dpr2 p2)), p1 = p2 :=
|
2014-08-15 03:12:54 +00:00
|
|
|
sigma_destruct p1 (take a1 b1, sigma_destruct p2 (take a2 b2 H1 H2, dpair_eq H1 H2))
|
|
|
|
|
2014-09-05 05:31:52 +00:00
|
|
|
theorem is_inhabited [protected] [instance] (H1 : inhabited A) (H2 : inhabited (B (default A))) :
|
2014-08-15 03:12:54 +00:00
|
|
|
inhabited (sigma B) :=
|
2014-09-04 23:36:06 +00:00
|
|
|
inhabited.destruct H1 (λa, inhabited.destruct H2 (λb, inhabited.mk (dpair (default A) b)))
|
2014-08-15 03:12:54 +00:00
|
|
|
end
|
|
|
|
end sigma
|