Skip to content

feat : add complete formal solution for IMO 2025 P6#166

Open
lean-tom wants to merge 7 commits intodwrensha:mainfrom
lean-tom:imo2025_p6
Open

feat : add complete formal solution for IMO 2025 P6#166
lean-tom wants to merge 7 commits intodwrensha:mainfrom
lean-tom:imo2025_p6

Conversation

@lean-tom
Copy link
Contributor

@lean-tom lean-tom commented Feb 12, 2026

Summary

I have successfully formalized the complete solution for IMO 2025 Problem 6 . To my knowledge, this is the first complete formalization of this problem in Lean 4 without any sorry.

The proof consists of approximately 4,700 lines and is fully compatible with Lean v4.28.0-rc1 and the latest Mathlib.

Methodology

The solution utilizes a multi-disciplinary approach to handle the complexity of the grid configuration:

1. Lower Bound (Necessity - Topological Combinatorics)

We establish the lower bound $n + 2\sqrt{n} - 3$ by applying the Erdős–Szekeres Theorem to the coordinates of the uncovered (black) squares.

  • Set-Theoretic Topological Partitioning: Instead of using step functions or explicit analytic boundary lines, the regions are defined through unions and intersections of discrete set intervals. This avoids the complexity of manual max/min casework at the boundaries where LIS and LDS relations shift.
  • Topological Pivot in the Disjoint Case: In cases where the LIS and LDS do not intersect, a "topological pivot" is defined as a specific region of white squares. This allows us to identify the pivot's properties without needing to compute an explicit analytic intersection point.
  • Precise Counting Strategy: To achieve the exact count of $k^2+2k−3$ tiles, we developed a counting method based on the base black squares rather than the white squares themselves.
    Boundary Filtering: We handled the grid boundary conditions by filtering the set of black squares (using $0<x<k^2−1$, $0<y<k^2−1$). This allowed us to systematically remove the 4 "out-of-bounds" labels that would otherwise extend beyond the grid, ensuring the formal count matches the required upper bound without grueling manual casework on the edges.
  • Erdős–Szekeres Theorem: Applied to the coordinates to extract the Longest Increasing Subsequence (LIS) and Longest Decreasing Subsequence (LDS). The theorem guarantees that the product of their lengths is at least $n$, establishing the fundamental bound.-

2. Upper Bound (Sufficiency - Elementary Number Theory)

For $n=k^2$ (specifically $n=2025$), we provide an explicit construction:

  • Index-Based Fiber Construction: To ensure disjointness, we define two integer forms for each point $p = (x, y)$:

    • $val_s(p) = x + ky + k + 1$
    • $val_t(p) = kx - y + k^2 + k$
  • Fiber Mapping: We consider the fibers of the mapping $p \mapsto (s, t)$, where:

    • $s = \lfloor val_s(p) / (k^2 + 1) \rfloor$
    • $t = \lfloor val_t(p) / (k^2 + 1) \rfloor$
      This integer division (Gaussian bracket) naturally partitions the grid into disjoint regions.
  • Lattice-Point Black Squares: The uncovered (black) squares are precisely the "lattice points" where both forms are divisible by $k^2 + 1$:

    all_black = { $p$ | $val_s(p) \equiv 0 \pmod {k^2 + 1}$ and $val_t(p) \equiv 0 \pmod {k^2 + 1}$ }

    The Matilda tiles are then defined by removing the black squares from these fibers:
    M_(s, t) = { $p$ | $s = \lfloor val_s(p) / (k^2 + 1) \rfloor$ and $t = \lfloor val_t(p) / (k^2 + 1) \rfloor$ } \ all_black }

  • Disjointness and Geometry:

    • By Construction: Since the fibers partition the grid, the tiles are guaranteed to be disjoint.
    • Geometric Proof: Using elementary number theory, we formally prove that each such tile corresponds to a $k \times k$ square (clipped at the grid boundaries) that sits to the immediate right of a black square.
    • Verification: We formally verify that this results in exactly $k^2 + 2k - 3$ tiles, covering all white squares.

Status: Verified

  • Local Build: lake build completed successfully (1994 jobs) with no errors.
  • Goals Accomplished: The final theorem is fully proven with no remaining goals.
  • Environment: Updated all deprecated terms (e.g., List.SortedList.Pairwise, IsReflStd.Refl) to match the latest Mathlib standards.

