2014-12-23 15:35:06 -05:00
|
|
|
|
/-
|
|
|
|
|
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
|
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
|
|
Module: data.prod
|
|
|
|
|
Author: Leonardo de Moura, Jeremy Avigad
|
|
|
|
|
-/
|
2014-11-30 20:34:12 -08:00
|
|
|
|
import logic.eq
|
2014-10-05 13:38:08 -07:00
|
|
|
|
open inhabited decidable eq.ops
|
2014-08-19 19:32:44 -07:00
|
|
|
|
|
2014-10-08 21:41:18 -04:00
|
|
|
|
namespace prod
|
2014-11-20 23:21:45 -05:00
|
|
|
|
variables {A B : Type} {a₁ a₂ : A} {b₁ b₂ : B} {u : A × B}
|
2014-09-04 18:41:06 -07:00
|
|
|
|
|
2014-10-05 13:38:08 -07:00
|
|
|
|
theorem pair_eq : a₁ = a₂ → b₁ = b₂ → (a₁, b₁) = (a₂, b₂) :=
|
|
|
|
|
assume H1 H2, H1 ▸ H2 ▸ rfl
|
2014-08-17 14:41:23 -07:00
|
|
|
|
|
2014-10-05 13:38:08 -07: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-14 20:12:54 -07:00
|
|
|
|
|
2015-02-24 15:25:02 -08:00
|
|
|
|
protected definition is_inhabited [instance] [h₁ : inhabited A] [h₂ : inhabited B] : inhabited (prod A B) :=
|
|
|
|
|
inhabited.mk (default A, default B)
|
2014-08-14 20:12:54 -07:00
|
|
|
|
|
2015-02-24 15:25:02 -08:00
|
|
|
|
protected definition has_decidable_eq [instance] [h₁ : decidable_eq A] [h₂ : decidable_eq B] : decidable_eq (A × B) :=
|
|
|
|
|
take (u v : A × B),
|
2014-10-05 13:38:08 -07:00
|
|
|
|
have H₃ : u = v ↔ (pr₁ u = pr₁ v) ∧ (pr₂ u = pr₂ v), from
|
2014-09-04 21:25:21 -07:00
|
|
|
|
iff.intro
|
2014-09-04 18:41:06 -07:00
|
|
|
|
(assume H, H ▸ and.intro rfl rfl)
|
2014-10-05 13:38:08 -07:00
|
|
|
|
(assume H, and.elim H (assume H₄ H₅, equal H₄ H₅)),
|
2014-12-15 19:17:51 -08:00
|
|
|
|
decidable_of_decidable_of_iff _ (iff.symm H₃)
|
2015-04-01 17:30:37 -07:00
|
|
|
|
|
|
|
|
|
definition swap {A : Type} : A × A → A × A
|
|
|
|
|
| (a, b) := (b, a)
|
|
|
|
|
|
|
|
|
|
theorem swap_swap {A : Type} : ∀ p : A × A, swap (swap p) = p
|
|
|
|
|
| (a, b) := rfl
|
|
|
|
|
|
|
|
|
|
theorem eq_of_swap_eq {A : Type} : ∀ p₁ p₂ : A × A, swap p₁ = swap p₂ → p₁ = p₂ :=
|
|
|
|
|
take p₁ p₂, assume seqs,
|
|
|
|
|
assert h₁ : swap (swap p₁) = swap (swap p₂), from congr_arg swap seqs,
|
|
|
|
|
by rewrite *swap_swap at h₁; exact h₁
|
2014-08-19 19:32:44 -07:00
|
|
|
|
end prod
|