theory Demo8 imports Main begin -- ------------------------------------------------------------------ text {* more automation *} -- "clarsimp: repeated clarify and simp" lemma "ys = [] \ \xs. xs @ ys = []" apply clarsimp oops -- "auto: simplification, classical reasoning, more" lemma "(\u::nat. x=y+u) \ a*(b+c)+y \ x + a*b+a*c" apply (auto simp add: add_mult_distrib2) done -- "also try: fastsimp and force" text {* simplification with assumptions, more control: *} lemma "\x. f x = g x \ g x = f x \ f [] = f [] @ []" -- "would diverge:" (* apply(simp) *) apply(simp (no_asm)) done -- ------------------------------------------------------ -- "let expressions" lemma "let a = f x in g a = x" apply (simp add: Let_def) oops thm Let_def term "let a = f x in g a" -- ------------------------------------------------------ -- "splitting case: manually" lemma "(case n of 0 \ x | Suc n' \ x) = x" apply (simp only: split: nat.splits) apply simp done -- "splitting if: automatic in conclusion" lemma "\ P; Q \ \ (if x then A else B) = z" apply simp oops lemma "\ (if x then A else B) = z; Q \ \ P" apply (simp split: split_if_asm) oops thm conj_cong lemma "A \ (A \ B)" apply (simp cong: conj_cong) oops thm if_cong lemma "\ (if x then x \ z else B) = z; Q \ \ P" apply (simp cong: if_cong) oops thm add_ac thm mult_ac lemmas all_ac = add_ac mult_ac lemma fixes f :: "'a \ 'a \ 'a" (infix "\" 70) assumes A: "\x y z. (x \ y) \ z = x \ (y \ z)" assumes C: "\x y. x \ y = y \ x" assumes AC: "\x y z. x \ (y \ z) = y \ (x \ z)" shows "(z \ x) \ (y \ v) = something" apply (simp only: C) apply (simp only: A C) apply (simp only: AC) oops text {* when all else fails: tracing the simplifier Isabelle/Isar -> Settings -> Trace Simplifier, then Proof-General -> Buffers -> Trace *} lemma "A \ (A \ B)" apply (simp cong: conj_cong) oops -- "single stepping: subst" thm add_commute declare add_assoc [simp] lemma "a + b = x + ((y::nat) + z)" apply (simp add: add_assoc [symmetric] del: add_assoc) apply (subst add_commute [where a=x]) oops end