some attempts to fit source on screen;
authorwenzelm
Sat, 17 Mar 2012 00:17:30 +0100
changeset 47849c54ca5717f73
parent 47845 7ca3608146d8
child 47850 80123a220219
some attempts to fit source on screen;
src/HOL/Quickcheck.thy
     1.1 --- a/src/HOL/Quickcheck.thy	Fri Mar 16 22:48:38 2012 +0100
     1.2 +++ b/src/HOL/Quickcheck.thy	Sat Mar 17 00:17:30 2012 +0100
     1.3 @@ -43,8 +43,9 @@
     1.4  instantiation itself :: (typerep) random
     1.5  begin
     1.6  
     1.7 -definition random_itself :: "code_numeral \<Rightarrow> Random.seed \<Rightarrow> ('a itself \<times> (unit \<Rightarrow> term)) \<times> Random.seed" where
     1.8 -  "random_itself _ = Pair (Code_Evaluation.valtermify TYPE('a))"
     1.9 +definition
    1.10 +  random_itself :: "code_numeral \<Rightarrow> Random.seed \<Rightarrow> ('a itself \<times> (unit \<Rightarrow> term)) \<times> Random.seed"
    1.11 +where "random_itself _ = Pair (Code_Evaluation.valtermify TYPE('a))"
    1.12  
    1.13  instance ..
    1.14  
    1.15 @@ -73,7 +74,9 @@
    1.16  instantiation nat :: random
    1.17  begin
    1.18  
    1.19 -definition random_nat :: "code_numeral \<Rightarrow> Random.seed \<Rightarrow> (nat \<times> (unit \<Rightarrow> Code_Evaluation.term)) \<times> Random.seed" where
    1.20 +definition random_nat :: "code_numeral \<Rightarrow> Random.seed
    1.21 +  \<Rightarrow> (nat \<times> (unit \<Rightarrow> Code_Evaluation.term)) \<times> Random.seed"
    1.22 +where
    1.23    "random_nat i = Random.range (i + 1) \<circ>\<rightarrow> (\<lambda>k. Pair (
    1.24       let n = Code_Numeral.nat_of k
    1.25       in (n, \<lambda>_. Code_Evaluation.term_of n)))"
    1.26 @@ -100,18 +103,22 @@
    1.27  text {* Towards @{typ "'a \<Rightarrow> 'b"} *}
    1.28  
    1.29  axiomatization random_fun_aux :: "typerep \<Rightarrow> typerep \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> term)
    1.30 -  \<Rightarrow> (Random.seed \<Rightarrow> ('b \<times> (unit \<Rightarrow> term)) \<times> Random.seed) \<Rightarrow> (Random.seed \<Rightarrow> Random.seed \<times> Random.seed)
    1.31 +  \<Rightarrow> (Random.seed \<Rightarrow> ('b \<times> (unit \<Rightarrow> term)) \<times> Random.seed)
    1.32 +  \<Rightarrow> (Random.seed \<Rightarrow> Random.seed \<times> Random.seed)
    1.33    \<Rightarrow> Random.seed \<Rightarrow> (('a \<Rightarrow> 'b) \<times> (unit \<Rightarrow> term)) \<times> Random.seed"
    1.34  
    1.35  definition random_fun_lift :: "(Random.seed \<Rightarrow> ('b \<times> (unit \<Rightarrow> term)) \<times> Random.seed)
    1.36 -  \<Rightarrow> Random.seed \<Rightarrow> (('a\<Colon>term_of \<Rightarrow> 'b\<Colon>typerep) \<times> (unit \<Rightarrow> term)) \<times> Random.seed" where
    1.37 -  "random_fun_lift f = random_fun_aux TYPEREP('a) TYPEREP('b) (op =) Code_Evaluation.term_of f Random.split_seed"
    1.38 +  \<Rightarrow> Random.seed \<Rightarrow> (('a\<Colon>term_of \<Rightarrow> 'b\<Colon>typerep) \<times> (unit \<Rightarrow> term)) \<times> Random.seed"
    1.39 +where
    1.40 +  "random_fun_lift f =
    1.41 +    random_fun_aux TYPEREP('a) TYPEREP('b) (op =) Code_Evaluation.term_of f Random.split_seed"
    1.42  
    1.43  instantiation "fun" :: ("{equal, term_of}", random) random
    1.44  begin
    1.45  
    1.46 -definition random_fun :: "code_numeral \<Rightarrow> Random.seed \<Rightarrow> (('a \<Rightarrow> 'b) \<times> (unit \<Rightarrow> term)) \<times> Random.seed" where
    1.47 -  "random i = random_fun_lift (random i)"
    1.48 +definition
    1.49 +  random_fun :: "code_numeral \<Rightarrow> Random.seed \<Rightarrow> (('a \<Rightarrow> 'b) \<times> (unit \<Rightarrow> term)) \<times> Random.seed"
    1.50 +  where "random i = random_fun_lift (random i)"
    1.51  
    1.52  instance ..
    1.53  
    1.54 @@ -119,19 +126,21 @@
    1.55  
    1.56  text {* Towards type copies and datatypes *}
    1.57  
    1.58 -definition collapse :: "('a \<Rightarrow> ('a \<Rightarrow> 'b \<times> 'a) \<times> 'a) \<Rightarrow> 'a \<Rightarrow> 'b \<times> 'a" where
    1.59 -  "collapse f = (f \<circ>\<rightarrow> id)"
    1.60 +definition collapse :: "('a \<Rightarrow> ('a \<Rightarrow> 'b \<times> 'a) \<times> 'a) \<Rightarrow> 'a \<Rightarrow> 'b \<times> 'a"
    1.61 +  where "collapse f = (f \<circ>\<rightarrow> id)"
    1.62  
    1.63 -definition beyond :: "code_numeral \<Rightarrow> code_numeral \<Rightarrow> code_numeral" where
    1.64 -  "beyond k l = (if l > k then l else 0)"
    1.65 +definition beyond :: "code_numeral \<Rightarrow> code_numeral \<Rightarrow> code_numeral"
    1.66 +  where "beyond k l = (if l > k then l else 0)"
    1.67  
    1.68 -lemma beyond_zero:
    1.69 -  "beyond k 0 = 0"
    1.70 +lemma beyond_zero: "beyond k 0 = 0"
    1.71    by (simp add: beyond_def)
    1.72  
    1.73  
    1.74 -definition (in term_syntax) [code_unfold]: "valterm_emptyset = Code_Evaluation.valtermify ({} :: ('a :: typerep) set)"
    1.75 -definition (in term_syntax) [code_unfold]: "valtermify_insert x s = Code_Evaluation.valtermify insert {\<cdot>} (x :: ('a :: typerep * _)) {\<cdot>} s"
    1.76 +definition (in term_syntax) [code_unfold]:
    1.77 +  "valterm_emptyset = Code_Evaluation.valtermify ({} :: ('a :: typerep) set)"
    1.78 +
    1.79 +definition (in term_syntax) [code_unfold]:
    1.80 +  "valtermify_insert x s = Code_Evaluation.valtermify insert {\<cdot>} (x :: ('a :: typerep * _)) {\<cdot>} s"
    1.81  
    1.82  instantiation set :: (random) random
    1.83  begin
    1.84 @@ -139,12 +148,17 @@
    1.85  primrec random_aux_set
    1.86  where
    1.87    "random_aux_set 0 j = collapse (Random.select_weight [(1, Pair valterm_emptyset)])"
    1.88 -| "random_aux_set (Code_Numeral.Suc i) j = collapse (Random.select_weight [(1, Pair valterm_emptyset), (Code_Numeral.Suc i, random j \<circ>\<rightarrow> (%x. random_aux_set i j \<circ>\<rightarrow> (%s. Pair (valtermify_insert x s))))])"
    1.89 +| "random_aux_set (Code_Numeral.Suc i) j =
    1.90 +    collapse (Random.select_weight
    1.91 +      [(1, Pair valterm_emptyset),
    1.92 +       (Code_Numeral.Suc i,
    1.93 +        random j \<circ>\<rightarrow> (%x. random_aux_set i j \<circ>\<rightarrow> (%s. Pair (valtermify_insert x s))))])"
    1.94  
    1.95  lemma [code]:
    1.96 -  "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))))])"
    1.97 +  "random_aux_set i j =
    1.98 +    collapse (Random.select_weight [(1, Pair valterm_emptyset),
    1.99 +      (i, random j \<circ>\<rightarrow> (%x. random_aux_set (i - 1) j \<circ>\<rightarrow> (%s. Pair (valtermify_insert x s))))])"
   1.100  proof (induct i rule: code_numeral.induct)
   1.101 -print_cases
   1.102    case zero
   1.103    show ?case by (subst select_weight_drop_zero[symmetric])
   1.104      (simp add: filter.simps random_aux_set.simps[simplified])
   1.105 @@ -153,9 +167,7 @@
   1.106    show ?case by (simp only: random_aux_set.simps(2)[of "i"] Suc_code_numeral_minus_one)
   1.107  qed
   1.108  
   1.109 -definition random_set
   1.110 -where
   1.111 -  "random_set i = random_aux_set i i" 
   1.112 +definition "random_set i = random_aux_set i i"
   1.113  
   1.114  instance ..
   1.115  
   1.116 @@ -190,13 +202,15 @@
   1.117  subsection {* The Random-Predicate Monad *} 
   1.118  
   1.119  fun iter' ::
   1.120 -  "'a itself => code_numeral => code_numeral => code_numeral * code_numeral => ('a::random) Predicate.pred"
   1.121 +  "'a itself => code_numeral => code_numeral => code_numeral * code_numeral
   1.122 +    => ('a::random) Predicate.pred"
   1.123  where
   1.124    "iter' T nrandom sz seed = (if nrandom = 0 then bot_class.bot else
   1.125       let ((x, _), seed') = random sz seed
   1.126     in Predicate.Seq (%u. Predicate.Insert x (iter' T (nrandom - 1) sz seed')))"
   1.127  
   1.128 -definition iter :: "code_numeral => code_numeral => code_numeral * code_numeral => ('a::random) Predicate.pred"
   1.129 +definition iter :: "code_numeral => code_numeral => code_numeral * code_numeral
   1.130 +  => ('a::random) Predicate.pred"
   1.131  where
   1.132    "iter nrandom sz seed = iter' (TYPE('a)) nrandom sz seed"
   1.133  
   1.134 @@ -262,8 +276,10 @@
   1.135  
   1.136  hide_const (open) catch_match random collapse beyond random_fun_aux random_fun_lift
   1.137  
   1.138 -hide_fact (open) iter'.simps iter_def empty_def single_def bind_def union_def if_randompred_def iterate_upto_def not_randompred_def Random_def map_def 
   1.139 +hide_fact (open) iter'.simps iter_def empty_def single_def bind_def union_def
   1.140 +  if_randompred_def iterate_upto_def not_randompred_def Random_def map_def 
   1.141  hide_type (open) randompred
   1.142 -hide_const (open) iter' iter empty single bind union if_randompred iterate_upto not_randompred Random map
   1.143 +hide_const (open) iter' iter empty single bind union if_randompred
   1.144 +  iterate_upto not_randompred Random map
   1.145  
   1.146  end