std
data NatThe unary natural numbers: zero and successor.
Nat.add
Section titled “Nat.add”def Nat.add (m : Nat) (n : Nat) : NatNatural-number addition, by recursion on the first argument.
Nat.mul
Section titled “Nat.mul”def Nat.mul (m : Nat) (n : Nat) : NatNatural-number multiplication, as repeated addition on the first argument.
Nat.sub
Section titled “Nat.sub”def Nat.sub (m : Nat) (n : Nat) : NatTruncated natural-number subtraction: m - n, or zero when n exceeds m.
data BoolThe booleans true and false.
Bool.and
Section titled “Bool.and”def Bool.and (a : Bool) (b : Bool) : BoolBoolean conjunction.
Bool.leftOfAnd
Section titled “Bool.leftOfAnd”def Bool.leftOfAnd (a : Bool) (b : Bool) : and a b = true -> a = trueThe left side of a true conjunction is true.
Bool.rightOfAnd
Section titled “Bool.rightOfAnd”def Bool.rightOfAnd (a : Bool) (b : Bool) : and a b = true -> b = trueThe right side of a true conjunction is true.
Bool.andOfBoth
Section titled “Bool.andOfBoth”def Bool.andOfBoth (a : Bool) (b : Bool) : a = true -> b = true -> and a b = trueBoth sides of a conjunction true make it true.
Bool.or
Section titled “Bool.or”def Bool.or (a : Bool) (b : Bool) : BoolBoolean disjunction.
Bool.not
Section titled “Bool.not”def Bool.not (a : Bool) : BoolBoolean negation.
Bool.dite
Section titled “Bool.dite”def Bool.dite {l : Level} {A : Type l} (c : Bool) (t : c = true -> A) (e : c = false -> A) : AIf-then-else whose branches receive the proof of the condition (what termination_by turns an if into).
Nat.beq
Section titled “Nat.beq”def Nat.beq (m : Nat) (n : Nat) : BoolBoolean equality test on natural numbers.
Nat.blt
Section titled “Nat.blt”def Nat.blt (m : Nat) (n : Nat) : BoolBoolean strict less-than test on natural numbers: m < n.
Nat.ble
Section titled “Nat.ble”def Nat.ble (m : Nat) (n : Nat) : BoolBoolean less-than-or-equal test on natural numbers: m <= n.
Nat.bleOfBlt
Section titled “Nat.bleOfBlt”def Nat.bleOfBlt (m : Nat) (n : Nat) (h : Nat.blt m n = true) : Nat.ble m n = trueStrictly less implies less or equal: m < n gives m <= n.
Nat.bgt
Section titled “Nat.bgt”def Nat.bgt (m : Nat) (n : Nat) : BoolBoolean strict greater-than test on natural numbers: m > n.
Nat.divAuxFuel
Section titled “Nat.divAuxFuel”def Nat.divAuxFuel (fuel : Nat) (q : Nat) (m : Nat) (n : Nat) : NatDivision by repeated subtraction with an accumulator q, bounded by fuel; stops when m < n, when n is zero, or when fuel runs out.
Nat.modAuxFuel
Section titled “Nat.modAuxFuel”def Nat.modAuxFuel (fuel : Nat) (m : Nat) (n : Nat) : NatRemainder by repeated subtraction, bounded by fuel; returns m unchanged when n is zero.
Nat.div
Section titled “Nat.div”def Nat.div (m : Nat) (n : Nat) : NatNatural-number division m / n, rounding down; division by zero gives zero.
Nat.mod
Section titled “Nat.mod”def Nat.mod (m : Nat) (n : Nat) : NatNatural-number remainder m mod n; the remainder modulo zero is m itself.
Nat.bge
Section titled “Nat.bge”def Nat.bge (m : Nat) (n : Nat) : BoolBoolean greater-than-or-equal test on natural numbers: m ≥ n.
Nat.bitwiseAndFuel
Section titled “Nat.bitwiseAndFuel”def Nat.bitwiseAndFuel (fuel : Nat) (m : Nat) (n : Nat) : NatBitwise and of the lowest fuel bits of m and n.
Nat.bitwiseOrFuel
Section titled “Nat.bitwiseOrFuel”def Nat.bitwiseOrFuel (fuel : Nat) (m : Nat) (n : Nat) : NatBitwise or of the lowest fuel bits of m and n.
Nat.bitwiseXorFuel
Section titled “Nat.bitwiseXorFuel”def Nat.bitwiseXorFuel (fuel : Nat) (m : Nat) (n : Nat) : NatBitwise exclusive or of the lowest fuel bits of m and n.
Nat.bitwiseAnd
Section titled “Nat.bitwiseAnd”def Nat.bitwiseAnd (m : Nat) (n : Nat) : NatBitwise and of natural numbers.
Nat.bitwiseOr
Section titled “Nat.bitwiseOr”def Nat.bitwiseOr (m : Nat) (n : Nat) : NatBitwise or of natural numbers.
Nat.bitwiseXor
Section titled “Nat.bitwiseXor”def Nat.bitwiseXor (m : Nat) (n : Nat) : NatBitwise exclusive or of natural numbers.
Nat.min
Section titled “Nat.min”def Nat.min (m : Nat) (n : Nat) : NatThe smaller of two natural numbers.
Nat.max
Section titled “Nat.max”def Nat.max (m : Nat) (n : Nat) : NatThe larger of two natural numbers.
Nat.maxSucc
Section titled “Nat.maxSucc”def Nat.maxSucc (j : Nat) (k : Nat) : succ (max j k) = max (succ j) (succ k)Successor distributes over max: succ (max j k) = max (succ j) (succ k).
Nat.maxComm
Section titled “Nat.maxComm”def Nat.maxComm (m : Nat) (n : Nat) : max m n = max n mCommutativity of max on natural numbers: max m n = max n m.
Option
Section titled “Option”data Option (A : Type)An optional value: nothing, or just a value of type A.
Option.withDefault
Section titled “Option.withDefault”def Option.withDefault {A : Type} (default : A) (mx : Option A) : AThe value inside a Maybe, or the given default when it is nothing.
Option.isSome
Section titled “Option.isSome”def Option.isSome {A : Type} (mx : Option A) : BoolBoolean test for whether a Maybe holds a value.
Option.isNone
Section titled “Option.isNone”def Option.isNone {A : Type} (mx : Option A) : BoolBoolean test for whether a Maybe is nothing.
Option.map
Section titled “Option.map”def Option.map {A B : Type} (f : A -> B) (mx : Option A) : Option BApply a function to the value inside a Maybe, if any.
data Pair (A : Type) (B : Type)A pair of a value of type A and a value of type B.
keepType
Section titled “keepType”def keepType {A : Type} (old : A) (new : A) : AReturn the new value, constrained to have the same type as the old one; used to desugar assignment to a let mut variable.
Pair.fstPair
Section titled “Pair.fstPair”def Pair.fstPair {A B : Type} (p : Pair A B) : AThe first component of a Pair.
Pair.sndPair
Section titled “Pair.sndPair”def Pair.sndPair {A B : Type} (p : Pair A B) : BThe second component of a Pair.
Either
Section titled “Either”data Either (A : Type) (B : Type)A value that is either a left A or a right B.
Either.bimap
Section titled “Either.bimap”def Either.bimap {A B C D : Type} (f : A -> C) (g : B -> D) (e : Either A B) : Either C DOne function applied to a left value, another to a right value.
Either.mapLeft
Section titled “Either.mapLeft”def Either.mapLeft {A B C : Type} (f : A -> C) (e : Either A B) : Either C BA function applied to a left value; a right value stays.
Either.mapRight
Section titled “Either.mapRight”def Either.mapRight {A B D : Type} (g : B -> D) (e : Either A B) : Either A DA function applied to a right value; a left value stays.
Either.swapSides
Section titled “Either.swapSides”def Either.swapSides {A B : Type} (e : Either A B) : Either B AThe sides swapped: a left becomes a right and the other way round.
Either.isLeft
Section titled “Either.isLeft”def Either.isLeft {A B : Type} (e : Either A B) : BoolWhether it is a left value.
Either.isRight
Section titled “Either.isRight”def Either.isRight {A B : Type} (e : Either A B) : BoolWhether it is a right value.
Either.fromLeft
Section titled “Either.fromLeft”def Either.fromLeft {A B : Type} (default : A) (e : Either A B) : AThe value inside a left, or default for a right.
Either.fromRight
Section titled “Either.fromRight”def Either.fromRight {A B : Type} (default : B) (e : Either A B) : BThe value inside a right, or default for a left.
Either.fold
Section titled “Either.fold”def Either.fold {A B C : Type} (f : A -> C) (g : B -> C) (e : Either A B) : Cf of a left value, g of a right value.
data List (A : Type)Finite lists: nil, or an element consed onto a list.
List.map
Section titled “List.map”def List.map {A B : Type} (f : A -> B) (xs : List A) : List BApply a function to every element of a list.
List.filter
Section titled “List.filter”def List.filter {A : Type} (p : A -> Bool) (xs : List A) : List AKeep the elements of a list that satisfy a boolean predicate.
List.append
Section titled “List.append”def List.append {A : Type} (xs : List A) (ys : List A) : List AConcatenate two lists.
List.length
Section titled “List.length”def List.length {A : Type} (xs : List A) : NatThe number of elements in a list.
List.listHead
Section titled “List.listHead”def List.listHead {A : Type} (default : A) (xs : List A) : AThe first element of a list, or the given default for an empty list.
List.listTail
Section titled “List.listTail”def List.listTail {A : Type} (xs : List A) : List AA list without its first element; the empty list stays empty.
List.revAcc
Section titled “List.revAcc”def List.revAcc {A : Type} (xs : List A) (acc : List A) : List AReverse xs onto the front of the accumulator acc; the helper behind reverse.
List.reverse
Section titled “List.reverse”def List.reverse {A : Type} (xs : List A) : List AReverse a list.
List.foldl
Section titled “List.foldl”def List.foldl {A B : Type} (f : B -> A -> B) (z : B) (xs : List A) : BLeft fold: combine the elements from left to right, starting from z.
List.foldr
Section titled “List.foldr”def List.foldr {A B : Type} (f : A -> B -> B) (z : B) (xs : List A) : BRight fold: combine the elements from right to left, ending with z.
List.take
Section titled “List.take”def List.take {A : Type} (n : Nat) (xs : List A) : List AThe first n elements of a list (or the whole list if it is shorter).
List.drop
Section titled “List.drop”def List.drop {A : Type} (n : Nat) (xs : List A) : List AA list without its first n elements.
List.replicate
Section titled “List.replicate”def List.replicate {A : Type} (n : Nat) (x : A) : List AA list of n copies of x.
List.rangeAcc
Section titled “List.rangeAcc”def List.rangeAcc (n : Nat) (acc : List Nat) : List NatThe numbers 0 to n - 1 prepended to acc; the helper behind range.
List.range
Section titled “List.range”def List.range (n : Nat) : List NatThe list of natural numbers 0, 1, …, n - 1.
Nat.addZeroR
Section titled “Nat.addZeroR”def Nat.addZeroR (m : Nat) : add m zero = mZero is a right identity for addition: m + 0 = m.
Nat.addSuccR
Section titled “Nat.addSuccR”def Nat.addSuccR (m : Nat) (n : Nat) : add m (succ n) = succ (add m n)Successor in the right summand moves outside: m + succ n = succ (m + n).
Nat.addAssoc
Section titled “Nat.addAssoc”def Nat.addAssoc (m : Nat) (n : Nat) (o : Nat) : add m (add n o) = add (add m n) oAssociativity of natural-number addition, right-nested to left-nested: m + (n + o) = (m + n) + o.
Bool.notnot
Section titled “Bool.notnot”def Bool.notnot (x : Bool) : not (not x) = xBoolean negation is an involution: not (not x) = x.
Bool.andTrue
Section titled “Bool.andTrue”def Bool.andTrue (a : Bool) : and a true = aTrue is a right identity for conjunction: and a true = a.
Bool.orFalse
Section titled “Bool.orFalse”def Bool.orFalse (a : Bool) : or a false = aFalse is a right identity for disjunction: or a false = a.
Bool.andFalse
Section titled “Bool.andFalse”def Bool.andFalse (a : Bool) : and a false = falseFalse absorbs conjunction on the right: and a false = false.
Bool.orTrue
Section titled “Bool.orTrue”def Bool.orTrue (a : Bool) : or a true = trueTrue absorbs disjunction on the right: or a true = true.
Bool.notTrue
Section titled “Bool.notTrue”def Bool.notTrue : not true = falseThe negation of true is false.
Bool.notFalse
Section titled “Bool.notFalse”def Bool.notFalse : not false = trueThe negation of false is true.
Nat.addZeroL
Section titled “Nat.addZeroL”def Nat.addZeroL (m : Nat) : add zero m = mZero is a left identity for addition: 0 + m = m.
Nat.addComm
Section titled “Nat.addComm”def Nat.addComm (m : Nat) (n : Nat) : add m n = add n mCommutativity of natural-number addition: m + n = n + m.
List.appendNil
Section titled “List.appendNil”def List.appendNil {A : Type} (xs : List A) : append xs nil = xsThe empty list is a right identity for append: append xs nil = xs.
Nat.subZero
Section titled “Nat.subZero”def Nat.subZero (m : Nat) : sub m zero = mZero is a right identity for truncated subtraction: m - 0 = m.
Nat.mulZeroR
Section titled “Nat.mulZeroR”def Nat.mulZeroR (m : Nat) : mul m zero = zeroZero absorbs multiplication on the right: m * 0 = 0.
Nat.mulOneR
Section titled “Nat.mulOneR”def Nat.mulOneR (m : Nat) : mul m (succ zero) = mOne is a right identity for multiplication: m * 1 = m.
Nat.addSwap
Section titled “Nat.addSwap”def Nat.addSwap (n : Nat) (k : Nat) (x : Nat) : add n (add k x) = add k (add n x)Swap the first two summands of a right-nested sum: n + (k + x) = k + (n + x).
Nat.mulSuccR
Section titled “Nat.mulSuccR”def Nat.mulSuccR (m : Nat) (n : Nat) : mul m (succ n) = add m (mul m n)Multiplication by a successor adds one copy: m * succ n = m + m * n.
List.nthOption
Section titled “List.nthOption”def List.nthOption {A : Type} (xs : List A) (n : Nat) : Option AReturns the element at the given index, or none when the index is out of range.
List.headOption
Section titled “List.headOption”def List.headOption {A : Type} (xs : List A) : Option AThe first element of a list, or none for an empty list.
List.zip
Section titled “List.zip”def List.zip {A B : Type} (xs : List A) (ys : List B) : List (Pair A B)Pair up corresponding elements of two lists, stopping at the shorter one.
List.zip3
Section titled “List.zip3”def List.zip3 {A B C : Type} (xs : List A) (ys : List B) (zs : List C) : List (Pair A (Pair B C))Combine three lists elementwise into right-nested triples, stopping at the shortest.
List.enumerate
Section titled “List.enumerate”def List.enumerate {A : Type} (xs : List A) : List (Pair Nat A)Pair every element of a list with its index, counting from 0.
concat
Section titled “concat”def concat {A : Type} (xss : List (List A)) : List AFlatten a list of lists into one list.
List.concatMap
Section titled “List.concatMap”def List.concatMap {A B : Type} (f : A -> List B) (xs : List A) : List BMap each element to a list and concatenate the results.
class Monad (M : Type -> Type)A monad: pure puts a value in, bind runs a computation and feeds its result to the next one. do blocks are written with these.
monadOption
Section titled “monadOption”instance monadOption : Monad OptionMaybe is a monad: bind stops at the first nothing.
monadEither
Section titled “monadEither”instance monadEither (E : Type) : Monad (Either E)Either E is a monad: bind stops at the first left.
monadList
Section titled “monadList”instance monadList : Monad ListList is a monad: bind maps each element to a list and concatenates the results.
LoopCtl
Section titled “LoopCtl”data LoopCtl (S : Type)Loop body result for loops using break or continue: continue with a state, or stop with a state.
LoopStep
Section titled “LoopStep”data LoopStep (R : Type) (S : Type)Loop body result for loops using return: continue, break, or return a value early.
forInListM
Section titled “forInListM”def forInListM {M : Type -> Type} {{inst : Monad M}} {A : Type} {S : Type} (xs : List A) (s : S) (f : A -> S -> M S) : M SExpansion of for x in xs do ... in any monad: runs f on each element in order, threading a state through.
forInListCtlM
Section titled “forInListCtlM”def forInListCtlM {M : Type -> Type} {{inst : Monad M}} {A : Type} {S : Type} (xs : List A) (s : S) (f : A -> S -> M (LoopCtl S)) : M SLike forInListM, for loops using break or continue.
forInListRM
Section titled “forInListRM”def forInListRM {M : Type -> Type} {{inst : Monad M}} {A : Type} {R : Type} {S : Type} (xs : List A) (s : S) (f : A -> S -> M (LoopStep R S)) : M (Either R S)Like forInListM, for loops using return: left v is an early return, right s the state at the end.
List.any
Section titled “List.any”def List.any {A : Type} (p : A -> Bool) (xs : List A) : BoolWhether some element of the list satisfies the predicate.
List.all
Section titled “List.all”def List.all {A : Type} (p : A -> Bool) (xs : List A) : BoolWhether every element of the list satisfies the predicate.
List.elemNat
Section titled “List.elemNat”def List.elemNat (x : Nat) (xs : List Nat) : BoolWhether a natural number occurs in a list of natural numbers.
List.mapAppend
Section titled “List.mapAppend”def List.mapAppend {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 append is appending the maps: map f (xs ++ ys) = map f xs ++ map f ys.
List.lengthAppend
Section titled “List.lengthAppend”def List.lengthAppend {A : Type} (xs : List A) (ys : List A) : length (append xs ys) = add (length xs) (length ys)The length of an append is the sum of the lengths: length (xs ++ ys) = length xs + length ys.
data UnitThe unit type, with the single element unit.
isContrUnit
Section titled “isContrUnit”def isContrUnit : (center : Unit) × ((x : Unit) -> center ≡ x)The unit type is contractible.
data EmptyThe empty type, with no constructors.
data Dec (A : Type)A decision for A: either an element of A or a refutation of A.
absurd
Section titled “absurd”def absurd {A : Type} (e : Empty) : AEx falso: from an element of Empty, produce an element of any type.
Nat.pred
Section titled “Nat.pred”def Nat.pred (n : Nat) : NatPredecessor of a natural number, sending zero to zero.
Nat.addSuccL
Section titled “Nat.addSuccL”def Nat.addSuccL (m : Nat) (n : Nat) : add (succ m) n = succ (add m n)Successor in the left summand moves outside: succ m + n = succ (m + n).
Nat.double
Section titled “Nat.double”def Nat.double (n : Nat) : NatDouble a natural number: n + n.
Bool.andComm
Section titled “Bool.andComm”def Bool.andComm (a : Bool) (b : Bool) : and a b = and b aCommutativity of boolean conjunction: and a b = and b a.
Bool.orComm
Section titled “Bool.orComm”def Bool.orComm (a : Bool) (b : Bool) : or a b = or b aCommutativity of boolean disjunction: or a b = or b a.
Bool.andAssoc
Section titled “Bool.andAssoc”def Bool.andAssoc (a : Bool) (b : Bool) (c : Bool) : and (and a b) c = and a (and b c)Associativity of boolean conjunction: and (and a b) c = and a (and b c).
Bool.orAssoc
Section titled “Bool.orAssoc”def Bool.orAssoc (a : Bool) (b : Bool) (c : Bool) : or (or a b) c = or a (or b c)Associativity of boolean disjunction: or (or a b) c = or a (or b c).
Bool.deMorgan1
Section titled “Bool.deMorgan1”def Bool.deMorgan1 (a : Bool) (b : Bool) : not (and a b) = or (not a) (not b)De Morgan’s law for conjunction: not (and a b) = or (not a) (not b).
Bool.deMorgan2
Section titled “Bool.deMorgan2”def Bool.deMorgan2 (a : Bool) (b : Bool) : not (or a b) = and (not a) (not b)De Morgan’s law for disjunction: not (or a b) = and (not a) (not b).
Nat.isZero
Section titled “Nat.isZero”def Nat.isZero (n : Nat) : BoolBoolean test for whether a natural number is zero.
Nat.isSucc
Section titled “Nat.isSucc”def Nat.isSucc (n : Nat) : BoolBoolean test for whether a natural number is a successor (nonzero).
Nat.pow
Section titled “Nat.pow”def Nat.pow (m : Nat) (n : Nat) : NatNatural-number exponentiation: m ^ n.
Nat.factorial
Section titled “Nat.factorial”def Nat.factorial (n : Nat) : NatFactorial: n! = n * (n - 1) * … * 1, with 0! = 1.
Nat.fibAcc
Section titled “Nat.fibAcc”def Nat.fibAcc (n : Nat) (a : Nat) (b : Nat) : NatFibonacci helper: run n steps of (a, b) to (b, a + b) and return a.
Nat.fib
Section titled “Nat.fib”def Nat.fib (n : Nat) : NatThe n-th Fibonacci number, with fib 0 = 0 and fib 1 = 1.
def id {A : Type} (a : A) : AThe identity function.
def const {A B : Type} (a : A) (b : B) : AThe constant function: return a and ignore b.
List.appendAssoc
Section titled “List.appendAssoc”def List.appendAssoc {A : Type} (xs : List A) (ys : List A) (zs : List A) : append (append xs ys) zs = append xs (append ys zs)Associativity of list append: (xs ++ ys) ++ zs = xs ++ (ys ++ zs).
List.mapId
Section titled “List.mapId”def List.mapId {A : Type} (xs : List A) : map (fun (x : A) => x) xs = xsMapping the identity function over a list changes nothing.
List.lengthMap
Section titled “List.lengthMap”def List.lengthMap {A B : Type} (f : A -> B) (xs : List A) : length (map f xs) = length xsMapping preserves length: length (map f xs) = length xs.
List.lengthReplicate
Section titled “List.lengthReplicate”def List.lengthReplicate {A : Type} (n : Nat) (x : A) : length (replicate n x) = nA list of n copies has length n.
data Le : Nat -> Nat -> TypeThe inductive <= relation on naturals: Le m n holds when m <= n (0 <= n, and m <= n gives m + 1 <= n + 1).
Nat.addOneSucc
Section titled “Nat.addOneSucc”def Nat.addOneSucc (m : Nat) : add m (succ zero) = succ mAdding one is the successor: m + 1 = succ m.
List.intersperse
Section titled “List.intersperse”def List.intersperse {A : Type} (sep : A) (xs : List A) : List APut the separator between every two adjacent elements of a list.
List.partition
Section titled “List.partition”def List.partition {A : Type} (p : A -> Bool) (xs : List A) : Pair (List A) (List A)Split a list into the elements that satisfy a predicate and those that do not, keeping order.
List.span
Section titled “List.span”def List.span {A : Type} (p : A -> Bool) (xs : List A) : Pair (List A) (List A)Split a list at the first element failing the predicate: the longest satisfying prefix and the rest.
List.takeWhile
Section titled “List.takeWhile”def List.takeWhile {A : Type} (p : A -> Bool) (xs : List A) : List AThe longest prefix of a list whose elements satisfy the predicate.
List.dropWhile
Section titled “List.dropWhile”def List.dropWhile {A : Type} (p : A -> Bool) (xs : List A) : List AA list without its longest prefix of elements satisfying the predicate.
List.find
Section titled “List.find”def List.find {A : Type} (p : A -> Bool) (xs : List A) : Option AThe first element of a list that satisfies the predicate, or nothing.
Nat.iterate
Section titled “Nat.iterate”def Nat.iterate {A : Type} (n : Nat) (f : A -> A) (x : A) : AApply f to x n times.
List.sum
Section titled “List.sum”def List.sum (xs : List Nat) : NatThe sum of a list of natural numbers.
List.product
Section titled “List.product”def List.product (xs : List Nat) : NatThe product of a list of natural numbers.
Nat.mulZeroL
Section titled “Nat.mulZeroL”def Nat.mulZeroL (n : Nat) : mul zero n = zeroZero absorbs multiplication on the left: 0 * n = 0.
Nat.mulOneL
Section titled “Nat.mulOneL”def Nat.mulOneL (n : Nat) : mul (succ zero) n = nOne is a left identity for multiplication: 1 * n = n.
Nat.beqRefl
Section titled “Nat.beqRefl”def Nat.beqRefl (n : Nat) : Nat.beq n n = trueBoolean equality on natural numbers is reflexive: Nat.beq n n = true.
Option.bind
Section titled “Option.bind”def Option.bind {A B : Type} (mx : Option A) (f : A -> Option B) : Option BMonadic bind for Maybe: apply f to the value if there is one, otherwise nothing.
Option.orElse
Section titled “Option.orElse”def Option.orElse {A : Type} (mx : Option A) (my : Option A) : Option AThe first Maybe if it holds a value, otherwise the second.
catMaybes
Section titled “catMaybes”def catMaybes {A : Type} (xs : List (Option A)) : List AKeep the values of the just elements of a list, dropping the nothings.
List.mapOptionFn
Section titled “List.mapOptionFn”def List.mapOptionFn {A B : Type} (f : A -> Option B) (xs : List A) : List BApply a partial function to every element, keeping only the successful results.
def apply {A B : Type} (f : A -> B) (x : A) : BFunction application: apply f x = f x.
Stream
Section titled “Stream”codata Stream {i : Size} (A : Type)Infinite streams, as a sized coinductive type with head and tail.
Stream.zeros
Section titled “Stream.zeros”def Stream.zeros : Stream NatThe stream of all zeros.
Stream.nats_from
Section titled “Stream.nats_from”def Stream.nats_from (n : Nat) : Stream NatThe stream n, n + 1, n + 2, …
Stream.nats
Section titled “Stream.nats”def Stream.nats : Stream NatThe stream of all natural numbers 0, 1, 2, …
Stream.repeat
Section titled “Stream.repeat”def Stream.repeat {A : Type} (a : A) : Stream AThe stream that repeats a forever.
codata CoNat {i : Size}Conatural numbers (possibly infinite), observed through an optional predecessor.
CoNat.coZero
Section titled “CoNat.coZero”def CoNat.coZero : CoNatThe conatural zero, which has no predecessor.
CoNat.coSucc
Section titled “CoNat.coSucc”def CoNat.coSucc (n : CoNat) : CoNatThe conatural successor of n.
CoNat.infinity
Section titled “CoNat.infinity”def CoNat.infinity : CoNatThe infinite conatural number, its own predecessor.
Stream.take_stream
Section titled “Stream.take_stream”def Stream.take_stream {A : Type} (n : Nat) (s : Stream A) : List AThe first n elements of a stream, as a list.
Stream.map_stream
Section titled “Stream.map_stream”def Stream.map_stream {A B : Type} (f : A -> B) (s : Stream A) : Stream BApply a function to every element of a stream.
Stream.iterate_stream
Section titled “Stream.iterate_stream”def Stream.iterate_stream {A : Type} (f : A -> A) (a : A) : Stream AThe stream a, f a, f (f a), …
Stream.zipWith_stream
Section titled “Stream.zipWith_stream”def Stream.zipWith_stream {A B : Type} {C : Type} (f : A -> B -> C) (s1 : Stream A) (s2 : Stream B) : Stream CCombine two streams elementwise with a function.
Stream.drop_stream
Section titled “Stream.drop_stream”def Stream.drop_stream {A : Type} (n : Nat) (s : Stream A) : Stream AA stream without its first n elements.
Stream.interleave
Section titled “Stream.interleave”def Stream.interleave {A : Type} (s1 : Stream A) (s2 : Stream A) : Stream AAlternate the elements of two streams, starting with the first.
CoNat.fromNat
Section titled “CoNat.fromNat”def CoNat.fromNat (n : Nat) : CoNatEmbed a natural number into the conatural numbers.
Colist
Section titled “Colist”codata Colist {i : Size} (A : Type)Possibly infinite lists, observed through uncons: nothing for empty, or a head and a tail.
def conil (A : Type) : Colist AThe empty colist.
cocons
Section titled “cocons”def cocons (A : Type) (x : A) (xs : Colist A) : Colist APrepend an element to a colist.
fromList
Section titled “fromList”def fromList (A : Type) (xs : List A) : Colist AConvert a finite list into a colist.
CoTree
Section titled “CoTree”codata CoTree {i : Size} (A : Type)Infinite binary trees with a label and left and right subtrees.
const_tree
Section titled “const_tree”def const_tree (A : Type) (a : A) : CoTree AThe infinite binary tree whose every label is a.
Process
Section titled “Process”codata Process {i : Size} (I : Type) (O : Type)A pure coinductive process that, on each input, produces an output and the next process.
Process.echoProcess
Section titled “Process.echoProcess”def Process.echoProcess : Process Nat NatThe process that outputs each natural-number input unchanged, forever.
codata M {i : Size} (S : Type) (P : S -> Type)The general coinductive M-type: a shape together with subtrees indexed by the positions of that shape.
Bool.xor
Section titled “Bool.xor”def Bool.xor (a : Bool) (b : Bool) : BoolBoolean exclusive or.
Bool.xorComm
Section titled “Bool.xorComm”def Bool.xorComm (a : Bool) (b : Bool) : xor a b = xor b aCommutativity of exclusive or: xor a b = xor b a.
Bool.xorFalse
Section titled “Bool.xorFalse”def Bool.xorFalse (a : Bool) : xor a false = aFalse is a right identity for exclusive or: xor a false = a.
Bool.xorSelf
Section titled “Bool.xorSelf”def Bool.xorSelf (a : Bool) : xor a a = falseAnything exclusive-or itself is false: xor a a = false.
Bool.implies
Section titled “Bool.implies”def Bool.implies (a : Bool) (b : Bool) : BoolBoolean implication: not a or b.
List.filterTrue
Section titled “List.filterTrue”def List.filterTrue {A : Type} (xs : List A) : filter (fun (x : A) => true) xs = xsFiltering with the always-true predicate keeps the whole list.
List.filterFalse
Section titled “List.filterFalse”def List.filterFalse {A : Type} (xs : List A) : filter (fun (x : A) => false) xs = nilFiltering with the always-false predicate gives the empty list.
Pair.swapPair
Section titled “Pair.swapPair”def Pair.swapPair {A B : Type} (p : Pair A B) : Pair B ASwap the two components of a Pair.
Pair.mapPair
Section titled “Pair.mapPair”def Pair.mapPair {A B : Type} {C : Type} {D : Type} (f : A -> C) (g : B -> D) (p : Pair A B) : Pair C DApply one function to each component of a Pair.
List.nth
Section titled “List.nth”def List.nth {A : Type} (default : A) (n : Nat) (xs : List A) : AThe element at index n of a list (counting from 0), or the default when the index is out of range.
List.snoc
Section titled “List.snoc”def List.snoc {A : Type} (xs : List A) (x : A) : List AAppend an element at the end of a list.
List.last
Section titled “List.last”def List.last {A : Type} (default : A) (xs : List A) : AThe last element of a list, or the default for an empty list.
List.initList
Section titled “List.initList”def List.initList {A : Type} (xs : List A) : List AA list without its last element; the empty list stays empty.
List.mapNil
Section titled “List.mapNil”def List.mapNil {A B : Type} (f : A -> B) : map f (nil : List A) = (nil : List B)Mapping over the empty list gives the empty list.
List.mapSingleton
Section titled “List.mapSingleton”def List.mapSingleton {A B : Type} (f : A -> B) (x : A) : map f (cons x nil) = cons (f x) (nil : List B)Mapping over a one-element list: map f [x] = [f x].
List.lengthSingleton
Section titled “List.lengthSingleton”def List.lengthSingleton {A : Type} (x : A) : length (cons x (nil : List A)) = succ zeroA one-element list has length one.
List.reverseNilStd
Section titled “List.reverseNilStd”def List.reverseNilStd {A : Type} : reverse (nil : List A) = (nil : List A)Reversing the empty list gives the empty list.
List.foldlNil
Section titled “List.foldlNil”def List.foldlNil {A B : Type} (f : B -> A -> B) (z : B) : foldl f z (nil : List A) = zA left fold over the empty list returns the initial value.
List.foldrNil
Section titled “List.foldrNil”def List.foldrNil {A B : Type} (f : A -> B -> B) (z : B) : foldr f z (nil : List A) = zA right fold over the empty list returns the initial value.
Pair.swapPairInvol
Section titled “Pair.swapPairInvol”def Pair.swapPairInvol {A B : Type} (p : Pair A B) : swapPair (swapPair p) = pSwapping a Pair twice gives it back.
Pair.mapPairId
Section titled “Pair.mapPairId”def Pair.mapPairId {A B : Type} (p : Pair A B) : mapPair (fun (a : A) => a) (fun (b : B) => b) p = pMapping identity functions over both components of a Pair changes nothing.
data PosPositive binary numbers, least significant bit outermost: xH is 1, xO p is 2p, xI p is 2p + 1.
data BinBinary natural numbers: zero, or a positive binary number.
data CharA character, given by its Unicode code point in binary.
String
Section titled “String”data StringA string, as a list of characters.
OptionPrim
Section titled “OptionPrim”data OptionPrim (A : Type)A local optional type used as the result of construct, to signal that reconstruction failed.
Principal
Section titled “Principal”data PrincipalAn owner identity, named by a string; used by the ownership predicate Owns.
proofIrrelevantTag
Section titled “proofIrrelevantTag”def proofIrrelevantTag (0 _tag : Nat) (n : Nat) : NatReturn the second argument, ignoring an erased (usage-0) Nat tag that only takes part in type checking.
proofIrrelevantWitnessZero
Section titled “proofIrrelevantWitnessZero”def proofIrrelevantWitnessZero : NatA use of proofIrrelevantTag with tag zero, evaluating to one.
proofIrrelevantWitnessSucc
Section titled “proofIrrelevantWitnessSucc”def proofIrrelevantWitnessSucc : NatA use of proofIrrelevantTag with tag one, evaluating to one; it is interchangeable with the zero-tag use under proof irrelevance.
Nat.beqSym
Section titled “Nat.beqSym”def Nat.beqSym (a : Nat) (b : Nat) : Nat.beq a b = Nat.beq b aBoolean equality on natural numbers is symmetric: Nat.beq a b = Nat.beq b a.
Nat.bleRefl
Section titled “Nat.bleRefl”def Nat.bleRefl (n : Nat) : Nat.ble n n = trueBoolean less-than-or-equal on natural numbers is reflexive: Nat.ble n n = true.
List.mapComp
Section titled “List.mapComp”def List.mapComp {A B : Type} {C : Type} (f : A -> B) (g : B -> C) (xs : List A) : map g (map f xs) = map (fun (x : A) => g (f x)) xsMapping twice is mapping the composition: map g (map f xs) = map (g ∘ f) xs.
List.zipWith
Section titled “List.zipWith”def List.zipWith {A B : Type} {C : Type} (f : A -> B -> C) (xs : List A) (ys : List B) : List CCombine two lists elementwise with a function, stopping at the shorter one.
Option.toList
Section titled “Option.toList”def Option.toList (A : Type) (mx : Option A) : List AConvert a Maybe to a list of zero or one elements.
decToBool
Section titled “decToBool”def decToBool {P : Type} (d : Dec P) : BoolForget a decision procedure’s evidence, keeping only whether it answered yes.
tfCode
Section titled “tfCode”def tfCode (b : Bool) : TypeSend true to Unit and false to Empty; used to tell true and false apart.
trueNeFalse
Section titled “trueNeFalse”def trueNeFalse (p : true = false) : EmptyTrue is not false: a path true = false yields Empty.
Bool.boolInspect
Section titled “Bool.boolInspect”def Bool.boolInspect (b : Bool) (P : Bool -> Type) : (b = true -> P true) -> (b = false -> P false) -> P bCase analysis on a boolean that also remembers which value it is (Agda’s inspect pattern).
Nat.bltSuccR
Section titled “Nat.bltSuccR”def Nat.bltSuccR (x : Nat) (n : Nat) (h : Nat.blt x n = true) : Nat.blt x (succ n) = trueA strict upper bound can be raised by one: x < n implies x < n + 1.
Nat.bltSelfSucc
Section titled “Nat.bltSelfSucc”def Nat.bltSelfSucc (m : Nat) : Nat.blt m (succ m) = trueEvery natural number is strictly less than its successor: m < m + 1.
Nat.bltZeroAbsurd
Section titled “Nat.bltZeroAbsurd”def Nat.bltZeroAbsurd {A : Type} (m : Nat) (h : Nat.blt m zero = true) : ANothing is below zero: a proof of m < 0 eliminates into any type (the base case of termination_by).
Nat.subLtSucc
Section titled “Nat.subLtSucc”def Nat.subLtSucc (m : Nat) (x : Nat) : Nat.blt (sub m x) (succ m) = trueTruncated subtraction stays below the successor: m - x < m + 1.
def subLt (m : Nat) (k : Nat) (j : Nat) (h : Nat.blt m (succ k) = true) (e : Nat.blt m (succ j) = false) : Nat.blt (sub m (succ j)) k = trueIf m < k + 1 and not m < j + 1, then m - (j + 1) < k.
Nat.modAuxStep
Section titled “Nat.modAuxStep”def Nat.modAuxStep (c : Bool) (m : Nat) (k : Nat) (j : Nat) : NatThe shape of modAuxFuel after one step, branching on whether m < j + 1; a proof helper for modAuxLt.
Nat.modAuxLt
Section titled “Nat.modAuxLt”def Nat.modAuxLt (k : Nat) : (m : Nat) -> (j : Nat) -> Nat.blt m k = true -> Nat.blt (modAuxFuel k m (succ j)) (succ j) = trueWith enough fuel (m < k), the remainder computed by modAuxFuel is less than the divisor j + 1.
Nat.modLt
Section titled “Nat.modLt”def Nat.modLt (m : Nat) (n : Nat) : Nat.blt (Nat.mod m (succ n)) (succ n) = trueThe remainder modulo n + 1 is less than n + 1.
Nat.subAddCancel
Section titled “Nat.subAddCancel”def Nat.subAddCancel (n : Nat) : (m : Nat) -> Nat.blt m n = false -> add n (sub m n) = mSubtracting and adding back cancels when n <= m: n + (m - n) = m.
Nat.addRotate
Section titled “Nat.addRotate”def Nat.addRotate (n : Nat) (x : Nat) (s : Nat) : add (add n x) s = add x (add n s)Moving the first summand inward: (n + x) + s = x + (n + s).
Nat.divAuxStep
Section titled “Nat.divAuxStep”def Nat.divAuxStep (c : Bool) (k : Nat) (q : Nat) (m : Nat) (j : Nat) : NatThe shape of divAuxFuel after one step, branching on whether m < j + 1; a proof helper for divModAuxEq.
Nat.divModStepEq
Section titled “Nat.divModStepEq”def Nat.divModStepEq (c : Bool) (k : Nat) (q : Nat) (m : Nat) (j : Nat) : TypeThe statement of divModAuxEq after one step; a proof helper.
Nat.divModAuxEq
Section titled “Nat.divModAuxEq”def Nat.divModAuxEq (f : Nat) : (q : Nat) -> (m : Nat) -> (j : Nat) -> add (mul (divAuxFuel f q m (succ j)) (succ j)) (modAuxFuel f m (succ j)) = add (mul q (succ j)) mThe division invariant of the fuelled helpers, for any fuel: quotient × divisor + remainder = q × divisor + m.
Nat.divModEq
Section titled “Nat.divModEq”def Nat.divModEq (m : Nat) (j : Nat) : add (mul (Nat.div m (succ j)) (succ j)) (Nat.mod m (succ j)) = mDivision with remainder: (m / (j + 1)) × (j + 1) + m mod (j + 1) = m.
Nat.bltTrans
Section titled “Nat.bltTrans”def Nat.bltTrans (m n p : Nat) (h1 : Nat.blt m n = true) (h2 : Nat.blt n p = true) : Nat.blt m p = trueTransitivity of the strict boolean order Nat.blt on natural numbers.
Nat.bltPredL
Section titled “Nat.bltPredL”def Nat.bltPredL (m : Nat) (n : Nat) (h : Nat.blt (succ m) n = true) : Nat.blt m n = trueDropping one from the left of a strict bound: m + 1 < n implies m < n.
Nat.bleSuccR
Section titled “Nat.bleSuccR”def Nat.bleSuccR (a : Nat) (c : Nat) (h : Nat.ble a c = true) : Nat.ble a (succ c) = trueRaising a bound by one: a <= c implies a <= c + 1.
Nat.bleSuccL
Section titled “Nat.bleSuccL”def Nat.bleSuccL (a : Nat) (c : Nat) (h : Nat.ble (succ a) c = true) : Nat.ble a c = trueDropping one from the left of a bound: a + 1 <= c implies a <= c.
Nat.bleAddL
Section titled “Nat.bleAddL”def Nat.bleAddL (a : Nat) (b : Nat) (c : Nat) (h : Nat.ble (add a b) c = true) : Nat.ble a c = trueThe left summand of a bounded sum is bounded: a + b <= c implies a <= c.
Nat.bleAddR
Section titled “Nat.bleAddR”def Nat.bleAddR (a : Nat) (b : Nat) (c : Nat) (h : Nat.ble (add a b) c = true) : Nat.ble b c = trueThe right summand of a bounded sum is bounded: a + b <= c implies b <= c.
Nat.addPosL
Section titled “Nat.addPosL”def Nat.addPosL (x : Nat) (y : Nat) (hx : Nat.blt 0 x = true) : Nat.blt 0 (add x y) = trueA sum with a positive left summand is positive: 0 < x implies 0 < x + y.
Nat.powTwoPos
Section titled “Nat.powTwoPos”def Nat.powTwoPos (k : Nat) : Nat.blt 0 (Nat.pow 2 k) = trueEvery power of two is positive: 0 < 2 ^ k.
IsTrue
Section titled “IsTrue”data IsTrue : Bool -> TypeIsTrue b: the Boolean b computes to true. Use it for preconditions written as Boolean
expressions (it needs no elimination of Eq); prove it for a concrete value with isTrue.
IsTrue.toEq
Section titled “IsTrue.toEq”def toEq {b : Bool} (h : IsTrue b) : Eq Bool b trueThe truth of a Boolean as an equality.
IsTrue.ofEq
Section titled “IsTrue.ofEq”def ofEq {b : Bool} (h : Eq Bool b true) : IsTrue bAn equality with true as the truth of a Boolean.
Bool.falseNeTrue
Section titled “Bool.falseNeTrue”def falseNeTrue (h : Eq Bool false true) : Emptyfalse and true are different.
def DecEq (A : Type) : TypeA 的相等可判定:任兩個值,x = y 成立或不成立(同 Lean 的 DecidableEq)。
路徑版是 foundations 的 isDiscrete(給 Hedberg);DecEq.toDiscrete(hlevel)由這個轉過去。
Nat.succInj
Section titled “Nat.succInj”def succInj {m : Nat} {n : Nat} (h : Eq Nat (succ m) (succ n)) : Eq Nat m nsucc is injective.
Path.cong
Section titled “Path.cong”def Path.cong {l : Level} {m : Level} {A : Type l} {B : Type m} {a : A} {b : A} (p : a ≡ b) (f : A -> B) : f a ≡ f bApplies f to both ends of a path: p.cong(f) runs from f a to f b.