<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://en.formulasearchengine.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=38.112.100.65</id>
	<title>formulasearchengine - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://en.formulasearchengine.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=38.112.100.65"/>
	<link rel="alternate" type="text/html" href="https://en.formulasearchengine.com/wiki/Special:Contributions/38.112.100.65"/>
	<updated>2026-05-03T01:34:40Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.0-wmf.28</generator>
	<entry>
		<id>https://en.formulasearchengine.com/index.php?title=Two-photon_absorption&amp;diff=249293</id>
		<title>Two-photon absorption</title>
		<link rel="alternate" type="text/html" href="https://en.formulasearchengine.com/index.php?title=Two-photon_absorption&amp;diff=249293"/>
		<updated>2014-12-09T19:09:36Z</updated>

		<summary type="html">&lt;p&gt;38.112.100.65: /* TPA Coefficients */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Greetings. The writer&#039;s title is Phebe and she feels comfy when people use the complete name. Years in the past he moved to North Dakota and his family members enjoys it. Managing individuals is what I do and the wage has been really fulfilling. The thing she adores most is physique building and now she is trying to earn cash with it.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;Here is my webpage ... [http://bikedance.com/blogs/post/15246 at home std testing]&lt;/div&gt;</summary>
		<author><name>38.112.100.65</name></author>
	</entry>
	<entry>
		<id>https://en.formulasearchengine.com/index.php?title=Energy_charge&amp;diff=8399</id>
		<title>Energy charge</title>
		<link rel="alternate" type="text/html" href="https://en.formulasearchengine.com/index.php?title=Energy_charge&amp;diff=8399"/>
		<updated>2013-09-23T15:06:45Z</updated>

		<summary type="html">&lt;p&gt;38.112.100.65: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{expert|date=June 2012}}&lt;br /&gt;
{{confusing|date=June 2012}}&lt;br /&gt;
&lt;br /&gt;
In the [[formal language theory]] of [[computer science]], &#039;&#039;&#039;left recursion&#039;&#039;&#039; is a special case of [[recursion]].  &lt;br /&gt;
&lt;br /&gt;
In terms of [[context-free grammar]], a non-terminal &amp;lt;code&amp;gt;r&amp;lt;/code&amp;gt; is left-recursive if the left-most symbol in any of &amp;lt;code&amp;gt;r&amp;lt;/code&amp;gt;’s productions (‘alternatives’) either immediately (direct/immediate left-recursive) or through some other non-terminal definitions (indirect/hidden left-recursive) rewrites to &amp;lt;code&amp;gt;r&amp;lt;/code&amp;gt; again.&lt;br /&gt;
&lt;br /&gt;
== Definition ==&lt;br /&gt;
&amp;quot;A grammar is left-recursive if we can find some non-terminal A which will eventually derive a [[sentential form]] with itself as the left-symbol.&amp;quot;&amp;lt;ref&amp;gt;[http://www.cs.may.ie/~jpower/Courses/parsing/parsing.pdf#search=&#039;indirect%20left%20recursion&#039;  Notes on Formal Language Theory and Parsing], James Power, Department of Computer Science National University of Ireland, Maynooth Maynooth, Co. Kildare, Ireland.[[JPR02]]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Immediate left recursion ===&lt;br /&gt;
Immediate left recursion occurs in rules of the form&lt;br /&gt;
:&amp;lt;math&amp;gt;A \to A\alpha \mid \beta&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\beta&amp;lt;/math&amp;gt; are sequences of nonterminals and terminals, and &amp;lt;math&amp;gt;\beta&amp;lt;/math&amp;gt; doesn&#039;t start with &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt;. For example, the rule&lt;br /&gt;
:&amp;lt;math&amp;gt;\mathit{Expr} \to \mathit{Expr} + \mathit{Term}&amp;lt;/math&amp;gt;&lt;br /&gt;
is immediately left-recursive. The &#039;&#039;[[recursive descent parser]]&#039;&#039; for this rule might look like:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
function Expr()&lt;br /&gt;
{  &lt;br /&gt;
    Expr();  match(&#039;+&#039;);  Term();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
and a recursive descent parser would fall into infinite recursion when trying to parse a grammar which contains this rule.&lt;br /&gt;
&lt;br /&gt;
=== Indirect left recursion ===&lt;br /&gt;
Indirect left recursion in its simplest form could be defined as:&lt;br /&gt;
:&amp;lt;math&amp;gt;A \to B\alpha \mid C&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;B \to A\beta \mid D,&amp;lt;/math&amp;gt;&lt;br /&gt;
possibly giving the derivation &amp;lt;math&amp;gt;A \Rightarrow B\alpha \Rightarrow A\beta\alpha \Rightarrow \ldots &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More generally, for the nonterminals &amp;lt;math&amp;gt;A_0, A_1, \ldots, A_n&amp;lt;/math&amp;gt;, indirect left recursion can be defined as being of the form:&lt;br /&gt;
:&amp;lt;math&amp;gt;A_0 \to A_1\alpha_1 \mid \ldots&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;A_1 \to A_2\alpha_2 \mid \ldots&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;\cdots&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;A_n \to A_0\alpha_{n+1} \mid \ldots&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;\alpha_1, \alpha_2, \ldots, \alpha_n&amp;lt;/math&amp;gt; are sequences of nonterminals and terminals.&lt;br /&gt;
&lt;br /&gt;
== Accommodating left recursion in top-down parsing ==&lt;br /&gt;
A [[formal grammar]] that contains left recursion cannot be [[parse]]d by a [[LL parser|LL(k)-parser]] or other naive [[recursive descent parser]] unless it is converted to a [[Weak equivalence (formal languages)|weakly equivalent]] right-recursive form. In contrast, left recursion is preferred for [[LALR]] parsers because it results in lower stack usage than [[right recursion]]. However, more sophisticated top-down parsers can implement general [[context-free grammar]]s by use of [[curtailment]]. In 2006, Frost and Hafiz described an algorithm which accommodates [[ambiguous grammar]]s with direct left-recursive [[Formal grammar#The syntax of grammars|production rules]].&amp;lt;ref name=&amp;quot;FrostHafiz2006&amp;quot;&amp;gt;{{cite journal|last=Frost|first=R.|coauthors=R. Hafiz|date=2006|title=A New Top-Down Parsing Algorithm to Accommodate Ambiguity and Left Recursion in Polynomial Time.|journal=ACM SIGPLAN Notices|volume=41|issue=5|pages=46–54|url=http://portal.acm.org/citation.cfm?id=1149988|doi=10.1145/1149982.1149988}}&amp;lt;/ref&amp;gt; That algorithm was extended to a complete [[parsing]] algorithm to accommodate indirect as well as direct left-recursion in [[polynomial]] time, and to generate compact polynomial-size representations of the potentially exponential number of parse trees for highly ambiguous grammars by Frost, Hafiz and Callaghan in 2007.&amp;lt;ref name=&amp;quot;FrostHafizCallaghan2007&amp;quot;&amp;gt;{{cite journal|last=Frost|first=R.|coauthors=R. Hafiz and P. Callaghan|date=June 2007|title=Modular and Efficient Top-Down Parsing for Ambiguous Left-Recursive Grammars.|journal=10th International Workshop on Parsing Technologies (IWPT), ACL-SIGPARSE|location=Prague|pages=109–120|url=http://acl.ldc.upenn.edu/W/W07/W07-2215.pdf}}&amp;lt;/ref&amp;gt; The authors then implemented the algorithm as a set of [[parser combinator]]s written in the [[Haskell (programming language)|Haskell]] programming language.&amp;lt;ref name=&amp;quot;FrostHafizCallaghan2008&amp;quot;&amp;gt;{{cite journal|last=Frost|first=R.|coauthors=R. Hafiz and P. Callaghan|date=January 2008|title=Parser Combinators for Ambiguous Left-Recursive Grammars|journal=10th International Symposium on Practical Aspects of Declarative Languages (PADL), ACM-SIGPLAN|volume=4902|issue=2008|pages=167–181|url=http://cs.uwindsor.ca/~richard/PUBLICATIONS/PADL_08.pdf|doi=10.1007/978-3-540-77442-6_12|series=Lecture Notes in Computer Science|isbn=978-3-540-77441-9}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Removing left recursion ==&lt;br /&gt;
=== Removing immediate left recursion ===&lt;br /&gt;
The general algorithm to remove immediate left recursion follows. Several improvements to this method have been made, including the ones described in &amp;quot;Removing Left Recursion from Context-Free Grammars&amp;quot;, written by Robert C. Moore.&amp;lt;ref name=&amp;quot;Moore2000&amp;quot;&amp;gt;{{cite journal|last=Moore|first=Robert C.|title=Removing Left Recursion from Context-Free Grammars|journal=6th Applied Natural Language Processing Conference|date=May 2000|pages=249–255|url=http://research.microsoft.com/pubs/68869/naacl2k-proc-rev.pdf}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
For each rule of the form &lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;A \rightarrow A\alpha_1\,|\,\ldots\,|\,A\alpha_n\,|\,\beta_1\,|\,\ldots\,|\,\beta_m &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
* A is a left-recursive nonterminal&lt;br /&gt;
* &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; is a sequence of nonterminals and terminals that is not null (&amp;lt;math&amp;gt;\alpha \ne \epsilon &amp;lt;/math&amp;gt;)&lt;br /&gt;
* &amp;lt;math&amp;gt;\beta&amp;lt;/math&amp;gt; is a sequence of nonterminals and terminals that does not start with A.&lt;br /&gt;
&lt;br /&gt;
replace the A-production by the production:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;A \rightarrow \beta_1A^\prime\, |\, \ldots\,  |\,  \beta_mA^\prime&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And create a new nonterminal&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;A^\prime \rightarrow \epsilon\, |\, \alpha_1A^\prime\,  |\,  \ldots\, |\, \alpha_nA^\prime&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This newly created symbol is often called the &amp;quot;tail&amp;quot;, or the &amp;quot;rest&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
As an example, consider the rule&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;Expr \rightarrow Expr\,+\,Expr\,|\,Int\,|\,String&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This could be rewritten to avoid left recursion as&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;Expr \rightarrow Int\,ExprRest\,|\,String\,ExprRest&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;ExprRest \rightarrow \epsilon\,|\,+\,Expr\,ExprRest&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The last rule happens to be equivalent to the slightly shorter form&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;ExprRest \rightarrow \epsilon\,|\,+\,Expr&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Removing indirect left recursion ===&lt;br /&gt;
If the grammar has no &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt;-productions (no productions of the form &amp;lt;math&amp;gt;A \rightarrow \ldots | \epsilon | \ldots &amp;lt;/math&amp;gt;) and is not cyclic (no derivations of the form &amp;lt;math&amp;gt;A \Rightarrow  \ldots \Rightarrow A &amp;lt;/math&amp;gt; for any nonterminal A), this general algorithm may be applied to remove indirect left recursion :&lt;br /&gt;
&lt;br /&gt;
Arrange the nonterminals in some (any) fixed order &amp;lt;math&amp;gt;A_1, \ldots A_n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
: for i = 1 to n {&lt;br /&gt;
::for j = 1 to i – 1 {&lt;br /&gt;
:::* let the current &amp;lt;math&amp;gt;A_j&amp;lt;/math&amp;gt; productions be&lt;br /&gt;
:::&amp;lt;math&amp;gt;A_j \rightarrow \delta_1 | \ldots | \delta_k&amp;lt;/math&amp;gt;&lt;br /&gt;
:::* replace each production &amp;lt;math&amp;gt;A_i \rightarrow A_j \gamma&amp;lt;/math&amp;gt; by&lt;br /&gt;
:::&amp;lt;math&amp;gt;A_i \rightarrow \delta_1\gamma | \ldots | \delta_k\gamma&amp;lt;/math&amp;gt;&lt;br /&gt;
::}&lt;br /&gt;
::* remove direct left recursion for &amp;lt;math&amp;gt;A_i&amp;lt;/math&amp;gt;&lt;br /&gt;
:}&lt;br /&gt;
&lt;br /&gt;
== Pitfalls ==&lt;br /&gt;
The above transformations remove left-recursion by creating a right-recursive grammar; but this changes the associativity of our rules. Left recursion makes left associativity; right recursion makes right associativity.&lt;br /&gt;
Example:&lt;br /&gt;
We start with a grammar:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;Expr \rightarrow Expr\,+\,Term\,|\,Term&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;Term \rightarrow Term\,*\,Factor\,|\,Factor&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;Factor \rightarrow (Expr)\,|\,Int&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After having applied standard transformations to remove left-recursion, we have the following grammar:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;Expr \rightarrow Term\ Expr&#039;&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;Expr&#039; \rightarrow {} + Term\ Expr&#039;\,|\,\epsilon&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;Term \rightarrow Factor\ Term&#039;&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;Term&#039; \rightarrow {} * Factor\ Term&#039;\,|\,\epsilon&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;Factor \rightarrow (Expr)\,|\,Int&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Parsing the string &#039;a + a + a&#039; with the first grammar in an LALR parser (which can recognize left-recursive grammars) would have resulted in the parse tree:&lt;br /&gt;
                             Expr&lt;br /&gt;
                          /   |   \&lt;br /&gt;
                        Expr   +   Term&lt;br /&gt;
                      /  |  \        \&lt;br /&gt;
                    Expr  + Term      Factor&lt;br /&gt;
                     |      |       |&lt;br /&gt;
                    Term    Factor    Int&lt;br /&gt;
                     |      |&lt;br /&gt;
                   Factor    Int&lt;br /&gt;
                     |&lt;br /&gt;
                    Int  &lt;br /&gt;
This parse tree grows to the left, indicating that the &#039;+&#039; operator is left associative, representing &#039;&#039;(a + a) + a&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
But now that we&#039;ve changed the grammar, our parse tree looks like this:&lt;br /&gt;
                             Expr ---&lt;br /&gt;
                            /        \&lt;br /&gt;
                          Term      Expr&#039; --&lt;br /&gt;
                           |       /  |     \ &lt;br /&gt;
                         Factor   +  Term   Expr&#039; ------&lt;br /&gt;
                           |          |      |  \       \&lt;br /&gt;
                          Int       Factor   +  Term   Expr&#039;&lt;br /&gt;
                                      |           |      |&lt;br /&gt;
                                     Int        Factor   &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt;&lt;br /&gt;
                                                  |&lt;br /&gt;
                                                 Int&lt;br /&gt;
&lt;br /&gt;
We can see that the tree grows to the right, representing &#039;&#039;a + (a + a)&#039;&#039;.  We have changed the associativity of our operator &#039;+&#039;, it is now right-associative. While this isn&#039;t a problem for the associativity of integer addition, it would have a significantly different value if this were subtraction.  &lt;br /&gt;
&lt;br /&gt;
The problem is that normal arithmetic requires left associativity. Several solutions are: (a) rewrite the grammar to be left recursive, or (b) rewrite the grammar with more nonterminals to force the correct precedence/associativity, or (c) if using [[YACC]] or [[GNU bison|Bison]], there are &#039;&#039;operator declarations,&#039;&#039; %left, %right and %nonassoc, which tell the [[parser generator]] which associativity to force.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Tail recursion]]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
* [http://www.cs.umd.edu/class/fall2002/cmsc430/lec4.pdf CMU lecture on left-recursion]&lt;br /&gt;
* [http://lambda.uta.edu/cse5317/notes/node21.html Practical Considerations for LALR(1) Grammars]&lt;br /&gt;
* [http://www.cs.uwindsor.ca/~hafiz/proHome.html X-SAIGA] - eXecutable SpecificAtIons of GrAmmars&lt;br /&gt;
&lt;br /&gt;
[[Category:Control flow]]&lt;br /&gt;
[[Category:Formal languages]]&lt;br /&gt;
[[Category:Parsing]]&lt;br /&gt;
[[Category:Recursion]]&lt;/div&gt;</summary>
		<author><name>38.112.100.65</name></author>
	</entry>
</feed>