Jump to content

Talk:Context-sensitive grammar

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by 150.203.209.134 (talk) at 05:08, 18 September 2013 (→‎Contradicts definition?). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

(Contrary to a previous version of this article, the decision problem is not undecidable.)

Natural Language?

The article says that Chomsky invented CSG for natural languages. Are CSGs really used in linguistics? I've only seen context-free grammars (or some mild extensions) in that context.

Yes, context-sensitive rewrite rules have been used in linguistics, but I do not know whether they are still in use today. Rp 13:36, 25 July 2007 (UTC)[reply]

Added by Paul Ogilvie: in computer science only algorithms have been developed that can easily parse context free languages. These are now common, such as the yacc compiler-generator, an algorithm that can parse a CFL-definition and generate a program that can regognizse the CF language. See Aho, Sethi, Ullman, Compilers - Principles, tools and technisques, 1986. No algorithms have been developed (to my knowledge) that can parse a CSL, except heuristically.

Yacc doesn't parse arbitrary context-free languages, but only LALR(1) ones. An example of a general context-free parsing framework is ASF+SDF. Rp 13:36, 25 July 2007 (UTC)[reply]

Yes, there are natural languages that are not context free (take for example verbs in Swiss German). The algorithm for parsing CSL is quite straightforward (the complexity is high, obviously).

Contradicts definition?

The example has the rule

   cB → Bc

but that means α = c on the left-hand side, but α is empty on the right-hand side? Or is the example simply using the alternative definition of context-sensitive? As you can see, I've only studied context-free grammars so far :)

