Which language does this klmn-grammar generate?

  • MHB
  • Thread starter evinda
  • Start date
  • Tags
    Language
In summary, the given grammar generates a language of words that can be represented as $k^p l^{q+r} m^r n^{p+q}$ where $p,q,r \in \mathbb Z_{\ge 0}$. There are two possible paths through the grammar, resulting in two possible word sets.
  • #1
evinda
Gold Member
MHB
3,836
0
Also,to see if I understood it,I tried an other example.
The grammar that is given is this:

[tex] w\epsilon \left \{ k,l,m,n \right \}^{*}:I\rightarrow I_{kn},I_{kn}\rightarrow kI_{kn}n|I_{ln}|I_{km},I_{ln}\rightarrow lI_{ln}n|I_{lm},I_{km}\rightarrow kI_{km}m|I_{lm},I_{lm}\rightarrow lI_{lm}m|\O [/tex] ,

and I found that it generates the following strings:

[tex]I\rightarrow I_{kn}\rightarrow k I_{kn} n \rightarrow kknn[/tex]
[tex]I\rightarrow I_{ln}\rightarrow l I_{kn} n \rightarrow llnn[/tex]
[tex]I\rightarrow I_{km}\rightarrow k I_{km} m \rightarrow kkmm[/tex]
[tex]I\rightarrow I_{lm}\rightarrow l I_{kn} m \rightarrow llmm[/tex]

Is this right?? :confused:
 
Technology news on Phys.org
  • #2
Re: How to find a language generated by a given grammar

evinda said:
Also,to see if I understood it,I tried an other example.
The grammar that is given is this:

[tex] w\epsilon \left \{ k,l,m,n \right \}^{*}:I\rightarrow I_{kn},I_{kn}\rightarrow kI_{kn}n|I_{ln}|I_{km},I_{ln}\rightarrow lI_{ln}n|I_{lm},I_{km}\rightarrow kI_{km}m|I_{lm},I_{lm}\rightarrow lI_{lm}m|\O [/tex] ,

and I found that it generates the following strings:

[tex]I\rightarrow I_{kn}\rightarrow k I_{kn} n \rightarrow kknn[/tex]
[tex]I\rightarrow I_{ln}\rightarrow l I_{kn} n \rightarrow llnn[/tex]
[tex]I\rightarrow I_{km}\rightarrow k I_{km} m \rightarrow kkmm[/tex]
[tex]I\rightarrow I_{lm}\rightarrow l I_{kn} m \rightarrow llmm[/tex]

Is this right?? :confused:

If it is right,how can I find the language it generates?It is more difficult than the previous one,isn't it? :eek:
 
  • #3
Re: How to find a language generated by a given grammar

evinda said:
Also,to see if I understood it,I tried an other example.
The grammar that is given is this:

[tex] w\epsilon \left \{ k,l,m,n \right \}^{*}:I\rightarrow I_{kn},I_{kn}\rightarrow kI_{kn}n|I_{ln}|I_{km},I_{ln}\rightarrow lI_{ln}n|I_{lm},I_{km}\rightarrow kI_{km}m|I_{lm},I_{lm}\rightarrow lI_{lm}m|\varnothing [/tex] ,

and I found that it generates the following strings:

[tex]I\rightarrow I_{kn}\rightarrow k I_{kn} n \rightarrow kknn[/tex]
[tex]I\rightarrow I_{ln}\rightarrow l I_{kn} n \rightarrow llnn[/tex]
[tex]I\rightarrow I_{km}\rightarrow k I_{km} m \rightarrow kkmm[/tex]
[tex]I\rightarrow I_{lm}\rightarrow l I_{kn} m \rightarrow llmm[/tex]

Is this right?? :confused:

It doesn't look right to me.
There is no rule $I_{kn} \to kn$ so you cannot produce the first string like that.
 
  • #4
Re: How to find a language generated by a given grammar

I like Serena said:
It doesn't look right to me.
There is no rule $I_{kn} \to kn$ so you cannot produce the first string like that.

I used the rules: [tex]I_{kn} \rightarrow kI_{kn}n[/tex] and [tex] I_{kn} \rightarrow \varnothing[/tex]
:confused: How else can I do this?
 
  • #5
Re: How to find a language generated by a given grammar

evinda said:
I used the rules: [tex]I_{kn} \rightarrow kI_{kn}n[/tex] and [tex] I_{kn} \rightarrow \varnothing[/tex]
:confused: How else can I do this?

Am I misunderstanding?
Then perhaps you can clarify?

