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-09-16 18:44:50 +00:00
|
|
|
|
import logic.core.inhabited logic.core.eq logic.core.decidable
|
2014-08-15 03:12:54 +00:00
|
|
|
|
|
2014-08-22 23:36:47 +00:00
|
|
|
|
-- data.prod
|
|
|
|
|
-- =========
|
|
|
|
|
|
2014-09-03 23:00:38 +00:00
|
|
|
|
open inhabited decidable
|
2014-08-20 02:32:44 +00:00
|
|
|
|
|
2014-09-05 05:31:52 +00:00
|
|
|
|
-- The cartesian product.
|
2014-08-15 03:12:54 +00:00
|
|
|
|
inductive prod (A B : Type) : Type :=
|
2014-09-05 05:31:52 +00:00
|
|
|
|
mk : A → B → prod A B
|
2014-09-04 23:36:06 +00:00
|
|
|
|
|
2014-09-17 21:39:05 +00:00
|
|
|
|
definition pair := @prod.mk
|
2014-08-22 23:36:47 +00:00
|
|
|
|
infixr `×` := prod
|
2014-08-15 03:12:54 +00:00
|
|
|
|
|
|
|
|
|
-- notation for n-ary tuples
|
2014-09-04 23:36:06 +00:00
|
|
|
|
notation `(` h `,` t:(foldl `,` (e r, prod.mk r e) h) `)` := t
|
2014-08-15 03:12:54 +00:00
|
|
|
|
|
|
|
|
|
namespace prod
|
|
|
|
|
section
|
|
|
|
|
parameters {A B : Type}
|
|
|
|
|
|
2014-09-17 21:39:05 +00:00
|
|
|
|
definition pr1 (p : prod A B) := rec (λ x y, x) p
|
|
|
|
|
definition 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-19 22:04:52 +00:00
|
|
|
|
protected theorem destruct {P : A × B → Prop} (p : A × B) (H : ∀a b, P (a, b)) : P p :=
|
2014-09-04 22:03:59 +00:00
|
|
|
|
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 23:36:06 +00:00
|
|
|
|
destruct p (λx y, eq.refl (x, y))
|
2014-08-15 03:12:54 +00:00
|
|
|
|
|
2014-10-02 00:51:17 +00:00
|
|
|
|
open eq.ops
|
2014-09-05 01:41:06 +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-09-05 01:41:06 +00:00
|
|
|
|
H1 ▸ H2 ▸ rfl
|
2014-08-17 21:41:23 +00:00
|
|
|
|
|
2014-09-19 22:04:52 +00:00
|
|
|
|
protected theorem equal {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-10-02 16:00:34 +00:00
|
|
|
|
protected definition is_inhabited [instance] (H1 : inhabited A) (H2 : inhabited B) : inhabited (prod A B) :=
|
2014-09-04 23:36:06 +00:00
|
|
|
|
inhabited.destruct H1 (λa, inhabited.destruct H2 (λb, inhabited.mk (pair a b)))
|
2014-08-15 03:12:54 +00:00
|
|
|
|
|
2014-09-30 16:02:37 +00:00
|
|
|
|
protected definition has_decidable_eq [instance] (H1 : decidable_eq A) (H2 : decidable_eq B) : decidable_eq (A × B) :=
|
2014-09-09 23:07:07 +00:00
|
|
|
|
take u v : A × B,
|
2014-08-22 00:54:50 +00:00
|
|
|
|
have H3 : u = v ↔ (pr1 u = pr1 v) ∧ (pr2 u = pr2 v), from
|
2014-09-05 04:25:21 +00:00
|
|
|
|
iff.intro
|
2014-09-05 01:41:06 +00:00
|
|
|
|
(assume H, H ▸ and.intro rfl rfl)
|
2014-09-05 05:31:52 +00:00
|
|
|
|
(assume H, and.elim H (assume H4 H5, equal H4 H5)),
|
2014-09-09 23:07:07 +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
|