refactor(library/data/{nat,int,rat}/{basic.lean,order.lean}: make algebra instance declarations local

This commit is contained in:
Jeremy Avigad 2015-05-12 14:44:31 +10:00 committed by Leonardo de Moura
parent f25c301c98
commit 42616f766f
6 changed files with 33 additions and 20 deletions

View file

@ -1,8 +1,6 @@
/- /-
Copyright (c) 2014 Floris van Doorn. All rights reserved. Copyright (c) 2014 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE. Released under Apache 2.0 license as described in the file LICENSE.
Module: data.int.basic
Authors: Floris van Doorn, Jeremy Avigad Authors: Floris van Doorn, Jeremy Avigad
The integers, with addition, multiplication, and subtraction. The representation of the integers is The integers, with addition, multiplication, and subtraction. The representation of the integers is
@ -609,10 +607,10 @@ or_of_or_of_imp_of_imp H3
(assume H : (nat_abs a) = nat.zero, nat_abs_eq_zero H) (assume H : (nat_abs a) = nat.zero, nat_abs_eq_zero H)
(assume H : (nat_abs b) = nat.zero, nat_abs_eq_zero H) (assume H : (nat_abs b) = nat.zero, nat_abs_eq_zero H)
section section migrate_algebra
open [classes] algebra open [classes] algebra
protected definition integral_domain [instance] [reducible] : algebra.integral_domain int := protected definition integral_domain [reducible] : algebra.integral_domain int :=
⦃algebra.integral_domain, ⦃algebra.integral_domain,
add := add, add := add,
add_assoc := add.assoc, add_assoc := add.assoc,
@ -632,6 +630,7 @@ section
mul_comm := mul.comm, mul_comm := mul.comm,
eq_zero_or_eq_zero_of_mul_eq_zero := @eq_zero_or_eq_zero_of_mul_eq_zero⦄ eq_zero_or_eq_zero_of_mul_eq_zero := @eq_zero_or_eq_zero_of_mul_eq_zero⦄
local attribute int.integral_domain [instance]
definition sub (a b : ) : := algebra.sub a b definition sub (a b : ) : := algebra.sub a b
infix - := int.sub infix - := int.sub
definition dvd (a b : ) : Prop := algebra.dvd a b definition dvd (a b : ) : Prop := algebra.dvd a b
@ -639,7 +638,7 @@ section
migrate from algebra with int migrate from algebra with int
replacing sub → sub, dvd → dvd replacing sub → sub, dvd → dvd
end end migrate_algebra
/- additional properties -/ /- additional properties -/

View file

@ -1,8 +1,6 @@
/- /-
Copyright (c) 2014 Floris van Doorn. All rights reserved. Copyright (c) 2014 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE. Released under Apache 2.0 license as described in the file LICENSE.
Module: data.int.order
Authors: Floris van Doorn, Jeremy Avigad Authors: Floris van Doorn, Jeremy Avigad
The order relation on the integers. We show that int is an instance of linear_comm_ordered_ring The order relation on the integers. We show that int is an instance of linear_comm_ordered_ring
@ -218,10 +216,10 @@ lt.intro
... = of_nat (succ (succ n * m + n)) : nat.add_succ ... = of_nat (succ (succ n * m + n)) : nat.add_succ
... = 0 + succ (succ n * m + n) : zero_add)) ... = 0 + succ (succ n * m + n) : zero_add))
section section migrate_algebra
open [classes] algebra open [classes] algebra
protected definition linear_ordered_comm_ring [instance] [reducible] : protected definition linear_ordered_comm_ring [reducible] :
algebra.linear_ordered_comm_ring int := algebra.linear_ordered_comm_ring int :=
⦃algebra.linear_ordered_comm_ring, int.integral_domain, ⦃algebra.linear_ordered_comm_ring, int.integral_domain,
le := le, le := le,
@ -237,12 +235,16 @@ section
le_total := le.total, le_total := le.total,
zero_ne_one := zero_ne_one⦄ zero_ne_one := zero_ne_one⦄
protected definition decidable_linear_ordered_comm_ring [instance] [reducible] : protected definition decidable_linear_ordered_comm_ring [reducible] :
algebra.decidable_linear_ordered_comm_ring int := algebra.decidable_linear_ordered_comm_ring int :=
⦃algebra.decidable_linear_ordered_comm_ring, ⦃algebra.decidable_linear_ordered_comm_ring,
int.linear_ordered_comm_ring, int.linear_ordered_comm_ring,
decidable_lt := decidable_lt⦄ decidable_lt := decidable_lt⦄
local attribute int.integral_domain [instance]
local attribute int.linear_ordered_comm_ring [instance]
local attribute int.decidable_linear_ordered_comm_ring [instance]
definition ge [reducible] (a b : ) := algebra.has_le.ge a b definition ge [reducible] (a b : ) := algebra.has_le.ge a b
definition gt [reducible] (a b : ) := algebra.has_lt.gt a b definition gt [reducible] (a b : ) := algebra.has_lt.gt a b
infix >= := int.ge infix >= := int.ge
@ -257,7 +259,7 @@ section
migrate from algebra with int migrate from algebra with int
replacing has_le.ge → ge, has_lt.gt → gt, sign → sign, abs → abs, dvd → dvd, sub → sub replacing has_le.ge → ge, has_lt.gt → gt, sign → sign, abs → abs, dvd → dvd, sub → sub
end end migrate_algebra
/- more facts specific to int -/ /- more facts specific to int -/

