src/HOL/New_DSequence.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
header {* Depth-Limited Sequences with failure element *}
bulwahn@36017
     5
bulwahn@36017
     6
theory New_DSequence
bulwahn@36017
     7
imports Random_Sequence
bulwahn@36017
     8
begin
bulwahn@36017
     9
huffman@36902
    10
subsection {* Positive Depth-Limited Sequence *}
bulwahn@36017
    11
bulwahn@42163
    12
type_synonym 'a pos_dseq = "code_numeral => 'a Lazy_Sequence.lazy_sequence"
bulwahn@36017
    13
bulwahn@36017
    14
definition pos_empty :: "'a pos_dseq"
bulwahn@36017
    15
where
bulwahn@36017
    16
  "pos_empty = (%i. Lazy_Sequence.empty)"
bulwahn@36017
    17
bulwahn@36017
    18
definition pos_single :: "'a => 'a pos_dseq"
bulwahn@36017
    19
where
bulwahn@36017
    20
  "pos_single x = (%i. Lazy_Sequence.single x)"
bulwahn@36017
    21
bulwahn@36017
    22
definition pos_bind :: "'a pos_dseq => ('a => 'b pos_dseq) => 'b pos_dseq"
bulwahn@36017
    23
where
bulwahn@40049
    24
  "pos_bind x f = (%i. Lazy_Sequence.bind (x i) (%a. f a i))"
bulwahn@40049
    25
bulwahn@40049
    26
definition pos_decr_bind :: "'a pos_dseq => ('a => 'b pos_dseq) => 'b pos_dseq"
bulwahn@40049
    27
where
bulwahn@40049
    28
  "pos_decr_bind x f = (%i. 
bulwahn@36017
    29
     if i = 0 then
bulwahn@36017
    30
       Lazy_Sequence.empty
bulwahn@36017
    31
     else
bulwahn@36017
    32
       Lazy_Sequence.bind (x (i - 1)) (%a. f a i))"
bulwahn@36017
    33
bulwahn@36017
    34
definition pos_union :: "'a pos_dseq => 'a pos_dseq => 'a pos_dseq"
bulwahn@36017
    35
where
bulwahn@36017
    36
  "pos_union xq yq = (%i. Lazy_Sequence.append (xq i) (yq i))"
bulwahn@36017
    37
bulwahn@36017
    38
definition pos_if_seq :: "bool => unit pos_dseq"
bulwahn@36017
    39
where
bulwahn@36017
    40
  "pos_if_seq b = (if b then pos_single () else pos_empty)"
bulwahn@36017
    41
bulwahn@36049
    42
definition pos_iterate_upto :: "(code_numeral => 'a) => code_numeral => code_numeral => 'a pos_dseq"
bulwahn@36049
    43
where
bulwahn@36049
    44
  "pos_iterate_upto f n m = (%i. Lazy_Sequence.iterate_upto f n m)"
bulwahn@36049
    45
 
bulwahn@36017
    46
definition pos_map :: "('a => 'b) => 'a pos_dseq => 'b pos_dseq"
bulwahn@36017
    47
where
bulwahn@36017
    48
  "pos_map f xq = (%i. Lazy_Sequence.map f (xq i))"
bulwahn@36017
    49
huffman@36902
    50
subsection {* Negative Depth-Limited Sequence *}
bulwahn@36017
    51
bulwahn@42163
    52
type_synonym 'a neg_dseq = "code_numeral => 'a Lazy_Sequence.hit_bound_lazy_sequence"
bulwahn@36017
    53
bulwahn@36017
    54
definition neg_empty :: "'a neg_dseq"
bulwahn@36017
    55
where
bulwahn@36017
    56
  "neg_empty = (%i. Lazy_Sequence.empty)"
bulwahn@36017
    57
bulwahn@36017
    58
definition neg_single :: "'a => 'a neg_dseq"
bulwahn@36017
    59
where
bulwahn@36017
    60
  "neg_single x = (%i. Lazy_Sequence.hb_single x)"
