src/HOL/New_Random_Sequence.thy
author huffman
Fri Mar 30 12:32:35 2012 +0200 (2012-03-30)
changeset 47220 52426c62b5d0
parent 42163 392fd6c4669c
child 50055 94041d602ecb
permissions -rw-r--r--
replace lemmas eval_nat_numeral with a simpler reformulation
bulwahn@36017
     1
bulwahn@36017
     2
(* Author: Lukas Bulwahn, TU Muenchen *)
bulwahn@36017
     3
bulwahn@36017
     4
theory New_Random_Sequence
bulwahn@36017
     5
imports Quickcheck New_DSequence
bulwahn@36017
     6
begin
bulwahn@36017
     7
bulwahn@42163
     8
type_synonym 'a pos_random_dseq = "code_numeral \<Rightarrow> code_numeral \<Rightarrow> Random.seed \<Rightarrow> 'a New_DSequence.pos_dseq"
bulwahn@42163
     9
type_synonym 'a neg_random_dseq = "code_numeral \<Rightarrow> code_numeral \<Rightarrow> Random.seed \<Rightarrow> 'a New_DSequence.neg_dseq"
bulwahn@36017
    10
bulwahn@36017
    11
definition pos_empty :: "'a pos_random_dseq"
bulwahn@36017
    12
where
bulwahn@36017
    13
  "pos_empty = (%nrandom size seed. New_DSequence.pos_empty)"
bulwahn@36017
    14
bulwahn@36017
    15
definition pos_single :: "'a => 'a pos_random_dseq"
bulwahn@36017
    16
where
bulwahn@36017
    17
  "pos_single x = (%nrandom size seed. New_DSequence.pos_single x)"
bulwahn@36017
    18
bulwahn@36017
    19
definition pos_bind :: "'a pos_random_dseq => ('a \<Rightarrow> 'b pos_random_dseq) \<Rightarrow> 'b pos_random_dseq"
bulwahn@36017
    20
where
bulwahn@36017
    21
  "pos_bind R f = (\<lambda>nrandom size seed. New_DSequence.pos_bind (R nrandom size seed) (%a. f a nrandom size seed))"
bulwahn@36017
    22
bulwahn@40049
    23
definition pos_decr_bind :: "'a pos_random_dseq => ('a \<Rightarrow> 'b pos_random_dseq) \<Rightarrow> 'b pos_random_dseq"
bulwahn@40049
    24
where
bulwahn@40049
    25
  "pos_decr_bind R f = (\<lambda>nrandom size seed. New_DSequence.pos_decr_bind (R nrandom size seed) (%a. f a nrandom size seed))"
bulwahn@40049
    26
bulwahn@36017
    27
definition pos_union :: "'a pos_random_dseq => 'a pos_random_dseq => 'a pos_random_dseq"
bulwahn@36017
    28
where
bulwahn@36017
    29
  "pos_union R1 R2 = (\<lambda>nrandom size seed. New_DSequence.pos_union (R1 nrandom size seed) (R2 nrandom size seed))"
bulwahn@36017
    30
bulwahn@36017
    31
definition pos_if_random_dseq :: "bool => unit pos_random_dseq"
bulwahn@36017
    32
where
bulwahn@36017
    33
  "pos_if_random_dseq b = (if b then pos_single () else pos_empty)"
bulwahn@36017
    34
bulwahn@36049
    35
definition pos_iterate_upto :: "(code_numeral => 'a) => code_numeral => code_numeral => 'a pos_random_dseq"
bulwahn@36049
    36
where
bulwahn@36049
    37
  "pos_iterate_upto f n m = (\<lambda>nrandom size seed. New_DSequence.pos_iterate_upto f n m)"
bulwahn@36049
    38
bulwahn@36017
    39
definition pos_not_random_dseq :: "unit neg_random_dseq => unit pos_random_dseq"
bulwahn@36017
    40
where
bulwahn@36017
    41
  "pos_not_random_dseq R = (\<lambda>nrandom size seed. New_DSequence.pos_not_seq (R nrandom size seed))"
bulwahn@36017
    42
bulwahn@36017
    43
fun iter :: "(code_numeral * code_numeral => ('a * (unit => term)) * code_numeral * code_numeral) => code_numeral => code_numeral * code_numeral => 'a Lazy_Sequence.lazy_sequence"
bulwahn@36017
    44
where
bulwahn@36017
    45
  "iter random nrandom seed =