View file

@ -290,7 +290,7 @@ nat.cases_on n
section section
open [classes] algebra open [classes] algebra
protected definition comm_semiring [instance] [reducible] : algebra.comm_semiring nat := protected definition comm_semiring [reducible] : algebra.comm_semiring nat :=
⦃algebra.comm_semiring, ⦃algebra.comm_semiring,
add := add, add := add,
add_assoc := add.assoc, add_assoc := add.assoc,
@ -312,6 +312,7 @@ end
section port_algebra section port_algebra
open [classes] algebra open [classes] algebra
local attribute comm_semiring [instance]
theorem mul.left_comm : ∀a b c : , a * (b * c) = b * (a * c) := algebra.mul.left_comm theorem mul.left_comm : ∀a b c : , a * (b * c) = b * (a * c) := algebra.mul.left_comm
theorem mul.right_comm : ∀a b c : , (a * b) * c = (a * c) * b := algebra.mul.right_comm theorem mul.right_comm : ∀a b c : , (a * b) * c = (a * c) * b := algebra.mul.right_comm

View file

@ -143,8 +143,9 @@ le.intro !zero_add
section section
open [classes] algebra open [classes] algebra
local attribute nat.comm_semiring [instance]
protected definition linear_ordered_semiring [instance] [reducible] : protected definition linear_ordered_semiring [reducible] :
algebra.linear_ordered_semiring nat := algebra.linear_ordered_semiring nat :=
⦃ algebra.linear_ordered_semiring, nat.comm_semiring, ⦃ algebra.linear_ordered_semiring, nat.comm_semiring,
add_left_cancel := @add.cancel_left, add_left_cancel := @add.cancel_left,
@ -164,6 +165,11 @@ section
mul_le_mul_of_nonneg_right := (take a b c H1 H2, mul_le_mul_right H1 c), mul_le_mul_of_nonneg_right := (take a b c H1 H2, mul_le_mul_right H1 c),
mul_lt_mul_of_pos_left := @mul_lt_mul_of_pos_left, mul_lt_mul_of_pos_left := @mul_lt_mul_of_pos_left,
mul_lt_mul_of_pos_right := @mul_lt_mul_of_pos_right ⦄ mul_lt_mul_of_pos_right := @mul_lt_mul_of_pos_right ⦄
end
section
open [classes] algebra
local attribute nat.linear_ordered_semiring [instance]
migrate from algebra with nat migrate from algebra with nat
replacing has_le.ge → ge, has_lt.gt → gt replacing has_le.ge → ge, has_lt.gt → gt
@ -172,6 +178,7 @@ end
section port_algebra section port_algebra
open [classes] algebra open [classes] algebra
local attribute nat.linear_ordered_semiring [instance]
theorem add_pos_left : ∀{a : }, 0 < a → ∀b : , 0 < a + b := theorem add_pos_left : ∀{a : }, 0 < a → ∀b : , 0 < a + b :=
take a H b, @algebra.add_pos_of_pos_of_nonneg _ _ a b H !zero_le take a H b, @algebra.add_pos_of_pos_of_nonneg _ _ a b H !zero_le
theorem add_pos_right : ∀{a : }, 0 < a → ∀b : , 0 < b + a := theorem add_pos_right : ∀{a : }, 0 < a → ∀b : , 0 < b + a :=

