theory FibInClass imports Main begin (* Function package *) fun fib :: "nat \ nat" where "fib 0 = 0" | "fib (Suc 0) = 1" | "fib n = fib (n - 2) + fib (n - 1)" primrec itfib :: "nat \ nat \ nat \ nat" where "itfib f f' 0 = f" | "itfib f f' (Suc k) = itfib f' (f + f') k" theorem "\ n. itfib (fib n) (fib (n + 1)) k = fib (n + k)" apply (induct k) apply simp apply auto thm allE apply (erule_tac x="n+1" in allE) apply simp done thm conjE thm conjI thm disjI1 thm disjI2 thm disjE theorem "P \ Q \ P" proof - show "P \ Q \ P" proof (rule impI) assume pq: "P \ Q" from pq show "P" by (rule conjunct1) qed qed (* lemma L1[simp]: versus lemma L1: then later apply (auto simp: L1) or apply (simp add: L1) *) (* Example with custom termination measure *) function sum :: "nat \ nat \ nat" where "sum i n = (if i > n then 0 else i + sum (i + 1) n)" by pat_completeness auto termination sum apply (relation "measure (\(i,n). (n + 1) - i)") apply auto done end