Zulip Chat Archive

Stream: new members

Topic: COMPREHENSIVE MWE: 5 Critical Issues in Lean 4 Mathematical


Harikrishnan R (Aug 07 2025 at 05:04):

================================================================
BUILD ENVIRONMENT & CONTEXT
================================================================

Lean Version: 4.20.0
Mathlib Version: Current (via lake)
Project Setup: Lake project with custom axiom system for mathematical research

MATHEMATICAL DOMAIN:
We're developing a formalization of idempotent tower constructions in abstract algebra, involving:

  • Bi-infinite towers of orthogonal idempotents (..., e₋₂, e₋₁, e₀, e₁, e₂, ...)
  • Weight filtrations (graded structures indexed by natural numbers)
  • Shape modalities (topological/geometric operations on algebraic structures)

PROBLEM:
After 5 debugging sessions, we've identified 5 distinct blocking issues. Some are Lean 4 API/tactic problems, others are mathematical proof strategy gaps.

================================================================
ISSUE #1: TACTIC REWRITE FAILURE - FUNCTION UNFOLD PROBLEM
================================================================

PROBLEM: rw tactic fails when trying to unfold custom function definitions
ERROR: "tactic 'rewrite' failed, equality or iff proof expected"

SELF-CONTAINED MINIMAL EXAMPLE:

-- Simplified version without custom imports
structure MySystem (α : Type*) where
  weight_func :   α  α
  shape_func : α  α
  zero_elem : α

variable {α : Type*} (S : MySystem α)

-- This pattern fails in our actual code
example (x : α) (i : ) :
  S.weight_func i (S.shape_func x) = S.zero_elem := by
  -- This fails: tactic 'rewrite' failed, equality or iff proof expected
  rw [S.weight_func]  -- ERROR: Cannot unfold function field
  sorry

FULL ERROR FROM OUR ACTUAL BUILD:

error: /home/hari/Documents/uya_lean/UYA_Lean_V2/UYA/Chapter1/Idempotents.lean:37:8:
tactic 'rewrite' failed, equality or iff proof expected
  𝒰
case pos
𝒰 : Type u_1
B : Bindhu.Final.BindhuAxiomSystem 𝒰
i j : 
x : 𝒰
h_neq : i  j
h : i.natAbs = j.natAbs
 Bindhu.Final.BindhuAxiomSystem.components.weight_filtration i.natAbs
      (Bindhu.Final.BindhuAxiomSystem.components.shape_modality x) =
    Bindhu.Final.UnifiedMathOps.zero

QUESTION:

  1. How should we unfold/rewrite custom function fields in structures?
  2. Is rw [S.function_field] the wrong approach?
  3. Should we use unfold, simp, or a different tactic?
  4. Does the structure field need to be marked with specific attributes (@[simp], @[reducible])?

Harikrishnan R (Aug 07 2025 at 05:04):

================================================================
ISSUE #2: LEAN 4 API ERROR - INT.NATCAST UNKNOWN CONSTANT
================================================================

PROBLEM: Int.natCast doesn't exist in current Lean 4/Mathlib
ERROR: "unknown constant 'Int.natCast'"

SELF-CONTAINED MINIMAL EXAMPLE:

-- This reproduces the exact error
example (i : Int) (h_negative : i < 0) : Int.natAbs i = Int.natCast (-i) := by
  -- ERROR: unknown constant 'Int.natCast'
  sorry

FULL ERROR FROM OUR ACTUAL BUILD:

error: /home/hari/Documents/uya_lean/UYA_Lean_V2/UYA/Chapter1/Idempotents.lean:181:46:
unknown constant 'Int.natCast'
error: /home/hari/Documents/uya_lean/UYA_Lean_V2/UYA/Chapter1/Idempotents.lean:182:14:
tactic 'rewrite' failed, did not find instance of the pattern in the target expression
  (-?a).natAbs

MATHEMATICAL CONTEXT:
We're trying to prove: "If i ∉ {-9, -8, ..., 8, 9}, then Int.natAbs i ≥ 10"
The proof strategy involves showing that for i < -9, we have Int.natAbs i = (-i) and (-i) > 9.

QUESTIONS:

  1. What is the correct Lean 4 replacement for Int.natCast?
  2. How do we properly convert between Int and Nat in current Mathlib?
  3. Is there a direct way to prove Int.natAbs i = (-i).natAbs for negative i?
  4. What's the idiomatic approach for integer absolute value bounds in Lean 4?

POSSIBLE ALTERNATIVES WE'VE CONSIDERED:

-- Option 1: Direct natAbs relationship
Int.natAbs i = Int.natAbs (-i)

-- Option 2: Using coercion
Int.natAbs i = ((-i : ) : )  -- But this might not type-check