View file

@ -365,10 +365,10 @@ take a b, quot.rec_on_subsingleton₂ a b
theorem inv_zero : inv 0 = 0 := theorem inv_zero : inv 0 = 0 :=
quot.sound (prerat.inv_zero' ▸ !prerat.equiv.refl) quot.sound (prerat.inv_zero' ▸ !prerat.equiv.refl)
section section migrate_algebra
open [classes] algebra open [classes] algebra
protected definition discrete_field [instance] [reducible] : algebra.discrete_field rat := protected definition discrete_field [reducible] : algebra.discrete_field rat :=
⦃algebra.discrete_field, ⦃algebra.discrete_field,
add := add, add := add,
add_assoc := add.assoc, add_assoc := add.assoc,
@ -392,10 +392,12 @@ section
inv_zero := inv_zero, inv_zero := inv_zero,
has_decidable_eq := has_decidable_eq⦄ has_decidable_eq := has_decidable_eq⦄
local attribute rat.discrete_field [instance]
definition divide (a b : rat) := algebra.divide a b definition divide (a b : rat) := algebra.divide a b
definition dvd (a b : rat) := algebra.dvd a b definition dvd (a b : rat) := algebra.dvd a b
migrate from algebra with rat migrate from algebra with rat
replacing sub → rat.sub, divide → divide, dvd → dvd replacing sub → rat.sub, divide → divide, dvd → dvd
end
end migrate_algebra
end rat end rat

View file

@ -202,10 +202,10 @@ have H : pos (a * b), from pos_mul (!sub_zero ▸ H1) (!sub_zero ▸ H2),
definition decidable_lt [instance] : decidable_rel rat.lt := definition decidable_lt [instance] : decidable_rel rat.lt :=
take a b, decidable_pos (b - a) take a b, decidable_pos (b - a)
section section migrate_algebra
open [classes] algebra open [classes] algebra
protected definition discrete_linear_ordered_field [instance] [reducible] : protected definition discrete_linear_ordered_field [reducible] :
algebra.discrete_linear_ordered_field rat := algebra.discrete_linear_ordered_field rat :=
⦃algebra.discrete_linear_ordered_field, ⦃algebra.discrete_linear_ordered_field,
rat.discrete_field, rat.discrete_field,
@ -220,10 +220,12 @@ section
mul_pos := @mul_pos, mul_pos := @mul_pos,
decidable_lt := @decidable_lt⦄ decidable_lt := @decidable_lt⦄
local attribute rat.discrete_field [instance]
local attribute rat.discrete_linear_ordered_field [instance]
definition abs (n : rat) : rat := algebra.abs n definition abs (n : rat) : rat := algebra.abs n
definition sign (n : rat) : rat := algebra.sign n definition sign (n : rat) : rat := algebra.sign n
migrate from algebra with rat migrate from algebra with rat
replacing has_le.ge → ge, has_lt.gt → gt, sub → sub, abs → abs, sign → sign, dvd → dvd, divide → divide replacing has_le.ge → ge, has_lt.gt → gt, sub → sub, abs → abs, sign → sign, dvd → dvd, divide → divide
end end migrate_algebra
end rat end rat