# HG changeset patch # User haftmann # Date 1196860575 -3600 # Node ID 6b2031004d3ffc0bb3cae520605dea1ebb44754b # Parent ced4104f6c1ff844cd9b46a051b1913291410e99 dropped Classpackage.thy diff -r ced4104f6c1f -r 6b2031004d3f src/HOL/IsaMakefile --- a/src/HOL/IsaMakefile Wed Dec 05 14:16:14 2007 +0100 +++ b/src/HOL/IsaMakefile Wed Dec 05 14:16:15 2007 +0100 @@ -668,7 +668,7 @@ $(LOG)/HOL-ex.gz: $(OUT)/HOL Library/Commutative_Ring.thy \ ex/Abstract_NAT.thy ex/Antiquote.thy ex/Arith_Examples.thy \ ex/BT.thy ex/BinEx.thy ex/CTL.thy \ - ex/Chinese.thy ex/Classical.thy ex/Classpackage.thy ex/Dense_Linear_Order_Ex.thy \ + ex/Chinese.thy ex/Classical.thy ex/Dense_Linear_Order_Ex.thy \ ex/Eval_Examples.thy ex/Groebner_Examples.thy ex/Random.thy \ ex/Codegenerator.thy ex/Codegenerator_Pretty.thy \ ex/Commutative_RingEx.thy ex/Hex_Bin_Examples.thy \ diff -r ced4104f6c1f -r 6b2031004d3f src/HOL/ex/Classpackage.thy --- a/src/HOL/ex/Classpackage.thy Wed Dec 05 14:16:14 2007 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,321 +0,0 @@ -(* ID: $Id$ - Author: Florian Haftmann, TU Muenchen -*) - -header {* Test and examples for Isar class package *} - -theory Classpackage -imports List -begin - -class semigroup = type + - fixes mult :: "'a \ 'a \ 'a" (infixl "\" 70) - assumes assoc: "x \ y \ z = x \ (y \ z)" - -instance nat :: semigroup - "m \ n \ (m\nat) + n" -proof - fix m n q :: nat - from mult_nat_def show "m \ n \ q = m \ (n \ q)" by simp -qed - -instance int :: semigroup - "k \ l \ (k\int) + l" -proof - fix k l j :: int - from mult_int_def show "k \ l \ j = k \ (l \ j)" by simp -qed - -instance * :: (semigroup, semigroup) semigroup - mult_prod_def: "x \ y \ let (x1, x2) = x; (y1, y2) = y in - (x1 \ y1, x2 \ y2)" -by default (simp_all add: split_paired_all mult_prod_def assoc) - -instance list :: (type) semigroup - "xs \ ys \ xs @ ys" -proof - fix xs ys zs :: "'a list" - show "xs \ ys \ zs = xs \ (ys \ zs)" - proof - - from mult_list_def have "\xs ys\'a list. xs \ ys \ xs @ ys" . - thus ?thesis by simp - qed -qed - -class monoidl = semigroup + - fixes one :: 'a ("\") - assumes neutl: "\ \ x = x" - -instance nat :: monoidl and int :: monoidl - "\ \ (0\nat)" - "\ \ (0\int)" -proof - fix n :: nat - from mult_nat_def one_nat_def show "\ \ n = n" by simp -next - fix k :: int - from mult_int_def one_int_def show "\ \ k = k" by simp -qed - -instance * :: (monoidl, monoidl) monoidl - one_prod_def: "\ \ (\, \)" -by default (simp_all add: split_paired_all mult_prod_def one_prod_def neutl) - -instance list :: (type) monoidl - "\ \ []" -proof - fix xs :: "'a list" - show "\ \ xs = xs" - proof - - from mult_list_def have "\xs ys\'a list. xs \ ys \ xs @ ys" . - moreover from one_list_def have "\ \ []\'a list" by simp - ultimately show ?thesis by simp - qed -qed - -class monoid = monoidl + - assumes neutr: "x \ \ = x" -begin - -definition - units :: "'a set" where - "units = {y. \x. x \ y = \ \ y \ x = \}" - -lemma inv_obtain: - assumes "x \ units" - obtains y where "y \ x = \" and "x \ y = \" -proof - - from assms units_def obtain y - where "y \ x = \" and "x \ y = \" by auto - thus ?thesis .. -qed - -lemma inv_unique: - assumes "y \ x = \" "x \ y' = \" - shows "y = y'" -proof - - from assms neutr have "y = y \ (x \ y')" by simp - also with assoc have "... = (y \ x) \ y'" by simp - also with assms neutl have "... = y'" by simp - finally show ?thesis . -qed - -lemma units_inv_comm: - assumes inv: "x \ y = \" - and G: "x \ units" - shows "y \ x = \" -proof - - from G inv_obtain obtain z - where z_choice: "z \ x = \" by blast - from inv neutl neutr have "x \ y \ x = x \ \" by simp - with assoc have "z \ x \ y \ x = z \ x \ \" by simp - with neutl z_choice show ?thesis by simp -qed - -fun - npow :: "nat \ 'a \ 'a" -where - "npow 0 x = \" - | "npow (Suc n) x = x \ npow n x" - -abbreviation - npow_syn :: "'a \ nat \ 'a" (infix "\" 75) where - "x \ n \ npow n x" - -lemma nat_pow_one: - "\ \ n = \" -using neutl by (induct n) simp_all - -lemma nat_pow_mult: "x \ n \ x \ m = x \ (n + m)" -proof (induct n) - case 0 with neutl show ?case by simp -next - case (Suc n) with Suc.hyps assoc show ?case by simp -qed - -lemma nat_pow_pow: "(x \ m) \ n = x \ (n * m)" -using nat_pow_mult by (induct n) simp_all - -end - -instance * :: (monoid, monoid) monoid -by default (simp_all add: split_paired_all mult_prod_def one_prod_def neutr) - -instance list :: (type) monoid -proof - fix xs :: "'a list" - show "xs \ \ = xs" - proof - - from mult_list_def have "\xs ys\'a list. xs \ ys \ xs @ ys" . - moreover from one_list_def have "\ \ []\'a list" by simp - ultimately show ?thesis by simp - qed -qed - -class monoid_comm = monoid + - assumes comm: "x \ y = y \ x" - -instance nat :: monoid_comm and int :: monoid_comm -proof - fix n :: nat - from mult_nat_def one_nat_def show "n \ \ = n" by simp -next - fix n m :: nat - from mult_nat_def show "n \ m = m \ n" by simp -next - fix k :: int - from mult_int_def one_int_def show "k \ \ = k" by simp -next - fix k l :: int - from mult_int_def show "k \ l = l \ k" by simp -qed - -instance * :: (monoid_comm, monoid_comm) monoid_comm -by default (simp_all add: split_paired_all mult_prod_def comm) - -class group = monoidl + - fixes inv :: "'a \ 'a" ("\
_" [81] 80) - assumes invl: "\
x \ x = \" -begin - -lemma cancel: - "(x \ y = x \ z) = (y = z)" -proof - fix x y z :: 'a - assume eq: "x \ y = x \ z" - hence "\
x \ (x \ y) = \
x \ (x \ z)" by simp - with assoc have "\
x \ x \ y = \
x \ x \ z" by simp - with neutl invl show "y = z" by simp -next - fix x y z :: 'a - assume eq: "y = z" - thus "x \ y = x \ z" by simp -qed - -subclass monoid -proof unfold_locales - fix x - from invl have "\
x \ x = \" by simp - with assoc [symmetric] neutl invl have "\
x \ (x \ \) = \
x \ x" by simp - with cancel show "x \ \ = x" by simp -qed - -end context group begin - -find_theorems name: neut - -lemma invr: - "x \ \
x = \" -proof - - from neutl invl have "\
x \ x \ \
x = \
x" by simp - with neutr have "\
x \ x \ \
x = \
x \ \ " by simp - with assoc have "\
x \ (x \ \
x) = \
x \ \ " by simp - with cancel show ?thesis .. -qed - -lemma all_inv [intro]: - "(x\'a) \ units" - unfolding units_def -proof - - fix x :: "'a" - from invl invr have "\
x \ x = \" and "x \ \
x = \" . - then obtain y where "y \ x = \" and "x \ y = \" .. - hence "\y\'a. y \ x = \ \ x \ y = \" by blast - thus "x \ {y\'a. \x\'a. x \ y = \ \ y \ x = \}" by simp -qed - -lemma cancer: - "(y \ x = z \ x) = (y = z)" -proof - assume eq: "y \ x = z \ x" - with assoc [symmetric] have "y \ (x \ \
x) = z \ (x \ \
x)" by (simp del: invr) - with invr neutr show "y = z" by simp -next - assume eq: "y = z" - thus "y \ x = z \ x" by simp -qed - -lemma inv_one: - "\
\ = \" -proof - - from neutl have "\
\ = \ \ (\
\)" .. - moreover from invr have "... = \" by simp - finally show ?thesis . -qed - -lemma inv_inv: - "\
(\
x) = x" -proof - - from invl invr neutr - have "\
(\
x) \ \
x \ x = x \ \
x \ x" by simp - with assoc [symmetric] - have "\
(\
x) \ (\
x \ x) = x \ (\
x \ x)" by simp - with invl neutr show ?thesis by simp -qed - -lemma inv_mult_group: - "\
(x \ y) = \
y \ \
x" -proof - - from invl have "\
(x \ y) \ (x \ y) = \" by simp - with assoc have "\
(x \ y) \ x \ y = \" by simp - with neutl have "\
(x \ y) \ x \ y \ \
y \ \
x = \
y \ \
x" by simp - with assoc have "\
(x \ y) \ (x \ (y \ \
y) \ \
x) = \
y \ \
x" by simp - with invr neutr show ?thesis by simp -qed - -lemma inv_comm: - "x \ \
x = \
x \ x" -using invr invl by simp - -definition - pow :: "int \ 'a \ 'a" -where - "pow k x = (if k < 0 then \
(npow (nat (-k)) x) - else (npow (nat k) x))" - -abbreviation - pow_syn :: "'a \ int \ 'a" (infix "\\" 75) -where - "x \\ k \ pow k x" - -lemma int_pow_zero: - "x \\ (0\int) = \" -using pow_def by simp - -lemma int_pow_one: - "\ \\ (k\int) = \" -using pow_def nat_pow_one inv_one by simp - -end - -instance * :: (group, group) group - inv_prod_def: "\
x \ let (x1, x2) = x in (\
x1, \
x2)" -by default (simp_all add: split_paired_all mult_prod_def one_prod_def inv_prod_def invl) - -class group_comm = group + monoid_comm - -instance int :: group_comm - "\
k \ - (k\int)" -proof - fix k :: int - from mult_int_def one_int_def inv_int_def show "\
k \ k = \" by simp -qed - -instance * :: (group_comm, group_comm) group_comm -by default (simp_all add: split_paired_all mult_prod_def comm) - -definition - "X a b c = (a \ \ \ b, a \ \ \ b, npow 3 [a, b] \ \ \ [a, b, c])" - -definition - "Y a b c = (a, \
a) \ \ \ \
(b, \
pow (-3) c)" - -definition "x1 = X (1::nat) 2 3" -definition "x2 = X (1::int) 2 3" -definition "y2 = Y (1::int) 2 3" - -export_code x1 x2 y2 pow in SML module_name Classpackage - in OCaml file - - in Haskell file - - -end diff -r ced4104f6c1f -r 6b2031004d3f src/HOL/ex/ROOT.ML --- a/src/HOL/ex/ROOT.ML Wed Dec 05 14:16:14 2007 +0100 +++ b/src/HOL/ex/ROOT.ML Wed Dec 05 14:16:15 2007 +0100 @@ -7,7 +7,6 @@ no_document use_thys [ "Parity", "GCD", - "Classpackage", "Eval", "State_Monad", "Code_Integer",