HOME

TheInfoList



OR:

In
theoretical computer science computer science (TCS) is a subset of general computer science and mathematics that focuses on mathematical aspects of computer science such as the theory of computation, lambda calculus, and type theory. It is difficult to circumscribe the ...
, the Krivine machine is an ''
abstract machine An abstract machine is a computer science theoretical model that allows for a detailed and precise analysis of how a computer system functions. It is analogous to a mathematical function in that it receives inputs and produces outputs based on pr ...
'' (sometimes called ''
virtual machine In computing, a virtual machine (VM) is the virtualization/ emulation of a computer system. Virtual machines are based on computer architectures and provide functionality of a physical computer. Their implementations may involve specialized h ...
''). As an abstract machine, it shares features with
Turing machine A Turing machine is a mathematical model of computation describing an abstract machine that manipulates symbols on a strip of tape according to a table of rules. Despite the model's simplicity, it is capable of implementing any computer algori ...
s and the
SECD machine The SECD machine is a highly influential (''see: '') virtual machine and abstract machine intended as a target for functional programming language compilers. The letters stand for Stack, Environment, Control, Dump—the internal registers of the mac ...
. The Krivine machine explains how to compute a recursive function. More specifically it aims to define rigorously
head normal form A head is the part of an organism which usually includes the ears, brain, forehead, cheeks, chin, eyes, nose, and mouth, each of which aid in various sensory functions such as sight, hearing, smell, and taste. Some very simple animals may ...
reduction of a
lambda term Lambda calculus (also written as ''λ''-calculus) is a formal system in mathematical logic for expressing computation based on function abstraction and application using variable binding and substitution. It is a universal model of computation ...
using
call-by-name In a programming language, an evaluation strategy is a set of rules for evaluating expressions. The term is often used to refer to the more specific notion of a ''parameter-passing strategy'' that defines the kind of value that is passed to the f ...
reduction. Thanks to its formalism, it tells in details how a kind of reduction works and sets the theoretical foundation of the
operational semantics Operational semantics is a category of formal programming language semantics in which certain desired properties of a program, such as correctness, safety or security, are verified by constructing proofs from logical statements about its execut ...
of
functional programming language In computer science, functional programming is a programming paradigm where programs are constructed by applying and composing functions. It is a declarative programming paradigm in which function definitions are trees of expressions that ...
s. On the other hand, Krivine machine implements call-by-name because it evaluates the body of a β- redex before it applies the body to its parameter. In other words, in an expression (''λ'' ''x''. ''t'') ''u'' it evaluates first ''λ'' ''x''. ''t'' before applying it to ''u''. In
functional programming In computer science, functional programming is a programming paradigm where programs are constructed by applying and composing functions. It is a declarative programming paradigm in which function definitions are trees of expressions that ...
, this would mean that in order to evaluate a function applied to a parameter, it evaluates first the function before applying it to the parameter. The Krivine machine has been designed by the French logician Jean-Louis Krivine at the beginning of the 1980s.


Call by name and head normal form reduction

The Krivine machine is based on two concepts related to lambda calculus, namely head reduction and call by name.


Head normal form reduction

A redex tp://ftp.cs.ru.nl/pub/CompMath.Found/ErrataLCalculus.pdf Corrections (one says also β-redex) is a term of the lambda calculus of the form (''λ'' ''x''. ''t'') ''u''. If a term has the shape (''λ'' ''x''. ''t'') ''u''1 ... ''u''''n'' it is said to be a ''head redex''. A ''
head normal form A head is the part of an organism which usually includes the ears, brain, forehead, cheeks, chin, eyes, nose, and mouth, each of which aid in various sensory functions such as sight, hearing, smell, and taste. Some very simple animals may ...
'' is a term of the lambda calculus which is not a head redex. A ''head reduction'' is a (non empty) sequence of contractions of a term which contracts head redexes. A head reduction of a term ''t'' (which is supposed not to be in head normal form) is a head reduction which starts from a term ''t'' and ends on a head normal form. From an abstract point of view, head reduction is the way a program computes when it evaluates a recursive sub-program. To understand how such a reduction can be implemented is important. One of the aims of the Krivine machine is to propose a process to reduct a term in head normal form and to describe formally this process. Like
Turing Alan Mathison Turing (; 23 June 1912 – 7 June 1954) was an English mathematician, computer scientist, logician, cryptanalyst, philosopher, and theoretical biologist. Turing was highly influential in the development of theoretical co ...
used an abstract machine to describe formally the notion of algorithm, Krivine used an abstract machine to describe formally the notion of head normal form reduction.


An example

The term ((''λ'' 0) (''λ'' 0)) (''λ'' 0) (which corresponds, if one uses explicit variables, to the term (''λx''.''x'') (''λy''.''y'') (''λz''.''z'')) is not in head normal form because (''λ'' 0) (''λ'' 0) contracts in (''λ'' 0) yielding the head redex (''λ'' 0) (''λ'' 0) which contracts in (''λ'' 0) and which is therefore the head normal form of ((''λ'' 0) (''λ'' 0)) (''λ'' 0). Said otherwise the head normal form contraction is: : ((''λ'' 0) (''λ'' 0)) (''λ'' 0) ➝ (''λ'' 0) (''λ'' 0) ➝ ''λ'' 0, which corresponds to : : (''λx''.''x'') (''λy''.''y'') (''λz''.''z'') ➝ (''λy''.''y'') (''λz''.''z'') ➝ ''λz''.''z''. We will see further how the Krivine machine reduces the term ((''λ'' 0) (''λ'' 0)) (''λ'' 0).


