Hyperbolic tangent

Percentage Accurate: 8.8% → 98.3%
Time: 5.8s
Alternatives: 6
Speedup: 409.0×

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 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: 8.8% 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: 98.3% accurate, 0.1× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ x_s = \mathsf{copysign}\left(1, x\right) \\ \begin{array}{l} t_0 := {\left(\sqrt[3]{-0.05396825396825397}\right)}^{4}\\ t_1 := -0.1111111111111111 \cdot \sqrt[3]{\frac{1}{t_0}}\\ t_2 := {\left(\sqrt[3]{-0.05396825396825397}\right)}^{2}\\ t_3 := \frac{1}{t_2}\\ t_4 := \mathsf{fma}\left(-0.2222222222222222, t_3, \frac{0.037037037037037035}{t_2}\right)\\ t_5 := e^{-x_m}\\ t_6 := \frac{e^{x_m} - t_5}{e^{x_m} + t_5}\\ t_7 := \sqrt[3]{\frac{1}{\sqrt[3]{-0.05396825396825397}}}\\ x_s \cdot \begin{array}{l} \mathbf{if}\;t_6 \leq 0.005:\\ \;\;\;\;x_m + \left(-0.3333333333333333 \cdot {x_m}^{3} + \left(-0.05396825396825397 \cdot {x_m}^{7} + 0.13333333333333333 \cdot {x_m}^{5}\right)\right)\\ \mathbf{elif}\;t_6 \leq 2:\\ \;\;\;\;t_6\\ \mathbf{else}:\\ \;\;\;\;-0.05396825396825397 + \mathsf{fma}\left(x_m, \sqrt[3]{t_0}, \mathsf{fma}\left({x_m}^{2}, \mathsf{fma}\left(-0.1111111111111111, t_7, \mathsf{fma}\left(0.2222222222222222, t_7, \sqrt[3]{-0.05396825396825397} \cdot t_1\right)\right), {x_m}^{3} \cdot \mathsf{fma}\left(-0.3333333333333333, t_4, \mathsf{fma}\left(-0.07407407407407407, t_3, \mathsf{fma}\left(0.3333333333333333, t_1 \cdot \sqrt[3]{t_3}, \sqrt[3]{-0.05396825396825397} \cdot \mathsf{fma}\left(-0.6666666666666666, \frac{t_4}{\sqrt[3]{-0.05396825396825397}}, 1.3725490196078431\right)\right)\right)\right)\right)\right)\\ \end{array} \end{array} \end{array} \]
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
(FPCore (x_s x_m)
 :precision binary64
 (let* ((t_0 (pow (cbrt -0.05396825396825397) 4.0))
        (t_1 (* -0.1111111111111111 (cbrt (/ 1.0 t_0))))
        (t_2 (pow (cbrt -0.05396825396825397) 2.0))
        (t_3 (/ 1.0 t_2))
        (t_4 (fma -0.2222222222222222 t_3 (/ 0.037037037037037035 t_2)))
        (t_5 (exp (- x_m)))
        (t_6 (/ (- (exp x_m) t_5) (+ (exp x_m) t_5)))
        (t_7 (cbrt (/ 1.0 (cbrt -0.05396825396825397)))))
   (*
    x_s
    (if (<= t_6 0.005)
      (+
       x_m
       (+
        (* -0.3333333333333333 (pow x_m 3.0))
        (+
         (* -0.05396825396825397 (pow x_m 7.0))
         (* 0.13333333333333333 (pow x_m 5.0)))))
      (if (<= t_6 2.0)
        t_6
        (+
         -0.05396825396825397
         (fma
          x_m
          (cbrt t_0)
          (fma
           (pow x_m 2.0)
           (fma
            -0.1111111111111111
            t_7
            (fma 0.2222222222222222 t_7 (* (cbrt -0.05396825396825397) t_1)))
           (*
            (pow x_m 3.0)
            (fma
             -0.3333333333333333
             t_4
             (fma
              -0.07407407407407407
              t_3
              (fma
               0.3333333333333333
               (* t_1 (cbrt t_3))
               (*
                (cbrt -0.05396825396825397)
                (fma
                 -0.6666666666666666
                 (/ t_4 (cbrt -0.05396825396825397))
                 1.3725490196078431))))))))))))))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
	double t_0 = pow(cbrt(-0.05396825396825397), 4.0);
	double t_1 = -0.1111111111111111 * cbrt((1.0 / t_0));
	double t_2 = pow(cbrt(-0.05396825396825397), 2.0);
	double t_3 = 1.0 / t_2;
	double t_4 = fma(-0.2222222222222222, t_3, (0.037037037037037035 / t_2));
	double t_5 = exp(-x_m);
	double t_6 = (exp(x_m) - t_5) / (exp(x_m) + t_5);
	double t_7 = cbrt((1.0 / cbrt(-0.05396825396825397)));
	double tmp;
	if (t_6 <= 0.005) {
		tmp = x_m + ((-0.3333333333333333 * pow(x_m, 3.0)) + ((-0.05396825396825397 * pow(x_m, 7.0)) + (0.13333333333333333 * pow(x_m, 5.0))));
	} else if (t_6 <= 2.0) {
		tmp = t_6;
	} else {
		tmp = -0.05396825396825397 + fma(x_m, cbrt(t_0), fma(pow(x_m, 2.0), fma(-0.1111111111111111, t_7, fma(0.2222222222222222, t_7, (cbrt(-0.05396825396825397) * t_1))), (pow(x_m, 3.0) * fma(-0.3333333333333333, t_4, fma(-0.07407407407407407, t_3, fma(0.3333333333333333, (t_1 * cbrt(t_3)), (cbrt(-0.05396825396825397) * fma(-0.6666666666666666, (t_4 / cbrt(-0.05396825396825397)), 1.3725490196078431))))))));
	}
	return x_s * tmp;
}
x_m = abs(x)
x_s = copysign(1.0, x)
function code(x_s, x_m)
	t_0 = cbrt(-0.05396825396825397) ^ 4.0
	t_1 = Float64(-0.1111111111111111 * cbrt(Float64(1.0 / t_0)))
	t_2 = cbrt(-0.05396825396825397) ^ 2.0
	t_3 = Float64(1.0 / t_2)
	t_4 = fma(-0.2222222222222222, t_3, Float64(0.037037037037037035 / t_2))
	t_5 = exp(Float64(-x_m))
	t_6 = Float64(Float64(exp(x_m) - t_5) / Float64(exp(x_m) + t_5))
	t_7 = cbrt(Float64(1.0 / cbrt(-0.05396825396825397)))
	tmp = 0.0
	if (t_6 <= 0.005)
		tmp = Float64(x_m + Float64(Float64(-0.3333333333333333 * (x_m ^ 3.0)) + Float64(Float64(-0.05396825396825397 * (x_m ^ 7.0)) + Float64(0.13333333333333333 * (x_m ^ 5.0)))));
	elseif (t_6 <= 2.0)
		tmp = t_6;
	else
		tmp = Float64(-0.05396825396825397 + fma(x_m, cbrt(t_0), fma((x_m ^ 2.0), fma(-0.1111111111111111, t_7, fma(0.2222222222222222, t_7, Float64(cbrt(-0.05396825396825397) * t_1))), Float64((x_m ^ 3.0) * fma(-0.3333333333333333, t_4, fma(-0.07407407407407407, t_3, fma(0.3333333333333333, Float64(t_1 * cbrt(t_3)), Float64(cbrt(-0.05396825396825397) * fma(-0.6666666666666666, Float64(t_4 / cbrt(-0.05396825396825397)), 1.3725490196078431)))))))));
	end
	return Float64(x_s * tmp)
