0% found this document useful (0 votes)
25 views1 page

Quiz03 Sol

The document presents a quiz on function composition in programming, focusing on defining combinators for both mathematical and sequential function compositions. It includes detailed proofs demonstrating the associativity of the defined combinators C and D. The solutions utilize lambda calculus to validate the properties of these combinators.

Uploaded by

Anant Chhajwani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views1 page

Quiz03 Sol

The document presents a quiz on function composition in programming, focusing on defining combinators for both mathematical and sequential function compositions. It includes detailed proofs demonstrating the associativity of the defined combinators C and D. The solutions utilize lambda calculus to validate the properties of these combinators.

Uploaded by

Anant Chhajwani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Name: Entry: 1

COL 765: Introduction to (Logic and Functional) Programming


Note: Every algorithm and program will be judged not just for correctness, but elegance and efficiency as well.

II semester 2017-18
Mon 16 Sep 2019 Quiz 3 30 minutes Max Marks 10

1. Function composition in mathematics defined by (f ◦ g)(x) = f (g(x)) is associative. Define a combinator


C for function composition and prove that function composition is associative i.e.

(C f ((C g) h)) =β (C ((C f ) g) h)

2. However, programmers are more interested in the sequential composition of functions defined as (f ; g)(x) =
g(f (x). Define another combinator D which captures sequential composition and prove that it is also
associative.

Solution.

Consider the combinators


df
C = λx y z[(x (y z))] (1)
df
D = λx y z[(y (x z))] (2)

which when applied to the functions f and g and to the functions g and h yield new combinators as follows:
df
Fg = ((C f ) g) =β λz[(f (g z))] . . . (1.1)
df
Gf = ((D f ) g) =β λz[(g (f z))] . . . (2.1)
df
Gh = ((C g) h) =β λz[(g (h z))] . . . (1.2)
df
Hg = ((D g) h) =β λz[(h (g z))] . . . (2.2)

1. To prove that C is associative we need to show that

(C f (C g h)) =β (C (C f g) h))

(C (C f g) h) (C f (C g h))
=β (C Fg h) by (1.1) =β (C f Gh) by (1.2)
≡ (λx y z[(x (y z))] Fg h) ≡ ((λx y z[(x (y z))] f ) Gh)
→2β λz[(Fg (h z))] →2β λz[(f (Gh z))]
≡α λz[(λu[(f (g u))] (h z))] by (2.1) ≡α λz[(f (λu[(g (h u))] z))] by (2.2)
→β λz[(f (g (h z)))] →β λz[(f (g (h z)))]

2. To prove that D is associative we need to show that

(D f (D g h)) =β (D (D f g) h))

(D (D f g) h) (D f (D g h))
=β (D Gf h) by (2.1) =β (D f Hg) by (2.2)
≡ (λx y z[(y (x z))] Gf h) ≡ ((λx y z[(y (x z))] f ) Hg)
→2β λz[(h (Gf z))] →2β λz[(Hg (f z))]
≡α λz[(h (λu[(g (f u))] z))] by (2.1) ≡α λz[(λu[(h (g u))] (f z))] by (2.2)
→β λz[(h (g (f z)))] →β λz[(h (g (f z)))]

You might also like