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 deﬁne 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) deﬁne 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 deﬁnition 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 deﬁnes the same ternary
relation.
10pt
Solution:
y
list
append
(
nil
)
r1
append
(
)
a
nat
append
(
cons
(
)
cons
(
))
r2
(c) Prove that the sodeﬁned relation is singlevalued,
i.e.
, that it repre
sents a binary function.
12pt
1
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentTo 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 ﬁnd that
z
0
=
z
0
0
. Therefore,
z
=
cons
(
0
) =
cons
(
0
0
) =
z
0
as required.
This is the end of the preview.
Sign up
to
access the rest of the document.
 Fall '09
 MacQueen
 Logic, Mathematical Induction, Natural number, inference rules

Click to edit the document details