Future Work

  • Refactoring: I plan to "golf" the code myself to improve readability and reduce the line count.
  • Lean Blueprint: I intend to create a Lean Blueprint in the near future to visualize the topological dependency graph of the proof.

I have cleaned up all draft files and organized the final code in Compfiles/Imo2025P6.lean. I believe this is ready to be merged.

Acknowledgments & Attribution

  • Division of Labor:

  • Human (lean-tom): Acted as the architectural lead. Conceived the core mathematical strategies and rigorously decomposed the entire proof into a granular series of lemmas to ensure a verifiable path toward the final theorem. This includes:

    • The set-theoretic topological approach to region partitioning.
    • The fiber-based construction and the linear congruence system.
    • The boundary-filtering logic for precise counting.
  • AI Assistant (Gemini 3 Pro): Provided extensive support for implementing the human-designed lemmas in Lean 4, handling syntax verification and the iterative refinement of internal proof steps within each lemma.

  • Nature of Collaboration:
    The final 4,700-line proof emerged from a symbiotic human-AI dialogue. The global architecture and rigorous decomposition of lemmas were human-led and cross-checked by Gemini 3 Pro for structural consistency. The AI was instrumental in validating the overall configuration, refining local logic, and proposing tactical bridges, ensuring the integrity and coherence of this large-scale formalization.

  • Verification Note:
    This work was completed through a high-intensity, iterative conversational process. It is a product of human-directed formalization and pre-dates or was developed independently of the fully autonomous "Deep Think" reasoning models announced on Feb 13, 2026. Every strategic leap, from the topological pivoting to the boundary filtering, was a human-led decision, ensuring that the resulting proof is a result of genuine mathematical understanding rather than a black-box generation.

@dwrensha
Copy link
Owner

Please move the new file into the directory Compfiles/, where the rest of the problem files live.

@dwrensha
Copy link
Owner

When I open this file in my code editor I see many errors.

@lean-tom lean-tom changed the title Add IMO 2025 P6 [WIP] IMO 2025 P6 Feb 12, 2026
@lean-tom lean-tom changed the title [WIP] IMO 2025 P6 [WIP] IMO 2025 P6 (Logic complete, fixing version mismatch) Feb 12, 2026
@lean-tom lean-tom changed the title [WIP] IMO 2025 P6 (Logic complete, fixing version mismatch) feat : add complete formal solution for IMO 2025 P6 Feb 13, 2026
@dwrensha
Copy link
Owner

Thank you for fixing the errors. There are still many warnings like

Messages below:                                                                                                                                                                                           
81:0:                                                                                                                                                                                                     
automatically included section variable(s) unused in theorem `Imo2025P6.mem_rect`:                                                                                                                        
  [NeZero n]                                                                                                                                                                                              
consider restructuring your `variable` declarations so that the variables are not in scope or explicitly omit them:                                                                                       
  omit [NeZero n] in theorem ...                                                                                                                                                                          
                                                                                                                                                                                                          
Note: This linter can be disabled with `set_option linter.unusedSectionVars false`                                                                                                                        
102:0:                                                                                                                                                                                                    
automatically included section variable(s) unused in theorem `Imo2025P6.eq_of_px_eq`:                                                                                                                     
  [NeZero n]                                                                                                                                                                                              
consider restructuring your `variable` declarations so that the variables are not in scope or explicitly omit them:                                                                                       
  omit [NeZero n] in theorem ...                                                                                                                                                                          
                                                                                                                                                                                                          
Note: This linter can be disabled with `set_option linter.unusedSectionVars false`                                                                                                                        
107:0:                                                                                                                                                                                                    
automatically included section variable(s) unused in theorem `Imo2025P6.eq_of_py_eq`:                                                                                                                     
  [NeZero n]                                                                                                                                                                                              
consider restructuring your `variable` declarations so that the variables are not in scope or explicitly omit them:                                                                                       
  omit [NeZero n] in theorem ...                                                                                                                                                                          
                                                                                                                                                                                                          
Note: This linter can be disabled with `set_option linter.unusedSectionVars false`                                                                                                                        
120:0:                                                                                                                                                                                                    
automatically included section variable(s) unused in theorem `Imo2025P6.chain_u_mono_le`:                                                                                                                 
  [NeZero n]                                                                                                                                                                                              
consider restructuring your `variable` declarations so that the variables are not in scope or explicitly omit them:                                                                                       
  omit [NeZero n] in theorem ...                              

Please fix them too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants