# Beta reduction

### From HaskellWiki

(Difference between revisions)

BrettGiles (Talk | contribs) (2 cents on wording / links.) |
|||

(2 intermediate revisions by 2 users not shown) | |||

Line 1: | Line 1: | ||

− | A ''beta reduction'' (also written ''β reduction'') is where you actually apply a lambda function to an expression to generate a result. |
+ | A ''beta reduction'' (also written ''β reduction'') is the process of calculating a result from the application of a function to an expression. |

− | For example, suppose we have |
+ | {{Foundations infobox}} |

+ | For example, suppose we apply the function |
||

<haskell> |
<haskell> |
||

− | (\x y -> 2*x*x + y) 7 |
+ | (\x -> 2*x*x + y) |

</haskell> |
</haskell> |
||

− | If we now replace every occurance of <hask>x</hask> with 7, we arrive at |
+ | to the value <hask>7</hask>. To calculate the result, we substitute <hask>7</hask> for every [[Free variable|free occurrence]] of <hask>x</hask>, and so the application of the function |

<haskell> |
<haskell> |
||

− | \y -> 2*7*7 + y |
+ | (\x -> 2*x*x + y)(7) |

</haskell> |
</haskell> |
||

− | We have thus performed a ''beta reduction''. |
+ | is ''reduced'' to the result |

+ | <haskell> |
||

+ | 2*7*7 + y |
||

+ | </haskell> |
||

+ | This is a ''beta reduction''. |
||

− | [[Category:Glossary]] |
+ | (Further reductions could be applied to reduce <hask>2*7*7</hask> to <hask>98</hask>. Although the lambdas are not explicit, they exist hidden in the definition of <hask>(*)</hask>.) |

Also see [[Lambda calculus]] and the [http://en.wikipedia.org/wiki/Lambda_calculus wikipedia lambda calculus article]. |
Also see [[Lambda calculus]] and the [http://en.wikipedia.org/wiki/Lambda_calculus wikipedia lambda calculus article]. |
||

+ | |||

+ | [[Category:Glossary]] |

## Latest revision as of 18:22, 3 February 2007

A *beta reduction* (also written *β reduction*) is the process of calculating a result from the application of a function to an expression.

For example, suppose we apply the function

(\x -> 2*x*x + y)

7

7

x

(\x -> 2*x*x + y)(7)

is *reduced* to the result

2*7*7 + y

This is a *beta reduction*.

2*7*7

98

(*)

Also see Lambda calculus and the wikipedia lambda calculus article.