sol1 - CMSC 22100/32100: Programming Languages Sample...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CMSC 22100/32100: Programming Languages Sample solution to Homework 1 M. Blume Due: October 7, 2008 1. Consider the rules: zero nat zero n nat succ ( n ) nat succ nil list nil n nat l list cons ( n,l ) list cons These rules define a set of terms nat representing natural numbers in Peano encoding and a set of terms list representing lists of such numbers. We can inductively ( i.e. , recursively) define the following append function on lists: append ( nil ,m ) = m append ( cons ( ) ) = cons ( n, append ( l,m )) (a) Represent append as a ternary relation and give its definition induc- tively. 9pt Solution: Let the relation A be the smallest set such that i. For every y such that y list we have ( nil ,y,y ) A . ii. If ( x,y,z ) A and a nat , then ( cons ( a,x ) ,y, cons ( a,z )) A . (b) Write down a set of inference rules that defines the same ternary relation. 10pt Solution: y list append ( nil ) r1 append ( ) a nat append ( cons ( ) cons ( )) r2 (c) Prove that the so-defined relation is single-valued, i.e. , that it repre- sents a binary function. 12pt 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
To show: If append ( x,y,z ) and append ( 0 ), then z = z 0 . Proof: By induction on the derivation of append ( ). Case 1: Rule r1 was used to derive append ( ), so x = nil and y = z . Since x = nil , rule r1 must also have been used to derive append ( 0 ). Thus, z 0 = y = z . Case 2: Rule r2 was used to derive append ( ). Thus, x = cons ( a,x 0 ) for some a and x 0 , and z = cons ( a,z 0 ) for some z 0 . Furthermore, inversion of r2 gives append ( x 0 ,y,z 0 ). Since x 6 = nil , r2 must also have been used to derive append ( 0 ). Thus, we have z 0 = cons ( 0 0 ) and append ( x 0 0 0 ) for some z 0 0 . Using the induction hypoth- esis we find that z 0 = z 0 0 . Therefore, z = cons ( 0 ) = cons ( 0 0 ) = z 0 as required.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/10/2009 for the course CMSC 2210 taught by Professor Macqueen during the Fall '09 term at UChicago.

Page1 / 5

sol1 - CMSC 22100/32100: Programming Languages Sample...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online