Kappa calculus

From testwiki
Jump to navigation Jump to search

Template:Short description In mathematical logic, category theory, and computer science, kappa calculus is a formal system for defining first-order functions.

Unlike lambda calculus, kappa calculus has no higher-order functions; its functions are not first class objects. Kappa-calculus can be regarded as "a reformulation of the first-order fragment of typed lambda calculus".[1]

Because its functions are not first-class objects, evaluation of kappa calculus expressions does not require closures.

Definition

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

Grammar

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

τ=1τ×τ
e=xidτ!τliftτ(e)eeκx:1τ.e

In other words,

  • 1 is a type
  • If τ1 and τ2 are types then τ1×τ2 is a type.
  • Every variable is an expression
  • If Template:Mvar is a type then idτ is an expression
  • If Template:Mvar is a type then !τ is an expression
  • If Template:Mvar is a type and e is an expression then liftτ(e) is an expression
  • If e1 and e2 are expressions then e1e2 is an expression
  • If x is a variable, Template:Mvar is a type, and e is an expression, then κx:1τ.e is an expression

The :1τ and the subscripts of Template:Math, Template:Math, and lift are sometimes omitted when they can be unambiguously determined from the context.

Juxtaposition is often used as an abbreviation for a combination of lift and composition:

e1e2 =def e1lift(e2)

Typing rules

The presentation here uses sequents (Γe:τ) 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[1]

In kappa calculus an expression has two types: the type of its source and the type of its target. The notation e:τ1τ2 is used to indicate that expression e has source type τ1 and target type τ2.

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

x:1τΓΓx:1τ (Var)
idτ:ττ (Id)
!τ:τ1 (Bang)
Γe1:τ1τ2Γe2:τ2τ3Γe2e1:τ1τ3 (Comp)
Γe:1τ1Γliftτ2(e):τ2(τ1×τ2) (Lift)
Γ,x:1τ1e:τ2τ3Γκx:1τ1.e:τ1×τ2τ3 (Kappa)

In other words,

  • Var: assuming x:1τ lets you conclude that x:1τ
  • Id: for any type Template:Mvar, idτ:ττ
  • Bang: for any type Template:Mvar, !τ:τ1
  • Comp: if the target type of e1 matches the source type of e2 they may be composed to form an expression e2e1 with the source type of e1 and target type of e2
  • Lift: if e:1τ1, then liftτ2(e):τ2(τ1×τ2)
  • Kappa: if we can conclude that e:τ2τ3 under the assumption that x:1τ1, then we may conclude without that assumption that κx:1τ1.e:τ1×τ2τ3

Equalities

Kappa calculus obeys the following equalities:

  • Neutrality: If f:τ1τ2 then fidτ1=f and f=idτ2f
  • Associativity: If f:τ1τ2, g:τ2τ3, and h:τ3τ4, then (hg)f=h(gf).
  • Terminality: If f:τ1 and g:τ1 then f=g
  • Lift-Reduction: (κx.f)liftτ(c)=f[c/x]
  • Kappa-Reduction: κx.(hliftτ(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 Template:Val can be regarded as the unit type. Because of this, any two functions whose argument type is the same and whose result type is Template:Val should be equal – since there is only a single value of type Template:Val both functions must return that value for every argument (Terminality).

Expressions with type 1τ can be regarded as "constants" or values of "ground type"; this is because Template:Val 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τ for some Template:Mvar. This is the basic mechanism which ensures that all functions are first-order.

Categorical semantics

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

Examples

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

f:A×(B×(C×1))D

If we define left-associative juxtaposition fc as an abbreviation for (flift(c)), then – assuming that a:1A, b:1B, and c:1C – we can apply this function:

fabc:1D

Since the expression fabc has source type Template:Val, it is a "ground value" and may be passed as an argument to another function. If g:(D×E)F, then

g(fabc):EF

Much like a curried function of type A(B(CD)) in lambda calculus, partial application is possible:

fa:B×(C×1)D

However no higher types (i.e. (ττ)τ) are involved. Note that because the source type of Template:Mvar is not Template:Val, the following expression cannot be well-typed under the assumptions mentioned so far:

h(fa)

Because successive application is used for multiple arguments it is not necessary to know the arity of a function in order to determine its typing; for example, if we know that c:1C then the expression

Template:Mvar

is well-typed as long as Template:Mvar has type

(C×α)β for some Template:Mvar

and Template:Mvar. This property is important when calculating the principal type of an expression, something which can be difficult when attempting to exclude higher-order functions from typed lambda calculi by restricting the grammar of types.

History

Barendregt originally introduced[2] the term "functional completeness" in the context of combinatory algebra. Kappa calculus arose out of efforts by Lambek[3] to formulate an appropriate analogue of functional completeness for arbitrary categories (see Hermida and Jacobs,[4] section 1). Hasegawa later developed kappa calculus into a usable (though simple) programming language including arithmetic over natural numbers and primitive recursion.[1] Connections to arrows were later investigated[5] by Power, Thielecke, and others.

Variants

It is possible to explore versions of kappa calculus with substructural types such as linear, affine, and ordered types. These extensions require eliminating or restricting the !τ expression. In such circumstances the Template:Math type operator is not a true cartesian product, and is generally written Template:Math to make this clear.

References