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-10-21 21:08:07 +00:00
|
|
|
|
import logic.inhabited logic.eq logic.decidable general_notation
|
2014-08-15 03:12:54 +00:00
|
|
|
|
|
2014-08-22 23:36:47 +00:00
|
|
|
|
-- data.prod
|
|
|
|
|
-- =========
|
|
|
|
|
|
2014-10-05 20:38:08 +00:00
|
|
|
|
open inhabited decidable eq.ops
|
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-10-09 01:41:18 +00:00
|
|
|
|
|
|
|
|
|
namespace prod
|
2014-10-21 21:08:07 +00:00
|
|
|
|
notation A × B := prod A B
|
2014-08-15 03:12:54 +00:00
|
|
|
|
|
2014-10-10 23:33:58 +00:00
|
|
|
|
-- notation for n-ary tuples
|
|
|
|
|
notation `(` h `,` t:(foldl `,` (e r, prod.mk r e) h) `)` := t
|
2014-08-15 03:12:54 +00:00
|
|
|
|
|
2014-10-09 14:13:06 +00:00
|
|
|
|
variables {A B : Type}
|
2014-10-05 20:38:08 +00:00
|
|
|
|
protected theorem destruct {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
|
|
|
|
|
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-10-21 01:43:56 +00:00
|
|
|
|
notation `pr₁` := pr1
|
|
|
|
|
notation `pr₂` := pr2
|
2014-08-15 03:12:54 +00:00
|
|
|
|
|
2014-10-05 20:38:08 +00:00
|
|
|
|
variables (a : A) (b : B)
|
2014-08-26 05:54:44 +00:00
|
|
|
|
|
2014-10-05 20:38:08 +00:00
|
|
|
|
theorem pr1.pair : pr₁ (a, b) = a :=
|
2014-08-26 05:54:44 +00:00
|
|
|
|
rfl
|
2014-08-15 03:12:54 +00:00
|
|
|
|
|
2014-10-05 20:38:08 +00:00
|
|
|
|
theorem pr2.pair : pr₂ (a, b) = b :=
|
|
|
|
|
rfl
|
2014-08-15 03:12:54 +00:00
|
|
|
|
|
2014-11-03 16:29:05 +00:00
|
|
|
|
protected theorem eta (p : prod A B) : pair (pr₁ p) (pr₂ 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-05 20:38:08 +00:00
|
|
|
|
variables {a₁ a₂ : A} {b₁ b₂ : B}
|
2014-09-05 01:41:06 +00:00
|
|
|
|
|
2014-10-05 20:38:08 +00:00
|
|
|
|
theorem pair_eq : a₁ = a₂ → b₁ = b₂ → (a₁, b₁) = (a₂, b₂) :=
|
|
|
|
|
assume H1 H2, H1 ▸ H2 ▸ rfl
|
2014-08-17 21:41:23 +00:00
|
|
|
|
|
2014-10-05 20:38:08 +00:00
|
|
|
|
protected theorem equal {p₁ p₂ : prod A B} : pr₁ p₁ = pr₁ p₂ → pr₂ p₁ = pr₂ p₂ → p₁ = p₂ :=
|
|
|
|
|
destruct p₁ (take a₁ b₁, destruct p₂ (take a₂ b₂ H₁ H₂, pair_eq H₁ H₂))
|
2014-08-15 03:12:54 +00:00
|
|
|
|
|
2014-10-05 20:38:08 +00:00
|
|
|
|
protected definition is_inhabited [instance] : inhabited A → inhabited B → inhabited (prod A B) :=
|
|
|
|
|
take (H₁ : inhabited A) (H₂ : inhabited B),
|
|
|
|
|
inhabited.destruct H₁ (λa, inhabited.destruct H₂ (λb, inhabited.mk (pair a b)))
|
2014-08-15 03:12:54 +00:00
|
|
|
|
|
2014-10-05 20:38:08 +00:00
|
|
|
|
protected definition has_decidable_eq [instance] : decidable_eq A → decidable_eq B → decidable_eq (A × B) :=
|
|
|
|
|
take (H₁ : decidable_eq A) (H₂ : decidable_eq B) (u v : A × B),
|
|
|
|
|
have H₃ : u = v ↔ (pr₁ u = pr₁ v) ∧ (pr₂ u = pr₂ 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-10-05 20:38:08 +00:00
|
|
|
|
(assume H, and.elim H (assume H₄ H₅, equal H₄ H₅)),
|
|
|
|
|
decidable_iff_equiv _ (iff.symm H₃)
|
2014-08-20 02:32:44 +00:00
|
|
|
|
end prod
|