Let me expand your ruleset:
\begin{array}{}
I&\rightarrow &I_{kn} \\
I_{kn}&\rightarrow& kI_{kn}n&|&I_{ln}&|&I_{km} \\
I_{ln}&\rightarrow& lI_{ln}n&|&I_{lm} \\
I_{km}&\rightarrow& kI_{km}m&|&I_{lm} \\
I_{lm}&\rightarrow& lI_{lm}m&|&\varnothing \\
\end{array}

Where is $I_{kn} \rightarrow \varnothing$?

I only see $I_{lm} \rightarrow \varnothing$.
 
  • #6
Re: How to find a language generated by a given grammar

I like Serena said:
Am I misunderstanding?
Then perhaps you can clarify?

Let me expand your ruleset:
\begin{array}{}
I&\rightarrow &I_{kn} \\
I_{kn}&\rightarrow& kI_{kn}n&|&I_{ln}&|&I_{km} \\
I_{ln}&\rightarrow& lI_{ln}n&|&I_{lm} \\
I_{km}&\rightarrow& kI_{km}m&|&I_{lm} \\
I_{lm}&\rightarrow& lI_{lm}m&|&\varnothing \\
\end{array}

Where is $I_{kn} \rightarrow \varnothing$?

I only see $I_{lm} \rightarrow \varnothing$.

Oh I think I misunderstood the rules.
Now I found that the grammar generates the following strings:
[tex]I\rightarrow I_{kn}\rightarrow kI_{kn}n\rightarrow kI_{ln}n\rightarrow klI_{ln}nn\rightarrow klI_{lm}nn\rightarrow kllI_{lm}mnn\rightarrow kllmnn[/tex]
[tex]I\rightarrow _{kn}\rightarrow kI_{kn}n\rightarrow kI_{km}n\rightarrow kkI_{km}mn\rightarrow kkI_{lm}mn\rightarrow kklI_{lm}mmn\rightarrow kklmmn[/tex]
So is the language [tex]\{k^il^jm^in^j\}[/tex]? :confused:
 
  • #7
Re: How to find a language generated by a given grammar

evinda said:
Oh I think I misunderstood the rules.
Now I found that the grammar generates the following strings:
[tex]I\rightarrow I_{kn}\rightarrow kI_{kn}n\rightarrow kI_{ln}n\rightarrow klI_{ln}nn\rightarrow klI_{lm}nn\rightarrow kllI_{lm}mnn\rightarrow kllmnn[/tex]
[tex]I\rightarrow _{kn}\rightarrow kI_{kn}n\rightarrow kI_{km}n\rightarrow kkI_{km}mn\rightarrow kkI_{lm}mn\rightarrow kklI_{lm}mmn\rightarrow kklmmn[/tex]
So is the language [tex]\{k^il^jm^in^j\}[/tex]? :confused:

Those look like correct words. ;)
But I don't think that is the language.

Let's try to visualize it:

View attachment 1808

Does that perhaps give you a clue what the words will look like?
 

Attachments

  • Grammar_klmn.png
    Grammar_klmn.png
    5.1 KB · Views: 46
  • #8
Re: How to find a language generated by a given grammar

I like Serena said:
Those look like correct words. ;)
But I don't think that is the language.

Let's try to visualize it:

https://www.physicsforums.com/attachments/1808

Does that perhaps give you a clue what the words will look like?

Is it maybe [tex]\{k^il^jm^in^j:i,j>0\}[/tex] or is it something else? :confused:
 
Last edited:
  • #9
Re: How to find a language generated by a given grammar

evinda said:
Is it maybe [tex]\{k^il^jm^in^j:i,j>0\}[/tex] or is it something else? :confused:

I'm afraid it's something else.
For starters, there are 2 paths through the graph, so you will get 2 possibilities.

Let's try the upper path.
When we leave state $I_{kn}$ we have $k^p I_{ln} n^p$, where $p$ could be $0$.
When leaving state $I_{ln}$, we have made it to $k^p l^q I_{lm} n^q n^p$.
When we finally leave $I_{lm}$ with $\varnothing$, we have $k^p l^q l^r m^r n^q n^p$.

So one of the 2 possible word sets is $\{ k^p l^{q+r} m^r n^{p+q} : p,q,r \in \mathbb Z_{\ge 0} \}$.
 
  • #10
Re: How to find a language generated by a given grammar

I like Serena said:
I'm afraid it's something else.
For starters, there are 2 paths through the graph, so you will get 2 possibilities.

Let's try the upper path.
When we leave state $I_{kn}$ we have $k^p I_{ln} n^p$, where $p$ could be $0$.
When leaving state $I_{ln}$, we have made it to $k^p l^q I_{lm} n^q n^p$.
When we finally leave $I_{lm}$ with $\varnothing$, we have $k^p l^q l^r m^r n^q n^p$.

