Hyperbolic tangent

Percentage Accurate: 9.1% → 100.0%
Time: 9.9s
Alternatives: 7
Speedup: 70.3×

Specification

?
\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-x}\\ \frac{e^{x} - t\_0}{e^{x} + t\_0} \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (exp (- x)))) (/ (- (exp x) t_0) (+ (exp x) t_0))))
double code(double x) {
	double t_0 = exp(-x);
	return (exp(x) - t_0) / (exp(x) + t_0);
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: t_0
    t_0 = exp(-x)
    code = (exp(x) - t_0) / (exp(x) + t_0)
end function
public static double code(double x) {
	double t_0 = Math.exp(-x);
	return (Math.exp(x) - t_0) / (Math.exp(x) + t_0);
}
def code(x):
	t_0 = math.exp(-x)
	return (math.exp(x) - t_0) / (math.exp(x) + t_0)
function code(x)
	t_0 = exp(Float64(-x))
	return Float64(Float64(exp(x) - t_0) / Float64(exp(x) + t_0))
end
function tmp = code(x)
	t_0 = exp(-x);
	tmp = (exp(x) - t_0) / (exp(x) + t_0);
end
code[x_] := Block[{t$95$0 = N[Exp[(-x)], $MachinePrecision]}, N[(N[(N[Exp[x], $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[Exp[x], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{-x}\\
\frac{e^{x} - t\_0}{e^{x} + t\_0}
\end{array}
\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 7 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: 9.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-x}\\ \frac{e^{x} - t\_0}{e^{x} + t\_0} \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (exp (- x)))) (/ (- (exp x) t_0) (+ (exp x) t_0))))
double code(double x) {
	double t_0 = exp(-x);
	return (exp(x) - t_0) / (exp(x) + t_0);
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: t_0
    t_0 = exp(-x)
    code = (exp(x) - t_0) / (exp(x) + t_0)
end function
public static double code(double x) {
	double t_0 = Math.exp(-x);
	return (Math.exp(x) - t_0) / (Math.exp(x) + t_0);
}
def code(x):
	t_0 = math.exp(-x)
	return (math.exp(x) - t_0) / (math.exp(x) + t_0)
function code(x)
	t_0 = exp(Float64(-x))
	return Float64(Float64(exp(x) - t_0) / Float64(exp(x) + t_0))
end
function tmp = code(x)
	t_0 = exp(-x);
	tmp = (exp(x) - t_0) / (exp(x) + t_0);
end
code[x_] := Block[{t$95$0 = N[Exp[(-x)], $MachinePrecision]}, N[(N[(N[Exp[x], $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[Exp[x], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{-x}\\
\frac{e^{x} - t\_0}{e^{x} + t\_0}
\end{array}
\end{array}

Alternative 1: 100.0% accurate, 4.2× speedup?

\[\begin{array}{l} \\ \tanh x \end{array} \]
(FPCore (x) :precision binary64 (tanh x))
double code(double x) {
	return tanh(x);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = tanh(x)
end function
public static double code(double x) {
	return Math.tanh(x);
}
def code(x):
	return math.tanh(x)
function code(x)
	return tanh(x)
end
function tmp = code(x)
	tmp = tanh(x);
end
code[x_] := N[Tanh[x], $MachinePrecision]
\begin{array}{l}

\\
\tanh x
\end{array}
Derivation
  1. Initial program 10.0%

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

      \[\leadsto \color{blue}{\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}} \]
    2. lift--.f64N/A

      \[\leadsto \frac{\color{blue}{e^{x} - e^{-x}}}{e^{x} + e^{-x}} \]
    3. lift-exp.f64N/A

      \[\leadsto \frac{\color{blue}{e^{x}} - e^{-x}}{e^{x} + e^{-x}} \]
    4. lift-exp.f64N/A

      \[\leadsto \frac{e^{x} - \color{blue}{e^{-x}}}{e^{x} + e^{-x}} \]
    5. lift-neg.f64N/A

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

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

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

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

      \[\leadsto \frac{e^{x} - e^{\mathsf{neg}\left(x\right)}}{e^{x} + e^{\color{blue}{\mathsf{neg}\left(x\right)}}} \]
    10. tanh-undefN/A

      \[\leadsto \color{blue}{\tanh x} \]
    11. lower-tanh.f64100.0

      \[\leadsto \color{blue}{\tanh x} \]
  4. Applied rewrites100.0%

    \[\leadsto \color{blue}{\tanh x} \]
  5. Add Preprocessing

Alternative 2: 97.1% accurate, 7.5× speedup?

\[\begin{array}{l} \\ \frac{0.5}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.0010582010582010583, x \cdot x, -0.011111111111111112\right), x \cdot x, 0.16666666666666666\right), x \cdot x, 0.5\right)}{x}} \end{array} \]
(FPCore (x)
 :precision binary64
 (/
  0.5
  (/
   (fma
    (fma
     (fma 0.0010582010582010583 (* x x) -0.011111111111111112)
     (* x x)
     0.16666666666666666)
    (* x x)
    0.5)
   x)))
double code(double x) {
	return 0.5 / (fma(fma(fma(0.0010582010582010583, (x * x), -0.011111111111111112), (x * x), 0.16666666666666666), (x * x), 0.5) / x);
}
function code(x)
	return Float64(0.5 / Float64(fma(fma(fma(0.0010582010582010583, Float64(x * x), -0.011111111111111112), Float64(x * x), 0.16666666666666666), Float64(x * x), 0.5) / x))
end
code[x_] := N[(0.5 / N[(N[(N[(N[(0.0010582010582010583 * N[(x * x), $MachinePrecision] + -0.011111111111111112), $MachinePrecision] * N[(x * x), $MachinePrecision] + 0.16666666666666666), $MachinePrecision] * N[(x * x), $MachinePrecision] + 0.5), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{0.5}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.0010582010582010583, x \cdot x, -0.011111111111111112\right), x \cdot x, 0.16666666666666666\right), x \cdot x, 0.5\right)}{x}}
\end{array}
Derivation
  1. Initial program 10.0%

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

      \[\leadsto \color{blue}{\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}} \]
    2. div-invN/A

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

      \[\leadsto \color{blue}{\left(e^{x} - e^{-x}\right)} \cdot \frac{1}{e^{x} + e^{-x}} \]
    4. flip3--N/A

      \[\leadsto \color{blue}{\frac{{\left(e^{x}\right)}^{3} - {\left(e^{-x}\right)}^{3}}{e^{x} \cdot e^{x} + \left(e^{-x} \cdot e^{-x} + e^{x} \cdot e^{-x}\right)}} \cdot \frac{1}{e^{x} + e^{-x}} \]
    5. clear-numN/A

      \[\leadsto \color{blue}{\frac{1}{\frac{e^{x} \cdot e^{x} + \left(e^{-x} \cdot e^{-x} + e^{x} \cdot e^{-x}\right)}{{\left(e^{x}\right)}^{3} - {\left(e^{-x}\right)}^{3}}}} \cdot \frac{1}{e^{x} + e^{-x}} \]
    6. lift-+.f64N/A

      \[\leadsto \frac{1}{\frac{e^{x} \cdot e^{x} + \left(e^{-x} \cdot e^{-x} + e^{x} \cdot e^{-x}\right)}{{\left(e^{x}\right)}^{3} - {\left(e^{-x}\right)}^{3}}} \cdot \frac{1}{\color{blue}{e^{x} + e^{-x}}} \]
    7. lift-exp.f64N/A

      \[\leadsto \frac{1}{\frac{e^{x} \cdot e^{x} + \left(e^{-x} \cdot e^{-x} + e^{x} \cdot e^{-x}\right)}{{\left(e^{x}\right)}^{3} - {\left(e^{-x}\right)}^{3}}} \cdot \frac{1}{\color{blue}{e^{x}} + e^{-x}} \]
    8. lift-exp.f64N/A

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

      \[\leadsto \frac{1}{\frac{e^{x} \cdot e^{x} + \left(e^{-x} \cdot e^{-x} + e^{x} \cdot e^{-x}\right)}{{\left(e^{x}\right)}^{3} - {\left(e^{-x}\right)}^{3}}} \cdot \frac{1}{e^{x} + e^{\color{blue}{\mathsf{neg}\left(x\right)}}} \]
    10. cosh-undefN/A

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

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

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

    \[\leadsto \color{blue}{\frac{0.5}{\frac{0.5}{\sinh x} \cdot \cosh x}} \]
  5. Taylor expanded in x around 0

    \[\leadsto \frac{\frac{1}{2}}{\color{blue}{\frac{\frac{1}{2} + {x}^{2} \cdot \left(\frac{1}{6} + {x}^{2} \cdot \left(\frac{1}{945} \cdot {x}^{2} - \frac{1}{90}\right)\right)}{x}}} \]
  6. Step-by-step derivation
    1. lower-/.f64N/A

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

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

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

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

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

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

      \[\leadsto \frac{\frac{1}{2}}{\frac{\mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(\frac{1}{945} \cdot {x}^{2} - \frac{1}{90}, {x}^{2}, \frac{1}{6}\right)}, {x}^{2}, \frac{1}{2}\right)}{x}} \]
    8. sub-negN/A

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

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

      \[\leadsto \frac{\frac{1}{2}}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(\frac{1}{945}, {x}^{2}, \frac{-1}{90}\right)}, {x}^{2}, \frac{1}{6}\right), {x}^{2}, \frac{1}{2}\right)}{x}} \]
    11. unpow2N/A

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

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

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

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

      \[\leadsto \frac{\frac{1}{2}}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{945}, x \cdot x, \frac{-1}{90}\right), x \cdot x, \frac{1}{6}\right), \color{blue}{x \cdot x}, \frac{1}{2}\right)}{x}} \]
    16. lower-*.f6497.3

      \[\leadsto \frac{0.5}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.0010582010582010583, x \cdot x, -0.011111111111111112\right), x \cdot x, 0.16666666666666666\right), \color{blue}{x \cdot x}, 0.5\right)}{x}} \]
  7. Applied rewrites97.3%

    \[\leadsto \frac{0.5}{\color{blue}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.0010582010582010583, x \cdot x, -0.011111111111111112\right), x \cdot x, 0.16666666666666666\right), x \cdot x, 0.5\right)}{x}}} \]
  8. Add Preprocessing

