[STATEMENT]
lemma bin_cat_zero [simp]: "(\<lambda>k n l. concat_bit n l k) 0 n w = (take_bit :: nat \<Rightarrow> int \<Rightarrow> int) n w"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. concat_bit n w 0 = take_bit n w
[PROOF STEP]
by (simp add: bin_cat_eq_push_bit_add_take_bit)


[STATEMENT]
lemma bintr_cat1: "(take_bit :: nat \<Rightarrow> int \<Rightarrow> int) (k + n) ((\<lambda>k n l. concat_bit n l k) a n b) = (\<lambda>k n l. concat_bit n l k) ((take_bit :: nat \<Rightarrow> int \<Rightarrow> int) k a) n b"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. take_bit (k + n) (concat_bit n b a) = concat_bit n b (take_bit k a)
[PROOF STEP]
by (metis bin_cat_assoc bin_cat_zero)


[STATEMENT]
lemma bintr_cat: "(take_bit :: nat \<Rightarrow> int \<Rightarrow> int) m ((\<lambda>k n l. concat_bit n l k) a n b) =
    (\<lambda>k n l. concat_bit n l k) ((take_bit :: nat \<Rightarrow> int \<Rightarrow> int) (m - n) a) n ((take_bit :: nat \<Rightarrow> int \<Rightarrow> int) (min m n) b)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. take_bit m (concat_bit n b a) = concat_bit n (take_bit (min m n) b) (take_bit (m - n) a)
[PROOF STEP]
by (rule bin_eqI) (auto simp: bin_nth_cat nth_bintr)


[STATEMENT]
lemma bintr_cat_same [simp]: "(take_bit :: nat \<Rightarrow> int \<Rightarrow> int) n ((\<lambda>k n l. concat_bit n l k) a n b) = (take_bit :: nat \<Rightarrow> int \<Rightarrow> int) n b"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. take_bit n (concat_bit n b a) = take_bit n b
[PROOF STEP]
by (auto simp add : bintr_cat)


[STATEMENT]
lemma cat_bintr [simp]: "(\<lambda>k n l. concat_bit n l k) a n ((take_bit :: nat \<Rightarrow> int \<Rightarrow> int) n b) = (\<lambda>k n l. concat_bit n l k) a n b"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. concat_bit n (take_bit n b) a = concat_bit n b a
[PROOF STEP]
by (simp add: bin_cat_eq_push_bit_add_take_bit)


[STATEMENT]
lemma split_bintrunc: "bin_split n c = (a, b) \<Longrightarrow> b = (take_bit :: nat \<Rightarrow> int \<Rightarrow> int) n c"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. bin_split n c = (a, b) \<Longrightarrow> b = take_bit n c
[PROOF STEP]
by simp


[STATEMENT]
lemma bin_cat_split: "bin_split n w = (u, v) \<Longrightarrow> w = (\<lambda>k n l. concat_bit n l k) u n v"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. bin_split n w = (u, v) \<Longrightarrow> w = concat_bit n v u
[PROOF STEP]
by (auto simp add: bin_cat_eq_push_bit_add_take_bit bits_ident)


[STATEMENT]
lemma drop_bit_bin_cat_eq:
  \<open>drop_bit n ((\<lambda>k n l. concat_bit n l k) v n w) = v\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. drop_bit n (concat_bit n w v) = v
[PROOF STEP]
by (rule bit_eqI) (simp add: bit_drop_bit_eq bit_concat_bit_iff)


[STATEMENT]
lemma take_bit_bin_cat_eq:
  \<open>take_bit n ((\<lambda>k n l. concat_bit n l k) v n w) = take_bit n w\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. take_bit n (concat_bit n w v) = take_bit n w
[PROOF STEP]
by (rule bit_eqI) (simp add: bit_concat_bit_iff)


[STATEMENT]
lemma bin_split_cat: "bin_split n ((\<lambda>k n l. concat_bit n l k) v n w) = (v, (take_bit :: nat \<Rightarrow> int \<Rightarrow> int) n w)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. bin_split n (concat_bit n w v) = (v, take_bit n w)
[PROOF STEP]
by (simp add: drop_bit_bin_cat_eq take_bit_bin_cat_eq)


[STATEMENT]
lemma bin_split_zero [simp]: "bin_split n 0 = (0, 0)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. bin_split n 0 = (0, 0)
[PROOF STEP]
by simp


[STATEMENT]
lemma bin_split_minus1 [simp]:
  "bin_split n (- 1) = (- 1, (take_bit :: nat \<Rightarrow> int \<Rightarrow> int) n (- 1))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. bin_split n (- 1) = (- 1, take_bit n (- 1))
[PROOF STEP]
by simp


[STATEMENT]
lemma bin_split_trunc:
  "bin_split (min m n) c = (a, b) \<Longrightarrow>
    bin_split n ((take_bit :: nat \<Rightarrow> int \<Rightarrow> int) m c) = ((take_bit :: nat \<Rightarrow> int \<Rightarrow> int) (m - n) a, b)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. bin_split (min m n) c = (a, b) \<Longrightarrow> bin_split n (take_bit m c) = (take_bit (m - n) a, b)
[PROOF STEP]
apply (induct n arbitrary: m b c, clarsimp)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>n m b c. \<lbrakk>\<And>m b c. bin_split (min m n) c = (a, b) \<Longrightarrow> bin_split n (take_bit m c) = (take_bit (m - n) a, b); bin_split (min m (Suc n)) c = (a, b)\<rbrakk> \<Longrightarrow> bin_split (Suc n) (take_bit m c) = (take_bit (m - Suc n) a, b)
[PROOF STEP]
apply (simp add: bin_rest_trunc Let_def split: prod.split_asm)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>n m c. \<lbrakk>\<And>m c. drop_bit (min m n) c = a \<Longrightarrow> drop_bit n (take_bit m c) = take_bit (m - n) a \<and> take_bit (min n m) c = take_bit (min m n) c; drop_bit (min m (Suc n)) c = a\<rbrakk> \<Longrightarrow> drop_bit (Suc n) (take_bit m c) = take_bit (m - Suc n) a \<and> take_bit (min (Suc n) m) c = take_bit (min m (Suc n)) c
[PROOF STEP]
apply (case_tac m)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. \<And>n m c. \<lbrakk>\<And>m c. drop_bit (min m n) c = a \<Longrightarrow> drop_bit n (take_bit m c) = take_bit (m - n) a \<and> take_bit (min n m) c = take_bit (min m n) c; drop_bit (min m (Suc n)) c = a; m = 0\<rbrakk> \<Longrightarrow> drop_bit (Suc n) (take_bit m c) = take_bit (m - Suc n) a \<and> take_bit (min (Suc n) m) c = take_bit (min m (Suc n)) c
 2. \<And>n m c nat. \<lbrakk>\<And>m c. drop_bit (min m n) c = a \<Longrightarrow> drop_bit n (take_bit m c) = take_bit (m - n) a \<and> take_bit (min n m) c = take_bit (min m n) c; drop_bit (min m (Suc n)) c = a; m = Suc nat\<rbrakk> \<Longrightarrow> drop_bit (Suc n) (take_bit m c) = take_bit (m - Suc n) a \<and> take_bit (min (Suc n) m) c = take_bit (min m (Suc n)) c
[PROOF STEP]
apply (auto simp: Let_def drop_bit_Suc take_bit_Suc mod_2_eq_odd split: prod.split_asm)
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done


[STATEMENT]
lemma bin_split_trunc1:
  "bin_split n c = (a, b) \<Longrightarrow>
    bin_split n ((take_bit :: nat \<Rightarrow> int \<Rightarrow> int) m c) = ((take_bit :: nat \<Rightarrow> int \<Rightarrow> int) (m - n) a, (take_bit :: nat \<Rightarrow> int \<Rightarrow> int) m b)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. bin_split n c = (a, b) \<Longrightarrow> bin_split n (take_bit m c) = (take_bit (m - n) a, take_bit m b)
[PROOF STEP]
apply (induct n arbitrary: m b c, clarsimp)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>n m b c. \<lbrakk>\<And>m b c. bin_split n c = (a, b) \<Longrightarrow> bin_split n (take_bit m c) = (take_bit (m - n) a, take_bit m b); bin_split (Suc n) c = (a, b)\<rbrakk> \<Longrightarrow> bin_split (Suc n) (take_bit m c) = (take_bit (m - Suc n) a, take_bit m b)
[PROOF STEP]
apply (simp add: bin_rest_trunc Let_def split: prod.split_asm)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>n m c. \<lbrakk>\<And>m c. drop_bit n c = a \<Longrightarrow> drop_bit n (take_bit m c) = take_bit (m - n) a \<and> take_bit (min n m) c = take_bit (min m n) c; drop_bit (Suc n) c = a\<rbrakk> \<Longrightarrow> drop_bit (Suc n) (take_bit m c) = take_bit (m - Suc n) a \<and> take_bit (min (Suc n) m) c = take_bit (min m (Suc n)) c
[PROOF STEP]
apply (case_tac m)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. \<And>n m c. \<lbrakk>\<And>m c. drop_bit n c = a \<Longrightarrow> drop_bit n (take_bit m c) = take_bit (m - n) a \<and> take_bit (min n m) c = take_bit (min m n) c; drop_bit (Suc n) c = a; m = 0\<rbrakk> \<Longrightarrow> drop_bit (Suc n) (take_bit m c) = take_bit (m - Suc n) a \<and> take_bit (min (Suc n) m) c = take_bit (min m (Suc n)) c
 2. \<And>n m c nat. \<lbrakk>\<And>m c. drop_bit n c = a \<Longrightarrow> drop_bit n (take_bit m c) = take_bit (m - n) a \<and> take_bit (min n m) c = take_bit (min m n) c; drop_bit (Suc n) c = a; m = Suc nat\<rbrakk> \<Longrightarrow> drop_bit (Suc n) (take_bit m c) = take_bit (m - Suc n) a \<and> take_bit (min (Suc n) m) c = take_bit (min m (Suc n)) c
[PROOF STEP]
apply (auto simp: Let_def drop_bit_Suc take_bit_Suc mod_2_eq_odd split: prod.split_asm)
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done


[STATEMENT]
lemma bin_cat_num: "(\<lambda>k n l. concat_bit n l k) a n b = a * 2 ^ n + (take_bit :: nat \<Rightarrow> int \<Rightarrow> int) n b"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. concat_bit n b a = a * 2 ^ n + take_bit n b
[PROOF STEP]
by (simp add: bin_cat_eq_push_bit_add_take_bit push_bit_eq_mult)


[STATEMENT]
lemma bin_split_num: "bin_split n b = (b div 2 ^ n, b mod 2 ^ n)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. bin_split n b = (b div 2 ^ n, b mod 2 ^ n)
[PROOF STEP]
by (simp add: drop_bit_eq_div take_bit_eq_mod)