-- Option 3: Using natCast replacement (what is it?)
Int.natAbs i = ???  -- Need the correct API

Harikrishnan R (Aug 07 2025 at 05:05):

================================================================
ISSUE #2: LEAN 4 API ERROR - INT.NATCAST UNKNOWN CONSTANT
================================================================

PROBLEM: Int.natCast doesn't exist in current Lean 4/Mathlib
ERROR: "unknown constant 'Int.natCast'"

SELF-CONTAINED MINIMAL EXAMPLE:

-- This reproduces the exact error
example (i : Int) (h_negative : i < 0) : Int.natAbs i = Int.natCast (-i) := by
  -- ERROR: unknown constant 'Int.natCast'
  sorry

FULL ERROR FROM OUR ACTUAL BUILD:

error: /home/hari/Documents/uya_lean/UYA_Lean_V2/UYA/Chapter1/Idempotents.lean:181:46:
unknown constant 'Int.natCast'
error: /home/hari/Documents/uya_lean/UYA_Lean_V2/UYA/Chapter1/Idempotents.lean:182:14:
tactic 'rewrite' failed, did not find instance of the pattern in the target expression
  (-?a).natAbs

MATHEMATICAL CONTEXT:
We're trying to prove: "If i ∉ {-9, -8, ..., 8, 9}, then Int.natAbs i ≥ 10"
The proof strategy involves showing that for i < -9, we have Int.natAbs i = (-i) and (-i) > 9.

QUESTIONS:

  1. What is the correct Lean 4 replacement for Int.natCast?
  2. How do we properly convert between Int and Nat in current Mathlib?
  3. Is there a direct way to prove Int.natAbs i = (-i).natAbs for negative i?
  4. What's the idiomatic approach for integer absolute value bounds in Lean 4?

POSSIBLE ALTERNATIVES WE'VE CONSIDERED:

-- Option 1: Direct natAbs relationship
Int.natAbs i = Int.natAbs (-i)

-- Option 2: Using coercion
Int.natAbs i = ((-i : ) : )  -- But this might not type-check

-- Option 3: Using natCast replacement (what is it?)
Int.natAbs i = ???  -- Need the correct API

Harikrishnan R (Aug 07 2025 at 05:06):

================================================================
ISSUE #3: MATHEMATICAL LOGIC FLAW - ABSOLUTE VALUE REASONING
================================================================

PROBLEM: Our proof assumes i ≠ j → Int.natAbs i ≠ Int.natAbs j, which is false
NATURE: Mathematical reasoning error, not a Lean issue

SELF-CONTAINED MINIMAL EXAMPLE:

-- This statement is mathematically false
example (i j : Int) (h : i  j) : Int.natAbs i  Int.natAbs j := by
  -- COUNTER-EXAMPLE: i = 2, j = -2
  -- We have i ≠ j but Int.natAbs i = Int.natAbs j = 2
  sorry

MATHEMATICAL CONTEXT:
In our orthogonality proof, we need to show that weight filtrations at different indices are orthogonal.
We assumed that integer indices i ≠ j would have different absolute values, but this fails for i = -j cases.

QUESTIONS:

  1. How should we handle the case where |i| = |j| but i ≠ j in orthogonality proofs?
  2. Should we split into cases: (a) |i| ≠ |j| and (b) |i| = |j| but i ≠ j?
  3. Is there a standard mathematical pattern for handling signed index orthogonality?
  4. What's the cleanest way to express "indices with same absolute value but different signs are still orthogonal"?
    ================================================================
    ISSUE #3: MATHEMATICAL GAP - WEIGHT ORTHOGONALITY PROOF
    ================================================================
    Line 103 in enhanced_e_orth theorem
    NATURE: Mathematical logic flaw - i ≠ j does not imply |i| ≠ |j|
example (i j : ) (h_neq : i  j) : Int.natAbs i  Int.natAbs j := by
  -- MATHEMATICAL GAP: Need to prove that if i ≠ j then |i| ≠ |j|
  -- This is not always true! Counter-example: i = 2, j = -2
  -- We have i ≠ j but Int.natAbs i = Int.natAbs j = 2
  sorry

QUESTION: Is this statement mathematically correct?
The proof assumes i ≠ j implies |i| ≠ |j|, but this fails for i = -j cases. Should the theorem handle the case where |i| = |j| but i ≠ j separately?

Harikrishnan R (Aug 07 2025 at 05:07):

================================================================
ISSUE #4: PROOF STRATEGY GAP - COMPOSED FILTRATION ORTHOGONALITY
================================================================

PROBLEM: Need theorem for orthogonality of composed weight filtrations
NATURE: Missing mathematical lemma/theorem

MATHEMATICAL CONTEXT:
We have: weight_filtration i (shape_modality (weight_filtration j x)) = 0 (from existing theorem)
We need: weight_filtration i (weight_filtration j x) = 0 (for our proof)

