0% found this document useful (0 votes)
9 views3 pages

HW 1

The document outlines Homework No. 1 for a course on Languages and Machines, with a deadline of April 25, 2025. It includes several problems related to binary relations, regular expressions, context-free grammars, and grammar transformations, along with solutions and justifications for each problem. The solutions demonstrate the application of mathematical induction, regular expression construction, and grammar manipulation techniques.

Uploaded by

lkjGAFd
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)
9 views3 pages

HW 1

The document outlines Homework No. 1 for a course on Languages and Machines, with a deadline of April 25, 2025. It includes several problems related to binary relations, regular expressions, context-free grammars, and grammar transformations, along with solutions and justifications for each problem. The solutions demonstrate the application of mathematical induction, regular expression construction, and grammar manipulation techniques.

Uploaded by

lkjGAFd
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/ 3

Languages and Machines (2025) Homework No.

1 Deadline: April 25, 10h

Michael Roeleveld (s4737407)

1. 20 points Let R be a binary relation over a non-empty set A, i.e., R ⊆ A × A.


Define the transitive closure R+ of R as follows:
• Basis: If x R y, then x R+ y.
• Recursive Step: If x R+ y and y R+ z, then x R+ z.
(a) 10 points Prove by induction that for any x and y, if x R+ y, then

∃k > 0.∃z0 , . . . , zk .z0 = x ∧ z0 R z1 ∧ · · · ∧ zk−1 R zk ∧ zk = y .

Hint: Your proof must use the recursive definition of R+ .


(b) 10 points Prove by induction that for any k > 0, for any x and y, if

∃z0 , . . . , zk .z0 = x ∧ z0 R z1 ∧ · · · ∧ zk−1 R zk ∧ zk = y,

then x R+ y.

Solution:
A:
To prove: there is a chain of at least 1 R element when x transitively ‘R’s y.
Base case: k = 1
This yields z0 , z1 such that z0 R z1 . By definition, z0 = x and zk = z1 = y, so by substitution x R y. Which
tracks because it is given that x R+ y, which by definition of R+ means x R y.
Proven: there indeed always exists some k (trivial case: k = 1). I don’t see the need for induction…
Inductive step: for n > 1, P (n)⇒P (n + 1)
B:

2. 20 points Let Σ := {a, b} and L ⊆ Σ∗ be the language of words that do not contain ”aa“ as a substring. Give
a regular expression that generates L. Justify that your regular expression generates L.

Solution:
First, lets start with generating any sequence of a and b: b∗ (a∗ b∗ )∗
This lets us start with any amount of b, then alternate independent amounts of a and b, for an undetermined
amount of alternations.
However, this definition allows “bab” to be interpreted as “one b, (zero a zero b), (one a one b)”. That middle
term is quite distracting noise, so we can redefine it to not generate those epsilon terms:
equivalent: b∗ (aa∗ bb∗ )∗
This still generates any sequence of a and b. It just makes sure that in each alternation, progress is actually
made.
For the second requirement, to not contain “aa”: any repetition of more than 1 a contains “aa”. So it is trivial
to amend the expression to disallow consecutive as by simply removing a∗ .
L = b∗ (abb∗ )∗
Languages and Machines – HW1 Page 2 of 3

3. 20 points Let G1 and G2 be context-free grammars with a common set of terminals Σ.

(a) 6 points Give a context-free grammar generating the set L(G1 ) ∪ L(G2 ).
(b) 6 points Give a context-free grammar generating the set L(G1 )L(G2 ).
(c) 8 points Give a context-free grammar generating the set L(G1 )∗ .
Justify briefly why your proposed grammars are correct.

Solution:
Let S1 be the start symbol of G1 . Let S2 be the start symbol of G2 .
a. The union of 2 languages is the disjunction of their starting symbols.

G : S → S1 | S2

L(G) produces all strings in G1 as well as all strings in G2 , but does not cross contaminate their individual
production rules. It should however be noted that parsing ambiguities may arise, for example in the trivial
case where S1 = S2 .
b. The concatenation of 2 languages is the concatenation of their starting symbols.

G : S → S1 S2

L(G) contains the following: ∀x ∈ L(G1 ), ∀y ∈ L(G2 ).xy


Ambiguities may arise, for instance if

S1 → ab | a
S2 → ϵ | b

with the string “ab”. Is that S1 → ab and S2 → ϵ, or is that S1 → a and S2 → b? No one knows…
c. The kleene star of a language is repetition in any amount of its starting symbol. To notate repetition in
the language of formal grammars, we must abuse the concept of recursion in a production rule to generate
a degerenate parse tree (one should rather consider it a linked list).

G : S → S1 S | ϵ

This grammar generates either the empty string, or a string in L(G1 ) followed by (recurse here). Ambiguities
may be introduced, for instance in the case that
S1 → x | xx
where x is some other symbol in G1 . In sexpr notation, it is unclear if the string “xx” is (S(S1 xx)(Sϵ)) or
(S(S1 x)(S(S1 x)(Sϵ))).

4. 30 points Consider the grammar:

S → ABS | ASa
A → ϵ | c | AA
B → bb | CA
C→ϵ
Languages and Machines – HW1 Page 3 of 3

Use the standard algorithm to construct an equivalent, productive grammar.

Solution:
1. Make start symbol non recursive:

S→T
T → ABT | AT a
A → ϵ | c | AA
B → bb | CA
C→ϵ

2. Remove ϵ productions:

S→T |ϵ
T → ABT | AT a
A → cA | c | AA
B → bb | A

3. Remove chain production rules by replacement by transitive reflective closure:

S→T |ϵ
T → ABT | AT a
A → cA | c
B → bb | cA | c

You might also like