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.
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 #
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
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 #
The sequence of natural numbers some 0, some 1, ...
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.