anchor.diff:  open FSharp.Quotations
   open phase_based_optimizer
   open types
  +open ccodegen
   
   let symdiff (exp: Expr): Expr = 
     exp
  
positive.code:               ruleengine.compilePatternToRule <@ cast_d @>; 
                ruleengine.compilePatternToRule <@ vget_d @>;
                ruleengine.compilePatternToRule <@ mget_d @>;
                ruleengine.compilePatternToRule <@ vlength_d @>;
                ruleengine.compilePatternToRule <@ mlength_d @>;
                ruleengine.compilePatternToRule <@ vbuild_d @>;
                ruleengine.compilePatternToRule <@ mbuild_d @>;
                //ruleengine.compilePatternToRule <@ sfold_d @>;
                fold_d;
                const_d;
  
negative.code:   let diffBody = Diff body (Expr.Var(new Var("dx", typeof<Number>)))
    transformer.LambdaN(List.append inputs inputsd, diffBody |> symdiff)
  
  let compileD (opt: bool) (moduleName: string) (methodName: string): string = 
       printf "compile [d]%s.%s: " moduleName methodName
       let expr = compiler.getMethodExpr moduleName methodName
       let e = expr |> transformDiff
       let optimized = if opt then e else e
       let debug = true
       if(debug) then 
         printfn "/* Original code:\n%A\n*/\n" (prettyprint e)
         if(opt) then 
           printfn "/* Optimized code:\n%A\n*/\n" (prettyprint optimized)
       let functionName = transformer.methodVariableName methodName moduleName
       let s = (
                 printf "C"
                 ccodegenTopLevel optimized (diffName functionName) debug)
       printfn " done"
       s
  
  let test_symdiff () = 
      //printfn "symdiff: %A" (symdiff <@ fun (x: double) -> diff (1. * 2.) x @>)
      //printfn "symdiff2: %A" (symdiff <@ fun (x: double) -> diff (let v = 1. * 2. in v) x @>)
  