primrec pshowsp_prod :: "(shows × shows) showsp" where "pshowsp_prod p (x, y) = shows_string ''('' o x o shows_string '', '' o y o shows_string '')''"
(*NOTE: in order to be compatible with automatically generated show funtions, show-argumentsof"map"-functionsneedtogetprecedence1(whichmayleadto redundantparenthesesintheoutput,butseemsunavoidableinthecurrentsetup,
i.e., pshowsp via primrec followed by defining showsp via pshowsp composed with map).*) definition showsp_prod :: "'a showsp ==> 'b showsp ==> ('a × 'b) showsp" where
[code del]: "showsp_prod s1 s2 p = pshowsp_prod p o map_prod (s1 1) (s2 1)"
lemma showsp_prod_simps [simp, code]: "showsp_prod s1 s2 p (x, y) = shows_string ''('' o s1 1 x o shows_string '', '' o s2 1 y o shows_string '')''" by (simp add: showsp_prod_def)
lemma show_law_prod [show_law_intros]: "(∧x. x ∈ Basic_BNFs.fsts y ==> show_law s1 x) ==> (∧x. x ∈ Basic_BNFs.snds y ==> show_law s2 x) ==> show_law (showsp_prod s1 s2) y" proof (induct y) case (Pair x y) note * = Pair [unfolded prod_set_simps] show ?case by (rule show_lawI)
(auto simp del: o_apply intro!: o_append intro: show_lawD * simp: show_law_simps) qed
definition string_of_digit :: "nat ==> string" where "string_of_digit n = (if n = 0 then ''0'' else if n = 1 then ''1'' else if n = 2 then ''2'' else if n = 3 then ''3'' else if n = 4 then ''4'' else if n = 5 then ''5'' else if n = 6 then ''6'' else if n = 7 then ''7'' else if n = 8 then ''8'' else ''9'')"
fun showsp_nat :: "nat showsp" where "showsp_nat p n = (if n < 10 then shows_string (string_of_digit n) else showsp_nat p (n div 10) o shows_string (string_of_digit (n mod 10)))" declare showsp_nat.simps [simp del]
lemma show_law_nat [show_law_intros]: "show_law showsp_nat n" by (rule show_lawI, induct n rule: nat_less_induct) (simp add: show_law_simps showsp_nat.simps)
lemma showsp_nat_append [show_law_simps]: "showsp_nat p n (x @ y) = showsp_nat p n x @ y" by (intro show_lawD show_law_intros)
definition showsp_int :: "int showsp" where "showsp_int p i = (if i < 0 then shows_string ''-'' o showsp_nat p (nat (- i)) else showsp_nat p (nat i))"
lemma show_law_int [show_law_intros]: "show_law showsp_int i" by (rule show_lawI, cases "i < 0") (simp_all add: showsp_int_def show_law_simps)
lemma showsp_int_append [show_law_simps]: "showsp_int p i (x @ y) = showsp_int p i x @ y" by (intro show_lawD show_law_intros)
definition showsp_rat :: "rat showsp" where "showsp_rat p x = (case quotient_of x of (d, n) ==> if n = 1 then showsp_int p d else showsp_int p d o shows_string ''/'' o showsp_int p n)"
lemma showsp_rat_append [show_law_simps]: "showsp_rat p r (x @ y) = showsp_rat p r x @ y" by (intro show_lawD show_law_intros)
text‹
Automatic show functions are not used for @{type unit}, @{type prod}, and numbers:
for @{type unit} and @{type prod}, we do not want to display @{term "''Unity''"} and
@{term "''Pair''"}; for @{type nat}, we do not want to display
@{term "''Suc (Suc (... (Suc 0) ...))''"}; and neither @{type int}
nor @{type rat} are datatypes. ›
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.