A collection of common non-deterministic and/or combinatorial operations. Many operations are intended to operate on sets. The representation of these sets is not hidden; rather sets are represented as lists. Ideally these lists contains no duplicate elements and the order of their elements cannot be observed. In practice, these conditions are not enforced.
permute
:: [a] -> [a]
Compute any permutation of a list.
:: [a]
|
The list. |
-> [a]
|
A permutation of the argument. |
permute [1,2,3,4] ~> [1,3,4,2]
(permute1234)
length (permute xs) <~> length xs
(permLength)
anyOf (permute xs) <~> anyOf xs
(permElems)
subset
:: [a] -> [a]
Compute any sublist of a list. The sublist contains some of the elements of the list in the same order.
:: [a]
|
The list. |
-> [a]
|
A sublist of the argument. |
subset [1,2,3,4] ~> [1,3]
(subset1234)
subset [1,2,3]
<~> ([1,2,3] ? ([1,2] ? ([1,3] ? ([1] ? ([2,3] ? ([2] ? ([3] ? [])))))))
(subset123)
anyOf (subset xs) <~ anyOf xs
(subsetElems)
allSubsets
:: Ord a => [a] -> [[a]]
Compute all the sublists of a list.
:: Ord a
|
|
=> [a]
|
The list. |
-> [[a]]
|
All the sublists of the argument. |
allSubsets [1,2,3] -=- [[],[1],[1,2],[1,2,3],[1,3],[2],[2,3],[3]]
(allSubsets123)
splitSet
:: [a] -> ([a], [a])
Split a list into any two sublists.
:: [a]
|
The list. |
-> ([a], [a])
|
A pair consisting of two complementary sublists of the argument. |
splitSet [1,2,3,4] ~> ([1,3,4],[2])
(splitSet1234)
(\(xs,ys) -> length xs + length ys) (splitSet zs) <~> length zs
(splitSetLengths)
(\(xs,ys) -> anyOf xs ? anyOf ys) (splitSet zs) <~> anyOf zs
(splitSetElems)
sizedSubset
:: Int -> [a] -> [a]
Compute any sublist of fixed length of a list. Similar to subset, but the length of the result is fixed.
:: Int
|
The length of the output sublist. |
-> [a]
|
The input list. |
-> [a]
|
A sublist of xs
of length c .
|
(sizedSubset c _)
requires
c >= 0
(sizedSubset'pre)
((c >= 0) && (length xs >= c)) ==> (length (sizedSubset c xs) <~> c)
(sizedSubsetLength)
((c >= 0) && (length xs < c)) ==> failing (sizedSubset c xs)
(sizedSubsetLengthTooSmall)
partition
:: [a] -> [[a]]
Compute any partition of a list. The output is a list of non-empty lists such that their concatenation is a permutation of the input list. No guarantee is made on the order of the arguments in the output.
:: [a]
|
The input list. |
-> [[a]]
|
A partition of xs
represented as a list of lists.
|
partition [1,2,3,4] ~> [[4],[2,3],[1]]
(partition1234)
partition [1,2,3]
<~> ([[1,2,3]]
? ([[2,3],[1]] ? ([[1,3],[2]] ? ([[3],[1,2]] ? [[3],[2],[1]]))))
(partition123)
sum (map length (partition xs)) <~> length xs
(partitionLengths)
anyOf (map anyOf (partition xs)) <~> anyOf xs
(partitionElems)