diff -r b98cd131e2b5 -r 5b5656a63bd6 src/HOL/ex/Adhoc_Overloading_Examples.thy --- a/src/HOL/ex/Adhoc_Overloading_Examples.thy Tue Oct 06 17:46:07 2015 +0200 +++ b/src/HOL/ex/Adhoc_Overloading_Examples.thy Tue Oct 06 17:47:28 2015 +0200 @@ -2,7 +2,7 @@ Author: Christian Sternagel *) -section {* Ad Hoc Overloading *} +section \Ad Hoc Overloading\ theory Adhoc_Overloading_Examples imports @@ -11,30 +11,30 @@ "~~/src/HOL/Library/Infinite_Set" begin -text {*Adhoc overloading allows to overload a constant depending on +text \Adhoc overloading allows to overload a constant depending on its type. Typically this involves to introduce an uninterpreted constant (used for input and output) and then add some variants (used -internally).*} +internally).\ -subsection {* Plain Ad Hoc Overloading *} +subsection \Plain Ad Hoc Overloading\ -text {*Consider the type of first-order terms.*} +text \Consider the type of first-order terms.\ datatype ('a, 'b) "term" = Var 'b | Fun 'a "('a, 'b) term list" -text {*The set of variables of a term might be computed as follows.*} +text \The set of variables of a term might be computed as follows.\ fun term_vars :: "('a, 'b) term \ 'b set" where "term_vars (Var x) = {x}" | "term_vars (Fun f ts) = \set (map term_vars ts)" -text {*However, also for \emph{rules} (i.e., pairs of terms) and term +text \However, also for \emph{rules} (i.e., pairs of terms) and term rewrite systems (i.e., sets of rules), the set of variables makes -sense. Thus we introduce an unspecified constant @{text vars}.*} +sense. Thus we introduce an unspecified constant @{text vars}.\ consts vars :: "'a \ 'b set" -text {*Which is then overloaded with variants for terms, rules, and TRSs.*} +text \Which is then overloaded with variants for terms, rules, and TRSs.\ adhoc_overloading vars term_vars @@ -56,20 +56,20 @@ value "vars {(Var 1, Var 0)}" -text {*Sometimes it is necessary to add explicit type constraints -before a variant can be determined.*} +text \Sometimes it is necessary to add explicit type constraints +before a variant can be determined.\ (*value "vars R" (*has multiple instances*)*) value "vars (R :: (('a, 'b) term \ ('a, 'b) term) set)" -text {*It is also possible to remove variants.*} +text \It is also possible to remove variants.\ no_adhoc_overloading vars term_vars rule_vars (*value "vars (Var 1)" (*does not have an instance*)*) -text {*As stated earlier, the overloaded constant is only used for +text \As stated earlier, the overloaded constant is only used for input and output. Internally, always a variant is used, as can be -observed by the configuration option @{text show_variants}.*} +observed by the configuration option @{text show_variants}.\ adhoc_overloading vars term_vars @@ -79,10 +79,10 @@ term "vars (Var 1)" (*which yields: "term_vars (Var 1)"*) -subsection {* Adhoc Overloading inside Locales *} +subsection \Adhoc Overloading inside Locales\ -text {*As example we use permutations that are parametrized over an -atom type @{typ "'a"}.*} +text \As example we use permutations that are parametrized over an +atom type @{typ "'a"}.\ definition perms :: "('a \ 'a) set" where "perms = {f. bij f \ finite {x. f x \ x}}" @@ -90,7 +90,7 @@ typedef 'a perm = "perms :: ('a \ 'a) set" by standard (auto simp: perms_def) -text {*First we need some auxiliary lemmas.*} +text \First we need some auxiliary lemmas.\ lemma permsI [Pure.intro]: assumes "bij f" and "MOST x. f x = x" shows "f \ perms" @@ -170,16 +170,16 @@ Rep_perm_uminus -section {* Permutation Types *} +section \Permutation Types\ -text {*We want to be able to apply permutations to arbitrary types. To +text \We want to be able to apply permutations to arbitrary types. To this end we introduce a constant @{text PERMUTE} together with -convenient infix syntax.*} +convenient infix syntax.\ consts PERMUTE :: "'a perm \ 'b \ 'b" (infixr "\" 75) -text {*Then we add a locale for types @{typ 'b} that support -appliciation of permutations.*} +text \Then we add a locale for types @{typ 'b} that support +appliciation of permutations.\ locale permute = fixes permute :: "'a perm \ 'b \ 'b" assumes permute_zero [simp]: "permute 0 x = x" @@ -191,7 +191,7 @@ end -text {*Permuting atoms.*} +text \Permuting atoms.\ definition permute_atom :: "'a perm \ 'a \ 'a" where "permute_atom p a = (Rep_perm p) a" @@ -201,7 +201,7 @@ interpretation atom_permute: permute permute_atom by standard (simp_all add: permute_atom_def Rep_perm_simps) -text {*Permuting permutations.*} +text \Permuting permutations.\ definition permute_perm :: "'a perm \ 'a perm \ 'a perm" where "permute_perm p q = p + q - p" @@ -215,7 +215,7 @@ apply (simp only: diff_conv_add_uminus minus_add add.assoc) done -text {*Permuting functions.*} +text \Permuting functions.\ locale fun_permute = dom: permute perm1 + ran: permute perm2 for perm1 :: "'a perm \ 'b \ 'b"