1 / 13

Exploring Function Definition and Evaluation in Lambda Calculus

This document provides an analysis of a piece of code utilizing lambda calculus to define and evaluate mathematical functions. It highlights the definition of a function (f), which determines behavior based on the input value, along with another function (foo) that utilizes a helper function (bar). We observe the evaluations for specific inputs, gaining insight into how the functions interact. The process emphasizes the significance of lambda expressions in functional programming and the evaluation process, offering clarity on the logic and structure behind recursive functions.

justin
Télécharger la présentation

Exploring Function Definition and Evaluation in Lambda Calculus

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. GE f: P1 para:x body:(if … ) (define (f x) (if (< x 0) (lambda (y) (- y x)) (lambda (y) (- x y))))

  2. GE f: foo: P1 P2 para:x body:(if … ) para:bar,x,y body:(let … ) (define (f x) (if (< x 0) (lambda (y) (- y x)) (lambda (y) (- x y)))) (define (foo bar x y) (let ((g (bar y))) (+ (g x) (g y))))

  3. GE f: foo: P1 P2 bar:P1 x:1 y:-2 para:x body:(if … ) para:bar,x,y body:(let … ) (define (f x) (if (< x 0) (lambda (y) (- y x)) (lambda (y) (- x y)))) (define (foo bar x y) (let ((g (bar y))) (+ (g x) (g y)))) (foo f 1 -2)

  4. GE f: foo: P1 P2 bar:P1 x:1 y:-2 para:x body:(if … ) para:bar,x,y body:(let … ) Evaluating: (bar y) => (P1 -2) (define (f x) (if (< x 0) (lambda (y) (- y x)) (lambda (y) (- x y)))) (define (foo bar x y) (let ((g (bar y))) (+ (g x) (g y)))) (foo f 1 -2)

  5. GE f: foo: P1 P2 bar:P1 x:1 y:-2 x:-2 para:x body:(if … ) para:bar,x,y body:(let … ) Evaluating: (bar y) => (P1 -2) (define (f x) (if (< x 0) (lambda (y) (- y x)) (lambda (y) (- x y)))) (define (foo bar x y) (let ((g (bar y))) (+ (g x) (g y)))) (foo f 1 -2)

  6. GE f: foo: P1 P2 bar:P1 x:1 y:-2 x:-2 para:x body:(if … ) para:bar,x,y body:(let … ) Evaluating: (if (< x 0) … ) (define (f x) (if (< x 0) (lambda (y) (- y x)) (lambda (y) (- x y)))) (define (foo bar x y) (let ((g (bar y))) (+ (g x) (g y)))) (foo f 1 -2)

  7. GE f: foo: P1 P2 bar:P1 x:1 y:-2 x:-2 para:x body:(if … ) para:bar,x,y body:(let … ) P3 para:y body:(- y x) (define (f x) (if (< x 0) (lambda (y) (- y x)) (lambda (y) (- x y)))) (define (foo bar x y) (let ((g (bar y))) (+ (g x) (g y)))) (foo f 1 -2)

  8. GE f: foo: P1 P2 bar:P1 x:1 y:-2 x:-2 para:x body:(if … ) para:bar,x,y body:(let … ) P3 para:y body:(- y x) g: (define (f x) (if (< x 0) (lambda (y) (- y x)) (lambda (y) (- x y)))) (define (foo bar x y) (let ((g (bar y))) (+ (g x) (g y)))) (foo f 1 -2)

  9. GE f: foo: P1 P2 bar:P1 x:1 y:-2 x:-2 para:x body:(if … ) para:bar,x,y body:(let … ) P3 para:y body:(- y x) g: Evaluating: (g x) => (P3 1) (define (f x) (if (< x 0) (lambda (y) (- y x)) (lambda (y) (- x y)))) (define (foo bar x y) (let ((g (bar y))) (+ (g x) (g y)))) (foo f 1 -2)

  10. GE f: foo: P1 P2 bar:P1 x:1 y:-2 x:-2 y:1 para:x body:(if … ) para:bar,x,y body:(let … ) P3 Evaluating: (- y x) => 3 para:y body:(- y x) g: (define (f x) (if (< x 0) (lambda (y) (- y x)) (lambda (y) (- x y)))) (define (foo bar x y) (let ((g (bar y))) (+ (g x) (g y)))) (foo f 1 -2)

  11. GE f: foo: P1 P2 bar:P1 x:1 y:-2 x:-2 y:1 para:x body:(if … ) para:bar,x,y body:(let … ) P3 para:y body:(- y x) g: Evaluating: (g y) => (P3 -2) (define (f x) (if (< x 0) (lambda (y) (- y x)) (lambda (y) (- x y)))) (define (foo bar x y) (let ((g (bar y))) (+ (g x) (g y)))) (foo f 1 -2)

  12. GE f: foo: P1 P2 bar:P1 x:1 y:-2 x:-2 y:1 para:x body:(if … ) para:bar,x,y body:(let … ) P3 y:-2 Evaluating: (- y x) => 0 para:y body:(- y x) g: (define (f x) (if (< x 0) (lambda (y) (- y x)) (lambda (y) (- x y)))) (define (foo bar x y) (let ((g (bar y))) (+ (g x) (g y)))) (foo f 1 -2)

  13. GE f: foo: P1 P2 bar:P1 x:1 y:-2 x:-2 y:1 para:x body:(if … ) para:bar,x,y body:(let … ) P3 y:-2 para:y body:(- y x) g: Evaluating: (+ 3 0) => 3 (define (f x) (if (< x 0) (lambda (y) (- y x)) (lambda (y) (- x y)))) (define (foo bar x y) (let ((g (bar y))) (+ (g x) (g y)))) (foo f 1 -2)

More Related