src/HOL/Word/BinOperations.thy
changeset 28042 1471f2974eb1
parent 26558 7fcc10088e72
child 28562 4e74209f113e
equal deleted inserted replaced
28041:f496e9f343b7 28042:1471f2974eb1
   512 subsection {* Splitting and concatenation *}
   512 subsection {* Splitting and concatenation *}
   513 
   513 
   514 definition bin_rcat :: "nat \<Rightarrow> int list \<Rightarrow> int" where
   514 definition bin_rcat :: "nat \<Rightarrow> int list \<Rightarrow> int" where
   515   "bin_rcat n = foldl (%u v. bin_cat u n v) Int.Pls"
   515   "bin_rcat n = foldl (%u v. bin_cat u n v) Int.Pls"
   516 
   516 
   517 function bin_rsplit_aux :: "nat \<Rightarrow> nat \<Rightarrow> int \<Rightarrow> int list \<Rightarrow> int list" where
   517 fun bin_rsplit_aux :: "nat \<Rightarrow> nat \<Rightarrow> int \<Rightarrow> int list \<Rightarrow> int list" where
   518   "bin_rsplit_aux n m c bs =
   518   "bin_rsplit_aux n m c bs =
   519     (if m = 0 | n = 0 then bs else
   519     (if m = 0 | n = 0 then bs else
   520       let (a, b) = bin_split n c 
   520       let (a, b) = bin_split n c 
   521       in bin_rsplit_aux n (m - n) a (b # bs))"
   521       in bin_rsplit_aux n (m - n) a (b # bs))"
   522 by pat_completeness auto
       
   523 termination by (relation "measure (fst o snd)") simp_all
       
   524 
   522 
   525 definition bin_rsplit :: "nat \<Rightarrow> nat \<times> int \<Rightarrow> int list" where
   523 definition bin_rsplit :: "nat \<Rightarrow> nat \<times> int \<Rightarrow> int list" where
   526   "bin_rsplit n w = bin_rsplit_aux n (fst w) (snd w) []"
   524   "bin_rsplit n w = bin_rsplit_aux n (fst w) (snd w) []"
   527 
   525 
   528 function bin_rsplitl_aux :: "nat \<Rightarrow> nat \<Rightarrow> int \<Rightarrow> int list \<Rightarrow> int list" where
   526 fun bin_rsplitl_aux :: "nat \<Rightarrow> nat \<Rightarrow> int \<Rightarrow> int list \<Rightarrow> int list" where
   529   "bin_rsplitl_aux n m c bs =
   527   "bin_rsplitl_aux n m c bs =
   530     (if m = 0 | n = 0 then bs else
   528     (if m = 0 | n = 0 then bs else
   531       let (a, b) = bin_split (min m n) c 
   529       let (a, b) = bin_split (min m n) c 
   532       in bin_rsplitl_aux n (m - n) a (b # bs))"
   530       in bin_rsplitl_aux n (m - n) a (b # bs))"
   533 by pat_completeness auto
       
   534 termination by (relation "measure (fst o snd)") simp_all
       
   535 
   531 
   536 definition bin_rsplitl :: "nat \<Rightarrow> nat \<times> int \<Rightarrow> int list" where
   532 definition bin_rsplitl :: "nat \<Rightarrow> nat \<times> int \<Rightarrow> int list" where
   537   "bin_rsplitl n w = bin_rsplitl_aux n (fst w) (snd w) []"
   533   "bin_rsplitl n w = bin_rsplitl_aux n (fst w) (snd w) []"
   538 
   534 
   539 declare bin_rsplit_aux.simps [simp del]
   535 declare bin_rsplit_aux.simps [simp del]