2014-08-07 18:36:44 +00:00
|
|
|
|
----------------------------------------------------------------------------------------------------
|
2014-08-04 02:57:29 +00:00
|
|
|
|
-- Copyright (c) 2014 Microsoft Corporation. All rights reserved.
|
2014-07-04 03:43:16 +00:00
|
|
|
|
-- Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
-- Author: Leonardo de Moura
|
2014-08-01 01:40:09 +00:00
|
|
|
|
----------------------------------------------------------------------------------------------------
|
|
|
|
|
|
2014-08-04 02:57:29 +00:00
|
|
|
|
import logic.classes.inhabited logic.connectives.eq
|
2014-07-04 03:43:16 +00:00
|
|
|
|
|
2014-07-07 21:48:19 +00:00
|
|
|
|
namespace pair
|
2014-07-04 03:43:16 +00:00
|
|
|
|
inductive pair (A : Type) (B : Type) : Type :=
|
|
|
|
|
| mk_pair : A → B → pair A B
|
|
|
|
|
|
2014-08-07 23:59:08 +00:00
|
|
|
|
section thms
|
2014-07-04 03:43:16 +00:00
|
|
|
|
parameter {A : Type}
|
|
|
|
|
parameter {B : Type}
|
|
|
|
|
|
|
|
|
|
definition fst [inline] (p : pair A B) := pair_rec (λ x y, x) p
|
|
|
|
|
definition snd [inline] (p : pair A B) := pair_rec (λ x y, y) p
|
|
|
|
|
|
2014-07-29 02:58:57 +00:00
|
|
|
|
theorem pair_inhabited (H1 : inhabited A) (H2 : inhabited B) : inhabited (pair A B) :=
|
|
|
|
|
inhabited_elim H1 (λ a, inhabited_elim H2 (λ b, inhabited_intro (mk_pair a b)))
|
2014-07-04 03:43:16 +00:00
|
|
|
|
|
2014-07-29 02:58:57 +00:00
|
|
|
|
theorem fst_mk_pair (a : A) (b : B) : fst (mk_pair a b) = a :=
|
|
|
|
|
refl a
|
2014-07-04 03:43:16 +00:00
|
|
|
|
|
2014-07-29 02:58:57 +00:00
|
|
|
|
theorem snd_mk_pair (a : A) (b : B) : snd (mk_pair a b) = b :=
|
|
|
|
|
refl b
|
2014-07-04 03:43:16 +00:00
|
|
|
|
|
2014-07-29 02:58:57 +00:00
|
|
|
|
theorem pair_ext (p : pair A B) : mk_pair (fst p) (snd p) = p :=
|
|
|
|
|
pair_rec (λ x y, refl (mk_pair x y)) p
|
2014-07-19 19:09:47 +00:00
|
|
|
|
|
2014-07-29 02:58:57 +00:00
|
|
|
|
theorem pair_ext_eq {p1 p2 : pair A B} (H1 : fst p1 = fst p2) (H2 : snd p1 = snd p2) : p1 = p2 :=
|
|
|
|
|
calc p1 = mk_pair (fst p1) (snd p1) : symm (pair_ext p1)
|
|
|
|
|
... = mk_pair (fst p2) (snd p1) : {H1}
|
|
|
|
|
... = mk_pair (fst p2) (snd p2) : {H2}
|
|
|
|
|
... = p2 : pair_ext p2
|
2014-08-07 23:59:08 +00:00
|
|
|
|
end thms
|
2014-07-07 21:48:19 +00:00
|
|
|
|
|
2014-07-07 22:40:32 +00:00
|
|
|
|
instance pair_inhabited
|
2014-07-04 22:45:50 +00:00
|
|
|
|
|
|
|
|
|
precedence `×`:30
|
|
|
|
|
infixr × := pair
|
2014-07-04 03:43:16 +00:00
|
|
|
|
|
|
|
|
|
-- notation for n-ary tuples
|
|
|
|
|
notation `(` h `,` t:(foldl `,` (e r, mk_pair r e) h) `)` := t
|
2014-08-07 23:59:08 +00:00
|
|
|
|
end pair
|