You are on page 1of 3

HW1 Q1

Name of member 1:
Roll no. of member 1:
Name of member 2:
Roll no. of member 2:

(Rename file to CSE322-HQ1-Roll1-Roll2)

Figure out how to use Math equations and symbols in Google Doc, either from Menu -> Insert ->
Equation or via plugins. Enabling Offline Editing may be useful.

Adhere to page limits. Anything above the limit may be ignored.


HQ1. [Page limit 2 pages] Consider the following recursive definition of a language L
over the alphabet {a,-,+,*}.
* a is in L.
* If strings x and y are in L then the strings x+y and x*y are in L.
* If string z is in L then the string -z is in L.
* Nothing else is in L.

(a) Prove that if x is a string in L then (i) x does not contain the substring '++' and (ii) x
does not end with + and (iii) x does not begin with +. Use induction on the length of x (no
marks for level-1).

(b) Prove that if x is a string in L then x does not contain the substring '++'. Use proof by
induction on the length of x. If you are unable to prove this statement then explain why.

(a) Base case: The smallest string in x is of length 1. Hence, we consider x of length 1, i.e., the
string a (notice that all rules generate strings whose size is more than 1).
(i) It is true that ‘a’ does not contain ++.
(ii) It is true that ‘a’ does not end with +.
(iii) It is true that ‘a’ does not begin with +.
Hence all three facts are true for x of length 0.
You cannot use a base case where you use x of length 0.

Induction hypothesis: Consider any x in L of length at most n. Then, the following facts are true:
(i) x does not contain the substring '++' and (ii) x does not end with + and (iii) x does not begin
with +.

Induction step: Consider any y in L of length n+1. By the construction rules, y can be written
only in this manner.
(i) y=u+v where u is in L and v is in L. Since y has length n+1, so, both u and v have length at
most n. Thus, by IH,
 u does not begin with + => y does not begin with +
 does not contain ++,
 u does not end with +,
 v does not begin with +,
 v does not contain ++, and
o These 4 conditions imply that y does not contain ++, since if any such did, that
++ should appear wholly inside u or wholly inside v or involve the central +.
 v does not end with + => y does not end with +

(ii) y=u*v. By the same reason as above,


 u does not begin with + => y does not begin with +
 does not contain ++,
 v does not contain ++, and
o These 2 conditions imply that y does not contain ++, since if any such did, that
++ should appear wholly inside u or wholly inside v.
 v does not end with + => y does not end with +

(iii) y=-z. Note that y does not start with +.


Further, the length of z is n, so by IH, z does not contain ++ which means that y also does not
contain ++.

Therefore, in all three cases, all the three facts are true.
Hence, by mathematical induction, the facts are true for strings of any length in L.

(b) The above method does not work for proving only (i) since if y=u+v then to prove that y does
not contain ++, we have to show that ++ does not appear inside u or v, or u does not end
with + or v does not start with +. However, our IH in this scenario can only infer that ++ does
not contain ++.

You might also like