Diagrams.Tangent:$catParam from diagrams-lib-1.3.0.3, D

Percentage Accurate: 99.8% → 99.9%
Time: 5.3s
Alternatives: 6
Speedup: 2.1×

Specification

?
\[\begin{array}{l} \\ 3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right) \end{array} \]
(FPCore (x) :precision binary64 (* 3.0 (+ (- (* (* x 3.0) x) (* x 4.0)) 1.0)))
double code(double x) {
	return 3.0 * ((((x * 3.0) * x) - (x * 4.0)) + 1.0);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 3.0d0 * ((((x * 3.0d0) * x) - (x * 4.0d0)) + 1.0d0)
end function
public static double code(double x) {
	return 3.0 * ((((x * 3.0) * x) - (x * 4.0)) + 1.0);
}
def code(x):
	return 3.0 * ((((x * 3.0) * x) - (x * 4.0)) + 1.0)
function code(x)
	return Float64(3.0 * Float64(Float64(Float64(Float64(x * 3.0) * x) - Float64(x * 4.0)) + 1.0))
end
function tmp = code(x)
	tmp = 3.0 * ((((x * 3.0) * x) - (x * 4.0)) + 1.0);
end
code[x_] := N[(3.0 * N[(N[(N[(N[(x * 3.0), $MachinePrecision] * x), $MachinePrecision] - N[(x * 4.0), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 6 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 99.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ 3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right) \end{array} \]
(FPCore (x) :precision binary64 (* 3.0 (+ (- (* (* x 3.0) x) (* x 4.0)) 1.0)))
double code(double x) {
	return 3.0 * ((((x * 3.0) * x) - (x * 4.0)) + 1.0);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 3.0d0 * ((((x * 3.0d0) * x) - (x * 4.0d0)) + 1.0d0)
end function
public static double code(double x) {
	return 3.0 * ((((x * 3.0) * x) - (x * 4.0)) + 1.0);
}
def code(x):
	return 3.0 * ((((x * 3.0) * x) - (x * 4.0)) + 1.0)
function code(x)
	return Float64(3.0 * Float64(Float64(Float64(Float64(x * 3.0) * x) - Float64(x * 4.0)) + 1.0))
end
function tmp = code(x)
	tmp = 3.0 * ((((x * 3.0) * x) - (x * 4.0)) + 1.0);
end
code[x_] := N[(3.0 * N[(N[(N[(N[(x * 3.0), $MachinePrecision] * x), $MachinePrecision] - N[(x * 4.0), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)
\end{array}

Alternative 1: 99.9% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(-12 + 9 \cdot x, x, 3\right) \end{array} \]
(FPCore (x) :precision binary64 (fma (+ -12.0 (* 9.0 x)) x 3.0))
double code(double x) {
	return fma((-12.0 + (9.0 * x)), x, 3.0);
}
function code(x)
	return fma(Float64(-12.0 + Float64(9.0 * x)), x, 3.0)
end
code[x_] := N[(N[(-12.0 + N[(9.0 * x), $MachinePrecision]), $MachinePrecision] * x + 3.0), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(-12 + 9 \cdot x, x, 3\right)
\end{array}
Derivation
  1. Initial program 99.5%

    \[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right) \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0

    \[\leadsto \color{blue}{3 + x \cdot \left(9 \cdot x - 12\right)} \]
  4. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \color{blue}{x \cdot \left(9 \cdot x - 12\right) + 3} \]
    2. distribute-rgt-out--N/A

      \[\leadsto \color{blue}{\left(\left(9 \cdot x\right) \cdot x - 12 \cdot x\right)} + 3 \]
    3. associate-*r*N/A

      \[\leadsto \left(\color{blue}{9 \cdot \left(x \cdot x\right)} - 12 \cdot x\right) + 3 \]
    4. unpow2N/A

      \[\leadsto \left(9 \cdot \color{blue}{{x}^{2}} - 12 \cdot x\right) + 3 \]
    5. metadata-evalN/A

      \[\leadsto \left(9 \cdot {x}^{2} - \color{blue}{\left(\mathsf{neg}\left(-12\right)\right)} \cdot x\right) + 3 \]
    6. metadata-evalN/A

      \[\leadsto \left(9 \cdot {x}^{2} - \left(\mathsf{neg}\left(\color{blue}{-12 \cdot 1}\right)\right) \cdot x\right) + 3 \]
    7. lft-mult-inverseN/A

      \[\leadsto \left(9 \cdot {x}^{2} - \left(\mathsf{neg}\left(-12 \cdot \color{blue}{\left(\frac{1}{x} \cdot x\right)}\right)\right) \cdot x\right) + 3 \]
    8. associate-*l*N/A

      \[\leadsto \left(9 \cdot {x}^{2} - \left(\mathsf{neg}\left(\color{blue}{\left(-12 \cdot \frac{1}{x}\right) \cdot x}\right)\right) \cdot x\right) + 3 \]
    9. metadata-evalN/A

      \[\leadsto \left(9 \cdot {x}^{2} - \left(\mathsf{neg}\left(\left(\color{blue}{\left(\mathsf{neg}\left(12\right)\right)} \cdot \frac{1}{x}\right) \cdot x\right)\right) \cdot x\right) + 3 \]
    10. distribute-lft-neg-inN/A

      \[\leadsto \left(9 \cdot {x}^{2} - \left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(12 \cdot \frac{1}{x}\right)\right)} \cdot x\right)\right) \cdot x\right) + 3 \]
    11. distribute-lft-neg-outN/A

      \[\leadsto \left(9 \cdot {x}^{2} - \color{blue}{\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(12 \cdot \frac{1}{x}\right)\right)\right)\right) \cdot x\right)} \cdot x\right) + 3 \]
    12. remove-double-negN/A

      \[\leadsto \left(9 \cdot {x}^{2} - \left(\color{blue}{\left(12 \cdot \frac{1}{x}\right)} \cdot x\right) \cdot x\right) + 3 \]
    13. associate-*r*N/A

      \[\leadsto \left(9 \cdot {x}^{2} - \color{blue}{\left(12 \cdot \frac{1}{x}\right) \cdot \left(x \cdot x\right)}\right) + 3 \]
    14. unpow2N/A

      \[\leadsto \left(9 \cdot {x}^{2} - \left(12 \cdot \frac{1}{x}\right) \cdot \color{blue}{{x}^{2}}\right) + 3 \]
    15. distribute-rgt-out--N/A

      \[\leadsto \color{blue}{{x}^{2} \cdot \left(9 - 12 \cdot \frac{1}{x}\right)} + 3 \]
    16. unpow2N/A

      \[\leadsto \color{blue}{\left(x \cdot x\right)} \cdot \left(9 - 12 \cdot \frac{1}{x}\right) + 3 \]
    17. associate-*l*N/A

      \[\leadsto \color{blue}{x \cdot \left(x \cdot \left(9 - 12 \cdot \frac{1}{x}\right)\right)} + 3 \]
    18. *-commutativeN/A

      \[\leadsto \color{blue}{\left(x \cdot \left(9 - 12 \cdot \frac{1}{x}\right)\right) \cdot x} + 3 \]
  5. Applied rewrites99.9%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(9, x, -12\right), x, 3\right)} \]
  6. Step-by-step derivation
    1. Applied rewrites99.9%

      \[\leadsto \mathsf{fma}\left(9 \cdot x + -12, x, 3\right) \]
    2. Final simplification99.9%

      \[\leadsto \mathsf{fma}\left(-12 + 9 \cdot x, x, 3\right) \]
    3. Add Preprocessing

    Alternative 2: 98.8% accurate, 0.7× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left(x \cdot 3\right) \cdot x - 4 \cdot x \leq 0.0005:\\ \;\;\;\;\mathsf{fma}\left(-12, x, 3\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(9, x, -12\right) \cdot x\\ \end{array} \end{array} \]
    (FPCore (x)
     :precision binary64
     (if (<= (- (* (* x 3.0) x) (* 4.0 x)) 0.0005)
       (fma -12.0 x 3.0)
       (* (fma 9.0 x -12.0) x)))
    double code(double x) {
    	double tmp;
    	if ((((x * 3.0) * x) - (4.0 * x)) <= 0.0005) {
    		tmp = fma(-12.0, x, 3.0);
    	} else {
    		tmp = fma(9.0, x, -12.0) * x;
    	}
    	return tmp;
    }
    
    function code(x)
    	tmp = 0.0
    	if (Float64(Float64(Float64(x * 3.0) * x) - Float64(4.0 * x)) <= 0.0005)
    		tmp = fma(-12.0, x, 3.0);
    	else
    		tmp = Float64(fma(9.0, x, -12.0) * x);
    	end
    	return tmp
    end
    
    code[x_] := If[LessEqual[N[(N[(N[(x * 3.0), $MachinePrecision] * x), $MachinePrecision] - N[(4.0 * x), $MachinePrecision]), $MachinePrecision], 0.0005], N[(-12.0 * x + 3.0), $MachinePrecision], N[(N[(9.0 * x + -12.0), $MachinePrecision] * x), $MachinePrecision]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;\left(x \cdot 3\right) \cdot x - 4 \cdot x \leq 0.0005:\\
    \;\;\;\;\mathsf{fma}\left(-12, x, 3\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;\mathsf{fma}\left(9, x, -12\right) \cdot x\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if (-.f64 (*.f64 (*.f64 x #s(literal 3 binary64)) x) (*.f64 x #s(literal 4 binary64))) < 5.0000000000000001e-4

      1. Initial program 100.0%

        \[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right) \]
      2. Add Preprocessing
      3. Taylor expanded in x around 0

        \[\leadsto \color{blue}{3 + -12 \cdot x} \]
      4. Step-by-step derivation
        1. +-commutativeN/A

          \[\leadsto \color{blue}{-12 \cdot x + 3} \]
        2. lower-fma.f6499.6

          \[\leadsto \color{blue}{\mathsf{fma}\left(-12, x, 3\right)} \]
      5. Applied rewrites99.6%

        \[\leadsto \color{blue}{\mathsf{fma}\left(-12, x, 3\right)} \]

      if 5.0000000000000001e-4 < (-.f64 (*.f64 (*.f64 x #s(literal 3 binary64)) x) (*.f64 x #s(literal 4 binary64)))

      1. Initial program 99.0%

        \[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right) \]
      2. Add Preprocessing
      3. Taylor expanded in x around inf

        \[\leadsto \color{blue}{{x}^{2} \cdot \left(9 - 12 \cdot \frac{1}{x}\right)} \]
      4. Step-by-step derivation
        1. unpow2N/A

          \[\leadsto \color{blue}{\left(x \cdot x\right)} \cdot \left(9 - 12 \cdot \frac{1}{x}\right) \]
        2. associate-*l*N/A

          \[\leadsto \color{blue}{x \cdot \left(x \cdot \left(9 - 12 \cdot \frac{1}{x}\right)\right)} \]
        3. *-commutativeN/A

          \[\leadsto \color{blue}{\left(x \cdot \left(9 - 12 \cdot \frac{1}{x}\right)\right) \cdot x} \]
        4. lower-*.f64N/A

          \[\leadsto \color{blue}{\left(x \cdot \left(9 - 12 \cdot \frac{1}{x}\right)\right) \cdot x} \]
        5. sub-negN/A

          \[\leadsto \left(x \cdot \color{blue}{\left(9 + \left(\mathsf{neg}\left(12 \cdot \frac{1}{x}\right)\right)\right)}\right) \cdot x \]
        6. distribute-rgt-inN/A

          \[\leadsto \color{blue}{\left(9 \cdot x + \left(\mathsf{neg}\left(12 \cdot \frac{1}{x}\right)\right) \cdot x\right)} \cdot x \]
        7. distribute-lft-neg-inN/A

          \[\leadsto \left(9 \cdot x + \color{blue}{\left(\left(\mathsf{neg}\left(12\right)\right) \cdot \frac{1}{x}\right)} \cdot x\right) \cdot x \]
        8. metadata-evalN/A

          \[\leadsto \left(9 \cdot x + \left(\color{blue}{-12} \cdot \frac{1}{x}\right) \cdot x\right) \cdot x \]
        9. associate-*l*N/A

          \[\leadsto \left(9 \cdot x + \color{blue}{-12 \cdot \left(\frac{1}{x} \cdot x\right)}\right) \cdot x \]
        10. lft-mult-inverseN/A

          \[\leadsto \left(9 \cdot x + -12 \cdot \color{blue}{1}\right) \cdot x \]
        11. metadata-evalN/A

          \[\leadsto \left(9 \cdot x + \color{blue}{-12}\right) \cdot x \]
        12. lower-fma.f6499.7

          \[\leadsto \color{blue}{\mathsf{fma}\left(9, x, -12\right)} \cdot x \]
      5. Applied rewrites99.7%

        \[\leadsto \color{blue}{\mathsf{fma}\left(9, x, -12\right) \cdot x} \]
    3. Recombined 2 regimes into one program.
    4. Final simplification99.7%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\left(x \cdot 3\right) \cdot x - 4 \cdot x \leq 0.0005:\\ \;\;\;\;\mathsf{fma}\left(-12, x, 3\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(9, x, -12\right) \cdot x\\ \end{array} \]
    5. Add Preprocessing

    Alternative 3: 98.2% accurate, 0.8× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left(x \cdot 3\right) \cdot x - 4 \cdot x \leq 0.0005:\\ \;\;\;\;\mathsf{fma}\left(-12, x, 3\right)\\ \mathbf{else}:\\ \;\;\;\;\left(9 \cdot x\right) \cdot x\\ \end{array} \end{array} \]
    (FPCore (x)
     :precision binary64
     (if (<= (- (* (* x 3.0) x) (* 4.0 x)) 0.0005)
       (fma -12.0 x 3.0)
       (* (* 9.0 x) x)))
    double code(double x) {
    	double tmp;
    	if ((((x * 3.0) * x) - (4.0 * x)) <= 0.0005) {
    		tmp = fma(-12.0, x, 3.0);
    	} else {
    		tmp = (9.0 * x) * x;
    	}
    	return tmp;
    }
    
    function code(x)
    	tmp = 0.0
    	if (Float64(Float64(Float64(x * 3.0) * x) - Float64(4.0 * x)) <= 0.0005)
    		tmp = fma(-12.0, x, 3.0);
    	else
    		tmp = Float64(Float64(9.0 * x) * x);
    	end
    	return tmp
    end
    
    code[x_] := If[LessEqual[N[(N[(N[(x * 3.0), $MachinePrecision] * x), $MachinePrecision] - N[(4.0 * x), $MachinePrecision]), $MachinePrecision], 0.0005], N[(-12.0 * x + 3.0), $MachinePrecision], N[(N[(9.0 * x), $MachinePrecision] * x), $MachinePrecision]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;\left(x \cdot 3\right) \cdot x - 4 \cdot x \leq 0.0005:\\
    \;\;\;\;\mathsf{fma}\left(-12, x, 3\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;\left(9 \cdot x\right) \cdot x\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if (-.f64 (*.f64 (*.f64 x #s(literal 3 binary64)) x) (*.f64 x #s(literal 4 binary64))) < 5.0000000000000001e-4

      1. Initial program 100.0%

        \[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right) \]
      2. Add Preprocessing
      3. Taylor expanded in x around 0

        \[\leadsto \color{blue}{3 + -12 \cdot x} \]
      4. Step-by-step derivation
        1. +-commutativeN/A

          \[\leadsto \color{blue}{-12 \cdot x + 3} \]
        2. lower-fma.f6499.6

          \[\leadsto \color{blue}{\mathsf{fma}\left(-12, x, 3\right)} \]
      5. Applied rewrites99.6%

        \[\leadsto \color{blue}{\mathsf{fma}\left(-12, x, 3\right)} \]

      if 5.0000000000000001e-4 < (-.f64 (*.f64 (*.f64 x #s(literal 3 binary64)) x) (*.f64 x #s(literal 4 binary64)))

      1. Initial program 99.0%

        \[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right) \]
      2. Add Preprocessing
      3. Taylor expanded in x around inf

        \[\leadsto \color{blue}{9 \cdot {x}^{2}} \]
      4. Step-by-step derivation
        1. *-commutativeN/A

          \[\leadsto \color{blue}{{x}^{2} \cdot 9} \]
        2. lower-*.f64N/A

          \[\leadsto \color{blue}{{x}^{2} \cdot 9} \]
        3. unpow2N/A

          \[\leadsto \color{blue}{\left(x \cdot x\right)} \cdot 9 \]
        4. lower-*.f6499.3

          \[\leadsto \color{blue}{\left(x \cdot x\right)} \cdot 9 \]
      5. Applied rewrites99.3%

        \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot 9} \]
      6. Step-by-step derivation
        1. Applied rewrites99.3%

          \[\leadsto \color{blue}{\left(9 \cdot x\right) \cdot x} \]
      7. Recombined 2 regimes into one program.
      8. Final simplification99.5%

        \[\leadsto \begin{array}{l} \mathbf{if}\;\left(x \cdot 3\right) \cdot x - 4 \cdot x \leq 0.0005:\\ \;\;\;\;\mathsf{fma}\left(-12, x, 3\right)\\ \mathbf{else}:\\ \;\;\;\;\left(9 \cdot x\right) \cdot x\\ \end{array} \]
      9. Add Preprocessing

      Alternative 4: 99.9% accurate, 2.1× speedup?

      \[\begin{array}{l} \\ \mathsf{fma}\left(\mathsf{fma}\left(9, x, -12\right), x, 3\right) \end{array} \]
      (FPCore (x) :precision binary64 (fma (fma 9.0 x -12.0) x 3.0))
      double code(double x) {
      	return fma(fma(9.0, x, -12.0), x, 3.0);
      }
      
      function code(x)
      	return fma(fma(9.0, x, -12.0), x, 3.0)
      end
      
      code[x_] := N[(N[(9.0 * x + -12.0), $MachinePrecision] * x + 3.0), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      \mathsf{fma}\left(\mathsf{fma}\left(9, x, -12\right), x, 3\right)
      \end{array}
      
      Derivation
      1. Initial program 99.5%

        \[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right) \]
      2. Add Preprocessing
      3. Taylor expanded in x around 0

        \[\leadsto \color{blue}{3 + x \cdot \left(9 \cdot x - 12\right)} \]
      4. Step-by-step derivation
        1. +-commutativeN/A

          \[\leadsto \color{blue}{x \cdot \left(9 \cdot x - 12\right) + 3} \]
        2. distribute-rgt-out--N/A

          \[\leadsto \color{blue}{\left(\left(9 \cdot x\right) \cdot x - 12 \cdot x\right)} + 3 \]
        3. associate-*r*N/A

          \[\leadsto \left(\color{blue}{9 \cdot \left(x \cdot x\right)} - 12 \cdot x\right) + 3 \]
        4. unpow2N/A

          \[\leadsto \left(9 \cdot \color{blue}{{x}^{2}} - 12 \cdot x\right) + 3 \]
        5. metadata-evalN/A

          \[\leadsto \left(9 \cdot {x}^{2} - \color{blue}{\left(\mathsf{neg}\left(-12\right)\right)} \cdot x\right) + 3 \]
        6. metadata-evalN/A

          \[\leadsto \left(9 \cdot {x}^{2} - \left(\mathsf{neg}\left(\color{blue}{-12 \cdot 1}\right)\right) \cdot x\right) + 3 \]
        7. lft-mult-inverseN/A

          \[\leadsto \left(9 \cdot {x}^{2} - \left(\mathsf{neg}\left(-12 \cdot \color{blue}{\left(\frac{1}{x} \cdot x\right)}\right)\right) \cdot x\right) + 3 \]
        8. associate-*l*N/A

          \[\leadsto \left(9 \cdot {x}^{2} - \left(\mathsf{neg}\left(\color{blue}{\left(-12 \cdot \frac{1}{x}\right) \cdot x}\right)\right) \cdot x\right) + 3 \]
        9. metadata-evalN/A

          \[\leadsto \left(9 \cdot {x}^{2} - \left(\mathsf{neg}\left(\left(\color{blue}{\left(\mathsf{neg}\left(12\right)\right)} \cdot \frac{1}{x}\right) \cdot x\right)\right) \cdot x\right) + 3 \]
        10. distribute-lft-neg-inN/A

          \[\leadsto \left(9 \cdot {x}^{2} - \left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(12 \cdot \frac{1}{x}\right)\right)} \cdot x\right)\right) \cdot x\right) + 3 \]
        11. distribute-lft-neg-outN/A

          \[\leadsto \left(9 \cdot {x}^{2} - \color{blue}{\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(12 \cdot \frac{1}{x}\right)\right)\right)\right) \cdot x\right)} \cdot x\right) + 3 \]
        12. remove-double-negN/A

          \[\leadsto \left(9 \cdot {x}^{2} - \left(\color{blue}{\left(12 \cdot \frac{1}{x}\right)} \cdot x\right) \cdot x\right) + 3 \]
        13. associate-*r*N/A

          \[\leadsto \left(9 \cdot {x}^{2} - \color{blue}{\left(12 \cdot \frac{1}{x}\right) \cdot \left(x \cdot x\right)}\right) + 3 \]
        14. unpow2N/A

          \[\leadsto \left(9 \cdot {x}^{2} - \left(12 \cdot \frac{1}{x}\right) \cdot \color{blue}{{x}^{2}}\right) + 3 \]
        15. distribute-rgt-out--N/A

          \[\leadsto \color{blue}{{x}^{2} \cdot \left(9 - 12 \cdot \frac{1}{x}\right)} + 3 \]
        16. unpow2N/A

          \[\leadsto \color{blue}{\left(x \cdot x\right)} \cdot \left(9 - 12 \cdot \frac{1}{x}\right) + 3 \]
        17. associate-*l*N/A

          \[\leadsto \color{blue}{x \cdot \left(x \cdot \left(9 - 12 \cdot \frac{1}{x}\right)\right)} + 3 \]
        18. *-commutativeN/A

          \[\leadsto \color{blue}{\left(x \cdot \left(9 - 12 \cdot \frac{1}{x}\right)\right) \cdot x} + 3 \]
      5. Applied rewrites99.9%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(9, x, -12\right), x, 3\right)} \]
      6. Add Preprocessing

      Alternative 5: 51.7% accurate, 3.9× speedup?

      \[\begin{array}{l} \\ \mathsf{fma}\left(-12, x, 3\right) \end{array} \]
      (FPCore (x) :precision binary64 (fma -12.0 x 3.0))
      double code(double x) {
      	return fma(-12.0, x, 3.0);
      }
      
      function code(x)
      	return fma(-12.0, x, 3.0)
      end
      
      code[x_] := N[(-12.0 * x + 3.0), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      \mathsf{fma}\left(-12, x, 3\right)
      \end{array}
      
      Derivation
      1. Initial program 99.5%

        \[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right) \]
      2. Add Preprocessing
      3. Taylor expanded in x around 0

        \[\leadsto \color{blue}{3 + -12 \cdot x} \]
      4. Step-by-step derivation
        1. +-commutativeN/A

          \[\leadsto \color{blue}{-12 \cdot x + 3} \]
        2. lower-fma.f6452.5

          \[\leadsto \color{blue}{\mathsf{fma}\left(-12, x, 3\right)} \]
      5. Applied rewrites52.5%

        \[\leadsto \color{blue}{\mathsf{fma}\left(-12, x, 3\right)} \]
      6. Add Preprocessing

      Alternative 6: 51.2% accurate, 27.0× speedup?

      \[\begin{array}{l} \\ 3 \end{array} \]
      (FPCore (x) :precision binary64 3.0)
      double code(double x) {
      	return 3.0;
      }
      
      real(8) function code(x)
          real(8), intent (in) :: x
          code = 3.0d0
      end function
      
      public static double code(double x) {
      	return 3.0;
      }
      
      def code(x):
      	return 3.0
      
      function code(x)
      	return 3.0
      end
      
      function tmp = code(x)
      	tmp = 3.0;
      end
      
      code[x_] := 3.0
      
      \begin{array}{l}
      
      \\
      3
      \end{array}
      
      Derivation
      1. Initial program 99.5%

        \[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right) \]
      2. Add Preprocessing
      3. Taylor expanded in x around 0

        \[\leadsto \color{blue}{3} \]
      4. Step-by-step derivation
        1. Applied rewrites52.2%

          \[\leadsto \color{blue}{3} \]
        2. Add Preprocessing

        Developer Target 1: 99.8% accurate, 1.2× speedup?

        \[\begin{array}{l} \\ 3 + \left(\left(9 \cdot x\right) \cdot x - 12 \cdot x\right) \end{array} \]
        (FPCore (x) :precision binary64 (+ 3.0 (- (* (* 9.0 x) x) (* 12.0 x))))
        double code(double x) {
        	return 3.0 + (((9.0 * x) * x) - (12.0 * x));
        }
        
        real(8) function code(x)
            real(8), intent (in) :: x
            code = 3.0d0 + (((9.0d0 * x) * x) - (12.0d0 * x))
        end function
        
        public static double code(double x) {
        	return 3.0 + (((9.0 * x) * x) - (12.0 * x));
        }
        
        def code(x):
        	return 3.0 + (((9.0 * x) * x) - (12.0 * x))
        
        function code(x)
        	return Float64(3.0 + Float64(Float64(Float64(9.0 * x) * x) - Float64(12.0 * x)))
        end
        
        function tmp = code(x)
        	tmp = 3.0 + (((9.0 * x) * x) - (12.0 * x));
        end
        
        code[x_] := N[(3.0 + N[(N[(N[(9.0 * x), $MachinePrecision] * x), $MachinePrecision] - N[(12.0 * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
        
        \begin{array}{l}
        
        \\
        3 + \left(\left(9 \cdot x\right) \cdot x - 12 \cdot x\right)
        \end{array}
        

        Reproduce

        ?
        herbie shell --seed 2024295 
        (FPCore (x)
          :name "Diagrams.Tangent:$catParam from diagrams-lib-1.3.0.3, D"
          :precision binary64
        
          :alt
          (! :herbie-platform default (+ 3 (- (* (* 9 x) x) (* 12 x))))
        
          (* 3.0 (+ (- (* (* x 3.0) x) (* x 4.0)) 1.0)))