Alternative 3: 96.8% accurate, 9.4× speedup?

\[\begin{array}{l} \\ \frac{0.5}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(-0.011111111111111112, x \cdot x, 0.16666666666666666\right), x \cdot x, 0.5\right)}{x}} \end{array} \]
(FPCore (x)
 :precision binary64
 (/
  0.5
  (/
   (fma (fma -0.011111111111111112 (* x x) 0.16666666666666666) (* x x) 0.5)
   x)))
double code(double x) {
	return 0.5 / (fma(fma(-0.011111111111111112, (x * x), 0.16666666666666666), (x * x), 0.5) / x);
}
function code(x)
	return Float64(0.5 / Float64(fma(fma(-0.011111111111111112, Float64(x * x), 0.16666666666666666), Float64(x * x), 0.5) / x))
end
code[x_] := N[(0.5 / N[(N[(N[(-0.011111111111111112 * N[(x * x), $MachinePrecision] + 0.16666666666666666), $MachinePrecision] * N[(x * x), $MachinePrecision] + 0.5), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{0.5}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(-0.011111111111111112, x \cdot x, 0.16666666666666666\right), x \cdot x, 0.5\right)}{x}}
\end{array}
Derivation
  1. Initial program 10.0%

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

      \[\leadsto \color{blue}{\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}} \]
    2. div-invN/A

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

      \[\leadsto \color{blue}{\left(e^{x} - e^{-x}\right)} \cdot \frac{1}{e^{x} + e^{-x}} \]
    4. flip3--N/A

      \[\leadsto \color{blue}{\frac{{\left(e^{x}\right)}^{3} - {\left(e^{-x}\right)}^{3}}{e^{x} \cdot e^{x} + \left(e^{-x} \cdot e^{-x} + e^{x} \cdot e^{-x}\right)}} \cdot \frac{1}{e^{x} + e^{-x}} \]
    5. clear-numN/A

      \[\leadsto \color{blue}{\frac{1}{\frac{e^{x} \cdot e^{x} + \left(e^{-x} \cdot e^{-x} + e^{x} \cdot e^{-x}\right)}{{\left(e^{x}\right)}^{3} - {\left(e^{-x}\right)}^{3}}}} \cdot \frac{1}{e^{x} + e^{-x}} \]
    6. lift-+.f64N/A

      \[\leadsto \frac{1}{\frac{e^{x} \cdot e^{x} + \left(e^{-x} \cdot e^{-x} + e^{x} \cdot e^{-x}\right)}{{\left(e^{x}\right)}^{3} - {\left(e^{-x}\right)}^{3}}} \cdot \frac{1}{\color{blue}{e^{x} + e^{-x}}} \]
    7. lift-exp.f64N/A

      \[\leadsto \frac{1}{\frac{e^{x} \cdot e^{x} + \left(e^{-x} \cdot e^{-x} + e^{x} \cdot e^{-x}\right)}{{\left(e^{x}\right)}^{3} - {\left(e^{-x}\right)}^{3}}} \cdot \frac{1}{\color{blue}{e^{x}} + e^{-x}} \]
    8. lift-exp.f64N/A

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

      \[\leadsto \frac{1}{\frac{e^{x} \cdot e^{x} + \left(e^{-x} \cdot e^{-x} + e^{x} \cdot e^{-x}\right)}{{\left(e^{x}\right)}^{3} - {\left(e^{-x}\right)}^{3}}} \cdot \frac{1}{e^{x} + e^{\color{blue}{\mathsf{neg}\left(x\right)}}} \]
    10. cosh-undefN/A

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

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

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

    \[\leadsto \color{blue}{\frac{0.5}{\frac{0.5}{\sinh x} \cdot \cosh x}} \]
  5. Taylor expanded in x around 0

    \[\leadsto \frac{\frac{1}{2}}{\color{blue}{\frac{\frac{1}{2} + {x}^{2} \cdot \left(\frac{1}{6} + \frac{-1}{90} \cdot {x}^{2}\right)}{x}}} \]
  6. Step-by-step derivation
    1. lower-/.f64N/A

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\frac{1}{2}}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(\frac{-1}{90}, x \cdot x, \frac{1}{6}\right), \color{blue}{x \cdot x}, \frac{1}{2}\right)}{x}} \]
    10. lower-*.f6496.9

      \[\leadsto \frac{0.5}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(-0.011111111111111112, x \cdot x, 0.16666666666666666\right), \color{blue}{x \cdot x}, 0.5\right)}{x}} \]
  7. Applied rewrites96.9%

    \[\leadsto \frac{0.5}{\color{blue}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(-0.011111111111111112, x \cdot x, 0.16666666666666666\right), x \cdot x, 0.5\right)}{x}}} \]
  8. Add Preprocessing

