refactor(library): use [] binder annotation when declaring instances

This commit is contained in:
Leonardo de Moura 2015-02-24 15:25:02 -08:00
parent 1cd44e894b
commit 3ede8e9150
21 changed files with 55 additions and 56 deletions

View file

@ -108,7 +108,7 @@ namespace morphism
... = retraction_of f ∘ f : {id_left f}
... = id : retraction_compose f)
theorem is_retraction_comp [instance] (Hf : is_retraction f) (Hg : is_retraction g)
theorem is_retraction_comp [instance] [Hf : is_retraction f] [Hg : is_retraction g]
: is_retraction (g ∘ f) :=
have aux : f ∘ section_of f ∘ section_of g = (f ∘ section_of f) ∘ section_of g,
from !assoc,
@ -121,7 +121,7 @@ namespace morphism
... = g ∘ section_of g : {id_left (section_of g)}
... = id : compose_section)
theorem is_inverse_comp [instance] (Hf : is_iso f) (Hg : is_iso g) : is_iso (g ∘ f) :=
theorem is_inverse_comp [instance] [Hf : is_iso f] [Hg : is_iso g] : is_iso (g ∘ f) :=
!is_iso_of_is_retraction_of_is_section
structure isomorphic (a b : ob) :=

View file

@ -48,7 +48,7 @@ definition weak_funext_of_naive_funext : naive_funext → weak_funext :=
context
universes l k
parameters (wf : weak_funext.{l k}) {A : Type.{l}} {B : A → Type.{k}} (f : Π x, B x)
parameters [wf : weak_funext.{l k}] {A : Type.{l}} {B : A → Type.{k}} (f : Π x, B x)
definition is_contr_sigma_homotopy [instance] : is_contr (Σ (g : Π x, B x), f g) :=
is_contr.mk (sigma.mk f (homotopy.refl f))
@ -78,7 +78,6 @@ context
@transport _ (λ gh, Q (pr1 gh) (pr2 gh)) (sigma.mk f (homotopy.refl f)) (sigma.mk g h)
(@center_eq _ is_contr_sigma_homotopy _ _) d
local attribute weak_funext [reducible]
local attribute homotopy_ind [reducible]
definition homotopy_ind_comp : homotopy_ind f (homotopy.refl f) = d :=
@ -93,15 +92,15 @@ local attribute weak_funext [reducible]
theorem funext_of_weak_funext (wf : weak_funext.{l k}) : funext.{l k} :=
funext.mk (λ A B f g,
let eq_to_f := (λ g' x, f = g') in
let sim2path := homotopy_ind _ f eq_to_f idp in
let sim2path := homotopy_ind f eq_to_f idp in
have t1 : sim2path f (homotopy.refl f) = idp,
proof homotopy_ind_comp _ f eq_to_f idp qed,
proof homotopy_ind_comp f eq_to_f idp qed,
have t2 : apD10 (sim2path f (homotopy.refl f)) = (homotopy.refl f),
proof ap apD10 t1 qed,
have sect : apD10 ∘ (sim2path g) id,
proof (homotopy_ind _ f (λ g' x, apD10 (sim2path g' x) = x) t2) g qed,
proof (homotopy_ind f (λ g' x, apD10 (sim2path g' x) = x) t2) g qed,
have retr : (sim2path g) ∘ apD10 id,
from (λ h, eq.rec_on h (homotopy_ind_comp _ f _ idp)),
from (λ h, eq.rec_on h (homotopy_ind_comp f _ idp)),
is_equiv.adjointify apD10 (sim2path g) sect retr)
definition funext_from_naive_funext : naive_funext -> funext :=

View file

@ -17,7 +17,7 @@ private definition path_coll (A : Type) := ∀ x y : A, coll (x = y)
context
parameter {A : Type}
hypothesis (h : decidable_eq A)
hypothesis [h : decidable_eq A]
variables {x y : A}
private definition pc [reducible] : path_coll A :=

View file