SELF-CONTAINED MINIMAL EXAMPLE:

-- Simplified mathematical structure
structure AlgebraSystem (α : Type*) where
  weight_op :   α  α
  shape_op : α  α
  zero : α
  -- Existing theorem: weight_op i (shape_op (weight_op j x)) = zero when i ≠ j
  orthogonal_with_shape :  i j x, i  j  weight_op i (shape_op (weight_op j x)) = zero

variable {α : Type*} (A : AlgebraSystem α)

-- We need this theorem but don't know how to prove it
example (i j : ) (x : α) (h : i  j) :
  A.weight_op i (A.weight_op j x) = A.zero := by
  -- Available: A.orthogonal_with_shape i j x h
  -- Needed: Bridge between shape_op and direct composition
  sorry

QUESTIONS:

  1. Is there a general mathematical principle for removing "shape operations" from orthogonality statements?
  2. Should we add a direct orthogonality theorem to our axiom system?
  3. What additional properties of shape_op would make this provable (idempotency, commutativity, etc.)?
  4. Is this a case where we need to expand our foundational theorems?

================================================================
ISSUE #4: MATHEMATICAL GAP - ENHANCED ORTHOGONALITY PROOF
================================================================
Line 117 in enhanced_e_orth theorem
NATURE: Missing theorem for composed weight filtrations

import UYA.Bindhu.Axiom_final

variable {𝒰 : Type*} [UYA.Bindhu.Final.BindhuAxiomSystem 𝒰]

example (B : UYA.Bindhu.Final.BindhuAxiomSystem 𝒰) (i j : ) (h_neq : i  j) (x : 𝒰) :
  B.components.weight_filtration (Int.natAbs i) (B.components.weight_filtration (Int.natAbs j) x) = UYA.Bindhu.Final.UnifiedMathOps.zero := by
  -- MATHEMATICAL GAP: Need to prove composed weight filtrations are orthogonal
  -- Available: idem_orthogonal gives weight_filtration i (shape_modality (weight_filtration j x)) = B.zero
  -- Needed: weight_filtration i (weight_filtration j x) = B.zero directly
  sorry

QUESTION: Should there be a canonical theorem for composed weight filtrations?
Or is there a way to bridge between idem_orthogonal and this statement?

Harikrishnan R (Aug 07 2025 at 05:07):

================================================================
ISSUE #5: PROOF STRATEGY GAP - FINITE SUPPORT PROPERTY
================================================================

PROBLEM: Missing theorem for "weight filtrations vanish beyond finite support"
NATURE: Mathematical gap requiring new foundational theorem

MATHEMATICAL CONTEXT:
Intuition: Weight filtrations should have finite support (only finitely many indices give non-zero results)
Needed: Explicit theorem stating this property with concrete bounds

SELF-CONTAINED MINIMAL EXAMPLE:

-- Mathematical structure with weight filtrations
structure FilteredAlgebra (α : Type*) where
  weight_filtration :   α  α
  zero : α
  -- We need this property but don't have it in our axiom system
  -- finite_support : ∃ bound : ℕ, ∀ x m, m ≥ bound → weight_filtration m x = zero

variable {α : Type*} (F : FilteredAlgebra α)

-- This is what we need to prove but have no foundation for
example (x : α) :  bound : ,  m  bound, F.weight_filtration m x = F.zero := by
  -- MATHEMATICAL GAP: No axiom or theorem provides this property
  -- Should we add it as a new axiom? Or derive it from existing properties?
  sorry

QUESTIONS:

  1. Is "finite support of weight filtrations" a standard property that should be axiomatic?
  2. Can this typically be derived from other algebraic properties (nilpotency, boundedness, etc.)?
  3. What would be a reasonable concrete bound (10, degree of polynomial, etc.)?
  4. Should this be an axiom in our system or a derived theorem from more fundamental properties?
    ================================================================
    ISSUE #5: LEAN 4 API ERROR - INT.NATCAST UNKNOWN CONSTANT
    ================================================================
    Line 181 in enhanced_finite_support theorem
    ERROR: unknown constant 'Int.natCast'
example (i : Int) (h_small : i < -9) : Int.natAbs i = Int.natCast (-i) := by
  -- LEAN 4 API ERROR: unknown constant 'Int.natCast'
  sorry

ORIGINAL ERROR MESSAGE:
error: /home/hari/Documents/uya_lean/UYA_Lean_V2/UYA/Chapter1/Idempotents.lean:181:46: unknown constant 'Int.natCast'

QUESTIONS:

  1. What is the correct Lean 4 replacement for Int.natCast?
  2. How should we convert between Int and Nat in Lean 4?
  3. Is Int.natCast deprecated or renamed in current Mathlib?

