src/HOL/Word/WordBitwise.thy
changeset 61799 4cf66f21b764
parent 61144 5e94dfead1c2
child 62390 842917225d56
equal deleted inserted replaced
61798:27f3c10b0b50 61799:4cf66f21b764
     7 
     7 
     8 imports Word
     8 imports Word
     9 
     9 
    10 begin
    10 begin
    11 
    11 
    12 text {* Helper constants used in defining addition *}
    12 text \<open>Helper constants used in defining addition\<close>
    13 
    13 
    14 definition
    14 definition
    15   xor3 :: "bool \<Rightarrow> bool \<Rightarrow> bool \<Rightarrow> bool"
    15   xor3 :: "bool \<Rightarrow> bool \<Rightarrow> bool \<Rightarrow> bool"
    16 where
    16 where
    17  "xor3 a b c = (a = (b = c))"
    17  "xor3 a b c = (a = (b = c))"
    37   "xor3 False a b = (a \<noteq> b)"
    37   "xor3 False a b = (a \<noteq> b)"
    38   "xor3 a False b = (a \<noteq> b)"
    38   "xor3 a False b = (a \<noteq> b)"
    39   "xor3 a b False = (a \<noteq> b)"
    39   "xor3 a b False = (a \<noteq> b)"
    40   by (simp_all add: xor3_def)
    40   by (simp_all add: xor3_def)
    41 
    41 
    42 text {* Breaking up word equalities into equalities on their
    42 text \<open>Breaking up word equalities into equalities on their
    43 bit lists. Equalities are generated and manipulated in the
    43 bit lists. Equalities are generated and manipulated in the
    44 reverse order to to_bl. *}
    44 reverse order to to_bl.\<close>
    45 
    45 
    46 lemma word_eq_rbl_eq:
    46 lemma word_eq_rbl_eq:
    47   "(x = y) = (rev (to_bl x) = rev (to_bl y))"
    47   "(x = y) = (rev (to_bl x) = rev (to_bl y))"
    48   by simp
    48   by simp
    49 
    49 
   320   fixes x :: "'a :: len word"
   320   fixes x :: "'a :: len word"
   321   shows "rev (to_bl (x * y)) = rbl_mul (rev (to_bl x)) (rev (to_bl y))"
   321   shows "rev (to_bl (x * y)) = rbl_mul (rev (to_bl x)) (rev (to_bl y))"
   322   using word_rbl_mul_induct[where xs="rev (to_bl x)" and y=y]
   322   using word_rbl_mul_induct[where xs="rev (to_bl x)" and y=y]
   323   by (simp add: word_size)
   323   by (simp add: word_size)
   324 
   324 
   325 text {* Breaking up inequalities into bitlist properties. *}
   325 text \<open>Breaking up inequalities into bitlist properties.\<close>
   326 
   326 
   327 definition
   327 definition
   328   "rev_bl_order F xs ys =
   328   "rev_bl_order F xs ys =
   329      (length xs = length ys \<and>
   329      (length xs = length ys \<and>
   330        ((xs = ys \<and> F)
   330        ((xs = ys \<and> F)
   447    apply (cases "to_bl y", simp)
   447    apply (cases "to_bl y", simp)
   448    apply (clarsimp simp: map_last_def rev_bl_order_rev_simp)
   448    apply (clarsimp simp: map_last_def rev_bl_order_rev_simp)
   449    apply auto
   449    apply auto
   450   done
   450   done
   451 
   451 
   452 text {* Lemmas for unpacking rev (to_bl n) for numerals n and also
   452 text \<open>Lemmas for unpacking rev (to_bl n) for numerals n and also
   453 for irreducible values and expressions. *}
   453 for irreducible values and expressions.\<close>
   454 
   454 
   455 lemma rev_bin_to_bl_simps:
   455 lemma rev_bin_to_bl_simps:
   456   "rev (bin_to_bl 0 x) = []"
   456   "rev (bin_to_bl 0 x) = []"
   457   "rev (bin_to_bl (Suc n) (numeral (num.Bit0 nm)))
   457   "rev (bin_to_bl (Suc n) (numeral (num.Bit0 nm)))
   458     = False # rev (bin_to_bl n (numeral nm))"
   458     = False # rev (bin_to_bl n (numeral nm))"
   492 lemma upt_eq_list_intros:
   492 lemma upt_eq_list_intros:
   493   "j <= i \<Longrightarrow> [i ..< j] = []"
   493   "j <= i \<Longrightarrow> [i ..< j] = []"
   494   "\<lbrakk> i = x; x < j; [x + 1 ..< j] = xs \<rbrakk> \<Longrightarrow> [i ..< j] = (x # xs)"
   494   "\<lbrakk> i = x; x < j; [x + 1 ..< j] = xs \<rbrakk> \<Longrightarrow> [i ..< j] = (x # xs)"
   495   by (simp_all add: upt_eq_Nil_conv upt_eq_Cons_conv)
   495   by (simp_all add: upt_eq_Nil_conv upt_eq_Cons_conv)
   496 
   496 
   497 text {* Tactic definition *}
   497 text \<open>Tactic definition\<close>
   498 
   498 
   499 ML {*
   499 ML \<open>
   500 structure Word_Bitwise_Tac =
   500 structure Word_Bitwise_Tac =
   501 struct
   501 struct
   502 
   502 
   503 val word_ss = simpset_of @{theory_context Word};
   503 val word_ss = simpset_of @{theory_context Word};
   504 
   504 
   615         map (fn ss => safe_full_simp_tac (put_simpset ss ctxt)) sss)
   615         map (fn ss => safe_full_simp_tac (put_simpset ss ctxt)) sss)
   616   end;
   616   end;
   617 
   617 
   618 end
   618 end
   619 
   619 
   620 *}
   620 \<close>
   621 
   621 
   622 method_setup word_bitwise =
   622 method_setup word_bitwise =
   623   {* Scan.succeed (fn ctxt => Method.SIMPLE_METHOD (Word_Bitwise_Tac.tac ctxt 1))  *}
   623   \<open>Scan.succeed (fn ctxt => Method.SIMPLE_METHOD (Word_Bitwise_Tac.tac ctxt 1))\<close>
   624   "decomposer for word equalities and inequalities into bit propositions"
   624   "decomposer for word equalities and inequalities into bit propositions"
   625 
   625 
   626 end
   626 end