Reduction strategy

Source: Wikipedia, the free encyclopedia.

In rewriting, a reduction strategy or rewriting strategy is a relation specifying a rewrite for each object or term, compatible with a given reduction relation.[1] Some authors use the term to refer to an evaluation strategy.[2][3]

Definitions

Formally, for an abstract rewriting system , a reduction strategy is a binary relation on with , where is the transitive closure of (but not the reflexive closure).[1] In addition the normal forms of the strategy must be the same as the normal forms of the original rewriting system, i.e. for all , there exists a with iff .[4]

A one step reduction strategy is one where . Otherwise it is a many step strategy.[5]

A deterministic strategy is one where is a partial function, i.e. for each there is at most one such that . Otherwise it is a nondeterministic strategy.[5]

Term rewriting

In a

redexes
), which one should be reduced (contracted) within a term.

One-step strategies for term rewriting include:[5]

  • leftmost-innermost: in each step the leftmost of the innermost redexes is contracted, where an innermost redex is a redex not containing any redexes[6]
  • leftmost-outermost: in each step the leftmost of the outermost redexes is contracted, where an outermost redex is a redex not contained in any redexes[6]
  • rightmost-innermost, rightmost-outermost: similarly

Many-step strategies include:[5]

  • parallel-innermost: reduces all innermost redexes simultaneously. This is well-defined because the redexes are pairwise disjoint.
  • parallel-outermost: similarly
  • Gross-Knuth reduction,[7] also called full substitution or Kleene reduction:[5] all redexes in the term are simultaneously reduced

Parallel outermost and Gross-Knuth reduction are hypernormalizing for all almost-orthogonal term rewriting systems, meaning that these strategies will eventually reach a normal form if it exists, even when performing (finitely many) arbitrary reductions between successive applications of the strategy.[8]

Stratego is a domain-specific language designed specifically for programming term rewriting strategies.[9]

Lambda calculus

In the context of the lambda calculus, normal-order reduction refers to leftmost-outermost reduction in the sense given above.[10] Normal-order reduction is normalizing, in the sense that if a term has a normal form, then normal‐order reduction will eventually reach it, hence the name normal. This is known as the standardization theorem.[11][12]

Leftmost reduction is sometimes used to refer to normal order reduction, as with a

in-order traversal
the notions are distinct. For example, in the term with defined here, the leftmost redex of the in-order traversal is while the leftmost-outermost redex is the entire expression.[15]

Applicative order reduction refers to leftmost-innermost reduction.[10] In contrast to normal order, applicative order reduction may not terminate, even when the term has a normal form.[10] For example, using applicative order reduction, the following sequence of reductions is possible:

But using normal-order reduction, the same starting point reduces quickly to normal form:

Full β-reduction refers to the nondeterministic one-step strategy that allows reducing any redex at each step.[3] Takahashi's parallel β-reduction is the strategy that reduces all redexes in the term simultaneously.[16]

Weak reduction

Normal and applicative order reduction are strong in that they allow reduction under lambda abstractions. In contrast, weak reduction does not reduce under a lambda abstraction.[17] Call-by-name reduction is the weak reduction strategy that reduces the leftmost outermost redex not inside a lambda abstraction, while call-by-value reduction is the weak reduction strategy that reduces the leftmost innermost redex not inside a lambda abstraction. These strategies were devised to reflect the call-by-name and call-by-value evaluation strategies.[18] In fact, applicative order reduction was also originally introduced to model the call-by-value parameter passing technique found in Algol 60 and modern programming languages. When combined with the idea of weak reduction, the resulting call-by-value reduction is indeed a faithful approximation.[19]

Unfortunately, weak reduction is not confluent,[17] and the traditional reduction equations of the lambda calculus are useless, because they suggest relationships that violate the weak evaluation regime.[19] However, it is possible to extend the system to be confluent by allowing a restricted form of reduction under an abstraction, in particular when the redex does not involve the variable bound by the abstraction.[17] For example, λx.(λy.x)z is in normal form for a weak reduction strategy because the redex y.x)z is contained in a lambda abstraction. But the term λx.(λy.y)z can still be reduced under the extended weak reduction strategy, because the redex y.y)z does not refer to x.[20]

Optimal reduction

Optimal reduction is motivated by the existence of lambda terms where there does not exist a sequence of reductions which reduces them without duplicating work. For example, consider

((λg.(g(g(λx.x))))
 (λh.((λf.(f(f(λz.z))))
      (λw.(h(w(λy.y)))))))

