Kappa calculus explained

In mathematical logic, category theory, andcomputer science, kappa calculus is aformal system for defining first-orderfunctions.

Unlike lambda calculus, kappa calculus has nohigher-order functions; its functions arenot first class objects. Kappa-calculus can beregarded as "a reformulation of the first-order fragment of typedlambda calculus".

Because its functions are not first-class objects, evaluation of kappacalculus expressions does not requireclosures.

Definition

The definition below has been adapted from the diagrams on pages 205 and 207 of Hasegawa.

Grammar

Kappa calculus consists of types and expressions, given by thegrammar below:

\tau= 1\mid \tau x \tau\mid \ldots

e= x\mid id\tau\mid !\tau\mid \operatorname{lift}\tau(e)\mid e\circe\mid \kappax:1{\to}\tau.e

In other words,

\tau1

and

\tau2

are types then

\tau1 x \tau2

is a type.

id\tau

is an expression

!\tau

is an expression

\operatorname{lift}\tau(e)

is an expression

e1

and

e2

are expressions then

e1\circe2

is an expression

\kappax{:}1{\to}\tau.e

is an expression

The

:1{\to}\tau

and the subscripts of,, and

\operatorname{lift}

aresometimes omitted when they can be unambiguously determined from thecontext.

Juxtaposition is often used as an abbreviation for a combination of

\operatorname{lift}

and composition:

e1e2 \overset\operatorname{def}{=}e1\circ\operatorname{lift}(e2)

Typing rules

The presentation here uses sequents (

\Gamma\vdashe:\tau

) rather than hypothetical judgments in order to ease comparison with the simply typed lambda calculus. This requires the additional Var rule, which does not appear in Hasegawa

In kappa calculus an expression has two types: the type of its source and the type of its target. The notation

e:\tau1{\to}\tau2

is used to indicate that expression e has source type

{\tau1}

and target type

{\tau2}

.

Expressions in kappa calculus are assigned types according to the following rules:

{x{:}1{\to}\tau\in\Gamma}\over{\Gamma\vdashx:1{\to}\tau}

(Var)

{}\over{\vdashid\tau:\tau\to\tau}

(Id)

{}\over{\vdash!\tau:\tau\to1}

(Bang)

{\Gamma\vdashe1{:}\tau1{\to}\tau2        \Gamma\vdashe2{:}\tau2{\to}\tau3 }\over{\Gamma\vdashe2\circe1:\tau1{\to}\tau3}

(Comp)

{\Gamma\vdashe{:}1{\to}\tau1} \over {\Gamma\vdash

\operatorname{lift}
\tau2

(e):\tau2\to(\tau1 x \tau2)}

(Lift)

{\Gamma,x{:}1{\to}\tau1 \vdashe:\tau2{\to}\tau3} \over {\Gamma\vdash\kappax{:}1{\to}\tau1.e:\tau1 x \tau2\to\tau3}

(Kappa)

In other words,

x:1{\to}\tau

lets you conclude that

x:1{\to}\tau

id\tau:\tau{\to}\tau

!\tau:\tau{\to}1

e1

matches the source type of

e2

they may be composed to form an expression

e2\circe1

with the source type of

e1

and target type of

e2

e:1{\to}\tau1

, then
\operatorname{lift}
\tau2

(e):\tau2{\to}(\tau1 x \tau2)

e:\tau2\to\tau3

under the assumption that

x:1{\to}\tau1

, then we may conclude without that assumption that

\kappax{:}1{\to}\tau1.e:\tau1 x \tau2\to\tau3

Equalities

Kappa calculus obeys the following equalities:

f:\tau1{\to}\tau2

then
f{\circ}id
\tau1

=f

and
f=id
\tau2

{\circ}f

f:\tau1{\to}\tau2

,

g:\tau2{\to}\tau3

, and

h:\tau3{\to}\tau4

, then

(h{\circ}g){\circ}f=h{\circ}(g{\circ}f)

.

f{:}\tau{\to}1

and

g{:}\tau{\to}1

then

f=g

(\kappax.f)\circ\operatorname{lift}\tau(c)=f[c/x]

\kappax.(h\circ\operatorname{lift}\tau(x))=h

if x is not free in h

The last two equalities are reduction rules for the calculus,rewriting from left to right.

Properties

The type can be regarded as the unit type. Because of this, any two functions whose argument type is the same and whose result type is should be equal – since there is only a single value of type both functions must return that value for every argument (Terminality).