@ -185,10 +185,10 @@ namespace inhabited
protected definition destruct {A : Type} {B : Type} (H1 : inhabited A) (H2 : A → B) : B :=
inhabited.rec H2 H1
definition fun_inhabited [instance] (A : Type) {B : Type} (H : inhabited B) : inhabited (A → B) :=
definition fun_inhabited [instance] (A : Type) {B : Type} [H : inhabited B] : inhabited (A → B) :=
destruct H (λb, mk (λa, b))
definition dfun_inhabited [instance] (A : Type) {B : A → Type} (H : Πx, inhabited (B x)) :
definition dfun_inhabited [instance] (A : Type) {B : A → Type} [H : Πx, inhabited (B x)] :
inhabited (Πx, B x) :=
mk (λa, destruct (H a) (λb, b))
@ -241,40 +241,40 @@ section
definition empty.decidable [instance] : decidable empty :=
inr not_empty
definition prod.decidable [instance] (Hp : decidable p) (Hq : decidable q) : decidable (prod p q) :=
definition prod.decidable [instance] [Hp : decidable p] [Hq : decidable q] : decidable (prod p q) :=
rec_on Hp
(assume Hp : p, rec_on Hq
(assume Hq : q, inl (prod.mk Hp Hq))
(assume Hnq : ¬q, inr (λ H : prod p q, prod.rec_on H (λ Hp Hq, absurd Hq Hnq))))
(assume Hnp : ¬p, inr (λ H : prod p q, prod.rec_on H (λ Hp Hq, absurd Hp Hnp)))
definition sum.decidable [instance] (Hp : decidable p) (Hq : decidable q) : decidable (sum p q) :=
definition sum.decidable [instance] [Hp : decidable p] [Hq : decidable q] : decidable (sum p q) :=
rec_on Hp
(assume Hp : p, inl (sum.inl Hp))
(assume Hnp : ¬p, rec_on Hq
(assume Hq : q, inl (sum.inr Hq))
(assume Hnq : ¬q, inr (λ H : sum p q, sum.rec_on H (λ Hp, absurd Hp Hnp) (λ Hq, absurd Hq Hnq))))
definition not.decidable [instance] (Hp : decidable p) : decidable (¬p) :=
definition not.decidable [instance] [Hp : decidable p] : decidable (¬p) :=
rec_on Hp
(assume Hp, inr (not_not_intro Hp))
(assume Hnp, inl Hnp)
definition implies.decidable [instance] (Hp : decidable p) (Hq : decidable q) : decidable (p → q) :=
definition implies.decidable [instance] [Hp : decidable p] [Hq : decidable q] : decidable (p → q) :=
rec_on Hp
(assume Hp : p, rec_on Hq
(assume Hq : q, inl (assume H, Hq))
(assume Hnq : ¬q, inr (assume H : p → q, absurd (H Hp) Hnq)))
(assume Hnp : ¬p, inl (assume Hp, absurd Hp Hnp))
definition iff.decidable [instance] (Hp : decidable p) (Hq : decidable q) : decidable (p ↔ q) :=
definition iff.decidable [instance] [Hp : decidable p] [Hq : decidable q] : decidable (p ↔ q) :=
show decidable (prod (p → q) (q → p)), from _
end
definition decidable_pred [reducible] {A : Type} (R : A → Type) := Π (a : A), decidable (R a)
definition decidable_rel [reducible] {A : Type} (R : A → A → Type) := Π (a b : A), decidable (R a b)
definition decidable_eq [reducible] (A : Type) := decidable_rel (@eq A)
definition decidable_ne [instance] {A : Type} (H : decidable_eq A) : decidable_rel (@ne A) :=
definition decidable_ne [instance] {A : Type} [H : decidable_eq A] : decidable_rel (@ne A) :=
show ∀ x y : A, decidable (x = y → empty), from _
definition ite (c : Type) [H : decidable c] {A : Type} (t e : A) : A :=

View file

