
bulwahn@34948: 
bulwahn@34948: (* Author: Lukas Bulwahn, TU Muenchen *)
bulwahn@34948: 
bulwahn@34948: theory Random_Sequence
bulwahn@34948: imports Quickcheck DSequence
bulwahn@34948: begin
bulwahn@34948: 
bulwahn@34948: types 'a random_dseq = "code_numeral \<Rightarrow> code_numeral \<Rightarrow> Random.seed \<Rightarrow> ('a DSequence.dseq \<times> Random.seed)"
bulwahn@34948: 
bulwahn@34948: definition empty :: "'a random_dseq"
bulwahn@34948: where
bulwahn@34948:   "empty = (%nrandom size. Pair (DSequence.empty))"
bulwahn@34948: 
bulwahn@34948: definition single :: "'a => 'a random_dseq"
bulwahn@34948: where
bulwahn@34948:   "single x = (%nrandom size. Pair (DSequence.single x))"
bulwahn@34948: 
bulwahn@34948: definition bind :: "'a random_dseq => ('a \<Rightarrow> 'b random_dseq) \<Rightarrow> 'b random_dseq"
bulwahn@34948: where
bulwahn@34948:   "bind R f = (\<lambda>nrandom size s. let
bulwahn@34948:      (P, s') = R nrandom size s;
bulwahn@34948:      (s1, s2) = Random.split_seed s'
bulwahn@34948:   in (DSequence.bind P (%a. fst (f a nrandom size s1)), s2))"
bulwahn@34948: 
bulwahn@34948: definition union :: "'a random_dseq => 'a random_dseq => 'a random_dseq"
bulwahn@34948: where
bulwahn@34948:   "union R1 R2 = (\<lambda>nrandom size s. let
bulwahn@34948:      (S1, s') = R1 nrandom size s; (S2, s'') = R2 nrandom size s'
bulwahn@34948:   in (DSequence.union S1 S2, s''))"
bulwahn@34948: 
bulwahn@34948: definition if_random_dseq :: "bool => unit random_dseq"
bulwahn@34948: where
bulwahn@34948:   "if_random_dseq b = (if b then single () else empty)"
bulwahn@34948: 
bulwahn@34948: definition not_random_dseq :: "unit random_dseq => unit random_dseq"
bulwahn@34948: where
bulwahn@34948:   "not_random_dseq R = (\<lambda>nrandom size s. let
bulwahn@34948:      (S, s') = R nrandom size s
bulwahn@34948:    in (DSequence.not_seq S, s'))"
bulwahn@34948: 
bulwahn@34948: fun Random :: "(code_numeral \<Rightarrow> Random.seed \<Rightarrow> (('a \<times> (unit \<Rightarrow> term)) \<times> Random.seed)) \<Rightarrow> 'a random_dseq"
bulwahn@34948: where
bulwahn@34948:   "Random g nrandom = (%size. if nrandom <= 0 then (Pair DSequence.empty) else
bulwahn@34948:      (scomp (g size) (%r. scomp (Random g (nrandom - 1) size) (%rs. Pair (DSequence.union (DSequence.single (fst r)) rs)))))"
bulwahn@34948: 
bulwahn@34948: definition map :: "('a => 'b) => 'a random_dseq => 'b random_dseq"
bulwahn@34948: where
bulwahn@34948:   "map f P = bind P (single o f)"
bulwahn@34948: 
bulwahn@34948: (*
wenzelm@36176: hide_const DSequence.empty DSequence.single DSequence.eval
bulwahn@34948:   DSequence.map_seq DSequence.bind DSequence.union DSequence.if_seq DSequence.not_seq
bulwahn@34948:   DSequence.map
bulwahn@34948: *)
bulwahn@34948: 
wenzelm@36176: hide_const (open) empty single bind union if_random_dseq not_random_dseq Random map
bulwahn@34948: 
wenzelm@36176: hide_type DSequence.dseq random_dseq
wenzelm@36176: hide_fact (open) empty_def single_def bind_def union_def if_random_dseq_def not_random_dseq_def Random.simps map_def
bulwahn@34948: 
bulwahn@34948: end