Expressions with type

1{\to}\tau

can be regarded as "constants" or values of "ground type"; this is because is the unit type, and so a function from this type is necessarily a constant function. Note that the kappa rule allows abstractions only when the variable being abstracted has the type

1{\to}\tau

for some . This is the basic mechanism which ensures that all functions are first-order.

Categorical semantics

Kappa calculus is intended to be the internal language ofcontextually complete categories.

Examples

Expressions with multiple arguments have source types which are"right-imbalanced" binary trees. For example, a function f with threearguments of types A, B, and C and result type D will have type

f:A x (B x (C x 1))\toD

If we define left-associative juxtaposition

fc

as an abbreviationfor

(f\circ\operatorname{lift}(c))

, then – assuming that

a:1{\to}A

,

b:1{\to}B

, and

c:1{\to}C

 - we can apply this function:

fabc: 1\toD

Since the expression

fabc

has source type, it is a "ground value" and may be passed as an argument to another function. If

g:(D x E){\to}F

, then

g(fabc):E\toF

Much like a curried function of type

A{\to}(B{\to}(C{\to}D))

in lambda calculus, partialapplication is possible:

fa:B x (C x 1)\toD

However no higher types (i.e.

(\tau{\to}\tau){\to}\tau

) are involved. Note that because the source type of is not, the following expression cannot be well-typed under the assumptions mentioned so far:

h(fa)

Because successive application is used for multiplearguments it is not necessary to know the arity of a function inorder to determine its typing; for example, if we know that

c:1{\to}C

then the expression

is well-typed as long as has type

(C x \alpha){\to}\beta

for some and . This property is important when calculatingthe principal type of an expression, somethingwhich can be difficult when attempting to exclude higher-orderfunctions from typed lambda calculi by restricting the grammar of types.

History

Barendregt originally introduced the term"functional completeness" in the context of combinatory algebra.Kappa calculus arose out of efforts by Lambek to formulate an appropriate analogue of functionalcompleteness for arbitrary categories (see Hermida and Jacobs, section 1). Hasegawa later developed kappacalculus into a usable (though simple) programming language includingarithmetic over natural numbers and primitive recursion. Connections to arrowswere later investigated by Power, Thielecke, and others.

Variants

It is possible to explore versions of kappa calculus withsubstructural types such as linear, affine,and ordered types. These extensions require eliminating orrestricting the

!\tau

expression. In such circumstancesthe type operator is not a true cartesian product,and is generally written to make this clear.

References

[1] [2] [3] [4] [5]

Notes and References

  1. Lambek . Joachim . Joachim Lambek . August 1, 1973 . Functional completeness of cartesian categories . Annals of Mathematical Logic . March 1974 . 6 . 3–4 . 259–292 . 10.1016/0003-4843(74)90003-5 . 0003-4843.
  2. Hermida . Claudio . Jacobs . Bart . December 1995 . Fibrations with indeterminates: contextual and functional completeness for polymorphic lambda calculi . Mathematical Structures in Computer Science . 5 . 4 . 501–531 . 10.1017/S0960129500001213 . 3428512 . 1469-8072.
  3. Book: October 1, 1984 . Barendregt . Hendrik Pieter . The Lambda Calculus: Its Syntax and Semantics . Studies in Logic and the Foundations of Mathematics . Revised . Amsterdam, North Holland . Elsevier Science . 103 . 978-0-444-87508-2.
  4. Book: Hasegawa . Masahito . Category Theory and Computer Science . Decomposing typed lambda calculus into a couple of categorical programming languages . 1995 . Pitt . David . Rydeheard . David E. . Johnstone . Peter . Peter Johnstone (mathematician) . Lecture Notes in Computer Science . Springer-Verlag Berlin Heidelberg . 953 . 200–219 . 10.1007/3-540-60164-3_28 . 978-3-540-60164-7 . 0302-9743. 10.1.1.53.715 .
  5. Book: Power . John . Thielecke . Hayo . Automata, Languages and Programming . Closed Freyd- and κ-categories . 1999 . Wiedermann . Jiří . van Emde Boas . Peter . Peter van Emde Boas . Nielsen . Mogens . Lecture Notes in Computer Science . Springer-Verlag Berlin Heidelberg . 1644 . 625–634 . 10.1007/3-540-48523-6_59 . 978-3-540-66224-2 . 0302-9743. 10.1.1.42.2151 .