merged
authorwenzelm
Mon Apr 03 23:12:44 2017 +0200 (2017-04-03)
changeset 65364db7c97cdcfe7
parent 65354 4ff2ba82d668
parent 65363 5eb619751b14
child 65365 d32e702d7ab8
merged
     1.1 --- a/src/HOL/Word/Bit_Representation.thy	Mon Apr 03 22:18:56 2017 +0200
     1.2 +++ b/src/HOL/Word/Bit_Representation.thy	Mon Apr 03 23:12:44 2017 +0200
     1.3 @@ -1,27 +1,24 @@
     1.4 -(* 
     1.5 -  Author: Jeremy Dawson, NICTA
     1.6 -*) 
     1.7 +(*  Title:      HOL/Word/Bit_Representation.thy
     1.8 +    Author:     Jeremy Dawson, NICTA
     1.9 +*)
    1.10  
    1.11  section \<open>Integers as implict bit strings\<close>
    1.12  
    1.13  theory Bit_Representation
    1.14 -imports Misc_Numeric
    1.15 +  imports Misc_Numeric
    1.16  begin
    1.17  
    1.18  subsection \<open>Constructors and destructors for binary integers\<close>
    1.19  
    1.20 -definition Bit :: "int \<Rightarrow> bool \<Rightarrow> int" (infixl "BIT" 90)
    1.21 -where
    1.22 -  "k BIT b = (if b then 1 else 0) + k + k"
    1.23 +definition Bit :: "int \<Rightarrow> bool \<Rightarrow> int"  (infixl "BIT" 90)
    1.24 +  where "k BIT b = (if b then 1 else 0) + k + k"
    1.25  
    1.26 -lemma Bit_B0:
    1.27 -  "k BIT False = k + k"
    1.28 -   by (unfold Bit_def) simp
    1.29 +lemma Bit_B0: "k BIT False = k + k"
    1.30 +   by (simp add: Bit_def)
    1.31  
    1.32 -lemma Bit_B1:
    1.33 -  "k BIT True = k + k + 1"
    1.34 -   by (unfold Bit_def) simp
    1.35 -  
    1.36 +lemma Bit_B1: "k BIT True = k + k + 1"
    1.37 +   by (simp add: Bit_def)
    1.38 +
    1.39  lemma Bit_B0_2t: "k BIT False = 2 * k"
    1.40    by (rule trans, rule Bit_B0) simp
    1.41  
    1.42 @@ -29,36 +26,28 @@
    1.43    by (rule trans, rule Bit_B1) simp
    1.44  
    1.45  definition bin_last :: "int \<Rightarrow> bool"
    1.46 -where
    1.47 -  "bin_last w \<longleftrightarrow> w mod 2 = 1"
    1.48 +  where "bin_last w \<longleftrightarrow> w mod 2 = 1"
    1.49  
    1.50 -lemma bin_last_odd:
    1.51 -  "bin_last = odd"
    1.52 +lemma bin_last_odd: "bin_last = odd"
    1.53    by (rule ext) (simp add: bin_last_def even_iff_mod_2_eq_zero)
    1.54  
    1.55  definition bin_rest :: "int \<Rightarrow> int"
    1.56 -where
    1.57 -  "bin_rest w = w div 2"
    1.58 +  where "bin_rest w = w div 2"
    1.59  
    1.60 -lemma bin_rl_simp [simp]:
    1.61 -  "bin_rest w BIT bin_last w = w"
    1.62 +lemma bin_rl_simp [simp]: "bin_rest w BIT bin_last w = w"
    1.63    unfolding bin_rest_def bin_last_def Bit_def
    1.64 -  using div_mult_mod_eq [of w 2]
    1.65 -  by (cases "w mod 2 = 0", simp_all)
    1.66 +  by (cases "w mod 2 = 0") (use div_mult_mod_eq [of w 2] in simp_all)
    1.67  
    1.68  lemma bin_rest_BIT [simp]: "bin_rest (x BIT b) = x"
    1.69    unfolding bin_rest_def Bit_def
    1.70 -  by (cases b, simp_all)
    1.71 +  by (cases b) simp_all
    1.72  
    1.73  lemma bin_last_BIT [simp]: "bin_last (x BIT b) = b"
    1.74    unfolding bin_last_def Bit_def
    1.75    by (cases b) simp_all
    1.76  
    1.77  lemma BIT_eq_iff [iff]: "u BIT b = v BIT c \<longleftrightarrow> u = v \<and> b = c"
    1.78 -  apply (auto simp add: Bit_def)
    1.79 -  apply arith
    1.80 -  apply arith
    1.81 -  done
    1.82 +  by (auto simp: Bit_def) arith+
    1.83  
    1.84  lemma BIT_bin_simps [simp]:
    1.85    "numeral k BIT False = numeral (Num.Bit0 k)"
    1.86 @@ -66,34 +55,32 @@
    1.87    "(- numeral k) BIT False = - numeral (Num.Bit0 k)"
    1.88    "(- numeral k) BIT True = - numeral (Num.BitM k)"
    1.89    unfolding numeral.simps numeral_BitM
    1.90 -  unfolding Bit_def
    1.91 -  by (simp_all del: arith_simps add_numeral_special diff_numeral_special)
    1.92 +  by (simp_all add: Bit_def del: arith_simps add_numeral_special diff_numeral_special)
    1.93  
    1.94  lemma BIT_special_simps [simp]:
    1.95 -  shows "0 BIT False = 0" and "0 BIT True = 1"
    1.96 -  and "1 BIT False = 2" and "1 BIT True = 3"
    1.97 -  and "(- 1) BIT False = - 2" and "(- 1) BIT True = - 1"
    1.98 -  unfolding Bit_def by simp_all
    1.99 +  shows "0 BIT False = 0"
   1.100 +    and "0 BIT True = 1"
   1.101 +    and "1 BIT False = 2"
   1.102 +    and "1 BIT True = 3"
   1.103 +    and "(- 1) BIT False = - 2"
   1.104 +    and "(- 1) BIT True = - 1"
   1.105 +  by (simp_all add: Bit_def)
   1.106  
   1.107  lemma Bit_eq_0_iff: "w BIT b = 0 \<longleftrightarrow> w = 0 \<and> \<not> b"
   1.108 -  apply (auto simp add: Bit_def)
   1.109 -  apply arith
   1.110 -  done
   1.111 +  by (auto simp: Bit_def) arith
   1.112  
   1.113  lemma Bit_eq_m1_iff: "w BIT b = -1 \<longleftrightarrow> w = -1 \<and> b"
   1.114 -  apply (auto simp add: Bit_def)
   1.115 -  apply arith
   1.116 -  done
   1.117 +  by (auto simp: Bit_def) arith
   1.118  
   1.119  lemma BitM_inc: "Num.BitM (Num.inc w) = Num.Bit1 w"
   1.120 -  by (induct w, simp_all)
   1.121 +  by (induct w) simp_all
   1.122  
   1.123  lemma expand_BIT:
   1.124    "numeral (Num.Bit0 w) = numeral w BIT False"
   1.125    "numeral (Num.Bit1 w) = numeral w BIT True"
   1.126    "- numeral (Num.Bit0 w) = (- numeral w) BIT False"
   1.127    "- numeral (Num.Bit1 w) = (- numeral (w + Num.One)) BIT True"
   1.128 -  unfolding add_One by (simp_all add: BitM_inc)
   1.129 +  by (simp_all add: add_One BitM_inc)
   1.130  
   1.131  lemma bin_last_numeral_simps [simp]:
   1.132    "\<not> bin_last 0"
   1.133 @@ -117,13 +104,11 @@
   1.134    "bin_rest (- numeral (Num.Bit1 w)) = - numeral (w + Num.One)"
   1.135    by (simp_all add: bin_rest_def zdiv_zminus1_eq_if) (auto simp add: divmod_def)
   1.136  
   1.137 -lemma less_Bits: 
   1.138 -  "v BIT b < w BIT c \<longleftrightarrow> v < w \<or> v \<le> w \<and> \<not> b \<and> c"
   1.139 -  unfolding Bit_def by auto
   1.140 +lemma less_Bits: "v BIT b < w BIT c \<longleftrightarrow> v < w \<or> v \<le> w \<and> \<not> b \<and> c"
   1.141 +  by (auto simp: Bit_def)
   1.142  
   1.143 -lemma le_Bits: 
   1.144 -  "v BIT b \<le> w BIT c \<longleftrightarrow> v < w \<or> v \<le> w \<and> (\<not> b \<or> c)" 
   1.145 -  unfolding Bit_def by auto
   1.146 +lemma le_Bits: "v BIT b \<le> w BIT c \<longleftrightarrow> v < w \<or> v \<le> w \<and> (\<not> b \<or> c)"
   1.147 +  by (auto simp: Bit_def)
   1.148  
   1.149  lemma pred_BIT_simps [simp]:
   1.150    "x BIT False - 1 = (x - 1) BIT True"
   1.151 @@ -148,31 +133,27 @@
   1.152    "x BIT True * y = (x * y) BIT False + y"
   1.153    by (simp_all add: Bit_B0_2t Bit_B1_2t algebra_simps)
   1.154  
   1.155 -lemma B_mod_2': 
   1.156 -  "X = 2 ==> (w BIT True) mod X = 1 & (w BIT False) mod X = 0"
   1.157 -  apply (simp (no_asm) only: Bit_B0 Bit_B1)
   1.158 -  apply simp
   1.159 -  done
   1.160 +lemma B_mod_2': "X = 2 \<Longrightarrow> (w BIT True) mod X = 1 \<and> (w BIT False) mod X = 0"
   1.161 +  by (simp add: Bit_B0 Bit_B1)
   1.162  
   1.163 -lemma bin_ex_rl: "EX w b. w BIT b = bin"
   1.164 +lemma bin_ex_rl: "\<exists>w b. w BIT b = bin"
   1.165    by (metis bin_rl_simp)
   1.166  
   1.167  lemma bin_exhaust:
   1.168 -  assumes Q: "\<And>x b. bin = x BIT b \<Longrightarrow> Q"
   1.169 +  assumes that: "\<And>x b. bin = x BIT b \<Longrightarrow> Q"
   1.170    shows "Q"
   1.171 -  apply (insert bin_ex_rl [of bin])  
   1.172 +  apply (insert bin_ex_rl [of bin])
   1.173    apply (erule exE)+
   1.174 -  apply (rule Q)
   1.175 +  apply (rule that)
   1.176    apply force
   1.177    done
   1.178  
   1.179 -primrec bin_nth where
   1.180 -  Z: "bin_nth w 0 \<longleftrightarrow> bin_last w"
   1.181 +primrec bin_nth
   1.182 +  where
   1.183 +    Z: "bin_nth w 0 \<longleftrightarrow> bin_last w"
   1.184    | Suc: "bin_nth w (Suc n) \<longleftrightarrow> bin_nth (bin_rest w) n"
   1.185  
   1.186 -lemma bin_abs_lem:
   1.187 -  "bin = (w BIT b) ==> bin ~= -1 --> bin ~= 0 -->
   1.188 -    nat \<bar>w\<bar> < nat \<bar>bin\<bar>"
   1.189 +lemma bin_abs_lem: "bin = (w BIT b) \<Longrightarrow> bin \<noteq> -1 \<longrightarrow> bin \<noteq> 0 \<longrightarrow> nat \<bar>w\<bar> < nat \<bar>bin\<bar>"
   1.190    apply clarsimp
   1.191    apply (unfold Bit_def)
   1.192    apply (cases b)
   1.193 @@ -183,10 +164,9 @@
   1.194  lemma bin_induct:
   1.195    assumes PPls: "P 0"
   1.196      and PMin: "P (- 1)"
   1.197 -    and PBit: "!!bin bit. P bin ==> P (bin BIT bit)"
   1.198 +    and PBit: "\<And>bin bit. P bin \<Longrightarrow> P (bin BIT bit)"
   1.199    shows "P bin"
   1.200 -  apply (rule_tac P=P and a=bin and f1="nat o abs" 
   1.201 -                  in wf_measure [THEN wf_induct])
   1.202 +  apply (rule_tac P=P and a=bin and f1="nat \<circ> abs" in wf_measure [THEN wf_induct])
   1.203    apply (simp add: measure_def inv_image_def)
   1.204    apply (case_tac x rule: bin_exhaust)
   1.205    apply (frule bin_abs_lem)
   1.206 @@ -196,26 +176,23 @@
   1.207  lemma Bit_div2 [simp]: "(w BIT b) div 2 = w"
   1.208    unfolding bin_rest_def [symmetric] by (rule bin_rest_BIT)
   1.209  
   1.210 -lemma bin_nth_eq_iff:
   1.211 -  "bin_nth x = bin_nth y \<longleftrightarrow> x = y"
   1.212 +lemma bin_nth_eq_iff: "bin_nth x = bin_nth y \<longleftrightarrow> x = y"
   1.213  proof -
   1.214 -  have bin_nth_lem [rule_format]: "ALL y. bin_nth x = bin_nth y --> x = y"
   1.215 +  have bin_nth_lem [rule_format]: "\<forall>y. bin_nth x = bin_nth y \<longrightarrow> x = y"
   1.216      apply (induct x rule: bin_induct)
   1.217        apply safe
   1.218        apply (erule rev_mp)
   1.219        apply (induct_tac y rule: bin_induct)
   1.220          apply safe
   1.221          apply (drule_tac x=0 in fun_cong, force)
   1.222 -       apply (erule notE, rule ext, 
   1.223 -            drule_tac x="Suc x" in fun_cong, force)
   1.224 +       apply (erule notE, rule ext, drule_tac x="Suc x" in fun_cong, force)
   1.225        apply (drule_tac x=0 in fun_cong, force)
   1.226       apply (erule rev_mp)
   1.227       apply (induct_tac y rule: bin_induct)
   1.228         apply safe
   1.229         apply (drule_tac x=0 in fun_cong, force)
   1.230 -      apply (erule notE, rule ext, 
   1.231 -           drule_tac x="Suc x" in fun_cong, force)
   1.232 -      apply (metis Bit_eq_m1_iff Z bin_last_BIT)
   1.233 +      apply (erule notE, rule ext, drule_tac x="Suc x" in fun_cong, force)
   1.234 +     apply (metis Bit_eq_m1_iff Z bin_last_BIT)
   1.235      apply (case_tac y rule: bin_exhaust)
   1.236      apply clarify
   1.237      apply (erule allE)
   1.238 @@ -227,13 +204,12 @@
   1.239      apply (drule_tac x="Suc x" for x in fun_cong, force)
   1.240      done
   1.241    show ?thesis
   1.242 -  by (auto elim: bin_nth_lem)
   1.243 +    by (auto elim: bin_nth_lem)
   1.244  qed
   1.245  
   1.246  lemmas bin_eqI = ext [THEN bin_nth_eq_iff [THEN iffD1]]
   1.247  
   1.248 -lemma bin_eq_iff:
   1.249 -  "x = y \<longleftrightarrow> (\<forall>n. bin_nth x n = bin_nth y n)"
   1.250 +lemma bin_eq_iff: "x = y \<longleftrightarrow> (\<forall>n. bin_nth x n = bin_nth y n)"
   1.251    using bin_nth_eq_iff by auto
   1.252  
   1.253  lemma bin_nth_zero [simp]: "\<not> bin_nth 0 n"
   1.254 @@ -251,11 +227,10 @@
   1.255  lemma bin_nth_Suc_BIT: "bin_nth (w BIT b) (Suc n) = bin_nth w n"
   1.256    by auto
   1.257  
   1.258 -lemma bin_nth_minus [simp]: "0 < n ==> bin_nth (w BIT b) n = bin_nth w (n - 1)"
   1.259 +lemma bin_nth_minus [simp]: "0 < n \<Longrightarrow> bin_nth (w BIT b) n = bin_nth w (n - 1)"
   1.260    by (cases n) auto
   1.261  
   1.262 -lemma bin_nth_numeral:
   1.263 -  "bin_rest x = y \<Longrightarrow> bin_nth x (numeral n) = bin_nth y (pred_numeral n)"
   1.264 +lemma bin_nth_numeral: "bin_rest x = y \<Longrightarrow> bin_nth x (numeral n) = bin_nth y (pred_numeral n)"
   1.265    by (simp add: numeral_eq_Suc)
   1.266  
   1.267  lemmas bin_nth_numeral_simps [simp] =
   1.268 @@ -265,7 +240,7 @@
   1.269    bin_nth_numeral [OF bin_rest_numeral_simps(7)]
   1.270    bin_nth_numeral [OF bin_rest_numeral_simps(8)]
   1.271  
   1.272 -lemmas bin_nth_simps = 
   1.273 +lemmas bin_nth_simps =
   1.274    bin_nth.Z bin_nth.Suc bin_nth_zero bin_nth_minus1
   1.275    bin_nth_numeral_simps
   1.276  
   1.277 @@ -273,8 +248,7 @@
   1.278  subsection \<open>Truncating binary integers\<close>
   1.279  
   1.280  definition bin_sign :: "int \<Rightarrow> int"
   1.281 -where
   1.282 -  bin_sign_def: "bin_sign k = (if k \<ge> 0 then 0 else - 1)"
   1.283 +  where "bin_sign k = (if k \<ge> 0 then 0 else - 1)"
   1.284  
   1.285  lemma bin_sign_simps [simp]:
   1.286    "bin_sign 0 = 0"
   1.287 @@ -283,28 +257,26 @@
   1.288    "bin_sign (numeral k) = 0"
   1.289    "bin_sign (- numeral k) = -1"
   1.290    "bin_sign (w BIT b) = bin_sign w"
   1.291 -  unfolding bin_sign_def Bit_def
   1.292 -  by simp_all
   1.293 +  by (simp_all add: bin_sign_def Bit_def)
   1.294  
   1.295 -lemma bin_sign_rest [simp]: 
   1.296 -  "bin_sign (bin_rest w) = bin_sign w"
   1.297 +lemma bin_sign_rest [simp]: "bin_sign (bin_rest w) = bin_sign w"
   1.298    by (cases w rule: bin_exhaust) auto
   1.299  
   1.300 -primrec bintrunc :: "nat \<Rightarrow> int \<Rightarrow> int" where
   1.301 -  Z : "bintrunc 0 bin = 0"
   1.302 -| Suc : "bintrunc (Suc n) bin = bintrunc n (bin_rest bin) BIT (bin_last bin)"
   1.303 +primrec bintrunc :: "nat \<Rightarrow> int \<Rightarrow> int"
   1.304 +  where
   1.305 +    Z : "bintrunc 0 bin = 0"
   1.306 +  | Suc : "bintrunc (Suc n) bin = bintrunc n (bin_rest bin) BIT (bin_last bin)"
   1.307  
   1.308 -primrec sbintrunc :: "nat => int => int" where
   1.309 -  Z : "sbintrunc 0 bin = (if bin_last bin then -1 else 0)"
   1.310 -| Suc : "sbintrunc (Suc n) bin = sbintrunc n (bin_rest bin) BIT (bin_last bin)"
   1.311 +primrec sbintrunc :: "nat \<Rightarrow> int \<Rightarrow> int"
   1.312 +  where
   1.313 +    Z : "sbintrunc 0 bin = (if bin_last bin then -1 else 0)"
   1.314 +  | Suc : "sbintrunc (Suc n) bin = sbintrunc n (bin_rest bin) BIT (bin_last bin)"
   1.315  
   1.316  lemma sign_bintr: "bin_sign (bintrunc n w) = 0"
   1.317    by (induct n arbitrary: w) auto
   1.318  
   1.319 -lemma bintrunc_mod2p: "bintrunc n w = (w mod 2 ^ n)"
   1.320 -  apply (induct n arbitrary: w, clarsimp)
   1.321 -  apply (simp add: bin_last_def bin_rest_def Bit_def zmod_zmult2_eq)
   1.322 -  done
   1.323 +lemma bintrunc_mod2p: "bintrunc n w = w mod 2 ^ n"
   1.324 +  by (induct n arbitrary: w) (auto simp add: bin_last_def bin_rest_def Bit_def zmod_zmult2_eq)
   1.325  
   1.326  lemma sbintrunc_mod2p: "sbintrunc n w = (w + 2 ^ n) mod 2 ^ (Suc n) - 2 ^ n"
   1.327    apply (induct n arbitrary: w)
   1.328 @@ -330,10 +302,8 @@
   1.329    "bintrunc (Suc n) (- 1) = bintrunc n (- 1) BIT True"
   1.330    "bintrunc (Suc n) (numeral (Num.Bit0 w)) = bintrunc n (numeral w) BIT False"
   1.331    "bintrunc (Suc n) (numeral (Num.Bit1 w)) = bintrunc n (numeral w) BIT True"
   1.332 -  "bintrunc (Suc n) (- numeral (Num.Bit0 w)) =
   1.333 -    bintrunc n (- numeral w) BIT False"
   1.334 -  "bintrunc (Suc n) (- numeral (Num.Bit1 w)) =
   1.335 -    bintrunc n (- numeral (w + Num.One)) BIT True"
   1.336 +  "bintrunc (Suc n) (- numeral (Num.Bit0 w)) = bintrunc n (- numeral w) BIT False"
   1.337 +  "bintrunc (Suc n) (- numeral (Num.Bit1 w)) = bintrunc n (- numeral (w + Num.One)) BIT True"
   1.338    by simp_all
   1.339  
   1.340  lemma sbintrunc_0_numeral [simp]:
   1.341 @@ -346,14 +316,10 @@
   1.342  
   1.343  lemma sbintrunc_Suc_numeral:
   1.344    "sbintrunc (Suc n) 1 = 1"
   1.345 -  "sbintrunc (Suc n) (numeral (Num.Bit0 w)) =
   1.346 -    sbintrunc n (numeral w) BIT False"
   1.347 -  "sbintrunc (Suc n) (numeral (Num.Bit1 w)) =
   1.348 -    sbintrunc n (numeral w) BIT True"
   1.349 -  "sbintrunc (Suc n) (- numeral (Num.Bit0 w)) =
   1.350 -    sbintrunc n (- numeral w) BIT False"
   1.351 -  "sbintrunc (Suc n) (- numeral (Num.Bit1 w)) =
   1.352 -    sbintrunc n (- numeral (w + Num.One)) BIT True"
   1.353 +  "sbintrunc (Suc n) (numeral (Num.Bit0 w)) = sbintrunc n (numeral w) BIT False"
   1.354 +  "sbintrunc (Suc n) (numeral (Num.Bit1 w)) = sbintrunc n (numeral w) BIT True"
   1.355 +  "sbintrunc (Suc n) (- numeral (Num.Bit0 w)) = sbintrunc n (- numeral w) BIT False"
   1.356 +  "sbintrunc (Suc n) (- numeral (Num.Bit1 w)) = sbintrunc n (- numeral (w + Num.One)) BIT True"
   1.357    by simp_all
   1.358  
   1.359  lemma bin_sign_lem: "(bin_sign (sbintrunc n bin) = -1) = bin_nth bin n"
   1.360 @@ -361,24 +327,21 @@
   1.361    apply (case_tac bin rule: bin_exhaust, case_tac b, auto)
   1.362    done
   1.363  
   1.364 -lemma nth_bintr: "bin_nth (bintrunc m w) n = (n < m & bin_nth w n)"
   1.365 +lemma nth_bintr: "bin_nth (bintrunc m w) n \<longleftrightarrow> n < m \<and> bin_nth w n"
   1.366    apply (induct n arbitrary: w m)
   1.367     apply (case_tac m, auto)[1]
   1.368    apply (case_tac m, auto)[1]
   1.369    done
   1.370  
   1.371 -lemma nth_sbintr:
   1.372 -  "bin_nth (sbintrunc m w) n = 
   1.373 -          (if n < m then bin_nth w n else bin_nth w m)"
   1.374 +lemma nth_sbintr: "bin_nth (sbintrunc m w) n = (if n < m then bin_nth w n else bin_nth w m)"
   1.375    apply (induct n arbitrary: w m)
   1.376 +   apply (case_tac m)
   1.377 +    apply simp_all
   1.378    apply (case_tac m)
   1.379 -  apply simp_all
   1.380 -  apply (case_tac m)
   1.381 -  apply simp_all
   1.382 +   apply simp_all
   1.383    done
   1.384  
   1.385 -lemma bin_nth_Bit:
   1.386 -  "bin_nth (w BIT b) n = (n = 0 & b | (EX m. n = Suc m & bin_nth w m))"
   1.387 +lemma bin_nth_Bit: "bin_nth (w BIT b) n \<longleftrightarrow> n = 0 \<and> b \<or> (\<exists>m. n = Suc m \<and> bin_nth w m)"
   1.388    by (cases n) auto
   1.389  
   1.390  lemma bin_nth_Bit0:
   1.391 @@ -391,69 +354,58 @@
   1.392      n = 0 \<or> (\<exists>m. n = Suc m \<and> bin_nth (numeral w) m)"
   1.393    using bin_nth_Bit [where w="numeral w" and b="True"] by simp
   1.394  
   1.395 -lemma bintrunc_bintrunc_l:
   1.396 -  "n <= m ==> (bintrunc m (bintrunc n w) = bintrunc n w)"
   1.397 -  by (rule bin_eqI) (auto simp add : nth_bintr)
   1.398 +lemma bintrunc_bintrunc_l: "n \<le> m \<Longrightarrow> bintrunc m (bintrunc n w) = bintrunc n w"
   1.399 +  by (rule bin_eqI) (auto simp: nth_bintr)
   1.400  
   1.401 -lemma sbintrunc_sbintrunc_l:
   1.402 -  "n <= m ==> (sbintrunc m (sbintrunc n w) = sbintrunc n w)"
   1.403 +lemma sbintrunc_sbintrunc_l: "n \<le> m \<Longrightarrow> sbintrunc m (sbintrunc n w) = sbintrunc n w"
   1.404    by (rule bin_eqI) (auto simp: nth_sbintr)
   1.405  
   1.406 -lemma bintrunc_bintrunc_ge:
   1.407 -  "n <= m ==> (bintrunc n (bintrunc m w) = bintrunc n w)"
   1.408 +lemma bintrunc_bintrunc_ge: "n \<le> m \<Longrightarrow> bintrunc n (bintrunc m w) = bintrunc n w"
   1.409    by (rule bin_eqI) (auto simp: nth_bintr)
   1.410  
   1.411 -lemma bintrunc_bintrunc_min [simp]:
   1.412 -  "bintrunc m (bintrunc n w) = bintrunc (min m n) w"
   1.413 -  apply (rule bin_eqI)
   1.414 -  apply (auto simp: nth_bintr)
   1.415 -  done
   1.416 +lemma bintrunc_bintrunc_min [simp]: "bintrunc m (bintrunc n w) = bintrunc (min m n) w"
   1.417 +  by (rule bin_eqI) (auto simp: nth_bintr)
   1.418  
   1.419 -lemma sbintrunc_sbintrunc_min [simp]:
   1.420 -  "sbintrunc m (sbintrunc n w) = sbintrunc (min m n) w"
   1.421 -  apply (rule bin_eqI)
   1.422 -  apply (auto simp: nth_sbintr min.absorb1 min.absorb2)
   1.423 -  done
   1.424 +lemma sbintrunc_sbintrunc_min [simp]: "sbintrunc m (sbintrunc n w) = sbintrunc (min m n) w"
   1.425 +  by (rule bin_eqI) (auto simp: nth_sbintr min.absorb1 min.absorb2)
   1.426  
   1.427 -lemmas bintrunc_Pls = 
   1.428 +lemmas bintrunc_Pls =
   1.429    bintrunc.Suc [where bin="0", simplified bin_last_numeral_simps bin_rest_numeral_simps]
   1.430  
   1.431 -lemmas bintrunc_Min [simp] = 
   1.432 +lemmas bintrunc_Min [simp] =
   1.433    bintrunc.Suc [where bin="-1", simplified bin_last_numeral_simps bin_rest_numeral_simps]
   1.434  
   1.435 -lemmas bintrunc_BIT  [simp] = 
   1.436 +lemmas bintrunc_BIT  [simp] =
   1.437    bintrunc.Suc [where bin="w BIT b", simplified bin_last_BIT bin_rest_BIT] for w b
   1.438  
   1.439  lemmas bintrunc_Sucs = bintrunc_Pls bintrunc_Min bintrunc_BIT
   1.440    bintrunc_Suc_numeral
   1.441  
   1.442 -lemmas sbintrunc_Suc_Pls = 
   1.443 +lemmas sbintrunc_Suc_Pls =
   1.444    sbintrunc.Suc [where bin="0", simplified bin_last_numeral_simps bin_rest_numeral_simps]
   1.445  
   1.446 -lemmas sbintrunc_Suc_Min = 
   1.447 +lemmas sbintrunc_Suc_Min =
   1.448    sbintrunc.Suc [where bin="-1", simplified bin_last_numeral_simps bin_rest_numeral_simps]
   1.449  
   1.450 -lemmas sbintrunc_Suc_BIT [simp] = 
   1.451 +lemmas sbintrunc_Suc_BIT [simp] =
   1.452    sbintrunc.Suc [where bin="w BIT b", simplified bin_last_BIT bin_rest_BIT] for w b
   1.453  
   1.454  lemmas sbintrunc_Sucs = sbintrunc_Suc_Pls sbintrunc_Suc_Min sbintrunc_Suc_BIT
   1.455    sbintrunc_Suc_numeral
   1.456  
   1.457 -lemmas sbintrunc_Pls = 
   1.458 -  sbintrunc.Z [where bin="0", 
   1.459 -               simplified bin_last_numeral_simps bin_rest_numeral_simps]
   1.460 +lemmas sbintrunc_Pls =
   1.461 +  sbintrunc.Z [where bin="0", simplified bin_last_numeral_simps bin_rest_numeral_simps]
   1.462  
   1.463 -lemmas sbintrunc_Min = 
   1.464 -  sbintrunc.Z [where bin="-1",
   1.465 -               simplified bin_last_numeral_simps bin_rest_numeral_simps]
   1.466 +lemmas sbintrunc_Min =
   1.467 +  sbintrunc.Z [where bin="-1", simplified bin_last_numeral_simps bin_rest_numeral_simps]
   1.468  
   1.469 -lemmas sbintrunc_0_BIT_B0 [simp] = 
   1.470 -  sbintrunc.Z [where bin="w BIT False", 
   1.471 -               simplified bin_last_numeral_simps bin_rest_numeral_simps] for w
   1.472 +lemmas sbintrunc_0_BIT_B0 [simp] =
   1.473 +  sbintrunc.Z [where bin="w BIT False", simplified bin_last_numeral_simps bin_rest_numeral_simps]
   1.474 +  for w
   1.475  
   1.476 -lemmas sbintrunc_0_BIT_B1 [simp] = 
   1.477 -  sbintrunc.Z [where bin="w BIT True", 
   1.478 -               simplified bin_last_BIT bin_rest_numeral_simps] for w
   1.479 +lemmas sbintrunc_0_BIT_B1 [simp] =
   1.480 +  sbintrunc.Z [where bin="w BIT True", simplified bin_last_BIT bin_rest_numeral_simps]
   1.481 +  for w
   1.482  
   1.483  lemmas sbintrunc_0_simps =
   1.484    sbintrunc_Pls sbintrunc_Min sbintrunc_0_BIT_B0 sbintrunc_0_BIT_B1
   1.485 @@ -461,20 +413,18 @@
   1.486  lemmas bintrunc_simps = bintrunc.Z bintrunc_Sucs
   1.487  lemmas sbintrunc_simps = sbintrunc_0_simps sbintrunc_Sucs
   1.488  
   1.489 -lemma bintrunc_minus:
   1.490 -  "0 < n ==> bintrunc (Suc (n - 1)) w = bintrunc n w"
   1.491 +lemma bintrunc_minus: "0 < n \<Longrightarrow> bintrunc (Suc (n - 1)) w = bintrunc n w"
   1.492 +  by auto
   1.493 +
   1.494 +lemma sbintrunc_minus: "0 < n \<Longrightarrow> sbintrunc (Suc (n - 1)) w = sbintrunc n w"
   1.495    by auto
   1.496  
   1.497 -lemma sbintrunc_minus:
   1.498 -  "0 < n ==> sbintrunc (Suc (n - 1)) w = sbintrunc n w"
   1.499 -  by auto
   1.500 -
   1.501 -lemmas bintrunc_minus_simps = 
   1.502 +lemmas bintrunc_minus_simps =
   1.503    bintrunc_Sucs [THEN [2] bintrunc_minus [symmetric, THEN trans]]
   1.504 -lemmas sbintrunc_minus_simps = 
   1.505 +lemmas sbintrunc_minus_simps =
   1.506    sbintrunc_Sucs [THEN [2] sbintrunc_minus [symmetric, THEN trans]]
   1.507  
   1.508 -lemmas thobini1 = arg_cong [where f = "%w. w BIT b"] for b
   1.509 +lemmas thobini1 = arg_cong [where f = "\<lambda>w. w BIT b"] for b
   1.510  
   1.511  lemmas bintrunc_BIT_I = trans [OF bintrunc_BIT thobini1]
   1.512  lemmas bintrunc_Min_I = trans [OF bintrunc_Min thobini1]
   1.513 @@ -484,35 +434,31 @@
   1.514  lemmas bintrunc_Min_minus_I = bmsts(2)
   1.515  lemmas bintrunc_BIT_minus_I = bmsts(3)
   1.516  
   1.517 -lemma bintrunc_Suc_lem:
   1.518 -  "bintrunc (Suc n) x = y ==> m = Suc n ==> bintrunc m x = y"
   1.519 +lemma bintrunc_Suc_lem: "bintrunc (Suc n) x = y \<Longrightarrow> m = Suc n \<Longrightarrow> bintrunc m x = y"
   1.520    by auto
   1.521  
   1.522 -lemmas bintrunc_Suc_Ialts = 
   1.523 +lemmas bintrunc_Suc_Ialts =
   1.524    bintrunc_Min_I [THEN bintrunc_Suc_lem]
   1.525    bintrunc_BIT_I [THEN bintrunc_Suc_lem]
   1.526  
   1.527  lemmas sbintrunc_BIT_I = trans [OF sbintrunc_Suc_BIT thobini1]
   1.528  
   1.529 -lemmas sbintrunc_Suc_Is = 
   1.530 +lemmas sbintrunc_Suc_Is =
   1.531    sbintrunc_Sucs(1-3) [THEN thobini1 [THEN [2] trans]]
   1.532  
   1.533 -lemmas sbintrunc_Suc_minus_Is = 
   1.534 +lemmas sbintrunc_Suc_minus_Is =
   1.535    sbintrunc_minus_simps(1-3) [THEN thobini1 [THEN [2] trans]]
   1.536  
   1.537 -lemma sbintrunc_Suc_lem:
   1.538 -  "sbintrunc (Suc n) x = y ==> m = Suc n ==> sbintrunc m x = y"
   1.539 +lemma sbintrunc_Suc_lem: "sbintrunc (Suc n) x = y \<Longrightarrow> m = Suc n \<Longrightarrow> sbintrunc m x = y"
   1.540    by auto
   1.541  
   1.542 -lemmas sbintrunc_Suc_Ialts = 
   1.543 +lemmas sbintrunc_Suc_Ialts =
   1.544    sbintrunc_Suc_Is [THEN sbintrunc_Suc_lem]
   1.545  
   1.546 -lemma sbintrunc_bintrunc_lt:
   1.547 -  "m > n ==> sbintrunc n (bintrunc m w) = sbintrunc n w"
   1.548 +lemma sbintrunc_bintrunc_lt: "m > n \<Longrightarrow> sbintrunc n (bintrunc m w) = sbintrunc n w"
   1.549    by (rule bin_eqI) (auto simp: nth_sbintr nth_bintr)
   1.550  
   1.551 -lemma bintrunc_sbintrunc_le:
   1.552 -  "m <= Suc n ==> bintrunc m (sbintrunc n w) = bintrunc m w"
   1.553 +lemma bintrunc_sbintrunc_le: "m \<le> Suc n \<Longrightarrow> bintrunc m (sbintrunc n w) = bintrunc m w"
   1.554    apply (rule bin_eqI)
   1.555    apply (auto simp: nth_sbintr nth_bintr)
   1.556     apply (subgoal_tac "x=n", safe, arith+)[1]
   1.557 @@ -522,19 +468,15 @@
   1.558  lemmas bintrunc_sbintrunc [simp] = order_refl [THEN bintrunc_sbintrunc_le]
   1.559  lemmas sbintrunc_bintrunc [simp] = lessI [THEN sbintrunc_bintrunc_lt]
   1.560  lemmas bintrunc_bintrunc [simp] = order_refl [THEN bintrunc_bintrunc_l]
   1.561 -lemmas sbintrunc_sbintrunc [simp] = order_refl [THEN sbintrunc_sbintrunc_l] 
   1.562 +lemmas sbintrunc_sbintrunc [simp] = order_refl [THEN sbintrunc_sbintrunc_l]
   1.563  
   1.564 -lemma bintrunc_sbintrunc' [simp]:
   1.565 -  "0 < n \<Longrightarrow> bintrunc n (sbintrunc (n - 1) w) = bintrunc n w"
   1.566 +lemma bintrunc_sbintrunc' [simp]: "0 < n \<Longrightarrow> bintrunc n (sbintrunc (n - 1) w) = bintrunc n w"
   1.567    by (cases n) (auto simp del: bintrunc.Suc)
   1.568  
   1.569 -lemma sbintrunc_bintrunc' [simp]:
   1.570 -  "0 < n \<Longrightarrow> sbintrunc (n - 1) (bintrunc n w) = sbintrunc (n - 1) w"
   1.571 +lemma sbintrunc_bintrunc' [simp]: "0 < n \<Longrightarrow> sbintrunc (n - 1) (bintrunc n w) = sbintrunc (n - 1) w"
   1.572    by (cases n) (auto simp del: bintrunc.Suc)
   1.573  
   1.574 -lemma bin_sbin_eq_iff: 
   1.575 -  "bintrunc (Suc n) x = bintrunc (Suc n) y \<longleftrightarrow> 
   1.576 -   sbintrunc n x = sbintrunc n y"
   1.577 +lemma bin_sbin_eq_iff: "bintrunc (Suc n) x = bintrunc (Suc n) y \<longleftrightarrow> sbintrunc n x = sbintrunc n y"
   1.578    apply (rule iffI)
   1.579     apply (rule box_equals [OF _ sbintrunc_bintrunc sbintrunc_bintrunc])
   1.580     apply simp
   1.581 @@ -543,8 +485,7 @@
   1.582    done
   1.583  
   1.584  lemma bin_sbin_eq_iff':
   1.585 -  "0 < n \<Longrightarrow> bintrunc n x = bintrunc n y \<longleftrightarrow> 
   1.586 -            sbintrunc (n - 1) x = sbintrunc (n - 1) y"
   1.587 +  "0 < n \<Longrightarrow> bintrunc n x = bintrunc n y \<longleftrightarrow> sbintrunc (n - 1) x = sbintrunc (n - 1) y"
   1.588    by (cases n) (simp_all add: bin_sbin_eq_iff del: bintrunc.Suc)
   1.589  
   1.590  lemmas bintrunc_sbintruncS0 [simp] = bintrunc_sbintrunc' [unfolded One_nat_def]
   1.591 @@ -557,36 +498,29 @@
   1.592    tends to get applied where it's not wanted in developing the theories,
   1.593    we get a version for when the word length is given literally *)
   1.594  
   1.595 -lemmas nat_non0_gr = 
   1.596 +lemmas nat_non0_gr =
   1.597    trans [OF iszero_def [THEN Not_eq_iff [THEN iffD2]] refl]
   1.598  
   1.599  lemma bintrunc_numeral:
   1.600 -  "bintrunc (numeral k) x =
   1.601 -    bintrunc (pred_numeral k) (bin_rest x) BIT bin_last x"
   1.602 +  "bintrunc (numeral k) x = bintrunc (pred_numeral k) (bin_rest x) BIT bin_last x"
   1.603    by (simp add: numeral_eq_Suc)
   1.604  
   1.605  lemma sbintrunc_numeral:
   1.606 -  "sbintrunc (numeral k) x =
   1.607 -    sbintrunc (pred_numeral k) (bin_rest x) BIT bin_last x"
   1.608 +  "sbintrunc (numeral k) x = sbintrunc (pred_numeral k) (bin_rest x) BIT bin_last x"
   1.609    by (simp add: numeral_eq_Suc)
   1.610  
   1.611  lemma bintrunc_numeral_simps [simp]:
   1.612 -  "bintrunc (numeral k) (numeral (Num.Bit0 w)) =
   1.613 -    bintrunc (pred_numeral k) (numeral w) BIT False"
   1.614 -  "bintrunc (numeral k) (numeral (Num.Bit1 w)) =
   1.615 -    bintrunc (pred_numeral k) (numeral w) BIT True"
   1.616 -  "bintrunc (numeral k) (- numeral (Num.Bit0 w)) =
   1.617 -    bintrunc (pred_numeral k) (- numeral w) BIT False"
   1.618 +  "bintrunc (numeral k) (numeral (Num.Bit0 w)) = bintrunc (pred_numeral k) (numeral w) BIT False"
   1.619 +  "bintrunc (numeral k) (numeral (Num.Bit1 w)) = bintrunc (pred_numeral k) (numeral w) BIT True"
   1.620 +  "bintrunc (numeral k) (- numeral (Num.Bit0 w)) = bintrunc (pred_numeral k) (- numeral w) BIT False"
   1.621    "bintrunc (numeral k) (- numeral (Num.Bit1 w)) =
   1.622      bintrunc (pred_numeral k) (- numeral (w + Num.One)) BIT True"
   1.623    "bintrunc (numeral k) 1 = 1"
   1.624    by (simp_all add: bintrunc_numeral)
   1.625  
   1.626  lemma sbintrunc_numeral_simps [simp]:
   1.627 -  "sbintrunc (numeral k) (numeral (Num.Bit0 w)) =
   1.628 -    sbintrunc (pred_numeral k) (numeral w) BIT False"
   1.629 -  "sbintrunc (numeral k) (numeral (Num.Bit1 w)) =
   1.630 -    sbintrunc (pred_numeral k) (numeral w) BIT True"
   1.631 +  "sbintrunc (numeral k) (numeral (Num.Bit0 w)) = sbintrunc (pred_numeral k) (numeral w) BIT False"
   1.632 +  "sbintrunc (numeral k) (numeral (Num.Bit1 w)) = sbintrunc (pred_numeral k) (numeral w) BIT True"
   1.633    "sbintrunc (numeral k) (- numeral (Num.Bit0 w)) =
   1.634      sbintrunc (pred_numeral k) (- numeral w) BIT False"
   1.635    "sbintrunc (numeral k) (- numeral (Num.Bit1 w)) =
   1.636 @@ -597,49 +531,45 @@
   1.637  lemma no_bintr_alt1: "bintrunc n = (\<lambda>w. w mod 2 ^ n :: int)"
   1.638    by (rule ext) (rule bintrunc_mod2p)
   1.639  
   1.640 -lemma range_bintrunc: "range (bintrunc n) = {i. 0 <= i & i < 2 ^ n}"
   1.641 +lemma range_bintrunc: "range (bintrunc n) = {i. 0 \<le> i \<and> i < 2 ^ n}"
   1.642    apply (unfold no_bintr_alt1)
   1.643    apply (auto simp add: image_iff)
   1.644    apply (rule exI)
   1.645    apply (auto intro: int_mod_lem [THEN iffD1, symmetric])
   1.646    done
   1.647  
   1.648 -lemma no_sbintr_alt2: 
   1.649 -  "sbintrunc n = (%w. (w + 2 ^ n) mod 2 ^ Suc n - 2 ^ n :: int)"
   1.650 +lemma no_sbintr_alt2: "sbintrunc n = (\<lambda>w. (w + 2 ^ n) mod 2 ^ Suc n - 2 ^ n :: int)"
   1.651    by (rule ext) (simp add : sbintrunc_mod2p)
   1.652  
   1.653 -lemma range_sbintrunc: 
   1.654 -  "range (sbintrunc n) = {i. - (2 ^ n) <= i & i < 2 ^ n}"
   1.655 +lemma range_sbintrunc: "range (sbintrunc n) = {i. - (2 ^ n) \<le> i \<and> i < 2 ^ n}"
   1.656    apply (unfold no_sbintr_alt2)
   1.657    apply (auto simp add: image_iff eq_diff_eq)
   1.658    apply (rule exI)
   1.659    apply (auto intro: int_mod_lem [THEN iffD1, symmetric])
   1.660    done
   1.661  
   1.662 -lemma sb_inc_lem:
   1.663 -  "(a::int) + 2^k < 0 \<Longrightarrow> a + 2^k + 2^(Suc k) <= (a + 2^k) mod 2^(Suc k)"
   1.664 +lemma sb_inc_lem: "a + 2^k < 0 \<Longrightarrow> a + 2^k + 2^(Suc k) \<le> (a + 2^k) mod 2^(Suc k)"
   1.665 +  for a :: int
   1.666    apply (erule int_mod_ge' [where n = "2 ^ (Suc k)" and b = "a + 2 ^ k", simplified zless2p])
   1.667    apply (rule TrueI)
   1.668    done
   1.669  
   1.670 -lemma sb_inc_lem':
   1.671 -  "(a::int) < - (2^k) \<Longrightarrow> a + 2^k + 2^(Suc k) <= (a + 2^k) mod 2^(Suc k)"
   1.672 +lemma sb_inc_lem': "a < - (2^k) \<Longrightarrow> a + 2^k + 2^(Suc k) \<le> (a + 2^k) mod 2^(Suc k)"
   1.673 +  for a :: int
   1.674    by (rule sb_inc_lem) simp
   1.675  
   1.676 -lemma sbintrunc_inc:
   1.677 -  "x < - (2^n) ==> x + 2^(Suc n) <= sbintrunc n x"
   1.678 +lemma sbintrunc_inc: "x < - (2^n) \<Longrightarrow> x + 2^(Suc n) \<le> sbintrunc n x"
   1.679    unfolding no_sbintr_alt2 by (drule sb_inc_lem') simp
   1.680  
   1.681 -lemma sb_dec_lem:
   1.682 -  "(0::int) \<le> - (2 ^ k) + a \<Longrightarrow> (a + 2 ^ k) mod (2 * 2 ^ k) \<le> - (2 ^ k) + a"
   1.683 +lemma sb_dec_lem: "0 \<le> - (2 ^ k) + a \<Longrightarrow> (a + 2 ^ k) mod (2 * 2 ^ k) \<le> - (2 ^ k) + a"
   1.684 +  for a :: int
   1.685    using int_mod_le'[where n = "2 ^ (Suc k)" and b = "a + 2 ^ k"] by simp
   1.686  
   1.687 -lemma sb_dec_lem':
   1.688 -  "(2::int) ^ k \<le> a \<Longrightarrow> (a + 2 ^ k) mod (2 * 2 ^ k) \<le> - (2 ^ k) + a"
   1.689 +lemma sb_dec_lem': "2 ^ k \<le> a \<Longrightarrow> (a + 2 ^ k) mod (2 * 2 ^ k) \<le> - (2 ^ k) + a"
   1.690 +  for a :: int
   1.691    by (rule sb_dec_lem) simp
   1.692  
   1.693 -lemma sbintrunc_dec:
   1.694 -  "x >= (2 ^ n) ==> x - 2 ^ (Suc n) >= sbintrunc n x"
   1.695 +lemma sbintrunc_dec: "x \<ge> (2 ^ n) \<Longrightarrow> x - 2 ^ (Suc n) >= sbintrunc n x"
   1.696    unfolding no_sbintr_alt2 by (drule sb_dec_lem') simp
   1.697  
   1.698  lemmas m2pths = pos_mod_sign pos_mod_bound [OF zless2p]
   1.699 @@ -659,55 +589,48 @@
   1.700  lemma sbintr_lt: "sbintrunc n w < 2 ^ n"
   1.701    by (simp add: sbintrunc_mod2p)
   1.702  
   1.703 -lemma sign_Pls_ge_0: 
   1.704 -  "(bin_sign bin = 0) = (bin >= (0 :: int))"
   1.705 -  unfolding bin_sign_def by simp
   1.706 +lemma sign_Pls_ge_0: "bin_sign bin = 0 \<longleftrightarrow> bin \<ge> 0"
   1.707 +  for bin :: int
   1.708 +  by (simp add: bin_sign_def)
   1.709  
   1.710 -lemma sign_Min_lt_0: 
   1.711 -  "(bin_sign bin = -1) = (bin < (0 :: int))"
   1.712 -  unfolding bin_sign_def by simp
   1.713 +lemma sign_Min_lt_0: "bin_sign bin = -1 \<longleftrightarrow> bin < 0"
   1.714 +  for bin :: int
   1.715 +  by (simp add: bin_sign_def)
   1.716  
   1.717 -lemma bin_rest_trunc:
   1.718 -  "(bin_rest (bintrunc n bin)) = bintrunc (n - 1) (bin_rest bin)"
   1.719 +lemma bin_rest_trunc: "bin_rest (bintrunc n bin) = bintrunc (n - 1) (bin_rest bin)"
   1.720    by (induct n arbitrary: bin) auto
   1.721  
   1.722  lemma bin_rest_power_trunc:
   1.723 -  "(bin_rest ^^ k) (bintrunc n bin) = 
   1.724 -    bintrunc (n - k) ((bin_rest ^^ k) bin)"
   1.725 +  "(bin_rest ^^ k) (bintrunc n bin) = bintrunc (n - k) ((bin_rest ^^ k) bin)"
   1.726    by (induct k) (auto simp: bin_rest_trunc)
   1.727  
   1.728 -lemma bin_rest_trunc_i:
   1.729 -  "bintrunc n (bin_rest bin) = bin_rest (bintrunc (Suc n) bin)"
   1.730 +lemma bin_rest_trunc_i: "bintrunc n (bin_rest bin) = bin_rest (bintrunc (Suc n) bin)"
   1.731    by auto
   1.732  
   1.733 -lemma bin_rest_strunc:
   1.734 -  "bin_rest (sbintrunc (Suc n) bin) = sbintrunc n (bin_rest bin)"
   1.735 +lemma bin_rest_strunc: "bin_rest (sbintrunc (Suc n) bin) = sbintrunc n (bin_rest bin)"
   1.736    by (induct n arbitrary: bin) auto
   1.737  
   1.738 -lemma bintrunc_rest [simp]: 
   1.739 -  "bintrunc n (bin_rest (bintrunc n bin)) = bin_rest (bintrunc n bin)"
   1.740 -  apply (induct n arbitrary: bin, simp)
   1.741 +lemma bintrunc_rest [simp]: "bintrunc n (bin_rest (bintrunc n bin)) = bin_rest (bintrunc n bin)"
   1.742 +  apply (induct n arbitrary: bin)
   1.743 +   apply simp
   1.744    apply (case_tac bin rule: bin_exhaust)
   1.745    apply (auto simp: bintrunc_bintrunc_l)
   1.746    done
   1.747  
   1.748 -lemma sbintrunc_rest [simp]:
   1.749 -  "sbintrunc n (bin_rest (sbintrunc n bin)) = bin_rest (sbintrunc n bin)"
   1.750 -  apply (induct n arbitrary: bin, simp)
   1.751 +lemma sbintrunc_rest [simp]: "sbintrunc n (bin_rest (sbintrunc n bin)) = bin_rest (sbintrunc n bin)"
   1.752 +  apply (induct n arbitrary: bin)
   1.753 +   apply simp
   1.754    apply (case_tac bin rule: bin_exhaust)
   1.755    apply (auto simp: bintrunc_bintrunc_l split: bool.splits)
   1.756    done
   1.757  
   1.758 -lemma bintrunc_rest':
   1.759 -  "bintrunc n o bin_rest o bintrunc n = bin_rest o bintrunc n"
   1.760 +lemma bintrunc_rest': "bintrunc n \<circ> bin_rest \<circ> bintrunc n = bin_rest \<circ> bintrunc n"
   1.761    by (rule ext) auto
   1.762  
   1.763 -lemma sbintrunc_rest' :
   1.764 -  "sbintrunc n o bin_rest o sbintrunc n = bin_rest o sbintrunc n"
   1.765 +lemma sbintrunc_rest': "sbintrunc n \<circ> bin_rest \<circ> sbintrunc n = bin_rest \<circ> sbintrunc n"
   1.766    by (rule ext) auto
   1.767  
   1.768 -lemma rco_lem:
   1.769 -  "f o g o f = g o f ==> f o (g o f) ^^ n = g ^^ n o f"
   1.770 +lemma rco_lem: "f \<circ> g \<circ> f = g \<circ> f \<Longrightarrow> f \<circ> (g \<circ> f) ^^ n = g ^^ n \<circ> f"
   1.771    apply (rule ext)
   1.772    apply (induct_tac n)
   1.773     apply (simp_all (no_asm))
   1.774 @@ -717,27 +640,29 @@
   1.775    apply simp
   1.776    done
   1.777  
   1.778 -lemmas rco_bintr = bintrunc_rest' 
   1.779 +lemmas rco_bintr = bintrunc_rest'
   1.780    [THEN rco_lem [THEN fun_cong], unfolded o_def]
   1.781 -lemmas rco_sbintr = sbintrunc_rest' 
   1.782 +lemmas rco_sbintr = sbintrunc_rest'
   1.783    [THEN rco_lem [THEN fun_cong], unfolded o_def]
   1.784  
   1.785 -  
   1.786 +
   1.787  subsection \<open>Splitting and concatenation\<close>
   1.788  
   1.789 -primrec bin_split :: "nat \<Rightarrow> int \<Rightarrow> int \<times> int" where
   1.790 -  Z: "bin_split 0 w = (w, 0)"
   1.791 -  | Suc: "bin_split (Suc n) w = (let (w1, w2) = bin_split n (bin_rest w)
   1.792 -        in (w1, w2 BIT bin_last w))"
   1.793 +primrec bin_split :: "nat \<Rightarrow> int \<Rightarrow> int \<times> int"
   1.794 +  where
   1.795 +    Z: "bin_split 0 w = (w, 0)"
   1.796 +  | Suc: "bin_split (Suc n) w =
   1.797 +      (let (w1, w2) = bin_split n (bin_rest w)
   1.798 +       in (w1, w2 BIT bin_last w))"
   1.799  
   1.800  lemma [code]:
   1.801    "bin_split (Suc n) w = (let (w1, w2) = bin_split n (bin_rest w) in (w1, w2 BIT bin_last w))"
   1.802    "bin_split 0 w = (w, 0)"
   1.803    by simp_all
   1.804  
   1.805 -primrec bin_cat :: "int \<Rightarrow> nat \<Rightarrow> int \<Rightarrow> int" where
   1.806 -  Z: "bin_cat w 0 v = w"
   1.807 +primrec bin_cat :: "int \<Rightarrow> nat \<Rightarrow> int \<Rightarrow> int"
   1.808 +  where
   1.809 +    Z: "bin_cat w 0 v = w"
   1.810    | Suc: "bin_cat w (Suc n) v = bin_cat w n (bin_rest v) BIT bin_last v"
   1.811  
   1.812  end
   1.813 -
     2.1 --- a/src/HOL/Word/Bits.thy	Mon Apr 03 22:18:56 2017 +0200
     2.2 +++ b/src/HOL/Word/Bits.thy	Mon Apr 03 23:12:44 2017 +0200
     2.3 @@ -5,35 +5,32 @@
     2.4  section \<open>Syntactic classes for bitwise operations\<close>
     2.5  
     2.6  theory Bits
     2.7 -imports Main
     2.8 +  imports Main
     2.9  begin
    2.10  
    2.11  class bit =
    2.12 -  fixes bitNOT :: "'a \<Rightarrow> 'a"       ("NOT _" [70] 71)
    2.13 -    and bitAND :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixr "AND" 64)
    2.14 -    and bitOR  :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixr "OR"  59)
    2.15 -    and bitXOR :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixr "XOR" 59)
    2.16 +  fixes bitNOT :: "'a \<Rightarrow> 'a"  ("NOT _" [70] 71)
    2.17 +    and bitAND :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"  (infixr "AND" 64)
    2.18 +    and bitOR :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"  (infixr "OR"  59)
    2.19 +    and bitXOR :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"  (infixr "XOR" 59)
    2.20  
    2.21  text \<open>
    2.22    We want the bitwise operations to bind slightly weaker
    2.23 -  than \<open>+\<close> and \<open>-\<close>, but \<open>~~\<close> to 
    2.24 +  than \<open>+\<close> and \<open>-\<close>, but \<open>~~\<close> to
    2.25    bind slightly stronger than \<open>*\<close>.
    2.26  \<close>
    2.27  
    2.28 -text \<open>
    2.29 -  Testing and shifting operations.
    2.30 -\<close>
    2.31 +text \<open>Testing and shifting operations.\<close>
    2.32  
    2.33  class bits = bit +
    2.34 -  fixes test_bit :: "'a \<Rightarrow> nat \<Rightarrow> bool" (infixl "!!" 100)
    2.35 -    and lsb      :: "'a \<Rightarrow> bool"
    2.36 -    and set_bit  :: "'a \<Rightarrow> nat \<Rightarrow> bool \<Rightarrow> 'a"
    2.37 -    and set_bits :: "(nat \<Rightarrow> bool) \<Rightarrow> 'a" (binder "BITS " 10)
    2.38 -    and shiftl   :: "'a \<Rightarrow> nat \<Rightarrow> 'a" (infixl "<<" 55)
    2.39 -    and shiftr   :: "'a \<Rightarrow> nat \<Rightarrow> 'a" (infixl ">>" 55)
    2.40 +  fixes test_bit :: "'a \<Rightarrow> nat \<Rightarrow> bool"  (infixl "!!" 100)
    2.41 +    and lsb :: "'a \<Rightarrow> bool"
    2.42 +    and set_bit :: "'a \<Rightarrow> nat \<Rightarrow> bool \<Rightarrow> 'a"
    2.43 +    and set_bits :: "(nat \<Rightarrow> bool) \<Rightarrow> 'a"  (binder "BITS " 10)
    2.44 +    and shiftl :: "'a \<Rightarrow> nat \<Rightarrow> 'a"  (infixl "<<" 55)
    2.45 +    and shiftr :: "'a \<Rightarrow> nat \<Rightarrow> 'a"  (infixl ">>" 55)
    2.46  
    2.47  class bitss = bits +
    2.48 -  fixes msb      :: "'a \<Rightarrow> bool"
    2.49 +  fixes msb :: "'a \<Rightarrow> bool"
    2.50  
    2.51  end
    2.52 -
     3.1 --- a/src/HOL/Word/Bits_Bit.thy	Mon Apr 03 22:18:56 2017 +0200
     3.2 +++ b/src/HOL/Word/Bits_Bit.thy	Mon Apr 03 23:12:44 2017 +0200
     3.3 @@ -11,20 +11,24 @@
     3.4  instantiation bit :: bit
     3.5  begin
     3.6  
     3.7 -primrec bitNOT_bit where
     3.8 -  "NOT 0 = (1::bit)"
     3.9 +primrec bitNOT_bit
    3.10 +  where
    3.11 +    "NOT 0 = (1::bit)"
    3.12    | "NOT 1 = (0::bit)"
    3.13  
    3.14 -primrec bitAND_bit where
    3.15 -  "0 AND y = (0::bit)"
    3.16 +primrec bitAND_bit
    3.17 +  where
    3.18 +    "0 AND y = (0::bit)"
    3.19    | "1 AND y = (y::bit)"
    3.20  
    3.21 -primrec bitOR_bit where
    3.22 -  "0 OR y = (y::bit)"
    3.23 +primrec bitOR_bit
    3.24 +  where
    3.25 +    "0 OR y = (y::bit)"
    3.26    | "1 OR y = (1::bit)"
    3.27  
    3.28 -primrec bitXOR_bit where
    3.29 -  "0 XOR y = (y::bit)"
    3.30 +primrec bitXOR_bit
    3.31 +  where
    3.32 +    "0 XOR y = (y::bit)"
    3.33    | "1 XOR y = (NOT y :: bit)"
    3.34  
    3.35  instance  ..
    3.36 @@ -34,40 +38,48 @@
    3.37  lemmas bit_simps =
    3.38    bitNOT_bit.simps bitAND_bit.simps bitOR_bit.simps bitXOR_bit.simps
    3.39  
    3.40 -lemma bit_extra_simps [simp]: 
    3.41 -  "x AND 0 = (0::bit)"
    3.42 -  "x AND 1 = (x::bit)"
    3.43 -  "x OR 1 = (1::bit)"
    3.44 -  "x OR 0 = (x::bit)"
    3.45 -  "x XOR 1 = NOT (x::bit)"
    3.46 -  "x XOR 0 = (x::bit)"
    3.47 +lemma bit_extra_simps [simp]:
    3.48 +  "x AND 0 = 0"
    3.49 +  "x AND 1 = x"
    3.50 +  "x OR 1 = 1"
    3.51 +  "x OR 0 = x"
    3.52 +  "x XOR 1 = NOT x"
    3.53 +  "x XOR 0 = x"
    3.54 +  for x :: bit
    3.55    by (cases x, auto)+
    3.56  
    3.57 -lemma bit_ops_comm: 
    3.58 -  "(x::bit) AND y = y AND x"
    3.59 -  "(x::bit) OR y = y OR x"
    3.60 -  "(x::bit) XOR y = y XOR x"
    3.61 +lemma bit_ops_comm:
    3.62 +  "x AND y = y AND x"
    3.63 +  "x OR y = y OR x"
    3.64 +  "x XOR y = y XOR x"
    3.65 +  for x :: bit
    3.66    by (cases y, auto)+
    3.67  
    3.68 -lemma bit_ops_same [simp]: 
    3.69 -  "(x::bit) AND x = x"
    3.70 -  "(x::bit) OR x = x"
    3.71 -  "(x::bit) XOR x = 0"
    3.72 +lemma bit_ops_same [simp]:
    3.73 +  "x AND x = x"
    3.74 +  "x OR x = x"
    3.75 +  "x XOR x = 0"
    3.76 +  for x :: bit
    3.77    by (cases x, auto)+
    3.78  
    3.79 -lemma bit_not_not [simp]: "NOT (NOT (x::bit)) = x"
    3.80 +lemma bit_not_not [simp]: "NOT (NOT x) = x"
    3.81 +  for x :: bit
    3.82    by (cases x) auto
    3.83  
    3.84 -lemma bit_or_def: "(b::bit) OR c = NOT (NOT b AND NOT c)"
    3.85 -  by (induct b, simp_all)
    3.86 +lemma bit_or_def: "b OR c = NOT (NOT b AND NOT c)"
    3.87 +  for b c :: bit
    3.88 +  by (induct b) simp_all
    3.89  
    3.90 -lemma bit_xor_def: "(b::bit) XOR c = (b AND NOT c) OR (NOT b AND c)"
    3.91 -  by (induct b, simp_all)
    3.92 +lemma bit_xor_def: "b XOR c = (b AND NOT c) OR (NOT b AND c)"
    3.93 +  for b c :: bit
    3.94 +  by (induct b) simp_all
    3.95  
    3.96 -lemma bit_NOT_eq_1_iff [simp]: "NOT (b::bit) = 1 \<longleftrightarrow> b = 0"
    3.97 -  by (induct b, simp_all)
    3.98 +lemma bit_NOT_eq_1_iff [simp]: "NOT b = 1 \<longleftrightarrow> b = 0"
    3.99 +  for b :: bit
   3.100 +  by (induct b) simp_all
   3.101  
   3.102 -lemma bit_AND_eq_1_iff [simp]: "(a::bit) AND b = 1 \<longleftrightarrow> a = 1 \<and> b = 1"
   3.103 -  by (induct a, simp_all)
   3.104 +lemma bit_AND_eq_1_iff [simp]: "a AND b = 1 \<longleftrightarrow> a = 1 \<and> b = 1"
   3.105 +  for a b :: bit
   3.106 +  by (induct a) simp_all
   3.107  
   3.108  end
     4.1 --- a/src/HOL/Word/Bits_Int.thy	Mon Apr 03 22:18:56 2017 +0200
     4.2 +++ b/src/HOL/Word/Bits_Int.thy	Mon Apr 03 23:12:44 2017 +0200
     4.3 @@ -1,15 +1,15 @@
     4.4 -(* 
     4.5 -  Author: Jeremy Dawson and Gerwin Klein, NICTA
     4.6 +(*  Title:      HOL/Word/Bits_Int.thy
     4.7 +    Author:     Jeremy Dawson and Gerwin Klein, NICTA
     4.8  
     4.9 -  Definitions and basic theorems for bit-wise logical operations 
    4.10 -  for integers expressed using Pls, Min, BIT,
    4.11 -  and converting them to and from lists of bools.
    4.12 -*) 
    4.13 +Definitions and basic theorems for bit-wise logical operations
    4.14 +for integers expressed using Pls, Min, BIT,
    4.15 +and converting them to and from lists of bools.
    4.16 +*)
    4.17  
    4.18  section \<open>Bitwise Operations on Binary Integers\<close>
    4.19  
    4.20  theory Bits_Int
    4.21 -imports Bits Bit_Representation
    4.22 +  imports Bits Bit_Representation
    4.23  begin
    4.24  
    4.25  subsection \<open>Logical operations\<close>
    4.26 @@ -19,17 +19,16 @@
    4.27  instantiation int :: bit
    4.28  begin
    4.29  
    4.30 -definition int_not_def:
    4.31 -  "bitNOT = (\<lambda>x::int. - x - 1)"
    4.32 +definition int_not_def: "bitNOT = (\<lambda>x::int. - x - 1)"
    4.33  
    4.34 -function bitAND_int where
    4.35 -  "bitAND_int x y =
    4.36 -    (if x = 0 then 0 else if x = -1 then y else
    4.37 -      (bin_rest x AND bin_rest y) BIT (bin_last x \<and> bin_last y))"
    4.38 +function bitAND_int
    4.39 +  where "bitAND_int x y =
    4.40 +    (if x = 0 then 0 else if x = -1 then y
    4.41 +     else (bin_rest x AND bin_rest y) BIT (bin_last x \<and> bin_last y))"
    4.42    by pat_completeness simp
    4.43  
    4.44  termination
    4.45 -  by (relation "measure (nat o abs o fst)", simp_all add: bin_rest_def)
    4.46 +  by (relation "measure (nat \<circ> abs \<circ> fst)", simp_all add: bin_rest_def)
    4.47  
    4.48  declare bitAND_int.simps [simp del]
    4.49  
    4.50 @@ -67,8 +66,8 @@
    4.51  lemma int_and_m1 [simp]: "(-1::int) AND x = x"
    4.52    by (simp add: bitAND_int.simps)
    4.53  
    4.54 -lemma int_and_Bits [simp]: 
    4.55 -  "(x BIT b) AND (y BIT c) = (x AND y) BIT (b \<and> c)" 
    4.56 +lemma int_and_Bits [simp]:
    4.57 +  "(x BIT b) AND (y BIT c) = (x AND y) BIT (b \<and> c)"
    4.58    by (subst bitAND_int.simps, simp add: Bit_eq_0_iff Bit_eq_m1_iff)
    4.59  
    4.60  lemma int_or_zero [simp]: "(0::int) OR x = x"
    4.61 @@ -77,14 +76,14 @@
    4.62  lemma int_or_minus1 [simp]: "(-1::int) OR x = -1"
    4.63    unfolding int_or_def by simp
    4.64  
    4.65 -lemma int_or_Bits [simp]: 
    4.66 +lemma int_or_Bits [simp]:
    4.67    "(x BIT b) OR (y BIT c) = (x OR y) BIT (b \<or> c)"
    4.68    unfolding int_or_def by simp
    4.69  
    4.70  lemma int_xor_zero [simp]: "(0::int) XOR x = x"
    4.71    unfolding int_xor_def by simp
    4.72  
    4.73 -lemma int_xor_Bits [simp]: 
    4.74 +lemma int_xor_Bits [simp]:
    4.75    "(x BIT b) XOR (y BIT c) = (x XOR y) BIT ((b \<or> c) \<and> \<not> (b \<and> c))"
    4.76    unfolding int_xor_def by auto
    4.77  
    4.78 @@ -115,9 +114,9 @@
    4.79    by (cases x rule: bin_exhaust, cases y rule: bin_exhaust, simp)
    4.80  
    4.81  lemma bin_nth_ops:
    4.82 -  "!!x y. bin_nth (x AND y) n = (bin_nth x n & bin_nth y n)" 
    4.83 +  "!!x y. bin_nth (x AND y) n = (bin_nth x n & bin_nth y n)"
    4.84    "!!x y. bin_nth (x OR y) n = (bin_nth x n | bin_nth y n)"
    4.85 -  "!!x y. bin_nth (x XOR y) n = (bin_nth x n ~= bin_nth y n)" 
    4.86 +  "!!x y. bin_nth (x XOR y) n = (bin_nth x n ~= bin_nth y n)"
    4.87    "!!x. bin_nth (NOT x) n = (~ bin_nth x n)"
    4.88    by (induct n) auto
    4.89  
    4.90 @@ -150,18 +149,18 @@
    4.91    by (auto simp add: bin_eq_iff bin_nth_ops)
    4.92  
    4.93  lemma bin_ops_same [simp]:
    4.94 -  "(x::int) AND x = x" 
    4.95 -  "(x::int) OR x = x" 
    4.96 +  "(x::int) AND x = x"
    4.97 +  "(x::int) OR x = x"
    4.98    "(x::int) XOR x = 0"
    4.99    by (auto simp add: bin_eq_iff bin_nth_ops)
   4.100  
   4.101 -lemmas bin_log_esimps = 
   4.102 +lemmas bin_log_esimps =
   4.103    int_and_extra_simps  int_or_extra_simps  int_xor_extra_simps
   4.104    int_and_0 int_and_m1 int_or_zero int_or_minus1 int_xor_zero int_xor_minus1
   4.105  
   4.106  (* basic properties of logical (bit-wise) operations *)
   4.107  
   4.108 -lemma bbw_ao_absorb: 
   4.109 +lemma bbw_ao_absorb:
   4.110    "!!y::int. x AND (y OR x) = x & x OR (y AND x) = x"
   4.111    by (auto simp add: bin_eq_iff bin_nth_ops)
   4.112  
   4.113 @@ -174,7 +173,7 @@
   4.114  lemmas bbw_ao_absorbs [simp] = bbw_ao_absorb bbw_ao_absorbs_other
   4.115  
   4.116  lemma int_xor_not:
   4.117 -  "!!y::int. (NOT x) XOR y = NOT (x XOR y) & 
   4.118 +  "!!y::int. (NOT x) XOR y = NOT (x XOR y) &
   4.119          x XOR (NOT y) = NOT (x XOR y)"
   4.120    by (auto simp add: bin_eq_iff bin_nth_ops)
   4.121  
   4.122 @@ -193,30 +192,30 @@
   4.123  lemmas bbw_assocs = int_and_assoc int_or_assoc int_xor_assoc
   4.124  
   4.125  (* BH: Why are these declared as simp rules??? *)
   4.126 -lemma bbw_lcs [simp]: 
   4.127 +lemma bbw_lcs [simp]:
   4.128    "(y::int) AND (x AND z) = x AND (y AND z)"
   4.129    "(y::int) OR (x OR z) = x OR (y OR z)"
   4.130 -  "(y::int) XOR (x XOR z) = x XOR (y XOR z)" 
   4.131 +  "(y::int) XOR (x XOR z) = x XOR (y XOR z)"
   4.132    by (auto simp add: bin_eq_iff bin_nth_ops)
   4.133  
   4.134 -lemma bbw_not_dist: 
   4.135 -  "!!y::int. NOT (x OR y) = (NOT x) AND (NOT y)" 
   4.136 +lemma bbw_not_dist:
   4.137 +  "!!y::int. NOT (x OR y) = (NOT x) AND (NOT y)"
   4.138    "!!y::int. NOT (x AND y) = (NOT x) OR (NOT y)"
   4.139    by (auto simp add: bin_eq_iff bin_nth_ops)
   4.140  
   4.141 -lemma bbw_oa_dist: 
   4.142 -  "!!y z::int. (x AND y) OR z = 
   4.143 +lemma bbw_oa_dist:
   4.144 +  "!!y z::int. (x AND y) OR z =
   4.145            (x OR z) AND (y OR z)"
   4.146    by (auto simp add: bin_eq_iff bin_nth_ops)
   4.147  
   4.148 -lemma bbw_ao_dist: 
   4.149 -  "!!y z::int. (x OR y) AND z = 
   4.150 +lemma bbw_ao_dist:
   4.151 +  "!!y z::int. (x OR y) AND z =
   4.152            (x AND z) OR (y AND z)"
   4.153    by (auto simp add: bin_eq_iff bin_nth_ops)
   4.154  
   4.155  (*
   4.156  Why were these declared simp???
   4.157 -declare bin_ops_comm [simp] bbw_assocs [simp] 
   4.158 +declare bin_ops_comm [simp] bbw_assocs [simp]
   4.159  *)
   4.160  
   4.161  subsubsection \<open>Simplification with numerals\<close>
   4.162 @@ -360,17 +359,17 @@
   4.163  
   4.164  subsubsection \<open>Truncating results of bit-wise operations\<close>
   4.165  
   4.166 -lemma bin_trunc_ao: 
   4.167 -  "!!x y. (bintrunc n x) AND (bintrunc n y) = bintrunc n (x AND y)" 
   4.168 +lemma bin_trunc_ao:
   4.169 +  "!!x y. (bintrunc n x) AND (bintrunc n y) = bintrunc n (x AND y)"
   4.170    "!!x y. (bintrunc n x) OR (bintrunc n y) = bintrunc n (x OR y)"
   4.171    by (auto simp add: bin_eq_iff bin_nth_ops nth_bintr)
   4.172  
   4.173 -lemma bin_trunc_xor: 
   4.174 -  "!!x y. bintrunc n (bintrunc n x XOR bintrunc n y) = 
   4.175 +lemma bin_trunc_xor:
   4.176 +  "!!x y. bintrunc n (bintrunc n x XOR bintrunc n y) =
   4.177            bintrunc n (x XOR y)"
   4.178    by (auto simp add: bin_eq_iff bin_nth_ops nth_bintr)
   4.179  
   4.180 -lemma bin_trunc_not: 
   4.181 +lemma bin_trunc_not:
   4.182    "!!x. bintrunc n (NOT (bintrunc n x)) = bintrunc n (NOT x)"
   4.183    by (auto simp add: bin_eq_iff bin_nth_ops nth_bintr)
   4.184  
   4.185 @@ -392,26 +391,26 @@
   4.186    Z: "bin_sc 0 b w = bin_rest w BIT b"
   4.187    | Suc: "bin_sc (Suc n) b w = bin_sc n b (bin_rest w) BIT bin_last w"
   4.188  
   4.189 -lemma bin_nth_sc [simp]: 
   4.190 +lemma bin_nth_sc [simp]:
   4.191    "bin_nth (bin_sc n b w) n \<longleftrightarrow> b"
   4.192    by (induct n arbitrary: w) auto
   4.193  
   4.194 -lemma bin_sc_sc_same [simp]: 
   4.195 +lemma bin_sc_sc_same [simp]:
   4.196    "bin_sc n c (bin_sc n b w) = bin_sc n c w"
   4.197    by (induct n arbitrary: w) auto
   4.198  
   4.199  lemma bin_sc_sc_diff:
   4.200 -  "m ~= n ==> 
   4.201 +  "m ~= n ==>
   4.202      bin_sc m c (bin_sc n b w) = bin_sc n b (bin_sc m c w)"
   4.203    apply (induct n arbitrary: w m)
   4.204     apply (case_tac [!] m)
   4.205       apply auto
   4.206    done
   4.207  
   4.208 -lemma bin_nth_sc_gen: 
   4.209 +lemma bin_nth_sc_gen:
   4.210    "bin_nth (bin_sc n b w) m = (if m = n then b else bin_nth w m)"
   4.211    by (induct n arbitrary: w m) (case_tac [!] m, auto)
   4.212 -  
   4.213 +
   4.214  lemma bin_sc_nth [simp]:
   4.215    "(bin_sc n (bin_nth w n) w) = w"
   4.216    by (induct n arbitrary: w) auto
   4.217 @@ -419,8 +418,8 @@
   4.218  lemma bin_sign_sc [simp]:
   4.219    "bin_sign (bin_sc n b w) = bin_sign w"
   4.220    by (induct n arbitrary: w) auto
   4.221 -  
   4.222 -lemma bin_sc_bintr [simp]: 
   4.223 +
   4.224 +lemma bin_sc_bintr [simp]:
   4.225    "bintrunc m (bin_sc n x (bintrunc m (w))) = bintrunc m (bin_sc n x w)"
   4.226    apply (induct n arbitrary: w m)
   4.227     apply (case_tac [!] w rule: bin_exhaust)
   4.228 @@ -464,14 +463,14 @@
   4.229  
   4.230  lemma bin_sc_TM [simp]: "bin_sc n True (- 1) = - 1"
   4.231    by (induct n) auto
   4.232 -  
   4.233 +
   4.234  lemmas bin_sc_simps = bin_sc.Z bin_sc.Suc bin_sc_TM bin_sc_FP
   4.235  
   4.236  lemma bin_sc_minus:
   4.237    "0 < n ==> bin_sc (Suc (n - 1)) b w = bin_sc n b w"
   4.238    by auto
   4.239  
   4.240 -lemmas bin_sc_Suc_minus = 
   4.241 +lemmas bin_sc_Suc_minus =
   4.242    trans [OF bin_sc_minus [symmetric] bin_sc.Suc]
   4.243  
   4.244  lemma bin_sc_numeral [simp]:
   4.245 @@ -490,7 +489,7 @@
   4.246  where
   4.247    "bin_rsplit_aux n m c bs =
   4.248      (if m = 0 | n = 0 then bs else
   4.249 -      let (a, b) = bin_split n c 
   4.250 +      let (a, b) = bin_split n c
   4.251        in bin_rsplit_aux n (m - n) a (b # bs))"
   4.252  
   4.253  definition bin_rsplit :: "nat \<Rightarrow> nat \<times> int \<Rightarrow> int list"
   4.254 @@ -501,7 +500,7 @@
   4.255  where
   4.256    "bin_rsplitl_aux n m c bs =
   4.257      (if m = 0 | n = 0 then bs else
   4.258 -      let (a, b) = bin_split (min m n) c 
   4.259 +      let (a, b) = bin_split (min m n) c
   4.260        in bin_rsplitl_aux n (m - n) a (b # bs))"
   4.261  
   4.262  definition bin_rsplitl :: "nat \<Rightarrow> nat \<times> int \<Rightarrow> int list"
   4.263 @@ -511,7 +510,7 @@
   4.264  declare bin_rsplit_aux.simps [simp del]
   4.265  declare bin_rsplitl_aux.simps [simp del]
   4.266  
   4.267 -lemma bin_sign_cat: 
   4.268 +lemma bin_sign_cat:
   4.269    "bin_sign (bin_cat x n y) = bin_sign x"
   4.270    by (induct n arbitrary: y) auto
   4.271  
   4.272 @@ -519,8 +518,8 @@
   4.273    "bin_cat w (Suc n) (v BIT b) = bin_cat w n v BIT b"
   4.274    by auto
   4.275  
   4.276 -lemma bin_nth_cat: 
   4.277 -  "bin_nth (bin_cat x k y) n = 
   4.278 +lemma bin_nth_cat:
   4.279 +  "bin_nth (bin_cat x k y) n =
   4.280      (if n < k then bin_nth y n else bin_nth x (n - k))"
   4.281    apply (induct k arbitrary: n y)
   4.282     apply clarsimp
   4.283 @@ -528,8 +527,8 @@
   4.284    done
   4.285  
   4.286  lemma bin_nth_split:
   4.287 -  "bin_split n c = (a, b) ==> 
   4.288 -    (ALL k. bin_nth a k = bin_nth c (n + k)) & 
   4.289 +  "bin_split n c = (a, b) ==>
   4.290 +    (ALL k. bin_nth a k = bin_nth c (n + k)) &
   4.291      (ALL k. bin_nth b k = (k < n & bin_nth c k))"
   4.292    apply (induct n arbitrary: b c)
   4.293     apply clarsimp
   4.294 @@ -538,8 +537,8 @@
   4.295    apply auto
   4.296    done
   4.297  
   4.298 -lemma bin_cat_assoc: 
   4.299 -  "bin_cat (bin_cat x m y) n z = bin_cat x (m + n) (bin_cat y n z)" 
   4.300 +lemma bin_cat_assoc:
   4.301 +  "bin_cat (bin_cat x m y) n z = bin_cat x (m + n) (bin_cat y n z)"
   4.302    by (induct n arbitrary: z) auto
   4.303  
   4.304  lemma bin_cat_assoc_sym:
   4.305 @@ -551,23 +550,23 @@
   4.306  lemma bin_cat_zero [simp]: "bin_cat 0 n w = bintrunc n w"
   4.307    by (induct n arbitrary: w) auto
   4.308  
   4.309 -lemma bintr_cat1: 
   4.310 +lemma bintr_cat1:
   4.311    "bintrunc (k + n) (bin_cat a n b) = bin_cat (bintrunc k a) n b"
   4.312    by (induct n arbitrary: b) auto
   4.313 -    
   4.314 -lemma bintr_cat: "bintrunc m (bin_cat a n b) = 
   4.315 +
   4.316 +lemma bintr_cat: "bintrunc m (bin_cat a n b) =
   4.317      bin_cat (bintrunc (m - n) a) n (bintrunc (min m n) b)"
   4.318    by (rule bin_eqI) (auto simp: bin_nth_cat nth_bintr)
   4.319 -    
   4.320 -lemma bintr_cat_same [simp]: 
   4.321 +
   4.322 +lemma bintr_cat_same [simp]:
   4.323    "bintrunc n (bin_cat a n b) = bintrunc n b"
   4.324    by (auto simp add : bintr_cat)
   4.325  
   4.326 -lemma cat_bintr [simp]: 
   4.327 +lemma cat_bintr [simp]:
   4.328    "bin_cat a n (bintrunc n b) = bin_cat a n b"
   4.329    by (induct n arbitrary: b) auto
   4.330  
   4.331 -lemma split_bintrunc: 
   4.332 +lemma split_bintrunc:
   4.333    "bin_split n c = (a, b) ==> b = bintrunc n c"
   4.334    by (induct n arbitrary: b c) (auto simp: Let_def split: prod.split_asm)
   4.335  
   4.336 @@ -587,7 +586,7 @@
   4.337    by (induct n) auto
   4.338  
   4.339  lemma bin_split_trunc:
   4.340 -  "bin_split (min m n) c = (a, b) ==> 
   4.341 +  "bin_split (min m n) c = (a, b) ==>
   4.342      bin_split n (bintrunc m c) = (bintrunc (m - n) a, b)"
   4.343    apply (induct n arbitrary: m b c, clarsimp)
   4.344    apply (simp add: bin_rest_trunc Let_def split: prod.split_asm)
   4.345 @@ -596,7 +595,7 @@
   4.346    done
   4.347  
   4.348  lemma bin_split_trunc1:
   4.349 -  "bin_split n c = (a, b) ==> 
   4.350 +  "bin_split n c = (a, b) ==>
   4.351      bin_split n (bintrunc m c) = (bintrunc (m - n) a, bintrunc m b)"
   4.352    apply (induct n arbitrary: m b c, clarsimp)
   4.353    apply (simp add: bin_rest_trunc Let_def split: prod.split_asm)
   4.354 @@ -621,12 +620,12 @@
   4.355  
   4.356  subsection \<open>Miscellaneous lemmas\<close>
   4.357  
   4.358 -lemma nth_2p_bin: 
   4.359 +lemma nth_2p_bin:
   4.360    "bin_nth (2 ^ n) m = (m = n)"
   4.361    apply (induct n arbitrary: m)
   4.362     apply clarsimp
   4.363     apply safe
   4.364 -   apply (case_tac m) 
   4.365 +   apply (case_tac m)
   4.366      apply (auto simp: Bit_B0_2t [symmetric])
   4.367    done
   4.368  
     5.1 --- a/src/HOL/Word/Bool_List_Representation.thy	Mon Apr 03 22:18:56 2017 +0200
     5.2 +++ b/src/HOL/Word/Bool_List_Representation.thy	Mon Apr 03 23:12:44 2017 +0200
     5.3 @@ -1,177 +1,156 @@
     5.4 -(* 
     5.5 -  Author: Jeremy Dawson, NICTA
     5.6 +(*  Title:      HOL/Word/Bool_List_Representation.thy
     5.7 +    Author:     Jeremy Dawson, NICTA
     5.8  
     5.9 -  Theorems to do with integers, expressed using Pls, Min, BIT,
    5.10 -  theorems linking them to lists of booleans, and repeated splitting 
    5.11 -  and concatenation.
    5.12 -*) 
    5.13 +Theorems to do with integers, expressed using Pls, Min, BIT,
    5.14 +theorems linking them to lists of booleans, and repeated splitting
    5.15 +and concatenation.
    5.16 +*)
    5.17  
    5.18  section "Bool lists and integers"
    5.19  
    5.20  theory Bool_List_Representation
    5.21 -imports Main Bits_Int
    5.22 +  imports Bits_Int
    5.23  begin
    5.24  
    5.25  definition map2 :: "('a \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> 'a list \<Rightarrow> 'b list \<Rightarrow> 'c list"
    5.26 -where
    5.27 -  "map2 f as bs = map (case_prod f) (zip as bs)"
    5.28 +  where "map2 f as bs = map (case_prod f) (zip as bs)"
    5.29  
    5.30 -lemma map2_Nil [simp, code]:
    5.31 -  "map2 f [] ys = []"
    5.32 -  unfolding map2_def by auto
    5.33 +lemma map2_Nil [simp, code]: "map2 f [] ys = []"
    5.34 +  by (auto simp: map2_def)
    5.35  
    5.36 -lemma map2_Nil2 [simp, code]:
    5.37 -  "map2 f xs [] = []"
    5.38 -  unfolding map2_def by auto
    5.39 +lemma map2_Nil2 [simp, code]: "map2 f xs [] = []"
    5.40 +  by (auto simp: map2_def)
    5.41  
    5.42 -lemma map2_Cons [simp, code]:
    5.43 -  "map2 f (x # xs) (y # ys) = f x y # map2 f xs ys"
    5.44 -  unfolding map2_def by auto
    5.45 +lemma map2_Cons [simp, code]: "map2 f (x # xs) (y # ys) = f x y # map2 f xs ys"
    5.46 +  by (auto simp: map2_def)
    5.47  
    5.48  
    5.49  subsection \<open>Operations on lists of booleans\<close>
    5.50  
    5.51  primrec bl_to_bin_aux :: "bool list \<Rightarrow> int \<Rightarrow> int"
    5.52 -where
    5.53 -  Nil: "bl_to_bin_aux [] w = w"
    5.54 -  | Cons: "bl_to_bin_aux (b # bs) w = 
    5.55 -      bl_to_bin_aux bs (w BIT b)"
    5.56 +  where
    5.57 +    Nil: "bl_to_bin_aux [] w = w"
    5.58 +  | Cons: "bl_to_bin_aux (b # bs) w = bl_to_bin_aux bs (w BIT b)"
    5.59  
    5.60  definition bl_to_bin :: "bool list \<Rightarrow> int"
    5.61 -where
    5.62 -  bl_to_bin_def: "bl_to_bin bs = bl_to_bin_aux bs 0"
    5.63 +  where "bl_to_bin bs = bl_to_bin_aux bs 0"
    5.64  
    5.65  primrec bin_to_bl_aux :: "nat \<Rightarrow> int \<Rightarrow> bool list \<Rightarrow> bool list"
    5.66 -where
    5.67 -  Z: "bin_to_bl_aux 0 w bl = bl"
    5.68 -  | Suc: "bin_to_bl_aux (Suc n) w bl =
    5.69 -      bin_to_bl_aux n (bin_rest w) ((bin_last w) # bl)"
    5.70 +  where
    5.71 +    Z: "bin_to_bl_aux 0 w bl = bl"
    5.72 +  | Suc: "bin_to_bl_aux (Suc n) w bl = bin_to_bl_aux n (bin_rest w) ((bin_last w) # bl)"
    5.73  
    5.74  definition bin_to_bl :: "nat \<Rightarrow> int \<Rightarrow> bool list"
    5.75 -where
    5.76 -  bin_to_bl_def : "bin_to_bl n w = bin_to_bl_aux n w []"
    5.77 +  where "bin_to_bl n w = bin_to_bl_aux n w []"
    5.78  
    5.79  primrec bl_of_nth :: "nat \<Rightarrow> (nat \<Rightarrow> bool) \<Rightarrow> bool list"
    5.80 -where
    5.81 -  Suc: "bl_of_nth (Suc n) f = f n # bl_of_nth n f"
    5.82 +  where
    5.83 +    Suc: "bl_of_nth (Suc n) f = f n # bl_of_nth n f"
    5.84    | Z: "bl_of_nth 0 f = []"
    5.85  
    5.86  primrec takefill :: "'a \<Rightarrow> nat \<Rightarrow> 'a list \<Rightarrow> 'a list"
    5.87  where
    5.88 -  Z: "takefill fill 0 xs = []"
    5.89 -  | Suc: "takefill fill (Suc n) xs = (
    5.90 -      case xs of [] => fill # takefill fill n xs
    5.91 -        | y # ys => y # takefill fill n ys)"
    5.92 +    Z: "takefill fill 0 xs = []"
    5.93 +  | Suc: "takefill fill (Suc n) xs =
    5.94 +      (case xs of
    5.95 +        [] \<Rightarrow> fill # takefill fill n xs
    5.96 +      | y # ys \<Rightarrow> y # takefill fill n ys)"
    5.97  
    5.98  
    5.99  subsection "Arithmetic in terms of bool lists"
   5.100  
   5.101  text \<open>
   5.102    Arithmetic operations in terms of the reversed bool list,
   5.103 -  assuming input list(s) the same length, and don't extend them. 
   5.104 +  assuming input list(s) the same length, and don't extend them.
   5.105  \<close>
   5.106  
   5.107 -primrec rbl_succ :: "bool list => bool list"
   5.108 -where
   5.109 -  Nil: "rbl_succ Nil = Nil"
   5.110 +primrec rbl_succ :: "bool list \<Rightarrow> bool list"
   5.111 +  where
   5.112 +    Nil: "rbl_succ Nil = Nil"
   5.113    | Cons: "rbl_succ (x # xs) = (if x then False # rbl_succ xs else True # xs)"
   5.114  
   5.115 -primrec rbl_pred :: "bool list => bool list"
   5.116 -where
   5.117 -  Nil: "rbl_pred Nil = Nil"
   5.118 +primrec rbl_pred :: "bool list \<Rightarrow> bool list"
   5.119 +  where
   5.120 +    Nil: "rbl_pred Nil = Nil"
   5.121    | Cons: "rbl_pred (x # xs) = (if x then False # xs else True # rbl_pred xs)"
   5.122  
   5.123 -primrec rbl_add :: "bool list => bool list => bool list"
   5.124 -where
   5.125 -  \<comment> "result is length of first arg, second arg may be longer"
   5.126 -  Nil: "rbl_add Nil x = Nil"
   5.127 -  | Cons: "rbl_add (y # ys) x = (let ws = rbl_add ys (tl x) in 
   5.128 -    (y ~= hd x) # (if hd x & y then rbl_succ ws else ws))"
   5.129 +primrec rbl_add :: "bool list \<Rightarrow> bool list \<Rightarrow> bool list"
   5.130 +  where \<comment> "result is length of first arg, second arg may be longer"
   5.131 +    Nil: "rbl_add Nil x = Nil"
   5.132 +  | Cons: "rbl_add (y # ys) x =
   5.133 +      (let ws = rbl_add ys (tl x)
   5.134 +       in (y \<noteq> hd x) # (if hd x \<and> y then rbl_succ ws else ws))"
   5.135  
   5.136 -primrec rbl_mult :: "bool list => bool list => bool list"
   5.137 -where
   5.138 -  \<comment> "result is length of first arg, second arg may be longer"
   5.139 -  Nil: "rbl_mult Nil x = Nil"
   5.140 -  | Cons: "rbl_mult (y # ys) x = (let ws = False # rbl_mult ys x in 
   5.141 -    if y then rbl_add ws x else ws)"
   5.142 +primrec rbl_mult :: "bool list \<Rightarrow> bool list \<Rightarrow> bool list"
   5.143 +  where \<comment> "result is length of first arg, second arg may be longer"
   5.144 +    Nil: "rbl_mult Nil x = Nil"
   5.145 +  | Cons: "rbl_mult (y # ys) x =
   5.146 +      (let ws = False # rbl_mult ys x
   5.147 +       in if y then rbl_add ws x else ws)"
   5.148  
   5.149 -lemma butlast_power:
   5.150 -  "(butlast ^^ n) bl = take (length bl - n) bl"
   5.151 +lemma butlast_power: "(butlast ^^ n) bl = take (length bl - n) bl"
   5.152    by (induct n) (auto simp: butlast_take)
   5.153  
   5.154  lemma bin_to_bl_aux_zero_minus_simp [simp]:
   5.155 -  "0 < n \<Longrightarrow> bin_to_bl_aux n 0 bl = 
   5.156 -    bin_to_bl_aux (n - 1) 0 (False # bl)"
   5.157 +  "0 < n \<Longrightarrow> bin_to_bl_aux n 0 bl = bin_to_bl_aux (n - 1) 0 (False # bl)"
   5.158    by (cases n) auto
   5.159  
   5.160  lemma bin_to_bl_aux_minus1_minus_simp [simp]:
   5.161 -  "0 < n ==> bin_to_bl_aux n (- 1) bl = 
   5.162 -    bin_to_bl_aux (n - 1) (- 1) (True # bl)"
   5.163 +  "0 < n \<Longrightarrow> bin_to_bl_aux n (- 1) bl = bin_to_bl_aux (n - 1) (- 1) (True # bl)"
   5.164    by (cases n) auto
   5.165  
   5.166  lemma bin_to_bl_aux_one_minus_simp [simp]:
   5.167 -  "0 < n \<Longrightarrow> bin_to_bl_aux n 1 bl = 
   5.168 -    bin_to_bl_aux (n - 1) 0 (True # bl)"
   5.169 +  "0 < n \<Longrightarrow> bin_to_bl_aux n 1 bl = bin_to_bl_aux (n - 1) 0 (True # bl)"
   5.170    by (cases n) auto
   5.171  
   5.172  lemma bin_to_bl_aux_Bit_minus_simp [simp]:
   5.173 -  "0 < n ==> bin_to_bl_aux n (w BIT b) bl = 
   5.174 -    bin_to_bl_aux (n - 1) w (b # bl)"
   5.175 +  "0 < n \<Longrightarrow> bin_to_bl_aux n (w BIT b) bl = bin_to_bl_aux (n - 1) w (b # bl)"
   5.176    by (cases n) auto
   5.177  
   5.178  lemma bin_to_bl_aux_Bit0_minus_simp [simp]:
   5.179 -  "0 < n ==> bin_to_bl_aux n (numeral (Num.Bit0 w)) bl = 
   5.180 -    bin_to_bl_aux (n - 1) (numeral w) (False # bl)"
   5.181 +  "0 < n \<Longrightarrow>
   5.182 +    bin_to_bl_aux n (numeral (Num.Bit0 w)) bl = bin_to_bl_aux (n - 1) (numeral w) (False # bl)"
   5.183    by (cases n) auto
   5.184  
   5.185  lemma bin_to_bl_aux_Bit1_minus_simp [simp]:
   5.186 -  "0 < n ==> bin_to_bl_aux n (numeral (Num.Bit1 w)) bl = 
   5.187 -    bin_to_bl_aux (n - 1) (numeral w) (True # bl)"
   5.188 +  "0 < n \<Longrightarrow>
   5.189 +    bin_to_bl_aux n (numeral (Num.Bit1 w)) bl = bin_to_bl_aux (n - 1) (numeral w) (True # bl)"
   5.190    by (cases n) auto
   5.191  
   5.192  text \<open>Link between bin and bool list.\<close>
   5.193  
   5.194 -lemma bl_to_bin_aux_append: 
   5.195 -  "bl_to_bin_aux (bs @ cs) w = bl_to_bin_aux cs (bl_to_bin_aux bs w)"
   5.196 +lemma bl_to_bin_aux_append: "bl_to_bin_aux (bs @ cs) w = bl_to_bin_aux cs (bl_to_bin_aux bs w)"
   5.197    by (induct bs arbitrary: w) auto
   5.198  
   5.199 -lemma bin_to_bl_aux_append: 
   5.200 -  "bin_to_bl_aux n w bs @ cs = bin_to_bl_aux n w (bs @ cs)"
   5.201 +lemma bin_to_bl_aux_append: "bin_to_bl_aux n w bs @ cs = bin_to_bl_aux n w (bs @ cs)"
   5.202    by (induct n arbitrary: w bs) auto
   5.203  
   5.204 -lemma bl_to_bin_append: 
   5.205 -  "bl_to_bin (bs @ cs) = bl_to_bin_aux cs (bl_to_bin bs)"
   5.206 +lemma bl_to_bin_append: "bl_to_bin (bs @ cs) = bl_to_bin_aux cs (bl_to_bin bs)"
   5.207    unfolding bl_to_bin_def by (rule bl_to_bin_aux_append)
   5.208  
   5.209 -lemma bin_to_bl_aux_alt: 
   5.210 -  "bin_to_bl_aux n w bs = bin_to_bl n w @ bs" 
   5.211 -  unfolding bin_to_bl_def by (simp add : bin_to_bl_aux_append)
   5.212 +lemma bin_to_bl_aux_alt: "bin_to_bl_aux n w bs = bin_to_bl n w @ bs"
   5.213 +  by (simp add: bin_to_bl_def bin_to_bl_aux_append)
   5.214  
   5.215  lemma bin_to_bl_0 [simp]: "bin_to_bl 0 bs = []"
   5.216 -  unfolding bin_to_bl_def by auto
   5.217 +  by (auto simp: bin_to_bl_def)
   5.218  
   5.219 -lemma size_bin_to_bl_aux: 
   5.220 -  "size (bin_to_bl_aux n w bs) = n + length bs"
   5.221 +lemma size_bin_to_bl_aux: "size (bin_to_bl_aux n w bs) = n + length bs"
   5.222    by (induct n arbitrary: w bs) auto
   5.223  
   5.224 -lemma size_bin_to_bl [simp]: "size (bin_to_bl n w) = n" 
   5.225 -  unfolding bin_to_bl_def by (simp add : size_bin_to_bl_aux)
   5.226 +lemma size_bin_to_bl [simp]: "size (bin_to_bl n w) = n"
   5.227 +  by (simp add: bin_to_bl_def size_bin_to_bl_aux)
   5.228  
   5.229 -lemma bin_bl_bin': 
   5.230 -  "bl_to_bin (bin_to_bl_aux n w bs) = 
   5.231 -    bl_to_bin_aux bs (bintrunc n w)"
   5.232 -  by (induct n arbitrary: w bs) (auto simp add : bl_to_bin_def)
   5.233 +lemma bin_bl_bin': "bl_to_bin (bin_to_bl_aux n w bs) = bl_to_bin_aux bs (bintrunc n w)"
   5.234 +  by (induct n arbitrary: w bs) (auto simp: bl_to_bin_def)
   5.235  
   5.236  lemma bin_bl_bin [simp]: "bl_to_bin (bin_to_bl n w) = bintrunc n w"
   5.237 -  unfolding bin_to_bl_def bin_bl_bin' by auto
   5.238 +  by (auto simp: bin_to_bl_def bin_bl_bin')
   5.239  
   5.240 -lemma bl_bin_bl':
   5.241 -  "bin_to_bl (n + length bs) (bl_to_bin_aux bs w) = 
   5.242 -    bin_to_bl_aux n w bs"
   5.243 +lemma bl_bin_bl': "bin_to_bl (n + length bs) (bl_to_bin_aux bs w) = bin_to_bl_aux n w bs"
   5.244    apply (induct bs arbitrary: w n)
   5.245     apply auto
   5.246 -    apply (simp_all only : add_Suc [symmetric])
   5.247 -    apply (auto simp add : bin_to_bl_def)
   5.248 +    apply (simp_all only: add_Suc [symmetric])
   5.249 +    apply (auto simp add: bin_to_bl_def)
   5.250    done
   5.251  
   5.252  lemma bl_bin_bl [simp]: "bin_to_bl (length bs) (bl_to_bin bs) = bs"
   5.253 @@ -182,9 +161,8 @@
   5.254     apply (rule bin_to_bl_aux.Z)
   5.255    apply simp
   5.256    done
   5.257 -  
   5.258 -lemma bl_to_bin_inj:
   5.259 -  "bl_to_bin bs = bl_to_bin cs ==> length bs = length cs ==> bs = cs"
   5.260 +
   5.261 +lemma bl_to_bin_inj: "bl_to_bin bs = bl_to_bin cs \<Longrightarrow> length bs = length cs \<Longrightarrow> bs = cs"
   5.262    apply (rule_tac box_equals)
   5.263      defer
   5.264      apply (rule bl_bin_bl)
   5.265 @@ -193,86 +171,74 @@
   5.266    done
   5.267  
   5.268  lemma bl_to_bin_False [simp]: "bl_to_bin (False # bl) = bl_to_bin bl"
   5.269 -  unfolding bl_to_bin_def by auto
   5.270 +  by (auto simp: bl_to_bin_def)
   5.271  
   5.272  lemma bl_to_bin_Nil [simp]: "bl_to_bin [] = 0"
   5.273 -  unfolding bl_to_bin_def by auto
   5.274 +  by (auto simp: bl_to_bin_def)
   5.275  
   5.276 -lemma bin_to_bl_zero_aux: 
   5.277 -  "bin_to_bl_aux n 0 bl = replicate n False @ bl"
   5.278 +lemma bin_to_bl_zero_aux: "bin_to_bl_aux n 0 bl = replicate n False @ bl"
   5.279    by (induct n arbitrary: bl) (auto simp: replicate_app_Cons_same)
   5.280  
   5.281  lemma bin_to_bl_zero: "bin_to_bl n 0 = replicate n False"
   5.282 -  unfolding bin_to_bl_def by (simp add: bin_to_bl_zero_aux)
   5.283 +  by (simp add: bin_to_bl_def bin_to_bl_zero_aux)
   5.284  
   5.285 -lemma bin_to_bl_minus1_aux:
   5.286 -  "bin_to_bl_aux n (- 1) bl = replicate n True @ bl"
   5.287 +lemma bin_to_bl_minus1_aux: "bin_to_bl_aux n (- 1) bl = replicate n True @ bl"
   5.288    by (induct n arbitrary: bl) (auto simp: replicate_app_Cons_same)
   5.289  
   5.290  lemma bin_to_bl_minus1: "bin_to_bl n (- 1) = replicate n True"
   5.291 -  unfolding bin_to_bl_def by (simp add: bin_to_bl_minus1_aux)
   5.292 +  by (simp add: bin_to_bl_def bin_to_bl_minus1_aux)
   5.293  
   5.294 -lemma bl_to_bin_rep_F: 
   5.295 -  "bl_to_bin (replicate n False @ bl) = bl_to_bin bl"
   5.296 -  apply (simp add: bin_to_bl_zero_aux [symmetric] bin_bl_bin')
   5.297 -  apply (simp add: bl_to_bin_def)
   5.298 -  done
   5.299 +lemma bl_to_bin_rep_F: "bl_to_bin (replicate n False @ bl) = bl_to_bin bl"
   5.300 +  by (simp add: bin_to_bl_zero_aux [symmetric] bin_bl_bin') (simp add: bl_to_bin_def)
   5.301  
   5.302 -lemma bin_to_bl_trunc [simp]:
   5.303 -  "n <= m ==> bin_to_bl n (bintrunc m w) = bin_to_bl n w"
   5.304 +lemma bin_to_bl_trunc [simp]: "n \<le> m \<Longrightarrow> bin_to_bl n (bintrunc m w) = bin_to_bl n w"
   5.305    by (auto intro: bl_to_bin_inj)
   5.306  
   5.307  lemma bin_to_bl_aux_bintr:
   5.308 -  "bin_to_bl_aux n (bintrunc m bin) bl = 
   5.309 +  "bin_to_bl_aux n (bintrunc m bin) bl =
   5.310      replicate (n - m) False @ bin_to_bl_aux (min n m) bin bl"
   5.311    apply (induct n arbitrary: m bin bl)
   5.312     apply clarsimp
   5.313    apply clarsimp
   5.314    apply (case_tac "m")
   5.315 -   apply (clarsimp simp: bin_to_bl_zero_aux) 
   5.316 +   apply (clarsimp simp: bin_to_bl_zero_aux)
   5.317     apply (erule thin_rl)
   5.318 -   apply (induct_tac n)   
   5.319 +   apply (induct_tac n)
   5.320      apply auto
   5.321    done
   5.322  
   5.323  lemma bin_to_bl_bintr:
   5.324 -  "bin_to_bl n (bintrunc m bin) =
   5.325 -    replicate (n - m) False @ bin_to_bl (min n m) bin"
   5.326 +  "bin_to_bl n (bintrunc m bin) = replicate (n - m) False @ bin_to_bl (min n m) bin"
   5.327    unfolding bin_to_bl_def by (rule bin_to_bl_aux_bintr)
   5.328  
   5.329  lemma bl_to_bin_rep_False: "bl_to_bin (replicate n False) = 0"
   5.330    by (induct n) auto
   5.331  
   5.332 -lemma len_bin_to_bl_aux: 
   5.333 -  "length (bin_to_bl_aux n w bs) = n + length bs"
   5.334 +lemma len_bin_to_bl_aux: "length (bin_to_bl_aux n w bs) = n + length bs"
   5.335    by (fact size_bin_to_bl_aux)
   5.336  
   5.337 -lemma len_bin_to_bl [simp]: "length (bin_to_bl n w) = n"
   5.338 +lemma len_bin_to_bl: "length (bin_to_bl n w) = n"
   5.339    by (fact size_bin_to_bl) (* FIXME: duplicate *)
   5.340 -  
   5.341 -lemma sign_bl_bin': 
   5.342 -  "bin_sign (bl_to_bin_aux bs w) = bin_sign w"
   5.343 +
   5.344 +lemma sign_bl_bin': "bin_sign (bl_to_bin_aux bs w) = bin_sign w"
   5.345    by (induct bs arbitrary: w) auto
   5.346 -  
   5.347 +
   5.348  lemma sign_bl_bin: "bin_sign (bl_to_bin bs) = 0"
   5.349 -  unfolding bl_to_bin_def by (simp add : sign_bl_bin')
   5.350 -  
   5.351 -lemma bl_sbin_sign_aux: 
   5.352 -  "hd (bin_to_bl_aux (Suc n) w bs) = 
   5.353 -    (bin_sign (sbintrunc n w) = -1)"
   5.354 +  by (simp add: bl_to_bin_def sign_bl_bin')
   5.355 +
   5.356 +lemma bl_sbin_sign_aux: "hd (bin_to_bl_aux (Suc n) w bs) = (bin_sign (sbintrunc n w) = -1)"
   5.357    apply (induct n arbitrary: w bs)
   5.358     apply clarsimp
   5.359     apply (cases w rule: bin_exhaust)
   5.360     apply simp
   5.361    done
   5.362 -    
   5.363 -lemma bl_sbin_sign: 
   5.364 -  "hd (bin_to_bl (Suc n) w) = (bin_sign (sbintrunc n w) = -1)"
   5.365 +
   5.366 +lemma bl_sbin_sign: "hd (bin_to_bl (Suc n) w) = (bin_sign (sbintrunc n w) = -1)"
   5.367    unfolding bin_to_bl_def by (rule bl_sbin_sign_aux)
   5.368  
   5.369  lemma bin_nth_of_bl_aux:
   5.370 -  "bin_nth (bl_to_bin_aux bl w) n = 
   5.371 -    (n < size bl & rev bl ! n | n >= length bl & bin_nth w (n - size bl))"
   5.372 +  "bin_nth (bl_to_bin_aux bl w) n =
   5.373 +    (n < size bl \<and> rev bl ! n | n \<ge> length bl \<and> bin_nth w (n - size bl))"
   5.374    apply (induct bl arbitrary: w)
   5.375     apply clarsimp
   5.376    apply clarsimp
   5.377 @@ -281,8 +247,8 @@
   5.378    apply auto
   5.379    done
   5.380  
   5.381 -lemma bin_nth_of_bl: "bin_nth (bl_to_bin bl) n = (n < length bl & rev bl ! n)"
   5.382 -  unfolding bl_to_bin_def by (simp add : bin_nth_of_bl_aux)
   5.383 +lemma bin_nth_of_bl: "bin_nth (bl_to_bin bl) n = (n < length bl \<and> rev bl ! n)"
   5.384 +  by (simp add: bl_to_bin_def bin_nth_of_bl_aux)
   5.385  
   5.386  lemma bin_nth_bl: "n < m \<Longrightarrow> bin_nth w n = nth (rev (bin_to_bl m w)) n"
   5.387    apply (induct n arbitrary: m w)
   5.388 @@ -296,11 +262,10 @@
   5.389    apply (simp add: bin_to_bl_aux_alt)
   5.390    done
   5.391  
   5.392 -lemma nth_rev:
   5.393 -  "n < length xs \<Longrightarrow> rev xs ! n = xs ! (length xs - 1 - n)"
   5.394 +lemma nth_rev: "n < length xs \<Longrightarrow> rev xs ! n = xs ! (length xs - 1 - n)"
   5.395    apply (induct xs)
   5.396     apply simp
   5.397 -  apply (clarsimp simp add : nth_append nth.simps split: nat.split)
   5.398 +  apply (clarsimp simp add: nth_append nth.simps split: nat.split)
   5.399    apply (rule_tac f = "\<lambda>n. xs ! n" in arg_cong)
   5.400    apply arith
   5.401    done
   5.402 @@ -309,7 +274,7 @@
   5.403    by (simp add: nth_rev)
   5.404  
   5.405  lemma nth_bin_to_bl_aux:
   5.406 -  "n < m + length bl \<Longrightarrow> (bin_to_bl_aux m w bl) ! n = 
   5.407 +  "n < m + length bl \<Longrightarrow> (bin_to_bl_aux m w bl) ! n =
   5.408      (if n < m then bin_nth w (m - 1 - n) else bl ! (n - m))"
   5.409    apply (induct m arbitrary: w n bl)
   5.410     apply clarsimp
   5.411 @@ -318,29 +283,29 @@
   5.412    apply simp
   5.413    done
   5.414  
   5.415 -lemma nth_bin_to_bl: "n < m ==> (bin_to_bl m w) ! n = bin_nth w (m - Suc n)"
   5.416 -  unfolding bin_to_bl_def by (simp add : nth_bin_to_bl_aux)
   5.417 +lemma nth_bin_to_bl: "n < m \<Longrightarrow> (bin_to_bl m w) ! n = bin_nth w (m - Suc n)"
   5.418 +  by (simp add: bin_to_bl_def nth_bin_to_bl_aux)
   5.419  
   5.420 -lemma bl_to_bin_lt2p_aux:
   5.421 -  "bl_to_bin_aux bs w < (w + 1) * (2 ^ length bs)"
   5.422 +lemma bl_to_bin_lt2p_aux: "bl_to_bin_aux bs w < (w + 1) * (2 ^ length bs)"
   5.423    apply (induct bs arbitrary: w)
   5.424     apply clarsimp
   5.425    apply clarsimp
   5.426    apply (drule meta_spec, erule xtrans(8) [rotated], simp add: Bit_def)+
   5.427    done
   5.428  
   5.429 -lemma bl_to_bin_lt2p_drop:
   5.430 -  "bl_to_bin bs < 2 ^ length (dropWhile Not bs)"
   5.431 +lemma bl_to_bin_lt2p_drop: "bl_to_bin bs < 2 ^ length (dropWhile Not bs)"
   5.432  proof (induct bs)
   5.433 +  case Nil
   5.434 +  then show ?case by simp
   5.435 +next
   5.436    case (Cons b bs) with bl_to_bin_lt2p_aux[where w=1]
   5.437    show ?case unfolding bl_to_bin_def by simp
   5.438 -qed simp
   5.439 +qed
   5.440  
   5.441  lemma bl_to_bin_lt2p: "bl_to_bin bs < 2 ^ length bs"
   5.442    by (metis bin_bl_bin bintr_lt2p bl_bin_bl)
   5.443  
   5.444 -lemma bl_to_bin_ge2p_aux:
   5.445 -  "bl_to_bin_aux bs w >= w * (2 ^ length bs)"
   5.446 +lemma bl_to_bin_ge2p_aux: "bl_to_bin_aux bs w \<ge> w * (2 ^ length bs)"
   5.447    apply (induct bs arbitrary: w)
   5.448     apply clarsimp
   5.449    apply clarsimp
   5.450 @@ -349,15 +314,14 @@
   5.451     apply (simp add: Bit_def)
   5.452    done
   5.453  
   5.454 -lemma bl_to_bin_ge0: "bl_to_bin bs >= 0"
   5.455 +lemma bl_to_bin_ge0: "bl_to_bin bs \<ge> 0"
   5.456    apply (unfold bl_to_bin_def)
   5.457    apply (rule xtrans(4))
   5.458     apply (rule bl_to_bin_ge2p_aux)
   5.459    apply simp
   5.460    done
   5.461  
   5.462 -lemma butlast_rest_bin: 
   5.463 -  "butlast (bin_to_bl n w) = bin_to_bl (n - 1) (bin_rest w)"
   5.464 +lemma butlast_rest_bin: "butlast (bin_to_bl n w) = bin_to_bl (n - 1) (bin_rest w)"
   5.465    apply (unfold bin_to_bl_def)
   5.466    apply (cases w rule: bin_exhaust)
   5.467    apply (cases n, clarsimp)
   5.468 @@ -365,180 +329,154 @@
   5.469    apply (auto simp add: bin_to_bl_aux_alt)
   5.470    done
   5.471  
   5.472 -lemma butlast_bin_rest:
   5.473 -  "butlast bl = bin_to_bl (length bl - Suc 0) (bin_rest (bl_to_bin bl))"
   5.474 +lemma butlast_bin_rest: "butlast bl = bin_to_bl (length bl - Suc 0) (bin_rest (bl_to_bin bl))"
   5.475    using butlast_rest_bin [where w="bl_to_bin bl" and n="length bl"] by simp
   5.476  
   5.477  lemma butlast_rest_bl2bin_aux:
   5.478 -  "bl ~= [] \<Longrightarrow>
   5.479 -    bl_to_bin_aux (butlast bl) w = bin_rest (bl_to_bin_aux bl w)"
   5.480 +  "bl \<noteq> [] \<Longrightarrow> bl_to_bin_aux (butlast bl) w = bin_rest (bl_to_bin_aux bl w)"
   5.481    by (induct bl arbitrary: w) auto
   5.482 -  
   5.483 -lemma butlast_rest_bl2bin: 
   5.484 -  "bl_to_bin (butlast bl) = bin_rest (bl_to_bin bl)"
   5.485 -  apply (unfold bl_to_bin_def)
   5.486 -  apply (cases bl)
   5.487 -   apply (auto simp add: butlast_rest_bl2bin_aux)
   5.488 -  done
   5.489 +
   5.490 +lemma butlast_rest_bl2bin: "bl_to_bin (butlast bl) = bin_rest (bl_to_bin bl)"
   5.491 +  by (cases bl) (auto simp: bl_to_bin_def butlast_rest_bl2bin_aux)
   5.492  
   5.493  lemma trunc_bl2bin_aux:
   5.494 -  "bintrunc m (bl_to_bin_aux bl w) = 
   5.495 +  "bintrunc m (bl_to_bin_aux bl w) =
   5.496      bl_to_bin_aux (drop (length bl - m) bl) (bintrunc (m - length bl) w)"
   5.497  proof (induct bl arbitrary: w)
   5.498 -  case Nil show ?case by simp
   5.499 +  case Nil
   5.500 +  show ?case by simp
   5.501  next
   5.502 -  case (Cons b bl) show ?case
   5.503 +  case (Cons b bl)
   5.504 +  show ?case
   5.505    proof (cases "m - length bl")
   5.506 -    case 0 then have "Suc (length bl) - m = Suc (length bl - m)" by simp
   5.507 +    case 0
   5.508 +    then have "Suc (length bl) - m = Suc (length bl - m)" by simp
   5.509      with Cons show ?thesis by simp
   5.510    next
   5.511 -    case (Suc n) then have *: "m - Suc (length bl) = n" by simp
   5.512 -    with Suc Cons show ?thesis by simp
   5.513 +    case (Suc n)
   5.514 +    then have "m - Suc (length bl) = n" by simp
   5.515 +    with Cons Suc show ?thesis by simp
   5.516    qed
   5.517  qed
   5.518  
   5.519 -lemma trunc_bl2bin: 
   5.520 -  "bintrunc m (bl_to_bin bl) = bl_to_bin (drop (length bl - m) bl)"
   5.521 -  unfolding bl_to_bin_def by (simp add : trunc_bl2bin_aux)
   5.522 -  
   5.523 -lemma trunc_bl2bin_len [simp]:
   5.524 -  "bintrunc (length bl) (bl_to_bin bl) = bl_to_bin bl"
   5.525 +lemma trunc_bl2bin: "bintrunc m (bl_to_bin bl) = bl_to_bin (drop (length bl - m) bl)"
   5.526 +  by (simp add: bl_to_bin_def trunc_bl2bin_aux)
   5.527 +
   5.528 +lemma trunc_bl2bin_len [simp]: "bintrunc (length bl) (bl_to_bin bl) = bl_to_bin bl"
   5.529    by (simp add: trunc_bl2bin)
   5.530  
   5.531 -lemma bl2bin_drop: 
   5.532 -  "bl_to_bin (drop k bl) = bintrunc (length bl - k) (bl_to_bin bl)"
   5.533 +lemma bl2bin_drop: "bl_to_bin (drop k bl) = bintrunc (length bl - k) (bl_to_bin bl)"
   5.534    apply (rule trans)
   5.535     prefer 2
   5.536     apply (rule trunc_bl2bin [symmetric])
   5.537 -  apply (cases "k <= length bl")
   5.538 +  apply (cases "k \<le> length bl")
   5.539     apply auto
   5.540    done
   5.541  
   5.542 -lemma nth_rest_power_bin:
   5.543 -  "bin_nth ((bin_rest ^^ k) w) n = bin_nth w (n + k)"
   5.544 -  apply (induct k arbitrary: n, clarsimp)
   5.545 +lemma nth_rest_power_bin: "bin_nth ((bin_rest ^^ k) w) n = bin_nth w (n + k)"
   5.546 +  apply (induct k arbitrary: n)
   5.547 +   apply clarsimp
   5.548    apply clarsimp
   5.549    apply (simp only: bin_nth.Suc [symmetric] add_Suc)
   5.550    done
   5.551  
   5.552 -lemma take_rest_power_bin:
   5.553 -  "m <= n ==> take m (bin_to_bl n w) = bin_to_bl m ((bin_rest ^^ (n - m)) w)" 
   5.554 +lemma take_rest_power_bin: "m \<le> n \<Longrightarrow> take m (bin_to_bl n w) = bin_to_bl m ((bin_rest ^^ (n - m)) w)"
   5.555    apply (rule nth_equalityI)
   5.556     apply simp
   5.557    apply (clarsimp simp add: nth_bin_to_bl nth_rest_power_bin)
   5.558    done
   5.559  
   5.560 -lemma hd_butlast: "size xs > 1 ==> hd (butlast xs) = hd xs"
   5.561 +lemma hd_butlast: "size xs > 1 \<Longrightarrow> hd (butlast xs) = hd xs"
   5.562    by (cases xs) auto
   5.563  
   5.564 -lemma last_bin_last': 
   5.565 -  "size xs > 0 \<Longrightarrow> last xs \<longleftrightarrow> bin_last (bl_to_bin_aux xs w)" 
   5.566 +lemma last_bin_last': "size xs > 0 \<Longrightarrow> last xs \<longleftrightarrow> bin_last (bl_to_bin_aux xs w)"
   5.567    by (induct xs arbitrary: w) auto
   5.568  
   5.569 -lemma last_bin_last: 
   5.570 -  "size xs > 0 ==> last xs \<longleftrightarrow> bin_last (bl_to_bin xs)" 
   5.571 +lemma last_bin_last: "size xs > 0 \<Longrightarrow> last xs \<longleftrightarrow> bin_last (bl_to_bin xs)"
   5.572    unfolding bl_to_bin_def by (erule last_bin_last')
   5.573 -  
   5.574 -lemma bin_last_last: 
   5.575 -  "bin_last w \<longleftrightarrow> last (bin_to_bl (Suc n) w)" 
   5.576 -  apply (unfold bin_to_bl_def)
   5.577 -  apply simp
   5.578 -  apply (auto simp add: bin_to_bl_aux_alt)
   5.579 -  done
   5.580 +
   5.581 +lemma bin_last_last: "bin_last w \<longleftrightarrow> last (bin_to_bl (Suc n) w)"
   5.582 +  by (simp add: bin_to_bl_def) (auto simp: bin_to_bl_aux_alt)
   5.583 +
   5.584  
   5.585 -(** links between bit-wise operations and operations on bool lists **)
   5.586 -    
   5.587 +subsection \<open>Links between bit-wise operations and operations on bool lists\<close>
   5.588 +
   5.589  lemma bl_xor_aux_bin:
   5.590 -  "map2 (%x y. x ~= y) (bin_to_bl_aux n v bs) (bin_to_bl_aux n w cs) = 
   5.591 -    bin_to_bl_aux n (v XOR w) (map2 (%x y. x ~= y) bs cs)"
   5.592 +  "map2 (\<lambda>x y. x \<noteq> y) (bin_to_bl_aux n v bs) (bin_to_bl_aux n w cs) =
   5.593 +    bin_to_bl_aux n (v XOR w) (map2 (\<lambda>x y. x \<noteq> y) bs cs)"
   5.594    apply (induct n arbitrary: v w bs cs)
   5.595     apply simp
   5.596    apply (case_tac v rule: bin_exhaust)
   5.597    apply (case_tac w rule: bin_exhaust)
   5.598    apply clarsimp
   5.599    apply (case_tac b)
   5.600 -  apply auto
   5.601 +   apply auto
   5.602    done
   5.603  
   5.604  lemma bl_or_aux_bin:
   5.605 -  "map2 (op | ) (bin_to_bl_aux n v bs) (bin_to_bl_aux n w cs) = 
   5.606 -    bin_to_bl_aux n (v OR w) (map2 (op | ) bs cs)"
   5.607 +  "map2 (op \<or>) (bin_to_bl_aux n v bs) (bin_to_bl_aux n w cs) =
   5.608 +    bin_to_bl_aux n (v OR w) (map2 (op \<or>) bs cs)"
   5.609    apply (induct n arbitrary: v w bs cs)
   5.610     apply simp
   5.611    apply (case_tac v rule: bin_exhaust)
   5.612    apply (case_tac w rule: bin_exhaust)
   5.613    apply clarsimp
   5.614    done
   5.615 -    
   5.616 +
   5.617  lemma bl_and_aux_bin:
   5.618 -  "map2 (op & ) (bin_to_bl_aux n v bs) (bin_to_bl_aux n w cs) = 
   5.619 -    bin_to_bl_aux n (v AND w) (map2 (op & ) bs cs)" 
   5.620 +  "map2 (op \<and>) (bin_to_bl_aux n v bs) (bin_to_bl_aux n w cs) =
   5.621 +    bin_to_bl_aux n (v AND w) (map2 (op \<and>) bs cs)"
   5.622    apply (induct n arbitrary: v w bs cs)
   5.623     apply simp
   5.624    apply (case_tac v rule: bin_exhaust)
   5.625    apply (case_tac w rule: bin_exhaust)
   5.626    apply clarsimp
   5.627    done
   5.628 -    
   5.629 -lemma bl_not_aux_bin:
   5.630 -  "map Not (bin_to_bl_aux n w cs) = 
   5.631 -    bin_to_bl_aux n (NOT w) (map Not cs)"
   5.632 -  apply (induct n arbitrary: w cs)
   5.633 -   apply clarsimp
   5.634 -  apply clarsimp
   5.635 -  done
   5.636 +
   5.637 +lemma bl_not_aux_bin: "map Not (bin_to_bl_aux n w cs) = bin_to_bl_aux n (NOT w) (map Not cs)"
   5.638 +  by (induct n arbitrary: w cs) auto
   5.639  
   5.640  lemma bl_not_bin: "map Not (bin_to_bl n w) = bin_to_bl n (NOT w)"
   5.641 -  unfolding bin_to_bl_def by (simp add: bl_not_aux_bin)
   5.642 +  by (simp add: bin_to_bl_def bl_not_aux_bin)
   5.643  
   5.644 -lemma bl_and_bin:
   5.645 -  "map2 (op \<and>) (bin_to_bl n v) (bin_to_bl n w) = bin_to_bl n (v AND w)"
   5.646 -  unfolding bin_to_bl_def by (simp add: bl_and_aux_bin)
   5.647 +lemma bl_and_bin: "map2 (op \<and>) (bin_to_bl n v) (bin_to_bl n w) = bin_to_bl n (v AND w)"
   5.648 +  by (simp add: bin_to_bl_def bl_and_aux_bin)
   5.649  
   5.650 -lemma bl_or_bin:
   5.651 -  "map2 (op \<or>) (bin_to_bl n v) (bin_to_bl n w) = bin_to_bl n (v OR w)"
   5.652 -  unfolding bin_to_bl_def by (simp add: bl_or_aux_bin)
   5.653 +lemma bl_or_bin: "map2 (op \<or>) (bin_to_bl n v) (bin_to_bl n w) = bin_to_bl n (v OR w)"
   5.654 +  by (simp add: bin_to_bl_def bl_or_aux_bin)
   5.655  
   5.656 -lemma bl_xor_bin:
   5.657 -  "map2 (\<lambda>x y. x \<noteq> y) (bin_to_bl n v) (bin_to_bl n w) = bin_to_bl n (v XOR w)"
   5.658 -  unfolding bin_to_bl_def by (simp only: bl_xor_aux_bin map2_Nil)
   5.659 +lemma bl_xor_bin: "map2 (\<lambda>x y. x \<noteq> y) (bin_to_bl n v) (bin_to_bl n w) = bin_to_bl n (v XOR w)"
   5.660 +  by (simp only: bin_to_bl_def bl_xor_aux_bin map2_Nil)
   5.661  
   5.662  lemma drop_bin2bl_aux:
   5.663 -  "drop m (bin_to_bl_aux n bin bs) = 
   5.664 +  "drop m (bin_to_bl_aux n bin bs) =
   5.665      bin_to_bl_aux (n - m) bin (drop (m - n) bs)"
   5.666    apply (induct n arbitrary: m bin bs, clarsimp)
   5.667    apply clarsimp
   5.668    apply (case_tac bin rule: bin_exhaust)
   5.669 -  apply (case_tac "m <= n", simp)
   5.670 +  apply (case_tac "m \<le> n", simp)
   5.671    apply (case_tac "m - n", simp)
   5.672    apply simp
   5.673 -  apply (rule_tac f = "%nat. drop nat bs" in arg_cong) 
   5.674 +  apply (rule_tac f = "\<lambda>nat. drop nat bs" in arg_cong)
   5.675    apply simp
   5.676    done
   5.677  
   5.678  lemma drop_bin2bl: "drop m (bin_to_bl n bin) = bin_to_bl (n - m) bin"
   5.679 -  unfolding bin_to_bl_def by (simp add : drop_bin2bl_aux)
   5.680 +  by (simp add: bin_to_bl_def drop_bin2bl_aux)
   5.681  
   5.682 -lemma take_bin2bl_lem1:
   5.683 -  "take m (bin_to_bl_aux m w bs) = bin_to_bl m w"
   5.684 -  apply (induct m arbitrary: w bs, clarsimp)
   5.685 +lemma take_bin2bl_lem1: "take m (bin_to_bl_aux m w bs) = bin_to_bl m w"
   5.686 +  apply (induct m arbitrary: w bs)
   5.687 +   apply clarsimp
   5.688    apply clarsimp
   5.689    apply (simp add: bin_to_bl_aux_alt)
   5.690    apply (simp add: bin_to_bl_def)
   5.691    apply (simp add: bin_to_bl_aux_alt)
   5.692    done
   5.693  
   5.694 -lemma take_bin2bl_lem:
   5.695 -  "take m (bin_to_bl_aux (m + n) w bs) = 
   5.696 -    take m (bin_to_bl (m + n) w)"
   5.697 -  apply (induct n arbitrary: w bs)
   5.698 -   apply (simp_all (no_asm) add: bin_to_bl_def take_bin2bl_lem1)
   5.699 -  apply simp
   5.700 -  done
   5.701 +lemma take_bin2bl_lem: "take m (bin_to_bl_aux (m + n) w bs) = take m (bin_to_bl (m + n) w)"
   5.702 +  by (induct n arbitrary: w bs) (simp_all (no_asm) add: bin_to_bl_def take_bin2bl_lem1, simp)
   5.703  
   5.704 -lemma bin_split_take:
   5.705 -  "bin_split n c = (a, b) \<Longrightarrow>
   5.706 -    bin_to_bl m a = take m (bin_to_bl (m + n) c)"
   5.707 +lemma bin_split_take: "bin_split n c = (a, b) \<Longrightarrow> bin_to_bl m a = take m (bin_to_bl (m + n) c)"
   5.708    apply (induct n arbitrary: b c)
   5.709     apply clarsimp
   5.710    apply (clarsimp simp: Let_def split: prod.split_asm)
   5.711 @@ -546,71 +484,59 @@
   5.712    apply (simp add: take_bin2bl_lem)
   5.713    done
   5.714  
   5.715 -lemma bin_split_take1: 
   5.716 -  "k = m + n ==> bin_split n c = (a, b) ==> 
   5.717 -    bin_to_bl m a = take m (bin_to_bl k c)"
   5.718 +lemma bin_split_take1:
   5.719 +  "k = m + n \<Longrightarrow> bin_split n c = (a, b) \<Longrightarrow> bin_to_bl m a = take m (bin_to_bl k c)"
   5.720    by (auto elim: bin_split_take)
   5.721 -  
   5.722 -lemma nth_takefill: "m < n \<Longrightarrow>
   5.723 -    takefill fill n l ! m = (if m < length l then l ! m else fill)"
   5.724 -  apply (induct n arbitrary: m l, clarsimp)
   5.725 +
   5.726 +lemma nth_takefill: "m < n \<Longrightarrow> takefill fill n l ! m = (if m < length l then l ! m else fill)"
   5.727 +  apply (induct n arbitrary: m l)
   5.728 +   apply clarsimp
   5.729    apply clarsimp
   5.730    apply (case_tac m)
   5.731     apply (simp split: list.split)
   5.732    apply (simp split: list.split)
   5.733    done
   5.734  
   5.735 -lemma takefill_alt:
   5.736 -  "takefill fill n l = take n l @ replicate (n - length l) fill"
   5.737 +lemma takefill_alt: "takefill fill n l = take n l @ replicate (n - length l) fill"
   5.738    by (induct n arbitrary: l) (auto split: list.split)
   5.739  
   5.740 -lemma takefill_replicate [simp]:
   5.741 -  "takefill fill n (replicate m fill) = replicate n fill"
   5.742 -  by (simp add : takefill_alt replicate_add [symmetric])
   5.743 +lemma takefill_replicate [simp]: "takefill fill n (replicate m fill) = replicate n fill"
   5.744 +  by (simp add: takefill_alt replicate_add [symmetric])
   5.745  
   5.746 -lemma takefill_le':
   5.747 -  "n = m + k \<Longrightarrow> takefill x m (takefill x n l) = takefill x m l"
   5.748 +lemma takefill_le': "n = m + k \<Longrightarrow> takefill x m (takefill x n l) = takefill x m l"
   5.749    by (induct m arbitrary: l n) (auto split: list.split)
   5.750  
   5.751  lemma length_takefill [simp]: "length (takefill fill n l) = n"
   5.752 -  by (simp add : takefill_alt)
   5.753 +  by (simp add: takefill_alt)
   5.754  
   5.755 -lemma take_takefill':
   5.756 -  "!!w n.  n = k + m ==> take k (takefill fill n w) = takefill fill k w"
   5.757 -  by (induct k) (auto split: list.split) 
   5.758 +lemma take_takefill': "\<And>w n.  n = k + m \<Longrightarrow> take k (takefill fill n w) = takefill fill k w"
   5.759 +  by (induct k) (auto split: list.split)
   5.760  
   5.761 -lemma drop_takefill:
   5.762 -  "!!w. drop k (takefill fill (m + k) w) = takefill fill m (drop k w)"
   5.763 -  by (induct k) (auto split: list.split) 
   5.764 +lemma drop_takefill: "\<And>w. drop k (takefill fill (m + k) w) = takefill fill m (drop k w)"
   5.765 +  by (induct k) (auto split: list.split)
   5.766  
   5.767 -lemma takefill_le [simp]:
   5.768 -  "m \<le> n \<Longrightarrow> takefill x m (takefill x n l) = takefill x m l"
   5.769 +lemma takefill_le [simp]: "m \<le> n \<Longrightarrow> takefill x m (takefill x n l) = takefill x m l"
   5.770    by (auto simp: le_iff_add takefill_le')
   5.771  
   5.772 -lemma take_takefill [simp]:
   5.773 -  "m \<le> n \<Longrightarrow> take m (takefill fill n w) = takefill fill m w"
   5.774 +lemma take_takefill [simp]: "m \<le> n \<Longrightarrow> take m (takefill fill n w) = takefill fill m w"
   5.775    by (auto simp: le_iff_add take_takefill')
   5.776 - 
   5.777 -lemma takefill_append:
   5.778 -  "takefill fill (m + length xs) (xs @ w) = xs @ (takefill fill m w)"
   5.779 +
   5.780 +lemma takefill_append: "takefill fill (m + length xs) (xs @ w) = xs @ (takefill fill m w)"
   5.781    by (induct xs) auto
   5.782  
   5.783 -lemma takefill_same': 
   5.784 -  "l = length xs ==> takefill fill l xs = xs"
   5.785 -  by (induct xs arbitrary: l, auto)
   5.786 - 
   5.787 +lemma takefill_same': "l = length xs \<Longrightarrow> takefill fill l xs = xs"
   5.788 +  by (induct xs arbitrary: l) auto
   5.789 +
   5.790  lemmas takefill_same [simp] = takefill_same' [OF refl]
   5.791  
   5.792 -lemma takefill_bintrunc:
   5.793 -  "takefill False n bl = rev (bin_to_bl n (bl_to_bin (rev bl)))"
   5.794 +lemma takefill_bintrunc: "takefill False n bl = rev (bin_to_bl n (bl_to_bin (rev bl)))"
   5.795    apply (rule nth_equalityI)
   5.796     apply simp
   5.797    apply (clarsimp simp: nth_takefill nth_rev nth_bin_to_bl bin_nth_of_bl)
   5.798    done
   5.799  
   5.800 -lemma bl_bin_bl_rtf:
   5.801 -  "bin_to_bl n (bl_to_bin bl) = rev (takefill False n (rev bl))"
   5.802 -  by (simp add : takefill_bintrunc)
   5.803 +lemma bl_bin_bl_rtf: "bin_to_bl n (bl_to_bin bl) = rev (takefill False n (rev bl))"
   5.804 +  by (simp add: takefill_bintrunc)
   5.805  
   5.806  lemma bl_bin_bl_rep_drop:
   5.807    "bin_to_bl n (bl_to_bin bl) =
   5.808 @@ -618,25 +544,24 @@
   5.809    by (simp add: bl_bin_bl_rtf takefill_alt rev_take)
   5.810  
   5.811  lemma tf_rev:
   5.812 -  "n + k = m + length bl ==> takefill x m (rev (takefill y n bl)) = 
   5.813 +  "n + k = m + length bl \<Longrightarrow> takefill x m (rev (takefill y n bl)) =
   5.814      rev (takefill y m (rev (takefill x k (rev bl))))"
   5.815    apply (rule nth_equalityI)
   5.816     apply (auto simp add: nth_takefill nth_rev)
   5.817 -  apply (rule_tac f = "%n. bl ! n" in arg_cong) 
   5.818 -  apply arith 
   5.819 +  apply (rule_tac f = "\<lambda>n. bl ! n" in arg_cong)
   5.820 +  apply arith
   5.821    done
   5.822  
   5.823 -lemma takefill_minus:
   5.824 -  "0 < n ==> takefill fill (Suc (n - 1)) w = takefill fill n w"
   5.825 +lemma takefill_minus: "0 < n \<Longrightarrow> takefill fill (Suc (n - 1)) w = takefill fill n w"
   5.826    by auto
   5.827  
   5.828 -lemmas takefill_Suc_cases = 
   5.829 +lemmas takefill_Suc_cases =
   5.830    list.cases [THEN takefill.Suc [THEN trans]]
   5.831  
   5.832  lemmas takefill_Suc_Nil = takefill_Suc_cases (1)
   5.833  lemmas takefill_Suc_Cons = takefill_Suc_cases (2)
   5.834  
   5.835 -lemmas takefill_minus_simps = takefill_Suc_cases [THEN [2] 
   5.836 +lemmas takefill_minus_simps = takefill_Suc_cases [THEN [2]
   5.837    takefill_minus [symmetric, THEN trans]]
   5.838  
   5.839  lemma takefill_numeral_Nil [simp]:
   5.840 @@ -647,32 +572,29 @@
   5.841    "takefill fill (numeral k) (x # xs) = x # takefill fill (pred_numeral k) xs"
   5.842    by (simp add: numeral_eq_Suc)
   5.843  
   5.844 -(* links with function bl_to_bin *)
   5.845 +
   5.846 +subsection \<open>Links with function \<open>bl_to_bin\<close>\<close>
   5.847  
   5.848 -lemma bl_to_bin_aux_cat: 
   5.849 -  "!!nv v. bl_to_bin_aux bs (bin_cat w nv v) = 
   5.850 +lemma bl_to_bin_aux_cat:
   5.851 +  "\<And>nv v. bl_to_bin_aux bs (bin_cat w nv v) =
   5.852      bin_cat w (nv + length bs) (bl_to_bin_aux bs v)"
   5.853 -  apply (induct bs)
   5.854 -   apply simp
   5.855 -  apply (simp add: bin_cat_Suc_Bit [symmetric] del: bin_cat.simps)
   5.856 -  done
   5.857 +  by (induct bs) (simp, simp add: bin_cat_Suc_Bit [symmetric] del: bin_cat.simps)
   5.858  
   5.859 -lemma bin_to_bl_aux_cat: 
   5.860 -  "!!w bs. bin_to_bl_aux (nv + nw) (bin_cat v nw w) bs = 
   5.861 +lemma bin_to_bl_aux_cat:
   5.862 +  "\<And>w bs. bin_to_bl_aux (nv + nw) (bin_cat v nw w) bs =
   5.863      bin_to_bl_aux nv v (bin_to_bl_aux nw w bs)"
   5.864 -  by (induct nw) auto 
   5.865 +  by (induct nw) auto
   5.866  
   5.867 -lemma bl_to_bin_aux_alt:
   5.868 -  "bl_to_bin_aux bs w = bin_cat w (length bs) (bl_to_bin bs)"
   5.869 +lemma bl_to_bin_aux_alt: "bl_to_bin_aux bs w = bin_cat w (length bs) (bl_to_bin bs)"
   5.870    using bl_to_bin_aux_cat [where nv = "0" and v = "0"]
   5.871 -  unfolding bl_to_bin_def [symmetric] by simp
   5.872 +  by (simp add: bl_to_bin_def [symmetric])
   5.873  
   5.874  lemma bin_to_bl_cat:
   5.875    "bin_to_bl (nv + nw) (bin_cat v nw w) =
   5.876      bin_to_bl_aux nv v (bin_to_bl nw w)"
   5.877 -  unfolding bin_to_bl_def by (simp add: bin_to_bl_aux_cat)
   5.878 +  by (simp add: bin_to_bl_def bin_to_bl_aux_cat)
   5.879  
   5.880 -lemmas bl_to_bin_aux_app_cat = 
   5.881 +lemmas bl_to_bin_aux_app_cat =
   5.882    trans [OF bl_to_bin_aux_append bl_to_bin_aux_alt]
   5.883  
   5.884  lemmas bin_to_bl_aux_cat_app =
   5.885 @@ -686,49 +608,46 @@
   5.886    "bin_to_bl (n + nw) (bin_cat w nw wa) = bin_to_bl n w @ bin_to_bl nw wa"
   5.887    by (simp only: bin_to_bl_def bin_to_bl_aux_cat_app)
   5.888  
   5.889 -(* bl_to_bin_app_cat_alt and bl_to_bin_app_cat are easily interderivable *)
   5.890 -lemma bl_to_bin_app_cat_alt: 
   5.891 -  "bin_cat (bl_to_bin cs) n w = bl_to_bin (cs @ bin_to_bl n w)"
   5.892 -  by (simp add : bl_to_bin_app_cat)
   5.893 +text \<open>\<open>bl_to_bin_app_cat_alt\<close> and \<open>bl_to_bin_app_cat\<close> are easily interderivable.\<close>
   5.894 +lemma bl_to_bin_app_cat_alt: "bin_cat (bl_to_bin cs) n w = bl_to_bin (cs @ bin_to_bl n w)"
   5.895 +  by (simp add: bl_to_bin_app_cat)
   5.896  
   5.897 -lemma mask_lem: "(bl_to_bin (True # replicate n False)) = 
   5.898 -    (bl_to_bin (replicate n True)) + 1"
   5.899 +lemma mask_lem: "(bl_to_bin (True # replicate n False)) = bl_to_bin (replicate n True) + 1"
   5.900    apply (unfold bl_to_bin_def)
   5.901    apply (induct n)
   5.902     apply simp
   5.903 -  apply (simp only: Suc_eq_plus1 replicate_add
   5.904 -                    append_Cons [symmetric] bl_to_bin_aux_append)
   5.905 +  apply (simp only: Suc_eq_plus1 replicate_add append_Cons [symmetric] bl_to_bin_aux_append)
   5.906    apply (simp add: Bit_B0_2t Bit_B1_2t)
   5.907    done
   5.908  
   5.909 -(* function bl_of_nth *)
   5.910 +
   5.911 +subsection \<open>Function \<open>bl_of_nth\<close>\<close>
   5.912 +
   5.913  lemma length_bl_of_nth [simp]: "length (bl_of_nth n f) = n"
   5.914    by (induct n)  auto
   5.915  
   5.916 -lemma nth_bl_of_nth [simp]:
   5.917 -  "m < n \<Longrightarrow> rev (bl_of_nth n f) ! m = f m"
   5.918 +lemma nth_bl_of_nth [simp]: "m < n \<Longrightarrow> rev (bl_of_nth n f) ! m = f m"
   5.919    apply (induct n)
   5.920     apply simp
   5.921 -  apply (clarsimp simp add : nth_append)
   5.922 -  apply (rule_tac f = "f" in arg_cong) 
   5.923 +  apply (clarsimp simp add: nth_append)
   5.924 +  apply (rule_tac f = "f" in arg_cong)
   5.925    apply simp
   5.926    done
   5.927  
   5.928 -lemma bl_of_nth_inj: 
   5.929 -  "(!!k. k < n ==> f k = g k) ==> bl_of_nth n f = bl_of_nth n g"
   5.930 +lemma bl_of_nth_inj: "(\<And>k. k < n \<Longrightarrow> f k = g k) \<Longrightarrow> bl_of_nth n f = bl_of_nth n g"
   5.931    by (induct n)  auto
   5.932  
   5.933 -lemma bl_of_nth_nth_le:
   5.934 -  "n \<le> length xs \<Longrightarrow> bl_of_nth n (nth (rev xs)) = drop (length xs - n) xs"
   5.935 -  apply (induct n arbitrary: xs, clarsimp)
   5.936 +lemma bl_of_nth_nth_le: "n \<le> length xs \<Longrightarrow> bl_of_nth n (nth (rev xs)) = drop (length xs - n) xs"
   5.937 +  apply (induct n arbitrary: xs)
   5.938 +   apply clarsimp
   5.939    apply clarsimp
   5.940    apply (rule trans [OF _ hd_Cons_tl])
   5.941     apply (frule Suc_le_lessD)
   5.942     apply (simp add: nth_rev trans [OF drop_Suc drop_tl, symmetric])
   5.943     apply (subst hd_drop_conv_nth)
   5.944 -     apply force
   5.945 -    apply simp_all
   5.946 -  apply (rule_tac f = "%n. drop n xs" in arg_cong) 
   5.947 +    apply force
   5.948 +   apply simp_all
   5.949 +  apply (rule_tac f = "\<lambda>n. drop n xs" in arg_cong)
   5.950    apply simp
   5.951    done
   5.952  
   5.953 @@ -741,45 +660,44 @@
   5.954  lemma size_rbl_succ: "length (rbl_succ bl) = length bl"
   5.955    by (induct bl) auto
   5.956  
   5.957 -lemma size_rbl_add:
   5.958 -  "!!cl. length (rbl_add bl cl) = length bl"
   5.959 -  by (induct bl) (auto simp: Let_def size_rbl_succ)
   5.960 +lemma size_rbl_add: "length (rbl_add bl cl) = length bl"
   5.961 +  by (induct bl arbitrary: cl) (auto simp: Let_def size_rbl_succ)
   5.962  
   5.963 -lemma size_rbl_mult: 
   5.964 -  "!!cl. length (rbl_mult bl cl) = length bl"
   5.965 -  by (induct bl) (auto simp add : Let_def size_rbl_add)
   5.966 +lemma size_rbl_mult: "length (rbl_mult bl cl) = length bl"
   5.967 +  by (induct bl arbitrary: cl) (auto simp add: Let_def size_rbl_add)
   5.968  
   5.969 -lemmas rbl_sizes [simp] = 
   5.970 +lemmas rbl_sizes [simp] =
   5.971    size_rbl_pred size_rbl_succ size_rbl_add size_rbl_mult
   5.972  
   5.973  lemmas rbl_Nils =
   5.974    rbl_pred.Nil rbl_succ.Nil rbl_add.Nil rbl_mult.Nil
   5.975  
   5.976 -lemma rbl_pred:
   5.977 -  "rbl_pred (rev (bin_to_bl n bin)) = rev (bin_to_bl n (bin - 1))"
   5.978 -  apply (induct n arbitrary: bin, simp)
   5.979 +lemma rbl_pred: "rbl_pred (rev (bin_to_bl n bin)) = rev (bin_to_bl n (bin - 1))"
   5.980    apply (unfold bin_to_bl_def)
   5.981 +  apply (induct n arbitrary: bin)
   5.982 +   apply simp
   5.983    apply clarsimp
   5.984    apply (case_tac bin rule: bin_exhaust)
   5.985    apply (case_tac b)
   5.986     apply (clarsimp simp: bin_to_bl_aux_alt)+
   5.987    done
   5.988  
   5.989 -lemma rbl_succ: 
   5.990 -  "rbl_succ (rev (bin_to_bl n bin)) = rev (bin_to_bl n (bin + 1))"
   5.991 -  apply (induct n arbitrary: bin, simp)
   5.992 +lemma rbl_succ: "rbl_succ (rev (bin_to_bl n bin)) = rev (bin_to_bl n (bin + 1))"
   5.993    apply (unfold bin_to_bl_def)
   5.994 +  apply (induct n arbitrary: bin)
   5.995 +   apply simp
   5.996    apply clarsimp
   5.997    apply (case_tac bin rule: bin_exhaust)
   5.998    apply (case_tac b)
   5.999     apply (clarsimp simp: bin_to_bl_aux_alt)+
  5.1000    done
  5.1001  
  5.1002 -lemma rbl_add: 
  5.1003 -  "!!bina binb. rbl_add (rev (bin_to_bl n bina)) (rev (bin_to_bl n binb)) = 
  5.1004 +lemma rbl_add:
  5.1005 +  "\<And>bina binb. rbl_add (rev (bin_to_bl n bina)) (rev (bin_to_bl n binb)) =
  5.1006      rev (bin_to_bl n (bina + binb))"
  5.1007 -  apply (induct n, simp)
  5.1008    apply (unfold bin_to_bl_def)
  5.1009 +  apply (induct n)
  5.1010 +   apply simp
  5.1011    apply clarsimp
  5.1012    apply (case_tac bina rule: bin_exhaust)
  5.1013    apply (case_tac binb rule: bin_exhaust)
  5.1014 @@ -788,82 +706,77 @@
  5.1015       apply (auto simp: rbl_succ bin_to_bl_aux_alt Let_def ac_simps)
  5.1016    done
  5.1017  
  5.1018 -lemma rbl_add_app2: 
  5.1019 -  "!!blb. length blb >= length bla ==> 
  5.1020 -    rbl_add bla (blb @ blc) = rbl_add bla blb"
  5.1021 -  apply (induct bla, simp)
  5.1022 +lemma rbl_add_app2: "length blb \<ge> length bla \<Longrightarrow> rbl_add bla (blb @ blc) = rbl_add bla blb"
  5.1023 +  apply (induct bla arbitrary: blb)
  5.1024 +   apply simp
  5.1025    apply clarsimp
  5.1026    apply (case_tac blb, clarsimp)
  5.1027    apply (clarsimp simp: Let_def)
  5.1028    done
  5.1029  
  5.1030 -lemma rbl_add_take2: 
  5.1031 -  "!!blb. length blb >= length bla ==> 
  5.1032 -    rbl_add bla (take (length bla) blb) = rbl_add bla blb"
  5.1033 -  apply (induct bla, simp)
  5.1034 +lemma rbl_add_take2:
  5.1035 +  "length blb >= length bla ==> rbl_add bla (take (length bla) blb) = rbl_add bla blb"
  5.1036 +  apply (induct bla arbitrary: blb)
  5.1037 +   apply simp
  5.1038    apply clarsimp
  5.1039    apply (case_tac blb, clarsimp)
  5.1040    apply (clarsimp simp: Let_def)
  5.1041    done
  5.1042  
  5.1043 -lemma rbl_add_long: 
  5.1044 -  "m >= n ==> rbl_add (rev (bin_to_bl n bina)) (rev (bin_to_bl m binb)) = 
  5.1045 +lemma rbl_add_long:
  5.1046 +  "m \<ge> n \<Longrightarrow> rbl_add (rev (bin_to_bl n bina)) (rev (bin_to_bl m binb)) =
  5.1047      rev (bin_to_bl n (bina + binb))"
  5.1048    apply (rule box_equals [OF _ rbl_add_take2 rbl_add])
  5.1049 -   apply (rule_tac f = "rbl_add (rev (bin_to_bl n bina))" in arg_cong) 
  5.1050 +   apply (rule_tac f = "rbl_add (rev (bin_to_bl n bina))" in arg_cong)
  5.1051     apply (rule rev_swap [THEN iffD1])
  5.1052     apply (simp add: rev_take drop_bin2bl)
  5.1053    apply simp
  5.1054    done
  5.1055  
  5.1056 -lemma rbl_mult_app2:
  5.1057 -  "!!blb. length blb >= length bla ==> 
  5.1058 -    rbl_mult bla (blb @ blc) = rbl_mult bla blb"
  5.1059 -  apply (induct bla, simp)
  5.1060 +lemma rbl_mult_app2: "length blb \<ge> length bla \<Longrightarrow> rbl_mult bla (blb @ blc) = rbl_mult bla blb"
  5.1061 +  apply (induct bla arbitrary: blb)
  5.1062 +   apply simp
  5.1063    apply clarsimp
  5.1064    apply (case_tac blb, clarsimp)
  5.1065    apply (clarsimp simp: Let_def rbl_add_app2)
  5.1066    done
  5.1067  
  5.1068 -lemma rbl_mult_take2: 
  5.1069 -  "length blb >= length bla ==> 
  5.1070 -    rbl_mult bla (take (length bla) blb) = rbl_mult bla blb"
  5.1071 +lemma rbl_mult_take2:
  5.1072 +  "length blb \<ge> length bla \<Longrightarrow> rbl_mult bla (take (length bla) blb) = rbl_mult bla blb"
  5.1073    apply (rule trans)
  5.1074     apply (rule rbl_mult_app2 [symmetric])
  5.1075     apply simp
  5.1076 -  apply (rule_tac f = "rbl_mult bla" in arg_cong) 
  5.1077 +  apply (rule_tac f = "rbl_mult bla" in arg_cong)
  5.1078    apply (rule append_take_drop_id)
  5.1079    done
  5.1080 -    
  5.1081 -lemma rbl_mult_gt1: 
  5.1082 -  "m >= length bl ==> rbl_mult bl (rev (bin_to_bl m binb)) = 
  5.1083 +
  5.1084 +lemma rbl_mult_gt1:
  5.1085 +  "m \<ge> length bl \<Longrightarrow>
  5.1086 +    rbl_mult bl (rev (bin_to_bl m binb)) =
  5.1087      rbl_mult bl (rev (bin_to_bl (length bl) binb))"
  5.1088    apply (rule trans)
  5.1089     apply (rule rbl_mult_take2 [symmetric])
  5.1090     apply simp_all
  5.1091 -  apply (rule_tac f = "rbl_mult bl" in arg_cong) 
  5.1092 +  apply (rule_tac f = "rbl_mult bl" in arg_cong)
  5.1093    apply (rule rev_swap [THEN iffD1])
  5.1094    apply (simp add: rev_take drop_bin2bl)
  5.1095    done
  5.1096 -    
  5.1097 -lemma rbl_mult_gt: 
  5.1098 -  "m > n ==> rbl_mult (rev (bin_to_bl n bina)) (rev (bin_to_bl m binb)) = 
  5.1099 +
  5.1100 +lemma rbl_mult_gt:
  5.1101 +  "m > n \<Longrightarrow>
  5.1102 +    rbl_mult (rev (bin_to_bl n bina)) (rev (bin_to_bl m binb)) =
  5.1103      rbl_mult (rev (bin_to_bl n bina)) (rev (bin_to_bl n binb))"
  5.1104    by (auto intro: trans [OF rbl_mult_gt1])
  5.1105 -  
  5.1106 +
  5.1107  lemmas rbl_mult_Suc = lessI [THEN rbl_mult_gt]
  5.1108  
  5.1109 -lemma rbbl_Cons: 
  5.1110 -  "b # rev (bin_to_bl n x) = rev (bin_to_bl (Suc n) (x BIT b))"
  5.1111 -  apply (unfold bin_to_bl_def)
  5.1112 -  apply simp
  5.1113 -  apply (simp add: bin_to_bl_aux_alt)
  5.1114 -  done
  5.1115 +lemma rbbl_Cons: "b # rev (bin_to_bl n x) = rev (bin_to_bl (Suc n) (x BIT b))"
  5.1116 +  by (simp add: bin_to_bl_def) (simp add: bin_to_bl_aux_alt)
  5.1117  
  5.1118 -lemma rbl_mult: "!!bina binb. 
  5.1119 -    rbl_mult (rev (bin_to_bl n bina)) (rev (bin_to_bl n binb)) = 
  5.1120 +lemma rbl_mult:
  5.1121 +  "rbl_mult (rev (bin_to_bl n bina)) (rev (bin_to_bl n binb)) =
  5.1122      rev (bin_to_bl n (bina * binb))"
  5.1123 -  apply (induct n)
  5.1124 +  apply (induct n arbitrary: bina binb)
  5.1125     apply simp
  5.1126    apply (unfold bin_to_bl_def)
  5.1127    apply clarsimp
  5.1128 @@ -875,32 +788,28 @@
  5.1129       apply (auto simp: rbbl_Cons rbl_mult_Suc rbl_add)
  5.1130    done
  5.1131  
  5.1132 -lemma rbl_add_split: 
  5.1133 -  "P (rbl_add (y # ys) (x # xs)) = 
  5.1134 -    (ALL ws. length ws = length ys --> ws = rbl_add ys xs --> 
  5.1135 -    (y --> ((x --> P (False # rbl_succ ws)) & (~ x -->  P (True # ws)))) &
  5.1136 -    (~ y --> P (x # ws)))"
  5.1137 -  apply (auto simp add: Let_def)
  5.1138 -   apply (case_tac [!] "y")
  5.1139 -     apply auto
  5.1140 -  done
  5.1141 +lemma rbl_add_split:
  5.1142 +  "P (rbl_add (y # ys) (x # xs)) =
  5.1143 +    (\<forall>ws. length ws = length ys \<longrightarrow> ws = rbl_add ys xs \<longrightarrow>
  5.1144 +      (y \<longrightarrow> ((x \<longrightarrow> P (False # rbl_succ ws)) \<and> (\<not> x \<longrightarrow> P (True # ws)))) \<and>
  5.1145 +      (\<not> y \<longrightarrow> P (x # ws)))"
  5.1146 +  by (cases y) (auto simp: Let_def)
  5.1147  
  5.1148 -lemma rbl_mult_split: 
  5.1149 -  "P (rbl_mult (y # ys) xs) = 
  5.1150 -    (ALL ws. length ws = Suc (length ys) --> ws = False # rbl_mult ys xs --> 
  5.1151 -    (y --> P (rbl_add ws xs)) & (~ y -->  P ws))"
  5.1152 -  by (clarsimp simp add : Let_def)
  5.1153 -  
  5.1154 +lemma rbl_mult_split:
  5.1155 +  "P (rbl_mult (y # ys) xs) =
  5.1156 +    (\<forall>ws. length ws = Suc (length ys) \<longrightarrow> ws = False # rbl_mult ys xs \<longrightarrow>
  5.1157 +      (y \<longrightarrow> P (rbl_add ws xs)) \<and> (\<not> y \<longrightarrow> P ws))"
  5.1158 +  by (auto simp: Let_def)
  5.1159  
  5.1160 -subsection "Repeated splitting or concatenation"
  5.1161  
  5.1162 -lemma sclem:
  5.1163 -  "size (concat (map (bin_to_bl n) xs)) = length xs * n"
  5.1164 +subsection \<open>Repeated splitting or concatenation\<close>
  5.1165 +
  5.1166 +lemma sclem: "size (concat (map (bin_to_bl n) xs)) = length xs * n"
  5.1167    by (induct xs) auto
  5.1168  
  5.1169  lemma bin_cat_foldl_lem:
  5.1170 -  "foldl (%u. bin_cat u n) x xs = 
  5.1171 -    bin_cat x (size xs * n) (foldl (%u. bin_cat u n) y xs)"
  5.1172 +  "foldl (\<lambda>u. bin_cat u n) x xs =
  5.1173 +    bin_cat x (size xs * n) (foldl (\<lambda>u. bin_cat u n) y xs)"
  5.1174    apply (induct xs arbitrary: x)
  5.1175     apply simp
  5.1176    apply (simp (no_asm))
  5.1177 @@ -908,17 +817,16 @@
  5.1178    apply (drule meta_spec)
  5.1179    apply (erule trans)
  5.1180    apply (drule_tac x = "bin_cat y n a" in meta_spec)
  5.1181 -  apply (simp add : bin_cat_assoc_sym min.absorb2)
  5.1182 +  apply (simp add: bin_cat_assoc_sym min.absorb2)
  5.1183    done
  5.1184  
  5.1185 -lemma bin_rcat_bl:
  5.1186 -  "(bin_rcat n wl) = bl_to_bin (concat (map (bin_to_bl n) wl))"
  5.1187 +lemma bin_rcat_bl: "bin_rcat n wl = bl_to_bin (concat (map (bin_to_bl n) wl))"
  5.1188    apply (unfold bin_rcat_def)
  5.1189    apply (rule sym)
  5.1190    apply (induct wl)
  5.1191 -   apply (auto simp add : bl_to_bin_append)
  5.1192 -  apply (simp add : bl_to_bin_aux_alt sclem)
  5.1193 -  apply (simp add : bin_cat_foldl_lem [symmetric])
  5.1194 +   apply (auto simp add: bl_to_bin_append)
  5.1195 +  apply (simp add: bl_to_bin_aux_alt sclem)
  5.1196 +  apply (simp add: bin_cat_foldl_lem [symmetric])
  5.1197    done
  5.1198  
  5.1199  lemmas bin_rsplit_aux_simps = bin_rsplit_aux.simps bin_rsplitl_aux.simps
  5.1200 @@ -934,19 +842,17 @@
  5.1201  lemmas bin_rsplit_aux_simp2s [simp] = rsplit_aux_simp2ls [unfolded Let_def]
  5.1202  lemmas rbscl = bin_rsplit_aux_simp2s (2)
  5.1203  
  5.1204 -lemmas rsplit_aux_0_simps [simp] = 
  5.1205 +lemmas rsplit_aux_0_simps [simp] =
  5.1206    rsplit_aux_simp1s [OF disjI1] rsplit_aux_simp1s [OF disjI2]
  5.1207  
  5.1208 -lemma bin_rsplit_aux_append:
  5.1209 -  "bin_rsplit_aux n m c (bs @ cs) = bin_rsplit_aux n m c bs @ cs"
  5.1210 +lemma bin_rsplit_aux_append: "bin_rsplit_aux n m c (bs @ cs) = bin_rsplit_aux n m c bs @ cs"
  5.1211    apply (induct n m c bs rule: bin_rsplit_aux.induct)
  5.1212    apply (subst bin_rsplit_aux.simps)
  5.1213    apply (subst bin_rsplit_aux.simps)
  5.1214    apply (clarsimp split: prod.split)
  5.1215    done
  5.1216  
  5.1217 -lemma bin_rsplitl_aux_append:
  5.1218 -  "bin_rsplitl_aux n m c (bs @ cs) = bin_rsplitl_aux n m c bs @ cs"
  5.1219 +lemma bin_rsplitl_aux_append: "bin_rsplitl_aux n m c (bs @ cs) = bin_rsplitl_aux n m c bs @ cs"
  5.1220    apply (induct n m c bs rule: bin_rsplitl_aux.induct)
  5.1221    apply (subst bin_rsplitl_aux.simps)
  5.1222    apply (subst bin_rsplitl_aux.simps)
  5.1223 @@ -958,41 +864,38 @@
  5.1224  
  5.1225  lemmas rsplit_def_auxs = bin_rsplit_def bin_rsplitl_def
  5.1226  
  5.1227 -lemmas rsplit_aux_alts = rsplit_aux_apps 
  5.1228 +lemmas rsplit_aux_alts = rsplit_aux_apps
  5.1229    [unfolded append_Nil rsplit_def_auxs [symmetric]]
  5.1230  
  5.1231 -lemma bin_split_minus: "0 < n ==> bin_split (Suc (n - 1)) w = bin_split n w"
  5.1232 +lemma bin_split_minus: "0 < n \<Longrightarrow> bin_split (Suc (n - 1)) w = bin_split n w"
  5.1233    by auto
  5.1234  
  5.1235  lemmas bin_split_minus_simp =
  5.1236    bin_split.Suc [THEN [2] bin_split_minus [symmetric, THEN trans]]
  5.1237  
  5.1238 -lemma bin_split_pred_simp [simp]: 
  5.1239 +lemma bin_split_pred_simp [simp]:
  5.1240    "(0::nat) < numeral bin \<Longrightarrow>
  5.1241 -  bin_split (numeral bin) w =
  5.1242 -  (let (w1, w2) = bin_split (numeral bin - 1) (bin_rest w)
  5.1243 -   in (w1, w2 BIT bin_last w))" 
  5.1244 +    bin_split (numeral bin) w =
  5.1245 +      (let (w1, w2) = bin_split (numeral bin - 1) (bin_rest w)
  5.1246 +       in (w1, w2 BIT bin_last w))"
  5.1247    by (simp only: bin_split_minus_simp)
  5.1248  
  5.1249  lemma bin_rsplit_aux_simp_alt:
  5.1250    "bin_rsplit_aux n m c bs =
  5.1251 -   (if m = 0 \<or> n = 0 
  5.1252 -   then bs
  5.1253 -   else let (a, b) = bin_split n c in bin_rsplit n (m - n, a) @ b # bs)"
  5.1254 -  unfolding bin_rsplit_aux.simps [of n m c bs]
  5.1255 -  apply simp
  5.1256 +    (if m = 0 \<or> n = 0 then bs
  5.1257 +     else let (a, b) = bin_split n c in bin_rsplit n (m - n, a) @ b # bs)"
  5.1258 +  apply (simp add: bin_rsplit_aux.simps [of n m c bs])
  5.1259    apply (subst rsplit_aux_alts)
  5.1260    apply (simp add: bin_rsplit_def)
  5.1261    done
  5.1262  
  5.1263 -lemmas bin_rsplit_simp_alt = 
  5.1264 +lemmas bin_rsplit_simp_alt =
  5.1265    trans [OF bin_rsplit_def bin_rsplit_aux_simp_alt]
  5.1266  
  5.1267  lemmas bthrs = bin_rsplit_simp_alt [THEN [2] trans]
  5.1268  
  5.1269 -lemma bin_rsplit_size_sign' [rule_format] : 
  5.1270 -  "\<lbrakk>n > 0; rev sw = bin_rsplit n (nw, w)\<rbrakk> \<Longrightarrow> 
  5.1271 -    (ALL v: set sw. bintrunc n v = v)"
  5.1272 +lemma bin_rsplit_size_sign' [rule_format]:
  5.1273 +  "n > 0 \<Longrightarrow> rev sw = bin_rsplit n (nw, w) \<Longrightarrow> \<forall>v\<in>set sw. bintrunc n v = v"
  5.1274    apply (induct sw arbitrary: nw w)
  5.1275     apply clarsimp
  5.1276    apply clarsimp
  5.1277 @@ -1003,12 +906,14 @@
  5.1278    apply simp
  5.1279    done
  5.1280  
  5.1281 -lemmas bin_rsplit_size_sign = bin_rsplit_size_sign' [OF asm_rl 
  5.1282 +lemmas bin_rsplit_size_sign = bin_rsplit_size_sign' [OF asm_rl
  5.1283    rev_rev_ident [THEN trans] set_rev [THEN equalityD2 [THEN subsetD]]]
  5.1284  
  5.1285  lemma bin_nth_rsplit [rule_format] :
  5.1286 -  "n > 0 ==> m < n ==> (ALL w k nw. rev sw = bin_rsplit n (nw, w) --> 
  5.1287 -       k < size sw --> bin_nth (sw ! k) m = bin_nth w (k * n + m))"
  5.1288 +  "n > 0 \<Longrightarrow> m < n \<Longrightarrow>
  5.1289 +    \<forall>w k nw.
  5.1290 +      rev sw = bin_rsplit n (nw, w) \<longrightarrow>
  5.1291 +      k < size sw \<longrightarrow> bin_nth (sw ! k) m = bin_nth w (k * n + m)"
  5.1292    apply (induct sw)
  5.1293     apply clarsimp
  5.1294    apply clarsimp
  5.1295 @@ -1017,24 +922,21 @@
  5.1296    apply clarify
  5.1297    apply (erule allE, erule impE, erule exI)
  5.1298    apply (case_tac k)
  5.1299 -   apply clarsimp   
  5.1300 +   apply clarsimp
  5.1301     prefer 2
  5.1302     apply clarsimp
  5.1303     apply (erule allE)
  5.1304     apply (erule (1) impE)
  5.1305 -   apply (drule bin_nth_split, erule conjE, erule allE,
  5.1306 -          erule trans, simp add : ac_simps)+
  5.1307 +   apply (drule bin_nth_split, erule conjE, erule allE, erule trans, simp add: ac_simps)+
  5.1308    done
  5.1309  
  5.1310 -lemma bin_rsplit_all:
  5.1311 -  "0 < nw ==> nw <= n ==> bin_rsplit n (nw, w) = [bintrunc n w]"
  5.1312 -  unfolding bin_rsplit_def
  5.1313 -  by (clarsimp dest!: split_bintrunc simp: rsplit_aux_simp2ls split: prod.split)
  5.1314 +lemma bin_rsplit_all: "0 < nw \<Longrightarrow> nw \<le> n \<Longrightarrow> bin_rsplit n (nw, w) = [bintrunc n w]"
  5.1315 +  by (auto simp: bin_rsplit_def rsplit_aux_simp2ls split: prod.split dest!: split_bintrunc)
  5.1316  
  5.1317 -lemma bin_rsplit_l [rule_format] :
  5.1318 -  "ALL bin. bin_rsplitl n (m, bin) = bin_rsplit n (m, bintrunc m bin)"
  5.1319 +lemma bin_rsplit_l [rule_format]:
  5.1320 +  "\<forall>bin. bin_rsplitl n (m, bin) = bin_rsplit n (m, bintrunc m bin)"
  5.1321    apply (rule_tac a = "m" in wf_less_than [THEN wf_induct])
  5.1322 -  apply (simp (no_asm) add : bin_rsplitl_def bin_rsplit_def)
  5.1323 +  apply (simp (no_asm) add: bin_rsplitl_def bin_rsplit_def)
  5.1324    apply (rule allI)
  5.1325    apply (subst bin_rsplitl_aux.simps)
  5.1326    apply (subst bin_rsplit_aux.simps)
  5.1327 @@ -1048,10 +950,10 @@
  5.1328    apply simp
  5.1329    done
  5.1330  
  5.1331 -lemma bin_rsplit_rcat [rule_format] :
  5.1332 -  "n > 0 --> bin_rsplit n (n * size ws, bin_rcat n ws) = map (bintrunc n) ws"
  5.1333 +lemma bin_rsplit_rcat [rule_format]:
  5.1334 +  "n > 0 \<longrightarrow> bin_rsplit n (n * size ws, bin_rcat n ws) = map (bintrunc n) ws"
  5.1335    apply (unfold bin_rsplit_def bin_rcat_def)
  5.1336 -  apply (rule_tac xs = "ws" in rev_induct)
  5.1337 +  apply (rule_tac xs = ws in rev_induct)
  5.1338     apply clarsimp
  5.1339    apply clarsimp
  5.1340    apply (subst rsplit_aux_alts)
  5.1341 @@ -1063,78 +965,75 @@
  5.1342    "\<forall>ws m. n \<noteq> 0 \<longrightarrow> ws = bin_rsplit_aux n nw w bs \<longrightarrow>
  5.1343      length ws \<le> m \<longleftrightarrow> nw + length bs * n \<le> m * n"
  5.1344  proof -
  5.1345 -  { fix i j j' k k' m :: nat and R
  5.1346 -    assume d: "(i::nat) \<le> j \<or> m < j'"
  5.1347 -    assume R1: "i * k \<le> j * k \<Longrightarrow> R"
  5.1348 -    assume R2: "Suc m * k' \<le> j' * k' \<Longrightarrow> R"
  5.1349 -    have "R" using d
  5.1350 -      apply safe
  5.1351 -       apply (rule R1, erule mult_le_mono1)
  5.1352 -      apply (rule R2, erule Suc_le_eq [THEN iffD2 [THEN mult_le_mono1]])
  5.1353 -      done
  5.1354 -  } note A = this
  5.1355 -  { fix sc m n lb :: nat
  5.1356 -    have "(0::nat) < sc \<Longrightarrow> sc - n + (n + lb * n) \<le> m * n \<longleftrightarrow> sc + lb * n \<le> m * n"
  5.1357 -      apply safe
  5.1358 -       apply arith
  5.1359 -      apply (case_tac "sc >= n")
  5.1360 -       apply arith
  5.1361 -      apply (insert linorder_le_less_linear [of m lb])
  5.1362 -      apply (erule_tac k2=n and k'2=n in A)
  5.1363 -       apply arith
  5.1364 -      apply simp
  5.1365 -      done
  5.1366 -  } note B = this
  5.1367 +  have *: R
  5.1368 +    if d: "i \<le> j \<or> m < j'"
  5.1369 +    and R1: "i * k \<le> j * k \<Longrightarrow> R"
  5.1370 +    and R2: "Suc m * k' \<le> j' * k' \<Longrightarrow> R"
  5.1371 +    for i j j' k k' m :: nat and R
  5.1372 +    using d
  5.1373 +    apply safe
  5.1374 +    apply (rule R1, erule mult_le_mono1)
  5.1375 +    apply (rule R2, erule Suc_le_eq [THEN iffD2 [THEN mult_le_mono1]])
  5.1376 +    done
  5.1377 +  have **: "0 < sc \<Longrightarrow> sc - n + (n + lb * n) \<le> m * n \<longleftrightarrow> sc + lb * n \<le> m * n"
  5.1378 +    for sc m n lb :: nat
  5.1379 +    apply safe
  5.1380 +     apply arith
  5.1381 +    apply (case_tac "sc \<ge> n")
  5.1382 +     apply arith
  5.1383 +    apply (insert linorder_le_less_linear [of m lb])
  5.1384 +    apply (erule_tac k=n and k'=n in *)
  5.1385 +     apply arith
  5.1386 +    apply simp
  5.1387 +    done
  5.1388    show ?thesis
  5.1389      apply (induct n nw w bs rule: bin_rsplit_aux.induct)
  5.1390      apply (subst bin_rsplit_aux.simps)
  5.1391 -    apply (simp add: B Let_def split: prod.split)
  5.1392 +    apply (simp add: ** Let_def split: prod.split)
  5.1393      done
  5.1394  qed
  5.1395  
  5.1396 -lemma bin_rsplit_len_le: 
  5.1397 -  "n \<noteq> 0 --> ws = bin_rsplit n (nw, w) --> (length ws <= m) = (nw <= m * n)"
  5.1398 -  unfolding bin_rsplit_def by (clarsimp simp add : bin_rsplit_aux_len_le)
  5.1399 - 
  5.1400 +lemma bin_rsplit_len_le: "n \<noteq> 0 \<longrightarrow> ws = bin_rsplit n (nw, w) \<longrightarrow> length ws \<le> m \<longleftrightarrow> nw \<le> m * n"
  5.1401 +  by (auto simp: bin_rsplit_def bin_rsplit_aux_len_le)
  5.1402 +
  5.1403  lemma bin_rsplit_aux_len:
  5.1404 -  "n \<noteq> 0 \<Longrightarrow> length (bin_rsplit_aux n nw w cs) =
  5.1405 -    (nw + n - 1) div n + length cs"
  5.1406 +  "n \<noteq> 0 \<Longrightarrow> length (bin_rsplit_aux n nw w cs) = (nw + n - 1) div n + length cs"
  5.1407    apply (induct n nw w cs rule: bin_rsplit_aux.induct)
  5.1408    apply (subst bin_rsplit_aux.simps)
  5.1409    apply (clarsimp simp: Let_def split: prod.split)
  5.1410    apply (erule thin_rl)
  5.1411    apply (case_tac m)
  5.1412 -  apply simp
  5.1413 -  apply (case_tac "m <= n")
  5.1414 +   apply simp
  5.1415 +  apply (case_tac "m \<le> n")
  5.1416     apply (auto simp add: div_add_self2)
  5.1417    done
  5.1418  
  5.1419 -lemma bin_rsplit_len: 
  5.1420 -  "n\<noteq>0 ==> length (bin_rsplit n (nw, w)) = (nw + n - 1) div n"
  5.1421 -  unfolding bin_rsplit_def by (clarsimp simp add : bin_rsplit_aux_len)
  5.1422 +lemma bin_rsplit_len: "n \<noteq> 0 \<Longrightarrow> length (bin_rsplit n (nw, w)) = (nw + n - 1) div n"
  5.1423 +  by (auto simp: bin_rsplit_def bin_rsplit_aux_len)
  5.1424  
  5.1425  lemma bin_rsplit_aux_len_indep:
  5.1426    "n \<noteq> 0 \<Longrightarrow> length bs = length cs \<Longrightarrow>
  5.1427      length (bin_rsplit_aux n nw v bs) =
  5.1428      length (bin_rsplit_aux n nw w cs)"
  5.1429  proof (induct n nw w cs arbitrary: v bs rule: bin_rsplit_aux.induct)
  5.1430 -  case (1 n m w cs v bs) show ?case
  5.1431 +  case (1 n m w cs v bs)
  5.1432 +  show ?case
  5.1433    proof (cases "m = 0")
  5.1434 -    case True then show ?thesis using \<open>length bs = length cs\<close> by simp
  5.1435 +    case True
  5.1436 +    with \<open>length bs = length cs\<close> show ?thesis by simp
  5.1437    next
  5.1438      case False
  5.1439      from "1.hyps" \<open>m \<noteq> 0\<close> \<open>n \<noteq> 0\<close> have hyp: "\<And>v bs. length bs = Suc (length cs) \<Longrightarrow>
  5.1440        length (bin_rsplit_aux n (m - n) v bs) =
  5.1441        length (bin_rsplit_aux n (m - n) (fst (bin_split n w)) (snd (bin_split n w) # cs))"
  5.1442 -    by auto
  5.1443 -    show ?thesis using \<open>length bs = length cs\<close> \<open>n \<noteq> 0\<close>
  5.1444 -      by (auto simp add: bin_rsplit_aux_simp_alt Let_def bin_rsplit_len
  5.1445 -        split: prod.split)
  5.1446 +      by auto
  5.1447 +    from \<open>length bs = length cs\<close> \<open>n \<noteq> 0\<close> show ?thesis
  5.1448 +      by (auto simp add: bin_rsplit_aux_simp_alt Let_def bin_rsplit_len split: prod.split)
  5.1449    qed
  5.1450  qed
  5.1451  
  5.1452 -lemma bin_rsplit_len_indep: 
  5.1453 -  "n\<noteq>0 ==> length (bin_rsplit n (nw, v)) = length (bin_rsplit n (nw, w))"
  5.1454 +lemma bin_rsplit_len_indep:
  5.1455 +  "n \<noteq> 0 \<Longrightarrow> length (bin_rsplit n (nw, v)) = length (bin_rsplit n (nw, w))"
  5.1456    apply (unfold bin_rsplit_def)
  5.1457    apply (simp (no_asm))
  5.1458    apply (erule bin_rsplit_aux_len_indep)
  5.1459 @@ -1147,33 +1046,27 @@
  5.1460  instantiation int :: bitss
  5.1461  begin
  5.1462  
  5.1463 -definition [iff]:
  5.1464 -  "i !! n \<longleftrightarrow> bin_nth i n"
  5.1465 +definition [iff]: "i !! n \<longleftrightarrow> bin_nth i n"
  5.1466  
  5.1467 -definition
  5.1468 -  "lsb i = (i :: int) !! 0"
  5.1469 +definition "lsb i = i !! 0" for i :: int
  5.1470  
  5.1471 -definition
  5.1472 -  "set_bit i n b = bin_sc n b i"
  5.1473 +definition "set_bit i n b = bin_sc n b i"
  5.1474  
  5.1475  definition
  5.1476    "set_bits f =
  5.1477 -  (if \<exists>n. \<forall>n'\<ge>n. \<not> f n' then 
  5.1478 -     let n = LEAST n. \<forall>n'\<ge>n. \<not> f n'
  5.1479 -     in bl_to_bin (rev (map f [0..<n]))
  5.1480 -   else if \<exists>n. \<forall>n'\<ge>n. f n' then
  5.1481 -     let n = LEAST n. \<forall>n'\<ge>n. f n'
  5.1482 -     in sbintrunc n (bl_to_bin (True # rev (map f [0..<n])))
  5.1483 -   else 0 :: int)"
  5.1484 +    (if \<exists>n. \<forall>n'\<ge>n. \<not> f n' then
  5.1485 +      let n = LEAST n. \<forall>n'\<ge>n. \<not> f n'
  5.1486 +      in bl_to_bin (rev (map f [0..<n]))
  5.1487 +     else if \<exists>n. \<forall>n'\<ge>n. f n' then
  5.1488 +      let n = LEAST n. \<forall>n'\<ge>n. f n'
  5.1489 +      in sbintrunc n (bl_to_bin (True # rev (map f [0..<n])))
  5.1490 +     else 0 :: int)"
  5.1491  
  5.1492 -definition
  5.1493 -  "shiftl x n = (x :: int) * 2 ^ n"
  5.1494 +definition "shiftl x n = x * 2 ^ n" for x :: int
  5.1495  
  5.1496 -definition
  5.1497 -  "shiftr x n = (x :: int) div 2 ^ n"
  5.1498 +definition "shiftr x n = x div 2 ^ n" for x :: int
  5.1499  
  5.1500 -definition
  5.1501 -  "msb x \<longleftrightarrow> (x :: int) < 0"
  5.1502 +definition "msb x \<longleftrightarrow> x < 0" for x :: int
  5.1503  
  5.1504  instance ..
  5.1505  
     6.1 --- a/src/HOL/Word/Examples/WordExamples.thy	Mon Apr 03 22:18:56 2017 +0200
     6.2 +++ b/src/HOL/Word/Examples/WordExamples.thy	Mon Apr 03 23:12:44 2017 +0200
     6.3 @@ -1,13 +1,13 @@
     6.4 -(* 
     6.5 -  Authors: Gerwin Klein and Thomas Sewell, NICTA
     6.6 +(*  Title:      HOL/Word/Examples/WordExamples.thy
     6.7 +    Authors:    Gerwin Klein and Thomas Sewell, NICTA
     6.8  
     6.9 -  Examples demonstrating and testing various word operations.
    6.10 +Examples demonstrating and testing various word operations.
    6.11  *)
    6.12  
    6.13  section "Examples of word operations"
    6.14  
    6.15  theory WordExamples
    6.16 -imports "../Word" "../WordBitwise"
    6.17 +  imports "../Word" "../WordBitwise"
    6.18  begin
    6.19  
    6.20  type_synonym word32 = "32 word"
    6.21 @@ -28,7 +28,7 @@
    6.22  
    6.23  text "number ring simps"
    6.24  
    6.25 -lemma 
    6.26 +lemma
    6.27    "27 + 11 = (38::'a::len word)"
    6.28    "27 + 11 = (6::5 word)"
    6.29    "7 * 3 = (21::'a::len word)"
    6.30 @@ -40,7 +40,7 @@
    6.31  lemma "word_pred 2 = 1" by simp
    6.32  
    6.33  lemma "word_succ (- 3) = -2" by simp
    6.34 -  
    6.35 +
    6.36  lemma "23 < (27::8 word)" by simp
    6.37  lemma "23 \<le> (27::8 word)" by simp
    6.38  lemma "\<not> 23 < (27::2 word)" by simp
    6.39 @@ -69,8 +69,10 @@
    6.40  lemma "ucast (1 :: 4 word) = (1 :: 2 word)" by simp
    6.41  
    6.42  text "reducing goals to nat or int and arith:"
    6.43 -lemma "i < x ==> i < (i + 1 :: 'a :: len word)" by unat_arith
    6.44 -lemma "i < x ==> i < (i + 1 :: 'a :: len word)" by uint_arith
    6.45 +lemma "i < x \<Longrightarrow> i < i + 1" for i x :: "'a::len word"
    6.46 +  by unat_arith
    6.47 +lemma "i < x \<Longrightarrow> i < i + 1" for i x :: "'a::len word"
    6.48 +  by unat_arith
    6.49  
    6.50  text "bool lists"
    6.51  
    6.52 @@ -111,7 +113,7 @@
    6.53  lemma "\<not> (0b1000 :: 3 word) !! 4" by simp
    6.54  lemma "\<not> (1 :: 3 word) !! 2" by simp
    6.55  
    6.56 -lemma "(0b11000 :: 10 word) !! n = (n = 4 \<or> n = 3)" 
    6.57 +lemma "(0b11000 :: 10 word) !! n = (n = 4 \<or> n = 3)"
    6.58    by (auto simp add: bin_nth_Bit0 bin_nth_Bit1)
    6.59  
    6.60  lemma "set_bit 55 7 True = (183::'a::len0 word)" by simp
    6.61 @@ -133,7 +135,7 @@
    6.62  lemma "\<not> msb (0::4 word)" by simp
    6.63  
    6.64  lemma "word_cat (27::4 word) (27::8 word) = (2843::'a::len word)" by simp
    6.65 -lemma "word_cat (0b0011::4 word) (0b1111::6word) = (0b0011001111 :: 10 word)" 
    6.66 +lemma "word_cat (0b0011::4 word) (0b1111::6word) = (0b0011001111 :: 10 word)"
    6.67    by simp
    6.68  
    6.69  lemma "0b1011 << 2 = (0b101100::'a::len0 word)" by simp
    6.70 @@ -171,20 +173,24 @@
    6.71  
    6.72  text "more proofs using bitwise expansion"
    6.73  
    6.74 -lemma "((x :: 10 word) AND NOT 3) >> 4 << 2 = ((x >> 2) AND NOT 3)"
    6.75 +lemma "(x AND NOT 3) >> 4 << 2 = ((x >> 2) AND NOT 3)"
    6.76 +  for x :: "10 word"
    6.77    by word_bitwise
    6.78  
    6.79 -lemma "(((x :: 12 word) AND -8) >> 3) AND 7 = (x AND 56) >> 3"
    6.80 +lemma "((x AND -8) >> 3) AND 7 = (x AND 56) >> 3"
    6.81 +  for x :: "12 word"
    6.82    by word_bitwise
    6.83  
    6.84  text "some problems require further reasoning after bit expansion"
    6.85  
    6.86 -lemma "x \<le> (42 :: 8 word) \<Longrightarrow> x \<le> 89"
    6.87 +lemma "x \<le> 42 \<Longrightarrow> x \<le> 89"
    6.88 +  for x :: "8 word"
    6.89    apply word_bitwise
    6.90    apply blast
    6.91    done
    6.92  
    6.93 -lemma "((x :: word32) AND 1023) = 0 \<Longrightarrow> x \<le> -1024"
    6.94 +lemma "(x AND 1023) = 0 \<Longrightarrow> x \<le> -1024"
    6.95 +  for x :: word32
    6.96    apply word_bitwise
    6.97    apply clarsimp
    6.98    done
    6.99 @@ -192,11 +198,10 @@
   6.100  text "operations like shifts by non-numerals will expose some internal list
   6.101   representations but may still be easy to solve"
   6.102  
   6.103 -lemma shiftr_overflow:
   6.104 -  "32 \<le> a \<Longrightarrow> (b::word32) >> a = 0"
   6.105 -  apply (word_bitwise)
   6.106 +lemma shiftr_overflow: "32 \<le> a \<Longrightarrow> b >> a = 0"
   6.107 +  for b :: word32
   6.108 +  apply word_bitwise
   6.109    apply simp
   6.110    done
   6.111  
   6.112 -
   6.113  end
     7.1 --- a/src/HOL/Word/Misc_Numeric.thy	Mon Apr 03 22:18:56 2017 +0200
     7.2 +++ b/src/HOL/Word/Misc_Numeric.thy	Mon Apr 03 23:12:44 2017 +0200
     7.3 @@ -1,76 +1,66 @@
     7.4 -(* 
     7.5 -  Author:  Jeremy Dawson, NICTA
     7.6 -*) 
     7.7 +(*  Title:      HOL/Word/Misc_Numeric.thy
     7.8 +    Author:     Jeremy Dawson, NICTA
     7.9 +*)
    7.10  
    7.11  section \<open>Useful Numerical Lemmas\<close>
    7.12  
    7.13  theory Misc_Numeric
    7.14 -imports Main
    7.15 +  imports Main
    7.16  begin
    7.17  
    7.18 -lemma one_mod_exp_eq_one [simp]:
    7.19 -  "1 mod (2 * 2 ^ n) = (1::int)"
    7.20 +lemma one_mod_exp_eq_one [simp]: "1 mod (2 * 2 ^ n) = (1::int)"
    7.21    by (smt mod_pos_pos_trivial zero_less_power)
    7.22  
    7.23 -lemma mod_2_neq_1_eq_eq_0:
    7.24 -  fixes k :: int
    7.25 -  shows "k mod 2 \<noteq> 1 \<longleftrightarrow> k mod 2 = 0"
    7.26 +lemma mod_2_neq_1_eq_eq_0: "k mod 2 \<noteq> 1 \<longleftrightarrow> k mod 2 = 0"
    7.27 +  for k :: int
    7.28    by (fact not_mod_2_eq_1_eq_0)
    7.29  
    7.30 -lemma z1pmod2:
    7.31 -  fixes b :: int
    7.32 -  shows "(2 * b + 1) mod 2 = (1::int)"
    7.33 +lemma z1pmod2: "(2 * b + 1) mod 2 = (1::int)"
    7.34 +  for b :: int
    7.35    by arith
    7.36  
    7.37 -lemma diff_le_eq':
    7.38 -  "a - b \<le> c \<longleftrightarrow> a \<le> b + (c::int)"
    7.39 +lemma diff_le_eq': "a - b \<le> c \<longleftrightarrow> a \<le> b + c"
    7.40 +  for a b c :: int
    7.41    by arith
    7.42  
    7.43 -lemma emep1:
    7.44 -  fixes n d :: int
    7.45 -  shows "even n \<Longrightarrow> even d \<Longrightarrow> 0 \<le> d \<Longrightarrow> (n + 1) mod d = (n mod d) + 1"
    7.46 +lemma emep1: "even n \<Longrightarrow> even d \<Longrightarrow> 0 \<le> d \<Longrightarrow> (n + 1) mod d = (n mod d) + 1"
    7.47 +  for n d :: int
    7.48    by (auto simp add: pos_zmod_mult_2 add.commute dvd_def)
    7.49  
    7.50 -lemma int_mod_ge:
    7.51 -  "a < n \<Longrightarrow> 0 < (n :: int) \<Longrightarrow> a \<le> a mod n"
    7.52 +lemma int_mod_ge: "a < n \<Longrightarrow> 0 < n \<Longrightarrow> a \<le> a mod n"
    7.53 +  for a n :: int
    7.54    by (metis dual_order.trans le_cases mod_pos_pos_trivial pos_mod_conj)
    7.55  
    7.56 -lemma int_mod_ge':
    7.57 -  "b < 0 \<Longrightarrow> 0 < (n :: int) \<Longrightarrow> b + n \<le> b mod n"
    7.58 +lemma int_mod_ge': "b < 0 \<Longrightarrow> 0 < n \<Longrightarrow> b + n \<le> b mod n"
    7.59 +  for b n :: int
    7.60    by (metis add_less_same_cancel2 int_mod_ge mod_add_self2)
    7.61  
    7.62 -lemma int_mod_le':
    7.63 -  "(0::int) \<le> b - n \<Longrightarrow> b mod n \<le> b - n"
    7.64 +lemma int_mod_le': "0 \<le> b - n \<Longrightarrow> b mod n \<le> b - n"
    7.65 +  for b n :: int
    7.66    by (metis minus_mod_self2 zmod_le_nonneg_dividend)
    7.67  
    7.68 -lemma zless2:
    7.69 -  "0 < (2 :: int)"
    7.70 +lemma zless2: "0 < (2 :: int)"
    7.71    by (fact zero_less_numeral)
    7.72  
    7.73 -lemma zless2p:
    7.74 -  "0 < (2 ^ n :: int)"
    7.75 +lemma zless2p: "0 < (2 ^ n :: int)"
    7.76    by arith
    7.77  
    7.78 -lemma zle2p:
    7.79 -  "0 \<le> (2 ^ n :: int)"
    7.80 +lemma zle2p: "0 \<le> (2 ^ n :: int)"
    7.81    by arith
    7.82  
    7.83 -lemma m1mod2k:
    7.84 -  "- 1 mod 2 ^ n = (2 ^ n - 1 :: int)"
    7.85 +lemma m1mod2k: "- 1 mod 2 ^ n = (2 ^ n - 1 :: int)"
    7.86    using zless2p by (rule zmod_minus1)
    7.87  
    7.88 -lemma p1mod22k':
    7.89 -  fixes b :: int
    7.90 -  shows "(1 + 2 * b) mod (2 * 2 ^ n) = 1 + 2 * (b mod 2 ^ n)"
    7.91 -  using zle2p by (rule pos_zmod_mult_2) 
    7.92 +lemma p1mod22k': "(1 + 2 * b) mod (2 * 2 ^ n) = 1 + 2 * (b mod 2 ^ n)"
    7.93 +  for b :: int
    7.94 +  using zle2p by (rule pos_zmod_mult_2)
    7.95  
    7.96 -lemma p1mod22k:
    7.97 -  fixes b :: int
    7.98 -  shows "(2 * b + 1) mod (2 * 2 ^ n) = 2 * (b mod 2 ^ n) + 1"
    7.99 +lemma p1mod22k: "(2 * b + 1) mod (2 * 2 ^ n) = 2 * (b mod 2 ^ n) + 1"
   7.100 +  for b :: int
   7.101    by (simp add: p1mod22k' add.commute)
   7.102  
   7.103 -lemma int_mod_lem: 
   7.104 -  "(0 :: int) < n ==> (0 <= b & b < n) = (b mod n = b)"
   7.105 +lemma int_mod_lem: "0 < n \<Longrightarrow> 0 \<le> b \<and> b < n \<longleftrightarrow> b mod n = b"
   7.106 +  for b n :: int
   7.107    apply safe
   7.108      apply (erule (1) mod_pos_pos_trivial)
   7.109     apply (erule_tac [!] subst)
   7.110 @@ -78,4 +68,3 @@
   7.111    done
   7.112  
   7.113  end
   7.114 -
     8.1 --- a/src/HOL/Word/Misc_Typedef.thy	Mon Apr 03 22:18:56 2017 +0200
     8.2 +++ b/src/HOL/Word/Misc_Typedef.thy	Mon Apr 03 23:12:44 2017 +0200
     8.3 @@ -1,4 +1,4 @@
     8.4 -(* 
     8.5 +(*
     8.6    Author:     Jeremy Dawson and Gerwin Klein, NICTA
     8.7  
     8.8    Consequences of type definition theorems, and of extended type definition.
     8.9 @@ -18,7 +18,7 @@
    8.10    tdD3: "type_definition Rep Abs A \<Longrightarrow> \<forall>y. y \<in> A \<longrightarrow> Rep (Abs y) = y"
    8.11    by (auto simp: type_definition_def)
    8.12  
    8.13 -lemma td_nat_int: 
    8.14 +lemma td_nat_int:
    8.15    "type_definition int nat (Collect (op <= 0))"
    8.16    unfolding type_definition_def by auto
    8.17  
    8.18 @@ -29,13 +29,13 @@
    8.19  
    8.20  lemma Abs_eqD: "Abs x = Abs y ==> x \<in> A ==> y \<in> A ==> x = y"
    8.21    by (simp add: Abs_inject)
    8.22 -   
    8.23 -lemma Abs_inverse': 
    8.24 +
    8.25 +lemma Abs_inverse':
    8.26    "r : A ==> Abs r = a ==> Rep a = r"
    8.27    by (safe elim!: Abs_inverse)
    8.28  
    8.29 -lemma Rep_comp_inverse: 
    8.30 -  "Rep o f = g ==> Abs o g = f"
    8.31 +lemma Rep_comp_inverse:
    8.32 +  "Rep \<circ> f = g ==> Abs \<circ> g = f"
    8.33    using Rep_inverse by auto
    8.34  
    8.35  lemma Rep_eqD [elim!]: "Rep x = Rep y ==> x = y"
    8.36 @@ -44,27 +44,27 @@
    8.37  lemma Rep_inverse': "Rep a = r ==> Abs r = a"
    8.38    by (safe intro!: Rep_inverse)
    8.39  
    8.40 -lemma comp_Abs_inverse: 
    8.41 -  "f o Abs = g ==> g o Rep = f"
    8.42 +lemma comp_Abs_inverse:
    8.43 +  "f \<circ> Abs = g ==> g \<circ> Rep = f"
    8.44    using Rep_inverse by auto
    8.45  
    8.46 -lemma set_Rep: 
    8.47 +lemma set_Rep:
    8.48    "A = range Rep"
    8.49  proof (rule set_eqI)
    8.50    fix x
    8.51    show "(x \<in> A) = (x \<in> range Rep)"
    8.52      by (auto dest: Abs_inverse [of x, symmetric])
    8.53 -qed  
    8.54 +qed
    8.55  
    8.56 -lemma set_Rep_Abs: "A = range (Rep o Abs)"
    8.57 +lemma set_Rep_Abs: "A = range (Rep \<circ> Abs)"
    8.58  proof (rule set_eqI)
    8.59    fix x
    8.60 -  show "(x \<in> A) = (x \<in> range (Rep o Abs))"
    8.61 +  show "(x \<in> A) = (x \<in> range (Rep \<circ> Abs))"
    8.62      by (auto dest: Abs_inverse [of x, symmetric])
    8.63 -qed  
    8.64 +qed
    8.65  
    8.66  lemma Abs_inj_on: "inj_on Abs A"
    8.67 -  unfolding inj_on_def 
    8.68 +  unfolding inj_on_def
    8.69    by (auto dest: Abs_inject [THEN iffD1])
    8.70  
    8.71  lemma image: "Abs ` A = UNIV"
    8.72 @@ -72,16 +72,16 @@
    8.73  
    8.74  lemmas td_thm = type_definition_axioms
    8.75  
    8.76 -lemma fns1: 
    8.77 -  "Rep o fa = fr o Rep | fa o Abs = Abs o fr ==> Abs o fr o Rep = fa"
    8.78 +lemma fns1:
    8.79 +  "Rep \<circ> fa = fr \<circ> Rep | fa \<circ> Abs = Abs \<circ> fr ==> Abs \<circ> fr \<circ> Rep = fa"
    8.80    by (auto dest: Rep_comp_inverse elim: comp_Abs_inverse simp: o_assoc)
    8.81  
    8.82  lemmas fns1a = disjI1 [THEN fns1]
    8.83  lemmas fns1b = disjI2 [THEN fns1]
    8.84  
    8.85  lemma fns4:
    8.86 -  "Rep o fa o Abs = fr ==> 
    8.87 -   Rep o fa = fr o Rep & fa o Abs = Abs o fr"
    8.88 +  "Rep \<circ> fa \<circ> Abs = fr ==>
    8.89 +   Rep \<circ> fa = fr \<circ> Rep & fa \<circ> Abs = Abs \<circ> fr"
    8.90    by auto
    8.91  
    8.92  end
    8.93 @@ -99,16 +99,16 @@
    8.94  subsection "Extended form of type definition predicate"
    8.95  
    8.96  lemma td_conds:
    8.97 -  "norm o norm = norm ==> (fr o norm = norm o fr) = 
    8.98 -    (norm o fr o norm = fr o norm & norm o fr o norm = norm o fr)"
    8.99 +  "norm \<circ> norm = norm ==> (fr \<circ> norm = norm \<circ> fr) =
   8.100 +    (norm \<circ> fr \<circ> norm = fr \<circ> norm & norm \<circ> fr \<circ> norm = norm \<circ> fr)"
   8.101    apply safe
   8.102      apply (simp_all add: comp_assoc)
   8.103     apply (simp_all add: o_assoc)
   8.104    done
   8.105  
   8.106  lemma fn_comm_power:
   8.107 -  "fa o tr = tr o fr ==> fa ^^ n o tr = tr o fr ^^ n" 
   8.108 -  apply (rule ext) 
   8.109 +  "fa \<circ> tr = tr \<circ> fr ==> fa ^^ n \<circ> tr = tr \<circ> fr ^^ n"
   8.110 +  apply (rule ext)
   8.111    apply (induct n)
   8.112     apply (auto dest: fun_cong)
   8.113    done
   8.114 @@ -122,15 +122,15 @@
   8.115    assumes eq_norm: "\<And>x. Rep (Abs x) = norm x"
   8.116  begin
   8.117  
   8.118 -lemma Abs_norm [simp]: 
   8.119 +lemma Abs_norm [simp]:
   8.120    "Abs (norm x) = Abs x"
   8.121    using eq_norm [of x] by (auto elim: Rep_inverse')
   8.122  
   8.123  lemma td_th:
   8.124 -  "g o Abs = f ==> f (Rep x) = g x"
   8.125 +  "g \<circ> Abs = f ==> f (Rep x) = g x"
   8.126    by (drule comp_Abs_inverse [symmetric]) simp
   8.127  
   8.128 -lemma eq_norm': "Rep o Abs = norm"
   8.129 +lemma eq_norm': "Rep \<circ> Abs = norm"
   8.130    by (auto simp: eq_norm)
   8.131  
   8.132  lemma norm_Rep [simp]: "norm (Rep x) = Rep x"
   8.133 @@ -141,42 +141,42 @@
   8.134  lemma set_iff_norm: "w : A \<longleftrightarrow> w = norm w"
   8.135    by (auto simp: set_Rep_Abs eq_norm' eq_norm [symmetric])
   8.136  
   8.137 -lemma inverse_norm: 
   8.138 +lemma inverse_norm:
   8.139    "(Abs n = w) = (Rep w = norm n)"
   8.140    apply (rule iffI)
   8.141     apply (clarsimp simp add: eq_norm)
   8.142    apply (simp add: eq_norm' [symmetric])
   8.143    done
   8.144  
   8.145 -lemma norm_eq_iff: 
   8.146 +lemma norm_eq_iff:
   8.147    "(norm x = norm y) = (Abs x = Abs y)"
   8.148    by (simp add: eq_norm' [symmetric])
   8.149  
   8.150 -lemma norm_comps: 
   8.151 -  "Abs o norm = Abs" 
   8.152 -  "norm o Rep = Rep" 
   8.153 -  "norm o norm = norm"
   8.154 +lemma norm_comps:
   8.155 +  "Abs \<circ> norm = Abs"
   8.156 +  "norm \<circ> Rep = Rep"
   8.157 +  "norm \<circ> norm = norm"
   8.158    by (auto simp: eq_norm' [symmetric] o_def)
   8.159  
   8.160  lemmas norm_norm [simp] = norm_comps
   8.161  
   8.162 -lemma fns5: 
   8.163 -  "Rep o fa o Abs = fr ==> 
   8.164 -  fr o norm = fr & norm o fr = fr"
   8.165 +lemma fns5:
   8.166 +  "Rep \<circ> fa \<circ> Abs = fr ==>
   8.167 +  fr \<circ> norm = fr & norm \<circ> fr = fr"
   8.168    by (fold eq_norm') auto
   8.169  
   8.170  (* following give conditions for converses to td_fns1
   8.171 -  the condition (norm o fr o norm = fr o norm) says that 
   8.172 +  the condition (norm \<circ> fr \<circ> norm = fr \<circ> norm) says that
   8.173    fr takes normalised arguments to normalised results,
   8.174 -  (norm o fr o norm = norm o fr) says that fr 
   8.175 +  (norm \<circ> fr \<circ> norm = norm \<circ> fr) says that fr
   8.176    takes norm-equivalent arguments to norm-equivalent results,
   8.177 -  (fr o norm = fr) says that fr 
   8.178 -  takes norm-equivalent arguments to the same result, and 
   8.179 -  (norm o fr = fr) says that fr takes any argument to a normalised result 
   8.180 +  (fr \<circ> norm = fr) says that fr
   8.181 +  takes norm-equivalent arguments to the same result, and
   8.182 +  (norm \<circ> fr = fr) says that fr takes any argument to a normalised result
   8.183    *)
   8.184 -lemma fns2: 
   8.185 -  "Abs o fr o Rep = fa ==> 
   8.186 -   (norm o fr o norm = fr o norm) = (Rep o fa = fr o Rep)"
   8.187 +lemma fns2:
   8.188 +  "Abs \<circ> fr \<circ> Rep = fa ==>
   8.189 +   (norm \<circ> fr \<circ> norm = fr \<circ> norm) = (Rep \<circ> fa = fr \<circ> Rep)"
   8.190    apply (fold eq_norm')
   8.191    apply safe
   8.192     prefer 2
   8.193 @@ -186,25 +186,25 @@
   8.194    apply auto
   8.195    done
   8.196  
   8.197 -lemma fns3: 
   8.198 -  "Abs o fr o Rep = fa ==> 
   8.199 -   (norm o fr o norm = norm o fr) = (fa o Abs = Abs o fr)"
   8.200 +lemma fns3:
   8.201 +  "Abs \<circ> fr \<circ> Rep = fa ==>
   8.202 +   (norm \<circ> fr \<circ> norm = norm \<circ> fr) = (fa \<circ> Abs = Abs \<circ> fr)"
   8.203    apply (fold eq_norm')
   8.204    apply safe
   8.205     prefer 2
   8.206     apply (simp add: comp_assoc)
   8.207    apply (rule ext)
   8.208 -  apply (drule_tac f="a o b" for a b in fun_cong)
   8.209 +  apply (drule_tac f="a \<circ> b" for a b in fun_cong)
   8.210    apply simp
   8.211    done
   8.212  
   8.213 -lemma fns: 
   8.214 -  "fr o norm = norm o fr ==> 
   8.215 -    (fa o Abs = Abs o fr) = (Rep o fa = fr o Rep)"
   8.216 +lemma fns:
   8.217 +  "fr \<circ> norm = norm \<circ> fr ==>
   8.218 +    (fa \<circ> Abs = Abs \<circ> fr) = (Rep \<circ> fa = fr \<circ> Rep)"
   8.219    apply safe
   8.220     apply (frule fns1b)
   8.221 -   prefer 2 
   8.222 -   apply (frule fns1a) 
   8.223 +   prefer 2
   8.224 +   apply (frule fns1a)
   8.225     apply (rule fns3 [THEN iffD1])
   8.226       prefer 3
   8.227       apply (rule fns2 [THEN iffD1])
   8.228 @@ -213,7 +213,7 @@
   8.229    done
   8.230  
   8.231  lemma range_norm:
   8.232 -  "range (Rep o Abs) = A"
   8.233 +  "range (Rep \<circ> Abs) = A"
   8.234    by (simp add: set_Rep_Abs)
   8.235  
   8.236  end
     9.1 --- a/src/HOL/Word/Word.thy	Mon Apr 03 22:18:56 2017 +0200
     9.2 +++ b/src/HOL/Word/Word.thy	Mon Apr 03 23:12:44 2017 +0200
     9.3 @@ -1827,8 +1827,8 @@
     9.4    by (auto simp: unat_word_ariths intro!: trans [OF _ nat_mod_lem])
     9.5  
     9.6  lemma unat_mult_lem:
     9.7 -  "unat x * unat y < 2 ^ len_of TYPE('a) \<longleftrightarrow>
     9.8 -    unat (x * y :: 'a::len word) = unat x * unat y"
     9.9 +  "unat x * unat y < 2 ^ len_of TYPE('a) \<longleftrightarrow> unat (x * y) = unat x * unat y"
    9.10 +  for x y :: "'a::len word"
    9.11    by (auto simp: unat_word_ariths intro!: trans [OF _ nat_mod_lem])
    9.12  
    9.13  lemmas unat_plus_if' =
    9.14 @@ -2002,7 +2002,7 @@
    9.15  
    9.16  lemmas div_lt_uint'' = order_less_imp_le [THEN div_lt_uint']
    9.17  
    9.18 -lemma word_le_exists': "x \<le> y \<Longrightarrow> (\<exists>z. y = x + z \<and> uint x + uint z < 2 ^ len_of TYPE('a))"
    9.19 +lemma word_le_exists': "x \<le> y \<Longrightarrow> \<exists>z. y = x + z \<and> uint x + uint z < 2 ^ len_of TYPE('a)"
    9.20    for x y z :: "'a::len0 word"
    9.21    apply (rule exI)
    9.22    apply (rule conjI)
    9.23 @@ -2330,13 +2330,15 @@
    9.24    unfolding to_bl_def word_log_defs bl_and_bin
    9.25    by (simp add: word_ubin.eq_norm)
    9.26  
    9.27 -lemma word_lsb_alt: "lsb (w::'a::len0 word) = test_bit w 0"
    9.28 +lemma word_lsb_alt: "lsb w = test_bit w 0"
    9.29 +  for w :: "'a::len0 word"
    9.30    by (auto simp: word_test_bit_def word_lsb_def)
    9.31  
    9.32  lemma word_lsb_1_0 [simp]: "lsb (1::'a::len word) \<and> \<not> lsb (0::'b::len0 word)"
    9.33    unfolding word_lsb_def uint_eq_0 uint_1 by simp
    9.34  
    9.35 -lemma word_lsb_last: "lsb (w::'a::len word) = last (to_bl w)"
    9.36 +lemma word_lsb_last: "lsb w = last (to_bl w)"
    9.37 +  for w :: "'a::len word"
    9.38    apply (unfold word_lsb_def uint_bl bin_to_bl_def)
    9.39    apply (rule_tac bin="uint w" in bin_exhaust)
    9.40    apply (cases "size w")
    9.41 @@ -2419,7 +2421,7 @@
    9.42    done
    9.43  
    9.44  lemma of_bl_rep_False: "of_bl (replicate n False @ bs) = of_bl bs"
    9.45 -  unfolding of_bl_def bl_to_bin_rep_F by auto
    9.46 +  by (auto simp: of_bl_def bl_to_bin_rep_F)
    9.47  
    9.48  lemma msb_nth: "msb w = w !! (len_of TYPE('a) - 1)"
    9.49    for w :: "'a::len word"
    9.50 @@ -2762,7 +2764,8 @@
    9.51  lemma shiftl1_of_bl: "shiftl1 (of_bl bl) = of_bl (bl @ [False])"
    9.52    by (simp add: of_bl_def bl_to_bin_append)
    9.53  
    9.54 -lemma shiftl1_bl: "shiftl1 (w::'a::len0 word) = of_bl (to_bl w @ [False])"
    9.55 +lemma shiftl1_bl: "shiftl1 w = of_bl (to_bl w @ [False])"
    9.56 +  for w :: "'a::len0 word"
    9.57  proof -
    9.58    have "shiftl1 w = shiftl1 (of_bl (to_bl w))"
    9.59      by simp
    9.60 @@ -2970,7 +2973,7 @@
    9.61    for x :: "'a::len0 word"
    9.62    using shiftr_bl_of [where 'a='a, of "to_bl x"] by simp
    9.63  
    9.64 -lemma msb_shift: "msb w \<longleftrightarrow> (w >> (len_of TYPE('a) - 1)) \<noteq> 0"
    9.65 +lemma msb_shift: "msb w \<longleftrightarrow> w >> (len_of TYPE('a) - 1) \<noteq> 0"
    9.66    for w :: "'a::len word"
    9.67    apply (unfold shiftr_bl word_msb_alt)
    9.68    apply (simp add: word_size Suc_le_eq take_Suc)
    9.69 @@ -3091,10 +3094,11 @@
    9.70     apply auto
    9.71    done
    9.72  
    9.73 -lemma eq_mod_iff: "0 < (n::int) \<Longrightarrow> b = b mod n \<longleftrightarrow> 0 \<le> b \<and> b < n"
    9.74 +lemma eq_mod_iff: "0 < n \<Longrightarrow> b = b mod n \<longleftrightarrow> 0 \<le> b \<and> b < n"
    9.75 +  for b n :: int
    9.76    by (simp add: int_mod_lem eq_sym_conv)
    9.77  
    9.78 -lemma mask_eq_iff: "(w AND mask n) = w \<longleftrightarrow> uint w < 2 ^ n"
    9.79 +lemma mask_eq_iff: "w AND mask n = w \<longleftrightarrow> uint w < 2 ^ n"
    9.80    apply (simp add: and_mask_bintr)
    9.81    apply (simp add: word_ubin.inverse_norm)
    9.82    apply (simp add: eq_mod_iff bintrunc_mod2p min_def)
    9.83 @@ -3632,8 +3636,9 @@
    9.84        split: prod.split)
    9.85  
    9.86  lemma test_bit_rsplit:
    9.87 -  "sw = word_rsplit w \<Longrightarrow> m < size (hd sw :: 'a::len word) \<Longrightarrow>
    9.88 -    k < length sw \<Longrightarrow> (rev sw ! k) !! m = (w !! (k * size (hd sw) + m))"
    9.89 +  "sw = word_rsplit w \<Longrightarrow> m < size (hd sw) \<Longrightarrow>
    9.90 +    k < length sw \<Longrightarrow> (rev sw ! k) !! m = w !! (k * size (hd sw) + m)"
    9.91 +  for sw :: "'a::len word list"
    9.92    apply (unfold word_rsplit_def word_test_bit_def)
    9.93    apply (rule trans)
    9.94     apply (rule_tac f = "\<lambda>x. bin_nth x m" in arg_cong)
    9.95 @@ -3673,8 +3678,9 @@
    9.96    done
    9.97  
    9.98  lemma test_bit_rcat:
    9.99 -  "sw = size (hd wl :: 'a::len word) \<Longrightarrow> rc = word_rcat wl \<Longrightarrow> rc !! n =
   9.100 +  "sw = size (hd wl) \<Longrightarrow> rc = word_rcat wl \<Longrightarrow> rc !! n =
   9.101      (n < size rc \<and> n div sw < size wl \<and> (rev wl) ! (n div sw) !! (n mod sw))"
   9.102 +  for wl :: "'a::len word list"
   9.103    apply (unfold word_rcat_bl word_size)
   9.104    apply (clarsimp simp add: test_bit_of_bl size_rcat_lem word_size td_gal_lt_len)
   9.105    apply safe
   9.106 @@ -4266,10 +4272,11 @@
   9.107    by (simp add: word_arith_wis int_word_uint mod_add_if_z word_size)
   9.108  
   9.109  lemma unat_plus_if_size:
   9.110 -  "unat (x + (y::'a::len word)) =
   9.111 +  "unat (x + y) =
   9.112      (if unat x + unat y < 2^size x
   9.113       then unat x + unat y
   9.114       else unat x + unat y - 2^size x)"
   9.115 +  for x y :: "'a::len word"
   9.116    apply (subst word_arith_nat_defs)
   9.117    apply (subst unat_of_nat)
   9.118    apply (simp add:  mod_nat_add word_size)
   9.119 @@ -4339,7 +4346,7 @@
   9.120    shows "(x - y) mod b = z' mod b'"
   9.121    using assms [symmetric] by (auto intro: mod_diff_cong)
   9.122  
   9.123 -lemma word_induct_less: "\<lbrakk>P 0; \<And>n. \<lbrakk>n < m; P n\<rbrakk> \<Longrightarrow> P (1 + n)\<rbrakk> \<Longrightarrow> P m"
   9.124 +lemma word_induct_less: "P 0 \<Longrightarrow> (\<And>n. n < m \<Longrightarrow> P n \<Longrightarrow> P (1 + n)) \<Longrightarrow> P m"
   9.125    for P :: "'a::len word \<Rightarrow> bool"
   9.126    apply (cases m)
   9.127    apply atomize
   9.128 @@ -4362,11 +4369,11 @@
   9.129    apply simp
   9.130    done
   9.131  
   9.132 -lemma word_induct: "\<lbrakk>P 0; \<And>n. P n \<Longrightarrow> P (1 + n)\<rbrakk> \<Longrightarrow> P m"
   9.133 +lemma word_induct: "P 0 \<Longrightarrow> (\<And>n. P n \<Longrightarrow> P (1 + n)) \<Longrightarrow> P m"
   9.134    for P :: "'a::len word \<Rightarrow> bool"
   9.135    by (erule word_induct_less) simp
   9.136  
   9.137 -lemma word_induct2 [induct type]: "\<lbrakk>P 0; \<And>n. \<lbrakk>1 + n \<noteq> 0; P n\<rbrakk> \<Longrightarrow> P (1 + n)\<rbrakk> \<Longrightarrow> P n"
   9.138 +lemma word_induct2 [induct type]: "P 0 \<Longrightarrow> (\<And>n. 1 + n \<noteq> 0 \<Longrightarrow> P n \<Longrightarrow> P (1 + n)) \<Longrightarrow> P n"
   9.139    for P :: "'b::len word \<Rightarrow> bool"
   9.140    apply (rule word_induct)
   9.141     apply simp
   9.142 @@ -4383,16 +4390,15 @@
   9.143  lemma word_rec_0: "word_rec z s 0 = z"
   9.144    by (simp add: word_rec_def)
   9.145  
   9.146 -lemma word_rec_Suc:
   9.147 -  "1 + n \<noteq> (0::'a::len word) \<Longrightarrow> word_rec z s (1 + n) = s n (word_rec z s n)"
   9.148 +lemma word_rec_Suc: "1 + n \<noteq> 0 \<Longrightarrow> word_rec z s (1 + n) = s n (word_rec z s n)"
   9.149 +  for n :: "'a::len word"
   9.150    apply (simp add: word_rec_def unat_word_ariths)
   9.151    apply (subst nat_mod_eq')
   9.152     apply (metis Suc_eq_plus1_left Suc_lessI of_nat_2p unat_1 unat_lt2p word_arith_nat_add)
   9.153    apply simp
   9.154    done
   9.155  
   9.156 -lemma word_rec_Pred:
   9.157 -  "n \<noteq> 0 \<Longrightarrow> word_rec z s n = s (n - 1) (word_rec z s (n - 1))"
   9.158 +lemma word_rec_Pred: "n \<noteq> 0 \<Longrightarrow> word_rec z s n = s (n - 1) (word_rec z s (n - 1))"
   9.159    apply (rule subst[where t="n" and s="1 + (n - 1)"])
   9.160     apply simp
   9.161    apply (subst word_rec_Suc)
   9.162 @@ -4468,7 +4474,8 @@
   9.163    apply simp
   9.164    done
   9.165  
   9.166 -lemma unatSuc: "1 + n \<noteq> (0::'a::len word) \<Longrightarrow> unat (1 + n) = Suc (unat n)"
   9.167 +lemma unatSuc: "1 + n \<noteq> 0 \<Longrightarrow> unat (1 + n) = Suc (unat n)"
   9.168 +  for n :: "'a::len word"
   9.169    by unat_arith
   9.170  
   9.171  declare bin_to_bl_def [simp]
    10.1 --- a/src/HOL/Word/WordBitwise.thy	Mon Apr 03 22:18:56 2017 +0200
    10.2 +++ b/src/HOL/Word/WordBitwise.thy	Mon Apr 03 23:12:44 2017 +0200
    10.3 @@ -2,24 +2,17 @@
    10.4      Authors:    Thomas Sewell, NICTA and Sascha Boehme, TU Muenchen
    10.5  *)
    10.6  
    10.7 -
    10.8  theory WordBitwise
    10.9 -
   10.10 -imports Word
   10.11 -
   10.12 +  imports Word
   10.13  begin
   10.14  
   10.15  text \<open>Helper constants used in defining addition\<close>
   10.16  
   10.17 -definition
   10.18 -  xor3 :: "bool \<Rightarrow> bool \<Rightarrow> bool \<Rightarrow> bool"
   10.19 -where
   10.20 - "xor3 a b c = (a = (b = c))"
   10.21 +definition xor3 :: "bool \<Rightarrow> bool \<Rightarrow> bool \<Rightarrow> bool"
   10.22 +  where "xor3 a b c = (a = (b = c))"
   10.23  
   10.24 -definition
   10.25 -  carry :: "bool \<Rightarrow> bool \<Rightarrow> bool \<Rightarrow> bool"
   10.26 -where
   10.27 - "carry a b c = ((a \<and> (b \<or> c)) \<or> (b \<and> c))"
   10.28 +definition carry :: "bool \<Rightarrow> bool \<Rightarrow> bool \<Rightarrow> bool"
   10.29 +  where "carry a b c = ((a \<and> (b \<or> c)) \<or> (b \<and> c))"
   10.30  
   10.31  lemma carry_simps:
   10.32    "carry True a b = (a \<or> b)"
   10.33 @@ -40,36 +33,28 @@
   10.34    by (simp_all add: xor3_def)
   10.35  
   10.36  text \<open>Breaking up word equalities into equalities on their
   10.37 -bit lists. Equalities are generated and manipulated in the
   10.38 -reverse order to to_bl.\<close>
   10.39 +  bit lists. Equalities are generated and manipulated in the
   10.40 +  reverse order to to_bl.\<close>
   10.41  
   10.42 -lemma word_eq_rbl_eq:
   10.43 -  "(x = y) = (rev (to_bl x) = rev (to_bl y))"
   10.44 +lemma word_eq_rbl_eq: "x = y \<longleftrightarrow> rev (to_bl x) = rev (to_bl y)"
   10.45    by simp
   10.46  
   10.47 -lemma rbl_word_or:
   10.48 -  "rev (to_bl (x OR y)) = map2 op \<or> (rev (to_bl x)) (rev (to_bl y))"
   10.49 +lemma rbl_word_or: "rev (to_bl (x OR y)) = map2 op \<or> (rev (to_bl x)) (rev (to_bl y))"
   10.50    by (simp add: map2_def zip_rev bl_word_or rev_map)
   10.51  
   10.52 -lemma rbl_word_and:
   10.53 -  "rev (to_bl (x AND y)) = map2 op \<and> (rev (to_bl x)) (rev (to_bl y))"
   10.54 +lemma rbl_word_and: "rev (to_bl (x AND y)) = map2 op \<and> (rev (to_bl x)) (rev (to_bl y))"
   10.55    by (simp add: map2_def zip_rev bl_word_and rev_map)
   10.56  
   10.57 -lemma rbl_word_xor:
   10.58 -  "rev (to_bl (x XOR y)) = map2 op \<noteq> (rev (to_bl x)) (rev (to_bl y))"
   10.59 +lemma rbl_word_xor: "rev (to_bl (x XOR y)) = map2 op \<noteq> (rev (to_bl x)) (rev (to_bl y))"
   10.60    by (simp add: map2_def zip_rev bl_word_xor rev_map)
   10.61  
   10.62 -lemma rbl_word_not:
   10.63 -  "rev (to_bl (NOT x)) = map Not (rev (to_bl x))"
   10.64 +lemma rbl_word_not: "rev (to_bl (NOT x)) = map Not (rev (to_bl x))"
   10.65    by (simp add: bl_word_not rev_map)
   10.66  
   10.67 -lemma bl_word_sub:
   10.68 -  "to_bl (x - y) = to_bl (x + (- y))"
   10.69 +lemma bl_word_sub: "to_bl (x - y) = to_bl (x + (- y))"
   10.70    by simp
   10.71  
   10.72 -lemma rbl_word_1:
   10.73 -  "rev (to_bl (1 :: ('a :: len0) word))
   10.74 -     = takefill False (len_of TYPE('a)) [True]"
   10.75 +lemma rbl_word_1: "rev (to_bl (1 :: 'a::len0 word)) = takefill False (len_of TYPE('a)) [True]"
   10.76    apply (rule_tac s="rev (to_bl (word_succ (0 :: 'a word)))" in trans)
   10.77     apply simp
   10.78    apply (simp only: rtb_rbl_ariths(1)[OF refl])
   10.79 @@ -79,22 +64,18 @@
   10.80    apply (simp add: takefill_alt)
   10.81    done
   10.82  
   10.83 -lemma rbl_word_if:
   10.84 -  "rev (to_bl (if P then x else y))
   10.85 -      = map2 (If P) (rev (to_bl x)) (rev (to_bl y))"
   10.86 +lemma rbl_word_if: "rev (to_bl (if P then x else y)) = map2 (If P) (rev (to_bl x)) (rev (to_bl y))"
   10.87    by (simp add: map2_def split_def)
   10.88  
   10.89  lemma rbl_add_carry_Cons:
   10.90 -  "(if car then rbl_succ else id) (rbl_add (x # xs) (y # ys))
   10.91 -        = xor3 x y car # (if carry x y car then rbl_succ else id)
   10.92 -             (rbl_add xs ys)"
   10.93 +  "(if car then rbl_succ else id) (rbl_add (x # xs) (y # ys)) =
   10.94 +    xor3 x y car # (if carry x y car then rbl_succ else id) (rbl_add xs ys)"
   10.95    by (simp add: carry_def xor3_def)
   10.96  
   10.97  lemma rbl_add_suc_carry_fold:
   10.98    "length xs = length ys \<Longrightarrow>
   10.99 -   \<forall>car. (if car then rbl_succ else id) (rbl_add xs ys)
  10.100 -        = (foldr (\<lambda>(x, y) res car. xor3 x y car # res (carry x y car))
  10.101 -                 (zip xs ys) (\<lambda>_. [])) car"
  10.102 +    \<forall>car. (if car then rbl_succ else id) (rbl_add xs ys) =
  10.103 +      (foldr (\<lambda>(x, y) res car. xor3 x y car # res (carry x y car)) (zip xs ys) (\<lambda>_. [])) car"
  10.104    apply (erule list_induct2)
  10.105     apply simp
  10.106    apply (simp only: rbl_add_carry_Cons)
  10.107 @@ -102,84 +83,70 @@
  10.108    done
  10.109  
  10.110  lemma to_bl_plus_carry:
  10.111 -  "to_bl (x + y)
  10.112 -     = rev (foldr (\<lambda>(x, y) res car. xor3 x y car # res (carry x y car))
  10.113 -                 (rev (zip (to_bl x) (to_bl y))) (\<lambda>_. []) False)"
  10.114 +  "to_bl (x + y) =
  10.115 +    rev (foldr (\<lambda>(x, y) res car. xor3 x y car # res (carry x y car))
  10.116 +      (rev (zip (to_bl x) (to_bl y))) (\<lambda>_. []) False)"
  10.117    using rbl_add_suc_carry_fold[where xs="rev (to_bl x)" and ys="rev (to_bl y)"]
  10.118    apply (simp add: word_add_rbl[OF refl refl])
  10.119    apply (drule_tac x=False in spec)
  10.120    apply (simp add: zip_rev)
  10.121    done
  10.122  
  10.123 -definition
  10.124 - "rbl_plus cin xs ys = foldr
  10.125 -       (\<lambda>(x, y) res car. xor3 x y car # res (carry x y car))
  10.126 -       (zip xs ys) (\<lambda>_. []) cin"
  10.127 +definition "rbl_plus cin xs ys =
  10.128 +  foldr (\<lambda>(x, y) res car. xor3 x y car # res (carry x y car)) (zip xs ys) (\<lambda>_. []) cin"
  10.129  
  10.130  lemma rbl_plus_simps:
  10.131 -  "rbl_plus cin (x # xs) (y # ys)
  10.132 -      = xor3 x y cin # rbl_plus (carry x y cin) xs ys"
  10.133 +  "rbl_plus cin (x # xs) (y # ys) = xor3 x y cin # rbl_plus (carry x y cin) xs ys"
  10.134    "rbl_plus cin [] ys = []"
  10.135    "rbl_plus cin xs [] = []"
  10.136    by (simp_all add: rbl_plus_def)
  10.137  
  10.138 -lemma rbl_word_plus:
  10.139 -  "rev (to_bl (x + y)) = rbl_plus False (rev (to_bl x)) (rev (to_bl y))"
  10.140 +lemma rbl_word_plus: "rev (to_bl (x + y)) = rbl_plus False (rev (to_bl x)) (rev (to_bl y))"
  10.141    by (simp add: rbl_plus_def to_bl_plus_carry zip_rev)
  10.142  
  10.143 -definition
  10.144 - "rbl_succ2 b xs = (if b then rbl_succ xs else xs)"
  10.145 +definition "rbl_succ2 b xs = (if b then rbl_succ xs else xs)"
  10.146  
  10.147  lemma rbl_succ2_simps:
  10.148    "rbl_succ2 b [] = []"
  10.149    "rbl_succ2 b (x # xs) = (b \<noteq> x) # rbl_succ2 (x \<and> b) xs"
  10.150    by (simp_all add: rbl_succ2_def)
  10.151  
  10.152 -lemma twos_complement:
  10.153 -  "- x = word_succ (NOT x)"
  10.154 +lemma twos_complement: "- x = word_succ (NOT x)"
  10.155    using arg_cong[OF word_add_not[where x=x], where f="\<lambda>a. a - x + 1"]
  10.156 -  by (simp add: word_succ_p1 word_sp_01[unfolded word_succ_p1]
  10.157 -           del: word_add_not)
  10.158 +  by (simp add: word_succ_p1 word_sp_01[unfolded word_succ_p1] del: word_add_not)
  10.159  
  10.160 -lemma rbl_word_neg:
  10.161 -  "rev (to_bl (- x)) = rbl_succ2 True (map Not (rev (to_bl x)))"
  10.162 -  by (simp add: twos_complement word_succ_rbl[OF refl]
  10.163 -                bl_word_not rev_map rbl_succ2_def)
  10.164 +lemma rbl_word_neg: "rev (to_bl (- x)) = rbl_succ2 True (map Not (rev (to_bl x)))"
  10.165 +  by (simp add: twos_complement word_succ_rbl[OF refl] bl_word_not rev_map rbl_succ2_def)
  10.166  
  10.167  lemma rbl_word_cat:
  10.168 -  "rev (to_bl (word_cat x y :: ('a :: len0) word))
  10.169 -     = takefill False (len_of TYPE('a)) (rev (to_bl y) @ rev (to_bl x))"
  10.170 +  "rev (to_bl (word_cat x y :: 'a::len0 word)) =
  10.171 +    takefill False (len_of TYPE('a)) (rev (to_bl y) @ rev (to_bl x))"
  10.172    by (simp add: word_cat_bl word_rev_tf)
  10.173  
  10.174  lemma rbl_word_slice:
  10.175 -  "rev (to_bl (slice n w :: ('a :: len0) word))
  10.176 -     = takefill False (len_of TYPE('a)) (drop n (rev (to_bl w)))"
  10.177 +  "rev (to_bl (slice n w :: 'a::len0 word)) =
  10.178 +    takefill False (len_of TYPE('a)) (drop n (rev (to_bl w)))"
  10.179    apply (simp add: slice_take word_rev_tf rev_take)
  10.180    apply (cases "n < len_of TYPE('b)", simp_all)
  10.181    done
  10.182  
  10.183  lemma rbl_word_ucast:
  10.184 -  "rev (to_bl (ucast x :: ('a :: len0) word))
  10.185 -     = takefill False (len_of TYPE('a)) (rev (to_bl x))"
  10.186 +  "rev (to_bl (ucast x :: 'a::len0 word)) = takefill False (len_of TYPE('a)) (rev (to_bl x))"
  10.187    apply (simp add: to_bl_ucast takefill_alt)
  10.188    apply (simp add: rev_drop)
  10.189 -  apply (case_tac "len_of TYPE('a) < len_of TYPE('b)")
  10.190 +  apply (cases "len_of TYPE('a) < len_of TYPE('b)")
  10.191     apply simp_all
  10.192    done
  10.193  
  10.194  lemma rbl_shiftl:
  10.195 -  "rev (to_bl (w << n)) = takefill False (size w)
  10.196 -     (replicate n False @ rev (to_bl w))"
  10.197 +  "rev (to_bl (w << n)) = takefill False (size w) (replicate n False @ rev (to_bl w))"
  10.198    by (simp add: bl_shiftl takefill_alt word_size rev_drop)
  10.199  
  10.200  lemma rbl_shiftr:
  10.201 -  "rev (to_bl (w >> n)) = takefill False (size w)
  10.202 -     (drop n (rev (to_bl w)))"
  10.203 +  "rev (to_bl (w >> n)) = takefill False (size w) (drop n (rev (to_bl w)))"
  10.204    by (simp add: shiftr_slice rbl_word_slice word_size)
  10.205  
  10.206 -definition
  10.207 - "drop_nonempty v n xs
  10.208 -     = (if n < length xs then drop n xs else [last (v # xs)])"
  10.209 +definition "drop_nonempty v n xs = (if n < length xs then drop n xs else [last (v # xs)])"
  10.210  
  10.211  lemma drop_nonempty_simps:
  10.212    "drop_nonempty v (Suc n) (x # xs) = drop_nonempty x n xs"
  10.213 @@ -187,86 +154,69 @@
  10.214    "drop_nonempty v n [] = [v]"
  10.215    by (simp_all add: drop_nonempty_def)
  10.216  
  10.217 -definition
  10.218 -  "takefill_last x n xs = takefill (last (x # xs)) n xs"
  10.219 +definition "takefill_last x n xs = takefill (last (x # xs)) n xs"
  10.220  
  10.221  lemma takefill_last_simps:
  10.222    "takefill_last z (Suc n) (x # xs) = x # takefill_last x n xs"
  10.223    "takefill_last z 0 xs = []"
  10.224    "takefill_last z n [] = replicate n z"
  10.225 -  apply (simp_all add: takefill_last_def)
  10.226 -  apply (simp_all add: takefill_alt)
  10.227 -  done
  10.228 +  by (simp_all add: takefill_last_def) (simp_all add: takefill_alt)
  10.229  
  10.230  lemma rbl_sshiftr:
  10.231 -  "rev (to_bl (w >>> n)) = 
  10.232 -     takefill_last False (size w) 
  10.233 -        (drop_nonempty False n (rev (to_bl w)))"
  10.234 +  "rev (to_bl (w >>> n)) = takefill_last False (size w) (drop_nonempty False n (rev (to_bl w)))"
  10.235    apply (cases "n < size w")
  10.236     apply (simp add: bl_sshiftr takefill_last_def word_size
  10.237 -                    takefill_alt rev_take last_rev
  10.238 -                    drop_nonempty_def)
  10.239 +      takefill_alt rev_take last_rev
  10.240 +      drop_nonempty_def)
  10.241    apply (subgoal_tac "(w >>> n) = of_bl (replicate (size w) (msb w))")
  10.242     apply (simp add: word_size takefill_last_def takefill_alt
  10.243 -                    last_rev word_msb_alt word_rev_tf
  10.244 -                    drop_nonempty_def take_Cons')
  10.245 +      last_rev word_msb_alt word_rev_tf
  10.246 +      drop_nonempty_def take_Cons')
  10.247     apply (case_tac "len_of TYPE('a)", simp_all)
  10.248    apply (rule word_eqI)
  10.249    apply (simp add: nth_sshiftr word_size test_bit_of_bl
  10.250 -                   msb_nth)
  10.251 +      msb_nth)
  10.252    done
  10.253  
  10.254  lemma nth_word_of_int:
  10.255 -  "(word_of_int x :: ('a :: len0) word) !! n
  10.256 -      = (n < len_of TYPE('a) \<and> bin_nth x n)"
  10.257 +  "(word_of_int x :: 'a::len0 word) !! n = (n < len_of TYPE('a) \<and> bin_nth x n)"
  10.258    apply (simp add: test_bit_bl word_size to_bl_of_bin)
  10.259    apply (subst conj_cong[OF refl], erule bin_nth_bl)
  10.260 -  apply (auto)
  10.261 +  apply auto
  10.262    done
  10.263  
  10.264  lemma nth_scast:
  10.265 -  "(scast (x :: ('a :: len) word) :: ('b :: len) word) !! n
  10.266 -     = (n < len_of TYPE('b) \<and>
  10.267 -          (if n < len_of TYPE('a) - 1 then x !! n
  10.268 -           else x !! (len_of TYPE('a) - 1)))"
  10.269 -  by (simp add: scast_def nth_word_of_int nth_sint)
  10.270 +  "(scast (x :: 'a::len word) :: 'b::len word) !! n =
  10.271 +    (n < len_of TYPE('b) \<and>
  10.272 +    (if n < len_of TYPE('a) - 1 then x !! n
  10.273 +     else x !! (len_of TYPE('a) - 1)))"
  10.274 +  by (simp add: scast_def nth_sint)
  10.275  
  10.276  lemma rbl_word_scast:
  10.277 -  "rev (to_bl (scast x :: ('a :: len) word))
  10.278 -     = takefill_last False (len_of TYPE('a))
  10.279 -           (rev (to_bl x))"
  10.280 +  "rev (to_bl (scast x :: 'a::len word)) = takefill_last False (len_of TYPE('a)) (rev (to_bl x))"
  10.281    apply (rule nth_equalityI)
  10.282     apply (simp add: word_size takefill_last_def)
  10.283    apply (clarsimp simp: nth_scast takefill_last_def
  10.284 -                        nth_takefill word_size nth_rev to_bl_nth)
  10.285 +      nth_takefill word_size nth_rev to_bl_nth)
  10.286    apply (cases "len_of TYPE('b)")
  10.287     apply simp
  10.288    apply (clarsimp simp: less_Suc_eq_le linorder_not_less
  10.289 -                        last_rev word_msb_alt[symmetric]
  10.290 -                        msb_nth)
  10.291 +      last_rev word_msb_alt[symmetric]
  10.292 +      msb_nth)
  10.293    done
  10.294  
  10.295 -definition
  10.296 -  rbl_mul :: "bool list \<Rightarrow> bool list \<Rightarrow> bool list"
  10.297 -where
  10.298 - "rbl_mul xs ys = foldr (\<lambda>x sm. rbl_plus False (map (op \<and> x) ys) (False # sm))
  10.299 -    xs []"
  10.300 +definition rbl_mul :: "bool list \<Rightarrow> bool list \<Rightarrow> bool list"
  10.301 +  where "rbl_mul xs ys = foldr (\<lambda>x sm. rbl_plus False (map (op \<and> x) ys) (False # sm)) xs []"
  10.302  
  10.303  lemma rbl_mul_simps:
  10.304 -  "rbl_mul (x # xs) ys
  10.305 -     = rbl_plus False (map (op \<and> x) ys) (False # rbl_mul xs ys)"
  10.306 +  "rbl_mul (x # xs) ys = rbl_plus False (map (op \<and> x) ys) (False # rbl_mul xs ys)"
  10.307    "rbl_mul [] ys = []"
  10.308    by (simp_all add: rbl_mul_def)
  10.309  
  10.310 -lemma takefill_le2:
  10.311 -  "length xs \<le> n \<Longrightarrow>
  10.312 -   takefill x m (takefill x n xs)
  10.313 -     = takefill x m xs"
  10.314 +lemma takefill_le2: "length xs \<le> n \<Longrightarrow> takefill x m (takefill x n xs) = takefill x m xs"
  10.315    by (simp add: takefill_alt replicate_add[symmetric])
  10.316  
  10.317 -lemma take_rbl_plus:
  10.318 -  "\<forall>n b. take n (rbl_plus b xs ys)
  10.319 -    = rbl_plus b (take n xs) (take n ys)"
  10.320 +lemma take_rbl_plus: "\<forall>n b. take n (rbl_plus b xs ys) = rbl_plus b (take n xs) (take n ys)"
  10.321    apply (simp add: rbl_plus_def take_zip[symmetric])
  10.322    apply (rule_tac list="zip xs ys" in list.induct)
  10.323     apply simp
  10.324 @@ -275,52 +225,39 @@
  10.325    done
  10.326  
  10.327  lemma word_rbl_mul_induct:
  10.328 -  fixes y :: "'a :: len word" shows
  10.329 -  "length xs \<le> size y
  10.330 -   \<Longrightarrow> rbl_mul xs (rev (to_bl y))
  10.331 -     = take (length xs) (rev (to_bl (of_bl (rev xs) * y)))"
  10.332 +  "length xs \<le> size y \<Longrightarrow>
  10.333 +    rbl_mul xs (rev (to_bl y)) = take (length xs) (rev (to_bl (of_bl (rev xs) * y)))"
  10.334 +  for y :: "'a::len word"
  10.335  proof (induct xs)
  10.336    case Nil
  10.337 -  show ?case
  10.338 -    by (simp add: rbl_mul_simps)
  10.339 +  show ?case by (simp add: rbl_mul_simps)
  10.340  next
  10.341    case (Cons z zs)
  10.342  
  10.343 -  have rbl_word_plus':
  10.344 -    "\<And>(x :: 'a word) y.
  10.345 -      to_bl (x + y) = rev (rbl_plus False (rev (to_bl x)) (rev (to_bl y)))"
  10.346 +  have rbl_word_plus': "to_bl (x + y) = rev (rbl_plus False (rev (to_bl x)) (rev (to_bl y)))"
  10.347 +    for x y :: "'a word"
  10.348      by (simp add: rbl_word_plus[symmetric])
  10.349 -  
  10.350 +
  10.351    have mult_bit: "to_bl (of_bl [z] * y) = map (op \<and> z) (to_bl y)"
  10.352 -    apply (cases z)
  10.353 -     apply (simp cong: map_cong)
  10.354 -    apply (simp add: map_replicate_const cong: map_cong)
  10.355 -    done
  10.356 - 
  10.357 -  have shiftl: "\<And>xs. of_bl xs * 2 * y = (of_bl xs * y) << 1"
  10.358 +    by (cases z) (simp cong: map_cong, simp add: map_replicate_const cong: map_cong)
  10.359 +
  10.360 +  have shiftl: "of_bl xs * 2 * y = (of_bl xs * y) << 1" for xs
  10.361      by (simp add: shiftl_t2n)
  10.362  
  10.363 -  have zip_take_triv: "\<And>xs ys n. n = length ys
  10.364 -      \<Longrightarrow> zip (take n xs) ys = zip xs ys"
  10.365 -    by (rule nth_equalityI, simp_all)
  10.366 +  have zip_take_triv: "\<And>xs ys n. n = length ys \<Longrightarrow> zip (take n xs) ys = zip xs ys"
  10.367 +    by (rule nth_equalityI) simp_all
  10.368  
  10.369 -  show ?case
  10.370 -    using Cons
  10.371 +  from Cons show ?case
  10.372      apply (simp add: trans [OF of_bl_append add.commute]
  10.373 -                     rbl_mul_simps rbl_word_plus'
  10.374 -                     Cons.hyps distrib_right mult_bit
  10.375 -                     shiftl rbl_shiftl)
  10.376 -    apply (simp add: takefill_alt word_size rev_map take_rbl_plus
  10.377 -                     min_def)
  10.378 +        rbl_mul_simps rbl_word_plus' distrib_right mult_bit shiftl rbl_shiftl)
  10.379 +    apply (simp add: takefill_alt word_size rev_map take_rbl_plus min_def)
  10.380      apply (simp add: rbl_plus_def zip_take_triv)
  10.381      done
  10.382  qed
  10.383  
  10.384 -lemma rbl_word_mul:
  10.385 -  fixes x :: "'a :: len word"
  10.386 -  shows "rev (to_bl (x * y)) = rbl_mul (rev (to_bl x)) (rev (to_bl y))"
  10.387 -  using word_rbl_mul_induct[where xs="rev (to_bl x)" and y=y]
  10.388 -  by (simp add: word_size)
  10.389 +lemma rbl_word_mul: "rev (to_bl (x * y)) = rbl_mul (rev (to_bl x)) (rev (to_bl y))"
  10.390 +  for x :: "'a::len word"
  10.391 +  using word_rbl_mul_induct[where xs="rev (to_bl x)" and y=y] by (simp add: word_size)
  10.392  
  10.393  text \<open>Breaking up inequalities into bitlist properties.\<close>
  10.394  
  10.395 @@ -333,9 +270,8 @@
  10.396  
  10.397  lemma rev_bl_order_simps:
  10.398    "rev_bl_order F [] [] = F"
  10.399 -  "rev_bl_order F (x # xs) (y # ys)
  10.400 -     = rev_bl_order ((y \<and> \<not> x) \<or> ((y \<or> \<not> x) \<and> F)) xs ys"
  10.401 -  apply (simp_all add: rev_bl_order_def)
  10.402 +  "rev_bl_order F (x # xs) (y # ys) = rev_bl_order ((y \<and> \<not> x) \<or> ((y \<or> \<not> x) \<and> F)) xs ys"
  10.403 +   apply (simp_all add: rev_bl_order_def)
  10.404    apply (rule conj_cong[OF refl])
  10.405    apply (cases "xs = ys")
  10.406     apply (simp add: nth_Cons')
  10.407 @@ -350,39 +286,30 @@
  10.408  
  10.409  lemma rev_bl_order_rev_simp:
  10.410    "length xs = length ys \<Longrightarrow>
  10.411 -   rev_bl_order F (xs @ [x]) (ys @ [y])
  10.412 -     = ((y \<and> \<not> x) \<or> ((y \<or> \<not> x) \<and> rev_bl_order F xs ys))"
  10.413 -  apply (induct arbitrary: F rule: list_induct2)
  10.414 -   apply (auto simp add: rev_bl_order_simps)
  10.415 -  done
  10.416 +   rev_bl_order F (xs @ [x]) (ys @ [y]) = ((y \<and> \<not> x) \<or> ((y \<or> \<not> x) \<and> rev_bl_order F xs ys))"
  10.417 +  by (induct arbitrary: F rule: list_induct2) (auto simp: rev_bl_order_simps)
  10.418  
  10.419  lemma rev_bl_order_bl_to_bin:
  10.420 -  "length xs = length ys
  10.421 -     \<Longrightarrow> rev_bl_order True xs ys
  10.422 -            = (bl_to_bin (rev xs) \<le> bl_to_bin (rev ys))
  10.423 -       \<and> rev_bl_order False xs ys
  10.424 -            = (bl_to_bin (rev xs) < bl_to_bin (rev ys))"
  10.425 +  "length xs = length ys \<Longrightarrow>
  10.426 +    rev_bl_order True xs ys = (bl_to_bin (rev xs) \<le> bl_to_bin (rev ys)) \<and>
  10.427 +    rev_bl_order False xs ys = (bl_to_bin (rev xs) < bl_to_bin (rev ys))"
  10.428    apply (induct xs ys rule: list_induct2)
  10.429     apply (simp_all add: rev_bl_order_simps bl_to_bin_app_cat)
  10.430    apply (auto simp add: bl_to_bin_def Bit_B0 Bit_B1 add1_zle_eq Bit_def)
  10.431    done
  10.432  
  10.433 -lemma word_le_rbl:
  10.434 -  fixes x :: "('a :: len0) word"
  10.435 -  shows "(x \<le> y) = rev_bl_order True (rev (to_bl x)) (rev (to_bl y))"
  10.436 +lemma word_le_rbl: "x \<le> y \<longleftrightarrow> rev_bl_order True (rev (to_bl x)) (rev (to_bl y))"
  10.437 +  for x y :: "'a::len0 word"
  10.438    by (simp add: rev_bl_order_bl_to_bin word_le_def)
  10.439  
  10.440 -lemma word_less_rbl:
  10.441 -  fixes x :: "('a :: len0) word"
  10.442 -  shows "(x < y) = rev_bl_order False (rev (to_bl x)) (rev (to_bl y))"
  10.443 +lemma word_less_rbl: "x < y \<longleftrightarrow> rev_bl_order False (rev (to_bl x)) (rev (to_bl y))"
  10.444 +  for x y :: "'a::len0 word"
  10.445    by (simp add: word_less_alt rev_bl_order_bl_to_bin)
  10.446  
  10.447 -lemma word_sint_msb_eq:
  10.448 -  "sint x = uint x - (if msb x then 2 ^ size x else 0)"
  10.449 +lemma word_sint_msb_eq: "sint x = uint x - (if msb x then 2 ^ size x else 0)"
  10.450    apply (cases "msb x")
  10.451     apply (rule word_sint.Abs_eqD[where 'a='a], simp_all)
  10.452 -    apply (simp add: word_size wi_hom_syms
  10.453 -                     word_of_int_2p_len)
  10.454 +    apply (simp add: word_size wi_hom_syms word_of_int_2p_len)
  10.455     apply (simp add: sints_num word_size)
  10.456     apply (rule conjI)
  10.457      apply (simp add: le_diff_eq')
  10.458 @@ -398,11 +325,8 @@
  10.459    apply simp
  10.460    done
  10.461  
  10.462 -lemma word_sle_msb_le:
  10.463 -  "(x <=s y) = ((msb y --> msb x) \<and> 
  10.464 -                  ((msb x \<and> \<not> msb y) \<or> (x <= y)))"
  10.465 -  apply (simp add: word_sle_def word_sint_msb_eq word_size
  10.466 -                   word_le_def)
  10.467 +lemma word_sle_msb_le: "x <=s y \<longleftrightarrow> (msb y \<longrightarrow> msb x) \<and> ((msb x \<and> \<not> msb y) \<or> x \<le> y)"
  10.468 +  apply (simp add: word_sle_def word_sint_msb_eq word_size word_le_def)
  10.469    apply safe
  10.470     apply (rule order_trans[OF _ uint_ge_0])
  10.471     apply (simp add: order_less_imp_le)
  10.472 @@ -411,13 +335,10 @@
  10.473    apply simp
  10.474    done
  10.475  
  10.476 -lemma word_sless_msb_less:
  10.477 -  "(x <s y) = ((msb y --> msb x) \<and> 
  10.478 -                  ((msb x \<and> \<not> msb y) \<or> (x < y)))"
  10.479 +lemma word_sless_msb_less: "x <s y \<longleftrightarrow> (msb y \<longrightarrow> msb x) \<and> ((msb x \<and> \<not> msb y) \<or> x < y)"
  10.480    by (auto simp add: word_sless_def word_sle_msb_le)
  10.481  
  10.482 -definition
  10.483 -  "map_last f xs = (if xs = [] then [] else butlast xs @ [f (last xs)])"
  10.484 +definition "map_last f xs = (if xs = [] then [] else butlast xs @ [f (last xs)])"
  10.485  
  10.486  lemma map_last_simps:
  10.487    "map_last f [] = []"
  10.488 @@ -426,8 +347,7 @@
  10.489    by (simp_all add: map_last_def)
  10.490  
  10.491  lemma word_sle_rbl:
  10.492 -  "(x <=s y) = rev_bl_order True (map_last Not (rev (to_bl x)))
  10.493 -     (map_last Not (rev (to_bl y)))"
  10.494 +  "x <=s y \<longleftrightarrow> rev_bl_order True (map_last Not (rev (to_bl x))) (map_last Not (rev (to_bl y)))"
  10.495    using word_msb_alt[where w=x] word_msb_alt[where w=y]
  10.496    apply (simp add: word_sle_msb_le word_le_rbl)
  10.497    apply (subgoal_tac "length (to_bl x) = length (to_bl y)")
  10.498 @@ -438,8 +358,7 @@
  10.499    done
  10.500  
  10.501  lemma word_sless_rbl:
  10.502 -  "(x <s y) = rev_bl_order False (map_last Not (rev (to_bl x)))
  10.503 -     (map_last Not (rev (to_bl y)))"
  10.504 +  "x <s y \<longleftrightarrow> rev_bl_order False (map_last Not (rev (to_bl x))) (map_last Not (rev (to_bl y)))"
  10.505    using word_msb_alt[where w=x] word_msb_alt[where w=y]
  10.506    apply (simp add: word_sless_msb_less word_less_rbl)
  10.507    apply (subgoal_tac "length (to_bl x) = length (to_bl y)")
  10.508 @@ -450,51 +369,45 @@
  10.509    done
  10.510  
  10.511  text \<open>Lemmas for unpacking rev (to_bl n) for numerals n and also
  10.512 -for irreducible values and expressions.\<close>
  10.513 +  for irreducible values and expressions.\<close>
  10.514  
  10.515  lemma rev_bin_to_bl_simps:
  10.516    "rev (bin_to_bl 0 x) = []"
  10.517 -  "rev (bin_to_bl (Suc n) (numeral (num.Bit0 nm)))
  10.518 -    = False # rev (bin_to_bl n (numeral nm))"
  10.519 -  "rev (bin_to_bl (Suc n) (numeral (num.Bit1 nm)))
  10.520 -    = True # rev (bin_to_bl n (numeral nm))"
  10.521 -  "rev (bin_to_bl (Suc n) (numeral (num.One)))
  10.522 -    = True # replicate n False"
  10.523 -  "rev (bin_to_bl (Suc n) (- numeral (num.Bit0 nm)))
  10.524 -    = False # rev (bin_to_bl n (- numeral nm))"
  10.525 -  "rev (bin_to_bl (Suc n) (- numeral (num.Bit1 nm)))
  10.526 -    = True # rev (bin_to_bl n (- numeral (nm + num.One)))"
  10.527 -  "rev (bin_to_bl (Suc n) (- numeral (num.One)))
  10.528 -    = True # replicate n True"
  10.529 -  "rev (bin_to_bl (Suc n) (- numeral (num.Bit0 nm + num.One)))
  10.530 -    = True # rev (bin_to_bl n (- numeral (nm + num.One)))"
  10.531 -  "rev (bin_to_bl (Suc n) (- numeral (num.Bit1 nm + num.One)))
  10.532 -    = False # rev (bin_to_bl n (- numeral (nm + num.One)))"
  10.533 -  "rev (bin_to_bl (Suc n) (- numeral (num.One + num.One)))
  10.534 -    = False # rev (bin_to_bl n (- numeral num.One))"
  10.535 -  apply (simp_all add: bin_to_bl_def)
  10.536 +  "rev (bin_to_bl (Suc n) (numeral (num.Bit0 nm))) = False # rev (bin_to_bl n (numeral nm))"
  10.537 +  "rev (bin_to_bl (Suc n) (numeral (num.Bit1 nm))) = True # rev (bin_to_bl n (numeral nm))"
  10.538 +  "rev (bin_to_bl (Suc n) (numeral (num.One))) = True # replicate n False"
  10.539 +  "rev (bin_to_bl (Suc n) (- numeral (num.Bit0 nm))) = False # rev (bin_to_bl n (- numeral nm))"
  10.540 +  "rev (bin_to_bl (Suc n) (- numeral (num.Bit1 nm))) =
  10.541 +    True # rev (bin_to_bl n (- numeral (nm + num.One)))"
  10.542 +  "rev (bin_to_bl (Suc n) (- numeral (num.One))) = True # replicate n True"
  10.543 +  "rev (bin_to_bl (Suc n) (- numeral (num.Bit0 nm + num.One))) =
  10.544 +    True # rev (bin_to_bl n (- numeral (nm + num.One)))"
  10.545 +  "rev (bin_to_bl (Suc n) (- numeral (num.Bit1 nm + num.One))) =
  10.546 +    False # rev (bin_to_bl n (- numeral (nm + num.One)))"
  10.547 +  "rev (bin_to_bl (Suc n) (- numeral (num.One + num.One))) =
  10.548 +    False # rev (bin_to_bl n (- numeral num.One))"
  10.549 +  apply simp_all
  10.550    apply (simp_all only: bin_to_bl_aux_alt)
  10.551    apply (simp_all)
  10.552    apply (simp_all add: bin_to_bl_zero_aux bin_to_bl_minus1_aux)
  10.553    done
  10.554  
  10.555 -lemma to_bl_upt:
  10.556 -  "to_bl x = rev (map (op !! x) [0 ..< size x])"
  10.557 +lemma to_bl_upt: "to_bl x = rev (map (op !! x) [0 ..< size x])"
  10.558    apply (rule nth_equalityI)
  10.559     apply (simp add: word_size)
  10.560 -  apply (clarsimp simp: to_bl_nth word_size nth_rev)
  10.561 +  apply (auto simp: to_bl_nth word_size nth_rev)
  10.562    done
  10.563  
  10.564 -lemma rev_to_bl_upt:
  10.565 -  "rev (to_bl x) = map (op !! x) [0 ..< size x]"
  10.566 +lemma rev_to_bl_upt: "rev (to_bl x) = map (op !! x) [0 ..< size x]"
  10.567    by (simp add: to_bl_upt)
  10.568  
  10.569  lemma upt_eq_list_intros:
  10.570 -  "j <= i \<Longrightarrow> [i ..< j] = []"
  10.571 -  "\<lbrakk> i = x; x < j; [x + 1 ..< j] = xs \<rbrakk> \<Longrightarrow> [i ..< j] = (x # xs)"
  10.572 -  by (simp_all add: upt_eq_Nil_conv upt_eq_Cons_conv)
  10.573 +  "j \<le> i \<Longrightarrow> [i ..< j] = []"
  10.574 +  "i = x \<Longrightarrow> x < j \<Longrightarrow> [x + 1 ..< j] = xs \<Longrightarrow> [i ..< j] = (x # xs)"
  10.575 +  by (simp_all add: upt_eq_Cons_conv)
  10.576  
  10.577 -text \<open>Tactic definition\<close>
  10.578 +
  10.579 +subsection \<open>Tactic definition\<close>
  10.580  
  10.581  ML \<open>
  10.582  structure Word_Bitwise_Tac =
  10.583 @@ -517,7 +430,7 @@
  10.584                       |> Thm.apply @{cterm Trueprop};
  10.585        in
  10.586          try (fn () =>
  10.587 -          Goal.prove_internal ctxt [] prop 
  10.588 +          Goal.prove_internal ctxt [] prop
  10.589              (K (REPEAT_DETERM (resolve_tac ctxt @{thms upt_eq_list_intros} 1
  10.590                  ORELSE simp_tac (put_simpset word_ss ctxt) 1))) |> mk_meta_eq) ()
  10.591        end
  10.592 @@ -616,7 +529,6 @@
  10.593    end;
  10.594  
  10.595  end
  10.596 -
  10.597  \<close>
  10.598  
  10.599  method_setup word_bitwise =
    11.1 --- a/src/HOL/Word/Word_Miscellaneous.thy	Mon Apr 03 22:18:56 2017 +0200
    11.2 +++ b/src/HOL/Word/Word_Miscellaneous.thy	Mon Apr 03 23:12:44 2017 +0200
    11.3 @@ -1,34 +1,27 @@
    11.4 -(*  Title:      HOL/Word/Word_Miscellaneous.thy
    11.5 -    Author:     Miscellaneous
    11.6 -*)
    11.7 +(*  Title:      HOL/Word/Word_Miscellaneous.thy  *)
    11.8  
    11.9  section \<open>Miscellaneous lemmas, of at least doubtful value\<close>
   11.10  
   11.11  theory Word_Miscellaneous
   11.12 -imports Main "~~/src/HOL/Library/Bit" Misc_Numeric
   11.13 +  imports "~~/src/HOL/Library/Bit" Misc_Numeric
   11.14  begin
   11.15  
   11.16 -lemma power_minus_simp:
   11.17 -  "0 < n \<Longrightarrow> a ^ n = a * a ^ (n - 1)"
   11.18 +lemma power_minus_simp: "0 < n \<Longrightarrow> a ^ n = a * a ^ (n - 1)"
   11.19    by (auto dest: gr0_implies_Suc)
   11.20  
   11.21 -lemma funpow_minus_simp:
   11.22 -  "0 < n \<Longrightarrow> f ^^ n = f \<circ> f ^^ (n - 1)"
   11.23 +lemma funpow_minus_simp: "0 < n \<Longrightarrow> f ^^ n = f \<circ> f ^^ (n - 1)"
   11.24    by (auto dest: gr0_implies_Suc)
   11.25  
   11.26 -lemma power_numeral:
   11.27 -  "a ^ numeral k = a * a ^ (pred_numeral k)"
   11.28 +lemma power_numeral: "a ^ numeral k = a * a ^ (pred_numeral k)"
   11.29    by (simp add: numeral_eq_Suc)
   11.30  
   11.31 -lemma funpow_numeral [simp]:
   11.32 -  "f ^^ numeral k = f \<circ> f ^^ (pred_numeral k)"
   11.33 +lemma funpow_numeral [simp]: "f ^^ numeral k = f \<circ> f ^^ (pred_numeral k)"
   11.34    by (simp add: numeral_eq_Suc)
   11.35  
   11.36 -lemma replicate_numeral [simp]:
   11.37 -  "replicate (numeral k) x = x # replicate (pred_numeral k) x"
   11.38 +lemma replicate_numeral [simp]: "replicate (numeral k) x = x # replicate (pred_numeral k) x"
   11.39    by (simp add: numeral_eq_Suc)
   11.40  
   11.41 -lemma rco_alt: "(f o g) ^^ n o f = f o (g o f) ^^ n"
   11.42 +lemma rco_alt: "(f \<circ> g) ^^ n \<circ> f = f \<circ> (g \<circ> f) ^^ n"
   11.43    apply (rule ext)
   11.44    apply (induct n)
   11.45     apply (simp_all add: o_def)
   11.46 @@ -37,7 +30,8 @@
   11.47  lemma list_exhaust_size_gt0:
   11.48    assumes y: "\<And>a list. y = a # list \<Longrightarrow> P"
   11.49    shows "0 < length y \<Longrightarrow> P"
   11.50 -  apply (cases y, simp)
   11.51 +  apply (cases y)
   11.52 +   apply simp
   11.53    apply (rule y)
   11.54    apply fastforce
   11.55    done
   11.56 @@ -46,22 +40,24 @@
   11.57    assumes y: "y = [] \<Longrightarrow> P"
   11.58    shows "length y = 0 \<Longrightarrow> P"
   11.59    apply (cases y)
   11.60 -   apply (rule y, simp)
   11.61 +   apply (rule y)
   11.62 +   apply simp
   11.63    apply simp
   11.64    done
   11.65  
   11.66 -lemma size_Cons_lem_eq:
   11.67 -  "y = xa # list ==> size y = Suc k ==> size list = k"
   11.68 +lemma size_Cons_lem_eq: "y = xa # list \<Longrightarrow> size y = Suc k \<Longrightarrow> size list = k"
   11.69    by auto
   11.70  
   11.71  lemmas ls_splits = prod.split prod.split_asm if_split_asm
   11.72  
   11.73 -lemma not_B1_is_B0: "y \<noteq> (1::bit) \<Longrightarrow> y = (0::bit)"
   11.74 +lemma not_B1_is_B0: "y \<noteq> 1 \<Longrightarrow> y = 0"
   11.75 +  for y :: bit
   11.76    by (cases y) auto
   11.77  
   11.78 -lemma B1_ass_B0: 
   11.79 -  assumes y: "y = (0::bit) \<Longrightarrow> y = (1::bit)"
   11.80 -  shows "y = (1::bit)"
   11.81 +lemma B1_ass_B0:
   11.82 +  fixes y :: bit
   11.83 +  assumes y: "y = 0 \<Longrightarrow> y = 1"
   11.84 +  shows "y = 1"
   11.85    apply (rule classical)
   11.86    apply (drule not_B1_is_B0)
   11.87    apply (erule y)
   11.88 @@ -72,7 +68,7 @@
   11.89  
   11.90  lemmas s2n_ths = n2s_ths [symmetric]
   11.91  
   11.92 -lemma and_len: "xs = ys ==> xs = ys & length xs = length ys"
   11.93 +lemma and_len: "xs = ys \<Longrightarrow> xs = ys \<and> length xs = length ys"
   11.94    by auto
   11.95  
   11.96  lemma size_if: "size (if p then xs else ys) = (if p then size xs else size ys)"
   11.97 @@ -84,20 +80,19 @@
   11.98  lemma hd_if: "hd (if p then xs else ys) = (if p then hd xs else hd ys)"
   11.99    by auto
  11.100  
  11.101 -lemma if_Not_x: "(if p then ~ x else x) = (p = (~ x))"
  11.102 +lemma if_Not_x: "(if p then \<not> x else x) = (p = (\<not> x))"
  11.103    by auto
  11.104  
  11.105 -lemma if_x_Not: "(if p then x else ~ x) = (p = x)"
  11.106 +lemma if_x_Not: "(if p then x else \<not> x) = (p = x)"
  11.107    by auto
  11.108  
  11.109 -lemma if_same_and: "(If p x y & If p u v) = (if p then x & u else y & v)"
  11.110 +lemma if_same_and: "(If p x y \<and> If p u v) = (if p then x \<and> u else y \<and> v)"
  11.111    by auto
  11.112  
  11.113 -lemma if_same_eq: "(If p x y  = (If p u v)) = (if p then x = (u) else y = (v))"
  11.114 +lemma if_same_eq: "(If p x y  = (If p u v)) = (if p then x = u else y = v)"
  11.115    by auto
  11.116  
  11.117 -lemma if_same_eq_not:
  11.118 -  "(If p x y  = (~ If p u v)) = (if p then x = (~u) else y = (~v))"
  11.119 +lemma if_same_eq_not: "(If p x y = (\<not> If p u v)) = (if p then x = (\<not> u) else y = (\<not> v))"
  11.120    by auto
  11.121  
  11.122  (* note - if_Cons can cause blowup in the size, if p is complex,
  11.123 @@ -105,25 +100,28 @@
  11.124  lemma if_Cons: "(if p then x # xs else y # ys) = If p x y # If p xs ys"
  11.125    by auto
  11.126  
  11.127 -lemma if_single:
  11.128 -  "(if xc then [xab] else [an]) = [if xc then xab else an]"
  11.129 +lemma if_single: "(if xc then [xab] else [an]) = [if xc then xab else an]"
  11.130    by auto
  11.131  
  11.132  lemma if_bool_simps:
  11.133 -  "If p True y = (p | y) & If p False y = (~p & y) & 
  11.134 -    If p y True = (p --> y) & If p y False = (p & y)"
  11.135 +  "If p True y = (p \<or> y) \<and> If p False y = (\<not> p \<and> y) \<and>
  11.136 +    If p y True = (p \<longrightarrow> y) \<and> If p y False = (p \<and> y)"
  11.137    by auto
  11.138  
  11.139 -lemmas if_simps = if_x_Not if_Not_x if_cancel if_True if_False if_bool_simps
  11.140 +lemmas if_simps =
  11.141 +  if_x_Not if_Not_x if_cancel if_True if_False if_bool_simps
  11.142  
  11.143  lemmas seqr = eq_reflection [where x = "size w"] for w (* FIXME: delete *)
  11.144  
  11.145 -lemma the_elemI: "y = {x} ==> the_elem y = x" 
  11.146 +lemma the_elemI: "y = {x} \<Longrightarrow> the_elem y = x"
  11.147    by simp
  11.148  
  11.149 -lemma nonemptyE: "S ~= {} ==> (!!x. x : S ==> R) ==> R" by auto
  11.150 +lemma nonemptyE: "S \<noteq> {} \<Longrightarrow> (\<And>x. x \<in> S \<Longrightarrow> R) \<Longrightarrow> R"
  11.151 +  by auto
  11.152  
  11.153 -lemma gt_or_eq_0: "0 < y \<or> 0 = (y::nat)" by arith 
  11.154 +lemma gt_or_eq_0: "0 < y \<or> 0 = y"
  11.155 +  for y :: nat
  11.156 +  by arith
  11.157  
  11.158  lemmas xtr1 = xtrans(1)
  11.159  lemmas xtr2 = xtrans(2)
  11.160 @@ -137,63 +135,76 @@
  11.161  lemmas nat_simps = diff_add_inverse2 diff_add_inverse
  11.162  lemmas nat_iffs = le_add1 le_add2
  11.163  
  11.164 -lemma sum_imp_diff: "j = k + i ==> j - i = (k :: nat)" by arith
  11.165 +lemma sum_imp_diff: "j = k + i \<Longrightarrow> j - i = k"
  11.166 +  for k :: nat
  11.167 +  by arith
  11.168  
  11.169  lemmas pos_mod_sign2 = zless2 [THEN pos_mod_sign [where b = "2::int"]]
  11.170  lemmas pos_mod_bound2 = zless2 [THEN pos_mod_bound [where b = "2::int"]]
  11.171  
  11.172 -lemma nmod2: "n mod (2::int) = 0 | n mod 2 = 1"
  11.173 +lemma nmod2: "n mod 2 = 0 \<or> n mod 2 = 1"
  11.174 +  for n :: int
  11.175    by arith
  11.176  
  11.177  lemmas eme1p = emep1 [simplified add.commute]
  11.178  
  11.179 -lemma le_diff_eq': "(a \<le> c - b) = (b + a \<le> (c::int))" by arith
  11.180 +lemma le_diff_eq': "a \<le> c - b \<longleftrightarrow> b + a \<le> c"
  11.181 +  for a b c :: int
  11.182 +  by arith
  11.183  
  11.184 -lemma less_diff_eq': "(a < c - b) = (b + a < (c::int))" by arith
  11.185 +lemma less_diff_eq': "a < c - b \<longleftrightarrow> b + a < c"
  11.186 +  for a b c :: int
  11.187 +  by arith
  11.188  
  11.189 -lemma diff_less_eq': "(a - b < c) = (a < b + (c::int))" by arith
  11.190 +lemma diff_less_eq': "a - b < c \<longleftrightarrow> a < b + c"
  11.191 +  for a b c :: int
  11.192 +  by arith
  11.193  
  11.194  lemmas m1mod22k = mult_pos_pos [OF zless2 zless2p, THEN zmod_minus1]
  11.195  
  11.196 -lemma z1pdiv2:
  11.197 -  "(2 * b + 1) div 2 = (b::int)" by arith
  11.198 +lemma z1pdiv2: "(2 * b + 1) div 2 = b"
  11.199 +  for b :: int
  11.200 +  by arith
  11.201  
  11.202  lemmas zdiv_le_dividend = xtr3 [OF div_by_1 [symmetric] zdiv_mono2,
  11.203    simplified int_one_le_iff_zero_less, simplified]
  11.204 -  
  11.205 -lemma axxbyy:
  11.206 -  "a + m + m = b + n + n ==> (a = 0 | a = 1) ==> (b = 0 | b = 1) ==>  
  11.207 -   a = b & m = (n :: int)" by arith
  11.208  
  11.209 -lemma axxmod2:
  11.210 -  "(1 + x + x) mod 2 = (1 :: int) & (0 + x + x) mod 2 = (0 :: int)" by arith
  11.211 +lemma axxbyy: "a + m + m = b + n + n \<Longrightarrow> a = 0 \<or> a = 1 \<Longrightarrow> b = 0 \<or> b = 1 \<Longrightarrow> a = b \<and> m = n"
  11.212 +  for a b m n :: int
  11.213 +  by arith
  11.214 +
  11.215 +lemma axxmod2: "(1 + x + x) mod 2 = 1 \<and> (0 + x + x) mod 2 = 0"
  11.216 +  for x :: int
  11.217 +  by arith
  11.218  
  11.219 -lemma axxdiv2:
  11.220 -  "(1 + x + x) div 2 = (x :: int) & (0 + x + x) div 2 = (x :: int)"  by arith
  11.221 +lemma axxdiv2: "(1 + x + x) div 2 = x \<and> (0 + x + x) div 2 = x"
  11.222 +  for x :: int
  11.223 +  by arith
  11.224  
  11.225 -lemmas iszero_minus = trans [THEN trans,
  11.226 -  OF iszero_def neg_equal_0_iff_equal iszero_def [symmetric]]
  11.227 +lemmas iszero_minus =
  11.228 +  trans [THEN trans, OF iszero_def neg_equal_0_iff_equal iszero_def [symmetric]]
  11.229  
  11.230 -lemmas zadd_diff_inverse = trans [OF diff_add_cancel [symmetric] add.commute]
  11.231 +lemmas zadd_diff_inverse =
  11.232 +  trans [OF diff_add_cancel [symmetric] add.commute]
  11.233  
  11.234 -lemmas add_diff_cancel2 = add.commute [THEN diff_eq_eq [THEN iffD2]]
  11.235 +lemmas add_diff_cancel2 =
  11.236 +  add.commute [THEN diff_eq_eq [THEN iffD2]]
  11.237  
  11.238  lemmas rdmods [symmetric] = mod_minus_eq
  11.239    mod_diff_left_eq mod_diff_right_eq mod_add_left_eq
  11.240    mod_add_right_eq mod_mult_right_eq mod_mult_left_eq
  11.241  
  11.242 -lemma mod_plus_right:
  11.243 -  "((a + x) mod m = (b + x) mod m) = (a mod m = b mod (m :: nat))"
  11.244 -  apply (induct x)
  11.245 -   apply (simp_all add: mod_Suc)
  11.246 -  apply arith
  11.247 -  done
  11.248 +lemma mod_plus_right: "(a + x) mod m = (b + x) mod m \<longleftrightarrow> a mod m = b mod m"
  11.249 +  for a b m x :: nat
  11.250 +  by (induct x) (simp_all add: mod_Suc, arith)
  11.251  
  11.252 -lemma nat_minus_mod: "(n - n mod m) mod m = (0 :: nat)"
  11.253 -  by (induct n) (simp_all add : mod_Suc)
  11.254 +lemma nat_minus_mod: "(n - n mod m) mod m = 0"
  11.255 +  for m n :: nat
  11.256 +  by (induct n) (simp_all add: mod_Suc)
  11.257  
  11.258 -lemmas nat_minus_mod_plus_right = trans [OF nat_minus_mod mod_0 [symmetric],
  11.259 -  THEN mod_plus_right [THEN iffD2], simplified]
  11.260 +lemmas nat_minus_mod_plus_right =
  11.261 +  trans [OF nat_minus_mod mod_0 [symmetric],
  11.262 +    THEN mod_plus_right [THEN iffD2], simplified]
  11.263  
  11.264  lemmas push_mods' = mod_add_eq
  11.265    mod_mult_eq mod_diff_eq
  11.266 @@ -202,23 +213,22 @@
  11.267  lemmas push_mods = push_mods' [THEN eq_reflection]
  11.268  lemmas pull_mods = push_mods [symmetric] rdmods [THEN eq_reflection]
  11.269  
  11.270 -lemma nat_mod_eq:
  11.271 -  "!!b. b < n ==> a mod n = b mod n ==> a mod n = (b :: nat)" 
  11.272 +lemma nat_mod_eq: "b < n \<Longrightarrow> a mod n = b mod n \<Longrightarrow> a mod n = b"
  11.273 +  for a b n :: nat
  11.274    by (induct a) auto
  11.275  
  11.276  lemmas nat_mod_eq' = refl [THEN [2] nat_mod_eq]
  11.277  
  11.278 -lemma nat_mod_lem: 
  11.279 -  "(0 :: nat) < n ==> b < n = (b mod n = b)"
  11.280 +lemma nat_mod_lem: "0 < n \<Longrightarrow> b < n \<longleftrightarrow> b mod n = b"
  11.281 +  for b n :: nat
  11.282    apply safe
  11.283     apply (erule nat_mod_eq')
  11.284    apply (erule subst)
  11.285    apply (erule mod_less_divisor)
  11.286    done
  11.287  
  11.288 -lemma mod_nat_add: 
  11.289 -  "(x :: nat) < z ==> y < z ==> 
  11.290 -   (x + y) mod z = (if x + y < z then x + y else x + y - z)"
  11.291 +lemma mod_nat_add: "x < z \<Longrightarrow> y < z \<Longrightarrow> (x + y) mod z = (if x + y < z then x + y else x + y - z)"
  11.292 +  for x y z :: nat
  11.293    apply (rule nat_mod_eq)
  11.294     apply auto
  11.295    apply (rule trans)
  11.296 @@ -228,42 +238,46 @@
  11.297    apply arith
  11.298    done
  11.299  
  11.300 -lemma mod_nat_sub: 
  11.301 -  "(x :: nat) < z ==> (x - y) mod z = x - y"
  11.302 +lemma mod_nat_sub: "x < z \<Longrightarrow> (x - y) mod z = x - y"
  11.303 +  for x y :: nat
  11.304    by (rule nat_mod_eq') arith
  11.305  
  11.306 -lemma int_mod_eq:
  11.307 -  "(0 :: int) <= b ==> b < n ==> a mod n = b mod n ==> a mod n = b"
  11.308 +lemma int_mod_eq: "0 \<le> b \<Longrightarrow> b < n \<Longrightarrow> a mod n = b mod n \<Longrightarrow> a mod n = b"
  11.309 +  for a b n :: int
  11.310    by (metis mod_pos_pos_trivial)
  11.311  
  11.312  lemmas int_mod_eq' = mod_pos_pos_trivial (* FIXME delete *)
  11.313  
  11.314 -lemma int_mod_le: "(0::int) <= a ==> a mod n <= a"
  11.315 +lemma int_mod_le: "0 \<le> a \<Longrightarrow> a mod n \<le> a"
  11.316 +  for a :: int
  11.317    by (fact Divides.semiring_numeral_div_class.mod_less_eq_dividend) (* FIXME: delete *)
  11.318  
  11.319  lemma mod_add_if_z:
  11.320 -  "(x :: int) < z ==> y < z ==> 0 <= y ==> 0 <= x ==> 0 <= z ==> 
  11.321 -   (x + y) mod z = (if x + y < z then x + y else x + y - z)"
  11.322 +  "x < z \<Longrightarrow> y < z \<Longrightarrow> 0 \<le> y \<Longrightarrow> 0 \<le> x \<Longrightarrow> 0 \<le> z \<Longrightarrow>
  11.323 +    (x + y) mod z = (if x + y < z then x + y else x + y - z)"
  11.324 +  for x y z :: int
  11.325    by (auto intro: int_mod_eq)
  11.326  
  11.327  lemma mod_sub_if_z:
  11.328 -  "(x :: int) < z ==> y < z ==> 0 <= y ==> 0 <= x ==> 0 <= z ==> 
  11.329 -   (x - y) mod z = (if y <= x then x - y else x - y + z)"
  11.330 +  "x < z \<Longrightarrow> y < z \<Longrightarrow> 0 \<le> y \<Longrightarrow> 0 \<le> x \<Longrightarrow> 0 \<le> z \<Longrightarrow>
  11.331 +    (x - y) mod z = (if y \<le> x then x - y else x - y + z)"
  11.332 +  for x y z :: int
  11.333    by (auto intro: int_mod_eq)
  11.334  
  11.335  lemmas zmde = mult_div_mod_eq [symmetric, THEN diff_eq_eq [THEN iffD2], symmetric]
  11.336  lemmas mcl = mult_cancel_left [THEN iffD1, THEN make_pos_rule]
  11.337  
  11.338  (* already have this for naturals, div_mult_self1/2, but not for ints *)
  11.339 -lemma zdiv_mult_self: "m ~= (0 :: int) ==> (a + m * n) div m = a div m + n"
  11.340 +lemma zdiv_mult_self: "m \<noteq> 0 \<Longrightarrow> (a + m * n) div m = a div m + n"
  11.341 +  for a m n :: int
  11.342    apply (rule mcl)
  11.343     prefer 2
  11.344     apply (erule asm_rl)
  11.345    apply (simp add: zmde ring_distribs)
  11.346    done
  11.347  
  11.348 -lemma mod_power_lem:
  11.349 -  "a > 1 ==> a ^ n mod a ^ m = (if m <= n then 0 else (a :: int) ^ n)"
  11.350 +lemma mod_power_lem: "a > 1 \<Longrightarrow> a ^ n mod a ^ m = (if m \<le> n then 0 else a ^ n)"
  11.351 +  for a :: int
  11.352    apply clarsimp
  11.353    apply safe
  11.354     apply (simp add: dvd_eq_mod_eq_0 [symmetric])
  11.355 @@ -275,15 +289,19 @@
  11.356     apply auto
  11.357    done
  11.358  
  11.359 -lemma pl_pl_rels: 
  11.360 -  "a + b = c + d ==> 
  11.361 -   a >= c & b <= d | a <= c & b >= (d :: nat)" by arith
  11.362 +lemma pl_pl_rels: "a + b = c + d \<Longrightarrow> a \<ge> c \<and> b \<le> d \<or> a \<le> c \<and> b \<ge> d"
  11.363 +  for a b c d :: nat
  11.364 +  by arith
  11.365  
  11.366  lemmas pl_pl_rels' = add.commute [THEN [2] trans, THEN pl_pl_rels]
  11.367  
  11.368 -lemma minus_eq: "(m - k = m) = (k = 0 | m = (0 :: nat))"  by arith
  11.369 +lemma minus_eq: "m - k = m \<longleftrightarrow> k = 0 \<or> m = 0"
  11.370 +  for k m :: nat
  11.371 +  by arith
  11.372  
  11.373 -lemma pl_pl_mm: "(a :: nat) + b = c + d ==> a - c = d - b"  by arith
  11.374 +lemma pl_pl_mm: "a + b = c + d \<Longrightarrow> a - c = d - b"
  11.375 +  for a b c d :: nat
  11.376 +  by arith
  11.377  
  11.378  lemmas pl_pl_mm' = add.commute [THEN [2] trans, THEN pl_pl_mm]
  11.379  
  11.380 @@ -291,33 +309,37 @@
  11.381  lemmas dtle = xtr3 [OF dme [symmetric] le_add1]
  11.382  lemmas th2 = order_trans [OF order_refl [THEN [2] mult_le_mono] dtle]
  11.383  
  11.384 -lemma td_gal: 
  11.385 -  "0 < c ==> (a >= b * c) = (a div c >= (b :: nat))"
  11.386 +lemma td_gal: "0 < c \<Longrightarrow> a \<ge> b * c \<longleftrightarrow> a div c \<ge> b"
  11.387 +  for a b c :: nat
  11.388    apply safe
  11.389     apply (erule (1) xtr4 [OF div_le_mono div_mult_self_is_m])
  11.390    apply (erule th2)
  11.391    done
  11.392 -  
  11.393 +
  11.394  lemmas td_gal_lt = td_gal [simplified not_less [symmetric], simplified]
  11.395  
  11.396 -lemma div_mult_le: "(a :: nat) div b * b <= a"
  11.397 +lemma div_mult_le: "a div b * b \<le> a"
  11.398 +  for a b :: nat
  11.399    by (fact dtle)
  11.400  
  11.401  lemmas sdl = split_div_lemma [THEN iffD1, symmetric]
  11.402  
  11.403 -lemma given_quot: "f > (0 :: nat) ==> (f * l + (f - 1)) div f = l"
  11.404 +lemma given_quot: "f > 0 \<Longrightarrow> (f * l + (f - 1)) div f = l"
  11.405 +  for f l :: nat
  11.406    by (rule sdl, assumption) (simp (no_asm))
  11.407  
  11.408 -lemma given_quot_alt: "f > (0 :: nat) ==> (l * f + f - Suc 0) div f = l"
  11.409 +lemma given_quot_alt: "f > 0 \<Longrightarrow> (l * f + f - Suc 0) div f = l"
  11.410 +  for f l :: nat
  11.411    apply (frule given_quot)
  11.412    apply (rule trans)
  11.413     prefer 2
  11.414     apply (erule asm_rl)
  11.415 -  apply (rule_tac f="%n. n div f" in arg_cong)
  11.416 +  apply (rule_tac f="\<lambda>n. n div f" in arg_cong)
  11.417    apply (simp add : ac_simps)
  11.418    done
  11.419 -    
  11.420 -lemma diff_mod_le: "(a::nat) < d ==> b dvd d ==> a - a mod b <= d - b"
  11.421 +
  11.422 +lemma diff_mod_le: "a < d \<Longrightarrow> b dvd d \<Longrightarrow> a - a mod b \<le> d - b"
  11.423 +  for a b d :: nat
  11.424    apply (unfold dvd_def)
  11.425    apply clarify
  11.426    apply (case_tac k)
  11.427 @@ -332,57 +354,56 @@
  11.428        apply auto
  11.429    done
  11.430  
  11.431 -lemma less_le_mult':
  11.432 -  "w * c < b * c ==> 0 \<le> c ==> (w + 1) * c \<le> b * (c::int)"
  11.433 +lemma less_le_mult': "w * c < b * c \<Longrightarrow> 0 \<le> c \<Longrightarrow> (w + 1) * c \<le> b * c"
  11.434 +  for b c w :: int
  11.435    apply (rule mult_right_mono)
  11.436     apply (rule zless_imp_add1_zle)
  11.437     apply (erule (1) mult_right_less_imp_less)
  11.438    apply assumption
  11.439    done
  11.440  
  11.441 -lemma less_le_mult:
  11.442 -  "w * c < b * c \<Longrightarrow> 0 \<le> c \<Longrightarrow> w * c + c \<le> b * (c::int)"
  11.443 +lemma less_le_mult: "w * c < b * c \<Longrightarrow> 0 \<le> c \<Longrightarrow> w * c + c \<le> b * c"
  11.444 +  for b c w :: int
  11.445    using less_le_mult' [of w c b] by (simp add: algebra_simps)
  11.446  
  11.447 -lemmas less_le_mult_minus = iffD2 [OF le_diff_eq less_le_mult, 
  11.448 +lemmas less_le_mult_minus = iffD2 [OF le_diff_eq less_le_mult,
  11.449    simplified left_diff_distrib]
  11.450  
  11.451 -lemma gen_minus: "0 < n ==> f n = f (Suc (n - 1))"
  11.452 +lemma gen_minus: "0 < n \<Longrightarrow> f n = f (Suc (n - 1))"
  11.453    by auto
  11.454  
  11.455 -lemma mpl_lem: "j <= (i :: nat) ==> k < j ==> i - j + k < i" by arith
  11.456 +lemma mpl_lem: "j \<le> i \<Longrightarrow> k < j \<Longrightarrow> i - j + k < i"
  11.457 +  for i j k :: nat
  11.458 +  by arith
  11.459  
  11.460 -lemma nonneg_mod_div:
  11.461 -  "0 <= a ==> 0 <= b ==> 0 <= (a mod b :: int) & 0 <= a div b"
  11.462 -  apply (cases "b = 0", clarsimp)
  11.463 -  apply (auto intro: pos_imp_zdiv_nonneg_iff [THEN iffD2])
  11.464 -  done
  11.465 +lemma nonneg_mod_div: "0 \<le> a \<Longrightarrow> 0 \<le> b \<Longrightarrow> 0 \<le> (a mod b) \<and> 0 \<le> a div b"
  11.466 +  for a b :: int
  11.467 +  by (cases "b = 0") (auto intro: pos_imp_zdiv_nonneg_iff [THEN iffD2])
  11.468  
  11.469  declare iszero_0 [intro]
  11.470  
  11.471 -lemma min_pm [simp]:
  11.472 -  "min a b + (a - b) = (a :: nat)"
  11.473 +lemma min_pm [simp]: "min a b + (a - b) = a"
  11.474 +  for a b :: nat
  11.475    by arith
  11.476 -  
  11.477 -lemma min_pm1 [simp]:
  11.478 -  "a - b + min a b = (a :: nat)"
  11.479 +
  11.480 +lemma min_pm1 [simp]: "a - b + min a b = a"
  11.481 +  for a b :: nat
  11.482    by arith
  11.483  
  11.484 -lemma rev_min_pm [simp]:
  11.485 -  "min b a + (a - b) = (a :: nat)"
  11.486 +lemma rev_min_pm [simp]: "min b a + (a - b) = a"
  11.487 +  for a b :: nat
  11.488    by arith
  11.489  
  11.490 -lemma rev_min_pm1 [simp]:
  11.491 -  "a - b + min b a = (a :: nat)"
  11.492 +lemma rev_min_pm1 [simp]: "a - b + min b a = a"
  11.493 +  for a b :: nat
  11.494    by arith
  11.495  
  11.496 -lemma min_minus [simp]:
  11.497 -  "min m (m - k) = (m - k :: nat)"
  11.498 +lemma min_minus [simp]: "min m (m - k) = m - k"
  11.499 +  for m k :: nat
  11.500    by arith
  11.501 -  
  11.502 -lemma min_minus' [simp]:
  11.503 -  "min (m - k) m = (m - k :: nat)"
  11.504 +
  11.505 +lemma min_minus' [simp]: "min (m - k) m = m - k"
  11.506 +  for m k :: nat
  11.507    by arith
  11.508  
  11.509  end
  11.510 -
    12.1 --- a/src/Pure/General/long_name.ML	Mon Apr 03 22:18:56 2017 +0200
    12.2 +++ b/src/Pure/General/long_name.ML	Mon Apr 03 23:12:44 2017 +0200
    12.3 @@ -64,4 +64,3 @@
    12.4        in implode (nth_map (length names - 1) f names) end;
    12.5  
    12.6  end;
    12.7 -
    13.1 --- a/src/Pure/General/long_name.scala	Mon Apr 03 22:18:56 2017 +0200
    13.2 +++ b/src/Pure/General/long_name.scala	Mon Apr 03 23:12:44 2017 +0200
    13.3 @@ -25,4 +25,3 @@
    13.4      if (name == "") ""
    13.5      else explode(name).last
    13.6  }
    13.7 -
    14.1 --- a/src/Pure/PIDE/command.scala	Mon Apr 03 22:18:56 2017 +0200
    14.2 +++ b/src/Pure/PIDE/command.scala	Mon Apr 03 23:12:44 2017 +0200
    14.3 @@ -435,7 +435,7 @@
    14.4        // inlined errors
    14.5        case Thy_Header.THEORY =>
    14.6          val reader = Scan.char_reader(Token.implode(span.content))
    14.7 -        val header = resources.check_thy_reader("", node_name, reader)
    14.8 +        val header = resources.check_thy_reader(node_name, reader)
    14.9          val errors =
   14.10            for ((imp, pos) <- header.imports if !can_import(imp)) yield {
   14.11              val msg =
    15.1 --- a/src/Pure/PIDE/document.ML	Mon Apr 03 22:18:56 2017 +0200
    15.2 +++ b/src/Pure/PIDE/document.ML	Mon Apr 03 23:12:44 2017 +0200
    15.3 @@ -178,9 +178,7 @@
    15.4    | NONE => false);
    15.5  
    15.6  fun loaded_theory name =
    15.7 -  (case try (unsuffix ".thy") name of
    15.8 -    SOME a => get_first Thy_Info.lookup_theory [a, Long_Name.base_name a]
    15.9 -  | NONE => NONE);
   15.10 +  get_first Thy_Info.lookup_theory [name, Long_Name.base_name name];
   15.11  
   15.12  fun get_node nodes name = String_Graph.get_node nodes name
   15.13    handle String_Graph.UNDEF _ => empty_node;
    16.1 --- a/src/Pure/PIDE/document.scala	Mon Apr 03 22:18:56 2017 +0200
    16.2 +++ b/src/Pure/PIDE/document.scala	Mon Apr 03 23:12:44 2017 +0200
    16.3 @@ -98,6 +98,7 @@
    16.4      object Name
    16.5      {
    16.6        val empty = Name("")
    16.7 +      def theory(theory: String): Name = Name(theory, "", theory)
    16.8  
    16.9        object Ordering extends scala.math.Ordering[Name]
   16.10        {
   16.11 @@ -486,12 +487,12 @@
   16.12      def is_stable: Boolean
   16.13      def snapshot(): Snapshot
   16.14  
   16.15 -    def node_name: Document.Node.Name
   16.16 +    def node_name: Node.Name
   16.17      def is_theory: Boolean = node_name.is_theory
   16.18      override def toString: String = node_name.toString
   16.19  
   16.20      def node_required: Boolean
   16.21 -    def get_blob: Option[Document.Blob]
   16.22 +    def get_blob: Option[Blob]
   16.23  
   16.24      def node_edits(
   16.25        node_header: Node.Header,
   16.26 @@ -502,13 +503,12 @@
   16.27          get_blob match {
   16.28            case None =>
   16.29              List(
   16.30 -              Document.Node.Deps(
   16.31 -                if (session.resources.base.loaded_theories(node_name.theory))
   16.32 +              Node.Deps(
   16.33 +                if (session.resources.session_base.loaded_theory(node_name))
   16.34                    node_header.error("Cannot update finished theory " + quote(node_name.theory))
   16.35                  else node_header),
   16.36 -              Document.Node.Edits(text_edits), perspective)
   16.37 -          case Some(blob) =>
   16.38 -            List(Document.Node.Blob(blob), Document.Node.Edits(text_edits))
   16.39 +              Node.Edits(text_edits), perspective)
   16.40 +          case Some(blob) => List(Node.Blob(blob), Node.Edits(text_edits))
   16.41          }
   16.42        edits.flatMap(edit => if (edit.is_void) None else Some(node_name -> edit))
   16.43      }
    17.1 --- a/src/Pure/PIDE/resources.scala	Mon Apr 03 22:18:56 2017 +0200
    17.2 +++ b/src/Pure/PIDE/resources.scala	Mon Apr 03 23:12:44 2017 +0200
    17.3 @@ -13,26 +13,16 @@
    17.4  import java.io.{File => JFile}
    17.5  
    17.6  
    17.7 -class Resources(val base: Sessions.Base, val log: Logger = No_Logger)
    17.8 +class Resources(
    17.9 +  val session_name: String,
   17.10 +  val session_base: Sessions.Base,
   17.11 +  val log: Logger = No_Logger)
   17.12  {
   17.13    val thy_info = new Thy_Info(this)
   17.14  
   17.15    def thy_path(path: Path): Path = path.ext("thy")
   17.16  
   17.17  
   17.18 -  /* document node names */
   17.19 -
   17.20 -  def node_name(qualifier: String, raw_path: Path): Document.Node.Name =
   17.21 -  {
   17.22 -    val no_qualifier = "" // FIXME
   17.23 -    val path = raw_path.expand
   17.24 -    val node = path.implode
   17.25 -    val theory = Long_Name.qualify(no_qualifier, Thy_Header.thy_name(node).getOrElse(""))
   17.26 -    val master_dir = if (theory == "") "" else path.dir.implode
   17.27 -    Document.Node.Name(node, master_dir, theory)
   17.28 -  }
   17.29 -
   17.30 -
   17.31    /* file-system operations */
   17.32  
   17.33    def append(dir: String, source_path: Path): String =
   17.34 @@ -77,28 +67,38 @@
   17.35      }
   17.36      else Nil
   17.37  
   17.38 -  private def dummy_name(theory: String): Document.Node.Name =
   17.39 -    Document.Node.Name(theory + ".thy", "", theory)
   17.40 +  def init_name(global: Boolean, raw_path: Path): Document.Node.Name =
   17.41 +  {
   17.42 +    val path = raw_path.expand
   17.43 +    val node = path.implode
   17.44 +    val qualifier = if (global) "" else session_name
   17.45 +    val theory = Long_Name.qualify(qualifier, Thy_Header.thy_name(node).getOrElse(""))
   17.46 +    val master_dir = if (theory == "") "" else path.dir.implode
   17.47 +    Document.Node.Name(node, master_dir, theory)
   17.48 +  }
   17.49  
   17.50 -  def import_name(qualifier: String, master: Document.Node.Name, s: String): Document.Node.Name =
   17.51 +  def import_name(master: Document.Node.Name, s: String): Document.Node.Name =
   17.52    {
   17.53 -    val no_qualifier = "" // FIXME
   17.54 -    val thy1 = Thy_Header.base_name(s)
   17.55 -    val thy2 = if (Long_Name.is_qualified(thy1)) thy1 else Long_Name.qualify(no_qualifier, thy1)
   17.56 -    (base.known_theories.get(thy1) orElse
   17.57 -     base.known_theories.get(thy2) orElse
   17.58 -     base.known_theories.get(Long_Name.base_name(thy1))) match {
   17.59 -      case Some(name) if base.loaded_theories(name.theory) => dummy_name(name.theory)
   17.60 +    val theory = Thy_Header.base_name(s)
   17.61 +    val is_base_name = Thy_Header.is_base_name(s)
   17.62 +    val is_qualified = is_base_name && Long_Name.is_qualified(s)
   17.63 +
   17.64 +    val known_theory =
   17.65 +      if (is_base_name)
   17.66 +        session_base.known_theories.get(theory) orElse
   17.67 +        (if (is_qualified) session_base.known_theories.get(Long_Name.base_name(theory))
   17.68 +         else session_base.known_theories.get(Long_Name.qualify(session_name, theory)))
   17.69 +      else None
   17.70 +
   17.71 +    known_theory match {
   17.72 +      case Some(name) if session_base.loaded_theory(name) => Document.Node.Name.theory(name.theory)
   17.73        case Some(name) => name
   17.74 +      case None if is_qualified => Document.Node.Name.theory(theory)
   17.75        case None =>
   17.76          val path = Path.explode(s)
   17.77 -        val theory = path.base.implode
   17.78 -        if (Long_Name.is_qualified(theory)) dummy_name(theory)
   17.79 -        else {
   17.80 -          val node = append(master.master_dir, thy_path(path))
   17.81 -          val master_dir = append(master.master_dir, path.dir)
   17.82 -          Document.Node.Name(node, master_dir, Long_Name.qualify(no_qualifier, theory))
   17.83 -        }
   17.84 +        val node = append(master.master_dir, thy_path(path))
   17.85 +        val master_dir = append(master.master_dir, path.dir)
   17.86 +        Document.Node.Name(node, master_dir, Long_Name.qualify(session_name, theory))
   17.87      }
   17.88    }
   17.89  
   17.90 @@ -111,9 +111,8 @@
   17.91      try { f(reader) } finally { reader.close }
   17.92    }
   17.93  
   17.94 -  def check_thy_reader(qualifier: String, node_name: Document.Node.Name,
   17.95 -      reader: Reader[Char], start: Token.Pos = Token.Pos.command, strict: Boolean = true)
   17.96 -    : Document.Node.Header =
   17.97 +  def check_thy_reader(node_name: Document.Node.Name, reader: Reader[Char],
   17.98 +    start: Token.Pos = Token.Pos.command, strict: Boolean = true): Document.Node.Header =
   17.99    {
  17.100      if (node_name.is_theory && reader.source.length > 0) {
  17.101        try {
  17.102 @@ -127,7 +126,7 @@
  17.103              Completion.report_names(pos, 1, List((base_name, ("theory", base_name)))))
  17.104  
  17.105          val imports =
  17.106 -          header.imports.map({ case (s, pos) => (import_name(qualifier, node_name, s), pos) })
  17.107 +          header.imports.map({ case (s, pos) => (import_name(node_name, s), pos) })
  17.108          Document.Node.Header(imports, header.keywords, header.abbrevs)
  17.109        }
  17.110        catch { case exn: Throwable => Document.Node.bad_header(Exn.message(exn)) }
  17.111 @@ -135,18 +134,18 @@
  17.112      else Document.Node.no_header
  17.113    }
  17.114  
  17.115 -  def check_thy(qualifier: String, name: Document.Node.Name,
  17.116 -      start: Token.Pos = Token.Pos.command, strict: Boolean = true): Document.Node.Header =
  17.117 -    with_thy_reader(name, check_thy_reader(qualifier, name, _, start, strict))
  17.118 +  def check_thy(name: Document.Node.Name, start: Token.Pos = Token.Pos.command,
  17.119 +      strict: Boolean = true): Document.Node.Header =
  17.120 +    with_thy_reader(name, check_thy_reader(name, _, start, strict))
  17.121  
  17.122  
  17.123    /* special header */
  17.124  
  17.125    def special_header(name: Document.Node.Name): Option[Document.Node.Header] =
  17.126      if (Thy_Header.is_ml_root(name.theory))
  17.127 -      Some(Document.Node.Header(List((import_name("", name, Thy_Header.ML_BOOTSTRAP), Position.none))))
  17.128 +      Some(Document.Node.Header(List((import_name(name, Thy_Header.ML_BOOTSTRAP), Position.none))))
  17.129      else if (Thy_Header.is_bootstrap(name.theory))
  17.130 -      Some(Document.Node.Header(List((import_name("", name, Thy_Header.PURE), Position.none))))
  17.131 +      Some(Document.Node.Header(List((import_name(name, Thy_Header.PURE), Position.none))))
  17.132      else None
  17.133  
  17.134  
  17.135 @@ -155,7 +154,7 @@
  17.136    def undefined_blobs(nodes: Document.Nodes): List[Document.Node.Name] =
  17.137      (for {
  17.138        (node_name, node) <- nodes.iterator
  17.139 -      if !base.loaded_theories(node_name.theory)
  17.140 +      if !session_base.loaded_theory(node_name)
  17.141        cmd <- node.load_commands.iterator
  17.142        name <- cmd.blobs_undefined.iterator
  17.143      } yield name).toList
    18.1 --- a/src/Pure/PIDE/session.scala	Mon Apr 03 22:18:56 2017 +0200
    18.2 +++ b/src/Pure/PIDE/session.scala	Mon Apr 03 23:12:44 2017 +0200
    18.3 @@ -191,7 +191,7 @@
    18.4  
    18.5    def recent_syntax(name: Document.Node.Name): Outer_Syntax =
    18.6      global_state.value.recent_finished.version.get_finished.nodes(name).syntax getOrElse
    18.7 -    resources.base.syntax
    18.8 +    resources.session_base.syntax
    18.9  
   18.10  
   18.11    /* pipelined change parsing */
    19.1 --- a/src/Pure/Thy/sessions.scala	Mon Apr 03 22:18:56 2017 +0200
    19.2 +++ b/src/Pure/Thy/sessions.scala	Mon Apr 03 23:12:44 2017 +0200
    19.3 @@ -17,25 +17,14 @@
    19.4  
    19.5  object Sessions
    19.6  {
    19.7 -  /* Pure */
    19.8 -
    19.9 -  def pure_name(name: String): Boolean = name == Thy_Header.PURE
   19.10 +  /* base info and source dependencies */
   19.11  
   19.12 -  def pure_files(resources: Resources, syntax: Outer_Syntax, dir: Path): List[Path] =
   19.13 -  {
   19.14 -    val roots = Thy_Header.ml_roots.map(_._1)
   19.15 -    val loaded_files =
   19.16 -      roots.flatMap(root => resources.loaded_files(syntax, File.read(dir + Path.explode(root))))
   19.17 -    (roots ::: loaded_files).map(file => dir + Path.explode(file))
   19.18 -  }
   19.19 -
   19.20 -  def pure_base(options: Options): Base = session_base(options, Thy_Header.PURE)
   19.21 -
   19.22 -
   19.23 -  /* base info and source dependencies */
   19.24 +  def is_pure(name: String): Boolean = name == Thy_Header.PURE
   19.25  
   19.26    object Base
   19.27    {
   19.28 +    def pure(options: Options): Base = session_base(options, Thy_Header.PURE)
   19.29 +
   19.30      lazy val bootstrap: Base =
   19.31        Base(keywords = Thy_Header.bootstrap_header, syntax = Thy_Header.bootstrap_syntax)
   19.32    }
   19.33 @@ -47,6 +36,10 @@
   19.34      syntax: Outer_Syntax = Outer_Syntax.empty,
   19.35      sources: List[(Path, SHA1.Digest)] = Nil,
   19.36      session_graph: Graph_Display.Graph = Graph_Display.empty_graph)
   19.37 +  {
   19.38 +    def loaded_theory(name: Document.Node.Name): Boolean =
   19.39 +      loaded_theories.contains(name.theory)
   19.40 +  }
   19.41  
   19.42    sealed case class Deps(deps: Map[String, Base])
   19.43    {
   19.44 @@ -67,12 +60,12 @@
   19.45            if (progress.stopped) throw Exn.Interrupt()
   19.46  
   19.47            try {
   19.48 -            val resources =
   19.49 -              new Resources(
   19.50 -                info.parent match {
   19.51 -                  case None => Base.bootstrap
   19.52 -                  case Some(parent) => deps(parent)
   19.53 -                })
   19.54 +            val parent_base =
   19.55 +              info.parent match {
   19.56 +                case None => Base.bootstrap
   19.57 +                case Some(parent) => deps(parent)
   19.58 +              }
   19.59 +            val resources = new Resources(name, parent_base)
   19.60  
   19.61              if (verbose || list_files) {
   19.62                val groups =
   19.63 @@ -87,10 +80,9 @@
   19.64                  info.theories.flatMap({
   19.65                    case (global, _, thys) =>
   19.66                      thys.map(thy =>
   19.67 -                      (resources.node_name(
   19.68 -                        if (global) "" else name, info.dir + resources.thy_path(thy)), info.pos))
   19.69 +                      (resources.init_name(global, info.dir + resources.thy_path(thy)), info.pos))
   19.70                  })
   19.71 -              val thy_deps = resources.thy_info.dependencies(name, root_theories)
   19.72 +              val thy_deps = resources.thy_info.dependencies(root_theories)
   19.73  
   19.74                thy_deps.errors match {
   19.75                  case Nil => thy_deps
   19.76 @@ -99,7 +91,7 @@
   19.77              }
   19.78  
   19.79              val known_theories =
   19.80 -              (resources.base.known_theories /: thy_deps.deps)({ case (known, dep) =>
   19.81 +              (parent_base.known_theories /: thy_deps.deps)({ case (known, dep) =>
   19.82                  val name = dep.name
   19.83                  known.get(name.theory) match {
   19.84                    case Some(name1) if name != name1 =>
   19.85 @@ -117,7 +109,13 @@
   19.86              val loaded_files =
   19.87                if (inlined_files) {
   19.88                  val pure_files =
   19.89 -                  if (pure_name(name)) Sessions.pure_files(resources, syntax, info.dir)
   19.90 +                  if (is_pure(name)) {
   19.91 +                    val roots = Thy_Header.ml_roots.map(p => info.dir + Path.explode(p._1))
   19.92 +                    val files =
   19.93 +                      roots.flatMap(root => resources.loaded_files(syntax, File.read(root))).
   19.94 +                        map(file => info.dir + Path.explode(file))
   19.95 +                    roots ::: files
   19.96 +                  }
   19.97                    else Nil
   19.98                  pure_files ::: thy_deps.loaded_files
   19.99                }
  19.100 @@ -138,7 +136,7 @@
  19.101  
  19.102              val session_graph =
  19.103                Present.session_graph(info.parent getOrElse "",
  19.104 -                resources.base.loaded_theories, thy_deps.deps)
  19.105 +                parent_base.loaded_theories, thy_deps.deps)
  19.106  
  19.107              val base =
  19.108                Base(loaded_theories, known_theories, keywords, syntax, sources, session_graph)
  19.109 @@ -365,8 +363,8 @@
  19.110            val name = entry.name
  19.111  
  19.112            if (name == "") error("Bad session name")
  19.113 -          if (pure_name(name) && entry.parent.isDefined) error("Illegal parent session")
  19.114 -          if (!pure_name(name) && !entry.parent.isDefined) error("Missing parent session")
  19.115 +          if (is_pure(name) && entry.parent.isDefined) error("Illegal parent session")
  19.116 +          if (!is_pure(name) && !entry.parent.isDefined) error("Missing parent session")
  19.117  
  19.118            val session_options = options ++ entry.options
  19.119  
    20.1 --- a/src/Pure/Thy/thy_header.scala	Mon Apr 03 22:18:56 2017 +0200
    20.2 +++ b/src/Pure/Thy/thy_header.scala	Mon Apr 03 23:12:44 2017 +0200
    20.3 @@ -80,6 +80,9 @@
    20.4    private val Base_Name = new Regex(""".*?([^/\\:]+)""")
    20.5    private val Thy_Name = new Regex(""".*?([^/\\:]+)\.thy""")
    20.6  
    20.7 +  def is_base_name(s: String): Boolean =
    20.8 +    s != "" && !s.exists("/\\:".contains(_))
    20.9 +
   20.10    def base_name(s: String): String =
   20.11      s match { case Base_Name(name) => name case _ => error("Malformed import: " + quote(s)) }
   20.12  
    21.1 --- a/src/Pure/Thy/thy_info.scala	Mon Apr 03 22:18:56 2017 +0200
    21.2 +++ b/src/Pure/Thy/thy_info.scala	Mon Apr 03 23:12:44 2017 +0200
    21.3 @@ -71,7 +71,7 @@
    21.4        val import_errors =
    21.5          (for {
    21.6            (theory, names) <- seen_names.iterator_list
    21.7 -          if !resources.base.loaded_theories(theory)
    21.8 +          if !resources.session_base.loaded_theories(theory)
    21.9            if names.length > 1
   21.10          } yield
   21.11            "Incoherent imports for theory " + quote(theory) + ":\n" +
   21.12 @@ -83,10 +83,12 @@
   21.13      }
   21.14  
   21.15      lazy val syntax: Outer_Syntax =
   21.16 -      resources.base.syntax.add_keywords(keywords).add_abbrevs(abbrevs)
   21.17 +      resources.session_base.syntax.add_keywords(keywords).add_abbrevs(abbrevs)
   21.18  
   21.19      def loaded_theories: Set[String] =
   21.20 -      (resources.base.loaded_theories /: rev_deps) { case (loaded, dep) => loaded + dep.name.theory }
   21.21 +      (resources.session_base.loaded_theories /: rev_deps) {
   21.22 +        case (loaded, dep) => loaded + dep.name.theory
   21.23 +      }
   21.24  
   21.25      def loaded_files: List[Path] =
   21.26      {
   21.27 @@ -104,12 +106,12 @@
   21.28      override def toString: String = deps.toString
   21.29    }
   21.30  
   21.31 -  private def require_thys(session: String, initiators: List[Document.Node.Name],
   21.32 -      required: Dependencies, thys: List[(Document.Node.Name, Position.T)]): Dependencies =
   21.33 -    (required /: thys)(require_thy(session, initiators, _, _))
   21.34 +  private def require_thys(initiators: List[Document.Node.Name], required: Dependencies,
   21.35 +      thys: List[(Document.Node.Name, Position.T)]): Dependencies =
   21.36 +    (required /: thys)(require_thy(initiators, _, _))
   21.37  
   21.38 -  private def require_thy(session: String, initiators: List[Document.Node.Name],
   21.39 -      required: Dependencies, thy: (Document.Node.Name, Position.T)): Dependencies =
   21.40 +  private def require_thy(initiators: List[Document.Node.Name], required: Dependencies,
   21.41 +    thy: (Document.Node.Name, Position.T)): Dependencies =
   21.42    {
   21.43      val (name, require_pos) = thy
   21.44  
   21.45 @@ -118,15 +120,14 @@
   21.46          required_by(initiators) + Position.here(require_pos)
   21.47  
   21.48      val required1 = required + thy
   21.49 -    if (required.seen(name) || resources.base.loaded_theories(name.theory)) required1
   21.50 +    if (required.seen(name) || resources.session_base.loaded_theory(name)) required1
   21.51      else {
   21.52        try {
   21.53          if (initiators.contains(name)) error(cycle_msg(initiators))
   21.54          val header =
   21.55 -          try { resources.check_thy(session, name, Token.Pos.file(name.node)).cat_errors(message) }
   21.56 +          try { resources.check_thy(name, Token.Pos.file(name.node)).cat_errors(message) }
   21.57            catch { case ERROR(msg) => cat_error(msg, message) }
   21.58 -        Thy_Info.Dep(name, header) ::
   21.59 -          require_thys(session, name :: initiators, required1, header.imports)
   21.60 +        Thy_Info.Dep(name, header) :: require_thys(name :: initiators, required1, header.imports)
   21.61        }
   21.62        catch {
   21.63          case e: Throwable =>
   21.64 @@ -135,6 +136,6 @@
   21.65      }
   21.66    }
   21.67  
   21.68 -  def dependencies(session: String, thys: List[(Document.Node.Name, Position.T)]): Dependencies =
   21.69 -    require_thys(session, Nil, Dependencies.empty, thys)
   21.70 +  def dependencies(thys: List[(Document.Node.Name, Position.T)]): Dependencies =
   21.71 +    require_thys(Nil, Dependencies.empty, thys)
   21.72  }
    22.1 --- a/src/Pure/Thy/thy_syntax.scala	Mon Apr 03 22:18:56 2017 +0200
    22.2 +++ b/src/Pure/Thy/thy_syntax.scala	Mon Apr 03 23:12:44 2017 +0200
    22.3 @@ -101,7 +101,7 @@
    22.4          else {
    22.5            val header = node.header
    22.6            val imports_syntax = header.imports.flatMap(a => nodes(a._1).syntax)
    22.7 -          Some((resources.base.syntax /: imports_syntax)(_ ++ _)
    22.8 +          Some((resources.session_base.syntax /: imports_syntax)(_ ++ _)
    22.9              .add_keywords(header.keywords).add_abbrevs(header.abbrevs))
   22.10          }
   22.11        nodes += (name -> node.update_syntax(syntax))
   22.12 @@ -300,7 +300,7 @@
   22.13        doc_blobs.get(name) orElse previous.nodes(name).get_blob
   22.14  
   22.15      def can_import(name: Document.Node.Name): Boolean =
   22.16 -      resources.base.loaded_theories(name.theory) || nodes0(name).has_header
   22.17 +      resources.session_base.loaded_theory(name) || nodes0(name).has_header
   22.18  
   22.19      val (doc_edits, version) =
   22.20        if (edits.isEmpty) (Nil, Document.Version.make(previous.nodes))
   22.21 @@ -324,7 +324,7 @@
   22.22          node_edits foreach {
   22.23            case (name, edits) =>
   22.24              val node = nodes(name)
   22.25 -            val syntax = node.syntax getOrElse resources.base.syntax
   22.26 +            val syntax = node.syntax getOrElse resources.session_base.syntax
   22.27              val commands = node.commands
   22.28  
   22.29              val node1 =
    23.1 --- a/src/Pure/Tools/build.scala	Mon Apr 03 22:18:56 2017 +0200
    23.2 +++ b/src/Pure/Tools/build.scala	Mon Apr 03 23:12:44 2017 +0200
    23.3 @@ -219,8 +219,8 @@
    23.4            "ML_Heap.share_common_data (); ML_Heap.save_child " +
    23.5              ML_Syntax.print_string0(File.platform_path(output))
    23.6  
    23.7 -        if (pide && !Sessions.pure_name(name)) {
    23.8 -          val resources = new Resources(deps(parent))
    23.9 +        if (pide && !Sessions.is_pure(name)) {
   23.10 +          val resources = new Resources(name, deps(parent))
   23.11            val session = new Session(options, resources)
   23.12            val handler = new Handler(progress, session, name)
   23.13            session.init_protocol_handler(handler)
   23.14 @@ -255,7 +255,7 @@
   23.15              (if (do_output) "; " + save_heap else "") + "));"
   23.16  
   23.17            val process =
   23.18 -            if (Sessions.pure_name(name)) {
   23.19 +            if (Sessions.is_pure(name)) {
   23.20                ML_Process(options, raw_ml_system = true, cwd = info.dir.file,
   23.21                  args =
   23.22                    (for ((root, _) <- Thy_Header.ml_roots) yield List("--use", root)).flatten :::
   23.23 @@ -519,7 +519,7 @@
   23.24                  val ancestor_results = selected_tree.ancestors(name).map(results(_))
   23.25                  val ancestor_heaps = ancestor_results.flatMap(_.heap_stamp)
   23.26  
   23.27 -                val do_output = build_heap || Sessions.pure_name(name) || queue.is_inner(name)
   23.28 +                val do_output = build_heap || Sessions.is_pure(name) || queue.is_inner(name)
   23.29  
   23.30                  val (current, heap_stamp) =
   23.31                  {
    24.1 --- a/src/Tools/VSCode/src/document_model.scala	Mon Apr 03 22:18:56 2017 +0200
    24.2 +++ b/src/Tools/VSCode/src/document_model.scala	Mon Apr 03 23:12:44 2017 +0200
    24.3 @@ -73,7 +73,7 @@
    24.4  
    24.5    def node_header: Document.Node.Header =
    24.6      resources.special_header(node_name) getOrElse
    24.7 -      resources.check_thy_reader("", node_name, Scan.char_reader(content.text))
    24.8 +      resources.check_thy_reader(node_name, Scan.char_reader(content.text))
    24.9  
   24.10  
   24.11    /* perspective */
    25.1 --- a/src/Tools/VSCode/src/server.scala	Mon Apr 03 22:18:56 2017 +0200
    25.2 +++ b/src/Tools/VSCode/src/server.scala	Mon Apr 03 23:12:44 2017 +0200
    25.3 @@ -225,8 +225,8 @@
    25.4            }
    25.5          }
    25.6  
    25.7 -        val base = Sessions.session_base(options, session_name, session_dirs)
    25.8 -        val resources = new VSCode_Resources(options, base, log)
    25.9 +        val session_base = Sessions.session_base(options, session_name, session_dirs)
   25.10 +        val resources = new VSCode_Resources(options, session_base, log)
   25.11            {
   25.12              override def commit(change: Session.Change): Unit =
   25.13                if (change.deps_changed || undefined_blobs(change.version.nodes).nonEmpty)
    26.1 --- a/src/Tools/VSCode/src/vscode_resources.scala	Mon Apr 03 22:18:56 2017 +0200
    26.2 +++ b/src/Tools/VSCode/src/vscode_resources.scala	Mon Apr 03 23:12:44 2017 +0200
    26.3 @@ -40,9 +40,10 @@
    26.4  }
    26.5  
    26.6  class VSCode_Resources(
    26.7 -  val options: Options,
    26.8 -  base: Sessions.Base,
    26.9 -  log: Logger = No_Logger) extends Resources(base, log)
   26.10 +    val options: Options,
   26.11 +    session_base: Sessions.Base,
   26.12 +    log: Logger = No_Logger)
   26.13 +  extends Resources(session_name = "", session_base, log)
   26.14  {
   26.15    private val state = Synchronized(VSCode_Resources.State())
   26.16  
   26.17 @@ -165,7 +166,7 @@
   26.18            (for ((_, model) <- st.models.iterator if model.is_theory)
   26.19             yield (model.node_name, Position.none)).toList
   26.20  
   26.21 -        val thy_files = thy_info.dependencies("", thys).deps.map(_.name)
   26.22 +        val thy_files = thy_info.dependencies(thys).deps.map(_.name)
   26.23  
   26.24  
   26.25          /* auxiliary files */
    27.1 --- a/src/Tools/jEdit/src/document_model.scala	Mon Apr 03 22:18:56 2017 +0200
    27.2 +++ b/src/Tools/jEdit/src/document_model.scala	Mon Apr 03 23:12:44 2017 +0200
    27.3 @@ -235,7 +235,7 @@
    27.4                val pending_nodes = for ((node_name, None) <- purged) yield node_name
    27.5                (open_nodes ::: touched_nodes ::: pending_nodes).map((_, Position.none))
    27.6              }
    27.7 -            val retain = PIDE.resources.thy_info.dependencies("", imports).deps.map(_.name).toSet
    27.8 +            val retain = PIDE.resources.thy_info.dependencies(imports).deps.map(_.name).toSet
    27.9  
   27.10              for ((node_name, Some(edits)) <- purged; if !retain(node_name); edit <- edits)
   27.11                yield edit
   27.12 @@ -331,7 +331,7 @@
   27.13  
   27.14    def node_header: Document.Node.Header =
   27.15      PIDE.resources.special_header(node_name) getOrElse
   27.16 -      PIDE.resources.check_thy_reader("", node_name, Scan.char_reader(content.text), strict = false)
   27.17 +      PIDE.resources.check_thy_reader(node_name, Scan.char_reader(content.text), strict = false)
   27.18  
   27.19  
   27.20    /* content */
   27.21 @@ -396,8 +396,7 @@
   27.22  
   27.23      PIDE.resources.special_header(node_name) getOrElse
   27.24        JEdit_Lib.buffer_lock(buffer) {
   27.25 -        PIDE.resources.check_thy_reader(
   27.26 -          "", node_name, JEdit_Lib.buffer_reader(buffer), strict = false)
   27.27 +        PIDE.resources.check_thy_reader(node_name, JEdit_Lib.buffer_reader(buffer), strict = false)
   27.28        }
   27.29    }
   27.30  
    28.1 --- a/src/Tools/jEdit/src/isabelle.scala	Mon Apr 03 22:18:56 2017 +0200
    28.2 +++ b/src/Tools/jEdit/src/isabelle.scala	Mon Apr 03 23:12:44 2017 +0200
    28.3 @@ -50,7 +50,7 @@
    28.4  
    28.5    def mode_syntax(mode: String): Option[Outer_Syntax] =
    28.6      mode match {
    28.7 -      case "isabelle" => Some(PIDE.resources.base.syntax)
    28.8 +      case "isabelle" => Some(PIDE.resources.session_base.syntax)
    28.9        case "isabelle-options" => Some(Options.options_syntax)
   28.10        case "isabelle-root" => Some(Sessions.root_syntax)
   28.11        case "isabelle-ml" => Some(ml_syntax)
    29.1 --- a/src/Tools/jEdit/src/jedit_resources.scala	Mon Apr 03 22:18:56 2017 +0200
    29.2 +++ b/src/Tools/jEdit/src/jedit_resources.scala	Mon Apr 03 23:12:44 2017 +0200
    29.3 @@ -21,7 +21,8 @@
    29.4  import org.gjt.sp.jedit.bufferio.BufferIORequest
    29.5  
    29.6  
    29.7 -class JEdit_Resources(base: Sessions.Base) extends Resources(base)
    29.8 +class JEdit_Resources(session_base: Sessions.Base)
    29.9 +  extends Resources(session_name = "", session_base)
   29.10  {
   29.11    /* document node name */
   29.12  
    30.1 --- a/src/Tools/jEdit/src/plugin.scala	Mon Apr 03 22:18:56 2017 +0200
    30.2 +++ b/src/Tools/jEdit/src/plugin.scala	Mon Apr 03 23:12:44 2017 +0200
    30.3 @@ -74,7 +74,7 @@
    30.4      val session_name = JEdit_Sessions.session_name(options)
    30.5      val session_base =
    30.6        try { Sessions.session_base(options, session_name, JEdit_Sessions.session_dirs()) }
    30.7 -      catch { case ERROR(_) => Sessions.pure_base(options) }
    30.8 +      catch { case ERROR(_) => Sessions.Base.pure(options) }
    30.9  
   30.10      _resources =
   30.11        new JEdit_Resources(session_base.copy(known_theories =
   30.12 @@ -135,7 +135,7 @@
   30.13            val thys =
   30.14              (for ((node_name, model) <- models.iterator if model.is_theory)
   30.15                yield (node_name, Position.none)).toList
   30.16 -          val thy_files = resources.thy_info.dependencies("", thys).deps.map(_.name)
   30.17 +          val thy_files = resources.thy_info.dependencies(thys).deps.map(_.name)
   30.18  
   30.19            val aux_files =
   30.20              if (options.bool("jedit_auto_resolve")) {
    31.1 --- a/src/Tools/jEdit/src/theories_dockable.scala	Mon Apr 03 22:18:56 2017 +0200
    31.2 +++ b/src/Tools/jEdit/src/theories_dockable.scala	Mon Apr 03 23:12:44 2017 +0200
    31.3 @@ -192,7 +192,7 @@
    31.4        }
    31.5      val nodes_status1 =
    31.6        (nodes_status /: iterator)({ case (status, (name, node)) =>
    31.7 -          if (!name.is_theory || PIDE.resources.base.loaded_theories(name.theory) || node.is_empty)
    31.8 +          if (!name.is_theory || PIDE.resources.session_base.loaded_theory(name) || node.is_empty)
    31.9              status
   31.10            else status + (name -> Protocol.node_status(snapshot.state, snapshot.version, node)) })
   31.11  
    32.1 --- a/src/Tools/jEdit/src/timing_dockable.scala	Mon Apr 03 22:18:56 2017 +0200
    32.2 +++ b/src/Tools/jEdit/src/timing_dockable.scala	Mon Apr 03 23:12:44 2017 +0200
    32.3 @@ -187,7 +187,7 @@
    32.4        }
    32.5      val nodes_timing1 =
    32.6        (nodes_timing /: iterator)({ case (timing1, (name, node)) =>
    32.7 -          if (PIDE.resources.base.loaded_theories(name.theory)) timing1
    32.8 +          if (PIDE.resources.session_base.loaded_theory(name)) timing1
    32.9            else {
   32.10              val node_timing =
   32.11                Protocol.node_timing(snapshot.state, snapshot.version, node, timing_threshold)