I have the following datatypes and functions
type_synonym variable = string
datatype bexpr =
Const bool
| Var variable
| And bexpr bexpr
| Or bexpr bexpr
| Imp bexpr bexpr
| Neg bexpr
datatype occ =
Even
| Odd
| Both
fun negate :: "occ ⇒ occ" where
"negate Even = Odd" |
"negate Odd = Even" |
"negate Both = Both"
fun merge :: "occ ⇒ occ ⇒ occ" where
"merge x y = (if x = y then x else Both)"
primrec occurrences :: "bexpr ⇒ variable ⇒ occ" where
"occurrences (Const _) _ = Even" |
"occurrences (Var y) x = Even" |
"occurrences (And phi psi) x = (merge (occurrences phi x) (occurrences psi x))" |
"occurrences (Or phi psi) x = (merge (occurrences phi x) (occurrences psi x))" |
"occurrences (Imp phi psi) x = (merge (negate (occurrences phi x)) (occurrences psi x))" |
"occurrences (Neg phi) x = (negate (occurrences phi x))"
and I want to prove that
lemma negateOccEvenIsOdd: "negate (occurrences phi x) = Even ⟶ occurrences phi x = Odd"
I know that Sledgehammer automatically finds proofs for this, e.g. using negate.elims by blast
or by (metis negate.cases negate.simps)
.
However, I want to prove this using Isar manually solely for learning purposes but I am a bit stuck on how to do that.
I managed to do an apply
-style proof:
lemma negateOccEvenIsOdd: "negate (occurrences phi x) = Even ⟶ occurrences phi x = Odd"
apply (rule impI)
apply (erule negate.elims)
apply simp
apply simp
apply simp
done
That proof looks like a candidate for apply (cases phi)
And replace ⟶
by ==>
Since I wanted to do it in Isar, I did
lemma "negate (occurrences phi x) = Even ⟹ occurrences phi x = Odd"
proof (cases phi)
case (Const b)
...
I would even go for:
lemma
assumes "negate (occurrences phi x) = Even"
shows "occurrences phi x = Odd"
proof (cases phi)
I would go for:
lemma negate_Even_iff:
‹negate b = Even ⟷ b = Odd›
by (cases b)
(simp_all only: negate.simps occ.simps refl)
lemma
assumes neg: "negate (occurrences phi x) = Even"
shows "occurrences phi x = Odd"
using assms
apply (subst (asm) negate_Even_iff)
apply assumption
done
This proof is also showing that my advice for cases phi
was wrong, sorry
Mathias Fleury said:
This proof is also showing that my advice for
cases phi
was wrong, sorry
Yeah I was about to comment that I don't think cases phi
is going to work. No worries though! Thanks for the comments.
Last updated: Dec 21 2024 at 16:20 UTC