Index: /branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionLatexFormatter.cs
===================================================================
--- /branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionLatexFormatter.cs	(revision 14763)
+++ /branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionLatexFormatter.cs	(revision 14764)
@@ -72,5 +72,5 @@
         strBuilder.AppendLine(FormatRecursively(symbolicExpressionTree.Root));
         return strBuilder.ToString();
-      } catch (NotImplementedException ex) {
+      } catch(NotImplementedException ex) {
         return ex.Message + Environment.NewLine + ex.StackTrace;
       }
@@ -85,9 +85,9 @@
       FormatBegin(node, strBuilder);
 
-      if (node.SubtreeCount > 0) {
+      if(node.SubtreeCount > 0) {
         strBuilder.Append(FormatRecursively(node.GetSubtree(0)));
       }
       int i = 1;
-      foreach (var subTree in node.Subtrees.Skip(1)) {
+      foreach(var subTree in node.Subtrees.Skip(1)) {
         FormatSep(node, strBuilder, i);
         // format the whole subtree
@@ -102,86 +102,86 @@
 
     private void FormatBegin(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) {
-      if (node.Symbol is Addition) {
+      if(node.Symbol is Addition) {
         strBuilder.Append(@" \left( ");
-      } else if (node.Symbol is Subtraction) {
-        if (node.SubtreeCount == 1) {
+      } else if(node.Symbol is Subtraction) {
+        if(node.SubtreeCount == 1) {
           strBuilder.Append(@"- \left( ");
         } else {
           strBuilder.Append(@" \left( ");
         }
-      } else if (node.Symbol is Multiplication) {
-      } else if (node.Symbol is Division) {
-        if (node.SubtreeCount == 1) {
+      } else if(node.Symbol is Multiplication) {
+      } else if(node.Symbol is Division) {
+        if(node.SubtreeCount == 1) {
           strBuilder.Append(@" \cfrac{1}{");
         } else {
           strBuilder.Append(@" \cfrac{ ");
         }
-      } else if (node.Symbol is Average) {
+      } else if(node.Symbol is Average) {
         // skip output of (1/1) if only one subtree
-        if (node.SubtreeCount > 1) {
+        if(node.SubtreeCount > 1) {
           strBuilder.Append(@" \cfrac{1}{" + node.SubtreeCount + @"}");
         }
         strBuilder.Append(@" \left( ");
-      } else if (node.Symbol is Logarithm) {
+      } else if(node.Symbol is Logarithm) {
         strBuilder.Append(@"\log \left( ");
-      } else if (node.Symbol is Exponential) {
+      } else if(node.Symbol is Exponential) {
         strBuilder.Append(@"\exp \left( ");
-      } else if (node.Symbol is Square) {
+      } else if(node.Symbol is Square) {
         strBuilder.Append(@"\left(");
-      } else if (node.Symbol is SquareRoot) {
+      } else if(node.Symbol is SquareRoot) {
         strBuilder.Append(@"\sqrt{");
-      } else if (node.Symbol is Sine) {
+      } else if(node.Symbol is Sine) {
         strBuilder.Append(@"\sin \left( ");
-      } else if (node.Symbol is Cosine) {
+      } else if(node.Symbol is Cosine) {
         strBuilder.Append(@"\cos \left( ");
-      } else if (node.Symbol is Tangent) {
+      } else if(node.Symbol is Tangent) {
         strBuilder.Append(@"\tan \left( ");
-      } else if (node.Symbol is AiryA) {
+      } else if(node.Symbol is AiryA) {
         strBuilder.Append(@"\operatorname{airy}_a \left( ");
-      } else if (node.Symbol is AiryB) {
+      } else if(node.Symbol is AiryB) {
         strBuilder.Append(@"\operatorname{airy}_b \left( ");
-      } else if (node.Symbol is Bessel) {
+      } else if(node.Symbol is Bessel) {
         strBuilder.Append(@"\operatorname{bessel}_1 \left( ");
-      } else if (node.Symbol is CosineIntegral) {
+      } else if(node.Symbol is CosineIntegral) {
         strBuilder.Append(@"\operatorname{cosInt} \left( ");
-      } else if (node.Symbol is Dawson) {
+      } else if(node.Symbol is Dawson) {
         strBuilder.Append(@"\operatorname{dawson} \left( ");
-      } else if (node.Symbol is Erf) {
+      } else if(node.Symbol is Erf) {
         strBuilder.Append(@"\operatorname{erf} \left( ");
-      } else if (node.Symbol is ExponentialIntegralEi) {
+      } else if(node.Symbol is ExponentialIntegralEi) {
         strBuilder.Append(@"\operatorname{expInt}_i \left( ");
-      } else if (node.Symbol is FresnelCosineIntegral) {
+      } else if(node.Symbol is FresnelCosineIntegral) {
         strBuilder.Append(@"\operatorname{fresnel}_\operatorname{cosInt} \left( ");
-      } else if (node.Symbol is FresnelSineIntegral) {
+      } else if(node.Symbol is FresnelSineIntegral) {
         strBuilder.Append(@"\operatorname{fresnel}_\operatorname{sinInt} \left( ");
-      } else if (node.Symbol is Gamma) {
+      } else if(node.Symbol is Gamma) {
         strBuilder.Append(@"\Gamma \left( ");
-      } else if (node.Symbol is HyperbolicCosineIntegral) {
+      } else if(node.Symbol is HyperbolicCosineIntegral) {
         strBuilder.Append(@"\operatorname{hypCosInt} \left( ");
-      } else if (node.Symbol is HyperbolicSineIntegral) {
+      } else if(node.Symbol is HyperbolicSineIntegral) {
         strBuilder.Append(@"\operatorname{hypSinInt} \left( ");
-      } else if (node.Symbol is Norm) {
+      } else if(node.Symbol is Norm) {
         strBuilder.Append(@"\operatorname{norm} \left( ");
-      } else if (node.Symbol is Psi) {
+      } else if(node.Symbol is Psi) {
         strBuilder.Append(@"\operatorname{digamma} \left( ");
-      } else if (node.Symbol is SineIntegral) {
+      } else if(node.Symbol is SineIntegral) {
         strBuilder.Append(@"\operatorname{sinInt} \left( ");
-      } else if (node.Symbol is GreaterThan) {
+      } else if(node.Symbol is GreaterThan) {
         strBuilder.Append(@"  \left( ");
-      } else if (node.Symbol is LessThan) {
+      } else if(node.Symbol is LessThan) {
         strBuilder.Append(@"  \left( ");
-      } else if (node.Symbol is And) {
+      } else if(node.Symbol is And) {
         strBuilder.Append(@"  \left( \left( ");
-      } else if (node.Symbol is Or) {
+      } else if(node.Symbol is Or) {
         strBuilder.Append(@"   \left( \left( ");
-      } else if (node.Symbol is Not) {
+      } else if(node.Symbol is Not) {
         strBuilder.Append(@" \neg \left( ");
-      } else if (node.Symbol is IfThenElse) {
+      } else if(node.Symbol is IfThenElse) {
         strBuilder.Append(@" \operatorname{if}  \left( ");
-      } else if (node.Symbol is Constant) {
+      } else if(node.Symbol is Constant) {
         var constName = "c_{" + constIndex + "}";
         constIndex++;
         var constNode = node as ConstantTreeNode;
-        if (constNode.Value.IsAlmost(1.0)) {
+        if(constNode.Value.IsAlmost(1.0)) {
           strBuilder.Append("1 ");
         } else {
@@ -190,16 +190,16 @@
         }
 
-      } else if (node.Symbol is FactorVariable) {
+      } else if(node.Symbol is FactorVariable) {
         var factorNode = node as FactorVariableTreeNode;
         var constName = "c_{" + constIndex + "}";
         strBuilder.Append(constName + " ");
-        foreach (var e in factorNode.Symbol.GetVariableValues(factorNode.VariableName)
+        foreach(var e in factorNode.Symbol.GetVariableValues(factorNode.VariableName)
           .Zip(factorNode.Weights, Tuple.Create)) {
           constants.Add(new KeyValuePair<string, double>("c_{" + constIndex + ", " + EscapeLatexString(factorNode.VariableName) + "=" + EscapeLatexString(e.Item1) + "}", e.Item2));
         }
         constIndex++;
-      } else if (node.Symbol is BinaryFactorVariable) {
+      } else if(node.Symbol is BinaryFactorVariable) {
         var binFactorNode = node as BinaryFactorVariableTreeNode;
-        if (!binFactorNode.Weight.IsAlmost((1.0))) {
+        if(!binFactorNode.Weight.IsAlmost((1.0))) {
           var constName = "c_{" + constIndex + "}";
           strBuilder.Append(constName + "  \\cdot");
@@ -207,10 +207,10 @@
           constIndex++;
         }
-        strBuilder.Append(EscapeLatexString(binFactorNode.VariableName));
+        strBuilder.Append("(" + EscapeLatexString(binFactorNode.VariableName));
         strBuilder.Append(LagToString(currentLag));
-        strBuilder.Append(" = " + EscapeLatexString(binFactorNode.VariableValue));
-      } else if (node.Symbol is LaggedVariable) {
+        strBuilder.Append(" = " + EscapeLatexString(binFactorNode.VariableValue) + " )");
+      } else if(node.Symbol is LaggedVariable) {
         var laggedVarNode = node as LaggedVariableTreeNode;
-        if (!laggedVarNode.Weight.IsAlmost(1.0)) {
+        if(!laggedVarNode.Weight.IsAlmost(1.0)) {
           var constName = "c_{" + constIndex + "}";
           strBuilder.Append(constName + "  \\cdot");
@@ -221,7 +221,7 @@
         strBuilder.Append(LagToString(currentLag + laggedVarNode.Lag));
 
-      } else if (node.Symbol is Variable) {
+      } else if(node.Symbol is Variable) {
         var varNode = node as VariableTreeNode;
-        if (!varNode.Weight.IsAlmost((1.0))) {
+        if(!varNode.Weight.IsAlmost((1.0))) {
           var constName = "c_{" + constIndex + "}";
           strBuilder.Append(constName + "  \\cdot");
@@ -231,33 +231,33 @@
         strBuilder.Append(EscapeLatexString(varNode.VariableName));
         strBuilder.Append(LagToString(currentLag));
-      } else if (node.Symbol is ProgramRootSymbol) {
+      } else if(node.Symbol is ProgramRootSymbol) {
         strBuilder
           .AppendLine("\\begin{align*}")
           .AppendLine("\\nonumber");
-      } else if (node.Symbol is Defun) {
+      } else if(node.Symbol is Defun) {
         var defunNode = node as DefunTreeNode;
         strBuilder.Append(defunNode.FunctionName + " & = ");
-      } else if (node.Symbol is InvokeFunction) {
+      } else if(node.Symbol is InvokeFunction) {
         var invokeNode = node as InvokeFunctionTreeNode;
         strBuilder.Append(invokeNode.Symbol.FunctionName + @" \left( ");
-      } else if (node.Symbol is StartSymbol) {
+      } else if(node.Symbol is StartSymbol) {
         FormatStartSymbol(strBuilder);
-      } else if (node.Symbol is Argument) {
+      } else if(node.Symbol is Argument) {
         var argSym = node.Symbol as Argument;
         strBuilder.Append(" ARG+" + argSym.ArgumentIndex + " ");
-      } else if (node.Symbol is Derivative) {
+      } else if(node.Symbol is Derivative) {
         strBuilder.Append(@" \cfrac{d \left( ");
-      } else if (node.Symbol is TimeLag) {
+      } else if(node.Symbol is TimeLag) {
         var laggedNode = node as ILaggedTreeNode;
         currentLag += laggedNode.Lag;
-      } else if (node.Symbol is Power) {
+      } else if(node.Symbol is Power) {
         strBuilder.Append(@" \left( ");
-      } else if (node.Symbol is Root) {
+      } else if(node.Symbol is Root) {
         strBuilder.Append(@" \left( ");
-      } else if (node.Symbol is Integral) {
+      } else if(node.Symbol is Integral) {
         // actually a new variable for t is needed in all subtrees (TODO)
         var laggedTreeNode = node as ILaggedTreeNode;
         strBuilder.Append(@"\sum_{t=" + (laggedTreeNode.Lag + currentLag) + @"}^0 \left( ");
-      } else if (node.Symbol is VariableCondition) {
+      } else if(node.Symbol is VariableCondition) {
         var conditionTreeNode = node as VariableConditionTreeNode;
         var constName = "c_{" + constants.Count + "}";
@@ -276,86 +276,86 @@
 
     private void FormatSep(ISymbolicExpressionTreeNode node, StringBuilder strBuilder, int step) {
-      if (node.Symbol is Addition) {
+      if(node.Symbol is Addition) {
         strBuilder.Append(" + ");
-      } else if (node.Symbol is Subtraction) {
+      } else if(node.Symbol is Subtraction) {
         strBuilder.Append(" - ");
-      } else if (node.Symbol is Multiplication) {
+      } else if(node.Symbol is Multiplication) {
         strBuilder.Append(@" \cdot ");
-      } else if (node.Symbol is Division) {
-        if (step + 1 == node.SubtreeCount)
+      } else if(node.Symbol is Division) {
+        if(step + 1 == node.SubtreeCount)
           strBuilder.Append(@"}{");
         else
           strBuilder.Append(@" }{ \cfrac{ ");
-      } else if (node.Symbol is Average) {
+      } else if(node.Symbol is Average) {
         strBuilder.Append(@" + ");
-      } else if (node.Symbol is Logarithm) {
-        throw new InvalidOperationException();
-      } else if (node.Symbol is Exponential) {
-        throw new InvalidOperationException();
-      } else if (node.Symbol is Square) {
-        throw new InvalidOperationException();
-      } else if (node.Symbol is SquareRoot) {
-        throw new InvalidOperationException();
-      } else if (node.Symbol is Sine) {
-        throw new InvalidOperationException();
-      } else if (node.Symbol is Cosine) {
-        throw new InvalidOperationException();
-      } else if (node.Symbol is Tangent) {
-        throw new InvalidOperationException();
-      } else if (node.Symbol is AiryA) {
-        throw new InvalidOperationException();
-      } else if (node.Symbol is AiryB) {
-        throw new InvalidOperationException();
-      } else if (node.Symbol is Bessel) {
-        throw new InvalidOperationException();
-      } else if (node.Symbol is CosineIntegral) {
-        throw new InvalidOperationException();
-      } else if (node.Symbol is Dawson) {
-        throw new InvalidOperationException();
-      } else if (node.Symbol is Erf) {
-        throw new InvalidOperationException();
-      } else if (node.Symbol is ExponentialIntegralEi) {
-        throw new InvalidOperationException();
-      } else if (node.Symbol is FresnelCosineIntegral) {
-        throw new InvalidOperationException();
-      } else if (node.Symbol is FresnelSineIntegral) {
-        throw new InvalidOperationException();
-      } else if (node.Symbol is Gamma) {
-        throw new InvalidOperationException();
-      } else if (node.Symbol is HyperbolicCosineIntegral) {
-        throw new InvalidOperationException();
-      } else if (node.Symbol is HyperbolicSineIntegral) {
-        throw new InvalidOperationException();
-      } else if (node.Symbol is Norm) {
-        throw new InvalidOperationException();
-      } else if (node.Symbol is Psi) {
-        throw new InvalidOperationException();
-      } else if (node.Symbol is SineIntegral) {
-        throw new InvalidOperationException();
-      } else if (node.Symbol is GreaterThan) {
+      } else if(node.Symbol is Logarithm) {
+        throw new InvalidOperationException();
+      } else if(node.Symbol is Exponential) {
+        throw new InvalidOperationException();
+      } else if(node.Symbol is Square) {
+        throw new InvalidOperationException();
+      } else if(node.Symbol is SquareRoot) {
+        throw new InvalidOperationException();
+      } else if(node.Symbol is Sine) {
+        throw new InvalidOperationException();
+      } else if(node.Symbol is Cosine) {
+        throw new InvalidOperationException();
+      } else if(node.Symbol is Tangent) {
+        throw new InvalidOperationException();
+      } else if(node.Symbol is AiryA) {
+        throw new InvalidOperationException();
+      } else if(node.Symbol is AiryB) {
+        throw new InvalidOperationException();
+      } else if(node.Symbol is Bessel) {
+        throw new InvalidOperationException();
+      } else if(node.Symbol is CosineIntegral) {
+        throw new InvalidOperationException();
+      } else if(node.Symbol is Dawson) {
+        throw new InvalidOperationException();
+      } else if(node.Symbol is Erf) {
+        throw new InvalidOperationException();
+      } else if(node.Symbol is ExponentialIntegralEi) {
+        throw new InvalidOperationException();
+      } else if(node.Symbol is FresnelCosineIntegral) {
+        throw new InvalidOperationException();
+      } else if(node.Symbol is FresnelSineIntegral) {
+        throw new InvalidOperationException();
+      } else if(node.Symbol is Gamma) {
+        throw new InvalidOperationException();
+      } else if(node.Symbol is HyperbolicCosineIntegral) {
+        throw new InvalidOperationException();
+      } else if(node.Symbol is HyperbolicSineIntegral) {
+        throw new InvalidOperationException();
+      } else if(node.Symbol is Norm) {
+        throw new InvalidOperationException();
+      } else if(node.Symbol is Psi) {
+        throw new InvalidOperationException();
+      } else if(node.Symbol is SineIntegral) {
+        throw new InvalidOperationException();
+      } else if(node.Symbol is GreaterThan) {
         strBuilder.Append(@" > ");
-      } else if (node.Symbol is LessThan) {
+      } else if(node.Symbol is LessThan) {
         strBuilder.Append(@" < ");
-      } else if (node.Symbol is And) {
+      } else if(node.Symbol is And) {
         strBuilder.Append(@" > 0  \right) \land \left(");
-      } else if (node.Symbol is Or) {
+      } else if(node.Symbol is Or) {
         strBuilder.Append(@" > 0  \right) \lor \left(");
-      } else if (node.Symbol is Not) {
-        throw new InvalidOperationException();
-      } else if (node.Symbol is IfThenElse) {
+      } else if(node.Symbol is Not) {
+        throw new InvalidOperationException();
+      } else if(node.Symbol is IfThenElse) {
         strBuilder.Append(@" , ");
-      } else if (node.Symbol is ProgramRootSymbol) {
+      } else if(node.Symbol is ProgramRootSymbol) {
         strBuilder.Append(@"\\" + Environment.NewLine);
-      } else if (node.Symbol is Defun) {
-      } else if (node.Symbol is InvokeFunction) {
+      } else if(node.Symbol is Defun) {
+      } else if(node.Symbol is InvokeFunction) {
         strBuilder.Append(" , ");
-      } else if (node.Symbol is StartSymbol) {
+      } else if(node.Symbol is StartSymbol) {
         strBuilder.Append(@"\\" + Environment.NewLine);
         FormatStartSymbol(strBuilder);
-      } else if (node.Symbol is Power) {
+      } else if(node.Symbol is Power) {
         strBuilder.Append(@"\right) ^ { \operatorname{round} \left(");
-      } else if (node.Symbol is Root) {
+      } else if(node.Symbol is Root) {
         strBuilder.Append(@"\right) ^ {  \cfrac{1}{ \operatorname{round} \left(");
-      } else if (node.Symbol is VariableCondition) {
+      } else if(node.Symbol is VariableCondition) {
         var conditionTreeNode = node as VariableConditionTreeNode;
         var const1Name = "c_{" + constants.Count + "}";
@@ -374,77 +374,77 @@
 
     private void FormatEnd(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) {
-      if (node.Symbol is Addition) {
-        strBuilder.Append(@" \right) ");
-      } else if (node.Symbol is Subtraction) {
-        strBuilder.Append(@" \right) ");
-      } else if (node.Symbol is Multiplication) {
-      } else if (node.Symbol is Division) {
+      if(node.Symbol is Addition) {
+        strBuilder.Append(@" \right) ");
+      } else if(node.Symbol is Subtraction) {
+        strBuilder.Append(@" \right) ");
+      } else if(node.Symbol is Multiplication) {
+      } else if(node.Symbol is Division) {
         strBuilder.Append(" } ");
-        for (int i = 2; i < node.SubtreeCount; i++)
+        for(int i = 2; i < node.SubtreeCount; i++)
           strBuilder.Append(" } ");
-      } else if (node.Symbol is Average) {
-        strBuilder.Append(@" \right) ");
-      } else if (node.Symbol is Logarithm) {
-        strBuilder.Append(@" \right) ");
-      } else if (node.Symbol is Exponential) {
-        strBuilder.Append(@" \right) ");
-      } else if (node.Symbol is Square) {
+      } else if(node.Symbol is Average) {
+        strBuilder.Append(@" \right) ");
+      } else if(node.Symbol is Logarithm) {
+        strBuilder.Append(@" \right) ");
+      } else if(node.Symbol is Exponential) {
+        strBuilder.Append(@" \right) ");
+      } else if(node.Symbol is Square) {
         strBuilder.Append(@"\right)^2");
-      } else if (node.Symbol is SquareRoot) {
+      } else if(node.Symbol is SquareRoot) {
         strBuilder.Append(@"}");
-      } else if (node.Symbol is Sine) {
-        strBuilder.Append(@" \right) ");
-      } else if (node.Symbol is Cosine) {
-        strBuilder.Append(@" \right) ");
-      } else if (node.Symbol is Tangent) {
-        strBuilder.Append(@" \right) ");
-      } else if (node.Symbol is AiryA) {
-        strBuilder.Append(@" \right) ");
-      } else if (node.Symbol is AiryB) {
-        strBuilder.Append(@" \right) ");
-      } else if (node.Symbol is Bessel) {
-        strBuilder.Append(@" \right) ");
-      } else if (node.Symbol is CosineIntegral) {
-        strBuilder.Append(@" \right) ");
-      } else if (node.Symbol is Dawson) {
-        strBuilder.Append(@" \right) ");
-      } else if (node.Symbol is Erf) {
-        strBuilder.Append(@" \right) ");
-      } else if (node.Symbol is ExponentialIntegralEi) {
-        strBuilder.Append(@" \right) ");
-      } else if (node.Symbol is FresnelCosineIntegral) {
-        strBuilder.Append(@" \right) ");
-      } else if (node.Symbol is FresnelSineIntegral) {
-        strBuilder.Append(@" \right) ");
-      } else if (node.Symbol is Gamma) {
-        strBuilder.Append(@" \right) ");
-      } else if (node.Symbol is HyperbolicCosineIntegral) {
-        strBuilder.Append(@" \right) ");
-      } else if (node.Symbol is HyperbolicSineIntegral) {
-        strBuilder.Append(@" \right) ");
-      } else if (node.Symbol is Norm) {
-        strBuilder.Append(@" \right) ");
-      } else if (node.Symbol is Psi) {
-        strBuilder.Append(@" \right) ");
-      } else if (node.Symbol is SineIntegral) {
-        strBuilder.Append(@" \right) ");
-      } else if (node.Symbol is GreaterThan) {
-        strBuilder.Append(@" \right) ");
-      } else if (node.Symbol is LessThan) {
-        strBuilder.Append(@" \right) ");
-      } else if (node.Symbol is And) {
+      } else if(node.Symbol is Sine) {
+        strBuilder.Append(@" \right) ");
+      } else if(node.Symbol is Cosine) {
+        strBuilder.Append(@" \right) ");
+      } else if(node.Symbol is Tangent) {
+        strBuilder.Append(@" \right) ");
+      } else if(node.Symbol is AiryA) {
+        strBuilder.Append(@" \right) ");
+      } else if(node.Symbol is AiryB) {
+        strBuilder.Append(@" \right) ");
+      } else if(node.Symbol is Bessel) {
+        strBuilder.Append(@" \right) ");
+      } else if(node.Symbol is CosineIntegral) {
+        strBuilder.Append(@" \right) ");
+      } else if(node.Symbol is Dawson) {
+        strBuilder.Append(@" \right) ");
+      } else if(node.Symbol is Erf) {
+        strBuilder.Append(@" \right) ");
+      } else if(node.Symbol is ExponentialIntegralEi) {
+        strBuilder.Append(@" \right) ");
+      } else if(node.Symbol is FresnelCosineIntegral) {
+        strBuilder.Append(@" \right) ");
+      } else if(node.Symbol is FresnelSineIntegral) {
+        strBuilder.Append(@" \right) ");
+      } else if(node.Symbol is Gamma) {
+        strBuilder.Append(@" \right) ");
+      } else if(node.Symbol is HyperbolicCosineIntegral) {
+        strBuilder.Append(@" \right) ");
+      } else if(node.Symbol is HyperbolicSineIntegral) {
+        strBuilder.Append(@" \right) ");
+      } else if(node.Symbol is Norm) {
+        strBuilder.Append(@" \right) ");
+      } else if(node.Symbol is Psi) {
+        strBuilder.Append(@" \right) ");
+      } else if(node.Symbol is SineIntegral) {
+        strBuilder.Append(@" \right) ");
+      } else if(node.Symbol is GreaterThan) {
+        strBuilder.Append(@" \right) ");
+      } else if(node.Symbol is LessThan) {
+        strBuilder.Append(@" \right) ");
+      } else if(node.Symbol is And) {
         strBuilder.Append(@" > 0 \right) \right) ");
-      } else if (node.Symbol is Or) {
+      } else if(node.Symbol is Or) {
         strBuilder.Append(@" > 0 \right) \right) ");
-      } else if (node.Symbol is Not) {
-        strBuilder.Append(@" \right) ");
-      } else if (node.Symbol is IfThenElse) {
-        strBuilder.Append(@" \right) ");
-      } else if (node.Symbol is Constant) {
-      } else if (node.Symbol is LaggedVariable) {
-      } else if (node.Symbol is Variable) {
-      } else if (node.Symbol is FactorVariable) {
-      } else if (node.Symbol is BinaryFactorVariable) {
-      } else if (node.Symbol is ProgramRootSymbol) {
+      } else if(node.Symbol is Not) {
+        strBuilder.Append(@" \right) ");
+      } else if(node.Symbol is IfThenElse) {
+        strBuilder.Append(@" \right) ");
+      } else if(node.Symbol is Constant) {
+      } else if(node.Symbol is LaggedVariable) {
+      } else if(node.Symbol is Variable) {
+      } else if(node.Symbol is FactorVariable) {
+      } else if(node.Symbol is BinaryFactorVariable) {
+      } else if(node.Symbol is ProgramRootSymbol) {
         strBuilder
           .AppendLine("\\end{align*}")
@@ -452,9 +452,9 @@
           .AppendLine("\\nonumber");
         // output all constant values
-        if (constants.Count > 0) {
-          foreach (var constant in constants) {
+        if(constants.Count > 0) {
+          foreach(var constant in constants) {
             // replace "." with ".&" to align decimal points
             var constStr = string.Format(System.Globalization.NumberFormatInfo.InvariantInfo, "{0:G5}", constant.Value);
-            if (!constStr.Contains(".")) constStr = constStr + ".0";
+            if(!constStr.Contains(".")) constStr = constStr + ".0";
             constStr = constStr.Replace(".", "&.");  // fix problem in rendering of aligned expressions
             strBuilder.Append(constant.Key + "& = & " + constStr);
@@ -463,21 +463,21 @@
         }
         strBuilder.AppendLine("\\end{align*}");
-      } else if (node.Symbol is Defun) {
-      } else if (node.Symbol is InvokeFunction) {
-        strBuilder.Append(@" \right) ");
-      } else if (node.Symbol is StartSymbol) {
-      } else if (node.Symbol is Argument) {
-      } else if (node.Symbol is Derivative) {
+      } else if(node.Symbol is Defun) {
+      } else if(node.Symbol is InvokeFunction) {
+        strBuilder.Append(@" \right) ");
+      } else if(node.Symbol is StartSymbol) {
+      } else if(node.Symbol is Argument) {
+      } else if(node.Symbol is Derivative) {
         strBuilder.Append(@" \right) }{dt} ");
-      } else if (node.Symbol is TimeLag) {
+      } else if(node.Symbol is TimeLag) {
         var laggedNode = node as ILaggedTreeNode;
         currentLag -= laggedNode.Lag;
-      } else if (node.Symbol is Power) {
+      } else if(node.Symbol is Power) {
         strBuilder.Append(@" \right) } ");
-      } else if (node.Symbol is Root) {
+      } else if(node.Symbol is Root) {
         strBuilder.Append(@" \right) } } ");
-      } else if (node.Symbol is Integral) {
-        strBuilder.Append(@" \right) ");
-      } else if (node.Symbol is VariableCondition) {
+      } else if(node.Symbol is Integral) {
+        strBuilder.Append(@" \right) ");
+      } else if(node.Symbol is VariableCondition) {
         strBuilder.Append(@"\right) ");
       } else {
@@ -488,5 +488,5 @@
     private void FormatStartSymbol(StringBuilder strBuilder) {
       strBuilder.Append(targetVariable ?? "target_" + (targetCount++));
-      if (containsTimeSeriesSymbol)
+      if(containsTimeSeriesSymbol)
         strBuilder.Append("(t)");
       strBuilder.Append(" & = ");
@@ -494,7 +494,7 @@
 
     private string LagToString(int lag) {
-      if (lag < 0) {
+      if(lag < 0) {
         return "(t" + lag + ")";
-      } else if (lag > 0) {
+      } else if(lag > 0) {
         return "(t+" + lag + ")";
       } else return "";
Index: /branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionMATLABFormatter.cs
===================================================================
--- /branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionMATLABFormatter.cs	(revision 14763)
+++ /branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionMATLABFormatter.cs	(revision 14764)
@@ -21,4 +21,5 @@
 
 using System.Globalization;
+using System.Linq;
 using System.Text;
 using HeuristicLab.Common;
@@ -77,4 +78,27 @@
       stringBuilder.AppendLine("  y = (f0 + 2*f1 - 2*f3 - f4) / 8;");
       stringBuilder.AppendLine("end");
+
+      var factorVariableNames =
+        symbolicExpressionTree.IterateNodesPostfix()
+          .OfType<FactorVariableTreeNode>()
+          .Select(n => n.VariableName)
+          .Distinct();
+
+      foreach(var factorVarName in factorVariableNames)
+      {
+        var factorSymb = symbolicExpressionTree.IterateNodesPostfix()
+          .OfType<FactorVariableTreeNode>()
+          .First(n => n.VariableName == factorVarName)
+          .Symbol;
+        stringBuilder.AppendFormat("function y = switch_{0}(val, v)", factorVarName).AppendLine();
+        var values = factorSymb.GetVariableValues(factorVarName).ToArray();
+        stringBuilder.AppendLine("switch val");
+        for(int i = 0; i < values.Length; i++) {
+          stringBuilder.AppendFormat(CultureInfo.InvariantCulture, "  case \"{0}\" y = v({1})", values[i], i).AppendLine();
+        }
+        stringBuilder.AppendLine("end");
+        stringBuilder.AppendLine();
+      }
+
       return stringBuilder.ToString();
     }
@@ -92,19 +116,19 @@
       StringBuilder stringBuilder = new StringBuilder();
 
-      if (symbol is ProgramRootSymbol) {
+      if(symbol is ProgramRootSymbol) {
         stringBuilder.AppendLine(FormatRecursively(node.GetSubtree(0)));
-      } else if (symbol is StartSymbol)
+      } else if(symbol is StartSymbol)
         return FormatRecursively(node.GetSubtree(0));
-      else if (symbol is Addition) {
-        stringBuilder.Append("(");
-        for (int i = 0; i < node.SubtreeCount; i++) {
-          if (i > 0) stringBuilder.Append("+");
-          stringBuilder.Append(FormatRecursively(node.GetSubtree(i)));
-        }
-        stringBuilder.Append(")");
-      } else if (symbol is And) {
+      else if(symbol is Addition) {
+        stringBuilder.Append("(");
+        for(int i = 0; i < node.SubtreeCount; i++) {
+          if(i > 0) stringBuilder.Append("+");
+          stringBuilder.Append(FormatRecursively(node.GetSubtree(i)));
+        }
+        stringBuilder.Append(")");
+      } else if(symbol is And) {
         stringBuilder.Append("((");
-        for (int i = 0; i < node.SubtreeCount; i++) {
-          if (i > 0) stringBuilder.Append("&");
+        for(int i = 0; i < node.SubtreeCount; i++) {
+          if(i > 0) stringBuilder.Append("&");
           stringBuilder.Append("((");
           stringBuilder.Append(FormatRecursively(node.GetSubtree(i)));
@@ -113,10 +137,10 @@
         stringBuilder.Append(")-0.5)*2");
         // MATLAB maps false and true to 0 and 1, resp., we map this result to -1.0 and +1.0, resp.
-      } else if (symbol is Average) {
+      } else if(symbol is Average) {
         stringBuilder.Append("(1/");
         stringBuilder.Append(node.SubtreeCount);
         stringBuilder.Append(")*(");
-        for (int i = 0; i < node.SubtreeCount; i++) {
-          if (i > 0) stringBuilder.Append("+");
+        for(int i = 0; i < node.SubtreeCount; i++) {
+          if(i > 0) stringBuilder.Append("+");
           stringBuilder.Append("(");
           stringBuilder.Append(FormatRecursively(node.GetSubtree(i)));
@@ -124,13 +148,13 @@
         }
         stringBuilder.Append(")");
-      } else if (symbol is Constant) {
+      } else if(symbol is Constant) {
         ConstantTreeNode constantTreeNode = node as ConstantTreeNode;
         stringBuilder.Append(constantTreeNode.Value.ToString(CultureInfo.InvariantCulture));
-      } else if (symbol is Cosine) {
+      } else if(symbol is Cosine) {
         stringBuilder.Append("cos(");
         stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
         stringBuilder.Append(")");
-      } else if (symbol is Division) {
-        if (node.SubtreeCount == 1) {
+      } else if(symbol is Division) {
+        if(node.SubtreeCount == 1) {
           stringBuilder.Append("1/");
           stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
@@ -138,23 +162,23 @@
           stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
           stringBuilder.Append("/(");
-          for (int i = 1; i < node.SubtreeCount; i++) {
-            if (i > 1) stringBuilder.Append("*");
+          for(int i = 1; i < node.SubtreeCount; i++) {
+            if(i > 1) stringBuilder.Append("*");
             stringBuilder.Append(FormatRecursively(node.GetSubtree(i)));
           }
           stringBuilder.Append(")");
         }
-      } else if (symbol is Exponential) {
+      } else if(symbol is Exponential) {
         stringBuilder.Append("exp(");
         stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
         stringBuilder.Append(")");
-      } else if (symbol is Square) {
+      } else if(symbol is Square) {
         stringBuilder.Append("(");
         stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
         stringBuilder.Append(").^2");
-      } else if (symbol is SquareRoot) {
+      } else if(symbol is SquareRoot) {
         stringBuilder.Append("sqrt(");
         stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
         stringBuilder.Append(")");
-      } else if (symbol is GreaterThan) {
+      } else if(symbol is GreaterThan) {
         stringBuilder.Append("((");
         stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
@@ -163,5 +187,5 @@
         stringBuilder.Append(")-0.5)*2");
         // MATLAB maps false and true to 0 and 1, resp., we map this result to -1.0 and +1.0, resp.
-      } else if (symbol is IfThenElse) {
+      } else if(symbol is IfThenElse) {
         stringBuilder.Append("(");
         stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
@@ -173,5 +197,5 @@
         stringBuilder.Append("<=0)*");
         stringBuilder.Append(FormatRecursively(node.GetSubtree(2)));
-      } else if (symbol is LaggedVariable) {
+      } else if(symbol is LaggedVariable) {
         // this if must be checked before if(symbol is LaggedVariable)
         LaggedVariableTreeNode laggedVariableTreeNode = node as LaggedVariableTreeNode;
@@ -180,5 +204,5 @@
         stringBuilder.Append(laggedVariableTreeNode.VariableName +
                              LagToString(currentLag + laggedVariableTreeNode.Lag));
-      } else if (symbol is LessThan) {
+      } else if(symbol is LessThan) {
         stringBuilder.Append("((");
         stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
@@ -187,21 +211,21 @@
         stringBuilder.Append(")-0.5)*2");
         // MATLAB maps false and true to 0 and 1, resp., we map this result to -1.0 and +1.0, resp.
-      } else if (symbol is Logarithm) {
+      } else if(symbol is Logarithm) {
         stringBuilder.Append("log_(");
         stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
         stringBuilder.Append(")");
-      } else if (symbol is Multiplication) {
-        for (int i = 0; i < node.SubtreeCount; i++) {
-          if (i > 0) stringBuilder.Append("*");
-          stringBuilder.Append(FormatRecursively(node.GetSubtree(i)));
-        }
-      } else if (symbol is Not) {
+      } else if(symbol is Multiplication) {
+        for(int i = 0; i < node.SubtreeCount; i++) {
+          if(i > 0) stringBuilder.Append("*");
+          stringBuilder.Append(FormatRecursively(node.GetSubtree(i)));
+        }
+      } else if(symbol is Not) {
         stringBuilder.Append("~(");
         stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
         stringBuilder.Append(" > 0 )");
-      } else if (symbol is Or) {
+      } else if(symbol is Or) {
         stringBuilder.Append("((");
-        for (int i = 0; i < node.SubtreeCount; i++) {
-          if (i > 0) stringBuilder.Append("|");
+        for(int i = 0; i < node.SubtreeCount; i++) {
+          if(i > 0) stringBuilder.Append("|");
           stringBuilder.Append("((");
           stringBuilder.Append(FormatRecursively(node.GetSubtree(i)));
@@ -210,16 +234,16 @@
         stringBuilder.Append(")-0.5)*2");
         // MATLAB maps false and true to 0 and 1, resp., we map this result to -1.0 and +1.0, resp.
-      } else if (symbol is Sine) {
+      } else if(symbol is Sine) {
         stringBuilder.Append("sin(");
         stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
         stringBuilder.Append(")");
-      } else if (symbol is Subtraction) {
-        stringBuilder.Append("(");
-        if (node.SubtreeCount == 1) {
+      } else if(symbol is Subtraction) {
+        stringBuilder.Append("(");
+        if(node.SubtreeCount == 1) {
           stringBuilder.Append("-");
           stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
         } else {
           stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
-          for (int i = 1; i < node.SubtreeCount; i++) {
+          for(int i = 1; i < node.SubtreeCount; i++) {
             stringBuilder.Append("-");
             stringBuilder.Append(FormatRecursively(node.GetSubtree(i)));
@@ -227,74 +251,84 @@
         }
         stringBuilder.Append(")");
-      } else if (symbol is Tangent) {
+      } else if(symbol is Tangent) {
         stringBuilder.Append("tan(");
         stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
         stringBuilder.Append(")");
-      } else if (node.Symbol is AiryA) {
+      } else if(node.Symbol is AiryA) {
         stringBuilder.Append("airy(");
         stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
         stringBuilder.Append(")");
-      } else if (node.Symbol is AiryB) {
+      } else if(node.Symbol is AiryB) {
         stringBuilder.Append("airy(2, ");
         stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
         stringBuilder.Append(")");
-      } else if (node.Symbol is Bessel) {
+      } else if(node.Symbol is Bessel) {
         stringBuilder.Append("besseli(0.0,");
         stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
         stringBuilder.Append(")");
-      } else if (node.Symbol is CosineIntegral) {
+      } else if(node.Symbol is CosineIntegral) {
         stringBuilder.Append("cosint(");
         stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
         stringBuilder.Append(")");
-      } else if (node.Symbol is Dawson) {
+      } else if(node.Symbol is Dawson) {
         stringBuilder.Append("dawson(");
         stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
         stringBuilder.Append(")");
-      } else if (node.Symbol is Erf) {
+      } else if(node.Symbol is Erf) {
         stringBuilder.Append("erf(");
         stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
         stringBuilder.Append(")");
-      } else if (node.Symbol is ExponentialIntegralEi) {
+      } else if(node.Symbol is ExponentialIntegralEi) {
         stringBuilder.Append("expint(");
         stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
         stringBuilder.Append(")");
-      } else if (node.Symbol is FresnelCosineIntegral) {
+      } else if(node.Symbol is FresnelCosineIntegral) {
         stringBuilder.Append("FresnelC(");
         stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
         stringBuilder.Append(")");
-      } else if (node.Symbol is FresnelSineIntegral) {
+      } else if(node.Symbol is FresnelSineIntegral) {
         stringBuilder.Append("FresnelS(");
         stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
         stringBuilder.Append(")");
-      } else if (node.Symbol is Gamma) {
+      } else if(node.Symbol is Gamma) {
         stringBuilder.Append("gamma(");
         stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
         stringBuilder.Append(")");
-      } else if (node.Symbol is HyperbolicCosineIntegral) {
+      } else if(node.Symbol is HyperbolicCosineIntegral) {
         stringBuilder.Append("Chi(");
         stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
         stringBuilder.Append(")");
-      } else if (node.Symbol is HyperbolicSineIntegral) {
+      } else if(node.Symbol is HyperbolicSineIntegral) {
         stringBuilder.Append("Shi(");
         stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
         stringBuilder.Append(")");
-      } else if (node.Symbol is Norm) {
+      } else if(node.Symbol is Norm) {
         stringBuilder.Append("normpdf(");
         stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
         stringBuilder.Append(")");
-      } else if (node.Symbol is Psi) {
+      } else if(node.Symbol is Psi) {
         stringBuilder.Append("psi(");
         stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
         stringBuilder.Append(")");
-      } else if (node.Symbol is SineIntegral) {
+      } else if(node.Symbol is SineIntegral) {
         stringBuilder.Append("sinint(");
         stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
         stringBuilder.Append(")");
-      } else if (symbol is HeuristicLab.Problems.DataAnalysis.Symbolic.Variable) {
+      } else if(symbol is HeuristicLab.Problems.DataAnalysis.Symbolic.Variable) {
         VariableTreeNode variableTreeNode = node as VariableTreeNode;
         stringBuilder.Append(variableTreeNode.Weight.ToString(CultureInfo.InvariantCulture));
         stringBuilder.Append("*");
         stringBuilder.Append(variableTreeNode.VariableName + LagToString(currentLag));
-      } else if (symbol is Power) {
+      } else if(symbol is HeuristicLab.Problems.DataAnalysis.Symbolic.FactorVariable) {
+        var factorNode = node as FactorVariableTreeNode;
+        var weights = string.Join(" ", factorNode.Weights.Select(w => w.ToString("G17", CultureInfo.InvariantCulture)));
+        stringBuilder.AppendFormat("switch_{0}(\"{1}\",[{2}])",
+          factorNode.VariableName, factorNode.VariableName, weights)
+          .AppendLine();
+      } else if(symbol is HeuristicLab.Problems.DataAnalysis.Symbolic.BinaryFactorVariable) {
+        var factorNode = node as BinaryFactorVariableTreeNode;
+        stringBuilder.AppendFormat(CultureInfo.InvariantCulture,
+          "((strcmp({0},\"{1}\")==1) * {2:G17})", factorNode.VariableName, factorNode.VariableValue, factorNode.Weight);
+      } else if(symbol is Power) {
         stringBuilder.Append("(");
         stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
@@ -302,5 +336,5 @@
         stringBuilder.Append(FormatRecursively(node.GetSubtree(1)));
         stringBuilder.Append(")");
-      } else if (symbol is Root) {
+      } else if(symbol is Root) {
         stringBuilder.Append("(");
         stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
@@ -308,5 +342,5 @@
         stringBuilder.Append(FormatRecursively(node.GetSubtree(1)));
         stringBuilder.Append("))");
-      } else if (symbol is Derivative) {
+      } else if(symbol is Derivative) {
         stringBuilder.Append("fivePoint(");
         // f0
@@ -326,5 +360,5 @@
         stringBuilder.Append(")");
         currentLag += 4;
-      } else if (symbol is Integral) {
+      } else if(symbol is Integral) {
         var laggedNode = node as LaggedTreeNode;
         string prevCounterVariable = CurrentIndexVariable;
@@ -334,5 +368,5 @@
                                  "))");
         ReleaseIndexVariable();
-      } else if (symbol is TimeLag) {
+      } else if(symbol is TimeLag) {
         var laggedNode = node as LaggedTreeNode;
         currentLag += laggedNode.Lag;
@@ -347,7 +381,7 @@
 
     private string LagToString(int lag) {
-      if (lag < 0) {
+      if(lag < 0) {
         return "(" + CurrentIndexVariable + "" + lag + ")";
-      } else if (lag > 0) {
+      } else if(lag > 0) {
         return "(" + CurrentIndexVariable + "+" + lag + ")";
       } else return "(" + CurrentIndexVariable + ")";
Index: /branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionMathematicaFormatter.cs
===================================================================
--- /branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionMathematicaFormatter.cs	(revision 14763)
+++ /branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionMathematicaFormatter.cs	(revision 14764)
@@ -53,28 +53,28 @@
 
     private void FormatRecursively(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) {
-      if (node.Subtrees.Any()) {
-        if (node.Symbol is Addition) {
+      if(node.Subtrees.Any()) {
+        if(node.Symbol is Addition) {
           FormatFunction(node, "Plus", strBuilder);
-        } else if (node.Symbol is Average) {
+        } else if(node.Symbol is Average) {
           FormatAverage(node, strBuilder);
-        } else if (node.Symbol is Multiplication) {
+        } else if(node.Symbol is Multiplication) {
           FormatFunction(node, "Times", strBuilder);
-        } else if (node.Symbol is Subtraction) {
+        } else if(node.Symbol is Subtraction) {
           FormatSubtraction(node, strBuilder);
-        } else if (node.Symbol is Division) {
+        } else if(node.Symbol is Division) {
           FormatDivision(node, strBuilder);
-        } else if (node.Symbol is Sine) {
+        } else if(node.Symbol is Sine) {
           FormatFunction(node, "Sin", strBuilder);
-        } else if (node.Symbol is Cosine) {
+        } else if(node.Symbol is Cosine) {
           FormatFunction(node, "Cos", strBuilder);
-        } else if (node.Symbol is Tangent) {
+        } else if(node.Symbol is Tangent) {
           FormatFunction(node, "Tan", strBuilder);
-        } else if (node.Symbol is Exponential) {
+        } else if(node.Symbol is Exponential) {
           FormatFunction(node, "Exp", strBuilder);
-        } else if (node.Symbol is Logarithm) {
+        } else if(node.Symbol is Logarithm) {
           FormatFunction(node, "Log", strBuilder);
-        } else if (node.Symbol is IfThenElse) {
+        } else if(node.Symbol is IfThenElse) {
           FormatIf(node, strBuilder);
-        } else if (node.Symbol is GreaterThan) {
+        } else if(node.Symbol is GreaterThan) {
           strBuilder.Append("If[Greater[");
           FormatRecursively(node.GetSubtree(0), strBuilder);
@@ -82,5 +82,5 @@
           FormatRecursively(node.GetSubtree(1), strBuilder);
           strBuilder.Append("], 1, -1]");
-        } else if (node.Symbol is LessThan) {
+        } else if(node.Symbol is LessThan) {
           strBuilder.Append("If[Less[");
           FormatRecursively(node.GetSubtree(0), strBuilder);
@@ -88,21 +88,21 @@
           FormatRecursively(node.GetSubtree(1), strBuilder);
           strBuilder.Append("], 1, -1]");
-        } else if (node.Symbol is And) {
+        } else if(node.Symbol is And) {
           FormatAnd(node, strBuilder);
-        } else if (node.Symbol is Not) {
+        } else if(node.Symbol is Not) {
           strBuilder.Append("If[Greater[");
           FormatRecursively(node.GetSubtree(0), strBuilder);
           strBuilder.Append(", 0], -1, 1]");
-        } else if (node.Symbol is Or) {
+        } else if(node.Symbol is Or) {
           FormatOr(node, strBuilder);
-        } else if (node.Symbol is Xor) {
+        } else if(node.Symbol is Xor) {
           FormatXor(node, strBuilder);
-        } else if (node.Symbol is Square) {
+        } else if(node.Symbol is Square) {
           FormatSquare(node, strBuilder);
-        } else if (node.Symbol is SquareRoot) {
+        } else if(node.Symbol is SquareRoot) {
           FormatFunction(node, "Sqrt", strBuilder);
-        } else if (node.Symbol is Power) {
+        } else if(node.Symbol is Power) {
           FormatFunction(node, "Power", strBuilder);
-        } else if (node.Symbol is Root) {
+        } else if(node.Symbol is Root) {
           FormatRoot(node, strBuilder);
         } else {
@@ -110,10 +110,25 @@
         }
       } else {
-        if (node is VariableTreeNode) {
+        // terminals
+        if(node.Symbol is Variable) {
           var varNode = node as VariableTreeNode;
           strBuilder.AppendFormat("Times[{0}, {1}]", varNode.VariableName, varNode.Weight.ToString("G17", CultureInfo.InvariantCulture));
-        } else if (node is ConstantTreeNode) {
+        } else if(node.Symbol is Constant) {
           var constNode = node as ConstantTreeNode;
           strBuilder.Append(constNode.Value.ToString("G17", CultureInfo.InvariantCulture));
+        } else if(node.Symbol is FactorVariable) {
+          var factorNode = node as FactorVariableTreeNode;
+          strBuilder.AppendFormat("Switch[{0},", factorNode.VariableName);
+          var varValues = factorNode.Symbol.GetVariableValues(factorNode.VariableName).ToArray();
+          var weights = varValues.Select(factorNode.GetValue).ToArray();
+
+          var weightStr = string.Join(", ",
+            varValues.Zip(weights, (s, d) => string.Format(CultureInfo.InvariantCulture, "\"{0}\", {1:G17}", s, d)));
+          strBuilder.Append(weightStr);
+          strBuilder.Append("]");
+        } else if(node.Symbol is BinaryFactorVariable) {
+          var factorNode = node as BinaryFactorVariableTreeNode;
+          strBuilder.AppendFormat(CultureInfo.InvariantCulture, "If[{0}==\"{1}\",{2:G17},0.0]", 
+            factorNode.VariableName, factorNode.VariableValue, factorNode.Weight);
         } else {
           throw new NotSupportedException("Formatting of symbol: " + node.Symbol + " is not supported.");
@@ -124,9 +139,9 @@
     private void FormatXor(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) {
       strBuilder.Append("If[Xor[");
-      foreach (var t in node.Subtrees) {
+      foreach(var t in node.Subtrees) {
         strBuilder.Append("Greater[");
         FormatRecursively(t, strBuilder);
         strBuilder.Append(", 0]");
-        if (t != node.Subtrees.Last()) strBuilder.Append(",");
+        if(t != node.Subtrees.Last()) strBuilder.Append(",");
       }
       strBuilder.Append("], 1, -1]");
@@ -135,9 +150,9 @@
     private void FormatOr(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) {
       strBuilder.Append("If[Or[");
-      foreach (var t in node.Subtrees) {
+      foreach(var t in node.Subtrees) {
         strBuilder.Append("Greater[");
         FormatRecursively(t, strBuilder);
         strBuilder.Append(", 0]");
-        if (t != node.Subtrees.Last()) strBuilder.Append(",");
+        if(t != node.Subtrees.Last()) strBuilder.Append(",");
       }
       strBuilder.Append("], 1, -1]");
@@ -146,9 +161,9 @@
     private void FormatAnd(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) {
       strBuilder.Append("If[And[");
-      foreach (var t in node.Subtrees) {
+      foreach(var t in node.Subtrees) {
         strBuilder.Append("Greater[");
         FormatRecursively(t, strBuilder);
         strBuilder.Append(", 0]");
-        if (t != node.Subtrees.Last()) strBuilder.Append(",");
+        if(t != node.Subtrees.Last()) strBuilder.Append(",");
       }
       strBuilder.Append("], 1, -1]");
@@ -169,5 +184,5 @@
       strBuilder.Append("Mean[{");
       FormatRecursively(node.GetSubtree(0), strBuilder);
-      for (int i = 1; i < node.SubtreeCount; i++) {
+      for(int i = 1; i < node.SubtreeCount; i++) {
         strBuilder.Append(",");
         FormatRecursively(node.GetSubtree(i), strBuilder);
@@ -180,5 +195,5 @@
       FormatRecursively(node.GetSubtree(0), strBuilder);
       strBuilder.Append(", Times[-1");
-      foreach (var t in node.Subtrees) {
+      foreach(var t in node.Subtrees) {
         strBuilder.Append(",");
         FormatRecursively(t, strBuilder);
@@ -202,5 +217,5 @@
 
     private void FormatDivision(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) {
-      if (node.SubtreeCount == 1) {
+      if(node.SubtreeCount == 1) {
         strBuilder.Append("Divide[1, ");
         FormatRecursively(node.GetSubtree(0), strBuilder);
@@ -211,5 +226,5 @@
         strBuilder.Append(", Times[");
         FormatRecursively(node.GetSubtree(1), strBuilder);
-        for (int i = 2; i < node.SubtreeCount; i++) {
+        for(int i = 2; i < node.SubtreeCount; i++) {
           strBuilder.Append(",");
           FormatRecursively(node.GetSubtree(i), strBuilder);
@@ -221,7 +236,7 @@
     private void FormatFunction(ISymbolicExpressionTreeNode node, string function, StringBuilder strBuilder) {
       strBuilder.Append(function + "[");
-      foreach (var child in node.Subtrees) {
+      foreach(var child in node.Subtrees) {
         FormatRecursively(child, strBuilder);
-        if (child != node.Subtrees.Last())
+        if(child != node.Subtrees.Last())
           strBuilder.Append(", ");
       }
Index: /branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionSmalltalkFormatter.cs
===================================================================
--- /branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionSmalltalkFormatter.cs	(revision 14763)
+++ /branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionSmalltalkFormatter.cs	(revision 14764)
@@ -48,5 +48,5 @@
       ISymbol symbol = node.Symbol;
 
-      if (symbol is ProgramRootSymbol || symbol is StartSymbol)
+      if(symbol is ProgramRootSymbol || symbol is StartSymbol)
         return FormatRecursively(node.GetSubtree(0));
 
@@ -55,13 +55,13 @@
       stringBuilder.Append("(");
 
-      if (symbol is Addition) {
-        for (int i = 0; i < node.SubtreeCount; i++) {
-          if (i > 0) stringBuilder.Append("+");
+      if(symbol is Addition) {
+        for(int i = 0; i < node.SubtreeCount; i++) {
+          if(i > 0) stringBuilder.Append("+");
           stringBuilder.Append(FormatRecursively(node.GetSubtree(i)));
         }
-      } else if (symbol is And) {
+      } else if(symbol is And) {
         stringBuilder.Append("(");
-        for (int i = 0; i < node.SubtreeCount; i++) {
-          if (i > 0) stringBuilder.Append("&");
+        for(int i = 0; i < node.SubtreeCount; i++) {
+          if(i > 0) stringBuilder.Append("&");
           stringBuilder.Append("(");
           stringBuilder.Append(FormatRecursively(node.GetSubtree(i)));
@@ -69,21 +69,21 @@
         }
         stringBuilder.Append(") ifTrue:[1] ifFalse:[-1]");
-      } else if (symbol is Average) {
+      } else if(symbol is Average) {
         stringBuilder.Append("(1/");
         stringBuilder.Append(node.SubtreeCount);
         stringBuilder.Append(")*(");
-        for (int i = 0; i < node.SubtreeCount; i++) {
-          if (i > 0) stringBuilder.Append("+");
+        for(int i = 0; i < node.SubtreeCount; i++) {
+          if(i > 0) stringBuilder.Append("+");
           stringBuilder.Append(FormatRecursively(node.GetSubtree(i)));
         }
         stringBuilder.Append(")");
-      } else if (symbol is Constant) {
+      } else if(symbol is Constant) {
         ConstantTreeNode constantTreeNode = node as ConstantTreeNode;
         stringBuilder.Append(constantTreeNode.Value.ToString(CultureInfo.InvariantCulture));
-      } else if (symbol is Cosine) {
+      } else if(symbol is Cosine) {
         stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
         stringBuilder.Append(" cos");
-      } else if (symbol is Division) {
-        if (node.SubtreeCount == 1) {
+      } else if(symbol is Division) {
+        if(node.SubtreeCount == 1) {
           stringBuilder.Append("1/");
           stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
@@ -91,14 +91,14 @@
           stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
           stringBuilder.Append("/(");
-          for (int i = 1; i < node.SubtreeCount; i++) {
-            if (i > 1) stringBuilder.Append("*");
+          for(int i = 1; i < node.SubtreeCount; i++) {
+            if(i > 1) stringBuilder.Append("*");
             stringBuilder.Append(FormatRecursively(node.GetSubtree(i)));
           }
           stringBuilder.Append(")");
         }
-      } else if (symbol is Exponential) {
+      } else if(symbol is Exponential) {
         stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
         stringBuilder.Append(" exp");
-      } else if (symbol is GreaterThan) {
+      } else if(symbol is GreaterThan) {
         stringBuilder.Append("(");
         stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
@@ -106,5 +106,5 @@
         stringBuilder.Append(FormatRecursively(node.GetSubtree(1)));
         stringBuilder.Append(") ifTrue: [1] ifFalse: [-1]");
-      } else if (symbol is IfThenElse) {
+      } else if(symbol is IfThenElse) {
         stringBuilder.Append("(");
         stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
@@ -114,7 +114,7 @@
         stringBuilder.Append(FormatRecursively(node.GetSubtree(2)));
         stringBuilder.Append("]");
-      } else if (symbol is LaggedVariable) {
-        stringBuilder.Append("lagged variable not implemented");
-      } else if (symbol is LessThan) {
+      } else if(symbol is LaggedVariable) {
+        stringBuilder.Append("lagged variables are not supported");
+      } else if(symbol is LessThan) {
         stringBuilder.Append("(");
         stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
@@ -122,20 +122,20 @@
         stringBuilder.Append(FormatRecursively(node.GetSubtree(1)));
         stringBuilder.Append(") ifTrue: [1] ifFalse: [-1]");
-      } else if (symbol is Logarithm) {
+      } else if(symbol is Logarithm) {
         stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
         stringBuilder.Append("ln");
-      } else if (symbol is Multiplication) {
-        for (int i = 0; i < node.SubtreeCount; i++) {
-          if (i > 0) stringBuilder.Append("*");
+      } else if(symbol is Multiplication) {
+        for(int i = 0; i < node.SubtreeCount; i++) {
+          if(i > 0) stringBuilder.Append("*");
           stringBuilder.Append(FormatRecursively(node.GetSubtree(i)));
         }
-      } else if (symbol is Not) {
+      } else if(symbol is Not) {
         stringBuilder.Append("(");
         stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
         stringBuilder.Append(">0) ifTrue: [-1] ifFalse: [1.0]");
-      } else if (symbol is Or) {
+      } else if(symbol is Or) {
         stringBuilder.Append("(");
-        for (int i = 0; i < node.SubtreeCount; i++) {
-          if (i > 0) stringBuilder.Append("|");
+        for(int i = 0; i < node.SubtreeCount; i++) {
+          if(i > 0) stringBuilder.Append("|");
           stringBuilder.Append("(");
           stringBuilder.Append(FormatRecursively(node.GetSubtree(i)));
@@ -143,30 +143,32 @@
         }
         stringBuilder.Append(") ifTrue:[1] ifFalse:[-1]");
-      } else if (symbol is Sine) {
+      } else if(symbol is Sine) {
         stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
         stringBuilder.Append(" sin");
-      } else if (symbol is Subtraction) {
-        if (node.SubtreeCount == 1) {
+      } else if(symbol is Subtraction) {
+        if(node.SubtreeCount == 1) {
           stringBuilder.Append("-1*");
           stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
         } else {
           stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
-          for (int i = 1; i < node.SubtreeCount; i++) {
+          for(int i = 1; i < node.SubtreeCount; i++) {
             stringBuilder.Append(" - ");
             stringBuilder.Append(FormatRecursively(node.GetSubtree(i)));
           }
         }
-      } else if (symbol is Tangent) {
+      } else if(symbol is Tangent) {
         stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
         stringBuilder.Append(" tan");
-      } else if (symbol is Variable) {
+      } else if(symbol is Variable) {
         VariableTreeNode variableTreeNode = node as VariableTreeNode;
         stringBuilder.Append(variableTreeNode.Weight.ToString(CultureInfo.InvariantCulture));
         stringBuilder.Append("*");
         stringBuilder.Append(variableTreeNode.VariableName);
+      } else if(symbol is BinaryFactorVariable || symbol is FactorVariable) {
+        stringBuilder.Append("factor variables are not supported");
       } else {
         stringBuilder.Append("(");
-        for (int i = 0; i < node.SubtreeCount; i++) {
-          if (i > 0) stringBuilder.Append(", ");
+        for(int i = 0; i < node.SubtreeCount; i++) {
+          if(i > 0) stringBuilder.Append(", ");
           stringBuilder.Append(FormatRecursively(node.GetSubtree(i)));
         }
Index: /branches/symbreg-factors-2650/HeuristicLab.Problems.ExternalEvaluation.GP/3.5/ExternalEvaluationSymbolicExpressionTreeStringFormatter.cs
===================================================================
--- /branches/symbreg-factors-2650/HeuristicLab.Problems.ExternalEvaluation.GP/3.5/ExternalEvaluationSymbolicExpressionTreeStringFormatter.cs	(revision 14763)
+++ /branches/symbreg-factors-2650/HeuristicLab.Problems.ExternalEvaluation.GP/3.5/ExternalEvaluationSymbolicExpressionTreeStringFormatter.cs	(revision 14764)
@@ -58,5 +58,5 @@
       StringBuilder strBuilder = new StringBuilder();
       if (Indent) strBuilder.Append(' ', indentLength);
-      if (node.Subtrees.Count() > 0) { // internal node
+      if (node.Subtrees.Any()) { // internal node
         strBuilder.Append("(");
         if (node.Symbol is Addition) {
@@ -103,8 +103,8 @@
         strBuilder.Append(")");
       } else {
-        if (node is VariableTreeNode) {
+        if (node.Symbol is HeuristicLab.Problems.DataAnalysis.Symbolic.Variable) {
           var varNode = node as VariableTreeNode;
           strBuilder.AppendFormat("(* {0} {1})", varNode.VariableName, varNode.Weight.ToString("g17", CultureInfo.InvariantCulture));
-        } else if (node is ConstantTreeNode) {
+        } else if (node.Symbol is Constant) {
           var constNode = node as ConstantTreeNode;
           strBuilder.Append(constNode.Value.ToString("g17", CultureInfo.InvariantCulture));
