src/HOL/Lazy_Sequence.thy
changeset 36049 0ce5b7a5c2fd
parent 36030 1cd962a0b1a6
child 36176 3fe7e97ccca8
--- a/src/HOL/Lazy_Sequence.thy	Wed Mar 31 16:44:41 2010 +0200
+++ b/src/HOL/Lazy_Sequence.thy	Wed Mar 31 16:44:41 2010 +0200
@@ -110,6 +110,13 @@
 where
   "if_seq b = (if b then single () else empty)"
 
+function iterate_upto :: "(code_numeral => 'a) => code_numeral => code_numeral => 'a Lazy_Sequence.lazy_sequence"
+where
+  "iterate_upto f n m = Lazy_Sequence.Lazy_Sequence (%u. if n > m then None else Some (f n, iterate_upto f (n + 1) m))"
+by pat_completeness auto
+
+termination by (relation "measure (%(f, n, m). Code_Numeral.nat_of (m + 1 - n))") auto
+
 definition not_seq :: "unit lazy_sequence => unit lazy_sequence"
 where
   "not_seq xq = (case yield xq of None => single () | Some ((), xq) => empty)"
@@ -206,7 +213,7 @@
   "hb_not_seq xq = (case yield xq of None => single () | Some (x, xq) => empty)"
 
 hide (open) type lazy_sequence
-hide (open) const Empty Insert Lazy_Sequence yield empty single append flat map bind if_seq not_seq
-hide fact yield.simps empty_def single_def append.simps flat.simps map.simps bind_def if_seq_def not_seq_def
+hide (open) const Empty Insert Lazy_Sequence yield empty single append flat map bind if_seq iterate_upto not_seq
+hide fact yield.simps empty_def single_def append.simps flat.simps map.simps bind_def iterate_upto.simps if_seq_def not_seq_def
 
 end