end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_] := Block[{t$95$0 = N[Power[N[Power[-0.05396825396825397, 1/3], $MachinePrecision], 4.0], $MachinePrecision]}, Block[{t$95$1 = N[(-0.1111111111111111 * N[Power[N[(1.0 / t$95$0), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Power[N[Power[-0.05396825396825397, 1/3], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$3 = N[(1.0 / t$95$2), $MachinePrecision]}, Block[{t$95$4 = N[(-0.2222222222222222 * t$95$3 + N[(0.037037037037037035 / t$95$2), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$5 = N[Exp[(-x$95$m)], $MachinePrecision]}, Block[{t$95$6 = N[(N[(N[Exp[x$95$m], $MachinePrecision] - t$95$5), $MachinePrecision] / N[(N[Exp[x$95$m], $MachinePrecision] + t$95$5), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$7 = N[Power[N[(1.0 / N[Power[-0.05396825396825397, 1/3], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]}, N[(x$95$s * If[LessEqual[t$95$6, 0.005], N[(x$95$m + N[(N[(-0.3333333333333333 * N[Power[x$95$m, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[(-0.05396825396825397 * N[Power[x$95$m, 7.0], $MachinePrecision]), $MachinePrecision] + N[(0.13333333333333333 * N[Power[x$95$m, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$6, 2.0], t$95$6, N[(-0.05396825396825397 + N[(x$95$m * N[Power[t$95$0, 1/3], $MachinePrecision] + N[(N[Power[x$95$m, 2.0], $MachinePrecision] * N[(-0.1111111111111111 * t$95$7 + N[(0.2222222222222222 * t$95$7 + N[(N[Power[-0.05396825396825397, 1/3], $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Power[x$95$m, 3.0], $MachinePrecision] * N[(-0.3333333333333333 * t$95$4 + N[(-0.07407407407407407 * t$95$3 + N[(0.3333333333333333 * N[(t$95$1 * N[Power[t$95$3, 1/3], $MachinePrecision]), $MachinePrecision] + N[(N[Power[-0.05396825396825397, 1/3], $MachinePrecision] * N[(-0.6666666666666666 * N[(t$95$4 / N[Power[-0.05396825396825397, 1/3], $MachinePrecision]), $MachinePrecision] + 1.3725490196078431), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]), $MachinePrecision]]]]]]]]]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)

\\
\begin{array}{l}
t_0 := {\left(\sqrt[3]{-0.05396825396825397}\right)}^{4}\\
t_1 := -0.1111111111111111 \cdot \sqrt[3]{\frac{1}{t_0}}\\
t_2 := {\left(\sqrt[3]{-0.05396825396825397}\right)}^{2}\\
t_3 := \frac{1}{t_2}\\
t_4 := \mathsf{fma}\left(-0.2222222222222222, t_3, \frac{0.037037037037037035}{t_2}\right)\\
t_5 := e^{-x_m}\\
t_6 := \frac{e^{x_m} - t_5}{e^{x_m} + t_5}\\
t_7 := \sqrt[3]{\frac{1}{\sqrt[3]{-0.05396825396825397}}}\\
x_s \cdot \begin{array}{l}
\mathbf{if}\;t_6 \leq 0.005:\\
\;\;\;\;x_m + \left(-0.3333333333333333 \cdot {x_m}^{3} + \left(-0.05396825396825397 \cdot {x_m}^{7} + 0.13333333333333333 \cdot {x_m}^{5}\right)\right)\\

\mathbf{elif}\;t_6 \leq 2:\\
\;\;\;\;t_6\\

\mathbf{else}:\\
\;\;\;\;-0.05396825396825397 + \mathsf{fma}\left(x_m, \sqrt[3]{t_0}, \mathsf{fma}\left({x_m}^{2}, \mathsf{fma}\left(-0.1111111111111111, t_7, \mathsf{fma}\left(0.2222222222222222, t_7, \sqrt[3]{-0.05396825396825397} \cdot t_1\right)\right), {x_m}^{3} \cdot \mathsf{fma}\left(-0.3333333333333333, t_4, \mathsf{fma}\left(-0.07407407407407407, t_3, \mathsf{fma}\left(0.3333333333333333, t_1 \cdot \sqrt[3]{t_3}, \sqrt[3]{-0.05396825396825397} \cdot \mathsf{fma}\left(-0.6666666666666666, \frac{t_4}{\sqrt[3]{-0.05396825396825397}}, 1.3725490196078431\right)\right)\right)\right)\right)\right)\\


\end{array}
\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (/.f64 (-.f64 (exp.f64 x) (exp.f64 (neg.f64 x))) (+.f64 (exp.f64 x) (exp.f64 (neg.f64 x)))) < 0.0050000000000000001

    1. Initial program 7.4%

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

      \[\leadsto \color{blue}{x + \left(-0.3333333333333333 \cdot {x}^{3} + \left(-0.05396825396825397 \cdot {x}^{7} + 0.13333333333333333 \cdot {x}^{5}\right)\right)} \]

    if 0.0050000000000000001 < (/.f64 (-.f64 (exp.f64 x) (exp.f64 (neg.f64 x))) (+.f64 (exp.f64 x) (exp.f64 (neg.f64 x)))) < 2

    1. Initial program 99.6%

      \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \]
    2. Add Preprocessing

    if 2 < (/.f64 (-.f64 (exp.f64 x) (exp.f64 (neg.f64 x))) (+.f64 (exp.f64 x) (exp.f64 (neg.f64 x))))

    1. Initial program 0.0%

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

      \[\leadsto \color{blue}{x + -0.3333333333333333 \cdot {x}^{3}} \]
    4. Step-by-step derivation
      1. *-commutative1.5%

        \[\leadsto x + \color{blue}{{x}^{3} \cdot -0.3333333333333333} \]
    5. Simplified1.5%

      \[\leadsto \color{blue}{x + {x}^{3} \cdot -0.3333333333333333} \]
    6. Applied egg-rr12.4%

      \[\leadsto x + \color{blue}{-0.05396825396825397} \]
    7. Step-by-step derivation
      1. add-cube-cbrt12.4%

        \[\leadsto \color{blue}{\left(\sqrt[3]{x + -0.05396825396825397} \cdot \sqrt[3]{x + -0.05396825396825397}\right) \cdot \sqrt[3]{x + -0.05396825396825397}} \]
      2. pow312.4%

        \[\leadsto \color{blue}{{\left(\sqrt[3]{x + -0.05396825396825397}\right)}^{3}} \]
    8. Applied egg-rr12.4%

      \[\leadsto \color{blue}{{\left(\sqrt[3]{x + -0.05396825396825397}\right)}^{3}} \]
    9. Taylor expanded in x around 0 0.0%

      \[\leadsto \color{blue}{\left(x \cdot \left(0.3333333333333333 \cdot {\left(1 \cdot {\left(\sqrt[3]{-0.05396825396825397}\right)}^{4}\right)}^{0.3333333333333333} + 0.6666666666666666 \cdot {\left(1 \cdot {\left(\sqrt[3]{-0.05396825396825397}\right)}^{4}\right)}^{0.3333333333333333}\right) + \left({x}^{2} \cdot \left(-0.1111111111111111 \cdot {\left(\frac{1}{\sqrt[3]{-0.05396825396825397}}\right)}^{0.3333333333333333} + \left(0.2222222222222222 \cdot {\left(\frac{1}{\sqrt[3]{-0.05396825396825397}}\right)}^{0.3333333333333333} + \sqrt[3]{-0.05396825396825397} \cdot \left(-0.2222222222222222 \cdot {\left(\frac{1}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{4}}\right)}^{0.3333333333333333} + 0.1111111111111111 \cdot {\left(\frac{1}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{4}}\right)}^{0.3333333333333333}\right)\right)\right) + {x}^{3} \cdot \left(-0.3333333333333333 \cdot \left(-0.2222222222222222 \cdot \left({1}^{0.3333333333333333} \cdot \frac{1}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{2}}\right) + 0.037037037037037035 \cdot \frac{1}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{2}}\right) + \left(-0.07407407407407407 \cdot \left({1}^{0.3333333333333333} \cdot \frac{1}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{2}}\right) + \left(0.3333333333333333 \cdot \left({\left(\frac{1}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{2}}\right)}^{0.3333333333333333} \cdot \left(-0.2222222222222222 \cdot {\left(\frac{1}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{4}}\right)}^{0.3333333333333333} + 0.1111111111111111 \cdot {\left(\frac{1}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{4}}\right)}^{0.3333333333333333}\right)\right) + \sqrt[3]{-0.05396825396825397} \cdot \left(-0.6666666666666666 \cdot \frac{-0.2222222222222222 \cdot \left({1}^{0.3333333333333333} \cdot \frac{1}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{2}}\right) + 0.037037037037037035 \cdot \frac{1}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{2}}}{\sqrt[3]{-0.05396825396825397}} + 1.3725490196078431 \cdot {1}^{0.3333333333333333}\right)\right)\right)\right)\right)\right) - 0.05396825396825397} \]
    10. Simplified12.7%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \sqrt[3]{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{4}} \cdot 1, \mathsf{fma}\left({x}^{2}, \mathsf{fma}\left(-0.1111111111111111, \sqrt[3]{\frac{1}{\sqrt[3]{-0.05396825396825397}}}, \mathsf{fma}\left(0.2222222222222222, \sqrt[3]{\frac{1}{\sqrt[3]{-0.05396825396825397}}}, \sqrt[3]{-0.05396825396825397} \cdot \left(\sqrt[3]{\frac{1}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{4}}} \cdot -0.1111111111111111\right)\right)\right), {x}^{3} \cdot \mathsf{fma}\left(-0.3333333333333333, \mathsf{fma}\left(-0.2222222222222222, \frac{1}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{2}}, \frac{0.037037037037037035}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{2}}\right), \mathsf{fma}\left(-0.07407407407407407, \frac{1}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{2}}, \mathsf{fma}\left(0.3333333333333333, \left(\sqrt[3]{\frac{1}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{4}}} \cdot -0.1111111111111111\right) \cdot \sqrt[3]{\frac{1}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{2}}}, \sqrt[3]{-0.05396825396825397} \cdot \mathsf{fma}\left(-0.6666666666666666, \frac{\mathsf{fma}\left(-0.2222222222222222, \frac{1}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{2}}, \frac{0.037037037037037035}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{2}}\right)}{\sqrt[3]{-0.05396825396825397}}, 1.3725490196078431\right)\right)\right)\right)\right)\right) + -0.05396825396825397} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification96.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \leq 0.005:\\ \;\;\;\;x + \left(-0.3333333333333333 \cdot {x}^{3} + \left(-0.05396825396825397 \cdot {x}^{7} + 0.13333333333333333 \cdot {x}^{5}\right)\right)\\ \mathbf{elif}\;\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \leq 2:\\ \;\;\;\;\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}\\ \mathbf{else}:\\ \;\;\;\;-0.05396825396825397 + \mathsf{fma}\left(x, \sqrt[3]{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{4}}, \mathsf{fma}\left({x}^{2}, \mathsf{fma}\left(-0.1111111111111111, \sqrt[3]{\frac{1}{\sqrt[3]{-0.05396825396825397}}}, \mathsf{fma}\left(0.2222222222222222, \sqrt[3]{\frac{1}{\sqrt[3]{-0.05396825396825397}}}, \sqrt[3]{-0.05396825396825397} \cdot \left(-0.1111111111111111 \cdot \sqrt[3]{\frac{1}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{4}}}\right)\right)\right), {x}^{3} \cdot \mathsf{fma}\left(-0.3333333333333333, \mathsf{fma}\left(-0.2222222222222222, \frac{1}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{2}}, \frac{0.037037037037037035}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{2}}\right), \mathsf{fma}\left(-0.07407407407407407, \frac{1}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{2}}, \mathsf{fma}\left(0.3333333333333333, \left(-0.1111111111111111 \cdot \sqrt[3]{\frac{1}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{4}}}\right) \cdot \sqrt[3]{\frac{1}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{2}}}, \sqrt[3]{-0.05396825396825397} \cdot \mathsf{fma}\left(-0.6666666666666666, \frac{\mathsf{fma}\left(-0.2222222222222222, \frac{1}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{2}}, \frac{0.037037037037037035}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{2}}\right)}{\sqrt[3]{-0.05396825396825397}}, 1.3725490196078431\right)\right)\right)\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 98.3% accurate, 0.1× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ x_s = \mathsf{copysign}\left(1, x\right) \\ \begin{array}{l} t_0 := {\left(\sqrt[3]{-0.05396825396825397}\right)}^{2}\\ t_1 := e^{-x_m}\\ t_2 := \frac{e^{x_m} - t_1}{e^{x_m} + t_1}\\ t_3 := \sqrt[3]{\frac{-18.529411764705884}{\sqrt[3]{-0.05396825396825397}}}\\ t_4 := \frac{-0.18518518518518517}{t_0}\\ x_s \cdot \begin{array}{l} \mathbf{if}\;t_2 \leq 0.005:\\ \;\;\;\;x_m + \left(-0.3333333333333333 \cdot {x_m}^{3} + \left(-0.05396825396825397 \cdot {x_m}^{7} + 0.13333333333333333 \cdot {x_m}^{5}\right)\right)\\ \mathbf{elif}\;t_2 \leq 2:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x_m, \sqrt[3]{-0.05396825396825397 \cdot \sqrt[3]{-0.05396825396825397}}, -0.05396825396825397\right) + {x_m}^{2} \cdot \left(\left(t_3 \cdot \left(\sqrt[3]{-0.05396825396825397} \cdot -0.1111111111111111\right) + \sqrt[3]{\frac{1}{\sqrt[3]{-0.05396825396825397}}} \cdot 0.1111111111111111\right) + x_m \cdot \left(\mathsf{fma}\left(\sqrt[3]{-0.05396825396825397}, \mathsf{fma}\left(-0.6666666666666666, \frac{t_4}{\sqrt[3]{-0.05396825396825397}}, 1.3725490196078431\right), \left(-0.1111111111111111 \cdot t_3\right) \cdot \left(0.3333333333333333 \cdot \sqrt[3]{\frac{1}{t_0}}\right)\right) + \mathsf{fma}\left(-0.3333333333333333, t_4, \frac{-0.07407407407407407}{t_0}\right)\right)\right)\\ \end{array} \end{array} \end{array} \]
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
(FPCore (x_s x_m)
 :precision binary64
 (let* ((t_0 (pow (cbrt -0.05396825396825397) 2.0))
        (t_1 (exp (- x_m)))
        (t_2 (/ (- (exp x_m) t_1) (+ (exp x_m) t_1)))
        (t_3 (cbrt (/ -18.529411764705884 (cbrt -0.05396825396825397))))
        (t_4 (/ -0.18518518518518517 t_0)))
   (*
    x_s
    (if (<= t_2 0.005)
      (+
       x_m
       (+
        (* -0.3333333333333333 (pow x_m 3.0))
        (+
         (* -0.05396825396825397 (pow x_m 7.0))
         (* 0.13333333333333333 (pow x_m 5.0)))))
      (if (<= t_2 2.0)
        t_2
        (+
         (fma
          x_m
          (cbrt (* -0.05396825396825397 (cbrt -0.05396825396825397)))
          -0.05396825396825397)
         (*
          (pow x_m 2.0)
          (+
           (+
            (* t_3 (* (cbrt -0.05396825396825397) -0.1111111111111111))
            (* (cbrt (/ 1.0 (cbrt -0.05396825396825397))) 0.1111111111111111))
           (*
            x_m
            (+
             (fma
              (cbrt -0.05396825396825397)
              (fma
               -0.6666666666666666
               (/ t_4 (cbrt -0.05396825396825397))
               1.3725490196078431)
              (*
               (* -0.1111111111111111 t_3)
               (* 0.3333333333333333 (cbrt (/ 1.0 t_0)))))
             (fma
              -0.3333333333333333
              t_4
              (/ -0.07407407407407407 t_0))))))))))))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
	double t_0 = pow(cbrt(-0.05396825396825397), 2.0);
	double t_1 = exp(-x_m);
	double t_2 = (exp(x_m) - t_1) / (exp(x_m) + t_1);
	double t_3 = cbrt((-18.529411764705884 / cbrt(-0.05396825396825397)));
	double t_4 = -0.18518518518518517 / t_0;
	double tmp;
	if (t_2 <= 0.005) {
		tmp = x_m + ((-0.3333333333333333 * pow(x_m, 3.0)) + ((-0.05396825396825397 * pow(x_m, 7.0)) + (0.13333333333333333 * pow(x_m, 5.0))));
	} else if (t_2 <= 2.0) {
		tmp = t_2;
	} else {
		tmp = fma(x_m, cbrt((-0.05396825396825397 * cbrt(-0.05396825396825397))), -0.05396825396825397) + (pow(x_m, 2.0) * (((t_3 * (cbrt(-0.05396825396825397) * -0.1111111111111111)) + (cbrt((1.0 / cbrt(-0.05396825396825397))) * 0.1111111111111111)) + (x_m * (fma(cbrt(-0.05396825396825397), fma(-0.6666666666666666, (t_4 / cbrt(-0.05396825396825397)), 1.3725490196078431), ((-0.1111111111111111 * t_3) * (0.3333333333333333 * cbrt((1.0 / t_0))))) + fma(-0.3333333333333333, t_4, (-0.07407407407407407 / t_0))))));
	}
	return x_s * tmp;
}
x_m = abs(x)
x_s = copysign(1.0, x)
function code(x_s, x_m)
	t_0 = cbrt(-0.05396825396825397) ^ 2.0
	t_1 = exp(Float64(-x_m))
	t_2 = Float64(Float64(exp(x_m) - t_1) / Float64(exp(x_m) + t_1))
	t_3 = cbrt(Float64(-18.529411764705884 / cbrt(-0.05396825396825397)))
	t_4 = Float64(-0.18518518518518517 / t_0)
	tmp = 0.0
	if (t_2 <= 0.005)
		tmp = Float64(x_m + Float64(Float64(-0.3333333333333333 * (x_m ^ 3.0)) + Float64(Float64(-0.05396825396825397 * (x_m ^ 7.0)) + Float64(0.13333333333333333 * (x_m ^ 5.0)))));
	elseif (t_2 <= 2.0)
		tmp = t_2;
	else
		tmp = Float64(fma(x_m, cbrt(Float64(-0.05396825396825397 * cbrt(-0.05396825396825397))), -0.05396825396825397) + Float64((x_m ^ 2.0) * Float64(Float64(Float64(t_3 * Float64(cbrt(-0.05396825396825397) * -0.1111111111111111)) + Float64(cbrt(Float64(1.0 / cbrt(-0.05396825396825397))) * 0.1111111111111111)) + Float64(x_m * Float64(fma(cbrt(-0.05396825396825397), fma(-0.6666666666666666, Float64(t_4 / cbrt(-0.05396825396825397)), 1.3725490196078431), Float64(Float64(-0.1111111111111111 * t_3) * Float64(0.3333333333333333 * cbrt(Float64(1.0 / t_0))))) + fma(-0.3333333333333333, t_4, Float64(-0.07407407407407407 / t_0)))))));
	end
	return Float64(x_s * tmp)
end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_] := Block[{t$95$0 = N[Power[N[Power[-0.05396825396825397, 1/3], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[Exp[(-x$95$m)], $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[Exp[x$95$m], $MachinePrecision] - t$95$1), $MachinePrecision] / N[(N[Exp[x$95$m], $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[Power[N[(-18.529411764705884 / N[Power[-0.05396825396825397, 1/3], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]}, Block[{t$95$4 = N[(-0.18518518518518517 / t$95$0), $MachinePrecision]}, N[(x$95$s * If[LessEqual[t$95$2, 0.005], N[(x$95$m + N[(N[(-0.3333333333333333 * N[Power[x$95$m, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[(-0.05396825396825397 * N[Power[x$95$m, 7.0], $MachinePrecision]), $MachinePrecision] + N[(0.13333333333333333 * N[Power[x$95$m, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 2.0], t$95$2, N[(N[(x$95$m * N[Power[N[(-0.05396825396825397 * N[Power[-0.05396825396825397, 1/3], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + -0.05396825396825397), $MachinePrecision] + N[(N[Power[x$95$m, 2.0], $MachinePrecision] * N[(N[(N[(t$95$3 * N[(N[Power[-0.05396825396825397, 1/3], $MachinePrecision] * -0.1111111111111111), $MachinePrecision]), $MachinePrecision] + N[(N[Power[N[(1.0 / N[Power[-0.05396825396825397, 1/3], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] * 0.1111111111111111), $MachinePrecision]), $MachinePrecision] + N[(x$95$m * N[(N[(N[Power[-0.05396825396825397, 1/3], $MachinePrecision] * N[(-0.6666666666666666 * N[(t$95$4 / N[Power[-0.05396825396825397, 1/3], $MachinePrecision]), $MachinePrecision] + 1.3725490196078431), $MachinePrecision] + N[(N[(-0.1111111111111111 * t$95$3), $MachinePrecision] * N[(0.3333333333333333 * N[Power[N[(1.0 / t$95$0), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-0.3333333333333333 * t$95$4 + N[(-0.07407407407407407 / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]), $MachinePrecision]]]]]]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)

\\
\begin{array}{l}
t_0 := {\left(\sqrt[3]{-0.05396825396825397}\right)}^{2}\\
t_1 := e^{-x_m}\\
t_2 := \frac{e^{x_m} - t_1}{e^{x_m} + t_1}\\
t_3 := \sqrt[3]{\frac{-18.529411764705884}{\sqrt[3]{-0.05396825396825397}}}\\
t_4 := \frac{-0.18518518518518517}{t_0}\\
x_s \cdot \begin{array}{l}
\mathbf{if}\;t_2 \leq 0.005:\\
\;\;\;\;x_m + \left(-0.3333333333333333 \cdot {x_m}^{3} + \left(-0.05396825396825397 \cdot {x_m}^{7} + 0.13333333333333333 \cdot {x_m}^{5}\right)\right)\\

\mathbf{elif}\;t_2 \leq 2:\\
\;\;\;\;t_2\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x_m, \sqrt[3]{-0.05396825396825397 \cdot \sqrt[3]{-0.05396825396825397}}, -0.05396825396825397\right) + {x_m}^{2} \cdot \left(\left(t_3 \cdot \left(\sqrt[3]{-0.05396825396825397} \cdot -0.1111111111111111\right) + \sqrt[3]{\frac{1}{\sqrt[3]{-0.05396825396825397}}} \cdot 0.1111111111111111\right) + x_m \cdot \left(\mathsf{fma}\left(\sqrt[3]{-0.05396825396825397}, \mathsf{fma}\left(-0.6666666666666666, \frac{t_4}{\sqrt[3]{-0.05396825396825397}}, 1.3725490196078431\right), \left(-0.1111111111111111 \cdot t_3\right) \cdot \left(0.3333333333333333 \cdot \sqrt[3]{\frac{1}{t_0}}\right)\right) + \mathsf{fma}\left(-0.3333333333333333, t_4, \frac{-0.07407407407407407}{t_0}\right)\right)\right)\\


\end{array}
\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (/.f64 (-.f64 (exp.f64 x) (exp.f64 (neg.f64 x))) (+.f64 (exp.f64 x) (exp.f64 (neg.f64 x)))) < 0.0050000000000000001

    1. Initial program 7.4%

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

      \[\leadsto \color{blue}{x + \left(-0.3333333333333333 \cdot {x}^{3} + \left(-0.05396825396825397 \cdot {x}^{7} + 0.13333333333333333 \cdot {x}^{5}\right)\right)} \]

    if 0.0050000000000000001 < (/.f64 (-.f64 (exp.f64 x) (exp.f64 (neg.f64 x))) (+.f64 (exp.f64 x) (exp.f64 (neg.f64 x)))) < 2

    1. Initial program 99.6%

      \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \]
    2. Add Preprocessing

    if 2 < (/.f64 (-.f64 (exp.f64 x) (exp.f64 (neg.f64 x))) (+.f64 (exp.f64 x) (exp.f64 (neg.f64 x))))

    1. Initial program 0.0%

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

      \[\leadsto \color{blue}{x + -0.3333333333333333 \cdot {x}^{3}} \]
    4. Step-by-step derivation
      1. *-commutative1.5%

        \[\leadsto x + \color{blue}{{x}^{3} \cdot -0.3333333333333333} \]
    5. Simplified1.5%

      \[\leadsto \color{blue}{x + {x}^{3} \cdot -0.3333333333333333} \]
    6. Applied egg-rr12.4%

      \[\leadsto x + \color{blue}{-0.05396825396825397} \]
    7. Step-by-step derivation
      1. add-cube-cbrt12.4%

        \[\leadsto \color{blue}{\left(\sqrt[3]{x + -0.05396825396825397} \cdot \sqrt[3]{x + -0.05396825396825397}\right) \cdot \sqrt[3]{x + -0.05396825396825397}} \]
      2. pow312.4%

        \[\leadsto \color{blue}{{\left(\sqrt[3]{x + -0.05396825396825397}\right)}^{3}} \]
    8. Applied egg-rr12.4%

      \[\leadsto \color{blue}{{\left(\sqrt[3]{x + -0.05396825396825397}\right)}^{3}} \]
    9. Taylor expanded in x around 0 0.0%

      \[\leadsto \color{blue}{\left(x \cdot \left(0.3333333333333333 \cdot {\left(1 \cdot {\left(\sqrt[3]{-0.05396825396825397}\right)}^{4}\right)}^{0.3333333333333333} + 0.6666666666666666 \cdot {\left(1 \cdot {\left(\sqrt[3]{-0.05396825396825397}\right)}^{4}\right)}^{0.3333333333333333}\right) + \left({x}^{2} \cdot \left(-0.1111111111111111 \cdot {\left(\frac{1}{\sqrt[3]{-0.05396825396825397}}\right)}^{0.3333333333333333} + \left(0.2222222222222222 \cdot {\left(\frac{1}{\sqrt[3]{-0.05396825396825397}}\right)}^{0.3333333333333333} + \sqrt[3]{-0.05396825396825397} \cdot \left(-0.2222222222222222 \cdot {\left(\frac{1}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{4}}\right)}^{0.3333333333333333} + 0.1111111111111111 \cdot {\left(\frac{1}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{4}}\right)}^{0.3333333333333333}\right)\right)\right) + {x}^{3} \cdot \left(-0.3333333333333333 \cdot \left(-0.2222222222222222 \cdot \left({1}^{0.3333333333333333} \cdot \frac{1}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{2}}\right) + 0.037037037037037035 \cdot \frac{1}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{2}}\right) + \left(-0.07407407407407407 \cdot \left({1}^{0.3333333333333333} \cdot \frac{1}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{2}}\right) + \left(0.3333333333333333 \cdot \left({\left(\frac{1}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{2}}\right)}^{0.3333333333333333} \cdot \left(-0.2222222222222222 \cdot {\left(\frac{1}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{4}}\right)}^{0.3333333333333333} + 0.1111111111111111 \cdot {\left(\frac{1}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{4}}\right)}^{0.3333333333333333}\right)\right) + \sqrt[3]{-0.05396825396825397} \cdot \left(-0.6666666666666666 \cdot \frac{-0.2222222222222222 \cdot \left({1}^{0.3333333333333333} \cdot \frac{1}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{2}}\right) + 0.037037037037037035 \cdot \frac{1}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{2}}}{\sqrt[3]{-0.05396825396825397}} + 1.3725490196078431 \cdot {1}^{0.3333333333333333}\right)\right)\right)\right)\right)\right) - 0.05396825396825397} \]
    10. Simplified12.7%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \sqrt[3]{-0.05396825396825397 \cdot \sqrt[3]{-0.05396825396825397}}, -0.05396825396825397\right) + {x}^{2} \cdot \left(\left(\sqrt[3]{\frac{-18.529411764705884}{\sqrt[3]{-0.05396825396825397}}} \cdot \left(-0.1111111111111111 \cdot \sqrt[3]{-0.05396825396825397}\right) + \sqrt[3]{\frac{1}{\sqrt[3]{-0.05396825396825397}}} \cdot 0.1111111111111111\right) + x \cdot \left(\mathsf{fma}\left(\sqrt[3]{-0.05396825396825397}, \mathsf{fma}\left(-0.6666666666666666, \frac{\frac{-0.18518518518518517}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{2}}}{\sqrt[3]{-0.05396825396825397}}, 1.3725490196078431\right), \left(-0.1111111111111111 \cdot \sqrt[3]{\frac{-18.529411764705884}{\sqrt[3]{-0.05396825396825397}}}\right) \cdot \left(0.3333333333333333 \cdot \sqrt[3]{\frac{1}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{2}}}\right)\right) + \mathsf{fma}\left(-0.3333333333333333, \frac{-0.18518518518518517}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{2}}, \frac{-0.07407407407407407}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{2}}\right)\right)\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification96.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \leq 0.005:\\ \;\;\;\;x + \left(-0.3333333333333333 \cdot {x}^{3} + \left(-0.05396825396825397 \cdot {x}^{7} + 0.13333333333333333 \cdot {x}^{5}\right)\right)\\ \mathbf{elif}\;\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \leq 2:\\ \;\;\;\;\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, \sqrt[3]{-0.05396825396825397 \cdot \sqrt[3]{-0.05396825396825397}}, -0.05396825396825397\right) + {x}^{2} \cdot \left(\left(\sqrt[3]{\frac{-18.529411764705884}{\sqrt[3]{-0.05396825396825397}}} \cdot \left(\sqrt[3]{-0.05396825396825397} \cdot -0.1111111111111111\right) + \sqrt[3]{\frac{1}{\sqrt[3]{-0.05396825396825397}}} \cdot 0.1111111111111111\right) + x \cdot \left(\mathsf{fma}\left(\sqrt[3]{-0.05396825396825397}, \mathsf{fma}\left(-0.6666666666666666, \frac{\frac{-0.18518518518518517}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{2}}}{\sqrt[3]{-0.05396825396825397}}, 1.3725490196078431\right), \left(-0.1111111111111111 \cdot \sqrt[3]{\frac{-18.529411764705884}{\sqrt[3]{-0.05396825396825397}}}\right) \cdot \left(0.3333333333333333 \cdot \sqrt[3]{\frac{1}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{2}}}\right)\right) + \mathsf{fma}\left(-0.3333333333333333, \frac{-0.18518518518518517}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{2}}, \frac{-0.07407407407407407}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{2}}\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 98.3% accurate, 0.3× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ x_s = \mathsf{copysign}\left(1, x\right) \\ \begin{array}{l} t_0 := e^{-x_m}\\ t_1 := \frac{e^{x_m} - t_0}{e^{x_m} + t_0}\\ x_s \cdot \begin{array}{l} \mathbf{if}\;t_1 \leq 0.005:\\ \;\;\;\;x_m + \left(-0.3333333333333333 \cdot {x_m}^{3} + \left(-0.05396825396825397 \cdot {x_m}^{7} + 0.13333333333333333 \cdot {x_m}^{5}\right)\right)\\ \mathbf{elif}\;t_1 \leq 2:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x_m, \sqrt[3]{-0.05396825396825397 \cdot \sqrt[3]{-0.05396825396825397}}, -0.05396825396825397\right)\\ \end{array} \end{array} \end{array} \]
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
(FPCore (x_s x_m)
 :precision binary64
 (let* ((t_0 (exp (- x_m))) (t_1 (/ (- (exp x_m) t_0) (+ (exp x_m) t_0))))
   (*
    x_s
    (if (<= t_1 0.005)
      (+
       x_m
       (+
        (* -0.3333333333333333 (pow x_m 3.0))
        (+
         (* -0.05396825396825397 (pow x_m 7.0))
         (* 0.13333333333333333 (pow x_m 5.0)))))
      (if (<= t_1 2.0)
        t_1
        (fma
         x_m
         (cbrt (* -0.05396825396825397 (cbrt -0.05396825396825397)))
         -0.05396825396825397))))))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
	double t_0 = exp(-x_m);
	double t_1 = (exp(x_m) - t_0) / (exp(x_m) + t_0);
	double tmp;
	if (t_1 <= 0.005) {
		tmp = x_m + ((-0.3333333333333333 * pow(x_m, 3.0)) + ((-0.05396825396825397 * pow(x_m, 7.0)) + (0.13333333333333333 * pow(x_m, 5.0))));
	} else if (t_1 <= 2.0) {
		tmp = t_1;
	} else {
		tmp = fma(x_m, cbrt((-0.05396825396825397 * cbrt(-0.05396825396825397))), -0.05396825396825397);
	}
	return x_s * tmp;
}
x_m = abs(x)
x_s = copysign(1.0, x)
function code(x_s, x_m)
	t_0 = exp(Float64(-x_m))
	t_1 = Float64(Float64(exp(x_m) - t_0) / Float64(exp(x_m) + t_0))
	tmp = 0.0
	if (t_1 <= 0.005)
		tmp = Float64(x_m + Float64(Float64(-0.3333333333333333 * (x_m ^ 3.0)) + Float64(Float64(-0.05396825396825397 * (x_m ^ 7.0)) + Float64(0.13333333333333333 * (x_m ^ 5.0)))));
	elseif (t_1 <= 2.0)
		tmp = t_1;
	else
		tmp = fma(x_m, cbrt(Float64(-0.05396825396825397 * cbrt(-0.05396825396825397))), -0.05396825396825397);
	end
	return Float64(x_s * tmp)
end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_] := Block[{t$95$0 = N[Exp[(-x$95$m)], $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[Exp[x$95$m], $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[Exp[x$95$m], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]}, N[(x$95$s * If[LessEqual[t$95$1, 0.005], N[(x$95$m + N[(N[(-0.3333333333333333 * N[Power[x$95$m, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[(-0.05396825396825397 * N[Power[x$95$m, 7.0], $MachinePrecision]), $MachinePrecision] + N[(0.13333333333333333 * N[Power[x$95$m, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2.0], t$95$1, N[(x$95$m * N[Power[N[(-0.05396825396825397 * N[Power[-0.05396825396825397, 1/3], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + -0.05396825396825397), $MachinePrecision]]]), $MachinePrecision]]]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)

\\
\begin{array}{l}
t_0 := e^{-x_m}\\
t_1 := \frac{e^{x_m} - t_0}{e^{x_m} + t_0}\\
x_s \cdot \begin{array}{l}
\mathbf{if}\;t_1 \leq 0.005:\\
\;\;\;\;x_m + \left(-0.3333333333333333 \cdot {x_m}^{3} + \left(-0.05396825396825397 \cdot {x_m}^{7} + 0.13333333333333333 \cdot {x_m}^{5}\right)\right)\\

\mathbf{elif}\;t_1 \leq 2:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x_m, \sqrt[3]{-0.05396825396825397 \cdot \sqrt[3]{-0.05396825396825397}}, -0.05396825396825397\right)\\


\end{array}
\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (/.f64 (-.f64 (exp.f64 x) (exp.f64 (neg.f64 x))) (+.f64 (exp.f64 x) (exp.f64 (neg.f64 x)))) < 0.0050000000000000001

    1. Initial program 7.4%

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

      \[\leadsto \color{blue}{x + \left(-0.3333333333333333 \cdot {x}^{3} + \left(-0.05396825396825397 \cdot {x}^{7} + 0.13333333333333333 \cdot {x}^{5}\right)\right)} \]

    if 0.0050000000000000001 < (/.f64 (-.f64 (exp.f64 x) (exp.f64 (neg.f64 x))) (+.f64 (exp.f64 x) (exp.f64 (neg.f64 x)))) < 2

    1. Initial program 99.6%

      \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \]
    2. Add Preprocessing

    if 2 < (/.f64 (-.f64 (exp.f64 x) (exp.f64 (neg.f64 x))) (+.f64 (exp.f64 x) (exp.f64 (neg.f64 x))))

    1. Initial program 0.0%

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

      \[\leadsto \color{blue}{x + -0.3333333333333333 \cdot {x}^{3}} \]
    4. Step-by-step derivation
      1. *-commutative1.5%

        \[\leadsto x + \color{blue}{{x}^{3} \cdot -0.3333333333333333} \]
    5. Simplified1.5%

      \[\leadsto \color{blue}{x + {x}^{3} \cdot -0.3333333333333333} \]
    6. Applied egg-rr12.4%

      \[\leadsto x + \color{blue}{-0.05396825396825397} \]
    7. Step-by-step derivation
      1. add-cube-cbrt12.4%

        \[\leadsto \color{blue}{\left(\sqrt[3]{x + -0.05396825396825397} \cdot \sqrt[3]{x + -0.05396825396825397}\right) \cdot \sqrt[3]{x + -0.05396825396825397}} \]
      2. pow312.4%

        \[\leadsto \color{blue}{{\left(\sqrt[3]{x + -0.05396825396825397}\right)}^{3}} \]
    8. Applied egg-rr12.4%

      \[\leadsto \color{blue}{{\left(\sqrt[3]{x + -0.05396825396825397}\right)}^{3}} \]
    9. Taylor expanded in x around 0 12.7%

      \[\leadsto \color{blue}{x \cdot \left(0.3333333333333333 \cdot {\left(1 \cdot {\left(\sqrt[3]{-0.05396825396825397}\right)}^{4}\right)}^{0.3333333333333333} + 0.6666666666666666 \cdot {\left(1 \cdot {\left(\sqrt[3]{-0.05396825396825397}\right)}^{4}\right)}^{0.3333333333333333}\right) - 0.05396825396825397} \]
    10. Step-by-step derivation
      1. fma-neg12.7%

        \[\leadsto \color{blue}{\mathsf{fma}\left(x, 0.3333333333333333 \cdot {\left(1 \cdot {\left(\sqrt[3]{-0.05396825396825397}\right)}^{4}\right)}^{0.3333333333333333} + 0.6666666666666666 \cdot {\left(1 \cdot {\left(\sqrt[3]{-0.05396825396825397}\right)}^{4}\right)}^{0.3333333333333333}, -0.05396825396825397\right)} \]
      2. distribute-rgt-out12.7%

        \[\leadsto \mathsf{fma}\left(x, \color{blue}{{\left(1 \cdot {\left(\sqrt[3]{-0.05396825396825397}\right)}^{4}\right)}^{0.3333333333333333} \cdot \left(0.3333333333333333 + 0.6666666666666666\right)}, -0.05396825396825397\right) \]
      3. metadata-eval12.7%

        \[\leadsto \mathsf{fma}\left(x, {\left(1 \cdot {\left(\sqrt[3]{-0.05396825396825397}\right)}^{4}\right)}^{0.3333333333333333} \cdot \color{blue}{1}, -0.05396825396825397\right) \]
      4. *-rgt-identity12.7%

        \[\leadsto \mathsf{fma}\left(x, \color{blue}{{\left(1 \cdot {\left(\sqrt[3]{-0.05396825396825397}\right)}^{4}\right)}^{0.3333333333333333}}, -0.05396825396825397\right) \]
      5. unpow1/312.7%

        \[\leadsto \mathsf{fma}\left(x, \color{blue}{\sqrt[3]{1 \cdot {\left(\sqrt[3]{-0.05396825396825397}\right)}^{4}}}, -0.05396825396825397\right) \]
      6. *-lft-identity12.7%

        \[\leadsto \mathsf{fma}\left(x, \sqrt[3]{\color{blue}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{4}}}, -0.05396825396825397\right) \]
      7. metadata-eval12.7%

        \[\leadsto \mathsf{fma}\left(x, \sqrt[3]{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{\color{blue}{\left(2 \cdot 2\right)}}}, -0.05396825396825397\right) \]
      8. pow-sqr12.7%

        \[\leadsto \mathsf{fma}\left(x, \sqrt[3]{\color{blue}{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{2} \cdot {\left(\sqrt[3]{-0.05396825396825397}\right)}^{2}}}, -0.05396825396825397\right) \]
      9. unpow212.7%

        \[\leadsto \mathsf{fma}\left(x, \sqrt[3]{{\left(\sqrt[3]{-0.05396825396825397}\right)}^{2} \cdot \color{blue}{\left(\sqrt[3]{-0.05396825396825397} \cdot \sqrt[3]{-0.05396825396825397}\right)}}, -0.05396825396825397\right) \]
      10. associate-*r*12.7%

        \[\leadsto \mathsf{fma}\left(x, \sqrt[3]{\color{blue}{\left({\left(\sqrt[3]{-0.05396825396825397}\right)}^{2} \cdot \sqrt[3]{-0.05396825396825397}\right) \cdot \sqrt[3]{-0.05396825396825397}}}, -0.05396825396825397\right) \]
      11. unpow212.7%

        \[\leadsto \mathsf{fma}\left(x, \sqrt[3]{\left(\color{blue}{\left(\sqrt[3]{-0.05396825396825397} \cdot \sqrt[3]{-0.05396825396825397}\right)} \cdot \sqrt[3]{-0.05396825396825397}\right) \cdot \sqrt[3]{-0.05396825396825397}}, -0.05396825396825397\right) \]
      12. rem-3cbrt-lft12.7%

        \[\leadsto \mathsf{fma}\left(x, \sqrt[3]{\color{blue}{-0.05396825396825397} \cdot \sqrt[3]{-0.05396825396825397}}, -0.05396825396825397\right) \]
      13. metadata-eval12.7%

        \[\leadsto \mathsf{fma}\left(x, \sqrt[3]{-0.05396825396825397 \cdot \sqrt[3]{-0.05396825396825397}}, \color{blue}{-0.05396825396825397}\right) \]
    11. Simplified12.7%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \sqrt[3]{-0.05396825396825397 \cdot \sqrt[3]{-0.05396825396825397}}, -0.05396825396825397\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification96.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \leq 0.005:\\ \;\;\;\;x + \left(-0.3333333333333333 \cdot {x}^{3} + \left(-0.05396825396825397 \cdot {x}^{7} + 0.13333333333333333 \cdot {x}^{5}\right)\right)\\ \mathbf{elif}\;\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \leq 2:\\ \;\;\;\;\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, \sqrt[3]{-0.05396825396825397 \cdot \sqrt[3]{-0.05396825396825397}}, -0.05396825396825397\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 97.2% accurate, 1.9× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ x_s = \mathsf{copysign}\left(1, x\right) \\ x_s \cdot \left(x_m + \left(-0.3333333333333333 \cdot {x_m}^{3} + {x_m}^{5} \cdot 0.125\right)\right) \end{array} \]
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
(FPCore (x_s x_m)
 :precision binary64
 (*
  x_s
  (+ x_m (+ (* -0.3333333333333333 (pow x_m 3.0)) (* (pow x_m 5.0) 0.125)))))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
	return x_s * (x_m + ((-0.3333333333333333 * pow(x_m, 3.0)) + (pow(x_m, 5.0) * 0.125)));
}
x_m = abs(x)
x_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m)
    real(8), intent (in) :: x_s
    real(8), intent (in) :: x_m
    code = x_s * (x_m + (((-0.3333333333333333d0) * (x_m ** 3.0d0)) + ((x_m ** 5.0d0) * 0.125d0)))
end function
x_m = Math.abs(x);
x_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m) {
	return x_s * (x_m + ((-0.3333333333333333 * Math.pow(x_m, 3.0)) + (Math.pow(x_m, 5.0) * 0.125)));
}
x_m = math.fabs(x)
x_s = math.copysign(1.0, x)
def code(x_s, x_m):
	return x_s * (x_m + ((-0.3333333333333333 * math.pow(x_m, 3.0)) + (math.pow(x_m, 5.0) * 0.125)))
x_m = abs(x)
x_s = copysign(1.0, x)
function code(x_s, x_m)
	return Float64(x_s * Float64(x_m + Float64(Float64(-0.3333333333333333 * (x_m ^ 3.0)) + Float64((x_m ^ 5.0) * 0.125))))
end
x_m = abs(x);
x_s = sign(x) * abs(1.0);
function tmp = code(x_s, x_m)
	tmp = x_s * (x_m + ((-0.3333333333333333 * (x_m ^ 3.0)) + ((x_m ^ 5.0) * 0.125)));
end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_] := N[(x$95$s * N[(x$95$m + N[(N[(-0.3333333333333333 * N[Power[x$95$m, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[Power[x$95$m, 5.0], $MachinePrecision] * 0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)

\\
x_s \cdot \left(x_m + \left(-0.3333333333333333 \cdot {x_m}^{3} + {x_m}^{5} \cdot 0.125\right)\right)
\end{array}
Derivation
  1. Initial program 8.5%

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

    \[\leadsto \frac{\color{blue}{0.3333333333333333 \cdot {x}^{3} + 2 \cdot x}}{e^{x} + e^{-x}} \]
  4. Taylor expanded in x around 0 95.1%

    \[\leadsto \color{blue}{x + \left(-0.3333333333333333 \cdot {x}^{3} + 0.125 \cdot {x}^{5}\right)} \]
  5. Final simplification95.1%

    \[\leadsto x + \left(-0.3333333333333333 \cdot {x}^{3} + {x}^{5} \cdot 0.125\right) \]
  6. Add Preprocessing

Alternative 5: 97.3% accurate, 1.9× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ x_s = \mathsf{copysign}\left(1, x\right) \\ x_s \cdot \left(x_m + \left(-0.3333333333333333 \cdot {x_m}^{3} + 0.13333333333333333 \cdot {x_m}^{5}\right)\right) \end{array} \]
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
(FPCore (x_s x_m)
 :precision binary64
 (*
  x_s
  (+
   x_m
   (+
    (* -0.3333333333333333 (pow x_m 3.0))
    (* 0.13333333333333333 (pow x_m 5.0))))))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
	return x_s * (x_m + ((-0.3333333333333333 * pow(x_m, 3.0)) + (0.13333333333333333 * pow(x_m, 5.0))));
}
x_m = abs(x)
x_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m)
    real(8), intent (in) :: x_s
    real(8), intent (in) :: x_m
    code = x_s * (x_m + (((-0.3333333333333333d0) * (x_m ** 3.0d0)) + (0.13333333333333333d0 * (x_m ** 5.0d0))))
end function
x_m = Math.abs(x);
x_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m) {
	return x_s * (x_m + ((-0.3333333333333333 * Math.pow(x_m, 3.0)) + (0.13333333333333333 * Math.pow(x_m, 5.0))));
}
x_m = math.fabs(x)
x_s = math.copysign(1.0, x)
def code(x_s, x_m):
	return x_s * (x_m + ((-0.3333333333333333 * math.pow(x_m, 3.0)) + (0.13333333333333333 * math.pow(x_m, 5.0))))
x_m = abs(x)
x_s = copysign(1.0, x)
function code(x_s, x_m)
	return Float64(x_s * Float64(x_m + Float64(Float64(-0.3333333333333333 * (x_m ^ 3.0)) + Float64(0.13333333333333333 * (x_m ^ 5.0)))))
end
x_m = abs(x);
x_s = sign(x) * abs(1.0);
function tmp = code(x_s, x_m)
	tmp = x_s * (x_m + ((-0.3333333333333333 * (x_m ^ 3.0)) + (0.13333333333333333 * (x_m ^ 5.0))));
end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_] := N[(x$95$s * N[(x$95$m + N[(N[(-0.3333333333333333 * N[Power[x$95$m, 3.0], $MachinePrecision]), $MachinePrecision] + N[(0.13333333333333333 * N[Power[x$95$m, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)

\\
x_s \cdot \left(x_m + \left(-0.3333333333333333 \cdot {x_m}^{3} + 0.13333333333333333 \cdot {x_m}^{5}\right)\right)
\end{array}
Derivation
  1. Initial program 8.5%

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

    \[\leadsto \color{blue}{x + \left(-0.3333333333333333 \cdot {x}^{3} + 0.13333333333333333 \cdot {x}^{5}\right)} \]
  4. Final simplification95.1%

    \[\leadsto x + \left(-0.3333333333333333 \cdot {x}^{3} + 0.13333333333333333 \cdot {x}^{5}\right) \]
  5. Add Preprocessing

Alternative 6: 96.7% accurate, 409.0× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ x_s = \mathsf{copysign}\left(1, x\right) \\ x_s \cdot x_m \end{array} \]
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
(FPCore (x_s x_m) :precision binary64 (* x_s x_m))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
	return x_s * x_m;
}
x_m = abs(x)
x_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m)
    real(8), intent (in) :: x_s
    real(8), intent (in) :: x_m
    code = x_s * x_m
end function
x_m = Math.abs(x);
x_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m) {
	return x_s * x_m;
}
x_m = math.fabs(x)
x_s = math.copysign(1.0, x)
def code(x_s, x_m):
	return x_s * x_m
x_m = abs(x)
x_s = copysign(1.0, x)
function code(x_s, x_m)
	return Float64(x_s * x_m)
end
x_m = abs(x);
x_s = sign(x) * abs(1.0);
function tmp = code(x_s, x_m)
	tmp = x_s * x_m;
end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_] := N[(x$95$s * x$95$m), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)

\\
x_s \cdot x_m
\end{array}
Derivation
  1. Initial program 8.5%

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

    \[\leadsto \color{blue}{x} \]
  4. Final simplification94.9%

    \[\leadsto x \]
  5. Add Preprocessing

Reproduce

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