Alternative 4: 96.9% accurate, 14.6× speedup?

\[\begin{array}{l} \\ \frac{0.5}{\mathsf{fma}\left(0.16666666666666666, x, \frac{0.5}{x}\right)} \end{array} \]
(FPCore (x) :precision binary64 (/ 0.5 (fma 0.16666666666666666 x (/ 0.5 x))))
double code(double x) {
	return 0.5 / fma(0.16666666666666666, x, (0.5 / x));
}
function code(x)
	return Float64(0.5 / fma(0.16666666666666666, x, Float64(0.5 / x)))
end
code[x_] := N[(0.5 / N[(0.16666666666666666 * x + N[(0.5 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{0.5}{\mathsf{fma}\left(0.16666666666666666, x, \frac{0.5}{x}\right)}
\end{array}
Derivation
  1. Initial program 10.0%

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

      \[\leadsto \color{blue}{\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}} \]
    2. div-invN/A

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

      \[\leadsto \color{blue}{\left(e^{x} - e^{-x}\right)} \cdot \frac{1}{e^{x} + e^{-x}} \]
    4. flip3--N/A

      \[\leadsto \color{blue}{\frac{{\left(e^{x}\right)}^{3} - {\left(e^{-x}\right)}^{3}}{e^{x} \cdot e^{x} + \left(e^{-x} \cdot e^{-x} + e^{x} \cdot e^{-x}\right)}} \cdot \frac{1}{e^{x} + e^{-x}} \]
    5. clear-numN/A

      \[\leadsto \color{blue}{\frac{1}{\frac{e^{x} \cdot e^{x} + \left(e^{-x} \cdot e^{-x} + e^{x} \cdot e^{-x}\right)}{{\left(e^{x}\right)}^{3} - {\left(e^{-x}\right)}^{3}}}} \cdot \frac{1}{e^{x} + e^{-x}} \]
    6. lift-+.f64N/A

      \[\leadsto \frac{1}{\frac{e^{x} \cdot e^{x} + \left(e^{-x} \cdot e^{-x} + e^{x} \cdot e^{-x}\right)}{{\left(e^{x}\right)}^{3} - {\left(e^{-x}\right)}^{3}}} \cdot \frac{1}{\color{blue}{e^{x} + e^{-x}}} \]
    7. lift-exp.f64N/A

      \[\leadsto \frac{1}{\frac{e^{x} \cdot e^{x} + \left(e^{-x} \cdot e^{-x} + e^{x} \cdot e^{-x}\right)}{{\left(e^{x}\right)}^{3} - {\left(e^{-x}\right)}^{3}}} \cdot \frac{1}{\color{blue}{e^{x}} + e^{-x}} \]
    8. lift-exp.f64N/A

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

      \[\leadsto \frac{1}{\frac{e^{x} \cdot e^{x} + \left(e^{-x} \cdot e^{-x} + e^{x} \cdot e^{-x}\right)}{{\left(e^{x}\right)}^{3} - {\left(e^{-x}\right)}^{3}}} \cdot \frac{1}{e^{x} + e^{\color{blue}{\mathsf{neg}\left(x\right)}}} \]
    10. cosh-undefN/A

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

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

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

    \[\leadsto \color{blue}{\frac{0.5}{\frac{0.5}{\sinh x} \cdot \cosh x}} \]
  5. Taylor expanded in x around 0

    \[\leadsto \frac{\frac{1}{2}}{\color{blue}{\frac{\frac{1}{2} + {x}^{2} \cdot \left(\frac{1}{6} + {x}^{2} \cdot \left(\frac{1}{945} \cdot {x}^{2} - \frac{1}{90}\right)\right)}{x}}} \]
  6. Step-by-step derivation
    1. lower-/.f64N/A

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

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

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

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

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

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

      \[\leadsto \frac{\frac{1}{2}}{\frac{\mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(\frac{1}{945} \cdot {x}^{2} - \frac{1}{90}, {x}^{2}, \frac{1}{6}\right)}, {x}^{2}, \frac{1}{2}\right)}{x}} \]
    8. sub-negN/A

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

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

      \[\leadsto \frac{\frac{1}{2}}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(\frac{1}{945}, {x}^{2}, \frac{-1}{90}\right)}, {x}^{2}, \frac{1}{6}\right), {x}^{2}, \frac{1}{2}\right)}{x}} \]
    11. unpow2N/A

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

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

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

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

      \[\leadsto \frac{\frac{1}{2}}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{945}, x \cdot x, \frac{-1}{90}\right), x \cdot x, \frac{1}{6}\right), \color{blue}{x \cdot x}, \frac{1}{2}\right)}{x}} \]
    16. lower-*.f6497.3

      \[\leadsto \frac{0.5}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.0010582010582010583, x \cdot x, -0.011111111111111112\right), x \cdot x, 0.16666666666666666\right), \color{blue}{x \cdot x}, 0.5\right)}{x}} \]
  7. Applied rewrites97.3%

    \[\leadsto \frac{0.5}{\color{blue}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.0010582010582010583, x \cdot x, -0.011111111111111112\right), x \cdot x, 0.16666666666666666\right), x \cdot x, 0.5\right)}{x}}} \]
  8. Taylor expanded in x around 0

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

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

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

      \[\leadsto \frac{\frac{1}{2}}{\frac{\color{blue}{\left(\frac{1}{6} \cdot x\right) \cdot x} + \frac{1}{2}}{x}} \]
    4. metadata-evalN/A

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

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

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

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

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

      \[\leadsto \frac{\frac{1}{2}}{\frac{\color{blue}{x \cdot \left(\frac{1}{6} \cdot x + \left(\frac{1}{2} \cdot \frac{1}{{x}^{2}}\right) \cdot x\right)}}{x}} \]
    10. distribute-rgt-inN/A

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

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

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

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

      \[\leadsto \frac{\frac{1}{2}}{\color{blue}{x \cdot \left(\frac{1}{6} + \frac{1}{2} \cdot \frac{1}{{x}^{2}}\right)}} \]
    15. distribute-rgt-inN/A

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

      \[\leadsto \frac{\frac{1}{2}}{\frac{1}{6} \cdot x + \color{blue}{\frac{\frac{1}{2} \cdot 1}{{x}^{2}}} \cdot x} \]
    17. metadata-evalN/A

      \[\leadsto \frac{\frac{1}{2}}{\frac{1}{6} \cdot x + \frac{\color{blue}{\frac{1}{2}}}{{x}^{2}} \cdot x} \]
    18. associate-*l/N/A

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

      \[\leadsto \frac{\frac{1}{2}}{\frac{1}{6} \cdot x + \frac{\frac{1}{2} \cdot x}{\color{blue}{x \cdot x}}} \]
    20. times-fracN/A

      \[\leadsto \frac{\frac{1}{2}}{\frac{1}{6} \cdot x + \color{blue}{\frac{\frac{1}{2}}{x} \cdot \frac{x}{x}}} \]
    21. *-inversesN/A

      \[\leadsto \frac{\frac{1}{2}}{\frac{1}{6} \cdot x + \frac{\frac{1}{2}}{x} \cdot \color{blue}{1}} \]
  10. Applied rewrites96.9%

    \[\leadsto \frac{0.5}{\color{blue}{\mathsf{fma}\left(0.16666666666666666, x, \frac{0.5}{x}\right)}} \]
  11. Add Preprocessing

