list
本頁內容尚未翻譯。
List.reverseNil
Section titled “List.reverseNil”def reverseNil (A : Type) : reverse (nil : List A) = (nil : List A)Reversing the empty list gives the empty list.
List.reverseCons
Section titled “List.reverseCons”def reverseCons {A : Type} (x : A) (xs : List A) : reverse (cons x xs) = revAcc xs (cons x (nil : List A))Reversing a cons unfolds to the accumulator-based reversal of the tail with the head as the initial accumulator.
List.myAppendNil
Section titled “List.myAppendNil”def myAppendNil {A : Type} (xs : List A) : append xs (nil : List A) = xsAppending the empty list on the right leaves a list unchanged.
List.myAppendAssoc
Section titled “List.myAppendAssoc”def myAppendAssoc {A : Type} (xs : List A) (ys : List A) (zs : List A) : append (append xs ys) zs = append xs (append ys zs)List append is associative.
List.myMapId
Section titled “List.myMapId”def myMapId {A : Type} (xs : List A) : map (fun (x : A) => x) xs = xsMapping the identity function over a list leaves it unchanged.
List.myLengthMap
Section titled “List.myLengthMap”def myLengthMap {A B : Type} (f : A -> B) (xs : List A) : length (map f xs) = length xsMapping a function over a list preserves its length.
List.mapFusion
Section titled “List.mapFusion”def mapFusion {A B : Type} {C : Type} (f : B -> C) (g : A -> B) (xs : List A) : map f (map g xs) = map (fun (x : A) => f (g x)) xsMapping two functions in sequence over a list equals mapping their composition.
List.mapReplicate
Section titled “List.mapReplicate”def mapReplicate {A B : Type} (f : A -> B) (n : Nat) (x : A) : map f (replicate n x) = replicate n (f x)Mapping a function over a list of n copies of x gives n copies of f x.
List.zipSigma
Section titled “List.zipSigma”def zipSigma {A B : Type} (xs : List A) (ys : List B) : List ((a : A) × B)Pairs up corresponding elements of two lists as dependent pairs, stopping at the shorter list.
List.unzip
Section titled “List.unzip”def unzip {A B : Type} (xs : List ((a : A) × B)) : (a : List A) × List BSplits a list of pairs into the list of first components and the list of second components.
List.takeZero
Section titled “List.takeZero”def takeZero {A : Type} (xs : List A) : take zero xs = (nil : List A)Taking zero elements gives the empty list.
List.dropZero
Section titled “List.dropZero”def dropZero {A : Type} (xs : List A) : drop zero xs = xsDropping zero elements leaves a list unchanged.
List.snocNil
Section titled “List.snocNil”def snocNil {A : Type} (x : A) : snoc (nil : List A) x = cons x (nil : List A)Appending an element to the end of the empty list gives a singleton list.
List.appendSingle
Section titled “List.appendSingle”def appendSingle {A : Type} (xs : List A) (y : A) : append xs (cons y nil) = snoc xs yAppending a singleton list equals adding that element to the end with snoc.
List.lengthNil
Section titled “List.lengthNil”def lengthNil {A : Type} : length (nil : List A) = zeroThe empty list has length zero.
List.lengthCons
Section titled “List.lengthCons”def lengthCons {A : Type} (x : A) (xs : List A) : length (cons x xs) = succ (length xs)The length of a cons is one more than the length of its tail.
List.mapDistAppend
Section titled “List.mapDistAppend”def mapDistAppend {A B : Type} (f : A -> B) (xs : List A) (ys : List A) : map f (append xs ys) = append (map f xs) (map f ys)Mapping over an appended list equals appending the mapped lists.
List.replicateZero
Section titled “List.replicateZero”def replicateZero {A : Type} (x : A) : replicate zero x = (nil : List A)Zero copies of a value form the empty list.
List.replicateOne
Section titled “List.replicateOne”def replicateOne {A : Type} (x : A) : replicate (succ zero) x = cons x (nil : List A)One copy of a value forms a singleton list.
List.zipSigmaNilL
Section titled “List.zipSigmaNilL”def zipSigmaNilL {A B : Type} (ys : List B) : zipSigma (nil : List A) ys = (nil : List ((a : A) × B))Zipping the empty list with any list gives the empty list.
List.zipSigmaNilR
Section titled “List.zipSigmaNilR”def zipSigmaNilR {A B : Type} (xs : List A) : zipSigma xs (nil : List B) = (nil : List ((a : A) × B))Zipping any list with the empty list gives the empty list.
List.appendNilL
Section titled “List.appendNilL”def appendNilL {A : Type} (xs : List A) : append (nil : List A) xs = xsThe empty list is a left identity for append.
List.lengthSnoc
Section titled “List.lengthSnoc”def lengthSnoc {A : Type} (xs : List A) (x : A) : length (snoc xs x) = succ (length xs)Adding an element to the end of a list increases its length by one.
List.snocCons
Section titled “List.snocCons”def snocCons {A : Type} (x : A) (xs : List A) (y : A) : snoc (cons x xs) y = cons x (snoc xs y)Adding an element to the end of a cons keeps the head in front.
List.nthOptionZeroCons
Section titled “List.nthOptionZeroCons”def nthOptionZeroCons {A : Type} (x : A) (xs : List A) : nthOption (cons x xs) zero = some xIndexing a cons at zero gives its head.
List.nthOptionSuccCons
Section titled “List.nthOptionSuccCons”def nthOptionSuccCons {A : Type} (x : A) (xs : List A) (n : Nat) : nthOption (cons x xs) (succ n) = nthOption xs nIndexing a cons at a successor index indexes into its tail.
List.nthOptionNil
Section titled “List.nthOptionNil”def nthOptionNil {A : Type} (n : Nat) : nthOption (nil : List A) n = (none : Option A)Indexing the empty list at any position gives nothing.
List.isNil
Section titled “List.isNil”def isNil {A : Type} (xs : List A) : BoolReturns true exactly when the list is empty.
List.listSum
Section titled “List.listSum”def listSum (xs : List Nat) : NatSums a list of natural numbers with a left fold.
List.listProduct
Section titled “List.listProduct”def listProduct (xs : List Nat) : NatMultiplies a list of natural numbers with a left fold, giving one for the empty list.
List.filterNil
Section titled “List.filterNil”def filterNil {A : Type} (p : A -> Bool) : filter p (nil : List A) = (nil : List A)Filtering the empty list gives the empty list.
List.takeNil
Section titled “List.takeNil”def takeNil {A : Type} (n : Nat) : take n (nil : List A) = (nil : List A)Taking any number of elements from the empty list gives the empty list.
List.dropNil
Section titled “List.dropNil”def dropNil {A : Type} (n : Nat) : drop n (nil : List A) = (nil : List A)Dropping any number of elements from the empty list gives the empty list.
List.concatNil
Section titled “List.concatNil”def concatNil {A : Type} : concat (nil : List (List A)) = (nil : List A)Concatenating an empty list of lists gives the empty list.
List.concatCons
Section titled “List.concatCons”def concatCons {A : Type} (xs : List A) (xss : List (List A)) : concat (cons xs xss) = append xs (concat xss)Concatenating a cons of lists appends the first list to the concatenation of the rest.
List.spanSigmaAcc
Section titled “List.spanSigmaAcc”def spanSigmaAcc {A : Type} (p : A -> Bool) (xs : List A) (acc : List A) : (a : List A) × List AAccumulator helper for spanSigma: collects the longest prefix satisfying the predicate and returns it with the remaining suffix.
List.spanSigma
Section titled “List.spanSigma”def spanSigma {A : Type} (p : A -> Bool) (xs : List A) : (a : List A) × List ASplits a list at the first element that fails the predicate, returning the prefix and the suffix as a pair.
List.partitionSigmaAcc
Section titled “List.partitionSigmaAcc”def partitionSigmaAcc {A : Type} (p : A -> Bool) (xs : List A) (yes_acc : List A) (no_acc : List A) : (a : List A) × List AAccumulator helper for partitionSigma: collects the elements that satisfy and fail the predicate in two accumulators.
List.partitionSigma
Section titled “List.partitionSigma”def partitionSigma {A : Type} (p : A -> Bool) (xs : List A) : (a : List A) × List ASplits a list into the elements that satisfy the predicate and those that do not, preserving order.
List.elemNatList
Section titled “List.elemNatList”def elemNatList (x : Nat) (xs : List Nat) : BoolReturns true when the natural number occurs in the list.
List.nubAcc
Section titled “List.nubAcc”def nubAcc (xs : List Nat) (seen : List Nat) : List NatAccumulator helper for nub: drops elements already present in the list of seen values.
List.nub
Section titled “List.nub”def nub (xs : List Nat) : List NatRemoves duplicate natural numbers from a list, keeping the first occurrence of each.
List.mapConst
Section titled “List.mapConst”def mapConst {A B : Type} (c : B) (xs : List A) : map (fun (_ : A) => c) xs = replicate (length xs) cMapping a constant function over a list gives that many copies of the constant.
List.lengthMapNat
Section titled “List.lengthMapNat”def lengthMapNat (f : Nat -> Nat) (xs : List Nat) : length (map f xs) = length xsMapping a function over a list of natural numbers preserves its length.
List.isSorted
Section titled “List.isSorted”def isSorted (xs : List Nat) : BoolReturns true when a list of natural numbers is sorted in ascending order.
List.countNat
Section titled “List.countNat”def countNat (n : Nat) (xs : List Nat) : NatCounts how many times a natural number occurs in a list.
List.sumList
Section titled “List.sumList”def sumList (xs : List Nat) : NatSums a list of natural numbers by direct recursion.
List.productList
Section titled “List.productList”def productList (xs : List Nat) : NatMultiplies a list of natural numbers by direct recursion, giving one for the empty list.
List.maxList
Section titled “List.maxList”def maxList (xs : List Nat) : NatReturns the maximum of a list of natural numbers, or zero for the empty list.
List.minList
Section titled “List.minList”def minList (xs : List Nat) : NatReturns the minimum of a list of natural numbers, or zero for the empty list.
List.sumListSingle
Section titled “List.sumListSingle”def sumListSingle (n : Nat) : sumList (cons n nil) = nThe sum of a singleton list is its element.
List.scanlNat
Section titled “List.scanlNat”def scanlNat (f : Nat -> Nat -> Nat) (z : Nat) (xs : List Nat) : List NatLeft scan over natural numbers: returns every intermediate accumulator, starting with the initial value.
List.scanrNatGo
Section titled “List.scanrNatGo”def scanrNatGo (f : Nat -> Nat -> Nat) (z : Nat) (xs : List Nat) : (a : Nat) × List NatHelper for scanrNat that returns the final right-fold value together with the list of intermediate values.
List.scanrNat
Section titled “List.scanrNat”def scanrNat (f : Nat -> Nat -> Nat) (z : Nat) (xs : List Nat) : List NatRight scan over natural numbers: returns every intermediate right-fold value, ending with the initial value.
List.intercalateNat
Section titled “List.intercalateNat”def intercalateNat (sep : List Nat) (xss : List (List Nat)) : List NatJoins a list of lists of natural numbers, inserting the separator list between consecutive lists.
List.countNatNil
Section titled “List.countNatNil”def countNatNil (n : Nat) : countNat n (nil : List Nat) = zeroCounting occurrences in the empty list gives zero.
List.lastOption
Section titled “List.lastOption”def lastOption {A : Type} (xs : List A) : Option AReturns the last element of a list, or nothing for the empty list.
List.headNat
Section titled “List.headNat”def headNat (xs : List Nat) : NatReturns the first element of a list of natural numbers, or zero for the empty list.
List.tailList
Section titled “List.tailList”def tailList {A : Type} (xs : List A) : List AReturns the list without its first element, or the empty list for the empty list.
List.tailListLength
Section titled “List.tailListLength”def tailListLength {A : Type} (xs : List A) : length (tailList xs) = pred (length xs)Dropping the head of a list decreases its length by one, truncated at zero.
List.insertSorted
Section titled “List.insertSorted”def insertSorted (x : Nat) (xs : List Nat) : List NatInserts a natural number into a sorted list, keeping it sorted.
List.insertionSort
Section titled “List.insertionSort”def insertionSort (xs : List Nat) : List NatSorts a list of natural numbers by insertion sort.
List.unfoldrNat
Section titled “List.unfoldrNat”def unfoldrNat (fuel : Nat) (f : Nat -> Option ((a : Nat) × Nat)) (seed : Nat) : List NatUnfolds a list of natural numbers from a seed for at most fuel steps, stopping early when the step function returns nothing.
List.countdownStep
Section titled “List.countdownStep”def countdownStep (n : Nat) : Option ((a : Nat) × Nat)Step function for countdown: emits n and continues from n - 1, stopping at zero.
List.countdown
Section titled “List.countdown”def countdown (n : Nat) : List NatGenerates the list n, n - 1, …, 1.
List.unfoldrNatZeroFuel
Section titled “List.unfoldrNatZeroFuel”def unfoldrNatZeroFuel (f : Nat -> Option ((a : Nat) × Nat)) (s : Nat) : unfoldrNat zero f s = (nil : List Nat)Unfolding with zero fuel gives the empty list.
List.groupByNatAcc
Section titled “List.groupByNatAcc”def groupByNatAcc (xs : List Nat) (cur : Nat) (curGroup : List Nat) : List (List Nat)Accumulator helper for groupByNat: extends the current group while elements equal the current value.
List.groupByNat
Section titled “List.groupByNat”def groupByNat (xs : List Nat) : List (List Nat)Groups consecutive equal natural numbers into sublists.
List.appendConsL
Section titled “List.appendConsL”def appendConsL {A : Type} (x : A) (xs : List A) (ys : List A) : append (cons x xs) ys = cons x (append xs ys)Appending to a cons keeps the head in front.
List.lengthAppendList
Section titled “List.lengthAppendList”def lengthAppendList (xs : List Nat) (ys : List Nat) : length (append xs ys) = add (length xs) (length ys)The length of an appended list of natural numbers is the sum of the lengths.
List.appendAssocNat
Section titled “List.appendAssocNat”def appendAssocNat (xs : List Nat) (ys : List Nat) (zs : List Nat) : append (append xs ys) zs = append xs (append ys zs)Append is associative on lists of natural numbers.
List.appendNilRNat
Section titled “List.appendNilRNat”def appendNilRNat (xs : List Nat) : append xs (nil : List Nat) = xsAppending the empty list on the right leaves a list of natural numbers unchanged.
List.mapAppendNat
Section titled “List.mapAppendNat”def mapAppendNat (f : Nat -> Nat) (xs : List Nat) (ys : List Nat) : map f (append xs ys) = append (map f xs) (map f ys)Mapping over an appended list of natural numbers equals appending the mapped lists.
List.mapIdNatList
Section titled “List.mapIdNatList”def mapIdNatList (xs : List Nat) : map (fun (x : Nat) => x) xs = xsMapping the identity function over a list of natural numbers leaves it unchanged.
List.mapCompNat
Section titled “List.mapCompNat”def mapCompNat (f : Nat -> Nat) (g : Nat -> Nat) (xs : List Nat) : map g (map f xs) = map (fun (x : Nat) => g (f x)) xsMapping two functions in sequence over a list of natural numbers equals mapping their composition.
List.foldrConsId
Section titled “List.foldrConsId”def foldrConsId (xs : List Nat) : foldr (fun (y : Nat) => fun (ys : List Nat) => cons y ys) (nil : List Nat) xs = xsRight-folding cons over a list with the empty list as the base gives back the list.
List.foldrAppendNat
Section titled “List.foldrAppendNat”def foldrAppendNat (xss : List (List Nat)) : foldr (fun (a : List Nat) => fun (b : List Nat) => append a b) (nil : List Nat) xss = concat xssRight-folding append over a list of lists equals concatenating them.
List.sumListAppend
Section titled “List.sumListAppend”def sumListAppend (xs : List Nat) (ys : List Nat) : sumList (append xs ys) = add (sumList xs) (sumList ys)The sum of an appended list is the sum of the two sums.
List.sumListCons
Section titled “List.sumListCons”def sumListCons (x : Nat) (xs : List Nat) : sumList (cons x xs) = add x (sumList xs)The sum of a cons is the head plus the sum of the tail.
List.productListCons
Section titled “List.productListCons”def productListCons (x : Nat) (xs : List Nat) : productList (cons x xs) = mul x (productList xs)The product of a cons is the head times the product of the tail.
List.sumListReplicate
Section titled “List.sumListReplicate”def sumListReplicate (n : Nat) (x : Nat) : sumList (replicate n x) = mul n xThe sum of n copies of x is n times x.
List.revAccNil
Section titled “List.revAccNil”def revAccNil {A : Type} (acc : List A) : revAcc (nil : List A) acc = accAccumulator reversal of the empty list returns the accumulator.
List.revAccCons
Section titled “List.revAccCons”def revAccCons {A : Type} (x : A) (xs : List A) (acc : List A) : revAcc (cons x xs) acc = revAcc xs (cons x acc)Accumulator reversal of a cons moves the head onto the accumulator.
List.reverseSingleton
Section titled “List.reverseSingleton”def reverseSingleton {A : Type} (x : A) : reverse (cons x nil) = cons x (nil : List A)Reversing a singleton list leaves it unchanged.
List.takeSuccCons
Section titled “List.takeSuccCons”def takeSuccCons {A : Type} (n : Nat) (x : A) (xs : List A) : take (succ n) (cons x xs) = cons x (take n xs)Taking n + 1 elements of a cons keeps the head and takes n from the tail.
List.dropSuccCons
Section titled “List.dropSuccCons”def dropSuccCons {A : Type} (n : Nat) (x : A) (xs : List A) : drop (succ n) (cons x xs) = drop n xsDropping n + 1 elements of a cons drops n from the tail.
List.filterTrueNat
Section titled “List.filterTrueNat”def filterTrueNat (xs : List Nat) : filter (fun (_ : Nat) => true) xs = xsFiltering a list of natural numbers with the always-true predicate leaves it unchanged.
List.filterFalseNat
Section titled “List.filterFalseNat”def filterFalseNat (xs : List Nat) : filter (fun (_ : Nat) => false) xs = (nil : List Nat)Filtering a list of natural numbers with the always-false predicate gives the empty list.
List.lengthReplicateNat
Section titled “List.lengthReplicateNat”def lengthReplicateNat (n : Nat) (x : Nat) : length (replicate n x) = nA list of n copies of a natural number has length n.
List.replicateSucc
Section titled “List.replicateSucc”def replicateSucc {A : Type} (n : Nat) (x : A) : replicate (succ n) x = cons x (replicate n x)n + 1 copies of x is x followed by n copies of x.
List.mapReplicateNat
Section titled “List.mapReplicateNat”def mapReplicateNat (f : Nat -> Nat) (n : Nat) (x : Nat) : map f (replicate n x) = replicate n (f x)Mapping a function over n copies of a natural number gives n copies of its image.
List.lengthSnocNat
Section titled “List.lengthSnocNat”def lengthSnocNat (xs : List Nat) (x : Nat) : length (snoc xs x) = succ (length xs)Adding an element to the end of a list of natural numbers increases its length by one.
List.takeWhileNat
Section titled “List.takeWhileNat”def takeWhileNat (p : Nat -> Bool) (xs : List Nat) : List NatReturns the longest prefix of a list of natural numbers whose elements all satisfy the predicate.
List.dropWhileNat
Section titled “List.dropWhileNat”def dropWhileNat (p : Nat -> Bool) (xs : List Nat) : List NatDrops the longest prefix of a list of natural numbers whose elements all satisfy the predicate.
List.takeWhileTrue
Section titled “List.takeWhileTrue”def takeWhileTrue (xs : List Nat) : takeWhileNat (fun (_ : Nat) => true) xs = xstakeWhileNat with the always-true predicate leaves a list unchanged.
List.dropWhileTrue
Section titled “List.dropWhileTrue”def dropWhileTrue (xs : List Nat) : dropWhileNat (fun (_ : Nat) => true) xs = (nil : List Nat)dropWhileNat with the always-true predicate gives the empty list.
List.takeWhileFalse
Section titled “List.takeWhileFalse”def takeWhileFalse (xs : List Nat) : takeWhileNat (fun (_ : Nat) => false) xs = (nil : List Nat)takeWhileNat with the always-false predicate gives the empty list.
List.findNat
Section titled “List.findNat”def findNat (p : Nat -> Bool) (xs : List Nat) : Option NatReturns the first natural number in the list that satisfies the predicate, or nothing.
List.findIndexNatGo
Section titled “List.findIndexNatGo”def findIndexNatGo (p : Nat -> Bool) (xs : List Nat) (idx : Nat) : Option NatHelper for findIndexNat that tracks the current index.
List.findIndexNat
Section titled “List.findIndexNat”def findIndexNat (p : Nat -> Bool) (xs : List Nat) : Option NatReturns the index of the first natural number in the list that satisfies the predicate, or nothing.
List.removeNat
Section titled “List.removeNat”def removeNat (x : Nat) (xs : List Nat) : List NatRemoves the first occurrence of a natural number from a list.
List.replaceNat
Section titled “List.replaceNat”def replaceNat (old : Nat) (new : Nat) (xs : List Nat) : List NatReplaces the first occurrence of a natural number in a list with a new value.
List.flatMapNat
Section titled “List.flatMapNat”def flatMapNat (f : Nat -> List Nat) (xs : List Nat) : List NatMaps each natural number to a list and concatenates the results.
List.flatMapNatId
Section titled “List.flatMapNatId”def flatMapNatId (xs : List Nat) : flatMapNat (fun (x : Nat) => cons x nil) xs = xsflatMapNat with the singleton function leaves a list unchanged.
List.crossList
Section titled “List.crossList”def crossList : List NatExample list 3, 1, 4, 1, 5 used to check several properties on the same data.
List.revAccAppendNat
Section titled “List.revAccAppendNat”def revAccAppendNat (xs : List Nat) (acc : List Nat) (zs : List Nat) : revAcc xs (append acc zs) = append (revAcc xs acc) zsAccumulator reversal commutes with appending a suffix to the accumulator, for lists of natural numbers.
List.revAccAppendListNat
Section titled “List.revAccAppendListNat”def revAccAppendListNat (xs : List Nat) (ys : List Nat) (acc : List Nat) : revAcc (append xs ys) acc = revAcc ys (revAcc xs acc)Accumulator reversal of an appended list reverses the first part onto the accumulator and then the second.
List.revAppendNat
Section titled “List.revAppendNat”def revAppendNat (xs : List Nat) (ys : List Nat) : reverse (append xs ys) = append (reverse ys) (reverse xs)Reversing an appended list of natural numbers appends the reversed second list to the reversed first list.
List.revAccRev
Section titled “List.revAccRev”def revAccRev {A : Type} (xs : List A) (acc : List A) : revAcc (revAcc xs acc) nil = revAcc acc xsReversing the result of an accumulator reversal gives the accumulator reversed onto the original list.
List.revRev
Section titled “List.revRev”def revRev {A : Type} (xs : List A) : reverse (reverse xs) = xsReversing a list twice gives back the original list.
List.crossList2
Section titled “List.crossList2”def crossList2 : List NatExample list 2, 0, 3, 0, 1 used to check several properties on the same data.
List.elemBy
Section titled “List.elemBy”def elemBy {A : Type} (eq : A -> A -> Bool) (a : A) (xs : List A) : BoolReturns true when the list contains an element equal to a under the given equality test.
List.countBy
Section titled “List.countBy”def countBy {A : Type} (p : A -> Bool) (xs : List A) : NatCounts the elements of a list that satisfy the predicate.
List.nubByAcc
Section titled “List.nubByAcc”def nubByAcc {A : Type} (eq : A -> A -> Bool) (xs : List A) (acc : List A) : List AAccumulator helper for nubBy: keeps an element only if it is not equal to one already kept.
List.nubBy
Section titled “List.nubBy”def nubBy {A : Type} (eq : A -> A -> Bool) (xs : List A) : List ARemoves duplicates from a list under the given equality test, keeping the first occurrence of each.
List.scanl
Section titled “List.scanl”def scanl {A B : Type} (f : B -> A -> B) (z : B) (xs : List A) : List BLeft scan: like foldl but returns every intermediate accumulator, starting with the initial value.
List.scanlLength
Section titled “List.scanlLength”def scanlLength {A B : Type} (f : B -> A -> B) (z : B) (xs : List A) : length (scanl f z xs) = succ (length xs)A left scan has one more element than the input list.
List.lastNat
Section titled “List.lastNat”def lastNat (default : Nat) (xs : List Nat) : NatReturns the last element of a list of natural numbers, or the default for the empty list.
List.zipNilL
Section titled “List.zipNilL”def zipNilL {A B : Type} (ys : List B) : zip (nil : List A) ys = (nil : List (Pair A B))Zipping the empty list with any list gives the empty list.
List.zipNilR
Section titled “List.zipNilR”def zipNilR {A B : Type} (xs : List A) : zip xs (nil : List B) = (nil : List (Pair A B))Zipping any list with the empty list gives the empty list.
List.intersperseNil
Section titled “List.intersperseNil”def intersperseNil {A : Type} (sep : A) : intersperse sep (nil : List A) = (nil : List A)Interspersing a separator into the empty list gives the empty list.
List.intersperseSingle
Section titled “List.intersperseSingle”def intersperseSingle {A : Type} (sep : A) (x : A) : intersperse sep (cons x nil) = cons x (nil : List A)Interspersing a separator into a singleton list leaves it unchanged.
List.replicateTwo
Section titled “List.replicateTwo”def replicateTwo {A : Type} (x : A) : replicate (succ (succ zero)) x = cons x (cons x (nil : List A))Two copies of x form the list x, x.
List.replicateThree
Section titled “List.replicateThree”def replicateThree {A : Type} (x : A) : replicate (succ (succ (succ zero))) x = cons x (cons x (cons x (nil : List A)))Three copies of x form the list x, x, x.
List.allNil
Section titled “List.allNil”def allNil {A : Type} (p : A -> Bool) : all p (nil : List A) = trueEvery element of the empty list satisfies any predicate.
List.anyNil
Section titled “List.anyNil”def anyNil {A : Type} (p : A -> Bool) : any p (nil : List A) = falseNo element of the empty list satisfies any predicate.
List.zipWithNilL
Section titled “List.zipWithNilL”def zipWithNilL {A B : Type} {C : Type} (f : A -> B -> C) (ys : List B) : zipWith f (nil : List A) ys = (nil : List C)zipWith with the empty list on the left gives the empty list.
List.zipWithNilR
Section titled “List.zipWithNilR”def zipWithNilR {A B : Type} {C : Type} (f : A -> B -> C) (xs : List A) : zipWith f xs (nil : List B) = (nil : List C)zipWith with the empty list on the right gives the empty list.
List.scanlNil
Section titled “List.scanlNil”def scanlNil {A B : Type} (f : B -> A -> B) (z : B) : scanl f z (nil : List A) = cons z (nil : List B)A left scan over the empty list gives the singleton of the initial value.
List.list_return_v140
Section titled “List.list_return_v140”def list_return_v140 {A : Type} (x : A) : List AThe unit of the list monad: wraps a value in a singleton list.
List.listBind
Section titled “List.listBind”def listBind {A B : Type} (xs : List A) (f : A -> List B) : List BThe bind of the list monad: applies a list-valued function to each element and concatenates the results.
List.listBindReturn
Section titled “List.listBindReturn”def listBindReturn {A B : Type} (x : A) (f : A -> List B) : listBind (list_return_v140 x) f = append (f x) (nil : List B)Binding a singleton list to f gives f x appended with the empty list.
List.listBindReturnNil
Section titled “List.listBindReturnNil”def listBindReturnNil {A : Type} : listBind (nil : List A) (fun (x : A) => list_return_v140 x) = (nil : List A)Binding the empty list to the unit gives the empty list.
List.listBindNil
Section titled “List.listBindNil”def listBindNil {A B : Type} (f : A -> List B) : listBind (nil : List A) f = (nil : List B)Binding the empty list to any function gives the empty list.
List.listBindCons
Section titled “List.listBindCons”def listBindCons {A B : Type} (x : A) (xs : List A) (f : A -> List B) : listBind (cons x xs) f = append (f x) (listBind xs f)Binding a cons appends the image of the head to the bind of the tail.
List.concatMap_v140
Section titled “List.concatMap_v140”def concatMap_v140 {A B : Type} (f : A -> List B) (xs : List A) : List BMaps each element to a list and concatenates the results.
List.concatMapNil
Section titled “List.concatMapNil”def concatMapNil {A B : Type} (f : A -> List B) : concatMap_v140 f (nil : List A) = (nil : List B)concatMap over the empty list gives the empty list.
List.concatMapCons
Section titled “List.concatMapCons”def concatMapCons {A B : Type} (f : A -> List B) (x : A) (xs : List A) : concatMap_v140 f (cons x xs) = append (f x) (concatMap_v140 f xs)concatMap over a cons appends the image of the head to the concatMap of the tail.
List.concatMapSingletonNil
Section titled “List.concatMapSingletonNil”def concatMapSingletonNil {A : Type} : concatMap_v140 (fun (x : A) => cons x (nil : List A)) (nil : List A) = (nil : List A)concatMap of the singleton function over the empty list gives the empty list.
List.iterate_v140
Section titled “List.iterate_v140”def iterate_v140 {A : Type} (f : A -> A) (n : Nat) (x : A) : List AReturns the first n iterates x, f x, f (f x), … of a function.
List.iterateZeroV140
Section titled “List.iterateZeroV140”def iterateZeroV140 {A : Type} (f : A -> A) (x : A) : iterate_v140 f zero x = (nil : List A)Zero iterates give the empty list.
List.iterateOneV140
Section titled “List.iterateOneV140”def iterateOneV140 {A : Type} (f : A -> A) (x : A) : iterate_v140 f (succ zero) x = cons x (nil : List A)One iterate gives the singleton of the starting value.
List.iterateTwo
Section titled “List.iterateTwo”def iterateTwo {A : Type} (f : A -> A) (x : A) : iterate_v140 f (succ (succ zero)) x = cons x (cons (f x) (nil : List A))Two iterates give x followed by f x.
List.unfoldr
Section titled “List.unfoldr”def unfoldr {A B : Type} (f : B -> (a : A) × B) (n : Nat) (b : B) : List AUnfolds a list from a seed for exactly n steps, each step producing an element and a new seed.
List.unfoldrZero
Section titled “List.unfoldrZero”def unfoldrZero {A B : Type} (f : B -> (a : A) × B) (b : B) : unfoldr f zero b = (nil : List A)Unfolding for zero steps gives the empty list.
List.listAppendAssoc
Section titled “List.listAppendAssoc”def listAppendAssoc {A : Type} (xs ys zs : List A) : append (append xs ys) zs = append xs (append ys zs)List append is associative.
List.zipWithNilLeft
Section titled “List.zipWithNilLeft”def zipWithNilLeft {A B C : Type} (f : A -> B -> C) (ys : List B) : zipWith f (nil : List A) ys = (nil : List C)zipWith with the empty list on the left gives the empty list.
List.zipWithNilRight
Section titled “List.zipWithNilRight”def zipWithNilRight {A B C : Type} (f : A -> B -> C) (x : A) (xs : List A) : zipWith f (cons x xs) (nil : List B) = (nil : List C)zipWith of a cons with the empty list gives the empty list.
List.zipWithConsCons
Section titled “List.zipWithConsCons”def zipWithConsCons {A B C : Type} (f : A -> B -> C) (x : A) (xs : List A) (y : B) (ys : List B) : zipWith f (cons x xs) (cons y ys) = cons (f x y) (zipWith f xs ys)zipWith of two conses combines the heads and zips the tails.
List.zipSigmaConsNil
Section titled “List.zipSigmaConsNil”def zipSigmaConsNil {A B : Type} (x : A) (xs : List A) : zipSigma (cons x xs) (nil : List B) = (nil : List ((a : A) × B))Zipping a cons with the empty list as dependent pairs gives the empty list.
List.listLen0
Section titled “List.listLen0”def listLen0 {A : Type} : List AThe empty list, as an example of a list of length zero.
List.listLen1
Section titled “List.listLen1”def listLen1 {A : Type} (x : A) : List AA singleton list, as an example of a list of length one.
List.listLen1Length
Section titled “List.listLen1Length”def listLen1Length {A : Type} (x : A) : length (listLen1 x) = succ zeroThe example singleton list has length one.
List.listLen2
Section titled “List.listLen2”def listLen2 {A : Type} (x y : A) : List AA two-element list, as an example of a list of length two.
List.listLen2Length
Section titled “List.listLen2Length”def listLen2Length {A : Type} (x y : A) : length (listLen2 x y) = succ (succ zero)The example two-element list has length two.
List.reverseLengthPreserve
Section titled “List.reverseLengthPreserve”def reverseLengthPreserve {A : Type} (xs : List A) : length (reverse xs) = length xsReversing a list preserves its length.
List.revAccLength
Section titled “List.revAccLength”def revAccLength {A : Type} (xs : List A) (acc : List A) : length (revAcc xs acc) = add (length xs) (length acc)The length of an accumulator reversal is the length of the list plus the length of the accumulator.
List.reverseLength
Section titled “List.reverseLength”def reverseLength {A : Type} (xs : List A) : length (reverse xs) = length xsReversing a list preserves its length.
List.reverseLengthPreserveV140Helper
Section titled “List.reverseLengthPreserveV140Helper”def reverseLengthPreserveV140Helper {A : Type} (y : A) (ys : List A) : length (reverse (cons y ys)) = length (cons y ys)Reversing a cons preserves its length.
List.appendNilNil
Section titled “List.appendNilNil”def appendNilNil {A : Type} : append (nil : List A) (nil : List A) = (nil : List A)Appending two empty lists gives the empty list.
List.appendNilCons
Section titled “List.appendNilCons”def appendNilCons {A : Type} (x : A) (xs : List A) : append (nil : List A) (cons x xs) = cons x xsAppending a cons to the empty list gives the cons.
List.appendConsNil
Section titled “List.appendConsNil”def appendConsNil {A : Type} (x : A) : append (cons x (nil : List A)) (nil : List A) = cons x (nil : List A)Appending the empty list to a singleton list gives the singleton list.
List.appendLengthNil
Section titled “List.appendLengthNil”def appendLengthNil {A : Type} (xs : List A) : length (append xs (nil : List A)) = length xsAppending the empty list on the right preserves the length.
List.list140c
Section titled “List.list140c”def list140c : List NatExample list 3, 2, 1, 0 used in concrete checks.
List.setNth
Section titled “List.setNth”def List.setNth {A : Type} (xs : List A) (n : Nat) (x : A) : List AThe list with the element at index n replaced by x; an index past the end leaves the list unchanged.
List.lengthSetNth
Section titled “List.lengthSetNth”def List.lengthSetNth {A : Type} (xs : List A) (n : Nat) (x : A) : length (List.setNth xs n x) = length xsReplacing an element keeps the length.
List.nthOptionAppendLeft
Section titled “List.nthOptionAppendLeft”def List.nthOptionAppendLeft {A : Type} (xs : List A) (ys : List A) (i : Nat) : Nat.blt i (length xs) = true -> List.nthOption (append xs ys) i = List.nthOption xs iAn index inside the first list reads the first list.
List.nthOptionAppendRight
Section titled “List.nthOptionAppendRight”def List.nthOptionAppendRight {A : Type} (xs : List A) (ys : List A) (i : Nat) : Nat.blt i (length xs) = false -> List.nthOption (append xs ys) i = List.nthOption ys (Nat.sub i (length xs))An index past the first list reads the second, shifted by the first list’s length.
List.setNthAppendLeft
Section titled “List.setNthAppendLeft”def List.setNthAppendLeft {A : Type} (xs : List A) (ys : List A) (i : Nat) (x : A) : Nat.blt i (length xs) = true -> List.setNth (append xs ys) i x = append (List.setNth xs i x) ysReplacing inside the first list replaces in the first list.
List.setNthAppendRight
Section titled “List.setNthAppendRight”def List.setNthAppendRight {A : Type} (xs : List A) (ys : List A) (i : Nat) (x : A) : Nat.blt i (length xs) = false -> List.setNth (append xs ys) i x = append xs (List.setNth ys (Nat.sub i (length xs)) x)Replacing past the first list replaces in the second, shifted by the first list’s length.
List.nthOptionSetNthSame
Section titled “List.nthOptionSetNthSame”def List.nthOptionSetNthSame {A : Type} (xs : List A) (n : Nat) (x : A) : Nat.blt n (length xs) = true -> List.nthOption (List.setNth xs n x) n = some xReading the replaced index gives the new element.
List.nthOptionSetNthOther
Section titled “List.nthOptionSetNthOther”def List.nthOptionSetNthOther {A : Type} (xs : List A) (n : Nat) (m : Nat) (x : A) : Nat.beq n m = false -> List.nthOption (List.setNth xs n x) m = List.nthOption xs mReading another index is unaffected by the replacement.
List.setNthOutside
Section titled “List.setNthOutside”def List.setNthOutside {A : Type} (xs : List A) (n : Nat) (x : A) : Nat.blt n (length xs) = false -> List.setNth xs n x = xsReplacing past the end leaves the list unchanged.
List.allSome
Section titled “List.allSome”def List.allSome {A : Type} (xs : List (Option A)) : BoolWhether every cell holds a value.
List.somes
Section titled “List.somes”def List.somes {A : Type} (xs : List (Option A)) : List AThe values of the cells, skipping empty ones.
List.nthOptionOutside
Section titled “List.nthOptionOutside”def List.nthOptionOutside {A : Type} (xs : List A) (i : Nat) : Nat.blt i (length xs) = false -> List.nthOption xs i = noneReading past the end gives none.
List.nthOptionTake
Section titled “List.nthOptionTake”def List.nthOptionTake {A : Type} (n : Nat) (xs : List A) (i : Nat) : Nat.blt i n = true -> List.nthOption (List.take n xs) i = List.nthOption xs iReading inside a prefix reads the list.
List.lengthTake
Section titled “List.lengthTake”def List.lengthTake {A : Type} (n : Nat) (xs : List A) : Nat.ble n (length xs) = true -> length (List.take n xs) = nA prefix no longer than the list has the asked length.
List.takeSetNth
Section titled “List.takeSetNth”def List.takeSetNth {A : Type} (n : Nat) (xs : List A) (i : Nat) (x : A) : List.take n (List.setNth xs i x) = List.setNth (List.take n xs) i xReplacing inside a prefix commutes with taking the prefix.
List.lengthSomes
Section titled “List.lengthSomes”def List.lengthSomes {A : Type} (xs : List (Option A)) : List.allSome xs = true -> length (List.somes xs) = length xsWhen every cell holds a value, the values are as many as the cells.
List.nthOptionSomes
Section titled “List.nthOptionSomes”def List.nthOptionSomes {A : Type} (xs : List (Option A)) (i : Nat) : List.allSome xs = true -> List.nthOption (List.somes xs) i = Option.bind (List.nthOption xs i) (fun (c : Option A) => c)When every cell holds a value, reading the values reads the cell’s value.
List.allSomeSetNth
Section titled “List.allSomeSetNth”def List.allSomeSetNth {A : Type} (xs : List (Option A)) (i : Nat) (x : A) : List.allSome xs = true -> List.allSome (List.setNth xs i (some x)) = trueWriting a value keeps every cell holding a value.
List.somesSetNth
Section titled “List.somesSetNth”def List.somesSetNth {A : Type} (xs : List (Option A)) (i : Nat) (x : A) : List.allSome xs = true -> List.somes (List.setNth xs i (some x)) = List.setNth (List.somes xs) i xWriting a value into full cells writes the value into the values.
List.takeSuccSetNth
Section titled “List.takeSuccSetNth”def List.takeSuccSetNth {A : Type} (n : Nat) (xs : List A) (x : A) : Nat.blt n (length xs) = true -> List.take (succ n) (List.setNth xs n x) = List.snoc (List.take n xs) xTaking one past a replaced index ends with the new element.
List.takeAppendLeft
Section titled “List.takeAppendLeft”def List.takeAppendLeft {A : Type} (n : Nat) (xs : List A) (ys : List A) : Nat.ble n (length xs) = true -> List.take n (append xs ys) = List.take n xsA prefix of the first list is a prefix of the concatenation.
List.allSomeSnoc
Section titled “List.allSomeSnoc”def List.allSomeSnoc {A : Type} (xs : List (Option A)) (x : A) : List.allSome xs = true -> List.allSome (List.snoc xs (some x)) = trueAppending a value keeps every cell holding a value.
List.somesSnoc
Section titled “List.somesSnoc”def List.somesSnoc {A : Type} (xs : List (Option A)) (x : A) : List.somes (List.snoc xs (some x)) = List.snoc (List.somes xs) xThe values of cells ending with a value end with that value.
List.takeTakeSucc
Section titled “List.takeTakeSucc”def List.takeTakeSucc {A : Type} (m : Nat) (xs : List A) : List.take m (List.take (succ m) xs) = List.take m xsWithin a longer prefix, the shorter prefix is the same.
List.allSomeTake
Section titled “List.allSomeTake”def List.allSomeTake {A : Type} (m : Nat) (xs : List (Option A)) : List.allSome xs = true -> List.allSome (List.take m xs) = trueA prefix of full cells is full.
List.somesTake
Section titled “List.somesTake”def List.somesTake {A : Type} (m : Nat) (xs : List (Option A)) : List.allSome xs = true -> List.somes (List.take m xs) = List.take m (List.somes xs)When every cell holds a value, the values of a prefix are the prefix of the values.
List.nilOfLengthZero
Section titled “List.nilOfLengthZero”def List.nilOfLengthZero {A : Type} (xs : List A) : length xs = zero -> xs = nilA list of length zero is empty.