Index: trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/InfixExpressionFormatter.cs
===================================================================
--- trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/InfixExpressionFormatter.cs	(revision 18171)
+++ trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/InfixExpressionFormatter.cs	(revision 18172)
@@ -37,7 +37,12 @@
         var token = GetToken(node.Symbol);
         // operators
-        if (token == "+" || token == "-" || token == "OR" || token == "XOR" ||
-            token == "*" || token == "/" || token == "AND") {
-          strBuilder.Append("(");
+        if (token == "+" || token == "-" || token == "OR" || token == "XOR") {
+          var parenthesisRequired = false;
+          if (node.Parent != null && node.Parent.SubtreeCount > 1) {
+            var parentOp = GetToken(node.Parent.Symbol);
+            if (parentOp != "+" && parentOp != "-" && parentOp != "OR" && parentOp != "XOR")
+              parenthesisRequired = true;
+          }
+          if (parenthesisRequired) strBuilder.Append("(");
           FormatRecursively(node.Subtrees.First(), strBuilder, numberFormat, formatString, parameters);
 
@@ -47,12 +52,25 @@
           }
 
-          strBuilder.Append(")");
+          if (parenthesisRequired) strBuilder.Append(")");
+        } else if (token == "*" || token == "/" || token == "AND") {
+          FormatRecursively(node.Subtrees.First(), strBuilder, numberFormat, formatString, parameters);
+
+          foreach (var subtree in node.Subtrees.Skip(1)) {
+            strBuilder.Append(" ").Append(token).Append(" ");
+            // a / b * c => a / (b * C)
+            if (subtree.SubtreeCount > 1 && token == "/" && GetToken(subtree.Symbol) == "*") {
+              strBuilder.Append("(");
+              FormatRecursively(subtree, strBuilder, numberFormat, formatString, parameters);
+              strBuilder.Append(")");
+            } else {
+              FormatRecursively(subtree, strBuilder, numberFormat, formatString, parameters);
+            }
+          }
         } else if (token == "^") {
           // handle integer powers directly
-          strBuilder.Append("(");
           FormatRecursively(node.Subtrees.First(), strBuilder, numberFormat, formatString, parameters);
 
           var power = node.GetSubtree(1);
-          if(power is INumericTreeNode numNode && Math.Truncate(numNode.Value) == numNode.Value) {
+          if (power is INumericTreeNode numNode && Math.Truncate(numNode.Value) == numNode.Value) {
             strBuilder.Append(" ").Append(token).Append(" ").Append(numNode.Value.ToString(formatString, numberFormat));
           } else {
@@ -60,6 +78,4 @@
             FormatRecursively(power, strBuilder, numberFormat, formatString, parameters);
           }
-
-          strBuilder.Append(")");
         } else {
           // function with multiple arguments
@@ -76,7 +92,6 @@
         var token = GetToken(node.Symbol);
         if (token == "-" || token == "NOT") {
-          strBuilder.Append("(").Append(token).Append("(");
-          FormatRecursively(node.GetSubtree(0), strBuilder, numberFormat, formatString, parameters);
-          strBuilder.Append("))");
+          strBuilder.Append(token);
+          FormatRecursively(node.GetSubtree(0), strBuilder, numberFormat, formatString, parameters);
         } else if (token == "/") {
           strBuilder.Append("1/");
@@ -95,5 +110,4 @@
           var varNode = node as LaggedVariableTreeNode;
           if (!varNode.Weight.IsAlmost(1.0)) {
-            strBuilder.Append("(");
             AppendNumber(strBuilder, parameters, varNode.Weight, formatString, numberFormat);
             strBuilder.Append("*");
@@ -105,16 +119,11 @@
                     .AppendFormat(numberFormat, "{0}", varNode.Lag)
                     .Append(")");
-          if (!varNode.Weight.IsAlmost(1.0)) strBuilder.Append(")");
         } else if (node.Symbol is Variable) {
           var varNode = node as VariableTreeNode;
           if (!varNode.Weight.IsAlmost(1.0)) {
-            strBuilder.Append("(");
             AppendNumber(strBuilder, parameters, varNode.Weight, formatString, numberFormat);
             strBuilder.Append("*");
           }
-
           AppendVariableName(strBuilder, varNode.VariableName);
-
-          if (!varNode.Weight.IsAlmost(1.0)) strBuilder.Append(")");
         } else if (node.Symbol is FactorVariable) {
           var factorNode = node as FactorVariableTreeNode;
@@ -130,20 +139,14 @@
           var factorNode = node as BinaryFactorVariableTreeNode;
           if (!factorNode.Weight.IsAlmost(1.0)) {
-            strBuilder.Append("(");
             AppendNumber(strBuilder, parameters, factorNode.Weight, formatString, numberFormat);
-
             strBuilder.Append("*");
           }
-
           AppendVariableName(strBuilder, factorNode.VariableName);
           strBuilder.Append(" = ");
           AppendVariableName(strBuilder, factorNode.VariableValue);
-
-          if (!factorNode.Weight.IsAlmost(1.0)) strBuilder.Append(")");
         } else if (node is INumericTreeNode numNode) {
           if (parameters == null && numNode.Value < 0) {
             // negative value
-            strBuilder.Append("(").Append(numNode.Value.ToString(formatString, numberFormat))
-                      .Append(")"); 
+            strBuilder.Append(numNode.Value.ToString(formatString, numberFormat));
           } else {
             AppendNumber(strBuilder, parameters, numNode.Value, formatString, numberFormat);
