Is there any correspondence between the coproduct(sum) type in type theory and arithmetical summation?
For example what does 3+4 or x+6 mean in type theory?
Computer Science Stack Exchange is a question and answer site for students, researchers and practitioners of computer science. It only takes a minute to sign up.
Sign up to join this communityIs there any correspondence between the coproduct(sum) type in type theory and arithmetical summation?
For example what does 3+4 or x+6 mean in type theory?
The arithmetic notation in type theory is motivated by the behaviour on sets, where the disjoint union $A + B$ has $|A| + |B|$ elements; the cartesian product has $|A| \times |B|$ elements; and the set of functions $B^A$ has $|B|^{|A|}$ elements. Sum, product and function types satisfy many of the usual identities you expect of arithmetic (although typically up to isomorphism, rather than equality).
The paper Objects of Categories as Complex Numbers by Marcelo Fiore and Tom Leinster explores this in some detail, though it helps to have a little experience with algebra or category theory.
Sometimes a natural number $n$ will denote a type with exactly $n$ terms in any context (analogous to a set with $n$ elements). In this setting, $3 + 4 \cong 7$ as types. $x + 6$ isn't well-formed without placing $x$ in some context.
type TWO = A + B
and type THREE = C + D + E
and then the sum type TWO + THREE
would have five possible type constructors, corresponding to A
, B
, C
, D
or E
, which you could case split on. Does this help?
$\endgroup$
X
is a specific type, then a polynomial X * X + X + 1
corresponds to a type (either a pair of X
s, a single X
or nothing). Here +
represents "or", which can be considered the disjoint union of sets. Adding and multiplying polynomials of types acts in the same way you would add and multiply polynomials of integers. Case-splitting corresponds to case
, match
or switch
in the type theory; and the piecewise notation in typical mathematics.
$\endgroup$