# HG changeset patch # Parent efd58f8b16591ddd7c201bb7473cf1ba14946723 proper datatype for 8-bit characters diff -r efd58f8b1659 thys/Affine_Arithmetic/Print.thy --- a/thys/Affine_Arithmetic/Print.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/Affine_Arithmetic/Print.thy Tue Apr 24 11:35:45 2018 +0200 @@ -5,7 +5,6 @@ Affine_Code Show.Show_Instances "HOL-Library.Monad_Syntax" - "HOL-Library.Code_Char" Optimize_Float begin diff -r efd58f8b1659 thys/CAVA_Automata/CAVA_Base/Code_String.thy --- a/thys/CAVA_Automata/CAVA_Base/Code_String.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/CAVA_Automata/CAVA_Base/Code_String.thy Tue Apr 24 11:35:45 2018 +0200 @@ -6,41 +6,6 @@ imports (*"HOL-Library.List_lexord"*) Collections.Refine_Dflt - "HOL-Library.Code_Char" begin -(* TODO: Move to Collections *) -instantiation String.literal :: hashable -begin - definition hashcode_literal :: "String.literal \ uint32" - where "hashcode_literal s = hashcode (String.explode s)" - - definition def_hashmap_size_literal - :: "String.literal itself \ nat" where - "def_hashmap_size_literal _ = 10" - - instance proof - qed (simp_all only: def_hashmap_size_literal_def) end - -(* Append on literal strings -- allows for easier written exceptions *) - -context - includes literal.lifting -begin - -lift_definition literal_append - :: "String.literal \ String.literal \ String.literal" (infixr "@@" 65) - is "(@)" . - -end - -lifting_update literal.lifting -lifting_forget literal.lifting - -code_printing - constant literal_append \ - (SML) infixr 5 "^" - and (Haskell) infixr 5 "++" - and (OCaml) infixr 5 "^" -end diff -r efd58f8b1659 thys/CAVA_LTL_Modelchecker/BoolProgs/BoolProgs_LTL_Conv.thy --- a/thys/CAVA_LTL_Modelchecker/BoolProgs/BoolProgs_LTL_Conv.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/CAVA_LTL_Modelchecker/BoolProgs/BoolProgs_LTL_Conv.thy Tue Apr 24 11:35:45 2018 +0200 @@ -22,10 +22,10 @@ | "ltl_conv _ _ False_ltlc = Inl False_ltlc" | "ltl_conv C _ (Prop_ltlc (CProp s)) = (case Mapping.lookup C s of Some c \ Inl (b2l c) - | None \ Inr (STR ''Unknown constant: '' @@ s))" + | None \ Inr (STR ''Unknown constant: '' + s))" | "ltl_conv _ M (Prop_ltlc (FProp (s, argm))) = (case Mapping.lookup M s of Some f \ (Inl \ b2l \ f \ nat_of_integer) argm - | None \ Inr (STR ''Unknown function: '' @@ s))" + | None \ Inr (STR ''Unknown function: '' + s))" | "ltl_conv C M (Not_ltlc x) = (case ltl_conv C M x of Inl l \ Inl (Not_ltlc l) | Inr s \ Inr s)" | "ltl_conv C M (Next_ltlc x) = (case ltl_conv C M x of Inl l \ Inl (Next_ltlc l) | Inr s \ Inr s)" | "ltl_conv C M (Final_ltlc x) = (case ltl_conv C M x of Inl l \ Inl (Final_ltlc l) | Inr s \ Inr s)" diff -r efd58f8b1659 thys/CAVA_LTL_Modelchecker/BoolProgs/Programs/BoolProgs_Programs.thy --- a/thys/CAVA_LTL_Modelchecker/BoolProgs/Programs/BoolProgs_Programs.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/CAVA_LTL_Modelchecker/BoolProgs/Programs/BoolProgs_Programs.thy Tue Apr 24 11:35:45 2018 +0200 @@ -26,7 +26,7 @@ where "chose_prog P n = (case Mapping.lookup progs P of Some (descr, ndescr, p) \ (descr, ndescr, p n) | None \ let (descr, ndescr, p) = the (Mapping.lookup progs default_prog) - in (descr@@(STR '' (fallback)''), ndescr, p n))" + in (descr + STR '' (fallback)'', ndescr, p n))" definition list_progs :: "(String.literal \ String.literal \ String.literal) list" where "list_progs \ let keys = keys_of_map progs in diff -r efd58f8b1659 thys/CAVA_LTL_Modelchecker/CAVA_Impl.thy --- a/thys/CAVA_LTL_Modelchecker/CAVA_Impl.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/CAVA_LTL_Modelchecker/CAVA_Impl.thy Tue Apr 24 11:35:45 2018 +0200 @@ -876,6 +876,7 @@ nat_of_integer int_of_integer integer_of_nat integer_of_int in SML + module_name CAVA file "code/CAVA_Export.sml" end diff -r efd58f8b1659 thys/CakeML/generated/CakeML/PrimTypes.thy --- a/thys/CakeML/generated/CakeML/PrimTypes.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/CakeML/generated/CakeML/PrimTypes.thy Tue Apr 24 11:35:45 2018 +0200 @@ -30,8 +30,8 @@ Tdec (Dexn undefined (''Div'') []), Tdec (Dexn undefined (''Subscript'') []), Tdec (Dtype undefined [([], (''bool''), [((''false''), []), ((''true''), [])])]), - Tdec (Dtype undefined [([([(char_of_nat 39), (CHR ''a'')])], (''list''), [((''nil''), []), ((''::''), [Tvar ([(char_of_nat 39), (CHR ''a'')]), Tapp [Tvar ([(char_of_nat 39), (CHR ''a'')])] (TC_name (Short (''list'')))]) ])]), - Tdec (Dtype undefined [([([(char_of_nat 39), (CHR ''a'')])], (''option''), [((''NONE''), []),((''SOME''), [Tvar ([(char_of_nat 39), (CHR ''a'')])]) ])]) ])" + Tdec (Dtype undefined [([([CHR 0x27, CHR ''a''])], (''list''), [((''nil''), []), ((''::''), [Tvar ([CHR 0x27, CHR ''a'']), Tapp [Tvar ([CHR 0x27, CHR ''a''])] (TC_name (Short (''list'')))]) ])]), + Tdec (Dtype undefined [([([CHR 0x27, CHR ''a''])], (''option''), [((''NONE''), []),((''SOME''), [Tvar ([CHR 0x27, CHR ''a''])]) ])]) ])" (*val add_to_sem_env : diff -r efd58f8b1659 thys/CakeML/generated/CakeML/SemanticPrimitives.thy --- a/thys/CakeML/generated/CakeML/SemanticPrimitives.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/CakeML/generated/CakeML/SemanticPrimitives.thy Tue Apr 24 11:35:45 2018 +0200 @@ -452,12 +452,12 @@ (*val ws_to_chars : list word8 -> list char*) definition ws_to_chars :: "(8 word)list \(char)list " where - " ws_to_chars ws = ( List.map (\ w . char_of_nat(unat w)) ws )" + " ws_to_chars ws = ( List.map (\ w . char_of (unat w)) ws )" (*val chars_to_ws : list char -> list word8*) definition chars_to_ws :: "(char)list \(8 word)list " where - " chars_to_ws cs = ( List.map (\ c2 . word_of_int(int(nat_of_char c2))) cs )" + " chars_to_ws cs = ( List.map (\ c2 . word_of_int(of_char c2)) cs )" (*val opn_lookup : opn -> integer -> integer -> integer*) @@ -663,15 +663,15 @@ | _ => None ) | (Ord, [Litv (Char c2)]) => - Some ((s,t1), Rval (Litv(IntLit(int(nat_of_char c2))))) + Some ((s,t1), Rval (Litv(IntLit(of_char c2)))) | (Chr, [Litv (IntLit i)]) => Some ((s,t1), (if (i <( 0 :: int)) \ (i >( 255 :: int)) then Rerr (Rraise (prim_exn (''Chr''))) else - Rval (Litv(Char(char_of_nat(nat (abs ( i)))))))) + Rval (Litv(Char(char_of(nat (abs ( i)))))))) | (Chopb op1, [Litv (Char c1), Litv (Char c2)]) => - Some ((s,t1), Rval (Boolv (opb_lookup op1 (int(nat_of_char c1)) (int(nat_of_char c2))))) + Some ((s,t1), Rval (Boolv (opb_lookup op1 (of_char c1) (of_char c2)))) | (Implode, [v2]) => (case v_to_char_list v2 of Some ls => @@ -767,7 +767,7 @@ | (FFI n, [Litv(StrLit conf), Loc lnum]) => (case store_lookup lnum s of Some (W8array ws) => - (case call_FFI t1 n (List.map (\ c2 . of_nat(nat_of_char c2)) ( conf)) ws of + (case call_FFI t1 n (List.map (\ c2 . of_char c2) ( conf)) ws of (t', ws') => (case store_assign lnum (W8array ws') s of Some s' => Some ((s', t'), Rval (Conv None [])) diff -r efd58f8b1659 thys/CakeML/generated/LemExtraDefs.thy --- a/thys/CakeML/generated/LemExtraDefs.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/CakeML/generated/LemExtraDefs.thy Tue Apr 24 11:35:45 2018 +0200 @@ -850,16 +850,12 @@ subsection \Strings\ -lemma explode_str_simp [simp] : - "String.explode (STR l) = l" -by (metis STR_inverse UNIV_I) - declare String.literal.explode_inverse [simp] subsection \num to string conversions\ definition nat_list_to_string :: "nat list \ string" where - "nat_list_to_string nl = map char_of_nat nl" + "nat_list_to_string nl = map char_of nl" definition is_digit where "is_digit (n::nat) = (n < 10)" diff -r efd58f8b1659 thys/CakeML/generated/Lem_show.thy --- a/thys/CakeML/generated/Lem_show.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/CakeML/generated/Lem_show.thy Tue Apr 24 11:35:45 2018 +0200 @@ -26,7 +26,7 @@ definition instance_Show_Show_string_dict :: "(string)Show_class " where " instance_Show_Show_string_dict = ((| - show_method = (\ s. ([(char_of_nat 34)]) @ (s @ ([(char_of_nat 34)])))|) )" + show_method = (\ s. ([(char_of (34 :: nat))]) @ (s @ ([(char_of (34 :: nat))])))|) )" (*val stringFromMaybe : forall 'a. ('a -> string) -> maybe 'a -> string*) diff -r efd58f8b1659 thys/CakeML/generated/Lem_string_extra.thy --- a/thys/CakeML/generated/Lem_string_extra.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/CakeML/generated/Lem_string_extra.thy Tue Apr 24 11:35:45 2018 +0200 @@ -43,7 +43,7 @@ if n =( 0 :: nat) then acc1 else - stringFromNatHelper (n div( 10 :: nat)) (char_of_nat ((n mod( 10 :: nat)) +( 48 :: nat)) # acc1))" + stringFromNatHelper (n div( 10 :: nat)) (char_of ((n mod( 10 :: nat)) +( 48 :: nat)) # acc1))" by pat_completeness auto @@ -59,7 +59,7 @@ if n =( 0 :: nat) then acc1 else - stringFromNaturalHelper (n div( 10 :: nat)) (char_of_nat ( ((n mod( 10 :: nat)) +( 48 :: nat))) # acc1))" + stringFromNaturalHelper (n div( 10 :: nat)) (char_of ( ((n mod( 10 :: nat)) +( 48 :: nat))) # acc1))" by pat_completeness auto diff -r efd58f8b1659 thys/Collections/Lib/HashCode.thy --- a/thys/Collections/Lib/HashCode.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/Collections/Lib/HashCode.thy Tue Apr 24 11:35:45 2018 +0200 @@ -84,7 +84,7 @@ instantiation char :: hashable begin - definition [simp]: "hashcode (c :: char) == uint32_of_int (int (nat_of_char c))" + definition [simp]: "hashcode (c :: char) == uint32_of_int (of_char c)" definition "def_hashmap_size = (\_ :: char itself. 32)" instance by(intro_classes)(simp_all add: def_hashmap_size_char_def) end @@ -145,6 +145,21 @@ apply (simp_all add: algebra_simps mod_add_right_eq) *) +instantiation String.literal :: hashable +begin + +definition hashcode_literal :: "String.literal \ uint32" + where "hashcode_literal s = hashcode (String.explode s)" + +definition def_hashmap_size_literal :: "String.literal itself \ nat" + where "def_hashmap_size_literal _ = 10" + +instance + by standard (simp_all only: def_hashmap_size_literal_def) + +end + + hide_type (open) word end diff -r efd58f8b1659 thys/ConcurrentGC/Tactics.thy --- a/thys/ConcurrentGC/Tactics.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/ConcurrentGC/Tactics.thy Tue Apr 24 11:35:45 2018 +0200 @@ -193,7 +193,7 @@ lemmas loc_simps = bex_simps append.simps list.simps rev.simps (* evaluate string equality *) - Char_eq_Char_iff cong_exp_iff_simps (* evaluate character equality *) + char.inject cong_exp_iff_simps (* evaluate character equality *) prefix_code suffix_to_prefix mem_Collect_eq Un_iff UNION_eq Compl_iff insertI1 insertI2 singleton_iff Diff_iff UNIV_I if_True if_False diff -r efd58f8b1659 thys/Containers/Collection_Order.thy --- a/thys/Containers/Collection_Order.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/Containers/Collection_Order.thy Tue Apr 24 11:35:45 2018 +0200 @@ -311,11 +311,9 @@ instance by(intro_classes)(simp add: infinite_UNIV_listI) end -lemma UNIV_literal_eq_range_STR: "UNIV = range STR" -by(auto intro: explode_inverse[symmetric]) - -lemma infinite_UNIV_literal: "\ finite (UNIV :: String.literal set)" -by(auto simp add: UNIV_literal_eq_range_STR infinite_UNIV_listI dest!: finite_imageD intro: inj_onI) +lemma infinite_UNIV_literal: + "infinite (UNIV :: String.literal set)" + by (fact infinite_literal) instantiation String.literal :: cproper_interval begin definition cproper_interval_literal :: "String.literal proper_interval" diff -r efd58f8b1659 thys/Containers/Set_Linorder.thy --- a/thys/Containers/Set_Linorder.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/Containers/Set_Linorder.thy Tue Apr 24 11:35:45 2018 +0200 @@ -2150,32 +2150,42 @@ "proper_interval (Some x) (Some y) \ y - x > 1" by(transfer, simp)+ -lemma char_less_iff_nat_of_char: "x < y \ nat_of_char x < nat_of_char y" +lemma char_less_iff_nat_of_char: "x < y \ of_char x < (of_char y :: nat)" by (fact less_char_def) -lemma nat_of_char_inject [simp]: "nat_of_char x = nat_of_char y \ x = y" - by (fact nat_of_char_eq_iff) +lemma nat_of_char_inject [simp]: "of_char x = (of_char y :: nat) \ x = y" + by (fact of_char_eq_iff) -lemma char_le_iff_nat_of_char: "x \ y \ nat_of_char x \ nat_of_char y" +lemma char_le_iff_nat_of_char: "x \ y \ of_char x \ (of_char y :: nat)" by (fact less_eq_char_def) -instantiation char :: proper_interval begin +instantiation char :: proper_interval +begin + fun proper_interval_char :: "char proper_interval" where "proper_interval_char None None \ True" -| "proper_interval_char None (Some x) \ x \ 0" +| "proper_interval_char None (Some x) \ x \ CHR 0x00" | "proper_interval_char (Some x) None \ x \ CHR 0xFF" -| "proper_interval_char (Some x) (Some y) \ nat_of_char y - nat_of_char x > 1" -instance -proof intro_classes +| "proper_interval_char (Some x) (Some y) \ of_char y - of_char x > (1 :: nat)" + +instance proof fix y :: char - { assume "y \ 0" - hence "0 < y" - by (simp add: char_less_iff_nat_of_char nat_of_char_eq_iff [symmetric]) } + { assume "y \ CHR 0x00" + have "CHR 0x00 < y" + proof (rule ccontr) + assume "\ CHR 0x00 < y" + then have "of_char y = (of_char CHR 0x00 :: nat)" + by (simp add: not_less char_le_iff_nat_of_char) + then have "y = CHR 0x00" + using nat_of_char_inject [of y "CHR 0x00"] by simp + with \y \ CHR 0x00\ show False + by simp + qed } moreover { fix z :: char - assume "z < 0" + assume "z < CHR 0x00" hence False - by (simp add: char_less_iff_nat_of_char nat_of_char_eq_iff [symmetric]) } + by (simp add: char_less_iff_nat_of_char of_char_eq_iff [symmetric]) } ultimately show "proper_interval None (Some y) = (\z. z < y)" by auto @@ -2193,19 +2203,22 @@ (insert nat_of_char_less_256 [of z], simp) } ultimately show "proper_interval (Some x) None = (\z. x < z)" by auto - { assume gt: "nat_of_char y - nat_of_char x > 1" - let ?z = "char_of_nat (nat_of_char x + 1)" - from gt nat_of_char_less_256[of y] - have 255: "nat_of_char x < 255" by arith + { assume gt: "of_char y - of_char x > (1 :: nat)" + let ?z = "char_of (of_char x + (1 :: nat))" + from gt nat_of_char_less_256 [of y] + have 255: "of_char x < (255 :: nat)" by arith with gt have "x < ?z" "?z < y" by (simp_all add: char_less_iff_nat_of_char) hence "\z. x < z \ z < y" by blast } moreover { fix z assume "x < z" "z < y" - hence "1 < nat_of_char y - nat_of_char x" by(simp add: char_less_iff_nat_of_char) } - ultimately show "proper_interval (Some x) (Some y) = (\z>x. z < y)" by auto + hence "(1 :: nat) < of_char y - of_char x" + by (simp add: char_less_iff_nat_of_char) } + ultimately show "proper_interval (Some x) (Some y) = (\z>x. z < y)" + by auto qed simp + end instantiation Enum.finite_1 :: proper_interval begin diff -r efd58f8b1659 thys/FOL_Harrison/FOL_Harrison.thy --- a/thys/FOL_Harrison/FOL_Harrison.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/FOL_Harrison/FOL_Harrison.thy Tue Apr 24 11:35:45 2018 +0200 @@ -11,7 +11,7 @@ theory FOL_Harrison imports - "HOL-Library.Code_Char" + Main begin section \Module Proven\ diff -r efd58f8b1659 thys/Formal_SSA/Disjoin_Transform.thy --- a/thys/Formal_SSA/Disjoin_Transform.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/Formal_SSA/Disjoin_Transform.thy Tue Apr 24 11:35:45 2018 +0200 @@ -43,7 +43,7 @@ by (induction c) (auto intro:newname.intros dest:maxVnameLen_aux_newname) lemma tempname_newname[intro]: "newname c (tempName c)" -by (rule maxVnameLen_newname) (auto simp:tempName_def String.literal.STR_inverse implode_def) + by (rule maxVnameLen_newname) (simp add: tempName_def) fun transform_aux :: "vname \ cmd \ cmd" where "transform_aux _ Skip = Skip" diff -r efd58f8b1659 thys/Formula_Derivatives/WS1S_Nameful.thy --- a/thys/Formula_Derivatives/WS1S_Nameful.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/Formula_Derivatives/WS1S_Nameful.thy Tue Apr 24 11:35:45 2018 +0200 @@ -6,8 +6,8 @@ begin (*>*) -declare nat_of_char_Char[simp] - [[coercion nat_of_char, coercion_enabled]] +declare [[coercion "of_char :: char \ nat", coercion_enabled]] + definition is_upper :: "char \ bool" where [simp]: "is_upper c = (c \ {65..90 :: nat})" definition is_lower :: "char \ bool" where [simp]: "is_lower c = (c \ {97..122 :: nat})" diff -r efd58f8b1659 thys/HereditarilyFinite/Finitary.thy --- a/thys/HereditarilyFinite/Finitary.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/HereditarilyFinite/Finitary.thy Tue Apr 24 11:35:45 2018 +0200 @@ -43,9 +43,9 @@ instantiation char :: finitary begin definition hf_of_char_def: - "hf_of x \ hf_of (nat_of_char x)" + "hf_of x \ hf_of (of_char x :: nat)" instance - by intro_classes (auto simp: inj_on_def hf_of_char_def nat_of_char_eq_iff) + by standard (auto simp: inj_on_def hf_of_char_def) end instantiation prod :: (finitary,finitary) finitary diff -r efd58f8b1659 thys/IP_Addresses/Lib_Numbers_toString.thy --- a/thys/IP_Addresses/Lib_Numbers_toString.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/IP_Addresses/Lib_Numbers_toString.thy Tue Apr 24 11:35:45 2018 +0200 @@ -6,8 +6,8 @@ (*http://stackoverflow.com/questions/23864965/string-of-nat-in-isabelle*) fun string_of_nat :: "nat \ string" where - "string_of_nat n = (if n < 10 then [char_of_nat (48 + n)] else - string_of_nat (n div 10) @ [char_of_nat (48 + (n mod 10))])" + "string_of_nat n = (if n < 10 then [char_of (48 + n)] else + string_of_nat (n div 10) @ [char_of (48 + (n mod 10))])" definition string_of_int :: "int \ string" where "string_of_int i = (if i < 0 then ''-'' @ string_of_nat (nat (- i)) else string_of_nat (nat i))" diff -r efd58f8b1659 thys/IP_Addresses/Lib_Word_toString.thy --- a/thys/IP_Addresses/Lib_Word_toString.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/IP_Addresses/Lib_Word_toString.thy Tue Apr 24 11:35:45 2018 +0200 @@ -14,11 +14,11 @@ (if w < 10 then - [char_of_nat (48 + unat w)] + [char_of (48 + unat w)] else if w < 36 then - [char_of_nat ((if lc then 87 else 55) + unat w)] + [char_of ((if lc then 87 else 55) + unat w)] else undefined)" @@ -86,7 +86,7 @@ lemma "dec_string_of_word0 (-1::8 word) = ''255''" by eval lemma string_of_word_single_atoi: - "n < 10 \ string_of_word_single True n = [char_of_nat (48 + unat n)]" + "n < 10 \ string_of_word_single True n = [char_of (48 + unat n)]" by(simp add: string_of_word_single_def) (*TODO: move!*) diff -r efd58f8b1659 thys/Iptables_Semantics/Primitive_Matchers/Code_Interface.thy --- a/thys/Iptables_Semantics/Primitive_Matchers/Code_Interface.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/Iptables_Semantics/Primitive_Matchers/Code_Interface.thy Tue Apr 24 11:35:45 2018 +0200 @@ -13,7 +13,6 @@ Native_Word.Code_Target_Bits_Int "HOL-Library.Code_Target_Nat" "HOL-Library.Code_Target_Int" - "HOL-Library.Code_Char" begin (*Note: common_primitive_match_expr_ipv4_toString can be really slow*) diff -r efd58f8b1659 thys/Iptables_Semantics/ROOT --- a/thys/Iptables_Semantics/ROOT Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/Iptables_Semantics/ROOT Tue Apr 24 11:35:45 2018 +0200 @@ -11,7 +11,6 @@ Native_Word.Code_Target_Bits_Int "HOL-Library.Code_Target_Nat" "HOL-Library.Code_Target_Int" - "HOL-Library.Code_Char" Automatic_Refinement.Misc (* mergesort *) "Common/List_Misc" "Common/WordInterval_Lists" diff -r efd58f8b1659 thys/Isabelle_Meta_Model/Init.thy --- a/thys/Isabelle_Meta_Model/Init.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/Isabelle_Meta_Model/Init.thy Tue Apr 24 11:35:45 2018 +0200 @@ -36,9 +36,8 @@ ******************************************************************************) theory Init -imports "HOL-Library.Code_Char" - "isabelle_home/src/HOL/Isabelle_Main0" - +imports + "isabelle_home/src/HOL/Isabelle_Main0" begin section\Optimization on the String Datatype\ diff -r efd58f8b1659 thys/JinjaThreads/Basic/Auxiliary.thy --- a/thys/JinjaThreads/Basic/Auxiliary.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/JinjaThreads/Basic/Auxiliary.thy Tue Apr 24 11:35:45 2018 +0200 @@ -11,7 +11,6 @@ Complex_Main "HOL-Library.Transitive_Closure_Table" "HOL-Library.Predicate_Compile_Alternative_Defs" - "HOL-Library.Code_Char" "HOL-Library.Monad_Syntax" "HOL-Library.Infinite_Set" FinFun.FinFun diff -r efd58f8b1659 thys/JinjaThreads/Basic/Basic_Main.thy --- a/thys/JinjaThreads/Basic/Basic_Main.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/JinjaThreads/Basic/Basic_Main.thy Tue Apr 24 11:35:45 2018 +0200 @@ -2,7 +2,6 @@ imports Main "HOL-Library.Sublist" "HOL-Library.Transitive_Closure_Table" - "HOL-Library.Code_Char" "HOL-Library.Predicate_Compile_Alternative_Defs" "HOL-Library.Dlist" Set_without_equal diff -r efd58f8b1659 thys/JinjaThreads/Compiler/Compiler1.thy --- a/thys/JinjaThreads/Compiler/Compiler1.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/JinjaThreads/Compiler/Compiler1.thy Tue Apr 24 11:35:45 2018 +0200 @@ -13,13 +13,14 @@ begin definition fresh_var :: "vname list \ vname" -where "fresh_var Vs \ sum_list (STR ''V'' # Vs)" + where "fresh_var Vs = sum_list (STR ''V'' # Vs)" lemma fresh_var_fresh: "fresh_var Vs \ set Vs" proof - - have "\V \ set Vs. length (String.explode V) < length (String.explode (fresh_var Vs))" - by (induct Vs) (auto simp add: fresh_var_def STR_inverse implode_def) - thus ?thesis by auto + have "V \ set Vs \ length (String.explode V) < length (String.explode (fresh_var Vs))" for V + by (induction Vs) (auto simp add: fresh_var_def Literal.rep_eq) + then show ?thesis + by auto qed text{* Replacing variable names by indices. *} diff -r efd58f8b1659 thys/JinjaThreads/Examples/ApprenticeChallenge.thy --- a/thys/JinjaThreads/Examples/ApprenticeChallenge.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/JinjaThreads/Examples/ApprenticeChallenge.thy Tue Apr 24 11:35:45 2018 +0200 @@ -45,7 +45,7 @@ (Job, Thread, [(STR ''objref'', Class Container, \volatile=False\)], [(STR ''incr'', [], Class Job, \([], sync(Var (STR ''objref'')) - ((Var (STR ''objref''))\STR ''counter''{STR []} := ((Var (STR ''objref''))\STR ''counter''{STR []} \Add\ Val (Intg 1)));; + ((Var (STR ''objref''))\STR ''counter''{STR ''''} := ((Var (STR ''objref''))\STR ''counter''{STR ''''} \Add\ Val (Intg 1)));; Var this)\), (STR ''setref'', [Class Container], Void, \([STR ''o''], LAss (STR ''objref'') (Var (STR ''o'')))\), diff -r efd58f8b1659 thys/JinjaThreads/Examples/BufferExample.thy --- a/thys/JinjaThreads/Examples/BufferExample.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/JinjaThreads/Examples/BufferExample.thy Tue Apr 24 11:35:45 2018 +0200 @@ -36,7 +36,7 @@ (STR ''buffer'' := newA (Class Object)\Var (STR ''size'')\);; (STR ''front'' := Val (Intg 0));; (STR ''back'' := Val (Intg (- 1)));; - (Var this\(STR ''size''){STR []} := Val (Intg 0)))\), + (Var this\(STR ''size''){STR ''''} := Val (Intg 0)))\), (STR ''empty'', [], Boolean, \([], sync(Var this) (Var (STR ''size'') \Eq\ Val (Intg 0)))\), (STR ''full'', [], Boolean, \([], sync(Var this) (Var (STR ''size'') \Eq\ ((Var (STR ''buffer''))\length)))\), @@ -79,7 +79,7 @@ [(run, [], Void, \([], {STR ''i'':Integer=\Intg 0\; while (Var (STR ''i'') \NotEq\ Val (Intg (word_of_int n))) ( - (Var (STR ''buffer''))\STR ''put''([{STR ''temp'':Class (STR ''Integer'')=None; (STR ''temp'' := new (STR ''Integer'');; ((FAss (Var (STR ''temp'')) (STR ''value'') (STR []) (Var (STR ''i'')));; Var (STR ''temp'')))} ]);; + (Var (STR ''buffer''))\STR ''put''([{STR ''temp'':Class (STR ''Integer'')=None; (STR ''temp'' := new (STR ''Integer'');; ((FAss (Var (STR ''temp'')) (STR ''value'') (STR '''') (Var (STR ''i'')));; Var (STR ''temp'')))} ]);; STR ''i'' := (Var (STR ''i'') \Add\ (Val (Intg 1)))) })\)])" @@ -118,8 +118,8 @@ {STR ''p'':Class Producer=None; STR ''p'' := new Producer;; {STR ''c'':Class Consumer=None; (STR ''c'' := new Consumer);; - (Var (STR ''c'')\STR ''buffer''{STR []} := Var (STR ''b''));; - (Var (STR ''p'')\STR ''buffer''{STR []} := Var (STR ''b''));; + (Var (STR ''c'')\STR ''buffer''{STR ''''} := Var (STR ''b''));; + (Var (STR ''p'')\STR ''buffer''{STR ''''} := Var (STR ''b''));; (Var (STR ''c'')\Type.start([]));;(Var (STR ''p'')\Type.start([])) } } diff -r efd58f8b1659 thys/JinjaThreads/Execute/Code_Generation.thy --- a/thys/JinjaThreads/Execute/Code_Generation.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/JinjaThreads/Execute/Code_Generation.thy Tue Apr 24 11:35:45 2018 +0200 @@ -13,7 +13,6 @@ "../Compiler/Compiler" Coinductive.Lazy_TLList "HOL-Library.Code_Target_Int" - "HOL-Library.Code_Char" "HOL-Library.Code_Target_Numeral" begin diff -r efd58f8b1659 thys/JinjaThreads/Execute/ToString.thy --- a/thys/JinjaThreads/Execute/ToString.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/JinjaThreads/Execute/ToString.thy Tue Apr 24 11:35:45 2018 +0200 @@ -261,7 +261,7 @@ instantiation rbt :: ("{toString,linorder}", toString) toString begin definition [code]: "toString (t :: ('a, 'b) rbt) = - sum_list (list_toString (STR [CHR 0x2C, CHR 0x0A]) (rm_to_list t))" + sum_list (list_toString (STR '',\'') (rm_to_list t))" instance proof qed end diff -r efd58f8b1659 thys/JinjaThreads/J/Annotate.thy --- a/thys/JinjaThreads/J/Annotate.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/JinjaThreads/J/Annotate.thy Tue Apr 24 11:35:45 2018 +0200 @@ -12,12 +12,12 @@ abbreviation (output) unanFAcc :: "'addr expr \ vname \ 'addr expr" ("(_\_)" [10,10] 90) where - "unanFAcc e F \ FAcc e F (STR [])" + "unanFAcc e F \ FAcc e F (STR '''')" abbreviation (output) unanFAss :: "'addr expr \ vname \ 'addr expr \ 'addr expr" ("(_\_ := _)" [10,0,90] 90) where - "unanFAss e F e' \ FAss e F (STR []) e'" + "unanFAss e F e' \ FAss e F (STR '''') e'" definition array_length_field_name :: vname where "array_length_field_name = STR ''length''" @@ -68,24 +68,24 @@ AnnoFAcc: "\ is_lub,P,E \ e \ e'; is_lub,P,E \ e' :: U; class_type_of' U = \C\; P \ C sees F:T (fm) in D; is_Array U \ F \ array_length_field_name \ - \ is_lub,P,E \ e\F{STR []} \ e'\F{D}" + \ is_lub,P,E \ e\F{STR ''''} \ e'\F{D}" | AnnoFAccALength: "\ is_lub,P,E \ e \ e'; is_lub,P,E \ e' :: T\\ \ - \ is_lub,P,E \ e\array_length_field_name{STR []} \ e'\length" + \ is_lub,P,E \ e\array_length_field_name{STR ''''} \ e'\length" | AnnoFAccSuper: \ \In class C with super class D, "super" is syntactic sugar for "((D) this)" (cf. JLS, 15.11.2)\ "\ E this = \Class C\; C \ Object; class P C = \(D, fs, ms)\; P \ D sees F:T (fm) in D' \ - \ is_lub,P,E \ Var super\F{STR []} \ (Cast (Class D) (Var this))\F{D'}" + \ is_lub,P,E \ Var super\F{STR ''''} \ (Cast (Class D) (Var this))\F{D'}" | AnnoFAss: "\ is_lub,P,E \ e1 \ e1'; is_lub,P,E \ e2 \ e2'; is_lub,P,E \ e1' :: U; class_type_of' U = \C\; P \ C sees F:T (fm) in D; is_Array U \ F \ array_length_field_name \ - \ is_lub,P,E \ e1\F{STR []} := e2 \ e1'\F{D} := e2'" + \ is_lub,P,E \ e1\F{STR ''''} := e2 \ e1'\F{D} := e2'" | AnnoFAssSuper: "\ E this = \Class C\; C \ Object; class P C = \(D, fs, ms)\; P \ D sees F:T (fm) in D'; is_lub,P,E \ e \ e' \ - \ is_lub,P,E \ Var super\F{STR []} := e \ (Cast (Class D) (Var this))\F{D'} := e'" + \ is_lub,P,E \ Var super\F{STR ''''} := e \ (Cast (Class D) (Var this))\F{D'} := e'" | AnnoCAS: "\ is_lub,P,E \ e1 \ e1'; is_lub,P,E \ e2 \ e2'; is_lub,P,E \ e3 \ e3' \ \ is_lub,P,E \ e1\compareAndSwap(D\F, e2, e3) \ e1'\compareAndSwap(D\F, e2', e3')" @@ -161,7 +161,7 @@ and Annos_fun: "\ is_lub,P,E \ es [\] es'; is_lub,P,E \ es [\] es'' \ \ es' = es''" proof(induct arbitrary: e'' and es'' rule: Anno_Annos.inducts) case (AnnoFAcc E e e' U C F T fm D) - from `is_lub,P,E \ e\F{STR []} \ e''` show ?case + from `is_lub,P,E \ e\F{STR ''''} \ e''` show ?case proof(rule Anno_cases) fix e''' U' C' T' fm' D' assume "is_lub,P,E \ e \ e'''" "is_lub,P,E \ e''' :: U'" @@ -198,7 +198,7 @@ case AnnoFAccALength thus ?case by(fastforce intro: WT_unique[OF is_lub_unique]) next case (AnnoFAss E e1 e1' e2 e2' U C F T fm D) - from `is_lub,P,E \ e1\F{STR []} := e2 \ e''` + from `is_lub,P,E \ e1\F{STR ''''} := e2 \ e''` show ?case proof(rule Anno_cases) fix e1'' e2'' U' C' T' fm' D' diff -r efd58f8b1659 thys/JinjaThreads/MM/SC_Collections.thy --- a/thys/JinjaThreads/MM/SC_Collections.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/JinjaThreads/MM/SC_Collections.thy Tue Apr 24 11:35:45 2018 +0200 @@ -305,7 +305,7 @@ assumes "map_of FDTs (F, D) = \(T, fm)\" shows "\fs' v. tm_\ (init_fields (map (\(FD, (T, fm)). (FD, T)) FDTs)) (String.explode F) = \fs'\ \ lm_\ fs' D = \v\ \ sc.conf P h v T" using assms -by(induct FDTs)(auto simp add: tm.lookup_correct tm.update_correct lm.update_correct init_fields_def explode_inject) + by(induct FDTs)(auto simp add: tm.lookup_correct tm.update_correct lm.update_correct init_fields_def String.explode_inject) lemma sc_oconf_init_fields: assumes "P \ C has_fields FDTs" @@ -349,7 +349,7 @@ fs' = (case tm_lookup (String.explode F) fs of None \ lm_empty () | Some fs' \ fs') \ \ P,h \sc (Obj C (tm_update (String.explode F) (lm_update D v fs') fs)) \" unfolding sc_oconf_def has_field_def -apply(auto dest: has_fields_fun simp add: lm.update_correct tm.update_correct tm.lookup_correct explode_inject) +apply(auto dest: has_fields_fun simp add: lm.update_correct tm.update_correct tm.lookup_correct String.explode_inject) apply(drule (1) has_fields_fun, fastforce) apply(drule (1) has_fields_fun, fastforce) done diff -r efd58f8b1659 thys/Knuth_Morris_Pratt/KMP.thy --- a/thys/Knuth_Morris_Pratt/KMP.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/Knuth_Morris_Pratt/KMP.thy Tue Apr 24 11:35:45 2018 +0200 @@ -1,7 +1,6 @@ theory KMP imports Refine_Imperative_HOL.IICF "HOL-Library.Sublist" - "HOL-Library.Code_Char" begin declare len_greater_imp_nonempty[simp del] min_absorb2[simp] @@ -927,8 +926,8 @@ section \Tests of Generated ML-Code\ ML_val \ - fun str2arl s = (Array.fromList (String.explode s), @{code nat_of_integer} (String.size s)) - fun kmp s t = map_option (@{code integer_of_nat}) (@{code kmp_string_impl} (str2arl s) (str2arl t) ()) + fun str2arl s = (Array.fromList (@{code String.explode} s), @{code nat_of_integer} (String.size s)) + fun kmp s t = map_option @{code integer_of_nat} (@{code kmp_string_impl} (str2arl s) (str2arl t) ()) val test1 = kmp "anas" "bananas" val test2 = kmp "" "bananas" diff -r efd58f8b1659 thys/LLL_Factorization/Modern_Computer_Algebra_Problem.thy --- a/thys/LLL_Factorization/Modern_Computer_Algebra_Problem.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/LLL_Factorization/Modern_Computer_Algebra_Problem.thy Tue Apr 24 11:35:45 2018 +0200 @@ -10,7 +10,6 @@ theory Modern_Computer_Algebra_Problem imports Factorization_Algorithm_16_22 - "HOL-Library.Code_Char" begin fun max_degree_poly :: "int poly \ int poly \ int poly" diff -r efd58f8b1659 thys/LOFT/OpenFlow_Matches.thy --- a/thys/LOFT/OpenFlow_Matches.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/LOFT/OpenFlow_Matches.thy Tue Apr 24 11:35:45 2018 +0200 @@ -3,6 +3,7 @@ Simple_Firewall.Simple_Packet "HOL-Library.Monad_Syntax" (*"../Iptables_Semantics/Primitive_Matchers/Simple_Packet" (* I just want those TCP,UDP,\ defs *)*) + "HOL-Library.List_lexord" "HOL-Library.Char_ord" (* For a linorder on strings. See below. *) begin @@ -101,8 +102,9 @@ termination prerequisites by(relation "measure (match_sorter \ fst)", simp_all) -definition "less_eq_of_match_field1 (a::of_match_field) (b::of_match_field) \ (case (a, b) of - (IngressPort a, IngressPort b) \ String.implode a \ String.implode b | +definition less_eq_of_match_field1 :: "of_match_field \ of_match_field \ bool" + where "less_eq_of_match_field1 (a::of_match_field) (b::of_match_field) \ (case (a, b) of + (IngressPort a, IngressPort b) \ a \ b | (VlanId a, VlanId b) \ a \ b | (EtherDst a, EtherDst b) \ a \ b | (EtherSrc a, EtherSrc b) \ a \ b | @@ -114,12 +116,20 @@ (L4Src a1 a2, L4Src b1 b2) \ if a2 = b2 then a1 \ b1 else a2 \ b2 | (L4Dst a1 a2, L4Dst b1 b2) \ if a2 = b2 then a1 \ b1 else a2 \ b2 | (a, b) \ match_sorter a < match_sorter b)" + (* feel free to move this to OpenFlowSerialize if it gets in the way. *) instantiation of_match_field :: linorder begin - definition "less_eq_of_match_field (a::of_match_field) (b::of_match_field) \ less_eq_of_match_field1 a b" - definition "less_of_match_field (a::of_match_field) (b::of_match_field) \ (a \ b \ less_eq_of_match_field1 a b)" -instance by standard (auto simp: less_eq_of_match_field_def less_eq_of_match_field1_def less_of_match_field_def implode_def split: prod.splits of_match_field.splits if_splits) + +definition + "less_eq_of_match_field (a::of_match_field) (b::of_match_field) \ less_eq_of_match_field1 a b" + +definition + "less_of_match_field (a::of_match_field) (b::of_match_field) \ a \ b \ less_eq_of_match_field1 a b" + +instance + by standard (auto simp add: less_eq_of_match_field_def less_of_match_field_def less_eq_of_match_field1_def split: prod.splits of_match_field.splits if_splits) + end fun match_no_prereq :: "of_match_field \ (32, 'a) simple_packet_ext_scheme \ bool" where diff -r efd58f8b1659 thys/LOFT/OpenFlow_Serialize.thy --- a/thys/LOFT/OpenFlow_Serialize.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/LOFT/OpenFlow_Serialize.thy Tue Apr 24 11:35:45 2018 +0200 @@ -4,7 +4,6 @@ Semantics_OpenFlow Simple_Firewall.Primitives_toString IP_Addresses.Lib_Word_toString - "HOL-Library.Code_Char" begin definition "serialization_test_entry \ OFEntry 7 {EtherDst 0x1, IPv4Dst (PrefixMatch 0xA000201 32), IngressPort ''s1-lan'', L4Dst 0x50 0, L4Src 0x400 0x3FF, IPv4Proto 6, EtherType 0x800} [ModifyField_l2dst 0xA641F185E862, Forward ''s1-wan'']" diff -r efd58f8b1659 thys/LTL/example/LTL_Example.thy --- a/thys/LTL/example/LTL_Example.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/LTL/example/LTL_Example.thy Tue Apr 24 11:35:45 2018 +0200 @@ -6,7 +6,7 @@ section \Example\ theory LTL_Example - imports Main "../LTL" "../LTL_Rewrite" "HOL-Library.Code_Target_Numeral" "HOL-Library.Code_Char" + imports Main "../LTL" "../LTL_Rewrite" "HOL-Library.Code_Target_Numeral" begin \ \The included parser always returns a @{typ "String.literal ltlc"}. If a different labelling is diff -r efd58f8b1659 thys/LTL/example/rewrite_example.sml --- a/thys/LTL/example/rewrite_example.sml Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/LTL/example/rewrite_example.sml Tue Apr 24 11:35:45 2018 +0200 @@ -19,6 +19,22 @@ end; (*struct HOL*) +structure Product_Type : sig + val equal_unit : unit HOL.equal + val fst : 'a * 'b -> 'a + val snd : 'a * 'b -> 'b +end = struct + +fun equal_unita u v = true; + +val equal_unit = {equal = equal_unita} : unit HOL.equal; + +fun fst (x1, x2) = x1; + +fun snd (x1, x2) = x2; + +end; (*struct Product_Type*) + structure Orderings : sig type 'a ord val less_eq : 'a ord -> 'a -> 'a -> bool @@ -49,6 +65,7 @@ val zero_nat : nat val funpow : nat -> ('a -> 'a) -> 'a -> 'a val less_nat : nat -> nat -> bool + val bit_cut_integer : IntInf.int -> IntInf.int * bool val less_eq_nat : nat -> nat -> bool end = struct @@ -85,6 +102,17 @@ fun less_nat m n = IntInf.< (integer_of_nat m, integer_of_nat n); +fun bit_cut_integer k = + (if ((k : IntInf.int) = (0 : IntInf.int)) then ((0 : IntInf.int), false) + else let + val (r, s) = + IntInf.divMod (IntInf.abs k, IntInf.abs (2 : IntInf.int)); + in + ((if IntInf.< ((0 : IntInf.int), k) then r + else IntInf.- (IntInf.~ r, s)), + ((s : IntInf.int) = (1 : IntInf.int))) + end); + fun less_eq_nat m n = IntInf.<= (integer_of_nat m, integer_of_nat n); end; (*struct Arith*) @@ -296,29 +324,51 @@ end; (*struct LTL*) -structure Stringa : sig +structure List : sig + val map : ('a -> 'b) -> 'a list -> 'b list + val size_list : 'a list -> Arith.nat +end = struct + +fun map f [] = [] + | map f (x21 :: x22) = f x21 :: map f x22; + +fun gen_length n (x :: xs) = gen_length (Arith.suc n) xs + | gen_length n [] = n; + +fun size_list x = gen_length Arith.zero_nat x; + +end; (*struct List*) + +structure String : sig + type char val size_literal : string -> Arith.nat end = struct -fun size_literal s = Arith.zero_nat; +datatype char = Chara of bool * bool * bool * bool * bool * bool * bool * bool; -end; (*struct Stringa*) +fun char_of_integer k = let + val (q0, b0) = Arith.bit_cut_integer k; + val (q1, b1) = Arith.bit_cut_integer q0; + val (q2, b2) = Arith.bit_cut_integer q1; + val (q3, b3) = Arith.bit_cut_integer q2; + val (q4, b4) = Arith.bit_cut_integer q3; + val (q5, b5) = Arith.bit_cut_integer q4; + val (q6, b6) = Arith.bit_cut_integer q5; + val a = Arith.bit_cut_integer q6; + val (_, aa) = a; + in + Chara (b0, b1, b2, b3, b4, b5, b6, aa) + end; -structure Product_Type : sig - val equal_unit : unit HOL.equal - val fst : 'a * 'b -> 'a - val snd : 'a * 'b -> 'b -end = struct +fun explode s = + List.map char_of_integer + ((map (fn c => let val k = Char.ord c in if k < 128 then IntInf.fromInt k else raise Fail "Non-ASCII character in literal" end) + o String.explode) + s); -fun equal_unita u v = true; +fun size_literal xa = List.size_list (explode xa); -val equal_unit = {equal = equal_unita} : unit HOL.equal; - -fun fst (x1, x2) = x1; - -fun snd (x1, x2) = x2; - -end; (*struct Product_Type*) +end; (*struct String*) structure Predicate : sig type 'a seq @@ -1285,7 +1335,7 @@ fun rewrite x = (LTL_Rewrite.rewrite_iter_slow Arith.equal_nat o LTL.ltlc_to_ltln o - LTL.map_ltlc Stringa.size_literal) + LTL.map_ltlc String.size_literal) x; end; (*struct LTL_Example*) diff -r efd58f8b1659 thys/LTL_to_DRA/Impl/Export_Code.thy --- a/thys/LTL_to_DRA/Impl/Export_Code.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/LTL_to_DRA/Impl/Export_Code.thy Tue Apr 24 11:35:45 2018 +0200 @@ -10,7 +10,6 @@ "HOL-Library.AList_Mapping" (* Future, Performance: Replace by LC *) LTL.LTL_Rewrite "HOL-Library.Code_Target_Numeral" - "HOL-Library.Code_Char" begin subsection \External Interface\ diff -r efd58f8b1659 thys/Native_Word/Native_Cast.thy --- a/thys/Native_Word/Native_Cast.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/Native_Word/Native_Cast.thy Tue Apr 24 11:35:45 2018 +0200 @@ -2,39 +2,25 @@ Author: Andreas Lochbihler, ETH Zurich *) -chapter {* Conversions between unsigned words and between char *} +chapter \Conversions between unsigned words and between char\ -theory Native_Cast imports - "HOL-Library.Code_Char" +theory Native_Cast + imports Uint8 Uint16 Uint32 Uint64 begin -text {* Auxiliary stuff *} - -context includes lifting_syntax -begin - -lemma char_of_integer_transfer [transfer_rule]: - "(pcr_integer ===> (=)) (\n. char_of_nat (nat n)) char_of_integer" -by(simp add: integer.pcr_cr_eq cr_integer_def rel_fun_def char_of_integer_def nat_of_integer_def) - -lemma integer_of_char_transfer [transfer_rule]: - "((=) ===> pcr_integer) (\n. int (nat_of_char n)) integer_of_char" -by(simp add: integer.pcr_cr_eq cr_integer_def rel_fun_def integer_of_char_def) - -end +text \Auxiliary stuff\ lemma integer_of_char_char_of_integer [simp]: - "0 \ x \ integer_of_char (char_of_integer x) = x mod 256" -unfolding integer_of_char_def char_of_integer_def o_apply nat_of_char_of_nat -including integer.lifting by transfer(auto dest: nat_mod_distrib[of _ 256, symmetric]) + "integer_of_char (char_of_integer x) = x mod 256" + by (simp add: integer_of_char_def char_of_integer_def) lemma char_of_integer_integer_of_char [simp]: "char_of_integer (integer_of_char x) = x" -by(simp add: integer_of_char_def char_of_integer_def) + by (simp add: integer_of_char_def char_of_integer_def) lemma int_lt_numeral [simp]: "int x < numeral n \ x < numeral n" by (metis nat_numeral zless_nat_eq_int_zless) @@ -43,58 +29,11 @@ including integer.lifting by transfer simp lemma integer_of_char_ge_0 [simp]: "0 \ integer_of_char x" -including integer.lifting by transfer simp + including integer.lifting unfolding integer_of_char_def + by transfer (simp add: of_char_def) -section {* Conversions between @{typ uint8} and @{typ char} *} - -definition uint8_of_char :: "char \ uint8" -where "uint8_of_char = Uint8 \ integer_of_char" - -definition char_of_uint8 :: "uint8 \ char" -where "char_of_uint8 = char_of_integer \ integer_of_int \ uint \ Rep_uint8'" - -lemma uint8_of_char_char_of_uint8 [simp]: - "uint8_of_char (char_of_uint8 x) = x" -apply(simp add: uint8_of_char_def char_of_uint8_def) -including integer.lifting apply transfer -apply(simp add: mod_pos_pos_trivial uint_bounded[where ?'a=8, simplified]) -done - -lemma char_of_uint8_uint8_of_char [simp]: - "char_of_uint8 (uint8_of_char x) = x" -proof - - have "char_of_uint8 (uint8_of_char x) = - char_of_integer (of_int (int_of_integer (integer_of_char x) mod 256))" - by(simp add: uint8_of_char_def char_of_uint8_def Uint8.rep_eq uint_word_of_int) - also { have "int_of_integer (integer_of_char x) < 256" - including integer.lifting by transfer(simp add: nat_of_char_less_256) } - hence "\ = x" - by(simp add: mod_pos_pos_trivial int_of_integer_ge_0) - finally show ?thesis . -qed - -code_printing code_module Native_Casts \ (Haskell) -{*import qualified Data.Char; - -ord :: Char -> Int; -ord = Data.Char.ord; - -chr :: Int -> Char; -chr = Data.Char.chr; -*} -code_reserved Haskell Native_Casts - -code_printing constant uint8_of_char \ - (SML) "Word8.fromInt (Char.ord _)" and - (Haskell) "(Prelude.fromIntegral (Native'_Casts.ord _) :: Uint8.Word8)" and - (Scala) "_.toByte" -| constant char_of_uint8 \ - (SML) "Char.chr (Word8.toInt _)" and - (Haskell) "Native'_Casts.chr (Prelude.fromIntegral _)" and - (Scala) "((_).toInt & 0xFF).toChar" - -section {* Conversion between native words *} +section \Conversion between native words\ lift_definition uint8_of_uint16 :: "uint16 \ uint8" is ucast . lift_definition uint8_of_uint32 :: "uint32 \ uint8" is ucast . @@ -167,11 +106,11 @@ (Scala) "((_).toLong & 0xFFFFFFFFL)" and (OCaml) "Int64.logand (Int64.of'_int32 _) (Int64.of'_string \"4294967295\")" -text {* +text \ Use @{const Abs_uint8'} etc. instead of @{const Rep_uint8} in code equations for conversion functions to avoid exceptions during code generation when the target language provides only some of the uint types. -*} +\ lemma uint8_of_uint16_code [code]: "uint8_of_uint16 x = Abs_uint8' (ucast (Rep_uint16' x))" diff -r efd58f8b1659 thys/Native_Word/Native_Word_Test.thy --- a/thys/Native_Word/Native_Word_Test.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/Native_Word/Native_Word_Test.thy Tue Apr 24 11:35:45 2018 +0200 @@ -421,8 +421,6 @@ definition test_casts :: bool where "test_casts \ - map uint8_of_char [CHR ''a'', 0, char_of_nat 255] = [97, 0, 255] \ - map char_of_uint8 [65, 0, 255] = [CHR ''A'', 0, char_of_nat 255] \ map uint8_of_uint32 [10, 0, 0xFE, 0xFFFFFFFF] = [10, 0, 0xFE, 0xFF] \ map uint8_of_uint64 [10, 0, 0xFE, 0xFFFFFFFFFFFFFFFF] = [10, 0, 0xFE, 0xFF] \ map uint32_of_uint8 [10, 0, 0xFF] = [10, 0, 0xFF] \ diff -r efd58f8b1659 thys/Ordinary_Differential_Equations/Numerics/Refine_Reachability_Analysis.thy --- a/thys/Ordinary_Differential_Equations/Numerics/Refine_Reachability_Analysis.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/Ordinary_Differential_Equations/Numerics/Refine_Reachability_Analysis.thy Tue Apr 24 11:35:45 2018 +0200 @@ -1172,7 +1172,7 @@ shows "(nres_of ?f, mk_safe $ (R::'a::executable_euclidean_space set)) \ \appr_rel\nres_rel" unfolding autoref_tag_defs unfolding mk_safe_def - by (autoref_monadic) + by autoref_monadic concrete_definition mk_safe_impl for Ri uses mk_safe_impl lemma sappr_rel_nres_relI: @@ -1218,7 +1218,7 @@ shows "(nres_of (?f::?'c dres), mk_safe_coll IS)\?R" unfolding mk_safe_coll_def by (subst rel_ANNOT_eq[of "sets_of_coll X" "\\appr_rel\list_wset_rel\nres_rel" for X]) - (autoref_monadic) + autoref_monadic concrete_definition mk_safe_coll_impl for ISi uses mk_safe_coll_impl lemma mk_safe_coll_impl_refine[autoref_rules]: @@ -1482,7 +1482,7 @@ unfolding autoref_tag_defs unfolding Picard_step_ivl_def including art - by (autoref_monadic) + by autoref_monadic concrete_definition Picard_step_ivl_impl for X0i t0i hi PHIi uses Picard_step_ivl_impl lemmas [autoref_rules] = Picard_step_ivl_impl.refine @@ -1541,7 +1541,7 @@ shows "(nres_of (?f::?'r dres), P_iter $ X0 $ h $ i $ PHI::'a set option nres) \ ?R" unfolding P_iter_def uncurry_rec_nat APP_def including art - by (autoref_monadic) + by autoref_monadic concrete_definition P_iter_impl for X0i hi i_i PHIi uses P_iter_impl lemmas [autoref_rules] = P_iter_impl.refine @@ -2197,10 +2197,11 @@ notes [autoref_rules] = autoref_parameters shows "(nres_of (?f::?'r dres), rk2_step $ (X::'a set) $ h) \ ?R" unfolding one_step_def rk2_step_def[abs_def] - by (autoref_monadic) + by autoref_monadic concrete_definition rk2_step_impl for Xi hi uses rk2_step_impl lemmas [autoref_rules] = rk2_step_impl.refine +ML_val \Autoref_Rules.get @{context} |> length\ definition "choose_step = (if method_id optns = 2 then rk2_step else euler_step)" sublocale autoref_op_pat_def choose_step . @@ -2211,7 +2212,7 @@ assumes [autoref_rules]: "(Xi, X) \ sappr_rel" "(hi, h) \ Id" shows "(nres_of (?f::?'r dres), choose_step $ (X::'a set) $ h) \ ?R" unfolding choose_step_def autoref_tag_defs cond_application_beta ncc_precond_def - by (autoref_monadic) + by autoref_monadic concrete_definition choose_step_impl for Xi hi uses choose_step_impl lemmas [autoref_rules] = choose_step_impl.refine @@ -2821,7 +2822,7 @@ unfolding autoref_tag_defs apply (rule nres_rel_trans2[OF intersects_sctns_spec_nres]) including art - by (autoref_monadic) + by autoref_monadic concrete_definition intersects_sctns_spec_impl for ai sctnsi uses intersects_sctns_spec_impl lemma intersects_sctns_spec_impl_refine[autoref_rules]: @@ -3605,7 +3606,7 @@ unfolding autoref_tag_defs unfolding fst_safe_coll_def including art - by (autoref_monadic) + by autoref_monadic concrete_definition fst_safe_coll_impl for XSi uses fst_safe_coll_impl lemmas [autoref_rules] = fst_safe_coll_impl.refine lemma fst_safe_coll[le, refine_vcg]: @@ -3724,7 +3725,7 @@ assumes [autoref_rules]: "(Xi, X::'a::executable_euclidean_space set) \ lvivl_rel" "(sctni, sctn) \ \lv_rel\sctn_rel" shows "(nres_of ?R, subset_spec_plane $ X $ sctn) \ \bool_rel\nres_rel" unfolding subset_spec_plane_def - by (autoref_monadic) + by autoref_monadic concrete_definition subset_spec_plane_impl for Xi sctni uses subset_spec_plane_impl lemmas [autoref_rules] = subset_spec_plane_impl.refine lemma subset_spec_plane[le, refine_vcg]: @@ -3832,7 +3833,7 @@ assumes [autoref_rules]: "(Xi, X::'a set) \ appr_rel" "(sctni, sctn) \ \lv_rel\sctn_rel" "(Si, S) \ lvivl_rel" shows "(nres_of ?R, op_eventually_within_sctn $ X $ sctn $ S) \ \bool_rel\nres_rel" unfolding op_eventually_within_sctn_def - by (autoref_monadic) + by autoref_monadic concrete_definition op_eventually_within_sctn_impl for Xi sctni Si uses op_eventually_within_sctn_impl lemmas [autoref_rules] = op_eventually_within_sctn_impl.refine @@ -4556,7 +4557,7 @@ unfolding autoref_tag_defs unfolding split_spec_param1_def including art - by (autoref_monadic) + by autoref_monadic concrete_definition split_spec_param1_impl for Xi uses split_spec_param1_impl lemma split_spec_param1_refine[autoref_rules]: "DIM_precond TYPE('n::enum rvec) D \ @@ -4749,7 +4750,7 @@ unfolding autoref_tag_defs unfolding split_spec_param1e_def including art - by (autoref_monadic) + by autoref_monadic concrete_definition split_spec_param1e_impl for Xi uses split_spec_param1e_impl lemma split_spec_param1e_refine[autoref_rules]: "DIM_precond TYPE('n::enum rvec) D \ @@ -4788,7 +4789,7 @@ if [autoref_rules]: "(Xi, X::'n eucl1 set) \ appr1_rel" "(Ci, C) \ reducer_rel" and [autoref_rules_raw]: "DIM_precond TYPE((real, 'n::enum) vec) D" unfolding reduce_spec1_def - by (autoref_monadic) + by autoref_monadic concrete_definition reduce_spec1_impl for Ci Xi uses reduce_spec1_impl lemma reduce_spec1_impl_refine[autoref_rules]: "(\C x. nres_of (reduce_spec1_impl C x), reduce_spec1::_\'n eucl1 set\_) \ @@ -4811,7 +4812,7 @@ and [autoref_rules_raw]: "DIM_precond TYPE((real, 'n::enum) vec) D" unfolding reduce_spec1e_def including art - by (autoref_monadic) + by autoref_monadic concrete_definition reduce_spec1e_impl for Ci Xi uses reduce_spec1e_impl lemma reduce_spec1e_impl_refine[autoref_rules]: "(\C x. nres_of (reduce_spec1e_impl C x), reduce_spec1e::_\'n eucl1 set\_) \ @@ -4846,7 +4847,7 @@ unfolding autoref_tag_defs unfolding split_under_threshold_def including art - by (autoref_monadic) + by autoref_monadic concrete_definition split_under_threshold_impl for ti thi Xi uses split_under_threshold_impl lemmas [autoref_rules] = split_under_threshold_impl.refine @@ -5216,7 +5217,7 @@ \clw_rel (iinfo_rel appr1e_rel) \\<^sub>r clw_rel appr_rel \\<^sub>r clw_rel (iinfo_rel appr1e_rel)\nres_rel" unfolding pre_intersection_step_def including art - by (autoref_monadic) + by autoref_monadic concrete_definition pre_intersection_step_impl for roptnsi Xi hi uses pre_intersection_step_impl lemmas [autoref_rules] = pre_intersection_step_impl.refine @@ -5623,7 +5624,7 @@ shows "(nres_of ?r, subset_iplane_coll $ x $ ics) \ \bool_rel\nres_rel" unfolding subset_iplane_coll_def including art - by (autoref_monadic) + by autoref_monadic concrete_definition subset_iplane_coll_impl uses subset_iplane_coll_impl lemmas [autoref_rules] = subset_iplane_coll_impl.refine @@ -5645,7 +5646,7 @@ shows "(nres_of ?r, subsets_iplane_coll $ x $ ics) \ \bool_rel\nres_rel" unfolding subsets_iplane_coll_def including art - by (autoref_monadic) + by autoref_monadic concrete_definition subsets_iplane_coll_impl uses subsets_iplane_coll_impl lemmas [autoref_rules] = subsets_iplane_coll_impl.refine @@ -5976,7 +5977,7 @@ shows "(nres_of ?r, leaves_halfspace $ S $ X) \ \\\lv_rel\sctn_rel\option_rel\nres_rel" unfolding leaves_halfspace_def including art - by (autoref_monadic) + by autoref_monadic concrete_definition leaves_halfspace_impl for Si Xi uses leaves_halfspace_impl lemmas [autoref_rules] = leaves_halfspace_impl.refine @@ -6778,7 +6779,7 @@ shows "(nres_of ?R, op_enlarge_ivl_sctn $ ivl $ sctn $ d) \ \lvivl_rel\nres_rel" unfolding op_enlarge_ivl_sctn_def including art - by (autoref_monadic) + by autoref_monadic concrete_definition op_enlarge_ivl_sctn_impl for ivli sctni di uses op_enlarge_ivl_sctn_impl lemmas [autoref_rules] = op_enlarge_ivl_sctn_impl.refine @@ -6882,7 +6883,7 @@ unfolding autoref_tag_defs unfolding resolve_ivlplanes_def including art - by (autoref_monadic) + by autoref_monadic concrete_definition resolve_ivlplanes_impl for guardsi ivlplanesi XSi uses resolve_ivlplanes_impl lemmas [autoref_rules] = resolve_ivlplanes_impl.refine @@ -7288,7 +7289,7 @@ unfolding autoref_tag_defs unfolding poincare_onto2_def including art - by (autoref_monadic) + by autoref_monadic concrete_definition poincare_onto2_impl for guardsi XSi uses poincare_onto2_impl lemmas [autoref_rules] = poincare_onto2_impl.refine @@ -7858,7 +7859,7 @@ assumes [autoref_rules]: "(FXSi, FXS) \ clw_rel lvivl_rel" "(Ai, A::'n::enum rvec set) \ lvivl_rel" shows "(nres_of ?r, op_single_inter_ivl A FXS) \ \clw_rel lvivl_rel\nres_rel" unfolding op_single_inter_ivl_def - by (autoref_monadic) + by autoref_monadic concrete_definition op_single_inter_ivl_impl for Ai FXSi uses op_single_inter_ivl_impl lemma op_single_inter_ivl_impl_refine[autoref_rules]: "DIM_precond TYPE((real, 'a::enum) vec) D \ @@ -7985,7 +7986,7 @@ shows "(nres_of ?r, vec1repse X) \ \\clw_rel appre_rel\option_rel\nres_rel" unfolding vec1repse_def including art - by (autoref_monadic) + by autoref_monadic concrete_definition vec1repse_impl for Xi uses vec1repse_impl lemmas vec1repse_impl_refine[autoref_rules] = vec1repse_impl.refine[autoref_higher_order_rule] @@ -8119,7 +8120,7 @@ unfolding autoref_tag_defs unfolding reduce_ivl_def including art - by (autoref_monadic) + by autoref_monadic concrete_definition reduce_ivl_impl for Yi bi uses reduce_ivl_impl lemmas [autoref_rules] = reduce_ivl_impl.refine @@ -8259,7 +8260,7 @@ unfolding autoref_tag_defs unfolding reduce_ivle_def including art - by (autoref_monadic) + by autoref_monadic concrete_definition reduce_ivle_impl for Yi bi uses reduce_ivle_impl lemmas [autoref_rules] = reduce_ivle_impl.refine @@ -9100,7 +9101,7 @@ unfolding autoref_tag_defs unfolding poincare_onto_from_def including art - by (autoref_monadic) + by autoref_monadic concrete_definition poincare_onto_from_impl for symstartd Si guardsi ivli sctni roi XSi uses poincare_onto_from_impl lemmas [autoref_rules] = poincare_onto_from_impl.refine @@ -9221,7 +9222,7 @@ "(dPi, dP) \ \lvivl_rel\(default_rel UNIV)" unfolding subset_spec1_def including art - by (autoref_monadic) + by autoref_monadic lemmas [autoref_rules] = subset_spec1_impl[autoref_higher_order_rule] lemma subset_spec1[refine_vcg]: "subset_spec1 R P dP \ SPEC (\b. b \ R \ flow1_of_vec1 ` (P \ dP))" @@ -9449,7 +9450,7 @@ shows "(nres_of ?r, one_step_until_time_ivl $ X0 $ ph $ t1 $ t2) \ \appr1e_rel \\<^sub>r \clw_rel appr_rel\phantom_rel\nres_rel" unfolding one_step_until_time_ivl_def including art - by (autoref_monadic) + by autoref_monadic concrete_definition one_step_until_time_ivl_impl for X0i phi t1i t2i uses one_step_until_time_ivl_impl lemmas [autoref_rules] = one_step_until_time_ivl_impl.refine @@ -9584,7 +9585,7 @@ unfolding autoref_tag_defs unfolding init_ode_solver_def including art - by (autoref_monadic) + by autoref_monadic concrete_definition init_ode_solveri uses init_ode_solver_autoref lemmas [autoref_rules] = init_ode_solveri.refine @@ -9714,7 +9715,7 @@ unfolding autoref_tag_defs unfolding solve_one_step_until_timea_def including art - by (autoref_monadic) + by autoref_monadic concrete_definition solve_one_step_until_time for X0i CXi t1i t2i uses solve_one_step_until_time_autoref lemmas solve_one_step_until_time_refine[autoref_rules] = solve_one_step_until_time.refine @@ -9887,7 +9888,7 @@ unfolding autoref_tag_defs unfolding poincare_onto_from_in_ivl_def including art - by (autoref_monadic) + by autoref_monadic concrete_definition poincare_onto_from_in_ivl_impl for symstarti Si guardsi ivli sctni roi XSi Pimpl dPi uses poincare_onto_from_in_ivl_impl lemmas [autoref_rules] = poincare_onto_from_in_ivl_impl.refine @@ -10053,7 +10054,7 @@ shows "(nres_of ?r, one_step_until_time_ivl_in_ivl X0 t1 t2 R dR) \ \bool_rel\nres_rel" unfolding one_step_until_time_ivl_in_ivl_def including art - by (autoref_monadic) + by autoref_monadic concrete_definition one_step_until_time_ivl_in_ivl_impl for X0i t1i t2i Ri dRi uses one_step_until_time_ivl_in_ivl_impl lemmas one_step_until_time_ivl_in_ivl_impl_refine[autoref_rules] = one_step_until_time_ivl_in_ivl_impl.refine diff -r efd58f8b1659 thys/Ordinary_Differential_Equations/Refinement/Refine_String.thy --- a/thys/Ordinary_Differential_Equations/Refinement/Refine_String.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/Ordinary_Differential_Equations/Refinement/Refine_String.thy Tue Apr 24 11:35:45 2018 +0200 @@ -3,19 +3,11 @@ Autoref_Misc begin -subsection \Setup for literals\ -context begin interpretation autoref_syn . -lemma [autoref_itype]: "STR x ::\<^sub>i I" - and [autoref_op_pat_def]: "STR x \ OP (STR x) :::\<^sub>i I" - and [autoref_rules]: "(STR x, OP (STR x) ::: Id) \ Id" - by simp_all -end - subsection \Setup for characters\ context begin interpretation autoref_syn . -lemma [autoref_itype]: "Char x ::\<^sub>i I" - and [autoref_op_pat_def]: "Char x \ OP (Char x) :::\<^sub>i I" - and [autoref_rules]: "(Char x, OP (Char x) ::: Id) \ Id" +lemma [autoref_itype]: "Char b0 b1 b2 b3 b4 b5 b6 b7 ::\<^sub>i I" + and [autoref_op_pat_def]: "Char b0 b1 b2 b3 b4 b5 b6 b7 \ OP (Char b0 b1 b2 b3 b4 b5 b6 b7) :::\<^sub>i I" + and [autoref_rules]: "(Char b0 b1 b2 b3 b4 b5 b6 b7, OP (Char b0 b1 b2 b3 b4 b5 b6 b7) ::: Id) \ Id" by simp_all end @@ -50,4 +42,24 @@ by (simp_all add: string_rel_def) end +subsection \Setup for literals\ +context begin interpretation autoref_syn . +lemma [autoref_itype]: "String.empty_literal ::\<^sub>i I" + and [autoref_op_pat_def]: "String.empty_literal \ OP String.empty_literal :::\<^sub>i I" + and [autoref_rules]: "(String.empty_literal, OP String.empty_literal ::: Id) \ Id" + by simp_all + +lemma [autoref_itype]: "String.Literal b0 b1 b2 b3 b4 b5 b6 s ::\<^sub>i I" + and [autoref_op_pat_def]: "String.Literal b0 b1 b2 b3 b4 b5 b6 s \ + OP (String.Literal b0 b1 b2 b3 b4 b5 b6 s) :::\<^sub>i I" + and [autoref_rules]: "(String.Literal b0 b1 b2 b3 b4 b5 b6 s, + OP (String.Literal b0 b1 b2 b3 b4 b5 b6 s) ::: Id) \ Id" + by simp_all end + +text \A little check\ + +schematic_goal "(?c::?'c, RETURN (STR '''', STR ''Hello''))\?R" + by autoref + +end diff -r efd58f8b1659 thys/Paraconsistency/Paraconsistency.thy --- a/thys/Paraconsistency/Paraconsistency.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/Paraconsistency/Paraconsistency.thy Tue Apr 24 11:35:45 2018 +0200 @@ -183,8 +183,8 @@ fun string_of_nat :: "nat \ string" where - "string_of_nat n = (if n < 10 then [char_of_nat (48 + n)] else - string_of_nat (n div 10) @ [char_of_nat (48 + (n mod 10))])" + "string_of_nat n = (if n < 10 then [char_of (48 + n)] else + string_of_nat (n div 10) @ [char_of (48 + (n mod 10))])" fun string_tv :: "tv \ string" where diff -r efd58f8b1659 thys/Promela/Promela.thy --- a/thys/Promela/Promela.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/Promela/Promela.thy Tue Apr 24 11:35:45 2018 +0200 @@ -28,7 +28,7 @@ "add_label l lbls pos = ( case lm.lookup l lbls of None \ lm.update l pos lbls - | Some _ \ abortv ''Label given twice: '' l (\_. lbls))" + | Some _ \ abortv STR ''Label given twice: '' l (\_. lbls))" definition min_prio :: "edge list \ integer \ integer" where "min_prio es start = Min ((prio ` set es) \ {start})" @@ -80,7 +80,7 @@ fun lookupVar :: "variable \ integer option \ integer" where "lookupVar (Var _ val) None = val" -| "lookupVar (Var _ _) (Some _) = abort ''Array used on var'' (\_.0)" +| "lookupVar (Var _ _) (Some _) = abort STR ''Array used on var'' (\_.0)" | "lookupVar (VArray _ _ vals) None = vals !! 0" (* sic! *) | "lookupVar (VArray _ siz vals) (Some idx) = vals !! nat_of_integer idx" @@ -91,10 +91,10 @@ if lRange = 0 \ val > 0 then val mod (hRange + 1) else \ \we do not want to implement C-semantics (ie type casts)\ - abort ''Value overflow'' (\_. lRange))" + abort STR ''Value overflow'' (\_. lRange))" | "checkVarValue VTChan val = ( if val < min_var_value \ val > max_var_value - then abort ''Value overflow'' (\_. 0) + then abort STR ''Value overflow'' (\_. 0) else val)" lemma [simp]: @@ -124,7 +124,7 @@ fun editVar :: "variable \ integer option \ integer \ variable" where "editVar (Var type _ ) None val = Var type (checkVarValue type val)" -| "editVar (Var _ _) (Some _) _ = abort ''Array used on var'' (\_. Var VTChan 0)" +| "editVar (Var _ _) (Some _) _ = abort STR ''Array used on var'' (\_. Var VTChan 0)" | "editVar (VArray type siz vals) None val = ( let lv = IArray.list_of vals in let v' = lv[0:=checkVarValue type val] in @@ -180,13 +180,13 @@ if gl then if v = STR ''_'' then (g,p) \ \\''_''\ is a write-only scratch variable\ else case lm.lookup v (gState.vars g) of - None \ abortv ''Unknown global variable: '' v (\_. (g,p)) + None \ abortv STR ''Unknown global variable: '' v (\_. (g,p)) | Some x \ (g\gState.vars := lm.update v (editVar x idx val) (gState.vars g)\ , p) else case lm.lookup v (pState.vars p) of - None \ abortv ''Unknown proc variable: '' v (\_. (g,p)) + None \ abortv STR ''Unknown proc variable: '' v (\_. (g,p)) | Some x \ (g, p\pState.vars := lm.update v (editVar x idx val) (pState.vars p)\))" @@ -266,9 +266,9 @@ \ 'x" where "withChannel' gl v idx f g p = ( - let error = \_. abortv ''Variable is not a channel: '' v + let error = \_. abortv STR ''Variable is not a channel: '' v (\_. f 0 InvChannel) in - let abort = \_. abortv ''Channel already closed / invalid: '' v + let abort = \_. abortv STR ''Channel already closed / invalid: '' v (\_. f 0 InvChannel) in withVar' gl v idx (\i. let i = nat_of_integer i in if i \ length (channels g) then error () @@ -391,7 +391,7 @@ \_ c. pollCheck g p c rs srt) g p)" | "pollCheck g p InvChannel _ _ = - abort ''Channel already closed / invalid.'' (\_. False)" + abort STR ''Channel already closed / invalid.'' (\_. False)" | "pollCheck g p (HSChannel _) _ _ = False" | "pollCheck g p (Channel _ _ q) rs srt = ( if q = [] then False @@ -400,9 +400,9 @@ | "recvArgsCheck _ _ [] [] = True" | "recvArgsCheck _ _ _ [] = - abort ''Length mismatch on receiving.'' (\_. False)" + abort STR ''Length mismatch on receiving.'' (\_. False)" | "recvArgsCheck _ _ [] _ = - abort ''Length mismatch on receiving.'' (\_. False)" + abort STR ''Length mismatch on receiving.'' (\_. False)" | "recvArgsCheck g p (r#rs) (v#vs) = (( case r of RecvArgConst c \ c = v @@ -465,7 +465,7 @@ where "toVariable g p (VarDeclNum lb hb name siz init) = ( let type = VTBounded lb hb in - if \ varType_inv type then abortv ''Invalid var def (varType_inv failed): '' name + if \ varType_inv type then abortv STR ''Invalid var def (varType_inv failed): '' name (\_. (name, Var VTChan 0, [])) else let @@ -477,7 +477,7 @@ | Some s \ if nat_of_integer s \ max_array_size then VArray type (nat_of_integer s) (IArray.tabulate (s, \_. init)) - else abortv ''Invalid var def (array too large): '' name + else abortv STR ''Invalid var def (array too large): '' name (\_. Var VTChan 0)) in (name, v, []))" @@ -491,7 +491,7 @@ let C = (if cap = 0 then HSChannel tys else Channel cap tys []) in if \ channel_inv C - then abortv ''Invalid var def (channel_inv failed): '' + then abortv STR ''Invalid var def (channel_inv failed): '' name (\_. []) else replicate size C); cidx = (case types of @@ -504,7 +504,7 @@ (IArray.tabulate (s, \i. if cidx = 0 then 0 else i + cidx)) - else abortv ''Invalid var def (array too large): '' + else abortv STR ''Invalid var def (array too large): '' name (\_. Var VTChan 0)) in (name, v, chans))" @@ -544,7 +544,7 @@ if cs = [] then (g,p) else let l = length (channels g) in if l + length cs > max_channels - then abort ''Too much channels'' (\_. (g,p)) + then abort STR ''Too much channels'' (\_. (g,p)) else let cs\<^sub>p = map integer_of_nat [l..channels := channels g @ cs\; @@ -793,7 +793,7 @@ (ProcArg ty name, val) \ if varType_inv ty then let init = checkVarValue ty val in (name, Var ty init) - else abortv ''Invalid proc arg (varType_inv failed)'' + else abortv STR ''Invalid proc arg (varType_inv failed)'' name (\_. (name, Var VTChan 0)))" definition emptyProc :: "pState" @@ -829,11 +829,11 @@ "mkProc g p name args (sidx, start, argDecls, decls) pidN = ( let start = case start of Index x \ x - | _ \ abortv ''Process start is not index: '' name (\_. 0) + | _ \ abortv STR ''Process start is not index: '' name (\_. 0) in \ \sanity check\ if length args \ length argDecls - then abortv ''Signature mismatch: '' name (\_. (g,emptyProc)) + then abortv STR ''Signature mismatch: '' name (\_. (g,emptyProc)) else let \ \evaluate args (in the context of the calling process)\ @@ -1041,10 +1041,10 @@ where "runProc name args prog g p = ( if length (procs g) \ max_procs - then abort ''Too many processes'' (\_. (g,p)) + then abort STR ''Too many processes'' (\_. (g,p)) else let pid = length (procs g) + 1 in case lm.lookup name (proc_data prog) of - None \ abortv ''No such process: '' name + None \ abortv STR ''No such process: '' name (\_. (g,p)) | Some proc_idx \ let (g', proc) = mkProc g p name args (processes prog !! proc_idx) pid @@ -1275,7 +1275,7 @@ ([[\cond = ECTrue, effect = EEGoto, target = onxt, prio = pri, atomic = NonAtomic \]], onxt, lbls)" | "stmntToState StmntBreak (_,_,_,_,None,_) = - abort ''Misplaced break'' (\_. ([],Index 0,lm.empty()))" + abort STR ''Misplaced break'' (\_. ([],Index 0,lm.empty()))" | "stmntToState (StmntRun n args) (lbls, pri, pos, nxt, onxt, _) = ([[\cond = ECRun n, effect = EERun n args, target = nxt, prio = pri, @@ -1304,7 +1304,7 @@ definition resolveLabel :: "String.literal \ labels \ nat" where "resolveLabel l lbls = ( case lm.lookup l lbls of - None \ abortv ''Unresolved label: '' l (\_. 0) + None \ abortv STR ''Unresolved label: '' l (\_. 0) | Some pos \ pos)" primrec resolveLabels :: "edge list list \ labels \ edge list \ edge list" where @@ -1347,7 +1347,7 @@ in case pos of Index s \ if s < length states then (IArray states, pos, lbls) - else abort ''Start index out of bounds'' (\_. (IArray states, Index 0, lbls)))" + else abort STR ''Start index out of bounds'' (\_. (IArray states, Index 0, lbls)))" lemma toStates_inv: assumes "toStates steps = (ss,start,lbls)" @@ -1535,9 +1535,9 @@ where "evalRecvArgs [] [] g l = (g,l)" | "evalRecvArgs _ [] g l = - abort ''Length mismatch on receiving.'' (\_. (g,l))" + abort STR ''Length mismatch on receiving.'' (\_. (g,l))" | "evalRecvArgs [] _ g l = - abort ''Length mismatch on receiving.'' (\_. (g,l))" + abort STR ''Length mismatch on receiving.'' (\_. (g,l))" | "evalRecvArgs (r#rs) (v#vs) g l = ( let (g,l) = case r of @@ -1589,11 +1589,11 @@ else (g,l))" | "evalEffect (EESend v es srt) _ g l = withChannel v (\i c. let - ab = \_. abort ''Length mismatch on sending.'' (\_. (g,l)); + ab = \_. abort STR ''Length mismatch on sending.'' (\_. (g,l)); es = map (exprArith g l) es in if \ for_all (\x. x \ min_var_value \ x \ max_var_value) es - then abort ''Invalid Channel'' (\_. (g,l)) + then abort STR ''Invalid Channel'' (\_. (g,l)) else case c of Channel cap ts q \ @@ -1611,12 +1611,12 @@ | HSChannel ts \ if length ts \ length es then ab() else (g\hsdata := es, handshake := i\, l) - | InvChannel \ abort ''Trying to send on invalid channel'' (\_. (g,l)) + | InvChannel \ abort STR ''Trying to send on invalid channel'' (\_. (g,l)) ) g l" | "evalEffect (EERecv v rs srt rem) _ g l = withChannel v (\i c. case c of Channel cap ts qs \ - if qs = [] then abort ''Recv from empty channel'' (\_. (g,l)) + if qs = [] then abort STR ''Recv from empty channel'' (\_. (g,l)) else let (q', qs') = if \ srt then (hd qs, tl qs) @@ -1631,7 +1631,7 @@ let (g,l) = evalRecvArgs rs (hsdata g) g l in let g = g\ handshake := 0, hsdata := [] \ in (g,l) - | InvChannel \ abort ''Receiving on invalid channel'' (\_. (g,l)) + | InvChannel \ abort STR ''Receiving on invalid channel'' (\_. (g,l)) ) g l" lemma statesDecls_effect: @@ -1934,7 +1934,7 @@ "sort_by_pri min_pri edges = foldl (\es e. let idx = nat_of_integer (abs (prio e)) in if idx > min_pri - then abort ''Invalid priority'' (\_. es) + then abort STR ''Invalid priority'' (\_. es) else let ep = e # (es ! idx) in es[idx := ep] ) (replicate (min_pri + 1) []) edges" @@ -2248,8 +2248,8 @@ let p'' = (case target e of Index t \ if t < IArray.length (states prog !! pState.idx p') then p'\pc := t\ - else abort ''Edge target out of bounds'' (\_. p') - | _ \ abort ''Edge target not Index'' (\_. p')); + else abort STR ''Edge target out of bounds'' (\_. p') + | _ \ abort STR ''Edge target not Index'' (\_. p')); ASSERT (pState_inv prog p''); let g'' = g'\procs := list_update (procs g') (pid p'' - 1) p''\; @@ -2558,7 +2558,7 @@ if E = [] then if check g then RETURN [] else if \ timeout g then D (g\timeout := True\) - else abort ''Stuttering should not occur on replay'' + else abort STR ''Stuttering should not occur on replay'' (\_. RETURN []) else let g = reset\<^sub>I g in diff -r efd58f8b1659 thys/Promela/PromelaDatastructures.thy --- a/thys/Promela/PromelaDatastructures.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/Promela/PromelaDatastructures.thy Tue Apr 24 11:35:45 2018 +0200 @@ -130,20 +130,17 @@ consts warn :: "String.literal \ unit" -abbreviation "with_warn msg e \ let _ = warn (STR msg) in e" -abbreviation "the_warn opt msg \ case opt of None \ () | _ \ warn (STR msg)" +abbreviation "with_warn msg e \ let _ = warn msg in e" +abbreviation "the_warn opt msg \ case opt of None \ () | _ \ warn msg" text {* @{text usc}: "Unsupported Construct" *} -definition [code del]: "usc' c \ undefined" -abbreviation "usc c \ usc' (STR c)" +definition [code del]: "usc (c :: String.literal) \ undefined" -definition [code del]: "err' e = undefined" -abbreviation "err e \ err' (STR e)" -abbreviation "errv e v \ err' (STR e @@ v)" +definition [code del]: "err (e :: String.literal) = undefined" +abbreviation "errv e v \ err (e + v)" -definition [simp, code del]: "abort' msg f = f ()" -abbreviation "abort msg f \ abort' (STR msg) f" -abbreviation "abortv msg v f \ abort' (STR msg @@ v) f" +definition [simp, code del]: "abort (msg :: String.literal) f = f ()" +abbreviation "abortv msg v f \ abort (msg + v) f" code_printing code_module PromelaUtils \ (SML) {* @@ -157,9 +154,9 @@ fun abort msg _ = raise (RuntimeError msg) end *} | constant warn \ (SML) "PromelaUtils.warn" -| constant usc' \ (SML) "PromelaUtils.usc" -| constant err' \ (SML) "PromelaUtils.err" -| constant abort' \ (SML) "PromelaUtils.abort" +| constant usc \ (SML) "PromelaUtils.usc" +| constant err \ (SML) "PromelaUtils.err" +| constant abort \ (SML) "PromelaUtils.abort" code_reserved SML PromelaUtils @@ -184,17 +181,17 @@ | "ppBinOp AST.BinOpNEq = BinOpNEq" | "ppBinOp AST.BinOpAnd = BinOpAnd" | "ppBinOp AST.BinOpOr = BinOpOr" -| "ppBinOp AST.BinOpBitAnd = usc ''BinOpBitAnd''" -| "ppBinOp AST.BinOpBitXor = usc ''BinOpBitXor''" -| "ppBinOp AST.BinOpBitOr = usc ''BinOpBitOr''" -| "ppBinOp AST.BinOpShiftL = usc ''BinOpShiftL''" -| "ppBinOp AST.BinOpShiftR = usc ''BinOpShiftR''" +| "ppBinOp AST.BinOpBitAnd = usc STR ''BinOpBitAnd''" +| "ppBinOp AST.BinOpBitXor = usc STR ''BinOpBitXor''" +| "ppBinOp AST.BinOpBitOr = usc STR ''BinOpBitOr''" +| "ppBinOp AST.BinOpShiftL = usc STR ''BinOpShiftL''" +| "ppBinOp AST.BinOpShiftR = usc STR ''BinOpShiftR''" primrec ppUnOp :: "AST.unOp \ unOp" where "ppUnOp AST.UnOpMinus = UnOpMinus" | "ppUnOp AST.UnOpNeg = UnOpNeg" -| "ppUnOp AST.UnOpComp = usc ''UnOpComp''" +| "ppUnOp AST.UnOpComp = usc STR ''UnOpComp''" text {* The data structure holding all information on variables we found so far. *} type_synonym var_data = " @@ -217,15 +214,15 @@ in case lm.lookup n m of Some i \ (case idx of None \ fM i - | _ \ err ''Array subscript used on MType (via alias).'') + | _ \ err STR ''Array subscript used on MType (via alias).'') | None \ (case lm.lookup n v of Some g \ fV n g idx | None \ (case lm.lookup n c of Some g \ fC n g idx - | None \ err' (STR ''Unknown variable referenced: '' + n))))" + | None \ err (STR ''Unknown variable referenced: '' + n))))" primrec enforceChan :: "varRef + chanRef \ chanRef" where - "enforceChan (Inl _) = err ''Channel expected. Got normal variable.''" + "enforceChan (Inl _) = err STR ''Channel expected. Got normal variable.''" | "enforceChan (Inr c) = c" fun liftChan :: "varRef + chanRef \ varRef" where @@ -237,7 +234,7 @@ "resolveIdx None None = None" | "resolveIdx idx None = idx" | "resolveIdx None aliasIdx = aliasIdx" -| "resolveIdx _ _ = err ''Array subscript used twice (via alias).''" +| "resolveIdx _ _ = err STR ''Array subscript used twice (via alias).''" fun ppExpr :: "var_data \ AST.expr \ expr" and ppVarRef :: "var_data \ AST.varRef \ varRef + chanRef" @@ -248,9 +245,9 @@ Inr (ChanRef (VarRef g name (resolveIdx idx aIdx)))) (\name (_,g) aIdx. let idx = map_option (ppExpr cvm) idx in Inl (VarRef g name (resolveIdx idx aIdx))) - (\_. err ''Variable expected. Got MType.'')" + (\_. err STR ''Variable expected. Got MType.'')" | "ppVarRef cvm (AST.VarRef _ _ (Some _)) = - usc ''next operation on variables''" + usc STR ''next operation on variables''" | "ppExpr cvm AST.ExprTimeOut = ExprTimeOut" | "ppExpr cvm (AST.ExprConst c) = ExprConst c" @@ -290,12 +287,12 @@ | "ppExpr cvm (AST.ExprRndPoll v es) = ExprPoll (enforceChan (ppVarRef cvm v)) (map (ppRecvArg cvm) es) True" -| "ppExpr cvm AST.ExprNP = usc ''ExprNP''" -| "ppExpr cvm (AST.ExprEnabled _) = usc ''ExprEnabled''" -| "ppExpr cvm (AST.ExprPC _) = usc ''ExprPC''" -| "ppExpr cvm (AST.ExprRemoteRef _ _ _) = usc ''ExprRemoteRef''" -| "ppExpr cvm (AST.ExprGetPrio _) = usc ''ExprGetPrio''" -| "ppExpr cvm (AST.ExprSetPrio _ _) = usc ''ExprSetPrio''" +| "ppExpr cvm AST.ExprNP = usc STR ''ExprNP''" +| "ppExpr cvm (AST.ExprEnabled _) = usc STR ''ExprEnabled''" +| "ppExpr cvm (AST.ExprPC _) = usc STR ''ExprPC''" +| "ppExpr cvm (AST.ExprRemoteRef _ _ _) = usc STR ''ExprRemoteRef''" +| "ppExpr cvm (AST.ExprGetPrio _) = usc STR ''ExprGetPrio''" +| "ppExpr cvm (AST.ExprSetPrio _ _) = usc STR ''ExprSetPrio''" | "ppRecvArg cvm (AST.RecvArgVar v) = ( let to_ra = \_. RecvArgVar (liftChan (ppVarRef cvm v)) in @@ -318,8 +315,8 @@ | "ppVarType AST.VarTypeInt = VTBounded (-(2^31)) ((2^31) - 1)" | "ppVarType AST.VarTypeMType = VTBounded 1 255" | "ppVarType AST.VarTypeChan = VTChan" -| "ppVarType AST.VarTypeUnsigned = usc ''VarTypeUnsigned''" -| "ppVarType (AST.VarTypeCustom _) = usc ''VarTypeCustom''" +| "ppVarType AST.VarTypeUnsigned = usc STR ''VarTypeUnsigned''" +| "ppVarType (AST.VarTypeCustom _) = usc STR ''VarTypeCustom''" fun ppVarDecl :: "var_data \ varType \ bool \ AST.varDecl \ var_data \ varDecl" @@ -327,47 +324,47 @@ "ppVarDecl (c,v,m,a) (VTBounded l h) g (AST.VarDeclNum name sze init) = ( case lm.lookup name v of - Some _ \ errv ''Duplicate variable '' name + Some _ \ errv STR ''Duplicate variable '' name | _ \ (case lm.lookup name a of Some _ \ errv - ''Variable name clashes with alias: '' name + STR ''Variable name clashes with alias: '' name | _ \ ((c, lm.update name (sze,g) v, m, a), VarDeclNum l h name sze (map_option (ppExpr (c,v,m,a)) init))))" | "ppVarDecl _ _ g (AST.VarDeclNum name sze init) = - err ''Assiging num to non-num''" + err STR ''Assiging num to non-num''" | "ppVarDecl (c,v,m,a) VTChan g (AST.VarDeclChan name sze cap) = ( let cap' = map_option (apsnd (map ppVarType)) cap in case lm.lookup name c of - Some _ \ errv ''Duplicate variable '' name + Some _ \ errv STR ''Duplicate variable '' name | _ \ (case lm.lookup name a of Some _ \ errv - ''Variable name clashes with alias: '' name + STR ''Variable name clashes with alias: '' name | _ \ ((lm.update name (sze, g) c, v, m, a), VarDeclChan name sze cap')))" | "ppVarDecl _ _ g (AST.VarDeclChan name sze init) = - err ''Assiging chan to non-chan''" + err STR ''Assiging chan to non-chan''" | "ppVarDecl (c,v,m,a) (VTBounded l h) g (AST.VarDeclMType name sze init) = ( let init = map_option (\mty. case lm.lookup mty m of - None \ errv ''Unknown MType '' mty + None \ errv STR ''Unknown MType '' mty | Some mval \ ExprMConst mval mty) init in case lm.lookup name c of - Some _ \ errv ''Duplicate variable '' name + Some _ \ errv STR ''Duplicate variable '' name | _ \ (case lm.lookup name a of Some _ - \ errv ''Variable name clashes with alias: '' name + \ errv STR ''Variable name clashes with alias: '' name | _ \ ((c, lm.update name (sze,g) v, m, a), VarDeclNum l h name sze init)))" | "ppVarDecl _ _ g (AST.VarDeclMType name sze init) = - err ''Assiging num to non-num''" + err STR ''Assiging num to non-num''" | "ppVarDecl _ _ _ (AST.VarDeclUnsigned _ _ _) = - usc ''VarDeclUnsigned''" + usc STR ''VarDeclUnsigned''" definition ppProcVarDecl :: "var_data \ varType \ bool \ AST.varDecl \ var_data \ procVarDecl" @@ -375,7 +372,7 @@ "ppProcVarDecl cvm ty g v = (case ppVarDecl cvm ty g v of (cvm, VarDeclNum l h name sze init) \ (cvm, ProcVarDeclNum l h name sze init) | (cvm, VarDeclChan name sze None) \ (cvm, ProcVarDeclChan name sze) - | _ \ err ''Channel initilizations only allowed at the beginning of proctypes.'')" + | _ \ err STR ''Channel initilizations only allowed at the beginning of proctypes.'')" fun ppProcArg :: "var_data \ varType \ bool \ AST.varDecl \ var_data \ procArg" @@ -383,39 +380,39 @@ "ppProcArg (c,v,m,a) (VTBounded l h) g (AST.VarDeclNum name None None) = ( case lm.lookup name v of - Some _ \ errv ''Duplicate variable '' name + Some _ \ errv STR ''Duplicate variable '' name | _ \ (case lm.lookup name a of Some _ \ errv - ''Variable name clashes with alias: '' name + STR ''Variable name clashes with alias: '' name | _ \ ((c, lm.update name (None, g) v, m, a), ProcArg (VTBounded l h) name)))" | "ppProcArg _ _ _ (AST.VarDeclNum _ _ _) = - err ''Invalid proctype arguments''" + err STR ''Invalid proctype arguments''" | "ppProcArg (c,v,m,a) VTChan g (AST.VarDeclChan name None None) = ( case lm.lookup name c of - Some _ \ errv ''Duplicate variable '' name + Some _ \ errv STR ''Duplicate variable '' name | _ \ (case lm.lookup name a of Some _ \ errv - ''Variable name clashes with alias: '' name + STR ''Variable name clashes with alias: '' name | _ \ ((lm.update name (None, g) c, v, m, a), ProcArg VTChan name)))" | "ppProcArg _ _ _ (AST.VarDeclChan _ _ _) = - err ''Invalid proctype arguments''" + err STR ''Invalid proctype arguments''" | "ppProcArg (c,v,m,a) (VTBounded l h) g (AST.VarDeclMType name None None) = ( case lm.lookup name v of - Some _ \ errv ''Duplicate variable '' name + Some _ \ errv STR ''Duplicate variable '' name | _ \ (case lm.lookup name a of Some _ \ errv - ''Variable name clashes with alias: '' name + STR ''Variable name clashes with alias: '' name | _ \ ((c, lm.update name (None, g) v, m, a), ProcArg (VTBounded l h) name)))" | "ppProcArg _ _ _ (AST.VarDeclMType _ _ _) = - err ''Invalid proctype arguments''" + err STR ''Invalid proctype arguments''" -| "ppProcArg _ _ _ (AST.VarDeclUnsigned _ _ _) = usc ''VarDeclUnsigned''" +| "ppProcArg _ _ _ (AST.VarDeclUnsigned _ _ _) = usc STR ''VarDeclUnsigned''" text {* Some preprocessing functions enrich the @{typ var_data} argument and hence return a new updated one. When chaining multiple calls to such functions after another, we need to make @@ -437,7 +434,7 @@ fun liftDecl where "liftDecl f g cvm (AST.Decl vis t decls) = ( - let _ = the_warn vis ''Visibility in declarations not supported. Ignored.'' in + let _ = the_warn vis STR ''Visibility in declarations not supported. Ignored.'' in let t = ppVarType t in cvm_fold (\cvm. f cvm t g) cvm decls)" @@ -622,9 +619,9 @@ let (cvm', ps') = ppDecl False cvm d in ((True, ps@ps', i, cvm'), StepSkip))" | "ppStep (_,cvm) (AST.StepXR _) = - with_warn ''StepXR not supported. Ignored.'' ((False,cvm), StepSkip)" + with_warn STR ''StepXR not supported. Ignored.'' ((False,cvm), StepSkip)" | "ppStep (_,cvm) (AST.StepXS _) = - with_warn ''StepXS not supported. Ignored.'' ((False,cvm), StepSkip)" + with_warn STR ''StepXS not supported. Ignored.'' ((False,cvm), StepSkip)" | "ppStmnt (_,cvm) (AST.StmntBreak) = ((False,cvm), StmntBreak)" | "ppStmnt (_,cvm) (AST.StmntElse) = ((False,cvm), StmntElse)" @@ -656,7 +653,7 @@ ((False,ps,i,cvm), StmntRecv (enforceChan (ppVarRef cvm v)) (map (ppRecvArg cvm) rs) True False)" | "ppStmnt (_,ps,i,cvm) (AST.StmntRun n es p) = ( - let _ = the_warn p ''Priorities for 'run' not supported. Ignored.'' in + let _ = the_warn p STR ''Priorities for 'run' not supported. Ignored.'' in ((False,ps,i,cvm), StmntRun n (map (ppExpr cvm) es)))" | "ppStmnt (_,cvm) (AST.StmntSeq ss) = apsnd StmntSeq (cvm_fold ppStep (False,cvm) ss)" @@ -674,9 +671,9 @@ ((False,ps,i,cvm), decr (liftChan (ppVarRef cvm v)))" | "ppStmnt (_,cvm) (AST.StmntPrintF _ _) = - with_warn ''PrintF ignored'' ((False,cvm), StmntSkip)" + with_warn STR ''PrintF ignored'' ((False,cvm), StmntSkip)" | "ppStmnt (_,cvm) (AST.StmntPrintM _) = - with_warn ''PrintM ignored'' ((False,cvm), StmntSkip)" + with_warn STR ''PrintM ignored'' ((False,cvm), StmntSkip)" | "ppStmnt (_,ps,inl,cvm) (AST.StmntFor (AST.RangeFromTo i lb ub) @@ -695,11 +692,11 @@ in case ppVarRef cvm v of Inr c \ (cvm', forInChan i c steps) - | Inl (VarRef _ _ (Some _)) \ err ''Iterating over array-member.'' + | Inl (VarRef _ _ (Some _)) \ err STR ''Iterating over array-member.'' | Inl (VarRef _ name None) \ ( let (_,v,_) = cvm in case fst (the (lm.lookup name v)) of - None \ err ''Iterating over non-array variable.'' + None \ err STR ''Iterating over non-array variable.'' | Some N \ (cvm', forInArray i N steps)))" | "ppStmnt (_,ps,inl,cvm) (AST.StmntSelect @@ -710,7 +707,7 @@ in ((False,ps,inl,cvm), select i lb ub))" | "ppStmnt (_,cvm) (AST.StmntSelect (AST.RangeIn _ _)) = - err ''\"in\" not allowed in select''" + err STR ''\"in\" not allowed in select''" | "ppStmnt (_,ps,inl,cvm) (AST.StmntCall macro args) = ( let @@ -718,16 +715,16 @@ (c,v,m,a) = cvm in case lm.lookup macro inl of - None \ errv ''Calling unknown macro '' macro + None \ errv STR ''Calling unknown macro '' macro | Some (names,sF) \ if length names \ length args then - (err ''Called macro with wrong number of arguments.'') + (err STR ''Called macro with wrong number of arguments.'') else let a' = foldl (\a (k,v). lm.update k v a) a (zip names args) in let ((c,v,m,_),steps) = sF (c,v,m,a') in ((False,ps,inl,c,v,m,a), StmntSeq steps))" -| "ppStmnt cvm (AST.StmntDStep _) = usc ''StmntDStep''" +| "ppStmnt cvm (AST.StmntDStep _) = usc STR ''StmntDStep''" fun ppModule :: "var_data \ inlines \ AST.module @@ -735,15 +732,15 @@ where "ppModule (cvm, inl) (AST.ProcType act name args prio prov steps) = ( let - _ = the_warn prio ''Priorities for procs not supported. Ignored.''; - _ = the_warn prov ''Priov (??) for procs not supported. Ignored.''; + _ = the_warn prio STR ''Priorities for procs not supported. Ignored.''; + _ = the_warn prov STR ''Priov (??) for procs not supported. Ignored.''; (cvm', args) = cvm_fold ppDeclProcArg cvm args; ((_, vars, _, _), steps) = cvm_fold ppStep (True,[],inl,cvm') steps in (cvm, inl, Inr (Inl (ProcType act name (concat args) vars steps))))" | "ppModule (cvm,inl) (AST.Init prio steps) = ( - let _ = the_warn prio ''Priorities for procs not supported. Ignored.'' in + let _ = the_warn prio STR ''Priorities for procs not supported. Ignored.'' in let ((_, vars, _, _), steps) = cvm_fold ppStep (True,[],inl,cvm) steps in (cvm, inl, Inr (Inl (Init vars steps))))" @@ -769,11 +766,11 @@ in let inl = lm.update name (args, stepF) inl in (cvm,inl, Inl[]))" -| "ppModule cvm (AST.DProcType _ _ _ _ _ _) = usc ''DProcType''" -| "ppModule cvm (AST.Never _) = usc ''Never''" -| "ppModule cvm (AST.Trace _) = usc ''Trace''" -| "ppModule cvm (AST.NoTrace _) = usc ''NoTrace''" -| "ppModule cvm (AST.TypeDef _ _) = usc ''TypeDef''" +| "ppModule cvm (AST.DProcType _ _ _ _ _ _) = usc STR ''DProcType''" +| "ppModule cvm (AST.Never _) = usc STR ''Never''" +| "ppModule cvm (AST.Trace _) = usc STR ''Trace''" +| "ppModule cvm (AST.NoTrace _) = usc STR ''NoTrace''" +| "ppModule cvm (AST.TypeDef _ _) = usc STR ''TypeDef''" definition preprocess :: "AST.module list \ promela" where "preprocess ms = ( diff -r efd58f8b1659 thys/Promela/PromelaLTL.thy --- a/thys/Promela/PromelaLTL.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/Promela/PromelaLTL.thy Tue Apr 24 11:35:45 2018 +0200 @@ -312,9 +312,9 @@ (* from PromelaDatastructures *) -hide_const (open) abort abort' abortv - err err' errv - usc usc' +hide_const (open) abort abortv + err errv + usc warn the_warn with_warn hide_const (open) idx idx' diff -r efd58f8b1659 thys/ROBDD/Conc_Impl.thy --- a/thys/ROBDD/Conc_Impl.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/ROBDD/Conc_Impl.thy Tue Apr 24 11:35:45 2018 +0200 @@ -166,7 +166,7 @@ (ifci a tb fb s'') } | None \ do { - case_ifexici (return (t,s)) (return (e,s)) (\_ _ _. raise ''Cannot happen'') i s + case_ifexici (return (t,s)) (return (e,s)) (\_ _ _. raise STR ''Cannot happen'') i s } }" declare iteci.simps[code] @@ -269,7 +269,7 @@ cl \ hm_update (i,t,e) r (dcli s); return (r,dcli_update (const cl) s) } - | None \ raise ''Cannot happen'' )}) + | None \ raise STR ''Cannot happen'' )}) })}" term ht_lookup diff -r efd58f8b1659 thys/Refine_Imperative_HOL/IICF/Impl/IICF_Sepl_Binding.thy --- a/thys/Refine_Imperative_HOL/IICF/Impl/IICF_Sepl_Binding.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/Refine_Imperative_HOL/IICF/Impl/IICF_Sepl_Binding.thy Tue Apr 24 11:35:45 2018 +0200 @@ -56,11 +56,11 @@ (* TODO: Move to Open_List *) definition os_head :: "'a::heap os_list \ ('a) Heap" where "os_head p \ case p of - None \ raise ''os_Head: Empty list'' + None \ raise STR ''os_Head: Empty list'' | Some p \ do { m \!p; return (val m) }" primrec os_tl :: "'a::heap os_list \ ('a os_list) Heap" where - "os_tl None = raise ''os_tl: Empty list''" + "os_tl None = raise STR ''os_tl: Empty list''" | "os_tl (Some p) = do { m \!p; return (next m) }" interpretation os: imp_list_head os_list os_head @@ -78,7 +78,7 @@ definition cs_head :: "'a::heap cs_list \ 'a Heap" where "cs_head p \ case p of - None \ raise ''cs_head: Empty list'' + None \ raise STR ''cs_head: Empty list'' | Some p \ do { n \ !p; return (val n)}" interpretation cs: imp_list_head cs_list cs_head by unfold_locales (sep_auto simp: neq_Nil_conv cs_head_def) diff -r efd58f8b1659 thys/Refine_Imperative_HOL/Sepref_HOL_Bindings.thy --- a/thys/Refine_Imperative_HOL/Sepref_HOL_Bindings.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/Refine_Imperative_HOL/Sepref_HOL_Bindings.thy Tue Apr 24 11:35:45 2018 +0200 @@ -1414,15 +1414,34 @@ done subsection \String Literals\ - -context fixes x :: "char list" begin - sepref_register "PR_CONST (STR x)" - lemma STR_hnr[sepref_import_param]: "(STR x,PR_CONST (STR x))\Id" by simp +sepref_register "PR_CONST String.empty_literal" + +lemma empty_literal_hnr [sepref_import_param]: + "(String.empty_literal, PR_CONST String.empty_literal) \ Id" + by simp + +lemma empty_literal_pat [def_pat_rules]: + "String.empty_literal \ UNPROTECT String.empty_literal" + by simp + +context + fixes b0 b1 b2 b3 b4 b5 b6 :: bool + and s :: String.literal +begin + +sepref_register "PR_CONST (String.Literal b0 b1 b2 b3 b4 b5 b6 s)" + +lemma Literal_hnr [sepref_import_param]: + "(String.Literal b0 b1 b2 b3 b4 b5 b6 s, + PR_CONST (String.Literal b0 b1 b2 b3 b4 b5 b6 s)) \ Id" + by simp end -lemma STR_pat[def_pat_rules]: "STR$x \ UNPROTECT (STR$x)" by simp - +lemma Literal_pat [def_pat_rules]: + "String.Literal $ b0 $ b1 $ b2 $ b3 $ b4 $ b5 $ b6 $ s \ + UNPROTECT (String.Literal $ b0 $ b1 $ b2 $ b3 $ b4 $ b5 $ b6 $ s)" + by simp end diff -r efd58f8b1659 thys/Refine_Imperative_HOL/benchmarks/Dijkstra/isabelle/dijkstra_export.sml --- a/thys/Refine_Imperative_HOL/benchmarks/Dijkstra/isabelle/dijkstra_export.sml Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/Refine_Imperative_HOL/benchmarks/Dijkstra/isabelle/dijkstra_export.sml Tue Apr 24 11:35:45 2018 +0200 @@ -317,10 +317,6 @@ datatype typerepa = Typerep of string * typerepa list; -datatype num = One | Bit0 of num | Bit1 of num; - -datatype char = Zero_char | Char of num; - datatype 'a itself = Type; fun typerep_nata t = Typerep ("Nat.nat", []); @@ -461,6 +457,8 @@ fun nat_of_integer k = Nat (max ord_integer (0 : IntInf.int) k); +datatype num = One | Bit0 of num | Bit1 of num; + fun def_hashmap_size_nat x = (fn _ => nat_of_integer (16 : IntInf.int)) x; type 'a hashable = diff -r efd58f8b1659 thys/Refine_Imperative_HOL/benchmarks/Heapmap/isabelle/heapmap_export.sml --- a/thys/Refine_Imperative_HOL/benchmarks/Heapmap/isabelle/heapmap_export.sml Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/Refine_Imperative_HOL/benchmarks/Heapmap/isabelle/heapmap_export.sml Tue Apr 24 11:35:45 2018 +0200 @@ -283,8 +283,8 @@ end; (*struct Bits_Integer*) structure Heapmap : sig + type nat type num - type nat val integer_of_nat : nat -> IntInf.int type ('a, 'b) lp type ('b, 'a) fingerTree @@ -295,10 +295,6 @@ datatype typerepa = Typerep of string * typerepa list; -datatype num = One | Bit0 of num | Bit1 of num; - -datatype char = Zero_char | Char of num; - datatype nat = Nat of IntInf.int; datatype 'a itself = Type; @@ -321,6 +317,8 @@ val heap_nat = {countable_heap = countable_nat, typerep_heap = typerep_nat} : nat heap; +datatype num = One | Bit0 of num | Bit1 of num; + val one_nata : nat = Nat (1 : IntInf.int); type 'a one = {one : 'a}; diff -r efd58f8b1659 thys/Refine_Imperative_HOL/benchmarks/NestedDFS/isabelle/NDFS_Benchmark_export.sml --- a/thys/Refine_Imperative_HOL/benchmarks/NestedDFS/isabelle/NDFS_Benchmark_export.sml Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/Refine_Imperative_HOL/benchmarks/NestedDFS/isabelle/NDFS_Benchmark_export.sml Tue Apr 24 11:35:45 2018 +0200 @@ -326,10 +326,6 @@ datatype typerepa = Typerep of string * typerepa list; -datatype num = One | Bit0 of num | Bit1 of num; - -datatype char = Zero_char | Char of num; - datatype 'a itself = Type; fun typerep_nata t = Typerep ("Nat.nat", []); @@ -385,6 +381,8 @@ less = (fn a => fn b => IntInf.< (a, b))} : IntInf.int ord; +datatype num = One | Bit0 of num | Bit1 of num; + datatype color = R | B; datatype ('a, 'b) rbt = Empty | diff -r efd58f8b1659 thys/Separation_Logic_Imperative_HOL/Examples/Circ_List.thy --- a/thys/Separation_Logic_Imperative_HOL/Examples/Circ_List.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/Separation_Logic_Imperative_HOL/Examples/Circ_List.thy Tue Apr 24 11:35:45 2018 +0200 @@ -139,7 +139,7 @@ subsubsection {* Pop First Element *} fun cs_pop :: "'a::heap cs_list \ ('a\'a cs_list) Heap" where - "cs_pop None = raise ''Pop from empty list''" + "cs_pop None = raise STR ''Pop from empty list''" | "cs_pop (Some p) = do { n1 \ !p; if next n1 = Some p then diff -r efd58f8b1659 thys/Separation_Logic_Imperative_HOL/Examples/Open_List.thy --- a/thys/Separation_Logic_Imperative_HOL/Examples/Open_List.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/Separation_Logic_Imperative_HOL/Examples/Open_List.thy Tue Apr 24 11:35:45 2018 +0200 @@ -83,7 +83,7 @@ reference of the node and return the pair of those. *} fun os_pop :: "'a::heap os_list \ ('a \ 'a os_list) Heap" where - "os_pop None = raise ''Empty Os_list''" | + "os_pop None = raise STR ''Empty Os_list''" | "os_pop (Some p) = do {m \ !p; return (val m, next m)}" declare os_pop.simps[simp del] diff -r efd58f8b1659 thys/Simpl/hoare.ML --- a/thys/Simpl/hoare.ML Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/Simpl/hoare.ML Tue Apr 24 11:35:45 2018 +0200 @@ -1586,7 +1586,7 @@ (* simplify equality test on strings (and datatype-constructors) and propagate result*) fun string_eq_simp_tac ctxt = simp_tac (put_simpset HOL_basic_ss ctxt - addsimps @{thms list.inject list.distinct Char_eq_Char_iff + addsimps @{thms list.inject list.distinct char.inject cong_exp_iff_simps simp_thms}); @@ -2961,7 +2961,7 @@ simpset_of (put_simpset (simpset_of @{theory_context Fun}) @{context} addsimps (@{thm StateFun.lookup_def} :: @{thm StateFun.id_id_cancel} - :: @{thms list.inject list.distinct Char_eq_Char_iff + :: @{thms list.inject list.distinct char.inject cong_exp_iff_simps simp_thms}) addsimprocs [Record.simproc, StateFun.lazy_conj_simproc] |> fold Simplifier.add_cong @{thms block_conj_cong}); @@ -3102,7 +3102,7 @@ val state_fun_update_ss = simpset_of (put_simpset HOL_basic_ss @{context} addsimps ([@{thm StateFun.update_def}, @{thm id_def}, @{thm fun_upd_apply}, @{thm if_True}, @{thm if_False}] - @ @{thms list.inject list.distinct Char_eq_Char_iff + @ @{thms list.inject list.distinct char.inject cong_exp_iff_simps simp_thms} @ K_fun_convs) addsimprocs [DistinctTreeProver.distinct_simproc ["distinct_fields", "distinct_fields_globals"]] |> Simplifier.add_cong @{thm imp_cong} (* K_fun_congs FIXME: Stefan fragen*) diff -r efd58f8b1659 thys/XML/Xml.thy --- a/thys/XML/Xml.thy Sat Apr 21 08:42:02 2018 +0200 +++ b/thys/XML/Xml.thy Tue Apr 24 11:35:45 2018 +0200 @@ -170,26 +170,8 @@ CHR ''a'' \ c \ c \ CHR ''z'' \ CHR ''A'' \ c \ c \ CHR ''Z'' \ CHR ''0'' \ c \ c \ CHR ''9'' \ - c \ set ''_&;:-''" (is "_ \ ?rhs") -proof (cases c) - case (char_of_nat n) - then have [simp]: "n mod 256 = n" by simp - have [simp]: "n > 0 \ {m.. c \ set letters" - by (simp add: is_letter_def) - also have "\ \ n \ set (map nat_of_char letters)" - by (auto intro!: image_eqI simp add: char_of_nat) - also have "map nat_of_char letters = - [97..<123] @ [65..<91] @ [95] @ [48..<58] @ [38, 59, 58, 45]" (is "_ = ?I") - by (simp add: letters_def) - also have "n \ set ?I \ - n \ {97..122} \ {65..90} \ {95} \ {48..57} \ {38, 59, 58, 45}" (is "_ \ _ \ ?J") - by (simp only: set_append set_upt) simp - also have "\ \ ?rhs" - by (auto simp add: char_of_nat Char_def less_eq_char_def) - finally show ?thesis . -qed + c \ set ''_&;:-''" + by (cases c) (simp add: is_letter_def letters_def) definition many_letters :: "string parser" where