diff -r 3032bc7d613d -r d052d61da398 src/Doc/Classes/Classes.thy --- a/src/Doc/Classes/Classes.thy Tue Sep 12 13:54:48 2023 +0100 +++ b/src/Doc/Classes/Classes.thy Wed Sep 13 17:08:54 2023 +0000 @@ -101,8 +101,8 @@ \ class %quote semigroup = - fixes mult :: "\ \ \ \ \" (infixl "\" 70) - assumes assoc: "(x \ y) \ z = x \ (y \ z)" + fixes mult :: \\ \ \ \ \\ (infixl \\\ 70) + assumes assoc: \(x \ y) \ z = x \ (y \ z)\ text \ \<^noindent> This @{command class} specification consists of two parts: @@ -110,9 +110,9 @@ "fixes"}), the \qn{logical} part specifies properties on them (@{element "assumes"}). The local @{element "fixes"} and @{element "assumes"} are lifted to the theory toplevel, yielding the global - parameter @{term [source] "mult :: \::semigroup \ \ \ \"} and the - global theorem @{fact "semigroup.assoc:"}~@{prop [source] "\x y z :: - \::semigroup. (x \ y) \ z = x \ (y \ z)"}. + parameter @{term [source] \mult :: \::semigroup \ \ \ \\} and the + global theorem @{fact "semigroup.assoc:"}~@{prop [source] \\x y z :: + \::semigroup. (x \ y) \ z = x \ (y \ z)\}. \ @@ -128,11 +128,11 @@ begin definition %quote - mult_int_def: "i \ j = i + (j::int)" + mult_int_def: \i \ j = i + (j::int)\ instance %quote proof - fix i j k :: int have "(i + j) + k = i + (j + k)" by simp - then show "(i \ j) \ k = i \ (j \ k)" + fix i j k :: int have \(i + j) + k = i + (j + k)\ by simp + then show \(i \ j) \ k = i \ (j \ k)\ unfolding mult_int_def . qed @@ -160,12 +160,12 @@ begin primrec %quote mult_nat where - "(0::nat) \ n = n" - | "Suc m \ n = Suc (m \ n)" + \(0::nat) \ n = n\ + | \Suc m \ n = Suc (m \ n)\ instance %quote proof fix m n q :: nat - show "m \ n \ q = m \ (n \ q)" + show \m \ n \ q = m \ (n \ q)\ by (induct m) auto qed @@ -191,11 +191,11 @@ begin definition %quote - mult_prod_def: "p\<^sub>1 \ p\<^sub>2 = (fst p\<^sub>1 \ fst p\<^sub>2, snd p\<^sub>1 \ snd p\<^sub>2)" + mult_prod_def: \p\<^sub>1 \ p\<^sub>2 = (fst p\<^sub>1 \ fst p\<^sub>2, snd p\<^sub>1 \ snd p\<^sub>2)\ instance %quote proof - fix p\<^sub>1 p\<^sub>2 p\<^sub>3 :: "\::semigroup \ \::semigroup" - show "p\<^sub>1 \ p\<^sub>2 \ p\<^sub>3 = p\<^sub>1 \ (p\<^sub>2 \ p\<^sub>3)" + fix p\<^sub>1 p\<^sub>2 p\<^sub>3 :: \\::semigroup \ \::semigroup\ + show \p\<^sub>1 \ p\<^sub>2 \ p\<^sub>3 = p\<^sub>1 \ (p\<^sub>2 \ p\<^sub>3)\ unfolding mult_prod_def by (simp add: assoc) qed @@ -220,8 +220,8 @@ \ class %quote monoidl = semigroup + - fixes neutral :: "\" ("\") - assumes neutl: "\ \ x = x" + fixes neutral :: \\\ (\\\) + assumes neutl: \\ \ x = x\ text \ \<^noindent> Again, we prove some instances, by providing suitable @@ -234,18 +234,18 @@ begin definition %quote - neutral_nat_def: "\ = (0::nat)" + neutral_nat_def: \\ = (0::nat)\ definition %quote - neutral_int_def: "\ = (0::int)" + neutral_int_def: \\ = (0::int)\ instance %quote proof fix n :: nat - show "\ \ n = n" + show \\ \ n = n\ unfolding neutral_nat_def by simp next fix k :: int - show "\ \ k = k" + show \\ \ k = k\ unfolding neutral_int_def mult_int_def by simp qed @@ -255,11 +255,11 @@ begin definition %quote - neutral_prod_def: "\ = (\, \)" + neutral_prod_def: \\ = (\, \)\ instance %quote proof - fix p :: "\::monoidl \ \::monoidl" - show "\ \ p = p" + fix p :: \\::monoidl \ \::monoidl\ + show \\ \ p = p\ unfolding neutral_prod_def mult_prod_def by (simp add: neutl) qed @@ -271,18 +271,18 @@ \ class %quote monoid = monoidl + - assumes neutr: "x \ \ = x" + assumes neutr: \x \ \ = x\ instantiation %quote nat and int :: monoid begin instance %quote proof fix n :: nat - show "n \ \ = n" + show \n \ \ = n\ unfolding neutral_nat_def by (induct n) simp_all next fix k :: int - show "k \ \ = k" + show \k \ \ = k\ unfolding neutral_int_def mult_int_def by simp qed @@ -292,8 +292,8 @@ begin instance %quote proof - fix p :: "\::monoid \ \::monoid" - show "p \ \ = p" + fix p :: \\::monoid \ \::monoid\ + show \p \ \ = p\ unfolding neutral_prod_def mult_prod_def by (simp add: neutr) qed @@ -304,19 +304,19 @@ \ class %quote group = monoidl + - fixes inverse :: "\ \ \" ("(_\
)" [1000] 999) - assumes invl: "x\
\ x = \" + fixes inverse :: \\ \ \\ (\(_\
)\ [1000] 999) + assumes invl: \x\
\ x = \\ instantiation %quote int :: group begin definition %quote - inverse_int_def: "i\
= - (i::int)" + inverse_int_def: \i\
= - (i::int)\ instance %quote proof fix i :: int - have "-i + i = 0" by simp - then show "i\
\ i = \" + have \-i + i = 0\ by simp + then show \i\
\ i = \\ unfolding mult_int_def neutral_int_def inverse_int_def . qed @@ -335,20 +335,20 @@ \ class %quote idem = - fixes f :: "\ \ \" - assumes idem: "f (f x) = f x" + fixes f :: \\ \ \\ + assumes idem: \f (f x) = f x\ text \ \<^noindent> essentially introduces the locale \ (*<*)setup %invisible \Sign.add_path "foo"\ (*>*) locale %quote idem = - fixes f :: "\ \ \" - assumes idem: "f (f x) = f x" + fixes f :: \\ \ \\ + assumes idem: \f (f x) = f x\ text \\<^noindent> together with corresponding constant(s):\ -consts %quote f :: "\ \ \" +consts %quote f :: \\ \ \\ text \ \<^noindent> The connection to the type system is done by means of a @@ -357,7 +357,7 @@ \ interpretation %quote idem_class: - idem "f :: (\::idem) \ \" + idem \f :: (\::idem) \ \\ (*<*)sorry(*>*) text \ @@ -375,26 +375,26 @@ states that the function \(x \)\ is injective: \ -lemma %quote (in group) left_cancel: "x \ y = x \ z \ y = z" +lemma %quote (in group) left_cancel: \x \ y = x \ z \ y = z\ proof - assume "x \ y = x \ z" - then have "x\
\ (x \ y) = x\
\ (x \ z)" by simp - then have "(x\
\ x) \ y = (x\
\ x) \ z" using assoc by simp - then show "y = z" using neutl and invl by simp + assume \x \ y = x \ z\ + then have \x\
\ (x \ y) = x\
\ (x \ z)\ by simp + then have \(x\
\ x) \ y = (x\
\ x) \ z\ using assoc by simp + then show \y = z\ using neutl and invl by simp next - assume "y = z" - then show "x \ y = x \ z" by simp + assume \y = z\ + then show \x \ y = x \ z\ by simp qed text \ \<^noindent> Here the \qt{@{keyword "in"} \<^class>\group\} target specification indicates that the result is recorded within that context for later use. This local theorem is also lifted to the - global one @{fact "group.left_cancel:"} @{prop [source] "\x y z :: - \::group. x \ y = x \ z \ y = z"}. Since type \int\ has been + global one @{fact "group.left_cancel:"} @{prop [source] \\x y z :: + \::group. x \ y = x \ z \ y = z\}. Since type \int\ has been made an instance of \group\ before, we may refer to that - fact as well: @{prop [source] "\x y z :: int. x \ y = x \ z \ y = - z"}. + fact as well: @{prop [source] \\x y z :: int. x \ y = x \ z \ y = + z\}. \ @@ -404,14 +404,14 @@ Isabelle locales are targets which support local definitions: \ -primrec %quote (in monoid) pow_nat :: "nat \ \ \ \" where - "pow_nat 0 x = \" - | "pow_nat (Suc n) x = x \ pow_nat n x" +primrec %quote (in monoid) pow_nat :: \nat \ \ \ \\ where + \pow_nat 0 x = \\ + | \pow_nat (Suc n) x = x \ pow_nat n x\ text \ \<^noindent> If the locale \group\ is also a class, this local definition is propagated onto a global definition of @{term [source] - "pow_nat :: nat \ \::monoid \ \::monoid"} with corresponding theorems + \pow_nat :: nat \ \::monoid \ \::monoid\} with corresponding theorems @{thm pow_nat.simps [no_vars]}. @@ -438,7 +438,7 @@ for lists: \ -interpretation %quote list_monoid: monoid append "[]" +interpretation %quote list_monoid: monoid append \[]\ proof qed auto text \ @@ -449,18 +449,18 @@ be appropriate to map derived definitions accordingly: \ -primrec %quote replicate :: "nat \ \ list \ \ list" where - "replicate 0 _ = []" - | "replicate (Suc n) xs = xs @ replicate n xs" +primrec %quote replicate :: \nat \ \ list \ \ list\ where + \replicate 0 _ = []\ + | \replicate (Suc n) xs = xs @ replicate n xs\ -interpretation %quote list_monoid: monoid append "[]" rewrites - "monoid.pow_nat append [] = replicate" +interpretation %quote list_monoid: monoid append \[]\ rewrites + \monoid.pow_nat append [] = replicate\ proof - - interpret monoid append "[]" .. - show "monoid.pow_nat append [] = replicate" + interpret monoid append \[]\ .. + show \monoid.pow_nat append [] = replicate\ proof fix n - show "monoid.pow_nat append [] n = replicate n" + show \monoid.pow_nat append [] n = replicate n\ by (induct n) auto qed qed intro_locales @@ -486,9 +486,9 @@ subclass %quote (in group) monoid proof fix x - from invl have "x\
\ x = \" by simp - with assoc [symmetric] neutl invl have "x\
\ (x \ \) = x\
\ x" by simp - with left_cancel show "x \ \ = x" by simp + from invl have \x\
\ x = \\ by simp + with assoc [symmetric] neutl invl have \x\
\ (x \ \) = x\
\ x\ by simp + with left_cancel show \x \ \ = x\ by simp qed text \ @@ -530,14 +530,14 @@ For illustration, a derived definition in \group\ using \pow_nat\ \ -definition %quote (in group) pow_int :: "int \ \ \ \" where - "pow_int k x = (if k >= 0 +definition %quote (in group) pow_int :: \int \ \ \ \\ where + \pow_int k x = (if k \ 0 then pow_nat (nat k) x - else (pow_nat (nat (- k)) x)\
)" + else (pow_nat (nat (- k)) x)\
)\ text \ - \<^noindent> yields the global definition of @{term [source] "pow_int :: - int \ \::group \ \::group"} with the corresponding theorem @{thm + \<^noindent> yields the global definition of @{term [source] \pow_int :: + int \ \::group \ \::group\} with the corresponding theorem @{thm pow_int_def [no_vars]}. \ @@ -552,12 +552,12 @@ context %quote semigroup begin -term %quote "x \ y" \ \example 1\ -term %quote "(x::nat) \ y" \ \example 2\ +term %quote \x \ y\ \ \example 1\ +term %quote \(x::nat) \ y\ \ \example 2\ end %quote -term %quote "x \ y" \ \example 3\ +term %quote \x \ y\ \ \example 3\ text \ \<^noindent> Here in example 1, the term refers to the local class @@ -583,7 +583,7 @@ \ definition %quote example :: int where - "example = pow_int 10 (-2)" + \example = pow_int 10 (-2)\ text \ \<^noindent> This maps to Haskell as follows: @@ -628,4 +628,3 @@ \ end -