@ -110,7 +110,7 @@ namespace morphism
... = retraction_of f ∘ f : {id_left f}
... = id : !retraction_compose)
theorem composition_is_retraction [instance] (Hf : is_retraction f) (Hg : is_retraction g)
theorem composition_is_retraction [instance] [Hf : is_retraction f] [Hg : is_retraction g]
: is_retraction (g ∘ f) :=
is_retraction.mk
(calc
@ -120,7 +120,7 @@ namespace morphism
... = g ∘ section_of g : {id_left (section_of g)}
... = id : !compose_section)
theorem composition_is_inverse [instance] (Hf : is_iso f) (Hg : is_iso g) : is_iso (g ∘ f) :=
theorem composition_is_inverse [instance] [Hf : is_iso f] [Hg : is_iso g] : is_iso (g ∘ f) :=
!section_retraction_imp_iso
structure isomorphic (a b : ob) :=

View file

@ -78,7 +78,7 @@ namespace is_congruence
{T3 : Type} {R3 : T3 → T3 → Prop}
{g : T2 → T3} (C2 : is_congruence R2 R3 g)
⦃T1 : Type⦄ {R1 : T1 → T1 → Prop}
{f : T1 → T2} (C1 : is_congruence R1 R2 f) :
{f : T1 → T2} [C1 : is_congruence R1 R2 f] :
is_congruence R1 R3 (λx, g (f x)) :=
is_congruence.mk (λx1 x2 H, app C2 (app C1 H))
@ -88,8 +88,8 @@ namespace is_congruence
{T4 : Type} {R4 : T4 → T4 → Prop}
{g : T2 → T3 → T4} (C3 : is_congruence2 R2 R3 R4 g)
⦃T1 : Type⦄ {R1 : T1 → T1 → Prop}
{f1 : T1 → T2} (C1 : is_congruence R1 R2 f1)
{f2 : T1 → T3} (C2 : is_congruence R1 R3 f2) :
{f1 : T1 → T2} [C1 : is_congruence R1 R2 f1]
{f2 : T1 → T3} [C2 : is_congruence R1 R3 f2] :
is_congruence R1 R4 (λx, g (f1 x) (f2 x)) :=
is_congruence.mk (λx1 x2 H, app2 C3 (app C1 H) (app C2 H))

View file

@ -215,7 +215,7 @@ list.induction_on l
from H3 ▸ rfl,
!exists.intro (!exists.intro H4)))
definition mem.is_decidable [instance] (H : decidable_eq T) (x : T) (l : list T) : decidable (x ∈ l) :=
definition mem.is_decidable [instance] [H : decidable_eq T] (x : T) (l : list T) : decidable (x ∈ l) :=
list.rec_on l
(decidable.inr (not_of_iff_false !mem_nil))
(take (h : T) (l : list T) (iH : decidable (x ∈ l)),

View file

@ -63,7 +63,7 @@ end nat
section
open nat decidable
definition decidable_bex [instance] (n : nat) (P : nat → Prop) (H : decidable_pred P) : decidable (bex n P) :=
definition decidable_bex [instance] (n : nat) (P : nat → Prop) [H : decidable_pred P] : decidable (bex n P) :=
nat.rec_on n
(inr (not_bex_zero P))
(λ a ih, decidable.rec_on ih
@ -72,7 +72,7 @@ section
(λ hpa : P a, inl (bex_succ_of_pred hpa))
(λ hna : ¬ P a, inr (not_bex_succ hneg hna))))
definition decidable_ball [instance] (n : nat) (P : nat → Prop) (H : decidable_pred P) : decidable (ball n P) :=
definition decidable_ball [instance] (n : nat) (P : nat → Prop) [H : decidable_pred P] : decidable (ball n P) :=
nat.rec_on n
(inl (ball_zero P))
(λ n₁ ih, decidable.rec_on ih

View file

@ -28,7 +28,7 @@ namespace option
protected definition is_inhabited [instance] (A : Type) : inhabited (option A) :=
inhabited.mk none
protected definition has_decidable_eq [instance] {A : Type} (H : decidable_eq A) : decidable_eq (option A) :=
protected definition has_decidable_eq [instance] {A : Type} [H : decidable_eq A] : decidable_eq (option A) :=
take o₁ o₂ : option A,
option.rec_on o₁
(option.rec_on o₂ (inl rfl) (take a₂, (inr (none_ne_some a₂))))

View file

@ -17,12 +17,11 @@ namespace prod
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₂))
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)))
protected definition is_inhabited [instance] [h₁ : inhabited A] [h₂ : inhabited B] : inhabited (prod A B) :=
inhabited.mk (default A, default B)
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),
protected definition has_decidable_eq [instance] [h₁ : decidable_eq A] [h₂ : decidable_eq B] : decidable_eq (A × B) :=
take (u v : A × B),
have H₃ : u = v ↔ (pr₁ u = pr₁ v) ∧ (pr₂ u = pr₂ v), from
iff.intro
(assume H, H ▸ and.intro rfl rfl)

