Index: /branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/Grammar.cs
===================================================================
--- /branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/Grammar.cs	(revision 15848)
+++ /branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/Grammar.cs	(revision 15849)
@@ -42,7 +42,5 @@
     public TerminalSymbol Inv;
 
-    // For infix notation
-    public TerminalSymbol OpeningBracket;
-    public TerminalSymbol ClosingBracket;
+    public TerminalSymbol Const;
 
     #endregion
@@ -93,6 +91,5 @@
       Inv = new TerminalSymbol("inv");
 
-      OpeningBracket = new TerminalSymbol("(");
-      ClosingBracket = new TerminalSymbol(")");
+      Const = new TerminalSymbol("c");
       #endregion
 
@@ -107,6 +104,6 @@
 
       productions[Expr] = new[] {
-        new Production(Term, Expr, Addition),
-        new Production(Term)
+        new Production(Const, Term, Multiplication, Expr, Addition),
+        new Production(Const, Term, Multiplication, Const, Addition)
       };
 
@@ -126,11 +123,11 @@
 
       productions[LogFactor] = new[] { new Production(SimpleExpr, Log) };
-      productions[ExpFactor] = new[] { new Production(SimpleTerm, Exp) };
+      productions[ExpFactor] = new[] { new Production(Const, SimpleTerm, Multiplication, Exp) };
       productions[SinFactor] = new[] { new Production(SimpleExpr, Sin) };
       productions[CosFactor] = new[] { new Production(SimpleExpr, Cos) };
 
       productions[SimpleExpr] = new[] {
-        new Production(SimpleTerm, SimpleExpr, Addition),
-        new Production(SimpleTerm)
+        new Production(Const, SimpleTerm, Multiplication, SimpleExpr, Addition),
+        new Production(Const, SimpleTerm, Multiplication, Const, Addition)
       };
 
@@ -141,6 +138,6 @@
 
       productions[InvExpr] = new[] {
-        new Production(InvTerm, InvExpr, Addition),
-        new Production(InvTerm)
+        new Production(Const, InvTerm, Multiplication, InvExpr, Addition),
+        new Production(Const, InvTerm, Multiplication, Const, Addition)
       };
 
@@ -206,6 +203,15 @@
       if (currentSymbol == Addition) {
         parsedSubTree = addSy.CreateTreeNode();
-        parsedSubTree.AddSubtree(ParseSymbolicExpressionTree(parseStack)); // left part
-        parsedSubTree.AddSubtree(ParseSymbolicExpressionTree(parseStack)); // right part
+        ISymbolicExpressionTreeNode rightSubtree = ParseSymbolicExpressionTree(parseStack);
+        if (rightSubtree is ConstantTreeNode) {
+          ((ConstantTreeNode)rightSubtree).Value = 0.0;
+        }
+        parsedSubTree.AddSubtree(rightSubtree); // left part
+
+        ISymbolicExpressionTreeNode leftSubtree = ParseSymbolicExpressionTree(parseStack);
+        if (leftSubtree is ConstantTreeNode) {
+          ((ConstantTreeNode)leftSubtree).Value = 0.0;
+        }
+        parsedSubTree.AddSubtree(leftSubtree); // right part
 
       } else if (currentSymbol == Multiplication) {
@@ -236,4 +242,9 @@
         parsedSubTree.AddSubtree(dividend);
         parsedSubTree.AddSubtree(ParseSymbolicExpressionTree(parseStack));
+
+      } else if (currentSymbol == Const) {
+        ConstantTreeNode constNode = (ConstantTreeNode)constSy.CreateTreeNode();
+        constNode.Value = 1.0;
+        parsedSubTree = constNode;
 
       } else if (currentSymbol is VariableTerminalSymbol) {
Index: /branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/Hashing/Hasher.cs
===================================================================
--- /branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/Hashing/Hasher.cs	(revision 15848)
+++ /branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/Hashing/Hasher.cs	(revision 15849)
@@ -44,5 +44,5 @@
       }
 
-      // var or nonterminal symbol
+      // var, const or nonterminal symbol
       return new[] { AggregateHashes(currentSymbol, new THashType[0]) };
     }
Index: /branches/2886_SymRegGrammarEnumeration/Test/GrammarEnumerationTest.cs
===================================================================
--- /branches/2886_SymRegGrammarEnumeration/Test/GrammarEnumerationTest.cs	(revision 15848)
+++ /branches/2886_SymRegGrammarEnumeration/Test/GrammarEnumerationTest.cs	(revision 15849)
@@ -31,4 +31,7 @@
       alg.Problem = problem;
       alg.GuiUpdateInterval = int.MaxValue;
+      foreach (IGrammarEnumerationAnalyzer grammarEnumerationAnalyzer in alg.Analyzers) {
+        alg.Analyzers.SetItemCheckedState(grammarEnumerationAnalyzer, grammarEnumerationAnalyzer is RSquaredEvaluator);
+      }
     }
 
