diff -r 9fa7d3890488 -r ba9297b71897 doc-src/AxClass/Group/Group.thy --- a/doc-src/AxClass/Group/Group.thy Tue Oct 03 18:45:36 2000 +0200 +++ b/doc-src/AxClass/Group/Group.thy Tue Oct 03 18:55:23 2000 +0200 @@ -4,7 +4,7 @@ theory Group = Main: text {* - \medskip\noindent The meta-type system of Isabelle supports + \medskip\noindent The meta-level type system of Isabelle supports \emph{intersections} and \emph{inclusions} of type classes. These directly correspond to intersections and inclusions of type predicates in a purely set theoretic sense. This is sufficient as a @@ -21,56 +21,53 @@ *} consts - times :: "'a => 'a => 'a" (infixl "\" 70) - inverse :: "'a => 'a" ("(_\)" [1000] 999) - one :: 'a ("\") + times :: "'a \ 'a \ 'a" (infixl "\" 70) + inverse :: "'a \ 'a" ("(_\)" [1000] 999) + one :: 'a ("\") text {* - \noindent Next we define class $monoid$ of monoids with operations - $\TIMES$ and $1$. Note that multiple class axioms are allowed for - user convenience --- they simply represent the conjunction of their - respective universal closures. + \noindent Next we define class @{text monoid} of monoids with + operations @{text \} and @{text \}. Note that multiple class + axioms are allowed for user convenience --- they simply represent the + conjunction of their respective universal closures. *} -axclass - monoid < "term" - assoc: "(x \ y) \ z = x \ (y \ z)" - left_unit: "\ \ x = x" - right_unit: "x \ \ = x" +axclass monoid < "term" + assoc: "(x \ y) \ z = x \ (y \ z)" + left_unit: "\ \ x = x" + right_unit: "x \ \ = x" text {* - \noindent So class $monoid$ contains exactly those types $\tau$ where - $\TIMES :: \tau \To \tau \To \tau$ and $1 :: \tau$ are specified - appropriately, such that $\TIMES$ is associative and $1$ is a left - and right unit element for the $\TIMES$ operation. + \noindent So class @{text monoid} contains exactly those types @{text + \} where @{text "\ \ \ \ \ \ \"} and @{text "\ \ \"} are + specified appropriately, such that @{text \} is associative and + @{text \} is a left and right unit element for the @{text \} + operation. *} text {* - \medskip Independently of $monoid$, we now define a linear hierarchy - of semigroups, general groups and Abelian groups. Note that the - names of class axioms are automatically qualified with each class - name, so we may re-use common names such as $assoc$. + \medskip Independently of @{text monoid}, we now define a linear + hierarchy of semigroups, general groups and Abelian groups. Note + that the names of class axioms are automatically qualified with each + class name, so we may re-use common names such as @{text assoc}. *} -axclass - semigroup < "term" - assoc: "(x \ y) \ z = x \ (y \ z)" +axclass semigroup < "term" + assoc: "(x \ y) \ z = x \ (y \ z)" -axclass - group < semigroup - left_unit: "\ \ x = x" - left_inverse: "x\ \ x = \" +axclass group < semigroup + left_unit: "\ \ x = x" + left_inverse: "x\ \ x = \" -axclass - agroup < group - commute: "x \ y = y \ x" +axclass agroup < group + commute: "x \ y = y \ x" text {* - \noindent Class $group$ inherits associativity of $\TIMES$ from - $semigroup$ and adds two further group axioms. Similarly, $agroup$ - is defined as the subset of $group$ such that for all of its elements - $\tau$, the operation $\TIMES :: \tau \To \tau \To \tau$ is even - commutative. + \noindent Class @{text group} inherits associativity of @{text \} + from @{text semigroup} and adds two further group axioms. Similarly, + @{text agroup} is defined as the subset of @{text group} such that + for all of its elements @{text \}, the operation @{text "\ \ \ \ \ \ \"} + is even commutative. *} @@ -79,13 +76,13 @@ text {* In a sense, axiomatic type classes may be viewed as \emph{abstract theories}. Above class definitions gives rise to abstract axioms - $assoc$, $left_unit$, $left_inverse$, $commute$, where any of these - contain a type variable $\alpha :: c$ that is restricted to types of - the corresponding class $c$. \emph{Sort constraints} like this - express a logical precondition for the whole formula. For example, - $assoc$ states that for all $\tau$, provided that $\tau :: - semigroup$, the operation $\TIMES :: \tau \To \tau \To \tau$ is - associative. + @{text assoc}, @{text left_unit}, @{text left_inverse}, @{text + commute}, where any of these contain a type variable @{text "'a \ c"} + that is restricted to types of the corresponding class @{text c}. + \emph{Sort constraints} like this express a logical precondition for + the whole formula. For example, @{text assoc} states that for all + @{text \}, provided that @{text "\ \ semigroup"}, the operation + @{text "\ \ \ \ \ \ \"} is associative. \medskip From a technical point of view, abstract axioms are just ordinary Isabelle theorems, which may be used in proofs without @@ -94,21 +91,21 @@ well-known laws of general groups. *} -theorem group_right_inverse: "x \ x\ = (\\\'a\\group)" +theorem group_right_inverse: "x \ x\ = (\\'a\group)" proof - - have "x \ x\ = \ \ (x \ x\)" + have "x \ x\ = \ \ (x \ x\)" by (simp only: group.left_unit) - also have "... = \ \ x \ x\" + also have "... = \ \ x \ x\" by (simp only: semigroup.assoc) - also have "... = (x\)\ \ x\ \ x \ x\" + also have "... = (x\)\ \ x\ \ x \ x\" by (simp only: group.left_inverse) - also have "... = (x\)\ \ (x\ \ x) \ x\" + also have "... = (x\)\ \ (x\ \ x) \ x\" by (simp only: semigroup.assoc) - also have "... = (x\)\ \ \ \ x\" + also have "... = (x\)\ \ \ \ x\" by (simp only: group.left_inverse) - also have "... = (x\)\ \ (\ \ x\)" + also have "... = (x\)\ \ (\ \ x\)" by (simp only: semigroup.assoc) - also have "... = (x\)\ \ x\" + also have "... = (x\)\ \ x\" by (simp only: group.left_unit) also have "... = \" by (simp only: group.left_inverse) @@ -116,18 +113,18 @@ qed text {* - \noindent With $group_right_inverse$ already available, - $group_right_unit$\label{thm:group-right-unit} is now established - much easier. + \noindent With @{text group_right_inverse} already available, @{text + group_right_unit}\label{thm:group-right-unit} is now established much + easier. *} -theorem group_right_unit: "x \ \ = (x\\'a\\group)" +theorem group_right_unit: "x \ \ = (x\'a\group)" proof - - have "x \ \ = x \ (x\ \ x)" + have "x \ \ = x \ (x\ \ x)" by (simp only: group.left_inverse) - also have "... = x \ x\ \ x" + also have "... = x \ x\ \ x" by (simp only: semigroup.assoc) - also have "... = \ \ x" + also have "... = \ \ x" by (simp only: group_right_inverse) also have "... = x" by (simp only: group.left_unit) @@ -136,24 +133,25 @@ text {* \medskip Abstract theorems may be instantiated to only those types - $\tau$ where the appropriate class membership $\tau :: c$ is known at - Isabelle's type signature level. Since we have $agroup \subseteq - group \subseteq semigroup$ by definition, all theorems of $semigroup$ - and $group$ are automatically inherited by $group$ and $agroup$. + @{text \} where the appropriate class membership @{text "\ \ c"} is + known at Isabelle's type signature level. Since we have @{text + "agroup \ group \ semigroup"} by definition, all theorems of @{text + semigroup} and @{text group} are automatically inherited by @{text + group} and @{text agroup}. *} subsection {* Abstract instantiation *} text {* - From the definition, the $monoid$ and $group$ classes have been - independent. Note that for monoids, $right_unit$ had to be included - as an axiom, but for groups both $right_unit$ and $right_inverse$ are - derivable from the other axioms. With $group_right_unit$ derived as - a theorem of group theory (see page~\pageref{thm:group-right-unit}), - we may now instantiate $monoid \subseteq semigroup$ and $group - \subseteq monoid$ properly as follows - (cf.\ \figref{fig:monoid-group}). + From the definition, the @{text monoid} and @{text group} classes + have been independent. Note that for monoids, @{text right_unit} had + to be included as an axiom, but for groups both @{text right_unit} + and @{text right_inverse} are derivable from the other axioms. With + @{text group_right_unit} derived as a theorem of group theory (see + page~\pageref{thm:group-right-unit}), we may now instantiate @{text + "monoid \ semigroup"} and @{text "group \ monoid"} properly as + follows (cf.\ \figref{fig:monoid-group}). \begin{figure}[htbp] \begin{center} @@ -162,20 +160,20 @@ \begin{picture}(65,90)(0,-10) \put(15,10){\line(0,1){10}} \put(15,30){\line(0,1){10}} \put(15,50){\line(1,1){10}} \put(35,60){\line(1,-1){10}} - \put(15,5){\makebox(0,0){$agroup$}} - \put(15,25){\makebox(0,0){$group$}} - \put(15,45){\makebox(0,0){$semigroup$}} - \put(30,65){\makebox(0,0){$term$}} \put(50,45){\makebox(0,0){$monoid$}} + \put(15,5){\makebox(0,0){@{text agroup}}} + \put(15,25){\makebox(0,0){@{text group}}} + \put(15,45){\makebox(0,0){@{text semigroup}}} + \put(30,65){\makebox(0,0){@{text "term"}}} \put(50,45){\makebox(0,0){@{text monoid}}} \end{picture} \hspace{4em} \begin{picture}(30,90)(0,0) \put(15,10){\line(0,1){10}} \put(15,30){\line(0,1){10}} \put(15,50){\line(0,1){10}} \put(15,70){\line(0,1){10}} - \put(15,5){\makebox(0,0){$agroup$}} - \put(15,25){\makebox(0,0){$group$}} - \put(15,45){\makebox(0,0){$monoid$}} - \put(15,65){\makebox(0,0){$semigroup$}} - \put(15,85){\makebox(0,0){$term$}} + \put(15,5){\makebox(0,0){@{text agroup}}} + \put(15,25){\makebox(0,0){@{text group}}} + \put(15,45){\makebox(0,0){@{text monoid}}} + \put(15,65){\makebox(0,0){@{text semigroup}}} + \put(15,85){\makebox(0,0){@{text term}}} \end{picture} \caption{Monoids and groups: according to definition, and by proof} \label{fig:monoid-group} @@ -185,30 +183,30 @@ instance monoid < semigroup proof intro_classes - fix x y z :: "'a\\monoid" - show "x \ y \ z = x \ (y \ z)" + fix x y z :: "'a\monoid" + show "x \ y \ z = x \ (y \ z)" by (rule monoid.assoc) qed instance group < monoid proof intro_classes - fix x y z :: "'a\\group" - show "x \ y \ z = x \ (y \ z)" + fix x y z :: "'a\group" + show "x \ y \ z = x \ (y \ z)" by (rule semigroup.assoc) - show "\ \ x = x" + show "\ \ x = x" by (rule group.left_unit) - show "x \ \ = x" + show "x \ \ = x" by (rule group_right_unit) qed text {* \medskip The $\isakeyword{instance}$ command sets up an appropriate goal that represents the class inclusion (or type arity, see - \secref{sec:inst-arity}) to be proven - (see also \cite{isabelle-isar-ref}). The $intro_classes$ proof - method does back-chaining of class membership statements wrt.\ the - hierarchy of any classes defined in the current theory; the effect is - to reduce to the initial statement to a number of goals that directly + \secref{sec:inst-arity}) to be proven (see also + \cite{isabelle-isar-ref}). The @{text intro_classes} proof method + does back-chaining of class membership statements wrt.\ the hierarchy + of any classes defined in the current theory; the effect is to reduce + to the initial statement to a number of goals that directly correspond to any class axioms encountered on the path upwards through the class hierarchy. *} @@ -226,15 +224,15 @@ class membership may be established at the logical level and then transferred to Isabelle's type signature level. - \medskip As a typical example, we show that type $bool$ with - exclusive-or as $\TIMES$ operation, identity as $\isasyminv$, and - $False$ as $1$ forms an Abelian group. + \medskip As a typical example, we show that type @{typ bool} with + exclusive-or as @{text \} operation, identity as @{text \}, and + @{term False} as @{text \} forms an Abelian group. *} defs (overloaded) - times_bool_def: "x \ y \\ x \\ (y\\bool)" - inverse_bool_def: "x\ \\ x\\bool" - unit_bool_def: "\ \\ False" + times_bool_def: "x \ y \ x \ (y\bool)" + inverse_bool_def: "x\ \ x\bool" + unit_bool_def: "\ \ False" text {* \medskip It is important to note that above $\DEFS$ are just @@ -247,18 +245,18 @@ best applied in the context of type classes. \medskip Since we have chosen above $\DEFS$ of the generic group - operations on type $bool$ appropriately, the class membership $bool - :: agroup$ may be now derived as follows. + operations on type @{typ bool} appropriately, the class membership + @{text "bool \ agroup"} may be now derived as follows. *} instance bool :: agroup proof (intro_classes, unfold times_bool_def inverse_bool_def unit_bool_def) fix x y z - show "((x \\ y) \\ z) = (x \\ (y \\ z))" by blast - show "(False \\ x) = x" by blast - show "(x \\ x) = False" by blast - show "(x \\ y) = (y \\ x)" by blast + show "((x \ y) \ z) = (x \ (y \ z))" by blast + show "(False \ x) = x" by blast + show "(x \ x) = False" by blast + show "(x \ y) = (y \ x)" by blast qed text {* @@ -268,12 +266,13 @@ care of this new instance automatically. \medskip We could now also instantiate our group theory classes to - many other concrete types. For example, $int :: agroup$ (e.g.\ by - defining $\TIMES$ as addition, $\isasyminv$ as negation and $1$ as - zero) or $list :: (term)semigroup$ (e.g.\ if $\TIMES$ is defined as - list append). Thus, the characteristic constants $\TIMES$, - $\isasyminv$, $1$ really become overloaded, i.e.\ have different - meanings on different types. + many other concrete types. For example, @{text "int \ agroup"} + (e.g.\ by defining @{text \} as addition, @{text \} as negation + and @{text \} as zero) or @{text "list \ (term) semigroup"} + (e.g.\ if @{text \} is defined as list append). Thus, the + characteristic constants @{text \}, @{text \}, @{text \} + really become overloaded, i.e.\ have different meanings on different + types. *} @@ -288,27 +287,27 @@ This feature enables us to \emph{lift operations}, say to Cartesian products, direct sums or function spaces. Subsequently we lift - $\TIMES$ component-wise to binary products $\alpha \times \beta$. + @{text \} component-wise to binary products @{typ "'a \ 'b"}. *} defs (overloaded) - times_prod_def: "p \ q \\ (fst p \ fst q, snd p \ snd q)" + times_prod_def: "p \ q \ (fst p \ fst q, snd p \ snd q)" text {* - It is very easy to see that associativity of $\TIMES^\alpha$ and - $\TIMES^\beta$ transfers to ${\TIMES}^{\alpha \times \beta}$. Hence - the binary type constructor $\times$ maps semigroups to semigroups. - This may be established formally as follows. + It is very easy to see that associativity of @{text \} on @{typ 'a} + and @{text \} on @{typ 'b} transfers to @{text \} on @{typ "'a \ 'b"}. + Hence the binary type constructor @{text \} maps semigroups to + semigroups. This may be established formally as follows. *} instance * :: (semigroup, semigroup) semigroup proof (intro_classes, unfold times_prod_def) - fix p q r :: "'a\\semigroup \\ 'b\\semigroup" + fix p q r :: "'a\semigroup \ 'b\semigroup" show - "(fst (fst p \ fst q, snd p \ snd q) \ fst r, - snd (fst p \ fst q, snd p \ snd q) \ snd r) = - (fst p \ fst (fst q \ fst r, snd q \ snd r), - snd p \ snd (fst q \ fst r, snd q \ snd r))" + "(fst (fst p \ fst q, snd p \ snd q) \ fst r, + snd (fst p \ fst q, snd p \ snd q) \ snd r) = + (fst p \ fst (fst q \ fst r, snd q \ snd r), + snd p \ snd (fst q \ fst r, snd q \ snd r))" by (simp add: semigroup.assoc) qed