anchor.diff:      open FSharp.Stats
       open FSharp.Stats.Optimization
   
  +    let roundToNext (xVal:float) (xVals:seq<float>) =
  +        xVals 
  +        |> Seq.minBy (fun xI -> Math.Abs (xI - xVal))
  +
  +    /// gives smoothing spline function
       let initEvalAt (x:Vector<float>) (a:Vector<float>) (c:Vector<float>) =
   
           let n = x.Length
  
positive.code:     let splineDecreasing (x:Vector<float>) (y:Vector<float>) (W:Matrix<float>) con = 
          spline (~+) x y W con
  
      ///returns the best fit of the observation x,-and y-values and a given weightingMatrix
      let getBestFitOfWeighting x_values y_values wMat= 
          let getinitialestimate = getInitialEstimateOfWXY wMat (vector y_values) x_values
          let initialSelectionCriterion = getinitialestimate.AICc
          
          //monotone splines
          let fst1 =(In0,splineIncreasing x_values (vector y_values) wMat 0) |> fun (shapeClass,(constraintMatrices,result)) -> shapeClass,result //(cl, createTempClassResultSimple x.TraceA x.TraceC x.Error (x.GCV*1.04) x.Lambda x.Ctemp x.AICc x.SplineFunction)
          let fst2 =(De0,splineDecreasing x_values (vector y_values) wMat 0) |> fun (shapeClass,(constraintMatrices,result)) -> shapeClass,result //(cl, createTempClassResultSimple x.TraceA x.TraceC x.Error (x.GCV*1.04) x.Lambda x.Ctemp x.AICc x.SplineFunction)
          let bestfst = [fst1;fst2] |> List.minBy (fun (cl,x) -> x.AICc)                                                                
          //splines with one extremum
          let snd1 =(In1,splineIncreasing x_values (vector y_values) wMat 1) |> fun (shapeClass,(constraintMatrices,result)) -> shapeClass,result //(cl, createTempClassResultSimple x.TraceA x.TraceC x.Error (x.GCV*1.06) x.Lambda x.Ctemp x.AICc x.SplineFunction)
          let snd2 =(De1,splineDecreasing x_values (vector y_values) wMat 1) |> fun (shapeClass,(constraintMatrices,result)) -> shapeClass,result //(cl, createTempClassResultSimple x.TraceA x.TraceC x.Error (x.GCV*1.06) x.Lambda x.Ctemp x.AICc x.SplineFunction)
          let bestsnd = [snd1;snd2] |> List.minBy (fun (cl,x) -> x.AICc)                                                               
          //splines with two extrema                                                                                                                                             
          let trd1 =(In2,splineIncreasing x_values (vector y_values) wMat 2) |> fun (shapeClass,(constraintMatrices,result)) -> shapeClass,result //(cl, createTempClassResultSimple x.TraceA x.TraceC x.Error (x.GCV*1.08) x.Lambda x.Ctemp x.AICc x.SplineFunction)
          let trd2 =(De2,splineDecreasing x_values (vector y_values) wMat 2) |> fun (shapeClass,(constraintMatrices,result)) -> shapeClass,result //(cl, createTempClassResultSimple x.TraceA x.TraceC x.Error (x.GCV*1.08) x.Lambda x.Ctemp x.AICc x.SplineFunction)
          let besttrd = [trd1;trd2] |> List.minBy (fun (cl,x) -> x.AICc)
          //splines with three extremum
          let qua1 =(In3,splineIncreasing x_values (vector y_values) wMat 3) |> fun (shapeClass,(constraintMatrices,result)) -> shapeClass,result //(cl, createTempClassResultSimple x.TraceA x.TraceC x.Error (x.GCV*1.06) x.Lambda x.Ctemp x.AICc x.SplineFunction)
          let qua2 =(De3,splineDecreasing x_values (vector y_values) wMat 3) |> fun (shapeClass,(constraintMatrices,result)) -> shapeClass,result //(cl, createTempClassResultSimple x.TraceA x.TraceC x.Error (x.GCV*1.06) x.Lambda x.Ctemp x.AICc x.SplineFunction)
          let bestqua = [qua1;qua2] |> List.minBy (fun (cl,x) -> x.AICc)                                                               
          //splines with four extrema                                                                                                                                             
          let qui1 =(In4,splineIncreasing x_values (vector y_values) wMat 4) |> fun (shapeClass,(constraintMatrices,result)) -> shapeClass,result //(cl, createTempClassResultSimple x.TraceA x.TraceC x.Error (x.GCV*1.08) x.Lambda x.Ctemp x.AICc x.SplineFunction)
          let qui2 =(De4,splineDecreasing x_values (vector y_values) wMat 4) |> fun (shapeClass,(constraintMatrices,result)) -> shapeClass,result //(cl, createTempClassResultSimple x.TraceA x.TraceC x.Error (x.GCV*1.08) x.Lambda x.Ctemp x.AICc x.SplineFunction)
          let bestqui = [qui1;qui2] |> List.minBy (fun (cl,x) -> x.AICc)
  
          //selection of optimal shape possibility by model selection via AICc 
          [bestfst;bestsnd;besttrd;bestqua;bestqui]
          |> List.minBy (fun (cl,result) -> result.AICc)
          |> fun (cl,result) -> if result.AICc < initialSelectionCriterion then (cl,result) else Complex,result        
  
      //same as initEvalAt, but with recalculated polynomial coefficients
      let initFunctionWithCoefficients (x:Vector<float>) (a:Vector<float>) (c:Vector<float>) =  
          let n = x.Length
  
negative.code:             deriv i a.[i .. i+1] c.[i .. i+1] t
              )
  
      [<Obsolete("Only applicable at equal x spacing. Use initEvalTrdDerivativeAt instead")>]    
      ///returns a function that calculates the third derivative for a given xValue
      let getTrdDerivative (x:Vector<float>) (a:Vector<float>) (c:Vector<float>) =
          let n = x.Length
  