lambda calculus examples
play

Lambda Calculus Examples Dr. Mattox Beckman University of Illinois - PowerPoint PPT Presentation

Objectives Examples Lambda Calculus Examples Dr. Mattox Beckman University of Illinois at Urbana-Champaign Department of Computer Science Objectives Examples Objectives You should be able to ... Here are some examples! Perform a


  1. Objectives Examples Lambda Calculus Examples Dr. Mattox Beckman University of Illinois at Urbana-Champaign Department of Computer Science

  2. Objectives Examples Objectives You should be able to ... Here are some examples! ◮ Perform a beta-reduction. ◮ Detect α -capture and use α -renaming to avoid it. ◮ Normalize any given λ -calculus term.

  3. Objectives Examples Examples ( λ x . x ) a ( λ x . x x ) a ( λ x . y x ) a ( λ x .λ a . x ) a ( λ x .λ x . x ) a ( λ x . ( λ y . y ) x ) a

  4. Objectives Examples Examples ( λ x . x ) a a → β ( λ x . x x ) a ( λ x . y x ) a ( λ x .λ a . x ) a ( λ x .λ x . x ) a ( λ x . ( λ y . y ) x ) a @ → β a a λ x x

  5. Objectives Examples Examples ( λ x . x ) a a → β ( λ x . x x ) a a a → β ( λ x . y x ) a ( λ x .λ a . x ) a ( λ x .λ x . x ) a ( λ x . ( λ y . y ) x ) a @ → β @ a a a λ x @ x x

  6. Objectives Examples Examples ( λ x . x ) a a → β ( λ x . x x ) a a a → β ( λ x . y x ) a y a → β ( λ x .λ a . x ) a ( λ x .λ x . x ) a ( λ x . ( λ y . y ) x ) a @ → β @ y a a λ x @ y x

  7. Objectives Examples Examples ( λ x . x ) a a → β ( λ x . x x ) a a a → β ( λ x . y x ) a y a → β ( λ x .λ a . x ) a ( λ x .λ a ′ . x ) λ a ′ . a → α → β ( λ x .λ x . x ) a ( λ x . ( λ y . y ) x ) a @ λ a → α,β λ a ′ �→ a a a λ x λ a x

  8. Objectives Examples Examples ( λ x . x ) a a → β ( λ x . x x ) a a a → β ( λ x . y x ) a y a → β ( λ x .λ a . x ) a ( λ x .λ a ′ . x ) λ a ′ . a → α → β ( λ x .λ x . x ) a λ x . x → β ( λ x . ( λ y . y ) x ) a → β @ λ x a x λ x λ x x

  9. Objectives Examples Examples ( λ x . x ) a a → β ( λ x . x x ) a a a → β ( λ x . y x ) a y a → β ( λ x .λ a . x ) a ( λ x .λ a ′ . x ) λ a ′ . a → α → β ( λ x .λ x . x ) a λ x . x → β ( λ x . ( λ y . y ) x ) a ( λ y . y ) a → β → β → β a @ @ a a λ x λ y y @ λ y x y

  10. Objectives Examples Examples ( λ x . x ) a a → β ( λ x . x x ) a a a → β ( λ x . y x ) a y a → β ( λ x .λ a . x ) a ( λ x .λ a ′ . x ) λ a ′ . a → α → β ( λ x .λ x . x ) a λ x . x → β ( λ x . ( λ y . y ) x ) a ( λ y . y ) a → β a → β → β → β a @ @ a a λ x λ y y @ λ y x y

  11. Objectives Examples α capture ( λ x .λ a . x ) a → α ( λ x .λ a ′ . x ) λ a ′ . a → β ◮ If a free occurrence of a variable gets placed under a λ that binds it, this is called α capture. ◮ To resolve this, rename the binder .

  12. Objectives Examples Here’s One for You to Try! ◮ Convert this tree into an equivalent λ term. ◮ Identify the free variables. ◮ Simplify it by performing as many β reductions (and necessary α renamings) as possible. @ @ λ a λ q λ x @ λ f f a a @ f x

  13. Objectives Examples Solution @ @ λ a λ q @ λ x a a λ f f @ x f ( λ xf . fx )( λ q . f )( λ a . aa ) ◮ There is one free variable ....

  14. Objectives Examples Solution, Step 1 @ 1 @ 1 @ 2 λ a @ 2 λ a λ q λ x @ 4 λ q λ x @ 4 a a a a λ f ′ f λ f f @ 3 @ 3 x f x f ′ ( λ xf . fx )( λ q . f )( λ a . aa ) ( λ xf ′ . f ′ x )( λ q . f )( λ a . aa ) → α

  15. @ f a @ @ q a a f f f f q f a aa Objectives Examples Solution, Step 2 @ 1 @ 2 λ a λ q λ x @ 4 a a λ f ′ f @ 3 x f ′ ( λ xf ′ . f ′ x )( λ q . f )( λ a . aa ) → β

  16. Objectives Examples Solution, Step 2 @ 1 @ 1 @ 2 λ a λ f ′ λ a λ q λ x @ 3 @ 4 @ 4 a a λ q a a λ f ′ f f ′ f @ 3 x f ′ ( λ xf ′ . f ′ x )( λ q . f )( λ a . aa ) ( λ f ′ . f ′ ( λ q . f ))( λ a . aa ) → β

  17. @ q a @ f a a a aa q f Objectives Examples Solution, Step 3 @ 1 λ f ′ λ a @ 3 @ 4 λ q a a f ′ f ( λ f ′ . f ′ ( λ q . f ))( λ a . aa ) → β

  18. Objectives Examples Solution, Step 3 @ 1 @ 3 λ q λ f ′ λ a λ a @ 3 @ 4 f @ 4 a a λ q a a f ′ f ( λ f ′ . f ′ ( λ q . f ))( λ a . aa ) ( λ a . aa )( λ q . f ) → β

  19. @ q q f f q f q f Objectives Examples Solution, Step 4 @ 3 λ q λ a @ 4 f a a ( λ f ′ . f ′ ( λ q . f ))( λ a . aa ) → β

  20. Objectives Examples Solution, Step 4 @ 3 @ 4 λ q λ q λ q λ a f f @ 4 f a a ( λ f ′ . f ′ ( λ q . f ))( λ a . aa ) ( λ q . f )( λ q . f ) → β

  21. f f Objectives Examples Solution, Step 5 @ 4 λ q λ q f f ( λ q . f )( λ q . f ) → β

  22. Objectives Examples Solution, Step 5 f @ 4 λ q λ q f f ( λ q . f )( λ q . f ) f → β

Recommend


More recommend