词条 | Krivine machine | |||||||||||||
释义 |
In theoretical computer science, the Krivine machine is an abstract machine (sometimes called virtual machine). As an abstract machine, it shares features with Turing machines and the SECD machine. The Krivine machine explains how to compute a recursive function. More specifically it aims to define rigorously head normal form reduction of a lambda term using call-by-name reduction. Thanks to its formalism, it tells in details how a kind of reduction works and sets the theoretical foundation of the operational semantics of functional programming languages. On the other hand, Krivine machine implements call-by-name because it evaluates the body of a β-redex before it evaluates its parameter. In other words, in an expression (λ x. t) u it evaluates first λ x. t before evaluating u. In functional programming, this would mean that in order to evaluate a function applied to a parameter, it evaluates first the function before evaluating 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{{more|lambda-calculus}}The Krivine machine is based on two concepts related to lambda calculus, namely head reduction and call by name. Head normal form reductionA redex[1] (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) u1 ... un it is said to be a head redex. A head normal form is a term of the lambda calculus which is not a head redex{{efn|If one deals only with closed terms, that terms has the form λ x. t.}} 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 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 exampleThe 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 nameTo 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.{{efn|This ancient terminology refers to concepts of the 60's and hardly justified in 2017.}} The Krivine machine implements call by name. DescriptionThe 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.[2] 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 stateThe state has three components[2]
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 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 transitionsThe Krivine machine[2] 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 examplesLet 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)
This confirms the above fact that the normal form of the term ((λ 0) (λ 0)) (λ 0) is (λ 0). See also
Notes{{notelist}}References1. ^{{Citation |last=Barendregt |first=Hendrik Pieter |author-link= |last2= |first2= |author2-link= |title=The Lambda Calculus: Its Syntax and Semantics |place= |publisher=North Holland, Amsterdam |year=1984 |volume=103 |series=Studies in Logic and the Foundations of Mathematics |edition=Revised |url=http://www.elsevier.com/wps/find/bookdescription.cws_home/501727/description |doi= |id= |isbn=0-444-87508-5 |deadurl=yes |archiveurl=https://web.archive.org/web/20040823174002/https://www.elsevier.com/wps/find/bookdescription.cws_home/501727/description |archivedate=2004-08-23 |df= }} Corrections. 2. ^1 2 {{cite book | first1 = Pierre-Louis | last1 = Curien| title = Categorical Combinators, Sequential Algorithms and Functional| publisher = Birkhaüser| year = 1993| edition = 2nd}} Content in this edit is translated from the existing French Wikipedia article at fr:Machine de Krivine; see its history for attribution. Bibliography
| last1 = Curien | title = Categorical Combinators, Sequential Algorithms and Functional | publisher = Birkhaüser | year = 1993 | edition = 2nd}}
8 : Lambda calculus|Operational semantics|Educational abstract machines|Theoretical computer science|Models of computation|Computability theory|Abstract machines|Programming language implementation |
|||||||||||||
随便看 |
|
开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。