theory Demo7 imports Main begin -- ------------------------------------------------------------------ text {* Isar *} lemma "\ A; B \ \ A \ B" proof (rule conjI) assume A: "A" from A show "A" by assumption next assume "B" from `B` show "B" by assumption qed lemma assumes A: "A" assumes B: "B" shows "A \ B" proof (rule conjI) from A show "A" by assumption from B show "B" by assumption qed lemma "(x::nat) + 1 = 1 + x" proof - have A: "x + 1 = Suc x" by simp have B: "1 + x = Suc x" by simp show "x + 1 = 1 + x" by (simp only: A B) qed -- ------------------------------------------------------------------ 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" apply (simp split: nat.splits) 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" apply (simp cong: conj_cong) oops thm if_cong lemma "\ (if x then x \ z else B) = z; Q \ \ P" -- " apply simp" apply (simp cong: if_cong) oops thm add_ac thm 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" apply (simp cong: conj_cong) oops -- "single stepping: subst" thm add_commute lemma "a + b = x + (y::nat)" apply (subst add_commute) back -- "since Isabelle2005 also: apply (subst (asm) some_thm)" oops end