@@ -57,9 +60,10 @@
     public void NoConstants_Nguyen1() {
       // x³ + x² + x
-      alg.MaxTreeSize = 12;
+      alg.MaxTreeSize = 20;
       alg.Problem.ProblemData = new NguyenFunctionOne(Seed).GenerateRegressionData();
 
       alg.Start();
 
+      TerminalSymbol constSymbol = alg.Grammar.Const;
       TerminalSymbol varSymbol = alg.Grammar.VarTerminals.First();
       TerminalSymbol mulSymbol = alg.Grammar.Multiplication;
@@ -67,7 +71,8 @@
 
       SymbolString targetSolution = new SymbolString(new[] {
-        varSymbol, varSymbol, varSymbol, mulSymbol, mulSymbol,
-        varSymbol, varSymbol, mulSymbol, addSymbol,
-        varSymbol, addSymbol
+        constSymbol, varSymbol, varSymbol, varSymbol, mulSymbol, mulSymbol, mulSymbol,
+        constSymbol, varSymbol, varSymbol, mulSymbol, mulSymbol, addSymbol,
+        constSymbol, varSymbol, mulSymbol, addSymbol,
+        constSymbol, addSymbol
       });
 
@@ -88,5 +93,5 @@
     public void NoConstants_Nguyen2() {
       // x^4 + x³ + x² + x
-      alg.MaxTreeSize = 20;
+      alg.MaxTreeSize = 30;
       alg.Problem.ProblemData = new NguyenFunctionTwo(Seed).GenerateRegressionData();
 
@@ -112,9 +117,10 @@
     public void NoConstants_Nguyen6() {
       // sin(x) + sin(x + x²)
-      alg.MaxTreeSize = 10;
+      alg.MaxTreeSize = 25;
       alg.Problem.ProblemData = new NguyenFunctionSix(Seed).GenerateRegressionData();
 
       alg.Start();
 
+      TerminalSymbol constSymbol = alg.Grammar.Const;
       TerminalSymbol varSymbol = alg.Grammar.VarTerminals.First();
       TerminalSymbol mulSymbol = alg.Grammar.Multiplication;
@@ -122,7 +128,9 @@
       TerminalSymbol sinSymbol = alg.Grammar.Sin;
 
+      // c * sin(c x + c) + c * sin(c * x * x + c * x) + c
       SymbolString targetSolution = new SymbolString(new[] {
-        varSymbol, sinSymbol,
-        varSymbol, varSymbol, mulSymbol, varSymbol, addSymbol, sinSymbol, addSymbol
+        varSymbol, constSymbol, mulSymbol, constSymbol, addSymbol, sinSymbol, constSymbol, mulSymbol,
+        varSymbol, varSymbol, mulSymbol, constSymbol, mulSymbol, varSymbol, constSymbol, mulSymbol, addSymbol, constSymbol, addSymbol, sinSymbol, constSymbol, mulSymbol, addSymbol,
+        constSymbol, addSymbol
       });
 
@@ -140,5 +148,5 @@
     public void NoConstants_Nguyen9() {
       // sin(x) + sin(y²)
-      alg.MaxTreeSize = 11;
+      alg.MaxTreeSize = 22;
       alg.Problem.ProblemData = new NguyenFunctionNine(Seed).GenerateRegressionData();
 
@@ -147,11 +155,14 @@
       TerminalSymbol xSymbol = alg.Grammar.VarTerminals.First(v => v.StringRepresentation == "X");
       TerminalSymbol ySymbol = alg.Grammar.VarTerminals.First(v => v.StringRepresentation == "Y");
+      TerminalSymbol constSymbol = alg.Grammar.Const;
       TerminalSymbol mulSymbol = alg.Grammar.Multiplication;
       TerminalSymbol addSymbol = alg.Grammar.Addition;
       TerminalSymbol sinSymbol = alg.Grammar.Sin;
 
+      // c*sin(c*x + c) + c*sin(c*y*y + c) + c
       SymbolString targetSolution = new SymbolString(new[] {
-        xSymbol, sinSymbol,
-        ySymbol, ySymbol, mulSymbol, sinSymbol, addSymbol
+        xSymbol, constSymbol, mulSymbol, constSymbol, addSymbol, sinSymbol, constSymbol, mulSymbol,
+        ySymbol, ySymbol, mulSymbol, constSymbol, mulSymbol, constSymbol, addSymbol, sinSymbol, constSymbol, mulSymbol, addSymbol,
+        constSymbol, addSymbol
       });
 
@@ -180,5 +191,5 @@
     public void NoConstants_Inverse() {
       // x / (log(x)*x + x)
-      alg.MaxTreeSize = 12;
+      alg.MaxTreeSize = 23;
 
       var x = Enumerable.Range(0, 100).Select(_ => rand.NextDouble() + 1.1).ToList();
Index: /branches/2886_SymRegGrammarEnumeration/Test/TreeHashingTest.cs
===================================================================
--- /branches/2886_SymRegGrammarEnumeration/Test/TreeHashingTest.cs	(revision 15848)
+++ /branches/2886_SymRegGrammarEnumeration/Test/TreeHashingTest.cs	(revision 15849)
@@ -12,4 +12,5 @@
     private TerminalSymbol varB;
     private TerminalSymbol varC;
+    private TerminalSymbol c;
 
     [TestInitialize]
@@ -20,4 +21,5 @@
       varB = grammar.VarTerminals.First(s => s.StringRepresentation == "b");
       varC = grammar.VarTerminals.First(s => s.StringRepresentation == "c");
+      c = grammar.Const;
     }
 
@@ -132,4 +134,17 @@
     }
 
+    // Constants
+    [TestMethod]
+    [TestCategory("TreeHashing")]
+    public void SimpleConst() {
+      SymbolString s1 = new SymbolString(new Symbol[] { c, varA, grammar.Multiplication, c, grammar.Addition});
+      SymbolString s2 = new SymbolString(new Symbol[] { c, varA, grammar.Multiplication, c, varA, grammar.Multiplication, grammar.Addition, c, grammar.Addition });
+
+      int hash1 = grammar.Hasher.CalcHashCode(s1);
+      int hash2 = grammar.Hasher.CalcHashCode(s2);
+
+      Assert.AreEqual(hash1, hash2);
+    }
+
     /* DEPRECATED; SINCE WE DO NOT ALLOW COMPOUND DIVISIONS
     [TestMethod]
