Index: /trunk/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/DeriveTest.cs
===================================================================
--- /trunk/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/DeriveTest.cs	(revision 18169)
+++ /trunk/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/DeriveTest.cs	(revision 18170)
@@ -34,41 +34,40 @@
     public void DeriveExpressions() {
       var formatter = new InfixExpressionFormatter();
-      var parser = new InfixExpressionParser();
       Assert.AreEqual("0", Derive("<num=3>", "x"));
       Assert.AreEqual("1", Derive("x", "x"));
       Assert.AreEqual("10", Derive("<num=10>*x", "x"));
       Assert.AreEqual("10", Derive("x*<num=10>", "x"));
-      Assert.AreEqual("(2*'x')", Derive("x*x", "x"));
-      Assert.AreEqual("((('x' * 'x') * 2) + ('x' * 'x'))", Derive("x*x*x", "x")); // simplifier does not merge (x*x)*2 + x*x  to 3*x*x
+      Assert.AreEqual("2*'x'", Derive("x*x", "x"));
+      Assert.AreEqual("'x' * 'x' * 2 + 'x' * 'x'", Derive("x*x*x", "x")); // simplifier does not merge (x*x)*2 + x*x  to 3*x*x
       Assert.AreEqual("0", Derive("<num=10>*x", "y"));
       Assert.AreEqual("20", Derive("<num=10>*x+<num=20>*y", "y"));
       Assert.AreEqual("6", Derive("<num=2>*<num=3>*x", "x"));
-      Assert.AreEqual("(10*'y')", Derive("<num=10>*x*y+<num=20>*y", "x"));
+      Assert.AreEqual("10 * 'y'", Derive("<num=10>*x*y+<num=20>*y", "x"));
       Assert.AreEqual("(1 / (SQR('x') * (-1)))", Derive("1/x", "x"));
-      Assert.AreEqual("('y' / (SQR('x') * (-1)))", Derive("y/x", "x"));
-      Assert.AreEqual("((((-2*'x') + (-1)) * ('a' + 'b')) / SQR(('x' + ('x' * 'x'))))",
+      Assert.AreEqual("'y' / (SQR('x') * -1)", Derive("y/x", "x"));
+      Assert.AreEqual("(-2*'x' + -1) * ('a' + 'b') / SQR('x' + 'x' * 'x')",
         Derive("(a+b)/(x+x*x)", "x"));
-      Assert.AreEqual("((((-2*'x') + (-1)) * ('a' + 'b')) / SQR(('x' + SQR('x'))))", Derive("(a+b)/(x+SQR(x))", "x"));
+      Assert.AreEqual("(-2*'x' + -1) * ('a' + 'b') / SQR('x' + SQR('x'))", Derive("(a+b)/(x+SQR(x))", "x"));
       Assert.AreEqual("EXP('x')", Derive("exp(x)", "x"));
-      Assert.AreEqual("(EXP((3*'x')) * 3)", Derive("exp(<num=3>*x)", "x"));
-      Assert.AreEqual("(1 / 'x')", Derive("log(x)", "x"));
-      Assert.AreEqual("(1 / 'x')", Derive("log(<num=3>*x)", "x"));   // 3 * 1/(3*x)
-      Assert.AreEqual("(1 / ('x' + (0.333333333333333*'y')))", Derive("log(<num=3>*x+y)", "x"));  // simplifier does not try to keep fractions
-      Assert.AreEqual("(1 / (SQRT(((3*'x') + 'y')) * 0.666666666666667))", Derive("sqrt(<num=3>*x+y)", "x"));   // 3 / (2 * sqrt(3*x+y)) = 1 / ((2/3) * sqrt(3*x+y)) 
-      Assert.AreEqual("(COS((3*'x')) * 3)", Derive("sin(<num=3>*x)", "x"));
-      Assert.AreEqual("(SIN((3*'x')) * (-3))", Derive("cos(<num=3>*x)", "x"));
-      Assert.AreEqual("(1 / (SQR(COS((3*'x'))) * 0.333333333333333))", Derive("tan(<num=3>*x)", "x")); // diff(tan(f(x)), x) = 1.0 / cos²(f(x)), simplifier puts constant factor into the denominator
+      Assert.AreEqual("EXP(3*'x') * 3", Derive("exp(<num=3>*x)", "x"));
+      Assert.AreEqual("1 / 'x'", Derive("log(x)", "x"));
+      Assert.AreEqual("1 / 'x'", Derive("log(<num=3>*x)", "x"));   // 3 * 1/(3*x)
+      Assert.AreEqual("1 / ('x' + 0.333333333333333*'y')", Derive("log(<num=3>*x+y)", "x"));  // simplifier does not try to keep fractions
+      Assert.AreEqual("1 / (SQRT(3*'x' + 'y') * 0.666666666666667)", Derive("sqrt(<num=3>*x+y)", "x"));   // 3 / (2 * sqrt(3*x+y)) = 1 / ((2/3) * sqrt(3*x+y)) 
+      Assert.AreEqual("COS(3*'x') * 3", Derive("sin(<num=3>*x)", "x"));
+      Assert.AreEqual("SIN(3*'x') * -3", Derive("cos(<num=3>*x)", "x"));
+      Assert.AreEqual("1 / (SQR(COS(3*'x')) * 0.333333333333333)", Derive("tan(<num=3>*x)", "x")); // diff(tan(f(x)), x) = 1.0 / cos²(f(x)), simplifier puts constant factor into the denominator
 
-      Assert.AreEqual("((9*'x') / ABS((3*'x')))", Derive("abs(<num=3>*x)", "x"));
-      Assert.AreEqual("(SQR('x') * 3)", Derive("cube(x)", "x"));
-      Assert.AreEqual("(1 / (SQR(CUBEROOT('x')) * 3))", Derive("cuberoot(x)", "x"));
+      Assert.AreEqual("9*'x' / ABS(3*'x')", Derive("abs(<num=3>*x)", "x"));
+      Assert.AreEqual("SQR('x') * 3", Derive("cube(x)", "x"));
+      Assert.AreEqual("1 / (SQR(CUBEROOT('x')) * 3)", Derive("cuberoot(x)", "x"));
 
       Assert.AreEqual("0", Derive("(a+b)/(x+SQR(x))", "y")); // df(a,b,x) / dy = 0
 
 
-      Assert.AreEqual("('a' * 'b' * 'c')", Derive("a*b*c*d", "d"));
-      Assert.AreEqual("('a' / ('b' * 'c' * SQR('d') * (-1)))", Derive("a/b/c/d", "d"));
+      Assert.AreEqual("'a' * 'b' * 'c'", Derive("a*b*c*d", "d"));
+      Assert.AreEqual("'a' / ('b' * 'c' * SQR('d') * -1)", Derive("a/b/c/d", "d"));
 
-      Assert.AreEqual("('x' * ((SQR(TANH(SQR('x'))) * (-1)) + 1) * 2)", Derive("tanh(sqr(x))", "x")); // (2*'x'*(1 - SQR(TANH(SQR('x'))))
+      Assert.AreEqual("'x' * (SQR(TANH(SQR('x'))) * -1 + 1) * 2", Derive("tanh(sqr(x))", "x")); // (2*'x'*(1 - SQR(TANH(SQR('x'))))
 
       {
@@ -125,11 +124,11 @@
         var t = new SymbolicExpressionTree(root);
 
-        Assert.AreEqual("(('y' * 'z' * 60) / (SQR('y') * SQR('z') * 400))", // actually 3 / (4y  5z) but simplifier is not smart enough to cancel numerator and denominator
+        Assert.AreEqual("'y' * 'z' * 60 / (SQR('y') * SQR('z') * 400)", // actually 3 / (4y  5z) but simplifier is not smart enough to cancel numerator and denominator
                                                                             // 60 y z / y² z² 20² == 6 / y z 40 == 3 / y z 20
           formatter.Format(DerivativeCalculator.Derive(t, "x")));
-        Assert.AreEqual("(('x' * 'z' * (-60)) / (SQR('y') * SQR('z') * 400))", // actually 3x * -(4 5 z) / (4y 5z)² = -3x / (20 y² z)
+        Assert.AreEqual("'x' * 'z' * -60 / (SQR('y') * SQR('z') * 400)", // actually 3x * -(4 5 z) / (4y 5z)² = -3x / (20 y² z)
                                                                                // -3 4 5 x z / 4² y² 5² z² = -60 x z / 20² z² y² ==    -60 x z / y² z² 20² 
           formatter.Format(DerivativeCalculator.Derive(t, "y")));
-        Assert.AreEqual("(('x' * 'y' * (-60)) / (SQR('y') * SQR('z') * 400))",
+        Assert.AreEqual("'x' * 'y' * -60 / (SQR('y') * SQR('z') * 400)",
           formatter.Format(DerivativeCalculator.Derive(t, "z")));
       }
Index: /trunk/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/InfixExpressionParserTest.cs
===================================================================
--- /trunk/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/InfixExpressionParserTest.cs	(revision 18169)
+++ /trunk/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/InfixExpressionParserTest.cs	(revision 18170)
@@ -35,6 +35,6 @@
       var parser = new InfixExpressionParser();
       Assert.AreEqual("3", formatter.Format(parser.Parse("3")));
-      Assert.AreEqual("(3 * 3)", formatter.Format(parser.Parse("3*3")));
-      Assert.AreEqual("(3 * 4)",formatter.Format(parser.Parse("3 * 4")));
+      Assert.AreEqual("3 * 3", formatter.Format(parser.Parse("3*3")));
+      Assert.AreEqual("3 * 4",formatter.Format(parser.Parse("3 * 4")));
       Assert.AreEqual("0.123",formatter.Format(parser.Parse("123E-03")));
       Assert.AreEqual("0.123",formatter.Format(parser.Parse("123e-03")));
@@ -50,38 +50,38 @@
       Assert.AreEqual("123000",formatter.Format(parser.Parse("123.0E+3")));
 
-      Assert.AreEqual("(3.1415 + 2)",formatter.Format(parser.Parse("3.1415+2.0")));
-      Assert.AreEqual("(3.1415 / 2)",formatter.Format(parser.Parse("3.1415/2.0")));
-      Assert.AreEqual("(3.1415 * 2)",formatter.Format(parser.Parse("3.1415*2.0")));
-      Assert.AreEqual("(3.1415 - 2)", formatter.Format(parser.Parse("3.1415-2.0")));
+      Assert.AreEqual("3.1415 + 2",formatter.Format(parser.Parse("3.1415+2.0")));
+      Assert.AreEqual("3.1415 / 2",formatter.Format(parser.Parse("3.1415/2.0")));
+      Assert.AreEqual("3.1415 * 2",formatter.Format(parser.Parse("3.1415*2.0")));
+      Assert.AreEqual("3.1415 - 2", formatter.Format(parser.Parse("3.1415-2.0")));
       // round-trip
-      Assert.AreEqual("(3.1415 - 2)",formatter.Format(parser.Parse(formatter.Format(parser.Parse("3.1415-2.0")))));
-      Assert.AreEqual("(3.1415 + 2)",formatter.Format(parser.Parse("3.1415+(2.0)")));
-      Assert.AreEqual("(3.1415 + 2)", formatter.Format(parser.Parse("(3.1415+(2.0))")));
+      Assert.AreEqual("3.1415 - 2",formatter.Format(parser.Parse(formatter.Format(parser.Parse("3.1415-2.0")))));
+      Assert.AreEqual("3.1415 + 2",formatter.Format(parser.Parse("3.1415+(2.0)")));
+      Assert.AreEqual("3.1415 + 2", formatter.Format(parser.Parse("(3.1415+(2.0))")));
 
 
       Assert.AreEqual("LOG(3)",formatter.Format(parser.Parse("log(3)")));
-      Assert.AreEqual("LOG((-3))",formatter.Format(parser.Parse("log(-3)")));
+      Assert.AreEqual("LOG(-3)",formatter.Format(parser.Parse("log(-3)")));
       Assert.AreEqual("EXP(3)",formatter.Format(parser.Parse("exp(3)")));
-      Assert.AreEqual("EXP((-3))",formatter.Format(parser.Parse("exp(-3)")));
+      Assert.AreEqual("EXP(-3)",formatter.Format(parser.Parse("exp(-3)")));
       Assert.AreEqual("SQRT(3)", formatter.Format(parser.Parse("sqrt(3)")));
 
-      Assert.AreEqual("SQR((-3))", formatter.Format(parser.Parse("sqr((-3))")));
+      Assert.AreEqual("SQR(-3)", formatter.Format(parser.Parse("sqr((-3))")));
 
-      Assert.AreEqual("((3 / 3) + (2 / 2) + (1 / 1))",formatter.Format(parser.Parse("3/3+2/2+1/1")));
-      Assert.AreEqual("((((((-3) + 30) - 2) + 20) - 1) + 10)", formatter.Format(parser.Parse("-3+30-2+20-1+10")));
+      Assert.AreEqual("3 / 3 + 2 / 2 + 1 / 1",formatter.Format(parser.Parse("3/3+2/2+1/1")));
+      Assert.AreEqual("-3 + 30 - 2 + 20 - 1 + 10", formatter.Format(parser.Parse("-3+30-2+20-1+10")));
 
       // 'flattening' of nested addition, subtraction, multiplication, or division
-      Assert.AreEqual("(1 + 2 + 3 + 4)", formatter.Format(parser.Parse("1 + 2 + 3 + 4")));
-      Assert.AreEqual("(1 - 2 - 3 - 4)", formatter.Format(parser.Parse("1 - 2 - 3 - 4")));
-      Assert.AreEqual("(1 * 2 * 3 * 4)", formatter.Format(parser.Parse("1 * 2 * 3 * 4")));
-      Assert.AreEqual("(1 / 2 / 3 / 4)", formatter.Format(parser.Parse("1 / 2 / 3 / 4")));
+      Assert.AreEqual("1 + 2 + 3 + 4", formatter.Format(parser.Parse("1 + 2 + 3 + 4")));
+      Assert.AreEqual("1 - 2 - 3 - 4", formatter.Format(parser.Parse("1 - 2 - 3 - 4")));
+      Assert.AreEqual("1 * 2 * 3 * 4", formatter.Format(parser.Parse("1 * 2 * 3 * 4")));
+      Assert.AreEqual("1 / 2 / 3 / 4", formatter.Format(parser.Parse("1 / 2 / 3 / 4")));
 
       // signed variables / constants
-      Assert.AreEqual("(-1*'x1')", formatter.Format(parser.Parse("-x1")));
+      Assert.AreEqual("-1*'x1'", formatter.Format(parser.Parse("-x1")));
       Assert.AreEqual("1", formatter.Format(parser.Parse("--1.0")));
       Assert.AreEqual("1", formatter.Format(parser.Parse("----1.0")));
       Assert.AreEqual("1", formatter.Format(parser.Parse("-+-1.0")));
       Assert.AreEqual("1", formatter.Format(parser.Parse("+-+-1.0")));
-      Assert.AreEqual("((-3) + (-1))", formatter.Format(parser.Parse("-3 + -1.0")));
+      Assert.AreEqual("-3 + -1", formatter.Format(parser.Parse("-3 + -1.0")));
 
 
@@ -95,19 +95,19 @@
 
 
-      Assert.AreEqual("('x1' * 'x2')",formatter.Format(parser.Parse("\"x1\"*\"x2\"")));
-      Assert.AreEqual("(('x1' * 'x2') + ('x3' * 'x4'))",formatter.Format(parser.Parse("\"x1\"*\"x2\"+\"x3\"*\"x4\"")));
-      Assert.AreEqual("(('x1' * 'x2') + ('x3' * 'x4'))", formatter.Format(parser.Parse("x1*x2+x3*x4")));
+      Assert.AreEqual("'x1' * 'x2'",formatter.Format(parser.Parse("\"x1\"*\"x2\"")));
+      Assert.AreEqual("'x1' * 'x2' + 'x3' * 'x4'",formatter.Format(parser.Parse("\"x1\"*\"x2\"+\"x3\"*\"x4\"")));
+      Assert.AreEqual("'x1' * 'x2' + 'x3' * 'x4'", formatter.Format(parser.Parse("x1*x2+x3*x4")));
 
 
-      Assert.AreEqual("(3 ^ 2)",formatter.Format(parser.Parse("POW(3, 2)")));
-      Assert.AreEqual("(3.1 ^ 2.1)",formatter.Format(parser.Parse("POW(3.1, 2.1)")));
-      Assert.AreEqual("(3.1 ^ 2.1)",formatter.Format(parser.Parse("POW(3.1 , 2.1)")));
-      Assert.AreEqual("(3.1 ^ 2.1)",formatter.Format(parser.Parse("POW(3.1 ,2.1)")));
-      Assert.AreEqual("((-3.1) ^ (-2.1))",formatter.Format(parser.Parse("POW(-3.1 , - 2.1)")));
+      Assert.AreEqual("3 ^ 2",formatter.Format(parser.Parse("POW(3, 2)")));
+      Assert.AreEqual("3.1 ^ 2.1",formatter.Format(parser.Parse("POW(3.1, 2.1)")));
+      Assert.AreEqual("3.1 ^ 2.1",formatter.Format(parser.Parse("POW(3.1 , 2.1)")));
+      Assert.AreEqual("3.1 ^ 2.1",formatter.Format(parser.Parse("POW(3.1 ,2.1)")));
+      Assert.AreEqual("-3.1 ^ -2.1",formatter.Format(parser.Parse("POW(-3.1 , - 2.1)")));
       Assert.AreEqual("ROOT(3, 2)",formatter.Format(parser.Parse("ROOT(3, 2)")));
       Assert.AreEqual("ROOT(3.1, 2.1)",formatter.Format(parser.Parse("ROOT(3.1, 2.1)")));
       Assert.AreEqual("ROOT(3.1, 2.1)",formatter.Format(parser.Parse("ROOT(3.1 , 2.1)")));
       Assert.AreEqual("ROOT(3.1, 2.1)",formatter.Format(parser.Parse("ROOT(3.1 ,2.1)")));
-      Assert.AreEqual("ROOT((-3.1), (-2.1))", formatter.Format(parser.Parse("ROOT(-3.1 , -2.1)")));
+      Assert.AreEqual("ROOT(-3.1, -2.1)", formatter.Format(parser.Parse("ROOT(-3.1 , -2.1)")));
 
       Assert.AreEqual("IF(GT(0, 1), 1, 0)",formatter.Format(parser.Parse("IF(GT( 0, 1), 1, 0)")));
@@ -116,22 +116,22 @@
       Assert.AreEqual("LAG('x', -1)",formatter.Format(parser.Parse("LAG(x, -1)")));
       Assert.AreEqual("LAG('x', 1)",formatter.Format(parser.Parse("LAG(x, +1)")));
-      Assert.AreEqual("('x' * LAG('x', 1))", formatter.Format(parser.Parse("x * LAG('x', +1)")));
+      Assert.AreEqual("'x' * LAG('x', 1)", formatter.Format(parser.Parse("x * LAG('x', +1)")));
 
       // factor variables
-      Assert.AreEqual("('x'[1] * 'y')",formatter.Format(parser.Parse("x [1.0] * y")));
-      Assert.AreEqual("('x'[1, 2] * 'y'[1, 2])",formatter.Format(parser.Parse("x [1.0, 2.0] * y [1.0, 2.0]")));
-      Assert.AreEqual("('x'[1] * 'y')",formatter.Format(parser.Parse("x[1] * y")));
-      Assert.AreEqual("('x'[1, 2] * 'y'[1, 2])",formatter.Format(parser.Parse("x[1, 2] * y [1, 2]")));
-      Assert.AreEqual("('x'[1] * 'y')",formatter.Format(parser.Parse("x [+1.0] * y")));
-      Assert.AreEqual("('x'[-1] * 'y')",formatter.Format(parser.Parse("x [-1.0] * y")));
-      Assert.AreEqual("('x'[-1, -2] * 'y'[1, 2])", formatter.Format(parser.Parse("x [-1.0, -2.0] * y [+1.0, +2.0]")));
+      Assert.AreEqual("'x'[1] * 'y'",formatter.Format(parser.Parse("x [1.0] * y")));
+      Assert.AreEqual("'x'[1, 2] * 'y'[1, 2]",formatter.Format(parser.Parse("x [1.0, 2.0] * y [1.0, 2.0]")));
+      Assert.AreEqual("'x'[1] * 'y'",formatter.Format(parser.Parse("x[1] * y")));
+      Assert.AreEqual("'x'[1, 2] * 'y'[1, 2]",formatter.Format(parser.Parse("x[1, 2] * y [1, 2]")));
+      Assert.AreEqual("'x'[1] * 'y'",formatter.Format(parser.Parse("x [+1.0] * y")));
+      Assert.AreEqual("'x'[-1] * 'y'",formatter.Format(parser.Parse("x [-1.0] * y")));
+      Assert.AreEqual("'x'[-1, -2] * 'y'[1, 2]", formatter.Format(parser.Parse("x [-1.0, -2.0] * y [+1.0, +2.0]")));
 
       // one-hot for factor
-      Assert.AreEqual("('x' = 'val' * 'y')",formatter.Format(parser.Parse("x='val' * y")));
+      Assert.AreEqual("'x' = 'val' * 'y'",formatter.Format(parser.Parse("x='val' * y")));
       Assert.AreEqual("'x' = 'val'",formatter.Format(parser.Parse("x = 'val'")));
       Assert.AreEqual("'x' = 'val'",formatter.Format(parser.Parse("x = \"val\"")));
-      Assert.AreEqual("(1 * 'x' = 'val')",formatter.Format(parser.Parse("1.0 * x = val")));
-      Assert.AreEqual("((-1) * 'x' = 'val')",formatter.Format(parser.Parse("-1.0 * x = val")));
-      Assert.AreEqual("((1 * 'x' = 'val1') + 'y' = 'val2')", formatter.Format(parser.Parse("+1.0 * \"x\" = val1 + y = \"val2\"")));
+      Assert.AreEqual("1 * 'x' = 'val'",formatter.Format(parser.Parse("1.0 * x = val")));
+      Assert.AreEqual("-1 * 'x' = 'val'",formatter.Format(parser.Parse("-1.0 * x = val")));
+      Assert.AreEqual("1 * 'x' = 'val1' + 'y' = 'val2'", formatter.Format(parser.Parse("+1.0 * \"x\" = val1 + y = \"val2\"")));
 
       // numeric parameters
@@ -140,6 +140,6 @@
       Assert.AreEqual("1", formatter.Format(parser.Parse("< num=1.0>")));
       Assert.AreEqual("1", formatter.Format(parser.Parse("< num = 1.0>")));
-      Assert.AreEqual("(-1)", formatter.Format(parser.Parse("< num =-1.0>")));
-      Assert.AreEqual("(-1)", formatter.Format(parser.Parse("< num = - 1.0>")));
+      Assert.AreEqual("-1", formatter.Format(parser.Parse("< num =-1.0>")));
+      Assert.AreEqual("-1", formatter.Format(parser.Parse("< num = - 1.0>")));
       
       // numeric parameter with sign
