src/HOL/Word/Bit_Representation.thy
changeset 46600 d6847e6b62db
parent 46599 102a06189a6c
child 46601 be67deaea760
equal deleted inserted replaced
46599:102a06189a6c 46600:d6847e6b62db
    33   "bin_rest w BIT bin_last w = w"
    33   "bin_rest w BIT bin_last w = w"
    34   unfolding bin_rest_def bin_last_def Bit_def
    34   unfolding bin_rest_def bin_last_def Bit_def
    35   using mod_div_equality [of w 2]
    35   using mod_div_equality [of w 2]
    36   by (cases "w mod 2 = 0", simp_all)
    36   by (cases "w mod 2 = 0", simp_all)
    37 
    37 
    38 lemma bin_rest_BIT: "bin_rest (x BIT b) = x"
    38 lemma bin_rest_BIT [simp]: "bin_rest (x BIT b) = x"
    39   unfolding bin_rest_def Bit_def
    39   unfolding bin_rest_def Bit_def
    40   by (cases b, simp_all)
    40   by (cases b, simp_all)
    41 
    41 
    42 lemma bin_last_BIT: "bin_last (x BIT b) = b"
    42 lemma bin_last_BIT [simp]: "bin_last (x BIT b) = b"
    43   unfolding bin_last_def Bit_def
    43   unfolding bin_last_def Bit_def
    44   by (cases b, simp_all add: z1pmod2)
    44   by (cases b, simp_all add: z1pmod2)
    45 
    45 
    46 lemma BIT_eq_iff [iff]: "u BIT b = v BIT c \<longleftrightarrow> u = v \<and> b = c"
    46 lemma BIT_eq_iff [iff]: "u BIT b = v BIT c \<longleftrightarrow> u = v \<and> b = c"
    47   by (metis bin_rest_BIT bin_last_BIT)
    47   by (metis bin_rest_BIT bin_last_BIT)
   207 lemma bin_rest_simps [simp]: 
   207 lemma bin_rest_simps [simp]: 
   208   "bin_rest Int.Pls = Int.Pls"
   208   "bin_rest Int.Pls = Int.Pls"
   209   "bin_rest Int.Min = Int.Min"
   209   "bin_rest Int.Min = Int.Min"
   210   "bin_rest (Int.Bit0 w) = w"
   210   "bin_rest (Int.Bit0 w) = w"
   211   "bin_rest (Int.Bit1 w) = w"
   211   "bin_rest (Int.Bit1 w) = w"
   212   "bin_rest (w BIT b) = w"
       
   213   using bin_rl_simps bin_rl_def by auto
   212   using bin_rl_simps bin_rl_def by auto
   214 
   213 
   215 lemma bin_last_simps [simp]: 
   214 lemma bin_last_simps [simp]: 
   216   "bin_last Int.Pls = (0::bit)"
   215   "bin_last Int.Pls = (0::bit)"
   217   "bin_last Int.Min = (1::bit)"
   216   "bin_last Int.Min = (1::bit)"
   218   "bin_last (Int.Bit0 w) = (0::bit)"
   217   "bin_last (Int.Bit0 w) = (0::bit)"
   219   "bin_last (Int.Bit1 w) = (1::bit)"
   218   "bin_last (Int.Bit1 w) = (1::bit)"
   220   "bin_last (w BIT b) = b"
       
   221   using bin_rl_simps bin_rl_def by auto
   219   using bin_rl_simps bin_rl_def by auto
   222 
   220 
   223 lemma Bit_div2 [simp]: "(w BIT b) div 2 = w"
   221 lemma Bit_div2 [simp]: "(w BIT b) div 2 = w"
   224   unfolding bin_rest_def [symmetric] by auto
   222   unfolding bin_rest_def [symmetric] by (rule bin_rest_BIT)
   225 
   223 
   226 lemma bin_nth_lem [rule_format]:
   224 lemma bin_nth_lem [rule_format]:
   227   "ALL y. bin_nth x = bin_nth y --> x = y"
   225   "ALL y. bin_nth x = bin_nth y --> x = y"
   228   apply (induct x rule: bin_induct)
   226   apply (induct x rule: bin_induct [unfolded Pls_def Min_def])
   229     apply safe
   227     apply safe
   230     apply (erule rev_mp)
   228     apply (erule rev_mp)
   231     apply (induct_tac y rule: bin_induct)
   229     apply (induct_tac y rule: bin_induct [unfolded Pls_def Min_def])
   232       apply safe
   230       apply safe
   233       apply (drule_tac x=0 in fun_cong, force)
   231       apply (drule_tac x=0 in fun_cong, force)
   234      apply (erule notE, rule ext, 
   232      apply (erule notE, rule ext, 
   235             drule_tac x="Suc x" in fun_cong, force)
   233             drule_tac x="Suc x" in fun_cong, force)
   236     apply (drule_tac x=0 in fun_cong, force simp: BIT_simps)
   234     apply (drule_tac x=0 in fun_cong, force)
   237    apply (erule rev_mp)
   235    apply (erule rev_mp)
   238    apply (induct_tac y rule: bin_induct)
   236    apply (induct_tac y rule: bin_induct [unfolded Pls_def Min_def])
   239      apply safe
   237      apply safe
   240      apply (drule_tac x=0 in fun_cong, force)
   238      apply (drule_tac x=0 in fun_cong, force)
   241     apply (erule notE, rule ext, 
   239     apply (erule notE, rule ext, 
   242            drule_tac x="Suc x" in fun_cong, force)
   240            drule_tac x="Suc x" in fun_cong, force)
   243    apply (drule_tac x=0 in fun_cong, force simp: BIT_simps)
   241    apply (drule_tac x=0 in fun_cong, force)
   244   apply (case_tac y rule: bin_exhaust)
   242   apply (case_tac y rule: bin_exhaust)
   245   apply clarify
   243   apply clarify
   246   apply (erule allE)
   244   apply (erule allE)
   247   apply (erule impE)
   245   apply (erule impE)
   248    prefer 2
   246    prefer 2
   451 
   449 
   452 lemmas bintrunc_Min [simp] = 
   450 lemmas bintrunc_Min [simp] = 
   453   bintrunc.Suc [where bin="Int.Min", simplified bin_last_simps bin_rest_simps]
   451   bintrunc.Suc [where bin="Int.Min", simplified bin_last_simps bin_rest_simps]
   454 
   452 
   455 lemmas bintrunc_BIT  [simp] = 
   453 lemmas bintrunc_BIT  [simp] = 
   456   bintrunc.Suc [where bin="w BIT b", simplified bin_last_simps bin_rest_simps] for w b
   454   bintrunc.Suc [where bin="w BIT b", simplified bin_last_BIT bin_rest_BIT] for w b
   457 
   455 
   458 lemma bintrunc_Bit0 [simp]:
   456 lemma bintrunc_Bit0 [simp]:
   459   "bintrunc (Suc n) (Int.Bit0 w) = Int.Bit0 (bintrunc n w)"
   457   "bintrunc (Suc n) (Int.Bit0 w) = Int.Bit0 (bintrunc n w)"
   460   using bintrunc_BIT [where b="(0::bit)"] by (simp add: BIT_simps)
   458   using bintrunc_BIT [where b="(0::bit)"] by (simp add: BIT_simps)
   461 
   459 
   472 
   470 
   473 lemmas sbintrunc_Suc_Min = 
   471 lemmas sbintrunc_Suc_Min = 
   474   sbintrunc.Suc [where bin="Int.Min", simplified bin_last_simps bin_rest_simps]
   472   sbintrunc.Suc [where bin="Int.Min", simplified bin_last_simps bin_rest_simps]
   475 
   473 
   476 lemmas sbintrunc_Suc_BIT [simp] = 
   474 lemmas sbintrunc_Suc_BIT [simp] = 
   477   sbintrunc.Suc [where bin="w BIT b", simplified bin_last_simps bin_rest_simps] for w b
   475   sbintrunc.Suc [where bin="w BIT b", simplified bin_last_BIT bin_rest_BIT] for w b
   478 
   476 
   479 lemma sbintrunc_Suc_Bit0 [simp]:
   477 lemma sbintrunc_Suc_Bit0 [simp]:
   480   "sbintrunc (Suc n) (Int.Bit0 w) = Int.Bit0 (sbintrunc n w)"
   478   "sbintrunc (Suc n) (Int.Bit0 w) = Int.Bit0 (sbintrunc n w)"
   481   using sbintrunc_Suc_BIT [where b="(0::bit)"] by (simp add: BIT_simps)
   479   using sbintrunc_Suc_BIT [where b="(0::bit)"] by (simp add: BIT_simps)
   482 
   480