Zulip Chat Archive

Stream: new members

Topic: Sorting divisors


Nathan (Sep 26 2025 at 04:43):

How can I formalize (in Lean) this statement from an IMO problem?

Let n2n\geq 2 be a positive integer, with divisors 1=d1<d2<<dk=n1=d_1<d_2<\ldots <d_k =n. Prove that d1d2+d2d3++dk1dkd_1 d_2+d_2 d_3 + \ldots + d_{k-1} d_k is always less than n2n^2, and determine when it is a divisor of n2n^2.

I initially tried using Finset.sort Nat.lt n.divisors but I get the error "failed to synthesize DecidableRel Nat.lt". I also considered defining did_i recursively, as the minimum of the set of divisors that are bigger than di1d_{i-1}.

Ruben Van de Velde (Sep 26 2025 at 06:01):

I don't think you should use Nat.lt directly. Does (. < .) work?

Nathan (Sep 26 2025 at 06:10):

Screenshot 2025-09-26 at 2.10.20 AM.png
no, it doesn't seem to

Nathan (Sep 26 2025 at 06:13):

oh wait

Nathan (Sep 26 2025 at 06:14):

(. ≤ .) seems to work

Nathan (Sep 26 2025 at 06:21):

thanks :pray:

Nathan (Sep 26 2025 at 06:27):

sort produces a List. I wonder, are lists the right approach here?

Nathan (Sep 26 2025 at 06:31):

my goal is to prove the solution to the problem

Ruben Van de Velde (Sep 26 2025 at 07:33):

Yes, I think you want a list, and then probably sum over Finset.range n? You'll want to start your indices from 0 as well

Nathan (Sep 26 2025 at 18:11):

Shouldn't I sum over something like Finset.range (n.divisors.card-1)?

Ruben Van de Velde (Sep 26 2025 at 18:15):

Uh, yes, confused my variables there

Nathan (Sep 26 2025 at 19:02):

Is this right? I'm not sure how to prove h1, h2

import MIL.Common

section p_1_12_13
  def divi (n i : ) (h : i < n.divisors.card) :=
    let d := n.divisors.sort (.  .)
    have h : d.length = n.divisors.card := Multiset.length_sort (.  .)
    d[i]

  def sumdiv (n : ) :=
     i : Finset.Icc 0 (n.divisors.card-2),
      have h₁ : i < n.divisors.card := sorry
      have h₂ : i+1 < n.divisors.card := sorry
      (divi n i h₁) * (divi n (i+1) h₂)

  example : sumdiv 4 = 10 := sorry

  theorem t1 (n : ) (h : n  2) : sumdiv n < n^2 := sorry
end p_1_12_13

Jireh Loreaux (Sep 26 2025 at 19:23):

import Mathlib

example (n : ) :
    letI sorted_divisors := n.divisors.sort (·  ·)
    (List.zipWith (· * ·) (0 :: sorted_divisors) sorted_divisors).sum < n ^ 2 := by
  sorry

Nathan (Sep 26 2025 at 20:01):

I see! thanks :pray: This avoids indices. I'll try to make some progress with the proof later.

Nathan (Sep 27 2025 at 16:39):

I think I still might need something like divi (which I defined above), because I want to use diid_i\geq i. The proof goes like this:

i=1k1didi+1=i=1k1dkidki+1=i=1k1ndi+1ndin2i=1k11i(i+1)\sum_{i=1}^{k-1}d_i d_{i+1}=\sum_{i=1}^{k-1}d_{k-i}d_{k-i+1}=\sum_{i=1}^{k-1}\frac{n}{d_{i+1}}\cdot\frac{n}{d_{i}}\leq n^2\sum_{i=1}^{k-1}\frac{1}{i(i+1)}

So won't I need something that maps idii \mapsto d_i?

Nathan (Sep 27 2025 at 16:55):

I found a lot of helpful things in Mathlib like List.sum_le_sum and Nat.image_div_divisors_eq_divisors but I wasn't able to put them together into anything coherent.


Last updated: Dec 20 2025 at 21:32 UTC