Index: branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/TreeToAutoDiffTermConverter.cs
===================================================================
--- branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/TreeToAutoDiffTermConverter.cs	(revision 16500)
+++ branches/2974_Constants_Optimization/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/TreeToAutoDiffTermConverter.cs	(revision 16508)
@@ -98,23 +98,11 @@
 
       // use a transformator object which holds the state (variable list, parameter list, ...) for recursive transformation of the tree
-      var transformator = new TreeToAutoDiffTermConverter(makeVariableWeightsVariable);
+      var transformator = new TreeToAutoDiffTermConverter(makeVariableWeightsVariable, addLinearScalingTerms);
       AutoDiff.Term term;
       try {
         term = transformator.ConvertToAutoDiff(tree.Root.GetSubtree(0));
-
-        if (addLinearScalingTerms) {
-          // scaling variables α, β are given at the beginning of the parameter vector
-          var alpha = new AutoDiff.Variable();
-          var beta = new AutoDiff.Variable();
-          transformator.variables.Insert(0, alpha);
-          transformator.variables.Insert(0, beta);
-
-          term = term * alpha + beta;
-        }
-
         var parameterEntries = transformator.parameters.ToArray(); // guarantee same order for keys and values
         var compiledTerm = term.Compile(transformator.variables.ToArray(),
           parameterEntries.Select(kvp => kvp.Value).ToArray());
-
         parameters = new List<DataForVariable>(parameterEntries.Select(kvp => kvp.Key));
         initialConstants = transformator.initialConstants.ToArray();
@@ -123,51 +111,7 @@
         return true;
       } catch (ConversionException) {
-        parameters = null;
-        initialConstants = null;
         func = null;
         func_grad = null;
-      }
-      return false;
-    }
-
-    public static bool TryConvertToAutoDiff(ISymbolicExpressionTree tree, bool addLinearScalingTerms, IEnumerable<DataForVariable> variables,
-      out IParametricCompiledTerm autoDiffTerm, out double[] initialConstants) {
-      // use a transformator object which holds the state (variable list, parameter list, ...) for recursive transformation of the tree
-      //TODO change ctor
-      var transformator = new TreeToAutoDiffTermConverter(true);
-      var parameters = new AutoDiff.Variable[variables.Count()];
-
-      int i = 0;
-      foreach(var variable in variables) { 
-        var autoDiffVar = new AutoDiff.Variable();
-        transformator.parameters.Add(variable, autoDiffVar);
-        parameters[i] = autoDiffVar;
-        i++;
-      }
-
-      AutoDiff.Term term;
-      try {
-        term = transformator.ConvertToAutoDiff(tree.Root.GetSubtree(0));
-        if (addLinearScalingTerms) {
-          // scaling variables α, β are given at the end of the parameter vector
-          var alpha = new AutoDiff.Variable();
-          var beta = new AutoDiff.Variable();
-
-          term = term * alpha + beta;
-
-          transformator.variables.Add(alpha);
-          transformator.variables.Add(beta);
-
-          transformator.initialConstants.Add(1.0);
-          transformator.initialConstants.Add(0.0);
-        }
-
-        var compiledTerm = term.Compile(transformator.variables.ToArray(), parameters);
-        autoDiffTerm = compiledTerm;
-        initialConstants = transformator.initialConstants.ToArray();
-
-        return true;
-      } catch (ConversionException) {
-        autoDiffTerm = null;
+        parameters = null;
         initialConstants = null;
       }
@@ -180,7 +124,9 @@
     private readonly List<AutoDiff.Variable> variables;
     private readonly bool makeVariableWeightsVariable;
-
-    private TreeToAutoDiffTermConverter(bool makeVariableWeightsVariable) {
+    private readonly bool addLinearScalingTerms;
+
+    private TreeToAutoDiffTermConverter(bool makeVariableWeightsVariable, bool addLinearScalingTerms) {
       this.makeVariableWeightsVariable = makeVariableWeightsVariable;
+      this.addLinearScalingTerms = addLinearScalingTerms;
       this.initialConstants = new List<double>();
       this.parameters = new Dictionary<DataForVariable, AutoDiff.Variable>();
@@ -325,5 +271,13 @@
       }
       if (node.Symbol is StartSymbol) {
-        return ConvertToAutoDiff(node.GetSubtree(0));
+        if (addLinearScalingTerms) {
+          // scaling variables α, β are given at the beginning of the parameter vector
+          var alpha = new AutoDiff.Variable();
+          var beta = new AutoDiff.Variable();
+          variables.Add(beta);
+          variables.Add(alpha);
+          var t = ConvertToAutoDiff(node.GetSubtree(0));
+          return t * alpha + beta;
+        } else return ConvertToAutoDiff(node.GetSubtree(0));
       }
       throw new ConversionException();