CONTEXT: We're trying to prove Int.natAbs i ≥ 10 when i ∉ {-9,...,9}
The goal is to show that elements outside a finite integer set have large absolute value.

Harikrishnan R (Aug 07 2025 at 05:08):

================================================================
SUMMARY & SPECIFIC REQUESTS
================================================================

LEAN 4 TECHNICAL ISSUES (Need Expert Guidance):

  • Issue #1: How to properly unfold/rewrite custom structure function fields
  • Issue #2: Correct API for Int↔Nat conversions (replacing Int.natCast)

MATHEMATICAL PROOF STRATEGY GAPS (Need Mathematical Guidance):

  • Issue #3: Handling signed indices in orthogonality proofs (|i| = |j| but i ≠ j cases)
  • Issue #4: Proving orthogonality for composed operations vs. operations with intermediate steps
  • Issue #5: Axiomatizing vs. deriving finite support properties in filtered algebras

WHAT WOULD HELP US MOST:

  1. Tactic recommendations for unfolding custom definitions
  2. Current Lean 4 API for integer arithmetic and absolute values
  3. Mathematical proof patterns for orthogonality in graded/filtered structures
  4. Best practices for axiomatizing vs. deriving finite support properties
  5. Structure design advice for making custom operations amenable to standard tactics

LEAN API/TACTIC ISSUES (Need Expert Lean 4 Guidance):

  • Issue #1: rewrite tactic failure with weight_filtration
  • Issue #5: Int.natCast API error

MATHEMATICAL GAPS (Need Proof Strategy/New Theorems):

  • Issue #2: Large weight bound theorem (finite support property)
  • Issue #3: Weight orthogonality logic flaw (i ≠ j vs |i| ≠ |j|)
  • Issue #4: Composed weight filtration orthogonality theorem

SPECIFIC REQUESTS:

  1. Correct Lean 4 API for Int-Nat conversions (replacing Int.natCast)
  2. Proper way to unfold/rewrite custom function definitions
  3. Mathematical guidance on orthogonality proofs for weight filtrations
  4. Whether new canonical theorems should be added to the axiom system

Thank you for any guidance you can provide!

(deleted) (Aug 07 2025 at 05:30):

this looks unreadable, could you write the message by yourself

(deleted) (Aug 07 2025 at 05:30):

I'm happy to help but first you need to make your message easy to understand, and unfortunately AI is making your message completely unreadable

Harikrishnan R (Aug 07 2025 at 12:08):

Comprehensive Minimal Working Example (MWE) for Lean 4 Expert Consultation

We are formalizing idempotent tower constructions with weight filtrations in Lean 4. We face 5 blocking issues involving Lean 4 tactic/API usage and mathematical proof gaps. Below is a concise MWE combining all issues as clear questions.


1. Tactic rewrite failure when unfolding structure function fields

We have a structure with function fields and want to rewrite/unfold them, but get an error:

structure MySystem (α : Type*) where
  weight_func :   α  α
  shape_func : α  α
  zero_elem : α

variable {α : Type*} (S : MySystem α)

example (x : α) (i : ) :
  S.weight_func i (S.shape_func x) = S.zero_elem := by
  rw [S.weight_func]  -- Error: tactic 'rewrite' failed, equality or iff proof expected
  sorry

Questions:

  • How to properly rewrite or unfold function fields inside structures?
  • Should we mark these fields with attributes like @[simp] or @[reducible]?
  • Are there better tactics than rw for this?

2. Lean 4 API error: Int.natCast unknown constant

We get the following error when trying to use Int.natCast:

example (i : Int) (h_neg : i < 0) : Int.natAbs i = Int.natCast (-i) := by
  sorry

Error message:

unknown constant 'Int.natCast'

Questions:

  • What is the correct Lean 4 API to convert Int to Nat?
  • How to express Int.natAbs i = (-i).natAbs for negative integers?
  • Are there idiomatic ways to handle integer absolute values and coercions in Lean 4?

3. Mathematical logic flaw: i ≠ j does not imply Int.natAbs i ≠ Int.natAbs j

We assumed:

example (i j : Int) (h : i  j) : Int.natAbs i  Int.natAbs j := by sorry

But this is false, e.g., i = 2, j = -2 satisfy i ≠ j but Int.natAbs i = Int.natAbs j = 2.

Questions:

  • How to handle cases where indices differ but have the same absolute value in orthogonality proofs?
  • Should proofs split cases for |i| = |j| and |i| ≠ |j|?
  • Is there a standard approach for signed index orthogonality?

4. Missing theorem for orthogonality of composed weight filtrations

Given:

structure AlgebraSystem (α : Type*) where
  weight_op :   α  α
  shape_op : α  α
  zero : α
  orthogonal_with_shape :  i j x, i  j  weight_op i (shape_op (weight_op j x)) = zero

