church numerals
play

Church Numerals Dr. Mattox Beckman University of Illinois at - PowerPoint PPT Presentation

Introduction Church Numerals Church Numerals Dr. Mattox Beckman University of Illinois at Urbana-Champaign Department of Computer Science Introduction Church Numerals Objectives You should be able to... Explain the form of a Church


  1. Introduction Church Numerals Church Numerals Dr. Mattox Beckman University of Illinois at Urbana-Champaign Department of Computer Science

  2. Introduction Church Numerals Objectives You should be able to... ◮ Explain the form of a Church numeral ◮ Defjne some operations on Church numerals: inc, plus, times ◮ Explain how to represent boolean operations: and, or, not, if

  3. Introduction Church Numerals What is a Number? ◮ The Lambda Calculus doesn’t have numbers. ◮ A number n can be thought of as a potential: someday we are going to do something n times. Some Church Numerals 1 f0 = \f -> \x -> x 2 f1 = \f -> \x -> f x 3 f2 = \f -> \x -> f (f x) 4 f3 = \f -> \x -> f (f (f x)) 1 Prelude > let show m = m (+1) 0 2 Prelude > show (\f x -> f (f x)) 3 2

  4. Introduction Church Numerals Incrementing Church Numerals, 0 ◮ To increment a Church Numeral, what do we want to do? Running Example 1 finc = undefined

  5. Introduction Church Numerals Incrementing Church Numerals, 1 ◮ To increment a Church Numeral, what do we want to do? ◮ First step, take the church numeral you want to increment. Running Example 1 finc = \m -> undefined

  6. Introduction Church Numerals Incrementing Church Numerals, 2 ◮ To increment a Church Numeral, what do we want to do? ◮ First step, take the church numeral you want to increment. ◮ Second step, return a church numeral representing your result. Running Example 1 finc = \m -> \f x -> undefined

  7. Introduction Church Numerals Incrementing Church Numerals, 3 ◮ To increment a Church Numeral, what do we want to do? ◮ First step, take the church numeral you want to increment. ◮ Second step, return a church numeral representing your result. ◮ Third step, apply f to x , m times. Running Example 1 finc = \m -> \f x -> m f x

  8. Introduction Church Numerals Incrementing Church Numerals, 4 ◮ To increment a Church Numeral, what do we want to do? ◮ First step, take the church numeral you want to increment. ◮ Second step, return a church numeral representing your result. ◮ Third step, apply f to x , m times. ◮ Finally, apply f once more to the result. Running Example 1 finc = \m -> \f x -> f (m f x)

  9. Introduction Church Numerals Adding Church Numerals ◮ Similar reasoning can yield addition and multiplication. ◮ Here is addition. Can you fjgure our multiplication? Hint: What does ( nf ) do? Running Example 1 fadd m n = \f x -> m f (n f x) ◮ In your activity you will think about how to represent booleans. ◮ If a numeral represents a potential number of actions, what would a boolean represent?

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend