Lambda-mu calculus

From HandWiki
Short description: Extension of lambda calculus

In mathematical logic and computer science, the lambda-mu calculus is an extension of the lambda calculus introduced by Michel Parigot.[1] It introduces two new operators: the μ operator (which is completely different both from the μ operator found in computability theory and from the μ operator of modal μ-calculus) and the bracket operator. Proof-theoretically, it provides a well-behaved formulation of classical natural deduction.

One of the main goals of this extended calculus is to be able to describe expressions corresponding to theorems in classical logic. According to the Curry–Howard isomorphism, lambda calculus on its own can express theorems in intuitionistic logic only, and several classical logical theorems can't be written at all. However with these new operators one is able to write terms that have, for example, the type of Peirce's law.

The μ operator corresponds to Felleisen's undelimited control operator C and bracket corresponds to calling a captured continuation.[2]

Formal definition

The three forms of expressions in lambda calculus are as follows:

  1. A variable x.
  2. An abstraction λx. M, where x is any variable and M is any lambda expression.
  3. An application (M N), where M and N are any lambda expressions.

In addition to the traditional λ-variables, the lambda-mu calculus includes a distinct set of μ-variables, which can be understood as continuation variables. The set of terms is divided into unnamed (all traditional lambda expressions are of this kind) and named terms. The terms that are added by the lambda-mu calculus are of the form:

  1. [α]M is a named term, where α is a μ-variable and M is an unnamed term.
  2. (μ α. t) is an unnamed term, where α is a μ-variable and t is a named term.

Reduction

The basic reduction rules used in the lambda-mu calculus are the following:

beta reduction
(λx.M)NM[N/x]
structural reduction
(μα.t)Mμα.t[[α](NM)/[α]N], where the substitutions are to be made for all subterms of t of the form [α]N.
renaming
[α]μβ.tt[α/β]
μη-reduction
μα.[α]MM, if α does not occur freely in M

These rules cause the calculus to be confluent.

Typed lambda-mu calculus

The lambda-mu calculus can be typed. The typed lambda-mu calculus is to classical propositional logic as the simply typed lambda calculus is to intuitionistic propositional logic.[3]

Typed lambda-mu calculus can be presented in sequent calculus:[3]: Figure 6.2 Γ,x:τx:τΓ,x:σM:τΓ(λx:σ.M):στΓ,M:στΓN:σΓ(MN):τΓ,α:¬σM:Γ(μα:¬σ.M):σΓ,α:¬σM:σΓ,α:¬σ([α]M):The first 3 rules are the same as simply typed lambda calculus. The next 2 are new to the lambda-mu calculus.

Curry–Howard correspondence

Simply typed lambda calculus, by the Curry–Howard correspondence, corresponds to purely functional programs that can only redirect their inputs.

A sequent Γt:τ states that, within a program context Γ, one can construct an object t of type τ.

The rule Γ,x:τx:τ states that, within a context that includes some x:τ, one can construct an object x with type τ. This is obvious, by simply taking that same x:τ.

The lambda-introduction rule Γ,x:σM:τΓ(λx:σ.M):στ states that, if one can construct M:τ within a context of Γ,x:τ, then one can construct (λx:σ.M):στ within a context of Γ. This object (λx:σ.M) is a function-object defined within the context of Γ. It takes an object x:σ as input, and internally reproduces the context of Γ,x:τ, in which one then constructs M:τ. This is a form of closure.

The lambda-reduction rule Γ,M:στΓN:σΓ(MN):τ is a reverse of the previous rule.

The typed lambda-mu calculus is similar to the simply typed lambda calculus, but it allows redirecing both the inputs and the outputs. The redirection of input is by lambda abstraction, or closure. The redirection of output is by mu abstraction, or call/cc, jumps, or control operators.

The negation symbol ¬ denotes duality. Whereas x:σ in the program context denotes an input from which an object with type σ appears, α:¬σ denotes an output for an object with type σ goes to.

M: denotes a computational process that does not return any value, because its value would be returned to an output in context.

The address abstraction rule Γ,α:¬σM:Γ(μα:¬σ.M):σ closes an output from context. This corresponds to catch in call/cc.

The address application rule Γ,α:¬σM:σΓ,α:¬σ([α]M): redirects the output of a process M:σ to the output α in context. This corresponds to throw in call/cc.

The μ is a channel device. The address α:¬p is a channel that values of type p can be transmitted along, and [α]M represents transmittal of M to α, provided that M is of type p.[3]: 134 

Examples