variable {α : Type*} (A : AlgebraSystem α)

example (i j : ) (x : α) (h : i  j) :
  A.weight_op i (A.weight_op j x) = A.zero := by
  sorry

Questions:

  • Is there a known principle to remove intermediate shape_op in orthogonality statements?
  • Should we add a direct orthogonality axiom for composed operations?
  • What properties of shape_op (idempotent, commutative) help prove this?

5. Missing finite support property for weight filtrations

We want to prove:

structure FilteredAlgebra (α : Type*) where
  weight_filtration :   α  α
  zero : α

variable {α : Type*} (F : FilteredAlgebra α)

example (x : α) :  bound : ,  m  bound, F.weight_filtration m x = F.zero := by
  sorry

Questions:

  • Is finite support of weight filtrations a standard axiom or derivable?
  • Can it be derived from nilpotency or boundedness?
  • What are reasonable bounds (e.g., 10 or polynomial degree)?
  • Should this be added as a new axiom or proven from fundamentals?

We appreciate any guidance on Lean 4 tactics, API usage, and mathematical proof strategies related to these issues. Please let us know if more context or code is needed.

Thank you!

Matthew Ballard (Aug 07 2025 at 12:31):

Please stop dumping AI output into posts. With AI, you still bear the responsibility of contributing meaningfully to the discussion. You should summarize, synthesize, and provide context for any such output. Passive copying degrades the experience for all other users attempting to help.

Also, no more all caps posts.

Please know this is a warning before a potential suspension of your account.

Harikrishnan R (Aug 07 2025 at 12:38):

IAM SORRY SIR, MY LANGUAGE IS NOT GOOD, SOO I USE THE AI TO DESIGN QUESTIONS

Aaron Liu (Aug 07 2025 at 12:40):

Ask your questions one at a time

Aaron Liu (Aug 07 2025 at 12:40):

I don't know which one to answer

Robin Arnez (Aug 07 2025 at 12:40):

Please use a translator then instead; don't use AI

Matthew Ballard (Aug 07 2025 at 12:41):

Harikrishnan R said:

IAM SORRY SIR, MY LANGUAGE IS NOT GOOD, SOO I USE THE AI TO DESIGN QUESTIONS

All caps message

Matthew Ballard (Aug 07 2025 at 12:42):

As you see people here are eager to help but you are making it off-putting and difficult for them. I encourage you to follow their advice

Harikrishnan R (Aug 07 2025 at 12:43):

I will try my best. let me map the first question and share it. im sorry for the inconvinience

Matthew Ballard (Aug 07 2025 at 12:45):

I appreciate your interest in learning. I am just trying to help you channel it in the most effective way.

Harikrishnan R (Aug 07 2025 at 12:52):

Iam facing issues when im trying to Tactic rewrite failure when unfolding structure function fields
the basic code structure is as follows

structure MySystem (α : Type*) where
weight_func : ℕ → α → α
zero_elem : α

example (S : MySystem α) (x : α) (i : ℕ) :
S.weight_func i x = S.zero_elem := by
rw [S.weight_func] -- Error: tactic 'rewrite' failed
sorry

How can i solve the function fields in structures? The rw tactic isn't working."

ERROR
error: /home/hari/Documents/uya_lean/UYA_Lean_V2/UYA/Chapter1/Idempotents.lean:37:8:
tactic 'rewrite' failed, equality or iff proof expected
𝒰
case pos
𝒰 : Type u_1
B : Bindhu.Final.BindhuAxiomSystem 𝒰
i j : ℤ
x : 𝒰
h_neq : i ≠ j
h : i.natAbs = j.natAbs
⊢ Bindhu.Final.BindhuAxiomSystem.components.weight_filtration i.natAbs
(Bindhu.Final.BindhuAxiomSystem.components.shape_modality x) =
Bindhu.Final.UnifiedMathOps.zero

Matthew Ballard (Aug 07 2025 at 12:57):

```lean
structure MySystem (α : Type*) where
weight_func :   α  α
zero_elem : α

example (S : MySystem α) (x : α) (i : ) :
S.weight_func i x = S.zero_elem := by
rw [S.weight_func] -- Error: tactic 'rewrite' failed
sorry
```

Wrap your code like this to get syntax highlighting.

Aaron Liu (Aug 07 2025 at 12:57):

In this case what is the equation you are trying to rewrite with?

Robin Arnez (Aug 07 2025 at 12:59):

Well you defined it to be arbitrary when you defined MySystem so it doesn't have any definition and there's nothing to rewrite

Harikrishnan R (Aug 07 2025 at 13:08):