bulwahn@36017
    61
bulwahn@36017
    62
definition neg_bind :: "'a neg_dseq => ('a => 'b neg_dseq) => 'b neg_dseq"
bulwahn@36017
    63
where
bulwahn@40049
    64
  "neg_bind x f = (%i. hb_bind (x i) (%a. f a i))"
bulwahn@40049
    65
bulwahn@40049
    66
definition neg_decr_bind :: "'a neg_dseq => ('a => 'b neg_dseq) => 'b neg_dseq"
bulwahn@40049
    67
where
bulwahn@40049
    68
  "neg_decr_bind x f = (%i. 
bulwahn@36017
    69
     if i = 0 then
bulwahn@36017
    70
       Lazy_Sequence.hit_bound
bulwahn@36017
    71
     else
bulwahn@36017
    72
       hb_bind (x (i - 1)) (%a. f a i))"
bulwahn@36017
    73
bulwahn@36017
    74
definition neg_union :: "'a neg_dseq => 'a neg_dseq => 'a neg_dseq"
bulwahn@36017
    75
where
bulwahn@36017
    76
  "neg_union x y = (%i. Lazy_Sequence.append (x i) (y i))"
bulwahn@36017
    77
bulwahn@36017
    78
definition neg_if_seq :: "bool => unit neg_dseq"
bulwahn@36017
    79
where
bulwahn@36017
    80
  "neg_if_seq b = (if b then neg_single () else neg_empty)"
bulwahn@36017
    81
bulwahn@36049
    82
definition neg_iterate_upto 
bulwahn@36049
    83
where
bulwahn@36049
    84
  "neg_iterate_upto f n m = (%i. Lazy_Sequence.iterate_upto (%i. Some (f i)) n m)"
bulwahn@36049
    85
bulwahn@36017
    86
definition neg_map :: "('a => 'b) => 'a neg_dseq => 'b neg_dseq"
bulwahn@36017
    87
where
bulwahn@36017
    88
  "neg_map f xq = (%i. Lazy_Sequence.hb_map f (xq i))"
bulwahn@36017
    89
huffman@36902
    90
subsection {* Negation *}
bulwahn@36017
    91
bulwahn@36017
    92
definition pos_not_seq :: "unit neg_dseq => unit pos_dseq"
bulwahn@36017
    93
where
bulwahn@39183
    94
  "pos_not_seq xq = (%i. Lazy_Sequence.hb_not_seq (xq (3 * i)))"
bulwahn@36017
    95
bulwahn@36017
    96
definition neg_not_seq :: "unit pos_dseq => unit neg_dseq"
bulwahn@36017
    97
where
bulwahn@36017
    98
  "neg_not_seq x = (%i. case Lazy_Sequence.yield (x i) of
bulwahn@36017
    99
    None => Lazy_Sequence.hb_single ()
bulwahn@36017
   100
  | Some ((), xq) => Lazy_Sequence.empty)"
bulwahn@36017
   101
wenzelm@36176
   102
hide_type (open) pos_dseq neg_dseq
bulwahn@36017
   103
wenzelm@36176
   104
hide_const (open)
bulwahn@40049
   105
  pos_empty pos_single pos_bind pos_decr_bind pos_union pos_if_seq pos_iterate_upto pos_not_seq pos_map
bulwahn@40049
   106
  neg_empty neg_single neg_bind neg_decr_bind neg_union neg_if_seq neg_iterate_upto neg_not_seq neg_map
wenzelm@36176
   107
hide_fact (open)
bulwahn@36049
   108
  pos_empty_def pos_single_def pos_bind_def pos_union_def pos_if_seq_def pos_iterate_upto_def pos_not_seq_def pos_map_def
bulwahn@36049
   109
  neg_empty_def neg_single_def neg_bind_def neg_union_def neg_if_seq_def neg_iterate_upto_def neg_not_seq_def neg_map_def
bulwahn@36017
   110
bulwahn@36017
   111
end