Zulip Chat Archive
Stream: new members
Topic: confusion about how to orelse
Xiyu Zhai (Dec 07 2024 at 09:54):
Hi, all. I'm confused about the behavior of orelse
and first
in lean4.
import Mathlib
-- success
example (x : ℝ) (h : x > 0) : 1/x + 1 = (x+1)/x := by
field_simp; ring
-- unsolved goals
-- x : ℝ
-- h : x > 0
-- ⊢ 1 + x⁻¹ = x * x⁻¹ + x⁻¹Lean 4
example (x : ℝ) (h : x > 0) : 1/x + 1 = (x+1)/x := by
ring <;> (field_simp ;ring)
-- unsolved goals
-- x : ℝ
-- h : x > 0
-- ⊢ 1 + x⁻¹ = x * x⁻¹ + x⁻¹Lean 4
example (x : ℝ) (h : x > 0) : 1/x + 1 = (x+1)/x := by
first | ring | (field_simp ;ring)
For example, since the first in the above code succeed, I would expect all followings will succeed too.
Claude Sonnet seems to agree with me. Please enlight me and Claude.
Daniel Weber (Dec 07 2024 at 10:01):
In the second example I'm seeing no goals to be solved
on the second ring
, because the field_simp
solved it.
In the third, first
uses the first tactic that succeeds, where succeeds means "throws no errors". You can change ring
to (ring; done)
to assert that all goals are solved, and then that will fail and the second tactic sequence (field_simp; ring
) will act
Xiyu Zhai (Dec 07 2024 at 10:02):
wow, excellent!
Xiyu Zhai (Dec 07 2024 at 10:02):
Thanks a lot!!
Xiyu Zhai (Dec 07 2024 at 10:03):
Now I understand that if only one goal is solved, it counts as success.
Last updated: May 02 2025 at 03:31 UTC