|
1 | 1 | /-
|
2 |
| -Copyright (c) 2018 Johannes Hölzl. All rights reserved. |
| 2 | +Copyright (c) 2017 Johannes Hölzl. All rights reserved. |
3 | 3 | Released under Apache 2.0 license as described in the file LICENSE.
|
4 | 4 | Authors: Johannes Hölzl
|
5 | 5 |
|
6 |
| -This is an extension of `init/relator.lean` |
| 6 | +Relator for functions, pairs, sums, and lists. |
7 | 7 | -/
|
8 |
| -variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} |
9 |
| -variables {r : α → β → Prop} {p : β → γ → Prop} {q : γ → δ → Prop} |
| 8 | + |
| 9 | +prelude |
| 10 | +import init.core init.data.basic |
10 | 11 |
|
11 | 12 | namespace relator
|
| 13 | +universe variables u₁ u₂ v₁ v₂ |
| 14 | + |
| 15 | +reserve infixr ` ⇒ `:40 |
| 16 | + |
| 17 | +/- TODO(johoelzl): |
| 18 | + * should we introduce relators of datatypes as recursive function or as inductive |
| 19 | +predicate? For now we stick to the recursor approach. |
| 20 | + * relation lift for datatypes, Π, Σ, set, and subtype types |
| 21 | + * proof composition and identity laws |
| 22 | + * implement method to derive relators from datatype |
| 23 | +-/ |
| 24 | + |
| 25 | +section |
| 26 | +variables {α : Type u₁} {β : Type u₂} {γ : Type v₁} {δ : Type v₂} |
| 27 | +variables (R : α → β → Prop) (S : γ → δ → Prop) |
| 28 | + |
| 29 | +def lift_fun (f : α → γ) (g : β → δ) : Prop := |
| 30 | +∀{a b}, R a b → S (f a) (g b) |
| 31 | + |
| 32 | +infixr ⇒ := lift_fun |
| 33 | + |
| 34 | +end |
| 35 | + |
| 36 | +section |
| 37 | +variables {α : Type u₁} {β : out_param $ Type u₂} (R : out_param $ α → β → Prop) |
| 38 | + |
| 39 | +@[class] def right_total := ∀b, ∃a, R a b |
| 40 | +@[class] def left_total := ∀a, ∃b, R a b |
| 41 | +@[class] def bi_total := left_total R ∧ right_total R |
| 42 | + |
| 43 | +end |
| 44 | + |
| 45 | +section |
| 46 | +variables {α : Type u₁} {β : Type u₂} (R : α → β → Prop) |
| 47 | + |
| 48 | +@[class] def left_unique := ∀{a b c}, R a b → R c b → a = c |
| 49 | +@[class] def right_unique := ∀{a b c}, R a b → R a c → b = c |
| 50 | + |
| 51 | +lemma rel_forall_of_right_total [t : right_total R] : ((R ⇒ implies) ⇒ implies) (λp, ∀i, p i) (λq, ∀i, q i) := |
| 52 | +assume p q Hrel H b, exists.elim (t b) (assume a Rab, Hrel Rab (H _)) |
| 53 | + |
| 54 | +lemma rel_exists_of_left_total [t : left_total R] : ((R ⇒ implies) ⇒ implies) (λp, ∃i, p i) (λq, ∃i, q i) := |
| 55 | +assume p q Hrel ⟨a, pa⟩, let ⟨b, Rab⟩ := t a in ⟨b, Hrel Rab pa⟩ |
| 56 | + |
| 57 | +lemma rel_forall_of_total [t : bi_total R] : ((R ⇒ iff) ⇒ iff) (λp, ∀i, p i) (λq, ∀i, q i) := |
| 58 | +assume p q Hrel, |
| 59 | + ⟨assume H b, exists.elim (t.right b) (assume a Rab, (Hrel Rab).mp (H _)), |
| 60 | + assume H a, exists.elim (t.left a) (assume b Rab, (Hrel Rab).mpr (H _))⟩ |
| 61 | + |
| 62 | +lemma rel_exists_of_total [t : bi_total R] : ((R ⇒ iff) ⇒ iff) (λp, ∃i, p i) (λq, ∃i, q i) := |
| 63 | +assume p q Hrel, |
| 64 | + ⟨assume ⟨a, pa⟩, let ⟨b, Rab⟩ := t.left a in ⟨b, (Hrel Rab).1 pa⟩, |
| 65 | + assume ⟨b, qb⟩, let ⟨a, Rab⟩ := t.right b in ⟨a, (Hrel Rab).2 qb⟩⟩ |
| 66 | + |
| 67 | +lemma left_unique_of_rel_eq {eq' : β → β → Prop} (he : (R ⇒ (R ⇒ iff)) eq eq') : left_unique R |
| 68 | +| a b c (ab : R a b) (cb : R c b) := |
| 69 | +have eq' b b, |
| 70 | + from iff.mp (he ab ab) rfl, |
| 71 | +iff.mpr (he ab cb) this |
| 72 | + |
| 73 | +end |
| 74 | + |
| 75 | +lemma rel_imp : (iff ⇒ (iff ⇒ iff)) implies implies := |
| 76 | +assume p q h r s l, imp_congr h l |
| 77 | + |
| 78 | +lemma rel_not : (iff ⇒ iff) not not := |
| 79 | +assume p q h, not_congr h |
| 80 | + |
| 81 | +instance bi_total_eq {α : Type u₁} : relator.bi_total (@eq α) := |
| 82 | +⟨assume a, ⟨a, rfl⟩, assume a, ⟨a, rfl⟩⟩ |
| 83 | + |
| 84 | +variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} |
| 85 | +variables {r : α → β → Prop} {p : β → γ → Prop} {q : γ → δ → Prop} |
12 | 86 |
|
13 | 87 | def bi_unique (r : α → β → Prop) : Prop := left_unique r ∧ right_unique r
|
14 | 88 |
|
|
0 commit comments