Skip to main content
deleted 316 characters in body
Source Link

I am trying to create a context free grammar in Extended Backus–Naur form, which starts with a non-empty sequence of a's and is followed by a non-empty sequence of b's. With the special condition that the number of b's has to be unequal to the number of a's.

Thus, the grammar should generate words like:

  • aaaabbb
  • aaabb
  • abbb

So basically I could do something like this:

$\ G=(N,T,P,S)$

$\ N = \{S\}$

$\ T = \{a,b\}$

$\ P = \{S=aa(S|\epsilon)b\}$

But then the words would always have $\ 2n$ a's and n b's:

  • aab
  • aaaabb
  • aaaaaabbb

So how is it possible to make the number of a's uncorrelated of the number of b's, without being equal?

Update

This question was suggested as a duplicate. But it's not quite what I want. So I posted my own solution as an answer below.

I am trying to create a context free grammar in Extended Backus–Naur form, which starts with a non-empty sequence of a's and is followed by a non-empty sequence of b's. With the special condition that the number of b's has to be unequal to the number of a's.

Thus, the grammar should generate words like:

  • aaaabbb
  • aaabb
  • abbb

So basically I could do something like this:

$\ G=(N,T,P,S)$

$\ N = \{S\}$

$\ T = \{a,b\}$

$\ P = \{S=aa(S|\epsilon)b\}$

But then the words would always have $\ 2n$ a's and n b's:

  • aab
  • aaaabb
  • aaaaaabbb

So how is it possible to make the number of a's uncorrelated of the number of b's, without being equal?

Update

This question was suggested as a duplicate. But it's not quite what I want. So I posted my own solution as an answer below.

I am trying to create a context free grammar in Extended Backus–Naur form, which starts with a non-empty sequence of a's and is followed by a non-empty sequence of b's. With the special condition that the number of b's has to be unequal to the number of a's.

Thus, the grammar should generate words like:

  • aaaabbb
  • aaabb
  • abbb

So basically I could do something like this:

$\ G=(N,T,P,S)$

$\ N = \{S\}$

$\ T = \{a,b\}$

$\ P = \{S=aa(S|\epsilon)b\}$

But then the words would always have $\ 2n$ a's and n b's:

  • aab
  • aaaabb
  • aaaaaabbb

So how is it possible to make the number of a's uncorrelated of the number of b's, without being equal?

edited title
Link
Yuval Filmus
  • 279.1k
  • 27
  • 316
  • 512

Context Free Grammar - Starting with x Number of Chars and Ending with nfree grammar for $\{a^x b^y !=: x Number of Chars\neq y\}$

added 30 characters in body
Source Link

I am trying to create a context free grammar in Extended Backus–Naur form, which starts with a non-empty sequence of Aa's and is followed by a non-empty sequence of Bb's. With the special condition that the number of Bb's has to be unequal to the number of Aa's.

Thus, the grammar should generate words like:

  • AAAABBBaaaabbb
  • AAABBaaabb
  • ABBBabbb

So basically I could do something like this:

$\ G=(N,T,P,Sequence)$$\ G=(N,T,P,S)$

$\ N = \{Sequence\}$$\ N = \{S\}$

$\ T = \{A,B\}$$\ T = \{a,b\}$

$\ P = \{Sequence=AA(Sequence|\epsilon)B\}$$\ P = \{S=aa(S|\epsilon)b\}$

But then the words would always have $\ 2n$ Aa's and n Bb's:

  • AABaab
  • AAAABBaaaabb
  • AAAAAABBBaaaaaabbb

So how is it possible to make the number of Aa's uncorrelated of the number of Bb's, without being equal?

Update

This question was suggested as a duplicate. But it's not quite what I want. So I posted my own solution as an answeranswer below.

I am trying to create a context free grammar in Extended Backus–Naur form, which starts with a non-empty sequence of A's and is followed by a non-empty sequence of B's. With the special condition that the number of B's has to be unequal to the number of A's.

Thus, the grammar should generate words like:

  • AAAABBB
  • AAABB
  • ABBB

So basically I could do something like this:

$\ G=(N,T,P,Sequence)$

$\ N = \{Sequence\}$

$\ T = \{A,B\}$

$\ P = \{Sequence=AA(Sequence|\epsilon)B\}$

But then the words would always have $\ 2n$ A's and n B's:

  • AAB
  • AAAABB
  • AAAAAABBB

So how is it possible to make the number of A's uncorrelated of the number of B's, without being equal?

Update

This question was suggested as a duplicate. But it's not quite what I want. So I posted my own solution as an answer below.

I am trying to create a context free grammar in Extended Backus–Naur form, which starts with a non-empty sequence of a's and is followed by a non-empty sequence of b's. With the special condition that the number of b's has to be unequal to the number of a's.

Thus, the grammar should generate words like:

  • aaaabbb
  • aaabb
  • abbb

So basically I could do something like this:

$\ G=(N,T,P,S)$

$\ N = \{S\}$

$\ T = \{a,b\}$

$\ P = \{S=aa(S|\epsilon)b\}$

But then the words would always have $\ 2n$ a's and n b's:

  • aab
  • aaaabb
  • aaaaaabbb

So how is it possible to make the number of a's uncorrelated of the number of b's, without being equal?

Update

This question was suggested as a duplicate. But it's not quite what I want. So I posted my own solution as an answer below.

added 260 characters in body
Source Link
Loading
Nothing about regular languages in this Q
Link
rici
  • 12.1k
  • 22
  • 39
Loading
Source Link
Loading