bulwahn@36017
    46
    (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')))"
bulwahn@36017
    47
bulwahn@36017
    48
definition Random :: "(code_numeral \<Rightarrow> Random.seed \<Rightarrow> (('a \<times> (unit \<Rightarrow> term)) \<times> Random.seed)) \<Rightarrow> 'a pos_random_dseq"
bulwahn@36017
    49
where
bulwahn@36017
    50
  "Random g = (%nrandom size seed depth. iter (g size) nrandom seed)"
bulwahn@36017
    51
bulwahn@36017
    52
definition pos_map :: "('a => 'b) => 'a pos_random_dseq => 'b pos_random_dseq"
bulwahn@36017
    53
where
bulwahn@36017
    54
  "pos_map f P = pos_bind P (pos_single o f)"
bulwahn@36017
    55
bulwahn@36017
    56
bulwahn@36017
    57
definition neg_empty :: "'a neg_random_dseq"
bulwahn@36017
    58
where
bulwahn@36017
    59
  "neg_empty = (%nrandom size seed. New_DSequence.neg_empty)"
bulwahn@36017
    60
bulwahn@36017
    61
definition neg_single :: "'a => 'a neg_random_dseq"
bulwahn@36017
    62
where
bulwahn@36017
    63
  "neg_single x = (%nrandom size seed. New_DSequence.neg_single x)"
bulwahn@36017
    64
bulwahn@36017
    65
definition neg_bind :: "'a neg_random_dseq => ('a \<Rightarrow> 'b neg_random_dseq) \<Rightarrow> 'b neg_random_dseq"
bulwahn@36017
    66
where
bulwahn@36017
    67
  "neg_bind R f = (\<lambda>nrandom size seed. New_DSequence.neg_bind (R nrandom size seed) (%a. f a nrandom size seed))"
bulwahn@36017
    68
bulwahn@40049
    69
definition neg_decr_bind :: "'a neg_random_dseq => ('a \<Rightarrow> 'b neg_random_dseq) \<Rightarrow> 'b neg_random_dseq"
bulwahn@40049
    70
where
bulwahn@40049
    71
  "neg_decr_bind R f = (\<lambda>nrandom size seed. New_DSequence.neg_decr_bind (R nrandom size seed) (%a. f a nrandom size seed))"
bulwahn@40049
    72
bulwahn@36017
    73
definition neg_union :: "'a neg_random_dseq => 'a neg_random_dseq => 'a neg_random_dseq"
bulwahn@36017
    74
where
bulwahn@36017
    75
  "neg_union R1 R2 = (\<lambda>nrandom size seed. New_DSequence.neg_union (R1 nrandom size seed) (R2 nrandom size seed))"
bulwahn@36017
    76
bulwahn@36017
    77
definition neg_if_random_dseq :: "bool => unit neg_random_dseq"
bulwahn@36017
    78
where
bulwahn@36017
    79
  "neg_if_random_dseq b = (if b then neg_single () else neg_empty)"
bulwahn@36017
    80
bulwahn@36049
    81
definition neg_iterate_upto :: "(code_numeral => 'a) => code_numeral => code_numeral => 'a neg_random_dseq"
bulwahn@36049
    82
where
bulwahn@36049
    83
  "neg_iterate_upto f n m = (\<lambda>nrandom size seed. New_DSequence.neg_iterate_upto f n m)"
bulwahn@36049
    84
bulwahn@36017
    85
definition neg_not_random_dseq :: "unit pos_random_dseq => unit neg_random_dseq"
bulwahn@36017
    86
where
bulwahn@36017
    87
  "neg_not_random_dseq R = (\<lambda>nrandom size seed. New_DSequence.neg_not_seq (R nrandom size seed))"
bulwahn@36017
    88
(*
bulwahn@36017
    89
fun iter :: "(code_numeral * code_numeral => ('a * (unit => term)) * code_numeral * code_numeral) => code_numeral => code_numeral * code_numeral => 'a Lazy_Sequence.lazy_sequence"
bulwahn@36017
    90
where
bulwahn@36017
    91
  "iter random nrandom seed =
bulwahn@36017
    92
    (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')))"
bulwahn@36017
    93
bulwahn@36017
    94
definition Random :: "(code_numeral \<Rightarrow> Random.seed \<Rightarrow> (('a \<times> (unit \<Rightarrow> term)) \<times> Random.seed)) \<Rightarrow> 'a pos_random_dseq"
bulwahn@36017
    95
where
bulwahn@36017
    96
  "Random g = (%nrandom size seed depth. iter (g size) nrandom seed)"
bulwahn@36017
    97
*)
bulwahn@36017
    98
definition neg_map :: "('a => 'b) => 'a neg_random_dseq => 'b neg_random_dseq"
bulwahn@36017
    99
where
bulwahn@36017
   100
  "neg_map f P = neg_bind P (neg_single o f)"
bulwahn@36017
   101
(*
wenzelm@36176
   102
hide_const DSequence.empty DSequence.single DSequence.eval
bulwahn@36017
   103
  DSequence.map_seq DSequence.bind DSequence.union DSequence.if_seq DSequence.not_seq
bulwahn@36017
   104
  DSequence.map
bulwahn@36017
   105
*)
bulwahn@36017
   106
wenzelm@36176
   107
hide_const (open)
bulwahn@40049
   108
  pos_empty pos_single pos_bind pos_decr_bind pos_union pos_if_random_dseq pos_iterate_upto pos_not_random_dseq iter Random pos_map
bulwahn@40049
   109
  neg_empty neg_single neg_bind neg_decr_bind neg_union neg_if_random_dseq neg_iterate_upto neg_not_random_dseq neg_map
wenzelm@36176
   110
hide_type New_DSequence.pos_dseq New_DSequence.neg_dseq pos_random_dseq neg_random_dseq
bulwahn@36017
   111
(* FIXME: hide facts *)
wenzelm@36176
   112
(*hide_fact (open) empty_def single_def bind_def union_def if_random_dseq_def not_random_dseq_def Random.simps map_def*)
bulwahn@36017
   113
bulwahn@36017
   114
end