Skip to content

Commit

Permalink
feat(algebra/order/floor): floor/ceil are preserved under order r…
Browse files Browse the repository at this point in the history
…ing homs (#16025)

`⌊f a⌋ = ⌊a⌋`, `⌈f a⌉ = ⌈a⌉` and similar for `f` a strictly monotone ring homomorphism.
  • Loading branch information
YaelDillies committed Aug 24, 2022
1 parent a9402e0 commit fa0bbc7
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 3 deletions.
60 changes: 57 additions & 3 deletions src/algebra/order/floor.lean
Expand Up @@ -37,8 +37,6 @@ for `nnnorm`.
## TODO
Some `nat.floor` and `nat.ceil` lemmas require `linear_ordered_ring α`. Is `has_ordered_sub` enough?
`linear_ordered_ring`/`linear_ordered_semiring` can be relaxed to `order_ring`/`order_semiring` in
many lemmas.
Expand All @@ -48,7 +46,7 @@ rounding, floor, ceil
-/

open set
variables {α : Type*}
variables {F α β : Type*}

/-! ### Floor semiring -/

Expand Down Expand Up @@ -737,6 +735,62 @@ end

end round

namespace nat
variables [linear_ordered_semiring α] [linear_ordered_semiring β] [floor_semiring α]
[floor_semiring β] [ring_hom_class F α β] {a : α} {b : β}
include β

lemma floor_congr (h : ∀ n : ℕ, (n : α) ≤ a ↔ (n : β) ≤ b) : ⌊a⌋₊ = ⌊b⌋₊ :=
begin
have h₀ : 0 ≤ a ↔ 0 ≤ b := by simpa only [cast_zero] using h 0,
obtain ha | ha := lt_or_le a 0,
{ rw [floor_of_nonpos ha.le, floor_of_nonpos (le_of_not_le $ h₀.not.mp ha.not_le)] },
exact (le_floor $ (h _).1 $ floor_le ha).antisymm (le_floor $ (h _).2 $ floor_le $ h₀.1 ha),
end

lemma ceil_congr (h : ∀ n : ℕ, a ≤ n ↔ b ≤ n) : ⌈a⌉₊ = ⌈b⌉₊ :=
(ceil_le.2 $ (h _).2 $ le_ceil _).antisymm $ ceil_le.2 $ (h _).1 $ le_ceil _

lemma map_floor (f : F) (hf : strict_mono f) (a : α) : ⌊f a⌋₊ = ⌊a⌋₊ :=
floor_congr $ λ n, by rw [←map_nat_cast f, hf.le_iff_le]

lemma map_ceil (f : F) (hf : strict_mono f) (a : α) : ⌈f a⌉₊ = ⌈a⌉₊ :=
ceil_congr $ λ n, by rw [←map_nat_cast f, hf.le_iff_le]

end nat

namespace int
variables [linear_ordered_ring α] [linear_ordered_ring β] [floor_ring α] [floor_ring β]
[ring_hom_class F α β] {a : α} {b : β}
include β

lemma floor_congr (h : ∀ n : ℤ, (n : α) ≤ a ↔ (n : β) ≤ b) : ⌊a⌋ = ⌊b⌋ :=
(le_floor.2 $ (h _).1 $ floor_le _).antisymm $ le_floor.2 $ (h _).2 $ floor_le _

lemma ceil_congr (h : ∀ n : ℤ, a ≤ n ↔ b ≤ n) : ⌈a⌉ = ⌈b⌉ :=
(ceil_le.2 $ (h _).2 $ le_ceil _).antisymm $ ceil_le.2 $ (h _).1 $ le_ceil _

lemma map_floor (f : F) (hf : strict_mono f) (a : α) : ⌊f a⌋ = ⌊a⌋ :=
floor_congr $ λ n, by rw [←map_int_cast f, hf.le_iff_le]

lemma map_ceil (f : F) (hf : strict_mono f) (a : α) : ⌈f a⌉ = ⌈a⌉ :=
ceil_congr $ λ n, by rw [←map_int_cast f, hf.le_iff_le]

lemma map_fract (f : F) (hf : strict_mono f) (a : α) : fract (f a) = f (fract a) :=
by simp_rw [fract, map_sub, map_int_cast, map_floor _ hf]

end int

namespace int
variables [linear_ordered_field α] [linear_ordered_field β] [floor_ring α] [floor_ring β]
[ring_hom_class F α β] {a : α} {b : β}
include β

lemma map_round (f : F) (hf : strict_mono f) (a : α) : round (f a) = round a :=
by simp_rw [round, ←map_floor _ hf, map_add, one_div, map_inv₀, map_bit0, map_one]

end int

variables {α} [linear_ordered_ring α] [floor_ring α]

/-! #### A floor ring as a floor semiring -/
Expand Down
10 changes: 10 additions & 0 deletions src/algebra/order/hom/monoid.lean
Expand Up @@ -161,6 +161,16 @@ instance [order_monoid_with_zero_hom_class F α β] : has_coe_t F (α →*₀o

end monoid_with_zero

section ordered_add_comm_monoid
variables [ordered_add_comm_monoid α] [ordered_add_comm_monoid β] [order_add_monoid_hom_class F α β]
(f : F) {a : α}
include β

lemma map_nonneg (ha : 0 ≤ a) : 0 ≤ f a := by { rw ←map_zero f, exact order_hom_class.mono _ ha }
lemma map_nonpos (ha : a ≤ 0) : f a ≤ 0 := by { rw ←map_zero f, exact order_hom_class.mono _ ha }

end ordered_add_comm_monoid

namespace order_monoid_hom
section preorder
variables [preorder α] [preorder β] [preorder γ] [preorder δ] [mul_one_class α]
Expand Down

0 comments on commit fa0bbc7

Please sign in to comment.