Skip to content

Commit d1d1e4b

Browse files
committed
chore: address unusedHavesSuffices warning (#13754)
This linter was silently not doing anything until leanprover/lean4#4410 was fixed, and now it is working so a backlog of warnings needed to be addressed. Some were addressed here: #13680. The warnings in this PRs are false positives (leanprover-community/batteries#428?), but a workaround is put in place. Co-authored-by: L Lllvvuu <[email protected]>
1 parent fbf1dad commit d1d1e4b

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

Mathlib/Data/Nat/Log.lean

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ namespace Nat
3030
such that `b^k ≤ n`, so if `b^k = n`, it returns exactly `k`. -/
3131
--@[pp_nodot] porting note: unknown attribute
3232
def log (b : ℕ) : ℕ → ℕ
33-
| n =>
34-
if h : b ≤ n ∧ 1 < b then
35-
have : n / b < n := div_lt_self ((Nat.zero_lt_one.trans h.2).trans_le h.1) h.2
36-
log b (n / b) + 1
37-
else 0
33+
| n => if h : b ≤ n ∧ 1 < b then log b (n / b) + 1 else 0
34+
decreasing_by
35+
-- putting this in the def triggers the `unusedHavesSuffices` linter:
36+
-- https://github.com/leanprover-community/batteries/issues/428
37+
have : n / b < n := div_lt_self ((Nat.zero_lt_one.trans h.2).trans_le h.1) h.2
38+
decreasing_trivial
3839
#align nat.log Nat.log
3940

4041
@[simp]
@@ -238,11 +239,13 @@ theorem add_pred_div_lt {b n : ℕ} (hb : 1 < b) (hn : 2 ≤ n) : (n + b - 1) /
238239
`k : ℕ` such that `n ≤ b^k`, so if `b^k = n`, it returns exactly `k`. -/
239240
--@[pp_nodot]
240241
def clog (b : ℕ) : ℕ → ℕ
241-
| n =>
242-
if h : 1 < b ∧ 1 < n then
243-
have : (n + b - 1) / b < n := add_pred_div_lt h.1 h.2
244-
clog b ((n + b - 1) / b) + 1
245-
else 0
242+
| n => if h : 1 < b ∧ 1 < n then clog b ((n + b - 1) / b) + 1 else 0
243+
decreasing_by
244+
-- putting this in the def triggers the `unusedHavesSuffices` linter:
245+
-- https://github.com/leanprover-community/batteries/issues/428
246+
have : (n + b - 1) / b < n := add_pred_div_lt h.1 h.2
247+
decreasing_trivial
248+
246249
#align nat.clog Nat.clog
247250

248251
theorem clog_of_left_le_one {b : ℕ} (hb : b ≤ 1) (n : ℕ) : clog b n = 0 := by

0 commit comments

Comments
 (0)