So one of the 2 possible word sets is $\{ k^p l^{q+r} m^r n^{p+q} : p,q,r \in \mathbb Z_{\ge 0} \}$.

So,the other possible word set is: [tex] \{k^{p+q}l^{r}m^{r+q}n^{p}: p,q,r \in \mathbb Z_{\ge 0} \} [/tex] ?
 
  • #11
Re: How to find a language generated by a given grammar

evinda said:
So,the other possible word set is: [tex] \{k^{p+q}l^{r}m^{r+q}n^{p}: p,q,r \in \mathbb Z_{\ge 0} \} [/tex] ?

Yep! :D
 
  • #12
Re: How to find a language generated by a given grammar

I like Serena said:
Yep! :D

Nice :) so,if I want to write the general language,do I have to write both cases?

Or can we find one formula that satisfies both cases? :confused:
 
Last edited:
  • #13
Re: How to find a language generated by a given grammar

evinda said:
Nice :) so,if I want to write the general language,do I have to write both cases?

Or can we find one formula that satisfies both cases? :confused:

So,is the answer the languages [tex] \{k^{p+q}l^{r}m^{r+q}n^{p}: p,q,r \in \mathbb Z_{\ge 0} \} [/tex] and $\{ k^p l^{q+r} m^r n^{p+q} : p,q,r \in \mathbb Z_{\ge 0} \}$ ?
 
  • #14
Re: How to find a language generated by a given grammar

evinda said:
So,is the answer the languages [tex] \{k^{p+q}l^{r}m^{r+q}n^{p}: p,q,r \in \mathbb Z_{\ge 0} \} [/tex] and $\{ k^p l^{q+r} m^r n^{p+q} : p,q,r \in \mathbb Z_{\ge 0} \}$ ?

The language is the combination of the two:
$$\{k^{p+q}l^{r}m^{r+q}n^{p}: p,q,r \in \mathbb Z_{\ge 0} \} \cup \{ k^p l^{q+r} m^r n^{p+q} : p,q,r \in \mathbb Z_{\ge 0} \}$$
Or for short:
$$\{k^{p+q}l^{r}m^{r+q}n^{p},\quad k^p l^{q+r} m^r n^{p+q}\ :\ p,q,r \in \mathbb Z_{\ge 0} \}$$
 
  • #15
Re: How to find a language generated by a given grammar

I like Serena said:
The language is the combination of the two:
$$\{k^{p+q}l^{r}m^{r+q}n^{p}: p,q,r \in \mathbb Z_{\ge 0} \} \cup \{ k^p l^{q+r} m^r n^{p+q} : p,q,r \in \mathbb Z_{\ge 0} \}$$
Or for short:
$$\{k^{p+q}l^{r}m^{r+q}n^{p},\quad k^p l^{q+r} m^r n^{p+q}\ :\ p,q,r \in \mathbb Z_{\ge 0} \}$$

Great!Thank you very much! (Clapping)
 

Related to Which language does this klmn-grammar generate?

1. What is a klmn-grammar?

A klmn-grammar is a type of formal grammar that is used to generate strings of symbols from a given alphabet. It is named after the four letters (k, l, m, n) used to represent the four types of production rules in the grammar.

2. How is a klmn-grammar different from other types of grammars?

Klmn-grammars are different from other types of grammars because they use four types of production rules (k, l, m, n) instead of just two (left-hand side and right-hand side). This allows for a more complex and flexible set of rules to generate strings.

3. Which language can be generated by a klmn-grammar?

A klmn-grammar can generate any language that can be expressed using a context-free grammar. This means that it can generate languages that have a finite number of rules and can be parsed using a pushdown automaton.

4. How can I determine which language a specific klmn-grammar can generate?

To determine which language a klmn-grammar can generate, you can analyze the production rules and see what types of strings they can generate. Additionally, you can use mathematical tools such as formal language theory to prove which language the grammar can generate.

5. Can a klmn-grammar generate an infinite language?

Yes, a klmn-grammar can generate an infinite language as long as it follows the rules of a context-free grammar. This means that the grammar can have an infinite number of production rules and generate an infinite number of strings from a given alphabet.

Similar threads

  • Differential Geometry
Replies
1
Views
12K
  • Advanced Physics Homework Help
Replies
6
Views
7K
  • Programming and Computer Science
Replies
8
Views
3K
  • Precalculus Mathematics Homework Help
Replies
3
Views
1K
  • Advanced Physics Homework Help
Replies
1
Views
981
  • Introductory Physics Homework Help
Replies
24
Views
3K
  • Advanced Physics Homework Help
Replies
7
Views
2K
  • Programming and Computer Science
Replies
1
Views
1K
Replies
1
Views
2K
  • Linear and Abstract Algebra
Replies
4
Views
1K
Back
Top