Sei sulla pagina 1di 4

Term Rewriting Systems SS 11

Solution - Exercise Sheet 1


aa Prof. Dr. Jrgen Giesl Marc Brockschmidt, Carsten Fuhs, Thomas Strder
Exercise 1 (Syntax and Semantics): (2 + 4 = 6 points)
a) Give a set of equalities that describes the function of the arithmetic operators as minus and / as div for
subtraction and division on natural numbers. The exact semantics should be as follows:
div(x, y) = ,x/y if y > 0
minus(x, y) =

x y if x > y
0 otherwise
Thus, minus(15, 10) = 5, minus(5, 10) = 0 and div(15, 10) = 2. You should not dene div for a divisor of
0.
Use the representation of natural numbers presented in the lecture, where 0 is represented by O
0
and
n is represented by applying the successor symbol s
1
n times (i.e., by s
n
(O)). Dene the signature of
your equalities explicitly by giving denitions for
i
and .
b) Let =
0

1

2
with
0
= O,
1
= s and
2
= plus. Consider = plus(O, y)
y, plus(s(x), y) s(plus(x, y)), the set of equations describing + on our representation of natural numbers.
Prove that ,[= plus(x, y) plus(y, x).
Hints:
You can use a model A = (/, ) where / does not only consist of N, but also contains additional
elements and . Then dene
plus
(n, m) such that it models addition for n, m N, but behaves
dierently if n or m are from , .
Solution:
a) =
0

1

2
with
0
= O,
1
= s and
2
= minus, div.
minus(s(x), s(y)) minus(x, y)
minus(x, O) x
minus(O, y) O
div(s(x), s(y)) s(div(minus(s(x), s(y)), s(y)))
div(O, s(y)) O
b) As counterexample, consider A = (N , , ) with

O
:= 0

s
(n) :=

n + 1 if n N
otherwise

plus
(n, m) :=

n + m if n, m N
n if n ,
m if n = 0 m ,
if n > 0 m ,
1
Term Rewriting Systems SS 11
Solution - Exercise Sheet 1
To prove A [= , we consider each of the equations from . For the rst one, we have
plus
(
O
, y) =

plus
(0, y) = y. For the second equation, we have to consider three cases.
Case 1: x, y N. Then for the left hand side, we have
plus
(
s
(x), y) =
plus
((x + 1), y) = x + 1 + y. For
the right hand side, we have
s
(
plus
(x, y)) =
s
(x + y) = 1 + x + y.
Case 2: x N, y , . Then for the left hand side, we have
plus
(
s
(x), y) =
plus
((x + 1), y) = .
For the right hand side, we have
s
(
plus
(x, y)) =
s
(z) = where z , .
Case 3: x , , y N , . Then for the left hand side, we have
plus
(
s
(x), y) =
plus
(, y) = .
For the right hand side, we have
s
(
plus
(x, y)) =
s
() = .
Thus, A [= plus(s(x), y) s(plus(x, y)). We now show A ,[= plus(x, y) plus(y, x). For the latter,
consider the interpretation I := (N , , , ) with (x) = and (y) = 1. Then I(plus(x, y)) =

plus
(, 1) = and I(plus(x, y)) =
plus
(1, ) = .
.
Exercise 2 (Matching): (2 + 2 = 4 points)
a) Consider the following pairs of terms s and t over the signature =
0

2
with
0
= a and
2
= f.
Moreover, we have x, y, z 1 for the set of variables 1. If s matches t, then give a suitable matcher .
Otherwise give a brief (at most two sentences) explanation why there is no matcher.
1. s = f(y, z), t = f(a, x)
2. s = f(x, a), t = f(a, x)
3. s = f(y, y), t = f(a, x)
4. s = f(x, y), t = f(f(x, y), a)
b) Let be the matching relation, i.e., for two terms s and t we have s t i s matches t.
Prove or disprove the following propositions:
1. For all terms s and t we have s t i t s (i.e., the matching relation is symmetric).
2. For all terms s and t we have s t and t s i s = t.
Solution:
a) 1. = y/a, z/x
2. The term f(x, a) does not match the term f(a, x), because a cannot be replaced by x using a substitution.
3. The term f(y, y) does not match the term f(a, x), because y cannot be replaced by a and x at the same
time using a substitution.
4. = x/f(x, y), y/a
b) 1. The proposition is wrong. Consider the terms s = a and t = x. Then we have t s, but s t.
2. The proposition is wrong. Consider the terms s = x and t = y. Then we have s = ty/x and
t = sx/y, but s ,= t.
.
2
Term Rewriting Systems SS 11
Solution - Exercise Sheet 1
Exercise 3 (Stability): (1 + 1 + 1 + 1 = 4 points)
Consider the following relations
1
, . . . ,
4
T (, 1) T (, 1). Prove or disprove for each of these relations
that they are stable.
a) s
1
t i the numbers of dierent variables in s and t are equal, i.e., [1(s)[ = [1(t)[.
b) s
2
t i s is a subterm of t
c) s
3
t i s matches t
d) s
4
t i 1(s) 1(t)
Hints:
You can use the lemma proven in Exercise 4.
Solution:
a)
1
is not stable. Consider the terms s = f(x) and t = f(y). The number of dierent variables is 1 for both
terms. Applying the substitution = x/a to both terms yields the terms s = f(a) and t = f(y) where
the number of dierent variables is not equal anymore.
b)
2
is stable. Let s and t be terms with s being a subterm of t, i.e., there is a position such that t[

= s.
Moreover, let be a substitution. Then we obtain t[

Hint
= t[

t|=s
= s and, thus, s is a subterm of t,
i.e., s
2
t.
c)
3
is not stable. Consider the terms s = f(x) and t = f(y). We have s = t for the matcher = x/y.
Applying the substitution = x/a to both terms yields the terms s = f(a) and t = f(y) where s
does not match t anymore.
d)
4
is stable. Let s and t be terms with 1(s) 1(t) and be a substitution. Furthermore, let x 1(s).
If x / 1(s) or x DOM(), then there must be some y 1(s) with x 1(y). As we have y 1(t),
we also obtain x 1(t). If x 1(s) \ DOM(), then we obtain x 1(t) again, because x = x and
x 1(t).
.
Exercise 4 (Induction): (4 points)
Let t T (, 1), Occ(t) and SUB(, 1). Show by induction over that (t[

) = (t)[

holds.
Hints:
In the induction base, prove the proposition for = .
In the induction step, consider the case = i

, where as induction hypothesis, you can assume that


(q[

) = (q)[

for all q T (, 1) and all SUB(, 1).


Solution:
3
Term Rewriting Systems SS 11
Solution - Exercise Sheet 1
First, we consider the case = . Then, t[

= t = (t[

).
Now let = i

and assume that the proposition holds for

. As Occ(t), we have t = f(q


1
, . . . , q
i
, . . . , q
n
).
By denition, (t[
i
) = (q
i
[

) and (q
i
)[

= (t)[
i
hold. By our induction hypothesis, we have (q
i
[

) =
(q
i
)[

and thus, (t[


i
) = (t)[
i
.
.
4

Potrebbero piacerti anche