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
This commit is contained in:
Sebastian Ullrich 2016-08-12 16:51:53 -04:00 committed by Leonardo de Moura
parent 47e104311c
commit fd2c42a8bf
203 changed files with 2221 additions and 1116 deletions

View file

@ -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

View file

@ -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 \-> (→))

View file

@ -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}

View file

@ -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

View file

@ -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,

View file

@ -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) _,

View file

@ -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⦄

View file

@ -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) :=

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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),

View file

@ -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),

View file

@ -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 :=

View file

@ -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 _,

View file

@ -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 :=

View file

@ -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)

View file

@ -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 ⦄

View file

@ -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 :=

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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,

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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))

View file

@ -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 :=

View file

@ -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

View file

@ -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) :=

View file

@ -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,

View file

@ -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]

View file

@ -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

View file

@ -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 :=

View file

@ -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

View file

@ -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 :=

View file

@ -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 :=

View file

@ -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,

View file

@ -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
/-

View file

@ -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

View file

@ -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

View file

@ -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
/-

View file

@ -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

View file

@ -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

View file

@ -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,

View file

@ -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)

View file

@ -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 :=

View file

@ -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

View file

@ -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

View file

@ -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 :=

View file

@ -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 :=

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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~ :=

View file

@ -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 :=

View file

@ -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 :=

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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 :=

View file

@ -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

View file

@ -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 :=

View file

@ -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 :=

View file

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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)

View file

@ -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 :=

View file

@ -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

View file

@ -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) :=

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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 -/

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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 -/

Some files were not shown because too many files have changed in this diff Show more