Index: /branches/ExperimentalFunctionsBaking/Addition.cs
===================================================================
--- /branches/ExperimentalFunctionsBaking/Addition.cs	(revision 219)
+++ /branches/ExperimentalFunctionsBaking/Addition.cs	(revision 220)
@@ -30,5 +30,5 @@
 
 namespace HeuristicLab.Functions {
-  public class Addition : FunctionBase {
+  public sealed class Addition : FunctionBase {
     public override string Description {
       get {
@@ -46,19 +46,4 @@
     }
 
-    public static double Add(double[] args) {
-      // (+ 3) => 3
-      // (+ 2 3) => 5
-      // (+ 3 4 5) => 12
-      double sum = 0.0;
-      for (int i = 0; i < args.Length; i++) {
-        sum += args[i];
-      }
-      return sum;
-    }
-
-    public override double Apply(Dataset dataset, int sampleIndex, double[] args) {
-      return Addition.Add(args);
-    }
-
     public override void Accept(IFunctionVisitor visitor) {
       visitor.Visit(this);
Index: /branches/ExperimentalFunctionsBaking/And.cs
===================================================================
--- /branches/ExperimentalFunctionsBaking/And.cs	(revision 219)
+++ /branches/ExperimentalFunctionsBaking/And.cs	(revision 220)
@@ -28,5 +28,5 @@
 
 namespace HeuristicLab.Functions {
-  public class And : FunctionBase {
+  public sealed class And : FunctionBase {
     public override string Description {
       get {
@@ -42,38 +42,7 @@
     }
 
-    public override IFunctionTree GetTreeNode() {
-      return new AndFunctionTree(this);
-    }
-
-    // special form
-    public override double Apply(Dataset dataset, int sampleIndex, double[] args) {
-      throw new NotImplementedException();
-    }
-
     public override void Accept(IFunctionVisitor visitor) {
       visitor.Visit(this);
     }
   }
-
-  class AndFunctionTree : FunctionTree {
-    public AndFunctionTree() : base() { }
-    public AndFunctionTree(And and) : base(and) { }
-
-    public override double Evaluate(Dataset dataset, int sampleIndex) {
-      foreach(IFunctionTree subTree in SubTrees) {
-        double result = Math.Round(subTree.Evaluate(dataset, sampleIndex));
-        if(result == 0.0) return 0.0; // one sub-tree is 0.0 (false) => return false
-        else if(result != 1.0) return double.NaN;
-      }
-      // all sub-trees evaluated to 1.0 (true) => return 1.0 (true)
-      return 1.0;
-    }
-
-    public override object Clone(IDictionary<Guid, object> clonedObjects) {
-      AndFunctionTree clone = new AndFunctionTree();
-      clonedObjects.Add(clone.Guid, clone);
-      FillClone(clone, clonedObjects);
-      return clone;
-    }
-  }
 }
Index: /branches/ExperimentalFunctionsBaking/Average.cs
===================================================================
--- /branches/ExperimentalFunctionsBaking/Average.cs	(revision 219)
+++ /branches/ExperimentalFunctionsBaking/Average.cs	(revision 220)
@@ -28,5 +28,5 @@
 
 namespace HeuristicLab.Functions {
-  public class Average : FunctionBase {
+  public sealed class Average : FunctionBase {
     public override string Description {
       get {
@@ -40,12 +40,4 @@
     }
 
-    public override double Apply(Dataset dataset, int sampleIndex, double[] args) {
-      double sum = 0.0;
-      for(int i = 0; i < args.Length; i++) {
-        sum += args[i];
-      }
-      return sum / args.Length;
-    }
-
     public override void Accept(IFunctionVisitor visitor) {
       visitor.Visit(this);
Index: /branches/ExperimentalFunctionsBaking/BakedFunctionTree.cs
===================================================================
--- /branches/ExperimentalFunctionsBaking/BakedFunctionTree.cs	(revision 219)
+++ /branches/ExperimentalFunctionsBaking/BakedFunctionTree.cs	(revision 220)
@@ -30,17 +30,67 @@
 namespace HeuristicLab.Functions {
   class BakedFunctionTree : ItemBase, IFunctionTree {
-    private List<double> code;
-    private static double nextFunctionSymbol = 10000;
-    private static Dictionary<double, IFunction> symbolTable = new Dictionary<double, IFunction>();
-    private static Dictionary<IFunction, double> reverseSymbolTable = new Dictionary<IFunction, double>();
-    private static double additionSymbol = -1;
-    private static double substractionSymbol = -1;
-    private static double multiplicationSymbol = -1;
-    private static double divisionSymbol = -1;
-    private static double variableSymbol = -1;
-    private static double constantSymbol = -1;
+    private List<int> code;
+    private List<double> data;
+    private const int ADDITION = 10010;
+    private const int AND = 10020;
+    private const int AVERAGE = 10030;
+    private const int CONSTANT = 10040;
+    private const int COSINUS = 10050;
+    private const int DIVISION = 10060;
+    private const int EQU = 10070;
+    private const int EXP = 10080;
+    private const int GT = 10090;
+    private const int IFTE = 10100;
+    private const int LT = 10110;
+    private const int LOG = 10120;
+    private const int MULTIPLICATION = 10130;
+    private const int NOT = 10140;
+    private const int OR = 10150;
+    private const int POWER = 10160;
+    private const int SIGNUM = 10170;
+    private const int SINUS = 10180;
+    private const int SQRT = 10190;
+    private const int SUBSTRACTION = 10200;
+    private const int TANGENS = 10210;
+    private const int VARIABLE = 10220;
+    private const int XOR = 10230;
+
+    private static int nextFunctionSymbol = 10240;
+    private static Dictionary<int, IFunction> symbolTable;
+    private static Dictionary<IFunction, int> reverseSymbolTable;
+    private static Dictionary<Type, int> staticTypes;
+
+    static BakedFunctionTree() {
+      symbolTable = new Dictionary<int, IFunction>();
+      reverseSymbolTable = new Dictionary<IFunction, int>();
+      staticTypes = new Dictionary<Type, int>();
+      staticTypes[typeof(Addition)] = ADDITION;
+      staticTypes[typeof(And)] = AND;
+      staticTypes[typeof(Average)] = AVERAGE;
+      staticTypes[typeof(Constant)] = CONSTANT;
+      staticTypes[typeof(Cosinus)] = COSINUS;
+      staticTypes[typeof(Division)] = DIVISION;
+      staticTypes[typeof(Equal)] = EQU;
+      staticTypes[typeof(Exponential)] = EXP;
+      staticTypes[typeof(GreaterThan)] = GT;
+      staticTypes[typeof(IfThenElse)] = IFTE;
+      staticTypes[typeof(LessThan)] = LT;
+      staticTypes[typeof(Logarithm)] = LOG;
+      staticTypes[typeof(Multiplication)] = MULTIPLICATION;
+      staticTypes[typeof(Not)] = NOT;
+      staticTypes[typeof(Or)] = OR;
+      staticTypes[typeof(Power)] = POWER;
+      staticTypes[typeof(Signum)] = SIGNUM;
+      staticTypes[typeof(Sinus)] = SINUS;
+      staticTypes[typeof(Sqrt)] = SQRT;
+      staticTypes[typeof(Substraction)] = SUBSTRACTION;
+      staticTypes[typeof(Tangens)] = TANGENS;
+      staticTypes[typeof(Variable)] = VARIABLE;
+      staticTypes[typeof(Xor)] = XOR;
+    }
 
     internal BakedFunctionTree() {
-      code = new List<double>();
+      code = new List<int>();
+      data = new List<double>();
     }
 
@@ -65,8 +115,8 @@
       code.Add(0);
       code.Add(MapFunction(tree.Function));
-      code.Add((byte)tree.LocalVariables.Count);
+      code.Add(tree.LocalVariables.Count);
       foreach(IVariable variable in tree.LocalVariables) {
         IItem value = variable.Value;
-        code.Add(GetDoubleValue(value));
+        data.Add(GetDoubleValue(value));
       }
       foreach(IFunctionTree subTree in tree.SubTrees) {
@@ -87,38 +137,32 @@
     }
 
-    private double MapFunction(IFunction function) {
+    private int MapFunction(IFunction function) {
       if(!reverseSymbolTable.ContainsKey(function)) {
-        reverseSymbolTable[function] = nextFunctionSymbol;
-        symbolTable[nextFunctionSymbol] = function;
-        if(function is Variable) {
-          variableSymbol = nextFunctionSymbol;
-        } else if(function is Constant) {
-          constantSymbol = nextFunctionSymbol;
-        } else if(function is Addition) {
-          additionSymbol = nextFunctionSymbol;
-        } else if(function is Substraction) {
-          substractionSymbol = nextFunctionSymbol;
-        } else if(function is Multiplication) {
-          multiplicationSymbol = nextFunctionSymbol;
-        } else if(function is Division) {
-          divisionSymbol = nextFunctionSymbol;
-        } else throw new NotSupportedException("Unsupported function " + function);
-
-        nextFunctionSymbol++;
+        int curFunctionSymbol;
+        if(staticTypes.ContainsKey(function.GetType())) curFunctionSymbol = staticTypes[function.GetType()];
+        else {
+          curFunctionSymbol = nextFunctionSymbol;
+          nextFunctionSymbol++;
+        }
+        reverseSymbolTable[function] = curFunctionSymbol;
+        symbolTable[curFunctionSymbol] = function;
       }
       return reverseSymbolTable[function];
     }
 
-    private int BranchLength(int branchRoot) {
-      double arity = code[branchRoot];
-      int nLocalVariables = (int)code[branchRoot + 2];
-      int len = 3 + nLocalVariables;
-      int subBranchStart = branchRoot + len;
+    private void BranchLength(int branchRoot, out int codeLength, out int dataLength) {
+      int arity = code[branchRoot];
+      int nLocalVariables = code[branchRoot + 2];
+      codeLength = 3;
+      dataLength = nLocalVariables;
+      int subBranchStart = branchRoot + codeLength;
       for(int i = 0; i < arity; i++) {
-        int branchLen = BranchLength(subBranchStart);
-        len += branchLen;
-        subBranchStart += branchLen;
-      }
-      return len;
+        int branchCodeLength;
+        int branchDataLength;
+        BranchLength(subBranchStart, out branchCodeLength, out branchDataLength);
+        subBranchStart += branchCodeLength;
+        codeLength += branchCodeLength;
+        dataLength += branchDataLength;
+      }
     }
 
@@ -130,4 +174,5 @@
           subTree.FlattenTrees();
           code.AddRange(subTree.code);
+          data.AddRange(subTree.data);
         }
         treesExpanded = false;
@@ -139,8 +184,6 @@
       if(variablesExpanded) {
         code[2] = variables.Count;
-        int localVariableIndex = 3;
         foreach(IVariable variable in variables) {
-          code.Insert(localVariableIndex, GetDoubleValue(variable.Value));
-          localVariableIndex++;
+          data.Add(GetDoubleValue(variable.Value));
         }
         variablesExpanded = false;
@@ -155,17 +198,23 @@
         if(!treesExpanded) {
           subTrees = new List<IFunctionTree>();
-          double arity = code[0];
-          int nLocalVariables = (int)code[2];
-          int branchIndex = 3 + nLocalVariables;
+          int arity = code[0];
+          int nLocalVariables = code[2];
+          int branchIndex = 3;
+          int dataIndex = nLocalVariables; // skip my local variables to reach the local variables of the first branch
           for(int i = 0; i < arity; i++) {
             BakedFunctionTree subTree = new BakedFunctionTree();
-            int branchLen = BranchLength(branchIndex);
-            subTree.code = code.GetRange(branchIndex, branchLen);
-            branchIndex += branchLen;
+            int codeLength;
+            int dataLength;
+            BranchLength(branchIndex, out codeLength, out dataLength);
+            subTree.code = code.GetRange(branchIndex, codeLength);
+            subTree.data = data.GetRange(dataIndex, dataLength);
+            branchIndex += codeLength;
+            dataIndex += dataLength;
             subTrees.Add(subTree);
           }
           treesExpanded = true;
-          code.RemoveRange(3 + nLocalVariables, code.Count - (3 + nLocalVariables));
+          code.RemoveRange(3, code.Count - 3);
           code[0] = 0;
+          data.RemoveRange(nLocalVariables, data.Count - nLocalVariables);
         }
         return subTrees;
@@ -180,5 +229,5 @@
           variables = new List<IVariable>();
           IFunction function = symbolTable[code[1]];
-          int localVariableIndex = 3;
+          int localVariableIndex = 0;
           foreach(IVariableInfo variableInfo in function.VariableInfos) {
             if(variableInfo.Local) {
@@ -186,11 +235,11 @@
               IItem value = clone.Value;
               if(value is ConstrainedDoubleData) {
-                ((ConstrainedDoubleData)value).Data = code[localVariableIndex];
+                ((ConstrainedDoubleData)value).Data = data[localVariableIndex];
               } else if(value is ConstrainedIntData) {
-                ((ConstrainedIntData)value).Data = (int)code[localVariableIndex];
+                ((ConstrainedIntData)value).Data = (int)data[localVariableIndex];
               } else if(value is DoubleData) {
-                ((DoubleData)value).Data = code[localVariableIndex];
+                ((DoubleData)value).Data = data[localVariableIndex];
               } else if(value is IntData) {
-                ((IntData)value).Data = (int)code[localVariableIndex];
+                ((IntData)value).Data = (int)data[localVariableIndex];
               } else throw new NotSupportedException("Invalid local variable type for GP.");
               variables.Add(clone);
@@ -200,5 +249,5 @@
           variablesExpanded = true;
           code[2] = 0;
-          code.RemoveRange(3, variables.Count);
+          data.RemoveRange(0, variables.Count);
         }
         return variables;
@@ -211,124 +260,221 @@
 
     public IVariable GetLocalVariable(string name) {
-      throw new NotImplementedException();
+      foreach(IVariable var in LocalVariables) {
+        if(var.Name == name) return var;
+      }
+      return null;
     }
 
     public void AddVariable(IVariable variable) {
-      throw new NotImplementedException();
+      throw new NotSupportedException();
     }
 
     public void RemoveVariable(string name) {
-      throw new NotImplementedException();
+      throw new NotSupportedException();
     }
 
     public void AddSubTree(IFunctionTree tree) {
-      if(treesExpanded) {
-        subTrees.Add(tree);
-      } else {
-        //code.AddRange(((BakedFunctionTree)tree).code);
-        //code[0] = code[0] + 1;
-        throw new NotImplementedException();
-      }
+      if(!treesExpanded) throw new InvalidOperationException();
+      subTrees.Add(tree);
     }
 
     public void InsertSubTree(int index, IFunctionTree tree) {
-      if(treesExpanded) {
-        subTrees.Insert(index, tree);
-      } else {
-        //byte nLocalVariables = code[2];
-        //// skip branches
-        //int currentBranchIndex = 3 + nLocalVariables;
-        //for(int i = 0; i < index; i++) {
-        //  int branchLength = BranchLength(currentBranchIndex);
-        //  currentBranchIndex += branchLength;
-        //}
-
-        //code.InsertRange(currentBranchIndex, ((BakedFunctionTree)tree).code);
-        //code[0] = code[0] + 1;
-
-        throw new NotImplementedException();
-      }
+      if(!treesExpanded) throw new InvalidOperationException();
+      subTrees.Insert(index, tree);
     }
 
     public void RemoveSubTree(int index) {
-      if(treesExpanded) {
-        subTrees.RemoveAt(index);
-      } else {
-        //int nLocalVariables = (int)code[2];
-        //// skip branches
-        //int currentBranchIndex = 3 + nLocalVariables;
-        //for(int i = 0; i < index; i++) {
-        //  int branchLength = BranchLength(currentBranchIndex);
-        //  currentBranchIndex += branchLength;
-        //}
-        //int deletedBranchLength = BranchLength(currentBranchIndex);
-        //code.RemoveRange(currentBranchIndex, deletedBranchLength);
-        //code[0] = code[0] - 1;
-        throw new NotImplementedException();
-      }
+      // sanity check
+      if(!treesExpanded) throw new InvalidOperationException();
+      subTrees.RemoveAt(index);
     }
 
     private int PC;
-    private double[] codeArr;
+    private int DP;
+    private int[] codeArr;
+    private double[] dataArr;
+    private Dataset dataset;
+    private int sampleIndex;
     public double Evaluate(Dataset dataset, int sampleIndex) {
       PC = 0;
+      DP = 0;
       FlattenVariables();
       FlattenTrees();
       if(codeArr == null) {
-        codeArr = new double[code.Count];
+        codeArr = new int[code.Count];
+        dataArr = new double[data.Count];
         code.CopyTo(codeArr);
-      }
-      return EvaluateBakedCode(dataset, sampleIndex);
-    }
-
-    private double EvaluateBakedCode(Dataset dataset, int sampleIndex) {
-      double arity = codeArr[PC++];
-      double functionSymbol = codeArr[PC++];
-      double nLocalVariables = codeArr[PC++];
-      if(functionSymbol == variableSymbol) {
-        int var = (int)codeArr[PC++];
-        double weight = codeArr[PC++];
-        int offset = (int)codeArr[PC++];
-        return weight * dataset.GetValue(sampleIndex+offset, var);
-      } else if(functionSymbol == constantSymbol) {
-        double value = codeArr[PC++];
-        return value;
-      } else if(functionSymbol == additionSymbol) {
-        double sum = 0.0;
-        for(int i = 0; i < arity; i++) {
-          sum += EvaluateBakedCode(dataset, sampleIndex);
-        }
-        return sum;
-      } else if(functionSymbol == substractionSymbol) {
-        if(arity == 1) {
-          return -EvaluateBakedCode(dataset, sampleIndex);
-        } else {
-          double result = EvaluateBakedCode(dataset, sampleIndex);
-          for(int i = 1; i < arity; i++) {
-            result -= EvaluateBakedCode(dataset, sampleIndex);
-          }
-          return result;
-        }
-      } else if(functionSymbol == multiplicationSymbol) {
-        double result = 1.0;
-        for(int i = 0; i < arity; i++) {
-          result *= EvaluateBakedCode(dataset, sampleIndex);
-        }
-        return result;
-      } else if(functionSymbol == divisionSymbol) {
-        if(arity == 1) {
-          double divisor = EvaluateBakedCode(dataset, sampleIndex);
-          if(divisor == 0) return 0;
-          else return 1.0 / divisor;
-        } else {
-          double result = EvaluateBakedCode(dataset, sampleIndex);
-          for(int i = 1; i < arity; i++) {
-            double divisor = EvaluateBakedCode(dataset, sampleIndex);
-            if(divisor == 0) result = 0; 
-            else result /= divisor;
-          }
-          return result;
-        }
-      } else { throw new NotSupportedException(); }
+        data.CopyTo(dataArr);
+      }
+      this.sampleIndex = sampleIndex;
+      this.dataset = dataset;
+      return EvaluateBakedCode();
+    }
+
+    private double EvaluateBakedCode() {
+      int arity = codeArr[PC++];
+      int functionSymbol = codeArr[PC++];
+      int nLocalVariables = codeArr[PC++];
+      switch(functionSymbol) {
+        case VARIABLE: {
+            int var = (int)dataArr[DP++];
+            double weight = dataArr[DP++];
+            int offset = (int)dataArr[DP++];
+            return weight * dataset.GetValue(sampleIndex + offset, var);
+          }
+        case CONSTANT: {
+            double value = dataArr[DP++];
+            return value;
+          }
+        case MULTIPLICATION: {
+            double result = 1.0;
+            for(int i = 0; i < arity; i++) {
+              result *= EvaluateBakedCode();
+            }
+            return result;
+          }
+        case ADDITION: {
+            double sum = 0.0;
+            for(int i = 0; i < arity; i++) {
+              sum += EvaluateBakedCode();
+            }
+            return sum;
+          }
+        case SUBSTRACTION: {
+            if(arity == 1) {
+              return -EvaluateBakedCode();
+            } else {
+              double result = EvaluateBakedCode();
+              for(int i = 1; i < arity; i++) {
+                result -= EvaluateBakedCode();
+              }
+              return result;
+            }
+          }
+        case DIVISION: {
+            if(arity == 1) {
+              double divisor = EvaluateBakedCode();
+              if(divisor == 0) return 0;
+              else return 1.0 / divisor;
+            } else {
+              double result = EvaluateBakedCode();
+              for(int i = 1; i < arity; i++) {
+                double divisor = EvaluateBakedCode();
+                if(divisor == 0) result = 0;
+                else result /= divisor;
+              }
+              return result;
+            }
+          }
+        case AVERAGE: {
+            double sum = 0.0;
+            for(int i = 0; i < arity; i++) {
+              sum += EvaluateBakedCode();
+            }
+            return sum / arity;
+          }
+        case COSINUS: {
+            return Math.Cos(EvaluateBakedCode());
+          }
+        case SINUS: {
+            return Math.Sin(EvaluateBakedCode());
+          }
+        case EXP: {
+            return Math.Exp(EvaluateBakedCode());
+          }
+        case LOG: {
+            return Math.Log(EvaluateBakedCode());
+          }
+        case POWER: {
+            double x = EvaluateBakedCode();
+            double p = EvaluateBakedCode();
+            return Math.Pow(x, p);
+          }
+        case SIGNUM: {
+            // protected signum
+            double value = EvaluateBakedCode();
+            if(value < 0) return -1;
+            if(value > 0) return 1;
+            return 0;
+          }
+        case SQRT: {
+            return Math.Sqrt(EvaluateBakedCode());
+          }
+        case TANGENS: {
+            return Math.Tan(EvaluateBakedCode());
+          }
+        case AND: {
+            double result = 1.0;
+            // have to evaluate all sub-trees, skipping would probably not lead to a big gain because 
+            // we have to iterate over the linear structure anyway
+            for(int i = 0; i < arity; i++) {
+              double x = Math.Round(EvaluateBakedCode());
+              if(x == 0) result *= 0;
+              else if(x == 1.0) result *= 1.0;
+              else result *= double.NaN;
+            }
+            return result;
+          }
+        case EQU: {
+            double x = EvaluateBakedCode();
+            double y = EvaluateBakedCode();
+            if(x == y) return 1.0; else return 0.0;
+          }
+        case GT: {
+            double x = EvaluateBakedCode();
+            double y = EvaluateBakedCode();
+            if(x > y) return 1.0;
+            else return 0.0;
+          }
+        case IFTE: {
+            double condition = Math.Round(EvaluateBakedCode());
+            double x = EvaluateBakedCode();
+            double y = EvaluateBakedCode();
+            if(condition < .5) return x;
+            else if(condition >= .5) return y;
+            else return double.NaN;
+          }
+        case LT: {
+            double x = EvaluateBakedCode();
+            double y = EvaluateBakedCode();
+            if(x < y) return 1.0;
+            else return 0.0;
+          }
+        case NOT: {
+            double result = Math.Round(EvaluateBakedCode());
+            if(result == 0.0) return 1.0;
+            else if(result == 1.0) return 0.0;
+            else return double.NaN;
+          }
+        case OR: {
+            double result = 0.0; // default is false
+            for(int i = 0; i < arity; i++) {
+              double x = Math.Round(EvaluateBakedCode());
+              if(x == 1.0 && result == 0.0) result = 1.0; // found first true (1.0) => set to true
+              else if(x != 0.0) result = double.NaN; // if it was not true it can only be false (0.0) all other cases are undefined => (NaN)
+            }
+            return result;
+          }
+        case XOR: {
+            double x = Math.Round(EvaluateBakedCode());
+            double y = Math.Round(EvaluateBakedCode());
+            if(x == 0.0 && y == 0.0) return 0.0;
+            if(x == 1.0 && y == 0.0) return 1.0;
+            if(x == 0.0 && y == 1.0) return 1.0;
+            if(x == 1.0 && y == 1.0) return 0.0;
+            return double.NaN;
+          }
+        default: {
+            IFunction function = symbolTable[functionSymbol];
+            double[] args = new double[nLocalVariables + arity];
+            for(int i = 0; i < nLocalVariables; i++) {
+              args[i] = dataArr[DP++];
+            }
+            for(int j = 0; j < arity; j++) {
+              args[nLocalVariables + j] = EvaluateBakedCode();
+            }
+            return function.Apply(dataset, sampleIndex, args);
+          }
+      }
     }
 
@@ -343,9 +489,12 @@
     public override object Clone(IDictionary<Guid, object> clonedObjects) {
       BakedFunctionTree clone = new BakedFunctionTree();
-      if(treesExpanded || variablesExpanded) throw new InvalidOperationException();
-      //if(treesExpanded) FlattenTrees();
-      //if(variablesExpanded) FlattenVariables();
-      clone.code = new List<double>(code);
+      if(treesExpanded || variablesExpanded) throw new InvalidOperationException(); // sanity check
+      clone.code.AddRange(code);
+      clone.data.AddRange(data);
       return clone;
+    }
+
+    public override IView CreateView() {
+      return new FunctionTreeView(this);
     }
   }
Index: /branches/ExperimentalFunctionsBaking/Constant.cs
===================================================================
--- /branches/ExperimentalFunctionsBaking/Constant.cs	(revision 219)
+++ /branches/ExperimentalFunctionsBaking/Constant.cs	(revision 220)
@@ -30,5 +30,5 @@
 
 namespace HeuristicLab.Functions {
-  public class Constant : FunctionBase {
+  public sealed class Constant : FunctionBase {
     public const string VALUE = "Value";
 
@@ -51,46 +51,7 @@
       AddConstraint(new NumberOfSubOperatorsConstraint(0, 0));
     }
-
-    //public override IFunctionTree GetTreeNode() {
-    //  return new ConstantFunctionTree(this);
-    //}
-
-    // can't apply a constant
-    public override double Apply(Dataset dataset, int sampleIndex, double[] args) {
-      throw new NotSupportedException();
-    }
-
     public override void Accept(IFunctionVisitor visitor) {
       visitor.Visit(this);
     }
   }
-
-  class ConstantFunctionTree : FunctionTree {
-    private ConstrainedDoubleData value;
-    public ConstantFunctionTree() : base() { }
-    public ConstantFunctionTree(Constant constant) : base(constant) {
-      UpdateCachedValues();
-    }
-
-    private void UpdateCachedValues() {
-      value = (ConstrainedDoubleData)GetLocalVariable(Constant.VALUE).Value;
-    }
-
-    public override double Evaluate(Dataset dataset, int sampleIndex) {
-      return value.Data;
-    }
-
-    public override object Clone(IDictionary<Guid, object> clonedObjects) {
-      ConstantFunctionTree clone = new ConstantFunctionTree();
-      clonedObjects.Add(clone.Guid, clone);
-      FillClone(clone, clonedObjects);
-      clone.UpdateCachedValues();
-      return clone;
-    }
-
-    public override void Populate(System.Xml.XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
-      base.Populate(node, restoredObjects);
-      UpdateCachedValues();
-    }
-  }
 }
Index: /branches/ExperimentalFunctionsBaking/Cosinus.cs
===================================================================
--- /branches/ExperimentalFunctionsBaking/Cosinus.cs	(revision 219)
+++ /branches/ExperimentalFunctionsBaking/Cosinus.cs	(revision 220)
@@ -29,5 +29,5 @@
 
 namespace HeuristicLab.Functions {
-  public class Cosinus : FunctionBase {
+  public sealed class Cosinus : FunctionBase {
     public override string Description {
       get { return "Returns the cosinus of the first sub-tree."; }
@@ -40,8 +40,4 @@
     }
 
-    public override double Apply(Dataset dataset, int sampleIndex, double[] args) {
-      return Math.Cos(args[0]);
-    }
-
     public override void Accept(IFunctionVisitor visitor) {
       visitor.Visit(this);
Index: /branches/ExperimentalFunctionsBaking/Division.cs
===================================================================
--- /branches/ExperimentalFunctionsBaking/Division.cs	(revision 219)
+++ /branches/ExperimentalFunctionsBaking/Division.cs	(revision 220)
@@ -30,5 +30,5 @@
 
 namespace HeuristicLab.Functions {
-  public class Division : FunctionBase {
+  public sealed class Division : FunctionBase {
     private const double EPSILON = 10.0E-20; // if any divisor is < EPSILON return 0
 
@@ -52,27 +52,4 @@
     }
 
-    public static double Divide(double[] args) {
-      // (/ 3) => 1/3
-      // (/ 2 3) => 2/3
-      // (/ 3 4 5) => 3/20
-      if(args.Length == 1) {
-        double divisor = args[0];
-        if(Math.Abs(divisor) < EPSILON) return 0;
-        else return 1.0 / divisor;
-      } else {
-        double result = args[0];
-        for(int i = 1; i < args.Length; i++) {
-          double divisor = args[i];
-          if(Math.Abs(divisor) < EPSILON) return 0.0;
-          result /= divisor;
-        }
-        return result;
-      }
-    }
-
-    public override double Apply(Dataset dataset, int sampleIndex, double[] args) {
-      return Division.Divide(args);
-    }
-
     public override void Accept(IFunctionVisitor visitor) {
       visitor.Visit(this);
Index: /branches/ExperimentalFunctionsBaking/Equal.cs
===================================================================
--- /branches/ExperimentalFunctionsBaking/Equal.cs	(revision 219)
+++ /branches/ExperimentalFunctionsBaking/Equal.cs	(revision 220)
@@ -28,5 +28,5 @@
 
 namespace HeuristicLab.Functions {
-  public class Equal : FunctionBase {
+  public sealed class Equal : FunctionBase {
     public override string Description {
       get {
@@ -40,9 +40,4 @@
     }
 
-    public override double Apply(Dataset dataset, int sampleIndex, double[] args) {
-      if(args[0] == args[1]) return 1.0;
-      else return 0.0;
-    }
-
     public override void Accept(IFunctionVisitor visitor) {
       visitor.Visit(this);
Index: /branches/ExperimentalFunctionsBaking/Exponential.cs
===================================================================
--- /branches/ExperimentalFunctionsBaking/Exponential.cs	(revision 219)
+++ /branches/ExperimentalFunctionsBaking/Exponential.cs	(revision 220)
@@ -29,5 +29,5 @@
 
 namespace HeuristicLab.Functions {
-  public class Exponential : FunctionBase {
+  public sealed class Exponential : FunctionBase {
     public override string Description {
       get { return "Returns returns exponential of the first sub-tree (power(e, x))."; }
@@ -40,8 +40,4 @@
     }
 
-    public override double Apply(Dataset dataset, int sampleIndex, double[] args) {
-      return Math.Exp(args[0]);
-    }
-
     public override void Accept(IFunctionVisitor visitor) {
       visitor.Visit(this);
Index: /branches/ExperimentalFunctionsBaking/FunctionBase.cs
===================================================================
--- /branches/ExperimentalFunctionsBaking/FunctionBase.cs	(revision 219)
+++ /branches/ExperimentalFunctionsBaking/FunctionBase.cs	(revision 220)
@@ -34,6 +34,8 @@
   /// </summary>
   public abstract class FunctionBase : OperatorBase, IFunction {
-    
-    public abstract double Apply(Dataset dataset, int sampleIndex, double[] args);
+
+    public virtual double Apply(Dataset dataset, int sampleIndex, double[] args) {
+      throw new NotImplementedException();
+    }
 
     public virtual void Accept(IFunctionVisitor visitor) {
Index: /branches/ExperimentalFunctionsBaking/GreaterThan.cs
===================================================================
--- /branches/ExperimentalFunctionsBaking/GreaterThan.cs	(revision 219)
+++ /branches/ExperimentalFunctionsBaking/GreaterThan.cs	(revision 220)
@@ -28,5 +28,5 @@
 
 namespace HeuristicLab.Functions {
-  public class GreaterThan : FunctionBase {
+  public sealed class GreaterThan : FunctionBase {
     public override string Description {
       get {
@@ -39,10 +39,4 @@
       AddConstraint(new NumberOfSubOperatorsConstraint(2, 2));
     }
-
-    public override double Apply(Dataset dataset, int sampleIndex, double[] args) {
-      if(args[0] > args[1]) return 1.0;
-      else return 0.0;
-    }
-
     public override void Accept(IFunctionVisitor visitor) {
       visitor.Visit(this);
Index: /branches/ExperimentalFunctionsBaking/IfThenElse.cs
===================================================================
--- /branches/ExperimentalFunctionsBaking/IfThenElse.cs	(revision 219)
+++ /branches/ExperimentalFunctionsBaking/IfThenElse.cs	(revision 220)
@@ -28,5 +28,5 @@
 
 namespace HeuristicLab.Functions {
-  public class IfThenElse : FunctionBase {
+  public sealed class IfThenElse : FunctionBase {
     public override string Description {
       get {
@@ -41,35 +41,7 @@
     }
 
-    public override IFunctionTree GetTreeNode() {
-      return new IfThenElseFunctionTree(this);
-    }
-
-    // special form
-    public override double Apply(Dataset dataset, int sampleIndex, double[] args) {
-      throw new NotImplementedException();
-    }
-
     public override void Accept(IFunctionVisitor visitor) {
       visitor.Visit(this);
     }
   }
-
-  class IfThenElseFunctionTree : FunctionTree {
-    public IfThenElseFunctionTree() : base() { }
-    public IfThenElseFunctionTree(IfThenElse ifte) : base(ifte) { }
-
-    public override double Evaluate(Dataset dataset, int sampleIndex) {
-      double condition = Math.Round(SubTrees[0].Evaluate(dataset, sampleIndex));
-      if(condition < .5) return SubTrees[1].Evaluate(dataset, sampleIndex);
-      else if(condition >= .5) return SubTrees[2].Evaluate(dataset, sampleIndex);
-      else return double.NaN;
-    }
-
-    public override object Clone(IDictionary<Guid, object> clonedObjects) {
-      IfThenElseFunctionTree clone = new IfThenElseFunctionTree();
-      clonedObjects.Add(clone.Guid, clone);
-      FillClone(clone, clonedObjects);
-      return clone;
-    }
-  }
 }
Index: /branches/ExperimentalFunctionsBaking/LessThan.cs
===================================================================
--- /branches/ExperimentalFunctionsBaking/LessThan.cs	(revision 219)
+++ /branches/ExperimentalFunctionsBaking/LessThan.cs	(revision 220)
@@ -28,5 +28,5 @@
 
 namespace HeuristicLab.Functions {
-  public class LessThan : FunctionBase {
+  public sealed class LessThan : FunctionBase {
     public override string Description {
       get {
@@ -40,9 +40,4 @@
     }
 
-    public override double Apply(Dataset dataset, int sampleIndex, double[] args) {
-      if(args[0] < args[1]) return 1.0;
-      else return 0.0;
-    }
-
     public override void Accept(IFunctionVisitor visitor) {
       visitor.Visit(this);
Index: /branches/ExperimentalFunctionsBaking/Logarithm.cs
===================================================================
--- /branches/ExperimentalFunctionsBaking/Logarithm.cs	(revision 219)
+++ /branches/ExperimentalFunctionsBaking/Logarithm.cs	(revision 220)
@@ -29,5 +29,5 @@
 
 namespace HeuristicLab.Functions {
-  public class Logarithm : FunctionBase {
+  public sealed class Logarithm : FunctionBase {
     public override string Description {
       get { return "Returns the natural (base e) logarithm of the first sub-tree."; }
@@ -40,8 +40,4 @@
     }
 
-    public override double Apply(Dataset dataset, int sampleIndex, double[] args) {
-      return Math.Log(args[0]);
-    }
-
     public override void Accept(IFunctionVisitor visitor) {
       visitor.Visit(this);
Index: /branches/ExperimentalFunctionsBaking/Multiplication.cs
===================================================================
--- /branches/ExperimentalFunctionsBaking/Multiplication.cs	(revision 219)
+++ /branches/ExperimentalFunctionsBaking/Multiplication.cs	(revision 220)
@@ -30,5 +30,5 @@
 
 namespace HeuristicLab.Functions {
-  public class Multiplication : FunctionBase {
+  public sealed class Multiplication : FunctionBase {
     public override string Description {
       get {
@@ -45,17 +45,4 @@
       AddConstraint(new NumberOfSubOperatorsConstraint(2, 3));
     }
-    public static double Multipy(double[] args) {
-      // (* 3) => 3
-      // (* 2 3) => 6
-      // (* 3 4 5) => 60
-      double result = 1.0;
-      for(int i = 0; i < args.Length; i++) {
-        result *= args[i];
-      }
-      return result;
-    }
-    public override double Apply(Dataset dataset, int sampleIndex, double[] args) {
-      return Multiplication.Multipy(args);
-    }
 
     public override void Accept(IFunctionVisitor visitor) {
Index: /branches/ExperimentalFunctionsBaking/Not.cs
===================================================================
--- /branches/ExperimentalFunctionsBaking/Not.cs	(revision 219)
+++ /branches/ExperimentalFunctionsBaking/Not.cs	(revision 220)
@@ -28,5 +28,5 @@
 
 namespace HeuristicLab.Functions {
-  public class Not : FunctionBase {
+  public sealed class Not : FunctionBase {
     public override string Description {
       get {
@@ -40,11 +40,4 @@
     }
 
-    public override double Apply(Dataset dataset, int sampleIndex, double[] args) {
-      double result = Math.Round(args[0]);
-      if(result == 0.0) return 1.0;
-      else if(result == 1.0) return 0.0;
-      else return double.NaN;
-    }
-
     public override void Accept(IFunctionVisitor visitor) {
       visitor.Visit(this);
Index: /branches/ExperimentalFunctionsBaking/Or.cs
===================================================================
--- /branches/ExperimentalFunctionsBaking/Or.cs	(revision 219)
+++ /branches/ExperimentalFunctionsBaking/Or.cs	(revision 220)
@@ -28,5 +28,5 @@
 
 namespace HeuristicLab.Functions {
-  public class Or : FunctionBase {
+  public sealed class Or : FunctionBase {
     public override string Description {
       get {
@@ -41,36 +41,7 @@
     }
 
-    public override IFunctionTree GetTreeNode() {
-      return new OrFunctionTree(this);
-    }
-    // or is a special form and can't be applied
-    public override double Apply(Dataset dataset, int sampleIndex, double[] args) {
-      throw new NotImplementedException();
-    }
     public override void Accept(IFunctionVisitor visitor) {
       visitor.Visit(this);
     }
   }
-
-  class OrFunctionTree : FunctionTree {
-    public OrFunctionTree() : base() { }
-    public OrFunctionTree(Or or) : base(or) { }
-
-    public override double Evaluate(Dataset dataset, int sampleIndex) {
-      foreach(IFunctionTree subTree in SubTrees) {
-        double result = Math.Round(subTree.Evaluate(dataset, sampleIndex));
-        if(result == 1.0) return 1.0; // sub-tree evaluates to 1.0 (true) return 1.0
-        else if(result != 0.0) return double.NaN;
-      }
-      // all sub-trees evaluated to 0.0 (false) return false
-      return 0.0;
-    }
-
-    public override object Clone(IDictionary<Guid, object> clonedObjects) {
-      OrFunctionTree clone = new OrFunctionTree();
-      clonedObjects.Add(clone.Guid, clone);
-      FillClone(clone, clonedObjects);
-      return clone;
-    }
-  }
 }
Index: /branches/ExperimentalFunctionsBaking/Power.cs
===================================================================
--- /branches/ExperimentalFunctionsBaking/Power.cs	(revision 219)
+++ /branches/ExperimentalFunctionsBaking/Power.cs	(revision 220)
@@ -29,5 +29,5 @@
 
 namespace HeuristicLab.Functions {
-  public class Power : FunctionBase {
+  public sealed class Power : FunctionBase {
     public override string Description {
       get { return "Returns the result of the first sub-tree to the power of the second sub-tree (power(x, y))."; }
@@ -40,8 +40,4 @@
     }
 
-    public override double Apply(Dataset dataset, int sampleIndex, double[] args) {
-      return Math.Pow(args[0], args[1]);
-    }
-
     public override void Accept(IFunctionVisitor visitor) {
       visitor.Visit(this);
Index: /branches/ExperimentalFunctionsBaking/ProgrammableFunction.cs
===================================================================
--- /branches/ExperimentalFunctionsBaking/ProgrammableFunction.cs	(revision 219)
+++ /branches/ExperimentalFunctionsBaking/ProgrammableFunction.cs	(revision 220)
@@ -36,5 +36,5 @@
 
 namespace HeuristicLab.Functions {
-  public class ProgrammableFunction : ProgrammableOperator, IFunction {
+  public sealed class ProgrammableFunction : ProgrammableOperator, IFunction {
     private MethodInfo applyMethod;
     public ProgrammableFunction()
Index: /branches/ExperimentalFunctionsBaking/Signum.cs
===================================================================
--- /branches/ExperimentalFunctionsBaking/Signum.cs	(revision 219)
+++ /branches/ExperimentalFunctionsBaking/Signum.cs	(revision 220)
@@ -29,5 +29,5 @@
 
 namespace HeuristicLab.Functions {
-  public class Signum : FunctionBase {
+  public sealed class Signum : FunctionBase {
     public override string Description {
       get { return "Returns the signum of the first sub-tree."; }
@@ -40,11 +40,4 @@
     }
 
-    public override double Apply(Dataset dataset, int sampleIndex, double[] args) {
-      double value = args[0];
-      if(value < 0) return -1;
-      if(value > 0) return 1;
-      return 0;
-    }
-
     public override void Accept(IFunctionVisitor visitor) {
       visitor.Visit(this);
Index: /branches/ExperimentalFunctionsBaking/Sinus.cs
===================================================================
--- /branches/ExperimentalFunctionsBaking/Sinus.cs	(revision 219)
+++ /branches/ExperimentalFunctionsBaking/Sinus.cs	(revision 220)
@@ -29,5 +29,5 @@
 
 namespace HeuristicLab.Functions {
-  public class Sinus : FunctionBase {
+  public sealed class Sinus : FunctionBase {
     public override string Description {
       get { return "Returns the sinus of the first sub-tree."; }
@@ -40,8 +40,4 @@
     }
 
-    public override double Apply(Dataset dataset, int sampleIndex, double[] args) {
-      return Math.Sin(args[0]);
-    }
-
     public override void Accept(IFunctionVisitor visitor) {
       visitor.Visit(this);
Index: /branches/ExperimentalFunctionsBaking/Sqrt.cs
===================================================================
--- /branches/ExperimentalFunctionsBaking/Sqrt.cs	(revision 219)
+++ /branches/ExperimentalFunctionsBaking/Sqrt.cs	(revision 220)
@@ -29,5 +29,5 @@
 
 namespace HeuristicLab.Functions {
-  public class Sqrt : FunctionBase {
+  public sealed class Sqrt : FunctionBase {
     public override string Description {
       get { return "Returns the square root of the first sub-tree."; }
@@ -40,9 +40,4 @@
     }
 
-
-    public override double Apply(Dataset dataset, int sampleIndex, double[] args) {
-      return Math.Sqrt(args[0]);
-    }
-
     public override void Accept(IFunctionVisitor visitor) {
       visitor.Visit(this);
Index: /branches/ExperimentalFunctionsBaking/Substraction.cs
===================================================================
--- /branches/ExperimentalFunctionsBaking/Substraction.cs	(revision 219)
+++ /branches/ExperimentalFunctionsBaking/Substraction.cs	(revision 220)
@@ -30,5 +30,5 @@
 
 namespace HeuristicLab.Functions {
-  public class Substraction : FunctionBase {
+  public sealed class Substraction : FunctionBase {
     public override string Description {
       get {
@@ -46,20 +46,4 @@
     }
 
-    public static double Substract(double[] args) {
-      if(args.Length == 1) {
-        return -args[0];
-      } else {
-        double result = args[0];
-        for(int i = 1; i < args.Length; i++) {
-          result -= args[i];
-        }
-        return result;
-      }
-    }
-
-    public override double Apply(Dataset dataset, int sampleIndex, double[] args) {
-      return Substraction.Substract(args);
-    }
-
     public override void Accept(IFunctionVisitor visitor) {
       visitor.Visit(this);
Index: /branches/ExperimentalFunctionsBaking/Tangens.cs
===================================================================
--- /branches/ExperimentalFunctionsBaking/Tangens.cs	(revision 219)
+++ /branches/ExperimentalFunctionsBaking/Tangens.cs	(revision 220)
@@ -29,5 +29,5 @@
 
 namespace HeuristicLab.Functions {
-  public class Tangens : FunctionBase {
+  public sealed class Tangens : FunctionBase {
     public override string Description {
       get { return "Returns the tangens of the first sub-tree."; }
@@ -40,8 +40,4 @@
     }
 
-    public override double Apply(Dataset dataset, int sampleIndex, double[] args) {
-      return Math.Tan(args[0]);
-    }
-
     public override void Accept(IFunctionVisitor visitor) {
       visitor.Visit(this);
Index: /branches/ExperimentalFunctionsBaking/Variable.cs
===================================================================
--- /branches/ExperimentalFunctionsBaking/Variable.cs	(revision 219)
+++ /branches/ExperimentalFunctionsBaking/Variable.cs	(revision 220)
@@ -30,5 +30,5 @@
 
 namespace HeuristicLab.Functions {
-  public class Variable : FunctionBase {
+  public sealed class Variable : FunctionBase {
 
     public const string WEIGHT = "Weight";
@@ -37,7 +37,9 @@
 
     public override string Description {
-      get { return @"Variable reads a value from a dataset, multiplies that value with a given factor and returns the result.
+      get {
+        return @"Variable reads a value from a dataset, multiplies that value with a given factor and returns the result.
 The variable 'SampleOffset' can be used to read a value from previous or following rows.
-The index of the row that is actually read is SampleIndex+SampleOffset)."; }
+The index of the row that is actually read is SampleIndex+SampleOffset).";
+      }
     }
 
@@ -68,50 +70,7 @@
     }
 
-    //public override IFunctionTree GetTreeNode() {
-    //  return new VariableFunctionTree(this);
-    //}
-
-    // can't apply a variable
-    public override double Apply(Dataset dataset, int sampleIndex, double[] args) {
-      throw new NotSupportedException();
-    }
-
     public override void Accept(IFunctionVisitor visitor) {
       visitor.Visit(this);
     }
   }
-  class VariableFunctionTree : FunctionTree {
-    private ConstrainedDoubleData weight;
-    private ConstrainedIntData index;
-    private ConstrainedIntData offset;
-
-    public VariableFunctionTree() : base() { }
-    public VariableFunctionTree(Variable variable) : base(variable) {
-      UpdateCachedValues();
-    }
-
-    protected void UpdateCachedValues() {
-      weight = (ConstrainedDoubleData)GetLocalVariable(Variable.WEIGHT).Value;
-      index = (ConstrainedIntData)GetLocalVariable(Variable.INDEX).Value;
-      offset = (ConstrainedIntData)GetLocalVariable(Variable.OFFSET).Value;
-    }
-
-    public override double Evaluate(Dataset dataset, int sampleIndex) {
-      if(sampleIndex + offset.Data < 0 || sampleIndex + offset.Data >= dataset.Rows) return double.NaN;
-      return weight.Data * dataset.GetValue(sampleIndex + offset.Data, index.Data);
-    }
-
-    public override object Clone(IDictionary<Guid, object> clonedObjects) {
-      VariableFunctionTree clone = new VariableFunctionTree();
-      clonedObjects.Add(clone.Guid, clone);
-      FillClone(clone, clonedObjects);
-      clone.UpdateCachedValues();
-      return clone;
-    }
-
-    public override void Populate(System.Xml.XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
-      base.Populate(node, restoredObjects);
-      UpdateCachedValues();
-    }
-  }
 }
Index: /branches/ExperimentalFunctionsBaking/Xor.cs
===================================================================
--- /branches/ExperimentalFunctionsBaking/Xor.cs	(revision 219)
+++ /branches/ExperimentalFunctionsBaking/Xor.cs	(revision 220)
@@ -28,5 +28,5 @@
 
 namespace HeuristicLab.Functions {
-  public class Xor : FunctionBase {
+  public sealed class Xor : FunctionBase {
     public override string Description {
       get {
@@ -40,10 +40,4 @@
     }
 
-    public override double Apply(Dataset dataset, int sampleIndex, double[] args) {
-      if(args[0] == 0.0 && args[1] == 0.0) return 0.0;
-      if(args[0] * args[1] == 0.0) return 1.0;
-      return 0.0;
-    }
-
     public override void Accept(IFunctionVisitor visitor) {
       visitor.Visit(this);
