theory Demo12 = Main: consts sep :: "'a \ 'a list \ 'a list" recdef sep "measure (\(a, xs). size xs)" "sep (a, x # y # zs) = x # a # sep (a, y # zs)" "sep (a, xs) = xs" lemma "sep (a, [x,y,z]) = bla" apply simp oops lemma "map f (sep (x,xs)) = sep (f x, map f xs)" apply (induct xs) oops -- solution lemma "map f (sep (x,xs)) = sep (f x, map f xs)" apply (induct x xs rule: sep.induct) apply auto done consts ack :: "nat \ nat \ nat" recdef ack "measure (\m. m) <*lex*> measure (\n. n)" "ack (0, n) = Suc n" "ack (Suc m, 0) = ack (m, 1)" "ack (Suc m, Suc n) = ack (m, ack (m+1, n))" thm ack.induct consts quicksort :: "nat list \ nat list" recdef (permissive) quicksort "measure length" "quicksort [] = []" "quicksort (x#xs) = quicksort [y \ xs. y \ x] @ [x] @ quicksort [y \ xs. x < y]" (* (hints recdef_simp: less_Suc_eq_le) *) consts quicksort2 :: "nat list \ nat list" recdef (permissive) quicksort2 "measure length" "quicksort2 [] = []" "quicksort2 (x#xs) = quicksort2 [y \ xs. y \ x] @ [x] @ quicksort2 [y \ xs. x < y]" print_theorems -- --------------------------------------------------------------- -- "wfrec" thm wf_def thm wfrecI thm wfrec_def thm cut_def thm wfrec consts f :: "nat \ nat" recdef f "measure id" "f 0 = 0" "f (Suc n) = f n + 1" print_theorems thm wf_measure thm wf_less thm wf_lex_prod thm finite_acyclic_wf acyclic_def -- --------------------------------------------------------------- -- "also/finally" lemma right_inverse: fixes prod :: "'a \ 'a \ 'a" (infixl "\" 70) fixes inv :: "'a \ 'a" ("(_\<^sup>-)" [1000] 999) fixes one :: 'a ("\") assumes assoc: "\x y z. (x \ y) \ z = x \ (y \ z)" assumes left_inv: "\x. x\<^sup>- \ x = \" assumes left_one: "\x. \ \ x = x" shows "x \ x\<^sup>- = \" proof - have "x \ x\<^sup>- = \ \ (x \ x\<^sup>-)" by (simp only: left_one) also have "\ = \ \ x \ x\<^sup>-" by (simp only: assoc) also have "\ = (x\<^sup>-)\<^sup>- \ x\<^sup>- \ x \ x\<^sup>-" by (simp only: left_inv) also have "\ = (x\<^sup>-)\<^sup>- \ (x\<^sup>- \ x) \ x\<^sup>-" by (simp only: assoc) also have "\ = (x\<^sup>-)\<^sup>- \ \ \ x\<^sup>-" by (simp only: left_inv) also have "\ = (x\<^sup>-)\<^sup>- \ (\ \ x\<^sup>-)" by (simp only: assoc) also have "\ = (x\<^sup>-)\<^sup>- \ x\<^sup>-" by (simp only: left_one) also have "\ = \" by (simp only: left_inv) finally show ?thesis . qed declare f.simps [simp del] lemma "f (Suc n) = f n + 1" proof - let ?R = "measure id" let ?F = "\f. nat_case 0 (\u. f u + 1)" have wf: "wf ?R" by (rule wf_measure) have "f (Suc n) = wfrec ?R ?F (Suc n)" by (simp only: f_def) also from wf have "\ = ?F (cut (wfrec ?R ?F) ?R (Suc n)) (Suc n)" by (rule wfrec) also have "\ = cut (wfrec ?R ?F) ?R (Suc n) n + 1" by simp also have "\ = wfrec ?R ?F n + 1" by (simp add: cut_def measure_def inv_image_def) also have "\ = f n + 1" by (simp only: f_def) finally show ?thesis . qed -- "mixed operators" lemma "1 < (5::nat)" proof - have "1 < Suc 1" by simp also have "Suc 1 = 2" by simp also have "2 \ (5::nat)" by simp finally show ?thesis . qed -- "substitution" lemma blah proof - have "x + 2*y = (0::nat)" sorry also have "2*y = x" sorry also have "(0::nat) \ 2*c" sorry also have "c = d div 2" sorry also have "d = 2 * x" sorry finally have "x + x \ 2 * x " by simp oops -- "antisymmetry" lemma blub proof - have "a < (b::nat)" sorry also have "b < a" sorry finally show blub . qed -- "notE as trans" thm notE declare notE [trans] lemma blub proof - have "\P" sorry also have "P" sorry finally show blub . qed -- "monotonicity" lemma "a+b \ 2*a + 2*(b::nat)" proof - have "a + b \ 2*a + b" by simp also have "b \ 2*b" by simp finally show "a+b \ 2*a + 2*(b::nat)" by simp qed lemma "a+b \ 2*a + 2*(b::nat)" proof - have "a + b \ 2*a + b" by simp also have "b \ 2*b" by simp also have "\x y. x \ y \ 2 * a + x \ 2 * a + y" by simp ultimately show "a+b \ 2*a + 2*(b::nat)" . qed declare ring_eq_simps [simp] lemma "(a+b::int)\ \ 2*(a\ + b\)" proof - have "(a+b)\ \ (a+b)\ + (a-b)\" by simp also have "(a+b)\ \ a\ + b\ + 2*a*b" by (simp add: numeral_2_eq_2) also have "(a-b)\ = a\ + b\ - 2*a*b" by (simp add:numeral_2_eq_2) finally show ?thesis by simp qed end