I WILL PREPARE THE COMPLETE QUESTION AND CODE AND GET BACK TO U AS I THINK THE CONTEXT WAS COMPLETELY MISSING, WHAT I WAS AIMING WAS TO GET THE IDEA OF THE FUNCTION BLOCKING ME, BUT I THINK THIS IS NOT ENOUGH. IM SORRY LEAN TEAM FOR THE UNNECESSARY CONFUSION. LET ME PREPARE THE QUESTION PROPERLY AND SHARE U

Matthew Ballard (Aug 07 2025 at 13:09):

I map my caps lock to the escape key. It might also help here.

Harikrishnan R (Aug 07 2025 at 13:19):

tNX MATHEW, MY KEYBORD CAPS KEY GOT STRUCK .. I NEED TO REPLACE THEM .. IM SORRY

Matthew Ballard (Aug 07 2025 at 13:23):

In that case, mapping to escape is probably a bad idea ;)

Kenny Lau (Aug 07 2025 at 13:38):

there's on-screen keyboard that can help you to be unstuck

Martin Dvořák (Aug 07 2025 at 13:55):

In addition to what has been said, I recommend not using #numbers on Lean Zulip, as they have a special meaning (you will generate misleading links).

Harikrishnan R (Aug 07 2025 at 14:11):

iam working on weight filtration finite support proofs in idempotent theory. The project builds successfully in Lean 4, butthe main issue is with integer absolute values and finite set membership proofs.

Issue:
I need to prove that if an integer is not in a small finite set {-9, -8, ..., 8, 9}, then its absolute value is at least 10. This pattern appears in our weight filtration proofs where we need to show elements outside finite support sets have large absolute values.

Goal: Prove that if an integer i is not in a small finite set, then its absolute value is large.

Context:
This lemma supports our main theorem about finite support properties:

lemma enhanced_finite_support (x : 𝒰) :
   S : Finset ,  i : , i  S  weight_filtration (Int.natAbs i) x = zero

** LEAN 4 TECHNICAL QUESTION:**
What's the best approach to prove: i  {-9,...,9}  Int.natAbs i  10?

I think the mathematical logic (contrapositive: Int.natAbs i  9  -9  i  9  i  {-9,...,9}), but im not sure how to solve this

**i tried:**
1. **Contrapositive approach**: Works mathematically but I get stuck proving Int.natAbs i  9  -9  i  9
2. **Range bounds**: I can show the bounds but struggle with the finite set membership step
3. **Various tactics**: Tried simp, omega, interval_cases - none seem to handle this cleanly

(deleted) (Aug 07 2025 at 14:17):

  1. Int.natCast doesn't currently exist. Instead, a natural number can be cast to an integer using the up arrow notation (↑a : ℤ)

Yakov Pechersky (Aug 07 2025 at 14:18):

For this issue

structure MySystem (α : Type*) where
  weight_func :   α  α
  shape_func : α  α
  zero_elem : α

variable {α : Type*} (S : MySystem α)

example (x : α) (i : ) :
  S.weight_func i (S.shape_func x) = S.zero_elem := by
  rw [S.weight_func]  -- Error: tactic 'rewrite' failed, equality or iff proof expected
  sorry

What do you want to achieve with rewriting with S.weight_func? In your example, S is arbitrary -- what do you want the rewrite to do?

Harikrishnan R (Aug 07 2025 at 14:19):

thn huynh but do u think :

/
lemma finite_set_natabs_bound (i : ) :
  i  ({-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9} : Finset ) 
  Int.natAbs i  10 := by
  intro h_notin

  -- **ATTEMPTED APPROACH 1**: Contrapositive
  by_contra h_contra
  push_neg at h_contra
  -- h_contra: Int.natAbs i < 10

  -- Convert to: Int.natAbs i ≤ 9
  have h_le_nine : Int.natAbs i  9 := Nat.lt_succ_iff.mp h_contra

  -- **TECHNICAL ISSUE**: How do we cleanly go from Int.natAbs i ≤ 9 to i ∈ {-9,...,9}?
  -- We know that Int.natAbs i ≤ 9 means |i| ≤ 9, so -9 ≤ i ≤ 9

  -- **ATTEMPTED APPROACH 2**: Range bounds
  have i_in_range : -9  i  i  9 := by
    constructor
    · -- Prove i ≥ -9
      by_contra h_small
      push_neg at h_small
      -- If i < -9, then Int.natAbs i = Int.natAbs i > 9
      sorry -- How to cleanly derive this contradiction?
    · -- Prove i ≤ 9
      by_contra h_large
      push_neg at h_large
      -- If i > 9, then Int.natAbs i = i > 9
      sorry -- How to cleanly derive this contradiction?

  -- **ATTEMPTED APPROACH 3**: Direct membership
  -- From -9 ≤ i ≤ 9, we should be able to show i ∈ {-9,...,9}
  have i_in_finite_set : i  ({-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9} : Finset ) := by
    -- **SPECIFIC LEAN 4 QUESTION**: What's the cleanest tactic for this?
    -- We tried: simp, omega, interval_cases, dec_trivial
    sorry -- What's the modern Lean 4 approach here?

  -- Contradiction with h_notin
  exact h_notin i_in_finite_set