Peirce's law ((pq)p)p is the type of the following term:λx(pq)p.μα¬p.[α]x(λyp.μβ¬q.[α]y)where we write xτ for x:τ, in order to save space.

Intuitively, one can understand this construction as follows. The program opens an input context x:(pq)p, and an output context α:¬p. One way to satisfy the output requirement of α:¬p is to construct something of type pq, and give it to x. That something is λyp.μβ¬q.[α]y:pq. If x takes this object without trying to use it, then it will return an object of type p, which can then be given to α. Alternatively, x might attempt to use it by providing it with an object y:p, which can then be given to α without ever replying an object of type q to x.

The Łukasiewicz axiom is the type of the following term:λx(pq)rλyrp.λzs.μα¬p.[α]y(μβ¬r.[β]x(λup.μγ¬q.[α]u))The double-negation translation corresponds to continuation-passing style. That is, the double-negation translation turns every formula provable in classical propositional logic into a provable formula in intuitionistic propositional logic. This corresponds to converting a program with catch/throw into a purely functional program that uses continuation-passing.[3]: Sec. 6.4 

For example, the double-negation translation of Peirce's law ((¬¬p¬¬q)¬¬p)¬¬p is the type of the following term:λx(¬¬p¬¬q)¬¬p.λα¬px(λy¬¬p.λβ¬q.yα)αCompare these two, in parallel:λx(pq)p.μα¬p.[α]x(λyp.μβ¬q.[α]y)λx(¬¬p¬¬q)¬¬p.λα¬p.x(λy¬¬p.λβ¬q.yα)αThe "jump to a different output" control behavior, as defined by μα[α], is translated into a pure lambda expression λαα. Instead of allowing a jump to the address α:¬p, one encodes the entire "the rest of the computation after the jumping to α:¬p" as a single object, called the continuation object. This continuation object can then be called for as many times as one wants, as long as that continuation object remains in context.

Variations

Call-by-value lambda-mu calculus

To obtain call-by-value semantics, one must refine the beta reduction rule and add another form of structural reduction:[4]

call-by-value beta reduction
(λx.M)VM[V/x], where V is a value
right structural reduction
V(μα.t)μα.t[[α](VN)/[α]N], where V is a value

This addition corresponds to the addition of an additional evaluation context former when moving from call-by-name to call-by-value evaluation.

De Groote's unstratified syntax

For a closer correspondence with conventional formalizations of control operators, the distinction between named and unnamed terms can be abolished, meaning that [α]M is of the same sort as other lambda-expressions and the body of μ-abstraction can also be any expression.[2] Another variant in this vein is the Λμ-calculus.[5]

Symmetric lambda-mu calculus

One can consider a structural reduction rule symmetric to the original one:[1]

M(μα.t)μα.t[[α](MN)/[α]N]

This, however, breaks confluence and the correspondence to control operators.

See also

References

  1. 1.0 1.1 Michel Parigot (1992). λμ-Calculus: An algorithmic interpretation of classical natural deduction.. Lecture Notes in Computer Science. 624. pp. 190–201. doi:10.1007/BFb0013061. ISBN 3-540-55727-X. 
  2. 2.0 2.1 de Groote, Philippe (1994). "Logic Programming and Automated Reasoning, 5th International Conference, LPAR'94, Kiev, Ukraine, July 16–22, 1994, Proceedings". in Pfenning, Frank. 822. Springer. pp. 31–43. doi:10.1007/3-540-58216-9_27. ISBN 978-3-540-58216-8. 
  3. 3.0 3.1 3.2 3.3 Sørensen, Morten Heine; Urzyczyn, Paweł (2006). "6. Classical logic and control operators". Lectures on the Curry-Howard isomorphism. Studies in logic and the foundations of mathematics. ScienceDirect (Online service) (1 ed.). Amsterdam Boston [MA]: Elsevier. ISBN 978-0-444-52077-7. 
  4. Ong, C.-H. L.; Stewart, C. A. (1997-01-01). "A Curry-Howard foundation for functional computation with control". Proceedings of the 24th ACM SIGPLAN-SIGACT symposium on Principles of programming languages - POPL '97. New York, NY, USA: Association for Computing Machinery. pp. 215–227. doi:10.1145/263699.263722. ISBN 978-0-89791-853-4. https://dl.acm.org/doi/10.1145/263699.263722. 
  5. Saurin, Alexis (2005). "20th IEEE Symposium on Logic in Computer Science (LICS 2005), 26–29 June 2005, Chicago, IL, USA, Proceedings". IEEE Computer Society. pp. 356–365. doi:10.1109/LICS.2005.48. 
  • Lambda-mu relevant discussion on Lambda the Ultimate.