Zulip Chat Archive
Stream: new members
Topic: linarith failed to find a contradiction
Vasily Ilin (Sep 14 2021 at 19:50):
In the following script I get the error "linarith failed to find a contradiction" even though k1
asserts that the same thing times 2 is positive. I don't understand what is going on.
import data.real.basic
example {n : ℕ} : 0 < 1/(n+1 : ℝ) :=
begin
have k1 : 1/(n+1 : ℝ) > 0,
exact nat.one_div_pos_of_nat,
have k2 : 1/2 * 1/(n+1 : ℝ) > 0,
linarith,
end
Yaël Dillies (Sep 14 2021 at 19:52):
linarith
doesn't know about multiplication.
Yaël Dillies (Sep 14 2021 at 19:53):
I would have expected nlinarith
to solve this, but it doesn't :thinking:. Just apply mul_pos
, I guess.
Vasily Ilin (Sep 14 2021 at 19:54):
But this works just fine. So linarith
must know about multiplication.
example {ε : ℝ} (h : ε > 0) : 1/2 * ε > 0 :=
begin
linarith,
end
Yaël Dillies (Sep 14 2021 at 19:56):
Actually, you didn't really write what you meant.
Yaël Dillies (Sep 14 2021 at 19:57):
linarith
does know about multiplication, but only handles constants well.
Yaël Dillies (Sep 14 2021 at 19:57):
This works.
import data.real.basic
example {n : ℕ} : 0 < 1/(n+1 : ℝ) :=
begin
have k1 : 0 < 1/(n+1 : ℝ),
exact nat.one_div_pos_of_nat,
have k2 : 0 < 1/2 * (1/(n+1 : ℝ)),
linarith,
end
Alex J. Best (Sep 14 2021 at 19:59):
The difference being the brackets, 1/2 * 1 / n
is treated as (1/2 * 1) / n
and not (1/2)*(1/n)
.
Vasily Ilin (Sep 14 2021 at 19:59):
Oh. My. God. Okay... Thanks
Yaël Dillies (Sep 14 2021 at 19:59):
The Infoview is your friend! Click on the operators and see what gets selected.
Yaël Dillies (Sep 14 2021 at 20:00):
Clicking on the second /
in 1/2 * 1/(n+1 : ℝ)
selects everything. That's how I spotted it.
Vasily Ilin (Sep 14 2021 at 20:00):
What do you mean @Yaël Dillies ? Click on *
? Nothing happens for me.
Alex J. Best (Sep 14 2021 at 20:01):
Are you using vscode?
Yaël Dillies (Sep 14 2021 at 20:01):
in the Infoview, I mean. Are you not using VScode?
Vasily Ilin (Sep 14 2021 at 20:01):
Yes
Vasily Ilin (Sep 14 2021 at 20:01):
No, I use VScode. I just don't know what is infoview
Yaël Dillies (Sep 14 2021 at 20:01):
This is how it looks like. image.png
Alex J. Best (Sep 14 2021 at 20:02):
Vasily Ilin (Sep 14 2021 at 20:02):
Ohhh, very cool! I did not know about this functionality. Thank you!
Yaël Dillies (Sep 14 2021 at 20:03):
This is THE functionality :wink:
Yaël Dillies (Sep 14 2021 at 20:03):
where interactive theorem proving comes true.
Shange Tang (Oct 27 2024 at 12:55):
Hi, I have a trivial question. I am writing the following lean code, which seems can be solved easily by linarith. However linarith failed to find a contradiction. I am wondering why? And how to fix it?
import Mathlib
import Aesop
set_option maxHeartbeats 0
open BigOperators Real Nat
theorem problem1_step3 (n : ℕ) (a : ℕ → ℝ) (h₀ : ∀ k < n, |a k| < 1) (h₁ : ∑ k ∈ Finset.range n, |a k| = 19 + |∑ k ∈ Finset.range n, a k|) (t_ge_19 : ∑ k ∈ Finset.range n, |a k| ≥ 19) (t_lt_n : ∑ k ∈ Finset.range n, |a k| < ↑n) : 19 < n := by
linarith [t_ge_19, t_lt_n]
Shange Tang (Oct 27 2024 at 12:56):
For your information, I receive the following message.
Screenshot 2024-10-27 at 8.55.33 AM.png
Ruben Van de Velde (Oct 27 2024 at 12:57):
Probably it's not dealing with the coercions between naturals and reals
Ruben Van de Velde (Oct 27 2024 at 13:01):
Though that doesn't help:
import Mathlib
import Aesop
set_option maxHeartbeats 0
open BigOperators Real Nat
theorem problem1_step3 (n : ℕ) (a : ℕ → ℝ) (h₀ : ∀ k < n, |a k| < 1) (h₁ : ∑ k ∈ Finset.range n, |a k| = 19 + |∑ k ∈ Finset.range n, a k|) (t_ge_19 : ∑ k ∈ Finset.range n, |a k| ≥ 19) (t_lt_n : ∑ k ∈ Finset.range n, |a k| < ↑n) : 19 < n := by
rw [← Nat.ofNat_lt_cast (α := ℝ)]
rw [ge_iff_le] at t_ge_19
fail_if_success linarith [t_ge_19, t_lt_n]
exact t_ge_19.trans_lt t_lt_n
Shange Tang (Oct 27 2024 at 13:06):
Thank you very much! It seems that even after dealing with the coercions, linarith still can not close the goal.
Daniel Weber (Oct 27 2024 at 13:15):
Fwiw
theorem problem1_step3 (n : ℕ) (a : ℕ → ℝ) (h₀ : ∀ k < n, |a k| < 1) (h₁ : ∑ k ∈ Finset.range n, |a k| = 19 + |∑ k ∈ Finset.range n, a k|) (t_ge_19 : ∑ k ∈ Finset.range n, |a k| ≥ 19) (t_lt_n : ∑ k ∈ Finset.range n, |a k| < ↑n) : 19 < n := by
rify at *
linarith
works
Ruben Van de Velde (Oct 27 2024 at 13:35):
:exploding_head:
Last updated: May 02 2025 at 03:31 UTC