Zulip Chat Archive

Stream: new members

Topic: Floor division hell in asymptotics


Gareth Ma (Apr 23 2024 at 23:15):

(Not surprisingly) I am struggling to prove the following result:

example {b : } (hb : 2 <= b) :
     c > 0, |((b / 2 * (b / 2 - 1) / 2) : ) - (b : ) ^ 2 / 8|  c * |(b : )| / 2 := by
  sorry

Is there any general tips on how to tackle these? In particular, I just want to prove some messy division stuff is O(highest order term)O(\text{highest order term}), but it's all in floor division :(

Gareth Ma (Apr 23 2024 at 23:17):

(This basically comes from 0kbbk\sum_{0 \leq k \leq b} b - k or something, so some floor(s / divisions) are unavoidable?)

Richard Copley (Apr 23 2024 at 23:18):

All of those divisions are ℝ → ℝ → ℝ, fyi

Mario Carneiro (Apr 23 2024 at 23:19):

you can lower and upper bound floor division wrt regular division, and apply asymptotics on the result

Gareth Ma (Apr 23 2024 at 23:27):

That's the idea but implementing it still seems hard, can you provide some help? For example I guess a generous estimate would be to lower bound bkkbk\frac{b - k}{k} \leq \lfloor\frac{b}{k}\rfloor, so I want to prove

example {b : } (hb : 2  b) :
    ((b : ) - 2) * (b - 2) / 8 - (b - 2) / 4  ((b / 2) * (b / 2 - 1) / 2 : ) := by
  sorry

I think.

Mario Carneiro (Apr 23 2024 at 23:28):

does gcongr help?

Gareth Ma (Apr 23 2024 at 23:28):

Nope 0 progress

Mario Carneiro (Apr 23 2024 at 23:29):

looks like you did some simplifications on that expression too

Gareth Ma (Apr 23 2024 at 23:30):

example {b : } (hb : 2  b) :
    (((b - 2 : ) / 2) * ((b - 2 : ) / 2 - 1) - 2) / 2  ((b / 2) * (b / 2 - 1) / 2 : ) := by
  gcongr

I reverted the manual simplifiactions I did, but still 0 progress

Gareth Ma (Apr 23 2024 at 23:32):

It fails for this too:

example {a b : } (hb : a  b) :
    ((a : ) - 2) / 2  (b / 2 : ) := by
  gcongr

So I don't think it can help with floor divisions.

Mario Carneiro (Apr 23 2024 at 23:32):

it helps with all the stuff which isn't the floor divisions here

Mario Carneiro (Apr 23 2024 at 23:33):

for the floor division itself you need a lemma

Gareth Ma (Apr 23 2024 at 23:42):

I will start with

lemma aux_floor_div {a b k : } (hb : a  b) (hk : 0 < k) :
    ((a : ) - k + 1) / k  (b / k : ) := by
  rw [div_le_iff (by norm_cast),  add_sub_right_comm, sub_le_iff_le_add]
  norm_cast
  rw [add_one_le_iff]
  apply lt_of_le_of_lt hb
  rw [ add_one_mul,  Int.ediv_lt_iff_lt_mul hk]
  exact lt_succ _

lemma aux_floor_div' {a b k : } (hb : a  b) (hk : 0 < k) :
    ((a : ) - k) / k  (b / k : ) := by
  apply le_trans ?_ (aux_floor_div hb hk)
  gcongr
  exact le_add_of_nonneg_right zero_le_one

and "build" the blocks one by one I guess. Thanks!

Mario Carneiro (Apr 23 2024 at 23:42):

I think your original expression is off, it seems to work except for that

Gareth Ma (Apr 23 2024 at 23:43):

The very first message? Yes I put the type casting wrong, let me fix it

Mario Carneiro (Apr 23 2024 at 23:43):

no, the numbers are wrong

Gareth Ma (Apr 23 2024 at 23:43):

which one?

Mario Carneiro (Apr 23 2024 at 23:44):

import Mathlib.Tactic.Linarith
import Mathlib.Data.Real.Basic

theorem todo (a b : ) : (a / b - 1 : )  (a / b : ) := sorry

example {b : } (hb : 4  b) :
    ((b : ) - 2) * (b - 4) / 8 - 1  ((b / 2) * (b / 2 - 1) / 2 : ) := by
  calc  ((b : ) - 2) * (b - 4) / 8 - 1
    _ = ((b / 2 - 1) * ((b / 2 - 1) - 1)) / 2 - 1 := by ring
    _  ((b / 2 : ) * ((b / 2 : ) - 1)) / 2 - 1 := by
      gcongr
      · linarith [show 4  (b:) by exact_mod_cast hb]
      · apply todo
      · apply todo
    _  ((b / 2) * (b / 2 - 1) : ) / 2 - 1 := by simp
    _  ((b / 2) * (b / 2 - 1) / 2 : ) := todo ..

Gareth Ma (Apr 23 2024 at 23:44):

Oh my god lol thanks so much...

Gareth Ma (Apr 25 2024 at 10:21):

Ohhhhhh wait I had a realisation. I shouldn't be bounding the final term (b/2)*(b/2-1)/2 directly (every / is floor division here)

Gareth Ma (Apr 25 2024 at 10:24):

The term is obtained from a sum Sb/21=1++(b/21)S_{\lfloor b / 2 \rfloor - 1} = 1 + \cdots + (\lfloor b / 2 \rfloor - 1), so I should bound Sb/21Sb/21=Sb/21Sb/21|S_{\lfloor b / 2 \rfloor - 1} - S_{b / 2 - 1}| = |S_{\lfloor b / 2 \rfloor - 1} - S_{\lfloor b / 2 - 1 \rfloor}|, which is easier because SySxy(yx)S_y - S_x \leq y(y - x) for integers yxy \geq x.

Gareth Ma (Apr 25 2024 at 10:24):

Where Sa=k=1akS_a = \sum_{k = 1}^{\lfloor a \rfloor} k


Last updated: May 02 2025 at 03:31 UTC