Zulip Chat Archive
Stream: new members
Topic: Convert `z ∣ ` to divisor list
Li Xuanji (Feb 03 2026 at 04:05):
Are there lemma-free proofs for either of these theorems?
import Mathlib
lemma ndvd_two_then (z : ℕ) (hz : z ∣ 2) : z = 1 ∨ z = 2 := by
have : z ∈ Nat.divisors 2 := by grind [Nat.mem_divisors]
rw [show Nat.divisors 2 = {1, 2} by rfl] at this
grind
lemma zdvd_two_then (z : ℤ) (hz : z ∣ 2) : z = 1 ∨ z = -1 ∨ z = 2 ∨ z = -2 := by
have : (Int.natAbs z) ∣ 2 := by
rw [← Int.ofNat_dvd_right]
norm_num
exact hz
have : (Int.natAbs z) ∈ Nat.divisors 2 := by grind [Nat.mem_divisors]
simp [show Nat.divisors 2 = {1, 2} by rfl] at this
grind
(failing that, any way to make them shorter?)
Yongxi Lin (Aaron) (Feb 03 2026 at 04:19):
My attempt:
import Mathlib
lemma ndvd_two_then (z : ℕ) (hz : z ∣ 2) : z = 1 ∨ z = 2 := by
have : z ∈ Nat.divisors 2 := by grind
simpa [show Nat.divisors 2 = {1, 2} by rfl] using this
lemma zdvd_two_then (z : ℤ) (hz : z ∣ 2) : z = 1 ∨ z = -1 ∨ z = 2 ∨ z = -2 := by
have : (Int.natAbs z) ∣ 2 := by simpa [← Int.ofNat_dvd_right] using hz
grind [ndvd_two_then (Int.natAbs z) this]
Eric Wieser (Feb 03 2026 at 04:44):
We have another thread about this somewhere
Li Xuanji (Feb 03 2026 at 15:11):
Ah, I found the thread, which taught me about the divisors_ofNat simproc.
import Mathlib
lemma ndvd_two_then (z : ℕ) (hz : z ∣ 2) : z = 1 ∨ z = 2 := by
have : z ∈ Nat.divisors 2 := by grind [Nat.mem_divisors]
simp_all
I think there is a problem that Nat.mem_divisors (marked as @simp) simplifies Nat.divisors 2 to z ∣ 2, but the divisors_ofNat simproc fires on Nat.divisors 2 but not z ∣ 2
Last updated: Feb 28 2026 at 14:05 UTC