Zulip Chat Archive
Stream: lean4
Topic: Prove return value of functon
Jesse Slater (Jan 04 2023 at 17:20):
I am having trouble finishing this proof. What can I do to replace the sorry?
structure SystemState where
evenCount : Nat
oddCount : Nat
deriving Repr
def bar (S : SystemState) := S
def foo (S: SystemState): Option SystemState :=
if S.oddCount ≥ 2 then Option.some (bar S)
else Option.none
variable (x : SystemState)
variable (ge2 : x.oddCount ≥ 2)
theorem t : foo x = Option.some (bar x) :=
by sorry
I have simplified it to retain only the relevant parts. This is part of a larger proof, where bar does something, and where I get x and ge2 from assumptions
František Silváši 🦉 (Jan 04 2023 at 17:45):
To be as explicit as possible, one can first inspect the definition of foo and apply a lemma (if_pos
) stating that if the boolean test is true, then we get the first branch. As such:
theorem t : foo x = Option.some (bar x) := by
unfold foo
rw [if_pos ge2]
František Silváši 🦉 (Jan 04 2023 at 17:47):
Normally for proofs that have an obvious series of rewrites to reach the goal, you'll see something like by simp [foo, *]
.
Jesse Slater (Jan 04 2023 at 17:54):
Thank you!
Last updated: Dec 20 2023 at 11:08 UTC