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.
|
2014-08-17 21:41:23 +00:00
|
|
|
|
-- Author: Leonardo de Moura, Jeremy Avigad
|
2014-08-15 03:12:54 +00:00
|
|
|
|
|
2014-08-22 23:36:47 +00:00
|
|
|
|
-- data.prod
|
|
|
|
|
-- =========
|
|
|
|
|
|
|
|
|
|
-- The cartesian product.
|
|
|
|
|
|
2014-08-28 01:39:55 +00:00
|
|
|
|
import logic.classes.inhabited logic.core.eq logic.classes.decidable
|
2014-08-15 03:12:54 +00:00
|
|
|
|
|
2014-09-03 23:00:38 +00:00
|
|
|
|
open inhabited decidable
|
2014-08-20 02:32:44 +00:00
|
|
|
|
|
2014-08-15 03:12:54 +00:00
|
|
|
|
inductive prod (A B : Type) : Type :=
|
2014-08-22 22:46:10 +00:00
|
|
|
|
pair : A → B → prod A B
|
2014-08-15 03:12:54 +00:00
|
|
|
|
|
2014-08-22 23:36:47 +00:00
|
|
|
|
infixr `×` := prod
|
2014-08-15 03:12:54 +00:00
|
|
|
|
|
|
|
|
|
-- notation for n-ary tuples
|
|
|
|
|
notation `(` h `,` t:(foldl `,` (e r, pair r e) h) `)` := t
|
|
|
|
|
|
|
|
|
|
namespace prod
|
|
|
|
|
|
|
|
|
|
section
|
|
|
|
|
|
|
|
|
|
parameters {A B : Type}
|
|
|
|
|
|
2014-09-04 22:03:59 +00:00
|
|
|
|
abbreviation pr1 (p : prod A B) := rec (λ x y, x) p
|
|
|
|
|
abbreviation pr2 (p : prod A B) := rec (λ x y, y) p
|
2014-08-15 03:12:54 +00:00
|
|
|
|
|
2014-08-26 05:54:44 +00:00
|
|
|
|
theorem pr1_pair (a : A) (b : B) : pr1 (a, b) = a :=
|
|
|
|
|
rfl
|
|
|
|
|
|
|
|
|
|
theorem pr2_pair (a : A) (b : B) : pr2 (a, b) = b :=
|
|
|
|
|
rfl
|
2014-08-15 03:12:54 +00:00
|
|
|
|
|
2014-09-04 22:03:59 +00:00
|
|
|
|
theorem destruct [protected] {P : A × B → Prop} (p : A × B) (H : ∀a b, P (a, b)) : P p :=
|
|
|
|
|
rec H p
|
2014-08-15 03:12:54 +00:00
|
|
|
|
|
|
|
|
|
theorem prod_ext (p : prod A B) : pair (pr1 p) (pr2 p) = p :=
|
2014-09-04 22:03:59 +00:00
|
|
|
|
destruct p (λx y, refl (x, y))
|
2014-08-15 03:12:54 +00:00
|
|
|
|
|
2014-08-17 21:41:23 +00:00
|
|
|
|
theorem pair_eq {a1 a2 : A} {b1 b2 : B} (H1 : a1 = a2) (H2 : b1 = b2) : (a1, b1) = (a2, b2) :=
|
2014-08-26 05:54:44 +00:00
|
|
|
|
subst H1 (subst H2 rfl)
|
2014-08-17 21:41:23 +00:00
|
|
|
|
|
|
|
|
|
theorem prod_eq {p1 p2 : prod A B} : ∀ (H1 : pr1 p1 = pr1 p2) (H2 : pr2 p1 = pr2 p2), p1 = p2 :=
|
2014-09-04 22:03:59 +00:00
|
|
|
|
destruct p1 (take a1 b1, destruct p2 (take a2 b2 H1 H2, pair_eq H1 H2))
|
2014-08-15 03:12:54 +00:00
|
|
|
|
|
2014-08-26 05:54:44 +00:00
|
|
|
|
theorem prod_inhabited [instance] (H1 : inhabited A) (H2 : inhabited B) : inhabited (prod A B) :=
|
2014-08-20 02:32:44 +00:00
|
|
|
|
inhabited_destruct H1 (λa, inhabited_destruct H2 (λb, inhabited_mk (pair a b)))
|
2014-08-15 03:12:54 +00:00
|
|
|
|
|
2014-08-26 05:54:44 +00:00
|
|
|
|
theorem prod_eq_decidable [instance] (u v : A × B) (H1 : decidable (pr1 u = pr1 v))
|
2014-08-22 00:54:50 +00:00
|
|
|
|
(H2 : decidable (pr2 u = pr2 v)) : decidable (u = v) :=
|
|
|
|
|
have H3 : u = v ↔ (pr1 u = pr1 v) ∧ (pr2 u = pr2 v), from
|
|
|
|
|
iff_intro
|
2014-08-26 05:54:44 +00:00
|
|
|
|
(assume H, subst H (and_intro rfl rfl))
|
2014-08-22 22:46:10 +00:00
|
|
|
|
(assume H, and_elim H (assume H4 H5, prod_eq H4 H5)),
|
2014-08-22 00:54:50 +00:00
|
|
|
|
decidable_iff_equiv _ (iff_symm H3)
|
|
|
|
|
|
2014-08-15 03:12:54 +00:00
|
|
|
|
end
|
|
|
|
|
|
2014-08-20 02:32:44 +00:00
|
|
|
|
end prod
|