Call by name In a programming language, an evaluation strategy is a set of rules for evaluating expressions. The term is often used to refer to the more specific notion of a ''parameter-passing strategy'' that defines the kind of value that is passed to the f ...

To implement the head reduction of a term ''u v'' which is an application, but which is not a redex, one must reduce the body ''u'' to exhibit an abstraction and therefore create a redex with ''v''. When a redex appears, one reduces it. To reduce always the body of an application first is called ''
call by name In a programming language, an evaluation strategy is a set of rules for evaluating expressions. The term is often used to refer to the more specific notion of a ''parameter-passing strategy'' that defines the kind of value that is passed to the f ...
''. The Krivine machine implements ''call by name''.


Description

The presentation of the Krivine machine given here is based on notations of lambda terms that use de Bruijn indices and assumes that the terms of which it computes the head normal forms are closed. It modifies the current state until it cannot do it anymore, in which case it obtains a head normal form. This head normal form represents the result of the computation or yields an error, meaning that the term it started from is not correct. However, it can enter an infinite sequence of transitions, which means that the term it attempts reducing has no head normal form and corresponds to a non terminating computation. It has been proved that the Krivine machine implements correctly the call by name head normal form reduction in the lambda-calculus. Moreover, the Krivine machine is deterministic, since each pattern of the state corresponds to at most one machine transition.


The state

The state has three components :# a term, :# a stack, :# an environment. The term is a λ-term with de Bruijn indices. The stack and the environment belong to the same recursive data structure. More precisely, the environment and the stack are lists of pairs '''', that are called ''closures''. In what follows, the insertion as the head of a list ℓ (stack or environment) of an element ''a'' is written ''a:ℓ'', whereas the empty list is written □. The stack is the location where the machine stores the closures that must be evaluated furthermore, whereas the environment is the association between the indices and the closures at a given time during the evaluation. The first element of the environment is the closure associated with the index ''0'', the second element corresponds to the closure associated with index ''1'' etc. If the machine has to evaluate an index, it fetches there the pair '''' the closure that yields the term to be evaluated and the environment in which this term must be evaluated. This intuitive explanations allow understanding the operating rules of the machine. If one writes ''t'' for term, p for stack, and e for environment, the states associated with these three entities will be written ''t'', p, e. The rules explain how the machine transforms a state into another state, after identifying the patterns among the states. The ''initial state'' aims to evaluate a term ''t'', it is the state ''t'',□,□, in which the term is ''t'' and the stack and the environment are empty. The ''final state'' (in absence of error) is of the form ''λ t'', □, e, in other words, the resulting terms is an abstraction together with its environment and an empty stack.


The transitions

The Krivine machine has four transitions : ''App'', ''Abs'', ''Zero'', ''Succ''. The transition ''App'' removes the parameter of an application and put it on the stack for further evaluation. The transition ''Abs'' removes the λ of the term and pop up the closure from the top of the stack and put it on the top of the environment. This closure corresponds to the de Bruijn index ''0'' in the new environment. The transition ''Zero'' takes the first closure of the environment. The term of this closure becomes the current term and the environment of this closure becomes the current environment. The transition ''Succ'' removes the first closure of the environment list and decreases the value of the index.


Two examples

Let us evaluate the term (''λ'' 0 0) (''λ'' 0) which corresponds to the term (''λ'' ''x''. ''x'' ''x'') (''λ'' ''x''. ''x''). Let us start with the state (''λ'' 0 0) (''λ'' 0), □, □. The conclusion is that the head normal form of the term (''λ'' 0 0) (''λ'' 0) is ''λ'' 0. This translates with variables in: the head normal form of the term (''λ'' ''x''. ''x'' ''x'') (''λ'' ''x''. ''x'') is ''λ'' ''x''. ''x''. Let us evaluate the term ((''λ'' 0) (''λ'' 0)) (''λ'' 0) as shown belown: This confirms the above fact that the normal form of the term ((''λ'' 0) (''λ'' 0)) (''λ'' 0) is (''λ'' 0).


See also

*
Explicit substitution In computer science, lambda calculus, lambda calculi are said to have explicit substitutions if they pay special attention to the formalization of the process of substitution of variables, substitution. This is in contrast to the standard lambda cal ...
*
Operational semantics Operational semantics is a category of formal programming language semantics in which certain desired properties of a program, such as correctness, safety or security, are verified by constructing proofs from logical statements about its execut ...
*
SECD machine The SECD machine is a highly influential (''see: '') virtual machine and abstract machine intended as a target for functional programming language compilers. The letters stand for Stack, Environment, Control, Dump—the internal registers of the mac ...
*
Semantics of programming languages In programming language theory, semantics is the rigorous mathematical study of the meaning of programming languages. Semantics assigns computational meaning to valid string (computer science), strings in a programming language syntax. Semantic ...


Notes


References

Content in this edit is translated from the existing French Wikipedia article at :fr:Machine de Krivine; see its history for attribution.


Bibliography

*Jean-Louis Krivine: ''A call-by-name lambda-calculus machine''. Higher-Order and Symbolic Computation 20(3): 199-207 (2007
archive
* *Frédéric Lang: ''Explaining the lazy Krivine machine using explicit substitution and addresses''. Higher-Order and Symbolic Computation 20(3): 257-270 (2007
archive
* Olivier Danvy (Ed.): Editorial of special issue of ''Higher-Order and Symbolic Computation'' on the Krivine machine, vol. 20(3) (2007)


External links

*{{Commonscatinline Lambda calculus Operational semantics Educational abstract machines Theoretical computer science Models of computation Computability theory Abstract machines Programming language implementation