advertisement

Introduction Church Numerals Introduction Church Numerals Objectives You should be able to... Church Numerals Dr. Mattox Beckman University of Illinois at Urbana-Champaign Department of Computer Science Introduction Church Numerals What is a Number? I The Lambda Calculus doesn’t have numbers. I A number n can be thought of as a potential: someday we are going to do something n times. 2 3 4 1 2 3 f0 f1 f2 f3 = = = = \f-> \f-> \f-> \f-> \x-> \x-> \x-> \x-> x f x f (f x) f (f (f x)) Prelude> let show m = m (+1) 0 Prelude> show (\f x -> f (f x)) 2 Explain the form of a Church numeral I Deﬁne some operations on Church numerals: inc, plus, times I Explain how to represent boolean operations: and, or, not, if Introduction Church Numerals Incrementing Church Numerals, 0 I Some Church Numerals 1 I To increment a Church Numeral, what do we want to do? Running Example 1 finc = undefined Introduction Church Numerals Incrementing Church Numerals, 1 I To increment a Church Numeral, what do we want to do? I First step, take the church numeral you want to increment. Introduction Incrementing Church Numerals, 2 Running Example 1 1 Church Numerals Incrementing Church Numerals, 3 I To increment a Church Numeral, what do we want to do? I First step, take the church numeral you want to increment. I Second step, return a church numeral representing your result. I Third step, apply f to x, m times. To increment a Church Numeral, what do we want to do? I First step, take the church numeral you want to increment. I Second step, return a church numeral representing your result. finc = \m -> \f x -> undefined Introduction Church Numerals Incrementing Church Numerals, 4 Running Example 1 I Running Example finc = \m -> undefined Introduction Church Numerals I To increment a Church Numeral, what do we want to do? I First step, take the church numeral you want to increment. I Second step, return a church numeral representing your result. I Third step, apply f to x, m times. I Finally, apply f once more to the result. Running Example finc = \m -> \f x -> m f x 1 finc = \m -> \f x -> f (m f x) Introduction Church Numerals Adding Church Numerals I Similar reasoning can yield addition and multiplication. I Here is addition. Can you ﬁgure our multiplication? Hint: What does (nf) do? Running Example 1 fadd m n = \f x -> m f (n f x) I In your activity you will think about how to represent booleans. I If a numeral represents a potential number of actions, what would a boolean represent?