[STATEMENT]
lemma bin_rsplit_aux_append: "bin_rsplit_aux n m c (bs @ cs) = bin_rsplit_aux n m c bs @ cs"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. bin_rsplit_aux n m c (bs @ cs) = bin_rsplit_aux n m c bs @ cs
[PROOF STEP]
apply (induct n m c bs rule: bin_rsplit_aux.induct)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>n m c bs. (\<And>x xa y. \<lbrakk>\<not> (m = 0 \<or> n = 0); x = bin_split n c; (xa, y) = x\<rbrakk> \<Longrightarrow> bin_rsplit_aux n (m - n) xa ((y # bs) @ cs) = bin_rsplit_aux n (m - n) xa (y # bs) @ cs) \<Longrightarrow> bin_rsplit_aux n m c (bs @ cs) = bin_rsplit_aux n m c bs @ cs
[PROOF STEP]
apply (subst bin_rsplit_aux.simps)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>n m c bs. (\<And>x xa y. \<lbrakk>\<not> (m = 0 \<or> n = 0); x = bin_split n c; (xa, y) = x\<rbrakk> \<Longrightarrow> bin_rsplit_aux n (m - n) xa ((y # bs) @ cs) = bin_rsplit_aux n (m - n) xa (y # bs) @ cs) \<Longrightarrow> (if m = 0 \<or> n = 0 then bs @ cs else let (a, b) = bin_split n c in bin_rsplit_aux n (m - n) a (b # bs @ cs)) = bin_rsplit_aux n m c bs @ cs
[PROOF STEP]
apply (subst bin_rsplit_aux.simps)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>n m c bs. (\<And>x xa y. \<lbrakk>\<not> (m = 0 \<or> n = 0); x = bin_split n c; (xa, y) = x\<rbrakk> \<Longrightarrow> bin_rsplit_aux n (m - n) xa ((y # bs) @ cs) = bin_rsplit_aux n (m - n) xa (y # bs) @ cs) \<Longrightarrow> (if m = 0 \<or> n = 0 then bs @ cs else let (a, b) = bin_split n c in if m - n = 0 \<or> n = 0 then b # bs @ cs else let (a, ba) = bin_split n a in bin_rsplit_aux n (m - n - n) a (ba # b # bs @ cs)) = bin_rsplit_aux n m c bs @ cs
[PROOF STEP]
apply (clarsimp split: prod.split)
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done


[STATEMENT]
lemma bin_rsplitl_aux_append: "bin_rsplitl_aux n m c (bs @ cs) = bin_rsplitl_aux n m c bs @ cs"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. bin_rsplitl_aux n m c (bs @ cs) = bin_rsplitl_aux n m c bs @ cs
[PROOF STEP]
apply (induct n m c bs rule: bin_rsplitl_aux.induct)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>n m c bs. (\<And>x xa y. \<lbrakk>\<not> (m = 0 \<or> n = 0); x = bin_split (min m n) c; (xa, y) = x\<rbrakk> \<Longrightarrow> bin_rsplitl_aux n (m - n) xa ((y # bs) @ cs) = bin_rsplitl_aux n (m - n) xa (y # bs) @ cs) \<Longrightarrow> bin_rsplitl_aux n m c (bs @ cs) = bin_rsplitl_aux n m c bs @ cs
[PROOF STEP]
apply (subst bin_rsplitl_aux.simps)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>n m c bs. (\<And>x xa y. \<lbrakk>\<not> (m = 0 \<or> n = 0); x = bin_split (min m n) c; (xa, y) = x\<rbrakk> \<Longrightarrow> bin_rsplitl_aux n (m - n) xa ((y # bs) @ cs) = bin_rsplitl_aux n (m - n) xa (y # bs) @ cs) \<Longrightarrow> (if m = 0 \<or> n = 0 then bs @ cs else let (a, b) = bin_split (min m n) c in bin_rsplitl_aux n (m - n) a (b # bs @ cs)) = bin_rsplitl_aux n m c bs @ cs
[PROOF STEP]
apply (subst bin_rsplitl_aux.simps)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>n m c bs. (\<And>x xa y. \<lbrakk>\<not> (m = 0 \<or> n = 0); x = bin_split (min m n) c; (xa, y) = x\<rbrakk> \<Longrightarrow> bin_rsplitl_aux n (m - n) xa ((y # bs) @ cs) = bin_rsplitl_aux n (m - n) xa (y # bs) @ cs) \<Longrightarrow> (if m = 0 \<or> n = 0 then bs @ cs else let (a, b) = bin_split (min m n) c in if m - n = 0 \<or> n = 0 then b # bs @ cs else let (a, ba) = bin_split (min (m - n) n) a in bin_rsplitl_aux n (m - n - n) a (ba # b # bs @ cs)) = bin_rsplitl_aux n m c bs @ cs
[PROOF STEP]
apply (clarsimp split: prod.split)
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done


[STATEMENT]
lemma bin_split_minus: "0 < n \<Longrightarrow> bin_split (Suc (n - 1)) w = bin_split n w"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 0 < n \<Longrightarrow> bin_split (Suc (n - 1)) w = bin_split n w
[PROOF STEP]
by auto


[STATEMENT]
lemma bin_split_pred_simp [simp]:
  "(0::nat) < numeral bin \<Longrightarrow>
    bin_split (numeral bin) w =
      (let (w1, w2) = bin_split (numeral bin - 1) ((\<lambda>k::int. k div 2) w)
       in (w1, of_bool (odd w) + 2 * w2))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 0 < numeral bin \<Longrightarrow> bin_split (numeral bin) w = (let (w1, w2) = bin_split (numeral bin - 1) (w div 2) in (w1, of_bool (odd w) + 2 * w2))
[PROOF STEP]
by (simp add: take_bit_rec drop_bit_rec mod_2_eq_odd)


[STATEMENT]
lemma bin_rsplit_aux_simp_alt:
  "bin_rsplit_aux n m c bs =
    (if m = 0 \<or> n = 0 then bs
     else let (a, b) = bin_split n c in bin_rsplit n (m - n, a) @ b # bs)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. bin_rsplit_aux n m c bs = (if m = 0 \<or> n = 0 then bs else let (a, b) = bin_split n c in bin_rsplit n (m - n, a) @ b # bs)
[PROOF STEP]
apply (simp add: bin_rsplit_aux.simps [of n m c bs])
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 0 < m \<and> 0 < n \<longrightarrow> bin_rsplit_aux n (m - n) (drop_bit n c) (take_bit n c # bs) = bin_rsplit n (m - n, drop_bit n c) @ take_bit n c # bs
[PROOF STEP]
apply (subst rsplit_aux_alts)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 0 < m \<and> 0 < n \<longrightarrow> bin_rsplit_aux n (m - n) (drop_bit n c) [] @ take_bit n c # bs = bin_rsplit n (m - n, drop_bit n c) @ take_bit n c # bs
[PROOF STEP]
apply (simp add: bin_rsplit_def)
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done


[STATEMENT]
lemma bin_rsplit_size_sign' [rule_format]:
  "n > 0 \<Longrightarrow> rev sw = bin_rsplit n (nw, w) \<Longrightarrow> \<forall>v\<in>set sw. (take_bit :: nat \<Rightarrow> int \<Rightarrow> int) n v = v"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>0 < n; rev sw = bin_rsplit n (nw, w)\<rbrakk> \<Longrightarrow> \<forall>v\<in>set sw. take_bit n v = v
[PROOF STEP]
apply (induct sw arbitrary: nw w)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. \<And>nw w. \<lbrakk>0 < n; rev [] = bin_rsplit n (nw, w)\<rbrakk> \<Longrightarrow> \<forall>v\<in>set []. take_bit n v = v
 2. \<And>a sw nw w. \<lbrakk>\<And>nw w. \<lbrakk>0 < n; rev sw = bin_rsplit n (nw, w)\<rbrakk> \<Longrightarrow> \<forall>v\<in>set sw. take_bit n v = v; 0 < n; rev (a # sw) = bin_rsplit n (nw, w)\<rbrakk> \<Longrightarrow> \<forall>v\<in>set (a # sw). take_bit n v = v
[PROOF STEP]
apply clarsimp
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>a sw nw w. \<lbrakk>\<And>nw w. \<lbrakk>0 < n; rev sw = bin_rsplit n (nw, w)\<rbrakk> \<Longrightarrow> \<forall>v\<in>set sw. take_bit n v = v; 0 < n; rev (a # sw) = bin_rsplit n (nw, w)\<rbrakk> \<Longrightarrow> \<forall>v\<in>set (a # sw). take_bit n v = v
[PROOF STEP]
apply clarsimp
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>a sw nw w. \<lbrakk>\<And>nw w. rev sw = bin_rsplit n (nw, w) \<Longrightarrow> \<forall>v\<in>set sw. take_bit n v = v; 0 < n; rev sw @ [a] = bin_rsplit n (nw, w)\<rbrakk> \<Longrightarrow> take_bit n a = a \<and> (\<forall>v\<in>set sw. take_bit n v = v)
[PROOF STEP]
apply (drule bthrs)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>a sw nw w. \<lbrakk>\<And>nw w. rev sw = bin_rsplit n (nw, w) \<Longrightarrow> \<forall>v\<in>set sw. take_bit n v = v; 0 < n; rev sw @ [a] = (if fst (nw, w) = 0 \<or> n = 0 then [] else let (a, b) = bin_split n (snd (nw, w)) in bin_rsplit n (fst (nw, w) - n, a) @ [b])\<rbrakk> \<Longrightarrow> take_bit n a = a \<and> (\<forall>v\<in>set sw. take_bit n v = v)
[PROOF STEP]
apply (simp (no_asm_use) add: Let_def split: prod.split_asm if_split_asm)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>sw nw w. \<lbrakk>\<And>nw w. rev sw = bin_rsplit n (nw, w) \<Longrightarrow> \<forall>v\<in>set sw. take_bit n v = v; 0 < n; 0 < nw \<and> 0 < n; rev sw = bin_rsplit n (nw - n, drop_bit n w)\<rbrakk> \<Longrightarrow> \<forall>v\<in>set sw. take_bit n v = v
[PROOF STEP]
apply clarify
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>sw nw w v. \<lbrakk>\<And>nw w. rev sw = bin_rsplit n (nw, w) \<Longrightarrow> \<forall>v\<in>set sw. take_bit n v = v; 0 < n; rev sw = bin_rsplit n (nw - n, drop_bit n w); v \<in> set sw; 0 < nw; 0 < n\<rbrakk> \<Longrightarrow> take_bit n v = v
[PROOF STEP]
apply simp
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done


[STATEMENT]
lemma bin_nth_rsplit [rule_format] :
  "n > 0 \<Longrightarrow> m < n \<Longrightarrow>
    \<forall>w k nw.
      rev sw = bin_rsplit n (nw, w) \<longrightarrow>
      k < size sw \<longrightarrow> (bit :: int \<Rightarrow> nat \<Rightarrow> bool) (sw ! k) m = (bit :: int \<Rightarrow> nat \<Rightarrow> bool) w (k * n + m)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>0 < n; m < n\<rbrakk> \<Longrightarrow> \<forall>w k nw. rev sw = bin_rsplit n (nw, w) \<longrightarrow> k < length sw \<longrightarrow> bit (sw ! k) m = bit w (k * n + m)
[PROOF STEP]
apply (induct sw)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. \<lbrakk>0 < n; m < n\<rbrakk> \<Longrightarrow> \<forall>w k nw. rev [] = bin_rsplit n (nw, w) \<longrightarrow> k < length [] \<longrightarrow> bit ([] ! k) m = bit w (k * n + m)
 2. \<And>a sw. \<lbrakk>\<lbrakk>0 < n; m < n\<rbrakk> \<Longrightarrow> \<forall>w k nw. rev sw = bin_rsplit n (nw, w) \<longrightarrow> k < length sw \<longrightarrow> bit (sw ! k) m = bit w (k * n + m); 0 < n; m < n\<rbrakk> \<Longrightarrow> \<forall>w k nw. rev (a # sw) = bin_rsplit n (nw, w) \<longrightarrow> k < length (a # sw) \<longrightarrow> bit ((a # sw) ! k) m = bit w (k * n + m)
[PROOF STEP]
apply clarsimp
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>a sw. \<lbrakk>\<lbrakk>0 < n; m < n\<rbrakk> \<Longrightarrow> \<forall>w k nw. rev sw = bin_rsplit n (nw, w) \<longrightarrow> k < length sw \<longrightarrow> bit (sw ! k) m = bit w (k * n + m); 0 < n; m < n\<rbrakk> \<Longrightarrow> \<forall>w k nw. rev (a # sw) = bin_rsplit n (nw, w) \<longrightarrow> k < length (a # sw) \<longrightarrow> bit ((a # sw) ! k) m = bit w (k * n + m)
[PROOF STEP]
apply clarsimp
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>a sw w nw k. \<lbrakk>\<forall>w. (\<exists>nw. rev sw = bin_rsplit n (nw, w)) \<longrightarrow> (\<forall>k<length sw. bit (sw ! k) m = bit w (k * n + m)); m < n; rev sw @ [a] = bin_rsplit n (nw, w); k < Suc (length sw)\<rbrakk> \<Longrightarrow> bit ((a # sw) ! k) m = bit w (k * n + m)
[PROOF STEP]
apply (drule bthrs)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>a sw w nw k. \<lbrakk>\<forall>w. (\<exists>nw. rev sw = bin_rsplit n (nw, w)) \<longrightarrow> (\<forall>k<length sw. bit (sw ! k) m = bit w (k * n + m)); m < n; k < Suc (length sw); rev sw @ [a] = (if fst (nw, w) = 0 \<or> n = 0 then [] else let (a, b) = bin_split n (snd (nw, w)) in bin_rsplit n (fst (nw, w) - n, a) @ [b])\<rbrakk> \<Longrightarrow> bit ((a # sw) ! k) m = bit w (k * n + m)
[PROOF STEP]
apply (simp (no_asm_use) add: Let_def split: prod.split_asm if_split_asm)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>sw w nw k. \<lbrakk>\<forall>w. (\<exists>nw. rev sw = bin_rsplit n (nw, w)) \<longrightarrow> (\<forall>k<length sw. bit (sw ! k) m = bit w (k * n + m)); m < n; k < Suc (length sw); 0 < nw \<and> 0 < n; rev sw = bin_rsplit n (nw - n, drop_bit n w)\<rbrakk> \<Longrightarrow> bit ((take_bit n w # sw) ! k) m = bit w (k * n + m)
[PROOF STEP]
apply (erule allE, erule impE, erule exI)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>sw w nw k. \<lbrakk>m < n; k < Suc (length sw); 0 < nw \<and> 0 < n; rev sw = bin_rsplit n (nw - n, drop_bit n w); \<forall>k<length sw. bit (sw ! k) m = bit (drop_bit n w) (k * n + m)\<rbrakk> \<Longrightarrow> bit ((take_bit n w # sw) ! k) m = bit w (k * n + m)
[PROOF STEP]
apply (case_tac k)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. \<And>sw w nw k. \<lbrakk>m < n; k < Suc (length sw); 0 < nw \<and> 0 < n; rev sw = bin_rsplit n (nw - n, drop_bit n w); \<forall>k<length sw. bit (sw ! k) m = bit (drop_bit n w) (k * n + m); k = 0\<rbrakk> \<Longrightarrow> bit ((take_bit n w # sw) ! k) m = bit w (k * n + m)
 2. \<And>sw w nw k nat. \<lbrakk>m < n; k < Suc (length sw); 0 < nw \<and> 0 < n; rev sw = bin_rsplit n (nw - n, drop_bit n w); \<forall>k<length sw. bit (sw ! k) m = bit (drop_bit n w) (k * n + m); k = Suc nat\<rbrakk> \<Longrightarrow> bit ((take_bit n w # sw) ! k) m = bit w (k * n + m)
[PROOF STEP]
apply clarsimp
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. \<And>sw w nw. \<lbrakk>m < n; 0 < nw; rev sw = bin_rsplit n (nw - n, drop_bit n w); \<forall>k<length sw. bit (sw ! k) m = bit (drop_bit n w) (k * n + m)\<rbrakk> \<Longrightarrow> bit (take_bit n w) m = bit w m
 2. \<And>sw w nw k nat. \<lbrakk>m < n; k < Suc (length sw); 0 < nw \<and> 0 < n; rev sw = bin_rsplit n (nw - n, drop_bit n w); \<forall>k<length sw. bit (sw ! k) m = bit (drop_bit n w) (k * n + m); k = Suc nat\<rbrakk> \<Longrightarrow> bit ((take_bit n w # sw) ! k) m = bit w (k * n + m)
[PROOF STEP]
prefer 2
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. \<And>sw w nw k nat. \<lbrakk>m < n; k < Suc (length sw); 0 < nw \<and> 0 < n; rev sw = bin_rsplit n (nw - n, drop_bit n w); \<forall>k<length sw. bit (sw ! k) m = bit (drop_bit n w) (k * n + m); k = Suc nat\<rbrakk> \<Longrightarrow> bit ((take_bit n w # sw) ! k) m = bit w (k * n + m)
 2. \<And>sw w nw. \<lbrakk>m < n; 0 < nw; rev sw = bin_rsplit n (nw - n, drop_bit n w); \<forall>k<length sw. bit (sw ! k) m = bit (drop_bit n w) (k * n + m)\<rbrakk> \<Longrightarrow> bit (take_bit n w) m = bit w m
[PROOF STEP]
apply clarsimp
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. \<And>sw w nw nat. \<lbrakk>m < n; nat < length sw; 0 < nw; rev sw = bin_rsplit n (nw - n, drop_bit n w); \<forall>k<length sw. bit (sw ! k) m = bit (drop_bit n w) (k * n + m)\<rbrakk> \<Longrightarrow> bit (drop_bit n w) (nat * n + m) = bit w (n + nat * n + m)
 2. \<And>sw w nw. \<lbrakk>m < n; 0 < nw; rev sw = bin_rsplit n (nw - n, drop_bit n w); \<forall>k<length sw. bit (sw ! k) m = bit (drop_bit n w) (k * n + m)\<rbrakk> \<Longrightarrow> bit (take_bit n w) m = bit w m
[PROOF STEP]
apply (erule allE)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. \<And>sw w nw nat. \<lbrakk>m < n; nat < length sw; 0 < nw; rev sw = bin_rsplit n (nw - n, drop_bit n w); ?k40 sw w nw nat < length sw \<longrightarrow> bit (sw ! ?k40 sw w nw nat) m = bit (drop_bit n w) (?k40 sw w nw nat * n + m)\<rbrakk> \<Longrightarrow> bit (drop_bit n w) (nat * n + m) = bit w (n + nat * n + m)
 2. \<And>sw w nw. \<lbrakk>m < n; 0 < nw; rev sw = bin_rsplit n (nw - n, drop_bit n w); \<forall>k<length sw. bit (sw ! k) m = bit (drop_bit n w) (k * n + m)\<rbrakk> \<Longrightarrow> bit (take_bit n w) m = bit w m
[PROOF STEP]
apply (erule (1) impE)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. \<And>sw w nw nat. \<lbrakk>m < n; nat < length sw; 0 < nw; rev sw = bin_rsplit n (nw - n, drop_bit n w); bit (sw ! nat) m = bit (drop_bit n w) (nat * n + m)\<rbrakk> \<Longrightarrow> bit (drop_bit n w) (nat * n + m) = bit w (n + nat * n + m)
 2. \<And>sw w nw. \<lbrakk>m < n; 0 < nw; rev sw = bin_rsplit n (nw - n, drop_bit n w); \<forall>k<length sw. bit (sw ! k) m = bit (drop_bit n w) (k * n + m)\<rbrakk> \<Longrightarrow> bit (take_bit n w) m = bit w m
[PROOF STEP]
apply (simp add: bit_drop_bit_eq ac_simps)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>sw w nw. \<lbrakk>m < n; 0 < nw; rev sw = bin_rsplit n (nw - n, drop_bit n w); \<forall>k<length sw. bit (sw ! k) m = bit (drop_bit n w) (k * n + m)\<rbrakk> \<Longrightarrow> bit (take_bit n w) m = bit w m
[PROOF STEP]
apply (simp add: bit_take_bit_iff ac_simps)
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done


[STATEMENT]
lemma bin_rsplit_all: "0 < nw \<Longrightarrow> nw \<le> n \<Longrightarrow> bin_rsplit n (nw, w) = [(take_bit :: nat \<Rightarrow> int \<Rightarrow> int) n w]"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>0 < nw; nw \<le> n\<rbrakk> \<Longrightarrow> bin_rsplit n (nw, w) = [take_bit n w]
[PROOF STEP]
by (auto simp: bin_rsplit_def rsplit_aux_simp2ls split: prod.split dest!: split_bintrunc)


[STATEMENT]
lemma bin_rsplit_l [rule_format]:
  "\<forall>bin. bin_rsplitl n (m, bin) = bin_rsplit n (m, (take_bit :: nat \<Rightarrow> int \<Rightarrow> int) m bin)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<forall>bin. bin_rsplitl n (m, bin) = bin_rsplit n (m, take_bit m bin)
[PROOF STEP]
apply (rule_tac a = "m" in wf_less_than [THEN wf_induct])
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>x. \<forall>y. (y, x) \<in> less_than \<longrightarrow> (\<forall>bin. bin_rsplitl n (y, bin) = bin_rsplit n (y, take_bit y bin)) \<Longrightarrow> \<forall>bin. bin_rsplitl n (x, bin) = bin_rsplit n (x, take_bit x bin)
[PROOF STEP]
apply (simp (no_asm) add: bin_rsplitl_def bin_rsplit_def)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>x. \<forall>y. (y, x) \<in> less_than \<longrightarrow> (\<forall>bin. bin_rsplitl n (y, bin) = bin_rsplit n (y, take_bit y bin)) \<Longrightarrow> \<forall>bin. bin_rsplitl_aux n x bin [] = bin_rsplit_aux n x (take_bit x bin) []
[PROOF STEP]
apply (rule allI)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>x bin. \<forall>y. (y, x) \<in> less_than \<longrightarrow> (\<forall>bin. bin_rsplitl n (y, bin) = bin_rsplit n (y, take_bit y bin)) \<Longrightarrow> bin_rsplitl_aux n x bin [] = bin_rsplit_aux n x (take_bit x bin) []
[PROOF STEP]
apply (subst bin_rsplitl_aux.simps)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>x bin. \<forall>y. (y, x) \<in> less_than \<longrightarrow> (\<forall>bin. bin_rsplitl n (y, bin) = bin_rsplit n (y, take_bit y bin)) \<Longrightarrow> (if x = 0 \<or> n = 0 then [] else let (a, b) = bin_split (min x n) bin in bin_rsplitl_aux n (x - n) a [b]) = bin_rsplit_aux n x (take_bit x bin) []
[PROOF STEP]
apply (subst bin_rsplit_aux.simps)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>x bin. \<forall>y. (y, x) \<in> less_than \<longrightarrow> (\<forall>bin. bin_rsplitl n (y, bin) = bin_rsplit n (y, take_bit y bin)) \<Longrightarrow> (if x = 0 \<or> n = 0 then [] else let (a, b) = bin_split (min x n) bin in bin_rsplitl_aux n (x - n) a [b]) = (if x = 0 \<or> n = 0 then [] else let (a, b) = bin_split n (take_bit x bin) in bin_rsplit_aux n (x - n) a [b])
[PROOF STEP]
apply (clarsimp simp: Let_def split: prod.split)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>x bin. \<lbrakk>\<forall>y<x. \<forall>bin. bin_rsplitl n (y, bin) = bin_rsplit n (y, take_bit y bin); 0 < x; 0 < n\<rbrakk> \<Longrightarrow> bin_rsplitl_aux n (x - n) (drop_bit (min x n) bin) [take_bit (min x n) bin] = bin_rsplit_aux n (x - n) (drop_bit n (take_bit x bin)) [take_bit (min n x) bin]
[PROOF STEP]
apply (simp add: ac_simps)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>x bin. \<lbrakk>\<forall>y<x. \<forall>bin. bin_rsplitl n (y, bin) = bin_rsplit n (y, take_bit y bin); 0 < x; 0 < n\<rbrakk> \<Longrightarrow> bin_rsplitl_aux n (x - n) (drop_bit (min x n) bin) [take_bit (min x n) bin] = bin_rsplit_aux n (x - n) (drop_bit n (take_bit x bin)) [take_bit (min x n) bin]
[PROOF STEP]
apply (subst rsplit_aux_alts(1))
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>x bin. \<lbrakk>\<forall>y<x. \<forall>bin. bin_rsplitl n (y, bin) = bin_rsplit n (y, take_bit y bin); 0 < x; 0 < n\<rbrakk> \<Longrightarrow> bin_rsplitl_aux n (x - n) (drop_bit (min x n) bin) [take_bit (min x n) bin] = bin_rsplit_aux n (x - n) (drop_bit n (take_bit x bin)) [] @ [take_bit (min x n) bin]
[PROOF STEP]
apply (subst rsplit_aux_alts(2))
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>x bin. \<lbrakk>\<forall>y<x. \<forall>bin. bin_rsplitl n (y, bin) = bin_rsplit n (y, take_bit y bin); 0 < x; 0 < n\<rbrakk> \<Longrightarrow> bin_rsplitl_aux n (x - n) (drop_bit (min x n) bin) [] @ [take_bit (min x n) bin] = bin_rsplit_aux n (x - n) (drop_bit n (take_bit x bin)) [] @ [take_bit (min x n) bin]
[PROOF STEP]
apply clarsimp
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>x bin. \<lbrakk>\<forall>y<x. \<forall>bin. bin_rsplitl n (y, bin) = bin_rsplit n (y, take_bit y bin); 0 < x; 0 < n\<rbrakk> \<Longrightarrow> bin_rsplitl_aux n (x - n) (drop_bit (min x n) bin) [] = bin_rsplit_aux n (x - n) (drop_bit n (take_bit x bin)) []
[PROOF STEP]
unfolding bin_rsplit_def bin_rsplitl_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>x bin. \<lbrakk>\<forall>y<x. \<forall>bin. bin_rsplitl_aux n (fst (y, bin)) (snd (y, bin)) [] = bin_rsplit_aux n (fst (y, take_bit y bin)) (snd (y, take_bit y bin)) []; 0 < x; 0 < n\<rbrakk> \<Longrightarrow> bin_rsplitl_aux n (x - n) (drop_bit (min x n) bin) [] = bin_rsplit_aux n (x - n) (drop_bit n (take_bit x bin)) []
[PROOF STEP]
apply (simp add: drop_bit_take_bit)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>x bin. \<lbrakk>\<forall>y<x. \<forall>bin. bin_rsplitl_aux n y bin [] = bin_rsplit_aux n y (take_bit y bin) []; 0 < x; 0 < n\<rbrakk> \<Longrightarrow> bin_rsplit_aux n (x - n) (take_bit (x - n) (drop_bit (min x n) bin)) [] = bin_rsplit_aux n (x - n) (take_bit (x - n) (drop_bit n bin)) []
[PROOF STEP]
apply (case_tac \<open>x < n\<close>)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. \<And>x bin. \<lbrakk>\<forall>y<x. \<forall>bin. bin_rsplitl_aux n y bin [] = bin_rsplit_aux n y (take_bit y bin) []; 0 < x; 0 < n; x < n\<rbrakk> \<Longrightarrow> bin_rsplit_aux n (x - n) (take_bit (x - n) (drop_bit (min x n) bin)) [] = bin_rsplit_aux n (x - n) (take_bit (x - n) (drop_bit n bin)) []
 2. \<And>x bin. \<lbrakk>\<forall>y<x. \<forall>bin. bin_rsplitl_aux n y bin [] = bin_rsplit_aux n y (take_bit y bin) []; 0 < x; 0 < n; \<not> x < n\<rbrakk> \<Longrightarrow> bin_rsplit_aux n (x - n) (take_bit (x - n) (drop_bit (min x n) bin)) [] = bin_rsplit_aux n (x - n) (take_bit (x - n) (drop_bit n bin)) []
[PROOF STEP]
apply (simp_all add: not_less min_def)
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done


[STATEMENT]
lemma bin_rsplit_rcat [rule_format]:
  "n > 0 \<longrightarrow> bin_rsplit n (n * size ws, bin_rcat n ws) = map ((take_bit :: nat \<Rightarrow> int \<Rightarrow> int) n) ws"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 0 < n \<longrightarrow> bin_rsplit n (n * length ws, bin_rcat n ws) = map (take_bit n) ws
[PROOF STEP]
apply (unfold bin_rsplit_def bin_rcat_eq_foldl)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 0 < n \<longrightarrow> bin_rsplit_aux n (fst (n * length ws, foldl (\<lambda>u v. concat_bit n v u) 0 ws)) (snd (n * length ws, foldl (\<lambda>u v. concat_bit n v u) 0 ws)) [] = map (take_bit n) ws
[PROOF STEP]
apply (rule_tac xs = ws in rev_induct)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. 0 < n \<longrightarrow> bin_rsplit_aux n (fst (n * length [], foldl (\<lambda>u v. concat_bit n v u) 0 [])) (snd (n * length [], foldl (\<lambda>u v. concat_bit n v u) 0 [])) [] = map (take_bit n) []
 2. \<And>x xs. 0 < n \<longrightarrow> bin_rsplit_aux n (fst (n * length xs, foldl (\<lambda>u v. concat_bit n v u) 0 xs)) (snd (n * length xs, foldl (\<lambda>u v. concat_bit n v u) 0 xs)) [] = map (take_bit n) xs \<Longrightarrow> 0 < n \<longrightarrow> bin_rsplit_aux n (fst (n * length (xs @ [x]), foldl (\<lambda>u v. concat_bit n v u) 0 (xs @ [x]))) (snd (n * length (xs @ [x]), foldl (\<lambda>u v. concat_bit n v u) 0 (xs @ [x]))) [] = map (take_bit n) (xs @ [x])
[PROOF STEP]
apply clarsimp
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>x xs. 0 < n \<longrightarrow> bin_rsplit_aux n (fst (n * length xs, foldl (\<lambda>u v. concat_bit n v u) 0 xs)) (snd (n * length xs, foldl (\<lambda>u v. concat_bit n v u) 0 xs)) [] = map (take_bit n) xs \<Longrightarrow> 0 < n \<longrightarrow> bin_rsplit_aux n (fst (n * length (xs @ [x]), foldl (\<lambda>u v. concat_bit n v u) 0 (xs @ [x]))) (snd (n * length (xs @ [x]), foldl (\<lambda>u v. concat_bit n v u) 0 (xs @ [x]))) [] = map (take_bit n) (xs @ [x])
[PROOF STEP]
apply clarsimp
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>x xs. \<lbrakk>0 < n; bin_rsplit_aux n (n * length xs) (foldl (\<lambda>u v. concat_bit n v u) 0 xs) [] = map (take_bit n) xs\<rbrakk> \<Longrightarrow> bin_rsplit_aux n (n * length xs) (drop_bit n (concat_bit n x (foldl (\<lambda>u v. concat_bit n v u) 0 xs))) [take_bit n x] = map (take_bit n) xs @ [take_bit n x]
[PROOF STEP]
apply (subst rsplit_aux_alts)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>x xs. \<lbrakk>0 < n; bin_rsplit_aux n (n * length xs) (foldl (\<lambda>u v. concat_bit n v u) 0 xs) [] = map (take_bit n) xs\<rbrakk> \<Longrightarrow> bin_rsplit_aux n (n * length xs) (drop_bit n (concat_bit n x (foldl (\<lambda>u v. concat_bit n v u) 0 xs))) [] @ [take_bit n x] = map (take_bit n) xs @ [take_bit n x]
[PROOF STEP]
apply (simp add: drop_bit_bin_cat_eq take_bit_bin_cat_eq)
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done


[STATEMENT]
lemma bin_rsplit_aux_len_le [rule_format] :
  "\<forall>ws m. n \<noteq> 0 \<longrightarrow> ws = bin_rsplit_aux n nw w bs \<longrightarrow>
    length ws \<le> m \<longleftrightarrow> nw + length bs * n \<le> m * n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<forall>ws m. n \<noteq> 0 \<longrightarrow> ws = bin_rsplit_aux n nw w bs \<longrightarrow> (length ws \<le> m) = (nw + length bs * n \<le> m * n)
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<forall>ws m. n \<noteq> 0 \<longrightarrow> ws = bin_rsplit_aux n nw w bs \<longrightarrow> (length ws \<le> m) = (nw + length bs * n \<le> m * n)
[PROOF STEP]
have *: R
    if d: "i \<le> j \<or> m < j'"
    and R1: "i * k \<le> j * k \<Longrightarrow> R"
    and R2: "Suc m * k' \<le> j' * k' \<Longrightarrow> R"
    for i j j' k k' m :: nat and R
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. R
[PROOF STEP]
using d
[PROOF STATE]
proof (prove)
using this:
i \<le> j \<or> m < j'

goal (1 subgoal):
 1. R
[PROOF STEP]
apply safe
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. i \<le> j \<Longrightarrow> R
 2. m < j' \<Longrightarrow> R
[PROOF STEP]
apply (rule R1, erule mult_le_mono1)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. m < j' \<Longrightarrow> R
[PROOF STEP]
apply (rule R2, erule Suc_le_eq [THEN iffD2 [THEN mult_le_mono1]])
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done
[PROOF STATE]
proof (state)
this:
\<lbrakk>?i \<le> ?j \<or> ?m < ?j'; ?i * ?k \<le> ?j * ?k \<Longrightarrow> ?R; Suc ?m * ?k' \<le> ?j' * ?k' \<Longrightarrow> ?R\<rbrakk> \<Longrightarrow> ?R

goal (1 subgoal):
 1. \<forall>ws m. n \<noteq> 0 \<longrightarrow> ws = bin_rsplit_aux n nw w bs \<longrightarrow> (length ws \<le> m) = (nw + length bs * n \<le> m * n)
[PROOF STEP]
have **: "0 < sc \<Longrightarrow> sc - n + (n + lb * n) \<le> m * n \<longleftrightarrow> sc + lb * n \<le> m * n"
    for sc m n lb :: nat
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 0 < sc \<Longrightarrow> (sc - n + (n + lb * n) \<le> m * n) = (sc + lb * n \<le> m * n)
[PROOF STEP]
apply safe
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. \<lbrakk>0 < sc; sc - n + (n + lb * n) \<le> m * n\<rbrakk> \<Longrightarrow> sc + lb * n \<le> m * n
 2. \<lbrakk>0 < sc; sc + lb * n \<le> m * n\<rbrakk> \<Longrightarrow> sc - n + (n + lb * n) \<le> m * n
[PROOF STEP]
apply arith
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>0 < sc; sc + lb * n \<le> m * n\<rbrakk> \<Longrightarrow> sc - n + (n + lb * n) \<le> m * n
[PROOF STEP]
apply (case_tac "sc \<ge> n")
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. \<lbrakk>0 < sc; sc + lb * n \<le> m * n; n \<le> sc\<rbrakk> \<Longrightarrow> sc - n + (n + lb * n) \<le> m * n
 2. \<lbrakk>0 < sc; sc + lb * n \<le> m * n; \<not> n \<le> sc\<rbrakk> \<Longrightarrow> sc - n + (n + lb * n) \<le> m * n
[PROOF STEP]
apply arith
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>0 < sc; sc + lb * n \<le> m * n; \<not> n \<le> sc\<rbrakk> \<Longrightarrow> sc - n + (n + lb * n) \<le> m * n
[PROOF STEP]
apply (insert linorder_le_less_linear [of m lb])
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>0 < sc; sc + lb * n \<le> m * n; \<not> n \<le> sc; m \<le> lb \<or> lb < m\<rbrakk> \<Longrightarrow> sc - n + (n + lb * n) \<le> m * n
[PROOF STEP]
apply (erule_tac k=n and k'=n in *)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. \<lbrakk>0 < sc; sc + lb * n \<le> m * n; \<not> n \<le> sc; m * n \<le> lb * n\<rbrakk> \<Longrightarrow> sc - n + (n + lb * n) \<le> m * n
 2. \<lbrakk>0 < sc; sc + lb * n \<le> m * n; \<not> n \<le> sc; Suc lb * n \<le> m * n\<rbrakk> \<Longrightarrow> sc - n + (n + lb * n) \<le> m * n
[PROOF STEP]
apply arith
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>0 < sc; sc + lb * n \<le> m * n; \<not> n \<le> sc; Suc lb * n \<le> m * n\<rbrakk> \<Longrightarrow> sc - n + (n + lb * n) \<le> m * n
[PROOF STEP]
apply simp
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done
[PROOF STATE]
proof (state)
this:
0 < ?sc \<Longrightarrow> (?sc - ?n + (?n + ?lb * ?n) \<le> ?m * ?n) = (?sc + ?lb * ?n \<le> ?m * ?n)

goal (1 subgoal):
 1. \<forall>ws m. n \<noteq> 0 \<longrightarrow> ws = bin_rsplit_aux n nw w bs \<longrightarrow> (length ws \<le> m) = (nw + length bs * n \<le> m * n)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<forall>ws m. n \<noteq> 0 \<longrightarrow> ws = bin_rsplit_aux n nw w bs \<longrightarrow> (length ws \<le> m) = (nw + length bs * n \<le> m * n)
[PROOF STEP]
apply (induct n nw w bs rule: bin_rsplit_aux.induct)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>n m c bs. (\<And>x xa y. \<lbrakk>\<not> (m = 0 \<or> n = 0); x = bin_split n c; (xa, y) = x\<rbrakk> \<Longrightarrow> \<forall>ws ma. n \<noteq> 0 \<longrightarrow> ws = bin_rsplit_aux n (m - n) xa (y # bs) \<longrightarrow> (length ws \<le> ma) = (m - n + length (y # bs) * n \<le> ma * n)) \<Longrightarrow> \<forall>ws ma. n \<noteq> 0 \<longrightarrow> ws = bin_rsplit_aux n m c bs \<longrightarrow> (length ws \<le> ma) = (m + length bs * n \<le> ma * n)
[PROOF STEP]
apply (subst bin_rsplit_aux.simps)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>n m c bs. (\<And>x xa y. \<lbrakk>\<not> (m = 0 \<or> n = 0); x = bin_split n c; (xa, y) = x\<rbrakk> \<Longrightarrow> \<forall>ws ma. n \<noteq> 0 \<longrightarrow> ws = bin_rsplit_aux n (m - n) xa (y # bs) \<longrightarrow> (length ws \<le> ma) = (m - n + length (y # bs) * n \<le> ma * n)) \<Longrightarrow> \<forall>ws ma. n \<noteq> 0 \<longrightarrow> ws = (if m = 0 \<or> n = 0 then bs else let (a, b) = bin_split n c in bin_rsplit_aux n (m - n) a (b # bs)) \<longrightarrow> (length ws \<le> ma) = (m + length bs * n \<le> ma * n)
[PROOF STEP]
apply (simp add: ** Let_def split: prod.split)
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done
[PROOF STATE]
proof (state)
this:
\<forall>ws m. n \<noteq> 0 \<longrightarrow> ws = bin_rsplit_aux n nw w bs \<longrightarrow> (length ws \<le> m) = (nw + length bs * n \<le> m * n)

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
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"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. n \<noteq> 0 \<longrightarrow> ws = bin_rsplit n (nw, w) \<longrightarrow> (length ws \<le> m) = (nw \<le> m * n)
[PROOF STEP]
by (auto simp: bin_rsplit_def bin_rsplit_aux_len_le)


[STATEMENT]
lemma bin_rsplit_aux_len:
  "n \<noteq> 0 \<Longrightarrow> length (bin_rsplit_aux n nw w cs) = (nw + n - 1) div n + length cs"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. n \<noteq> 0 \<Longrightarrow> length (bin_rsplit_aux n nw w cs) = (nw + n - 1) div n + length cs
[PROOF STEP]
apply (induct n nw w cs rule: bin_rsplit_aux.induct)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>n m c bs. \<lbrakk>\<And>x xa y. \<lbrakk>\<not> (m = 0 \<or> n = 0); x = bin_split n c; (xa, y) = x; n \<noteq> 0\<rbrakk> \<Longrightarrow> length (bin_rsplit_aux n (m - n) xa (y # bs)) = (m - n + n - 1) div n + length (y # bs); n \<noteq> 0\<rbrakk> \<Longrightarrow> length (bin_rsplit_aux n m c bs) = (m + n - 1) div n + length bs
[PROOF STEP]
apply (subst bin_rsplit_aux.simps)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>n m c bs. \<lbrakk>\<And>x xa y. \<lbrakk>\<not> (m = 0 \<or> n = 0); x = bin_split n c; (xa, y) = x; n \<noteq> 0\<rbrakk> \<Longrightarrow> length (bin_rsplit_aux n (m - n) xa (y # bs)) = (m - n + n - 1) div n + length (y # bs); n \<noteq> 0\<rbrakk> \<Longrightarrow> length (if m = 0 \<or> n = 0 then bs else let (a, b) = bin_split n c in bin_rsplit_aux n (m - n) a (b # bs)) = (m + n - 1) div n + length bs
[PROOF STEP]
apply (clarsimp simp: Let_def split: prod.split)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>n m c bs. \<lbrakk>\<And>a xa. \<lbrakk>a = drop_bit n c; xa = drop_bit n c\<rbrakk> \<Longrightarrow> length (bin_rsplit_aux n (m - n) (drop_bit n c) (take_bit n c # bs)) = Suc ((m - n + n - Suc 0) div n + length bs); 0 < n; 0 < m\<rbrakk> \<Longrightarrow> Suc ((m - n + n - Suc 0) div n) = (m + n - Suc 0) div n
[PROOF STEP]
apply (erule thin_rl)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>n m c bs. \<lbrakk>0 < n; 0 < m\<rbrakk> \<Longrightarrow> Suc ((m - n + n - Suc 0) div n) = (m + n - Suc 0) div n
[PROOF STEP]
apply (case_tac m)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. \<And>n m c bs. \<lbrakk>0 < n; 0 < m; m = 0\<rbrakk> \<Longrightarrow> Suc ((m - n + n - Suc 0) div n) = (m + n - Suc 0) div n
 2. \<And>n m c bs nat. \<lbrakk>0 < n; 0 < m; m = Suc nat\<rbrakk> \<Longrightarrow> Suc ((m - n + n - Suc 0) div n) = (m + n - Suc 0) div n
[PROOF STEP]
apply simp
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>n m c bs nat. \<lbrakk>0 < n; 0 < m; m = Suc nat\<rbrakk> \<Longrightarrow> Suc ((m - n + n - Suc 0) div n) = (m + n - Suc 0) div n
[PROOF STEP]
apply (case_tac "m \<le> n")
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. \<And>n m c bs nat. \<lbrakk>0 < n; 0 < m; m = Suc nat; m \<le> n\<rbrakk> \<Longrightarrow> Suc ((m - n + n - Suc 0) div n) = (m + n - Suc 0) div n
 2. \<And>n m c bs nat. \<lbrakk>0 < n; 0 < m; m = Suc nat; \<not> m \<le> n\<rbrakk> \<Longrightarrow> Suc ((m - n + n - Suc 0) div n) = (m + n - Suc 0) div n
[PROOF STEP]
apply (auto simp add: div_add_self2)
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done


[STATEMENT]
lemma bin_rsplit_len: "n \<noteq> 0 \<Longrightarrow> length (bin_rsplit n (nw, w)) = (nw + n - 1) div n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. n \<noteq> 0 \<Longrightarrow> length (bin_rsplit n (nw, w)) = (nw + n - 1) div n
[PROOF STEP]
by (auto simp: bin_rsplit_def bin_rsplit_aux_len)


[STATEMENT]
lemma bin_rsplit_aux_len_indep:
  "n \<noteq> 0 \<Longrightarrow> length bs = length cs \<Longrightarrow>
    length (bin_rsplit_aux n nw v bs) =
    length (bin_rsplit_aux n nw w cs)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>n \<noteq> 0; length bs = length cs\<rbrakk> \<Longrightarrow> length (bin_rsplit_aux n nw v bs) = length (bin_rsplit_aux n nw w cs)
[PROOF STEP]
proof (induct n nw w cs arbitrary: v bs rule: bin_rsplit_aux.induct)
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>n m c bs v bsa. \<lbrakk>\<And>x xa y v bsa. \<lbrakk>\<not> (m = 0 \<or> n = 0); x = bin_split n c; (xa, y) = x; n \<noteq> 0; length bsa = length (y # bs)\<rbrakk> \<Longrightarrow> length (bin_rsplit_aux n (m - n) v bsa) = length (bin_rsplit_aux n (m - n) xa (y # bs)); n \<noteq> 0; length bsa = length bs\<rbrakk> \<Longrightarrow> length (bin_rsplit_aux n m v bsa) = length (bin_rsplit_aux n m c bs)
[PROOF STEP]
case (1 n m w cs v bs)
[PROOF STATE]
proof (state)
this:
\<lbrakk>\<not> (m = 0 \<or> n = 0); ?x = bin_split n w; (?xa, ?y) = ?x; n \<noteq> 0; length ?bs = length (?y # cs)\<rbrakk> \<Longrightarrow> length (bin_rsplit_aux n (m - n) ?v ?bs) = length (bin_rsplit_aux n (m - n) ?xa (?y # cs))
n \<noteq> 0
length bs = length cs

goal (1 subgoal):
 1. \<And>n m c bs v bsa. \<lbrakk>\<And>x xa y v bsa. \<lbrakk>\<not> (m = 0 \<or> n = 0); x = bin_split n c; (xa, y) = x; n \<noteq> 0; length bsa = length (y # bs)\<rbrakk> \<Longrightarrow> length (bin_rsplit_aux n (m - n) v bsa) = length (bin_rsplit_aux n (m - n) xa (y # bs)); n \<noteq> 0; length bsa = length bs\<rbrakk> \<Longrightarrow> length (bin_rsplit_aux n m v bsa) = length (bin_rsplit_aux n m c bs)
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. length (bin_rsplit_aux n m v bs) = length (bin_rsplit_aux n m w cs)
[PROOF STEP]
proof (cases "m = 0")
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. m = 0 \<Longrightarrow> length (bin_rsplit_aux n m v bs) = length (bin_rsplit_aux n m w cs)
 2. m \<noteq> 0 \<Longrightarrow> length (bin_rsplit_aux n m v bs) = length (bin_rsplit_aux n m w cs)
[PROOF STEP]
case True
[PROOF STATE]
proof (state)
this:
m = 0

goal (2 subgoals):
 1. m = 0 \<Longrightarrow> length (bin_rsplit_aux n m v bs) = length (bin_rsplit_aux n m w cs)
 2. m \<noteq> 0 \<Longrightarrow> length (bin_rsplit_aux n m v bs) = length (bin_rsplit_aux n m w cs)
[PROOF STEP]
with \<open>length bs = length cs\<close>
[PROOF STATE]
proof (chain)
picking this:
length bs = length cs
m = 0
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
length bs = length cs
m = 0

goal (1 subgoal):
 1. length (bin_rsplit_aux n m v bs) = length (bin_rsplit_aux n m w cs)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
length (bin_rsplit_aux n m v bs) = length (bin_rsplit_aux n m w cs)

goal (1 subgoal):
 1. m \<noteq> 0 \<Longrightarrow> length (bin_rsplit_aux n m v bs) = length (bin_rsplit_aux n m w cs)
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. m \<noteq> 0 \<Longrightarrow> length (bin_rsplit_aux n m v bs) = length (bin_rsplit_aux n m w cs)
[PROOF STEP]
case False
[PROOF STATE]
proof (state)
this:
m \<noteq> 0

goal (1 subgoal):
 1. m \<noteq> 0 \<Longrightarrow> length (bin_rsplit_aux n m v bs) = length (bin_rsplit_aux n m w cs)
[PROOF STEP]
from "1.hyps" [of \<open>bin_split n w\<close> \<open>drop_bit n w\<close> \<open>take_bit n w\<close>] \<open>m \<noteq> 0\<close> \<open>n \<noteq> 0\<close>
[PROOF STATE]
proof (chain)
picking this:
\<lbrakk>\<not> (m = 0 \<or> n = 0); bin_split n w = bin_split n w; (drop_bit n w, take_bit n w) = bin_split n w; n \<noteq> 0; length ?bs = length (take_bit n w # cs)\<rbrakk> \<Longrightarrow> length (bin_rsplit_aux n (m - n) ?v ?bs) = length (bin_rsplit_aux n (m - n) (drop_bit n w) (take_bit n w # cs))
m \<noteq> 0
n \<noteq> 0
[PROOF STEP]
have hyp: "\<And>v bs. length bs = Suc (length cs) \<Longrightarrow>
      length (bin_rsplit_aux n (m - n) v bs) =
      length (bin_rsplit_aux n (m - n) (drop_bit n w) (take_bit n w # cs))"
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>\<not> (m = 0 \<or> n = 0); bin_split n w = bin_split n w; (drop_bit n w, take_bit n w) = bin_split n w; n \<noteq> 0; length ?bs = length (take_bit n w # cs)\<rbrakk> \<Longrightarrow> length (bin_rsplit_aux n (m - n) ?v ?bs) = length (bin_rsplit_aux n (m - n) (drop_bit n w) (take_bit n w # cs))
m \<noteq> 0
n \<noteq> 0

goal (1 subgoal):
 1. \<And>v bs. length bs = Suc (length cs) \<Longrightarrow> length (bin_rsplit_aux n (m - n) v bs) = length (bin_rsplit_aux n (m - n) (drop_bit n w) (take_bit n w # cs))
[PROOF STEP]
using bin_rsplit_aux_len
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>\<not> (m = 0 \<or> n = 0); bin_split n w = bin_split n w; (drop_bit n w, take_bit n w) = bin_split n w; n \<noteq> 0; length ?bs = length (take_bit n w # cs)\<rbrakk> \<Longrightarrow> length (bin_rsplit_aux n (m - n) ?v ?bs) = length (bin_rsplit_aux n (m - n) (drop_bit n w) (take_bit n w # cs))
m \<noteq> 0
n \<noteq> 0
?n \<noteq> 0 \<Longrightarrow> length (bin_rsplit_aux ?n ?nw ?w ?cs) = (?nw + ?n - 1) div ?n + length ?cs

goal (1 subgoal):
 1. \<And>v bs. length bs = Suc (length cs) \<Longrightarrow> length (bin_rsplit_aux n (m - n) v bs) = length (bin_rsplit_aux n (m - n) (drop_bit n w) (take_bit n w # cs))
[PROOF STEP]
by fastforce
[PROOF STATE]
proof (state)
this:
length ?bs = Suc (length cs) \<Longrightarrow> length (bin_rsplit_aux n (m - n) ?v ?bs) = length (bin_rsplit_aux n (m - n) (drop_bit n w) (take_bit n w # cs))

goal (1 subgoal):
 1. m \<noteq> 0 \<Longrightarrow> length (bin_rsplit_aux n m v bs) = length (bin_rsplit_aux n m w cs)
[PROOF STEP]
from \<open>length bs = length cs\<close> \<open>n \<noteq> 0\<close>
[PROOF STATE]
proof (chain)
picking this:
length bs = length cs
n \<noteq> 0
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
length bs = length cs
n \<noteq> 0

goal (1 subgoal):
 1. length (bin_rsplit_aux n m v bs) = length (bin_rsplit_aux n m w cs)
[PROOF STEP]
by (auto simp add: bin_rsplit_aux_simp_alt Let_def bin_rsplit_len split: prod.split)
[PROOF STATE]
proof (state)
this:
length (bin_rsplit_aux n m v bs) = length (bin_rsplit_aux n m w cs)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
length (bin_rsplit_aux n m v bs) = length (bin_rsplit_aux n m w cs)

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma bin_rsplit_len_indep:
  "n \<noteq> 0 \<Longrightarrow> length (bin_rsplit n (nw, v)) = length (bin_rsplit n (nw, w))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. n \<noteq> 0 \<Longrightarrow> length (bin_rsplit n (nw, v)) = length (bin_rsplit n (nw, w))
[PROOF STEP]
apply (unfold bin_rsplit_def)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. n \<noteq> 0 \<Longrightarrow> length (bin_rsplit_aux n (fst (nw, v)) (snd (nw, v)) []) = length (bin_rsplit_aux n (fst (nw, w)) (snd (nw, w)) [])
[PROOF STEP]
apply (simp (no_asm))
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. n \<noteq> 0 \<Longrightarrow> length (bin_rsplit_aux n nw v []) = length (bin_rsplit_aux n nw w [])
[PROOF STEP]
apply (erule bin_rsplit_aux_len_indep)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. length [] = length []
[PROOF STEP]
apply (rule refl)
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done


[STATEMENT]
lemma bin_sc_0 [simp]:
  "bin_sc 0 b w = of_bool b + 2 * (\<lambda>k::int. k div 2) w"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. set_bit_class.set_bit w 0 b = of_bool b + 2 * (w div 2)
[PROOF STEP]
by (simp add: set_bit_int_def)


[STATEMENT]
lemma bin_sc_Suc [simp]:
  "bin_sc (Suc n) b w = of_bool (odd w) + 2 * bin_sc n b (w div 2)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. set_bit_class.set_bit w (Suc n) b = of_bool (odd w) + 2 * set_bit_class.set_bit (w div 2) n b
[PROOF STEP]
by (simp add: set_bit_int_def set_bit_Suc unset_bit_Suc bin_last_def)


[STATEMENT]
lemma bin_nth_sc [bit_simps]: "bit (bin_sc n b w) n \<longleftrightarrow> b"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. bit (set_bit_class.set_bit w n b) n = b
[PROOF STEP]
by (simp add: bit_simps)


[STATEMENT]
lemma bin_sc_sc_same [simp]: "bin_sc n c (bin_sc n b w) = bin_sc n c w"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. set_bit_class.set_bit (set_bit_class.set_bit w n b) n c = set_bit_class.set_bit w n c
[PROOF STEP]
by (induction n arbitrary: w) (simp_all add: bit_Suc)


[STATEMENT]
lemma bin_sc_sc_diff: "m \<noteq> n \<Longrightarrow> bin_sc m c (bin_sc n b w) = bin_sc n b (bin_sc m c w)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. m \<noteq> n \<Longrightarrow> set_bit_class.set_bit (set_bit_class.set_bit w n b) m c = set_bit_class.set_bit (set_bit_class.set_bit w m c) n b
[PROOF STEP]
apply (induct n arbitrary: w m)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. \<And>w m. m \<noteq> 0 \<Longrightarrow> set_bit_class.set_bit (set_bit_class.set_bit w 0 b) m c = set_bit_class.set_bit (set_bit_class.set_bit w m c) 0 b
 2. \<And>n w m. \<lbrakk>\<And>w m. m \<noteq> n \<Longrightarrow> set_bit_class.set_bit (set_bit_class.set_bit w n b) m c = set_bit_class.set_bit (set_bit_class.set_bit w m c) n b; m \<noteq> Suc n\<rbrakk> \<Longrightarrow> set_bit_class.set_bit (set_bit_class.set_bit w (Suc n) b) m c = set_bit_class.set_bit (set_bit_class.set_bit w m c) (Suc n) b
[PROOF STEP]
apply (case_tac [!] m)
[PROOF STATE]
proof (prove)
goal (4 subgoals):
 1. \<And>w m. \<lbrakk>m \<noteq> 0; m = 0\<rbrakk> \<Longrightarrow> set_bit_class.set_bit (set_bit_class.set_bit w 0 b) m c = set_bit_class.set_bit (set_bit_class.set_bit w m c) 0 b
 2. \<And>w m nat. \<lbrakk>m \<noteq> 0; m = Suc nat\<rbrakk> \<Longrightarrow> set_bit_class.set_bit (set_bit_class.set_bit w 0 b) m c = set_bit_class.set_bit (set_bit_class.set_bit w m c) 0 b
 3. \<And>n w m. \<lbrakk>\<And>w m. m \<noteq> n \<Longrightarrow> set_bit_class.set_bit (set_bit_class.set_bit w n b) m c = set_bit_class.set_bit (set_bit_class.set_bit w m c) n b; m \<noteq> Suc n; m = 0\<rbrakk> \<Longrightarrow> set_bit_class.set_bit (set_bit_class.set_bit w (Suc n) b) m c = set_bit_class.set_bit (set_bit_class.set_bit w m c) (Suc n) b
 4. \<And>n w m nat. \<lbrakk>\<And>w m. m \<noteq> n \<Longrightarrow> set_bit_class.set_bit (set_bit_class.set_bit w n b) m c = set_bit_class.set_bit (set_bit_class.set_bit w m c) n b; m \<noteq> Suc n; m = Suc nat\<rbrakk> \<Longrightarrow> set_bit_class.set_bit (set_bit_class.set_bit w (Suc n) b) m c = set_bit_class.set_bit (set_bit_class.set_bit w m c) (Suc n) b
[PROOF STEP]
apply auto
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done


[STATEMENT]
lemma bin_nth_sc_gen: "(bit :: int \<Rightarrow> nat \<Rightarrow> bool) (bin_sc n b w) m = (if m = n then b else (bit :: int \<Rightarrow> nat \<Rightarrow> bool) w m)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. bit (set_bit_class.set_bit w n b) m = (if m = n then b else bit w m)
[PROOF STEP]
by (simp add: bit_simps)


[STATEMENT]
lemma bin_sc_eq:
  \<open>bin_sc n False = unset_bit n\<close>
  \<open>bin_sc n True = Bit_Operations.set_bit n\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<lambda>i. set_bit_class.set_bit i n False) = unset_bit n &&& (\<lambda>i. set_bit_class.set_bit i n True) = semiring_bit_operations_class.set_bit n
[PROOF STEP]
apply (simp_all add: fun_eq_iff bit_eq_iff)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. \<forall>x na. bit (set_bit_class.set_bit x n False) na = bit (unset_bit n x) na
 2. \<forall>x na. bit (set_bit_class.set_bit x n True) na = bit (semiring_bit_operations_class.set_bit n x) na
[PROOF STEP]
apply (simp_all add: bit_simps bin_nth_sc_gen)
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done


[STATEMENT]
lemma bin_sc_nth [simp]: "bin_sc n ((bit :: int \<Rightarrow> nat \<Rightarrow> bool) w n) w = w"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. set_bit_class.set_bit w n (bit w n) = w
[PROOF STEP]
by (rule bit_eqI) (simp add: bin_nth_sc_gen)


[STATEMENT]
lemma bin_sign_sc [simp]: "bin_sign (bin_sc n b w) = bin_sign w"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. bin_sign (set_bit_class.set_bit w n b) = bin_sign w
[PROOF STEP]
proof (induction n arbitrary: w)
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. \<And>w. bin_sign (set_bit_class.set_bit w 0 b) = bin_sign w
 2. \<And>n w. (\<And>w. bin_sign (set_bit_class.set_bit w n b) = bin_sign w) \<Longrightarrow> bin_sign (set_bit_class.set_bit w (Suc n) b) = bin_sign w
[PROOF STEP]
case 0
[PROOF STATE]
proof (state)
this:

goal (2 subgoals):
 1. \<And>w. bin_sign (set_bit_class.set_bit w 0 b) = bin_sign w
 2. \<And>n w. (\<And>w. bin_sign (set_bit_class.set_bit w n b) = bin_sign w) \<Longrightarrow> bin_sign (set_bit_class.set_bit w (Suc n) b) = bin_sign w
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. bin_sign (set_bit_class.set_bit w 0 b) = bin_sign w
[PROOF STEP]
by (auto simp add: bin_sign_def) (use bin_rest_ge_0 in fastforce)
[PROOF STATE]
proof (state)
this:
bin_sign (set_bit_class.set_bit w 0 b) = bin_sign w

goal (1 subgoal):
 1. \<And>n w. (\<And>w. bin_sign (set_bit_class.set_bit w n b) = bin_sign w) \<Longrightarrow> bin_sign (set_bit_class.set_bit w (Suc n) b) = bin_sign w
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>n w. (\<And>w. bin_sign (set_bit_class.set_bit w n b) = bin_sign w) \<Longrightarrow> bin_sign (set_bit_class.set_bit w (Suc n) b) = bin_sign w
[PROOF STEP]
case (Suc n)
[PROOF STATE]
proof (state)
this:
bin_sign (set_bit_class.set_bit ?w n b) = bin_sign ?w

goal (1 subgoal):
 1. \<And>n w. (\<And>w. bin_sign (set_bit_class.set_bit w n b) = bin_sign w) \<Longrightarrow> bin_sign (set_bit_class.set_bit w (Suc n) b) = bin_sign w
[PROOF STEP]
from Suc [of \<open>w div 2\<close>]
[PROOF STATE]
proof (chain)
picking this:
bin_sign (set_bit_class.set_bit (w div 2) n b) = bin_sign (w div 2)
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
using this:
bin_sign (set_bit_class.set_bit (w div 2) n b) = bin_sign (w div 2)

goal (1 subgoal):
 1. bin_sign (set_bit_class.set_bit w (Suc n) b) = bin_sign w
[PROOF STEP]
by (auto simp add: bin_sign_def split: if_splits)
[PROOF STATE]
proof (state)
this:
bin_sign (set_bit_class.set_bit w (Suc n) b) = bin_sign w

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma bin_sc_bintr [simp]:
  "(take_bit :: nat \<Rightarrow> int \<Rightarrow> int) m (bin_sc n x ((take_bit :: nat \<Rightarrow> int \<Rightarrow> int) m w)) = (take_bit :: nat \<Rightarrow> int \<Rightarrow> int) m (bin_sc n x w)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. take_bit m (set_bit_class.set_bit (take_bit m w) n x) = take_bit m (set_bit_class.set_bit w n x)
[PROOF STEP]
apply (rule bit_eqI)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>na. possible_bit TYPE(int) na \<Longrightarrow> bit (take_bit m (set_bit_class.set_bit (take_bit m w) n x)) na = bit (take_bit m (set_bit_class.set_bit w n x)) na
[PROOF STEP]
apply (cases x)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. \<And>na. \<lbrakk>possible_bit TYPE(int) na; x\<rbrakk> \<Longrightarrow> bit (take_bit m (set_bit_class.set_bit (take_bit m w) n x)) na = bit (take_bit m (set_bit_class.set_bit w n x)) na
 2. \<And>na. \<lbrakk>possible_bit TYPE(int) na; \<not> x\<rbrakk> \<Longrightarrow> bit (take_bit m (set_bit_class.set_bit (take_bit m w) n x)) na = bit (take_bit m (set_bit_class.set_bit w n x)) na
[PROOF STEP]
apply (auto simp add: bit_simps bin_sc_eq)
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done


[STATEMENT]
lemma bin_clr_le: "bin_sc n False w \<le> w"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. set_bit_class.set_bit w n False \<le> w
[PROOF STEP]
by (simp add: set_bit_int_def unset_bit_less_eq)


[STATEMENT]
lemma bin_set_ge: "bin_sc n True w \<ge> w"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. w \<le> set_bit_class.set_bit w n True
[PROOF STEP]
by (simp add: set_bit_int_def set_bit_greater_eq)


[STATEMENT]
lemma bintr_bin_clr_le: "(take_bit :: nat \<Rightarrow> int \<Rightarrow> int) n (bin_sc m False w) \<le> (take_bit :: nat \<Rightarrow> int \<Rightarrow> int) n w"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. take_bit n (set_bit_class.set_bit w m False) \<le> take_bit n w
[PROOF STEP]
by (simp add: set_bit_int_def take_bit_unset_bit_eq unset_bit_less_eq)


[STATEMENT]
lemma bintr_bin_set_ge: "(take_bit :: nat \<Rightarrow> int \<Rightarrow> int) n (bin_sc m True w) \<ge> (take_bit :: nat \<Rightarrow> int \<Rightarrow> int) n w"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. take_bit n w \<le> take_bit n (set_bit_class.set_bit w m True)
[PROOF STEP]
by (simp add: set_bit_int_def take_bit_set_bit_eq set_bit_greater_eq)


[STATEMENT]
lemma bin_sc_FP [simp]: "bin_sc n False 0 = 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. set_bit_class.set_bit 0 n False = 0
[PROOF STEP]
by (induct n) auto


[STATEMENT]
lemma bin_sc_TM [simp]: "bin_sc n True (- 1) = - 1"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. set_bit_class.set_bit (- 1) n True = - 1
[PROOF STEP]
by (induct n) auto


[STATEMENT]
lemma bin_sc_minus: "0 < n \<Longrightarrow> bin_sc (Suc (n - 1)) b w = bin_sc n b w"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 0 < n \<Longrightarrow> set_bit_class.set_bit w (Suc (n - 1)) b = set_bit_class.set_bit w n b
[PROOF STEP]
by auto


[STATEMENT]
lemma bin_sc_numeral [simp]:
  "bin_sc (numeral k) b w =
    of_bool (odd w) + 2 * bin_sc (pred_numeral k) b (w div 2)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. set_bit_class.set_bit w (numeral k) b = of_bool (odd w) + 2 * set_bit_class.set_bit (w div 2) (pred_numeral k) b
[PROOF STEP]
by (simp add: numeral_eq_Suc)


[STATEMENT]
lemma int_set_bit_0 [simp]: fixes x :: int shows
  "set_bit x 0 b = of_bool b + 2 * (x div 2)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. set_bit_class.set_bit x 0 b = of_bool b + 2 * (x div 2)
[PROOF STEP]
by (fact bin_sc_0)


[STATEMENT]
lemma int_set_bit_Suc: fixes x :: int shows
  "set_bit x (Suc n) b = of_bool (odd x) + 2 * set_bit (x div 2) n b"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. set_bit_class.set_bit x (Suc n) b = of_bool (odd x) + 2 * set_bit_class.set_bit (x div 2) n b
[PROOF STEP]
by (fact bin_sc_Suc)


[STATEMENT]
lemma bin_last_set_bit:
  "odd (set_bit x n b :: int) = (if n > 0 then odd x else b)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. odd (set_bit_class.set_bit x n b) = (if 0 < n then odd x else b)
[PROOF STEP]
by (cases n) (simp_all add: int_set_bit_Suc)


[STATEMENT]
lemma bin_rest_set_bit:
  "(set_bit x n b :: int) div 2 = (if n > 0 then set_bit (x div 2) (n - 1) b else x div 2)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. set_bit_class.set_bit x n b div 2 = (if 0 < n then set_bit_class.set_bit (x div 2) (n - 1) b else x div 2)
[PROOF STEP]
by (cases n) (simp_all add: int_set_bit_Suc)


[STATEMENT]
lemma int_set_bit_numeral: fixes x :: int shows
  "set_bit x (numeral w) b = of_bool (odd x) + 2 * set_bit (x div 2) (pred_numeral w) b"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. set_bit_class.set_bit x (numeral w) b = of_bool (odd x) + 2 * set_bit_class.set_bit (x div 2) (pred_numeral w) b
[PROOF STEP]
by (fact bin_sc_numeral)


[STATEMENT]
lemma msb_set_bit [simp]:
  "msb (set_bit (x :: int) n b) \<longleftrightarrow> msb x"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. msb (set_bit_class.set_bit x n b) = msb x
[PROOF STEP]
by (simp add: msb_int_def set_bit_int_def)


[STATEMENT]
lemma word_set_bit_def:
  \<open>set_bit a n x = word_of_int (bin_sc n x (uint a))\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. set_bit_class.set_bit a n x = word_of_int (set_bit_class.set_bit (uint a) n x)
[PROOF STEP]
apply (rule bit_word_eqI)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>na. na < LENGTH('a) \<Longrightarrow> bit (set_bit_class.set_bit a n x) na = bit (word_of_int (set_bit_class.set_bit (uint a) n x)) na
[PROOF STEP]
apply (cases x)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. \<And>na. \<lbrakk>na < LENGTH('a); x\<rbrakk> \<Longrightarrow> bit (set_bit_class.set_bit a n x) na = bit (word_of_int (set_bit_class.set_bit (uint a) n x)) na
 2. \<And>na. \<lbrakk>na < LENGTH('a); \<not> x\<rbrakk> \<Longrightarrow> bit (set_bit_class.set_bit a n x) na = bit (word_of_int (set_bit_class.set_bit (uint a) n x)) na
[PROOF STEP]
apply (simp_all add: bit_simps bin_sc_eq)
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done


[STATEMENT]
lemma set_bit_word_of_int:
  "set_bit (word_of_int x) n b = word_of_int (bin_sc n b x)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. set_bit_class.set_bit (word_of_int x) n b = word_of_int (set_bit_class.set_bit x n b)
[PROOF STEP]
unfolding word_set_bit_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. word_of_int (set_bit_class.set_bit (uint (word_of_int x)) n b) = word_of_int (set_bit_class.set_bit x n b)
[PROOF STEP]
by (rule word_eqI) (simp add: word_size bin_nth_sc_gen nth_bintr bit_simps)


[STATEMENT]
lemma word_set_numeral [simp]:
  "set_bit (numeral bin::'a::len word) n b =
    word_of_int (bin_sc n b (numeral bin))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. set_bit_class.set_bit (numeral bin) n b = word_of_int (set_bit_class.set_bit (numeral bin) n b)
[PROOF STEP]
unfolding word_numeral_alt
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. set_bit_class.set_bit (word_of_int (numeral bin)) n b = word_of_int (set_bit_class.set_bit (numeral bin) n b)
[PROOF STEP]
by (rule set_bit_word_of_int)


[STATEMENT]
lemma word_set_neg_numeral [simp]:
  "set_bit (- numeral bin::'a::len word) n b =
    word_of_int (bin_sc n b (- numeral bin))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. set_bit_class.set_bit (- numeral bin) n b = word_of_int (set_bit_class.set_bit (- numeral bin) n b)
[PROOF STEP]
unfolding word_neg_numeral_alt
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. set_bit_class.set_bit (word_of_int (- numeral bin)) n b = word_of_int (set_bit_class.set_bit (- numeral bin) n b)
[PROOF STEP]
by (rule set_bit_word_of_int)


[STATEMENT]
lemma word_set_bit_0 [simp]: "set_bit 0 n b = word_of_int (bin_sc n b 0)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. set_bit_class.set_bit 0 n b = word_of_int (set_bit_class.set_bit 0 n b)
[PROOF STEP]
unfolding word_0_wi
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. set_bit_class.set_bit (word_of_int 0) n b = word_of_int (set_bit_class.set_bit 0 n b)
[PROOF STEP]
by (rule set_bit_word_of_int)


[STATEMENT]
lemma word_set_bit_1 [simp]: "set_bit 1 n b = word_of_int (bin_sc n b 1)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. set_bit_class.set_bit 1 n b = word_of_int (set_bit_class.set_bit 1 n b)
[PROOF STEP]
unfolding word_1_wi
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. set_bit_class.set_bit (word_of_int 1) n b = word_of_int (set_bit_class.set_bit 1 n b)
[PROOF STEP]
by (rule set_bit_word_of_int)


[STATEMENT]
lemma int_not_simps:
  "NOT (0::int) = -1"
  "NOT (1::int) = -2"
  "NOT (- 1::int) = 0"
  "NOT (numeral w::int) = - numeral (w + Num.One)"
  "NOT (- numeral (Num.Bit0 w)::int) = numeral (Num.BitM w)"
  "NOT (- numeral (Num.Bit1 w)::int) = numeral (Num.Bit0 w)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (NOT 0 = - 1 &&& NOT 1 = - 2 &&& NOT (- 1) = 0) &&& NOT (numeral w) = - numeral (w + num.One) &&& NOT (- numeral (num.Bit0 w)) = numeral (Num.BitM w) &&& NOT (- numeral (num.Bit1 w)) = numeral (num.Bit0 w)
[PROOF STEP]
by (simp_all add: not_int_def)


[STATEMENT]
lemma int_not_not: "NOT (NOT x) = x"
  for x :: int
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. NOT (NOT x) = x
[PROOF STEP]
by (fact bit.double_compl)


[STATEMENT]
lemma int_and_0 [simp]: "0 AND x = 0"
  for x :: int
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 0 AND x = 0
[PROOF STEP]
by (fact bit.conj_zero_left)


[STATEMENT]
lemma int_and_m1 [simp]: "-1 AND x = x"
  for x :: int
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. - 1 AND x = x
[PROOF STEP]
by (fact and.left_neutral)


[STATEMENT]
lemma int_or_minus1 [simp]: "-1 OR x = -1"
  for x :: int
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. - 1 OR x = - 1
[PROOF STEP]
by (fact bit.disj_one_left)


[STATEMENT]
lemma int_xor_zero [simp]: "0 XOR x = x"
  for x :: int
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 0 XOR x = x
[PROOF STEP]
by (fact xor.left_neutral)


[STATEMENT]
lemma bin_rest_NOT [simp]: "(\<lambda>k::int. k div 2) (NOT x) = NOT ((\<lambda>k::int. k div 2) x)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. NOT x div 2 = NOT (x div 2)
[PROOF STEP]
by (fact not_int_div_2)


[STATEMENT]
lemma bin_last_NOT [simp]: "(odd :: int \<Rightarrow> bool) (NOT x) \<longleftrightarrow> \<not> (odd :: int \<Rightarrow> bool) x"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. odd (NOT x) = (\<not> odd x)
[PROOF STEP]
by simp


[STATEMENT]
lemma bin_rest_AND [simp]: "(\<lambda>k::int. k div 2) (x AND y) = (\<lambda>k::int. k div 2) x AND (\<lambda>k::int. k div 2) y"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (x AND y) div 2 = x div 2 AND y div 2
[PROOF STEP]
by (subst and_int_rec) auto


[STATEMENT]
lemma bin_last_AND [simp]: "(odd :: int \<Rightarrow> bool) (x AND y) \<longleftrightarrow> (odd :: int \<Rightarrow> bool) x \<and> (odd :: int \<Rightarrow> bool) y"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. odd (x AND y) = (odd x \<and> odd y)
[PROOF STEP]
by (subst and_int_rec) auto


[STATEMENT]
lemma bin_rest_OR [simp]: "(\<lambda>k::int. k div 2) (x OR y) = (\<lambda>k::int. k div 2) x OR (\<lambda>k::int. k div 2) y"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (x OR y) div 2 = x div 2 OR y div 2
[PROOF STEP]
by (subst or_int_rec) auto


[STATEMENT]
lemma bin_last_OR [simp]: "(odd :: int \<Rightarrow> bool) (x OR y) \<longleftrightarrow> (odd :: int \<Rightarrow> bool) x \<or> (odd :: int \<Rightarrow> bool) y"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. odd (x OR y) = (odd x \<or> odd y)
[PROOF STEP]
by (subst or_int_rec) auto


[STATEMENT]
lemma bin_rest_XOR [simp]: "(\<lambda>k::int. k div 2) (x XOR y) = (\<lambda>k::int. k div 2) x XOR (\<lambda>k::int. k div 2) y"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (x XOR y) div 2 = x div 2 XOR y div 2
[PROOF STEP]
by (subst xor_int_rec) auto


[STATEMENT]
lemma bin_last_XOR [simp]: "(odd :: int \<Rightarrow> bool) (x XOR y) \<longleftrightarrow> ((odd :: int \<Rightarrow> bool) x \<or> (odd :: int \<Rightarrow> bool) y) \<and> \<not> ((odd :: int \<Rightarrow> bool) x \<and> (odd :: int \<Rightarrow> bool) y)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. odd (x XOR y) = ((odd x \<or> odd y) \<and> \<not> (odd x \<and> odd y))
[PROOF STEP]
by (subst xor_int_rec) auto


[STATEMENT]
lemma bin_nth_ops:
  "\<And>x y. (bit :: int \<Rightarrow> nat \<Rightarrow> bool) (x AND y) n \<longleftrightarrow> (bit :: int \<Rightarrow> nat \<Rightarrow> bool) x n \<and> (bit :: int \<Rightarrow> nat \<Rightarrow> bool) y n"
  "\<And>x y. (bit :: int \<Rightarrow> nat \<Rightarrow> bool) (x OR y) n \<longleftrightarrow> (bit :: int \<Rightarrow> nat \<Rightarrow> bool) x n \<or> (bit :: int \<Rightarrow> nat \<Rightarrow> bool) y n"
  "\<And>x y. (bit :: int \<Rightarrow> nat \<Rightarrow> bool) (x XOR y) n \<longleftrightarrow> (bit :: int \<Rightarrow> nat \<Rightarrow> bool) x n \<noteq> (bit :: int \<Rightarrow> nat \<Rightarrow> bool) y n"
  "\<And>x. (bit :: int \<Rightarrow> nat \<Rightarrow> bool) (NOT x) n \<longleftrightarrow> \<not> (bit :: int \<Rightarrow> nat \<Rightarrow> bool) x n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ((\<And>x y. bit (x AND y) n = (bit x n \<and> bit y n)) &&& (\<And>x y. bit (x OR y) n = (bit x n \<or> bit y n))) &&& (\<And>x y. bit (x XOR y) n = (bit x n \<noteq> bit y n)) &&& (\<And>x. bit (NOT x) n = (\<not> bit x n))
[PROOF STEP]
by (simp_all add: bit_and_iff bit_or_iff bit_xor_iff bit_not_iff)


[STATEMENT]
lemma int_xor_minus1 [simp]: "-1 XOR x = NOT x"
  for x :: int
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. - 1 XOR x = NOT x
[PROOF STEP]
by (fact bit.xor_one_left)


[STATEMENT]
lemma int_xor_extra_simps [simp]:
  "w XOR 0 = w"
  "w XOR -1 = NOT w"
  for w :: int
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. w XOR 0 = w &&& w XOR - 1 = NOT w
[PROOF STEP]
by simp_all


[STATEMENT]
lemma int_or_extra_simps [simp]:
  "w OR 0 = w"
  "w OR -1 = -1"
  for w :: int
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. w OR 0 = w &&& w OR - 1 = - 1
[PROOF STEP]
by simp_all


[STATEMENT]
lemma int_and_extra_simps [simp]:
  "w AND 0 = 0"
  "w AND -1 = w"
  for w :: int
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. w AND 0 = 0 &&& w AND - 1 = w
[PROOF STEP]
by simp_all


[STATEMENT]
lemma bin_ops_comm:
  fixes x y :: int
  shows int_and_comm: "x AND y = y AND x"
    and int_or_comm:  "x OR y = y OR x"
    and int_xor_comm: "x XOR y = y XOR x"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x AND y = y AND x &&& x OR y = y OR x &&& x XOR y = y XOR x
[PROOF STEP]
by (simp_all add: ac_simps)


[STATEMENT]
lemma bin_ops_same [simp]:
  "x AND x = x"
  "x OR x = x"
  "x XOR x = 0"
  for x :: int
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x AND x = x &&& x OR x = x &&& x XOR x = 0
[PROOF STEP]
by simp_all


[STATEMENT]
lemma bbw_ao_absorb: "x AND (y OR x) = x \<and> x OR (y AND x) = x"
  for x y :: int
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x AND (y OR x) = x \<and> x OR y AND x = x
[PROOF STEP]
by (auto simp add: bin_eq_iff bin_nth_ops)


[STATEMENT]
lemma bbw_ao_absorbs_other:
  "x AND (x OR y) = x \<and> (y AND x) OR x = x"
  "(y OR x) AND x = x \<and> x OR (x AND y) = x"
  "(x OR y) AND x = x \<and> (x AND y) OR x = x"
  for x y :: int
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x AND (x OR y) = x \<and> y AND x OR x = x &&& (y OR x) AND x = x \<and> x OR x AND y = x &&& (x OR y) AND x = x \<and> x AND y OR x = x
[PROOF STEP]
by (auto simp add: bin_eq_iff bin_nth_ops)


[STATEMENT]
lemma int_xor_not: "(NOT x) XOR y = NOT (x XOR y) \<and> x XOR (NOT y) = NOT (x XOR y)"
  for x y :: int
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. NOT x XOR y = NOT (x XOR y) \<and> x XOR NOT y = NOT (x XOR y)
[PROOF STEP]
by (auto simp add: bin_eq_iff bin_nth_ops)


[STATEMENT]
lemma int_and_assoc: "(x AND y) AND z = x AND (y AND z)"
  for x y z :: int
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (x AND y) AND z = x AND y AND z
[PROOF STEP]
by (auto simp add: bin_eq_iff bin_nth_ops)


[STATEMENT]
lemma int_or_assoc: "(x OR y) OR z = x OR (y OR z)"
  for x y z :: int
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (x OR y) OR z = x OR y OR z
[PROOF STEP]
by (auto simp add: bin_eq_iff bin_nth_ops)


[STATEMENT]
lemma int_xor_assoc: "(x XOR y) XOR z = x XOR (y XOR z)"
  for x y z :: int
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (x XOR y) XOR z = x XOR y XOR z
[PROOF STEP]
by (auto simp add: bin_eq_iff bin_nth_ops)


[STATEMENT]
lemma bbw_lcs [simp]:
  "y AND (x AND z) = x AND (y AND z)"
  "y OR (x OR z) = x OR (y OR z)"
  "y XOR (x XOR z) = x XOR (y XOR z)"
  for x y :: int
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. y AND x AND z = x AND y AND z &&& y OR x OR z = x OR y OR z &&& y XOR x XOR z = x XOR y XOR z
[PROOF STEP]
by (auto simp add: bin_eq_iff bin_nth_ops)


[STATEMENT]
lemma bbw_not_dist:
  "NOT (x OR y) = (NOT x) AND (NOT y)"
  "NOT (x AND y) = (NOT x) OR (NOT y)"
  for x y :: int
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. NOT (x OR y) = NOT x AND NOT y &&& NOT (x AND y) = NOT x OR NOT y
[PROOF STEP]
by (auto simp add: bin_eq_iff bin_nth_ops)


[STATEMENT]
lemma bbw_oa_dist: "(x AND y) OR z = (x OR z) AND (y OR z)"
  for x y z :: int
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x AND y OR z = (x OR z) AND (y OR z)
[PROOF STEP]
by (auto simp add: bin_eq_iff bin_nth_ops)


[STATEMENT]
lemma bbw_ao_dist: "(x OR y) AND z = (x AND z) OR (y AND z)"
  for x y z :: int
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (x OR y) AND z = x AND z OR y AND z
[PROOF STEP]
by (auto simp add: bin_eq_iff bin_nth_ops)


[STATEMENT]
lemma bin_rest_neg_numeral_BitM [simp]:
  "(\<lambda>k::int. k div 2) (- numeral (Num.BitM w)) = - numeral w"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. - numeral (Num.BitM w) div 2 = - numeral w
[PROOF STEP]
by simp


[STATEMENT]
lemma bin_last_neg_numeral_BitM [simp]:
  "(odd :: int \<Rightarrow> bool) (- numeral (Num.BitM w))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. odd (- numeral (Num.BitM w))
[PROOF STEP]
by simp


[STATEMENT]
lemma le_int_or: "bin_sign y = 0 \<Longrightarrow> x \<le> x OR y"
  for x y :: int
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. bin_sign y = 0 \<Longrightarrow> x \<le> x OR y
[PROOF STEP]
by (simp add: bin_sign_def or_greater_eq split: if_splits)


[STATEMENT]
lemma bin_add_not: "x + NOT x = (-1::int)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x + NOT x = - 1
[PROOF STEP]
by (simp add: not_int_def)


[STATEMENT]
lemma AND_mod: "x AND (2 ^ n - 1) = x mod 2 ^ n"
  for x :: int
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x AND 2 ^ n - 1 = x mod 2 ^ n
[PROOF STEP]
by (simp flip: take_bit_eq_mod add: take_bit_eq_mask mask_eq_exp_minus_1)


[STATEMENT]
lemma bin_trunc_ao:
  "(take_bit :: nat \<Rightarrow> int \<Rightarrow> int) n x AND (take_bit :: nat \<Rightarrow> int \<Rightarrow> int) n y = (take_bit :: nat \<Rightarrow> int \<Rightarrow> int) n (x AND y)"
  "(take_bit :: nat \<Rightarrow> int \<Rightarrow> int) n x OR (take_bit :: nat \<Rightarrow> int \<Rightarrow> int) n y = (take_bit :: nat \<Rightarrow> int \<Rightarrow> int) n (x OR y)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. take_bit n x AND take_bit n y = take_bit n (x AND y) &&& take_bit n x OR take_bit n y = take_bit n (x OR y)
[PROOF STEP]
by simp_all


[STATEMENT]
lemma bin_trunc_xor: "(take_bit :: nat \<Rightarrow> int \<Rightarrow> int) n ((take_bit :: nat \<Rightarrow> int \<Rightarrow> int) n x XOR (take_bit :: nat \<Rightarrow> int \<Rightarrow> int) n y) = (take_bit :: nat \<Rightarrow> int \<Rightarrow> int) n (x XOR y)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. take_bit n (take_bit n x XOR take_bit n y) = take_bit n (x XOR y)
[PROOF STEP]
by simp


[STATEMENT]
lemma bin_trunc_not: "(take_bit :: nat \<Rightarrow> int \<Rightarrow> int) n (NOT ((take_bit :: nat \<Rightarrow> int \<Rightarrow> int) n x)) = (take_bit :: nat \<Rightarrow> int \<Rightarrow> int) n (NOT x)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. take_bit n (NOT (take_bit n x)) = take_bit n (NOT x)
[PROOF STEP]
by (fact take_bit_not_take_bit)


[STATEMENT]
lemma bintr_bintr_i: "x = (take_bit :: nat \<Rightarrow> int \<Rightarrow> int) n y \<Longrightarrow> (take_bit :: nat \<Rightarrow> int \<Rightarrow> int) n x = (take_bit :: nat \<Rightarrow> int \<Rightarrow> int) n y"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x = take_bit n y \<Longrightarrow> take_bit n x = take_bit n y
[PROOF STEP]
by auto


[STATEMENT]
lemma not_int_cmp_0 [simp]:
  fixes i :: int shows
  "0 < NOT i \<longleftrightarrow> i < -1"
  "0 \<le> NOT i \<longleftrightarrow> i < 0"
  "NOT i < 0 \<longleftrightarrow> i \<ge> 0"
  "NOT i \<le> 0 \<longleftrightarrow> i \<ge> -1"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ((0 < NOT i) = (i < - 1) &&& (0 \<le> NOT i) = (i < 0)) &&& (NOT i < 0) = (0 \<le> i) &&& (NOT i \<le> 0) = (- 1 \<le> i)
[PROOF STEP]
by(simp_all add: int_not_def) arith+


[STATEMENT]
lemma bbw_ao_dist2: "(x :: int) AND (y OR z) = x AND y OR x AND z"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x AND (y OR z) = x AND y OR x AND z
[PROOF STEP]
by (fact bit.conj_disj_distrib)


[STATEMENT]
lemma int_nand_same [simp]: fixes x :: int shows "x AND NOT x = 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x AND NOT x = 0
[PROOF STEP]
by simp


[STATEMENT]
lemma int_nand_same_middle: fixes x :: int shows "x AND y AND NOT x = 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x AND y AND NOT x = 0
[PROOF STEP]
by (simp add: bit_eq_iff bit_and_iff bit_not_iff)


[STATEMENT]
lemma and_xor_dist: fixes x :: int shows
  "x AND (y XOR z) = (x AND y) XOR (x AND z)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x AND (y XOR z) = x AND y XOR x AND z
[PROOF STEP]
by (fact bit.conj_xor_distrib)


[STATEMENT]
lemma int_and_lt0 [simp]:
  \<open>x AND y < 0 \<longleftrightarrow> x < 0 \<and> y < 0\<close> for x y :: int
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (x AND y < 0) = (x < 0 \<and> y < 0)
[PROOF STEP]
by (fact and_negative_int_iff)


[STATEMENT]
lemma int_and_ge0 [simp]:
  \<open>x AND y \<ge> 0 \<longleftrightarrow> x \<ge> 0 \<or> y \<ge> 0\<close> for x y :: int
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (0 \<le> x AND y) = (0 \<le> x \<or> 0 \<le> y)
[PROOF STEP]
by (fact and_nonnegative_int_iff)


[STATEMENT]
lemma int_and_1: fixes x :: int shows "x AND 1 = x mod 2"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x AND 1 = x mod 2
[PROOF STEP]
by (fact and_one_eq)


[STATEMENT]
lemma int_1_and: fixes x :: int shows "1 AND x = x mod 2"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 1 AND x = x mod 2
[PROOF STEP]
by (fact one_and_eq)


[STATEMENT]
lemma int_or_lt0 [simp]:
  \<open>x OR y < 0 \<longleftrightarrow> x < 0 \<or> y < 0\<close> for x y :: int
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (x OR y < 0) = (x < 0 \<or> y < 0)
[PROOF STEP]
by (fact or_negative_int_iff)


[STATEMENT]
lemma int_or_ge0 [simp]:
  \<open>x OR y \<ge> 0 \<longleftrightarrow> x \<ge> 0 \<and> y \<ge> 0\<close> for x y :: int
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (0 \<le> x OR y) = (0 \<le> x \<and> 0 \<le> y)
[PROOF STEP]
by (fact or_nonnegative_int_iff)


[STATEMENT]
lemma int_xor_lt0 [simp]:
  \<open>x XOR y < 0 \<longleftrightarrow> (x < 0) \<noteq> (y < 0)\<close> for x y :: int
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (x XOR y < 0) = ((x < 0) \<noteq> (y < 0))
[PROOF STEP]
by (fact xor_negative_int_iff)


[STATEMENT]
lemma int_xor_ge0 [simp]:
  \<open>x XOR y \<ge> 0 \<longleftrightarrow> (x \<ge> 0 \<longleftrightarrow> y \<ge> 0)\<close> for x y :: int
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (0 \<le> x XOR y) = ((0 \<le> x) = (0 \<le> y))
[PROOF STEP]
by (fact xor_nonnegative_int_iff)


[STATEMENT]
lemma even_conv_AND:
  \<open>even i \<longleftrightarrow> i AND 1 = 0\<close> for i :: int
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. even i = (i AND 1 = 0)
[PROOF STEP]
by (simp add: and_one_eq mod2_eq_if)


[STATEMENT]
lemma bin_last_conv_AND:
  "(odd :: int \<Rightarrow> bool) i \<longleftrightarrow> i AND 1 \<noteq> 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. odd i = (i AND 1 \<noteq> 0)
[PROOF STEP]
by (simp add: and_one_eq mod2_eq_if)


[STATEMENT]
lemma bitval_bin_last:
  "of_bool ((odd :: int \<Rightarrow> bool) i) = i AND 1"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. of_bool (odd i) = i AND 1
[PROOF STEP]
by (simp add: and_one_eq mod2_eq_if)


[STATEMENT]
lemma bin_sign_and:
  "bin_sign (i AND j) = - (bin_sign i * bin_sign j)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. bin_sign (i AND j) = - (bin_sign i * bin_sign j)
[PROOF STEP]
by(simp add: bin_sign_def)


[STATEMENT]
lemma int_not_neg_numeral: "NOT (- numeral n) = (Num.sub n num.One :: int)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. NOT (- numeral n) = neg_numeral_class.sub n num.One
[PROOF STEP]
by(simp add: int_not_def)


[STATEMENT]
lemma int_neg_numeral_pOne_conv_not: "- numeral (n + num.One) = (NOT (numeral n) :: int)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. - numeral (n + num.One) = NOT (numeral n)
[PROOF STEP]
by(simp add: int_not_def)


[STATEMENT]
lemma int_shiftl_BIT: fixes x :: int
  shows int_shiftl0: "x << 0 = x"
  and int_shiftl_Suc: "x << Suc n = 2 * x << n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x << 0 = x &&& x << Suc n = 2 * x << n
[PROOF STEP]
by (auto simp add: shiftl_int_def)


[STATEMENT]
lemma int_0_shiftl: "push_bit n 0 = (0 :: int)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. push_bit n 0 = 0
[PROOF STEP]
by (fact push_bit_of_0)


[STATEMENT]
lemma bin_last_shiftl: "odd (push_bit n x) \<longleftrightarrow> n = 0 \<and> (odd :: int \<Rightarrow> bool) x"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. odd (push_bit n x) = (n = 0 \<and> odd x)
[PROOF STEP]
by simp


[STATEMENT]
lemma bin_rest_shiftl: "(\<lambda>k::int. k div 2) (push_bit n x) = (if n > 0 then push_bit (n - 1) x else (\<lambda>k::int. k div 2) x)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. push_bit n x div 2 = (if 0 < n then push_bit (n - 1) x else x div 2)
[PROOF STEP]
by (cases n) (simp_all add: push_bit_eq_mult)


[STATEMENT]
lemma bin_nth_shiftl: "(bit :: int \<Rightarrow> nat \<Rightarrow> bool) (push_bit n x) m \<longleftrightarrow> n \<le> m \<and> (bit :: int \<Rightarrow> nat \<Rightarrow> bool) x (m - n)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. bit (push_bit n x) m = (n \<le> m \<and> bit x (m - n))
[PROOF STEP]
by (fact bit_push_bit_iff_int)


[STATEMENT]
lemma bin_last_shiftr: "odd (drop_bit n x) \<longleftrightarrow> bit x n" for x :: int
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. odd (drop_bit n x) = bit x n
[PROOF STEP]
by (simp add: bit_iff_odd_drop_bit)


[STATEMENT]
lemma bin_rest_shiftr: "(\<lambda>k::int. k div 2) (drop_bit n x) = drop_bit (Suc n) x"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. drop_bit n x div 2 = drop_bit (Suc n) x
[PROOF STEP]
by (simp add: drop_bit_Suc drop_bit_half)


[STATEMENT]
lemma bin_nth_shiftr: "(bit :: int \<Rightarrow> nat \<Rightarrow> bool) (drop_bit n x) m = (bit :: int \<Rightarrow> nat \<Rightarrow> bool) x (n + m)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. bit (drop_bit n x) m = bit x (n + m)
[PROOF STEP]
by (simp add: bit_simps)


[STATEMENT]
lemma bin_nth_conv_AND:
  fixes x :: int shows
  "(bit :: int \<Rightarrow> nat \<Rightarrow> bool) x n \<longleftrightarrow> x AND (push_bit n 1) \<noteq> 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. bit x n = (x AND push_bit n 1 \<noteq> 0)
[PROOF STEP]
by (fact bit_iff_and_push_bit_not_eq_0)


[STATEMENT]
lemma int_shiftl_numeral [simp]:
  "push_bit (numeral w') (numeral w :: int) = push_bit (pred_numeral w') (numeral (num.Bit0 w))"
  "push_bit (numeral w') (- numeral w :: int) = push_bit (pred_numeral w') (- numeral (num.Bit0 w))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. push_bit (numeral w') (numeral w) = push_bit (pred_numeral w') (numeral (num.Bit0 w)) &&& push_bit (numeral w') (- numeral w) = push_bit (pred_numeral w') (- numeral (num.Bit0 w))
[PROOF STEP]
by(simp_all add: numeral_eq_Suc shiftl_int_def)
  (metis add_One mult_inc semiring_norm(11) semiring_norm(13) semiring_norm(2) semiring_norm(6) semiring_norm(87))+


[STATEMENT]
lemma int_shiftl_One_numeral [simp]:
  "push_bit (numeral w) (1::int) = push_bit (pred_numeral w) 2"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. push_bit (numeral w) 1 = push_bit (pred_numeral w) 2
[PROOF STEP]
using int_shiftl_numeral [of Num.One w]
[PROOF STATE]
proof (prove)
using this:
push_bit Numeral1 (numeral w) = push_bit (pred_numeral num.One) (numeral (num.Bit0 w))
push_bit Numeral1 (- numeral w) = push_bit (pred_numeral num.One) (- numeral (num.Bit0 w))

goal (1 subgoal):
 1. push_bit (numeral w) 1 = push_bit (pred_numeral w) 2
[PROOF STEP]
by (simp only: numeral_eq_Suc push_bit_Suc) simp


[STATEMENT]
lemma shiftl_ge_0: fixes i :: int shows "push_bit n i \<ge> 0 \<longleftrightarrow> i \<ge> 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (0 \<le> push_bit n i) = (0 \<le> i)
[PROOF STEP]
by (fact push_bit_nonnegative_int_iff)


[STATEMENT]
lemma shiftl_lt_0: fixes i :: int shows "push_bit n i < 0 \<longleftrightarrow> i < 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (push_bit n i < 0) = (i < 0)
[PROOF STEP]
by (fact push_bit_negative_int_iff)


[STATEMENT]
lemma int_shiftl_test_bit: "bit (push_bit i n :: int) m \<longleftrightarrow> m \<ge> i \<and> bit n (m - i)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. bit (push_bit i n) m = (i \<le> m \<and> bit n (m - i))
[PROOF STEP]
by (fact bit_push_bit_iff_int)


[STATEMENT]
lemma int_0shiftr: "drop_bit x (0 :: int) = 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. drop_bit x 0 = 0
[PROOF STEP]
by (fact drop_bit_of_0)


[STATEMENT]
lemma int_minus1_shiftr: "drop_bit x (-1 :: int) = -1"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. drop_bit x (- 1) = - 1
[PROOF STEP]
by (fact drop_bit_minus_one)


[STATEMENT]
lemma int_shiftr_ge_0: fixes i :: int shows "drop_bit n i \<ge> 0 \<longleftrightarrow> i \<ge> 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (0 \<le> drop_bit n i) = (0 \<le> i)
[PROOF STEP]
by (fact drop_bit_nonnegative_int_iff)


[STATEMENT]
lemma int_shiftr_lt_0 [simp]: fixes i :: int shows "drop_bit n i < 0 \<longleftrightarrow> i < 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (drop_bit n i < 0) = (i < 0)
[PROOF STEP]
by (fact drop_bit_negative_int_iff)


[STATEMENT]
lemma int_shiftr_numeral [simp]:
  "drop_bit (numeral w') (1 :: int) = 0"
  "drop_bit (numeral w') (numeral num.One :: int) = 0"
  "drop_bit (numeral w') (numeral (num.Bit0 w) :: int) = drop_bit (pred_numeral w') (numeral w)"
  "drop_bit (numeral w') (numeral (num.Bit1 w) :: int) = drop_bit (pred_numeral w') (numeral w)"
  "drop_bit (numeral w') (- numeral (num.Bit0 w) :: int) = drop_bit (pred_numeral w') (- numeral w)"
  "drop_bit (numeral w') (- numeral (num.Bit1 w) :: int) = drop_bit (pred_numeral w') (- numeral (Num.inc w))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (drop_bit (numeral w') 1 = 0 &&& drop_bit (numeral w') Numeral1 = 0 &&& drop_bit (numeral w') (numeral (num.Bit0 w)) = drop_bit (pred_numeral w') (numeral w)) &&& drop_bit (numeral w') (numeral (num.Bit1 w)) = drop_bit (pred_numeral w') (numeral w) &&& drop_bit (numeral w') (- numeral (num.Bit0 w)) = drop_bit (pred_numeral w') (- numeral w) &&& drop_bit (numeral w') (- numeral (num.Bit1 w)) = drop_bit (pred_numeral w') (- numeral (Num.inc w))
[PROOF STEP]
by (simp_all add: numeral_eq_Suc add_One drop_bit_Suc)


[STATEMENT]
lemma int_shiftr_numeral_Suc0 [simp]:
  "drop_bit (Suc 0) (1 :: int) = 0"
  "drop_bit (Suc 0) (numeral num.One :: int) = 0"
  "drop_bit (Suc 0) (numeral (num.Bit0 w) :: int) = numeral w"
  "drop_bit (Suc 0) (numeral (num.Bit1 w) :: int) = numeral w"
  "drop_bit (Suc 0) (- numeral (num.Bit0 w) :: int) = - numeral w"
  "drop_bit (Suc 0) (- numeral (num.Bit1 w) :: int) = - numeral (Num.inc w)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (drop_bit (Suc 0) 1 = 0 &&& drop_bit (Suc 0) Numeral1 = 0 &&& drop_bit (Suc 0) (numeral (num.Bit0 w)) = numeral w) &&& drop_bit (Suc 0) (numeral (num.Bit1 w)) = numeral w &&& drop_bit (Suc 0) (- numeral (num.Bit0 w)) = - numeral w &&& drop_bit (Suc 0) (- numeral (num.Bit1 w)) = - numeral (Num.inc w)
[PROOF STEP]
by (simp_all add: drop_bit_Suc add_One)


[STATEMENT]
lemma bin_nth_minus_p2:
  assumes sign: "bin_sign x = 0"
    and y: "y = push_bit n 1"
    and m: "m < n"
    and x: "x < y"
  shows "bit (x - y) m = bit x m"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. bit (x - y) m = bit x m
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. bit (x - y) m = bit x m
[PROOF STEP]
from \<open>bin_sign x = 0\<close>
[PROOF STATE]
proof (chain)
picking this:
bin_sign x = 0
[PROOF STEP]
have \<open>x \<ge> 0\<close>
[PROOF STATE]
proof (prove)
using this:
bin_sign x = 0

goal (1 subgoal):
 1. 0 \<le> x
[PROOF STEP]
by (simp add: sign_Pls_ge_0)
[PROOF STATE]
proof (state)
this:
0 \<le> x

goal (1 subgoal):
 1. bit (x - y) m = bit x m
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
0 \<le> x

goal (1 subgoal):
 1. bit (x - y) m = bit x m
[PROOF STEP]
from x y
[PROOF STATE]
proof (chain)
picking this:
x < y
y = push_bit n 1
[PROOF STEP]
have \<open>x < 2 ^ n\<close>
[PROOF STATE]
proof (prove)
using this:
x < y
y = push_bit n 1

goal (1 subgoal):
 1. x < 2 ^ n
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
x < 2 ^ n

goal (1 subgoal):
 1. bit (x - y) m = bit x m
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
0 \<le> x
x < 2 ^ n
[PROOF STEP]
have \<open>q < n\<close> if \<open>bit x q\<close> for q
[PROOF STATE]
proof (prove)
using this:
0 \<le> x
x < 2 ^ n

goal (1 subgoal):
 1. q < n
[PROOF STEP]
using that
[PROOF STATE]
proof (prove)
using this:
0 \<le> x
x < 2 ^ n
bit x q

goal (1 subgoal):
 1. q < n
[PROOF STEP]
by (metis bit_take_bit_iff take_bit_int_eq_self)
[PROOF STATE]
proof (state)
this:
bit x ?q \<Longrightarrow> ?q < n

goal (1 subgoal):
 1. bit (x - y) m = bit x m
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
bit x ?q \<Longrightarrow> ?q < n
[PROOF STEP]
have \<open>bit (x + NOT (mask n)) m = bit x m\<close>
[PROOF STATE]
proof (prove)
using this:
bit x ?q \<Longrightarrow> ?q < n

goal (1 subgoal):
 1. bit (x + NOT (mask n)) m = bit x m
[PROOF STEP]
using \<open>m < n\<close>
[PROOF STATE]
proof (prove)
using this:
bit x ?q \<Longrightarrow> ?q < n
m < n

goal (1 subgoal):
 1. bit (x + NOT (mask n)) m = bit x m
[PROOF STEP]
by (simp add: disjunctive_add bit_simps)
[PROOF STATE]
proof (state)
this:
bit (x + NOT (mask n)) m = bit x m

goal (1 subgoal):
 1. bit (x - y) m = bit x m
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
bit (x + NOT (mask n)) m = bit x m

goal (1 subgoal):
 1. bit (x - y) m = bit x m
[PROOF STEP]
have \<open>x + NOT (mask n) = x - y\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x + NOT (mask n) = x - y
[PROOF STEP]
using y
[PROOF STATE]
proof (prove)
using this:
y = push_bit n 1

goal (1 subgoal):
 1. x + NOT (mask n) = x - y
[PROOF STEP]
by (simp flip: minus_exp_eq_not_mask)
[PROOF STATE]
proof (state)
this:
x + NOT (mask n) = x - y

goal (1 subgoal):
 1. bit (x - y) m = bit x m
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
bit (x - y) m = bit x m
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
bit (x - y) m = bit x m

goal (1 subgoal):
 1. bit (x - y) m = bit x m
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
bit (x - y) m = bit x m

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma bin_clr_conv_NAND:
  "bin_sc n False i = i AND NOT (push_bit n 1)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. set_bit_class.set_bit i n False = i AND NOT (push_bit n 1)
[PROOF STEP]
by (rule bit_eqI) (auto simp add: bin_sc_eq bit_simps)


[STATEMENT]
lemma bin_set_conv_OR:
  "bin_sc n True i = i OR (push_bit n 1)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. set_bit_class.set_bit i n True = i OR push_bit n 1
[PROOF STEP]
by (rule bit_eqI) (auto simp add: bin_sc_eq bit_simps)


[STATEMENT]
lemma msb_conv_bin_sign:
  "msb x \<longleftrightarrow> bin_sign x = -1"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. msb x = (bin_sign x = - 1)
[PROOF STEP]
by (simp add: bin_sign_def not_le msb_int_def)


[STATEMENT]
lemma msb_bin_sc:
  "msb (bin_sc n b x) \<longleftrightarrow> msb x"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. msb (set_bit_class.set_bit x n b) = msb x
[PROOF STEP]
by (simp add: msb_conv_bin_sign)


[STATEMENT]
lemma msb_word_def:
  \<open>msb a \<longleftrightarrow> bin_sign (signed_take_bit (LENGTH('a) - 1) (uint a)) = - 1\<close>
  for a :: \<open>'a::len word\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. msb a = (bin_sign (signed_take_bit (LENGTH('a) - 1) (uint a)) = - 1)
[PROOF STEP]
by (simp add: bin_sign_def bit_simps msb_word_iff_bit)


[STATEMENT]
lemma word_msb_def:
  "msb a \<longleftrightarrow> bin_sign (sint a) = - 1"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. msb a = (bin_sign (sint a) = - 1)
[PROOF STEP]
by (simp add: msb_word_def sint_uint)


[STATEMENT]
lemma word_rcat_eq:
  \<open>word_rcat ws = word_of_int (bin_rcat (LENGTH('a::len)) (map uint ws))\<close>
  for ws :: \<open>'a::len word list\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. word_rcat ws = word_of_int (bin_rcat LENGTH('a) (map uint ws))
[PROOF STEP]
apply (simp add: word_rcat_def bin_rcat_def rev_map)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. word_of_int (horner_sum uint (2 ^ LENGTH('a)) (rev ws)) = word_of_int (horner_sum (take_bit LENGTH('a)) (2 ^ LENGTH('a)) (map uint (rev ws)))
[PROOF STEP]
apply transfer
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>ws. take_bit LENGTH('b) (horner_sum (take_bit LENGTH('a)) (2 ^ LENGTH('a)) (rev ws)) = take_bit LENGTH('b) (horner_sum (take_bit LENGTH('a)) (2 ^ LENGTH('a)) (map (take_bit LENGTH('a)) (rev ws)))
[PROOF STEP]
apply (simp add: horner_sum_foldr foldr_map comp_def)
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done


[STATEMENT]
lemma sign_uint_Pls [simp]: "bin_sign (uint x) = 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. bin_sign (uint x) = 0
[PROOF STEP]
by (simp add: sign_Pls_ge_0)


[STATEMENT]
lemma setBit_no: "Bit_Operations.set_bit n (numeral bin) = word_of_int (bin_sc n True (numeral bin))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. semiring_bit_operations_class.set_bit n (numeral bin) = word_of_int (set_bit_class.set_bit (numeral bin) n True)
[PROOF STEP]
by (rule bit_word_eqI) (simp add: bit_simps)


[STATEMENT]
lemma clearBit_no:
  "unset_bit n (numeral bin) = word_of_int (bin_sc n False (numeral bin))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. unset_bit n (numeral bin) = word_of_int (set_bit_class.set_bit (numeral bin) n False)
[PROOF STEP]
by (rule bit_word_eqI) (simp add: bit_simps)


[STATEMENT]
lemma eq_mod_iff: "0 < n \<Longrightarrow> b = b mod n \<longleftrightarrow> 0 \<le> b \<and> b < n"
  for b n :: int
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 0 < n \<Longrightarrow> (b = b mod n) = (0 \<le> b \<and> b < n)
[PROOF STEP]
using pos_mod_sign [of n b] pos_mod_bound [of n b]
[PROOF STATE]
proof (prove)
using this:
0 < n \<Longrightarrow> 0 \<le> b mod n
0 < n \<Longrightarrow> b mod n < n

goal (1 subgoal):
 1. 0 < n \<Longrightarrow> (b = b mod n) = (0 \<le> b \<and> b < n)
[PROOF STEP]
by (safe, auto)


[STATEMENT]
lemma split_uint_lem: "bin_split n (uint w) = (a, b) \<Longrightarrow>
    a = take_bit (LENGTH('a) - n) a \<and> b = take_bit (LENGTH('a)) b"
  for w :: "'a::len word"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. bin_split n (uint w) = (a, b) \<Longrightarrow> a = take_bit (LENGTH('a) - n) a \<and> b = take_bit LENGTH('a) b
[PROOF STEP]
by transfer (simp add: drop_bit_take_bit ac_simps)

\<comment> \<open>limited hom result\<close>


[STATEMENT]
lemma word_cat_hom:
  "LENGTH('a::len) \<le> LENGTH('b::len) + LENGTH('c::len) \<Longrightarrow>
    (word_cat (word_of_int w :: 'b word) (b :: 'c word) :: 'a word) =
    word_of_int ((\<lambda>k n l. concat_bit n l k) w (size b) (uint b))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. LENGTH('a) \<le> LENGTH('b) + LENGTH('c) \<Longrightarrow> word_cat (word_of_int w) b = word_of_int (concat_bit (size b) (uint b) w)
[PROOF STEP]
by transfer (simp add: take_bit_concat_bit_eq)


[STATEMENT]
lemma bintrunc_shiftl:
  "take_bit n (push_bit i m) = push_bit i (take_bit (n - i) m)"
  for m :: int
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. take_bit n (push_bit i m) = push_bit i (take_bit (n - i) m)
[PROOF STEP]
by (fact take_bit_push_bit)


[STATEMENT]
lemma uint_shiftl:
  "uint (push_bit i n) = take_bit (size n) (push_bit i (uint n))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. uint (push_bit i n) = take_bit (size n) (push_bit i (uint n))
[PROOF STEP]
by (simp add: unsigned_push_bit_eq word_size)


[STATEMENT]
lemma bin_mask_conv_pow2:
  "mask n = 2 ^ n - (1 :: int)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. mask n = 2 ^ n - 1
[PROOF STEP]
by (fact mask_eq_exp_minus_1)


[STATEMENT]
lemma bin_mask_ge0: "mask n \<ge> (0 :: int)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 0 \<le> mask n
[PROOF STEP]
by (fact mask_nonnegative_int)


[STATEMENT]
lemma and_bin_mask_conv_mod: "x AND mask n = x mod 2 ^ n"
  for x :: int
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x AND mask n = x mod 2 ^ n
[PROOF STEP]
by (simp flip: take_bit_eq_mod add: take_bit_eq_mask)


[STATEMENT]
lemma bin_mask_numeral:
  "mask (numeral n) = (1 :: int) + 2 * mask (pred_numeral n)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. mask (numeral n) = 1 + 2 * mask (pred_numeral n)
[PROOF STEP]
by (fact mask_numeral)


[STATEMENT]
lemma bin_nth_mask: "bit (mask n :: int) i \<longleftrightarrow> i < n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. bit (mask n) i = (i < n)
[PROOF STEP]
by (simp add: bit_mask_iff)