Alternative 5: 96.8% accurate, 24.8× speedup?

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

\\
\mathsf{fma}\left(\left(x \cdot x\right) \cdot x, -0.3333333333333333, x\right)
\end{array}
Derivation
  1. Initial program 10.0%

    \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\color{blue}{{x}^{2} \cdot x}, \frac{-1}{3}, x\right) \]
    8. pow-plusN/A

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

      \[\leadsto \mathsf{fma}\left(\color{blue}{{x}^{\left(2 + 1\right)}}, \frac{-1}{3}, x\right) \]
    10. metadata-eval96.8

      \[\leadsto \mathsf{fma}\left({x}^{\color{blue}{3}}, -0.3333333333333333, x\right) \]
  5. Applied rewrites96.8%

    \[\leadsto \color{blue}{\mathsf{fma}\left({x}^{3}, -0.3333333333333333, x\right)} \]
  6. Step-by-step derivation
    1. Applied rewrites96.8%

      \[\leadsto \mathsf{fma}\left(\left(x \cdot x\right) \cdot x, -0.3333333333333333, x\right) \]
    2. Add Preprocessing

    Alternative 6: 96.8% accurate, 24.8× speedup?

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

      \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\color{blue}{{x}^{2} \cdot x}, \frac{-1}{3}, x\right) \]
      8. pow-plusN/A

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

        \[\leadsto \mathsf{fma}\left(\color{blue}{{x}^{\left(2 + 1\right)}}, \frac{-1}{3}, x\right) \]
      10. metadata-eval96.8

        \[\leadsto \mathsf{fma}\left({x}^{\color{blue}{3}}, -0.3333333333333333, x\right) \]
    5. Applied rewrites96.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left({x}^{3}, -0.3333333333333333, x\right)} \]
    6. Step-by-step derivation
      1. Applied rewrites96.8%

        \[\leadsto \mathsf{fma}\left(-0.3333333333333333 \cdot x, x, 1\right) \cdot \color{blue}{x} \]
      2. Add Preprocessing

      Alternative 7: 96.6% accurate, 70.3× speedup?

      \[\begin{array}{l} \\ 1 \cdot x \end{array} \]
      (FPCore (x) :precision binary64 (* 1.0 x))
      double code(double x) {
      	return 1.0 * x;
      }
      
      real(8) function code(x)
          real(8), intent (in) :: x
          code = 1.0d0 * x
      end function
      
      public static double code(double x) {
      	return 1.0 * x;
      }
      
      def code(x):
      	return 1.0 * x
      
      function code(x)
      	return Float64(1.0 * x)
      end
      
      function tmp = code(x)
      	tmp = 1.0 * x;
      end
      
      code[x_] := N[(1.0 * x), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      1 \cdot x
      \end{array}
      
      Derivation
      1. Initial program 10.0%

        \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \]
      2. Add Preprocessing
      3. Taylor expanded in x around 0

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

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

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

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

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

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

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

          \[\leadsto \mathsf{fma}\left(\color{blue}{{x}^{2} \cdot x}, \frac{-1}{3}, x\right) \]
        8. pow-plusN/A

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

          \[\leadsto \mathsf{fma}\left(\color{blue}{{x}^{\left(2 + 1\right)}}, \frac{-1}{3}, x\right) \]
        10. metadata-eval96.8

          \[\leadsto \mathsf{fma}\left({x}^{\color{blue}{3}}, -0.3333333333333333, x\right) \]
      5. Applied rewrites96.8%

        \[\leadsto \color{blue}{\mathsf{fma}\left({x}^{3}, -0.3333333333333333, x\right)} \]
      6. Step-by-step derivation
        1. Applied rewrites96.8%

          \[\leadsto \mathsf{fma}\left(-0.3333333333333333 \cdot x, x, 1\right) \cdot \color{blue}{x} \]
        2. Taylor expanded in x around 0

          \[\leadsto 1 \cdot x \]
        3. Step-by-step derivation
          1. Applied rewrites96.3%

            \[\leadsto 1 \cdot x \]
          2. Add Preprocessing

          Reproduce

          ?
          herbie shell --seed 2024248 
          (FPCore (x)
            :name "Hyperbolic tangent"
            :precision binary64
            (/ (- (exp x) (exp (- x))) (+ (exp x) (exp (- x)))))