src/HOL/Quickcheck.thy
changeset 46311 56fae81902ce
parent 45801 5616fbda86e6
child 46547 d1dcb91a512e
equal deleted inserted replaced
46310:8af202923906 46311:56fae81902ce
   126   "beyond k l = (if l > k then l else 0)"
   126   "beyond k l = (if l > k then l else 0)"
   127 
   127 
   128 lemma beyond_zero:
   128 lemma beyond_zero:
   129   "beyond k 0 = 0"
   129   "beyond k 0 = 0"
   130   by (simp add: beyond_def)
   130   by (simp add: beyond_def)
       
   131 
       
   132 
       
   133 definition (in term_syntax) [code_unfold]: "valterm_emptyset = Code_Evaluation.valtermify ({} :: ('a :: typerep) set)"
       
   134 definition (in term_syntax) [code_unfold]: "valtermify_insert x s = Code_Evaluation.valtermify insert {\<cdot>} (x :: ('a :: typerep * _)) {\<cdot>} s"
       
   135 
       
   136 instantiation set :: (random) random
       
   137 begin
       
   138 
       
   139 primrec random_aux_set
       
   140 where
       
   141   "random_aux_set 0 j = collapse (Random.select_weight [(1, Pair valterm_emptyset)])"
       
   142 | "random_aux_set (Suc_code_numeral i) j = collapse (Random.select_weight [(1, Pair valterm_emptyset), (Suc_code_numeral i, random j \<circ>\<rightarrow> (%x. random_aux_set i j \<circ>\<rightarrow> (%s. Pair (valtermify_insert x s))))])"
       
   143 
       
   144 lemma [code]:
       
   145   "random_aux_set i j = collapse (Random.select_weight [(1, Pair valterm_emptyset), (i, random j \<circ>\<rightarrow> (%x. random_aux_set (i - 1) j \<circ>\<rightarrow> (%s. Pair (valtermify_insert x s))))])"
       
   146 proof (induct i rule: code_numeral.induct)
       
   147 print_cases
       
   148   case zero
       
   149   show ?case by (subst select_weight_drop_zero[symmetric])
       
   150     (simp add: filter.simps random_aux_set.simps[simplified])
       
   151 next
       
   152   case (Suc_code_numeral i)
       
   153   show ?case by (simp only: random_aux_set.simps(2)[of "i"] Suc_code_numeral_minus_one)
       
   154 qed
       
   155 
       
   156 definition random_set
       
   157 where
       
   158   "random_set i = random_aux_set i i" 
       
   159 
       
   160 instance ..
       
   161 
       
   162 end
   131 
   163 
   132 lemma random_aux_rec:
   164 lemma random_aux_rec:
   133   fixes random_aux :: "code_numeral \<Rightarrow> 'a"
   165   fixes random_aux :: "code_numeral \<Rightarrow> 'a"
   134   assumes "random_aux 0 = rhs 0"
   166   assumes "random_aux 0 = rhs 0"
   135     and "\<And>k. random_aux (Suc_code_numeral k) = rhs (Suc_code_numeral k)"
   167     and "\<And>k. random_aux (Suc_code_numeral k) = rhs (Suc_code_numeral k)"