**SPECIFIC QUESTIONS**:
1. What's the cleanest way to prove Int.natAbs i  9  -9  i  9?
 2. What's the best tactic for finite set membership when we have range bounds?
3. Is there a more direct approach than contrapositive for this type of lemma?
4. Should we use interval_cases, omega, or a different modern Lean 4 tactic?

Aaron Liu (Aug 07 2025 at 14:23):

import Mathlib

lemma finite_set_natabs_bound (i : ) :
    i  ({-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9} : Finset ) 
    Int.natAbs i  10 := by
  rw [not_imp_comm, ge_iff_le, not_le]
  intro hi
  have : -10 < i := by omega
  have : i < 10 := by omega
  interval_cases i <;> simp

Yakov Pechersky (Aug 07 2025 at 14:26):

That rw can even be contrapose!

Harikrishnan R (Aug 07 2025 at 14:57):

Aaron uare the best. thanks brother for guiding me through the toughest time of my life...tnx for ur great continuous contribution and im always thankful to u and robin

Harikrishnan R (Aug 07 2025 at 16:09):

Im designing a orthogonality proofs, we need to establish that different integer indices lead to orthogonal mathematical objects. A key technical step requires proving that different integers have different absolute values:

Given: i ≠ j (where i, j : Int)  
Want:  Int.natAbs i ≠ Int.natAbs j

However, this statement is not always true due to cases where i = -j (e.g., i = 3, j = -3).

Technical issues

  1. FAILED ATTEMPT: We tried using a theorem called Int.natAbs_eq.mp but discovered this doesn't exist in Lean 4.

  2. MATHEMATICAL REALITY: The correct equivalence is:
    Int.natAbs i = Int.natAbs j ↔ (i = j ∨ i = -j)

  3. CONTEXT: This arises in orthogonality proofs where we have:
    lean theorem orthogonality (i j : Int) (h_neq : i ≠ j) : some_orthogonality_property := by have h_abs_neq : Int.natAbs i ≠ Int.natAbs j := ‹need help here› ⟨rest of proof uses h_abs_neq›
    MWE:

  • Shows the problem case: Int.natAbs (3 : Int) = Int.natAbs (-3 : Int)
  • Shows a working case: Int.natAbs (3 : Int) ≠ Int.natAbs (4 : Int)
  • Demonstrates our failed proof attempts with sorry placeholders
  • Illustrates the mathematical context where this arises

How to handle Int.natAbs inequality in Lean 4?

-- Problem: This doesn't always hold due to i = -j case
example (i j : Int) (h_neq : i ≠ j) : Int.natAbs i ≠ Int.natAbs j := by
-- Mathematical fact: Int.natAbs i = Int.natAbs j iff (i = j ∨ i = -j)
-- Since i ≠ j, the issue arises when i = -j

intro h_abs_eq -- Assume Int.natAbs i = Int.natAbs j
-- Need: if Int.natAbs i = Int.natAbs j, then i = j ∨ i = -j
-- Question: What's the correct Lean 4 theorem for this equivalence?
-- Previous attempts used non-existent "Int.natAbs_eq.mp"
sorry

-- Alternative: What if we exclude the problematic case?
example (i j : Int) (h_neq : i ≠ j) (h_not_neg : i ≠ -j) : Int.natAbs i ≠ Int.natAbs j := by
-- This should definitely hold, but what's the Lean 4 proof?
intro h_abs_eq
-- With both conditions, we should reach a contradiction
-- But how to connect Int.natAbs equality to i = j ∨ i = -j?
sorry

-- Examples that work:
example : Int.natAbs (3 : Int) = Int.natAbs (-3 : Int) := rfl -- Shows the problem
example : Int.natAbs (3 : Int) ≠ Int.natAbs (4 : Int) := by decide -- This works

-- Failed attempts to find the right theorem:
-- #check Int.natAbs_eq -- doesn't exist
-- #check Int.natAbs.inj -- doesn't exist
-- #check Int.natAbs_inj -- doesn't exist

-- Cntext where this arises:
-- theorem orthogonality (i j : Int) (h_neq : i ≠ j) : some_orthogonality_property := by
-- have h_abs_neq : Int.natAbs i ≠ Int.natAbs j := ‹need help here›
-- ⟨rest of proof uses h_abs_neq⟩

Questions
Question 1: Library Theorem
What is the correct Lean 4 theorem that expresses the equivalence:
Int.natAbs i = Int.natAbs j ↔ (i = j ∨ i = -j)?

