theory Demo14 = Main: section {* Example 1 *} locale semi = fixes prod :: "['a, 'a] => 'a" (infixl "\" 70) assumes assoc: "(x \ y) \ z = x \ (y \ z)" locale group = semi + fixes one ("\") and inv ("_\<^sup>-" [100] 100) assumes l_one: "\ \ x = x" assumes l_inv: "x\<^sup>-\ x = \" lemma (in group) r_inv: "x \ x\<^sup>- = \" proof - have "x \ x\<^sup>- = \ \ (x \ x\<^sup>-)" by (simp only: l_one) also have "\ = \ \ x \ x\<^sup>-" by (simp only: assoc) also have "\ = (x\<^sup>-)\<^sup>- \ x\<^sup>- \ x \ x\<^sup>-" by (simp only: l_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: l_inv) also have "\ = (x\<^sup>-)\<^sup>- \ (\ \ x\<^sup>-)" by (simp only: assoc) also have "\ = (x\<^sup>-)\<^sup>- \ x\<^sup>-" by (simp only: l_one) also have "\ = \" by (simp only: l_inv) finally show ?thesis . qed lemma (in group) r_one: "x \ \ = x" proof - have "x \ \ = x \ (x\<^sup>- \ x)" by (simp only: l_inv) also have "\ = (x \ x\<^sup>-) \ x" by (simp only: assoc) also have "\ = \ \ x" by (simp only: r_inv) also have "\ = x" by (simp only: l_one) finally show "x \ \ = x" . qed lemma (in group) l_cancel [simp]: "(x \ y = x \ z) = (y = z)" proof assume "x \ y = x \ z" then have "(x\<^sup>- \ x) \ y = (x\<^sup>- \ x) \ z" by (simp add: assoc) then show "y = z" by (simp add: l_inv l_one) next assume "y = z" then show "x \ y = x \ z" by simp qed subsection {* Export *} thm semi.assoc group.l_cancel subsection {* Definitions *} locale semi2 = semi + fixes rprod (infixl "\" 70) defines rprod_def: "rprod x y \ y \ x " lemma (in semi2) r_assoc: "(x \ y) \ z = x \ (y \ z)" by (simp only: rprod_def assoc) thm semi2.r_assoc -- ----------------------------------------------------------------- section {* Example 2 *} locale group_hom = group sum zero minus + group + fixes hom assumes hom_mult: "hom (sum x y) = hom x \ hom y" lemma (in group_hom) hom_one: "hom zero = \" proof - have "hom zero \ \ = hom zero \ hom zero" by (simp add: hom_mult [symmetric] sum_zero_minus.l_one prod_one_inv.r_one) -- {* Or add @{text l_one} to simpset right away. *} then show ?thesis by simp qed locale simple = fixes a and b assumes A: "a + b = x" print_theorems locale not_so_simple = simple + fixes c and d defines "c \ a + b" assumes B: "a + c = d" print_theorems -- --------------------------------------------------------------- section {* Example 3 *} lemma int_semi: "semi (op +::[int, int]=>int)" by (auto intro!: semi.intro) lemma int_group: "group (op +) (0::int) uminus" by (auto intro!: group.intro semi.intro group_axioms.intro) text {* Manual instantiation possible with the OF attribute. *} thm semi.assoc [OF int_semi] thm group.l_cancel [OF int_group] text {* Automatic instantiation *} lemma bla: True proof - from int_group instantiate my: group thm my.assoc my.l_cancel oops end