src/HOL/New_DSequence.thy
author bulwahn
Thu Oct 21 19:13:07 2010 +0200 (2010-10-21)
changeset 40049 75d9f57123d6
parent 39183 512c10416590
child 42163 392fd6c4669c
permissions -rw-r--r--
adding decreasing bind and non-decreasing bind; depth-limited and depth-unlimited compilation possible
     1 
     2 (* Author: Lukas Bulwahn, TU Muenchen *)
     3 
     4 header {* Depth-Limited Sequences with failure element *}
     5 
     6 theory New_DSequence
     7 imports Random_Sequence
     8 begin
     9 
    10 subsection {* Positive Depth-Limited Sequence *}
    11 
    12 types 'a pos_dseq = "code_numeral => 'a Lazy_Sequence.lazy_sequence"
    13 
    14 definition pos_empty :: "'a pos_dseq"
    15 where
    16   "pos_empty = (%i. Lazy_Sequence.empty)"
    17 
    18 definition pos_single :: "'a => 'a pos_dseq"
    19 where
    20   "pos_single x = (%i. Lazy_Sequence.single x)"
    21 
    22 definition pos_bind :: "'a pos_dseq => ('a => 'b pos_dseq) => 'b pos_dseq"
    23 where
    24   "pos_bind x f = (%i. Lazy_Sequence.bind (x i) (%a. f a i))"
    25 
    26 definition pos_decr_bind :: "'a pos_dseq => ('a => 'b pos_dseq) => 'b pos_dseq"
    27 where
    28   "pos_decr_bind x f = (%i. 
    29      if i = 0 then
    30        Lazy_Sequence.empty
    31      else
    32        Lazy_Sequence.bind (x (i - 1)) (%a. f a i))"
    33 
    34 definition pos_union :: "'a pos_dseq => 'a pos_dseq => 'a pos_dseq"
    35 where
    36   "pos_union xq yq = (%i. Lazy_Sequence.append (xq i) (yq i))"
    37 
    38 definition pos_if_seq :: "bool => unit pos_dseq"
    39 where
    40   "pos_if_seq b = (if b then pos_single () else pos_empty)"
    41 
    42 definition pos_iterate_upto :: "(code_numeral => 'a) => code_numeral => code_numeral => 'a pos_dseq"
    43 where
    44   "pos_iterate_upto f n m = (%i. Lazy_Sequence.iterate_upto f n m)"
    45  
    46 definition pos_map :: "('a => 'b) => 'a pos_dseq => 'b pos_dseq"
    47 where
    48   "pos_map f xq = (%i. Lazy_Sequence.map f (xq i))"
    49 
    50 subsection {* Negative Depth-Limited Sequence *}
    51 
    52 types 'a neg_dseq = "code_numeral => 'a Lazy_Sequence.hit_bound_lazy_sequence"
    53 
    54 definition neg_empty :: "'a neg_dseq"
    55 where
    56   "neg_empty = (%i. Lazy_Sequence.empty)"
    57 
    58 definition neg_single :: "'a => 'a neg_dseq"
    59 where
    60   "neg_single x = (%i. Lazy_Sequence.hb_single x)"
    61 
    62 definition neg_bind :: "'a neg_dseq => ('a => 'b neg_dseq) => 'b neg_dseq"
    63 where
    64   "neg_bind x f = (%i. hb_bind (x i) (%a. f a i))"
    65 
    66 definition neg_decr_bind :: "'a neg_dseq => ('a => 'b neg_dseq) => 'b neg_dseq"
    67 where
    68   "neg_decr_bind x f = (%i. 
    69      if i = 0 then
    70        Lazy_Sequence.hit_bound
    71      else
    72        hb_bind (x (i - 1)) (%a. f a i))"
    73 
    74 definition neg_union :: "'a neg_dseq => 'a neg_dseq => 'a neg_dseq"
    75 where
    76   "neg_union x y = (%i. Lazy_Sequence.append (x i) (y i))"
    77 
    78 definition neg_if_seq :: "bool => unit neg_dseq"
    79 where
    80   "neg_if_seq b = (if b then neg_single () else neg_empty)"
    81 
    82 definition neg_iterate_upto 
    83 where
    84   "neg_iterate_upto f n m = (%i. Lazy_Sequence.iterate_upto (%i. Some (f i)) n m)"
    85 
    86 definition neg_map :: "('a => 'b) => 'a neg_dseq => 'b neg_dseq"
    87 where
    88   "neg_map f xq = (%i. Lazy_Sequence.hb_map f (xq i))"
    89 
    90 subsection {* Negation *}
    91 
    92 definition pos_not_seq :: "unit neg_dseq => unit pos_dseq"
    93 where
    94   "pos_not_seq xq = (%i. Lazy_Sequence.hb_not_seq (xq (3 * i)))"
    95 
    96 definition neg_not_seq :: "unit pos_dseq => unit neg_dseq"
    97 where
    98   "neg_not_seq x = (%i. case Lazy_Sequence.yield (x i) of
    99     None => Lazy_Sequence.hb_single ()
   100   | Some ((), xq) => Lazy_Sequence.empty)"
   101 
   102 hide_type (open) pos_dseq neg_dseq
   103 
   104 hide_const (open)
   105   pos_empty pos_single pos_bind pos_decr_bind pos_union pos_if_seq pos_iterate_upto pos_not_seq pos_map
   106   neg_empty neg_single neg_bind neg_decr_bind neg_union neg_if_seq neg_iterate_upto neg_not_seq neg_map
   107 hide_fact (open)
   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
   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
   110 
   111 end