Wilkinson's polynomial: Difference between revisions

From formulasearchengine
Jump to navigation Jump to search
en>Addbot
m Bot: Migrating 2 interwiki links, now provided by Wikidata on d:q2613931
en>Krishnavedala
m Vector images and grouped
 
Line 1: Line 1:
In [[computer science]], an '''ambiguous grammar''' is a [[formal grammar]] for which there exists a [[string (computer science)|string]] that can have more than one [[leftmost derivation]], while an '''unambiguous grammar''' is a formal grammar for which every valid string has a unique leftmost derivation. Many languages admit both ambiguous and unambiguous grammars, while some languages admit only ambiguous grammars. Any non-empty language admits an ambiguous grammar by taking an unambiguous grammar and introducing a duplicate rule or synonym (the only language without ambiguous grammars is the empty language). A language that only admits ambiguous grammars is called an [[#Inherently ambiguous languages|inherently ambiguous language]], and there are inherently ambiguous [[context-free language]]s. [[Deterministic context-free grammar]]s are always unambiguous, and are an important subclass of unambiguous CFGs; there are non-deterministic unambiguous CFGs, however.
That this person who wrote all of the article is called Leland but it's not this particular most masucline name on the. To go to karaoke is the thing she loves most of every bit of. He works as a cashier. His wife and him live from Massachusetts and he enjoys everything that he [http://Www.adobe.com/cfusion/search/index.cfm?term=&conditions&loc=en_us&siteSection=home conditions] there. He's not godd at design but you might want to check his / her website: http://[http://Mondediplo.com/spip.php?page=recherche&recherche=prometeu.net prometeu.net]<br><br>My page; clash of clans hack tool ([http://prometeu.net Going in prometeu.net])
 
For real-world [[programming language]]s, the reference CFG is often ambiguous, due to issues such as the [[#Dangling else|dangling else]] problem. If present, these ambiguities are generally resolved by adding precedence rules or other context-sensitive parsing rules, so the overall phrase grammar is unambiguous.
 
==Examples==
 
===Trivial language===
The simplest example is the following ambiguous grammar for the trivial language, which consists of only the empty string:
:A →
:B →
…meaning that the empty string can be produced by either of two equivalent productions, and thus has two leftmost derivations.
 
Another ambiguous grammar for the trivial language is:
:A → A |
…meaning that a production can either be itself again, or the empty string. Thus the empty string has leftmost derivations of length 1, 2, 3, and indeed of any length, depending on how many times the rule A → A is used.
 
This language also has the unambiguous grammar, consisting of a single production rule:
:A →
…meaning that the unique production can only produce the empty string, which is the unique string in the language.
 
In the same way, any grammar for a non-empty language can be made ambiguous by adding duplicates.
 
===Unary string===
The [[regular language]] of unary strings of a given character, say <code>'a'</code> (the regular expression <code>a*</code>), has the unambiguous grammar:
:A → aA |
…but also has the ambiguous grammar:
:A → aA | Aa |
These correspond to producing a [[right-associative]] tree (for the unambiguous grammar) or allowing both left- and right- association. This is elaborated below.
 
===Addition and subtraction===
 
The [[context free grammar]]
:A → A + A | A − A | a
is ambiguous since there are two leftmost derivations for the string a + a + a:
 
{| border="0"
|-----
| &nbsp;&nbsp;&nbsp;&nbsp; || A || → A + A
| &nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;
| A || → A + A
|-----
| &nbsp;&nbsp;&nbsp;&nbsp; ||  || → a + A
| &nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;
| || → A + A + A (First A is replaced by A+A. Replacement of the second A would yield a similar derivation)
|-----
| &nbsp;&nbsp;&nbsp;&nbsp; ||  || → a + A + A
| &nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;
| || → a + A + A
|-----
| &nbsp;&nbsp;&nbsp;&nbsp; ||  || → a + a + A
| &nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;
| || → a + a + A
|-----
| &nbsp;&nbsp;&nbsp;&nbsp; ||  || → a + a + a
| &nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;
| || → a + a + a
|}
 
As another example, the grammar is ambiguous since there are two parse trees for the string a + a &minus; a:
:[[Image:Leftmostderivations jaredwf.png|Leftmostderivations jaredwf.png]]
 
The language that it generates, however, is not inherently ambiguous; the following is a non-ambiguous grammar generating the same language:
:A → A + a | A − a | a
 
===Dangling else===
{{main|Dangling else}}
A common example of ambiguity in real-world programming languages is the [[dangling else]] problem. In many languages, the <code>else</code> in an [[Conditional (computer programming)#If–then(–else)|If–then(–else)]] statement is optional, which results in nested conditionals being ambiguous, at least in terms of the [[Context-free grammar|CFG]].
 
Concretely, in many languages one may write conditionals in two forms: the if-then form, and the if-then-else form – the else clause is optional:
 
In a grammar containing the rules
 
Statement = '''if''' Condition '''then''' Statement |
            '''if''' Condition '''then''' Statement '''else''' Statement |
            ...
Condition = ...
 
some ambiguous phrase structures can appear. The expression
'''if''' a '''then''' '''if''' b '''then''' s '''else''' s2
can be parsed as either
'''if''' a '''then''' ('''if''' b '''then''' s) '''else''' s2
or as
'''if''' a '''then''' ('''if''' b '''then''' s '''else''' s2)
depending on whether the <code>else</code> is associated with the first <code>if</code> or second <code>if</code>.
 
This is resolved in various ways in different languages. Sometimes the CFG is modified so that it is unambiguous, such as by requiring an <code>endif</code> statement or making <code>else</code> mandatory. In other cases the CFG is left ambiguous, but the ambiguity is resolved by making the overall phrase grammar context-sensitive, such as by associating an <code>else</code> with the nearest <code>if</code>. In this latter case the grammar is unambiguous, but the CF grammar is ambiguous.
 
==Recognizing ambiguous grammars==
 
The general [[decision problem]] of whether a grammar is ambiguous is [[Undecidable problem|undecidable]] because it can be shown that it is equivalent to the [[Post correspondence problem]]. At least, there are tools implementing some [[semi-decidable|semi-decision procedure]] for detecting ambiguity of context-free grammars.<ref>{{cite book | last1 = Axelsson | first1 = Roland | last2 = Heljanko | first2 = Keijo | last3 = Lange | first3 = Martin | year = 2008 | chapter = Analyzing Context-Free Grammars Using an Incremental SAT Solver | title = Proceedings of the 35th [[International Colloquium on Automata, Languages and Programming]] (ICALP'08), Reykjavik, Iceland | series = [[Lecture Notes in Computer Science]] | volume = 5126 | pages = 410–422 | publisher = Springer-Verlag}}</ref>
 
The efficiency of context-free grammar parsing is determined by the automaton that accepts it. [[Deterministic context-free grammar]]s are accepted by [[deterministic pushdown automata]] and can be parsed in linear time, for example by the [[LR parser]].<ref>{{cite doi|10.1016/S0019-9958(65)90426-2}}</ref> This is a subset of the [[context-free grammars]] which are accepted by the [[pushdown automaton]] and can be parsed in polynomial time, for example by the [[CYK algorithm]]. Unambiguous context-free grammars can be nondeterministic. For example, the language of even-length [[palindrome]]s on the alphabet of 0 and 1 has the unambiguous context-free grammar S → 0S0 | 1S1 | ε.  An arbitrary string of this language cannot be parsed without reading all its letters first which means that a pushdown automaton has to try alternative state transitions to accommodate for the different possible lengths of a semi-parsed string.<ref>{{cite book | last = [[John Hopcroft|Hopcroft]] | first = John | coauthors = [[Rajeev Motwani]] & [[Jeffrey Ullman]] | title = [[Introduction to automata theory, languages, and computation]] 2nd edition | year = 2001 | publisher = Addison-Wesley | pages = 249–253 }}</ref> Nevertheless, removing grammar ambiguity may produce a deterministic context-free grammar and thus allow for more efficient parsing. Compiler generators such as [[YACC]] include features for resolving some kinds of ambiguity, such as by using the precedence and associativity constraints.
 
==Inherently ambiguous languages==
 
Inherent ambiguity was proven with [[Parikh's theorem]] in 1961 by [[Rohit Jivanlal Parikh|Rohit Parikh]] in an MIT research report.<ref>{{cite book | last = Parikh | first = Rohit | title = Language-generating devices | publisher = Quarterly Progress Report, Research Laboratory of Electronics, MIT | date = January 1961}}</ref>
 
While some context-free languages (the set of strings that can be generated by a grammar) have both ambiguous and unambiguous grammars, there exist context-free languages for which no unambiguous context-free grammar can exist. An example of an inherently ambiguous language is the union of <math>\{a^n b^m c^m d^n | n, m > 0\}</math> with <math>\{a^n b^n c^m d^m | n, m > 0\}</math>. This set is context-free, since the union of two context-free languages is always context-free. But {{harvtxt|Hopcroft|Ullman|1979}} give a proof that there is no way to unambiguously parse strings in the (non-context-free) subset <math>\{a^n b^n c^n d^n | n > 0\}</math> which is the intersection of these two languages.
 
==See also==
*[[Semantic ambiguity]]
==References==
 
<references/>
 
*{{cite book
  | last = Gross
  | first = Maurice
  | title = Inherent ambiguity of minimal linear grammars
  | publisher = Information and Control
  | volume = 7:3
  | pages = 366–368
  | year = 1964
}}
 
*{{cite book
  | last = Michael
  | first = Harrison.
  | title = Introduction to Formal Language Theory
  | publisher = Addison-Wesley
  | year = 1978
}}
 
*{{cite book
  | last1 = Hopcroft
  | first1 = John E.
  | last2 = Ullman
  | first2 = Jeffrey D.
  | title = Introduction to Automata Theory, Languages, and Computation
  | publisher = Addison-Wesley
  | edition = 1st
  | year = 1979
  | ref = harv
}}
 
*{{cite book
  | last1 = Hopcroft
  | first1 = John.
  | last2 = Mowani
  | first2 = Rajeev.
  | last3 = Ullman
  | first3 = Jeffrey.
  | title = Introduction to Automata Theory, Languages and Computation (second edition)
  | publisher = Addison Wesley
  | pages = 217
  | year = 2001
  | ref = harv
}}
 
* {{cite book | last1 = Brabrand | first1 = Claus | last2 = Giegerich | first2 = Robert | last3 = Møller | first3 = Anders | year = 2010 | chapter = Analyzing Ambiguity of Context-Free Grammars | title = Science of Computer Programming | volume = 75 | number = 3 | pages = 176–191 | publisher = Elsevier | ref = harv}}
 
==External links==
*[http://www.brics.dk/grammar dk.brics.grammar] - a grammar ambiguity analyzer.
*[http://www2.tcs.ifi.lmu.de/~mlange/cfganalyzer/index.html CFGAnalyzer] - tool for analyzing context-free grammars with respect to language universality, ambiguity, and similar properties.
 
[[Category:Formal languages]]

Latest revision as of 17:04, 8 January 2015

That this person who wrote all of the article is called Leland but it's not this particular most masucline name on the. To go to karaoke is the thing she loves most of every bit of. He works as a cashier. His wife and him live from Massachusetts and he enjoys everything that he conditions there. He's not godd at design but you might want to check his / her website: http://prometeu.net

My page; clash of clans hack tool (Going in prometeu.net)