I think the example is using a monotonic grammar for the sake of simplicity (as an equivalent context-sensitive grammar can be constructed, but it probably wouldn't be as simple).
A monotonic grammar and a context-sensitive one isn't necessarily the same, so maybe the difference between the grammar and the generated language should be further illuminated. --Bernhard Bauer 00:46, 28 July 2006 (UTC)[reply]
I think that the following grammar will work:
S -> aRc
R -> aRT | b
bTc -> bbcc
bTT -> bbUT
UT -> UU
UUc -> VUc -> Vcc
UV -> VV
bVc -> bbcc
bVV -> bbWV
WV -> WW
WWc -> TWc -> Tcc
WT -> TT
As you can see, it is rather more complicated than the one in the article. 66.218.45.98 00:39, 20 January 2007 (UTC)[reply]


There is a more standard definition of context sensitive rules (used in most textbooks): a rule x -> y is context sensitive iff |x| <= |y|.

Why should people believe those two definitions are equivalent? Liberulo (talk) 21:06, 30 December 2012 (UTC)[reply]
UPDATE: This paper has a proof of the equivalence of the context-sensitive languages and monotonic languages, but I cannot vouch for its correctness. Liberulo (talk) 21:20, 30 December 2012 (UTC)[reply]

According to this definition, Aa -> aA, a is terminal and A non terminal symbol, is context sensitive. Moreover, the authors claim that these 2 definitions are equivalent! How can this be possible? —Preceding unsigned comment added by 85.73.192.119 (talk) 21:01, 11 September 2008 (UTC)[reply]

I second this question: I'd like to know if and how these two definitions of CSGs are equivalent. Liberulo (talk) 21:06, 30 December 2012 (UTC)[reply]
UPDATE: Look here, see if this paper contains a satisfactory proof. Liberulo (talk) 21:20, 30 December 2012 (UTC)[reply]
This is the definition I have seen, for example in Peter Linz, 'An Introduction to Formal Languages and Automata (2nd Ed.)', Chapter 11.3 (1997). Note that if the empty word is to be in the language that needs to be directly specified as a special case, as 'non-contracting' rules obviously can't specify it. The reference Linz cites 'for example' to show that such a grammar is indeed 'context-sensitive' in the sense of the current state of this article is A. Salomaa, 'Formal Languages' (1973). If anyone can track this down it might be the best reference. 150.203.209.134 (talk) 05:08, 18 September 2013 (UTC)[reply]

Wrong grammar for language

The grammar given for the language mentioned is not right according to the definition. Moreover the rule CB -> BC makes the grammar unrestricted.

I suggest the following context-sensitive grammar which does apply to the definition given.

Again the derivation for "aaa bbb ccc" is:


--Gerel (talk) 15:20, 19 December 2008 (UTC)[reply]



This might be a dumb question, but is a context-sensitive grammar allowed to "crash"? As in, end up with non-terminals and have no valid rules to follow. If it is not, then I think I found a derivation that would cause it to crash. Again, sorry if this is legal, I'm just learning about these now and it was not mentioned in class; my assumption was that a valid grammar had to always return a string of all terminals. Here's the derivation that would "crash" it:

Again, sorry if this is a dumb question, I just had to answer this question for a problem set and came up with a different answer (that I believe is correct), that does not ever "crash" like this one.

Confusing

Using a grammar that contradicts the definition is highly confusing. What is a monotonic grammar?

I'm moving the definition to "monotonic" grammar to its own page. It's wrong to include it here, since this page is not about classes of grammars that happen to describe the contest-sensitive languages, but about context-sensitive grammers proper. Rp 13:38, 25 July 2007 (UTC)[reply]

HERE IS THE EASY ANSWER:

S → aSBC | abc
CB → BC
aB → ab
bB → bb
bC → bc
cC → cc

The problem with your solution lies in the clause "S -> abc". As far as "abc" terminates your recursion, the structure "aabcBC" always gets created whenever you try to use recursion. The way to go is the usage of "S -> aBC", which is totally equivalent with the grammar in the Wiki page. --AdamDi (talk) 11:11, 29 April 2012 (UTC)[reply]

can you please explain this textbook problem

That why AB -> BA is not type 1 grammar —The preceding unsigned comment was added by Ra.ravi.rav (talkcontribs) 11:24, 18 February 2007 (UTC).[reply]

Is context-dependent the same thing as context-sensitive?

In the Turing completeness article, there is a redlink for context-dependent grammar. If that is the same thing as context-sensitive grammar, please fix the link. Paul Foxworthy (talk) 06:51, 10 June 2010 (UTC)[reply]

Formal Definition is not accurate

Specifically, "...and S does not appear on the right-hand side of any rule..." It seems the definition is not accurate. I would like to propose to recommend that the definition changes to a more accurate definition. A more accurate definition would be that the length of the left hand side of the formula is less than or equal to the length of the right hand side of the formula and the grammar cannot be represented in Chomsky Normal Form (i.e. there must be at least one string on the right that is non-contracting and has at least three symbols). Thus, the start symbol, can still appear on the right side of the rule as long as those conditions are met. Being able to include the start symbol on the right of the grammar would be able to simplify many essentially non-contracting context sensitive grammars with equivalent constructions where the the start symbol would not be allowed on the right.

Consider this quick and dirty example I thought of below, as, to write it without the start symbol would create many more production rules, but the start symbol on the right does not effect the fact it the grammar is essentially non-contracting and context sensitive.


Not having the S symbol on the right is more of a rule of thumb or maybe a notation convention, not a formal definition. As it might be beneficial for the student to not write it as such for confusion resulting from the following situation:

Which might appear to be context sensitive, but isn't, because it could be rewritten in Chomsky Normal Form.

Thus, I suggest we change or clarify the definition in this article.

reference: http://www.princeton.edu/~achaney/tmve/wiki100k/docs/Context-sensitive_grammar.html

Jmark13 (talk) 16:50, 8 August 2013 (UTC)[reply]

Update:

After reading a few more texts on the matter [1] [2] It seems clear to me that the formal definition of a Context Sensitive grammar is simply the following:

Beginning of Formalism:

A context-sensitive grammar G is a quadruple (V, , R, S) where V is a finite set of symbols, is the subset of V which contains only the terminal symbols and S is the start symbol in V, V.

R is a finite set of production rules in the form such that and are members of V and and || || where |x| is the length of x.[3]

End of Formalism

Also, we should note that an essentially non-contracting non-context sensitive grammar is that context sensitive grammar which can be represented in such a way where no Start symbol appears on the right of the production Rule set. This is in contrast to what is written now, which states that a grammar cannot be context sensitive if there is a Start symbol on the right hand side of the production rule set which can go to the empty string. The actual formal definition of context sensitive grammars is broader based on the references cited.

  1. ^ "Membership for Growing Context Sensitive Grammars is Polynomial" Dahlhaus and Warmuth, Journal of Computer and System Sciences, 1986
  2. ^ "Uniform Recognition for Acyclic Context Sensitive Grammars is NP-Complete" Erik Aarts
  3. ^ "Membership for Growing Context Sensitive Grammars is Polynomial" Dahlhaus and Warmuth, Journal of Computer and System Sciences, 1986

Jmark13 (talk) 19:27, 9 August 2013 (UTC)[reply]

Hi Jmark13.
I don't think it's obvious why your references should be used to change the definition. Here are some other search results supporting the tendency of the current definition: [1], [2], [3].
However, I agree that the exceptional rule concerning is a bit informal (and even inaccurate, because it does not clearly state that S may appear on the right side, if there is no rule ). In addition, there are more quite important authors who defined context-sensitive grammars as non-contracting (Aho and Ullman, for example [4], and Ullman and John Hopcroft in Introduction to Automata Theory, Languages, and Computation). So it seems legitimate to adopt their definition in this article.
Still, since there are authors who distinguish context-sensitive grammars and monotonous grammars (e.g. Grzegorz Rozenberg and Arto Salomaa in [5]), I would object to replacing one definition by another. Rather than claiming that some authors additionally require non-contracting rules, it should be mentioned that the current definition implies non-contracting rules (except the exception) and that the generative power is the same (see my first link).
There's one thing I don't understand: Why do you mention Chomsky Normal Form as a negative criterion? Consider a grammar with two rules, , and , the grammar clearly is context-sensitive according to both definitions, yet it is in CNF – or am I missing something?
--Zahnradzacken (talk) 22:57, 19 August 2013 (UTC)[reply]


Thank You, Zahnradzacken, I don't think you are missing anything, but I do think something in the formal definition of context-sensitive grammars is a bit ambiguous. And no, we should definitely not change the formal definition in so far as it agrees with the sources mentioned.

However, a less ambiguous definition of CSG would be one that would be formalized in terms of LBA, and be those re-writing rules that form the languages accepted by an LBA, since it has been proven that the languages produced are equivalent.

In terms of CNF, I was incorrect in my assertion, as languages produced by context free grammars is a strict subset of those produced by context sensitive grammars. I apologize for any confusion.

All this said, essentially non-contracting context sensitive grammars is itself a subset of uniform context sensitive grammars, which may be "mildly contracting" (not to be confused with mildly context sensitive) in that there is a contraction, but the length of the right hand side of every rule, even after contraction, is still strictly greater than or equal to the left... The languages produced by this definition should be obviously equivalent to those languages produced by essentially non-contracting grammars.

In my opinion, a set of grammar production rules should be in it's simplest form, i.e. the fewest amount of rules that produce all strings in the language. However, this often requires "mild contraction" on a set of rules that would otherwise be context-sensitive and essentially non-contracting. And while this might seem like splitting hairs here, there are a lot of results to theorems that depend on grammars that are deemed essentially non-contracting and context sensitive that would have to be re-proved for a "mildly contracting" context sensitive grammar, but despite the fact there is an S on the right, it should be obvious that these mildly contracting context sensitive grammars can be re-written as essentially non-contracting context sensitive grammars (just add more rules and replace each S symbol accordingly), and have an equivalent expressive power.

So, "What is true?" And if it is true that mildly contracting CSGs produces the same languages as essentially non-contracting CSGs, then the source definition, which includes that S cannot be on the right hand side, isn't a uniform or optimal definition, but applies only to essentially non-contracting CSGs. By eliminating this extra rule, and observing the class of difference between Recursively Enumerable languages with unrestricted grammars that are not CSGs with mildly contracting CSGs, we may simplify our Rule sets when appropriate and still have a CSG.

Anyway, if you see the logic above, and the benefits of being able to reduce some grammar rule sets to a mildly contracting CSG, then I do propose to at least add to the article that only some definitions add the extra requirement that S not occur on the right hand side and that these grammars are called "essentially non-contracting".

Jmark13 (talk) 00:49, 21 August 2013 (UTC)[reply]