ArticleslgStudy

computer science

Krivine machine

Krivine machine is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Krivine machine rather than just read about it. In short: In theoretical computer science, the Krivine machine is an abstract machine. As an abstract machine, it shares features with Turing machines and the SECD machine.

Krivine machine — main illustration
Krivine machine — illustration

Key takeaways

  • Krivine machine belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Krivine machine to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Krivine machine from memory before moving on to harder problems.

Reference excerpt

In theoretical computer science, the Krivine machine is an abstract 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 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, 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 was 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 (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. 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 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 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. 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 <term, environment>, 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 <term, environment> 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.

… excerpt ends here. Continue reading the full article.

Illustrations

Krivine machine: A picture view of a Krivine machine
A picture view of a Krivine machine

Worked examples

Example 1 — a first encounter with Krivine machine

Start with the simplest possible case. Write down what Krivine machine claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Krivine machine before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Krivine machine ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Krivine machine

In research
Krivine machine appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Krivine machine in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Krivine machine is common in secondary-school and first-year university syllabi. It links to neighbouring topics Abstract machines, Computability theory, Educational abstract machines, so understanding it makes those chapters shorter.
In everyday life
Look for Krivine machine outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Krivine machine” →

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Krivine machine in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Krivine machine means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Krivine machine out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Krivine machine in simple terms?

In theoretical computer science, the Krivine machine is an abstract machine. As an abstract machine, it shares features with Turing machines and the SECD machine.

Why does Krivine machine matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Krivine machine?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Krivine machine.

Tags

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

Keep exploring