It is composed of three nested terms, x=((λg. ... ) (λh.y)), y=((λf. ...) (λw.z) ), and z=λw.(h(w(λy.y))). There are only two possible β-reductions to be done here, on x and on y. Reducing the outer x term first results in the inner y term being duplicated, and each copy will have to be reduced, but reducing the inner y term first will duplicate its argument z, which will cause work to be duplicated when the values of h and w are made known.[a]

Optimal reduction is not a reduction strategy for the lambda calculus in a narrow sense because performing β-reduction loses the information about the substituted redexes being shared. Instead it is defined for the labelled lambda calculus, an annotated lambda calculus which captures a precise notion of the work that should be shared.[21]: 113–114 

Labels consist of a countably infinite set of atomic labels, and concatenations , overlinings and underlinings of labels. A labelled term is a lambda calculus term where each subterm has a label. The standard initial labeling of a lambda term gives each subterm a unique atomic label.[21]: 132  Labelled β-reduction is given by:[22]

where concatenates labels, , and substitution is defined as follows (using the

Barendregt convention):[22]
The system can be proven to be confluent. Optimal reduction is then defined to be normal order or leftmost-outermost reduction using reduction by families, i.e. the parallel reduction of all redexes with the same function part label.
[23] The strategy is optimal in the sense that it performs the optimal (minimal) number of family reduction steps.[24]

A practical algorithm for optimal reduction was first described in 1989,[25] more than a decade after optimal reduction was first defined in 1974.[26] The Bologna Optimal Higher-order Machine (BOHM) is a prototype implementation of an extension of the technique to interaction nets.[21]: 362 [27] Lambdascope is a more recent implementation of optimal reduction, also using interaction nets.[28][b]

Call by need reduction

Call by need reduction can be defined similarly to optimal reduction as weak leftmost-outermost reduction using parallel reduction of redexes with the same label, for a slightly different labelled lambda calculus.[17] An alternate definition changes the beta rule to an operation that finds the next "needed" computation, evaluates it, and substitutes the result into all locations. This requires extending the beta rule to allow reducing terms that are not syntactically adjacent.[29] As with call-by-name and call-by-value, call-by-need reduction was devised to mimic the behavior of the evaluation strategy known as "call-by-need" or lazy evaluation.

See also

  • Reduction system
  • Reduction semantics
  • Thunk

Notes

  1. ^ Incidentally, the above term reduces to the identity function (λy.y), and is constructed by making wrappers which make the identity function available to the binders g=λh..., f=λw..., h=λx.x (at first), and w=λz.z (at first), all of which are applied to the innermost term λy.y.
  2. ^ A summary of recent research on optimal reduction can be found in the short article About the efficient reduction of lambda terms.

References

  1. ^ . Retrieved 14 August 2021.
  2. . Retrieved 21 August 2021.
  3. ^ .
  4. .
  5. ^ a b c d e Klop, J. W. "Term Rewriting Systems" (PDF). Papers by Nachum Dershowitz and students. Tel Aviv University. p. 77. Retrieved 14 August 2021.
  6. ^ a b Horwitz, Susan B. "Lambda Calculus". CS704 Notes. University of Wisconsin Madison. Retrieved 19 August 2021.
  7. .
  8. . Retrieved 8 September 2021.
  9. .
  10. ^ .
  11. .
  12. ^ Kashima, Ryo. "A Proof of the Standardization Theorem in λ-Calculus" (PDF). Tokyo Institute of Technology. Retrieved 19 August 2021.
  13. ^ Vial, Pierre (7 December 2017). Non-Idempotent Typing Operators, beyond the λ-Calculus (PDF) (PhD). Sorbonne Paris Cité. p. 62.
  14. ^ Partain, William D. (December 1989). Graph Reduction Without Pointers (PDF) (PhD). University of North Carolina at Chapel Hill. Retrieved 10 January 2022.
  15. .
  16. .
  17. ^ .
  18. .
  19. ^ .
  20. .
  21. ^ .
  22. ^ .
  23. .
  24. .
  25. .
  26. . Retrieved 17 August 2021.
  27. ^ Asperti, Andrea. "Bologna Optimal Higher-Order Machine, Version 1.1". GitHub.
  28. ^ van Oostrom, Vincent; van de Looij, Kees-Jan; Zwitserlood, Marijn (2004). ] (Lambdascope): Another optimal implementation of the lambda-calculus (PDF). Workshop on Algebra and Logic on Programming Systems (ALPS).
  29. S2CID 6350826
    .

External links