From fd2c42a8bfcb59ef3c1583caec0387ac8926da4a Mon Sep 17 00:00:00 2001 From: Sebastian Ullrich Date: Fri, 12 Aug 2016 16:51:53 -0400 Subject: [PATCH] chore(library, tests): switch to new attribute declaration syntax sed -Ei 's/^(\s*)((private |protected )?(noncomputable )?(abbreviation|definition|meta_definition|theorem|lemma|proposition|corollary)\s+\S+\s*)((\s*\[(\S+(\s+[0-9]+)*|priority.*)\])+)\s*/\1attribute \6\n\1\2/' library/**/*.lean tests/**/*.lean sed -Ei 's/\s+$//' library/**/*.lean # remove trailing whitespace --- library/algebra/binary.lean | 54 ++-- library/algebra/category/basic.lean | 3 +- library/algebra/category/constructions.lean | 36 ++- library/algebra/category/functor.lean | 15 +- library/algebra/category/morphism.lean | 36 ++- library/algebra/complete_lattice.lean | 15 +- library/algebra/field.lean | 39 ++- library/algebra/galois_connection.lean | 8 +- library/algebra/group.lean | 120 +++++--- library/algebra/group_power.lean | 3 +- library/algebra/interval.lean | 15 +- library/algebra/lattice.lean | 6 +- library/algebra/order.lean | 51 ++-- library/algebra/ordered_field.lean | 3 +- library/algebra/ordered_group.lean | 3 +- library/algebra/ordered_ring.lean | 9 +- library/algebra/relation.lean | 6 +- library/algebra/ring.lean | 42 ++- library/algebra/ring_power.lean | 9 +- library/data/bag.lean | 12 +- library/data/bool.lean | 99 ++++--- library/data/bv.lean | 21 +- library/data/complex.lean | 30 +- library/data/empty.lean | 6 +- library/data/encodable.lean | 27 +- library/data/equiv.lean | 75 +++-- library/data/examples/vector.lean | 3 +- library/data/finset/basic.lean | 18 +- library/data/finset/comb.lean | 9 +- library/data/finset/to_set.lean | 6 +- library/data/fintype/basic.lean | 21 +- library/data/fintype/card.lean | 3 +- library/data/fintype/function.lean | 3 +- library/data/hf.lean | 45 ++- library/data/int/basic.lean | 42 ++- library/data/int/countable.lean | 3 +- library/data/int/div.lean | 9 +- library/data/int/order.lean | 21 +- library/data/int/power.lean | 3 +- library/data/list/basic.lean | 120 +++++--- library/data/list/comb.lean | 54 ++-- library/data/list/perm.lean | 48 ++-- library/data/list/set.lean | 3 +- library/data/matrix.lean | 18 +- library/data/nat/basic.lean | 15 +- library/data/nat/bquant.lean | 21 +- library/data/nat/div.lean | 30 +- library/data/nat/gcd.lean | 9 +- library/data/nat/order.lean | 24 +- library/data/nat/parity.lean | 6 +- library/data/nat/power.lean | 3 +- library/data/nat/sub.lean | 54 ++-- library/data/num.lean | 6 +- library/data/old_fin.lean | 24 +- library/data/old_string.lean | 12 +- library/data/pnat.lean | 24 +- library/data/rat/basic.lean | 45 ++- library/data/rat/countable.lean | 9 +- library/data/rat/order.lean | 12 +- library/data/real/basic.lean | 27 +- library/data/real/division.lean | 6 +- library/data/real/order.lean | 9 +- library/data/set/comm_semiring.lean | 3 +- library/data/set/filter.lean | 12 +- library/data/set/finite.lean | 33 ++- library/data/set/function.lean | 21 +- library/data/set/map.lean | 3 +- library/data/sigma.lean | 18 +- library/data/squash.lean | 6 +- library/data/stream.lean | 6 +- library/data/sum.lean | 6 +- library/data/tuple.lean | 15 +- library/data/uprod.lean | 12 +- library/init/.gdb_history | 0 library/init/alternative.lean | 9 +- library/init/applicative.lean | 6 +- library/init/bool.lean | 12 +- library/init/char.lean | 6 +- library/init/coe.lean | 51 ++-- library/init/datatypes.lean | 6 +- library/init/fin.lean | 3 +- library/init/function.lean | 39 ++- library/init/functor.lean | 3 +- library/init/funext.lean | 6 +- library/init/instances.lean | 15 +- library/init/list.lean | 6 +- library/init/list_classes.lean | 15 +- library/init/logic.lean | 261 ++++++++++++------ library/init/meta/environment.lean | 6 +- library/init/meta/exceptional.lean | 18 +- library/init/meta/expr.lean | 6 +- library/init/meta/format.lean | 60 ++-- library/init/meta/fun_info.lean | 9 +- library/init/meta/level.lean | 12 +- library/init/meta/name.lean | 12 +- library/init/meta/occurrences.lean | 9 +- library/init/meta/options.lean | 6 +- library/init/meta/pexpr.lean | 9 +- library/init/meta/rb_map.lean | 21 +- library/init/meta/tactic.lean | 42 ++- library/init/monad.lean | 9 +- library/init/nat.lean | 57 ++-- library/init/num.lean | 9 +- library/init/option.lean | 33 ++- library/init/ordering.lean | 15 +- library/init/prod.lean | 9 +- library/init/quot.lean | 36 ++- library/init/reserved_notation.lean | 30 +- library/init/setoid.lean | 9 +- library/init/simplifier.lean | 30 +- library/init/sizeof.lean | 45 ++- library/init/state.lean | 21 +- library/init/string.lean | 6 +- library/init/subtype.lean | 3 +- library/init/to_string.lean | 42 ++- library/init/unit.lean | 6 +- library/init/unsigned.lean | 6 +- library/init/wf.lean | 3 +- .../logic/examples/propositional/deceq.lean | 3 +- .../examples/propositional/soundness.lean | 6 +- .../propositional/soundness_type.lean | 6 +- library/logic/quantifiers.lean | 6 +- library/theories/analysis/complex_norm.lean | 6 +- library/theories/analysis/inner_product.lean | 3 +- library/theories/analysis/metric_space.lean | 15 +- library/theories/analysis/normed_space.lean | 9 +- library/theories/analysis/real_limit.lean | 6 +- library/theories/group_theory/action.lean | 12 +- library/theories/group_theory/cyclic.lean | 9 +- library/theories/group_theory/finsubg.lean | 30 +- library/theories/group_theory/hom.lean | 12 +- library/theories/group_theory/perm.lean | 15 +- library/theories/group_theory/pgroup.lean | 15 +- library/theories/group_theory/subgroup.lean | 18 +- .../measure_theory/extended_real.lean | 36 ++- .../measure_theory/sigma_algebra.lean | 6 +- library/theories/number_theory/primes.lean | 6 +- library/theories/topology/basic.lean | 12 +- library/theories/topology/order_topology.lean | 6 +- tests/lean/640b.lean | 3 +- tests/lean/abbrev1.lean | 3 +- tests/lean/bad_class.lean | 3 +- tests/lean/change1.lean | 3 +- tests/lean/change2.lean | 3 +- tests/lean/char_lits.lean.expected.out | 2 +- tests/lean/coe4.lean | 3 +- tests/lean/coe5.lean | 3 +- tests/lean/coe6.lean | 3 +- tests/lean/defeq1.lean | 3 +- tests/lean/defeq_simp1.lean | 6 +- tests/lean/defeq_simp_lemmas1.lean | 12 +- tests/lean/defeq_simp_lemmas2.lean | 24 +- tests/lean/inst.lean | 9 +- tests/lean/inst.lean.expected.out | 4 +- tests/lean/interactive/class_bug.lean | 3 +- tests/lean/interactive/num2.lean | 6 +- tests/lean/interactive/whnfinst.lean | 3 +- tests/lean/pattern_pp.lean | 6 +- tests/lean/perf/perm_ac_100.lean | 3 +- tests/lean/perf/perm_ac_200.lean | 3 +- tests/lean/print_reducible.lean | 15 +- tests/lean/run/808.lean | 6 +- tests/lean/run/cases_crash1.lean | 3 +- tests/lean/run/cases_tac1.lean | 6 +- tests/lean/run/congr_imp_bug.lean | 3 +- tests/lean/run/dsimp_at1.lean | 3 +- tests/lean/run/elab_bug1.lean | 18 +- tests/lean/run/group.lean | 3 +- tests/lean/run/group3.lean | 3 +- tests/lean/run/interp.lean | 3 +- tests/lean/run/match_convoy.lean | 9 +- tests/lean/run/meta_tac4.lean | 3 +- tests/lean/run/mk_dec_eq1.lean | 6 +- tests/lean/run/pattern2.lean | 3 +- tests/lean/run/pattern3.lean | 3 +- tests/lean/run/priority_test.lean | 9 +- tests/lean/run/priority_test2.lean | 12 +- tests/lean/run/rw_set4.lean | 3 +- tests/lean/run/section5.lean | 3 +- tests/lean/run/sigma_match.lean | 3 +- tests/lean/run/simp1.lean | 6 +- tests/lean/run/stateT1.lean | 3 +- tests/lean/run/sum_bug.lean | 9 +- tests/lean/run/unification_hints.lean | 9 +- tests/lean/run/univ_bug1.lean | 3 +- tests/lean/run/univ_bug2.lean | 3 +- tests/lean/run/vm_eval1.lean | 3 +- tests/lean/run/whnfinst.lean | 3 +- tests/lean/unification_hints1.lean | 15 +- .../lean/unification_hints1.lean.expected.out | 8 +- tests/lean_before_refactoring/800.lean | 6 +- tests/lean_before_refactoring/run/679a.lean | 6 +- tests/lean_before_refactoring/run/679b.lean | 9 +- tests/lean_before_refactoring/run/803.lean | 9 +- .../run/blast_cc8.lean | 24 +- .../run/blast_safe_log_issue.lean | 3 +- .../run/blast_safe_log_issue2.lean | 60 ++-- tests/lean_before_refactoring/run/coe11.lean | 6 +- .../run/congr_tac2.lean | 3 +- .../run/finset_coe.lean | 3 +- .../run/prio_overloading.lean | 15 +- .../run/user_recursor.lean | 3 +- .../simplifier_light.lean | 6 +- 203 files changed, 2221 insertions(+), 1116 deletions(-) create mode 100644 library/init/.gdb_history diff --git a/library/algebra/binary.lean b/library/algebra/binary.lean index 038d736998..9678399c05 100644 --- a/library/algebra/binary.lean +++ b/library/algebra/binary.lean @@ -15,29 +15,45 @@ namespace binary local notation a * b := op₁ a b local notation a ⁻¹ := inv a - definition commutative [reducible] := ∀a b, a * b = b * a - definition associative [reducible] := ∀a b c, (a * b) * c = a * (b * c) - definition left_identity [reducible] := ∀a, one * a = a - definition right_identity [reducible] := ∀a, a * one = a - definition left_inverse [reducible] := ∀a, a⁻¹ * a = one - definition right_inverse [reducible] := ∀a, a * a⁻¹ = one - definition left_cancelative [reducible] := ∀a b c, a * b = a * c → b = c - definition right_cancelative [reducible] := ∀a b c, a * b = c * b → a = c + attribute [reducible] + definition commutative := ∀a b, a * b = b * a + attribute [reducible] + definition associative := ∀a b c, (a * b) * c = a * (b * c) + attribute [reducible] + definition left_identity := ∀a, one * a = a + attribute [reducible] + definition right_identity := ∀a, a * one = a + attribute [reducible] + definition left_inverse := ∀a, a⁻¹ * a = one + attribute [reducible] + definition right_inverse := ∀a, a * a⁻¹ = one + attribute [reducible] + definition left_cancelative := ∀a b c, a * b = a * c → b = c + attribute [reducible] + definition right_cancelative := ∀a b c, a * b = c * b → a = c - definition inv_op_cancel_left [reducible] := ∀a b, a⁻¹ * (a * b) = b - definition op_inv_cancel_left [reducible] := ∀a b, a * (a⁻¹ * b) = b - definition inv_op_cancel_right [reducible] := ∀a b, a * b⁻¹ * b = a - definition op_inv_cancel_right [reducible] := ∀a b, a * b * b⁻¹ = a + attribute [reducible] + definition inv_op_cancel_left := ∀a b, a⁻¹ * (a * b) = b + attribute [reducible] + definition op_inv_cancel_left := ∀a b, a * (a⁻¹ * b) = b + attribute [reducible] + definition inv_op_cancel_right := ∀a b, a * b⁻¹ * b = a + attribute [reducible] + definition op_inv_cancel_right := ∀a b, a * b * b⁻¹ = a variable (op₂ : A → A → A) local notation a + b := op₂ a b - definition left_distributive [reducible] := ∀a b c, a * (b + c) = a * b + a * c - definition right_distributive [reducible] := ∀a b c, (a + b) * c = a * c + b * c + attribute [reducible] + definition left_distributive := ∀a b c, a * (b + c) = a * b + a * c + attribute [reducible] + definition right_distributive := ∀a b c, (a + b) * c = a * c + b * c - definition right_commutative [reducible] {B : Type} (f : B → A → B) := ∀ b a₁ a₂, f (f b a₁) a₂ = f (f b a₂) a₁ - definition left_commutative [reducible] {B : Type} (f : A → B → B) := ∀ a₁ a₂ b, f a₁ (f a₂ b) = f a₂ (f a₁ b) + attribute [reducible] + definition right_commutative {B : Type} (f : B → A → B) := ∀ b a₁ a₂, f (f b a₁) a₂ = f (f b a₂) a₁ + attribute [reducible] + definition left_commutative {B : Type} (f : A → B → B) := ∀ a₁ a₂ b, f a₁ (f a₂ b) = f a₂ (f a₁ b) end section @@ -77,11 +93,13 @@ namespace binary ... = a*((b*c)*d) : sorry -- by rewrite (H_assoc b c d) end - definition right_commutative_comp_right [reducible] + attribute [reducible] + definition right_commutative_comp_right {A B : Type} (f : A → A → A) (g : B → A) (rcomm : right_commutative f) : right_commutative (comp_right f g) := λ a b₁ b₂, rcomm _ _ _ - definition left_commutative_compose_left [reducible] + attribute [reducible] + definition left_commutative_compose_left {A B : Type} (f : A → A → A) (g : B → A) (lcomm : left_commutative f) : left_commutative (comp_left f g) := λ a b₁ b₂, lcomm _ _ _ end binary diff --git a/library/algebra/category/basic.lean b/library/algebra/category/basic.lean index b24560da66..d3fcf8c8ca 100644 --- a/library/algebra/category/basic.lean +++ b/library/algebra/category/basic.lean @@ -23,7 +23,8 @@ namespace category definition compose := @comp ob _ - definition id [reducible] {a : ob} : hom a a := ID a + attribute [reducible] + definition id {a : ob} : hom a a := ID a infixr `∘` := comp infixl `⟶`:25 := hom -- input ⟶ using \--> (this is a different arrow than \-> (→)) diff --git a/library/algebra/category/constructions.lean b/library/algebra/category/constructions.lean index 628ace0d87..b4da8ae5e2 100644 --- a/library/algebra/category/constructions.lean +++ b/library/algebra/category/constructions.lean @@ -12,7 +12,8 @@ open eq eq.ops prod namespace category namespace opposite section - definition opposite [reducible] {ob : Type} (C : category ob) : category ob := + attribute [reducible] + definition opposite {ob : Type} (C : category ob) : category ob := mk (λa b, hom b a) (λ a b c f g, g ∘ f) (λ a, id) @@ -20,7 +21,8 @@ namespace category (λ a b f, !id_right) (λ a b f, !id_left) - definition Opposite [reducible] (C : Category) : Category := Mk (opposite C) + attribute [reducible] + definition Opposite (C : Category) : Category := Mk (opposite C) --direct construction: -- MK C -- (λa b, hom b a) @@ -45,7 +47,8 @@ namespace category end end opposite - definition type_category [reducible] : category Type := + attribute [reducible] + definition type_category : category Type := mk (λa b, a → b) (λ a b c, function.comp) (λ a, _root_.id) @@ -53,15 +56,19 @@ namespace category (λ a b f, function.comp.left_id f) (λ a b f, function.comp.right_id f) - definition Type_category [reducible] : Category := Mk type_category + attribute [reducible] + definition Type_category : Category := Mk type_category section open decidable unit empty variables {A : Type} [H : decidable_eq A] include H - definition set_hom [reducible] (a b : A) := decidable.rec_on (H a b) (λh, unit) (λh, empty) - theorem set_hom_subsingleton [instance] (a b : A) : subsingleton (set_hom a b) := rec_subsingleton - definition set_compose [reducible] {a b c : A} (g : set_hom b c) (f : set_hom a b) : set_hom a c := + attribute [reducible] + definition set_hom (a b : A) := decidable.rec_on (H a b) (λh, unit) (λh, empty) + attribute [instance] + theorem set_hom_subsingleton (a b : A) : subsingleton (set_hom a b) := rec_subsingleton + attribute [reducible] + definition set_compose {a b c : A} (g : set_hom b c) (f : set_hom a b) : set_hom a c := decidable.rec_on (H b c) (λ Hbc g, decidable.rec_on @@ -106,7 +113,8 @@ namespace category namespace product section open prod - definition prod_category [reducible] {obC obD : Type} (C : category obC) (D : category obD) + attribute [reducible] + definition prod_category {obC obD : Type} (C : category obC) (D : category obD) : category (obC × obD) := mk (λa b, hom (pr1 a) (pr1 b) × hom (pr2 a) (pr2 b)) (λ a b c g f, (pr1 g ∘ pr1 f , pr2 g ∘ pr2 f) ) @@ -115,7 +123,8 @@ namespace category (λ a b f, prod.eq !id_left !id_left ) (λ a b f, prod.eq !id_right !id_right) - definition Prod_category [reducible] (C D : Category) : Category := Mk (prod_category C D) + attribute [reducible] + definition Prod_category (C D : Category) : Category := Mk (prod_category C D) end end product @@ -133,7 +142,8 @@ namespace category namespace opposite section open functor - definition opposite_functor [reducible] {C D : Category} (F : C ⇒ D) : Cᵒᵖ ⇒ Dᵒᵖ := + attribute [reducible] + definition opposite_functor {C D : Category} (F : C ⇒ D) : Cᵒᵖ ⇒ Dᵒᵖ := @functor.mk (Cᵒᵖ) (Dᵒᵖ) (λ a, F a) (λ a b f, F f) @@ -145,7 +155,8 @@ namespace category namespace product section open ops functor - definition prod_functor [reducible] {C C' D D' : Category} (F : C ⇒ D) (G : C' ⇒ D') + attribute [reducible] + definition prod_functor {C C' D D' : Category} (F : C ⇒ D) (G : C' ⇒ D') : C ×c C' ⇒ D ×c D' := functor.mk (λ a, pair (F (pr1 a)) (G (pr2 a))) (λ a b f, pair (F (pr1 f)) (G (pr2 f))) @@ -224,7 +235,8 @@ namespace category -- (λ a b f, sigma.equal !id_right !proof_irrel) -- We use !proof_irrel instead of rfl, to give the unifier an easier time - definition Slice_category [reducible] (C : Category) (c : C) := Mk (slice_category C c) + attribute [reducible] + definition Slice_category (C : Category) (c : C) := Mk (slice_category C c) open category.ops attribute slice_category [instance] variables {D : Category} diff --git a/library/algebra/category/functor.lean b/library/algebra/category/functor.lean index 83f276498d..f8164838fe 100644 --- a/library/algebra/category/functor.lean +++ b/library/algebra/category/functor.lean @@ -25,7 +25,8 @@ namespace functor variables {A B C D : Category} - protected definition compose [reducible] (G : functor B C) (F : functor A B) : functor A C := + attribute [reducible] + protected definition compose (G : functor B C) (F : functor A B) : functor A C := functor.mk (λx, G (F x)) (λ a b f, G (F f)) @@ -43,9 +44,11 @@ namespace functor H ∘f (G ∘f F) = (H ∘f G) ∘f F := rfl - protected definition id [reducible] {C : Category} : functor C C := + attribute [reducible] + protected definition id {C : Category} : functor C C := mk (λa, a) (λ a b f, f) (λ a, rfl) (λ a b c f g, rfl) - protected definition ID [reducible] (C : Category) : functor C C := @functor.id C + attribute [reducible] + protected definition ID (C : Category) : functor C C := @functor.id C protected theorem id_left (F : functor C D) : (@functor.id D) ∘f F = F := functor.rec (λ obF homF idF compF, dcongr_arg4 mk rfl rfl !proof_irrel !proof_irrel) F @@ -56,7 +59,8 @@ end functor namespace category open functor - definition category_of_categories [reducible] : category Category := + attribute [reducible] + definition category_of_categories : category Category := mk (λ a b, functor a b) (λ a b c g f, functor.compose g f) (λ a, functor.id) @@ -64,7 +68,8 @@ namespace category (λ a b f, !functor.id_left) (λ a b f, !functor.id_right) - definition Category_of_categories [reducible] := Mk category_of_categories + attribute [reducible] + definition Category_of_categories := Mk category_of_categories namespace ops notation `Cat`:max := Category_of_categories diff --git a/library/algebra/category/morphism.lean b/library/algebra/category/morphism.lean index 1f3da406ac..667c7a9f05 100644 --- a/library/algebra/category/morphism.lean +++ b/library/algebra/category/morphism.lean @@ -41,16 +41,20 @@ namespace morphism theorem compose_section (f : a ⟶ b) [H : is_retraction f] : f ∘ section_of f = id := is_retraction.rec (λg h, h) H - theorem iso_imp_retraction [instance] (f : a ⟶ b) [H : is_iso f] : is_section f := + attribute [instance] + theorem iso_imp_retraction (f : a ⟶ b) [H : is_iso f] : is_section f := is_section.mk !inverse_compose - theorem iso_imp_section [instance] (f : a ⟶ b) [H : is_iso f] : is_retraction f := + attribute [instance] + theorem iso_imp_section (f : a ⟶ b) [H : is_iso f] : is_retraction f := is_retraction.mk !compose_inverse - theorem id_is_iso [instance] : is_iso (ID a) := + attribute [instance] + theorem id_is_iso : is_iso (ID a) := is_iso.mk !id_compose !id_compose - theorem inverse_is_iso [instance] (f : a ⟶ b) [H : is_iso f] : is_iso (f⁻¹) := + attribute [instance] + theorem inverse_is_iso (f : a ⟶ b) [H : is_iso f] : is_iso (f⁻¹) := is_iso.mk !compose_inverse !inverse_compose theorem left_inverse_eq_right_inverse {f : a ⟶ b} {g g' : hom b a} @@ -97,7 +101,8 @@ namespace morphism theorem iso_of_id : (ID a)⁻¹ = id := inverse_eq_intro_left !id_compose - theorem composition_is_section [instance] [Hf : is_section f] [Hg : is_section g] + attribute [instance] + theorem composition_is_section [Hf : is_section f] [Hg : is_section g] : is_section (g ∘ f) := is_section.mk (calc @@ -108,7 +113,8 @@ namespace morphism ... = retraction_of f ∘ f : by rewrite id_left ... = id : by rewrite retraction_compose) - theorem composition_is_retraction [instance] [Hf : is_retraction f] [Hg : is_retraction g] + attribute [instance] + theorem composition_is_retraction [Hf : is_retraction f] [Hg : is_retraction g] : is_retraction (g ∘ f) := is_retraction.mk (calc @@ -119,7 +125,8 @@ namespace morphism ... = g ∘ section_of g : by rewrite id_left ... = id : by rewrite compose_section) - theorem composition_is_inverse [instance] [Hf : is_iso f] [Hg : is_iso g] : is_iso (g ∘ f) := + attribute [instance] + theorem composition_is_inverse [Hf : is_iso f] [Hg : is_iso g] : is_iso (g ∘ f) := !section_retraction_imp_iso structure isomorphic (a b : ob) := @@ -136,7 +143,8 @@ namespace morphism theorem symm ⦃a b : ob⦄ (H : a ≅ b) : b ≅ a := mk (inverse (iso H)) theorem trans ⦃a b c : ob⦄ (H1 : a ≅ b) (H2 : b ≅ c) : a ≅ c := mk (iso H2 ∘ iso H1) - theorem is_equivalence_eq [instance] (T : Type) : is_equivalence (isomorphic : ob → ob → Type) := + attribute [instance] + theorem is_equivalence_eq (T : Type) : is_equivalence (isomorphic : ob → ob → Type) := is_equivalence.mk refl symm trans end isomorphic @@ -155,7 +163,8 @@ namespace morphism is_epi.mk H3 := H3 c g h H2 end - theorem section_is_mono [instance] (f : a ⟶ b) [H : is_section f] : is_mono f := + attribute [instance] + theorem section_is_mono (f : a ⟶ b) [H : is_section f] : is_mono f := is_mono.mk (λ c g h H, calc g = id ∘ g : by rewrite id_left @@ -164,7 +173,8 @@ namespace morphism ... = id ∘ h : by rewrite retraction_compose ... = h : by rewrite id_left) - theorem retraction_is_epi [instance] (f : a ⟶ b) [H : is_retraction f] : is_epi f := + attribute [instance] + theorem retraction_is_epi (f : a ⟶ b) [H : is_retraction f] : is_epi f := is_epi.mk (λ c g h H, calc g = g ∘ id : by rewrite id_right @@ -178,7 +188,8 @@ namespace morphism theorem id_is_mono : is_mono (ID a) theorem id_is_epi : is_epi (ID a) - theorem composition_is_mono [instance] [Hf : is_mono f] [Hg : is_mono g] : is_mono (g ∘ f) := + attribute [instance] + theorem composition_is_mono [Hf : is_mono f] [Hg : is_mono g] : is_mono (g ∘ f) := is_mono.mk (λ d h₁ h₂ H, have H2 : g ∘ (f ∘ h₁) = g ∘ (f ∘ h₂), @@ -187,7 +198,8 @@ namespace morphism end, mono_elim (mono_elim H2)) - theorem composition_is_epi [instance] [Hf : is_epi f] [Hg : is_epi g] : is_epi (g ∘ f) := + attribute [instance] + theorem composition_is_epi [Hf : is_epi f] [Hg : is_epi g] : is_epi (g ∘ f) := is_epi.mk (λ d h₁ h₂ H, have H2 : (h₁ ∘ g) ∘ f = (h₂ ∘ g) ∘ f, diff --git a/library/algebra/complete_lattice.lean b/library/algebra/complete_lattice.lean index 16b16f4b2f..065970c8cf 100644 --- a/library/algebra/complete_lattice.lean +++ b/library/algebra/complete_lattice.lean @@ -114,7 +114,8 @@ definition complete_lattice_Inf_to_complete_lattice_Sup [C : complete_lattice_In ⦃ complete_lattice_Sup, C ⦄ -- Every complete_lattice_Inf is a complete_lattice -definition complete_lattice_Inf_to_complete_lattice [trans_instance] [C : complete_lattice_Inf A] : +attribute [trans_instance] +definition complete_lattice_Inf_to_complete_lattice [C : complete_lattice_Inf A] : complete_lattice A := ⦃ complete_lattice, C ⦄ @@ -180,7 +181,8 @@ definition complete_lattice_Sup_to_complete_lattice_Inf [C : complete_lattice_Su -- Every complete_lattice_Sup is a complete_lattice section -definition complete_lattice_Sup_to_complete_lattice [trans_instance] [C : complete_lattice_Sup A] : +attribute [trans_instance] +definition complete_lattice_Sup_to_complete_lattice [C : complete_lattice_Sup A] : complete_lattice A := ⦃ complete_lattice, C ⦄ end @@ -345,7 +347,8 @@ end complete_lattice section open eq.ops complete_lattice -definition complete_lattice_fun [instance] (A B : Type) [complete_lattice B] : +attribute [instance] +definition complete_lattice_fun (A B : Type) [complete_lattice B] : complete_lattice (A → B) := ⦃ complete_lattice, lattice_fun A B, Inf := λS x, Inf ((λf, f x) ' S), @@ -363,7 +366,8 @@ definition complete_lattice_fun [instance] (A B : Type) [complete_lattice B] : section local attribute classical.prop_decidable [instance] -- Prop and set are only in the classical setting a complete lattice -definition complete_lattice_Prop [instance] : complete_lattice Prop := +attribute [instance] +definition complete_lattice_Prop : complete_lattice Prop := ⦃ complete_lattice, lattice_Prop, Inf := λS, false ∉ S, le_Inf := take x S H Hx Hf, @@ -403,7 +407,8 @@ funext (take x, end ... = @Sup (A → Prop) _ S x : rfl) -definition complete_lattice_set [instance] (A : Type) : complete_lattice (set A) := +attribute [instance] +definition complete_lattice_set (A : Type) : complete_lattice (set A) := ⦃ complete_lattice, le := subset, le_refl := @le_refl (A → Prop) _, diff --git a/library/algebra/field.lean b/library/algebra/field.lean index 481ea64afb..3cf081a682 100644 --- a/library/algebra/field.lean +++ b/library/algebra/field.lean @@ -21,16 +21,20 @@ section division_ring protected definition algebra.div (a b : A) : A := a * b⁻¹ - definition division_ring_has_div [instance] : has_div A := + attribute [instance] + definition division_ring_has_div : has_div A := has_div.mk algebra.div - lemma division.def [simp] (a b : A) : a / b = a * b⁻¹ := + attribute [simp] + lemma division.def (a b : A) : a / b = a * b⁻¹ := rfl - theorem mul_inv_cancel [simp] (H : a ≠ 0) : a * a⁻¹ = 1 := + attribute [simp] + theorem mul_inv_cancel (H : a ≠ 0) : a * a⁻¹ = 1 := division_ring.mul_inv_cancel H - theorem inv_mul_cancel [simp] (H : a ≠ 0) : a⁻¹ * a = 1 := + attribute [simp] + theorem inv_mul_cancel (H : a ≠ 0) : a⁻¹ * a = 1 := division_ring.inv_mul_cancel H theorem inv_eq_one_div (a : A) : a⁻¹ = 1 / a := eq.symm $ one_mul (a⁻¹) @@ -38,16 +42,20 @@ section division_ring theorem div_eq_mul_one_div (a b : A) : a / b = a * (1 / b) := sorry -- by simp - theorem mul_one_div_cancel [simp] (H : a ≠ 0) : a * (1 / a) = 1 := + attribute [simp] + theorem mul_one_div_cancel (H : a ≠ 0) : a * (1 / a) = 1 := sorry -- by simp - theorem one_div_mul_cancel [simp] (H : a ≠ 0) : (1 / a) * a = 1 := + attribute [simp] + theorem one_div_mul_cancel (H : a ≠ 0) : (1 / a) * a = 1 := sorry -- by simp - theorem div_self [simp] (H : a ≠ 0) : a / a = 1 := + attribute [simp] + theorem div_self (H : a ≠ 0) : a / a = 1 := sorry -- by simp - theorem one_div_one [simp] : 1 / 1 = (1:A) := + attribute [simp] + theorem one_div_one : 1 / 1 = (1:A) := div_self (ne.symm zero_ne_one) theorem mul_div_assoc (a b : A) : (a * b) / c = a * (b / c) := @@ -61,13 +69,16 @@ section division_ring absurd C1 zero_ne_one -/ - theorem one_inv_eq [simp] : 1⁻¹ = (1:A) := + attribute [simp] + theorem one_inv_eq : 1⁻¹ = (1:A) := sorry -- by rewrite [-mul_one, inv_mul_cancel (ne.symm (@zero_ne_one A _))] - theorem div_one [simp] (a : A) : a / 1 = a := + attribute [simp] + theorem div_one (a : A) : a / 1 = a := sorry -- by simp - theorem zero_div [simp] (a : A) : 0 / a = 0 := + attribute [simp] + theorem zero_div (a : A) : 0 / a = 0 := sorry -- by simp -- note: integral domain has a "mul_ne_zero". A commutative division ring is an integral @@ -152,7 +163,8 @@ section division_ring a = b := sorry -- by rewrite [-(division_ring.one_div_one_div Ha), H, (division_ring.one_div_one_div Hb)] - theorem mul_inv_eq [simp] (Ha : a ≠ 0) (Hb : b ≠ 0) : (b * a)⁻¹ = a⁻¹ * b⁻¹ := + attribute [simp] + theorem mul_inv_eq (Ha : a ≠ 0) (Hb : b ≠ 0) : (b * a)⁻¹ = a⁻¹ * b⁻¹ := sorry /- eq.symm (calc @@ -366,7 +378,8 @@ section discrete_field or.inr (by rewrite [-one_mul, -(inv_mul_cancel this), mul.assoc, H, mul_zero])) -/ - definition discrete_field.to_integral_domain [instance] : + attribute [instance] + definition discrete_field.to_integral_domain : integral_domain A := ⦃ integral_domain, s, eq_zero_or_eq_zero_of_mul_eq_zero := discrete_field.eq_zero_or_eq_zero_of_mul_eq_zero⦄ diff --git a/library/algebra/galois_connection.lean b/library/algebra/galois_connection.lean index e68edc2ad9..655031dd3e 100644 --- a/library/algebra/galois_connection.lean +++ b/library/algebra/galois_connection.lean @@ -130,14 +130,14 @@ lemma is_glb_l {a : A} : is_glb { b | a ≤ u b } (l a) := begin apply and.intro, { intro b, apply l_le }, - { intro b H, apply H, apply increasing_u_l } + { intro b H, apply H, apply increasing_u_l } end lemma is_lub_u {b : B} : is_lub { a | l a ≤ b } (u b) := begin apply and.intro, { intro a, apply le_u }, - { intro a H, apply H, apply decreasing_l_u } + { intro a H, apply H, apply decreasing_l_u } end end @@ -155,7 +155,7 @@ begin apply iff.symm, rewrite le_dual_eq_le, rewrite le_dual_eq_le, - exact gc, + exact gc, end protected lemma compose {A B C : Type} [weak_order A] [weak_order B] [weak_order C] @@ -164,7 +164,7 @@ protected lemma compose {A B C : Type} [weak_order A] [weak_order B] [weak_order galois_connection (l2 ∘ l1) (u1 ∘ u2) := by intros; rewrite gc2; rewrite gc1 -section +section variables {A B : Type} {f : A → B} protected lemma image_preimage : galois_connection (image f) (preimage f) := diff --git a/library/algebra/group.lean b/library/algebra/group.lean index 614105c569..216472bfea 100644 --- a/library/algebra/group.lean +++ b/library/algebra/group.lean @@ -23,17 +23,20 @@ structure semigroup [class] (A : Type) extends has_mul A := -- We add pattern hints to the following lemma because we want it to be used in both directions -- at inst_simp strategy. -theorem mul.assoc [simp] [semigroup A] (a b c : A) : a * b * c = a * (b * c) := +attribute [simp] +theorem mul.assoc [semigroup A] (a b c : A) : a * b * c = a * (b * c) := semigroup.mul_assoc a b c set_option pp.all true structure comm_semigroup [class] (A : Type) extends semigroup A := (mul_comm : ∀a b : A, a * b = b * a) -theorem mul.comm [simp] [comm_semigroup A] (a b : A) : a * b = b * a := +attribute [simp] +theorem mul.comm [comm_semigroup A] (a b : A) : a * b = b * a := comm_semigroup.mul_comm a b -theorem mul.left_comm [simp] [comm_semigroup A] (a b c : A) : a * (b * c) = b * (a * c) := +attribute [simp] +theorem mul.left_comm [comm_semigroup A] (a b c : A) : a * (b * c) = b * (a * c) := binary.left_comm (@mul.comm A _) (@mul.assoc A _) a b c theorem mul.right_comm [comm_semigroup A] (a b c : A) : (a * b) * c = (a * c) * b := @@ -60,16 +63,19 @@ abbreviation eq_of_mul_eq_mul_right' := @mul.right_cancel structure add_semigroup [class] (A : Type) extends has_add A := (add_assoc : ∀a b c : A, a + b + c = a + (b + c)) -theorem add.assoc [simp] [add_semigroup A] (a b c : A) : a + b + c = a + (b + c) := +attribute [simp] +theorem add.assoc [add_semigroup A] (a b c : A) : a + b + c = a + (b + c) := add_semigroup.add_assoc a b c structure add_comm_semigroup [class] (A : Type) extends add_semigroup A := (add_comm : ∀a b : A, a + b = b + a) -theorem add.comm [simp] [add_comm_semigroup A] (a b : A) : a + b = b + a := +attribute [simp] +theorem add.comm [add_comm_semigroup A] (a b : A) : a + b = b + a := add_comm_semigroup.add_comm a b -theorem add.left_comm [simp] [add_comm_semigroup A] (a b c : A) : a + (b + c) = b + (a + c) := +attribute [simp] +theorem add.left_comm [add_comm_semigroup A] (a b c : A) : a + (b + c) = b + (a + c) := binary.left_comm (@add.comm A _) (@add.assoc A _) a b c theorem add.right_comm [add_comm_semigroup A] (a b c : A) : (a + b) + c = (a + c) + b := @@ -96,9 +102,11 @@ abbreviation eq_of_add_eq_add_right := @add.right_cancel structure monoid [class] (A : Type) extends semigroup A, has_one A := (one_mul : ∀a : A, 1 * a = a) (mul_one : ∀a : A, a * 1 = a) -theorem one_mul [simp] [monoid A] (a : A) : 1 * a = a := monoid.one_mul a +attribute [simp] +theorem one_mul [monoid A] (a : A) : 1 * a = a := monoid.one_mul a -theorem mul_one [simp] [monoid A] (a : A) : a * 1 = a := monoid.mul_one a +attribute [simp] +theorem mul_one [monoid A] (a : A) : a * 1 = a := monoid.mul_one a structure comm_monoid [class] (A : Type) extends monoid A, comm_semigroup A @@ -107,9 +115,11 @@ structure comm_monoid [class] (A : Type) extends monoid A, comm_semigroup A structure add_monoid [class] (A : Type) extends add_semigroup A, has_zero A := (zero_add : ∀a : A, 0 + a = a) (add_zero : ∀a : A, a + 0 = a) -theorem zero_add [simp] [add_monoid A] (a : A) : 0 + a = a := add_monoid.zero_add a +attribute [simp] +theorem zero_add [add_monoid A] (a : A) : 0 + a = a := add_monoid.zero_add a -theorem add_zero [simp] [add_monoid A] (a : A) : a + 0 = a := add_monoid.add_zero a +attribute [simp] +theorem add_zero [add_monoid A] (a : A) : a + 0 = a := add_monoid.add_zero a structure add_comm_monoid [class] (A : Type) extends add_monoid A, add_comm_semigroup A @@ -148,12 +158,15 @@ structure group [class] (A : Type) extends monoid A, has_inv A := section group variable [group A] - theorem mul.left_inv [simp] (a : A) : a⁻¹ * a = 1 := group.mul_left_inv a + attribute [simp] + theorem mul.left_inv (a : A) : a⁻¹ * a = 1 := group.mul_left_inv a - theorem inv_mul_cancel_left [simp] (a b : A) : a⁻¹ * (a * b) = b := + attribute [simp] + theorem inv_mul_cancel_left (a b : A) : a⁻¹ * (a * b) = b := sorry -- by rewrite [-mul.assoc, mul.left_inv, one_mul] - theorem inv_mul_cancel_right [simp] (a b : A) : a * b⁻¹ * b = a := + attribute [simp] + theorem inv_mul_cancel_right (a b : A) : a * b⁻¹ * b = a := sorry -- by simp theorem inv_eq_of_mul_eq_one {a b : A} (H : a * b = 1) : a⁻¹ = b := @@ -163,10 +176,12 @@ section group by inst_simp -/ - theorem one_inv [simp] : 1⁻¹ = (1 : A) := + attribute [simp] + theorem one_inv : 1⁻¹ = (1 : A) := inv_eq_of_mul_eq_one (one_mul 1) - theorem inv_inv [simp] (a : A) : (a⁻¹)⁻¹ = a := + attribute [simp] + theorem inv_inv (a : A) : (a⁻¹)⁻¹ = a := inv_eq_of_mul_eq_one (mul.left_inv a) variable (A) @@ -207,20 +222,24 @@ section group by inst_simp -/ - theorem mul.right_inv [simp] (a : A) : a * a⁻¹ = 1 := + attribute [simp] + theorem mul.right_inv (a : A) : a * a⁻¹ = 1 := sorry /- have a = a⁻¹⁻¹, by simp, by inst_simp -/ - theorem mul_inv_cancel_left [simp] (a b : A) : a * (a⁻¹ * b) = b := + attribute [simp] + theorem mul_inv_cancel_left (a b : A) : a * (a⁻¹ * b) = b := sorry -- by inst_simp - theorem mul_inv_cancel_right [simp] (a b : A) : a * b * b⁻¹ = a := + attribute [simp] + theorem mul_inv_cancel_right (a b : A) : a * b * b⁻¹ = a := sorry -- by inst_simp - theorem mul_inv [simp] (a b : A) : (a * b)⁻¹ = b⁻¹ * a⁻¹ := + attribute [simp] + theorem mul_inv (a b : A) : (a * b)⁻¹ = b⁻¹ * a⁻¹ := sorry -- inv_eq_of_mul_eq_one (by inst_simp) theorem eq_of_mul_inv_eq_one {a b : A} (H : a * b⁻¹ = 1) : a = b := @@ -288,19 +307,24 @@ section group local attribute conj_by [reducible] - lemma conj_compose [simp] (f g a : A) : f ∘c g ∘c a = f*g ∘c a := + attribute [simp] + lemma conj_compose (f g a : A) : f ∘c g ∘c a = f*g ∘c a := sorry -- by inst_simp - lemma conj_id [simp] (a : A) : 1 ∘c a = a := + attribute [simp] + lemma conj_id (a : A) : 1 ∘c a = a := sorry -- by inst_simp - lemma conj_one [simp] (g : A) : g ∘c 1 = 1 := + attribute [simp] + lemma conj_one (g : A) : g ∘c 1 = 1 := sorry -- by inst_simp - lemma conj_inv_cancel [simp] (g : A) : ∀ a, g⁻¹ ∘c g ∘c a = a := + attribute [simp] + lemma conj_inv_cancel (g : A) : ∀ a, g⁻¹ ∘c g ∘c a = a := sorry -- by inst_simp - lemma conj_inv [simp] (g : A) : ∀ a, (g ∘c a)⁻¹ = g ∘c a⁻¹ := + attribute [simp] + lemma conj_inv (g : A) : ∀ a, (g ∘c a)⁻¹ = g ∘c a⁻¹ := sorry -- by inst_simp lemma is_conj.refl (a : A) : a ~ a := exists.intro 1 (conj_id a) @@ -324,12 +348,14 @@ section group end group -definition group.to_left_cancel_semigroup [instance] [s : group A] : +attribute [instance] +definition group.to_left_cancel_semigroup [s : group A] : left_cancel_semigroup A := ⦃ left_cancel_semigroup, s, mul_left_cancel := @mul_left_cancel A s ⦄ -definition group.to_right_cancel_semigroup [instance] [s : group A] : +attribute [instance] +definition group.to_right_cancel_semigroup [s : group A] : right_cancel_semigroup A := ⦃ right_cancel_semigroup, s, mul_right_cancel := @mul_right_cancel A s ⦄ @@ -350,13 +376,16 @@ section add_group variables [s : add_group A] include s - theorem add.left_inv [simp] (a : A) : -a + a = 0 := add_group.add_left_inv a + attribute [simp] + theorem add.left_inv (a : A) : -a + a = 0 := add_group.add_left_inv a - theorem neg_add_cancel_left [simp] (a b : A) : -a + (a + b) = b := + attribute [simp] + theorem neg_add_cancel_left (a b : A) : -a + (a + b) = b := calc -a + (a + b) = (-a + a) + b : sorry -- by rewrite add.assoc ... = b : sorry -- by simp - theorem neg_add_cancel_right [simp] (a b : A) : a + -b + b = a := + attribute [simp] + theorem neg_add_cancel_right (a b : A) : a + -b + b = a := sorry -- by simp theorem neg_eq_of_add_eq_zero {a b : A} (H : a + b = 0) : -a = b := @@ -366,9 +395,11 @@ section add_group by inst_simp -/ - theorem neg_zero [simp] : -0 = (0 : A) := neg_eq_of_add_eq_zero (zero_add 0) + attribute [simp] + theorem neg_zero : -0 = (0 : A) := neg_eq_of_add_eq_zero (zero_add 0) - theorem neg_neg [simp] (a : A) : -(-a) = a := neg_eq_of_add_eq_zero (add.left_inv a) + attribute [simp] + theorem neg_neg (a : A) : -(-a) = a := neg_eq_of_add_eq_zero (add.left_inv a) variable (A) theorem left_inverse_neg : function.left_inverse (λ a : A, - a) (λ a, - a) := @@ -405,20 +436,24 @@ section add_group theorem eq_neg_iff_eq_neg (a b : A) : a = -b ↔ b = -a := iff.intro eq_neg_of_eq_neg eq_neg_of_eq_neg - theorem add.right_inv [simp] (a : A) : a + -a = 0 := + attribute [simp] + theorem add.right_inv (a : A) : a + -a = 0 := sorry /- have a = -(-a), by simp, by inst_simp -/ - theorem add_neg_cancel_left [simp] (a b : A) : a + (-a + b) = b := + attribute [simp] + theorem add_neg_cancel_left (a b : A) : a + (-a + b) = b := sorry -- by inst_simp - theorem add_neg_cancel_right [simp] (a b : A) : a + b + -b = a := + attribute [simp] + theorem add_neg_cancel_right (a b : A) : a + b + -b = a := sorry -- by simp - theorem neg_add_rev [simp] (a b : A) : -(a + b) = -b + -a := + attribute [simp] + theorem neg_add_rev (a b : A) : -(a + b) = -b + -a := sorry -- neg_eq_of_add_eq_zero (by simp) -- TODO: delete these in favor of sub rules? @@ -466,11 +501,13 @@ section add_group by inst_simp -/ - definition add_group.to_left_cancel_semigroup [instance] : add_left_cancel_semigroup A := + attribute [instance] + definition add_group.to_left_cancel_semigroup : add_left_cancel_semigroup A := ⦃ add_left_cancel_semigroup, s, add_left_cancel := @add_left_cancel A s ⦄ - definition add_group.to_add_right_cancel_semigroup [instance] : + attribute [instance] + definition add_group.to_add_right_cancel_semigroup : add_right_cancel_semigroup A := ⦃ add_right_cancel_semigroup, s, add_right_cancel := @add_right_cancel A s ⦄ @@ -505,12 +542,15 @@ section add_group /- sub -/ -- TODO: derive corresponding facts for div in a field - protected definition algebra.sub [reducible] (a b : A) : A := a + -b + attribute [reducible] + protected definition algebra.sub (a b : A) : A := a + -b - definition add_group_has_sub [instance] : has_sub A := + attribute [instance] + definition add_group_has_sub : has_sub A := has_sub.mk algebra.sub - theorem sub_eq_add_neg [simp] (a b : A) : a - b = a + -b := rfl + attribute [simp] + theorem sub_eq_add_neg (a b : A) : a - b = a + -b := rfl theorem sub_self (a : A) : a - a = 0 := add.right_inv a diff --git a/library/algebra/group_power.lean b/library/algebra/group_power.lean index 35fe8ff491..df414e4320 100644 --- a/library/algebra/group_power.lean +++ b/library/algebra/group_power.lean @@ -40,7 +40,8 @@ definition monoid.pow (a : A) : ℕ → A | 0 := 1 | (n+1) := a * monoid.pow n -definition monoid_has_pow_nat [instance] : has_pow_nat A := +attribute [instance] +definition monoid_has_pow_nat : has_pow_nat A := has_pow_nat.mk monoid.pow theorem pow_zero (a : A) : a^0 = 1 := rfl diff --git a/library/algebra/interval.lean b/library/algebra/interval.lean index 57dfd054ab..82372f13cf 100644 --- a/library/algebra/interval.lean +++ b/library/algebra/interval.lean @@ -153,7 +153,8 @@ section nat -- put the instances in the intervals namespace open nat eq.ops variables m n : ℕ - proposition nat.Iic_finite [instance] (n : ℕ) : finite '(-∞, n] := + attribute [instance] + proposition nat.Iic_finite (n : ℕ) : finite '(-∞, n] := nat.induction_on n (have '(-∞, 0] ⊆ '{0}, from λ x H, mem_singleton_of_eq (le.antisymm H !zero_le), finite_subset this) @@ -162,19 +163,23 @@ open nat eq.ops by intro x H; rewrite [mem_union_iff, mem_singleton_iff]; apply le_or_eq_succ_of_le_succ H, finite_subset this) - proposition nat.Iio_finite [instance] (n : ℕ) : finite '(-∞, n) := + attribute [instance] + proposition nat.Iio_finite (n : ℕ) : finite '(-∞, n) := have '(-∞, n) ⊆ '(-∞, n], from λ x, le_of_lt, finite_subset this - proposition nat.Icc_finite [instance] (m n : ℕ) : finite ('[m, n]) := + attribute [instance] + proposition nat.Icc_finite (m n : ℕ) : finite ('[m, n]) := have '[m, n] ⊆ '(-∞, n], from λ x H, and.right H, finite_subset this - proposition nat.Ico_finite [instance] (m n : ℕ) : finite ('[m, n)) := + attribute [instance] + proposition nat.Ico_finite (m n : ℕ) : finite ('[m, n)) := have '[m, n) ⊆ '(-∞, n), from λ x H, and.right H, finite_subset this - proposition nat.Ioc_finite [instance] (m n : ℕ) : finite '(m, n] := + attribute [instance] + proposition nat.Ioc_finite (m n : ℕ) : finite '(m, n] := have '(m, n] ⊆ '(-∞, n], from λ x H, and.right H, finite_subset this end nat diff --git a/library/algebra/lattice.lean b/library/algebra/lattice.lean index 7e1b1c381d..d825d696a8 100644 --- a/library/algebra/lattice.lean +++ b/library/algebra/lattice.lean @@ -115,7 +115,8 @@ end /- lattice instances -/ -definition lattice_Prop [instance] : lattice Prop := +attribute [instance] +definition lattice_Prop : lattice Prop := ⦃ lattice, weak_order_Prop, inf := and, le_inf := take a b c Ha Hb Hc, and.intro (Ha Hc) (Hb Hc), @@ -127,7 +128,8 @@ definition lattice_Prop [instance] : lattice Prop := le_sup_right := @or.intro_right ⦄ -definition lattice_fun [instance] (A B : Type) [lattice B] : lattice (A → B) := +attribute [instance] +definition lattice_fun (A B : Type) [lattice B] : lattice (A → B) := ⦃ lattice, weak_order_fun A B, inf := λf g x, inf (f x) (g x), le_inf := take f g h Hf Hg x, le_inf (Hf x) (Hg x), diff --git a/library/algebra/order.lean b/library/algebra/order.lean index ccfe8041e1..399aa491d6 100644 --- a/library/algebra/order.lean +++ b/library/algebra/order.lean @@ -20,13 +20,16 @@ structure weak_order [class] (A : Type) extends has_le A := section variables [weak_order A] - theorem le.refl [refl] (a : A) : a ≤ a := weak_order.le_refl a + attribute [refl] + theorem le.refl (a : A) : a ≤ a := weak_order.le_refl a theorem le_of_eq {a b : A} (H : a = b) : a ≤ b := H ▸ le.refl a - theorem le.trans [trans] {a b c : A} : a ≤ b → b ≤ c → a ≤ c := weak_order.le_trans a b c + attribute [trans] + theorem le.trans {a b c : A} : a ≤ b → b ≤ c → a ≤ c := weak_order.le_trans a b c - theorem ge.trans [trans] {a b c : A} (H1 : a ≥ b) (H2: b ≥ c) : a ≥ c := le.trans H2 H1 + attribute [trans] + theorem ge.trans {a b c : A} (H1 : a ≥ b) (H2: b ≥ c) : a ≥ c := le.trans H2 H1 theorem le.antisymm {a b : A} : a ≤ b → b ≤ a → a = b := weak_order.le_antisymm a b @@ -60,9 +63,11 @@ section theorem lt_self_iff_false (a : A) : a < a ↔ false := iff_false_intro (lt.irrefl a) - theorem lt.trans [trans] {a b c : A} : a < b → b < c → a < c := strict_order.lt_trans a b c + attribute [trans] + theorem lt.trans {a b c : A} : a < b → b < c → a < c := strict_order.lt_trans a b c - theorem gt.trans [trans] {a b c : A} (H1 : a > b) (H2: b > c) : a > c := lt.trans H2 H1 + attribute [trans] + theorem gt.trans {a b c : A} (H1 : a > b) (H2: b > c) : a > c := lt.trans H2 H1 theorem ne_of_lt {a b : A} (lt_ab : a < b) : a ≠ b := assume eq_ab : a = b, @@ -105,21 +110,26 @@ section theorem le_of_lt : a < b → a ≤ b := order_pair.le_of_lt a b - theorem lt_of_lt_of_le [trans] : a < b → b ≤ c → a < c := order_pair.lt_of_lt_of_le a b c + attribute [trans] + theorem lt_of_lt_of_le : a < b → b ≤ c → a < c := order_pair.lt_of_lt_of_le a b c - theorem lt_of_le_of_lt [trans] : a ≤ b → b < c → a < c := order_pair.lt_of_le_of_lt a b c + attribute [trans] + theorem lt_of_le_of_lt : a ≤ b → b < c → a < c := order_pair.lt_of_le_of_lt a b c private theorem lt_irrefl (s' : order_pair A) (a : A) : ¬ a < a := order_pair.lt_irrefl a private theorem lt_trans (s' : order_pair A) (a b c: A) (lt_ab : a < b) (lt_bc : b < c) : a < c := lt_of_lt_of_le lt_ab (le_of_lt lt_bc) - definition order_pair.to_strict_order [instance] : strict_order A := + attribute [instance] + definition order_pair.to_strict_order : strict_order A := ⦃ strict_order, s, lt_irrefl := lt_irrefl s, lt_trans := lt_trans s ⦄ - theorem gt_of_gt_of_ge [trans] (H1 : a > b) (H2 : b ≥ c) : a > c := lt_of_le_of_lt H2 H1 + attribute [trans] + theorem gt_of_gt_of_ge (H1 : a > b) (H2 : b ≥ c) : a > c := lt_of_le_of_lt H2 H1 - theorem gt_of_ge_of_gt [trans] (H1 : a ≥ b) (H2 : b > c) : a > c := lt_of_lt_of_le H2 H1 + attribute [trans] + theorem gt_of_ge_of_gt (H1 : a ≥ b) (H2 : b > c) : a > c := lt_of_lt_of_le H2 H1 theorem not_le_of_gt (H : a > b) : ¬ a ≤ b := assume H1 : a ≤ b, @@ -188,7 +198,8 @@ section strong_order_pair show a < c, from iff.mpr (lt_iff_le_and_ne) (and.intro le_ac ne_ac) end strong_order_pair -definition strong_order_pair.to_order_pair [instance] +attribute [instance] +definition strong_order_pair.to_order_pair [s : strong_order_pair A] : order_pair A := ⦃ order_pair, s, lt_irrefl := lt_irrefl', @@ -203,7 +214,8 @@ structure linear_order_pair [class] (A : Type) extends order_pair A, linear_weak structure linear_strong_order_pair [class] (A : Type) extends strong_order_pair A, linear_weak_order A -definition linear_strong_order_pair.to_linear_order_pair [instance] +attribute [instance] +definition linear_strong_order_pair.to_linear_order_pair [s : linear_strong_order_pair A] : linear_order_pair A := ⦃ linear_order_pair, s, strong_order_pair.to_order_pair ⦄ @@ -262,10 +274,12 @@ section include s open decidable - definition decidable_lt [instance] : decidable (a < b) := + attribute [instance] + definition decidable_lt : decidable (a < b) := @decidable_linear_order.decidable_lt _ _ _ _ - definition decidable_le [instance] : decidable (a ≤ b) := + attribute [instance] + definition decidable_le : decidable (a ≤ b) := by_cases (assume H : a < b, tt (le_of_lt H)) (assume H : ¬ a < b, @@ -274,7 +288,8 @@ section (assume H2 : b < a, ff (not_le_of_gt H2)) (assume H2 : ¬ b < a, tt (le_of_not_gt H2))) - definition has_decidable_eq [instance] : decidable (a = b) := + attribute [instance] + definition has_decidable_eq : decidable (a = b) := by_cases (assume H : a ≤ b, by_cases @@ -475,7 +490,8 @@ end /- order instances -/ -definition weak_order_Prop [instance] : weak_order Prop := +attribute [instance] +definition weak_order_Prop : weak_order Prop := ⦃ weak_order, le := λx y, x → y, le_refl := λx, id, @@ -483,7 +499,8 @@ definition weak_order_Prop [instance] : weak_order Prop := le_antisymm := λf g H1 H2, propext (and.intro H1 H2) ⦄ -definition weak_order_fun [instance] (A B : Type) [weak_order B] : weak_order (A → B) := +attribute [instance] +definition weak_order_fun (A B : Type) [weak_order B] : weak_order (A → B) := ⦃ weak_order, le := λx y, ∀b, x b ≤ y b, le_refl := λf b, le.refl (f b), diff --git a/library/algebra/ordered_field.lean b/library/algebra/ordered_field.lean index cba3feea57..96eb8de4ad 100644 --- a/library/algebra/ordered_field.lean +++ b/library/algebra/ordered_field.lean @@ -469,7 +469,8 @@ section discrete_linear_ordered_field (assume H' : ¬ y < x, decidable.tt (le.antisymm (le_of_not_gt H') (le_of_not_gt H)))) - definition discrete_linear_ordered_field.to_discrete_field [instance] : discrete_field A := + attribute [instance] + definition discrete_linear_ordered_field.to_discrete_field : discrete_field A := ⦃ discrete_field, s, has_decidable_eq := dec_eq_of_dec_lt⦄ theorem pos_of_one_div_pos (H : 0 < 1 / a) : 0 < a := diff --git a/library/algebra/ordered_group.lean b/library/algebra/ordered_group.lean index ac29e5a9bb..1997c68553 100644 --- a/library/algebra/ordered_group.lean +++ b/library/algebra/ordered_group.lean @@ -276,7 +276,8 @@ theorem ordered_comm_group.lt_of_add_lt_add_left [ordered_comm_group A] {a b c : have H' : -a + (a + b) < -a + (a + c), from ordered_comm_group.add_lt_add_left _ _ H _, sorry -- by rewrite *neg_add_cancel_left at H'; exact H' -definition ordered_comm_group.to_ordered_cancel_comm_monoid [instance] [s : ordered_comm_group A] : ordered_cancel_comm_monoid A := +attribute [instance] +definition ordered_comm_group.to_ordered_cancel_comm_monoid [s : ordered_comm_group A] : ordered_cancel_comm_monoid A := ⦃ ordered_cancel_comm_monoid, s, add_left_cancel := @add.left_cancel A _, add_right_cancel := @add.right_cancel A _, diff --git a/library/algebra/ordered_ring.lean b/library/algebra/ordered_ring.lean index d1334254ad..761d3c4cb7 100644 --- a/library/algebra/ordered_ring.lean +++ b/library/algebra/ordered_ring.lean @@ -271,7 +271,8 @@ begin end -/ -definition ordered_ring.to_ordered_semiring [instance] +attribute [instance] +definition ordered_ring.to_ordered_semiring [s : ordered_ring A] : ordered_semiring A := ⦃ ordered_semiring, s, @@ -371,7 +372,8 @@ structure linear_ordered_ring [class] (A : Type) extends ordered_ring A, linear_strong_order_pair A := (zero_lt_one : lt zero one) -definition linear_ordered_ring.to_linear_ordered_semiring [instance] +attribute [instance] +definition linear_ordered_ring.to_linear_ordered_semiring [s : linear_ordered_ring A] : linear_ordered_semiring A := ⦃ linear_ordered_semiring, s, @@ -428,7 +430,8 @@ lt.by_cases -/ -- Linearity implies no zero divisors. Doesn't need commutativity. -definition linear_ordered_comm_ring.to_integral_domain [instance] +attribute [instance] +definition linear_ordered_comm_ring.to_integral_domain [s: linear_ordered_comm_ring A] : integral_domain A := ⦃ integral_domain, s, eq_zero_or_eq_zero_of_mul_eq_zero := diff --git a/library/algebra/relation.lean b/library/algebra/relation.lean index b462bda5f9..3fd9c70ced 100644 --- a/library/algebra/relation.lean +++ b/library/algebra/relation.lean @@ -98,12 +98,14 @@ namespace is_congruence end is_congruence -definition congruence_const [instance] {T2 : Type} (R2 : T2 → T2 → Prop) +attribute [instance] +definition congruence_const {T2 : Type} (R2 : T2 → T2 → Prop) [C : is_reflexive R2] ⦃T1 : Type⦄ (R1 : T1 → T1 → Prop) (c : T2) : is_congruence R1 R2 (λu : T1, c) := is_congruence.const R2 (is_reflexive.refl R2) R1 c -definition congruence_trivial [instance] {T : Type} (R : T → T → Prop) : +attribute [instance] +definition congruence_trivial {T : Type} (R : T → T → Prop) : is_congruence R R (λu, u) := is_congruence.mk (λx y H, H) diff --git a/library/algebra/ring.lean b/library/algebra/ring.lean index 31f9f51112..876a353bb7 100644 --- a/library/algebra/ring.lean +++ b/library/algebra/ring.lean @@ -27,8 +27,10 @@ structure mul_zero_class [class] (A : Type) extends has_mul A, has_zero A := (zero_mul : ∀a, mul zero a = zero) (mul_zero : ∀a, mul a zero = zero) -theorem zero_mul [simp] [mul_zero_class A] (a : A) : 0 * a = 0 := mul_zero_class.zero_mul a -theorem mul_zero [simp] [mul_zero_class A] (a : A) : a * 0 = 0 := mul_zero_class.mul_zero a +attribute [simp] +theorem zero_mul [mul_zero_class A] (a : A) : 0 * a = 0 := mul_zero_class.zero_mul a +attribute [simp] +theorem mul_zero [mul_zero_class A] (a : A) : a * 0 = 0 := mul_zero_class.mul_zero a structure zero_ne_one_class [class] (A : Type) extends has_zero A, has_one A := (zero_ne_one : zero ≠ one) @@ -81,7 +83,8 @@ section comm_semiring protected definition algebra.dvd (a b : A) : Prop := ∃c, b = a * c - definition comm_semiring_has_dvd [instance] [priority algebra.prio] : has_dvd A := + attribute [instance] [priority algebra.prio] + definition comm_semiring_has_dvd : has_dvd A := has_dvd.mk algebra.dvd theorem dvd.intro {a b c : A} (H : a * c = b) : a ∣ b := @@ -105,7 +108,8 @@ section comm_semiring theorem dvd.elim_left {P : Prop} {a b : A} (H₁ : a ∣ b) (H₂ : ∀c, b = c * a → P) : P := exists.elim (exists_eq_mul_left_of_dvd H₁) (take c, assume H₃ : b = c * a, H₂ c H₃) - theorem dvd.refl [simp] : a ∣ a := + attribute [simp] + theorem dvd.refl : a ∣ a := dvd.intro (mul_one a) theorem dvd.trans {a b c : A} (H₁ : a ∣ b) (H₂ : b ∣ c) : a ∣ c := @@ -122,13 +126,17 @@ section comm_semiring theorem eq_zero_of_zero_dvd {a : A} (H : 0 ∣ a) : a = 0 := dvd.elim H (take c, assume H' : a = 0 * c, eq.trans H' (zero_mul c)) - theorem dvd_zero [simp] : a ∣ 0 := dvd.intro (mul_zero a) + attribute [simp] + theorem dvd_zero : a ∣ 0 := dvd.intro (mul_zero a) - theorem one_dvd [simp] : 1 ∣ a := dvd.intro (one_mul a) + attribute [simp] + theorem one_dvd : 1 ∣ a := dvd.intro (one_mul a) - theorem dvd_mul_right [simp] : a ∣ a * b := dvd.intro rfl + attribute [simp] + theorem dvd_mul_right : a ∣ a * b := dvd.intro rfl - theorem dvd_mul_left [simp] : a ∣ b * a := + attribute [simp] + theorem dvd_mul_left : a ∣ b * a := sorry -- by simp theorem dvd_mul_of_dvd_left {a b : A} (H : a ∣ b) (c : A) : a ∣ b * c := @@ -178,7 +186,8 @@ end comm_semiring structure ring [class] (A : Type) extends add_comm_group A, monoid A, distrib A -theorem ring.mul_zero [simp] [ring A] (a : A) : a * 0 = 0 := +attribute [simp] +theorem ring.mul_zero [ring A] (a : A) : a * 0 = 0 := sorry /- have a * 0 + 0 = a * 0 + a * 0, from calc @@ -187,7 +196,8 @@ have a * 0 + 0 = a * 0 + a * 0, from calc show a * 0 = 0, from (add.left_cancel this)⁻¹ -/ -theorem ring.zero_mul [simp] [ring A] (a : A) : 0 * a = 0 := +attribute [simp] +theorem ring.zero_mul [ring A] (a : A) : 0 * a = 0 := sorry /- have 0 * a + 0 = 0 * a + 0 * a, from calc @@ -196,7 +206,8 @@ have 0 * a + 0 = 0 * a + 0 * a, from calc show 0 * a = 0, from (add.left_cancel this)⁻¹ -/ -definition ring.to_semiring [instance] [s : ring A] : semiring A := +attribute [instance] +definition ring.to_semiring [s : ring A] : semiring A := ⦃ semiring, s, mul_zero := ring.mul_zero, zero_mul := ring.zero_mul ⦄ @@ -223,8 +234,10 @@ section end -/ - theorem neg_mul_eq_neg_mul_symm [simp] : - a * b = - (a * b) := eq.symm (neg_mul_eq_neg_mul a b) - theorem mul_neg_eq_neg_mul_symm [simp] : a * - b = - (a * b) := eq.symm (neg_mul_eq_mul_neg a b) + attribute [simp] + theorem neg_mul_eq_neg_mul_symm : - a * b = - (a * b) := eq.symm (neg_mul_eq_neg_mul a b) + attribute [simp] + theorem mul_neg_eq_neg_mul_symm : a * - b = - (a * b) := eq.symm (neg_mul_eq_mul_neg a b) theorem neg_mul_neg : -a * -b = a * b := sorry -- by simp @@ -289,7 +302,8 @@ end structure comm_ring [class] (A : Type) extends ring A, comm_semigroup A -definition comm_ring.to_comm_semiring [instance] [s : comm_ring A] : comm_semiring A := +attribute [instance] +definition comm_ring.to_comm_semiring [s : comm_ring A] : comm_semiring A := ⦃ comm_semiring, s, mul_zero := mul_zero, zero_mul := zero_mul ⦄ diff --git a/library/algebra/ring_power.lean b/library/algebra/ring_power.lean index b0febfaf18..96140dfa14 100644 --- a/library/algebra/ring_power.lean +++ b/library/algebra/ring_power.lean @@ -14,7 +14,8 @@ section semiring variable [s : semiring A] include s -definition semiring_has_pow_nat [instance] : has_pow_nat A := +attribute [instance] +definition semiring_has_pow_nat : has_pow_nat A := monoid_has_pow_nat theorem zero_pow {m : ℕ} (mpos : m > 0) : 0^m = (0 : A) := @@ -33,7 +34,8 @@ section integral_domain variable [s : integral_domain A] include s -definition integral_domain_has_pow_nat [instance] : has_pow_nat A := +attribute [instance] +definition integral_domain_has_pow_nat : has_pow_nat A := monoid_has_pow_nat theorem eq_zero_of_pow_eq_zero {a : A} {m : ℕ} (H : a^m = 0) : a = 0 := @@ -151,7 +153,8 @@ section decidable_linear_ordered_comm_ring variable [s : decidable_linear_ordered_comm_ring A] include s -definition decidable_linear_ordered_comm_ring_has_pow_nat [instance] : has_pow_nat A := +attribute [instance] +definition decidable_linear_ordered_comm_ring_has_pow_nat : has_pow_nat A := monoid_has_pow_nat theorem abs_pow (a : A) (n : ℕ) : abs (a^n) = abs a^n := diff --git a/library/data/bag.lean b/library/data/bag.lean index ac5a101add..69397bb1ea 100644 --- a/library/data/bag.lean +++ b/library/data/bag.lean @@ -11,7 +11,8 @@ open [decl] perm variable {A : Type} -definition bag.setoid [instance] (A : Type) : setoid (list A) := +attribute [instance] +definition bag.setoid (A : Type) : setoid (list A) := setoid.mk (@perm A) (mk_equivalence (@perm A) (@perm.refl A) (@perm.symm A) (@perm.trans A)) definition bag (A : Type) : Type := @@ -63,7 +64,8 @@ calc b₁ ++ insert a b₂ = insert a b₂ ++ b₁ : append.comm ... = insert a (b₂ ++ b₁) : append_insert_left ... = insert a (b₁ ++ b₂) : append.comm -protected lemma induction_on [recursor 3] {C : bag A → Prop} (b : bag A) (h₁ : C empty) (h₂ : ∀ a b, C b → C (insert a b)) : C b := +attribute [recursor 3] +protected lemma induction_on {C : bag A → Prop} (b : bag A) (h₁ : C empty) (h₂ : ∀ a b, C b → C (insert a b)) : C b := quot.induction_on b (λ l, list.induction_on l h₁ (λ h t ih, h₂ h ⟦t⟧ ih)) section decidable_eq @@ -71,7 +73,8 @@ variable [decA : decidable_eq A] include decA open decidable -definition has_decidable_eq [instance] (b₁ b₂ : bag A) : decidable (b₁ = b₂) := +attribute [instance] +definition has_decidable_eq (b₁ b₂ : bag A) : decidable (b₁ = b₂) := quot.rec_on_subsingleton₂ b₁ b₂ (λ l₁ l₂, match decidable_perm l₁ l₂ with | inl h := inl (quot.sound h) @@ -679,7 +682,8 @@ private lemma ex_of_subcount_eq_ff : ∀ {l₁ l₂ : list A}, subcount l₁ l (suppose w ≠ a, exists.intro w (by rewrite (list.count_cons_of_ne `w ≠ a`); exact hw))) (suppose ¬ list.count a (a::l₁) ≤ list.count a l₂, exists.intro a this) -definition decidable_subbag [instance] (b₁ b₂ : bag A) : decidable (b₁ ⊆ b₂) := +attribute [instance] +definition decidable_subbag (b₁ b₂ : bag A) : decidable (b₁ ⊆ b₂) := quot.rec_on_subsingleton₂ b₁ b₂ (λ l₁ l₂, match subcount l₁ l₂ with | tt := suppose subcount l₁ l₂ = tt, inl (all_of_subcount_eq_tt this) diff --git a/library/data/bool.lean b/library/data/bool.lean index 3a7f566639..37496b500c 100644 --- a/library/data/bool.lean +++ b/library/data/bool.lean @@ -12,10 +12,12 @@ namespace bool theorem dichotomy (b : bool) : b = ff ∨ b = tt := sorry -- by rec_simp - theorem cond_ff [simp] {A : Type} (t e : A) : cond ff t e = e := + attribute [simp] + theorem cond_ff {A : Type} (t e : A) : cond ff t e = e := rfl - theorem cond_tt [simp] {A : Type} (t e : A) : cond tt t e = t := + attribute [simp] + theorem cond_tt {A : Type} (t e : A) : cond tt t e = t := rfl theorem eq_tt_of_ne_ff : ∀ {a : bool}, a ≠ ff → a = tt := @@ -27,30 +29,38 @@ namespace bool theorem absurd_of_eq_ff_of_eq_tt {B : Prop} {a : bool} (H₁ : a = ff) (H₂ : a = tt) : B := sorry -- by rec_simp - theorem tt_bor [simp] (a : bool) : bor tt a = tt := + attribute [simp] + theorem tt_bor (a : bool) : bor tt a = tt := rfl notation a || b := bor a b - theorem bor_tt [simp] (a : bool) : a || tt = tt := + attribute [simp] + theorem bor_tt (a : bool) : a || tt = tt := sorry -- by rec_simp - theorem ff_bor [simp] (a : bool) : ff || a = a := + attribute [simp] + theorem ff_bor (a : bool) : ff || a = a := sorry -- by rec_simp - theorem bor_ff [simp] (a : bool) : a || ff = a := + attribute [simp] + theorem bor_ff (a : bool) : a || ff = a := sorry -- by rec_simp - theorem bor_self [simp] (a : bool) : a || a = a := + attribute [simp] + theorem bor_self (a : bool) : a || a = a := sorry -- by rec_simp - theorem bor_comm [simp] (a b : bool) : a || b = b || a := + attribute [simp] + theorem bor_comm (a b : bool) : a || b = b || a := sorry -- by rec_simp - theorem bor_assoc [simp] (a b c : bool) : (a || b) || c = a || (b || c) := + attribute [simp] + theorem bor_assoc (a b c : bool) : (a || b) || c = a || (b || c) := sorry -- by rec_simp - theorem bor_left_comm [simp] (a b c : bool) : a || (b || c) = b || (a || c) := + attribute [simp] + theorem bor_left_comm (a b c : bool) : a || (b || c) = b || (a || c) := sorry -- by rec_simp theorem or_of_bor_eq {a b : bool} : a || b = tt → a = tt ∨ b = tt := @@ -62,28 +72,36 @@ namespace bool theorem bor_inr {a b : bool} (H : b = tt) : a || b = tt := sorry -- by rec_simp - theorem ff_band [simp] (a : bool) : ff && a = ff := + attribute [simp] + theorem ff_band (a : bool) : ff && a = ff := rfl - theorem tt_band [simp] (a : bool) : tt && a = a := + attribute [simp] + theorem tt_band (a : bool) : tt && a = a := sorry -- by rec_simp - theorem band_ff [simp] (a : bool) : a && ff = ff := + attribute [simp] + theorem band_ff (a : bool) : a && ff = ff := sorry -- by rec_simp - theorem band_tt [simp] (a : bool) : a && tt = a := + attribute [simp] + theorem band_tt (a : bool) : a && tt = a := sorry -- by rec_simp - theorem band_self [simp] (a : bool) : a && a = a := + attribute [simp] + theorem band_self (a : bool) : a && a = a := sorry -- by rec_simp - theorem band_comm [simp] (a b : bool) : a && b = b && a := + attribute [simp] + theorem band_comm (a b : bool) : a && b = b && a := sorry -- by rec_simp - theorem band_assoc [simp] (a b c : bool) : (a && b) && c = a && (b && c) := + attribute [simp] + theorem band_assoc (a b c : bool) : (a && b) && c = a && (b && c) := sorry -- by rec_simp - theorem band_left_comm [simp] (a b c : bool) : a && (b && c) = b && (a && c) := + attribute [simp] + theorem band_left_comm (a b c : bool) : a && (b && c) = b && (a && c) := sorry -- by rec_simp theorem band_elim_left {a b : bool} (H : a && b = tt) : a = tt := @@ -95,13 +113,16 @@ namespace bool theorem band_elim_right {a b : bool} (H : a && b = tt) : b = tt := sorry -- by rec_simp - theorem bnot_false [simp] : bnot ff = tt := + attribute [simp] + theorem bnot_false : bnot ff = tt := rfl - theorem bnot_true [simp] : bnot tt = ff := + attribute [simp] + theorem bnot_true : bnot tt = ff := rfl - theorem bnot_bnot [simp] (a : bool) : bnot (bnot a) = a := + attribute [simp] + theorem bnot_bnot (a : bool) : bnot (bnot a) = a := sorry -- by rec_simp theorem eq_tt_of_bnot_eq_ff {a : bool} : bnot a = ff → a = tt := @@ -116,32 +137,44 @@ namespace bool | tt ff := tt | tt tt := ff - lemma ff_bxor_ff [simp] : bxor ff ff = ff := rfl - lemma ff_bxor_tt [simp] : bxor ff tt = tt := rfl - lemma tt_bxor_ff [simp] : bxor tt ff = tt := rfl - lemma tt_bxor_tt [simp] : bxor tt tt = ff := rfl + attribute [simp] + lemma ff_bxor_ff : bxor ff ff = ff := rfl + attribute [simp] + lemma ff_bxor_tt : bxor ff tt = tt := rfl + attribute [simp] + lemma tt_bxor_ff : bxor tt ff = tt := rfl + attribute [simp] + lemma tt_bxor_tt : bxor tt tt = ff := rfl - lemma bxor_self [simp] (a : bool) : bxor a a = ff := + attribute [simp] + lemma bxor_self (a : bool) : bxor a a = ff := sorry -- by rec_simp - lemma bxor_ff [simp] (a : bool) : bxor a ff = a := + attribute [simp] + lemma bxor_ff (a : bool) : bxor a ff = a := sorry -- by rec_simp - lemma bxor_tt [simp] (a : bool) : bxor a tt = bnot a := + attribute [simp] + lemma bxor_tt (a : bool) : bxor a tt = bnot a := sorry -- by rec_simp - lemma ff_bxor [simp] (a : bool) : bxor ff a = a := + attribute [simp] + lemma ff_bxor (a : bool) : bxor ff a = a := sorry -- by rec_simp - lemma tt_bxor [simp] (a : bool) : bxor tt a = bnot a := + attribute [simp] + lemma tt_bxor (a : bool) : bxor tt a = bnot a := sorry -- by rec_simp - lemma bxor_comm [simp] (a b : bool) : bxor a b = bxor b a := + attribute [simp] + lemma bxor_comm (a b : bool) : bxor a b = bxor b a := sorry -- by rec_simp - lemma bxor_assoc [simp] (a b c : bool) : bxor (bxor a b) c = bxor a (bxor b c) := + attribute [simp] + lemma bxor_assoc (a b c : bool) : bxor (bxor a b) c = bxor a (bxor b c) := sorry -- by rec_simp - lemma bxor_left_comm [simp] (a b c : bool) : bxor a (bxor b c) = bxor b (bxor a c) := + attribute [simp] + lemma bxor_left_comm (a b c : bool) : bxor a (bxor b c) = bxor b (bxor a c) := sorry -- by rec_simp end bool diff --git a/library/data/bv.lean b/library/data/bv.lean index 2907beb2f7..3c23b85eea 100644 --- a/library/data/bv.lean +++ b/library/data/bv.lean @@ -19,7 +19,8 @@ open prod open subtype open tuple -definition bv [reducible] (n : ℕ) := tuple bool n +attribute [reducible] +definition bv (n : ℕ) := tuple bool n -- Create a zero bitvector definition bv_zero (n : ℕ) : bv n := replicate ff @@ -115,18 +116,24 @@ section arith definition bv_sub : bv n → bv n → bv n | x y := pr₂ (bv_sbb x y ff) - definition bv_has_zero [instance] : has_zero (bv n) := has_zero.mk (bv_zero n) - definition bv_has_one [instance] : has_one (bv n) := has_one.mk (bv_one n) - definition bv_has_add [instance] : has_add (bv n) := has_add.mk bv_add - definition bv_has_sub [instance] : has_sub (bv n) := has_sub.mk bv_sub - definition bv_has_neg [instance] : has_neg (bv n) := has_neg.mk bv_neg + attribute [instance] + definition bv_has_zero : has_zero (bv n) := has_zero.mk (bv_zero n) + attribute [instance] + definition bv_has_one : has_one (bv n) := has_one.mk (bv_one n) + attribute [instance] + definition bv_has_add : has_add (bv n) := has_add.mk bv_add + attribute [instance] + definition bv_has_sub : has_sub (bv n) := has_sub.mk bv_sub + attribute [instance] + definition bv_has_neg : has_neg (bv n) := has_neg.mk bv_neg definition bv_mul : bv n → bv n → bv n | x y := let f := λr b, cond b (r + r + y) (r + r) in foldl f 0 (to_list x) - definition bv_has_mul [instance] : has_mul (bv n) := has_mul.mk bv_mul + attribute [instance] + definition bv_has_mul : has_mul (bv n) := has_mul.mk bv_mul definition bv_ult : bv n → bv n → bool := λx y, pr₁ (bv_sbb x y ff) definition bv_ugt : bv n → bv n → bool := λx y, bv_ult y x diff --git a/library/data/complex.lean b/library/data/complex.lean index d2d61563a6..47246707e9 100644 --- a/library/data/complex.lean +++ b/library/data/complex.lean @@ -37,10 +37,12 @@ by cases z; exact rfl protected definition prio : num := num.pred real.prio -definition complex_has_zero [instance] [priority complex.prio] : has_zero ℂ := +attribute [instance] [priority complex.prio] +definition complex_has_zero : has_zero ℂ := has_zero.mk (of_nat 0) -definition complex_has_one [instance] [priority complex.prio] : has_one ℂ := +attribute [instance] [priority complex.prio] +definition complex_has_one : has_one ℂ := has_one.mk (of_nat 1) theorem re_of_real (x : ℝ) : re (of_real x) = x := rfl @@ -60,13 +62,16 @@ complex.mk /- notation -/ -definition complex_has_add [instance] [priority complex.prio] : has_add complex := +attribute [instance] [priority complex.prio] +definition complex_has_add : has_add complex := has_add.mk complex.add -definition complex_has_neg [instance] [priority complex.prio] : has_neg complex := +attribute [instance] [priority complex.prio] +definition complex_has_neg : has_neg complex := has_neg.mk complex.neg -definition complex_has_mul [instance] [priority complex.prio] : has_mul complex := +attribute [instance] [priority complex.prio] +definition complex_has_mul : has_mul complex := has_mul.mk complex.mul protected theorem add_def (z w : ℂ) : @@ -156,7 +161,8 @@ iff.intro eq_of_of_real_eq_of_real !congr_arg /- make complex an instance of ring -/ -protected definition comm_ring [reducible] : comm_ring complex := +attribute [reducible] +protected definition comm_ring : comm_ring complex := begin fapply comm_ring.mk, exact complex.add, @@ -179,7 +185,8 @@ protected definition comm_ring [reducible] : comm_ring complex := local attribute complex.comm_ring [instance] -definition complex_has_sub [instance] [priority complex.prio] : has_sub complex := +attribute [instance] [priority complex.prio] +definition complex_has_sub : has_sub complex := has_sub.mk has_sub.sub theorem of_real_sub (x y : ℝ) : of_real (x - y) = of_real x - of_real y := @@ -234,7 +241,8 @@ end protected noncomputable definition inv (z : ℂ) : complex := conj z * of_real (cmod z)⁻¹ -protected noncomputable definition complex_has_inv [instance] [priority complex.prio] : +attribute [instance] [priority complex.prio] +protected noncomputable definition complex_has_inv : has_inv complex := has_inv.mk complex.inv protected theorem inv_def (z : ℂ) : z⁻¹ = conj z * of_real (cmod z)⁻¹ := rfl @@ -252,7 +260,8 @@ classical.by_cases protected noncomputable definition div (z w : ℂ) : ℂ := z * w⁻¹ -noncomputable definition complex_has_div [instance] [priority complex.prio] : +attribute [instance] [priority complex.prio] +noncomputable definition complex_has_div : has_div complex := has_div.mk complex.div @@ -278,7 +287,8 @@ take z w, classical.prop_decidable (z = w) protected theorem zero_ne_one : (0 : ℂ) ≠ 1 := assume H, zero_ne_one (eq_of_of_real_eq_of_real H) -protected noncomputable definition discrete_field [trans_instance] : +attribute [trans_instance] +protected noncomputable definition discrete_field : discrete_field ℂ := ⦃ discrete_field, complex.comm_ring, mul_inv_cancel := @complex.mul_inv_cancel, diff --git a/library/data/empty.lean b/library/data/empty.lean index 6016e7fb2c..29e4b2e07e 100644 --- a/library/data/empty.lean +++ b/library/data/empty.lean @@ -9,11 +9,13 @@ namespace empty protected definition elim (A : Type) : empty → A := empty.rec (λe, A) - protected definition subsingleton [instance] : subsingleton empty := + attribute [instance] + protected definition subsingleton : subsingleton empty := subsingleton.intro (λ a b, empty.elim _ a) end empty -protected definition empty.has_decidable_eq [instance] : decidable_eq empty := +attribute [instance] +protected definition empty.has_decidable_eq : decidable_eq empty := take (a b : empty), decidable.tt (empty.elim _ a) definition tneg.tneg (A : Type) := A → empty diff --git a/library/data/encodable.lean b/library/data/encodable.lean index 3b8d2fdba3..6075562dfa 100644 --- a/library/data/encodable.lean +++ b/library/data/encodable.lean @@ -23,17 +23,20 @@ have injective encode, from by rewrite [*encodek at this]; injection this; assumption, exists.intro encode this -definition encodable_fintype [instance] {A : Type} [h₁ : fintype A] [h₂ : decidable_eq A] : +attribute [instance] +definition encodable_fintype {A : Type} [h₁ : fintype A] [h₂ : decidable_eq A] : encodable A := encodable.mk (λ a, find a (elements_of A)) (λ n, nth (elements_of A) n) (λ a, find_nth (fintype.complete a)) -definition encodable_nat [instance] : encodable nat := +attribute [instance] +definition encodable_nat : encodable nat := encodable.mk (λ a, a) (λ n, some n) (λ a, rfl) -definition encodable_option [instance] {A : Type} [h : encodable A] : encodable (option A) := +attribute [instance] +definition encodable_option {A : Type} [h : encodable A] : encodable (option A) := encodable.mk (λ o, match o with | some a := succ (encode a) @@ -87,7 +90,8 @@ private theorem decode_encode_sum : ∀ s : sum A B, decode_sum (encode_sum s) = nat.mul_div_cancel_left _ aux₁, encodable.encodek] end -definition encodable_sum [instance] : encodable (sum A B) := +attribute [instance] +definition encodable_sum : encodable (sum A B) := encodable.mk (λ s, encode_sum s) (λ n, decode_sum n) @@ -124,7 +128,8 @@ private theorem decode_encode_prod : ∀ p : A × B, decode_prod (encode_prod p) rewrite [*encodable.encodek] end -definition encodable_product [instance] : encodable (A × B) := +attribute [instance] +definition encodable_product : encodable (A × B) := encodable.mk encode_prod decode_prod @@ -200,7 +205,8 @@ begin apply decode_encode_list_core end -definition encodable_list [instance] : encodable (list A) := +attribute [instance] +definition encodable_list : encodable (list A) := encodable.mk encode_list decode_list @@ -230,7 +236,8 @@ have decode A (encode a) = decode A (encode b), by rewrite this, have some a = some b, by rewrite [*encodek at this]; exact this, option.no_confusion this (λ e, e) -private definition decidable_enle [instance] (a b : A) : decidable (enle a b) := +attribute [instance] +private definition decidable_enle (a b : A) : decidable (enle a b) := decidable_le (encode a) (encode b) variables [decA : decidable_eq A] @@ -268,7 +275,8 @@ quot.induction_on s (λ l, ... ~ l : sort_perm end) -definition encodable_finset [instance] : encodable (finset A) := +attribute [instance] +definition encodable_finset : encodable (finset A) := encodable.mk encode_finset decode_finset @@ -300,7 +308,8 @@ private lemma decode_encode_subtype : ∀ s : {a : A | P a}, decode_subtype (enc rewrite [dif_pos h] end -definition encodable_subtype [instance] : encodable {a : A | P a} := +attribute [instance] +definition encodable_subtype : encodable {a : A | P a} := encodable.mk encode_subtype decode_subtype diff --git a/library/data/equiv.lean b/library/data/equiv.lean index 62da1c9e52..f7a5ac8d4e 100644 --- a/library/data/equiv.lean +++ b/library/data/equiv.lean @@ -18,7 +18,8 @@ structure equiv [class] (A B : Type) := (right_inv : right_inverse inv_fun to_fun) namespace equiv -definition perm [reducible] (A : Type) := equiv A A +attribute [reducible] +definition perm (A : Type) := equiv A A infix ` ≃ `:50 := equiv @@ -39,13 +40,16 @@ lemma eq_of_to_fun_eq {A B : Type} : ∀ {e₁ e₂ : equiv A B}, fn e₁ = fn e show g₁ x = g₂ x, from injective_of_left_inverse l₁ this), by congruence; repeat assumption -protected definition refl [refl] (A : Type) : A ≃ A := +attribute [refl] +protected definition refl (A : Type) : A ≃ A := mk (@id A) (@id A) (λ x, rfl) (λ x, rfl) -protected definition symm [symm] {A B : Type} : A ≃ B → B ≃ A +attribute [symm] +protected definition symm {A B : Type} : A ≃ B → B ≃ A | (mk f g h₁ h₂) := mk g f h₂ h₁ -protected definition trans [trans] {A B C : Type} : A ≃ B → B ≃ C → A ≃ C +attribute [trans] +protected definition trans {A B C : Type} : A ≃ B → B ≃ C → A ≃ C | (mk f₁ g₁ l₁ r₁) (mk f₂ g₂ l₂ r₂) := mk (f₂ ∘ f₁) (g₁ ∘ g₂) (show ∀ x, g₁ (g₂ (f₂ (f₁ x))) = x, by intros; rewrite [l₂, l₁]; reflexivity) @@ -88,7 +92,8 @@ lemma apply_eq_iff_eq_inverse_apply {A B : Type} : ∀ (f : A ≃ B) (x : A) (y definition false_equiv_empty : empty ≃ false := mk (λ e, empty.rec _ e) (λ h, false.rec _ h) (λ e, empty.rec _ e) (λ h, false.rec _ h) -definition arrow_congr [congr] {A₁ B₁ A₂ B₂ : Type} : A₁ ≃ A₂ → B₁ ≃ B₂ → (A₁ → B₁) ≃ (A₂ → B₂) +attribute [congr] +definition arrow_congr {A₁ B₁ A₂ B₂ : Type} : A₁ ≃ A₂ → B₁ ≃ B₂ → (A₁ → B₁) ≃ (A₂ → B₂) | (mk f₁ g₁ l₁ r₁) (mk f₂ g₂ l₂ r₂) := mk (λ (h : A₁ → B₁) (a : A₂), f₂ (h (g₁ a))) @@ -98,27 +103,32 @@ definition arrow_congr [congr] {A₁ B₁ A₂ B₂ : Type} : A₁ ≃ A₂ → section open unit -definition arrow_unit_equiv_unit [simp] (A : Type) : (A → unit) ≃ unit := +attribute [simp] +definition arrow_unit_equiv_unit (A : Type) : (A → unit) ≃ unit := mk (λ f, star) (λ u, (λ f, star)) (λ f, funext (λ x, by cases (f x); reflexivity)) (λ u, by cases u; reflexivity) -definition unit_arrow_equiv [simp] (A : Type) : (unit → A) ≃ A := +attribute [simp] +definition unit_arrow_equiv (A : Type) : (unit → A) ≃ A := mk (λ f, f star) (λ a, (λ u, a)) (λ f, funext (λ x, by cases x; reflexivity)) (λ u, rfl) -definition empty_arrow_equiv_unit [simp] (A : Type) : (empty → A) ≃ unit := +attribute [simp] +definition empty_arrow_equiv_unit (A : Type) : (empty → A) ≃ unit := mk (λ f, star) (λ u, λ e, empty.rec _ e) (λ f, funext (λ x, empty.rec _ x)) (λ u, by cases u; reflexivity) -definition false_arrow_equiv_unit [simp] (A : Type) : (false → A) ≃ unit := +attribute [simp] +definition false_arrow_equiv_unit (A : Type) : (false → A) ≃ unit := calc (false → A) ≃ (empty → A) : arrow_congr false_equiv_empty !equiv.refl ... ≃ unit : empty_arrow_equiv_unit end -definition prod_congr [congr] {A₁ B₁ A₂ B₂ : Type} : A₁ ≃ A₂ → B₁ ≃ B₂ → (A₁ × B₁) ≃ (A₂ × B₂) +attribute [congr] +definition prod_congr {A₁ B₁ A₂ B₂ : Type} : A₁ ≃ A₂ → B₁ ≃ B₂ → (A₁ × B₁) ≃ (A₂ × B₂) | (mk f₁ g₁ l₁ r₁) (mk f₂ g₂ l₂ r₂) := mk (λ p, match p with (a₁, b₁) := (f₁ a₁, f₂ b₁) end) @@ -126,13 +136,15 @@ definition prod_congr [congr] {A₁ B₁ A₂ B₂ : Type} : A₁ ≃ A₂ → B (λ p, begin cases p, esimp, rewrite [l₁, l₂], reflexivity end) (λ p, begin cases p, esimp, rewrite [r₁, r₂], reflexivity end) -definition prod_comm [simp] (A B : Type) : (A × B) ≃ (B × A) := +attribute [simp] +definition prod_comm (A B : Type) : (A × B) ≃ (B × A) := mk (λ p, match p with (a, b) := (b, a) end) (λ p, match p with (b, a) := (a, b) end) (λ p, begin cases p, esimp end) (λ p, begin cases p, esimp end) -definition prod_assoc [simp] (A B C : Type) : ((A × B) × C) ≃ (A × (B × C)) := +attribute [simp] +definition prod_assoc (A B C : Type) : ((A × B) × C) ≃ (A × (B × C)) := mk (λ t, match t with ((a, b), c) := (a, (b, c)) end) (λ t, match t with (a, (b, c)) := ((a, b), c) end) (λ t, begin cases t with ab c, cases ab, esimp end) @@ -140,27 +152,32 @@ mk (λ t, match t with ((a, b), c) := (a, (b, c)) end) section open unit prod.ops -definition prod_unit_right [simp] (A : Type) : (A × unit) ≃ A := +attribute [simp] +definition prod_unit_right (A : Type) : (A × unit) ≃ A := mk (λ p, p.1) (λ a, (a, star)) (λ p, begin cases p with a u, cases u, esimp end) (λ a, rfl) -definition prod_unit_left [simp] (A : Type) : (unit × A) ≃ A := +attribute [simp] +definition prod_unit_left (A : Type) : (unit × A) ≃ A := calc (unit × A) ≃ (A × unit) : prod_comm ... ≃ A : prod_unit_right -definition prod_empty_right [simp] (A : Type) : (A × empty) ≃ empty := +attribute [simp] +definition prod_empty_right (A : Type) : (A × empty) ≃ empty := mk (λ p, empty.rec _ p.2) (λ e, empty.rec _ e) (λ p, empty.rec _ p.2) (λ e, empty.rec _ e) -definition prod_empty_left [simp] (A : Type) : (empty × A) ≃ empty := +attribute [simp] +definition prod_empty_left (A : Type) : (empty × A) ≃ empty := calc (empty × A) ≃ (A × empty) : prod_comm ... ≃ empty : prod_empty_right end section open sum -definition sum_congr [congr] {A₁ B₁ A₂ B₂ : Type} : A₁ ≃ A₂ → B₁ ≃ B₂ → (A₁ + B₁) ≃ (A₂ + B₂) +attribute [congr] +definition sum_congr {A₁ B₁ A₂ B₂ : Type} : A₁ ≃ A₂ → B₁ ≃ B₂ → (A₁ + B₁) ≃ (A₂ + B₂) | (mk f₁ g₁ l₁ r₁) (mk f₂ g₂ l₂ r₂) := mk (λ s, match s with inl a₁ := inl (f₁ a₁) | inr b₁ := inr (f₂ b₁) end) @@ -175,25 +192,29 @@ mk (λ b, match b with tt := inl star | ff := inr star end) (λ b, begin cases b, esimp, esimp end) (λ s, begin cases s with u u, {cases u, esimp}, {cases u, esimp} end) -definition sum_comm [simp] (A B : Type) : (A + B) ≃ (B + A) := +attribute [simp] +definition sum_comm (A B : Type) : (A + B) ≃ (B + A) := mk (λ s, match s with inl a := inr a | inr b := inl b end) (λ s, match s with inl b := inr b | inr a := inl a end) (λ s, begin cases s, esimp, esimp end) (λ s, begin cases s, esimp, esimp end) -definition sum_assoc [simp] (A B C : Type) : ((A + B) + C) ≃ (A + (B + C)) := +attribute [simp] +definition sum_assoc (A B C : Type) : ((A + B) + C) ≃ (A + (B + C)) := mk (λ s, match s with inl (inl a) := inl a | inl (inr b) := inr (inl b) | inr c := inr (inr c) end) (λ s, match s with inl a := inl (inl a) | inr (inl b) := inl (inr b) | inr (inr c) := inr c end) (λ s, begin cases s with ab c, cases ab, repeat esimp end) (λ s, begin cases s with a bc, esimp, cases bc, repeat esimp end) -definition sum_empty_right [simp] (A : Type) : (A + empty) ≃ A := +attribute [simp] +definition sum_empty_right (A : Type) : (A + empty) ≃ A := mk (λ s, match s with inl a := a | inr e := empty.rec _ e end) (λ a, inl a) (λ s, begin cases s with a e, esimp, exact empty.rec _ e end) (λ a, rfl) -definition sum_empty_left [simp] (A : Type) : (empty + A) ≃ A := +attribute [simp] +definition sum_empty_left (A : Type) : (empty + A) ≃ A := calc (empty + A) ≃ (A + empty) : sum_comm ... ≃ A : sum_empty_right end @@ -245,23 +266,27 @@ mk (λ n, match n with zero := inr star | succ a := inl a end) (λ n, begin cases n, repeat esimp end) (λ s, begin cases s with a u, esimp, {cases u, esimp} end) -definition nat_sum_unit_equiv_nat [simp] : (nat + unit) ≃ nat := +attribute [simp] +definition nat_sum_unit_equiv_nat : (nat + unit) ≃ nat := equiv.symm nat_equiv_nat_sum_unit -definition nat_prod_nat_equiv_nat [simp] : (nat × nat) ≃ nat := +attribute [simp] +definition nat_prod_nat_equiv_nat : (nat × nat) ≃ nat := mk (λ p, mkpair p.1 p.2) (λ n, unpair n) (λ p, begin cases p, apply unpair_mkpair end) (λ n, mkpair_unpair n) -definition nat_sum_bool_equiv_nat [simp] : (nat + bool) ≃ nat := +attribute [simp] +definition nat_sum_bool_equiv_nat : (nat + bool) ≃ nat := calc (nat + bool) ≃ (nat + (unit + unit)) : sum_congr !equiv.refl bool_equiv_unit_sum_unit ... ≃ ((nat + unit) + unit) : sum_assoc ... ≃ (nat + unit) : sum_congr nat_sum_unit_equiv_nat !equiv.refl ... ≃ nat : nat_sum_unit_equiv_nat open decidable -definition nat_sum_nat_equiv_nat [simp] : (nat + nat) ≃ nat := +attribute [simp] +definition nat_sum_nat_equiv_nat : (nat + nat) ≃ nat := mk (λ s, match s with inl n := 2*n | inr n := 2*n+1 end) (λ n, if even n then inl (n / 2) else inr ((n - 1) / 2)) (λ s, begin diff --git a/library/data/examples/vector.lean b/library/data/examples/vector.lean index d593dbe0bc..7a392c6662 100644 --- a/library/data/examples/vector.lean +++ b/library/data/examples/vector.lean @@ -19,7 +19,8 @@ namespace vector variables {A B C : Type} - protected definition is_inhabited [instance] [h : inhabited A] : ∀ (n : nat), inhabited (vector A n) + attribute [instance] + protected definition is_inhabited [h : inhabited A] : ∀ (n : nat), inhabited (vector A n) | 0 := inhabited.mk [] | (n+1) := inhabited.mk (inhabited.value h :: inhabited.value (is_inhabited n)) diff --git a/library/data/finset/basic.lean b/library/data/finset/basic.lean index 1b2f6a2d44..625cf405e6 100644 --- a/library/data/finset/basic.lean +++ b/library/data/finset/basic.lean @@ -33,7 +33,8 @@ perm.symm private definition eqv.trans {l₁ l₂ l₃ : nodup_list A} : l₁ ~ l₂ → l₂ ~ l₃ → l₁ ~ l₃ := perm.trans -definition finset.nodup_list_setoid [instance] (A : Type) : setoid (nodup_list A) := +attribute [instance] +definition finset.nodup_list_setoid (A : Type) : setoid (nodup_list A) := setoid.mk (@eqv A) (mk_equivalence (@eqv A) (@eqv.refl A) (@eqv.symm A) (@eqv.trans A)) definition finset (A : Type) : Type := @@ -60,7 +61,8 @@ have P : to_nodup_list_of_nodup n = to_nodup_list l, from end, quot.sound (eq.subst P !setoid.refl) -definition has_decidable_eq [instance] [decidable_eq A] : decidable_eq (finset A) := +attribute [instance] +definition has_decidable_eq [decidable_eq A] : decidable_eq (finset A) := λ s₁ s₂, quot.rec_on_subsingleton₂ s₁ s₂ (λ l₁ l₂, match decidable_perm (elt_of l₁) (elt_of l₂) with @@ -83,7 +85,8 @@ theorem mem_of_mem_list {a : A} {l : nodup_list A} : a ∈ elt_of l → a ∈ theorem mem_list_of_mem {a : A} {l : nodup_list A} : a ∈ ⟦l⟧ → a ∈ elt_of l := λ ainl, ainl -definition decidable_mem [instance] [h : decidable_eq A] : ∀ (a : A) (s : finset A), decidable (a ∈ s) := +attribute [instance] +definition decidable_mem [h : decidable_eq A] : ∀ (a : A) (s : finset A), decidable (a ∈ s) := λ a s, quot.rec_on_subsingleton s (λ l, match list.decidable_mem a (elt_of l) with | decidable.inl p := decidable.inl (mem_of_mem_list p) @@ -106,10 +109,12 @@ to_finset_of_nodup [] nodup_nil notation [priority finset.prio] `∅` := !empty -theorem not_mem_empty [simp] (a : A) : a ∉ ∅ := +attribute [simp] +theorem not_mem_empty (a : A) : a ∉ ∅ := λ aine : a ∈ ∅, aine -theorem mem_empty_iff [simp] (x : A) : x ∈ ∅ ↔ false := +attribute [simp] +theorem mem_empty_iff (x : A) : x ∈ ∅ ↔ false := iff_false_intro !not_mem_empty theorem mem_empty_eq (x : A) : x ∈ ∅ = false := @@ -224,7 +229,8 @@ theorem card_insert_le (a : A) (s : finset A) : if H : a ∈ s then by rewrite [card_insert_of_mem H]; apply le_succ else by rewrite [card_insert_of_not_mem H] -protected theorem induction [recursor 6] {P : finset A → Prop} +attribute [recursor 6] +protected theorem induction {P : finset A → Prop} (H1 : P empty) (H2 : ∀ ⦃a : A⦄, ∀{s : finset A}, a ∉ s → P s → P (insert a s)) : ∀s, P s := diff --git a/library/data/finset/comb.lean b/library/data/finset/comb.lean index 169591d04e..183c298cb8 100644 --- a/library/data/finset/comb.lean +++ b/library/data/finset/comb.lean @@ -265,7 +265,8 @@ quot.induction_on s (λ l H, list.all_of_forall H) theorem all_iff_forall (p : A → Prop) (s : finset A) : all s p ↔ (∀a, a ∈ s → p a) := iff.intro forall_of_all all_of_forall -definition decidable_all [instance] (p : A → Prop) [h : decidable_pred p] (s : finset A) : +attribute [instance] +definition decidable_all (p : A → Prop) [h : decidable_pred p] (s : finset A) : decidable (all s p) := quot.rec_on_subsingleton s (λ l, list.decidable_all p (elt_of l)) @@ -301,7 +302,8 @@ iff.intro (suppose s ⊆ t, all_of_forall (take x, suppose x ∈ s, mem_of_subset_of_mem `s ⊆ t` `x ∈ s`)) (suppose all s (λ x, x ∈ t), subset_of_forall (take x, suppose x ∈ s, of_mem_of_all `x ∈ s` `all s (λ x, x ∈ t)`)) -definition decidable_subset [instance] (s t : finset A) : decidable (s ⊆ t) := +attribute [instance] +definition decidable_subset (s t : finset A) : decidable (s ⊆ t) := decidable_of_decidable_of_iff _ (iff.symm !subset_iff_all) end all @@ -337,7 +339,8 @@ theorem any_of_insert_right [h : decidable_eq A] {p : A → Prop} {s : finset A} obtain b (H₁ : b ∈ s) (H₂ : p b), from exists_of_any H, any_of_mem (mem_insert_of_mem a H₁) H₂ -definition decidable_any [instance] (p : A → Prop) [h : decidable_pred p] (s : finset A) : +attribute [instance] +definition decidable_any (p : A → Prop) [h : decidable_pred p] (s : finset A) : decidable (any s p) := quot.rec_on_subsingleton s (λ l, list.decidable_any p (elt_of l)) end any diff --git a/library/data/finset/to_set.lean b/library/data/finset/to_set.lean index 258b5712b7..432b15f2ae 100644 --- a/library/data/finset/to_set.lean +++ b/library/data/finset/to_set.lean @@ -64,7 +64,8 @@ theorem to_set_image {B : Type} [h : decidable_eq B] (f : A → B) (s : finset A /- relations -/ -definition decidable_mem_to_set [instance] (x : A) (s : finset A) : decidable (x ∈ ts s) := +attribute [instance] +definition decidable_mem_to_set (x : A) (s : finset A) : decidable (x ∈ ts s) := decidable_of_decidable_of_eq _ !mem_eq_mem_to_set theorem eq_of_to_set_eq_to_set {s t : finset A} (H : to_set s = to_set t) : s = t := @@ -73,7 +74,8 @@ ext (take x, by rewrite [mem_eq_mem_to_set s, H]) theorem eq_eq_to_set_eq : (s = t) = (ts s = ts t) := propext (iff.intro (assume H, H ▸ rfl) !eq_of_to_set_eq_to_set) -definition decidable_to_set_eq [instance] (s t : finset A) : decidable (ts s = ts t) := +attribute [instance] +definition decidable_to_set_eq (s t : finset A) : decidable (ts s = ts t) := decidable_of_decidable_of_eq _ !eq_eq_to_set_eq theorem subset_eq_to_set_subset (s t : finset A) : (s ⊆ t) = (ts s ⊆ ts t) := diff --git a/library/data/fintype/basic.lean b/library/data/fintype/basic.lean index ba0305769b..455b5ad799 100644 --- a/library/data/fintype/basic.lean +++ b/library/data/fintype/basic.lean @@ -27,15 +27,18 @@ definition fintype_of_equiv {A B : Type} [h : fintype A] : A ≃ B → fintype B by rewrite r at this; exact this) end -definition fintype_unit [instance] : fintype unit := +attribute [instance] +definition fintype_unit : fintype unit := fintype.mk [star] dec_trivial (λ u, match u with star := dec_trivial end) -definition fintype_bool [instance] : fintype bool := +attribute [instance] +definition fintype_bool : fintype bool := fintype.mk [ff, tt] dec_trivial (λ b, match b with | tt := dec_trivial | ff := dec_trivial end) -definition fintype_product [instance] {A B : Type} : Π [h₁ : fintype A] [h₂ : fintype B], fintype (A × B) +attribute [instance] +definition fintype_product {A B : Type} : Π [h₁ : fintype A] [h₂ : fintype B], fintype (A × B) | (fintype.mk e₁ u₁ c₁) (fintype.mk e₂ u₂ c₂) := fintype.mk (product e₁ e₂) @@ -86,7 +89,8 @@ theorem all_eq_of_find_discr_eq_none {f g : A → B} : ∀ {l}, find_discr f g l by rewrite [find_discr_cons_of_ne l this at e]; contradiction) end find_discr -definition decidable_eq_fun [instance] {A B : Type} [h₁ : fintype A] [h₂ : decidable_eq B] : decidable_eq (A → B) := +attribute [instance] +definition decidable_eq_fun {A B : Type} [h₁ : fintype A] [h₂ : decidable_eq B] : decidable_eq (A → B) := λ f g, match h₁ with | fintype.mk e u c := @@ -129,7 +133,8 @@ theorem ex_of_check_pred_eq_ff {p : A → Prop} [h : decidable_pred p] : ∀ {l (suppose ¬ p a, exists.intro a this) end check_pred -definition decidable_forall_finite [instance] {A : Type} {p : A → Prop} [h₁ : fintype A] [h₂ : decidable_pred p] +attribute [instance] +definition decidable_forall_finite {A : Type} {p : A → Prop} [h₁ : fintype A] [h₂ : decidable_pred p] : decidable (∀ x : A, p x) := match h₁ with | fintype.mk e u c := @@ -142,7 +147,8 @@ match h₁ with end rfl end -definition decidable_exists_finite [instance] {A : Type} {p : A → Prop} [h₁ : fintype A] [h₂ : decidable_pred p] +attribute [instance] +definition decidable_exists_finite {A : Type} {p : A → Prop} [h₁ : fintype A] [h₂ : decidable_pred p] : decidable (∃ x : A, p x) := match h₁ with | fintype.mk e u c := @@ -202,7 +208,8 @@ private theorem mem_ltype_elems {A : Type} {s : list A} {a : ⟪s⟫} have aux : a ∈ ltype_elems (sub_of_cons_sub h), from mem_ltype_elems (sub_of_cons_sub h) vainl, mem_cons_of_mem _ aux) -definition fintype_list_as_type [instance] {A : Type} [h : decidable_eq A] {s : list A} : fintype ⟪s⟫ := +attribute [instance] +definition fintype_list_as_type {A : Type} [h : decidable_eq A] {s : list A} : fintype ⟪s⟫ := let nds : list A := erase_dup s in have sub₁ : nds ⊆ s, from erase_dup_sub s, have sub₂ : s ⊆ nds, from sub_erase_dup s, diff --git a/library/data/fintype/card.lean b/library/data/fintype/card.lean index 7873bffbf0..c58cff507f 100644 --- a/library/data/fintype/card.lean +++ b/library/data/fintype/card.lean @@ -10,7 +10,8 @@ open eq.ops nat function list finset namespace fintype -definition card [reducible] (A : Type) [finA : fintype A] := finset.card (@finset.univ A _) +attribute [reducible] +definition card (A : Type) [finA : fintype A] := finset.card (@finset.univ A _) lemma card_eq_card_image_of_inj {A : Type} [finA : fintype A] [deceqA : decidable_eq A] diff --git a/library/data/fintype/function.lean b/library/data/fintype/function.lean index b936ec60f7..75de6c50eb 100644 --- a/library/data/fintype/function.lean +++ b/library/data/fintype/function.lean @@ -318,7 +318,8 @@ lemma length_all_funs : length (@all_funs A B _ _ _) = (card B) ^ (card A) := ca ... = length (all_lists_of_len (card A)) : all_funs_to_all_lists ... = (card B) ^ (card A) : length_all_lists -definition fun_is_fintype [instance] : fintype (A → B) := +attribute [instance] +definition fun_is_fintype : fintype (A → B) := fintype.mk all_funs nodup_all_funs all_funs_complete lemma card_funs : card (A → B) = (card B) ^ (card A) := length_all_funs diff --git a/library/data/hf.lean b/library/data/hf.lean index ccdab5c17b..858871a3fd 100644 --- a/library/data/hf.lean +++ b/library/data/hf.lean @@ -20,10 +20,12 @@ local attribute hf [reducible] protected definition prio : num := num.succ std.priority.default -protected definition is_inhabited [instance] : inhabited hf := +attribute [instance] +protected definition is_inhabited : inhabited hf := nat.is_inhabited -protected definition has_decidable_eq [instance] : decidable_eq hf := +attribute [instance] +protected definition has_decidable_eq : decidable_eq hf := nat.has_decidable_eq definition of_finset (s : finset hf) : hf := @@ -88,7 +90,8 @@ begin end open decidable -protected definition decidable_mem [instance] : ∀ a s, decidable (a ∈ s) := +attribute [instance] +protected definition decidable_mem : ∀ a s, decidable (a ∈ s) := λ a s, finset.decidable_mem a (to_finset s) lemma insert_le (a s : hf) : s ≤ insert a s := @@ -120,7 +123,8 @@ by rewrite [*of_finset_to_finset at this]; exact this theorem insert_eq_of_mem {a : hf} {s : hf} : a ∈ s → insert a s = s := begin unfold mem, intro h, unfold [mem, insert], rewrite (finset.insert_eq_of_mem h), rewrite of_finset_to_finset end -protected theorem induction [recursor 4] {P : hf → Prop} +attribute [recursor 4] +protected theorem induction {P : hf → Prop} (h₁ : P empty) (h₂ : ∀ (a s : hf), a ∉ s → P s → P (insert a s)) (s : hf) : P s := have P (of_finset (to_finset s)), from @finset.induction _ _ _ h₁ @@ -528,29 +532,36 @@ of_list (list.append (to_list l₁) (to_list l₂)) notation l₁ ++ l₂ := append l₁ l₂ -theorem append_nil_left [simp] (t : hf) : nil ++ t = t := +attribute [simp] +theorem append_nil_left (t : hf) : nil ++ t = t := begin unfold [nil, append], rewrite [to_list_of_list, list.append_nil_left, of_list_to_list] end -theorem append_cons [simp] (x s t : hf) : (x::s) ++ t = x::(s ++ t) := +attribute [simp] +theorem append_cons (x s t : hf) : (x::s) ++ t = x::(s ++ t) := begin unfold [cons, append], rewrite [*to_list_of_list, list.append_cons] end -theorem append_nil_right [simp] (t : hf) : t ++ nil = t := +attribute [simp] +theorem append_nil_right (t : hf) : t ++ nil = t := begin unfold [nil, append], rewrite [to_list_of_list, list.append_nil_right, of_list_to_list] end -theorem append.assoc [simp] (s t u : hf) : s ++ t ++ u = s ++ (t ++ u) := +attribute [simp] +theorem append.assoc (s t u : hf) : s ++ t ++ u = s ++ (t ++ u) := begin unfold append, rewrite [*to_list_of_list, list.append.assoc] end /- length -/ definition length (l : hf) : nat := list.length (to_list l) -theorem length_nil [simp] : length nil = 0 := +attribute [simp] +theorem length_nil : length nil = 0 := begin unfold [length, nil] end -theorem length_cons [simp] (x t : hf) : length (x::t) = length t + 1 := +attribute [simp] +theorem length_cons (x t : hf) : length (x::t) = length t + 1 := begin unfold [length, cons], rewrite to_list_of_list end -theorem length_append [simp] (s t : hf) : length (s ++ t) = length s + length t := +attribute [simp] +theorem length_append (s t : hf) : length (s ++ t) = length s + length t := begin unfold [length, append], rewrite [to_list_of_list, list.length_append] end theorem eq_nil_of_length_eq_zero {l : hf} : length l = 0 → l = nil := @@ -563,7 +574,8 @@ begin unfold [length, nil], intro h₁ h₂, subst l, rewrite to_list_of_list at definition head (l : hf) : hf := list.head (to_list l) -theorem head_cons [simp] (a l : hf) : head (a::l) = a := +attribute [simp] +theorem head_cons (a l : hf) : head (a::l) = a := begin unfold [head, cons], rewrite to_list_of_list end private lemma to_list_ne_list_nil {s : hf} : s ≠ nil → to_list s ≠ list.nil := @@ -574,7 +586,8 @@ begin by rewrite [-this at h, of_list_to_list at h]; exact absurd rfl h end -theorem head_append [simp] (t : hf) {s : hf} : s ≠ nil → head (s ++ t) = head s := +attribute [simp] +theorem head_append (t : hf) {s : hf} : s ≠ nil → head (s ++ t) = head s := begin unfold [nil, head, append], rewrite to_list_of_list, suppose s ≠ of_list list.nil, @@ -584,10 +597,12 @@ end definition tail (l : hf) : hf := of_list (list.tail (to_list l)) -theorem tail_nil [simp] : tail nil = nil := +attribute [simp] +theorem tail_nil : tail nil = nil := begin unfold [tail, nil] end -theorem tail_cons [simp] (a l : hf) : tail (a::l) = l := +attribute [simp] +theorem tail_cons (a l : hf) : tail (a::l) = l := begin unfold [tail, cons], rewrite [to_list_of_list, list.tail_cons, of_list_to_list] end theorem cons_head_tail {l : hf} : l ≠ nil → (head l)::(tail l) = l := diff --git a/library/data/int/basic.lean b/library/data/int/basic.lean index d7a3f04d63..5cc2173698 100644 --- a/library/data/int/basic.lean +++ b/library/data/int/basic.lean @@ -38,7 +38,8 @@ inductive int : Type := notation `ℤ` := int -- [coercion] -definition int.of_num [reducible] [constructor] (n : num) : ℤ := +attribute [reducible] [constructor] +definition int.of_num (n : num) : ℤ := int.of_nat (nat.of_num n) namespace int @@ -49,10 +50,12 @@ notation `-[1+ ` n `]` := int.neg_succ_of_nat n -- for pretty-printing output protected definition prio : num := num.pred nat.prio -definition int_has_zero [instance] [priority int.prio] : has_zero int := +attribute [instance] [priority int.prio] +definition int_has_zero : has_zero int := has_zero.mk (of_nat 0) -definition int_has_one [instance] [priority int.prio] : has_one int := +attribute [instance] [priority int.prio] +definition int_has_one : has_one int := has_one.mk (of_nat 1) theorem of_nat_zero : of_nat (0:nat) = (0:int) := @@ -90,9 +93,12 @@ protected definition mul : ℤ → ℤ → ℤ /- notation -/ -definition int_has_add [instance] [priority int.prio] : has_add int := has_add.mk int.add -definition int_has_neg [instance] [priority int.prio] : has_neg int := has_neg.mk int.neg -definition int_has_mul [instance] [priority int.prio] : has_mul int := has_mul.mk int.mul +attribute [instance] [priority int.prio] +definition int_has_add : has_add int := has_add.mk int.add +attribute [instance] [priority int.prio] +definition int_has_neg : has_neg int := has_neg.mk int.neg +attribute [instance] [priority int.prio] +definition int_has_mul : has_mul int := has_mul.mk int.mul lemma mul_of_nat_of_nat (m n : nat) : of_nat m * of_nat n = of_nat (m * n) := rfl @@ -130,7 +136,8 @@ private definition has_decidable_eq₂ : Π (a b : ℤ), decidable (a = b) | -[1+ m] -[1+ n] := if H : m = n then inl (congr_arg neg_succ_of_nat H) else inr (not.mto neg_succ_of_nat.inj H) -definition has_decidable_eq [instance] [priority int.prio] : decidable_eq ℤ := has_decidable_eq₂ +attribute [instance] [priority int.prio] +definition has_decidable_eq : decidable_eq ℤ := has_decidable_eq₂ theorem of_nat_add (n m : nat) : of_nat (n + m) = of_nat n + of_nat m := rfl @@ -168,14 +175,17 @@ protected definition equiv (p q : ℕ × ℕ) : Prop := pr1 p + pr2 q = pr2 p + local infix ≡ := int.equiv -protected theorem equiv.refl [refl] {p : ℕ × ℕ} : p ≡ p := !add.comm +attribute [refl] +protected theorem equiv.refl {p : ℕ × ℕ} : p ≡ p := !add.comm local attribute int.equiv [reducible] -protected theorem equiv.symm [symm] {p q : ℕ × ℕ} (H : p ≡ q) : q ≡ p := +attribute [symm] +protected theorem equiv.symm {p q : ℕ × ℕ} (H : p ≡ q) : q ≡ p := by simp -protected theorem equiv.trans [trans] {p q r : ℕ × ℕ} (H1 : p ≡ q) (H2 : q ≡ r) : p ≡ r := +attribute [trans] +protected theorem equiv.trans {p q r : ℕ × ℕ} (H1 : p ≡ q) (H2 : q ≡ r) : p ≡ r := add.right_cancel (calc pr1 p + pr2 r + pr2 q = pr1 p + pr2 q + pr2 r : by simp_nohyps ... = pr2 p + pr1 r + pr2 q : by simp) @@ -516,7 +526,8 @@ protected theorem eq_zero_or_eq_zero_of_mul_eq_zero {a b : ℤ} (H : a * b = 0) or.imp eq_zero_of_nat_abs_eq_zero eq_zero_of_nat_abs_eq_zero (eq_zero_or_eq_zero_of_mul_eq_zero (by rewrite [-nat_abs_mul, H])) -protected definition integral_domain [trans_instance] : integral_domain int := +attribute [trans_instance] +protected definition integral_domain : integral_domain int := ⦃integral_domain, add := int.add, add_assoc := int.add_assoc, @@ -537,10 +548,12 @@ protected definition integral_domain [trans_instance] : integral_domain int := zero_ne_one := int.zero_ne_one, eq_zero_or_eq_zero_of_mul_eq_zero := @int.eq_zero_or_eq_zero_of_mul_eq_zero⦄ -definition int_has_sub [instance] [priority int.prio] : has_sub int := +attribute [instance] [priority int.prio] +definition int_has_sub : has_sub int := has_sub.mk has_sub.sub -definition int_has_dvd [instance] [priority int.prio] : has_dvd int := +attribute [instance] [priority int.prio] +definition int_has_dvd : has_dvd int := has_dvd.mk has_dvd.dvd /- additional properties -/ @@ -577,7 +590,8 @@ theorem pred_nat_succ (n : ℕ) : pred (nat.succ n) = n := pred_succ n theorem neg_nat_succ (n : ℕ) : -nat.succ n = pred (-n) := !neg_succ theorem succ_neg_nat_succ (n : ℕ) : succ (-nat.succ n) = -n := !succ_neg_succ -definition rec_nat_on [unfold 2] {P : ℤ → Type} (z : ℤ) (H0 : P 0) +attribute [unfold 2] +definition rec_nat_on {P : ℤ → Type} (z : ℤ) (H0 : P 0) (Hsucc : Π⦃n : ℕ⦄, P n → P (succ n)) (Hpred : Π⦃n : ℕ⦄, P (-n) → P (-nat.succ n)) : P z := int.rec (nat.rec H0 Hsucc) (λn, nat.rec H0 Hpred (nat.succ n)) z diff --git a/library/data/int/countable.lean b/library/data/int/countable.lean index 58f6a6b3eb..31fe14d12d 100644 --- a/library/data/int/countable.lean +++ b/library/data/int/countable.lean @@ -21,7 +21,8 @@ calc int ≃ (bool × nat) : int_equiv_bool_nat ... ≃ nat + nat : sum_congr !prod_unit_left !prod_unit_left ... ≃ nat : nat_sum_nat_equiv_nat -definition encodable_int [instance] : encodable int := +attribute [instance] +definition encodable_int : encodable int := encodable_of_equiv (_root_.equiv.symm int_equiv_nat) lemma countable_int : countable int := diff --git a/library/data/int/div.lean b/library/data/int/div.lean index ce3e9d8199..814d5fb1cb 100644 --- a/library/data/int/div.lean +++ b/library/data/int/div.lean @@ -23,7 +23,8 @@ sign b * | -[1+m] := -[1+ ((m:nat) / (nat_abs b))] end) -definition int_has_div [instance] [priority int.prio] : has_div int := +attribute [instance] [priority int.prio] +definition int_has_div : has_div int := has_div.mk int.div lemma of_nat_div_eq (m : nat) (b : ℤ) : (of_nat m) / b = sign b * of_nat (m / (nat_abs b)) := @@ -42,7 +43,8 @@ rfl protected definition mod (a b : ℤ) : ℤ := a - a / b * b -definition int_has_mod [instance] [priority int.prio] : has_mod int := +attribute [instance] [priority int.prio] +definition int_has_mod : has_mod int := has_mod.mk int.mod @@ -527,7 +529,8 @@ dvd.elim H (take z, assume H1 : b = a * z, H1⁻¹ ▸ !mul_mod_right) theorem dvd_iff_mod_eq_zero (a b : ℤ) : a ∣ b ↔ b % a = 0 := iff.intro mod_eq_zero_of_dvd dvd_of_mod_eq_zero -definition dvd.decidable_rel [instance] : decidable_rel dvd := +attribute [instance] +definition dvd.decidable_rel : decidable_rel dvd := take a n, decidable_of_decidable_of_iff _ (iff.symm !dvd_iff_mod_eq_zero) protected theorem div_mul_cancel {a b : ℤ} (H : b ∣ a) : a / b * b = a := diff --git a/library/data/int/order.lean b/library/data/int/order.lean index 81052110d7..d909a8794d 100644 --- a/library/data/int/order.lean +++ b/library/data/int/order.lean @@ -16,18 +16,23 @@ namespace int private definition nonneg (a : ℤ) : Prop := int.cases_on a (take n, true) (take n, false) protected definition le (a b : ℤ) : Prop := nonneg (b - a) -definition int_has_le [instance] [priority int.prio]: has_le int := +attribute [instance] [priority int.prio] +definition int_has_le : has_le int := has_le.mk int.le protected definition lt (a b : ℤ) : Prop := (a + 1) ≤ b -definition int_has_lt [instance] [priority int.prio]: has_lt int := +attribute [instance] [priority int.prio] +definition int_has_lt : has_lt int := has_lt.mk int.lt local attribute nonneg [reducible] -private definition decidable_nonneg [instance] (a : ℤ) : decidable (nonneg a) := int.cases_on a _ _ -definition decidable_le [instance] (a b : ℤ) : decidable (a ≤ b) := decidable_nonneg _ -definition decidable_lt [instance] (a b : ℤ) : decidable (a < b) := decidable_nonneg _ +attribute [instance] +private definition decidable_nonneg (a : ℤ) : decidable (nonneg a) := int.cases_on a _ _ +attribute [instance] +definition decidable_le (a b : ℤ) : decidable (a ≤ b) := decidable_nonneg _ +attribute [instance] +definition decidable_lt (a b : ℤ) : decidable (a < b) := decidable_nonneg _ private theorem nonneg.elim {a : ℤ} : nonneg a → ∃n : ℕ, a = n := int.cases_on a (take n H, exists.intro n rfl) (take n', false.elim) @@ -232,7 +237,8 @@ protected theorem lt_of_le_of_lt {a b c : ℤ} (Hab : a ≤ b) (Hbc : b < c) : (iff.mpr !int.lt_iff_le_and_ne) (and.intro Hac (assume Heq, int.not_le_of_gt (Heq⁻¹ ▸ Hbc) Hab)) -protected definition linear_ordered_comm_ring [trans_instance] : +attribute [trans_instance] +protected definition linear_ordered_comm_ring : linear_ordered_comm_ring int := ⦃linear_ordered_comm_ring, int.integral_domain, le := int.le, @@ -253,7 +259,8 @@ protected definition linear_ordered_comm_ring [trans_instance] : zero_lt_one := int.zero_lt_one, add_lt_add_left := @int.add_lt_add_left⦄ -protected definition decidable_linear_ordered_comm_ring [instance] : +attribute [instance] +protected definition decidable_linear_ordered_comm_ring : decidable_linear_ordered_comm_ring int := ⦃decidable_linear_ordered_comm_ring, int.linear_ordered_comm_ring, diff --git a/library/data/int/power.lean b/library/data/int/power.lean index e48782f989..4ffbebf811 100644 --- a/library/data/int/power.lean +++ b/library/data/int/power.lean @@ -9,7 +9,8 @@ import data.int.basic data.int.order data.int.div algebra.group_power data.nat.p namespace int -definition int_has_pow_nat [instance] [priority int.prio] : has_pow_nat int := +attribute [instance] [priority int.prio] +definition int_has_pow_nat : has_pow_nat int := has_pow_nat.mk has_pow_nat.pow_nat /- diff --git a/library/data/list/basic.lean b/library/data/list/basic.lean index 6ce47e4ff7..9d0fd8d68d 100644 --- a/library/data/list/basic.lean +++ b/library/data/list/basic.lean @@ -11,7 +11,8 @@ open nat function tactic namespace list variable {T : Type} -lemma cons_ne_nil [simp] (a : T) (l : list T) : a::l ≠ [] := +attribute [simp] +lemma cons_ne_nil (a : T) (l : list T) : a::l ≠ [] := sorry -- by contradiction lemma head_eq_of_cons_eq {A : Type} {h₁ h₂ : A} {t₁ t₂ : list A} : @@ -27,26 +28,33 @@ take l₁ l₂, assume Pe, tail_eq_of_cons_eq Pe /- append -/ -theorem append_nil_left [simp] (t : list T) : [] ++ t = t := +attribute [simp] +theorem append_nil_left (t : list T) : [] ++ t = t := rfl -theorem append_cons [simp] (x : T) (s t : list T) : (x::s) ++ t = x::(s ++ t) := +attribute [simp] +theorem append_cons (x : T) (s t : list T) : (x::s) ++ t = x::(s ++ t) := rfl -theorem append_nil_right [simp] : ∀ (t : list T), t ++ [] = t := +attribute [simp] +theorem append_nil_right : ∀ (t : list T), t ++ [] = t := sorry -- by rec_inst_simp -theorem append.assoc [simp] : ∀ (s t u : list T), s ++ t ++ u = s ++ (t ++ u) := +attribute [simp] +theorem append.assoc : ∀ (s t u : list T), s ++ t ++ u = s ++ (t ++ u) := sorry -- by rec_inst_simp /- length -/ -theorem length_nil [simp] : length (@nil T) = 0 := +attribute [simp] +theorem length_nil : length (@nil T) = 0 := rfl -theorem length_cons [simp] (x : T) (t : list T) : length (x::t) = length t + 1 := +attribute [simp] +theorem length_cons (x : T) (t : list T) : length (x::t) = length t + 1 := rfl -theorem length_append [simp] : ∀ (s t : list T), length (s ++ t) = length s + length t := +attribute [simp] +theorem length_append : ∀ (s t : list T), length (s ++ t) = length s + length t := sorry -- by rec_inst_simp theorem eq_nil_of_length_eq_zero : ∀ {l : list T}, length l = 0 → l = [] @@ -59,22 +67,28 @@ theorem ne_nil_of_length_eq_succ : ∀ {l : list T} {n : nat}, length l = succ n /- concat -/ -theorem concat_nil [simp] (x : T) : concat x [] = [x] := +attribute [simp] +theorem concat_nil (x : T) : concat x [] = [x] := rfl -theorem concat_cons [simp] (x y : T) (l : list T) : concat x (y::l) = y::(concat x l) := +attribute [simp] +theorem concat_cons (x y : T) (l : list T) : concat x (y::l) = y::(concat x l) := rfl -theorem concat_eq_append [simp] (a : T) : ∀ (l : list T), concat a l = l ++ [a] := +attribute [simp] +theorem concat_eq_append (a : T) : ∀ (l : list T), concat a l = l ++ [a] := sorry -- by rec_inst_simp -theorem concat_ne_nil [simp] (a : T) : ∀ (l : list T), concat a l ≠ [] := +attribute [simp] +theorem concat_ne_nil (a : T) : ∀ (l : list T), concat a l ≠ [] := sorry -- by intro l; induction l; repeat contradiction -theorem length_concat [simp] (a : T) : ∀ (l : list T), length (concat a l) = length l + 1 := +attribute [simp] +theorem length_concat (a : T) : ∀ (l : list T), length (concat a l) = length l + 1 := sorry -- by rec_inst_simp -theorem concat_append [simp] (a : T) : ∀ (l₁ l₂ : list T), concat a l₁ ++ l₂ = l₁ ++ a :: l₂ := +attribute [simp] +theorem concat_append (a : T) : ∀ (l₁ l₂ : list T), concat a l₁ ++ l₂ = l₁ ++ a :: l₂ := sorry -- by rec_inst_simp theorem append_concat (a : T) : ∀(l₁ l₂ : list T), l₁ ++ concat a l₂ = concat a (l₁ ++ l₂) := @@ -87,35 +101,43 @@ definition last : Π l : list T, l ≠ [] → T | [a] h := a | (a₁::a₂::l) h := last (a₂::l) $ cons_ne_nil a₂ l -lemma last_singleton [simp] (a : T) (h : [a] ≠ []) : last [a] h = a := +attribute [simp] +lemma last_singleton (a : T) (h : [a] ≠ []) : last [a] h = a := rfl -lemma last_cons_cons [simp] (a₁ a₂ : T) (l : list T) (h : a₁::a₂::l ≠ []) : last (a₁::a₂::l) h = last (a₂::l) (cons_ne_nil a₂ l) := +attribute [simp] +lemma last_cons_cons (a₁ a₂ : T) (l : list T) (h : a₁::a₂::l ≠ []) : last (a₁::a₂::l) h = last (a₂::l) (cons_ne_nil a₂ l) := rfl theorem last_congr {l₁ l₂ : list T} (h₁ : l₁ ≠ []) (h₂ : l₂ ≠ []) (h₃ : l₁ = l₂) : last l₁ h₁ = last l₂ h₂ := sorry -- by subst l₁ -theorem last_concat [simp] {x : T} : ∀ {l : list T} (h : concat x l ≠ []), last (concat x l) h = x := +attribute [simp] +theorem last_concat {x : T} : ∀ {l : list T} (h : concat x l ≠ []), last (concat x l) h = x := sorry -- by rec_simp -- add_rewrite append_nil append_cons /- reverse -/ -theorem reverse_nil [simp] : reverse (@nil T) = [] := +attribute [simp] +theorem reverse_nil : reverse (@nil T) = [] := rfl -theorem reverse_cons [simp] (x : T) (l : list T) : reverse (x::l) = concat x (reverse l) := +attribute [simp] +theorem reverse_cons (x : T) (l : list T) : reverse (x::l) = concat x (reverse l) := rfl -theorem reverse_singleton [simp] (x : T) : reverse [x] = [x] := +attribute [simp] +theorem reverse_singleton (x : T) : reverse [x] = [x] := rfl -theorem reverse_append [simp] : ∀ (s t : list T), reverse (s ++ t) = (reverse t) ++ (reverse s) := +attribute [simp] +theorem reverse_append : ∀ (s t : list T), reverse (s ++ t) = (reverse t) ++ (reverse s) := sorry -- by rec_inst_simp -theorem reverse_reverse [simp] : ∀ (l : list T), reverse (reverse l) = l := +attribute [simp] +theorem reverse_reverse : ∀ (l : list T), reverse (reverse l) = l := sorry -- by rec_inst_simp theorem concat_eq_reverse_cons (x : T) (l : list T) : concat x l = reverse (x :: reverse l) := @@ -126,16 +148,20 @@ sorry -- by rec_inst_simp /- head and tail -/ -theorem head_cons [simp] [h : inhabited T] (a : T) (l : list T) : head (a::l) = a := +attribute [simp] +theorem head_cons [h : inhabited T] (a : T) (l : list T) : head (a::l) = a := rfl -theorem head_append [simp] [h : inhabited T] (t : list T) : ∀ {s : list T}, s ≠ [] → head (s ++ t) = head s := +attribute [simp] +theorem head_append [h : inhabited T] (t : list T) : ∀ {s : list T}, s ≠ [] → head (s ++ t) = head s := sorry -- by rec_inst_simp -theorem tail_nil [simp] : tail (@nil T) = [] := +attribute [simp] +theorem tail_nil : tail (@nil T) = [] := rfl -theorem tail_cons [simp] (a : T) (l : list T) : tail (a::l) = l := +attribute [simp] +theorem tail_cons (a : T) (l : list T) : tail (a::l) = l := rfl theorem cons_head_tail [h : inhabited T] {l : list T} : l ≠ [] → (head l)::(tail l) = l := @@ -156,7 +182,8 @@ iff.rfl theorem not_mem_nil (x : T) : x ∉ [] := iff.mp $ mem_nil_iff x -theorem mem_cons [simp] (x : T) (l : list T) : x ∈ x :: l := +attribute [simp] +theorem mem_cons (x : T) (l : list T) : x ∈ x :: l := or.inl rfl theorem mem_cons_of_mem (y : T) {x : T} {l : list T} : x ∈ l → x ∈ y :: l := @@ -256,7 +283,8 @@ assume ainl₁, mem_append_of_mem_or_mem (or.inl ainl₁) theorem mem_append_right {a : T} (l₁ : list T) {l₂ : list T} : a ∈ l₂ → a ∈ l₁ ++ l₂ := assume ainl₂, mem_append_of_mem_or_mem (or.inr ainl₂) -definition decidable_mem [instance] [H : decidable_eq T] (x : T) (l : list T) : decidable (x ∈ l) := +attribute [instance] +definition decidable_mem [H : decidable_eq T] (x : T) (l : list T) : decidable (x ∈ l) := list.rec_on l (decidable.ff (not_of_iff_false (mem_nil_iff _))) (take (h : T) (l : list T) (iH : decidable (x ∈ l)), @@ -299,16 +327,19 @@ definition sublist (l₁ l₂ : list T) := ∀ ⦃a : T⦄, a ∈ l₁ → a ∈ infix ⊆ := sublist -theorem nil_sub [simp] (l : list T) : [] ⊆ l := +attribute [simp] +theorem nil_sub (l : list T) : [] ⊆ l := λ b i, false.elim (iff.mp (mem_nil_iff b) i) -theorem sub.refl [simp] (l : list T) : l ⊆ l := +attribute [simp] +theorem sub.refl (l : list T) : l ⊆ l := λ b i, i theorem sub.trans {l₁ l₂ l₃ : list T} (H₁ : l₁ ⊆ l₂) (H₂ : l₂ ⊆ l₃) : l₁ ⊆ l₃ := λ b i, H₂ (H₁ i) -theorem sub_cons [simp] (a : T) (l : list T) : l ⊆ a::l := +attribute [simp] +theorem sub_cons (a : T) (l : list T) : l ⊆ a::l := λ b i, or.inr i theorem sub_of_cons_sub {a : T} {l₁ l₂ : list T} : a::l₁ ⊆ l₂ → l₁ ⊆ l₂ := @@ -319,10 +350,12 @@ theorem cons_sub_cons {l₁ l₂ : list T} (a : T) (s : l₁ ⊆ l₂) : (a::l (λ e : b = a, or.inl e) (λ i : b ∈ l₁, or.inr (s i)) -theorem sub_append_left [simp] (l₁ l₂ : list T) : l₁ ⊆ l₁++l₂ := +attribute [simp] +theorem sub_append_left (l₁ l₂ : list T) : l₁ ⊆ l₁++l₂ := λ b i, iff.mpr (mem_append_iff b l₁ l₂) (or.inl i) -theorem sub_append_right [simp] (l₁ l₂ : list T) : l₂ ⊆ l₁++l₂ := +attribute [simp] +theorem sub_append_right (l₁ l₂ : list T) : l₂ ⊆ l₁++l₂ := λ b i, iff.mpr (mem_append_iff b l₁ l₂) (or.inr i) theorem sub_cons_of_sub (a : T) {l₁ l₂ : list T} : l₁ ⊆ l₂ → l₁ ⊆ (a::l₂) := @@ -361,7 +394,8 @@ definition find : T → list T → nat | a [] := 0 | a (b :: l) := if a = b then 0 else succ (find a l) -theorem find_nil [simp] (x : T) : find x [] = 0 := +attribute [simp] +theorem find_nil (x : T) : find x [] = 0 := rfl theorem find_cons (x y : T) (l : list T) : find x (y::l) = if x = y then 0 else succ (find x l) := @@ -431,10 +465,12 @@ end /- nth element -/ section nth -theorem nth_zero [simp] (a : T) (l : list T) : nth (a :: l) 0 = some a := +attribute [simp] +theorem nth_zero (a : T) (l : list T) : nth (a :: l) 0 = some a := rfl -theorem nth_succ [simp] (a : T) (l : list T) (n : nat) : nth (a::l) (succ n) = nth l n := +attribute [simp] +theorem nth_succ (a : T) (l : list T) (n : nat) : nth (a::l) (succ n) = nth l n := rfl theorem nth_eq_some : ∀ {l : list T} {n : nat}, n < length l → Σ a : T, nth l n = some a @@ -480,10 +516,12 @@ definition ith : Π (l : list T) (i : nat), i < length l → T | (x::xs) 0 h := x | (x::xs) (succ i) h := ith xs i (lt_of_succ_lt_succ h) -lemma ith_zero [simp] (a : T) (l : list T) (h : 0 < length (a::l)) : ith (a::l) 0 h = a := +attribute [simp] +lemma ith_zero (a : T) (l : list T) (h : 0 < length (a::l)) : ith (a::l) 0 h = a := rfl -lemma ith_succ [simp] (a : T) (l : list T) (i : nat) (h : succ i < length (a::l)) +attribute [simp] +lemma ith_succ (a : T) (l : list T) (i : nat) (h : succ i < length (a::l)) : ith (a::l) (succ i) h = ith l i (lt_of_succ_lt_succ h) := rfl end ith @@ -590,10 +628,12 @@ definition firstn : nat → list A → list A | (n+1) [] := [] | (n+1) (a::l) := a :: firstn n l -lemma firstn_zero [simp] : ∀ (l : list A), firstn 0 l = [] := +attribute [simp] +lemma firstn_zero : ∀ (l : list A), firstn 0 l = [] := sorry -- by intros; reflexivity -lemma firstn_nil [simp] : ∀ n, firstn n [] = ([] : list A) +attribute [simp] +lemma firstn_nil : ∀ n, firstn n [] = ([] : list A) | 0 := rfl | (n+1) := rfl diff --git a/library/data/list/comb.lean b/library/data/list/comb.lean index c91f348f16..2ead2aa322 100644 --- a/library/data/list/comb.lean +++ b/library/data/list/comb.lean @@ -45,7 +45,8 @@ lemma map_reverse (f : A → B) : Πl, map f (reverse l) = reverse (map f l) lemma map_singleton (f : A → B) (a : A) : map f [a] = [f a] := rfl -theorem map_id [simp] : ∀ l : list A, map id l = l +attribute [simp] +theorem map_id : ∀ l : list A, map id l = l | [] := rfl | (x::xs) := sorry -- begin rewrite [map_cons, map_id] end @@ -53,13 +54,15 @@ theorem map_id' {f : A → A} (H : ∀x, f x = x) : ∀ l : list A, map f l = l | [] := rfl | (x::xs) := sorry -- begin rewrite [map_cons, H, map_id'] end -theorem map_map [simp] (g : B → C) (f : A → B) : ∀ l, map g (map f l) = map (g ∘ f) l +attribute [simp] +theorem map_map (g : B → C) (f : A → B) : ∀ l, map g (map f l) = map (g ∘ f) l | [] := rfl | (a :: l) := show (g ∘ f) a :: map g (map f l) = map (g ∘ f) (a :: l), from sorry -- by rewrite (map_map l) -theorem length_map [simp] (f : A → B) : ∀ l : list A, length (map f l) = length l +attribute [simp] +theorem length_map (f : A → B) : ∀ l : list A, length (map f l) = length l | [] := sorry -- by esimp | (a :: l) := show length (map f l) + 1 = length l + 1, @@ -132,12 +135,15 @@ theorem length_map₂ : ∀(f : A → B → C) x y, length (map₂ f x y) = min ... = min (length (xh::xr)) (length (yh::yr)) : rfl /- filter -/ -theorem filter_nil [simp] (p : A → Prop) [h : decidable_pred p] : filter p [] = [] := rfl +attribute [simp] +theorem filter_nil (p : A → Prop) [h : decidable_pred p] : filter p [] = [] := rfl -theorem filter_cons_of_pos [simp] {p : A → Prop} [h : decidable_pred p] {a : A} : ∀ l, p a → filter p (a::l) = a :: filter p l := +attribute [simp] +theorem filter_cons_of_pos {p : A → Prop} [h : decidable_pred p] {a : A} : ∀ l, p a → filter p (a::l) = a :: filter p l := λ l pa, if_pos pa -theorem filter_cons_of_neg [simp] {p : A → Prop} [h : decidable_pred p] {a : A} : ∀ l, ¬ p a → filter p (a::l) = filter p l := +attribute [simp] +theorem filter_cons_of_neg {p : A → Prop} [h : decidable_pred p] {a : A} : ∀ l, ¬ p a → filter p (a::l) = filter p l := λ l pa, if_neg pa theorem of_mem_filter {p : A → Prop} [h : decidable_pred p] {a : A} : ∀ {l}, a ∈ filter p l → p a @@ -181,7 +187,8 @@ theorem mem_filter_of_mem {p : A → Prop} [h : decidable_pred p] {a : A} : ∀ (λ ainl : a ∈ l, by rewrite [filter_cons_of_neg _ npb]; exact (mem_filter_of_mem ainl pa))) -/ -theorem filter_sub [simp] {p : A → Prop} [h : decidable_pred p] (l : list A) : filter p l ⊆ l := +attribute [simp] +theorem filter_sub {p : A → Prop} [h : decidable_pred p] (l : list A) : filter p l ⊆ l := λ a ain, mem_of_mem_filter ain theorem filter_append {p : A → Prop} [h : decidable_pred p] : ∀ (l₁ l₂ : list A), filter p (l₁++l₂) = filter p l₁ ++ filter p l₂ @@ -198,17 +205,21 @@ definition foldl (f : A → B → A) : A → list B → A | a [] := a | a (b :: l) := foldl (f a b) l -theorem foldl_nil [simp] (f : A → B → A) (a : A) : foldl f a [] = a := rfl +attribute [simp] +theorem foldl_nil (f : A → B → A) (a : A) : foldl f a [] = a := rfl -theorem foldl_cons [simp] (f : A → B → A) (a : A) (b : B) (l : list B) : foldl f a (b::l) = foldl f (f a b) l := rfl +attribute [simp] +theorem foldl_cons (f : A → B → A) (a : A) (b : B) (l : list B) : foldl f a (b::l) = foldl f (f a b) l := rfl definition foldr (f : A → B → B) : B → list A → B | b [] := b | b (a :: l) := f a (foldr b l) -theorem foldr_nil [simp] (f : A → B → B) (b : B) : foldr f b [] = b := rfl +attribute [simp] +theorem foldr_nil (f : A → B → B) (b : B) : foldr f b [] = b := rfl -theorem foldr_cons [simp] (f : A → B → B) (b : B) (a : A) (l : list A) : foldr f b (a::l) = f a (foldr f b l) := rfl +attribute [simp] +theorem foldr_cons (f : A → B → B) (b : B) (a : A) (l : list A) : foldr f b (a::l) = f a (foldr f b l) := rfl section foldl_eq_foldr -- foldl and foldr coincide when f is commutative and associative @@ -246,11 +257,13 @@ section foldl_eq_foldr end foldl_eq_foldr -theorem foldl_append [simp] (f : B → A → B) : ∀ (b : B) (l₁ l₂ : list A), foldl f b (l₁++l₂) = foldl f (foldl f b l₁) l₂ +attribute [simp] +theorem foldl_append (f : B → A → B) : ∀ (b : B) (l₁ l₂ : list A), foldl f b (l₁++l₂) = foldl f (foldl f b l₁) l₂ | b [] l₂ := rfl | b (a::l₁) l₂ := sorry -- by rewrite [append_cons, *foldl_cons, foldl_append] -theorem foldr_append [simp] (f : A → B → B) : ∀ (b : B) (l₁ l₂ : list A), foldr f b (l₁++l₂) = foldr f (foldr f b l₂) l₁ +attribute [simp] +theorem foldr_append (f : A → B → B) : ∀ (b : B) (l₁ l₂ : list A), foldr f b (l₁++l₂) = foldr f (foldr f b l₂) l₁ | b [] l₂ := rfl | b (a::l₁) l₂ := sorry -- by rewrite [append_cons, *foldr_cons, foldr_append] @@ -261,7 +274,8 @@ foldr (λ a r, p a ∧ r) true l definition any (l : list A) (p : A → Prop) : Prop := foldr (λ a r, p a ∨ r) false l -theorem all_nil_eq [simp] (p : A → Prop) : all [] p = true := rfl +attribute [simp] +theorem all_nil_eq (p : A → Prop) : all [] p = true := rfl theorem all_nil (p : A → Prop) : all [] p := trivial @@ -304,9 +318,11 @@ theorem all_of_forall {p : A → Prop} : ∀ {l}, (∀a, a ∈ l → p a) → al | (a::l) H := all_cons (H a (mem_cons a l)) (all_of_forall (λ a' H', H a' (mem_cons_of_mem _ H'))) -theorem any_nil [simp] (p : A → Prop) : any [] p = false := rfl +attribute [simp] +theorem any_nil (p : A → Prop) : any [] p = false := rfl -theorem any_cons [simp] (p : A → Prop) (a : A) (l : list A) : any (a::l) p = (p a ∨ any l p) := rfl +attribute [simp] +theorem any_cons (p : A → Prop) (a : A) (l : list A) : any (a::l) p = (p a ∨ any l p) := rfl theorem any_of_mem {p : A → Prop} {a : A} : ∀ {l}, a ∈ l → p a → any l p := sorry @@ -366,9 +382,11 @@ definition unzip : list (A × B) → list A × list B | (la, lb) := (a :: la, b :: lb) end -theorem unzip_nil [simp] : unzip (@nil (A × B)) = ([], []) := rfl +attribute [simp] +theorem unzip_nil : unzip (@nil (A × B)) = ([], []) := rfl -theorem unzip_cons [simp] (a : A) (b : B) (l : list (A × B)) : +attribute [simp] +theorem unzip_cons (a : A) (b : B) (l : list (A × B)) : unzip ((a, b) :: l) = match (unzip l) with (la, lb) := (a :: la, b :: lb) end := rfl diff --git a/library/data/list/perm.lean b/library/data/list/perm.lean index c73a80b50b..0d13540ac5 100644 --- a/library/data/list/perm.lean +++ b/library/data/list/perm.lean @@ -47,11 +47,13 @@ have gen : ∀ (l₁ l₂ : list A) (p : l₁ ~ l₂), l₁ = [] → l₂ = (x:: assume p, gen [] (x::l) p rfl rfl -/ -protected theorem refl [refl] : ∀ (l : list A), l ~ l +attribute [refl] +protected theorem refl : ∀ (l : list A), l ~ l | [] := nil | (x::xs) := skip x (refl xs) -protected theorem symm [symm] : ∀ {l₁ l₂ : list A}, l₁ ~ l₂ → l₂ ~ l₁ := +attribute [symm] +protected theorem symm : ∀ {l₁ l₂ : list A}, l₁ ~ l₂ → l₂ ~ l₁ := take l₁ l₂ p, perm.induction_on p nil (λ x l₁ l₂ p₁ r₁, skip x r₁) @@ -63,7 +65,8 @@ attribute perm.trans [trans] theorem eqv (A : Type) : equivalence (@perm A) := mk_equivalence (@perm A) (@perm.refl A) (@perm.symm A) (@perm.trans A) -protected definition is_setoid [instance] (A : Type) : setoid (list A) := +attribute [instance] +protected definition is_setoid (A : Type) : setoid (list A) := setoid.mk (@perm A) (perm.eqv A) theorem mem_perm {a : A} {l₁ l₂ : list A} : l₁ ~ l₂ → a ∈ l₁ → a ∈ l₂ := @@ -109,10 +112,12 @@ theorem perm_cons_app (a : A) : ∀ (l : list A), (a::l) ~ (l ++ [a]) a::x::xs ~ x::a::xs : swap x a xs ... ~ x::(xs++[a]) : skip x (perm_cons_app xs) -theorem perm_cons_app_simp [simp] (a : A) : ∀ (l : list A), (l ++ [a]) ~ (a::l) := +attribute [simp] +theorem perm_cons_app_simp (a : A) : ∀ (l : list A), (l ++ [a]) ~ (a::l) := take l, perm.symm (perm_cons_app a l) -theorem perm_app_comm [simp] {l₁ l₂ : list A} : (l₁++l₂) ~ (l₂++l₁) := +attribute [simp] +theorem perm_app_comm {l₁ l₂ : list A} : (l₁++l₂) ~ (l₂++l₁) := sorry /- list.induction_on l₁ @@ -172,7 +177,8 @@ theorem perm_rev : ∀ (l : list A), l ~ (reverse l) ... = reverse (x::xs) : by rewrite [reverse_cons, concat_eq_append] -/ -theorem perm_rev_simp [simp] : ∀ (l : list A), (reverse l) ~ l := +attribute [simp] +theorem perm_rev_simp : ∀ (l : list A), (reverse l) ~ l := take l, perm.symm (perm_rev l) theorem perm_middle (a : A) (l₁ l₂ : list A) : (a::l₁)++l₂ ~ l₁++(a::l₂) := @@ -182,7 +188,8 @@ calc ... = l₁++(l₂++[a]) : append.assoc l₁ l₂ [a] ... ~ l₁++(a::l₂) : perm_app_right l₁ (perm.symm (perm_cons_app a l₂)) -theorem perm_middle_simp [simp] (a : A) (l₁ l₂ : list A) : l₁++(a::l₂) ~ (a::l₁)++l₂ := +attribute [simp] +theorem perm_middle_simp (a : A) (l₁ l₂ : list A) : l₁++(a::l₂) ~ (a::l₁)++l₂ := perm.symm $ perm_middle a l₁ l₂ theorem perm_cons_app_cons {l l₁ l₂ : list A} (a : A) : l ~ l₁++l₂ → a::l ~ l₁++(a::l₂) := @@ -208,7 +215,8 @@ theorem perm_erase [decidable_eq A] {a : A} : ∀ {l : list A}, a ∈ l → l ~ ... = a::(erase a (x::t)) : by rewrite [!erase_cons_tail naeqx]) -/ -theorem erase_perm_erase_of_perm [congr] [decidable_eq A] (a : A) {l₁ l₂ : list A} : l₁ ~ l₂ → erase a l₁ ~ erase a l₂ := +attribute [congr] +theorem erase_perm_erase_of_perm [decidable_eq A] (a : A) {l₁ l₂ : list A} : l₁ ~ l₂ → erase a l₁ ~ erase a l₂ := sorry /- assume p, perm.induction_on p @@ -247,7 +255,8 @@ assume p, calc x::y::l₁ ~ y::x::l₁ : swap y x l₁ ... ~ y::x::l₂ : skip y (skip x p) -theorem perm_map [congr] (f : A → B) {l₁ l₂ : list A} : l₁ ~ l₂ → map f l₁ ~ map f l₂ := +attribute [congr] +theorem perm_map (f : A → B) {l₁ l₂ : list A} : l₁ ~ l₂ → map f l₁ ~ map f l₂ := assume p, perm_induction_on p nil (λ x l₁ l₂ p r, skip (f x) r) @@ -294,7 +303,8 @@ definition decidable_perm_aux : ∀ (n : nat) (l₁ l₂ : list A), length l₁ inr (λ p : x::t₁ ~ l₂, absurd (mem_perm p !mem_cons) nxinl₂)) -/ -definition decidable_perm [instance] : ∀ (l₁ l₂ : list A), decidable (l₁ ~ l₂) := +attribute [instance] +definition decidable_perm : ∀ (l₁ l₂ : list A), decidable (l₁ ~ l₂) := λ l₁ l₂, by_cases (assume eql : length l₁ = length l₂, @@ -563,7 +573,8 @@ section foldr -/ end foldr -theorem perm_erase_dup_of_perm [congr] [H : decidable_eq A] {l₁ l₂ : list A} : l₁ ~ l₂ → erase_dup l₁ ~ erase_dup l₂ := +attribute [congr] +theorem perm_erase_dup_of_perm [H : decidable_eq A] {l₁ l₂ : list A} : l₁ ~ l₂ → erase_dup l₁ ~ erase_dup l₂ := sorry /- assume p, perm_induction_on p @@ -686,7 +697,8 @@ list.induction_on l by rewrite [union_cons_of_not_mem _ nxint₁, union_cons_of_not_mem _ nxint₂]; exact (skip _ (r p)))) -/ -theorem perm_union [congr] {l₁ l₂ t₁ t₂ : list A} : l₁ ~ l₂ → t₁ ~ t₂ → (union l₁ t₁) ~ (union l₂ t₂) := +attribute [congr] +theorem perm_union {l₁ l₂ t₁ t₂ : list A} : l₁ ~ l₂ → t₁ ~ t₂ → (union l₁ t₁) ~ (union l₂ t₂) := assume p₁ p₂, trans (perm_union_left t₁ p₁) (perm_union_right l₂ p₂) end perm_union @@ -694,7 +706,8 @@ section perm_insert variable [H : decidable_eq A] include H -theorem perm_insert [congr] (a : A) {l₁ l₂ : list A} : l₁ ~ l₂ → (insert a l₁) ~ (insert a l₂) := +attribute [congr] +theorem perm_insert (a : A) {l₁ l₂ : list A} : l₁ ~ l₂ → (insert a l₁) ~ (insert a l₂) := sorry /- assume p, by_cases @@ -748,7 +761,8 @@ list.induction_on l have nxint₂ : x ∉ t₂, from not_mem_perm p nxint₁, by rewrite [inter_cons_of_not_mem _ nxint₁, inter_cons_of_not_mem _ nxint₂]; exact (r p))) -/ -theorem perm_inter [congr] {l₁ l₂ t₁ t₂ : list A} : l₁ ~ l₂ → t₁ ~ t₂ → (inter l₁ t₁) ~ (inter l₂ t₂) := +attribute [congr] +theorem perm_inter {l₁ l₂ t₁ t₂ : list A} : l₁ ~ l₂ → t₁ ~ t₂ → (inter l₁ t₁) ~ (inter l₂ t₂) := assume p₁ p₂, trans (perm_inter_left t₁ p₁) (perm_inter_right l₂ p₂) end perm_inter @@ -856,12 +870,14 @@ list.induction_on l perm_app (perm_map _ p) (r p)) -/ -theorem perm_product [congr] {l₁ l₂ : list A} {t₁ t₂ : list B} : l₁ ~ l₂ → t₁ ~ t₂ → (product l₁ t₁) ~ (product l₂ t₂) := +attribute [congr] +theorem perm_product {l₁ l₂ : list A} {t₁ t₂ : list B} : l₁ ~ l₂ → t₁ ~ t₂ → (product l₁ t₁) ~ (product l₂ t₂) := assume p₁ p₂, trans (perm_product_left t₁ p₁) (perm_product_right l₂ p₂) end product /- filter -/ -theorem perm_filter [congr] {l₁ l₂ : list A} {p : A → Prop} [decidable_pred p] : +attribute [congr] +theorem perm_filter {l₁ l₂ : list A} {p : A → Prop} [decidable_pred p] : l₁ ~ l₂ → (filter p l₁) ~ (filter p l₂) := sorry /- diff --git a/library/data/list/set.lean b/library/data/list/set.lean index f686f7e1d4..f0755c6612 100644 --- a/library/data/list/set.lean +++ b/library/data/list/set.lean @@ -426,7 +426,8 @@ theorem erase_dup_eq_of_nodup [decidable_eq A] : ∀ {l : list A}, nodup l → e have dl : nodup l, from nodup_of_nodup_cons d, sorry -- by rewrite [erase_dup_cons_of_not_mem nainl, erase_dup_eq_of_nodup dl] -definition decidable_nodup [instance] [decidable_eq A] : ∀ (l : list A), decidable (nodup l) +attribute [instance] +definition decidable_nodup [decidable_eq A] : ∀ (l : list A), decidable (nodup l) | [] := tt nodup_nil | (a::l) := match (decidable_mem a l) with diff --git a/library/data/matrix.lean b/library/data/matrix.lean index b71de4fc67..a24219638e 100644 --- a/library/data/matrix.lean +++ b/library/data/matrix.lean @@ -8,12 +8,14 @@ Matrices import algebra.ring data.fin data.fintype open fin nat -definition matrix [reducible] (A : Type) (m n : nat) := fin m → fin n → A +attribute [reducible] +definition matrix (A : Type) (m n : nat) := fin m → fin n → A namespace matrix variables {A B C : Type} {m n p : nat} -definition val [reducible] (M : matrix A m n) (i : fin m) (j : fin n) : A := +attribute [reducible] +definition val (M : matrix A m n) (i : fin m) (j : fin n) : A := M i j namespace ops @@ -68,16 +70,20 @@ protected definition mul (M : matrix A m n) (N : matrix A n p) : matrix A m p := definition smul (a : A) (M : matrix A m n) : matrix A m n := λ i j, a * M[i, j] -definition matrix_has_zero [instance] (m n : nat) : has_zero (matrix A m n) := +attribute [instance] +definition matrix_has_zero (m n : nat) : has_zero (matrix A m n) := has_zero.mk (matrix.zero m n) -definition matrix_has_one [instance] (n : nat) : has_one (matrix A n n) := +attribute [instance] +definition matrix_has_one (n : nat) : has_one (matrix A n n) := has_one.mk (identity n) -definition matrix_has_add [instance] (m n : nat) : has_add (matrix A m n) := +attribute [instance] +definition matrix_has_add (m n : nat) : has_add (matrix A m n) := has_add.mk matrix.add -definition matrix_has_mul [instance] (n : nat) : has_mul (matrix A n n) := +attribute [instance] +definition matrix_has_mul (n : nat) : has_mul (matrix A n n) := has_mul.mk matrix.mul infix ` × ` := mul diff --git a/library/data/nat/basic.lean b/library/data/nat/basic.lean index e5a3829beb..7a1621589c 100644 --- a/library/data/nat/basic.lean +++ b/library/data/nat/basic.lean @@ -44,18 +44,22 @@ nat.induction_on x /- successor and predecessor -/ -theorem succ_ne_zero [simp] (n : ℕ) : succ n ≠ 0 := +attribute [simp] +theorem succ_ne_zero (n : ℕ) : succ n ≠ 0 := sorry -- by contradiction -theorem add_one_ne_zero [simp] (n : ℕ) : n + 1 ≠ 0 := +attribute [simp] +theorem add_one_ne_zero (n : ℕ) : n + 1 ≠ 0 := sorry -- by contradiction -- add_rewrite succ_ne_zero -theorem pred_zero [simp] : pred 0 = 0 := +attribute [simp] +theorem pred_zero : pred 0 = 0 := rfl -theorem pred_succ [simp] (n : ℕ) : pred (succ n) = n := +attribute [simp] +theorem pred_succ (n : ℕ) : pred (succ n) = n := rfl theorem eq_zero_or_eq_succ_pred (n : ℕ) : n = 0 ∨ n = succ (pred n) := @@ -252,7 +256,8 @@ nat.cases_on n (by simp) !succ_ne_zero)) -/ -protected definition comm_semiring [instance] : comm_semiring nat := +attribute [instance] +protected definition comm_semiring : comm_semiring nat := ⦃comm_semiring, add := nat.add, add_assoc := nat.add_assoc, diff --git a/library/data/nat/bquant.lean b/library/data/nat/bquant.lean index dacb4812e7..a15ffe5d09 100644 --- a/library/data/nat/bquant.lean +++ b/library/data/nat/bquant.lean @@ -19,13 +19,16 @@ import data.nat.order data.nat.div namespace nat open subtype - definition bex [reducible] (n : nat) (P : nat → Prop) : Prop := + attribute [reducible] + definition bex (n : nat) (P : nat → Prop) : Prop := ∃ x, x < n ∧ P x - definition bsub [reducible] (n : nat) (P : nat → Prop) : Type₁ := + attribute [reducible] + definition bsub (n : nat) (P : nat → Prop) : Type₁ := {x \ x < n ∧ P x} - definition ball [reducible] (n : nat) (P : nat → Prop) : Prop := + attribute [reducible] + definition ball (n : nat) (P : nat → Prop) : Prop := ∀ x, x < n → P x lemma bex_of_bsub {n : nat} {P : nat → Prop} : bsub n P → bex n P := @@ -90,7 +93,8 @@ end nat section open nat decidable - definition decidable_bex [instance] (n : nat) (P : nat → Prop) [H : decidable_pred P] : decidable (bex n P) := + attribute [instance] + definition decidable_bex (n : nat) (P : nat → Prop) [H : decidable_pred P] : decidable (bex n P) := nat.rec_on n (ff (not_bex_zero P)) (λ a ih, decidable.rec_on ih @@ -99,7 +103,8 @@ section (λ hpa : P a, tt (bex_succ_of_pred hpa))) (λ hpos : bex a P, tt (bex_succ hpos))) - definition decidable_ball [instance] (n : nat) (P : nat → Prop) [H : decidable_pred P] : decidable (ball n P) := + attribute [instance] + definition decidable_ball (n : nat) (P : nat → Prop) [H : decidable_pred P] : decidable (ball n P) := nat.rec_on n (tt (ball_zero P)) (λ n₁ ih, decidable.rec_on ih @@ -108,13 +113,15 @@ section (λ p_neg, ff (not_ball_of_not p_neg)) (λ p_pos, tt (ball_succ_of_ball ih_pos p_pos)))) - definition decidable_bex_le [instance] (n : nat) (P : nat → Prop) [decidable_pred P] + attribute [instance] + definition decidable_bex_le (n : nat) (P : nat → Prop) [decidable_pred P] : decidable (∃ x, x ≤ n ∧ P x) := decidable_of_decidable_of_iff (decidable_bex (succ n) P) (exists_congr (λn', and_congr (lt_succ_iff_le n' n) (iff.refl (P n')))) - definition decidable_ball_le [instance] (n : nat) (P : nat → Prop) [decidable_pred P] + attribute [instance] + definition decidable_ball_le (n : nat) (P : nat → Prop) [decidable_pred P] : decidable (∀ x, x ≤ n → P x) := decidable_of_decidable_of_iff (decidable_ball (succ n) P) diff --git a/library/data/nat/div.lean b/library/data/nat/div.lean index 4ad5b5be25..7b5fb1c3ce 100644 --- a/library/data/nat/div.lean +++ b/library/data/nat/div.lean @@ -29,13 +29,15 @@ local attribute [instance] nat_has_divide theorem div_def (x y : nat) : div x y = if 0 < y ∧ y ≤ x then div (x - y) y + 1 else 0 := congr_fun (fix_eq lt_wf div.F x) y -protected theorem div_zero [simp] (a : ℕ) : a / 0 = 0 := +attribute [simp] +protected theorem div_zero (a : ℕ) : a / 0 = 0 := eq.trans (div_def a 0) $ if_neg (not_and_of_not_left (0 ≤ a) (lt.irrefl 0)) theorem div_eq_zero_of_lt {a b : ℕ} (h : a < b) : a / b = 0 := eq.trans (div_def a b) $ if_neg (not_and_of_not_right (0 < b) (not_le_of_gt h)) -protected theorem zero_div [simp] (b : ℕ) : 0 / b = 0 := +attribute [simp] +protected theorem zero_div (b : ℕ) : 0 / b = 0 := eq.trans (div_def 0 b) $ if_neg (and.rec not_le_of_gt) theorem div_eq_succ_sub_div {a b : ℕ} (h₁ : b > 0) (h₂ : a ≥ b) : a / b = succ ((a - b) / b) := @@ -99,19 +101,22 @@ notation [priority nat.prio] a ≡ b `[mod `:0 c:0 `]` := a % c = b % c theorem mod_def (x y : nat) : mod x y = if 0 < y ∧ y ≤ x then mod (x - y) y else x := congr_fun (fix_eq lt_wf mod.F x) y -theorem mod_zero [simp] (a : ℕ) : a % 0 = a := +attribute [simp] +theorem mod_zero (a : ℕ) : a % 0 = a := eq.trans (mod_def a 0) $ if_neg (not_and_of_not_left (0 ≤ a) (lt.irrefl 0)) theorem mod_eq_of_lt {a b : ℕ} (h : a < b) : a % b = a := eq.trans (mod_def a b) $ if_neg (not_and_of_not_right (0 < b) (not_le_of_gt h)) -theorem zero_mod [simp] (b : ℕ) : 0 % b = 0 := +attribute [simp] +theorem zero_mod (b : ℕ) : 0 % b = 0 := eq.trans (mod_def 0 b) $ if_neg (λ h, and.rec_on h (λ l r, absurd (lt_of_lt_of_le l r) (lt.irrefl 0))) theorem mod_eq_sub_mod {a b : ℕ} (h₁ : b > 0) (h₂ : a ≥ b) : a % b = (a - b) % b := eq.trans (mod_def a b) $ if_pos (and.intro h₁ h₂) -theorem add_mod_self [simp] (x z : ℕ) : (x + z) % z = x % z := +attribute [simp] +theorem add_mod_self (x z : ℕ) : (x + z) % z = x % z := sorry /- by_cases_zero_pos z @@ -123,25 +128,30 @@ by_cases_zero_pos z ... = x % z : by rewrite nat.add_sub_cancel) -/ -theorem add_mod_self_left [simp] (x z : ℕ) : (x + z) % x = z % x := +attribute [simp] +theorem add_mod_self_left (x z : ℕ) : (x + z) % x = z % x := add.comm z x ▸ add_mod_self z x local attribute succ_mul [simp] -theorem add_mul_mod_self [simp] (x y z : ℕ) : (x + y * z) % z = x % z := +attribute [simp] +theorem add_mul_mod_self (x y z : ℕ) : (x + y * z) % z = x % z := sorry -- nat.induction_on y (by simp) (by inst_simp) -theorem add_mul_mod_self_left [simp] (x y z : ℕ) : (x + y * z) % y = x % y := +attribute [simp] +theorem add_mul_mod_self_left (x y z : ℕ) : (x + y * z) % y = x % y := sorry -- by inst_simp -theorem mul_mod_left [simp] (m n : ℕ) : (m * n) % n = 0 := +attribute [simp] +theorem mul_mod_left (m n : ℕ) : (m * n) % n = 0 := sorry /- calc (m * n) % n = (0 + m * n) % n : by simp ... = 0 : by inst_simp -/ -theorem mul_mod_right [simp] (m n : ℕ) : (m * n) % m = 0 := +attribute [simp] +theorem mul_mod_right (m n : ℕ) : (m * n) % m = 0 := sorry -- by inst_simp theorem mod_lt (x : ℕ) {y : ℕ} (H : y > 0) : x % y < y := diff --git a/library/data/nat/gcd.lean b/library/data/nat/gcd.lean index 9a5a4986bf..c7e10c5a0d 100644 --- a/library/data/nat/gcd.lean +++ b/library/data/nat/gcd.lean @@ -27,9 +27,11 @@ definition gcd.F : Π (p₁ : nat × nat), (Π p₂ : nat × nat, p₂ ≺ p₁ definition gcd (x y : nat) := fix pair_nat.lt.wf gcd.F (x, y) -theorem gcd_zero_right [simp] (x : nat) : gcd x 0 = x := rfl +attribute [simp] +theorem gcd_zero_right (x : nat) : gcd x 0 = x := rfl -theorem gcd_succ [simp] (x y : nat) : gcd x (succ y) = gcd (succ y) (x % succ y) := +attribute [simp] +theorem gcd_succ (x y : nat) : gcd x (succ y) = gcd (succ y) (x % succ y) := well_founded.fix_eq pair_nat.lt.wf gcd.F (x, succ y) theorem gcd_one_right (n : ℕ) : gcd n 1 = 1 := @@ -280,7 +282,8 @@ dvd.antisymm /- coprime -/ -definition coprime [reducible] (m n : ℕ) : Prop := gcd m n = 1 +attribute [reducible] +definition coprime (m n : ℕ) : Prop := gcd m n = 1 lemma gcd_eq_one_of_coprime {m n : ℕ} : coprime m n → gcd m n = 1 := λ h, h diff --git a/library/data/nat/order.lean b/library/data/nat/order.lean index a311578ddd..b6ce71d681 100644 --- a/library/data/nat/order.lean +++ b/library/data/nat/order.lean @@ -92,7 +92,8 @@ mul.comm k m ▸ mul.comm k n ▸ nat.mul_lt_mul_of_pos_left H Hk /- nat is an instance of a linearly ordered semiring and a lattice -/ -protected definition decidable_linear_ordered_semiring [instance] : +attribute [instance] +protected definition decidable_linear_ordered_semiring : decidable_linear_ordered_semiring nat := ⦃ decidable_linear_ordered_semiring, nat.comm_semiring, add_left_cancel := @nat.add_left_cancel, @@ -119,7 +120,8 @@ decidable_linear_ordered_semiring nat := mul_lt_mul_of_pos_right := @nat.mul_lt_mul_of_pos_right, decidable_lt := nat.decidable_lt ⦄ -definition nat_has_dvd [instance] [priority nat.prio] : has_dvd nat := +attribute [instance] [priority nat.prio] +definition nat_has_dvd : has_dvd nat := has_dvd.mk has_dvd.dvd theorem add_pos_left {a : ℕ} (H : 0 < a) (b : ℕ) : 0 < a + b := @@ -414,19 +416,24 @@ dvd.elim H /- min and max -/ open decidable -theorem min_zero [simp] (a : ℕ) : min a 0 = 0 := +attribute [simp] +theorem min_zero (a : ℕ) : min a 0 = 0 := sorry -- by rewrite [min_eq_right !zero_le] -theorem zero_min [simp] (a : ℕ) : min 0 a = 0 := +attribute [simp] +theorem zero_min (a : ℕ) : min 0 a = 0 := sorry -- by rewrite [min_eq_left !zero_le] -theorem max_zero [simp] (a : ℕ) : max a 0 = a := +attribute [simp] +theorem max_zero (a : ℕ) : max a 0 = a := sorry -- by rewrite [max_eq_left !zero_le] -theorem zero_max [simp] (a : ℕ) : max 0 a = a := +attribute [simp] +theorem zero_max (a : ℕ) : max 0 a = a := sorry -- by rewrite [max_eq_right !zero_le] -theorem min_succ_succ [simp] (a b : ℕ) : min (succ a) (succ b) = succ (min a b) := +attribute [simp] +theorem min_succ_succ (a b : ℕ) : min (succ a) (succ b) = succ (min a b) := sorry /- or.elim !lt_or_ge @@ -434,7 +441,8 @@ or.elim !lt_or_ge (suppose a ≥ b, by rewrite [min_eq_right this, min_eq_right (succ_le_succ this)]) -/ -theorem max_succ_succ [simp] (a b : ℕ) : max (succ a) (succ b) = succ (max a b) := +attribute [simp] +theorem max_succ_succ (a b : ℕ) : max (succ a) (succ b) = succ (max a b) := sorry /- or.elim !lt_or_ge diff --git a/library/data/nat/parity.lean b/library/data/nat/parity.lean index b08499d9aa..2e4b6c6557 100644 --- a/library/data/nat/parity.lean +++ b/library/data/nat/parity.lean @@ -14,12 +14,14 @@ open decidable definition even (n : nat) := n % 2 = 0 -definition decidable_even [instance] : ∀ n, decidable (even n) := +attribute [instance] +definition decidable_even : ∀ n, decidable (even n) := take n, !nat.has_decidable_eq definition odd (n : nat) := ¬even n -definition decidable_odd [instance] : ∀ n, decidable (odd n) := +attribute [instance] +definition decidable_odd : ∀ n, decidable (odd n) := take n, decidable_not lemma even_of_dvd {n} : 2 ∣ n → even n := diff --git a/library/data/nat/power.lean b/library/data/nat/power.lean index 2b147d2062..033d67464f 100644 --- a/library/data/nat/power.lean +++ b/library/data/nat/power.lean @@ -13,7 +13,8 @@ import data.nat.basic data.nat.order data.nat.div data.nat.gcd algebra.ring_powe namespace nat -definition nat_has_pow_nat [instance] [priority nat.prio] : has_pow_nat nat := +attribute [instance] [priority nat.prio] +definition nat_has_pow_nat : has_pow_nat nat := has_pow_nat.mk has_pow_nat.pow_nat theorem pow_le_pow_of_le {x y : ℕ} (i : ℕ) (H : x ≤ y) : x^i ≤ y^i := diff --git a/library/data/nat/sub.lean b/library/data/nat/sub.lean index 9b7ca3b586..4ded20aa69 100644 --- a/library/data/nat/sub.lean +++ b/library/data/nat/sub.lean @@ -11,42 +11,54 @@ namespace nat /- subtraction -/ -protected theorem sub_zero [simp] (n : ℕ) : n - 0 = n := +attribute [simp] +protected theorem sub_zero (n : ℕ) : n - 0 = n := rfl -theorem sub_succ [simp] (n m : ℕ) : n - succ m = pred (n - m) := +attribute [simp] +theorem sub_succ (n m : ℕ) : n - succ m = pred (n - m) := rfl -protected theorem zero_sub [simp] (n : ℕ) : 0 - n = 0 := +attribute [simp] +protected theorem zero_sub (n : ℕ) : 0 - n = 0 := sorry -- nat.induction_on n (by simp) (by simp) -theorem succ_sub_succ [simp] (n m : ℕ) : succ n - succ m = n - m := +attribute [simp] +theorem succ_sub_succ (n m : ℕ) : succ n - succ m = n - m := succ_sub_succ_eq_sub n m -protected theorem sub_self [simp] (n : ℕ) : n - n = 0 := +attribute [simp] +protected theorem sub_self (n : ℕ) : n - n = 0 := sorry -- nat.induction_on n (by simp) (by simp) local attribute nat.add_succ [simp] -protected theorem add_sub_add_right [simp] (n k m : ℕ) : (n + k) - (m + k) = n - m := +attribute [simp] +protected theorem add_sub_add_right (n k m : ℕ) : (n + k) - (m + k) = n - m := sorry -- nat.induction_on k (by simp) (by simp) -protected theorem add_sub_add_left [simp] (k n m : ℕ) : (k + n) - (k + m) = n - m := +attribute [simp] +protected theorem add_sub_add_left (k n m : ℕ) : (k + n) - (k + m) = n - m := sorry -- nat.induction_on k (by simp) (by simp) -protected theorem add_sub_cancel [simp] (n m : ℕ) : n + m - m = n := +attribute [simp] +protected theorem add_sub_cancel (n m : ℕ) : n + m - m = n := sorry -- nat.induction_on m (by simp) (by simp) -protected theorem add_sub_cancel_left [simp] (n m : ℕ) : n + m - n = m := +attribute [simp] +protected theorem add_sub_cancel_left (n m : ℕ) : n + m - n = m := sorry -- nat.induction_on n (by simp) (by simp) -protected theorem sub_sub [simp] (n m k : ℕ) : n - m - k = n - (m + k) := +attribute [simp] +protected theorem sub_sub (n m k : ℕ) : n - m - k = n - (m + k) := sorry -- nat.induction_on k (by simp) (by simp) -theorem succ_sub_sub_succ [simp] (n m k : ℕ) : succ n - m - succ k = n - m - k := +attribute [simp] +theorem succ_sub_sub_succ (n m k : ℕ) : succ n - m - succ k = n - m - k := sorry -- by simp -theorem sub_self_add [simp] (n m : ℕ) : n - (n + m) = 0 := +attribute [simp] +theorem sub_self_add (n m : ℕ) : n - (n + m) = 0 := sorry -- by inst_simp protected theorem sub.right_comm (m n k : ℕ) : m - n - k = m - k - n := @@ -55,23 +67,28 @@ sorry -- by simp theorem sub_one (n : ℕ) : n - 1 = pred n := rfl -theorem succ_sub_one [simp] (n : ℕ) : succ n - 1 = n := +attribute [simp] +theorem succ_sub_one (n : ℕ) : succ n - 1 = n := rfl local attribute nat.succ_mul nat.mul_succ [simp] /- interaction with multiplication -/ -theorem mul_pred_left [simp] (n m : ℕ) : pred n * m = n * m - m := +attribute [simp] +theorem mul_pred_left (n m : ℕ) : pred n * m = n * m - m := sorry -- nat.induction_on n (by simp) (by simp) -theorem mul_pred_right [simp] (n m : ℕ) : n * pred m = n * m - n := +attribute [simp] +theorem mul_pred_right (n m : ℕ) : n * pred m = n * m - n := sorry -- by inst_simp -protected theorem mul_sub_right_distrib [simp] (n m k : ℕ) : (n - m) * k = n * k - m * k := +attribute [simp] +protected theorem mul_sub_right_distrib (n m k : ℕ) : (n - m) * k = n * k - m * k := sorry -- nat.induction_on m (by simp) (by simp) -protected theorem mul_sub_left_distrib [simp] (n m k : ℕ) : n * (m - k) = n * m - n * k := +attribute [simp] +protected theorem mul_sub_left_distrib (n m k : ℕ) : n * (m - k) = n * m - n * k := sorry -- by inst_simp protected theorem mul_self_sub_mul_self_eq (a b : nat) : a * a - b * b = (a + b) * (a - b) := @@ -324,7 +341,8 @@ lt_of_succ_le this /- distance -/ -definition dist [reducible] (n m : ℕ) := (n - m) + (m - n) +attribute [reducible] +definition dist (n m : ℕ) := (n - m) + (m - n) theorem dist.comm (n m : ℕ) : dist n m = dist m n := sorry -- by simp diff --git a/library/data/num.lean b/library/data/num.lean index 7d7727be0c..83a966747f 100644 --- a/library/data/num.lean +++ b/library/data/num.lean @@ -6,10 +6,12 @@ Author: Leonardo de Moura import data.bool open bool tactic -definition pos_num_decidable_eq [instance] : decidable_eq pos_num := +attribute [instance] +definition pos_num_decidable_eq : decidable_eq pos_num := by mk_dec_eq_instance -definition num_decidable_eq [instance] : decidable_eq num := +attribute [instance] +definition num_decidable_eq : decidable_eq num := by mk_dec_eq_instance namespace pos_num diff --git a/library/data/old_fin.lean b/library/data/old_fin.lean index cb49c437da..52361b4d1b 100644 --- a/library/data/old_fin.lean +++ b/library/data/old_fin.lean @@ -10,7 +10,8 @@ open eq.ops nat function list finset fintype structure fin (n : nat) := (val : nat) (is_lt : val < n) -definition less_than [reducible] := fin +attribute [reducible] +definition less_than := fin namespace fin @@ -35,7 +36,8 @@ end def_equal section open decidable -protected definition has_decidable_eq [instance] (n : nat) : ∀ (i j : fin n), decidable (i = j) +attribute [instance] +protected definition has_decidable_eq (n : nat) : ∀ (i j : fin n), decidable (i = j) | (mk ival ilt) (mk jval jlt) := decidable_of_decidable_of_iff (nat.has_decidable_eq ival jval) eq_iff_veq end @@ -45,7 +47,8 @@ take a1 a2 Pa1 Pa2 Pmkeq, fin.no_confusion Pmkeq (λ Pe Pqe, Pe) lemma val_mk (n i : nat) (Plt : i < n) : fin.val (fin.mk i Plt) = i := rfl -definition upto [reducible] (n : nat) : list (fin n) := +attribute [reducible] +definition upto (n : nat) : list (fin n) := dmap (λ i, i < n) fin.mk (list.upto n) lemma nodup_upto (n : nat) : nodup (upto n) := @@ -68,7 +71,8 @@ calc length (upto n) = length (list.upto n) : (map_val_upto n ▸ length_map fin.val (upto n))⁻¹ ... = n : list.length_upto n -definition is_fintype [instance] (n : nat) : fintype (fin n) := +attribute [instance] +definition is_fintype (n : nat) : fintype (fin n) := fintype.mk (upto n) (nodup_upto n) (mem_upto n) section pigeonhole @@ -88,12 +92,14 @@ end pigeonhole protected definition zero (n : nat) : fin (succ n) := mk 0 !zero_lt_succ -definition fin_has_zero [instance] (n : nat) : has_zero (fin (succ n)) := +attribute [instance] +definition fin_has_zero (n : nat) : has_zero (fin (succ n)) := has_zero.mk (fin.zero n) theorem val_zero (n : nat) : val (0 : fin (succ n)) = 0 := rfl -definition mk_mod [reducible] (n i : nat) : fin (succ n) := +attribute [reducible] +definition mk_mod (n i : nat) : fin (succ n) := mk (i % (succ n)) (mod_lt _ !zero_lt_succ) theorem mk_mod_zero_eq (n : nat) : mk_mod n 0 = 0 := @@ -114,7 +120,8 @@ definition lift_succ (i : fin n) : fin (nat.succ n) := have r : fin (n+1), from lift i 1, r -definition maxi [reducible] : fin (succ n) := +attribute [reducible] +definition maxi : fin (succ n) := mk n !lt_succ_self theorem val_lift : ∀ (i : fin n) (m : nat), val i = val (lift i m) @@ -258,7 +265,8 @@ lemma madd_left_inv : ∀ i : fin (succ n), madd (minv i) i = fin.zero n | (mk iv ilt) := eq_of_veq (by rewrite [val_madd, ↑minv, ↑fin.zero, mod_add_mod, nat.sub_add_cancel (le_of_lt ilt), mod_self]) -definition madd_is_comm_group [instance] : add_comm_group (fin (succ n)) := +attribute [instance] +definition madd_is_comm_group : add_comm_group (fin (succ n)) := add_comm_group.mk madd madd_assoc (fin.zero n) zero_madd madd_zero minv madd_left_inv madd_comm end madd diff --git a/library/data/old_string.lean b/library/data/old_string.lean index c5eed51869..b3f8484149 100644 --- a/library/data/old_string.lean +++ b/library/data/old_string.lean @@ -6,15 +6,18 @@ Author: Leonardo de Moura import data.bool open bool -protected definition char.is_inhabited [instance] : inhabited char := +attribute [instance] +protected definition char.is_inhabited : inhabited char := inhabited.mk (char.mk ff ff ff ff ff ff ff ff) -protected definition string.is_inhabited [instance] : inhabited string := +attribute [instance] +protected definition string.is_inhabited : inhabited string := inhabited.mk string.empty open decidable -definition decidable_eq_char [instance] : ∀ c₁ c₂ : char, decidable (c₁ = c₂) := +attribute [instance] +definition decidable_eq_char : ∀ c₁ c₂ : char, decidable (c₁ = c₂) := begin intro c₁ c₂, cases c₁ with a₁ a₂ a₃ a₄ a₅ a₆ a₇ a₈, @@ -33,7 +36,8 @@ end open string -definition decidable_eq_string [instance] : ∀ s₁ s₂ : string, decidable (s₁ = s₂) +attribute [instance] +definition decidable_eq_string : ∀ s₁ s₂ : string, decidable (s₁ = s₂) | empty empty := by left; reflexivity | empty (str c₂ r₂) := by right; contradiction | (str c₁ r₁) empty := by right; contradiction diff --git a/library/data/pnat.lean b/library/data/pnat.lean index fbf68b5477..2132696db7 100644 --- a/library/data/pnat.lean +++ b/library/data/pnat.lean @@ -35,19 +35,24 @@ protected definition le (p q : ℕ+) := p~ ≤ q~ protected definition lt (p q : ℕ+) := p~ < q~ -definition pnat_has_add [instance] : has_add pnat := +attribute [instance] +definition pnat_has_add : has_add pnat := has_add.mk pnat.add -definition pnat_has_mul [instance] : has_mul pnat := +attribute [instance] +definition pnat_has_mul : has_mul pnat := has_mul.mk pnat.mul -definition pnat_has_le [instance] : has_le pnat := +attribute [instance] +definition pnat_has_le : has_le pnat := has_le.mk pnat.le -definition pnat_has_lt [instance] : has_lt pnat := +attribute [instance] +definition pnat_has_lt : has_lt pnat := has_lt.mk pnat.lt -definition pnat_has_one [instance] : has_one pnat := +attribute [instance] +definition pnat_has_one : has_one pnat := has_one.mk (pos (1:nat) dec_trivial) protected lemma mul_def (p q : ℕ+) : p * q = tag (p~ * q~) (mul_pos (pnat_pos p) (pnat_pos q)) := @@ -62,10 +67,12 @@ rfl protected theorem pnat.eq {p q : ℕ+} : p~ = q~ → p = q := subtype.eq -definition pnat_le_decidable [instance] (p q : ℕ+) : decidable (p ≤ q) := +attribute [instance] +definition pnat_le_decidable (p q : ℕ+) : decidable (p ≤ q) := begin rewrite pnat.le_def, exact nat.decidable_le p~ q~ end -definition pnat_lt_decidable [instance] {p q : ℕ+} : decidable (p < q) := +attribute [instance] +definition pnat_lt_decidable {p q : ℕ+} : decidable (p < q) := begin rewrite pnat.lt_def, exact nat.decidable_lt p~ q~ end protected theorem le_trans {p q r : ℕ+} : p ≤ q → q ≤ r → p ≤ r := @@ -105,7 +112,8 @@ notation 2 := (tag 2 dec_trivial : ℕ+) notation 3 := (tag 3 dec_trivial : ℕ+) definition pone : ℕ+ := tag 1 dec_trivial -definition rat_of_pnat [reducible] (n : ℕ+) : ℚ := +attribute [reducible] +definition rat_of_pnat (n : ℕ+) : ℚ := n~ theorem pnat.to_rat_of_nat (n : ℕ+) : rat_of_pnat n = of_nat n~ := diff --git a/library/data/rat/basic.lean b/library/data/rat/basic.lean index c3f3d0f081..d159af4d63 100644 --- a/library/data/rat/basic.lean +++ b/library/data/rat/basic.lean @@ -24,9 +24,11 @@ definition equiv (a b : prerat) : Prop := num a * denom b = num b * denom a infix ≡ := equiv -theorem equiv.refl [refl] (a : prerat) : a ≡ a := rfl +attribute [refl] +theorem equiv.refl (a : prerat) : a ≡ a := rfl -theorem equiv.symm [symm] {a b : prerat} (H : a ≡ b) : b ≡ a := !eq.symm H +attribute [symm] +theorem equiv.symm {a b : prerat} (H : a ≡ b) : b ≡ a := !eq.symm H theorem num_eq_zero_of_equiv {a b : prerat} (H : a ≡ b) (na_zero : num a = 0) : num b = 0 := have num a * denom b = 0, from !zero_mul ▸ na_zero ▸ rfl, @@ -48,7 +50,8 @@ neg_of_neg_pos this theorem equiv_of_num_eq_zero {a b : prerat} (H1 : num a = 0) (H2 : num b = 0) : a ≡ b := by rewrite [↑equiv, H1, H2, *zero_mul] -theorem equiv.trans [trans] {a b c : prerat} (H1 : a ≡ b) (H2 : b ≡ c) : a ≡ c := +attribute [trans] +theorem equiv.trans {a b c : prerat} (H1 : a ≡ b) (H2 : b ≡ c) : a ≡ c := decidable.by_cases (suppose num b = 0, have num a = 0, from num_eq_zero_of_equiv (equiv.symm H1) `num b = 0`, @@ -358,10 +361,12 @@ namespace rat protected definition prio := num.pred int.prio -definition rat_has_zero [instance] [priority rat.prio] : has_zero rat := +attribute [instance] [priority rat.prio] +definition rat_has_zero : has_zero rat := has_zero.mk (of_int 0) -definition rat_has_one [instance] [priority rat.prio] : has_one rat := +attribute [instance] [priority rat.prio] +definition rat_has_one : has_one rat := has_one.mk (of_int 1) theorem of_int_zero : of_int (0:int) = (0:rat) := @@ -401,21 +406,27 @@ definition denom (a : ℚ) : ℤ := prerat.denom (reduce a) theorem denom_pos (a : ℚ): denom a > 0 := prerat.denom_pos (reduce a) -definition rat_has_add [instance] [priority rat.prio] : has_add rat := +attribute [instance] [priority rat.prio] +definition rat_has_add : has_add rat := has_add.mk rat.add -definition rat_has_mul [instance] [priority rat.prio] : has_mul rat := +attribute [instance] [priority rat.prio] +definition rat_has_mul : has_mul rat := has_mul.mk rat.mul -definition rat_has_neg [instance] [priority rat.prio] : has_neg rat := +attribute [instance] [priority rat.prio] +definition rat_has_neg : has_neg rat := has_neg.mk rat.neg -definition rat_has_inv [instance] [priority rat.prio] : has_inv rat := +attribute [instance] [priority rat.prio] +definition rat_has_inv : has_inv rat := has_inv.mk rat.inv -protected definition sub [reducible] (a b : ℚ) : rat := a + (-b) +attribute [reducible] +protected definition sub (a b : ℚ) : rat := a + (-b) -definition rat_has_sub [instance] [priority rat.prio] : has_sub rat := +attribute [instance] [priority rat.prio] +definition rat_has_sub : has_sub rat := has_sub.mk rat.sub lemma sub.def (a b : ℚ) : a - b = a + (-b) := @@ -516,7 +527,8 @@ protected theorem inv_mul_cancel {a : ℚ} (H : a ≠ 0) : a⁻¹ * a = 1 := protected theorem zero_ne_one : (0 : ℚ) ≠ 1 := assume H, prerat.zero_not_equiv_one (quot.exact H) -definition has_decidable_eq [instance] : decidable_eq ℚ := +attribute [instance] +definition has_decidable_eq : decidable_eq ℚ := take a b, quot.rec_on_subsingleton₂ a b (take u v, if H : prerat.num u * prerat.denom v = prerat.num v * prerat.denom u @@ -550,7 +562,8 @@ decidable.by_cases end)) -protected definition discrete_field [trans_instance] : discrete_field rat := +attribute [trans_instance] +protected definition discrete_field : discrete_field rat := ⦃discrete_field, add := rat.add, add_assoc := rat.add_assoc, @@ -574,10 +587,12 @@ protected definition discrete_field [trans_instance] : discrete_field rat := inv_zero := rat.inv_zero, has_decidable_eq := has_decidable_eq⦄ -definition rat_has_div [instance] [priority rat.prio] : has_div rat := +attribute [instance] [priority rat.prio] +definition rat_has_div : has_div rat := has_div.mk has_div.div -definition rat_has_pow_nat [instance] [priority rat.prio] : has_pow_nat rat := +attribute [instance] [priority rat.prio] +definition rat_has_pow_nat : has_pow_nat rat := has_pow_nat.mk has_pow_nat.pow_nat theorem eq_num_div_denom (a : ℚ) : a = num a / denom a := diff --git a/library/data/rat/countable.lean b/library/data/rat/countable.lean index 1fada522d0..3e4ca578b3 100644 --- a/library/data/rat/countable.lean +++ b/library/data/rat/countable.lean @@ -29,17 +29,20 @@ begin rewrite unpair_mkpair, esimp, rewrite [*encodek, dif_pos h] end -definition encodable_prerat [instance] : encodable prerat := +attribute [instance] +definition encodable_prerat : encodable prerat := encodable.mk encode_prerat decode_prerat decode_encode_prerat -definition decidable_equiv [instance] : ∀ a b : prerat, decidable (prerat.equiv a b) +attribute [instance] +definition decidable_equiv : ∀ a b : prerat, decidable (prerat.equiv a b) | (prerat.mk n₁ d₁ h₁) (prerat.mk n₂ d₂ h₂) := begin unfold prerat.equiv, exact _ end -definition encodable_rat [instance] : encodable rat := +attribute [instance] +definition encodable_rat : encodable rat := @encodable_quot _ _ decidable_equiv encodable_prerat lemma countable_rat : countable rat := diff --git a/library/data/rat/order.lean b/library/data/rat/order.lean index d20e3c00d2..4033104ca9 100644 --- a/library/data/rat/order.lean +++ b/library/data/rat/order.lean @@ -142,10 +142,12 @@ quot.rec_on_subsingleton a (take u, int.decidable_lt 0 (prerat.num u)) protected definition lt (a b : ℚ) : Prop := pos (b - a) protected definition le (a b : ℚ) : Prop := nonneg (b - a) -definition rat_has_lt [instance] [priority rat.prio] : has_lt rat := +attribute [instance] [priority rat.prio] +definition rat_has_lt : has_lt rat := has_lt.mk rat.lt -definition rat_has_le [instance] [priority rat.prio] : has_le rat := +attribute [instance] [priority rat.prio] +definition rat_has_le : has_le rat := has_le.mk rat.le protected lemma lt_def (a b : ℚ) : (a < b) = pos (b - a) := @@ -266,7 +268,8 @@ protected theorem mul_pos (H1 : a > (0 : ℚ)) (H2 : b > (0 : ℚ)) : a * b > (0 have pos (a * b), from pos_mul (to_pos H1) (to_pos H2), begin rewrite -sub_zero at this, exact this end -definition decidable_lt [instance] : decidable_rel rat.lt := +attribute [instance] +definition decidable_lt : decidable_rel rat.lt := take a b, decidable_pos (b - a) protected theorem le_of_lt (H : a < b) : a ≤ b := iff.mpr !rat.le_iff_lt_or_eq (or.inl H) @@ -301,7 +304,8 @@ let H' := rat.le_of_lt H in (take Heq, let Heq' := add_left_cancel Heq in !rat.lt_irrefl (Heq' ▸ H))) -protected definition discrete_linear_ordered_field [trans_instance] : +attribute [trans_instance] +protected definition discrete_linear_ordered_field : discrete_linear_ordered_field rat := ⦃discrete_linear_ordered_field, rat.discrete_field, diff --git a/library/data/real/basic.lean b/library/data/real/basic.lean index 9f3a84b406..7aa26af025 100644 --- a/library/data/real/basic.lean +++ b/library/data/real/basic.lean @@ -996,7 +996,8 @@ definition rneg_well_defined {s t : reg_seq} (H : requiv s t) : requiv (-s) (-t) theorem requiv_is_equiv : equivalence requiv := mk_equivalence requiv requiv.refl requiv.symm requiv.trans -definition reg_seq.to_setoid [instance] : setoid reg_seq := +attribute [instance] +definition reg_seq.to_setoid : setoid reg_seq := ⦃setoid, r := requiv, iseqv := requiv_is_equiv⦄ definition r_zero : reg_seq := @@ -1075,18 +1076,23 @@ protected definition neg (x : ℝ) : ℝ := quot.sound (rneg_well_defined Hab))) --prefix [priority real.prio] `-` := neg -definition real_has_add [instance] [priority real.prio] : has_add real := +attribute [instance] [priority real.prio] +definition real_has_add : has_add real := has_add.mk real.add -definition real_has_mul [instance] [priority real.prio] : has_mul real := +attribute [instance] [priority real.prio] +definition real_has_mul : has_mul real := has_mul.mk real.mul -definition real_has_neg [instance] [priority real.prio] : has_neg real := +attribute [instance] [priority real.prio] +definition real_has_neg : has_neg real := has_neg.mk real.neg -protected definition sub [reducible] (a b : ℝ) : real := a + (-b) +attribute [reducible] +protected definition sub (a b : ℝ) : real := a + (-b) -definition real_has_sub [instance] [priority real.prio] : has_sub real := +attribute [instance] [priority real.prio] +definition real_has_sub : has_sub real := has_sub.mk real.sub open rat -- no coercions before @@ -1096,10 +1102,12 @@ open rat -- no coercions before -- definition of_nat [coercion] (n : ℕ) : ℝ := n -- definition of_num [coercion] [reducible] (n : num) : ℝ := of_rat (rat.of_num n) -definition real_has_zero [reducible] : has_zero real := has_zero.mk (of_rat 0) +attribute [reducible] +definition real_has_zero : has_zero real := has_zero.mk (of_rat 0) local attribute real_has_zero [instance] [priority real.prio] -definition real_has_one [reducible] : has_one real := has_one.mk (of_rat 1) +attribute [reducible] +definition real_has_one : has_one real := has_one.mk (of_rat 1) local attribute real_has_one [instance] [priority real.prio] theorem real_zero_eq_rat_zero : (0:real) = of_rat (0:rat) := @@ -1145,7 +1153,8 @@ protected theorem zero_ne_one : ¬ (0 : ℝ) = 1 := take H : 0 = 1, absurd (quot.exact H) (r_zero_nequiv_one) -protected definition comm_ring [reducible] : comm_ring ℝ := +attribute [reducible] +protected definition comm_ring : comm_ring ℝ := begin fapply comm_ring.mk, exact real.add, diff --git a/library/data/real/division.lean b/library/data/real/division.lean index ced813c0b9..307b7096a8 100644 --- a/library/data/real/division.lean +++ b/library/data/real/division.lean @@ -587,7 +587,8 @@ protected noncomputable definition inv (x : ℝ) : ℝ := quot.lift_on x (λ a, quot.mk (rat_seq.r_inv a)) (λ a b H, quot.sound (rat_seq.r_inv_well_defined H)) -noncomputable definition real_has_inv [instance] [priority real.prio] : has_inv real := +attribute [instance] [priority real.prio] +noncomputable definition real_has_inv : has_inv real := has_inv.mk real.inv protected noncomputable definition div (x y : ℝ) : ℝ := @@ -639,7 +640,8 @@ noncomputable definition dec_lt : decidable_rel real.lt := apply prop_decidable end -protected noncomputable definition discrete_linear_ordered_field [trans_instance]: +attribute [trans_instance] +protected noncomputable definition discrete_linear_ordered_field : discrete_linear_ordered_field ℝ := ⦃ discrete_linear_ordered_field, real.comm_ring, real.ordered_ring, le_total := real.le_total, diff --git a/library/data/real/order.lean b/library/data/real/order.lean index 25ada27633..253924b01e 100644 --- a/library/data/real/order.lean +++ b/library/data/real/order.lean @@ -1026,10 +1026,12 @@ protected definition lt (x y : ℝ) := protected definition le (x y : ℝ) := quot.lift_on₂ x y (λ a b, rat_seq.r_le a b) rat_seq.r_le_well_defined -definition real_has_lt [instance] [priority real.prio] : has_lt ℝ := +attribute [instance] [priority real.prio] +definition real_has_lt : has_lt ℝ := has_lt.mk real.lt -definition real_has_le [instance] [priority real.prio] : has_le ℝ := +attribute [instance] [priority real.prio] +definition real_has_le : has_le ℝ := has_le.mk real.le definition sep (x y : ℝ) := quot.lift_on₂ x y (λ a b, rat_seq.r_sep a b) rat_seq.r_sep_well_defined @@ -1092,7 +1094,8 @@ protected theorem le_of_lt_or_eq (x y : ℝ) : x < y ∨ x = y → x ≤ y := apply (or.inr (quot.exact H')) end))) -definition ordered_ring [trans_instance] : ordered_ring ℝ := +attribute [trans_instance] +definition ordered_ring : ordered_ring ℝ := ⦃ ordered_ring, real.comm_ring, le_refl := real.le_refl, le_trans := @real.le_trans, diff --git a/library/data/set/comm_semiring.lean b/library/data/set/comm_semiring.lean index 7d4e5fc311..0df47f3f30 100644 --- a/library/data/set/comm_semiring.lean +++ b/library/data/set/comm_semiring.lean @@ -8,7 +8,8 @@ Author: Leonardo de Moura import data.set.basic algebra.ring open set -definition set_comm_semiring [instance] (A : Type) : comm_semiring (set A) := +attribute [instance] +definition set_comm_semiring (A : Type) : comm_semiring (set A) := ⦃ comm_semiring, add := union, mul := inter, diff --git a/library/data/set/filter.lean b/library/data/set/filter.lean index 75e6d09efd..0f0cff07a1 100644 --- a/library/data/set/filter.lean +++ b/library/data/set/filter.lean @@ -156,10 +156,12 @@ begin end namespace complete_lattice - definition le [reducible] (F₁ F₂ : filter A) := F₁ ⊇ F₂ + attribute [reducible] + definition le (F₁ F₂ : filter A) := F₁ ⊇ F₂ local infix `≤`:50 := le - definition ge [reducible] (F₁ F₂ : filter A) := F₁ ⊆ F₂ + attribute [reducible] + definition ge (F₁ F₂ : filter A) := F₁ ⊆ F₂ local infix `≥`:50 := ge theorem le_refl (F : filter A) : F ≤ F := subset.refl _ @@ -286,7 +288,8 @@ namespace complete_lattice Sup_le (λ G GS, GS F FS) end complete_lattice -protected definition complete_lattice [trans_instance] : complete_lattice (filter A) := +attribute [trans_instance] +protected definition complete_lattice : complete_lattice (filter A) := ⦃ complete_lattice, le := complete_lattice.le, le_refl := complete_lattice.le_refl, @@ -438,7 +441,8 @@ inductive sets_generated_by {A : Type} (B : set (set A)) : set A → Prop := | inter_mem : ∀ {a b}, sets_generated_by B a → sets_generated_by B b → sets_generated_by B (a ∩ b) | mono : ∀ {a b}, a ⊆ b → sets_generated_by B a → sets_generated_by B b -definition filter_generated_by [reducible] {A : Type} (B : set (set A)) : filter A := +attribute [reducible] +definition filter_generated_by {A : Type} (B : set (set A)) : filter A := ⦃filter, sets := sets_generated_by B, univ_mem_sets := sets_generated_by.univ_mem B, diff --git a/library/data/set/finite.lean b/library/data/set/finite.lean index e64525877f..2a01c6c066 100644 --- a/library/data/set/finite.lean +++ b/library/data/set/finite.lean @@ -14,9 +14,11 @@ variable {A : Type} namespace set -definition finite [class] (s : set A) : Prop := ∃ (s' : finset A), s = finset.to_set s' +attribute [class] +definition finite (s : set A) : Prop := ∃ (s' : finset A), s = finset.to_set s' -theorem finite_finset [instance] (s : finset A) : finite (finset.to_set s) := +attribute [instance] +theorem finite_finset (s : finset A) : finite (finset.to_set s) := exists.intro s rfl /- to finset: casts every set to a finite set -/ @@ -51,7 +53,8 @@ theorem finite_of_to_set_to_finset_eq {s : set A} (H : finset.to_set (to_finset finite s := by rewrite -H; apply finite_finset -theorem finite_empty [instance] : finite (∅ : set A) := +attribute [instance] +theorem finite_empty : finite (∅ : set A) := by rewrite [-finset.to_set_empty]; apply finite_finset theorem to_finset_empty : to_finset (∅ : set A) = (#finset ∅) := @@ -68,7 +71,8 @@ theorem to_finset_eq_empty (s : set A) [fins : finite s] : (to_finset s = finset.empty) ↔ (s = ∅) := iff.intro eq_empty_of_to_finset_eq_empty to_finset_eq_empty_of_eq_empty -theorem finite_insert [instance] (a : A) (s : set A) [finite s] : finite (insert a s) := +attribute [instance] +theorem finite_insert (a : A) (s : set A) [finite s] : finite (insert a s) := exists.intro (finset.insert a (to_finset s)) (by rewrite [finset.to_set_insert, to_set_to_finset]) @@ -76,7 +80,8 @@ theorem to_finset_insert (a : A) (s : set A) [finite s] : to_finset (insert a s) = finset.insert a (to_finset s) := by apply to_finset_eq_of_to_set_eq; rewrite [finset.to_set_insert, to_set_to_finset] -theorem finite_union [instance] (s t : set A) [finite s] [finite t] : +attribute [instance] +theorem finite_union (s t : set A) [finite s] [finite t] : finite (s ∪ t) := exists.intro (#finset to_finset s ∪ to_finset t) (by rewrite [finset.to_set_union, *to_set_to_finset]) @@ -85,7 +90,8 @@ theorem to_finset_union (s t : set A) [finite s] [finite t] : to_finset (s ∪ t) = (#finset to_finset s ∪ to_finset t) := by apply to_finset_eq_of_to_set_eq; rewrite [finset.to_set_union, *to_set_to_finset] -theorem finite_inter [instance] (s t : set A) [finite s] [finite t] : +attribute [instance] +theorem finite_inter (s t : set A) [finite s] [finite t] : finite (s ∩ t) := exists.intro (#finset to_finset s ∩ to_finset t) (by rewrite [finset.to_set_inter, *to_set_to_finset]) @@ -94,7 +100,8 @@ theorem to_finset_inter (s t : set A) [finite s] [finite t] : to_finset (s ∩ t) = (#finset to_finset s ∩ to_finset t) := by apply to_finset_eq_of_to_set_eq; rewrite [finset.to_set_inter, *to_set_to_finset] -theorem finite_sep [instance] (s : set A) (p : A → Prop) [finite s] : +attribute [instance] +theorem finite_sep (s : set A) (p : A → Prop) [finite s] : finite {x ∈ s | p x} := exists.intro (finset.sep p (to_finset s)) (by rewrite [finset.to_set_sep, *to_set_to_finset]) @@ -103,7 +110,8 @@ theorem to_finset_sep (s : set A) (p : A → Prop) [finite s] : to_finset {x ∈ s | p x} = (#finset {x ∈ to_finset s | p x}) := by apply to_finset_eq_of_to_set_eq; rewrite [finset.to_set_sep, to_set_to_finset] -theorem finite_image [instance] {B : Type} (f : A → B) (s : set A) [finite s] : +attribute [instance] +theorem finite_image {B : Type} (f : A → B) (s : set A) [finite s] : finite (f ' s) := exists.intro (finset.image f (to_finset s)) (by rewrite [finset.to_set_image, *to_set_to_finset]) @@ -113,7 +121,8 @@ theorem to_finset_image {B : Type} (f : A → B) (s : set A) to_finset (f ' s) = (#finset f ' (to_finset s)) := by apply to_finset_eq_of_to_set_eq; rewrite [finset.to_set_image, to_set_to_finset] -theorem finite_diff [instance] (s t : set A) [finite s] : finite (s \ t) := +attribute [instance] +theorem finite_diff (s t : set A) [finite s] : finite (s \ t) := !finite_sep theorem to_finset_diff (s t : set A) [finite s] [finite t] : @@ -130,7 +139,8 @@ by rewrite [finset.subset_eq_to_set_subset, *to_set_to_finset] theorem finite_of_finite_insert {s : set A} {a : A} (finias : finite (insert a s)) : finite s := finite_subset (subset_insert a s) -theorem finite_upto [instance] (n : ℕ) : finite {i | i < n} := +attribute [instance] +theorem finite_upto (n : ℕ) : finite {i | i < n} := by rewrite [-finset.to_set_upto n]; apply finite_finset theorem to_finset_upto (n : ℕ) : to_finset {i | i < n} = finset.upto n := @@ -189,7 +199,8 @@ by rewrite H; apply finite_image /- induction for finite sets -/ -theorem induction_finite [recursor 6] {P : set A → Prop} +attribute [recursor 6] +theorem induction_finite {P : set A → Prop} (H1 : P ∅) (H2 : ∀ ⦃a : A⦄, ∀ {s : set A} [finite s], a ∉ s → P s → P (insert a s)) : ∀ (s : set A) [finite s], P s := begin diff --git a/library/data/set/function.lean b/library/data/set/function.lean index e8263659f6..e2bc7740dd 100644 --- a/library/data/set/function.lean +++ b/library/data/set/function.lean @@ -108,7 +108,8 @@ or.elim xmem /- maps to -/ -definition maps_to [reducible] (f : X → Y) (a : set X) (b : set Y) : Prop := ∀⦃x⦄, x ∈ a → f x ∈ b +attribute [reducible] +definition maps_to (f : X → Y) (a : set X) (b : set Y) : Prop := ∀⦃x⦄, x ∈ a → f x ∈ b theorem maps_to_of_eq_on {f1 f2 : X → Y} {a : set X} {b : set Y} (eq_on_a : eq_on f1 f2 a) (maps_to_f1 : maps_to f1 a b) : @@ -141,7 +142,8 @@ image_subset_of_maps_to_of_subset mfab (subset.refl a) /- injectivity -/ -definition inj_on [reducible] (f : X → Y) (a : set X) : Prop := +attribute [reducible] +definition inj_on (f : X → Y) (a : set X) : Prop := ∀⦃x1 x2 : X⦄, x1 ∈ a → x2 ∈ a → f x1 = f x2 → x1 = x2 theorem inj_on_empty (f : X → Y) : inj_on f ∅ := @@ -184,7 +186,8 @@ iff.intro /- surjectivity -/ -definition surj_on [reducible] (f : X → Y) (a : set X) (b : set Y) : Prop := b ⊆ f ' a +attribute [reducible] +definition surj_on (f : X → Y) (a : set X) (b : set Y) : Prop := b ⊆ f ' a theorem surj_on_of_eq_on {f1 f2 : X → Y} {a : set X} {b : set Y} (eq_f1_f2 : eq_on f1 f2 a) (surj_f1 : surj_on f1 a b) : @@ -226,7 +229,8 @@ eq_of_subset_of_subset (image_subset_of_maps_to H1) H2 /- bijectivity -/ -definition bij_on [reducible] (f : X → Y) (a : set X) (b : set Y) : Prop := +attribute [reducible] +definition bij_on (f : X → Y) (a : set X) (b : set Y) : Prop := maps_to f a b ∧ inj_on f a ∧ surj_on f a b lemma maps_to_of_bij_on {f : X → Y} {a : set X} {b : set Y} (H : bij_on f a b) : @@ -290,7 +294,8 @@ iff.intro /- left inverse -/ -- g is a left inverse to f on a -definition left_inv_on [reducible] (g : Y → X) (f : X → Y) (a : set X) : Prop := +attribute [reducible] +definition left_inv_on (g : Y → X) (f : X → Y) (a : set X) : Prop := ∀₀ x ∈ a, g (f x) = x theorem left_inv_on_of_eq_on_left {g1 g2 : Y → X} {f : X → Y} {a : set X} {b : set Y} @@ -333,7 +338,8 @@ calc /- right inverse -/ -- g is a right inverse to f on a -definition right_inv_on [reducible] (g : Y → X) (f : X → Y) (b : set Y) : Prop := +attribute [reducible] +definition right_inv_on (g : Y → X) (f : X → Y) (b : set Y) : Prop := left_inv_on f g b theorem right_inv_on_of_eq_on_left {g1 g2 : Y → X} {f : X → Y} {a : set X} {b : set Y} @@ -386,7 +392,8 @@ calc /- inverses -/ -- g is an inverse to f viewed as a map from a to b -definition inv_on [reducible] (g : Y → X) (f : X → Y) (a : set X) (b : set Y) : Prop := +attribute [reducible] +definition inv_on (g : Y → X) (f : X → Y) (a : set X) (b : set Y) : Prop := left_inv_on g f a ∧ right_inv_on g f b theorem bij_on_of_inv_on {g : Y → X} {f : X → Y} {a : set X} {b : set Y} (fab : maps_to f a b) diff --git a/library/data/set/map.lean b/library/data/set/map.lean index e50ffd8d95..f313d8bb73 100644 --- a/library/data/set/map.lean +++ b/library/data/set/map.lean @@ -20,7 +20,8 @@ variables {a : set X} {b : set Y} {c : set Z} /- the equivalence relation -/ -protected definition equiv [reducible] (f1 f2 : map a b) : Prop := eq_on f1 f2 a +attribute [reducible] +protected definition equiv (f1 f2 : map a b) : Prop := eq_on f1 f2 a namespace equiv_notation infix `~` := map.equiv diff --git a/library/data/sigma.lean b/library/data/sigma.lean index 5f6950f8ff..4f7abd9c0c 100644 --- a/library/data/sigma.lean +++ b/library/data/sigma.lean @@ -23,7 +23,8 @@ 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))] : + attribute [instance] + protected definition is_inhabited [H₁ : inhabited A] [H₂ : inhabited (B (default A))] : inhabited (sigma B) := inhabited.destruct H₁ (λa, inhabited.destruct H₂ (λb, inhabited.mk (sigma.mk (default A) b))) @@ -32,9 +33,14 @@ namespace sigma definition dtrip (a : A) (b : B a) (c : C a b) := (sigma.mk a (sigma.mk b c)) definition dquad (a : A) (b : B a) (c : C a b) (d : D a b c) := (sigma.mk a (sigma.mk b (sigma.mk c d))) - definition pr1' [reducible] (x : Σ a, B a) := x.1 - definition pr2' [reducible] (x : Σ a b, C a b) := x.2.1 - definition pr3 [reducible] (x : Σ a b, C a b) := x.2.2 - definition pr3' [reducible] (x : Σ a b c, D a b c) := x.2.2.1 - definition pr4 [reducible] (x : Σ a b c, D a b c) := x.2.2.2 + attribute [reducible] + definition pr1' (x : Σ a, B a) := x.1 + attribute [reducible] + definition pr2' (x : Σ a b, C a b) := x.2.1 + attribute [reducible] + definition pr3 (x : Σ a b, C a b) := x.2.2 + attribute [reducible] + definition pr3' (x : Σ a b c, D a b c) := x.2.2.1 + attribute [reducible] + definition pr4 (x : Σ a b c, D a b c) := x.2.2.2 end sigma diff --git a/library/data/squash.lean b/library/data/squash.lean index c13c72c058..33370c5ff1 100644 --- a/library/data/squash.lean +++ b/library/data/squash.lean @@ -46,8 +46,10 @@ end squash open squash decidable -definition decidable_eq_squash [instance] (A : Type) : decidable_eq ∥A∥ := +attribute [instance] +definition decidable_eq_squash (A : Type) : decidable_eq ∥A∥ := λ a b, inl (squash.irrelevant a b) -definition subsingleton_squash [instance] (A : Type) : subsingleton ∥A∥ := +attribute [instance] +definition subsingleton_squash (A : Type) : subsingleton ∥A∥ := subsingleton.intro (@squash.irrelevant A) diff --git a/library/data/stream.lean b/library/data/stream.lean index f65b658875..998720cead 100644 --- a/library/data/stream.lean +++ b/library/data/stream.lean @@ -20,7 +20,8 @@ definition cons (a : A) (s : stream A) : stream A := notation h :: t := cons h t -definition head [reducible] (s : stream A) : A := +attribute [reducible] +definition head (s : stream A) : A := s 0 definition tail (s : stream A) : stream A := @@ -29,7 +30,8 @@ definition tail (s : stream A) : stream A := definition drop (n : nat) (s : stream A) : stream A := λ i, s (i+n) -definition nth [reducible] (n : nat) (s : stream A) : A := +attribute [reducible] +definition nth (n : nat) (s : stream A) : A := s n protected theorem eta (s : stream A) : head s :: tail s = s := diff --git a/library/data/sum.lean b/library/data/sum.lean index 813f797ec2..c66edb5371 100644 --- a/library/data/sum.lean +++ b/library/data/sum.lean @@ -31,9 +31,11 @@ namespace sum definition inr_inj {b₁ b₂ : B} : intro_right A b₁ = intro_right A b₂ → b₁ = b₂ := sorry -- assume H, by injection H; assumption - protected definition is_inhabited_left [instance] [h : inhabited A] : inhabited (A + B) := + attribute [instance] + protected definition is_inhabited_left [h : inhabited A] : inhabited (A + B) := inhabited.mk (inl (default A)) - protected definition is_inhabited_right [instance] [h : inhabited B] : inhabited (A + B) := + attribute [instance] + protected definition is_inhabited_right [h : inhabited B] : inhabited (A + B) := inhabited.mk (inr (default B)) end sum diff --git a/library/data/tuple.lean b/library/data/tuple.lean index 471c20b11f..6140715509 100644 --- a/library/data/tuple.lean +++ b/library/data/tuple.lean @@ -9,12 +9,14 @@ It is implemented as a subtype. import logic data.list data.fin open nat list subtype function -definition tuple [reducible] (A : Type) (n : nat) := {l : list A | length l = n} +attribute [reducible] +definition tuple (A : Type) (n : nat) := {l : list A | length l = n} namespace tuple variables {A B C : Type} - theorem induction_on [recursor 4] {P : ∀ {n}, tuple A n → Prop} + attribute [recursor 4] + theorem induction_on {P : ∀ {n}, tuple A n → Prop} : ∀ {n} (v : tuple A n), (∀ (l : list A) {n : nat} (h : length l = n), P (tag l h)) → P v | n (tag l h) H := @H l n h @@ -29,11 +31,13 @@ namespace tuple notation a :: b := cons a b - protected definition is_inhabited [instance] [h : inhabited A] : ∀ (n : nat), inhabited (tuple A n) + attribute [instance] + protected definition is_inhabited [h : inhabited A] : ∀ (n : nat), inhabited (tuple A n) | 0 := inhabited.mk nil | (succ n) := inhabited.mk (inhabited.value h :: inhabited.value (is_inhabited n)) - protected definition has_decidable_eq [instance] [h : decidable_eq A] : ∀ (n : nat), decidable_eq (tuple A n) := + attribute [instance] + protected definition has_decidable_eq [h : decidable_eq A] : ∀ (n : nat), decidable_eq (tuple A n) := λ n, subtype.has_decidable_eq definition head {n : nat} : tuple A (succ n) → A @@ -153,7 +157,8 @@ namespace tuple theorem not_mem_nil (a : A) : a ∉ nil := list.not_mem_nil a - theorem mem_cons [simp] {n : nat} (a : A) (v : tuple A n) : a ∈ a :: v := + attribute [simp] + theorem mem_cons {n : nat} (a : A) (v : tuple A n) : a ∈ a :: v := induction_on v (λ l n h, !list.mem_cons) theorem mem_cons_of_mem {n : nat} (y : A) {x : A} {v : tuple A n} : x ∈ v → x ∈ y :: v := diff --git a/library/data/uprod.lean b/library/data/uprod.lean index 5cfbe83eff..595aca412b 100644 --- a/library/data/uprod.lean +++ b/library/data/uprod.lean @@ -13,15 +13,18 @@ p₁ = p₂ ∨ swap p₁ = p₂ infix `~` := eqv -- this is "~" -private theorem eqv.refl [refl] {A : Type} : ∀ p : A × A, p ~ p := +attribute [refl] +private theorem eqv.refl {A : Type} : ∀ p : A × A, p ~ p := take p, or.inl rfl -private theorem eqv.symm [symm] {A : Type} : ∀ p₁ p₂ : A × A, p₁ ~ p₂ → p₂ ~ p₁ := +attribute [symm] +private theorem eqv.symm {A : Type} : ∀ p₁ p₂ : A × A, p₁ ~ p₂ → p₂ ~ p₁ := take p₁ p₂ h, or.elim h (λ e, by rewrite e) (λ e, begin esimp [eqv], rewrite [-e, swap_swap], right, reflexivity end) -private theorem eqv.trans [trans] {A : Type} : ∀ p₁ p₂ p₃ : A × A, p₁ ~ p₂ → p₂ ~ p₃ → p₁ ~ p₃ := +attribute [trans] +private theorem eqv.trans {A : Type} : ∀ p₁ p₂ p₃ : A × A, p₁ ~ p₂ → p₂ ~ p₃ → p₁ ~ p₃ := take p₁ p₂ p₃ h₁ h₂, or.elim h₁ (λ e₁₂, or.elim h₂ (λ e₂₃, by rewrite [e₁₂, e₂₃]) @@ -33,7 +36,8 @@ take p₁ p₂ p₃ h₁ h₂, or.elim h₁ private theorem is_equivalence (A : Type) : equivalence (@eqv A) := mk_equivalence (@eqv A) (@eqv.refl A) (@eqv.symm A) (@eqv.trans A) -definition uprod.setoid [instance] (A : Type) : setoid (A × A) := +attribute [instance] +definition uprod.setoid (A : Type) : setoid (A × A) := setoid.mk (@eqv A) (is_equivalence A) definition uprod (A : Type) : Type := diff --git a/library/init/.gdb_history b/library/init/.gdb_history new file mode 100644 index 0000000000..e69de29bb2 diff --git a/library/init/alternative.lean b/library/init/alternative.lean index 3204a65784..0765f2de6c 100644 --- a/library/init/alternative.lean +++ b/library/init/alternative.lean @@ -10,13 +10,16 @@ structure alternative [class] (f : Type → Type) extends applicative f := (failure : Π {A : Type}, f A) (orelse : Π {A : Type}, f A → f A → f A) -definition failure [inline] {f : Type → Type} [alternative f] {A : Type} : f A := +attribute [inline] +definition failure {f : Type → Type} [alternative f] {A : Type} : f A := alternative.failure f -definition orelse [inline] {f : Type → Type} [alternative f] {A : Type} : f A → f A → f A := +attribute [inline] +definition orelse {f : Type → Type} [alternative f] {A : Type} : f A → f A → f A := alternative.orelse infixr ` <|> `:2 := orelse -definition guard [inline] {f : Type₁ → Type} [alternative f] (p : Prop) [decidable p] : f unit := +attribute [inline] +definition guard {f : Type₁ → Type} [alternative f] (p : Prop) [decidable p] : f unit := if p then pure () else failure diff --git a/library/init/applicative.lean b/library/init/applicative.lean index 517983ff92..e2f26f62b5 100644 --- a/library/init/applicative.lean +++ b/library/init/applicative.lean @@ -12,10 +12,12 @@ structure applicative.{u₁ u₂} [class] (f : Type.{u₁} → Type.{u₂}) exte (pure : Π {A : Type.{u₁}}, A → f A) (seq : Π {A B : Type.{u₁}}, f (A → B) → f A → f B) -definition pure [inline] {f : Type → Type} [applicative f] {A : Type} (a : A) : f A := +attribute [inline] +definition pure {f : Type → Type} [applicative f] {A : Type} (a : A) : f A := applicative.pure f a -definition seq_app [inline] {A B : Type} {f : Type → Type} [applicative f] (g : f (A → B)) (a : f A) : f B := +attribute [inline] +definition seq_app {A B : Type} {f : Type → Type} [applicative f] (g : f (A → B)) (a : f A) : f B := applicative.seq g a infixr ` <*> `:2 := seq_app diff --git a/library/init/bool.lean b/library/init/bool.lean index b8a3b2f3b1..b4b49c6400 100644 --- a/library/init/bool.lean +++ b/library/init/bool.lean @@ -5,16 +5,20 @@ prelude import init.datatypes init.reserved_notation namespace bool - definition cond [inline] {A : Type} (b : bool) (t e : A) := + attribute [inline] + definition cond {A : Type} (b : bool) (t e : A) := bool.rec_on b e t - definition bor [inline] (a b : bool) := + attribute [inline] + definition bor (a b : bool) := bool.rec_on a (bool.rec_on b ff tt) tt - definition band [inline] (a b : bool) := + attribute [inline] + definition band (a b : bool) := bool.rec_on a ff (bool.rec_on b ff tt) - definition bnot [inline] (a : bool) := + attribute [inline] + definition bnot (a : bool) := bool.rec_on a tt ff end bool diff --git a/library/init/char.lean b/library/init/char.lean index 0a95a2916a..0efe078552 100644 --- a/library/init/char.lean +++ b/library/init/char.lean @@ -18,9 +18,11 @@ definition to_nat (c : char) : nat := fin.val c end char -definition char_has_decidable_eq [instance] : decidable_eq char := +attribute [instance] +definition char_has_decidable_eq : decidable_eq char := have decidable_eq (fin 256), from _, this -definition char_is_inhabited [instance] : inhabited char := +attribute [instance] +definition char_is_inhabited : inhabited char := inhabited.mk (char.of_nat 65) diff --git a/library/init/coe.lean b/library/init/coe.lean index 263dc900d8..74b56a0c61 100644 --- a/library/init/coe.lean +++ b/library/init/coe.lean @@ -82,61 +82,78 @@ notation `↥`:max a:max := coe_sort a /- Transitive closure for has_lift, has_coe, has_coe_to_fun -/ -definition lift_trans [instance] {A B C : Type} [has_lift A B] [has_lift_t B C] : has_lift_t A C := +attribute [instance] +definition lift_trans {A B C : Type} [has_lift A B] [has_lift_t B C] : has_lift_t A C := has_lift_t.mk (λ a, lift_t (lift a : B)) -definition lift_base [instance] {A B : Type} [has_lift A B] : has_lift_t A B := +attribute [instance] +definition lift_base {A B : Type} [has_lift A B] : has_lift_t A B := has_lift_t.mk lift -definition coe_trans [instance] {A B C : Type} [has_coe A B] [has_coe_t B C] : has_coe_t A C := +attribute [instance] +definition coe_trans {A B C : Type} [has_coe A B] [has_coe_t B C] : has_coe_t A C := has_coe_t.mk (λ a, coe_t (coe_b a : B)) -definition coe_base [instance] {A B : Type} [has_coe A B] : has_coe_t A B := +attribute [instance] +definition coe_base {A B : Type} [has_coe A B] : has_coe_t A B := has_coe_t.mk coe_b -definition coe_fn_trans [instance] {A B : Type} [has_lift_t A B] [has_coe_to_fun B] : has_coe_to_fun A := +attribute [instance] +definition coe_fn_trans {A B : Type} [has_lift_t A B] [has_coe_to_fun B] : has_coe_to_fun A := has_coe_to_fun.mk (has_coe_to_fun.F B) (λ a, coe_fn (coe a)) -definition coe_sort_trans [instance] {A B : Type} [has_lift_t A B] [has_coe_to_sort B] : has_coe_to_sort A := +attribute [instance] +definition coe_sort_trans {A B : Type} [has_lift_t A B] [has_coe_to_sort B] : has_coe_to_sort A := has_coe_to_sort.mk (has_coe_to_sort.S B) (λ a, coe_sort (coe a)) /- Every coercion is also a lift -/ -definition coe_to_lift [instance] {A B : Type} [has_coe_t A B] : has_lift_t A B := +attribute [instance] +definition coe_to_lift {A B : Type} [has_coe_t A B] : has_lift_t A B := has_lift_t.mk coe_t /- Basic coercions -/ -definition coe_bool_to_Prop [instance] : has_coe bool Prop := +attribute [instance] +definition coe_bool_to_Prop : has_coe bool Prop := has_coe.mk (λ b, b = tt) -definition coe_decidable_eq [instance] (b : bool) : decidable (coe b) := +attribute [instance] +definition coe_decidable_eq (b : bool) : decidable (coe b) := show decidable (b = tt), from _ -definition coe_subtype [instance] {A : Type} {P : A → Prop} : has_coe {a \ P a} A := +attribute [instance] +definition coe_subtype {A : Type} {P : A → Prop} : has_coe {a \ P a} A := has_coe.mk (λ s, subtype.elt_of s) /- Basic lifts -/ /- Remark: we can't use [has_lift_t A₂ A₁] since it will produce non-termination whenever a type class resolution problem does not have a solution. -/ -definition lift_fn [instance] {A₁ A₂ B₁ B₂ : Type} [has_lift A₂ A₁] [has_lift_t B₁ B₂] : has_lift (A₁ → B₁) (A₂ → B₂) := +attribute [instance] +definition lift_fn {A₁ A₂ B₁ B₂ : Type} [has_lift A₂ A₁] [has_lift_t B₁ B₂] : has_lift (A₁ → B₁) (A₂ → B₂) := has_lift.mk (λ f a, ↑(f ↑a)) -definition lift_fn_range [instance] {A B₁ B₂ : Type} [has_lift_t B₁ B₂] : has_lift (A → B₁) (A → B₂) := +attribute [instance] +definition lift_fn_range {A B₁ B₂ : Type} [has_lift_t B₁ B₂] : has_lift (A → B₁) (A → B₂) := has_lift.mk (λ f a, ↑(f a)) -definition lift_fn_dom [instance] {A₁ A₂ B : Type} [has_lift A₂ A₁] : has_lift (A₁ → B) (A₂ → B) := +attribute [instance] +definition lift_fn_dom {A₁ A₂ B : Type} [has_lift A₂ A₁] : has_lift (A₁ → B) (A₂ → B) := has_lift.mk (λ f a, f ↑a) -definition lift_pair [instance] {A₁ A₂ B₁ B₂ : Type} [has_lift_t A₁ A₂] [has_lift_t B₁ B₂] : has_lift (A₁ × B₁) (A₂ × B₂) := +attribute [instance] +definition lift_pair {A₁ A₂ B₁ B₂ : Type} [has_lift_t A₁ A₂] [has_lift_t B₁ B₂] : has_lift (A₁ × B₁) (A₂ × B₂) := has_lift.mk (λ p, prod.cases_on p (λ a b, (↑a, ↑b))) -definition lift_pair₁ [instance] {A₁ A₂ B : Type} [has_lift_t A₁ A₂] : has_lift (A₁ × B) (A₂ × B) := +attribute [instance] +definition lift_pair₁ {A₁ A₂ B : Type} [has_lift_t A₁ A₂] : has_lift (A₁ × B) (A₂ × B) := has_lift.mk (λ p, prod.cases_on p (λ a b, (↑a, b))) -definition lift_pair₂ [instance] {A B₁ B₂ : Type} [has_lift_t B₁ B₂] : has_lift (A × B₁) (A × B₂) := +attribute [instance] +definition lift_pair₂ {A B₁ B₂ : Type} [has_lift_t B₁ B₂] : has_lift (A × B₁) (A × B₂) := has_lift.mk (λ p, prod.cases_on p (λ a b, (a, ↑b))) -definition lift_list [instance] {A B : Type} [has_lift_t A B] : has_lift (list A) (list B) := +attribute [instance] +definition lift_list {A B : Type} [has_lift_t A B] : has_lift (list A) (list B) := has_lift.mk (λ l, list.map (@coe A B _) l) diff --git a/library/init/datatypes.lean b/library/init/datatypes.lean index bbb6b587bb..61a2cbb9fe 100644 --- a/library/init/datatypes.lean +++ b/library/init/datatypes.lean @@ -52,10 +52,12 @@ inductive sum (A B : Type) : Type := | inl {} : A → sum A B | inr {} : B → sum A B -definition sum.intro_left [reducible] {A : Type} (B : Type) (a : A) : sum A B := +attribute [reducible] +definition sum.intro_left {A : Type} (B : Type) (a : A) : sum A B := sum.inl a -definition sum.intro_right [reducible] (A : Type) {B : Type} (b : B) : sum A B := +attribute [reducible] +definition sum.intro_right (A : Type) {B : Type} (b : B) : sum A B := sum.inr b inductive or (a b : Prop) : Prop := diff --git a/library/init/fin.lean b/library/init/fin.lean index b29350ca6d..5c0bd477a8 100644 --- a/library/init/fin.lean +++ b/library/init/fin.lean @@ -32,6 +32,7 @@ end fin open decidable fin -protected definition fin.has_decidable_eq [instance] (n : nat) : ∀ (i j : fin n), decidable (i = j) +attribute [instance] +protected definition fin.has_decidable_eq (n : nat) : ∀ (i j : fin n), decidable (i = j) | (mk ival ilt) (mk jval jlt) := decidable_of_decidable_of_iff (nat.has_decidable_eq ival jval) eq_iff_veq diff --git a/library/init/function.lean b/library/init/function.lean index eae841a173..3aa2e5db1f 100644 --- a/library/init/function.lean +++ b/library/init/function.lean @@ -12,10 +12,12 @@ notation f ` $ `:1 a:1 := f a variables {A : Type} {B : Type} {C : Type} {D : Type} {E : Type} -definition function.comp [inline] [reducible] [unfold_full] (f : B → C) (g : A → B) : A → C := +attribute [inline] [reducible] [unfold_full] +definition function.comp (f : B → C) (g : A → B) : A → C := λx, f (g x) -definition function.dcomp [inline] [reducible] [unfold_full] {B : A → Type} {C : Π {x : A}, B x → Type} +attribute [inline] [reducible] [unfold_full] +definition function.dcomp {B : A → Type} {C : Π {x : A}, B x → Type} (f : Π {x : A} (y : B x), C y) (g : Πx, B x) : Πx, C (g x) := λx, f (g x) @@ -24,32 +26,41 @@ infixr ` ∘' `:80 := function.dcomp namespace function -definition comp_right [reducible] [unfold_full] (f : B → B → B) (g : A → B) : B → A → B := +attribute [reducible] [unfold_full] +definition comp_right (f : B → B → B) (g : A → B) : B → A → B := λ b a, f b (g a) -definition comp_left [reducible] [unfold_full] (f : B → B → B) (g : A → B) : A → B → B := +attribute [reducible] [unfold_full] +definition comp_left (f : B → B → B) (g : A → B) : A → B → B := λ a b, f (g a) b -definition on_fun [reducible] [unfold_full] (f : B → B → C) (g : A → B) : A → A → C := +attribute [reducible] [unfold_full] +definition on_fun (f : B → B → C) (g : A → B) : A → A → C := λx y, f (g x) (g y) -definition combine [reducible] [unfold_full] (f : A → B → C) (op : C → D → E) (g : A → B → D) +attribute [reducible] [unfold_full] +definition combine (f : A → B → C) (op : C → D → E) (g : A → B → D) : A → B → E := λx y, op (f x y) (g x y) -definition const [reducible] [unfold_full] (B : Type) (a : A) : B → A := +attribute [reducible] [unfold_full] +definition const (B : Type) (a : A) : B → A := λx, a -definition swap [reducible] [unfold_full] {C : A → B → Type} (f : Πx y, C x y) : Πy x, C x y := +attribute [reducible] [unfold_full] +definition swap {C : A → B → Type} (f : Πx y, C x y) : Πy x, C x y := λy x, f x y -definition app [reducible] {B : A → Type} (f : Πx, B x) (x : A) : B x := +attribute [reducible] +definition app {B : A → Type} (f : Πx, B x) (x : A) : B x := f x -definition curry [reducible] [unfold_full] : (A × B → C) → A → B → C := +attribute [reducible] [unfold_full] +definition curry : (A × B → C) → A → B → C := λ f a b, f (a, b) -definition uncurry [reducible] [unfold 5] : (A → B → C) → (A × B → C) := +attribute [reducible] [unfold 5] +definition uncurry : (A → B → C) → (A × B → C) := λ f p, match p with (a, b) := f a b end theorem curry_uncurry (f : A → B → C) : curry (uncurry f) = f := @@ -73,13 +84,15 @@ theorem comp.right_id (f : A → B) : f ∘ id = f := rfl theorem comp_const_right (f : B → C) (b : B) : f ∘ (const A b) = const A (f b) := rfl -definition injective [reducible] (f : A → B) : Prop := ∀ ⦃a₁ a₂⦄, f a₁ = f a₂ → a₁ = a₂ +attribute [reducible] +definition injective (f : A → B) : Prop := ∀ ⦃a₁ a₂⦄, f a₁ = f a₂ → a₁ = a₂ theorem injective_comp {g : B → C} {f : A → B} (Hg : injective g) (Hf : injective f) : injective (g ∘ f) := take a₁ a₂, assume Heq, Hf (Hg Heq) -definition surjective [reducible] (f : A → B) : Prop := ∀ b, ∃ a, f a = b +attribute [reducible] +definition surjective (f : A → B) : Prop := ∀ b, ∃ a, f a = b theorem surjective_comp {g : B → C} {f : A → B} (Hg : surjective g) (Hf : surjective f) : surjective (g ∘ f) := diff --git a/library/init/functor.lean b/library/init/functor.lean index c1e22e975d..4d738125ef 100644 --- a/library/init/functor.lean +++ b/library/init/functor.lean @@ -8,7 +8,8 @@ prelude structure functor [class] (f : Type → Type) : Type := (map : Π {a b: Type}, (a → b) → f a → f b) -definition fmap [inline] {F : Type → Type} [functor F] {A B : Type} (f : A → B) (a : F A) : F B := +attribute [inline] +definition fmap {F : Type → Type} [functor F] {A B : Type} (f : A → B) (a : F A) : F B := functor.map f a infixr ` <$> `:100 := fmap diff --git a/library/init/funext.lean b/library/init/funext.lean index af694c511e..2c7c706e74 100644 --- a/library/init/funext.lean +++ b/library/init/funext.lean @@ -31,7 +31,8 @@ section open quot variables {A : Type} {B : A → Type} - private definition fun_setoid [instance] (A : Type) (B : A → Type) : setoid (Πx : A, B x) := + attribute [instance] + private definition fun_setoid (A : Type) (B : A → Type) : setoid (Πx : A, B x) := setoid.mk (@function.equiv A B) (function.equiv.is_equivalence A B) private definition extfun (A : Type) (B : A → Type) : Type := @@ -57,7 +58,8 @@ attribute funext [intro!] local infix `~` := function.equiv -definition subsingleton_pi [instance] {A : Type} {B : A → Type} (H : ∀ a, subsingleton (B a)) : +attribute [instance] +definition subsingleton_pi {A : Type} {B : A → Type} (H : ∀ a, subsingleton (B a)) : subsingleton (Π a, B a) := subsingleton.intro (take f₁ f₂, have eqv : f₁ ~ f₂, from diff --git a/library/init/instances.lean b/library/init/instances.lean index c14b9b5a1d..f8c06f11f9 100644 --- a/library/init/instances.lean +++ b/library/init/instances.lean @@ -8,17 +8,22 @@ import init.meta.mk_dec_eq_instance init.subtype init.meta.occurrences open tactic subtype -definition subtype_decidable_eq [instance] {A : Type} {P : A → Prop} [decidable_eq A] : decidable_eq {x \ P x} := +attribute [instance] +definition subtype_decidable_eq {A : Type} {P : A → Prop} [decidable_eq A] : decidable_eq {x \ P x} := by mk_dec_eq_instance -definition list_decidable_eq [instance] {A : Type} [decidable_eq A] : decidable_eq (list A) := +attribute [instance] +definition list_decidable_eq {A : Type} [decidable_eq A] : decidable_eq (list A) := by mk_dec_eq_instance -definition occurrences_decidable_eq [instance] : decidable_eq occurrences := +attribute [instance] +definition occurrences_decidable_eq : decidable_eq occurrences := by mk_dec_eq_instance -definition unit_decidable_eq [instance] : decidable_eq unit := +attribute [instance] +definition unit_decidable_eq : decidable_eq unit := by mk_dec_eq_instance -definition sum_decidable [instance] {A : Type} {B : Type} [decidable_eq A] [decidable_eq B] : decidable_eq (sum A B) := +attribute [instance] +definition sum_decidable {A : Type} {B : Type} [decidable_eq A] [decidable_eq B] : decidable_eq (sum A B) := by mk_dec_eq_instance diff --git a/library/init/list.lean b/library/init/list.lean index 9faa1ef673..51f9be8c93 100644 --- a/library/init/list.lean +++ b/library/init/list.lean @@ -7,7 +7,8 @@ prelude import init.logic init.nat open decidable list -protected definition list.is_inhabited [instance] (A : Type) : inhabited (list A) := +attribute [instance] +protected definition list.is_inhabited (A : Type) : inhabited (list A) := inhabited.mk list.nil notation h :: t := cons h t @@ -65,5 +66,6 @@ definition dropn : ℕ → list A → list A | (succ n) (x::r) := dropn n r end list -definition list_has_append [instance] {A : Type} : has_append (list A) := +attribute [instance] +definition list_has_append {A : Type} : has_append (list A) := has_append.mk list.append diff --git a/library/init/list_classes.lean b/library/init/list_classes.lean index 39d0d9ca86..c515426b07 100644 --- a/library/init/list_classes.lean +++ b/library/init/list_classes.lean @@ -7,17 +7,22 @@ prelude import init.monad init.alternative open list -definition list_fmap [inline] {A B : Type} (f : A → B) (l : list A) : list B := +attribute [inline] +definition list_fmap {A B : Type} (f : A → B) (l : list A) : list B := map f l -definition list_bind [inline] {A B : Type} (a : list A) (b : A → list B) : list B := +attribute [inline] +definition list_bind {A B : Type} (a : list A) (b : A → list B) : list B := join (map b a) -definition list_return [inline] {A : Type} (a : A) : list A := +attribute [inline] +definition list_return {A : Type} (a : A) : list A := [a] -definition list_is_monad [instance] : monad list := +attribute [instance] +definition list_is_monad : monad list := monad.mk @list_fmap @list_return @list_bind -definition list_is_alternative [instance] : alternative list := +attribute [instance] +definition list_is_alternative : alternative list := alternative.mk @list_fmap @list_return (@fapp _ _) @nil @list.append diff --git a/library/init/logic.lean b/library/init/logic.lean index 7786a7d3cf..ef0c2012a6 100644 --- a/library/init/logic.lean +++ b/library/init/logic.lean @@ -6,14 +6,16 @@ Authors: Leonardo de Moura, Jeremy Avigad, Floris van Doorn prelude import init.datatypes init.reserved_notation -definition id [reducible] [unfold_full] {A : Type} (a : A) : A := +attribute [reducible] [unfold_full] +definition id {A : Type} (a : A) : A := a /- implication -/ definition implies (a b : Prop) := a → b -lemma implies.trans [trans] {p q r : Prop} (h₁ : implies p q) (h₂ : implies q r) : implies p r := +attribute [trans] +lemma implies.trans {p q r : Prop} (h₁ : implies p q) (h₂ : implies q r) : implies p r := assume hp, h₂ (h₁ hp) definition trivial := true.intro @@ -21,10 +23,12 @@ definition trivial := true.intro definition not (a : Prop) := a → false prefix `¬` := not -definition absurd [inline] {a : Prop} {b : Type} (H1 : a) (H2 : ¬a) : b := +attribute [inline] +definition absurd {a : Prop} {b : Type} (H1 : a) (H2 : ¬a) : b := false.rec b (H2 H1) -lemma not.intro [intro!] {a : Prop} (H : a → false) : ¬ a := +attribute [intro!] +lemma not.intro {a : Prop} (H : a → false) : ¬ a := H theorem mt {a b : Prop} (H1 : a → b) (H2 : ¬b) : ¬a := @@ -55,7 +59,8 @@ definition rfl {A : Type} {a : A} : a = a := eq.refl a attribute [pattern] rfl -definition id.def [defeq] {A : Type} (a : A) : id a = a := rfl +attribute [defeq] +definition id.def {A : Type} (a : A) : id a = a := rfl -- proof irrelevance is built in theorem proof_irrel {a : Prop} (H₁ H₂ : a) : H₁ = H₂ := @@ -129,7 +134,8 @@ attribute eq.refl [refl] attribute eq.trans [trans] attribute eq.symm [symm] -definition cast [inline] {A B : Type} (H : A = B) (a : A) : B := +attribute [inline] +definition cast {A B : Type} (H : A = B) (a : A) : B := eq.rec a H theorem cast_proof_irrel {A B : Type} (H₁ H₂ : A = B) (a : A) : cast H₁ a = cast H₂ a := @@ -140,8 +146,10 @@ rfl /- ne -/ -definition ne [reducible] {A : Type} (a b : A) := ¬(a = b) -definition ne.def [defeq] {A : Type} (a b : A) : ne a b = ¬ (a = b) := rfl +attribute [reducible] +definition ne {A : Type} (a b : A) := ¬(a = b) +attribute [defeq] +definition ne.def {A : Type} (a b : A) : ne a b = ¬ (a = b) := rfl notation a ≠ b := ne a b namespace ne @@ -308,18 +316,21 @@ theorem iff.elim_right : (a ↔ b) → b → a := and.right definition iff.mpr := @iff.elim_right -theorem iff.refl [refl] (a : Prop) : a ↔ a := +attribute [refl] +theorem iff.refl (a : Prop) : a ↔ a := iff.intro (assume H, H) (assume H, H) theorem iff.rfl {a : Prop} : a ↔ a := iff.refl a -theorem iff.trans [trans] (H₁ : a ↔ b) (H₂ : b ↔ c) : a ↔ c := +attribute [trans] +theorem iff.trans (H₁ : a ↔ b) (H₂ : b ↔ c) : a ↔ c := iff.intro (assume Ha, iff.mp H₂ (iff.mp H₁ Ha)) (assume Hc, iff.mpr H₁ (iff.mpr H₂ Hc)) -theorem iff.symm [symm] (H : a ↔ b) : b ↔ a := +attribute [symm] +theorem iff.symm (H : a ↔ b) : b ↔ a := iff.intro (iff.elim_right H) (iff.elim_left H) theorem iff.comm : (a ↔ b) ↔ (b ↔ a) := @@ -351,7 +362,8 @@ iff.intro (λ (Hl : ¬¬¬a) (Ha : a), Hl (non_contradictory_intro Ha)) absurd -theorem imp_congr [congr] (H1 : a ↔ c) (H2 : b ↔ d) : (a → b) ↔ (c → d) := +attribute [congr] +theorem imp_congr (H1 : a ↔ c) (H2 : b ↔ d) : (a → b) ↔ (c → d) := iff.intro (λHab Hc, iff.mp H2 (Hab (iff.mpr H1 Hc))) (λHcd Ha, iff.mpr H2 (Hcd (iff.mp H1 Ha))) @@ -367,38 +379,48 @@ assume Hna : ¬a, Hna Ha theorem not_of_not_not_not (H : ¬¬¬a) : ¬a := λ Ha, absurd (not_not_intro Ha) H -theorem not_true [simp] : (¬ true) ↔ false := +attribute [simp] +theorem not_true : (¬ true) ↔ false := iff_false_intro (not_not_intro trivial) -theorem not_false_iff [simp] : (¬ false) ↔ true := +attribute [simp] +theorem not_false_iff : (¬ false) ↔ true := iff_true_intro not_false -theorem not_congr [congr] (H : a ↔ b) : ¬a ↔ ¬b := +attribute [congr] +theorem not_congr (H : a ↔ b) : ¬a ↔ ¬b := iff.intro (λ H₁ H₂, H₁ (iff.mpr H H₂)) (λ H₁ H₂, H₁ (iff.mp H H₂)) -theorem ne_self_iff_false [simp] {A : Type} (a : A) : (not (a = a)) ↔ false := +attribute [simp] +theorem ne_self_iff_false {A : Type} (a : A) : (not (a = a)) ↔ false := iff.intro false_of_ne false.elim -theorem eq_self_iff_true [simp] {A : Type} (a : A) : (a = a) ↔ true := +attribute [simp] +theorem eq_self_iff_true {A : Type} (a : A) : (a = a) ↔ true := iff_true_intro rfl -theorem heq_self_iff_true [simp] {A : Type} (a : A) : (a == a) ↔ true := +attribute [simp] +theorem heq_self_iff_true {A : Type} (a : A) : (a == a) ↔ true := iff_true_intro (heq.refl a) -theorem iff_not_self [simp] (a : Prop) : (a ↔ ¬a) ↔ false := +attribute [simp] +theorem iff_not_self (a : Prop) : (a ↔ ¬a) ↔ false := iff_false_intro (λ H, have H' : ¬a, from (λ Ha, (iff.mp H Ha) Ha), H' (iff.mpr H H')) -theorem not_iff_self [simp] (a : Prop) : (¬a ↔ a) ↔ false := +attribute [simp] +theorem not_iff_self (a : Prop) : (¬a ↔ a) ↔ false := iff_false_intro (λ H, have H' : ¬a, from (λ Ha, (iff.mpr H Ha) Ha), H' (iff.mp H H')) -theorem true_iff_false [simp] : (true ↔ false) ↔ false := +attribute [simp] +theorem true_iff_false : (true ↔ false) ↔ false := iff_false_intro (λ H, iff.mp H trivial) -theorem false_iff_true [simp] : (false ↔ true) ↔ false := +attribute [simp] +theorem false_iff_true : (false ↔ true) ↔ false := iff_false_intro (λ H, iff.mpr H trivial) theorem false_of_true_iff_false : (true ↔ false) → false := @@ -408,7 +430,8 @@ assume H, iff.mp H trivial theorem and.imp (H₂ : a → c) (H₃ : b → d) : a ∧ b → c ∧ d := and.rec (λHa Hb, and.intro (H₂ Ha) (H₃ Hb)) -theorem and_congr [congr] (H1 : a ↔ c) (H2 : b ↔ d) : (a ∧ b) ↔ (c ∧ d) := +attribute [congr] +theorem and_congr (H1 : a ↔ c) (H2 : b ↔ d) : (a ∧ b) ↔ (c ∧ d) := iff.intro (and.imp (iff.mp H1) (iff.mp H2)) (and.imp (iff.mpr H1) (iff.mpr H2)) theorem and_congr_right (H : a → (b ↔ c)) : (a ∧ b) ↔ (a ∧ c) := @@ -416,15 +439,18 @@ iff.intro (take Hab, and.intro (and.left Hab) (iff.elim_left (H (and.left Hab)) (and.right Hab))) (take Hac, and.intro (and.left Hac) (iff.elim_right (H (and.left Hac)) (and.right Hac))) -theorem and.comm [simp] : a ∧ b ↔ b ∧ a := +attribute [simp] +theorem and.comm : a ∧ b ↔ b ∧ a := iff.intro and.swap and.swap -theorem and.assoc [simp] : (a ∧ b) ∧ c ↔ a ∧ (b ∧ c) := +attribute [simp] +theorem and.assoc : (a ∧ b) ∧ c ↔ a ∧ (b ∧ c) := iff.intro (and.rec (λ H' Hc, and.rec (λ Ha Hb, and.intro Ha (and.intro Hb Hc)) H')) (and.rec (λ Ha, and.rec (λ Hb Hc, and.intro (and.intro Ha Hb) Hc))) -theorem and.left_comm [simp] : a ∧ (b ∧ c) ↔ b ∧ (a ∧ c) := +attribute [simp] +theorem and.left_comm : a ∧ (b ∧ c) ↔ b ∧ (a ∧ c) := iff.trans (iff.symm and.assoc) (iff.trans (and_congr and.comm (iff.refl c)) and.assoc) theorem and_iff_left {a b : Prop} (Hb : b) : (a ∧ b) ↔ a := @@ -433,25 +459,32 @@ iff.intro and.left (λHa, and.intro Ha Hb) theorem and_iff_right {a b : Prop} (Ha : a) : (a ∧ b) ↔ b := iff.intro and.right (and.intro Ha) -theorem and_true [simp] (a : Prop) : a ∧ true ↔ a := +attribute [simp] +theorem and_true (a : Prop) : a ∧ true ↔ a := and_iff_left trivial -theorem true_and [simp] (a : Prop) : true ∧ a ↔ a := +attribute [simp] +theorem true_and (a : Prop) : true ∧ a ↔ a := and_iff_right trivial -theorem and_false [simp] (a : Prop) : a ∧ false ↔ false := +attribute [simp] +theorem and_false (a : Prop) : a ∧ false ↔ false := iff_false_intro and.right -theorem false_and [simp] (a : Prop) : false ∧ a ↔ false := +attribute [simp] +theorem false_and (a : Prop) : false ∧ a ↔ false := iff_false_intro and.left -theorem not_and_self [simp] (a : Prop) : (¬a ∧ a) ↔ false := +attribute [simp] +theorem not_and_self (a : Prop) : (¬a ∧ a) ↔ false := iff_false_intro (λ H, and.elim H (λ H₁ H₂, absurd H₂ H₁)) -theorem and_not_self [simp] (a : Prop) : (a ∧ ¬a) ↔ false := +attribute [simp] +theorem and_not_self (a : Prop) : (a ∧ ¬a) ↔ false := iff_false_intro (λ H, and.elim H (λ H₁ H₂, absurd H₁ H₂)) -theorem and_self [simp] (a : Prop) : a ∧ a ↔ a := +attribute [simp] +theorem and_self (a : Prop) : a ∧ a ↔ a := iff.intro and.left (assume H, and.intro H H) /- or simp rules -/ @@ -465,32 +498,41 @@ or.imp H id theorem or.imp_right (H : a → b) : c ∨ a → c ∨ b := or.imp id H -theorem or_congr [congr] (H1 : a ↔ c) (H2 : b ↔ d) : (a ∨ b) ↔ (c ∨ d) := +attribute [congr] +theorem or_congr (H1 : a ↔ c) (H2 : b ↔ d) : (a ∨ b) ↔ (c ∨ d) := iff.intro (or.imp (iff.mp H1) (iff.mp H2)) (or.imp (iff.mpr H1) (iff.mpr H2)) -theorem or.comm [simp] : a ∨ b ↔ b ∨ a := iff.intro or.swap or.swap +attribute [simp] +theorem or.comm : a ∨ b ↔ b ∨ a := iff.intro or.swap or.swap -theorem or.assoc [simp] : (a ∨ b) ∨ c ↔ a ∨ (b ∨ c) := +attribute [simp] +theorem or.assoc : (a ∨ b) ∨ c ↔ a ∨ (b ∨ c) := iff.intro (or.rec (or.imp_right or.inl) (λ H, or.inr (or.inr H))) (or.rec (λ H, or.inl (or.inl H)) (or.imp_left or.inr)) -theorem or.left_comm [simp] : a ∨ (b ∨ c) ↔ b ∨ (a ∨ c) := +attribute [simp] +theorem or.left_comm : a ∨ (b ∨ c) ↔ b ∨ (a ∨ c) := iff.trans (iff.symm or.assoc) (iff.trans (or_congr or.comm (iff.refl c)) or.assoc) -theorem or_true [simp] (a : Prop) : a ∨ true ↔ true := +attribute [simp] +theorem or_true (a : Prop) : a ∨ true ↔ true := iff_true_intro (or.inr trivial) -theorem true_or [simp] (a : Prop) : true ∨ a ↔ true := +attribute [simp] +theorem true_or (a : Prop) : true ∨ a ↔ true := iff_true_intro (or.inl trivial) -theorem or_false [simp] (a : Prop) : a ∨ false ↔ a := +attribute [simp] +theorem or_false (a : Prop) : a ∨ false ↔ a := iff.intro (or.rec id false.elim) or.inl -theorem false_or [simp] (a : Prop) : false ∨ a ↔ a := +attribute [simp] +theorem false_or (a : Prop) : false ∨ a ↔ a := iff.trans or.comm (or_false a) -theorem or_self [simp] (a : Prop) : a ∨ a ↔ a := +attribute [simp] +theorem or_self (a : Prop) : a ∨ a ↔ a := iff.intro (or.rec id id) or.inl /- or resolution rulse -/ @@ -509,22 +551,28 @@ definition or.neg_resolve_right {a b : Prop} (H : a ∨ ¬ b) (Hb : b) : a := /- iff simp rules -/ -theorem iff_true [simp] (a : Prop) : (a ↔ true) ↔ a := +attribute [simp] +theorem iff_true (a : Prop) : (a ↔ true) ↔ a := iff.intro (assume H, iff.mpr H trivial) iff_true_intro -theorem true_iff [simp] (a : Prop) : (true ↔ a) ↔ a := +attribute [simp] +theorem true_iff (a : Prop) : (true ↔ a) ↔ a := iff.trans iff.comm (iff_true a) -theorem iff_false [simp] (a : Prop) : (a ↔ false) ↔ ¬ a := +attribute [simp] +theorem iff_false (a : Prop) : (a ↔ false) ↔ ¬ a := iff.intro and.left iff_false_intro -theorem false_iff [simp] (a : Prop) : (false ↔ a) ↔ ¬ a := +attribute [simp] +theorem false_iff (a : Prop) : (false ↔ a) ↔ ¬ a := iff.trans iff.comm (iff_false a) -theorem iff_self [simp] (a : Prop) : (a ↔ a) ↔ true := +attribute [simp] +theorem iff_self (a : Prop) : (a ↔ a) ↔ true := iff_true_intro iff.rfl -theorem iff_congr [congr] (H1 : a ↔ c) (H2 : b ↔ d) : (a ↔ b) ↔ (c ↔ d) := +attribute [congr] +theorem iff_congr (H1 : a ↔ c) (H2 : b ↔ d) : (a ↔ b) ↔ (c ↔ d) := and_congr (imp_congr H1 H2) (imp_congr H2 H1) /- exists -/ @@ -552,11 +600,13 @@ definition exists_unique {A : Type} (p : A → Prop) := notation `∃!` binders `, ` r:(scoped P, exists_unique P) := r -theorem exists_unique.intro [intro] {A : Type} {p : A → Prop} (w : A) (H1 : p w) (H2 : ∀y, p y → y = w) : +attribute [intro] +theorem exists_unique.intro {A : Type} {p : A → Prop} (w : A) (H1 : p w) (H2 : ∀y, p y → y = w) : ∃!x, p x := exists.intro w (and.intro H1 H2) -theorem exists_unique.elim [recursor 4] [elim] {A : Type} {p : A → Prop} {b : Prop} +attribute [recursor 4] [elim] +theorem exists_unique.elim {A : Type} {p : A → Prop} {b : Prop} (H2 : ∃!x, p x) (H1 : ∀x, p x → (∀y, p y → y = x) → b) : b := exists.elim H2 (λ w Hw, H1 w (and.left Hw) (and.right Hw)) @@ -578,18 +628,21 @@ exists_unique.elim H section variables {A : Type} {p₁ p₂ : A → Prop} -theorem forall_congr [congr] {A : Type} {P Q : A → Prop} (H : ∀a, (P a ↔ Q a)) : (∀a, P a) ↔ ∀a, Q a := +attribute [congr] +theorem forall_congr {A : Type} {P Q : A → Prop} (H : ∀a, (P a ↔ Q a)) : (∀a, P a) ↔ ∀a, Q a := iff.intro (λp a, iff.mp (H a) (p a)) (λq a, iff.mpr (H a) (q a)) theorem exists_imp_exists {A : Type} {P Q : A → Prop} (H : ∀a, (P a → Q a)) (p : ∃a, P a) : ∃a, Q a := exists.elim p (λa Hp, exists.intro a (H a Hp)) -theorem exists_congr [congr] {A : Type} {P Q : A → Prop} (H : ∀a, (P a ↔ Q a)) : (∃a, P a) ↔ ∃a, Q a := +attribute [congr] +theorem exists_congr {A : Type} {P Q : A → Prop} (H : ∀a, (P a ↔ Q a)) : (∃a, P a) ↔ ∃a, Q a := iff.intro (exists_imp_exists (λa, iff.mp (H a))) (exists_imp_exists (λa, iff.mpr (H a))) -theorem exists_unique_congr [congr] (H : ∀ x, p₁ x ↔ p₂ x) : (∃! x, p₁ x) ↔ (∃! x, p₂ x) := +attribute [congr] +theorem exists_unique_congr (H : ∀ x, p₁ x ↔ p₂ x) : (∃! x, p₁ x) ↔ (∃! x, p₂ x) := exists_congr (λx, and_congr (H x) (forall_congr (λy, imp_congr (H y) iff.rfl))) end @@ -599,20 +652,24 @@ inductive decidable [class] (p : Prop) : Type := | ff : ¬p → decidable p | tt : p → decidable p -definition decidable_true [instance] : decidable true := +attribute [instance] +definition decidable_true : decidable true := decidable.tt trivial -definition decidable_false [instance] : decidable false := +attribute [instance] +definition decidable_false : decidable false := decidable.ff not_false -- We use "dependent" if-then-else to be able to communicate the if-then-else condition -- to the branches -definition dite [inline] (c : Prop) [H : decidable c] {A : Type} : (c → A) → (¬ c → A) → A := +attribute [inline] +definition dite (c : Prop) [H : decidable c] {A : Type} : (c → A) → (¬ c → A) → A := λ t e, decidable.rec_on H e t /- if-then-else -/ -definition ite [inline] (c : Prop) [H : decidable c] {A : Type} (t e : A) : A := +attribute [inline] +definition ite (c : Prop) [H : decidable c] {A : Type} (t e : A) : A := decidable.rec_on H (λ Hnc, e) (λ Hc, t) namespace decidable @@ -658,35 +715,44 @@ section variables {p q : Prop} open decidable (rec_on tt ff) - definition decidable_and [instance] [decidable p] [decidable q] : decidable (p ∧ q) := + attribute [instance] + definition decidable_and [decidable p] [decidable q] : decidable (p ∧ q) := if hp : p then if hq : q then tt (and.intro hp hq) else ff (assume H : p ∧ q, hq (and.right H)) else ff (assume H : p ∧ q, hp (and.left H)) - definition decidable_or [instance] [decidable p] [decidable q] : decidable (p ∨ q) := + attribute [instance] + definition decidable_or [decidable p] [decidable q] : decidable (p ∨ q) := if hp : p then tt (or.inl hp) else if hq : q then tt (or.inr hq) else ff (or.rec hp hq) - definition decidable_not [instance] [decidable p] : decidable (¬p) := + attribute [instance] + definition decidable_not [decidable p] : decidable (¬p) := if hp : p then ff (absurd hp) else tt hp - definition decidable_implies [instance] [decidable p] [decidable q] : decidable (p → q) := + attribute [instance] + definition decidable_implies [decidable p] [decidable q] : decidable (p → q) := if hp : p then if hq : q then tt (assume H, hq) else ff (assume H : p → q, absurd (H hp) hq) else tt (assume Hp, absurd Hp hp) - definition decidable_iff [instance] [decidable p] [decidable q] : decidable (p ↔ q) := + attribute [instance] + definition decidable_iff [decidable p] [decidable q] : decidable (p ↔ q) := decidable_and 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} [decidable_eq A] (a b : A) : decidable (a ≠ b) := +attribute [reducible] +definition decidable_pred {A : Type} (R : A → Prop) := Π (a : A), decidable (R a) +attribute [reducible] +definition decidable_rel {A : Type} (R : A → A → Prop) := Π (a b : A), decidable (R a b) +attribute [reducible] +definition decidable_eq (A : Type) := decidable_rel (@eq A) +attribute [instance] +definition decidable_ne {A : Type} [decidable_eq A] (a b : A) : decidable (a ≠ b) := decidable_implies namespace bool @@ -698,7 +764,8 @@ definition is_dec_eq {A : Type} (p : A → A → bool) : Prop := ∀ ⦃x y : definition is_dec_refl {A : Type} (p : A → A → bool) : Prop := ∀x, p x x = tt open decidable -protected definition bool.has_decidable_eq [instance] : ∀a b : bool, decidable (a = b) +attribute [instance] +protected definition bool.has_decidable_eq : ∀a b : bool, decidable (a = b) | ff ff := tt rfl | ff tt := ff bool.ff_ne_tt | tt ff := ff (ne.symm bool.ff_ne_tt) @@ -726,35 +793,45 @@ end inductive inhabited [class] (A : Type) : Type := mk : A → inhabited A -protected definition inhabited.value [inline] {A : Type} : inhabited A → A := +attribute [inline] +protected definition inhabited.value {A : Type} : inhabited A → A := inhabited.rec (λa, a) -protected definition inhabited.destruct [inline] {A : Type} {B : Type} (H1 : inhabited A) (H2 : A → B) : B := +attribute [inline] +protected definition inhabited.destruct {A : Type} {B : Type} (H1 : inhabited A) (H2 : A → B) : B := inhabited.rec H2 H1 -definition default [inline] (A : Type) [H : inhabited A] : A := +attribute [inline] +definition default (A : Type) [H : inhabited A] : A := inhabited.value H -definition arbitrary [inline] [irreducible] (A : Type) [H : inhabited A] : A := +attribute [inline] [irreducible] +definition arbitrary (A : Type) [H : inhabited A] : A := inhabited.value H -definition Prop.is_inhabited [instance] : inhabited Prop := +attribute [instance] +definition Prop.is_inhabited : inhabited Prop := inhabited.mk true -definition inhabited_fun [instance] (A : Type) {B : Type} [H : inhabited B] : inhabited (A → B) := +attribute [instance] +definition inhabited_fun (A : Type) {B : Type} [H : inhabited B] : inhabited (A → B) := inhabited.rec_on H (λb, inhabited.mk (λa, b)) -definition inhabited_Pi [instance] (A : Type) {B : A → Type} [Πx, inhabited (B x)] : +attribute [instance] +definition inhabited_Pi (A : Type) {B : A → Type} [Πx, inhabited (B x)] : inhabited (Πx, B x) := inhabited.mk (λa, default (B a)) -protected definition bool.is_inhabited [inline] [instance] : inhabited bool := +attribute [inline] [instance] +protected definition bool.is_inhabited : inhabited bool := inhabited.mk ff -protected definition pos_num.is_inhabited [inline] [instance] : inhabited pos_num := +attribute [inline] [instance] +protected definition pos_num.is_inhabited : inhabited pos_num := inhabited.mk pos_num.one -protected definition num.is_inhabited [inline] [instance] : inhabited num := +attribute [inline] [instance] +protected definition num.is_inhabited : inhabited num := inhabited.mk num.zero inductive nonempty [class] (A : Type) : Prop := @@ -763,7 +840,8 @@ intro : A → nonempty A protected definition nonempty.elim {A : Type} {B : Prop} (H1 : nonempty A) (H2 : A → B) : B := nonempty.rec H2 H1 -theorem nonempty_of_inhabited [instance] {A : Type} [inhabited A] : nonempty A := +attribute [instance] +theorem nonempty_of_inhabited {A : Type} [inhabited A] : nonempty A := nonempty.intro (default A) theorem nonempty_of_exists {A : Type} {P : A → Prop} : (∃x, P x) → nonempty A := @@ -780,10 +858,12 @@ subsingleton.rec (λp, p) H protected definition subsingleton.helim {A B : Type} [H : subsingleton A] (h : A = B) : ∀ (a : A) (b : B), a == b := eq.rec_on h (λ a b : A, heq_of_eq (subsingleton.elim a b)) -definition subsingleton_prop [instance] (p : Prop) : subsingleton p := +attribute [instance] +definition subsingleton_prop (p : Prop) : subsingleton p := subsingleton.intro (λa b, proof_irrel a b) -definition subsingleton_decidable [instance] (p : Prop) : subsingleton (decidable p) := +attribute [instance] +definition subsingleton_decidable (p : Prop) : subsingleton (decidable p) := subsingleton.intro (λ d₁, match d₁ with | (tt t₁) := (λ d₂, @@ -816,7 +896,8 @@ decidable.rec (λ Hc : c, absurd Hc Hnc) H -theorem if_t_t [simp] (c : Prop) [H : decidable c] {A : Type} (t : A) : (ite c t t) = t := +attribute [simp] +theorem if_t_t (c : Prop) [H : decidable c] {A : Type} (t : A) : (ite c t t) = t := decidable.rec (λ Hnc : ¬c, eq.refl (@ite c (decidable.ff Hnc) A t t)) (λ Hc : c, eq.refl (@ite c (decidable.tt Hc) A t t)) @@ -842,7 +923,8 @@ decidable.rec_on dec_b ... = u : h_t (iff.mp h_c hp) ... = ite c u v : eq.subst (if_pos (iff.mp h_c hp)) (eq.refl (ite c u v))) -theorem if_congr [congr] {A : Type} {b c : Prop} [dec_b : decidable b] [dec_c : decidable c] +attribute [congr] +theorem if_congr {A : Type} {b c : Prop} [dec_b : decidable b] [dec_c : decidable c] {x y u v : A} (h_c : b ↔ c) (h_t : x = u) (h_e : y = v) : ite b x y = ite c u v := @@ -853,15 +935,18 @@ theorem if_ctx_simp_congr {A : Type} {b c : Prop} [dec_b : decidable b] {x y u v ite b x y = (@ite c (decidable_of_decidable_of_iff dec_b h_c) A u v) := @if_ctx_congr A b c dec_b (decidable_of_decidable_of_iff dec_b h_c) x y u v h_c h_t h_e -theorem if_simp_congr [congr] {A : Type} {b c : Prop} [dec_b : decidable b] {x y u v : A} +attribute [congr] +theorem if_simp_congr {A : Type} {b c : Prop} [dec_b : decidable b] {x y u v : A} (h_c : b ↔ c) (h_t : x = u) (h_e : y = v) : ite b x y = (@ite c (decidable_of_decidable_of_iff dec_b h_c) A u v) := @if_ctx_simp_congr A b c dec_b x y u v h_c (λ h, h_t) (λ h, h_e) -definition if_true [simp] {A : Type} (t e : A) : (if true then t else e) = t := +attribute [simp] +definition if_true {A : Type} (t e : A) : (if true then t else e) = t := if_pos trivial -definition if_false [simp] {A : Type} (t e : A) : (if false then t else e) = e := +attribute [simp] +definition if_false {A : Type} (t e : A) : (if false then t else e) = e := if_neg not_false theorem if_ctx_congr_prop {b c x y u v : Prop} [dec_b : decidable b] [dec_c : decidable c] @@ -877,7 +962,8 @@ decidable.rec_on dec_b ... ↔ u : h_t (iff.mp h_c hp) ... ↔ ite c u v : eq.subst (if_pos (iff.mp h_c hp)) (iff.refl (ite c u v))) -theorem if_congr_prop [congr] {b c x y u v : Prop} [dec_b : decidable b] [dec_c : decidable c] +attribute [congr] +theorem if_congr_prop {b c x y u v : Prop} [dec_b : decidable b] [dec_c : decidable c] (h_c : b ↔ c) (h_t : x ↔ u) (h_e : y ↔ v) : ite b x y ↔ ite c u v := if_ctx_congr_prop h_c (λ h, h_t) (λ h, h_e) @@ -887,7 +973,8 @@ theorem if_ctx_simp_congr_prop {b c x y u v : Prop} [dec_b : decidable b] ite b x y ↔ (@ite c (decidable_of_decidable_of_iff dec_b h_c) Prop u v) := @if_ctx_congr_prop b c x y u v dec_b (decidable_of_decidable_of_iff dec_b h_c) h_c h_t h_e -theorem if_simp_congr_prop [congr] {b c x y u v : Prop} [dec_b : decidable b] +attribute [congr] +theorem if_simp_congr_prop {b c x y u v : Prop} [dec_b : decidable b] (h_c : b ↔ c) (h_t : x ↔ u) (h_e : y ↔ v) : ite b x y ↔ (@ite c (decidable_of_decidable_of_iff dec_b h_c) Prop u v) := @if_ctx_simp_congr_prop b c x y u v dec_b h_c (λ h, h_t) (λ h, h_e) diff --git a/library/init/meta/environment.lean b/library/init/meta/environment.lean index 33fb7a78c5..a2bd2c2af7 100644 --- a/library/init/meta/environment.lean +++ b/library/init/meta/environment.lean @@ -72,8 +72,10 @@ match (refl_for env (const_name f)) with end end environment -meta_definition environment.has_to_string [instance] : has_to_string environment := +attribute [instance] +meta_definition environment.has_to_string : has_to_string environment := has_to_string.mk (λ e, "[environment]") -meta_definition environment.is_inhabited [instance] : inhabited environment := +attribute [instance] +meta_definition environment.is_inhabited : inhabited environment := inhabited.mk (environment.mk_std 0) diff --git a/library/init/meta/exceptional.lean b/library/init/meta/exceptional.lean index a010fd5a74..7f86aa116c 100644 --- a/library/init/meta/exceptional.lean +++ b/library/init/meta/exceptional.lean @@ -22,29 +22,35 @@ protected meta_definition exceptional.to_string : exceptional A → string | (success a) := to_string a | (exception ⌞A⌟ e) := "Exception: " ++ to_string (e options.mk) -protected meta_definition exceptional.has_to_string [instance] : has_to_string (exceptional A) := +attribute [instance] +protected meta_definition exceptional.has_to_string : has_to_string (exceptional A) := has_to_string.mk exceptional.to_string end namespace exceptional variables {A B : Type} -protected meta_definition fmap [inline] (f : A → B) (e : exceptional A) : exceptional B := +attribute [inline] +protected meta_definition fmap (f : A → B) (e : exceptional A) : exceptional B := exceptional.cases_on e (λ a, success (f a)) (λ f, exception B f) -protected meta_definition bind [inline] (e₁ : exceptional A) (e₂ : A → exceptional B) : exceptional B := +attribute [inline] +protected meta_definition bind (e₁ : exceptional A) (e₂ : A → exceptional B) : exceptional B := exceptional.cases_on e₁ (λ a, e₂ a) (λ f, exception B f) -protected meta_definition return [inline] (a : A) : exceptional A := +attribute [inline] +protected meta_definition return (a : A) : exceptional A := success a -meta_definition fail [inline] (f : format) : exceptional A := +attribute [inline] +meta_definition fail (f : format) : exceptional A := exception A (λ u, f) end exceptional -meta_definition exceptional.is_monad [instance] : monad exceptional := +attribute [instance] +meta_definition exceptional.is_monad : monad exceptional := monad.mk @exceptional.fmap @exceptional.return @exceptional.bind diff --git a/library/init/meta/expr.lean b/library/init/meta/expr.lean index 38fcc386f5..f61ce5e847 100644 --- a/library/init/meta/expr.lean +++ b/library/init/meta/expr.lean @@ -24,7 +24,8 @@ inductive expr := | elet : name → expr → expr → expr → expr | macro : macro_def → ∀ n : unsigned, (fin (unsigned.to_nat n) → expr) → expr -definition expr.is_inhabited [instance] : inhabited expr := +attribute [instance] +definition expr.is_inhabited : inhabited expr := inhabited.mk (expr.sort level.zero) meta_constant expr.mk_macro (d : macro_def) : list expr → expr @@ -37,7 +38,8 @@ meta_constant expr.alpha_eqv : expr → expr → bool notation a ` =ₐ `:50 b:50 := expr.alpha_eqv a b = bool.tt meta_constant expr.to_string : expr → string -meta_definition expr.has_to_string [instance] : has_to_string expr := +attribute [instance] +meta_definition expr.has_to_string : has_to_string expr := has_to_string.mk expr.to_string meta_constant expr.hash : expr → nat diff --git a/library/init/meta/format.lean b/library/init/meta/format.lean index f37406d7b4..fb227ae5df 100644 --- a/library/init/meta/format.lean +++ b/library/init/meta/format.lean @@ -26,28 +26,34 @@ meta_constant format.is_nil : format → bool meta_constant trace_fmt {A : Type} : format → (unit → A) → A -meta_definition format.is_inhabited [instance] : inhabited format := +attribute [instance] +meta_definition format.is_inhabited : inhabited format := inhabited.mk format.space -meta_definition format_has_append [instance] : has_append format := +attribute [instance] +meta_definition format_has_append : has_append format := has_append.mk format.compose -meta_definition format_has_to_string [instance] : has_to_string format := +attribute [instance] +meta_definition format_has_to_string : has_to_string format := has_to_string.mk (λ f, format.to_string f options.mk) structure has_to_format [class] (A : Type) := (to_format : A → format) -meta_definition format_has_to_format [instance] : has_to_format format := +attribute [instance] +meta_definition format_has_to_format : has_to_format format := has_to_format.mk id meta_definition to_fmt {A : Type} [has_to_format A] : A → format := has_to_format.to_format -meta_definition coe_nat_to_format [instance] : has_coe nat format := +attribute [instance] +meta_definition coe_nat_to_format : has_coe nat format := has_coe.mk format.of_nat -meta_definition coe_string_to_format [instance] : has_coe string format := +attribute [instance] +meta_definition coe_string_to_format : has_coe string format := has_coe.mk format.of_string open format list @@ -56,22 +62,28 @@ meta_definition format.when {A : Type} [has_to_format A] : bool → A → format | tt a := to_fmt a | ff a := nil -meta_definition options.has_to_format [instance] : has_to_format options := +attribute [instance] +meta_definition options.has_to_format : has_to_format options := has_to_format.mk (λ o, format.of_options o) -meta_definition bool.has_to_format [instance] : has_to_format bool := +attribute [instance] +meta_definition bool.has_to_format : has_to_format bool := has_to_format.mk (λ b, if b = tt then of_string "tt" else of_string "ff") -meta_definition decidable.has_to_format [instance] {p : Prop} : has_to_format (decidable p) := +attribute [instance] +meta_definition decidable.has_to_format {p : Prop} : has_to_format (decidable p) := has_to_format.mk (λ b, if p then of_string "tt" else of_string "ff") -meta_definition string.has_to_format [instance] : has_to_format string := +attribute [instance] +meta_definition string.has_to_format : has_to_format string := has_to_format.mk (λ s, format.of_string s) -meta_definition nat.has_to_format [instance] : has_to_format nat := +attribute [instance] +meta_definition nat.has_to_format : has_to_format nat := has_to_format.mk (λ n, format.of_nat n) -meta_definition char.has_to_format [instance] : has_to_format char := +attribute [instance] +meta_definition char.has_to_format : has_to_format char := has_to_format.mk (λ c : char, format.of_string [c]) meta_definition list.to_format_aux {A : Type} [has_to_format A] : bool → list A → format @@ -83,41 +95,49 @@ meta_definition list.to_format {A : Type} [has_to_format A] : list A → format | [] := to_fmt "[]" | (x::xs) := to_fmt "[" ++ group (nest 1 (list.to_format_aux tt (x::xs))) ++ to_fmt "]" -meta_definition list.has_to_format [instance] {A : Type} [has_to_format A] : has_to_format (list A) := +attribute [instance] +meta_definition list.has_to_format {A : Type} [has_to_format A] : has_to_format (list A) := has_to_format.mk list.to_format attribute [instance] string.has_to_format -meta_definition name.has_to_format [instance] : has_to_format name := +attribute [instance] +meta_definition name.has_to_format : has_to_format name := has_to_format.mk (λ n, to_fmt (to_string n)) -meta_definition unit.has_to_format [instance] : has_to_format unit := +attribute [instance] +meta_definition unit.has_to_format : has_to_format unit := has_to_format.mk (λ u, to_fmt "()") -meta_definition option.has_to_format [instance] {A : Type} [has_to_format A] : has_to_format (option A) := +attribute [instance] +meta_definition option.has_to_format {A : Type} [has_to_format A] : has_to_format (option A) := has_to_format.mk (λ o, option.cases_on o (to_fmt "none") (λ a, to_fmt "(some " ++ nest 6 (to_fmt a) ++ to_fmt ")")) -meta_definition sum.has_to_format [instance] {A B : Type} [has_to_format A] [has_to_format B] : has_to_format (sum A B) := +attribute [instance] +meta_definition sum.has_to_format {A B : Type} [has_to_format A] [has_to_format B] : has_to_format (sum A B) := has_to_format.mk (λ s, sum.cases_on s (λ a, to_fmt "(inl " ++ nest 5 (to_fmt a) ++ to_fmt ")") (λ b, to_fmt "(inr " ++ nest 5 (to_fmt b) ++ to_fmt ")")) open prod -meta_definition prod.has_to_format [instance] {A B : Type} [has_to_format A] [has_to_format B] : has_to_format (prod A B) := +attribute [instance] +meta_definition prod.has_to_format {A B : Type} [has_to_format A] [has_to_format B] : has_to_format (prod A B) := has_to_format.mk (λ p, group (nest 1 (to_fmt "(" ++ to_fmt (pr1 p) ++ to_fmt "," ++ line ++ to_fmt (pr2 p) ++ to_fmt ")"))) open sigma -meta_definition sigma.has_to_format [instance] {A : Type} {B : A → Type} [has_to_format A] [s : ∀ x, has_to_format (B x)] +attribute [instance] +meta_definition sigma.has_to_format {A : Type} {B : A → Type} [has_to_format A] [s : ∀ x, has_to_format (B x)] : has_to_format (sigma B) := has_to_format.mk (λ p, group (nest 1 (to_fmt "⟨" ++ to_fmt (pr1 p) ++ to_fmt "," ++ line ++ to_fmt (pr2 p) ++ to_fmt "⟩"))) open subtype -meta_definition subtype.has_to_format [instance] {A : Type} {P : A → Prop} [has_to_format A] : has_to_format (subtype P) := +attribute [instance] +meta_definition subtype.has_to_format {A : Type} {P : A → Prop} [has_to_format A] : has_to_format (subtype P) := has_to_format.mk (λ s, to_fmt (elt_of s)) meta_definition format.bracket : string → string → format → format diff --git a/library/init/meta/fun_info.lean b/library/init/meta/fun_info.lean index 087322c6c4..01697eb335 100644 --- a/library/init/meta/fun_info.lean +++ b/library/init/meta/fun_info.lean @@ -34,7 +34,8 @@ group ∘ cbrace $ when d "has_fwd_deps" +++ when (to_bool (length ds > 0)) (to_fmt "back_deps := " ++ to_fmt ds) -meta_definition param_info.has_to_format [instance] : has_to_format param_info := +attribute [instance] +meta_definition param_info.has_to_format : has_to_format param_info := has_to_format.mk param_info.to_format structure fun_info := @@ -47,7 +48,8 @@ group ∘ dcbrace $ ppfield "params" ps +++ ppfield "result_deps" ds -meta_definition fun_info_has_to_format [instance] : has_to_format fun_info := +attribute [instance] +meta_definition fun_info_has_to_format : has_to_format fun_info := has_to_format.mk fun_info_to_format /- @@ -82,7 +84,8 @@ group ∘ cbrace $ when s "specialized" +++ when ss "subsingleton" -meta_definition subsingleton_info_has_to_format [instance] : has_to_format subsingleton_info := +attribute [instance] +meta_definition subsingleton_info_has_to_format : has_to_format subsingleton_info := has_to_format.mk subsingleton_info_to_format namespace tactic diff --git a/library/init/meta/level.lean b/library/init/meta/level.lean index 181a29d366..60436b307d 100644 --- a/library/init/meta/level.lean +++ b/library/init/meta/level.lean @@ -16,7 +16,8 @@ inductive level := | global : name → level | meta : name → level -definition level.is_inhabited [instance] : inhabited level := +attribute [instance] +definition level.is_inhabited : inhabited level := inhabited.mk level.zero /- TODO(Leo): provide a definition in Lean. -/ @@ -42,13 +43,16 @@ if level.lt a b = bool.tt then ordering.lt else if a = b then ordering.eq else ordering.gt -meta_definition level.has_to_string [instance] : has_to_string level := +attribute [instance] +meta_definition level.has_to_string : has_to_string level := has_to_string.mk level.to_string -meta_definition level.has_to_format [instance] : has_to_format level := +attribute [instance] +meta_definition level.has_to_format : has_to_format level := has_to_format.mk (λ l, level.to_format l options.mk) -meta_definition level.has_to_cmp [instance] : has_ordering level := +attribute [instance] +meta_definition level.has_to_cmp : has_ordering level := has_ordering.mk level.cmp meta_definition level.of_nat : nat → level diff --git a/library/init/meta/name.lean b/library/init/meta/name.lean index 18e68b14a9..5b9c2771cc 100644 --- a/library/init/meta/name.lean +++ b/library/init/meta/name.lean @@ -12,7 +12,8 @@ inductive name := | mk_string : string → name → name | mk_numeral : unsigned → name → name -definition name.is_inhabited [instance] : inhabited name := +attribute [instance] +definition name.is_inhabited : inhabited name := inhabited.mk name.anonymous definition mk_str_name (n : name) (s : string) : name := @@ -24,7 +25,8 @@ name.mk_numeral (unsigned.of_nat v) n definition mk_simple_name (s : string) : name := mk_str_name name.anonymous s -definition coe_string_to_name [instance] : has_coe string name := +attribute [instance] +definition coe_string_to_name : has_coe string name := has_coe.mk mk_simple_name infix ` <.> `:65 := mk_str_name @@ -43,7 +45,8 @@ definition name.to_string : name → string | (mk_string s n) := name.to_string n ++ "." ++ s | (mk_numeral v n) := name.to_string n ++ "." ++ to_string v -definition name.has_to_string [instance] : has_to_string name := +attribute [instance] +definition name.has_to_string : has_to_string name := has_to_string.mk name.to_string /- TODO(Leo): provide a definition in Lean. -/ @@ -54,7 +57,8 @@ meta_constant name.lex_cmp : name → name → ordering attribute [instance] name.has_decidable_eq -meta_definition name_has_ordering [instance] : has_ordering name := +attribute [instance] +meta_definition name_has_ordering : has_ordering name := has_ordering.mk name.cmp /- (name.append_after n i) return a name of the form n_i -/ diff --git a/library/init/meta/occurrences.lean b/library/init/meta/occurrences.lean index a6341999c5..36e0eb6eba 100644 --- a/library/init/meta/occurrences.lean +++ b/library/init/meta/occurrences.lean @@ -25,7 +25,8 @@ inductive occurrences := open occurrences -definition occurrences_is_inhabited [instance] : inhabited occurrences := +attribute [instance] +definition occurrences_is_inhabited : inhabited occurrences := inhabited.mk all definition occurrences_to_string : occurrences → string @@ -33,7 +34,8 @@ definition occurrences_to_string : occurrences → string | (occurrences.pos l) := to_string l | (occurrences.neg l) := "-" ++ to_string l -definition occurrences_has_to_string [instance] : has_to_string occurrences := +attribute [instance] +definition occurrences_has_to_string : has_to_string occurrences := has_to_string.mk occurrences_to_string meta_definition occurrences_to_format : occurrences → format @@ -41,7 +43,8 @@ meta_definition occurrences_to_format : occurrences → format | (occurrences.pos l) := to_fmt l | (occurrences.neg l) := to_fmt "-" ++ to_fmt l -meta_definition occurrences_has_to_format [instance] : has_to_format occurrences := +attribute [instance] +meta_definition occurrences_has_to_format : has_to_format occurrences := has_to_format.mk occurrences_to_format open decidable tactic diff --git a/library/init/meta/options.lean b/library/init/meta/options.lean index 58609036ce..67e99d7135 100644 --- a/library/init/meta/options.lean +++ b/library/init/meta/options.lean @@ -22,8 +22,10 @@ meta_constant options.has_decidable_eq : decidable_eq options attribute [instance] options.has_decidable_eq -meta_definition options.has_add [instance] : has_add options := +attribute [instance] +meta_definition options.has_add : has_add options := has_add.mk options.join -meta_definition options.is_inhabited [instance] : inhabited options := +attribute [instance] +meta_definition options.is_inhabited : inhabited options := inhabited.mk options.mk diff --git a/library/init/meta/pexpr.lean b/library/init/meta/pexpr.lean index e85b6bc041..e771a22f1c 100644 --- a/library/init/meta/pexpr.lean +++ b/library/init/meta/pexpr.lean @@ -12,7 +12,8 @@ protected meta_constant pexpr.of_expr : expr → pexpr protected meta_constant pexpr.subst : pexpr → pexpr → pexpr meta_constant pexpr.to_string : pexpr → string -meta_definition pexpr.has_to_string [instance] : has_to_string pexpr := +attribute [instance] +meta_definition pexpr.has_to_string : has_to_string pexpr := has_to_string.mk pexpr.to_string structure has_to_pexpr [class] (A : Type) := @@ -21,8 +22,10 @@ structure has_to_pexpr [class] (A : Type) := meta_definition to_pexpr {A : Type} [has_to_pexpr A] : A → pexpr := has_to_pexpr.to_pexpr -meta_definition pexpr.has_to_pexpr [instance] : has_to_pexpr pexpr := +attribute [instance] +meta_definition pexpr.has_to_pexpr : has_to_pexpr pexpr := has_to_pexpr.mk id -meta_definition expr.has_to_pexpr [instance] : has_to_pexpr expr := +attribute [instance] +meta_definition expr.has_to_pexpr : has_to_pexpr expr := has_to_pexpr.mk pexpr.of_expr diff --git a/library/init/meta/rb_map.lean b/library/init/meta/rb_map.lean index 1751bf1132..8ddf8b89be 100644 --- a/library/init/meta/rb_map.lean +++ b/library/init/meta/rb_map.lean @@ -19,7 +19,8 @@ meta_constant min {key : Type} {data : Type} : rb_map key data → op meta_constant max {key : Type} {data : Type} : rb_map key data → option data meta_constant fold {key : Type} {data : Type} {A :Type} : rb_map key data → A → (key → data → A → A) → A -meta_definition mk [inline] (key : Type) [has_ordering key] (data : Type) : rb_map key data := +attribute [inline] +meta_definition mk (key : Type) [has_ordering key] (data : Type) : rb_map key data := mk_core data has_ordering.cmp open list @@ -29,19 +30,23 @@ meta_definition of_list {key : Type} {data : Type} [has_ordering key] : list (ke end rb_map -meta_definition nat_map [reducible] (data : Type) := rb_map nat data +attribute [reducible] +meta_definition nat_map (data : Type) := rb_map nat data namespace nat_map export rb_map (hiding mk) - meta_definition mk [inline] (data : Type) : nat_map data := + attribute [inline] + meta_definition mk (data : Type) : nat_map data := rb_map.mk nat data end nat_map -meta_definition name_map [reducible] (data : Type) := rb_map name data +attribute [reducible] +meta_definition name_map (data : Type) := rb_map name data namespace name_map export rb_map (hiding mk) - meta_definition mk [inline] (data : Type) : name_map data := + attribute [inline] + meta_definition mk (data : Type) : name_map data := rb_map.mk name data end name_map @@ -52,7 +57,8 @@ variables {key : Type} {data : Type} [has_to_format key] [has_to_format data] private meta_definition format_key_data (k : key) (d : data) (first : bool) : format := (if first = tt then to_fmt "" else to_fmt "," ++ line) ++ to_fmt k ++ space ++ to_fmt "←" ++ space ++ to_fmt d -meta_definition rb_map_has_to_format [instance] : has_to_format (rb_map key data) := +attribute [instance] +meta_definition rb_map_has_to_format : has_to_format (rb_map key data) := has_to_format.mk (λ m, group (to_fmt "⟨" ++ nest 1 (pr₁ (fold m (to_fmt "", tt) (λ k d p, (pr₁ p ++ format_key_data k d (pr₂ p), ff)))) ++ to_fmt "⟩")) @@ -63,7 +69,8 @@ variables {key : Type} {data : Type} [has_to_string key] [has_to_string data] private meta_definition key_data_to_string (k : key) (d : data) (first : bool) : string := (if first = tt then "" else ", ") ++ to_string k ++ " ← " ++ to_string d -meta_definition rb_map_has_to_string [instance] : has_to_string (rb_map key data) := +attribute [instance] +meta_definition rb_map_has_to_string : has_to_string (rb_map key data) := has_to_string.mk (λ m, "⟨" ++ (pr₁ (fold m ("", tt) (λ k d p, (pr₁ p ++ key_data_to_string k d (pr₂ p), ff)))) ++ "⟩") end diff --git a/library/init/meta/tactic.lean b/library/init/meta/tactic.lean index 41338b4e6f..cd214fa323 100644 --- a/library/init/meta/tactic.lean +++ b/library/init/meta/tactic.lean @@ -19,7 +19,8 @@ meta_constant get_options : tactic_state → options meta_constant set_options : tactic_state → options → tactic_state end tactic_state -meta_definition tactic_state.has_to_format [instance] : has_to_format tactic_state := +attribute [instance] +meta_definition tactic_state.has_to_format : has_to_format tactic_state := has_to_format.mk tactic_state.to_format inductive tactic_result (A : Type) := @@ -36,27 +37,32 @@ meta_definition tactic_result_to_string : tactic_result A → string | (success a s) := to_string a | (exception ⌞A⌟ e s) := "Exception: " ++ to_string (e ()) -meta_definition tactic_result_has_to_string [instance] : has_to_string (tactic_result A) := +attribute [instance] +meta_definition tactic_result_has_to_string : has_to_string (tactic_result A) := has_to_string.mk tactic_result_to_string end -meta_definition tactic [reducible] (A : Type) := +attribute [reducible] +meta_definition tactic (A : Type) := tactic_state → tactic_result A section variables {A B : Type} -meta_definition tactic_fmap [inline] (f : A → B) (t : tactic A) : tactic B := +attribute [inline] +meta_definition tactic_fmap (f : A → B) (t : tactic A) : tactic B := λ s, tactic_result.cases_on (t s) (λ a s', success (f a) s') (λ e s', exception B e s') -meta_definition tactic_bind [inline] (t₁ : tactic A) (t₂ : A → tactic B) : tactic B := +attribute [inline] +meta_definition tactic_bind (t₁ : tactic A) (t₂ : A → tactic B) : tactic B := λ s, tactic_result.cases_on (t₁ s) (λ a s', t₂ a s') (λ e s', exception B e s') -meta_definition tactic_return [inline] (a : A) : tactic A := +attribute [inline] +meta_definition tactic_return (a : A) : tactic A := λ s, success a s meta_definition tactic_orelse {A : Type} (t₁ t₂ : tactic A) : tactic A := @@ -67,7 +73,8 @@ meta_definition tactic_orelse {A : Type} (t₁ t₂ : tactic A) : tactic A := (exception A)) end -meta_definition tactic_is_monad [instance] : monad tactic := +attribute [instance] +meta_definition tactic_is_monad : monad tactic := monad.mk @tactic_fmap @tactic_return @tactic_bind meta_definition tactic.fail {A B : Type} [has_to_format B] (msg : B) : tactic A := @@ -76,7 +83,8 @@ meta_definition tactic.fail {A B : Type} [has_to_format B] (msg : B) : tactic A meta_definition tactic.failed {A : Type} : tactic A := tactic.fail "failed" -meta_definition tactic_is_alternative [instance] : alternative tactic := +attribute [instance] +meta_definition tactic_is_alternative : alternative tactic := alternative.mk @tactic_fmap (λ A a s, success a s) (@fapp _ _) @tactic.failed @tactic_orelse namespace tactic @@ -127,10 +135,12 @@ meta_definition decorate_ex (msg : format) (t : tactic A) : tactic A := success (λ e, exception A (λ u, msg ++ format.nest 2 (format.line ++ e u))) -meta_definition write [inline] (s' : tactic_state) : tactic unit := +attribute [inline] +meta_definition write (s' : tactic_state) : tactic unit := λ s, success () s' -meta_definition read [inline] : tactic tactic_state := +attribute [inline] +meta_definition read : tactic tactic_state := λ s, success s s end tactic @@ -140,7 +150,8 @@ do s ← tactic.read, return (tactic_state.format_expr s e) structure has_to_tactic_format [class] (A : Type) := (to_tactic_format : A → tactic format) -meta_definition expr_has_to_tactic_format [instance] : has_to_tactic_format expr := +attribute [instance] +meta_definition expr_has_to_tactic_format : has_to_tactic_format expr := has_to_tactic_format.mk tactic_format_expr meta_definition tactic.pp {A : Type} [has_to_tactic_format A] : A → tactic format := @@ -161,10 +172,12 @@ meta_definition list_to_tactic_format {A : Type} [has_to_tactic_format A] : list f ← list_to_tactic_format_aux tt (x::xs), return $ to_fmt "[" ++ group (nest 1 f) ++ to_fmt "]" -meta_definition list_has_to_tactic_format [instance] {A : Type} [has_to_tactic_format A] : has_to_tactic_format (list A) := +attribute [instance] +meta_definition list_has_to_tactic_format {A : Type} [has_to_tactic_format A] : has_to_tactic_format (list A) := has_to_tactic_format.mk list_to_tactic_format -meta_definition has_to_format_to_has_to_tactic_format [instance] (A : Type) [has_to_format A] : has_to_tactic_format A := +attribute [instance] +meta_definition has_to_format_to_has_to_tactic_format (A : Type) [has_to_format A] : has_to_tactic_format A := has_to_tactic_format.mk (return ∘ to_fmt) namespace tactic @@ -479,7 +492,8 @@ do g::gs ← get_goals | failed, gs' ← get_goals, set_goals (gs' ++ gs) -meta_definition tactic_has_andthen [instance] : has_andthen (tactic unit) := +attribute [instance] +meta_definition tactic_has_andthen : has_andthen (tactic unit) := has_andthen.mk seq /- Applies tac if c holds -/ diff --git a/library/init/monad.lean b/library/init/monad.lean index 6d69ceed2a..522fdbd8f7 100644 --- a/library/init/monad.lean +++ b/library/init/monad.lean @@ -10,7 +10,8 @@ structure monad [class] (m : Type → Type) extends functor m : Type := (ret : Π {a:Type}, a → m a) (bind : Π {a b: Type}, m a → (a → m b) → m b) -definition return [inline] {m : Type → Type} [monad m] {A : Type} (a : A) : m A := +attribute [inline] +definition return {m : Type → Type} [monad m] {A : Type} (a : A) : m A := monad.ret m a definition fapp {m : Type → Type} [monad m] {A B : Type} (f : m (A → B)) (a : m A) : m B := @@ -18,10 +19,12 @@ do g ← f, b ← a, return (g b) -definition monad_is_applicative [inline] [instance] (m : Type → Type) [monad m] : applicative m := +attribute [inline] [instance] +definition monad_is_applicative (m : Type → Type) [monad m] : applicative m := applicative.mk (@monad.map _ _) (@monad.ret _ _) (@fapp _ _) -definition monad.and_then [inline] {A B : Type} {m : Type → Type} [monad m] (a : m A) (b : m B) : m B := +attribute [inline] +definition monad.and_then {A B : Type} {m : Type → Type} [monad m] (a : m A) (b : m B) : m B := do a, b infixl ` >>= `:2 := monad.bind diff --git a/library/init/nat.lean b/library/init/nat.lean index 6fe62f62d9..9a3bb49536 100644 --- a/library/init/nat.lean +++ b/library/init/nat.lean @@ -10,7 +10,8 @@ open decidable or notation `ℕ` := nat namespace nat - protected definition rec_on [reducible] + attribute [reducible] + protected definition rec_on {C : ℕ → Type} (n : ℕ) (H₁ : C 0) (H₂ : Π (a : ℕ), C a → C (succ a)) : C n := nat.rec H₁ H₂ n @@ -18,19 +19,22 @@ namespace nat {C : ℕ → Prop} (n : ℕ) (H₁ : C 0) (H₂ : Π (a : ℕ), C a → C (succ a)) : C n := nat.rec H₁ H₂ n - protected definition cases_on [reducible] + attribute [reducible] + protected definition cases_on {C : ℕ → Type} (n : ℕ) (H₁ : C 0) (H₂ : Π (a : ℕ), C (succ a)) : C n := nat.rec H₁ (λ a ih, H₂ a) n attribute nat.rec_on [recursor] -- Hack: force rec_on to be the first one. TODO(Leo): we should add priorities to recursors - protected definition no_confusion_type [reducible] (P : Type) (v₁ v₂ : ℕ) : Type := + attribute [reducible] + protected definition no_confusion_type (P : Type) (v₁ v₂ : ℕ) : Type := nat.rec (nat.rec (P → P) (λ a₂ ih, P) v₂) (λ a₁ ih, nat.rec P (λ a₂ ih, (a₁ = a₂ → P) → P) v₂) v₁ - protected definition no_confusion [reducible] [unfold 4] + attribute [reducible] [unfold 4] + protected definition no_confusion {P : Type} {v₁ v₂ : ℕ} (H : v₁ = v₂) : nat.no_confusion_type P v₁ v₂ := have v₁ = v₁ → nat.no_confusion_type P v₁ v₁, from λ H₁ : v₁ = v₁, nat.rec (λ h, h) (λ a ih h, h (eq.refl a)) v₁, @@ -47,13 +51,16 @@ namespace nat local attribute [instance] [priority nat.prio] nat_has_le - protected lemma le_refl [refl] : ∀ a : nat, a ≤ a := + attribute [refl] + protected lemma le_refl : ∀ a : nat, a ≤ a := le.nat_refl - protected definition lt [reducible] (n m : ℕ) := succ n ≤ m + attribute [reducible] + protected definition lt (n m : ℕ) := succ n ≤ m definition nat_has_lt : has_lt nat := has_lt.mk nat.lt - definition pred [unfold 1] (a : nat) : nat := + attribute [unfold 1] + definition pred (a : nat) : nat := nat.cases_on a zero (λ a₁, a₁) -- add is defined in init.reserved_notation @@ -98,10 +105,12 @@ namespace nat | 0 := le.nat_refl 0 | (succ a) := le.step (le.nat_refl a) - theorem le_succ_iff_true [simp] (n : ℕ) : n ≤ succ n ↔ true := + attribute [simp] + theorem le_succ_iff_true (n : ℕ) : n ≤ succ n ↔ true := iff_true_intro (le_succ n) - theorem pred_le_iff_true [simp] (n : ℕ) : pred n ≤ n ↔ true := + attribute [simp] + theorem pred_le_iff_true (n : ℕ) : pred n ≤ n ↔ true := iff_true_intro (pred_le n) protected theorem le_trans {n m k : ℕ} (H1 : n ≤ m) : m ≤ k → n ≤ k := @@ -142,13 +151,15 @@ namespace nat theorem not_succ_le_self : Π {n : ℕ}, ¬succ n ≤ n := nat.rec (not_succ_le_zero 0) (λa b c, b (le_of_succ_le_succ c)) - theorem succ_le_self_iff_false [simp] (n : ℕ) : succ n ≤ n ↔ false := + attribute [simp] + theorem succ_le_self_iff_false (n : ℕ) : succ n ≤ n ↔ false := iff_false_intro not_succ_le_self theorem zero_le : ∀ (n : ℕ), 0 ≤ n := nat.rec (nat.le_refl 0) (λa, le.step) - theorem zero_le_iff_true [simp] (n : ℕ) : 0 ≤ n ↔ true := + attribute [simp] + theorem zero_le_iff_true (n : ℕ) : 0 ≤ n ↔ true := iff_true_intro (zero_le n) theorem lt.step {n m : ℕ} : n < m → n < succ m := le.step @@ -156,7 +167,8 @@ namespace nat theorem zero_lt_succ (n : ℕ) : 0 < succ n := succ_le_succ (zero_le n) - theorem zero_lt_succ_iff_true [simp] (n : ℕ) : 0 < succ n ↔ true := + attribute [simp] + theorem zero_lt_succ_iff_true (n : ℕ) : 0 < succ n ↔ true := iff_true_intro (zero_lt_succ n) protected theorem lt_trans {n m k : ℕ} (H1 : n < m) : m < k → n < k := @@ -174,7 +186,8 @@ namespace nat theorem self_lt_succ (n : ℕ) : n < succ n := nat.le_refl (succ n) - theorem self_lt_succ_iff_true [simp] (n : ℕ) : n < succ n ↔ true := + attribute [simp] + theorem self_lt_succ_iff_true (n : ℕ) : n < succ n ↔ true := iff_true_intro (self_lt_succ n) theorem lt.base (n : ℕ) : n < succ n := nat.le_refl (succ n) @@ -193,7 +206,8 @@ namespace nat theorem not_lt_zero (a : ℕ) : ¬ a < 0 := not_succ_le_zero a - theorem lt_zero_iff_false [simp] (a : ℕ) : a < 0 ↔ false := + attribute [simp] + theorem lt_zero_iff_false (a : ℕ) : a < 0 ↔ false := iff_false_intro (not_lt_zero a) protected theorem eq_or_lt_of_le {a b : ℕ} (H : a ≤ b) : a = b ∨ a < b := @@ -254,7 +268,8 @@ namespace nat theorem succ_le_of_lt {a b : ℕ} (h : a < b) : succ a ≤ b := h - theorem succ_sub_succ_eq_sub [simp] (a b : ℕ) : succ a - succ b = a - b := + attribute [simp] + theorem succ_sub_succ_eq_sub (a b : ℕ) : succ a - succ b = a - b := nat.rec_on b (show succ a - succ zero = a - zero, from (eq.refl (succ a - succ zero))) (λ b, congr_arg pred) @@ -262,7 +277,8 @@ namespace nat theorem sub_eq_succ_sub_succ (a b : ℕ) : a - b = succ a - succ b := eq.symm (succ_sub_succ_eq_sub a b) - theorem zero_sub_eq_zero [simp] (a : ℕ) : 0 - a = 0 := + attribute [simp] + theorem zero_sub_eq_zero (a : ℕ) : 0 - a = 0 := nat.rec rfl (λ a, congr_arg pred) a theorem zero_eq_zero_sub (a : ℕ) : 0 = 0 - a := @@ -271,7 +287,8 @@ namespace nat theorem sub_le (a b : ℕ) : a - b ≤ a := nat.rec_on b (nat.le_refl (a - 0)) (λ b₁, nat.le_trans (pred_le (a - b₁))) - theorem sub_le_iff_true [simp] (a b : ℕ) : a - b ≤ a ↔ true := + attribute [simp] + theorem sub_le_iff_true (a b : ℕ) : a - b ≤ a ↔ true := iff_true_intro (sub_le a b) theorem sub_lt {a b : ℕ} (H1 : 0 < a) (H2 : 0 < b) : a - b < a := @@ -284,7 +301,8 @@ namespace nat theorem sub_lt_succ (a b : ℕ) : a - b < succ a := lt_succ_of_le (sub_le a b) - theorem sub_lt_succ_iff_true [simp] (a b : ℕ) : a - b < succ a ↔ true := + attribute [simp] + theorem sub_lt_succ_iff_true (a b : ℕ) : a - b < succ a ↔ true := iff_true_intro (sub_lt_succ a b) definition repeat {A : Type} (f : nat → A → A) : nat → A → A @@ -293,7 +311,8 @@ namespace nat end nat -protected definition nat.is_inhabited [instance] : inhabited nat := +attribute [instance] +protected definition nat.is_inhabited : inhabited nat := inhabited.mk nat.zero attribute [recursor] nat.induction_on diff --git a/library/init/num.lean b/library/init/num.lean index 8f7b361387..7d88d94bc3 100644 --- a/library/init/num.lean +++ b/library/init/num.lean @@ -33,7 +33,8 @@ namespace pos_num pos_num.lt a (succ b) end pos_num -definition pos_num_has_mul [instance] : has_mul pos_num := +attribute [instance] +definition pos_num_has_mul : has_mul pos_num := has_mul.mk pos_num.mul namespace num @@ -49,7 +50,8 @@ namespace num num.rec_on a zero (λpa, num.rec_on b zero (λpb, pos (pos_num.mul pa pb))) end num -definition num_has_mul [instance] : has_mul num := +attribute [instance] +definition num_has_mul : has_mul num := has_mul.mk num.mul namespace num @@ -79,5 +81,6 @@ namespace num num.rec_on a zero (λpa, num.rec_on b a (λpb, psub pa pb)) end num -definition num_has_sub [instance] : has_sub num := +attribute [instance] +definition num_has_sub : has_sub num := has_sub.mk num.sub diff --git a/library/init/option.lean b/library/init/option.lean index 61ba9436b5..4ee7766b2c 100644 --- a/library/init/option.lean +++ b/library/init/option.lean @@ -8,10 +8,12 @@ import init.logic init.monad init.alternative open decidable -definition option_is_inhabited [instance] (A : Type) : inhabited (option A) := +attribute [instance] +definition option_is_inhabited (A : Type) : inhabited (option A) := inhabited.mk none -definition option_has_decidable_eq [instance] {A : Type} [H : decidable_eq A] : ∀ o₁ o₂ : option A, decidable (o₁ = o₂) +attribute [instance] +definition option_has_decidable_eq {A : Type} [H : decidable_eq A] : ∀ o₁ o₂ : option A, decidable (o₁ = o₂) | none none := tt rfl | none (some v₂) := ff (λ H, option.no_confusion H) | (some v₁) none := ff (λ H, option.no_confusion H) @@ -21,17 +23,20 @@ definition option_has_decidable_eq [instance] {A : Type} [H : decidable_eq A] : | (ff n) := ff (λ H, option.no_confusion H (λ e, absurd e n)) end -definition option_fmap [inline] {A B : Type} (f : A → B) (e : option A) : option B := +attribute [inline] +definition option_fmap {A B : Type} (f : A → B) (e : option A) : option B := option.cases_on e none (λ a, some (f a)) -definition option_bind [inline] {A B : Type} (a : option A) (b : A → option B) : option B := +attribute [inline] +definition option_bind {A B : Type} (a : option A) (b : A → option B) : option B := option.cases_on a none (λ a, b a) -definition option_is_monad [instance] : monad option := +attribute [instance] +definition option_is_monad : monad option := monad.mk @option_fmap @some @option_bind definition option_orelse {A : Type} : option A → option A → option A @@ -39,23 +44,28 @@ definition option_orelse {A : Type} : option A → option A → option A | none (some a) := some a | none none := none -definition option_is_alternative [instance] {A : Type} : alternative option := +attribute [instance] +definition option_is_alternative {A : Type} : alternative option := alternative.mk @option_fmap @some (@fapp _ _) @none @option_orelse definition optionT (m : Type → Type) [monad m] (A : Type) := m (option A) -definition optionT_fmap [inline] {m : Type → Type} [monad m] {A B : Type} (f : A → B) (e : optionT m A) : optionT m B := +attribute [inline] +definition optionT_fmap {m : Type → Type} [monad m] {A B : Type} (f : A → B) (e : optionT m A) : optionT m B := @monad.bind m _ _ _ e (λ a : option A, option.cases_on a (return none) (λ a, return (some (f a)))) -definition optionT_bind [inline] {m : Type → Type} [monad m] {A B : Type} (a : optionT m A) (b : A → optionT m B) +attribute [inline] +definition optionT_bind {m : Type → Type} [monad m] {A B : Type} (a : optionT m A) (b : A → optionT m B) : optionT m B := @monad.bind m _ _ _ a (λ a : option A, option.cases_on a (return none) (λ a, b a)) -definition optionT_return [inline] {m : Type → Type} [monad m] {A : Type} (a : A) : optionT m A := +attribute [inline] +definition optionT_return {m : Type → Type} [monad m] {A : Type} (a : A) : optionT m A := @monad.ret m _ _ (some a) -definition optionT_is_monad [instance] {m : Type → Type} [monad m] {A : Type} : monad (optionT m) := +attribute [instance] +definition optionT_is_monad {m : Type → Type} [monad m] {A : Type} : monad (optionT m) := monad.mk (@optionT_fmap m _) (@optionT_return m _) (@optionT_bind m _) definition optionT_orelse {m : Type → Type} [monad m] {A : Type} (a : optionT m A) (b : optionT m A) : optionT m A := @@ -64,7 +74,8 @@ definition optionT_orelse {m : Type → Type} [monad m] {A : Type} (a : optionT definition optionT_fail {m : Type → Type} [monad m] {A : Type} : optionT m A := @monad.ret m _ _ none -definition optionT_is_alternative [instance] {m : Type → Type} [monad m] {A : Type} : alternative (optionT m) := +attribute [instance] +definition optionT_is_alternative {m : Type → Type} [monad m] {A : Type} : alternative (optionT m) := alternative.mk (@optionT_fmap m _) (@optionT_return m _) diff --git a/library/init/ordering.lean b/library/init/ordering.lean index 144a81ba2a..45d0ba898b 100644 --- a/library/init/ordering.lean +++ b/library/init/ordering.lean @@ -11,7 +11,8 @@ inductive ordering := open ordering -definition ordering.has_to_string [instance] : has_to_string ordering := +attribute [instance] +definition ordering.has_to_string : has_to_string ordering := has_to_string.mk (λ s, match s with | ordering.lt := "lt" | ordering.eq := "eq" | ordering.gt := "gt" end) structure has_ordering [class] (A : Type) := @@ -22,7 +23,8 @@ if a < b then lt else if a = b then eq else gt -definition nat_has_ordering [instance] : has_ordering nat := +attribute [instance] +definition nat_has_ordering : has_ordering nat := has_ordering.mk nat.cmp section @@ -38,7 +40,8 @@ definition prod.cmp : A × B → A × B → ordering | ordering.gt := gt end -definition prod_has_ordering [instance] {A B : Type} [has_ordering A] [has_ordering B] : has_ordering (A × B) := +attribute [instance] +definition prod_has_ordering {A B : Type} [has_ordering A] [has_ordering B] : has_ordering (A × B) := has_ordering.mk prod.cmp end @@ -53,7 +56,8 @@ definition sum.cmp : sum A B → sum A B → ordering | (inl a₁) (inr b₂) := lt | (inr b₁) (inl a₂) := gt -definition sum_has_ordering [instance] {A B : Type} [has_ordering A] [has_ordering B] : has_ordering (sum A B) := +attribute [instance] +definition sum_has_ordering {A B : Type} [has_ordering A] [has_ordering B] : has_ordering (sum A B) := has_ordering.mk sum.cmp end @@ -68,6 +72,7 @@ definition option.cmp : option A → option A → ordering | none (some a₂) := lt | none none := eq -definition option_has_ordering [instance] {A : Type} [has_ordering A] : has_ordering (option A) := +attribute [instance] +definition option_has_ordering {A : Type} [has_ordering A] : has_ordering (option A) := has_ordering.mk option.cmp end diff --git a/library/init/prod.lean b/library/init/prod.lean index ee31a8f1cc..1bcd76bdb2 100644 --- a/library/init/prod.lean +++ b/library/init/prod.lean @@ -6,7 +6,8 @@ Author: Leonardo de Moura, Jeremy Avigad prelude import init.num init.relation -definition pair [constructor] := @prod.mk +attribute [constructor] +definition pair := @prod.mk notation A × B := prod A B -- notation for n-ary tuples notation `(` h `, ` t:(foldl `, ` (e r, prod.mk r e) h) `)` := t @@ -19,12 +20,14 @@ namespace prod end prod -protected definition prod.is_inhabited [instance] {A B : Type} [inhabited A] [inhabited B] : inhabited (prod A B) := +attribute [instance] +protected definition prod.is_inhabited {A B : Type} [inhabited A] [inhabited B] : inhabited (prod A B) := inhabited.mk (default A, default B) open decidable -protected definition prod.has_decidable_eq [instance] {A B : Type} [h₁ : decidable_eq A] [h₂ : decidable_eq B] : ∀ p₁ p₂ : A × B, decidable (p₁ = p₂) +attribute [instance] +protected definition prod.has_decidable_eq {A B : Type} [h₁ : decidable_eq A] [h₂ : decidable_eq B] : ∀ p₁ p₂ : A × B, decidable (p₁ = p₂) | (a, b) (a', b') := match (h₁ a a') with | (tt e₁) := diff --git a/library/init/quot.lean b/library/init/quot.lean index 25f7003ef1..63132690ef 100644 --- a/library/init/quot.lean +++ b/library/init/quot.lean @@ -14,7 +14,8 @@ constant quot.{l} : Π {A : Type.{l}}, setoid A → Type.{l} constant propext {a b : Prop} : (a ↔ b) → a = b -- iff can now be used to do substitutions in a calculation -theorem iff_subst [subst] {a b : Prop} {P : Prop → Prop} (H₁ : a ↔ b) (H₂ : P a) : P b := +attribute [subst] +theorem iff_subst {a b : Prop} {P : Prop → Prop} (H₁ : a ↔ b) (H₂ : P a) : P b := eq.subst (propext H₁) H₂ namespace quot @@ -33,7 +34,8 @@ namespace quot protected theorem ind_beta {A : Type} [s : setoid A] {B : quot s → Prop} (p : ∀ a, B ⟦a⟧) (a : A) : ind p ⟦a⟧ = p a := rfl - protected definition lift_on [reducible] {A B : Type} [s : setoid A] (q : quot s) (f : A → B) (c : ∀ a b, a ≈ b → f a = f b) : B := + attribute [reducible] + protected definition lift_on {A B : Type} [s : setoid A] (q : quot s) (f : A → B) (c : ∀ a b, a ≈ b → f a = f b) : B := lift f c q protected theorem induction_on {A : Type} [s : setoid A] {B : quot s → Prop} (q : quot s) (H : ∀ a, B ⟦a⟧) : B q := @@ -48,7 +50,8 @@ namespace quot variable {B : quot s → Type} include s - protected definition indep [reducible] (f : Π a, B ⟦a⟧) (a : A) : Σ q, B q := + attribute [reducible] + protected definition indep (f : Π a, B ⟦a⟧) (a : A) : Σ q, B q := sigma.mk ⟦a⟧ (f a) protected lemma indep_coherent (f : Π a, B ⟦a⟧) @@ -61,21 +64,25 @@ namespace quot (q : quot s) : (lift (quot.indep f) (quot.indep_coherent f H) q).1 = q := quot.ind (λ (a : A), eq.refl (quot.indep f a).1) q - protected definition rec [reducible] + attribute [reducible] + protected definition rec (f : Π a, B ⟦a⟧) (H : ∀ (a b : A) (p : a ≈ b), eq.rec (f a) (sound p) = f b) (q : quot s) : B q := let p := lift (quot.indep f) (quot.indep_coherent f H) q in eq.rec_on (quot.lift_indep_pr1 f H q) (p.2) - protected definition rec_on [reducible] + attribute [reducible] + protected definition rec_on (q : quot s) (f : Π a, B ⟦a⟧) (H : ∀ (a b : A) (p : a ≈ b), eq.rec (f a) (sound p) = f b) : B q := quot.rec f H q - protected definition rec_on_subsingleton [reducible] + attribute [reducible] + protected definition rec_on_subsingleton [H : ∀ a, subsingleton (B ⟦a⟧)] (q : quot s) (f : Π a, B ⟦a⟧) : B q := quot.rec f (λ a b h, subsingleton.elim _ (f b)) q - protected definition hrec_on [reducible] + attribute [reducible] + protected definition hrec_on (q : quot s) (f : Π a, B ⟦a⟧) (c : ∀ (a b : A) (p : a ≈ b), f a == f b) : B q := quot.rec_on q f (λ a b p, eq_of_heq (calc @@ -88,7 +95,8 @@ namespace quot variables [s₁ : setoid A] [s₂ : setoid B] include s₁ s₂ - protected definition lift₂ [reducible] + attribute [reducible] + protected definition lift₂ (f : A → B → C)(c : ∀ a₁ a₂ b₁ b₂, a₁ ≈ b₁ → a₂ ≈ b₂ → f a₁ a₂ = f b₁ b₂) (q₁ : quot s₁) (q₂ : quot s₂) : C := quot.lift @@ -103,7 +111,8 @@ namespace quot q₂) q₁ - protected definition lift_on₂ [reducible] + attribute [reducible] + protected definition lift_on₂ (q₁ : quot s₁) (q₂ : quot s₂) (f : A → B → C) (c : ∀ a₁ a₂ b₁ b₂, a₁ ≈ b₁ → a₂ ≈ b₂ → f a₁ a₂ = f b₁ b₂) : C := quot.lift₂ f c q₁ q₂ @@ -152,14 +161,16 @@ namespace quot include s₁ s₂ variable {C : quot s₁ → quot s₂ → Type} - protected definition rec_on_subsingleton₂ [reducible] + attribute [reducible] + protected definition rec_on_subsingleton₂ {C : quot s₁ → quot s₂ → Type₁} [H : ∀ a b, subsingleton (C ⟦a⟧ ⟦b⟧)] (q₁ : quot s₁) (q₂ : quot s₂) (f : Π a b, C ⟦a⟧ ⟦b⟧) : C q₁ q₂:= @quot.rec_on_subsingleton _ _ _ (λ a, quot.ind _ _) q₁ (λ a, quot.rec_on_subsingleton q₂ (λ b, f a b)) - protected definition hrec_on₂ [reducible] + attribute [reducible] + protected definition hrec_on₂ {C : quot s₁ → quot s₂ → Type₁} (q₁ : quot s₁) (q₂ : quot s₂) (f : Π a b, C ⟦a⟧ ⟦b⟧) (c : ∀ a₁ a₂ b₁ b₂, a₁ ≈ b₁ → a₂ ≈ b₂ → f a₁ a₂ == f b₁ b₂) : C q₁ q₂:= quot.hrec_on q₁ @@ -186,7 +197,8 @@ attribute quot.hrec_on₂ [unfold 6] attribute quot.rec_on_subsingleton₂ [unfold 7] open decidable -definition quot.has_decidable_eq [instance] {A : Type} {s : setoid A} [decR : ∀ a b : A, decidable (a ≈ b)] : decidable_eq (quot s) := +attribute [instance] +definition quot.has_decidable_eq {A : Type} {s : setoid A} [decR : ∀ a b : A, decidable (a ≈ b)] : decidable_eq (quot s) := λ q₁ q₂ : quot s, quot.rec_on_subsingleton₂ q₁ q₂ (λ a₁ a₂, diff --git a/library/init/reserved_notation.lean b/library/init/reserved_notation.lean index 933559b2ca..578cbe9eae 100644 --- a/library/init/reserved_notation.lean +++ b/library/init/reserved_notation.lean @@ -39,20 +39,25 @@ definition lt {A : Type} [has_lt A] : A → A → Prop := has_lt.lt definition append {A : Type} [has_append A] : A → A → A := has_append.append definition andthen {A : Type} [has_andthen A] : A → A → A := has_andthen.andthen -definition ge [reducible] {A : Type} [s : has_le A] (a b : A) : Prop := le b a -definition gt [reducible] {A : Type} [s : has_lt A] (a b : A) : Prop := lt b a +attribute [reducible] +definition ge {A : Type} [s : has_le A] (a b : A) : Prop := le b a +attribute [reducible] +definition gt {A : Type} [s : has_lt A] (a b : A) : Prop := lt b a definition bit0 {A : Type} [s : has_add A] (a : A) : A := add a a definition bit1 {A : Type} [s₁ : has_one A] [s₂ : has_add A] (a : A) : A := add (bit0 a) one attribute [pattern] zero one bit0 bit1 add -definition num_has_zero [instance] : has_zero num := +attribute [instance] +definition num_has_zero : has_zero num := has_zero.mk num.zero -definition num_has_one [instance] : has_one num := +attribute [instance] +definition num_has_one : has_one num := has_one.mk (num.pos pos_num.one) -definition pos_num_has_one [instance] : has_one pos_num := +attribute [instance] +definition pos_num_has_one : has_one pos_num := has_one.mk (pos_num.one) namespace pos_num @@ -79,7 +84,8 @@ namespace pos_num b end pos_num -definition pos_num_has_add [instance] : has_add pos_num := +attribute [instance] +definition pos_num_has_add : has_add pos_num := has_add.mk pos_num.add namespace num @@ -89,7 +95,8 @@ namespace num num.rec_on a b (λpa, num.rec_on b (pos pa) (λpb, pos (pos_num.add pa pb))) end num -definition num_has_add [instance] : has_add num := +attribute [instance] +definition num_has_add : has_add num := has_add.mk num.add definition std.priority.default : num := 1000 @@ -109,13 +116,16 @@ end nat attribute pos_num_has_add pos_num_has_one num_has_zero num_has_one num_has_add [instance] [priority nat.prio] -definition nat_has_zero [instance] [priority nat.prio] : has_zero nat := +attribute [instance] [priority nat.prio] +definition nat_has_zero : has_zero nat := has_zero.mk nat.zero -definition nat_has_one [instance] [priority nat.prio] : has_one nat := +attribute [instance] [priority nat.prio] +definition nat_has_one : has_one nat := has_one.mk (nat.succ (nat.zero)) -definition nat_has_add [instance] [priority nat.prio] : has_add nat := +attribute [instance] [priority nat.prio] +definition nat_has_add : has_add nat := has_add.mk nat.add /- diff --git a/library/init/setoid.lean b/library/init/setoid.lean index 3a7a00dabd..818f7ee3f5 100644 --- a/library/init/setoid.lean +++ b/library/init/setoid.lean @@ -17,12 +17,15 @@ namespace setoid variable [s : setoid A] include s - theorem refl [refl] (a : A) : a ≈ a := + attribute [refl] + theorem refl (a : A) : a ≈ a := and.elim_left (@setoid.iseqv A s) a - theorem symm [symm] {a b : A} : a ≈ b → b ≈ a := + attribute [symm] + theorem symm {a b : A} : a ≈ b → b ≈ a := λ H, and.elim_left (and.elim_right (@setoid.iseqv A s)) a b H - theorem trans [trans] {a b c : A} : a ≈ b → b ≈ c → a ≈ c := + attribute [trans] + theorem trans {a b c : A} : a ≈ b → b ≈ c → a ≈ c := λ H₁ H₂, and.elim_right (and.elim_right (@setoid.iseqv A s)) a b c H₁ H₂ end setoid diff --git a/library/init/simplifier.lean b/library/init/simplifier.lean index a799c8b288..09580c4950 100644 --- a/library/init/simplifier.lean +++ b/library/init/simplifier.lean @@ -22,17 +22,20 @@ namespace unit_simp variables {A B C : Prop} -lemma and_imp [simp] : (A ∧ B → C) ↔ (A → B → C) := +attribute [simp] +lemma and_imp : (A ∧ B → C) ↔ (A → B → C) := iff.intro (assume H a b, H (and.intro a b)) (assume H ab, H (and.left ab) (and.right ab)) -lemma or_imp [simp] : (A ∨ B → C) ↔ ((A → C) ∧ (B → C)) := +attribute [simp] +lemma or_imp : (A ∨ B → C) ↔ ((A → C) ∧ (B → C)) := iff.intro (assume H, and.intro (assume a, H (or.inl a)) (assume b, H (or.inr b))) (assume H ab, and.rec_on H (assume Hac Hbc, or.rec_on ab Hac Hbc)) -lemma imp_and [simp] : (A → B ∧ C) ↔ ((A → B) ∧ (A → C)) := +attribute [simp] +lemma imp_and : (A → B ∧ C) ↔ ((A → B) ∧ (A → C)) := iff.intro (assume H, and.intro (assume a, and.left (H a)) (assume a, and.right (H a))) (assume H a, and.rec_on H @@ -40,36 +43,43 @@ iff.intro (assume H, and.intro (assume a, and.left (H a)) -- TODO(dhs, leo): do we want to pre-process away the [iff]s? /- -lemma iff_and_imp [simp] : ((A ↔ B) → C) ↔ (((A → B) ∧ (B → A)) → C) := +attribute [simp] +lemma iff_and_imp : ((A ↔ B) → C) ↔ (((A → B) ∧ (B → A)) → C) := iff.intro (assume H1 H2, and.rec_on H2 (assume ab ba, H1 (iff.intro ab ba))) (assume H1 H2, H1 (and.intro (iff.elim_left H2) (iff.elim_right H2))) -/ -lemma a_of_a [simp] : (A → A) ↔ true := +attribute [simp] +lemma a_of_a : (A → A) ↔ true := iff.intro (assume H, trivial) (assume t a, a) -lemma not_true_of_false [simp] : ¬ true ↔ false := +attribute [simp] +lemma not_true_of_false : ¬ true ↔ false := iff.intro (assume H, H trivial) (assume f, false.rec (¬ true) f) -lemma imp_true [simp] : (A → true) ↔ true := +attribute [simp] +lemma imp_true : (A → true) ↔ true := iff.intro (assume H, trivial) (assume t a, trivial) -lemma true_imp [simp] : (true → A) ↔ A := +attribute [simp] +lemma true_imp : (true → A) ↔ A := iff.intro (assume H, H trivial) (assume a t, a) -- lemma fold_not [simp] : (A → false) ↔ ¬ A := -- iff.intro id id -lemma false_imp [simp] : (false → A) ↔ true := +attribute [simp] +lemma false_imp : (false → A) ↔ true := iff.intro (assume H, trivial) (assume t f, false.rec A f) -lemma ite_and [simp] [A_dec : decidable A] : ite A B C ↔ ((A → B) ∧ (¬ A → C)) := +attribute [simp] +lemma ite_and [A_dec : decidable A] : ite A B C ↔ ((A → B) ∧ (¬ A → C)) := iff.intro (assume H, and.intro (assume a, implies_of_if_pos H a) (assume a, implies_of_if_neg H a)) (assume H, and.rec_on H diff --git a/library/init/sizeof.lean b/library/init/sizeof.lean index f726f9f392..6f213a4b4b 100644 --- a/library/init/sizeof.lean +++ b/library/init/sizeof.lean @@ -15,47 +15,62 @@ structure has_sizeof [class] (A : Type) := definition sizeof {A : Type} [s : has_sizeof A] : A → nat := has_sizeof.sizeof -definition prop_has_sizeof [instance] (p : Prop) : has_sizeof p := +attribute [instance] +definition prop_has_sizeof (p : Prop) : has_sizeof p := has_sizeof.mk (λ t, zero) -definition nat_has_sizeof [instance] : has_sizeof nat := +attribute [instance] +definition nat_has_sizeof : has_sizeof nat := has_sizeof.mk (λ a, a) -definition Type_has_sizeof [instance] : has_sizeof Type := +attribute [instance] +definition Type_has_sizeof : has_sizeof Type := has_sizeof.mk (λ t, zero) -definition Prop_has_sizeof [instance] : has_sizeof Prop := +attribute [instance] +definition Prop_has_sizeof : has_sizeof Prop := has_sizeof.mk (λ t, zero) -definition fn_has_sizeof [instance] (A : Type) (B : A → Type) : has_sizeof (Π x, B x) := +attribute [instance] +definition fn_has_sizeof (A : Type) (B : A → Type) : has_sizeof (Π x, B x) := has_sizeof.mk (λf, zero) -definition option.has_sizeof [instance] (A : Type) [has_sizeof A] : has_sizeof (option A) := +attribute [instance] +definition option.has_sizeof (A : Type) [has_sizeof A] : has_sizeof (option A) := by mk_has_sizeof_instance -definition prod_has_sizeof [instance] (A B : Type) [has_sizeof A] [has_sizeof B] : has_sizeof (prod A B) := +attribute [instance] +definition prod_has_sizeof (A B : Type) [has_sizeof A] [has_sizeof B] : has_sizeof (prod A B) := by mk_has_sizeof_instance -definition sum_has_sizeof [instance] (A B : Type) [has_sizeof A] [has_sizeof B] : has_sizeof (sum A B) := +attribute [instance] +definition sum_has_sizeof (A B : Type) [has_sizeof A] [has_sizeof B] : has_sizeof (sum A B) := by mk_has_sizeof_instance -definition list_has_sizeof [instance] (A : Type) [has_sizeof A] : has_sizeof (list A) := +attribute [instance] +definition list_has_sizeof (A : Type) [has_sizeof A] : has_sizeof (list A) := by mk_has_sizeof_instance -definition unit_has_sizeof [instance] : has_sizeof unit := +attribute [instance] +definition unit_has_sizeof : has_sizeof unit := by mk_has_sizeof_instance -definition bool_has_sizeof [instance] : has_sizeof bool := +attribute [instance] +definition bool_has_sizeof : has_sizeof bool := by mk_has_sizeof_instance -definition sigma_has_sizeof [instance] (A : Type) (B : A → Type) [has_sizeof A] [∀ x, has_sizeof (B x)] : has_sizeof (Σ x, B x) := +attribute [instance] +definition sigma_has_sizeof (A : Type) (B : A → Type) [has_sizeof A] [∀ x, has_sizeof (B x)] : has_sizeof (Σ x, B x) := by mk_has_sizeof_instance -definition subtype_has_sizeof [instance] (A : Type) (P : A → Prop) [has_sizeof A] : has_sizeof {x \ P x} := +attribute [instance] +definition subtype_has_sizeof (A : Type) (P : A → Prop) [has_sizeof A] : has_sizeof {x \ P x} := by mk_has_sizeof_instance -definition pos_num_has_sizeof [instance] : has_sizeof pos_num := +attribute [instance] +definition pos_num_has_sizeof : has_sizeof pos_num := by mk_has_sizeof_instance -definition num_has_sizeof [instance] : has_sizeof num := +attribute [instance] +definition num_has_sizeof : has_sizeof num := by mk_has_sizeof_instance diff --git a/library/init/state.lean b/library/init/state.lean index f9f6bef8b5..8a7b749fe7 100644 --- a/library/init/state.lean +++ b/library/init/state.lean @@ -11,24 +11,30 @@ definition state (S : Type) (A : Type) := S → A × S section variables {S A B : Type} -definition state_fmap [inline] (f : A → B) (a : state S A) : state S B := +attribute [inline] +definition state_fmap (f : A → B) (a : state S A) : state S B := λ s, match (a s) with (a', s') := (f a', s') end -definition state_return [inline] (a : A) : state S A := +attribute [inline] +definition state_return (a : A) : state S A := λ s, (a, s) -definition state_bind [inline] (a : state S A) (b : A → state S B) : state S B := +attribute [inline] +definition state_bind (a : state S A) (b : A → state S B) : state S B := λ s, match (a s) with (a', s') := b a' s' end -definition state_is_monad [instance] (S : Type) : monad (state S) := +attribute [instance] +definition state_is_monad (S : Type) : monad (state S) := monad.mk (@state_fmap S) (@state_return S) (@state_bind S) end namespace state -definition read [inline] {S A : Type} : state S S := +attribute [inline] +definition read {S A : Type} : state S S := λ s, (s, s) -definition write [inline] {S : Type} : S → state S unit := +attribute [inline] +definition write {S : Type} : S → state S unit := λ s' s, ((), s') end state @@ -43,7 +49,8 @@ definition stateT_return {S : Type} {m : Type → Type} [monad m] {A : Type} (a definition stateT_bind.{l} {S : Type} {m : Type → Type} [monad m] {A B : Type.{l}} (a : stateT S m A) (b : A → stateT S m B) : stateT S m B := λ s, @monad.bind m _ _ _ (a s) (λ p : A × S, match p with (a', s') := b a' s' end) -definition stateT_is_monad [instance] (S : Type) (m : Type → Type) [monad m] : monad (stateT S m) := +attribute [instance] +definition stateT_is_monad (S : Type) (m : Type → Type) [monad m] : monad (stateT S m) := monad.mk (@stateT_fmap S m _) (@stateT_return S m _) (@stateT_bind S m _) namespace stateT diff --git a/library/init/string.lean b/library/init/string.lean index d71de1ceab..db755a0a9b 100644 --- a/library/init/string.lean +++ b/library/init/string.lean @@ -6,7 +6,8 @@ Author: Leonardo de Moura prelude import init.char init.list -definition string [reducible] := list char +attribute [reducible] +definition string := list char namespace string definition empty : string := list.nil @@ -16,7 +17,8 @@ definition concat (a b : string) : string := list.append b a end string -definition string.has_append [instance] : has_append string := +attribute [instance] +definition string.has_append : has_append string := has_append.mk string.concat open list diff --git a/library/init/subtype.lean b/library/init/subtype.lean index 7e4c5cc6ea..bb2348e04a 100644 --- a/library/init/subtype.lean +++ b/library/init/subtype.lean @@ -32,5 +32,6 @@ end subtype open subtype variables {A : Type} {P : A → Prop} -protected definition subtype.is_inhabited [instance] {a : A} (H : P a) : inhabited {x \ P x} := +attribute [instance] +protected definition subtype.is_inhabited {a : A} (H : P a) : inhabited {x \ P x} := inhabited.mk (tag a H) diff --git a/library/init/to_string.lean b/library/init/to_string.lean index aac947a795..5e078e817a 100644 --- a/library/init/to_string.lean +++ b/library/init/to_string.lean @@ -11,10 +11,12 @@ structure has_to_string [class] (A : Type) := definition to_string {A : Type} [has_to_string A] : A → string := has_to_string.to_string -definition bool.has_to_string [instance] : has_to_string bool := +attribute [instance] +definition bool.has_to_string : has_to_string bool := has_to_string.mk (λ b, cond b "tt" "ff") -definition decidable.has_to_string [instance] {p : Prop} : has_to_string (decidable p) := +attribute [instance] +definition decidable.has_to_string {p : Prop} : has_to_string (decidable p) := has_to_string.mk (λ b, if p then "tt" else "ff") definition list.to_string_aux {A : Type} [has_to_string A] : bool → list A → string @@ -26,26 +28,33 @@ definition list.to_string {A : Type} [has_to_string A] : list A → string | [] := "[]" | (x::xs) := "[" ++ list.to_string_aux tt (x::xs) ++ "]" -definition list.has_to_string [instance] {A : Type} [has_to_string A] : has_to_string (list A) := +attribute [instance] +definition list.has_to_string {A : Type} [has_to_string A] : has_to_string (list A) := has_to_string.mk list.to_string -definition unit.has_to_string [instance] : has_to_string unit := +attribute [instance] +definition unit.has_to_string : has_to_string unit := has_to_string.mk (λ u, "star") -definition option.has_to_string [instance] {A : Type} [has_to_string A] : has_to_string (option A) := +attribute [instance] +definition option.has_to_string {A : Type} [has_to_string A] : has_to_string (option A) := has_to_string.mk (λ o, match o with | none := "none" | (some a) := "(some " ++ to_string a ++ ")" end) -definition sum.has_to_string [instance] {A B : Type} [has_to_string A] [has_to_string B] : has_to_string (sum A B) := +attribute [instance] +definition sum.has_to_string {A B : Type} [has_to_string A] [has_to_string B] : has_to_string (sum A B) := has_to_string.mk (λ s, match s with | (inl a) := "(inl " ++ to_string a ++ ")" | (inr b) := "(inr " ++ to_string b ++ ")" end) -definition prod.has_to_string [instance] {A B : Type} [has_to_string A] [has_to_string B] : has_to_string (prod A B) := +attribute [instance] +definition prod.has_to_string {A B : Type} [has_to_string A] [has_to_string B] : has_to_string (prod A B) := has_to_string.mk (λ p, "(" ++ to_string (pr1 p) ++ ", " ++ to_string (pr2 p) ++ ")") -definition sigma.has_to_string [instance] {A : Type} {B : A → Type} [has_to_string A] [s : ∀ x, has_to_string (B x)] +attribute [instance] +definition sigma.has_to_string {A : Type} {B : A → Type} [has_to_string A] [s : ∀ x, has_to_string (B x)] : has_to_string (sigma B) := has_to_string.mk (λ p, "⟨" ++ to_string (pr1 p) ++ ", " ++ to_string (pr2 p) ++ "⟩") -definition subtype.has_to_string [instance] {A : Type} {P : A → Prop} [has_to_string A] : has_to_string (subtype P) := +attribute [instance] +definition subtype.has_to_string {A : Type} {P : A → Prop} [has_to_string A] : has_to_string (subtype P) := has_to_string.mk (λ s, to_string (elt_of s)) definition char.quote_core (c : char) : string := @@ -55,7 +64,8 @@ else if c = '\"' then "\\\"" else if c = '\'' then "\\\'" else c::nil -definition char.has_to_sting [instance] : has_to_string char := +attribute [instance] +definition char.has_to_sting : has_to_string char := has_to_string.mk (λ c, "'" ++ char.quote_core c ++ "'") definition string.quote_aux : string → string @@ -66,7 +76,8 @@ definition string.quote : string → string | [] := "\"\"" | (x::xs) := "\"" ++ string.quote_aux (x::xs) ++ "\"" -definition string.has_to_string [instance] : has_to_string string := +attribute [instance] +definition string.has_to_string : has_to_string string := has_to_string.mk string.quote /- Remark: the code generator replaces this definition with one that display natural numbers in decimal notation -/ @@ -74,11 +85,14 @@ definition nat.to_string : nat → string | 0 := "zero" | (succ a) := "(succ " ++ nat.to_string a ++ ")" -definition nat.has_to_string [instance] : has_to_string nat := +attribute [instance] +definition nat.has_to_string : has_to_string nat := has_to_string.mk nat.to_string -definition fin.has_to_string [instance] (n : nat) : has_to_string (fin n) := +attribute [instance] +definition fin.has_to_string (n : nat) : has_to_string (fin n) := has_to_string.mk (λ f, to_string (fin.val f)) -definition unsigned.has_to_string [instance] : has_to_string unsigned := +attribute [instance] +definition unsigned.has_to_string : has_to_string unsigned := has_to_string.mk (λ n, to_string (fin.val n)) diff --git a/library/init/unit.lean b/library/init/unit.lean index dcad625a6e..1775f7df75 100644 --- a/library/init/unit.lean +++ b/library/init/unit.lean @@ -12,8 +12,10 @@ unit.rec_on a (unit.rec_on b rfl) theorem unit_eq_unit (a : unit) : a = () := unit_eq a () -definition unit_subsingleton [instance] : subsingleton unit := +attribute [instance] +definition unit_subsingleton : subsingleton unit := subsingleton.intro unit_eq -definition unit_is_inhabited [instance] : inhabited unit := +attribute [instance] +definition unit_is_inhabited : inhabited unit := inhabited.mk () diff --git a/library/init/unsigned.lean b/library/init/unsigned.lean index fbd77379fc..8bd22b3671 100644 --- a/library/init/unsigned.lean +++ b/library/init/unsigned.lean @@ -7,7 +7,8 @@ prelude import init.fin definition unsigned_sz : nat := 4294967296 -definition unsigned [reducible] := fin unsigned_sz +attribute [reducible] +definition unsigned := fin unsigned_sz namespace unsigned @@ -18,6 +19,7 @@ definition to_nat (c : unsigned) : nat := fin.val c end unsigned -definition unsigned.has_decidable_eq [instance] : decidable_eq unsigned := +attribute [instance] +definition unsigned.has_decidable_eq : decidable_eq unsigned := have decidable_eq (fin unsigned_sz), from _, this diff --git a/library/init/wf.lean b/library/init/wf.lean index 47595cd9de..60ff3bd1e0 100644 --- a/library/init/wf.lean +++ b/library/init/wf.lean @@ -16,7 +16,8 @@ namespace acc acc.rec_on H₁ (λ x₁ ac₁ iH H₂, ac₁ y H₂) H₂ -- dependent elimination for acc - protected definition drec [recursor] + attribute [recursor] + protected definition drec {C : Π (a : A), acc R a → Type} (h₁ : Π (x : A) (acx : Π (y : A), R y x → acc R y), (Π (y : A) (ryx : R y x), C y (acx y ryx)) → C x (acc.intro x acx)) diff --git a/library/logic/examples/propositional/deceq.lean b/library/logic/examples/propositional/deceq.lean index e998bf5670..08b1443a29 100644 --- a/library/logic/examples/propositional/deceq.lean +++ b/library/logic/examples/propositional/deceq.lean @@ -39,6 +39,7 @@ namespace PropF | (Impl p₁ p₂) (Impl q₁ q₂) H := by rewrite [equal_to_eq (band_elim_left H), equal_to_eq (band_elim_right H)] - lemma has_decidable_eq [instance] : decidable_eq PropF := + attribute [instance] + lemma has_decidable_eq : decidable_eq PropF := decidable_eq_of_bool_pred equal_to_eq equal_refl end PropF diff --git a/library/logic/examples/propositional/soundness.lean b/library/logic/examples/propositional/soundness.lean index 867dbbb050..a8e7ae84c7 100644 --- a/library/logic/examples/propositional/soundness.lean +++ b/library/logic/examples/propositional/soundness.lean @@ -11,7 +11,8 @@ This file is based on Floris van Doorn Coq files. import data.nat data.list open nat bool list decidable -definition PropVar [reducible] := nat +attribute [reducible] +definition PropVar := nat inductive PropF := | Var : PropVar → PropF @@ -43,7 +44,8 @@ namespace PropF | TrueQ (A ∧ B) := TrueQ A && TrueQ B | TrueQ (A ⇒ B) := bnot (TrueQ A) || TrueQ B - definition is_true [reducible] (b : bool) := b = tt + attribute [reducible] + definition is_true (b : bool) := b = tt -- the valuation v satisfies a list of PropF, if forall (A : PropF) in Γ, -- (TrueQ v A) is tt (the Boolean true) diff --git a/library/logic/examples/propositional/soundness_type.lean b/library/logic/examples/propositional/soundness_type.lean index 91a4c6fa45..ecdb7db426 100644 --- a/library/logic/examples/propositional/soundness_type.lean +++ b/library/logic/examples/propositional/soundness_type.lean @@ -14,7 +14,8 @@ The idea is to be able to prove soundness using recursive equations. import data.nat data.list open nat bool list decidable -definition PropVar [reducible] := nat +attribute [reducible] +definition PropVar := nat inductive PropF := | Var : PropVar → PropF @@ -46,7 +47,8 @@ namespace PropF | TrueQ (A ∧ B) := TrueQ A && TrueQ B | TrueQ (A ⇒ B) := bnot (TrueQ A) || TrueQ B - definition is_true [reducible] (b : bool) := b = tt + attribute [reducible] + definition is_true (b : bool) := b = tt -- the valuation v satisfies a list of PropF, if forall (A : PropF) in Γ, -- (TrueQ v A) is tt (the Boolean true) diff --git a/library/logic/quantifiers.lean b/library/logic/quantifiers.lean index a58c615e4a..1d23cb6e06 100644 --- a/library/logic/quantifiers.lean +++ b/library/logic/quantifiers.lean @@ -61,11 +61,13 @@ section variables {A : Type} (P : A → Prop) (a : A) [H : decidable (P a)] include H - definition decidable_forall_eq [instance] : decidable (∀ x, x = a → P x) := + attribute [instance] + definition decidable_forall_eq : decidable (∀ x, x = a → P x) := if pa : P a then tt (λ x heq, eq.substr heq pa) else ff (not.mto (λH, H a rfl) pa) - definition decidable_exists_eq [instance] : decidable (∃ x, x = a ∧ P x) := + attribute [instance] + definition decidable_exists_eq : decidable (∃ x, x = a ∧ P x) := if pa : P a then tt (exists.intro a (and.intro rfl pa)) else ff (Exists.rec (λh, and.rec (λheq, eq.substr heq pa))) end diff --git a/library/theories/analysis/complex_norm.lean b/library/theories/analysis/complex_norm.lean index 236cc21a14..97a60298d2 100644 --- a/library/theories/analysis/complex_norm.lean +++ b/library/theories/analysis/complex_norm.lean @@ -46,7 +46,8 @@ namespace complex by rewrite [-complex.eta, `re x = 0`, `im x = 0`] end real_inner_product_space - protected definition real_inner_product_space [reducible] : inner_product_space ℂ := + attribute [reducible] + protected definition real_inner_product_space : inner_product_space ℂ := ⦃ inner_product_space, complex.discrete_field, smul := real_inner_product_space.smul, inner := real_inner_product_space.ip, @@ -63,7 +64,8 @@ namespace complex local attribute complex.real_inner_product_space [trans_instance] - protected definition normed_vector_space [trans_instance] : normed_vector_space ℂ := + attribute [trans_instance] + protected definition normed_vector_space : normed_vector_space ℂ := _ theorem norm_squared_eq_cmod (z : ℂ) : ∥ z ∥^2 = cmod z := by rewrite norm_squared diff --git a/library/theories/analysis/inner_product.lean b/library/theories/analysis/inner_product.lean index 4a0a0f0634..9156bd0c7b 100644 --- a/library/theories/analysis/inner_product.lean +++ b/library/theories/analysis/inner_product.lean @@ -172,7 +172,8 @@ have (ip_norm (u + v))^2 ≤ (ip_norm u + ip_norm v)^2, from mul.comm (ip_norm v) (ip_norm u)], le_of_squared_le_squared (add_nonneg !ip_norm_nonneg !ip_norm_nonneg) this -definition inner_product_space.to_normed_space [trans_instance] : +attribute [trans_instance] +definition inner_product_space.to_normed_space : normed_vector_space V := ⦃ normed_vector_space, _inst_1, norm := ip_norm, diff --git a/library/theories/analysis/metric_space.lean b/library/theories/analysis/metric_space.lean index aa388d0d7f..e5c2911f4c 100644 --- a/library/theories/analysis/metric_space.lean +++ b/library/theories/analysis/metric_space.lean @@ -72,7 +72,8 @@ take ε, assume epos : ε > 0, notation X `⟶` y `in` `ℕ` := converges_to_seq X y -definition converges_seq [class] (X : ℕ → M) : Prop := ∃ y, X ⟶ y in ℕ +attribute [class] +definition converges_seq (X : ℕ → M) : Prop := ∃ y, X ⟶ y in ℕ noncomputable definition limit_seq (X : ℕ → M) [H : converges_seq X] : M := some H @@ -268,7 +269,8 @@ definition converges_to_at (f : M → N) (y : N) (x : M) := notation f `⟶` y `at` x := converges_to_at f y x -definition converges_at [class] (f : M → N) (x : M) := +attribute [class] +definition converges_at (f : M → N) (x : M) := ∃ y, converges_to_at f y x noncomputable definition limit_at (f : M → N) (x : M) [H : converges_at f x] : N := @@ -484,7 +486,8 @@ omit Vmet definition open_sets_basis (V : Type) [metric_space V] := image (λ pair : V × ℝ, open_ball (pr1 pair) (pr2 pair)) univ -definition metric_topology [instance] (V : Type) [metric_space V] : topology V := +attribute [instance] +definition metric_topology (V : Type) [metric_space V] : topology V := topology.generated_by (open_sets_basis V) include Vmet @@ -743,7 +746,8 @@ exists.intro δ (and.intro definition continuous (f : M → N) : Prop := ∀ x, continuous_at f x -theorem converges_seq_comp_of_converges_seq_of_cts [instance] (X : ℕ → M) [HX : converges_seq X] {f : M → N} +attribute [instance] +theorem converges_seq_comp_of_converges_seq_of_cts (X : ℕ → M) [HX : converges_seq X] {f : M → N} (Hf : continuous f) : converges_seq (λ n, f (X n)) := begin @@ -792,7 +796,8 @@ end analysis /- the reals form a metric space -/ -noncomputable definition metric_space_real [instance] : metric_space ℝ := +attribute [instance] +noncomputable definition metric_space_real : metric_space ℝ := ⦃ metric_space, dist := λ x y, abs (x - y), dist_self := λ x, abstract by rewrite [sub_self, abs_zero] end, diff --git a/library/theories/analysis/normed_space.lean b/library/theories/analysis/normed_space.lean index 6329f0b6f6..40eccfb6be 100644 --- a/library/theories/analysis/normed_space.lean +++ b/library/theories/analysis/normed_space.lean @@ -86,7 +86,8 @@ section variable {V : Type} variable [normed_vector_space V] - private definition nvs_dist [reducible] (u v : V) := ∥ u - v ∥ + attribute [reducible] + private definition nvs_dist (u v : V) := ∥ u - v ∥ private lemma nvs_dist_self (u : V) : nvs_dist u u = 0 := by rewrite [↑nvs_dist, sub_self, norm_zero] @@ -103,7 +104,8 @@ section private lemma nvs_dist_comm (u v : V) : nvs_dist u v = nvs_dist v u := by rewrite [↑nvs_dist, -norm_neg, neg_sub] - definition normed_vector_space_to_metric_space [trans_instance] + attribute [trans_instance] + definition normed_vector_space_to_metric_space (V : Type) [nvsV : normed_vector_space V] : metric_space V := ⦃ metric_space, @@ -132,7 +134,8 @@ structure banach_space [class] (V : Type) extends nvsV : normed_vector_space V : (complete : ∀ X, @analysis.cauchy V (@normed_vector_space_to_metric_space V nvsV) X → @analysis.converges_seq V (@normed_vector_space_to_metric_space V nvsV) X) -definition banach_space_to_metric_space [trans_instance] (V : Type) [bsV : banach_space V] : +attribute [trans_instance] +definition banach_space_to_metric_space (V : Type) [bsV : banach_space V] : complete_metric_space V := ⦃ complete_metric_space, normed_vector_space_to_metric_space V, complete := banach_space.complete diff --git a/library/theories/analysis/real_limit.lean b/library/theories/analysis/real_limit.lean index 011518a088..b97c1969dc 100644 --- a/library/theories/analysis/real_limit.lean +++ b/library/theories/analysis/real_limit.lean @@ -221,7 +221,8 @@ exists.intro l end analysis -definition complete_metric_space_real [trans_instance] : +attribute [trans_instance] +definition complete_metric_space_real : complete_metric_space ℝ := ⦃complete_metric_space, metric_space_real, complete := @analysis.converges_seq_of_cauchy @@ -238,7 +239,8 @@ definition real_vector_space_real : real_vector_space ℝ := one_smul := one_mul ⦄ -definition banach_space_real [trans_instance] : banach_space ℝ := +attribute [trans_instance] +definition banach_space_real : banach_space ℝ := ⦃ banach_space, real_vector_space_real, norm := abs, norm_zero := abs_zero, diff --git a/library/theories/group_theory/action.lean b/library/theories/group_theory/action.lean index 4264f30eb8..12f72aa843 100644 --- a/library/theories/group_theory/action.lean +++ b/library/theories/group_theory/action.lean @@ -25,7 +25,8 @@ variables [decidable_eq S] definition orbit (hom : G → perm S) (H : finset G) (a : S) : finset S := image (move_by a) (image hom H) -definition fixed_points [reducible] (hom : G → perm S) (H : finset G) : finset S := +attribute [reducible] +definition fixed_points (hom : G → perm S) (H : finset G) : finset S := {a ∈ univ | orbit hom H a = '{a}} variable [decidable_eq G] -- required by {x ∈ H |p x} filtering @@ -182,7 +183,8 @@ lemma subg_stab_has_inv : finset_has_inv (stab hom H a) := have PfinvinH : f⁻¹ ∈ H, from finsubg_has_inv H (mem_of_mem_sep Pfstab), mem_sep_of_mem PfinvinH Pfinv -definition subg_stab_is_finsubg [instance] : +attribute [instance] +definition subg_stab_is_finsubg : is_finsubg (stab hom H a) := is_finsubg.mk subg_stab_has_one subg_stab_closed subg_stab_has_inv @@ -385,7 +387,8 @@ take g₁ g₂, assume Peq, perm.no_confusion Peq ... = g₂ * 1 : Pappeq ... = g₂ : mul_one) -definition action_by_lmul_is_iso [instance] : is_iso_class (@action_by_lmul G _ _) := +attribute [instance] +definition action_by_lmul_is_iso : is_iso_class (@action_by_lmul G _ _) := is_iso_class.mk action_by_lmul_hom action_by_lmul_inj end cayley @@ -412,7 +415,8 @@ lemma action_on_lcoset_hom : homomorphic (action_on_lcoset H) := take g₁ g₂, eq_of_feq (funext take S, subtype.eq (by rewrite [↑action_on_lcoset, ↑lcoset_lmul, -fin_lcoset_compose])) -definition action_on_lcoset_is_hom [instance] : is_hom_class (action_on_lcoset H) := +attribute [instance] +definition action_on_lcoset_is_hom : is_hom_class (action_on_lcoset H) := is_hom_class.mk action_on_lcoset_hom variable [finsubgH : is_finsubg H] diff --git a/library/theories/group_theory/cyclic.lean b/library/theories/group_theory/cyclic.lean index 8b326798ab..8b6d2539fe 100644 --- a/library/theories/group_theory/cyclic.lean +++ b/library/theories/group_theory/cyclic.lean @@ -210,7 +210,8 @@ have Pe : a^(n % order a) = 1, from end, dvd_of_mod_eq_zero (eq_zero_of_pow_eq_one Pe (mod_lt n !order_pos)) -definition cyc_is_finsubg [instance] (a : A) : is_finsubg (cyc a) := +attribute [instance] +definition cyc_is_finsubg (a : A) : is_finsubg (cyc a) := is_finsubg.mk (cyc_has_one a) (cyc_mul_closed a) (cyc_has_inv a) lemma order_dvd_group_order (a : A) : order a ∣ card A := @@ -314,7 +315,8 @@ lemma rotl_eq_rotl : ∀ {n : nat}, map (rotl 1) (upto n) = list.rotl (upto n) congruence, rewrite [ mod_add_mod, val_zero, add_zero, mod_eq_of_lt !lt_succ_self ] end -definition seq [reducible] (A : Type) (n : nat) := fin n → A +attribute [reducible] +definition seq (A : Type) (n : nat) := fin n → A variable {A : Type} @@ -354,7 +356,8 @@ end rot section rotg open nat fin fintype -definition rotl_perm [reducible] (A : Type) [finA : fintype A] [deceqA : decidable_eq A] (n : nat) (m : nat) : perm (seq A n) := +attribute [reducible] +definition rotl_perm (A : Type) [finA : fintype A] [deceqA : decidable_eq A] (n : nat) (m : nat) : perm (seq A n) := perm.mk (rotl_fun m) rotl_fun_inj variable {A : Type} diff --git a/library/theories/group_theory/finsubg.lean b/library/theories/group_theory/finsubg.lean index 86f4d045e7..f8ff6d382f 100644 --- a/library/theories/group_theory/finsubg.lean +++ b/library/theories/group_theory/finsubg.lean @@ -21,7 +21,8 @@ section subg variables {G : Type} [group G] variable [decidable_eq G] -definition finset_mul_closed_on [reducible] (H : finset G) : Prop := +attribute [reducible] +definition finset_mul_closed_on (H : finset G) : Prop := ∀ x y : G, x ∈ H → y ∈ H → x * y ∈ H definition finset_has_inv (H : finset G) : Prop := ∀ a : G, a ∈ H → a⁻¹ ∈ H @@ -31,10 +32,12 @@ structure is_finsubg [class] (H : finset G) : Type := (mul_closed : finset_mul_closed_on H) (has_inv : finset_has_inv H) -definition univ_is_finsubg [instance] [finG : fintype G] : is_finsubg (@finset.univ G _) := +attribute [instance] +definition univ_is_finsubg [finG : fintype G] : is_finsubg (@finset.univ G _) := is_finsubg.mk !mem_univ (λ x y Px Py, !mem_univ) (λ a Pa, !mem_univ) -definition one_is_finsubg [instance] : is_finsubg ('{(1:G)}) := +attribute [instance] +definition one_is_finsubg : is_finsubg ('{(1:G)}) := is_finsubg.mk !mem_singleton (λ x y Px Py, by rewrite [eq_of_mem_singleton Px, eq_of_mem_singleton Py, one_mul]; apply mem_singleton) (λ x Px, by rewrite [eq_of_mem_singleton Px, one_inv]; apply mem_singleton) @@ -46,7 +49,8 @@ lemma finsubg_mul_closed (H : finset G) [h : is_finsubg H] {x y : G} : x ∈ H lemma finsubg_has_inv (H : finset G) [h : is_finsubg H] {a : G} : a ∈ H → a⁻¹ ∈ H := @is_finsubg.has_inv G _ _ H h a -definition finsubg_to_subg [instance] {H : finset G} [h : is_finsubg H] +attribute [instance] +definition finsubg_to_subg {H : finset G} [h : is_finsubg H] : is_subgroup (ts H) := is_subgroup.mk (mem_eq_mem_to_set H 1 ▸ finsubg_has_one H) @@ -191,14 +195,16 @@ variables {A : Type} [group A] [fintype A] [decidable_eq A] variables G H : finset A -definition is_fin_lcoset [reducible] (S : finset A) : Prop := +attribute [reducible] +definition is_fin_lcoset (S : finset A) : Prop := ∃ g, g ∈ G ∧ fin_lcoset H g = S definition to_list : list A := list.filter (λ g, g ∈ G) (elems A) definition list_lcosets : list (finset A) := erase_dup (map (fin_lcoset H) (to_list G)) -definition lcoset_type [reducible] : Type := {S : finset A | is_fin_lcoset G H S} +attribute [reducible] +definition lcoset_type : Type := {S : finset A | is_fin_lcoset G H S} definition all_lcosets : list (lcoset_type G H) := dmap (is_fin_lcoset G H) tag (list_lcosets G H) @@ -287,7 +293,8 @@ injective_of_has_left_inverse (exists.intro (lcoset_lmul (finsubg_has_inv G Pg)) lemma card_elt_of_lcoset_type (S : lcoset_type G H) : card (elt_of S) = card H := obtain f Pfin Pf, from has_property S, Pf ▸ fin_lcoset_card f -definition lcoset_fintype [instance] : fintype (lcoset_type G H) := +attribute [instance] +definition lcoset_fintype : fintype (lcoset_type G H) := fintype.mk (all_lcosets G H) (dmap_nodup_of_dinj (dinj_tag (is_fin_lcoset G H)) !nodup_erase_dup) (take s, subtype.destruct s (take S, assume PS, mem_dmap PS (mem_list_lcosets_of_is_lcoset PS))) @@ -377,7 +384,8 @@ mem_sep_of_mem !mem_univ take h, begin exact and.left Pk end -definition normalizer_is_finsubg [instance] : is_finsubg (normalizer H) := +attribute [instance] +definition normalizer_is_finsubg : is_finsubg (normalizer H) := is_finsubg.mk normalizer_has_one normalizer_mul_closed normalizer_has_inv lemma lcoset_subset_normalizer (J : lcoset_type (normalizer H) H) : @@ -488,7 +496,8 @@ end variable (H) -definition fin_coset_group [instance] : group (lcoset_type (normalizer H) H) := +attribute [instance] +definition fin_coset_group : group (lcoset_type (normalizer H) H) := group.mk fin_coset_mul fin_coset_mul_assoc fin_coset_one fin_coset_one_mul fin_coset_mul_one fin_coset_inv fin_coset_left_inv variables {H} (Hc : finset (lcoset_type (normalizer H) H)) @@ -520,7 +529,8 @@ have Pjk : j*k ∈ elt_of (J*K), from mul_mem_lcoset_mul J K PjJ PkK, iff.elim_right !mem_Union_iff (exists.intro (J*K) (and.intro (finsubg_mul_closed Hc PJ PK) Pjk)) -definition fcU_is_finsubg [instance] : is_finsubg (fin_coset_Union Hc) := +attribute [instance] +definition fcU_is_finsubg : is_finsubg (fin_coset_Union Hc) := is_finsubg.mk fcU_has_one fcU_mul_closed fcU_has_inv end normalizer diff --git a/library/theories/group_theory/hom.lean b/library/theories/group_theory/hom.lean index eb32fc10df..70883cc965 100644 --- a/library/theories/group_theory/hom.lean +++ b/library/theories/group_theory/hom.lean @@ -26,7 +26,8 @@ include s1 include s2 -- the Prop of being hom -definition homomorphic [reducible] (f : A → B) : Prop := ∀ a b, f (a*b) = (f a)*(f b) +attribute [reducible] +definition homomorphic (f : A → B) : Prop := ∀ a b, f (a*b) = (f a)*(f b) -- type class for inference structure is_hom_class [class] (f : A → B) : Type := (is_hom : homomorphic f) @@ -50,7 +51,8 @@ section variables {A B : Type} variable [s1 : group A] -definition id_is_iso [instance] : @is_hom_class A A s1 s1 (@id A) := +attribute [instance] +definition id_is_iso : @is_hom_class A A s1 s1 (@id A) := is_hom_class.mk (take a b, rfl) variable [s2 : group B] @@ -140,11 +142,13 @@ variable {f : A → B} variable [h : is_hom_class f] include h -definition ker_nsubg [instance] : is_normal_subgroup (ker f) := +attribute [instance] +definition ker_nsubg : is_normal_subgroup (ker f) := is_normal_subgroup.mk (ker.has_one f) (ker.mul_closed f) (ker.has_inv f) (ker.normal f) -definition quot_over_ker [instance] : group (coset_of (ker f)) := mk_quotient_group (ker f) +attribute [instance] +definition quot_over_ker : group (coset_of (ker f)) := mk_quotient_group (ker f) -- under the wrap the tower of concepts collapse to a simple condition example (a x : A) : (x ∈ a ∘> ker f) = (f (a⁻¹*x) = 1) := rfl lemma ker_coset_same_val (a b : A): same_lcoset (ker f) a b → f a = f b := diff --git a/library/theories/group_theory/perm.lean b/library/theories/group_theory/perm.lean index 2304c479ab..335e630a2d 100644 --- a/library/theories/group_theory/perm.lean +++ b/library/theories/group_theory/perm.lean @@ -54,11 +54,13 @@ iff.intro eq_of_feq feq_of_eq lemma perm.f_mk {f : A → A} {Pinj : injective f} : perm.f (perm.mk f Pinj) = f := rfl -definition move_by [reducible] (a : A) (f : perm A) : A := f a +attribute [reducible] +definition move_by (a : A) (f : perm A) : A := f a variable [decidable_eq A] -lemma perm.has_decidable_eq [instance] : decidable_eq (perm A) := +attribute [instance] +lemma perm.has_decidable_eq : decidable_eq (perm A) := take f g, perm.destruct f (λ ff finj, perm.destruct g (λ gf ginj, decidable.rec_on (decidable_eq_fun ff gf) @@ -79,12 +81,14 @@ lemma all_perms_complete : ∀ p : perm A, p ∈ all_perms := have Pin : f ∈ all_injs A, from all_injs_complete Pinj, mem_dmap Pinj Pin) -definition perm_is_fintype [instance] : fintype (perm A) := +attribute [instance] +definition perm_is_fintype : fintype (perm A) := fintype.mk all_perms nodup_all_perms all_perms_complete definition perm.mul (f g : perm A) := perm.mk (f∘g) (injective_comp (perm.inj f) (perm.inj g)) -definition perm.one [reducible] : perm A := perm.mk id injective_id +attribute [reducible] +definition perm.one : perm A := perm.mk id injective_id definition perm.inv (f : perm A) := let inj := perm.inj f in perm.mk (perm_inv inj) (perm_inv_inj inj) @@ -103,7 +107,8 @@ lemma perm.right_inv (p : perm A) : p ^ (perm.inv p) = perm.one := rewrite [-perm_inv_right (perm.inj p)], intros, exact rfl end -definition perm_group [instance] : group (perm A) := +attribute [instance] +definition perm_group : group (perm A) := group.mk perm.mul perm.assoc perm.one perm.one_mul perm.mul_one perm.inv perm.left_inv lemma perm_one : (1 : perm A) = perm.one := rfl diff --git a/library/theories/group_theory/pgroup.lean b/library/theories/group_theory/pgroup.lean index e0e074750c..ada18aca10 100644 --- a/library/theories/group_theory/pgroup.lean +++ b/library/theories/group_theory/pgroup.lean @@ -124,7 +124,8 @@ open fin definition prodseq {n : nat} (s : seq A n) : A := Prodl (upto n) s -definition peo [reducible] {n : nat} (s : seq A n) := prodseq s = 1 +attribute [reducible] +definition peo {n : nat} (s : seq A n) := prodseq s = 1 definition constseq {n : nat} (s : seq A (succ n)) := ∀ i, s i = s !zero @@ -154,7 +155,8 @@ include deceqA variable (A) -definition peo_seq [reducible] (n : nat) := {s : seq A (succ n) | peo s} +attribute [reducible] +definition peo_seq (n : nat) := {s : seq A (succ n) | peo s} definition peo_seq_one (n : nat) : peo_seq A n := tag (λ i : fin (succ n), (1 : A)) peo_const_one @@ -230,7 +232,8 @@ eq.trans (eq.trans by rewrite [-Pmap, length_map])) length_all_prodl_eq_one -definition peo_seq_is_fintype [instance] {n : nat} : fintype (peo_seq A n) := +attribute [instance] +definition peo_seq_is_fintype {n : nat} : fintype (peo_seq A n) := fintype.mk (all_peo_seqs A n) nodup_all_peo_seqs all_peo_seqs_complete lemma card_peo_seq {n : nat} : card (peo_seq A n) = (card A)^n := @@ -268,7 +271,8 @@ take ps₁ ps₂, subtype.destruct ps₁ (λ s₁ P₁, subtype.destruct ps₂ ( variable (A) -definition rotl_perm_ps [reducible] (n : nat) (m : fin (succ n)) : perm (peo_seq A n) := +attribute [reducible] +definition rotl_perm_ps (n : nat) (m : fin (succ n)) : perm (peo_seq A n) := perm.mk (rotl_peo_seq A n m) rotl_peo_seq_inj variable {A} @@ -288,7 +292,8 @@ eq_of_feq (begin rewrite [↑rotl_perm_ps, {val (i+j)}val_madd, add.comm, -rotl_ section local attribute group_of_add_group [instance] -definition rotl_perm_ps_is_hom [instance] : is_hom_class (rotl_perm_ps A n) := +attribute [instance] +definition rotl_perm_ps_is_hom : is_hom_class (rotl_perm_ps A n) := is_hom_class.mk rotl_perm_ps_hom open finset diff --git a/library/theories/group_theory/subgroup.lean b/library/theories/group_theory/subgroup.lean index c2a0be65fa..fc1916e10c 100644 --- a/library/theories/group_theory/subgroup.lean +++ b/library/theories/group_theory/subgroup.lean @@ -180,10 +180,14 @@ lemma closed_lcontract_set a (H G : set A) : mul_closed_on G → H ⊆ G → a subset.trans PaHsubaG PaGsubG definition subgroup.has_inv H := ∀ (a : A), a ∈ H → a⁻¹ ∈ H -- two ways to define the same equivalence relatiohship for subgroups -definition in_lcoset [reducible] H (a b : A) := a ∈ b ∘> H -definition in_rcoset [reducible] H (a b : A) := a ∈ H <∘ b -definition same_lcoset [reducible] H (a b : A) := a ∘> H = b ∘> H -definition same_rcoset [reducible] H (a b : A) := H <∘ a = H <∘ b +attribute [reducible] +definition in_lcoset H (a b : A) := a ∈ b ∘> H +attribute [reducible] +definition in_rcoset H (a b : A) := a ∈ H <∘ b +attribute [reducible] +definition same_lcoset H (a b : A) := a ∘> H = b ∘> H +attribute [reducible] +definition same_rcoset H (a b : A) := H <∘ a = H <∘ b definition same_left_right_coset (N : set A) := ∀ x, x ∘> N = N <∘ x structure is_subgroup [class] (H : set A) : Type := (has_one : H 1) @@ -311,7 +315,8 @@ lemma nsubg_same_lcoset_inv : ∀ a b, (a ~ b) → (a⁻¹ ~ b⁻¹) := ... = (a⁻¹ ∘> a ∘> N) <∘ b⁻¹ : by rewrite Psame ... = N <∘ b⁻¹ : by rewrite glcoset_inv ... = b⁻¹ ∘> N : by rewrite nsubg_normal -definition nsubg_setoid [instance] : setoid A := +attribute [instance] +definition nsubg_setoid : setoid A := setoid.mk (same_lcoset N) (mk_equivalence (same_lcoset N) (subg_same_lcoset.refl) (subg_same_lcoset.symm) (subg_same_lcoset.trans)) definition coset_of : Type := quot (nsubg_setoid N) @@ -364,7 +369,8 @@ include s variable {N : set A} variable [is_nsubg : is_normal_subgroup N] include is_nsubg -definition quotient_group [instance] : group (coset_of N) := mk_quotient_group N +attribute [instance] +definition quotient_group : group (coset_of N) := mk_quotient_group N example (aN : coset_of N) : aN * aN⁻¹ = 1 := mul.right_inv aN definition natural (a : A) : coset_of N := ⟦a⟧ diff --git a/library/theories/measure_theory/extended_real.lean b/library/theories/measure_theory/extended_real.lean index 949db81c40..805d21c20c 100644 --- a/library/theories/measure_theory/extended_real.lean +++ b/library/theories/measure_theory/extended_real.lean @@ -31,10 +31,12 @@ protected definition prio := num.pred real.prio /- arithmetic operations on the ereals -/ -definition ereal_has_zero [instance] [priority ereal.prio] : has_zero ereal := +attribute [instance] [priority ereal.prio] +definition ereal_has_zero : has_zero ereal := has_zero.mk (of_real 0) -definition ereal_has_one [instance] [priority ereal.prio] : has_one ereal := +attribute [instance] [priority ereal.prio] +definition ereal_has_one : has_one ereal := has_one.mk (of_real 1) protected definition add : ereal → ereal → ereal @@ -49,7 +51,8 @@ protected definition neg : ereal → ereal | ∞ := -∞ | -∞ := ∞ -private definition blow_up [reducible] : ereal → ereal +attribute [reducible] +private definition blow_up : ereal → ereal | (of_real x) := if x = 0 then of_real 0 else if x > 0 then ∞ else -∞ | ∞ := ∞ | -∞ := -∞ @@ -61,18 +64,22 @@ protected definition mul : ereal → ereal → ereal | -∞ a := ereal.neg (blow_up a) | a -∞ := ereal.neg (blow_up a) -definition ereal_has_add [instance] [priority ereal.prio] : has_add ereal := +attribute [instance] [priority ereal.prio] +definition ereal_has_add : has_add ereal := has_add.mk ereal.add -definition ereal_has_neg [instance] [priority ereal.prio] : has_neg ereal := +attribute [instance] [priority ereal.prio] +definition ereal_has_neg : has_neg ereal := has_neg.mk ereal.neg protected definition sub (u v : ereal) : ereal := u + -v -definition ereal_has_sub [instance] [priority ereal.prio] : has_sub ereal := +attribute [instance] [priority ereal.prio] +definition ereal_has_sub : has_sub ereal := has_sub.mk ereal.sub -definition ereal_has_mul [instance] [priority ereal.prio] : has_mul ereal := +attribute [instance] [priority ereal.prio] +definition ereal_has_mul : has_mul ereal := has_mul.mk ereal.mul protected theorem zero_def : (0 : ereal) = of_real 0 := rfl @@ -281,7 +288,8 @@ by krewrite [ereal.mul_comm, ereal.one_mul] -- Note that distributivity fails, e.g. ∞ ⬝ (-1 + 1) ≠ ∞ * -1 + ∞ * 1 -protected definition comm_monoid [trans_instance] : comm_monoid ereal := +attribute [trans_instance] +protected definition comm_monoid : comm_monoid ereal := ⦃comm_monoid, mul := ereal.mul, mul_assoc := ereal.mul_assoc, @@ -291,7 +299,8 @@ protected definition comm_monoid [trans_instance] : comm_monoid ereal := mul_comm := ereal.mul_comm ⦄ -protected definition add_comm_monoid [trans_instance] : add_comm_monoid ereal := +attribute [trans_instance] +protected definition add_comm_monoid : add_comm_monoid ereal := ⦃add_comm_monoid, add := ereal.add, add_assoc := ereal.add_assoc, @@ -311,7 +320,8 @@ protected definition le : ereal → ereal → Prop | ∞ (of_real y) := false | ∞ -∞ := false -definition ereal_has_le [instance] [priority ereal.prio] : has_le ereal := +attribute [instance] [priority ereal.prio] +definition ereal_has_le : has_le ereal := has_le.mk ereal.le theorem of_real_le_of_real (x y : real) : of_real x ≤ of_real y ↔ x ≤ y := @@ -359,7 +369,8 @@ protected theorem le_antisymm : ∀ u v : ereal, u ≤ v → v ≤ u → u = v protected definition lt (x y : ereal) : Prop := x ≤ y ∧ x ≠ y -definition ereal_has_lt [instance] [priority ereal.prio] : +attribute [instance] [priority ereal.prio] +definition ereal_has_lt : has_lt ereal := has_lt.mk ereal.lt @@ -390,7 +401,8 @@ theorem neg_infty_lt_of_real (x : real) : -∞ < of_real x := and.intro trivial theorem of_real_lt_infty (x : real) : of_real x < ∞ := and.intro trivial (ne.symm !infty_ne_of_real) -protected definition decidable_linear_order [trans_instance] : decidable_linear_order ereal := +attribute [trans_instance] +protected definition decidable_linear_order : decidable_linear_order ereal := ⦃decidable_linear_order, le := ereal.le, le_refl := ereal.le_refl, diff --git a/library/theories/measure_theory/sigma_algebra.lean b/library/theories/measure_theory/sigma_algebra.lean index 008effcd55..79b3e4f8d3 100644 --- a/library/theories/measure_theory/sigma_algebra.lean +++ b/library/theories/measure_theory/sigma_algebra.lean @@ -112,7 +112,8 @@ theorem measurable_generated_by {G : set (set X)} : protected definition le (M N : sigma_algebra X) : Prop := @sets _ M ⊆ @sets _ N -definition sigma_algebra_has_le [instance] : +attribute [instance] +definition sigma_algebra_has_le : has_le (sigma_algebra X) := has_le.mk sigma_algebra.le @@ -200,7 +201,8 @@ protected theorem Sup_le {N : sigma_algebra X} {MS : set (sigma_algebra X)} (H : have (⋃ M ∈ MS, @sets _ M) ⊆ @sets _ N, from bUnion_subset H, sets_generated_by_initial this -protected definition complete_lattice [trans_instance] : +attribute [trans_instance] +protected definition complete_lattice : complete_lattice (sigma_algebra X) := ⦃complete_lattice, le := sigma_algebra.le, diff --git a/library/theories/number_theory/primes.lean b/library/theories/number_theory/primes.lean index c329d00490..e0008571dd 100644 --- a/library/theories/number_theory/primes.lean +++ b/library/theories/number_theory/primes.lean @@ -11,7 +11,8 @@ open bool subtype namespace nat open decidable -definition prime [reducible] (p : nat) := p ≥ 2 ∧ ∀ m, m ∣ p → m = 1 ∨ m = p +attribute [reducible] +definition prime (p : nat) := p ≥ 2 ∧ ∀ m, m ∣ p → m = 1 ∨ m = p definition prime_ext (p : nat) := p ≥ 2 ∧ ∀ m, m ≤ p → m ∣ p → m = 1 ∨ m = p local attribute prime_ext [reducible] @@ -27,7 +28,8 @@ iff.intro intro m l d, exact h₂ m d end -definition decidable_prime [instance] (p : nat) : decidable (prime p) := +attribute [instance] +definition decidable_prime (p : nat) : decidable (prime p) := decidable_of_decidable_of_iff _ (prime_ext_iff_prime p) lemma ge_two_of_prime {p : nat} : prime p → p ≥ 2 := diff --git a/library/theories/topology/basic.lean b/library/theories/topology/basic.lean index 465c6f7587..39bbe89d8c 100644 --- a/library/theories/topology/basic.lean +++ b/library/theories/topology/basic.lean @@ -61,7 +61,8 @@ end /- closed sets -/ -definition closed [reducible] (s : set X) : Prop := Open (-s) +attribute [reducible] +definition closed (s : set X) : Prop := Open (-s) theorem closed_iff_Open_compl (s : set X) : closed s ↔ Open (-s) := !iff.refl @@ -166,7 +167,8 @@ end topology structure T1_space [class] (X : Type) extends topology X := (T1 : ∀ {x y}, x ≠ y → ∃ U, U ∈ opens ∧ x ∈ U ∧ y ∉ U) -protected definition T0_space.of_T1 [trans_instance] {X : Type} [T : T1_space X] : +attribute [trans_instance] +protected definition T0_space.of_T1 {X : Type} [T : T1_space X] : T0_space X := ⦃T0_space, T, T0 := abstract @@ -208,7 +210,8 @@ end topology structure T2_space [class] (X : Type) extends topology X := (T2 : ∀ {x y}, x ≠ y → ∃ U V, U ∈ opens ∧ V ∈ opens ∧ x ∈ U ∧ y ∈ V ∧ U ∩ V = ∅) -protected definition T1_space.of_T2 [trans_instance] {X : Type} [T : T2_space X] : +attribute [trans_instance] +protected definition T1_space.of_T2 {X : Type} [T : T2_space X] : T1_space X := ⦃T1_space, T, T1 := abstract @@ -247,7 +250,8 @@ inductive opens_generated_by {X : Type} (B : set (set X)) : set X → Prop := opens_generated_by B (s ∩ t) | sUnion_mem : ∀ ⦃S : set (set X)⦄, S ⊆ opens_generated_by B → opens_generated_by B (⋃₀ S) -protected definition generated_by [instance] {X : Type} (B : set (set X)) : topology X := +attribute [instance] +protected definition generated_by {X : Type} (B : set (set X)) : topology X := ⦃topology, opens := opens_generated_by B, univ_mem_opens := opens_generated_by.univ_mem B, diff --git a/library/theories/topology/order_topology.lean b/library/theories/topology/order_topology.lean index 25fc35b132..308835100c 100644 --- a/library/theories/topology/order_topology.lean +++ b/library/theories/topology/order_topology.lean @@ -14,7 +14,8 @@ variables {X : Type} [linear_strong_order_pair X] definition linorder_generators : set (set X) := {y | ∃ a, y = '(a, ∞) } ∪ {y | ∃ a, y = '(-∞, a)} -definition linorder_topology [instance] : topology X := +attribute [instance] +definition linorder_topology : topology X := topology.generated_by linorder_generators theorem Open_Ioi {a : X} : Open '(a, ∞) := @@ -57,7 +58,8 @@ section exists.intro y (exists.intro x (and.intro (and.intro `x < y` `x < y`) this)) end -protected definition T2_space.of_linorder_topology [trans_instance] : +attribute [trans_instance] +protected definition T2_space.of_linorder_topology : T2_space X := ⦃ T2_space, linorder_topology, T2 := abstract diff --git a/tests/lean/640b.lean b/tests/lean/640b.lean index 5e74dc2905..e24647743c 100644 --- a/tests/lean/640b.lean +++ b/tests/lean/640b.lean @@ -1,2 +1,3 @@ -abbreviation bar [parsing_only] := @eq +attribute [parsing_only] +abbreviation bar := @eq check @bar diff --git a/tests/lean/abbrev1.lean b/tests/lean/abbrev1.lean index 1654767574..22158f4124 100644 --- a/tests/lean/abbrev1.lean +++ b/tests/lean/abbrev1.lean @@ -12,7 +12,8 @@ set_option pp.abbreviations true print definition tst -abbreviation id2 [parsing_only] {A : Type} (a : A) := a +attribute [parsing_only] +abbreviation id2 {A : Type} (a : A) := a definition tst1 :nat := id2 10 diff --git a/tests/lean/bad_class.lean b/tests/lean/bad_class.lean index 62e2c7f6be..f27a4291b7 100644 --- a/tests/lean/bad_class.lean +++ b/tests/lean/bad_class.lean @@ -3,6 +3,7 @@ namespace foo definition subsingleton (A : Type) := ∀⦃a b : A⦄, a = b attribute subsingleton [class] -protected definition prop.subsingleton [instance] (P : Prop) : subsingleton P := +attribute [instance] +protected definition prop.subsingleton (P : Prop) : subsingleton P := λa b, proof_irrel _ _ end foo diff --git a/tests/lean/change1.lean b/tests/lean/change1.lean index 8fe4d289a5..56dfab08cb 100644 --- a/tests/lean/change1.lean +++ b/tests/lean/change1.lean @@ -1,6 +1,7 @@ open tactic nat expr option -definition succ_eq_add [defeq] (n : nat) : succ n = n + 1 := +attribute [defeq] +definition succ_eq_add (n : nat) : succ n = n + 1 := rfl example (a b : nat) : a = b → succ (succ a) = succ (b + 1) := diff --git a/tests/lean/change2.lean b/tests/lean/change2.lean index 235647c661..fd228caa95 100644 --- a/tests/lean/change2.lean +++ b/tests/lean/change2.lean @@ -1,6 +1,7 @@ open tactic nat expr option -definition succ_eq_add [defeq] (n : nat) : succ n = n + 0 + 1 := +attribute [defeq] +definition succ_eq_add (n : nat) : succ n = n + 0 + 1 := rfl example (a b : nat) : a = b → succ (succ a) = succ (b + 1) := diff --git a/tests/lean/char_lits.lean.expected.out b/tests/lean/char_lits.lean.expected.out index fa82cf1b84..fd16fbb736 100644 --- a/tests/lean/char_lits.lean.expected.out +++ b/tests/lean/char_lits.lean.expected.out @@ -4,4 +4,4 @@ char.of_nat 97 : char '\\' aaa\ -aaa' +aaa' \ No newline at end of file diff --git a/tests/lean/coe4.lean b/tests/lean/coe4.lean index 0fde37b34b..2084b34844 100644 --- a/tests/lean/coe4.lean +++ b/tests/lean/coe4.lean @@ -1,7 +1,8 @@ structure Functor (A : Type) := (fn : A → A → A) (inj : ∀ x y, fn x = fn y → x = y) -definition coe_functor_to_fn [instance] (A : Type) : has_coe_to_fun (Functor A) := +attribute [instance] +definition coe_functor_to_fn (A : Type) : has_coe_to_fun (Functor A) := has_coe_to_fun.mk (A → A → A) Functor.fn constant f : Functor nat diff --git a/tests/lean/coe5.lean b/tests/lean/coe5.lean index 46bb0c1809..ba310eb1af 100644 --- a/tests/lean/coe5.lean +++ b/tests/lean/coe5.lean @@ -1,6 +1,7 @@ open tactic -definition expr_to_app [instance] : has_coe_to_fun expr := +attribute [instance] +definition expr_to_app : has_coe_to_fun expr := has_coe_to_fun.mk (expr → expr) (λ e, expr.app e) constants f a b : expr diff --git a/tests/lean/coe6.lean b/tests/lean/coe6.lean index bd6388abe4..574a40f81b 100644 --- a/tests/lean/coe6.lean +++ b/tests/lean/coe6.lean @@ -1,7 +1,8 @@ structure Group := (carrier : Type) (mul : carrier → carrier → carrier) (one : carrier) -definition Group_to_Type [instance] : has_coe_to_sort Group := +attribute [instance] +definition Group_to_Type : has_coe_to_sort Group := has_coe_to_sort.mk Type Group.carrier constant g : Group.{1} diff --git a/tests/lean/defeq1.lean b/tests/lean/defeq1.lean index 4a95f66305..004b0330fc 100644 --- a/tests/lean/defeq1.lean +++ b/tests/lean/defeq1.lean @@ -1,7 +1,8 @@ open nat tactic variables {A : Type} -definition succ_eq_add [defeq] (n : nat) : succ n = n + 1 := +attribute [defeq] +definition succ_eq_add (n : nat) : succ n = n + 1 := rfl example (n m : nat) (H : succ (succ n) = succ m) : true := diff --git a/tests/lean/defeq_simp1.lean b/tests/lean/defeq_simp1.lean index 3b3af0e8ac..432fc79632 100644 --- a/tests/lean/defeq_simp1.lean +++ b/tests/lean/defeq_simp1.lean @@ -1,4 +1,5 @@ -definition nat_has_add2 [reducible] : has_add nat := +attribute [reducible] +definition nat_has_add2 : has_add nat := has_add.mk (λ x y : nat, x + y) set_option pp.all true @@ -18,7 +19,8 @@ by do get_local `H >>= infer_type >>= defeq_simp >>= trace, constructor -definition nat_has_add3 [reducible] : nat → has_add nat := +attribute [reducible] +definition nat_has_add3 : nat → has_add nat := λ n, has_add.mk (λ x y : nat, x + y) constant x2 : nat -- update the environment to force defeq_canonize cache to be reset diff --git a/tests/lean/defeq_simp_lemmas1.lean b/tests/lean/defeq_simp_lemmas1.lean index 06673267b2..b69080c86a 100644 --- a/tests/lean/defeq_simp_lemmas1.lean +++ b/tests/lean/defeq_simp_lemmas1.lean @@ -8,10 +8,14 @@ definition g (x y : A) := h y definition f (x y z : A) := g (g x y) z definition d (x y z w : A) := f (f x y z) (f y z w) (f x w z) -definition h.def [defeq] (x : A) : h x = q x := rfl -definition g.def [defeq] (x y : A) : g x y = h y := rfl -definition f.def [defeq] (x y z : A) : f x y z = g (g x y) z := rfl -definition d.def [defeq] (x y z w : A) : d x y z w = f (f x y z) (f y z w) (f x w z) := rfl +attribute [defeq] +definition h.def (x : A) : h x = q x := rfl +attribute [defeq] +definition g.def (x y : A) : g x y = h y := rfl +attribute [defeq] +definition f.def (x y z : A) : f x y z = g (g x y) z := rfl +attribute [defeq] +definition d.def (x y z w : A) : d x y z w = f (f x y z) (f y z w) (f x w z) := rfl print [defeq] end foo diff --git a/tests/lean/defeq_simp_lemmas2.lean b/tests/lean/defeq_simp_lemmas2.lean index a722f662f4..53902b22bb 100644 --- a/tests/lean/defeq_simp_lemmas2.lean +++ b/tests/lean/defeq_simp_lemmas2.lean @@ -8,15 +8,23 @@ definition g (x y : A) := h y definition f (x y z : A) := g (g x y) z definition d (x y z w : A) := f (f x y z) (f y z w) (f x w z) -definition h.rfl [defeq] (x : A) : h x = x := rfl -definition g.rfl [defeq] (x y : A) : g x y = y := rfl -definition f.rfl [defeq] (x y z : A) : f x y z = z := rfl -definition d.rfl [defeq] (x y z w : A) : d x y z w = z := rfl +attribute [defeq] +definition h.rfl (x : A) : h x = x := rfl +attribute [defeq] +definition g.rfl (x y : A) : g x y = y := rfl +attribute [defeq] +definition f.rfl (x y z : A) : f x y z = z := rfl +attribute [defeq] +definition d.rfl (x y z w : A) : d x y z w = z := rfl -definition h.def [defeq] (x : A) : h x = q x := rfl -definition g.def [defeq] (x y : A) : g x y = h y := rfl -definition f.def [defeq] (x y z : A) : f x y z = g (g x y) z := rfl -definition d.def [defeq] (x y z w : A) : d x y z w = f (f x y z) (f y z w) (f x w z) := rfl +attribute [defeq] +definition h.def (x : A) : h x = q x := rfl +attribute [defeq] +definition g.def (x y : A) : g x y = h y := rfl +attribute [defeq] +definition f.def (x y z : A) : f x y z = g (g x y) z := rfl +attribute [defeq] +definition d.def (x y z w : A) : d x y z w = f (f x y z) (f y z w) (f x w z) := rfl -- Confirm that more recent annotations get priority print [defeq] diff --git a/tests/lean/inst.lean b/tests/lean/inst.lean index 5d0a75a1c8..23af8de9cb 100644 --- a/tests/lean/inst.lean +++ b/tests/lean/inst.lean @@ -8,13 +8,16 @@ definition val {A : Type} (c : C A) : A := C.rec (λa, a) c constant magic (A : Type) : A -definition C_magic [instance] [priority std.priority.max] (A : Type) : C A := +attribute [instance] [priority std.priority.max] +definition C_magic (A : Type) : C A := C.mk (magic A) -definition C_prop [instance] : C Prop := +attribute [instance] +definition C_prop : C Prop := C.mk true -definition C_prod [instance] {A B : Type} (Ha : C A) (Hb : C B) : C (prod A B) := +attribute [instance] +definition C_prod {A B : Type} (Ha : C A) (Hb : C B) : C (prod A B) := C.mk (pair (val Ha) (val Hb)) -- C_magic will be used because it has max priority diff --git a/tests/lean/inst.lean.expected.out b/tests/lean/inst.lean.expected.out index 8f9abdb0bb..a043d28ac0 100644 --- a/tests/lean/inst.lean.expected.out +++ b/tests/lean/inst.lean.expected.out @@ -1,5 +1,5 @@ -inst.lean:11:11:failed to generate bytecode for 'C_magic' +inst.lean:12:11:failed to generate bytecode for 'C_magic' code generation failed, VM does not have code for 'magic' -inst.lean:21:11:failed to generate bytecode for 'test' +inst.lean:24:11:failed to generate bytecode for 'test' code generation failed, VM does not have code for 'magic' C.mk (magic (prod Prop Prop)) diff --git a/tests/lean/interactive/class_bug.lean b/tests/lean/interactive/class_bug.lean index 17f1d989c5..1fc0f1e66c 100644 --- a/tests/lean/interactive/class_bug.lean +++ b/tests/lean/interactive/class_bug.lean @@ -1,6 +1,7 @@ import data.nat.basic open nonempty inhabited nat classical -theorem int_inhabited [instance] : inhabited nat := inhabited.mk zero +attribute [instance] +theorem int_inhabited : inhabited nat := inhabited.mk zero check epsilon (λ x : nat, true) diff --git a/tests/lean/interactive/num2.lean b/tests/lean/interactive/num2.lean index 06c5e02270..0f535b2f5f 100644 --- a/tests/lean/interactive/num2.lean +++ b/tests/lean/interactive/num2.lean @@ -13,7 +13,8 @@ one : pos_num| bit1 : pos_num → pos_num| bit0 : pos_num → pos_num -theorem pos_num.is_inhabited [instance] : inhabited pos_num := +attribute [instance] +theorem pos_num.is_inhabited : inhabited pos_num := inhabited.mk pos_num.one namespace pos_num @@ -28,7 +29,8 @@ inductive num : Type := zero : num, pos : pos_num → num -theorem num.is_inhabited [instance] : inhabited num := +attribute [instance] +theorem num.is_inhabited : inhabited num := inhabited.mk num.zero namespace num diff --git a/tests/lean/interactive/whnfinst.lean b/tests/lean/interactive/whnfinst.lean index cec0576cfd..c8f8e54abd 100644 --- a/tests/lean/interactive/whnfinst.lean +++ b/tests/lean/interactive/whnfinst.lean @@ -1,7 +1,8 @@ import logic open decidable -definition decidable_bin_rel [reducible] {A : Type} (R : A → A → Prop) := Πx y, decidable (R x y) +attribute [reducible] +definition decidable_bin_rel {A : Type} (R : A → A → Prop) := Πx y, decidable (R x y) section variable {A : Type} diff --git a/tests/lean/pattern_pp.lean b/tests/lean/pattern_pp.lean index 7a4a521160..ae7aec7af0 100644 --- a/tests/lean/pattern_pp.lean +++ b/tests/lean/pattern_pp.lean @@ -1,9 +1,11 @@ definition Sum : nat → (nat → nat) → nat := sorry -definition Sum_weird [forward] (f g h : nat → nat) (n : nat) : (Sum n (λ x, f (g (h x)))) = 1 := sorry +attribute [forward] +definition Sum_weird (f g h : nat → nat) (n : nat) : (Sum n (λ x, f (g (h x)))) = 1 := sorry print Sum_weird /- -definition Sum_weird [forward] : ∀ (f g h : nat → nat) (n : nat), eq (Sum n (λ (x : nat), f (g (h x)))) 1 := +attribute [forward] +definition Sum_weird : ∀ (f g h : nat → nat) (n : nat), eq (Sum n (λ (x : nat), f (g (h x)))) 1 := λ (f g h : nat → nat) (n : nat), sorry (multi-)patterns: ?M_1 : nat → nat, ?M_2 : nat → nat, ?M_3 : nat → nat, ?M_4 : nat diff --git a/tests/lean/perf/perm_ac_100.lean b/tests/lean/perf/perm_ac_100.lean index b9fd19de4c..4900925e76 100644 --- a/tests/lean/perf/perm_ac_100.lean +++ b/tests/lean/perf/perm_ac_100.lean @@ -1,6 +1,7 @@ import data.list.perm open list perm option nat -definition denote [reducible] {X : Type} (default : X) [add_comm_semigroup X] (xs : list X) : list nat -> X +attribute [reducible] +definition denote {X : Type} (default : X) [add_comm_semigroup X] (xs : list X) : list nat -> X | nil := default | (cons i is) := match nth xs i with | none := default diff --git a/tests/lean/perf/perm_ac_200.lean b/tests/lean/perf/perm_ac_200.lean index a6e88b8560..621f5f4bff 100644 --- a/tests/lean/perf/perm_ac_200.lean +++ b/tests/lean/perf/perm_ac_200.lean @@ -1,6 +1,7 @@ import data.list.perm open list perm option nat -definition denote [reducible] {X : Type} (default : X) [add_comm_semigroup X] (xs : list X) : list nat -> X +attribute [reducible] +definition denote {X : Type} (default : X) [add_comm_semigroup X] (xs : list X) : list nat -> X | nil := default | (cons i is) := match nth xs i with | none := default diff --git a/tests/lean/print_reducible.lean b/tests/lean/print_reducible.lean index 6b912a8bfa..06f1defc3c 100644 --- a/tests/lean/print_reducible.lean +++ b/tests/lean/print_reducible.lean @@ -1,12 +1,17 @@ prelude -definition id₁ [reducible] {A : Type} (a : A) := a -definition id₂ [reducible] {A : Type} (a : A) := a +attribute [reducible] +definition id₁ {A : Type} (a : A) := a +attribute [reducible] +definition id₂ {A : Type} (a : A) := a -definition id₅ [irreducible] {A : Type} (a : A) := a -definition id₆ [irreducible] {A : Type} (a : A) := a +attribute [irreducible] +definition id₅ {A : Type} (a : A) := a +attribute [irreducible] +definition id₆ {A : Type} (a : A) := a -definition pr [reducible] {A B : Type} (a : A) (b : B) := a +attribute [reducible] +definition pr {A B : Type} (a : A) (b : B) := a definition pr2 {A B : Type} (a : A) (b : B) := a print [reducible] diff --git a/tests/lean/run/808.lean b/tests/lean/run/808.lean index 7d53c9751a..36f9089734 100644 --- a/tests/lean/run/808.lean +++ b/tests/lean/run/808.lean @@ -4,6 +4,8 @@ postfix `x`:(max+1) := eq postfix [priority 1] `y`:max := eq -definition foo [instance] [priority 1] : inhabited nat := inhabited.mk nat.zero +attribute [instance] [priority 1] +definition foo : inhabited nat := inhabited.mk nat.zero -definition bar [unfold 1] := @eq +attribute [unfold 1] +definition bar := @eq diff --git a/tests/lean/run/cases_crash1.lean b/tests/lean/run/cases_crash1.lean index b4438097fe..0623003a27 100644 --- a/tests/lean/run/cases_crash1.lean +++ b/tests/lean/run/cases_crash1.lean @@ -3,7 +3,8 @@ open tactic axiom Sorry : ∀ A : Type, A inductive Enum : Type := ea | eb | ec | ed -noncomputable definition Enum_dec_eq [instance] : decidable_eq Enum := +attribute [instance] +noncomputable definition Enum_dec_eq : decidable_eq Enum := by do a ← intro `a, cases a, b ← intro `b, cases b, right >> reflexivity, diff --git a/tests/lean/run/cases_tac1.lean b/tests/lean/run/cases_tac1.lean index 4771b0b19a..da2f5b37d7 100644 --- a/tests/lean/run/cases_tac1.lean +++ b/tests/lean/run/cases_tac1.lean @@ -10,10 +10,12 @@ definition head {A : Type} : ∀ {n : nat}, vec A (n+1) → A definition tail {A : Type} : ∀ {n : nat}, vec A (n+1) → vec A n | n (cons h t) := t -definition head_cons [defeq] {A : Type} {n : nat} (a : A) (v : vec A n) : head (cons a v) = a := +attribute [defeq] +definition head_cons {A : Type} {n : nat} (a : A) (v : vec A n) : head (cons a v) = a := rfl -definition tail_cons [defeq] {A : Type} {n : nat} (a : A) (v : vec A n) : tail (cons a v) = v := +attribute [defeq] +definition tail_cons {A : Type} {n : nat} (a : A) (v : vec A n) : tail (cons a v) = v := rfl example {A : Type} {n : nat} (v w : vec A (n+1)) : head v = head w → tail v = tail w → v = w := diff --git a/tests/lean/run/congr_imp_bug.lean b/tests/lean/run/congr_imp_bug.lean index a9ec9ef30e..734ede1768 100644 --- a/tests/lean/run/congr_imp_bug.lean +++ b/tests/lean/run/congr_imp_bug.lean @@ -39,7 +39,8 @@ theorem compose21 theorem congr_and : congr.struc2 iff iff iff and := sorry -theorem congr_and_comp [instance] {T : Type} {R : T → T → Prop} {f1 f2 : T → Prop} +attribute [instance] +theorem congr_and_comp {T : Type} {R : T → T → Prop} {f1 f2 : T → Prop} (C1 : struc R iff f1) (C2 : struc R iff f2) : congr.struc R iff (λx, f1 x ∧ f2 x) := congr.compose21 congr_and C1 C2 diff --git a/tests/lean/run/dsimp_at1.lean b/tests/lean/run/dsimp_at1.lean index 5f8f3c281b..2396b3df7b 100644 --- a/tests/lean/run/dsimp_at1.lean +++ b/tests/lean/run/dsimp_at1.lean @@ -3,7 +3,8 @@ open tactic constants (A : Type.{1}) (x y : A) definition f (z : A) : A := z -definition f.def [defeq] (z:A) : f z = z := rfl +attribute [defeq] +definition f.def (z:A) : f z = z := rfl definition foo (z₁ z₂ : A) : f z₁ = f z₂ → z₁ = z₂ := by do H ← intro `H, diff --git a/tests/lean/run/elab_bug1.lean b/tests/lean/run/elab_bug1.lean index 5d9f081dfa..1d943591a1 100644 --- a/tests/lean/run/elab_bug1.lean +++ b/tests/lean/run/elab_bug1.lean @@ -28,7 +28,8 @@ theorem congr_app {T1 : Type} {T2 : Type} (R1 : T1 → T1 → Prop) (R2 : T2 → -- General tools to build instances -- -------------------------------- -theorem congr_trivial [instance] {T : Type} (R : T → T → Prop) : congruence R R id := +attribute [instance] +theorem congr_trivial {T : Type} (R : T → T → Prop) : congruence R R id := congruence.mk (take x y H, H) theorem congr_const {T2 : Type} (R2 : T2 → T2 → Prop) (H : reflexive R2) : @@ -37,22 +38,27 @@ take T1 R1 c, congruence.mk (take x y H1, H c) -- congruences for logic -theorem congr_const_iff [instance] (T1 : Type) (R1 : T1 → T1 → Prop) (c : Prop) : +attribute [instance] +theorem congr_const_iff (T1 : Type) (R1 : T1 → T1 → Prop) (c : Prop) : congruence R1 iff (const T1 c) := congr_const iff iff.refl T1 R1 c -theorem congr_or [instance] (T : Type) (R : T → T → Prop) (f1 f2 : T → Prop) +attribute [instance] +theorem congr_or (T : Type) (R : T → T → Prop) (f1 f2 : T → Prop) [H1 : congruence R iff f1] [H2 : congruence R iff f2] : congruence R iff (λx, f1 x ∨ f2 x) := sorry -theorem congr_implies [instance] (T : Type) (R : T → T → Prop) (f1 f2 : T → Prop) +attribute [instance] +theorem congr_implies (T : Type) (R : T → T → Prop) (f1 f2 : T → Prop) [H1 : congruence R iff f1] [H2 : congruence R iff f2] : congruence R iff (λx, f1 x → f2 x) := sorry -theorem congr_iff [instance] (T : Type) (R : T → T → Prop) (f1 f2 : T → Prop) +attribute [instance] +theorem congr_iff (T : Type) (R : T → T → Prop) (f1 f2 : T → Prop) [H1 : congruence R iff f1] [H2 : congruence R iff f2] : congruence R iff (λx, f1 x ↔ f2 x) := sorry -theorem congr_not [instance] (T : Type) (R : T → T → Prop) (f : T → Prop) +attribute [instance] +theorem congr_not (T : Type) (R : T → T → Prop) (f : T → Prop) [H : congruence R iff f] : congruence R iff (λx, ¬ f x) := sorry diff --git a/tests/lean/run/group.lean b/tests/lean/run/group.lean index f5d29af60c..92952dc4f6 100644 --- a/tests/lean/run/group.lean +++ b/tests/lean/run/group.lean @@ -19,7 +19,8 @@ mk_group : Π (A : Type), group_struct A → group definition carrier (g : group) : Type := group.rec (λ c s, c) g -definition group_to_struct [instance] (g : group) : group_struct (carrier g) +attribute [instance] +definition group_to_struct (g : group) : group_struct (carrier g) := group.rec (λ (A : Type) (s : group_struct A), s) g check group_struct diff --git a/tests/lean/run/group3.lean b/tests/lean/run/group3.lean index d7ac1c2d21..5b4cd98940 100644 --- a/tests/lean/run/group3.lean +++ b/tests/lean/run/group3.lean @@ -48,7 +48,8 @@ end semigroup section variables {A : Type} [s : semigroup A] include s - definition semigroup_has_mul [instance] : has_mul A := has_mul.mk semigroup.mul + attribute [instance] + definition semigroup_has_mul : has_mul A := has_mul.mk semigroup.mul end diff --git a/tests/lean/run/interp.lean b/tests/lean/run/interp.lean index fbf9259c45..38bcc7ee24 100644 --- a/tests/lean/run/interp.lean +++ b/tests/lean/run/interp.lean @@ -8,7 +8,8 @@ inductive univ := open univ -definition interp [reducible] : univ → Type₁ +attribute [reducible] +definition interp : univ → Type₁ | ubool := bool | unat := nat | (uarrow fr to) := interp fr → interp to diff --git a/tests/lean/run/match_convoy.lean b/tests/lean/run/match_convoy.lean index dbec601b36..94c867b38c 100644 --- a/tests/lean/run/match_convoy.lean +++ b/tests/lean/run/match_convoy.lean @@ -40,7 +40,8 @@ quot.lift_on b (λ l, list.count a l) definition subbag {A} (b₁ b₂ : bag A) := ∀ a, count a b₁ ≤ count a b₂ infix ⊆ := subbag -definition decidable_subbag [instance] {A} (b₁ b₂ : bag A) : decidable (b₁ ⊆ b₂) := +attribute [instance] +definition decidable_subbag {A} (b₁ b₂ : bag A) : decidable (b₁ ⊆ b₂) := quot.rec_on_subsingleton₂ b₁ b₂ (λ l₁ l₂, match subcount l₁ l₂, rfl : ∀ (b : _), subcount l₁ l₂ = b → _ with | tt, H := decidable.tt (all_of_subcount_eq_tt H) @@ -49,7 +50,8 @@ quot.rec_on_subsingleton₂ b₁ b₂ (λ l₁ l₂, (λ w hw, absurd (h w) hw)) end) -definition decidable_subbag2 [instance] {A} (b₁ b₂ : bag A) : decidable (b₁ ⊆ b₂) := +attribute [instance] +definition decidable_subbag2 {A} (b₁ b₂ : bag A) : decidable (b₁ ⊆ b₂) := quot.rec_on_subsingleton₂ b₁ b₂ (λ l₁ l₂, match sigma.mk (subcount l₁ l₂) rfl : (Σ (b : _), subcount l₁ l₂ = b) → _ with | sigma.mk tt H := decidable.tt (all_of_subcount_eq_tt H) @@ -60,7 +62,8 @@ quot.rec_on_subsingleton₂ b₁ b₂ (λ l₁ l₂, local notation ⟦ a , b ⟧ := sigma.mk a b -definition decidable_subbag3 [instance] {A} (b₁ b₂ : bag A) : decidable (b₁ ⊆ b₂) := +attribute [instance] +definition decidable_subbag3 {A} (b₁ b₂ : bag A) : decidable (b₁ ⊆ b₂) := quot.rec_on_subsingleton₂ b₁ b₂ (λ l₁ l₂, match ⟦subcount l₁ l₂, rfl⟧ : (Σ (b : _), subcount l₁ l₂ = b) → _ with | ⟦tt, H⟧ := decidable.tt (all_of_subcount_eq_tt H) diff --git a/tests/lean/run/meta_tac4.lean b/tests/lean/run/meta_tac4.lean index 638c520c63..c4aa19e37b 100644 --- a/tests/lean/run/meta_tac4.lean +++ b/tests/lean/run/meta_tac4.lean @@ -1,7 +1,8 @@ open tactic name list definition foo (a : nat) := a + 1 > 0 -definition boo [reducible] (a : nat) := a + 1 > 0 +attribute [reducible] +definition boo (a : nat) := a + 1 > 0 example : ∀ (a b : nat), foo a → boo a → a + 1 > 0 → foo a := by do diff --git a/tests/lean/run/mk_dec_eq1.lean b/tests/lean/run/mk_dec_eq1.lean index d960760a3d..69c86b1ebd 100644 --- a/tests/lean/run/mk_dec_eq1.lean +++ b/tests/lean/run/mk_dec_eq1.lean @@ -4,7 +4,8 @@ namespace test inductive enum1 : Type := ea | eb | ec | ed -definition enum1_dec_eq [instance] : decidable_eq enum1 := +attribute [instance] +definition enum1_dec_eq : decidable_eq enum1 := by mk_dec_eq_instance inductive Expr := @@ -13,7 +14,8 @@ inductive Expr := | Elet : Expr → Expr | bla : list nat → Expr -definition Expr_has_dec_eq [instance] : decidable_eq Expr := +attribute [instance] +definition Expr_has_dec_eq : decidable_eq Expr := by mk_dec_eq_instance definition prod_decidable {A : Type} {B : Type} [decidable_eq A] [decidable_eq B] : decidable_eq (A × B) := diff --git a/tests/lean/run/pattern2.lean b/tests/lean/run/pattern2.lean index b9f4d1bd88..ea790db874 100644 --- a/tests/lean/run/pattern2.lean +++ b/tests/lean/run/pattern2.lean @@ -4,7 +4,8 @@ attribute g [no_pattern] namespace foo -definition lemma1 [forward] {a b : nat} : f a b = g a b := +attribute [forward] +definition lemma1 {a b : nat} : f a b = g a b := sorry end foo diff --git a/tests/lean/run/pattern3.lean b/tests/lean/run/pattern3.lean index 86d761ff70..e239df3860 100644 --- a/tests/lean/run/pattern3.lean +++ b/tests/lean/run/pattern3.lean @@ -1,6 +1,7 @@ constant Sum : (nat → nat) → nat → nat -lemma l1 [forward] (f : nat → nat) : Sum f 0 = 0 := +attribute [forward] +lemma l1 (f : nat → nat) : Sum f 0 = 0 := sorry print l1 diff --git a/tests/lean/run/priority_test.lean b/tests/lean/run/priority_test.lean index 68b1959829..1dde2469f3 100644 --- a/tests/lean/run/priority_test.lean +++ b/tests/lean/run/priority_test.lean @@ -3,16 +3,19 @@ open nat structure foo [class] := (a : nat) (b : nat) -definition i1 [instance] [priority std.priority.default+1] : foo := +attribute [instance] [priority std.priority.default+1] +definition i1 : foo := foo.mk 1 1 -definition i2 [instance] : foo := +attribute [instance] +definition i2 : foo := foo.mk 2 2 example : foo.a = 1 := rfl -definition i3 [instance] [priority std.priority.default+2] : foo := +attribute [instance] [priority std.priority.default+2] +definition i3 : foo := foo.mk 3 3 example : foo.a = 3 := diff --git a/tests/lean/run/priority_test2.lean b/tests/lean/run/priority_test2.lean index d19d508a45..e3fde75890 100644 --- a/tests/lean/run/priority_test2.lean +++ b/tests/lean/run/priority_test2.lean @@ -3,25 +3,29 @@ open nat structure foo [class] := (a : nat) (b : nat) -definition i1 [instance] [priority std.priority.default-2] : foo := +attribute [instance] [priority std.priority.default-2] +definition i1 : foo := foo.mk 1 1 example : foo.a = 1 := rfl -definition i2 [instance] [priority std.priority.default-1] : foo := +attribute [instance] [priority std.priority.default-1] +definition i2 : foo := foo.mk 2 2 example : foo.a = 2 := rfl -definition i3 [instance] : foo := +attribute [instance] +definition i3 : foo := foo.mk 3 3 example : foo.a = 3 := rfl -definition i4 [instance] [priority std.priority.default-1] : foo := +attribute [instance] [priority std.priority.default-1] +definition i4 : foo := foo.mk 4 4 example : foo.a = 3 := diff --git a/tests/lean/run/rw_set4.lean b/tests/lean/run/rw_set4.lean index df4e24d567..5927b656e7 100644 --- a/tests/lean/run/rw_set4.lean +++ b/tests/lean/run/rw_set4.lean @@ -1,6 +1,7 @@ open tactic -theorem forall_congr_prop_eq [congr] [priority std.priority.default+1] {P₁ P₂ Q₁ Q₂ : Prop} : +attribute [congr] [priority std.priority.default+1] +theorem forall_congr_prop_eq {P₁ P₂ Q₁ Q₂ : Prop} : P₁ = P₂ → (P₂ → Q₁ = Q₂) → (P₁ → Q₁) = (P₂ → Q₂) := sorry diff --git a/tests/lean/run/section5.lean b/tests/lean/run/section5.lean index be38ea3f75..bca33e98f6 100644 --- a/tests/lean/run/section5.lean +++ b/tests/lean/run/section5.lean @@ -11,7 +11,8 @@ end foo check foo -definition point_nat [instance] : point nat := +attribute [instance] +definition point_nat : point nat := point.mk nat.zero nat.zero print classes diff --git a/tests/lean/run/sigma_match.lean b/tests/lean/run/sigma_match.lean index 691f7fa40c..c8c455cd91 100644 --- a/tests/lean/run/sigma_match.lean +++ b/tests/lean/run/sigma_match.lean @@ -2,7 +2,8 @@ open sigma constant hom.{l₁ l₂} {A : Type.{l₁}} {B : Type.{l₂}} (a : A) (b : B) : Type.{max l₁ l₂} -definition arrow_ob [reducible] (A B : Type) : Type := +attribute [reducible] +definition arrow_ob (A B : Type) : Type := Σ (a : A) (b : B), hom a b definition src1 {A B : Type} (x : arrow_ob A B) : A := diff --git a/tests/lean/run/simp1.lean b/tests/lean/run/simp1.lean index 2f91a98688..41933a52dc 100644 --- a/tests/lean/run/simp1.lean +++ b/tests/lean/run/simp1.lean @@ -1,6 +1,8 @@ constants (A : Type.{1}) (f : A → A → A) (x y z : A) (g : A → A) -lemma foo [simp] : f x y = y := sorry -lemma bar [simp] : g y = z := sorry +attribute [simp] +lemma foo : f x y = y := sorry +attribute [simp] +lemma bar : g y = z := sorry open tactic diff --git a/tests/lean/run/stateT1.lean b/tests/lean/run/stateT1.lean index 607fa0ac1c..2e004bc5b1 100644 --- a/tests/lean/run/stateT1.lean +++ b/tests/lean/run/stateT1.lean @@ -1,6 +1,7 @@ meta_definition mytactic (A : Type) := stateT (list nat) tactic A -meta_definition mytactic_is_monad [instance] : monad mytactic := +attribute [instance] +meta_definition mytactic_is_monad : monad mytactic := @stateT_is_monad _ _ _ meta_definition read_lst : mytactic (list nat) := diff --git a/tests/lean/run/sum_bug.lean b/tests/lean/run/sum_bug.lean index 60009f8f72..8c4059d281 100644 --- a/tests/lean/run/sum_bug.lean +++ b/tests/lean/run/sum_bug.lean @@ -32,13 +32,16 @@ have H1 : f (inr A b1), from rfl, have H2 : f (inr A b2), from subst H H1, H2 -theorem sum_inhabited_left [instance] {A B : Type} (H : inhabited A) : inhabited (A + B) := +attribute [instance] +theorem sum_inhabited_left {A B : Type} (H : inhabited A) : inhabited (A + B) := inhabited.mk (inl B (default A)) -theorem sum_inhabited_right [instance] {A B : Type} (H : inhabited B) : inhabited (A + B) := +attribute [instance] +theorem sum_inhabited_right {A B : Type} (H : inhabited B) : inhabited (A + B) := inhabited.mk (inr A (default B)) -theorem sum_eq_decidable [instance] {A B : Type} (s1 s2 : A + B) +attribute [instance] +theorem sum_eq_decidable {A B : Type} (s1 s2 : A + B) (H1 : ∀a1 a2 : A, decidable (inl B a1 = inl B a2)) (H2 : ∀b1 b2 : B, decidable (inr A b1 = inr A b2)) : decidable (s1 = s2) := sum.rec_on s1 diff --git a/tests/lean/run/unification_hints.lean b/tests/lean/run/unification_hints.lean index 51b3edb9dc..c1d302e5dc 100644 --- a/tests/lean/run/unification_hints.lean +++ b/tests/lean/run/unification_hints.lean @@ -5,9 +5,11 @@ structure unification_hint := (pattern : unification_constraint) (constraints : namespace toy constants (A : Type.{1}) (f h : A → A) (x y z : A) -definition g [irreducible] (x y : A) : A := f z +attribute [irreducible] +definition g (x y : A) : A := f z -definition toy_hint [unify] (x y : A) : unification_hint := +attribute [unify] +definition toy_hint (x y : A) : unification_hint := unification_hint.mk (unification_constraint.mk (g x y) (f z)) [] open tactic @@ -26,7 +28,8 @@ attribute add [irreducible] open tactic -definition add_zero_hint [unify] (m n : ℕ) [has_add ℕ] [has_one ℕ] [has_zero ℕ] : unification_hint := +attribute [unify] +definition add_zero_hint (m n : ℕ) [has_add ℕ] [has_one ℕ] [has_zero ℕ] : unification_hint := unification_hint.mk (unification_constraint.mk (m + 1) (succ n)) [unification_constraint.mk m n] definition ex2 (H : n + 1 = 0) : succ n = 0 := diff --git a/tests/lean/run/univ_bug1.lean b/tests/lean/run/univ_bug1.lean index 52ca0f5a34..f823616773 100644 --- a/tests/lean/run/univ_bug1.lean +++ b/tests/lean/run/univ_bug1.lean @@ -19,7 +19,8 @@ simplifies_to.rec (λx, x) C theorem infer_eq {T : Type} (t1 t2 : T) {C : simplifies_to t1 t2} : t1 = t2 := simplifies_to.rec (λx, x) C -theorem simp_app [instance] (S T : Type) (f1 f2 : S → T) (s1 s2 : S) +attribute [instance] +theorem simp_app (S T : Type) (f1 f2 : S → T) (s1 s2 : S) (C1 : simplifies_to f1 f2) (C2 : simplifies_to s1 s2) : simplifies_to (f1 s1) (f2 s2) := simplifies_to.mk (congr (get_eq C1) (get_eq C2)) diff --git a/tests/lean/run/univ_bug2.lean b/tests/lean/run/univ_bug2.lean index c3d82a454a..10f2e5cb7b 100644 --- a/tests/lean/run/univ_bug2.lean +++ b/tests/lean/run/univ_bug2.lean @@ -14,7 +14,8 @@ namespace simplifies_to theorem get_eq {T : Type} {t1 t2 : T} (C : simplifies_to t1 t2) : t1 = t2 := simplifies_to.rec (λx, x) C -theorem simp_app [instance] (S : Type) (T : Type) (f1 f2 : S → T) (s1 s2 : S) +attribute [instance] +theorem simp_app (S : Type) (T : Type) (f1 f2 : S → T) (s1 s2 : S) [C1 : simplifies_to f1 f2] [C2 : simplifies_to s1 s2] : simplifies_to (f1 s1) (f2 s2) := mk (congr (get_eq C1) (get_eq C2)) diff --git a/tests/lean/run/vm_eval1.lean b/tests/lean/run/vm_eval1.lean index dee2339f9e..e6276b2757 100644 --- a/tests/lean/run/vm_eval1.lean +++ b/tests/lean/run/vm_eval1.lean @@ -2,7 +2,8 @@ open bool nat -- set_option trace.compiler.code_gen true -definition foo [reducible] (b : bool) : Type₁ := +attribute [reducible] +definition foo (b : bool) : Type₁ := cond b nat (nat → nat) definition bla (b : bool) : foo b → nat := diff --git a/tests/lean/run/whnfinst.lean b/tests/lean/run/whnfinst.lean index 924aa0c854..c71900a2cb 100644 --- a/tests/lean/run/whnfinst.lean +++ b/tests/lean/run/whnfinst.lean @@ -1,6 +1,7 @@ open decidable -definition decidable_bin_rel [reducible] {A : Type} (R : A → A → Prop) := Πx y, decidable (R x y) +attribute [reducible] +definition decidable_bin_rel {A : Type} (R : A → A → Prop) := Πx y, decidable (R x y) section variable {A : Type} diff --git a/tests/lean/unification_hints1.lean b/tests/lean/unification_hints1.lean index fc375fc575..ec1a33cf25 100644 --- a/tests/lean/unification_hints1.lean +++ b/tests/lean/unification_hints1.lean @@ -6,11 +6,13 @@ structure unification_hint := (pattern : unification_constraint) (constraints : namespace toy constants (A : Type.{1}) (f h : A → A) (x y z : A) -definition g [irreducible] (x y : A) : A := f z +attribute [irreducible] +definition g (x y : A) : A := f z #unify (g x y), (f z) -definition toy_hint [unify] (x y : A) : unification_hint := +attribute [unify] +definition toy_hint (x y : A) : unification_hint := unification_hint.mk (unification_constraint.mk (g x y) (f z)) [] #unify (g x y), (f z) @@ -24,7 +26,8 @@ attribute add [irreducible] #unify (n + 1), succ n -definition add_zero_hint [unify] (m n : ℕ) [has_add ℕ] [has_one ℕ] [has_zero ℕ] : unification_hint := +attribute [unify] +definition add_zero_hint (m n : ℕ) [has_add ℕ] [has_one ℕ] [has_zero ℕ] : unification_hint := unification_hint.mk (unification_constraint.mk (m + 1) (succ n)) [unification_constraint.mk m n] #unify (n + 1), (succ n) @@ -36,7 +39,8 @@ namespace canonical inductive Canonical := mk : Π (carrier : Type) (op : carrier → carrier), Canonical -definition Canonical.carrier [irreducible] (s : Canonical) : Type := +attribute [irreducible] +definition Canonical.carrier (s : Canonical) : Type := Canonical.rec_on s (λ c op, c) constants (A : Type.{1}) (f : A → A) (x : A) @@ -44,7 +48,8 @@ definition A_canonical : Canonical := Canonical.mk A f #unify (Canonical.carrier A_canonical), A -definition Canonical_hint [unify] (C : Canonical) : unification_hint := +attribute [unify] +definition Canonical_hint (C : Canonical) : unification_hint := unification_hint.mk (unification_constraint.mk (Canonical.carrier C) A) [unification_constraint.mk C A_canonical] -- TODO(dhs): we mark carrier as irreducible and prove A_canonical explicitly to work around the fact that diff --git a/tests/lean/unification_hints1.lean.expected.out b/tests/lean/unification_hints1.lean.expected.out index f4f55f608a..07baddba10 100644 --- a/tests/lean/unification_hints1.lean.expected.out +++ b/tests/lean/unification_hints1.lean.expected.out @@ -1,8 +1,8 @@ -unification_hints1.lean:9:11:failed to generate bytecode for 'toy.g' +unification_hints1.lean:10:11:failed to generate bytecode for 'toy.g' code generation failed, VM does not have code for 'toy.f' g x y =?= f z fail -unification_hints1.lean:13:11:failed to generate bytecode for 'toy.toy_hint' +unification_hints1.lean:15:11:failed to generate bytecode for 'toy.toy_hint' code generation failed, VM does not have code for 'toy.f' g x y =?= f z g x y =?= f z @@ -17,11 +17,11 @@ success unification hints: (add, nat.succ) #4 + 1 =?= succ #3 {#4 =?= #3} (toy.g, toy.f) toy.g #1 #0 =?= toy.f toy.z {} -unification_hints1.lean:43:11:failed to generate bytecode for 'canonical.A_canonical' +unification_hints1.lean:47:11:failed to generate bytecode for 'canonical.A_canonical' code generation failed, VM does not have code for 'canonical.f' Canonical.carrier A_canonical =?= A fail -unification_hints1.lean:47:11:failed to generate bytecode for 'canonical.Canonical_hint' +unification_hints1.lean:52:11:failed to generate bytecode for 'canonical.Canonical_hint' code generation failed, VM does not have code for 'canonical.f' Canonical.carrier A_canonical =?= A Canonical.carrier A_canonical =?= A diff --git a/tests/lean_before_refactoring/800.lean b/tests/lean_before_refactoring/800.lean index bcf3ead72c..100bb39e19 100644 --- a/tests/lean_before_refactoring/800.lean +++ b/tests/lean_before_refactoring/800.lean @@ -3,8 +3,10 @@ open matrix nat list variables {A : Type} {m n : nat} -definition row_vector [reducible] (A : Type) (n : nat) := matrix A 1 n -definition get_row [reducible] (M : matrix A m n) (row : fin m) : row_vector A n := +attribute [reducible] +definition row_vector (A : Type) (n : nat) := matrix A 1 n +attribute [reducible] +definition get_row (M : matrix A m n) (row : fin m) : row_vector A n := λ i j, M row j variables (M : matrix A m n) (row : fin m) (col : fin n) diff --git a/tests/lean_before_refactoring/run/679a.lean b/tests/lean_before_refactoring/run/679a.lean index 89f28a518c..2b565b9ae4 100644 --- a/tests/lean_before_refactoring/run/679a.lean +++ b/tests/lean_before_refactoring/run/679a.lean @@ -3,10 +3,12 @@ open bool nat list finset attribute finset [class] -definition fin_nat [instance] : finset nat := +attribute [instance] +definition fin_nat : finset nat := to_finset [0] -definition fin_bool [instance] : finset bool := +attribute [instance] +definition fin_bool : finset bool := to_finset [tt, ff] definition tst (A : Type) [s : finset A] : finset A := diff --git a/tests/lean_before_refactoring/run/679b.lean b/tests/lean_before_refactoring/run/679b.lean index c43356af98..1d2fd3340e 100644 --- a/tests/lean_before_refactoring/run/679b.lean +++ b/tests/lean_before_refactoring/run/679b.lean @@ -1,12 +1,15 @@ import data.finset open bool nat list finset -definition fset [class] (A : Type) := finset A +attribute [class] +definition fset (A : Type) := finset A -definition fin_nat [instance] : fset nat := +attribute [instance] +definition fin_nat : fset nat := to_finset [0] -definition fin_bool [instance] : fset bool := +attribute [instance] +definition fin_bool : fset bool := to_finset [tt, ff] definition tst (A : Type) [s : fset A] : finset A := diff --git a/tests/lean_before_refactoring/run/803.lean b/tests/lean_before_refactoring/run/803.lean index a2b65dc650..1a50eb2751 100644 --- a/tests/lean_before_refactoring/run/803.lean +++ b/tests/lean_before_refactoring/run/803.lean @@ -3,12 +3,15 @@ open algebra fin nat namespace matrix -definition vector [reducible] (A : Type) (n : nat) := fin n → A +attribute [reducible] +definition vector (A : Type) (n : nat) := fin n → A -definition to_cvec [reducible] [coercion] {A : Type} {n : nat} (v : vector A n) +attribute [reducible] [coercion] +definition to_cvec {A : Type} {n : nat} (v : vector A n) : matrix A n 1 := λ i o, v i -definition to_rvec [reducible] [coercion] {A : Type} {n : nat} (v : vector A n) +attribute [reducible] [coercion] +definition to_rvec {A : Type} {n : nat} (v : vector A n) : matrix A 1 n := λ o i, v i variables (A : Type) (n : nat) diff --git a/tests/lean_before_refactoring/run/blast_cc8.lean b/tests/lean_before_refactoring/run/blast_cc8.lean index ee05abde1c..4693b70313 100644 --- a/tests/lean_before_refactoring/run/blast_cc8.lean +++ b/tests/lean_before_refactoring/run/blast_cc8.lean @@ -5,7 +5,8 @@ set_option blast.strategy "cc" structure finite_set [class] {T : Type} (xs : set T) := (to_finset : finset T) (is_equiv : to_set to_finset = xs) -definition finset_set.is_subsingleton [instance] (T : Type) (xs : set T) : subsingleton (finite_set xs) := +attribute [instance] +definition finset_set.is_subsingleton (T : Type) (xs : set T) : subsingleton (finite_set xs) := begin constructor, intro a b, induction a with f₁ h₁, @@ -17,13 +18,20 @@ end /- Add some instances for finite_sets -/ variable {A : Type} -definition finite_set_empty [instance] : finite_set (∅:set A) := sorry -definition finite_set_finset [instance] (fxs : finset A) : finite_set (to_set fxs) := sorry -definition finite_set_insert [instance] (xs : set A) [finite_set xs] (x : A) : finite_set (insert x xs) := sorry -definition finite_set_union [instance] (xs : set A) [finite_set xs] (ys : set A) [finite_set ys] : finite_set (xs ∪ ys) := sorry -definition finite_set_inter1 [instance] (xs : set A) [finite_set xs] (ys : set A) [decidable_pred ys] : finite_set (xs ∩ ys) := sorry -definition finite_set_inter2 [instance] (xs : set A) [finite_set xs] (ys : set A) [decidable_pred ys] : finite_set (ys ∩ xs) := sorry -definition finite_set_set_of [instance] (xs : set A) [finite_set xs] : finite_set (set.set_of xs) := sorry +attribute [instance] +definition finite_set_empty : finite_set (∅:set A) := sorry +attribute [instance] +definition finite_set_finset (fxs : finset A) : finite_set (to_set fxs) := sorry +attribute [instance] +definition finite_set_insert (xs : set A) [finite_set xs] (x : A) : finite_set (insert x xs) := sorry +attribute [instance] +definition finite_set_union (xs : set A) [finite_set xs] (ys : set A) [finite_set ys] : finite_set (xs ∪ ys) := sorry +attribute [instance] +definition finite_set_inter1 (xs : set A) [finite_set xs] (ys : set A) [decidable_pred ys] : finite_set (xs ∩ ys) := sorry +attribute [instance] +definition finite_set_inter2 (xs : set A) [finite_set xs] (ys : set A) [decidable_pred ys] : finite_set (ys ∩ xs) := sorry +attribute [instance] +definition finite_set_set_of (xs : set A) [finite_set xs] : finite_set (set.set_of xs) := sorry /- Defined cardinality using finite_set type class -/ noncomputable definition mycard {T : Type} (xs : set T) [finite_set xs] := diff --git a/tests/lean_before_refactoring/run/blast_safe_log_issue.lean b/tests/lean_before_refactoring/run/blast_safe_log_issue.lean index f0df3dcd4f..9a588e7abc 100644 --- a/tests/lean_before_refactoring/run/blast_safe_log_issue.lean +++ b/tests/lean_before_refactoring/run/blast_safe_log_issue.lean @@ -10,7 +10,8 @@ constants (safe_log : Π (x : ℝ), pos x → ℝ) lemma pos_add {x y : ℝ} : pos x → pos y → pos (x + y) := sorry lemma pos_mul {x y : ℝ} : pos x → pos y → pos (x * y) := sorry -lemma log_mul [simp] : ∀ (x y : ℝ) (x_pos : pos x) (y_pos : pos y), safe_log (x * y) (pos_mul x_pos y_pos) = safe_log x x_pos + safe_log y y_pos := sorry +attribute [simp] +lemma log_mul : ∀ (x y : ℝ) (x_pos : pos x) (y_pos : pos y), safe_log (x * y) (pos_mul x_pos y_pos) = safe_log x x_pos + safe_log y y_pos := sorry example (x y z w : ℝ) (x_pos : pos x) (y_pos : pos y) (z_pos : pos z) (w_pos : pos w) : diff --git a/tests/lean_before_refactoring/run/blast_safe_log_issue2.lean b/tests/lean_before_refactoring/run/blast_safe_log_issue2.lean index 9469d4c8bf..04dccd101a 100644 --- a/tests/lean_before_refactoring/run/blast_safe_log_issue2.lean +++ b/tests/lean_before_refactoring/run/blast_safe_log_issue2.lean @@ -18,27 +18,47 @@ definition sq (x : ℝ) := x * x notation a `²` := sq a -lemma nzero_of_pos [intro!] {x : ℝ} : pos x → nzero x := sorry +attribute [intro!] +lemma nzero_of_pos {x : ℝ} : pos x → nzero x := sorry -lemma pos_bit1 [intro!] {x : ℝ} : pos x → pos (: bit1 x :) := sorry -lemma pos_bit0 [intro!] {x : ℝ} : pos x → pos (: bit0 x :) := sorry -lemma pos_inv [forward] {x : ℝ} : pos x → (: pos (inv x) :) := sorry -lemma pos_1 [intro!] : pos (1:ℝ) := sorry -lemma pos_add [intro!] [forward] {x y : ℝ} : pos x → pos y → pos (: x + y :) := sorry -lemma pos_mul [intro!] [forward] {x y : ℝ} : pos x → pos y → pos (: x * y :) := sorry -lemma pos_sq [intro!] {x : ℝ} : pos x → pos (: sq x :) := sorry -lemma inv_pos [intro!] {x : ℝ} : pos x → pos (: x⁻¹ :) := sorry -lemma exp_pos [intro!] (x : ℝ) : pos (: exp x :) := sorry -lemma log_mul [forward] : ∀ (x y : ℝ), pos x → pos y → (: log (x * y) :) = (: log x + log y :) := sorry -lemma log_sq [forward] : ∀ (x : ℝ), pos x → (: log (sq x) :) = (: 2 * log x :) := sorry -lemma log_inv [forward] : ∀ (x : ℝ), pos x → (: log (x⁻¹) :) = (: - log x :) := sorry -lemma inv_mul [forward] : ∀ (x y : ℝ), pos x → pos y → (: (x * y)⁻¹ :) = (: x⁻¹ * y⁻¹ :) := sorry -lemma exp_add [forward] : ∀ (x y : ℝ), (: exp (x + y) :) = (: exp x * exp y :) := sorry -lemma pair_prod [forward] : ∀ (x y : ℝ), (: sq x + 2 * x * y + sq y :) = sq (x + y) := sorry -lemma mul_two_sum [forward] : ∀ (x : ℝ), (: 2 * x :) = (: x + x :) := sorry -lemma sub_def [forward] : ∀ (x y : ℝ), (x - y) = x + -y := sorry -lemma mul_div_cancel [forward] : ∀ (x y : ℝ), (y * x) / y = x := sorry -lemma div_neg [forward] : ∀ (x y : ℝ), x / -y = - (x / y) := sorry +attribute [intro!] +lemma pos_bit1 {x : ℝ} : pos x → pos (: bit1 x :) := sorry +attribute [intro!] +lemma pos_bit0 {x : ℝ} : pos x → pos (: bit0 x :) := sorry +attribute [forward] +lemma pos_inv {x : ℝ} : pos x → (: pos (inv x) :) := sorry +attribute [intro!] +lemma pos_1 : pos (1:ℝ) := sorry +attribute [intro!] [forward] +lemma pos_add {x y : ℝ} : pos x → pos y → pos (: x + y :) := sorry +attribute [intro!] [forward] +lemma pos_mul {x y : ℝ} : pos x → pos y → pos (: x * y :) := sorry +attribute [intro!] +lemma pos_sq {x : ℝ} : pos x → pos (: sq x :) := sorry +attribute [intro!] +lemma inv_pos {x : ℝ} : pos x → pos (: x⁻¹ :) := sorry +attribute [intro!] +lemma exp_pos (x : ℝ) : pos (: exp x :) := sorry +attribute [forward] +lemma log_mul : ∀ (x y : ℝ), pos x → pos y → (: log (x * y) :) = (: log x + log y :) := sorry +attribute [forward] +lemma log_sq : ∀ (x : ℝ), pos x → (: log (sq x) :) = (: 2 * log x :) := sorry +attribute [forward] +lemma log_inv : ∀ (x : ℝ), pos x → (: log (x⁻¹) :) = (: - log x :) := sorry +attribute [forward] +lemma inv_mul : ∀ (x y : ℝ), pos x → pos y → (: (x * y)⁻¹ :) = (: x⁻¹ * y⁻¹ :) := sorry +attribute [forward] +lemma exp_add : ∀ (x y : ℝ), (: exp (x + y) :) = (: exp x * exp y :) := sorry +attribute [forward] +lemma pair_prod : ∀ (x y : ℝ), (: sq x + 2 * x * y + sq y :) = sq (x + y) := sorry +attribute [forward] +lemma mul_two_sum : ∀ (x : ℝ), (: 2 * x :) = (: x + x :) := sorry +attribute [forward] +lemma sub_def : ∀ (x y : ℝ), (x - y) = x + -y := sorry +attribute [forward] +lemma mul_div_cancel : ∀ (x y : ℝ), (y * x) / y = x := sorry +attribute [forward] +lemma div_neg : ∀ (x y : ℝ), x / -y = - (x / y) := sorry attribute right_distrib [forward] diff --git a/tests/lean_before_refactoring/run/coe11.lean b/tests/lean_before_refactoring/run/coe11.lean index 734f7c3c7d..b20d863d2a 100644 --- a/tests/lean_before_refactoring/run/coe11.lean +++ b/tests/lean_before_refactoring/run/coe11.lean @@ -7,10 +7,12 @@ mk : Π (obF : obC → obD) (homF : Π{A B : obC}, hom A B → hom (obF A) (obF (Π {A B C : obC} {f : hom A B} {g : hom B C}, homF (g ∘ f) = homF g ∘ homF f) → my_functor C D -definition my_object [coercion] {obC obD : Type} {C : category obC} {D : category obD} (F : my_functor C D) : obC → obD := +attribute [coercion] +definition my_object {obC obD : Type} {C : category obC} {D : category obD} (F : my_functor C D) : obC → obD := my_functor.rec (λ obF homF Hid Hcomp, obF) F -definition my_homphism [coercion] {obC obD : Type} {C : category obC} {D : category obD} (F : my_functor C D) : +attribute [coercion] +definition my_homphism {obC obD : Type} {C : category obC} {D : category obD} (F : my_functor C D) : Π{A B : obC}, hom A B → hom (my_object F A) (my_object F B) := my_functor.rec (λ obF homF Hid Hcomp, homF) F diff --git a/tests/lean_before_refactoring/run/congr_tac2.lean b/tests/lean_before_refactoring/run/congr_tac2.lean index b0108cdaa3..39babca03b 100644 --- a/tests/lean_before_refactoring/run/congr_tac2.lean +++ b/tests/lean_before_refactoring/run/congr_tac2.lean @@ -11,7 +11,8 @@ end structure finite_set [class] {T : Type} (xs : set T) := (to_finset : finset T) (is_equiv : to_set to_finset = xs) -definition finset_set.is_subsingleton [instance] (T : Type) (xs : set T) : subsingleton (finite_set xs) := +attribute [instance] +definition finset_set.is_subsingleton (T : Type) (xs : set T) : subsingleton (finite_set xs) := begin constructor, intro a b, induction a with f₁ h₁, diff --git a/tests/lean_before_refactoring/run/finset_coe.lean b/tests/lean_before_refactoring/run/finset_coe.lean index 7798bad384..82935b92ff 100644 --- a/tests/lean_before_refactoring/run/finset_coe.lean +++ b/tests/lean_before_refactoring/run/finset_coe.lean @@ -1,7 +1,8 @@ import data.finset data.set open finset set -definition to_set [coercion] {A : Type} (s : finset A) : set A := λ a, a ∈ s +attribute [coercion] +definition to_set {A : Type} (s : finset A) : set A := λ a, a ∈ s constant P {A : Type} (s : set A) : Prop diff --git a/tests/lean_before_refactoring/run/prio_overloading.lean b/tests/lean_before_refactoring/run/prio_overloading.lean index cf27888dcd..514542cab3 100644 --- a/tests/lean_before_refactoring/run/prio_overloading.lean +++ b/tests/lean_before_refactoring/run/prio_overloading.lean @@ -1,15 +1,20 @@ import algebra.group data.real open nat -definition foo1 [instance] [priority 2] : inhabited nat := inhabited.mk 10 +attribute [instance] [priority 2] +definition foo1 : inhabited nat := inhabited.mk 10 -definition foo2 [instance] [priority 1] : inhabited nat := inhabited.mk 10 +attribute [instance] [priority 1] +definition foo2 : inhabited nat := inhabited.mk 10 open algebra -definition foo3 [instance] [priority 1] : inhabited nat := inhabited.mk 10 +attribute [instance] [priority 1] +definition foo3 : inhabited nat := inhabited.mk 10 -definition foo4 [unfold 2 3] (a b c : nat) := a + b + c +attribute [unfold 2 3] +definition foo4 (a b c : nat) := a + b + c -definition natrec [recursor 4] {C : nat → Type} (H₁ : C 0) (H₂ : Π (n : nat), C n → C (succ n)) (n : nat) : C n := +attribute [recursor 4] +definition natrec {C : nat → Type} (H₁ : C 0) (H₂ : Π (n : nat), C n → C (succ n)) (n : nat) : C n := nat.rec_on n H₁ H₂ diff --git a/tests/lean_before_refactoring/run/user_recursor.lean b/tests/lean_before_refactoring/run/user_recursor.lean index ef6dab08f5..7b44e659f7 100644 --- a/tests/lean_before_refactoring/run/user_recursor.lean +++ b/tests/lean_before_refactoring/run/user_recursor.lean @@ -1,7 +1,8 @@ import data.finset check @and.rec -definition and.rec2 [recursor 4] {p r : Prop} (H₁ : p → r) (H₂ : p ∧ p) : r := +attribute [recursor 4] +definition and.rec2 {p r : Prop} (H₁ : p → r) (H₂ : p ∧ p) : r := and.rec_on H₂ (λ h₁ h₁, H₁ h₁) set_option pp.all true diff --git a/tests/lean_before_refactoring/simplifier_light.lean b/tests/lean_before_refactoring/simplifier_light.lean index c27c587346..23752db705 100644 --- a/tests/lean_before_refactoring/simplifier_light.lean +++ b/tests/lean_before_refactoring/simplifier_light.lean @@ -44,7 +44,8 @@ attribute compl [light 2] -- TODO(dhs, leo): Where do we put this group of simp rules? attribute union_compl_self [simp] -lemma union_comp_self_left [simp] {X : Type} (s t : set X) : s ∪ (-s ∪ t)= univ := sorry +attribute [simp] +lemma union_comp_self_left {X : Type} (s t : set X) : s ∪ (-s ∪ t)= univ := sorry attribute union_comm [simp] attribute union_assoc [simp] @@ -53,7 +54,8 @@ attribute union_left_comm [simp] #simplify eq env 0 x ∪ y ∪ z ∪ -x attribute inter_compl_self [simp] -lemma inter_compl_self_left [simp] {X : Type} (s t : set X) : s ∩ (-s ∩ t)= empty := sorry +attribute [simp] +lemma inter_compl_self_left {X : Type} (s t : set X) : s ∩ (-s ∩ t)= empty := sorry attribute inter_comm [simp] attribute inter_assoc [simp]