Possibly infinite lists #
This file provides Stream'.Seq α, a type representing possibly infinite lists (referred here as
sequences). It is encoded as an infinite stream of options such that if f n = none, then
f m = none for all m ≥ n.
Main definitions #
Seq α: The type of possibly infinite lists (sequences) encoded as streams of options. It is encoded asStream' (Option α)such that iff n = none, thenf m = nonefor allm ≥ n. It has two "constructors":nilandcons, and a destructordestruct.Seq1 α: The type of nonempty sequencesSeq.get?: Extract the nth element of a sequence (if it exists).Seq.corec: Corecursion principle forSeq αas a coinductive type.Seq.Terminates: Predicate for when a sequence is finite.
One can convert between sequences and other types: List, Stream', MLList using corresponding
functions defined in this file.
There are also a number of operations and predicates on sequences mirroring those on lists:
Seq.map, Seq.zip, Seq.zipWith, Seq.unzip, Seq.fold, Seq.update, Seq.drop,
Seq.splitAt, Seq.append, Seq.join, Seq.enum, Seq.Pairwire,
as well as a cases principle Seq.recOn which allows one to reason about
sequences by cases (nil and cons).
Main statements #
eq_of_bisim: Bisimulation principle for sequences.
A stream s : Option α is a sequence if s.get n = none implies s.get (n + 1) = none.
Equations
Instances For
Get the nth element of a sequence (if it exists)
Equations
Instances For
Constructors #
Prepend an element to a sequence
Equations
Instances For
Destructors #
Get the first element of a sequence
Equations
Instances For
Recursion and corecursion principles #
Recursion principle for sequences, compare with List.recOn.
Equations
Instances For
Bisimulation #
If two streams are bisimilar, then they are equal. There are also versions
eq_of_bisim' and eq_of_bisim_strong that does not mention IsBisimulation and look
more like an induction principles.
Coinductive principle for equality on sequences.
This is a version of eq_of_bisim that looks more like an induction principle.
Coinductive principle for equality on sequences.
This is a version of eq_of_bisim' that requires proving only s₁ = s₂
instead of s₁ = nil ∧ s₂ = nil in step.
Termination #
A sequence has terminated at position n if the value at position n equals none.
Equations
Instances For
It is decidable whether a sequence terminates at a given position.
Equations
A sequence terminates if there is some position n at which it has terminated.
Equations
Instances For
The length of a terminating sequence.
Equations
Instances For
If a sequence terminated at position n, it also terminated at m ≥ n.
Membership #
Converting from/to other types #
Embed a list as a sequence
Equations
Instances For
Embed an infinite stream as a sequence
Equations
Instances For
Translate a sequence to a list. This function will run forever if run on an infinite sequence.
Equations
Instances For
Take the first n elements of the sequence (producing a list)
Equations
Instances For
Convert a sequence which is known to terminate into a list
Equations
Instances For
Convert a sequence which is known not to terminate into a stream
Equations
Instances For
Convert a sequence into either a list or a stream depending on whether it is finite or infinite. (Without decidability of the infiniteness predicate, this is not constructively possible.)
Equations
Instances For
Convert a sequence into a list, embedded in a computation to allow for the possibility of infinite sequences (in which case the computation never returns anything).
Equations
Instances For
Operations on sequences #
Append two sequences. If s₁ is infinite, then s₁ ++ s₂ = s₁,
otherwise it puts s₂ at the location of the nil in s₁.
Equations
Instances For
Map a function over a sequence.
Equations
Instances For
Flatten a sequence of sequences. (It is required that the
sequences be nonempty to ensure productivity; in the case
of an infinite sequence of nil, the first element is never
generated.)
Equations
Instances For
Remove the first n elements from the sequence.
Equations
Instances For
Split a sequence at n, producing a finite initial segment
and an infinite tail.
Equations
Instances For
Pair two sequences into a sequence of pairs
Equations
Instances For
Separate a sequence of pairs into two sequences
Equations
Instances For
The sequence of natural numbers some 0, some 1, ...
Equations
Instances For
Enumerate a sequence by tagging each element with its index.
Equations
Instances For
Applies f to the nth element of the sequence, if it exists, replacing that element
with the result.
Equations
Instances For
Sets the value of sequence s at index n to a. If the nth element does not exist
(s terminates earlier), the sequence is left unchanged.
Equations
Instances For
Pairwise R s means that all the elements with earlier indices are
R-related to all the elements with later indices.
Pairwise R [1, 2, 3] ↔ R 1 2 ∧ R 1 3 ∧ R 2 3
For example if R = (· ≠ ·) then it asserts s has no duplicates,
and if R = (· < ·) then it asserts that s is (strictly) sorted.