1 / (2 * cosh(x) + 2)

Percentage Accurate: 100.0% → 100.0%
Time: 4.4s
Alternatives: 8
Speedup: 0.6×

Specification

?
\[-1.79 \cdot 10^{+308} \leq x \land x \leq 1.79 \cdot 10^{+308}\]
\[\begin{array}{l} \\ \frac{1}{2 \cdot \cosh x + 2} \end{array} \]
(FPCore (x) :precision binary64 (/ 1.0 (+ (* 2.0 (cosh x)) 2.0)))
double code(double x) {
	return 1.0 / ((2.0 * cosh(x)) + 2.0);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 1.0d0 / ((2.0d0 * cosh(x)) + 2.0d0)
end function
public static double code(double x) {
	return 1.0 / ((2.0 * Math.cosh(x)) + 2.0);
}
def code(x):
	return 1.0 / ((2.0 * math.cosh(x)) + 2.0)
function code(x)
	return Float64(1.0 / Float64(Float64(2.0 * cosh(x)) + 2.0))
end
function tmp = code(x)
	tmp = 1.0 / ((2.0 * cosh(x)) + 2.0);
end
code[x_] := N[(1.0 / N[(N[(2.0 * N[Cosh[x], $MachinePrecision]), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{1}{2 \cdot \cosh x + 2}
\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 8 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: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{1}{2 \cdot \cosh x + 2} \end{array} \]
(FPCore (x) :precision binary64 (/ 1.0 (+ (* 2.0 (cosh x)) 2.0)))
double code(double x) {
	return 1.0 / ((2.0 * cosh(x)) + 2.0);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 1.0d0 / ((2.0d0 * cosh(x)) + 2.0d0)
end function
public static double code(double x) {
	return 1.0 / ((2.0 * Math.cosh(x)) + 2.0);
}
def code(x):
	return 1.0 / ((2.0 * math.cosh(x)) + 2.0)
function code(x)
	return Float64(1.0 / Float64(Float64(2.0 * cosh(x)) + 2.0))
end
function tmp = code(x)
	tmp = 1.0 / ((2.0 * cosh(x)) + 2.0);
end
code[x_] := N[(1.0 / N[(N[(2.0 * N[Cosh[x], $MachinePrecision]), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{1}{2 \cdot \cosh x + 2}
\end{array}

Alternative 1: 100.0% accurate, 0.4× speedup?

\[\begin{array}{l} \\ {\left(\left(2 + e^{-x}\right) + e^{x}\right)}^{-1} \end{array} \]
(FPCore (x) :precision binary64 (pow (+ (+ 2.0 (exp (- x))) (exp x)) -1.0))
double code(double x) {
	return pow(((2.0 + exp(-x)) + exp(x)), -1.0);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = ((2.0d0 + exp(-x)) + exp(x)) ** (-1.0d0)
end function
public static double code(double x) {
	return Math.pow(((2.0 + Math.exp(-x)) + Math.exp(x)), -1.0);
}
def code(x):
	return math.pow(((2.0 + math.exp(-x)) + math.exp(x)), -1.0)
function code(x)
	return Float64(Float64(2.0 + exp(Float64(-x))) + exp(x)) ^ -1.0
end
function tmp = code(x)
	tmp = ((2.0 + exp(-x)) + exp(x)) ^ -1.0;
end
code[x_] := N[Power[N[(N[(2.0 + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision] + N[Exp[x], $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision]
\begin{array}{l}

\\
{\left(\left(2 + e^{-x}\right) + e^{x}\right)}^{-1}
\end{array}
Derivation
  1. Initial program 100.0%

    \[\frac{1}{2 \cdot \cosh x + 2} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-+.f64N/A

      \[\leadsto \frac{1}{\color{blue}{2 \cdot \cosh x + 2}} \]
    2. +-commutativeN/A

      \[\leadsto \frac{1}{\color{blue}{2 + 2 \cdot \cosh x}} \]
    3. lift-*.f64N/A

      \[\leadsto \frac{1}{2 + \color{blue}{2 \cdot \cosh x}} \]
    4. lift-cosh.f64N/A

      \[\leadsto \frac{1}{2 + 2 \cdot \color{blue}{\cosh x}} \]
    5. cosh-undefN/A

      \[\leadsto \frac{1}{2 + \color{blue}{\left(e^{x} + e^{\mathsf{neg}\left(x\right)}\right)}} \]
    6. +-commutativeN/A

      \[\leadsto \frac{1}{2 + \color{blue}{\left(e^{\mathsf{neg}\left(x\right)} + e^{x}\right)}} \]
    7. associate-+r+N/A

      \[\leadsto \frac{1}{\color{blue}{\left(2 + e^{\mathsf{neg}\left(x\right)}\right) + e^{x}}} \]
    8. lower-+.f64N/A

      \[\leadsto \frac{1}{\color{blue}{\left(2 + e^{\mathsf{neg}\left(x\right)}\right) + e^{x}}} \]
    9. lower-+.f64N/A

      \[\leadsto \frac{1}{\color{blue}{\left(2 + e^{\mathsf{neg}\left(x\right)}\right)} + e^{x}} \]
    10. lower-exp.f64N/A

      \[\leadsto \frac{1}{\left(2 + \color{blue}{e^{\mathsf{neg}\left(x\right)}}\right) + e^{x}} \]
    11. lower-neg.f64N/A

      \[\leadsto \frac{1}{\left(2 + e^{\color{blue}{-x}}\right) + e^{x}} \]
    12. lower-exp.f64100.0

      \[\leadsto \frac{1}{\left(2 + e^{-x}\right) + \color{blue}{e^{x}}} \]
  4. Applied rewrites100.0%

    \[\leadsto \frac{1}{\color{blue}{\left(2 + e^{-x}\right) + e^{x}}} \]
  5. Final simplification100.0%

    \[\leadsto {\left(\left(2 + e^{-x}\right) + e^{x}\right)}^{-1} \]
  6. Add Preprocessing

Alternative 2: 95.9% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 3.5:\\ \;\;\;\;{\left(2 \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.001388888888888889, x \cdot x, 0.041666666666666664\right), x \cdot x, 0.5\right), x \cdot x, 1\right) + 2\right)}^{-1}\\ \mathbf{else}:\\ \;\;\;\;{\left(3 + e^{x}\right)}^{-1}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x 3.5)
   (pow
    (+
     (*
      2.0
      (fma
       (fma
        (fma 0.001388888888888889 (* x x) 0.041666666666666664)
        (* x x)
        0.5)
       (* x x)
       1.0))
     2.0)
    -1.0)
   (pow (+ 3.0 (exp x)) -1.0)))
double code(double x) {
	double tmp;
	if (x <= 3.5) {
		tmp = pow(((2.0 * fma(fma(fma(0.001388888888888889, (x * x), 0.041666666666666664), (x * x), 0.5), (x * x), 1.0)) + 2.0), -1.0);
	} else {
		tmp = pow((3.0 + exp(x)), -1.0);
	}
	return tmp;
}
function code(x)
	tmp = 0.0
	if (x <= 3.5)
		tmp = Float64(Float64(2.0 * fma(fma(fma(0.001388888888888889, Float64(x * x), 0.041666666666666664), Float64(x * x), 0.5), Float64(x * x), 1.0)) + 2.0) ^ -1.0;
	else
		tmp = Float64(3.0 + exp(x)) ^ -1.0;
	end
	return tmp
end
code[x_] := If[LessEqual[x, 3.5], N[Power[N[(N[(2.0 * N[(N[(N[(0.001388888888888889 * N[(x * x), $MachinePrecision] + 0.041666666666666664), $MachinePrecision] * N[(x * x), $MachinePrecision] + 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] + 2.0), $MachinePrecision], -1.0], $MachinePrecision], N[Power[N[(3.0 + N[Exp[x], $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.5:\\
\;\;\;\;{\left(2 \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.001388888888888889, x \cdot x, 0.041666666666666664\right), x \cdot x, 0.5\right), x \cdot x, 1\right) + 2\right)}^{-1}\\

\mathbf{else}:\\
\;\;\;\;{\left(3 + e^{x}\right)}^{-1}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 3.5

    1. Initial program 100.0%

      \[\frac{1}{2 \cdot \cosh x + 2} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \frac{1}{2 \cdot \color{blue}{\left(1 + {x}^{2} \cdot \left(\frac{1}{2} + {x}^{2} \cdot \left(\frac{1}{24} + \frac{1}{720} \cdot {x}^{2}\right)\right)\right)} + 2} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{1}{2 \cdot \color{blue}{\left({x}^{2} \cdot \left(\frac{1}{2} + {x}^{2} \cdot \left(\frac{1}{24} + \frac{1}{720} \cdot {x}^{2}\right)\right) + 1\right)} + 2} \]
      2. *-commutativeN/A

        \[\leadsto \frac{1}{2 \cdot \left(\color{blue}{\left(\frac{1}{2} + {x}^{2} \cdot \left(\frac{1}{24} + \frac{1}{720} \cdot {x}^{2}\right)\right) \cdot {x}^{2}} + 1\right) + 2} \]
      3. lower-fma.f64N/A

        \[\leadsto \frac{1}{2 \cdot \color{blue}{\mathsf{fma}\left(\frac{1}{2} + {x}^{2} \cdot \left(\frac{1}{24} + \frac{1}{720} \cdot {x}^{2}\right), {x}^{2}, 1\right)} + 2} \]
      4. +-commutativeN/A

        \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(\color{blue}{{x}^{2} \cdot \left(\frac{1}{24} + \frac{1}{720} \cdot {x}^{2}\right) + \frac{1}{2}}, {x}^{2}, 1\right) + 2} \]
      5. *-commutativeN/A

        \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(\color{blue}{\left(\frac{1}{24} + \frac{1}{720} \cdot {x}^{2}\right) \cdot {x}^{2}} + \frac{1}{2}, {x}^{2}, 1\right) + 2} \]
      6. lower-fma.f64N/A

        \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(\frac{1}{24} + \frac{1}{720} \cdot {x}^{2}, {x}^{2}, \frac{1}{2}\right)}, {x}^{2}, 1\right) + 2} \]
      7. +-commutativeN/A

        \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(\mathsf{fma}\left(\color{blue}{\frac{1}{720} \cdot {x}^{2} + \frac{1}{24}}, {x}^{2}, \frac{1}{2}\right), {x}^{2}, 1\right) + 2} \]
      8. lower-fma.f64N/A

        \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(\mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(\frac{1}{720}, {x}^{2}, \frac{1}{24}\right)}, {x}^{2}, \frac{1}{2}\right), {x}^{2}, 1\right) + 2} \]
      9. unpow2N/A

        \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{720}, \color{blue}{x \cdot x}, \frac{1}{24}\right), {x}^{2}, \frac{1}{2}\right), {x}^{2}, 1\right) + 2} \]
      10. lower-*.f64N/A

        \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{720}, \color{blue}{x \cdot x}, \frac{1}{24}\right), {x}^{2}, \frac{1}{2}\right), {x}^{2}, 1\right) + 2} \]
      11. unpow2N/A

        \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{720}, x \cdot x, \frac{1}{24}\right), \color{blue}{x \cdot x}, \frac{1}{2}\right), {x}^{2}, 1\right) + 2} \]
      12. lower-*.f64N/A

        \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{720}, x \cdot x, \frac{1}{24}\right), \color{blue}{x \cdot x}, \frac{1}{2}\right), {x}^{2}, 1\right) + 2} \]
      13. unpow2N/A

        \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{720}, x \cdot x, \frac{1}{24}\right), x \cdot x, \frac{1}{2}\right), \color{blue}{x \cdot x}, 1\right) + 2} \]
      14. lower-*.f6496.8

        \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.001388888888888889, x \cdot x, 0.041666666666666664\right), x \cdot x, 0.5\right), \color{blue}{x \cdot x}, 1\right) + 2} \]
    5. Applied rewrites96.8%

      \[\leadsto \frac{1}{2 \cdot \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.001388888888888889, x \cdot x, 0.041666666666666664\right), x \cdot x, 0.5\right), x \cdot x, 1\right)} + 2} \]

    if 3.5 < x

    1. Initial program 100.0%

      \[\frac{1}{2 \cdot \cosh x + 2} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \frac{1}{\color{blue}{2 \cdot \cosh x + 2}} \]
      2. +-commutativeN/A

        \[\leadsto \frac{1}{\color{blue}{2 + 2 \cdot \cosh x}} \]
      3. lift-*.f64N/A

        \[\leadsto \frac{1}{2 + \color{blue}{2 \cdot \cosh x}} \]
      4. lift-cosh.f64N/A

        \[\leadsto \frac{1}{2 + 2 \cdot \color{blue}{\cosh x}} \]
      5. cosh-undefN/A

        \[\leadsto \frac{1}{2 + \color{blue}{\left(e^{x} + e^{\mathsf{neg}\left(x\right)}\right)}} \]
      6. +-commutativeN/A

        \[\leadsto \frac{1}{2 + \color{blue}{\left(e^{\mathsf{neg}\left(x\right)} + e^{x}\right)}} \]
      7. associate-+r+N/A

        \[\leadsto \frac{1}{\color{blue}{\left(2 + e^{\mathsf{neg}\left(x\right)}\right) + e^{x}}} \]
      8. lower-+.f64N/A

        \[\leadsto \frac{1}{\color{blue}{\left(2 + e^{\mathsf{neg}\left(x\right)}\right) + e^{x}}} \]
      9. lower-+.f64N/A

        \[\leadsto \frac{1}{\color{blue}{\left(2 + e^{\mathsf{neg}\left(x\right)}\right)} + e^{x}} \]
      10. lower-exp.f64N/A

        \[\leadsto \frac{1}{\left(2 + \color{blue}{e^{\mathsf{neg}\left(x\right)}}\right) + e^{x}} \]
      11. lower-neg.f64N/A

        \[\leadsto \frac{1}{\left(2 + e^{\color{blue}{-x}}\right) + e^{x}} \]
      12. lower-exp.f64100.0

        \[\leadsto \frac{1}{\left(2 + e^{-x}\right) + \color{blue}{e^{x}}} \]
    4. Applied rewrites100.0%

      \[\leadsto \frac{1}{\color{blue}{\left(2 + e^{-x}\right) + e^{x}}} \]
    5. Taylor expanded in x around 0

      \[\leadsto \frac{1}{\color{blue}{3} + e^{x}} \]
    6. Step-by-step derivation
      1. Applied rewrites100.0%

        \[\leadsto \frac{1}{\color{blue}{3} + e^{x}} \]
    7. Recombined 2 regimes into one program.
    8. Final simplification97.7%

      \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 3.5:\\ \;\;\;\;{\left(2 \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.001388888888888889, x \cdot x, 0.041666666666666664\right), x \cdot x, 0.5\right), x \cdot x, 1\right) + 2\right)}^{-1}\\ \mathbf{else}:\\ \;\;\;\;{\left(3 + e^{x}\right)}^{-1}\\ \end{array} \]
    9. Add Preprocessing

    Alternative 3: 100.0% accurate, 0.6× speedup?

    \[\begin{array}{l} \\ {\left(\mathsf{fma}\left(\cosh x, 2, 2\right)\right)}^{-1} \end{array} \]
    (FPCore (x) :precision binary64 (pow (fma (cosh x) 2.0 2.0) -1.0))
    double code(double x) {
    	return pow(fma(cosh(x), 2.0, 2.0), -1.0);
    }
    
    function code(x)
    	return fma(cosh(x), 2.0, 2.0) ^ -1.0
    end
    
    code[x_] := N[Power[N[(N[Cosh[x], $MachinePrecision] * 2.0 + 2.0), $MachinePrecision], -1.0], $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    {\left(\mathsf{fma}\left(\cosh x, 2, 2\right)\right)}^{-1}
    \end{array}
    
    Derivation
    1. Initial program 100.0%

      \[\frac{1}{2 \cdot \cosh x + 2} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \frac{1}{\color{blue}{2 \cdot \cosh x + 2}} \]
      2. lift-*.f64N/A

        \[\leadsto \frac{1}{\color{blue}{2 \cdot \cosh x} + 2} \]
      3. *-commutativeN/A

        \[\leadsto \frac{1}{\color{blue}{\cosh x \cdot 2} + 2} \]
      4. lower-fma.f64100.0

        \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(\cosh x, 2, 2\right)}} \]
    4. Applied rewrites100.0%

      \[\leadsto \color{blue}{\frac{1}{\mathsf{fma}\left(\cosh x, 2, 2\right)}} \]
    5. Final simplification100.0%

      \[\leadsto {\left(\mathsf{fma}\left(\cosh x, 2, 2\right)\right)}^{-1} \]
    6. Add Preprocessing

    Alternative 4: 92.0% accurate, 0.8× speedup?

    \[\begin{array}{l} \\ {\left(2 \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.001388888888888889, x \cdot x, 0.041666666666666664\right), x \cdot x, 0.5\right), x \cdot x, 1\right) + 2\right)}^{-1} \end{array} \]
    (FPCore (x)
     :precision binary64
     (pow
      (+
       (*
        2.0
        (fma
         (fma (fma 0.001388888888888889 (* x x) 0.041666666666666664) (* x x) 0.5)
         (* x x)
         1.0))
       2.0)
      -1.0))
    double code(double x) {
    	return pow(((2.0 * fma(fma(fma(0.001388888888888889, (x * x), 0.041666666666666664), (x * x), 0.5), (x * x), 1.0)) + 2.0), -1.0);
    }
    
    function code(x)
    	return Float64(Float64(2.0 * fma(fma(fma(0.001388888888888889, Float64(x * x), 0.041666666666666664), Float64(x * x), 0.5), Float64(x * x), 1.0)) + 2.0) ^ -1.0
    end
    
    code[x_] := N[Power[N[(N[(2.0 * N[(N[(N[(0.001388888888888889 * N[(x * x), $MachinePrecision] + 0.041666666666666664), $MachinePrecision] * N[(x * x), $MachinePrecision] + 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] + 2.0), $MachinePrecision], -1.0], $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    {\left(2 \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.001388888888888889, x \cdot x, 0.041666666666666664\right), x \cdot x, 0.5\right), x \cdot x, 1\right) + 2\right)}^{-1}
    \end{array}
    
    Derivation
    1. Initial program 100.0%

      \[\frac{1}{2 \cdot \cosh x + 2} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \frac{1}{2 \cdot \color{blue}{\left(1 + {x}^{2} \cdot \left(\frac{1}{2} + {x}^{2} \cdot \left(\frac{1}{24} + \frac{1}{720} \cdot {x}^{2}\right)\right)\right)} + 2} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{1}{2 \cdot \color{blue}{\left({x}^{2} \cdot \left(\frac{1}{2} + {x}^{2} \cdot \left(\frac{1}{24} + \frac{1}{720} \cdot {x}^{2}\right)\right) + 1\right)} + 2} \]
      2. *-commutativeN/A

        \[\leadsto \frac{1}{2 \cdot \left(\color{blue}{\left(\frac{1}{2} + {x}^{2} \cdot \left(\frac{1}{24} + \frac{1}{720} \cdot {x}^{2}\right)\right) \cdot {x}^{2}} + 1\right) + 2} \]
      3. lower-fma.f64N/A

        \[\leadsto \frac{1}{2 \cdot \color{blue}{\mathsf{fma}\left(\frac{1}{2} + {x}^{2} \cdot \left(\frac{1}{24} + \frac{1}{720} \cdot {x}^{2}\right), {x}^{2}, 1\right)} + 2} \]
      4. +-commutativeN/A

        \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(\color{blue}{{x}^{2} \cdot \left(\frac{1}{24} + \frac{1}{720} \cdot {x}^{2}\right) + \frac{1}{2}}, {x}^{2}, 1\right) + 2} \]
      5. *-commutativeN/A

        \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(\color{blue}{\left(\frac{1}{24} + \frac{1}{720} \cdot {x}^{2}\right) \cdot {x}^{2}} + \frac{1}{2}, {x}^{2}, 1\right) + 2} \]
      6. lower-fma.f64N/A

        \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(\frac{1}{24} + \frac{1}{720} \cdot {x}^{2}, {x}^{2}, \frac{1}{2}\right)}, {x}^{2}, 1\right) + 2} \]
      7. +-commutativeN/A

        \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(\mathsf{fma}\left(\color{blue}{\frac{1}{720} \cdot {x}^{2} + \frac{1}{24}}, {x}^{2}, \frac{1}{2}\right), {x}^{2}, 1\right) + 2} \]
      8. lower-fma.f64N/A

        \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(\mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(\frac{1}{720}, {x}^{2}, \frac{1}{24}\right)}, {x}^{2}, \frac{1}{2}\right), {x}^{2}, 1\right) + 2} \]
      9. unpow2N/A

        \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{720}, \color{blue}{x \cdot x}, \frac{1}{24}\right), {x}^{2}, \frac{1}{2}\right), {x}^{2}, 1\right) + 2} \]
      10. lower-*.f64N/A

        \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{720}, \color{blue}{x \cdot x}, \frac{1}{24}\right), {x}^{2}, \frac{1}{2}\right), {x}^{2}, 1\right) + 2} \]
      11. unpow2N/A

        \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{720}, x \cdot x, \frac{1}{24}\right), \color{blue}{x \cdot x}, \frac{1}{2}\right), {x}^{2}, 1\right) + 2} \]
      12. lower-*.f64N/A

        \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{720}, x \cdot x, \frac{1}{24}\right), \color{blue}{x \cdot x}, \frac{1}{2}\right), {x}^{2}, 1\right) + 2} \]
      13. unpow2N/A

        \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{720}, x \cdot x, \frac{1}{24}\right), x \cdot x, \frac{1}{2}\right), \color{blue}{x \cdot x}, 1\right) + 2} \]
      14. lower-*.f6492.9

        \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.001388888888888889, x \cdot x, 0.041666666666666664\right), x \cdot x, 0.5\right), \color{blue}{x \cdot x}, 1\right) + 2} \]
    5. Applied rewrites92.9%

      \[\leadsto \frac{1}{2 \cdot \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.001388888888888889, x \cdot x, 0.041666666666666664\right), x \cdot x, 0.5\right), x \cdot x, 1\right)} + 2} \]
    6. Final simplification92.9%

      \[\leadsto {\left(2 \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.001388888888888889, x \cdot x, 0.041666666666666664\right), x \cdot x, 0.5\right), x \cdot x, 1\right) + 2\right)}^{-1} \]
    7. Add Preprocessing

    Alternative 5: 88.3% accurate, 0.9× speedup?

    \[\begin{array}{l} \\ {\left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.041666666666666664, x \cdot x, 0.5\right), x \cdot x, 1\right), 2, 2\right)\right)}^{-1} \end{array} \]
    (FPCore (x)
     :precision binary64
     (pow
      (fma (fma (fma 0.041666666666666664 (* x x) 0.5) (* x x) 1.0) 2.0 2.0)
      -1.0))
    double code(double x) {
    	return pow(fma(fma(fma(0.041666666666666664, (x * x), 0.5), (x * x), 1.0), 2.0, 2.0), -1.0);
    }
    
    function code(x)
    	return fma(fma(fma(0.041666666666666664, Float64(x * x), 0.5), Float64(x * x), 1.0), 2.0, 2.0) ^ -1.0
    end
    
    code[x_] := N[Power[N[(N[(N[(0.041666666666666664 * N[(x * x), $MachinePrecision] + 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision] * 2.0 + 2.0), $MachinePrecision], -1.0], $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    {\left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.041666666666666664, x \cdot x, 0.5\right), x \cdot x, 1\right), 2, 2\right)\right)}^{-1}
    \end{array}
    
    Derivation
    1. Initial program 100.0%

      \[\frac{1}{2 \cdot \cosh x + 2} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

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

        \[\leadsto \frac{1}{2 \cdot \color{blue}{\left({x}^{2} \cdot \left(\frac{1}{2} + \frac{1}{24} \cdot {x}^{2}\right) + 1\right)} + 2} \]
      2. *-commutativeN/A

        \[\leadsto \frac{1}{2 \cdot \left(\color{blue}{\left(\frac{1}{2} + \frac{1}{24} \cdot {x}^{2}\right) \cdot {x}^{2}} + 1\right) + 2} \]
      3. lower-fma.f64N/A

        \[\leadsto \frac{1}{2 \cdot \color{blue}{\mathsf{fma}\left(\frac{1}{2} + \frac{1}{24} \cdot {x}^{2}, {x}^{2}, 1\right)} + 2} \]
      4. +-commutativeN/A

        \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(\color{blue}{\frac{1}{24} \cdot {x}^{2} + \frac{1}{2}}, {x}^{2}, 1\right) + 2} \]
      5. lower-fma.f64N/A

        \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(\frac{1}{24}, {x}^{2}, \frac{1}{2}\right)}, {x}^{2}, 1\right) + 2} \]
      6. unpow2N/A

        \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{24}, \color{blue}{x \cdot x}, \frac{1}{2}\right), {x}^{2}, 1\right) + 2} \]
      7. lower-*.f64N/A

        \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{24}, \color{blue}{x \cdot x}, \frac{1}{2}\right), {x}^{2}, 1\right) + 2} \]
      8. unpow2N/A

        \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{24}, x \cdot x, \frac{1}{2}\right), \color{blue}{x \cdot x}, 1\right) + 2} \]
      9. lower-*.f6488.8

        \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(\mathsf{fma}\left(0.041666666666666664, x \cdot x, 0.5\right), \color{blue}{x \cdot x}, 1\right) + 2} \]
    5. Applied rewrites88.8%

      \[\leadsto \frac{1}{2 \cdot \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(0.041666666666666664, x \cdot x, 0.5\right), x \cdot x, 1\right)} + 2} \]
    6. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \frac{1}{\color{blue}{2 \cdot \mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{24}, x \cdot x, \frac{1}{2}\right), x \cdot x, 1\right) + 2}} \]
      2. lift-*.f64N/A

        \[\leadsto \frac{1}{\color{blue}{2 \cdot \mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{24}, x \cdot x, \frac{1}{2}\right), x \cdot x, 1\right)} + 2} \]
      3. *-commutativeN/A

        \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{24}, x \cdot x, \frac{1}{2}\right), x \cdot x, 1\right) \cdot 2} + 2} \]
      4. lower-fma.f6488.8

        \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.041666666666666664, x \cdot x, 0.5\right), x \cdot x, 1\right), 2, 2\right)}} \]
    7. Applied rewrites88.8%

      \[\leadsto \color{blue}{\frac{1}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.041666666666666664, x \cdot x, 0.5\right), x \cdot x, 1\right), 2, 2\right)}} \]
    8. Final simplification88.8%

      \[\leadsto {\left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.041666666666666664, x \cdot x, 0.5\right), x \cdot x, 1\right), 2, 2\right)\right)}^{-1} \]
    9. Add Preprocessing

    Alternative 6: 76.5% accurate, 1.1× speedup?

    \[\begin{array}{l} \\ {\left(\mathsf{fma}\left(x, x, 2\right) + 2\right)}^{-1} \end{array} \]
    (FPCore (x) :precision binary64 (pow (+ (fma x x 2.0) 2.0) -1.0))
    double code(double x) {
    	return pow((fma(x, x, 2.0) + 2.0), -1.0);
    }
    
    function code(x)
    	return Float64(fma(x, x, 2.0) + 2.0) ^ -1.0
    end
    
    code[x_] := N[Power[N[(N[(x * x + 2.0), $MachinePrecision] + 2.0), $MachinePrecision], -1.0], $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    {\left(\mathsf{fma}\left(x, x, 2\right) + 2\right)}^{-1}
    \end{array}
    
    Derivation
    1. Initial program 100.0%

      \[\frac{1}{2 \cdot \cosh x + 2} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

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

        \[\leadsto \frac{1}{\color{blue}{\left({x}^{2} + 2\right)} + 2} \]
      2. unpow2N/A

        \[\leadsto \frac{1}{\left(\color{blue}{x \cdot x} + 2\right) + 2} \]
      3. lower-fma.f6475.4

        \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(x, x, 2\right)} + 2} \]
    5. Applied rewrites75.4%

      \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(x, x, 2\right)} + 2} \]
    6. Final simplification75.4%

      \[\leadsto {\left(\mathsf{fma}\left(x, x, 2\right) + 2\right)}^{-1} \]
    7. Add Preprocessing

    Alternative 7: 76.5% accurate, 1.1× speedup?

    \[\begin{array}{l} \\ {\left(\mathsf{fma}\left(x, x, 4\right)\right)}^{-1} \end{array} \]
    (FPCore (x) :precision binary64 (pow (fma x x 4.0) -1.0))
    double code(double x) {
    	return pow(fma(x, x, 4.0), -1.0);
    }
    
    function code(x)
    	return fma(x, x, 4.0) ^ -1.0
    end
    
    code[x_] := N[Power[N[(x * x + 4.0), $MachinePrecision], -1.0], $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    {\left(\mathsf{fma}\left(x, x, 4\right)\right)}^{-1}
    \end{array}
    
    Derivation
    1. Initial program 100.0%

      \[\frac{1}{2 \cdot \cosh x + 2} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

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

        \[\leadsto \frac{1}{\color{blue}{{x}^{2} + 4}} \]
      2. unpow2N/A

        \[\leadsto \frac{1}{\color{blue}{x \cdot x} + 4} \]
      3. lower-fma.f6475.4

        \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(x, x, 4\right)}} \]
    5. Applied rewrites75.4%

      \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(x, x, 4\right)}} \]
    6. Final simplification75.4%

      \[\leadsto {\left(\mathsf{fma}\left(x, x, 4\right)\right)}^{-1} \]
    7. Add Preprocessing

    Alternative 8: 52.0% accurate, 120.0× speedup?

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

      \[\frac{1}{2 \cdot \cosh x + 2} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

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

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

      Reproduce

      ?
      herbie shell --seed 1 
      (FPCore (x)
        :name "1 / (2 * cosh(x) + 2)"
        :precision binary64
        :pre (and (<= -1.79e+308 x) (<= x 1.79e+308))
        (/ 1.0 (+ (* 2.0 (cosh x)) 2.0)))