View file

@ -33,7 +33,7 @@ namespace sigma
∀(H₁ : p.1 == p'.1) (H₂ : p.2 == p'.2), p == p' :=
destruct p (take a₁ b₁, destruct p' (take a₂ b₂ H₁ H₂, dpair_heq HB H₁ H₂))
protected definition is_inhabited [instance] (H₁ : inhabited A) (H₂ : inhabited (B (default A))) :
protected definition is_inhabited [instance] [H₁ : inhabited A] [H₂ : inhabited (B (default A))] :
inhabited (sigma B) :=
inhabited.destruct H₁ (λa, inhabited.destruct H₂ (λb, inhabited.mk ⟨default A, b⟩))

View file

@ -30,7 +30,7 @@ namespace subtype
protected definition is_inhabited [instance] {a : A} (H : P a) : inhabited {x | P x} :=
inhabited.mk (tag a H)
protected definition has_decidable_eq [instance] (H : decidable_eq A) : decidable_eq {x | P x} :=
protected definition has_decidable_eq [instance] [H : decidable_eq A] : decidable_eq {x | P x} :=
take a1 a2 : {x | P x},
have H1 : (a1 = a2) ↔ (elt_of a1 = elt_of a2), from
iff.intro (assume H, eq.subst H rfl) (assume H, equal H),

View file

@ -33,13 +33,13 @@ namespace sum
definition inr_inj {b₁ b₂ : B} : intro_right A b₁ = intro_right A b₂ → b₁ = b₂ :=
assume H, sum.no_confusion H (λe, e)
protected definition is_inhabited_left [instance] : inhabited A → inhabited (A + B) :=
assume H : inhabited A, inhabited.mk (inl (default A))
protected definition is_inhabited_left [instance] [h : inhabited A] : inhabited (A + B) :=
inhabited.mk (inl (default A))
protected definition is_inhabited_right [instance] : inhabited B → inhabited (A + B) :=
assume H : inhabited B, inhabited.mk (inr (default B))
protected definition is_inhabited_right [instance] [h : inhabited B] : inhabited (A + B) :=
inhabited.mk (inr (default B))
protected definition has_eq_decidable [instance] (h₁ : decidable_eq A) (h₂ : decidable_eq B) : ∀ s₁ s₂ : A + B, decidable (s₁ = s₂),
protected definition has_eq_decidable [instance] [h₁ : decidable_eq A] [h₂ : decidable_eq B] : ∀ s₁ s₂ : A + B, decidable (s₁ = s₂),
has_eq_decidable (inl a₁) (inl a₂) :=
match h₁ a₁ a₂ with
decidable.inl hp := decidable.inl (hp ▸ rfl),

View file

@ -18,7 +18,7 @@ namespace vector
variables {A B C : Type}
protected definition is_inhabited [instance] (h : inhabited A) : ∀ (n : nat), inhabited (vector A n),
protected definition is_inhabited [instance] [h : inhabited A] : ∀ (n : nat), inhabited (vector A n),
is_inhabited 0 := inhabited.mk nil,
is_inhabited (n+1) := inhabited.mk (inhabited.value h :: inhabited.value (is_inhabited n))

View file

@ -289,33 +289,33 @@ section
variables {p q : Prop}
open decidable (rec_on inl inr)
definition and.decidable [instance] (Hp : decidable p) (Hq : decidable q) : decidable (p ∧ q) :=
definition and.decidable [instance] [Hp : decidable p] [Hq : decidable q] : decidable (p ∧ q) :=
rec_on Hp
(assume Hp : p, rec_on Hq
(assume Hq : q, inl (and.intro Hp Hq))
(assume Hnq : ¬q, inr (assume H : p ∧ q, and.rec_on H (assume Hp Hq, absurd Hq Hnq))))
(assume Hnp : ¬p, inr (assume H : p ∧ q, and.rec_on H (assume Hp Hq, absurd Hp Hnp)))
definition or.decidable [instance] (Hp : decidable p) (Hq : decidable q) : decidable (p q) :=
definition or.decidable [instance] [Hp : decidable p] [Hq : decidable q] : decidable (p q) :=
rec_on Hp
(assume Hp : p, inl (or.inl Hp))
(assume Hnp : ¬p, rec_on Hq
(assume Hq : q, inl (or.inr Hq))
(assume Hnq : ¬q, inr (assume H : p q, or.elim H (assume Hp, absurd Hp Hnp) (assume Hq, absurd Hq Hnq))))
definition not.decidable [instance] (Hp : decidable p) : decidable (¬p) :=
definition not.decidable [instance] [Hp : decidable p] : decidable (¬p) :=
rec_on Hp
(assume Hp, inr (λ Hnp, absurd Hp Hnp))
(assume Hnp, inl Hnp)
definition implies.decidable [instance] (Hp : decidable p) (Hq : decidable q) : decidable (p → q) :=
definition implies.decidable [instance] [Hp : decidable p] [Hq : decidable q] : decidable (p → q) :=
rec_on Hp
(assume Hp : p, rec_on Hq
(assume Hq : q, inl (assume H, Hq))
(assume Hnq : ¬q, inr (assume H : p → q, absurd (H Hp) Hnq)))
(assume Hnp : ¬p, inl (assume Hp, absurd Hp Hnp))
definition iff.decidable [instance] (Hp : decidable p) (Hq : decidable q) : decidable (p ↔ q) :=
definition iff.decidable [instance] [Hp : decidable p] [Hq : decidable q] : decidable (p ↔ q) :=
show decidable ((p → q) ∧ (q → p)), from _
end
@ -323,7 +323,7 @@ end
definition decidable_pred [reducible] {A : Type} (R : A → Prop) := Π (a : A), decidable (R a)
definition decidable_rel [reducible] {A : Type} (R : A → A → Prop) := Π (a b : A), decidable (R a b)
definition decidable_eq [reducible] (A : Type) := decidable_rel (@eq A)
definition decidable_ne [instance] {A : Type} (H : decidable_eq A) : Π (a b : A), decidable (a ≠ b) :=
definition decidable_ne [instance] {A : Type} [H : decidable_eq A] : Π (a b : A), decidable (a ≠ b) :=
show Π x y : A, decidable (x = y → false), from _
inductive inhabited [class] (A : Type) : Type :=
@ -344,10 +344,10 @@ inhabited.rec (λa, a) H
definition Prop_inhabited [instance] : inhabited Prop :=
inhabited.mk true
definition fun_inhabited [instance] (A : Type) {B : Type} (H : inhabited B) : inhabited (A → B) :=
definition fun_inhabited [instance] (A : Type) {B : Type} [H : inhabited B] : inhabited (A → B) :=
inhabited.rec_on H (λb, inhabited.mk (λa, b))
definition dfun_inhabited [instance] (A : Type) {B : A → Type} (H : Πx, inhabited (B x)) :
definition dfun_inhabited [instance] (A : Type) {B : A → Type} [H : Πx, inhabited (B x)] :
inhabited (Πx, B x) :=
inhabited.mk (λa, inhabited.rec_on (H a) (λb, b))
@ -357,7 +357,7 @@ intro : A → nonempty A
protected definition nonempty.elim {A : Type} {B : Prop} (H1 : nonempty A) (H2 : A → B) : B :=
nonempty.rec H2 H1
theorem inhabited_imp_nonempty [instance] {A : Type} (H : inhabited A) : nonempty A :=
theorem inhabited_imp_nonempty [instance] {A : Type} [H : inhabited A] : nonempty A :=
nonempty.intro (default A)
definition ite (c : Prop) [H : decidable c] {A : Type} (t e : A) : A :=

View file

@ -20,13 +20,13 @@ measurable.rec_on s (λ f, f) a
definition nat.measurable [instance] : measurable nat :=
measurable.mk (λ a, a)
definition option.measurable [instance] (A : Type) (s : measurable A) : measurable (option A) :=
definition option.measurable [instance] (A : Type) [s : measurable A] : measurable (option A) :=
measurable.mk (λ a, option.cases_on a zero (λ a, size_of a))
definition prod.measurable [instance] (A B : Type) (sa : measurable A) (sb : measurable B) : measurable (prod A B) :=
definition prod.measurable [instance] (A B : Type) [sa : measurable A] [sb : measurable B] : measurable (prod A B) :=
measurable.mk (λ p, prod.cases_on p (λ a b, size_of a + size_of b))
definition sum.measurable [instance] (A B : Type) (sa : measurable A) (sb : measurable B) : measurable (sum A B) :=
definition sum.measurable [instance] (A B : Type) [sa : measurable A] [sb : measurable B] : measurable (sum A B) :=
measurable.mk (λ s, sum.cases_on s (λ a, size_of a) (λ b, size_of b))
definition bool.measurable [instance] : measurable bool :=

View file

@ -21,6 +21,7 @@ set_option class.conservative false
example (a b c d e : Prop) (H1 : a ↔ b) (H2 : a c → ¬(d → a)) : b c → ¬(d → b) :=
subst iff H1 H2
exit
example (a b c d e : Prop) (H1 : a ↔ b) (H2 : a c → ¬(d → a)) : b c → ¬(d → b) :=
H1 ▸ H2

View file

@ -106,7 +106,7 @@ theorem exists_not_of_not_forall {A : Type} {P : A → Prop} [D : ∀x, decidabl
[D' : decidable (∃x, ¬P x)] (H : ¬∀x, P x) :
∃x, ¬P x :=
@by_contradiction _ D' (assume H1 : ¬∃x, ¬P x,
have H2 : ∀x, ¬¬P x, from @forall_not_of_not_exists _ _ (take x, not.decidable (D x)) H1,
have H2 : ∀x, ¬¬P x, from @forall_not_of_not_exists _ _ (take x, not.decidable) H1,
have H3 : ∀x, P x, from take x, @not_not_elim _ (D x) (H2 x),
absurd H3 H)

View file

@ -33,6 +33,6 @@ subsingleton.intro (fun d1 d2,
protected theorem rec_subsingleton [instance] {p : Prop} [H : decidable p]
{H1 : p → Type} {H2 : ¬p → Type}
(H3 : Π(h : p), subsingleton (H1 h)) (H4 : Π(h : ¬p), subsingleton (H2 h))
[H3 : Π(h : p), subsingleton (H1 h)] [H4 : Π(h : ¬p), subsingleton (H2 h)]
: subsingleton (decidable.rec_on H H1 H2) :=
decidable.rec_on H (λh, H3 h) (λh, H4 h) --this can be proven using dependent version of "by_cases"

View file

@ -1,7 +1,7 @@
import logic data.prod
open prod
set_option class.unique_instances true
set_option class.unique_instances true set_option pp.implicit true
theorem tst (A : Type) (H₁ : inhabited A) (H₂ : inhabited A) : inhabited (A × A) :=
_

View file

@ -1,4 +1,4 @@
unique_instances.lean:6:0: error: ambiguous class-instance resolution, there is more than one solution
prod.is_inhabited H₂ H₂
@prod.is_inhabited A A H₂ H₂
and
prod.is_inhabited H₂ H₁
@prod.is_inhabited A A H₂ H₁