Question 2: Proof Strategy
Given i ≠ j, what's the standard Lean 4 approach to handle the fact that
Int.natAbs i ≠ Int.natAbs j doesn't always hold? Should we:

  • Add condition i ≠ -j and prove both cases separately?
  • Use a different mathematical approach entirely?
  • Handle the i = -j case contextually in the orthogonality proof?

Question 3: Best Practice
In mathematical contexts where orthogonality is the goal, what's the idiomatic
Lean 4 pattern for handling integer absolute value inequalities?

Aaron Liu (Aug 07 2025 at 16:11):

docs#Int.natAbs_eq_natAbs_iff

Joseph Myers (Aug 08 2025 at 02:12):

Aaron Liu said:

import Mathlib

lemma finite_set_natabs_bound (i : ) :
    i  ({-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9} : Finset ) 
    Int.natAbs i  10 := by
  rw [not_imp_comm, ge_iff_le, not_le]
  intro hi
  have : -10 < i := by omega
  have : i < 10 := by omega
  interval_cases i <;> simp

The documentation for grind at https://leanprover-community.github.io/mathlib-manual/html-multi/Tactics/All-tactics/#grind is completely empty - nothing at all about possible parameters to configure it - so it's necessary to do trial and error based on diagnostics, but:

import Mathlib

lemma finite_set_natabs_bound (i : ) :
    i  ({-9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9} : Finset ) 
    Int.natAbs i  10 := by
  grind (gen := 20) (ematch := 10)

appears to work.

Li Xuanji (Aug 08 2025 at 02:14):

AFAICT grind documentation is stored in lean language reference not Mathlib, probably because grind does not depend on Mathlib

Joseph Myers (Aug 08 2025 at 02:16):

The tactic manual is supposed to combine documentation from multiple sources of all tactics available when using mathlib. It should either incorporate or link to grind documentation so you don't need to remember a special rule for where to find it.

Li Xuanji (Aug 08 2025 at 02:20):

That's interesting, it does say it's automatically generated, I wonder why it's empty for grind

Joseph Myers (Aug 08 2025 at 02:20):

I also can't locate anything in that section of the language reference that looks like a comprehensive reference to all configuration options that can be passed in a call to the grind tactic, just incidental references to various such options in various places in the documentation.

Joseph Myers (Aug 08 2025 at 02:22):

So I don't know what (gen := 20) (ematch := 10) really means, just that the diagnostics gave hints that grind ran into those limits so I tried increasing them. (Since this entire lemma looked like it should be within the scope of grind, appropriately configured.)

Joseph Myers (Aug 08 2025 at 02:26):

(Of course, an advantage of formal proof is that you don't need to know what something means to use it in a proof, if it works. That's much more dangerous if you try it with some informal result you don't actually understand the statement of.)

Robin Arnez (Aug 08 2025 at 09:08):

Are the hovers not useful?
Screenshot 2025-08-08 110725.png

Michael Rothgang (Aug 08 2025 at 09:51):

@Jon Eugster

Joseph Myers said:

The tactic manual is supposed to combine documentation from multiple sources of all tactics available when using mathlib. It should either incorporate or link to grind documentation so you don't need to remember a special rule for where to find it.

IIUC, the mathlib manual just takes the doc-strings of each tactic: imho, the fact that grind has an empty doc-string is a bug. That doc-string can (and perhaps should) link to the language reference!

Michael Rothgang (Aug 08 2025 at 09:51):

@Joachim Breitner Would a PR adding some brief doc-string to grind be welcome in Lean core?

Joachim Breitner (Aug 08 2025 at 10:42):

There is a docstring:
https://leanprover-community.github.io/mathlib4_docs/Init/Grind/Tactics.html#Lean.Parser.Tactic.grind

Michael Rothgang (Aug 08 2025 at 10:59):

@Jon Eugster Would a PR updating the tactic manual to current mathlib be welcome? Do you know why the auto-generated doc-string for grind is empty?

Jon Eugster (Aug 08 2025 at 10:59):

You're both right: grind has a docstring, but it only has been added after the last stable Lean release (here) so it will have one in v4.22.0

Michael Rothgang (Aug 08 2025 at 11:00):

I see; thanks a lot!

Jon Eugster (Aug 08 2025 at 11:04):

And yes, updating or thinking about automated buping is certainly welcome!

currently I do the following in all projects:

-- Using this assumes that each dependency has a tag of the form `v4.X.0`.
def leanVersion : String := s!"v{Lean.versionString}"
require "leanprover-community" / "mathlib" @ git leanVersion
require "leanprover" / "verso" @ git leanVersion

and it seems both mathlib and verso have a v4.22.0-rc4 so you could just change the lean-toolchain to v4.22.0-rc4, call lake update and hope nothing breaks.


Last updated: Dec 20 2025 at 21:32 UTC