src/HOL/New_Random_Sequence.thy
author hoelzl
Thu Sep 02 10:14:32 2010 +0200 (2010-09-02)
changeset 39072 1030b1a166ef
parent 36176 3fe7e97ccca8
child 40049 75d9f57123d6
permissions -rw-r--r--
Add lessThan_Suc_eq_insert_0
     1 
     2 (* Author: Lukas Bulwahn, TU Muenchen *)
     3 
     4 theory New_Random_Sequence
     5 imports Quickcheck New_DSequence
     6 begin
     7 
     8 types 'a pos_random_dseq = "code_numeral \<Rightarrow> code_numeral \<Rightarrow> Random.seed \<Rightarrow> 'a New_DSequence.pos_dseq"
     9 types 'a neg_random_dseq = "code_numeral \<Rightarrow> code_numeral \<Rightarrow> Random.seed \<Rightarrow> 'a New_DSequence.neg_dseq"
    10 
    11 definition pos_empty :: "'a pos_random_dseq"
    12 where
    13   "pos_empty = (%nrandom size seed. New_DSequence.pos_empty)"
    14 
    15 definition pos_single :: "'a => 'a pos_random_dseq"
    16 where
    17   "pos_single x = (%nrandom size seed. New_DSequence.pos_single x)"
    18 
    19 definition pos_bind :: "'a pos_random_dseq => ('a \<Rightarrow> 'b pos_random_dseq) \<Rightarrow> 'b pos_random_dseq"
    20 where
    21   "pos_bind R f = (\<lambda>nrandom size seed. New_DSequence.pos_bind (R nrandom size seed) (%a. f a nrandom size seed))"
    22 
    23 definition pos_union :: "'a pos_random_dseq => 'a pos_random_dseq => 'a pos_random_dseq"
    24 where
    25   "pos_union R1 R2 = (\<lambda>nrandom size seed. New_DSequence.pos_union (R1 nrandom size seed) (R2 nrandom size seed))"
    26 
    27 definition pos_if_random_dseq :: "bool => unit pos_random_dseq"
    28 where
    29   "pos_if_random_dseq b = (if b then pos_single () else pos_empty)"
    30 
    31 definition pos_iterate_upto :: "(code_numeral => 'a) => code_numeral => code_numeral => 'a pos_random_dseq"
    32 where
    33   "pos_iterate_upto f n m = (\<lambda>nrandom size seed. New_DSequence.pos_iterate_upto f n m)"
    34 
    35 definition pos_not_random_dseq :: "unit neg_random_dseq => unit pos_random_dseq"
    36 where
    37   "pos_not_random_dseq R = (\<lambda>nrandom size seed. New_DSequence.pos_not_seq (R nrandom size seed))"
    38 
    39 fun iter :: "(code_numeral * code_numeral => ('a * (unit => term)) * code_numeral * code_numeral) => code_numeral => code_numeral * code_numeral => 'a Lazy_Sequence.lazy_sequence"
    40 where
    41   "iter random nrandom seed =
    42     (if nrandom = 0 then Lazy_Sequence.empty else Lazy_Sequence.Lazy_Sequence (%u. let ((x, _), seed') = random seed in Some (x, iter random (nrandom - 1) seed')))"
    43 
    44 definition Random :: "(code_numeral \<Rightarrow> Random.seed \<Rightarrow> (('a \<times> (unit \<Rightarrow> term)) \<times> Random.seed)) \<Rightarrow> 'a pos_random_dseq"
    45 where
    46   "Random g = (%nrandom size seed depth. iter (g size) nrandom seed)"
    47 
    48 definition pos_map :: "('a => 'b) => 'a pos_random_dseq => 'b pos_random_dseq"
    49 where
    50   "pos_map f P = pos_bind P (pos_single o f)"
    51 
    52 
    53 definition neg_empty :: "'a neg_random_dseq"
    54 where
    55   "neg_empty = (%nrandom size seed. New_DSequence.neg_empty)"
    56 
    57 definition neg_single :: "'a => 'a neg_random_dseq"
    58 where
    59   "neg_single x = (%nrandom size seed. New_DSequence.neg_single x)"
    60 
    61 definition neg_bind :: "'a neg_random_dseq => ('a \<Rightarrow> 'b neg_random_dseq) \<Rightarrow> 'b neg_random_dseq"
    62 where
    63   "neg_bind R f = (\<lambda>nrandom size seed. New_DSequence.neg_bind (R nrandom size seed) (%a. f a nrandom size seed))"
    64 
    65 definition neg_union :: "'a neg_random_dseq => 'a neg_random_dseq => 'a neg_random_dseq"
    66 where
    67   "neg_union R1 R2 = (\<lambda>nrandom size seed. New_DSequence.neg_union (R1 nrandom size seed) (R2 nrandom size seed))"
    68 
    69 definition neg_if_random_dseq :: "bool => unit neg_random_dseq"
    70 where
    71   "neg_if_random_dseq b = (if b then neg_single () else neg_empty)"
    72 
    73 definition neg_iterate_upto :: "(code_numeral => 'a) => code_numeral => code_numeral => 'a neg_random_dseq"
    74 where
    75   "neg_iterate_upto f n m = (\<lambda>nrandom size seed. New_DSequence.neg_iterate_upto f n m)"
    76 
    77 definition neg_not_random_dseq :: "unit pos_random_dseq => unit neg_random_dseq"
    78 where
    79   "neg_not_random_dseq R = (\<lambda>nrandom size seed. New_DSequence.neg_not_seq (R nrandom size seed))"
    80 (*
    81 fun iter :: "(code_numeral * code_numeral => ('a * (unit => term)) * code_numeral * code_numeral) => code_numeral => code_numeral * code_numeral => 'a Lazy_Sequence.lazy_sequence"
    82 where
    83   "iter random nrandom seed =
    84     (if nrandom = 0 then Lazy_Sequence.empty else Lazy_Sequence.Lazy_Sequence (%u. let ((x, _), seed') = random seed in Some (x, iter random (nrandom - 1) seed')))"
    85 
    86 definition Random :: "(code_numeral \<Rightarrow> Random.seed \<Rightarrow> (('a \<times> (unit \<Rightarrow> term)) \<times> Random.seed)) \<Rightarrow> 'a pos_random_dseq"
    87 where
    88   "Random g = (%nrandom size seed depth. iter (g size) nrandom seed)"
    89 *)
    90 definition neg_map :: "('a => 'b) => 'a neg_random_dseq => 'b neg_random_dseq"
    91 where
    92   "neg_map f P = neg_bind P (neg_single o f)"
    93 (*
    94 hide_const DSequence.empty DSequence.single DSequence.eval
    95   DSequence.map_seq DSequence.bind DSequence.union DSequence.if_seq DSequence.not_seq
    96   DSequence.map
    97 *)
    98 
    99 hide_const (open)
   100   pos_empty pos_single pos_bind pos_union pos_if_random_dseq pos_iterate_upto pos_not_random_dseq iter Random pos_map
   101   neg_empty neg_single neg_bind neg_union neg_if_random_dseq neg_iterate_upto neg_not_random_dseq neg_map
   102 hide_type New_DSequence.pos_dseq New_DSequence.neg_dseq pos_random_dseq neg_random_dseq
   103 (* FIXME: hide facts *)
   104 (*hide_fact (open) empty_def single_def bind_def union_def if_random_dseq_def not_random_dseq_def Random.simps map_def*)
   105 
   106 end