Index: branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/Grammar.cs
===================================================================
--- branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/Grammar.cs	(revision 15792)
+++ branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/Grammar.cs	(revision 15794)
@@ -24,8 +24,4 @@
     public NonterminalSymbol SinFactor;
 
-    public NonterminalSymbol InvExpr;
-    public NonterminalSymbol InvTerm;
-    public NonterminalSymbol InvFactor;
-
     public NonterminalSymbol SimpleExpr;
     public NonterminalSymbol SimpleTerm;
@@ -75,8 +71,4 @@
       SinFactor = new NonterminalSymbol("SinFactor");
 
-      InvExpr = new NonterminalSymbol("InvExpr");
-      InvTerm = new NonterminalSymbol("InvTerm");
-      InvFactor = new NonterminalSymbol("InvFactor");
-
       SimpleExpr = new NonterminalSymbol("SimpleExpr");
       SimpleTerm = new NonterminalSymbol("SimpleTerm");
@@ -95,6 +87,4 @@
 
       #region Production rules
-      // order of production is important, since they are accessed via index
-      // in memoization.
       StartSymbol = Expr;
 
@@ -103,6 +93,6 @@
 
       Term.AddProduction(Factor, Term, Multiplication);
+      Term.AddProduction(Expr, Inv, Term, Multiplication);
       Term.AddProduction(Factor);
-      Term.AddProduction(InvExpr, Inv);
 
       Factor.AddProduction(Var);
@@ -120,14 +110,4 @@
       SimpleTerm.AddProduction(Var, SimpleTerm, Multiplication);
       SimpleTerm.AddProduction(Var);
-  
-      InvExpr.AddProduction(InvTerm, InvExpr, Addition);
-      InvExpr.AddProduction(InvTerm);
-
-      InvTerm.AddProduction(InvFactor, InvTerm, Multiplication);
-      InvTerm.AddProduction(InvFactor);
-
-      InvFactor.AddProduction(Var);
-      InvFactor.AddProduction(LogFactor);
-      InvFactor.AddProduction(SinFactor);
       #endregion
 
@@ -157,4 +137,5 @@
 
       Stack<Symbol> parseStack = new Stack<Symbol>(sentence);
+      CancelOutCompoundInverse(parseStack);
 
       Symbol peek = parseStack.Peek();
@@ -164,4 +145,5 @@
 
     private string[] GetSubtreeHashes(Stack<Symbol> parseStack) {
+      CancelOutCompoundInverse(parseStack);
       Symbol currentSymbol = parseStack.Pop();
 
@@ -211,10 +193,22 @@
 
         // Cancel out inverse factors.
-        var inversChildHashes = childHashes
-          .Select(ch => AggregateHashes(Inv, ch.ToEnumerable()))
-          .ToList();
-
-        return childHashes // If this factor cancels out another one, then remove BOTH. Otherwise, keep the factor.
-          .Where(ch => !inversChildHashes.Remove(ch))
+        bool[] isFactorRemaining = Enumerable.Repeat(true, childHashes.Count).ToArray();
+
+        for (int i = 0; i < isFactorRemaining.Length; i++) {
+          if (!isFactorRemaining[i]) continue;
+          if (isFactorRemaining.Count(b => b) <= 2) break; // Until we have constants, we can't cancel out all terms.
+
+          var currFactor = childHashes[i];
+          var invFactor = AggregateHashes(Inv, currFactor.ToEnumerable());
+
+          int indexOfInv = childHashes.IndexOf(invFactor);
+          if (indexOfInv >= 0 && isFactorRemaining[indexOfInv]) {
+            isFactorRemaining[i] = isFactorRemaining[indexOfInv] = false;
+          }
+        }
+        return Enumerable
+          .Range(0, isFactorRemaining.Length)
+          .Where(i => isFactorRemaining[i])
+          .Select(i => childHashes[i])
           .ToArray();
       }
@@ -241,4 +235,19 @@
 
       return "[" + hashesArray.Aggregate(operatorSym.StringRepresentation, (result, ti) => result + " ° " + ti) + "]";
+    }
+
+    private void CancelOutCompoundInverse(Stack<Symbol> parseStack) {
+      // Resolve compound divisions
+      int compoundFractionsCount = 0;
+
+      while (ReferenceEquals(parseStack.Peek(), Inv)) {
+        compoundFractionsCount++;
+        parseStack.Pop();
+      }
+
+      if (compoundFractionsCount % 2 != 0) {
+        // Compound division are reduced to a single division.
+        parseStack.Push(Inv);
+      } // else: compound divisions fully cancel out each other.
     }
     #endregion
Index: branches/2886_SymRegGrammarEnumeration/Test/GrammarEnumerationTest.cs
===================================================================
--- branches/2886_SymRegGrammarEnumeration/Test/GrammarEnumerationTest.cs	(revision 15792)
+++ branches/2886_SymRegGrammarEnumeration/Test/GrammarEnumerationTest.cs	(revision 15794)
@@ -179,5 +179,5 @@
     [TestProperty("Goal", "structure search")]
     public void NoConstants_Inverse() {
-      // sin(x) / (log(x)*x + x)
+      // x / (log(x)*x + x)
       alg.MaxTreeSize = 12;
 
