Composable Enumerations #
This file defines Enum α, a type of computable enumerations over a type α,
together with a library of combinators for building complex enumerations from
simple ones. This forms the "generator" half of the DSL.
Design #
An Enum α is simply a function ℕ → Option α. Semantically, it represents a
(possibly infinite) stream of elements: enum 0, enum 1, enum 2, ..., where
none means "no output at this index" (allowing sparse enumerations).
The key combinators are:
Enum.naturals— enumerate all natural numbersEnum.ofList— enumerate elements of a finite listEnum.ofEncodable— enumerate all elements of anEncodabletypeEnum.product— enumerate all pairs (dovetailing)Enum.bind— monadic bind (flatMap with dovetailing)Enum.map— apply a function to each elementEnum.filterMap— filter and transform
Each combinator preserves the property that every element in the range eventually appears (surjectivity onto the range).
Main definitions #
Enum— the type of enumerationsEnum.range— the set of elements that appear in an enumerationEnum.Surjective— every element in the range appears- Various combinators with range correctness theorems
References #
This is the "generator" layer of the DSL described in the module
Langlib.Automata.Turing.DSL.SearchProcedure.
An enumeration of elements of type α.
Semantically, e : Enum α represents a computable sequence
e 0, e 1, e 2, ... where each step either produces an element (some a)
or is a no-op (none). The range of e is {a | ∃ n, e n = some a}.
Note: an Enum may produce the same element multiple times; what matters is
that every element in the intended set appears at least once.
Instances For
An enumeration is surjective onto a set S if every element of S
appears in the enumeration.
Equations
- e.SurjectiveOnto S = (S ⊆ e.range)
Instances For
Basic enumerations #
Combinators #
Pairing / Dovetailing #
To enumerate all pairs (a, b) from two enumerations, we use the Cantor
pairing function to dovetail.
Enumerate all pairs from two enumerations using dovetailing.
Equations
Instances For
Monadic bind (flatMap) with dovetailing.
For each element a from e, enumerate f a, interleaving all results.
Equations
Instances For
Derived enumerations #
Enumerate all pairs of natural numbers.