Hyperbolic tangent

Percentage Accurate: 9.3% → 99.7%
Time: 17.5s
Alternatives: 9
Speedup: 68.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 9 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.3% 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: 99.7% accurate, 0.6× 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}\\ x_s \cdot \begin{array}{l} \mathbf{if}\;\frac{e^{x_m} - t_0}{e^{x_m} + t_0} \leq 2 \cdot 10^{-6}:\\ \;\;\;\;x_m + -0.3333333333333333 \cdot {x_m}^{3}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + \frac{1}{e^{x_m \cdot 2}}} + \frac{-1}{{\left(e^{x_m}\right)}^{2} + 1}\\ \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))))
   (*
    x_s
    (if (<= (/ (- (exp x_m) t_0) (+ (exp x_m) t_0)) 2e-6)
      (+ x_m (* -0.3333333333333333 (pow x_m 3.0)))
      (+
       (/ 1.0 (+ 1.0 (/ 1.0 (exp (* x_m 2.0)))))
       (/ -1.0 (+ (pow (exp x_m) 2.0) 1.0)))))))
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 tmp;
	if (((exp(x_m) - t_0) / (exp(x_m) + t_0)) <= 2e-6) {
		tmp = x_m + (-0.3333333333333333 * pow(x_m, 3.0));
	} else {
		tmp = (1.0 / (1.0 + (1.0 / exp((x_m * 2.0))))) + (-1.0 / (pow(exp(x_m), 2.0) + 1.0));
	}
	return x_s * tmp;
}
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
    real(8) :: t_0
    real(8) :: tmp
    t_0 = exp(-x_m)
    if (((exp(x_m) - t_0) / (exp(x_m) + t_0)) <= 2d-6) then
        tmp = x_m + ((-0.3333333333333333d0) * (x_m ** 3.0d0))
    else
        tmp = (1.0d0 / (1.0d0 + (1.0d0 / exp((x_m * 2.0d0))))) + ((-1.0d0) / ((exp(x_m) ** 2.0d0) + 1.0d0))
    end if
    code = x_s * tmp
end function
x_m = Math.abs(x);
x_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m) {
	double t_0 = Math.exp(-x_m);
	double tmp;
	if (((Math.exp(x_m) - t_0) / (Math.exp(x_m) + t_0)) <= 2e-6) {
		tmp = x_m + (-0.3333333333333333 * Math.pow(x_m, 3.0));
	} else {
		tmp = (1.0 / (1.0 + (1.0 / Math.exp((x_m * 2.0))))) + (-1.0 / (Math.pow(Math.exp(x_m), 2.0) + 1.0));
	}
	return x_s * tmp;
}
x_m = math.fabs(x)
x_s = math.copysign(1.0, x)
def code(x_s, x_m):
	t_0 = math.exp(-x_m)
	tmp = 0
	if ((math.exp(x_m) - t_0) / (math.exp(x_m) + t_0)) <= 2e-6:
		tmp = x_m + (-0.3333333333333333 * math.pow(x_m, 3.0))
	else:
		tmp = (1.0 / (1.0 + (1.0 / math.exp((x_m * 2.0))))) + (-1.0 / (math.pow(math.exp(x_m), 2.0) + 1.0))
	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))
	tmp = 0.0
	if (Float64(Float64(exp(x_m) - t_0) / Float64(exp(x_m) + t_0)) <= 2e-6)
		tmp = Float64(x_m + Float64(-0.3333333333333333 * (x_m ^ 3.0)));
	else
		tmp = Float64(Float64(1.0 / Float64(1.0 + Float64(1.0 / exp(Float64(x_m * 2.0))))) + Float64(-1.0 / Float64((exp(x_m) ^ 2.0) + 1.0)));
	end
	return Float64(x_s * tmp)
end
x_m = abs(x);
x_s = sign(x) * abs(1.0);
function tmp_2 = code(x_s, x_m)
	t_0 = exp(-x_m);
	tmp = 0.0;
	if (((exp(x_m) - t_0) / (exp(x_m) + t_0)) <= 2e-6)
		tmp = x_m + (-0.3333333333333333 * (x_m ^ 3.0));
	else
		tmp = (1.0 / (1.0 + (1.0 / exp((x_m * 2.0))))) + (-1.0 / ((exp(x_m) ^ 2.0) + 1.0));
	end
	tmp_2 = 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]}, N[(x$95$s * If[LessEqual[N[(N[(N[Exp[x$95$m], $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[Exp[x$95$m], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision], 2e-6], N[(x$95$m + N[(-0.3333333333333333 * N[Power[x$95$m, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[(1.0 + N[(1.0 / N[Exp[N[(x$95$m * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-1.0 / N[(N[Power[N[Exp[x$95$m], $MachinePrecision], 2.0], $MachinePrecision] + 1.0), $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 := e^{-x_m}\\
x_s \cdot \begin{array}{l}
\mathbf{if}\;\frac{e^{x_m} - t_0}{e^{x_m} + t_0} \leq 2 \cdot 10^{-6}:\\
\;\;\;\;x_m + -0.3333333333333333 \cdot {x_m}^{3}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \frac{1}{e^{x_m \cdot 2}}} + \frac{-1}{{\left(e^{x_m}\right)}^{2} + 1}\\


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

    1. Initial program 7.2%

      \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \]
    2. Step-by-step derivation
      1. remove-double-neg7.2%

        \[\leadsto \frac{e^{x} - e^{-x}}{e^{\color{blue}{-\left(-x\right)}} + e^{-x}} \]
      2. +-commutative7.2%

        \[\leadsto \frac{e^{x} - e^{-x}}{\color{blue}{e^{-x} + e^{-\left(-x\right)}}} \]
      3. div-sub7.2%

        \[\leadsto \color{blue}{\frac{e^{x}}{e^{-x} + e^{-\left(-x\right)}} - \frac{e^{-x}}{e^{-x} + e^{-\left(-x\right)}}} \]
    3. Simplified5.8%

      \[\leadsto \color{blue}{\mathsf{reciprocal}\left(\left(1 + {\left(e^{x}\right)}^{-2}\right)\right) - \mathsf{reciprocal}\left(\left(1 + {\left(e^{x}\right)}^{2}\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 99.2%

      \[\leadsto \color{blue}{x + -0.3333333333333333 \cdot {x}^{3}} \]

    if 1.99999999999999991e-6 < (/.f64 (-.f64 (exp.f64 x) (exp.f64 (neg.f64 x))) (+.f64 (exp.f64 x) (exp.f64 (neg.f64 x))))

    1. Initial program 18.9%

      \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \]
    2. Step-by-step derivation
      1. remove-double-neg18.9%

        \[\leadsto \frac{e^{x} - e^{-x}}{e^{\color{blue}{-\left(-x\right)}} + e^{-x}} \]
      2. +-commutative18.9%

        \[\leadsto \frac{e^{x} - e^{-x}}{\color{blue}{e^{-x} + e^{-\left(-x\right)}}} \]
      3. div-sub19.3%

        \[\leadsto \color{blue}{\frac{e^{x}}{e^{-x} + e^{-\left(-x\right)}} - \frac{e^{-x}}{e^{-x} + e^{-\left(-x\right)}}} \]
    3. Simplified86.7%

      \[\leadsto \color{blue}{\mathsf{reciprocal}\left(\left(1 + {\left(e^{x}\right)}^{-2}\right)\right) - \mathsf{reciprocal}\left(\left(1 + {\left(e^{x}\right)}^{2}\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around inf 99.3%

      \[\leadsto \color{blue}{\frac{1}{1 + \frac{1}{{\left(e^{x}\right)}^{2}}} - \frac{1}{1 + {\left(e^{x}\right)}^{2}}} \]
    6. Step-by-step derivation
      1. pow-exp99.3%

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

      \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{e^{x \cdot 2}}}} - \frac{1}{1 + {\left(e^{x}\right)}^{2}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \leq 2 \cdot 10^{-6}:\\ \;\;\;\;x + -0.3333333333333333 \cdot {x}^{3}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + \frac{1}{e^{x \cdot 2}}} + \frac{-1}{{\left(e^{x}\right)}^{2} + 1}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 97.9% accurate, 0.7× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ x_s = \mathsf{copysign}\left(1, x\right) \\ x_s \cdot \frac{\mathsf{expm1}\left(x_m \cdot 2\right) - \mathsf{expm1}\left(x_m \cdot -2\right)}{\left(-1 - {\left(e^{x_m}\right)}^{2}\right) \cdot \left(-1 - {\left(e^{x_m}\right)}^{-2}\right)} \end{array} \]
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
(FPCore (x_s x_m)
 :precision binary64
 (*
  x_s
  (/
   (- (expm1 (* x_m 2.0)) (expm1 (* x_m -2.0)))
   (* (- -1.0 (pow (exp x_m) 2.0)) (- -1.0 (pow (exp x_m) -2.0))))))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
	return x_s * ((expm1((x_m * 2.0)) - expm1((x_m * -2.0))) / ((-1.0 - pow(exp(x_m), 2.0)) * (-1.0 - pow(exp(x_m), -2.0))));
}
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 * ((Math.expm1((x_m * 2.0)) - Math.expm1((x_m * -2.0))) / ((-1.0 - Math.pow(Math.exp(x_m), 2.0)) * (-1.0 - Math.pow(Math.exp(x_m), -2.0))));
}
x_m = math.fabs(x)
x_s = math.copysign(1.0, x)
def code(x_s, x_m):
	return x_s * ((math.expm1((x_m * 2.0)) - math.expm1((x_m * -2.0))) / ((-1.0 - math.pow(math.exp(x_m), 2.0)) * (-1.0 - math.pow(math.exp(x_m), -2.0))))
x_m = abs(x)
x_s = copysign(1.0, x)
function code(x_s, x_m)
	return Float64(x_s * Float64(Float64(expm1(Float64(x_m * 2.0)) - expm1(Float64(x_m * -2.0))) / Float64(Float64(-1.0 - (exp(x_m) ^ 2.0)) * Float64(-1.0 - (exp(x_m) ^ -2.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[(N[(N[(Exp[N[(x$95$m * 2.0), $MachinePrecision]] - 1), $MachinePrecision] - N[(Exp[N[(x$95$m * -2.0), $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision] / N[(N[(-1.0 - N[Power[N[Exp[x$95$m], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[(-1.0 - N[Power[N[Exp[x$95$m], $MachinePrecision], -2.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 \frac{\mathsf{expm1}\left(x_m \cdot 2\right) - \mathsf{expm1}\left(x_m \cdot -2\right)}{\left(-1 - {\left(e^{x_m}\right)}^{2}\right) \cdot \left(-1 - {\left(e^{x_m}\right)}^{-2}\right)}
\end{array}
Derivation
  1. Initial program 7.5%

    \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \]
  2. Step-by-step derivation
    1. remove-double-neg7.5%

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

      \[\leadsto \frac{e^{x} - e^{-x}}{\color{blue}{e^{-x} + e^{-\left(-x\right)}}} \]
    3. div-sub7.5%

      \[\leadsto \color{blue}{\frac{e^{x}}{e^{-x} + e^{-\left(-x\right)}} - \frac{e^{-x}}{e^{-x} + e^{-\left(-x\right)}}} \]
  3. Simplified7.4%

    \[\leadsto \color{blue}{\mathsf{reciprocal}\left(\left(1 + {\left(e^{x}\right)}^{-2}\right)\right) - \mathsf{reciprocal}\left(\left(1 + {\left(e^{x}\right)}^{2}\right)\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in x around inf 9.0%

    \[\leadsto \color{blue}{\frac{1}{1 + \frac{1}{{\left(e^{x}\right)}^{2}}} - \frac{1}{1 + {\left(e^{x}\right)}^{2}}} \]
  6. Step-by-step derivation
    1. frac-2neg9.0%

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

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

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

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

      \[\leadsto \color{blue}{\frac{-1 \cdot \left(-\left(1 + {\left(e^{x}\right)}^{2}\right)\right) - \left(-\left(1 + \frac{1}{{\left(e^{x}\right)}^{2}}\right)\right) \cdot -1}{\left(-\left(1 + \frac{1}{{\left(e^{x}\right)}^{2}}\right)\right) \cdot \left(-\left(1 + {\left(e^{x}\right)}^{2}\right)\right)}} \]
  7. Applied egg-rr7.5%

    \[\leadsto \color{blue}{\frac{-1 \cdot \left(-1 + \left(-{\left(e^{x}\right)}^{2}\right)\right) - \left(-1 + \left(-e^{-2 \cdot x}\right)\right) \cdot -1}{\left(-1 + \left(-e^{-2 \cdot x}\right)\right) \cdot \left(-1 + \left(-{\left(e^{x}\right)}^{2}\right)\right)}} \]
  8. Step-by-step derivation
    1. Simplified98.4%

      \[\leadsto \color{blue}{\frac{\mathsf{expm1}\left(x \cdot 2\right) - \mathsf{expm1}\left(x \cdot -2\right)}{\left(-1 - {\left(e^{x}\right)}^{2}\right) \cdot \left(-1 - {\left(e^{x}\right)}^{-2}\right)}} \]
    2. Final simplification98.4%

      \[\leadsto \frac{\mathsf{expm1}\left(x \cdot 2\right) - \mathsf{expm1}\left(x \cdot -2\right)}{\left(-1 - {\left(e^{x}\right)}^{2}\right) \cdot \left(-1 - {\left(e^{x}\right)}^{-2}\right)} \]
    3. Add Preprocessing

    Alternative 3: 99.9% accurate, 1.8× 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 \cdot 2}\\ x_s \cdot \begin{array}{l} \mathbf{if}\;x_m \leq 0.00095:\\ \;\;\;\;x_m + -0.3333333333333333 \cdot {x_m}^{3}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + \frac{1}{t_0}} + \frac{-1}{1 + t_0}\\ \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 2.0))))
       (*
        x_s
        (if (<= x_m 0.00095)
          (+ x_m (* -0.3333333333333333 (pow x_m 3.0)))
          (+ (/ 1.0 (+ 1.0 (/ 1.0 t_0))) (/ -1.0 (+ 1.0 t_0)))))))
    x_m = fabs(x);
    x_s = copysign(1.0, x);
    double code(double x_s, double x_m) {
    	double t_0 = exp((x_m * 2.0));
    	double tmp;
    	if (x_m <= 0.00095) {
    		tmp = x_m + (-0.3333333333333333 * pow(x_m, 3.0));
    	} else {
    		tmp = (1.0 / (1.0 + (1.0 / t_0))) + (-1.0 / (1.0 + t_0));
    	}
    	return x_s * tmp;
    }
    
    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
        real(8) :: t_0
        real(8) :: tmp
        t_0 = exp((x_m * 2.0d0))
        if (x_m <= 0.00095d0) then
            tmp = x_m + ((-0.3333333333333333d0) * (x_m ** 3.0d0))
        else
            tmp = (1.0d0 / (1.0d0 + (1.0d0 / t_0))) + ((-1.0d0) / (1.0d0 + t_0))
        end if
        code = x_s * tmp
    end function
    
    x_m = Math.abs(x);
    x_s = Math.copySign(1.0, x);
    public static double code(double x_s, double x_m) {
    	double t_0 = Math.exp((x_m * 2.0));
    	double tmp;
    	if (x_m <= 0.00095) {
    		tmp = x_m + (-0.3333333333333333 * Math.pow(x_m, 3.0));
    	} else {
    		tmp = (1.0 / (1.0 + (1.0 / t_0))) + (-1.0 / (1.0 + t_0));
    	}
    	return x_s * tmp;
    }
    
    x_m = math.fabs(x)
    x_s = math.copysign(1.0, x)
    def code(x_s, x_m):
    	t_0 = math.exp((x_m * 2.0))
    	tmp = 0
    	if x_m <= 0.00095:
    		tmp = x_m + (-0.3333333333333333 * math.pow(x_m, 3.0))
    	else:
    		tmp = (1.0 / (1.0 + (1.0 / t_0))) + (-1.0 / (1.0 + t_0))
    	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 * 2.0))
    	tmp = 0.0
    	if (x_m <= 0.00095)
    		tmp = Float64(x_m + Float64(-0.3333333333333333 * (x_m ^ 3.0)));
    	else
    		tmp = Float64(Float64(1.0 / Float64(1.0 + Float64(1.0 / t_0))) + Float64(-1.0 / Float64(1.0 + t_0)));
    	end
    	return Float64(x_s * tmp)
    end
    
    x_m = abs(x);
    x_s = sign(x) * abs(1.0);
    function tmp_2 = code(x_s, x_m)
    	t_0 = exp((x_m * 2.0));
    	tmp = 0.0;
    	if (x_m <= 0.00095)
    		tmp = x_m + (-0.3333333333333333 * (x_m ^ 3.0));
    	else
    		tmp = (1.0 / (1.0 + (1.0 / t_0))) + (-1.0 / (1.0 + t_0));
    	end
    	tmp_2 = 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[N[(x$95$m * 2.0), $MachinePrecision]], $MachinePrecision]}, N[(x$95$s * If[LessEqual[x$95$m, 0.00095], N[(x$95$m + N[(-0.3333333333333333 * N[Power[x$95$m, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[(1.0 + N[(1.0 / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-1.0 / N[(1.0 + t$95$0), $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 := e^{x_m \cdot 2}\\
    x_s \cdot \begin{array}{l}
    \mathbf{if}\;x_m \leq 0.00095:\\
    \;\;\;\;x_m + -0.3333333333333333 \cdot {x_m}^{3}\\
    
    \mathbf{else}:\\
    \;\;\;\;\frac{1}{1 + \frac{1}{t_0}} + \frac{-1}{1 + t_0}\\
    
    
    \end{array}
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if x < 9.49999999999999998e-4

      1. Initial program 7.2%

        \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \]
      2. Step-by-step derivation
        1. remove-double-neg7.2%

          \[\leadsto \frac{e^{x} - e^{-x}}{e^{\color{blue}{-\left(-x\right)}} + e^{-x}} \]
        2. +-commutative7.2%

          \[\leadsto \frac{e^{x} - e^{-x}}{\color{blue}{e^{-x} + e^{-\left(-x\right)}}} \]
        3. div-sub7.2%

          \[\leadsto \color{blue}{\frac{e^{x}}{e^{-x} + e^{-\left(-x\right)}} - \frac{e^{-x}}{e^{-x} + e^{-\left(-x\right)}}} \]
      3. Simplified6.2%

        \[\leadsto \color{blue}{\mathsf{reciprocal}\left(\left(1 + {\left(e^{x}\right)}^{-2}\right)\right) - \mathsf{reciprocal}\left(\left(1 + {\left(e^{x}\right)}^{2}\right)\right)} \]
      4. Add Preprocessing
      5. Taylor expanded in x around 0 98.8%

        \[\leadsto \color{blue}{x + -0.3333333333333333 \cdot {x}^{3}} \]

      if 9.49999999999999998e-4 < x

      1. Initial program 23.6%

        \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \]
      2. Step-by-step derivation
        1. remove-double-neg23.6%

          \[\leadsto \frac{e^{x} - e^{-x}}{e^{\color{blue}{-\left(-x\right)}} + e^{-x}} \]
        2. +-commutative23.6%

          \[\leadsto \frac{e^{x} - e^{-x}}{\color{blue}{e^{-x} + e^{-\left(-x\right)}}} \]
        3. div-sub24.1%

          \[\leadsto \color{blue}{\frac{e^{x}}{e^{-x} + e^{-\left(-x\right)}} - \frac{e^{-x}}{e^{-x} + e^{-\left(-x\right)}}} \]
      3. Simplified83.3%

        \[\leadsto \color{blue}{\mathsf{reciprocal}\left(\left(1 + {\left(e^{x}\right)}^{-2}\right)\right) - \mathsf{reciprocal}\left(\left(1 + {\left(e^{x}\right)}^{2}\right)\right)} \]
      4. Add Preprocessing
      5. Taylor expanded in x around inf 99.1%

        \[\leadsto \color{blue}{\frac{1}{1 + \frac{1}{{\left(e^{x}\right)}^{2}}} - \frac{1}{1 + {\left(e^{x}\right)}^{2}}} \]
      6. Step-by-step derivation
        1. pow-exp99.1%

          \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{e^{x \cdot 2}}}} - \frac{1}{1 + {\left(e^{x}\right)}^{2}} \]
      7. Applied egg-rr99.1%

        \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{e^{x \cdot 2}}}} - \frac{1}{1 + {\left(e^{x}\right)}^{2}} \]
      8. Step-by-step derivation
        1. pow-exp99.1%

          \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{e^{x \cdot 2}}}} - \frac{1}{1 + {\left(e^{x}\right)}^{2}} \]
      9. Applied egg-rr98.6%

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 0.00095:\\ \;\;\;\;x + -0.3333333333333333 \cdot {x}^{3}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + \frac{1}{e^{x \cdot 2}}} + \frac{-1}{1 + e^{x \cdot 2}}\\ \end{array} \]
    5. Add Preprocessing

    Alternative 4: 99.5% accurate, 1.9× speedup?

    \[\begin{array}{l} x_m = \left|x\right| \\ x_s = \mathsf{copysign}\left(1, x\right) \\ x_s \cdot \begin{array}{l} \mathbf{if}\;x_m \leq 1.15:\\ \;\;\;\;x_m + \left(-0.3333333333333333 \cdot {x_m}^{3} + 0.13333333333333333 \cdot {x_m}^{5}\right)\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{-1}{1 + e^{x_m \cdot 2}}\\ \end{array} \end{array} \]
    x_m = (fabs.f64 x)
    x_s = (copysign.f64 1 x)
    (FPCore (x_s x_m)
     :precision binary64
     (*
      x_s
      (if (<= x_m 1.15)
        (+
         x_m
         (+
          (* -0.3333333333333333 (pow x_m 3.0))
          (* 0.13333333333333333 (pow x_m 5.0))))
        (+ 1.0 (/ -1.0 (+ 1.0 (exp (* x_m 2.0))))))))
    x_m = fabs(x);
    x_s = copysign(1.0, x);
    double code(double x_s, double x_m) {
    	double tmp;
    	if (x_m <= 1.15) {
    		tmp = x_m + ((-0.3333333333333333 * pow(x_m, 3.0)) + (0.13333333333333333 * pow(x_m, 5.0)));
    	} else {
    		tmp = 1.0 + (-1.0 / (1.0 + exp((x_m * 2.0))));
    	}
    	return x_s * tmp;
    }
    
    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
        real(8) :: tmp
        if (x_m <= 1.15d0) then
            tmp = x_m + (((-0.3333333333333333d0) * (x_m ** 3.0d0)) + (0.13333333333333333d0 * (x_m ** 5.0d0)))
        else
            tmp = 1.0d0 + ((-1.0d0) / (1.0d0 + exp((x_m * 2.0d0))))
        end if
        code = x_s * tmp
    end function
    
    x_m = Math.abs(x);
    x_s = Math.copySign(1.0, x);
    public static double code(double x_s, double x_m) {
    	double tmp;
    	if (x_m <= 1.15) {
    		tmp = x_m + ((-0.3333333333333333 * Math.pow(x_m, 3.0)) + (0.13333333333333333 * Math.pow(x_m, 5.0)));
    	} else {
    		tmp = 1.0 + (-1.0 / (1.0 + Math.exp((x_m * 2.0))));
    	}
    	return x_s * tmp;
    }
    
    x_m = math.fabs(x)
    x_s = math.copysign(1.0, x)
    def code(x_s, x_m):
    	tmp = 0
    	if x_m <= 1.15:
    		tmp = x_m + ((-0.3333333333333333 * math.pow(x_m, 3.0)) + (0.13333333333333333 * math.pow(x_m, 5.0)))
    	else:
    		tmp = 1.0 + (-1.0 / (1.0 + math.exp((x_m * 2.0))))
    	return x_s * tmp
    
    x_m = abs(x)
    x_s = copysign(1.0, x)
    function code(x_s, x_m)
    	tmp = 0.0
    	if (x_m <= 1.15)
    		tmp = Float64(x_m + Float64(Float64(-0.3333333333333333 * (x_m ^ 3.0)) + Float64(0.13333333333333333 * (x_m ^ 5.0))));
    	else
    		tmp = Float64(1.0 + Float64(-1.0 / Float64(1.0 + exp(Float64(x_m * 2.0)))));
    	end
    	return Float64(x_s * tmp)
    end
    
    x_m = abs(x);
    x_s = sign(x) * abs(1.0);
    function tmp_2 = code(x_s, x_m)
    	tmp = 0.0;
    	if (x_m <= 1.15)
    		tmp = x_m + ((-0.3333333333333333 * (x_m ^ 3.0)) + (0.13333333333333333 * (x_m ^ 5.0)));
    	else
    		tmp = 1.0 + (-1.0 / (1.0 + exp((x_m * 2.0))));
    	end
    	tmp_2 = 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_] := N[(x$95$s * If[LessEqual[x$95$m, 1.15], 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], N[(1.0 + N[(-1.0 / N[(1.0 + N[Exp[N[(x$95$m * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
    
    \begin{array}{l}
    x_m = \left|x\right|
    \\
    x_s = \mathsf{copysign}\left(1, x\right)
    
    \\
    x_s \cdot \begin{array}{l}
    \mathbf{if}\;x_m \leq 1.15:\\
    \;\;\;\;x_m + \left(-0.3333333333333333 \cdot {x_m}^{3} + 0.13333333333333333 \cdot {x_m}^{5}\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;1 + \frac{-1}{1 + e^{x_m \cdot 2}}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if x < 1.1499999999999999

      1. Initial program 7.6%

        \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \]
      2. Step-by-step derivation
        1. remove-double-neg7.6%

          \[\leadsto \frac{e^{x} - e^{-x}}{e^{\color{blue}{-\left(-x\right)}} + e^{-x}} \]
        2. +-commutative7.6%

          \[\leadsto \frac{e^{x} - e^{-x}}{\color{blue}{e^{-x} + e^{-\left(-x\right)}}} \]
        3. div-sub7.6%

          \[\leadsto \color{blue}{\frac{e^{x}}{e^{-x} + e^{-\left(-x\right)}} - \frac{e^{-x}}{e^{-x} + e^{-\left(-x\right)}}} \]
      3. Simplified6.3%

        \[\leadsto \color{blue}{\mathsf{reciprocal}\left(\left(1 + {\left(e^{x}\right)}^{-2}\right)\right) - \mathsf{reciprocal}\left(\left(1 + {\left(e^{x}\right)}^{2}\right)\right)} \]
      4. Add Preprocessing
      5. Taylor expanded in x around 0 98.8%

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

      if 1.1499999999999999 < x

      1. Initial program 0.0%

        \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \]
      2. Step-by-step derivation
        1. remove-double-neg0.0%

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

          \[\leadsto \frac{e^{x} - e^{-x}}{\color{blue}{e^{-x} + e^{-\left(-x\right)}}} \]
        3. div-sub0.0%

          \[\leadsto \color{blue}{\frac{e^{x}}{e^{-x} + e^{-\left(-x\right)}} - \frac{e^{-x}}{e^{-x} + e^{-\left(-x\right)}}} \]
      3. Simplified100.0%

        \[\leadsto \color{blue}{\mathsf{reciprocal}\left(\left(1 + {\left(e^{x}\right)}^{-2}\right)\right) - \mathsf{reciprocal}\left(\left(1 + {\left(e^{x}\right)}^{2}\right)\right)} \]
      4. Add Preprocessing
      5. Taylor expanded in x around inf 100.0%

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

        \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{1 + 2 \cdot x}}} - \frac{1}{1 + {\left(e^{x}\right)}^{2}} \]
      7. Step-by-step derivation
        1. *-commutative54.6%

          \[\leadsto \frac{1}{1 + \frac{1}{1 + \color{blue}{x \cdot 2}}} - \frac{1}{2 + x \cdot 2} \]
      8. Simplified56.2%

        \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{1 + x \cdot 2}}} - \frac{1}{1 + {\left(e^{x}\right)}^{2}} \]
      9. Taylor expanded in x around inf 100.0%

        \[\leadsto \color{blue}{1 - \frac{1}{1 + {\left(e^{x}\right)}^{2}}} \]
      10. Step-by-step derivation
        1. pow-exp100.0%

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 1.15:\\ \;\;\;\;x + \left(-0.3333333333333333 \cdot {x}^{3} + 0.13333333333333333 \cdot {x}^{5}\right)\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{-1}{1 + e^{x \cdot 2}}\\ \end{array} \]
    5. Add Preprocessing

    Alternative 5: 99.5% accurate, 1.9× speedup?

    \[\begin{array}{l} x_m = \left|x\right| \\ x_s = \mathsf{copysign}\left(1, x\right) \\ x_s \cdot \begin{array}{l} \mathbf{if}\;x_m \leq 1.15:\\ \;\;\;\;\left(x_m + -0.3333333333333333 \cdot {x_m}^{3}\right) + 0.13333333333333333 \cdot {x_m}^{5}\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{-1}{1 + e^{x_m \cdot 2}}\\ \end{array} \end{array} \]
    x_m = (fabs.f64 x)
    x_s = (copysign.f64 1 x)
    (FPCore (x_s x_m)
     :precision binary64
     (*
      x_s
      (if (<= x_m 1.15)
        (+
         (+ x_m (* -0.3333333333333333 (pow x_m 3.0)))
         (* 0.13333333333333333 (pow x_m 5.0)))
        (+ 1.0 (/ -1.0 (+ 1.0 (exp (* x_m 2.0))))))))
    x_m = fabs(x);
    x_s = copysign(1.0, x);
    double code(double x_s, double x_m) {
    	double tmp;
    	if (x_m <= 1.15) {
    		tmp = (x_m + (-0.3333333333333333 * pow(x_m, 3.0))) + (0.13333333333333333 * pow(x_m, 5.0));
    	} else {
    		tmp = 1.0 + (-1.0 / (1.0 + exp((x_m * 2.0))));
    	}
    	return x_s * tmp;
    }
    
    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
        real(8) :: tmp
        if (x_m <= 1.15d0) then
            tmp = (x_m + ((-0.3333333333333333d0) * (x_m ** 3.0d0))) + (0.13333333333333333d0 * (x_m ** 5.0d0))
        else
            tmp = 1.0d0 + ((-1.0d0) / (1.0d0 + exp((x_m * 2.0d0))))
        end if
        code = x_s * tmp
    end function
    
    x_m = Math.abs(x);
    x_s = Math.copySign(1.0, x);
    public static double code(double x_s, double x_m) {
    	double tmp;
    	if (x_m <= 1.15) {
    		tmp = (x_m + (-0.3333333333333333 * Math.pow(x_m, 3.0))) + (0.13333333333333333 * Math.pow(x_m, 5.0));
    	} else {
    		tmp = 1.0 + (-1.0 / (1.0 + Math.exp((x_m * 2.0))));
    	}
    	return x_s * tmp;
    }
    
    x_m = math.fabs(x)
    x_s = math.copysign(1.0, x)
    def code(x_s, x_m):
    	tmp = 0
    	if x_m <= 1.15:
    		tmp = (x_m + (-0.3333333333333333 * math.pow(x_m, 3.0))) + (0.13333333333333333 * math.pow(x_m, 5.0))
    	else:
    		tmp = 1.0 + (-1.0 / (1.0 + math.exp((x_m * 2.0))))
    	return x_s * tmp
    
    x_m = abs(x)
    x_s = copysign(1.0, x)
    function code(x_s, x_m)
    	tmp = 0.0
    	if (x_m <= 1.15)
    		tmp = Float64(Float64(x_m + Float64(-0.3333333333333333 * (x_m ^ 3.0))) + Float64(0.13333333333333333 * (x_m ^ 5.0)));
    	else
    		tmp = Float64(1.0 + Float64(-1.0 / Float64(1.0 + exp(Float64(x_m * 2.0)))));
    	end
    	return Float64(x_s * tmp)
    end
    
    x_m = abs(x);
    x_s = sign(x) * abs(1.0);
    function tmp_2 = code(x_s, x_m)
    	tmp = 0.0;
    	if (x_m <= 1.15)
    		tmp = (x_m + (-0.3333333333333333 * (x_m ^ 3.0))) + (0.13333333333333333 * (x_m ^ 5.0));
    	else
    		tmp = 1.0 + (-1.0 / (1.0 + exp((x_m * 2.0))));
    	end
    	tmp_2 = 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_] := N[(x$95$s * If[LessEqual[x$95$m, 1.15], N[(N[(x$95$m + N[(-0.3333333333333333 * N[Power[x$95$m, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.13333333333333333 * N[Power[x$95$m, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(-1.0 / N[(1.0 + N[Exp[N[(x$95$m * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
    
    \begin{array}{l}
    x_m = \left|x\right|
    \\
    x_s = \mathsf{copysign}\left(1, x\right)
    
    \\
    x_s \cdot \begin{array}{l}
    \mathbf{if}\;x_m \leq 1.15:\\
    \;\;\;\;\left(x_m + -0.3333333333333333 \cdot {x_m}^{3}\right) + 0.13333333333333333 \cdot {x_m}^{5}\\
    
    \mathbf{else}:\\
    \;\;\;\;1 + \frac{-1}{1 + e^{x_m \cdot 2}}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if x < 1.1499999999999999

      1. Initial program 7.6%

        \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \]
      2. Step-by-step derivation
        1. remove-double-neg7.6%

          \[\leadsto \frac{e^{x} - e^{-x}}{e^{\color{blue}{-\left(-x\right)}} + e^{-x}} \]
        2. +-commutative7.6%

          \[\leadsto \frac{e^{x} - e^{-x}}{\color{blue}{e^{-x} + e^{-\left(-x\right)}}} \]
        3. div-sub7.6%

          \[\leadsto \color{blue}{\frac{e^{x}}{e^{-x} + e^{-\left(-x\right)}} - \frac{e^{-x}}{e^{-x} + e^{-\left(-x\right)}}} \]
      3. Simplified6.3%

        \[\leadsto \color{blue}{\mathsf{reciprocal}\left(\left(1 + {\left(e^{x}\right)}^{-2}\right)\right) - \mathsf{reciprocal}\left(\left(1 + {\left(e^{x}\right)}^{2}\right)\right)} \]
      4. Add Preprocessing
      5. Taylor expanded in x around 0 98.8%

        \[\leadsto \color{blue}{x + \left(-0.3333333333333333 \cdot {x}^{3} + 0.13333333333333333 \cdot {x}^{5}\right)} \]
      6. Step-by-step derivation
        1. associate-+r+98.8%

          \[\leadsto \color{blue}{\left(x + -0.3333333333333333 \cdot {x}^{3}\right) + 0.13333333333333333 \cdot {x}^{5}} \]
        2. +-commutative98.8%

          \[\leadsto \color{blue}{\left(-0.3333333333333333 \cdot {x}^{3} + x\right)} + 0.13333333333333333 \cdot {x}^{5} \]
        3. fma-def98.8%

          \[\leadsto \color{blue}{\mathsf{fma}\left(-0.3333333333333333, {x}^{3}, x\right)} + 0.13333333333333333 \cdot {x}^{5} \]
      7. Simplified98.8%

        \[\leadsto \color{blue}{\mathsf{fma}\left(-0.3333333333333333, {x}^{3}, x\right) + 0.13333333333333333 \cdot {x}^{5}} \]
      8. Step-by-step derivation
        1. fma-udef98.8%

          \[\leadsto \color{blue}{\left(-0.3333333333333333 \cdot {x}^{3} + x\right)} + 0.13333333333333333 \cdot {x}^{5} \]
      9. Applied egg-rr98.8%

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

      if 1.1499999999999999 < x

      1. Initial program 0.0%

        \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \]
      2. Step-by-step derivation
        1. remove-double-neg0.0%

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

          \[\leadsto \frac{e^{x} - e^{-x}}{\color{blue}{e^{-x} + e^{-\left(-x\right)}}} \]
        3. div-sub0.0%

          \[\leadsto \color{blue}{\frac{e^{x}}{e^{-x} + e^{-\left(-x\right)}} - \frac{e^{-x}}{e^{-x} + e^{-\left(-x\right)}}} \]
      3. Simplified100.0%

        \[\leadsto \color{blue}{\mathsf{reciprocal}\left(\left(1 + {\left(e^{x}\right)}^{-2}\right)\right) - \mathsf{reciprocal}\left(\left(1 + {\left(e^{x}\right)}^{2}\right)\right)} \]
      4. Add Preprocessing
      5. Taylor expanded in x around inf 100.0%

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

        \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{1 + 2 \cdot x}}} - \frac{1}{1 + {\left(e^{x}\right)}^{2}} \]
      7. Step-by-step derivation
        1. *-commutative54.6%

          \[\leadsto \frac{1}{1 + \frac{1}{1 + \color{blue}{x \cdot 2}}} - \frac{1}{2 + x \cdot 2} \]
      8. Simplified56.2%

        \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{1 + x \cdot 2}}} - \frac{1}{1 + {\left(e^{x}\right)}^{2}} \]
      9. Taylor expanded in x around inf 100.0%

        \[\leadsto \color{blue}{1 - \frac{1}{1 + {\left(e^{x}\right)}^{2}}} \]
      10. Step-by-step derivation
        1. pow-exp100.0%

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 1.15:\\ \;\;\;\;\left(x + -0.3333333333333333 \cdot {x}^{3}\right) + 0.13333333333333333 \cdot {x}^{5}\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{-1}{1 + e^{x \cdot 2}}\\ \end{array} \]
    5. Add Preprocessing

    Alternative 6: 99.3% accurate, 3.6× speedup?

    \[\begin{array}{l} x_m = \left|x\right| \\ x_s = \mathsf{copysign}\left(1, x\right) \\ x_s \cdot \begin{array}{l} \mathbf{if}\;x_m \leq 1.05:\\ \;\;\;\;x_m + -0.3333333333333333 \cdot {x_m}^{3}\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{-1}{1 + e^{x_m \cdot 2}}\\ \end{array} \end{array} \]
    x_m = (fabs.f64 x)
    x_s = (copysign.f64 1 x)
    (FPCore (x_s x_m)
     :precision binary64
     (*
      x_s
      (if (<= x_m 1.05)
        (+ x_m (* -0.3333333333333333 (pow x_m 3.0)))
        (+ 1.0 (/ -1.0 (+ 1.0 (exp (* x_m 2.0))))))))
    x_m = fabs(x);
    x_s = copysign(1.0, x);
    double code(double x_s, double x_m) {
    	double tmp;
    	if (x_m <= 1.05) {
    		tmp = x_m + (-0.3333333333333333 * pow(x_m, 3.0));
    	} else {
    		tmp = 1.0 + (-1.0 / (1.0 + exp((x_m * 2.0))));
    	}
    	return x_s * tmp;
    }
    
    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
        real(8) :: tmp
        if (x_m <= 1.05d0) then
            tmp = x_m + ((-0.3333333333333333d0) * (x_m ** 3.0d0))
        else
            tmp = 1.0d0 + ((-1.0d0) / (1.0d0 + exp((x_m * 2.0d0))))
        end if
        code = x_s * tmp
    end function
    
    x_m = Math.abs(x);
    x_s = Math.copySign(1.0, x);
    public static double code(double x_s, double x_m) {
    	double tmp;
    	if (x_m <= 1.05) {
    		tmp = x_m + (-0.3333333333333333 * Math.pow(x_m, 3.0));
    	} else {
    		tmp = 1.0 + (-1.0 / (1.0 + Math.exp((x_m * 2.0))));
    	}
    	return x_s * tmp;
    }
    
    x_m = math.fabs(x)
    x_s = math.copysign(1.0, x)
    def code(x_s, x_m):
    	tmp = 0
    	if x_m <= 1.05:
    		tmp = x_m + (-0.3333333333333333 * math.pow(x_m, 3.0))
    	else:
    		tmp = 1.0 + (-1.0 / (1.0 + math.exp((x_m * 2.0))))
    	return x_s * tmp
    
    x_m = abs(x)
    x_s = copysign(1.0, x)
    function code(x_s, x_m)
    	tmp = 0.0
    	if (x_m <= 1.05)
    		tmp = Float64(x_m + Float64(-0.3333333333333333 * (x_m ^ 3.0)));
    	else
    		tmp = Float64(1.0 + Float64(-1.0 / Float64(1.0 + exp(Float64(x_m * 2.0)))));
    	end
    	return Float64(x_s * tmp)
    end
    
    x_m = abs(x);
    x_s = sign(x) * abs(1.0);
    function tmp_2 = code(x_s, x_m)
    	tmp = 0.0;
    	if (x_m <= 1.05)
    		tmp = x_m + (-0.3333333333333333 * (x_m ^ 3.0));
    	else
    		tmp = 1.0 + (-1.0 / (1.0 + exp((x_m * 2.0))));
    	end
    	tmp_2 = 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_] := N[(x$95$s * If[LessEqual[x$95$m, 1.05], N[(x$95$m + N[(-0.3333333333333333 * N[Power[x$95$m, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(-1.0 / N[(1.0 + N[Exp[N[(x$95$m * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
    
    \begin{array}{l}
    x_m = \left|x\right|
    \\
    x_s = \mathsf{copysign}\left(1, x\right)
    
    \\
    x_s \cdot \begin{array}{l}
    \mathbf{if}\;x_m \leq 1.05:\\
    \;\;\;\;x_m + -0.3333333333333333 \cdot {x_m}^{3}\\
    
    \mathbf{else}:\\
    \;\;\;\;1 + \frac{-1}{1 + e^{x_m \cdot 2}}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if x < 1.05000000000000004

      1. Initial program 7.6%

        \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \]
      2. Step-by-step derivation
        1. remove-double-neg7.6%

          \[\leadsto \frac{e^{x} - e^{-x}}{e^{\color{blue}{-\left(-x\right)}} + e^{-x}} \]
        2. +-commutative7.6%

          \[\leadsto \frac{e^{x} - e^{-x}}{\color{blue}{e^{-x} + e^{-\left(-x\right)}}} \]
        3. div-sub7.6%

          \[\leadsto \color{blue}{\frac{e^{x}}{e^{-x} + e^{-\left(-x\right)}} - \frac{e^{-x}}{e^{-x} + e^{-\left(-x\right)}}} \]
      3. Simplified6.3%

        \[\leadsto \color{blue}{\mathsf{reciprocal}\left(\left(1 + {\left(e^{x}\right)}^{-2}\right)\right) - \mathsf{reciprocal}\left(\left(1 + {\left(e^{x}\right)}^{2}\right)\right)} \]
      4. Add Preprocessing
      5. Taylor expanded in x around 0 98.6%

        \[\leadsto \color{blue}{x + -0.3333333333333333 \cdot {x}^{3}} \]

      if 1.05000000000000004 < x

      1. Initial program 0.0%

        \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \]
      2. Step-by-step derivation
        1. remove-double-neg0.0%

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

          \[\leadsto \frac{e^{x} - e^{-x}}{\color{blue}{e^{-x} + e^{-\left(-x\right)}}} \]
        3. div-sub0.0%

          \[\leadsto \color{blue}{\frac{e^{x}}{e^{-x} + e^{-\left(-x\right)}} - \frac{e^{-x}}{e^{-x} + e^{-\left(-x\right)}}} \]
      3. Simplified100.0%

        \[\leadsto \color{blue}{\mathsf{reciprocal}\left(\left(1 + {\left(e^{x}\right)}^{-2}\right)\right) - \mathsf{reciprocal}\left(\left(1 + {\left(e^{x}\right)}^{2}\right)\right)} \]
      4. Add Preprocessing
      5. Taylor expanded in x around inf 100.0%

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

        \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{1 + 2 \cdot x}}} - \frac{1}{1 + {\left(e^{x}\right)}^{2}} \]
      7. Step-by-step derivation
        1. *-commutative54.6%

          \[\leadsto \frac{1}{1 + \frac{1}{1 + \color{blue}{x \cdot 2}}} - \frac{1}{2 + x \cdot 2} \]
      8. Simplified56.2%

        \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{1 + x \cdot 2}}} - \frac{1}{1 + {\left(e^{x}\right)}^{2}} \]
      9. Taylor expanded in x around inf 100.0%

        \[\leadsto \color{blue}{1 - \frac{1}{1 + {\left(e^{x}\right)}^{2}}} \]
      10. Step-by-step derivation
        1. pow-exp100.0%

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

        \[\leadsto 1 - \frac{1}{1 + \color{blue}{e^{x \cdot 2}}} \]
    3. Recombined 2 regimes into one program.
    4. Final simplification98.6%

      \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 1.05:\\ \;\;\;\;x + -0.3333333333333333 \cdot {x}^{3}\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{-1}{1 + e^{x \cdot 2}}\\ \end{array} \]
    5. Add Preprocessing

    Alternative 7: 99.3% accurate, 3.7× speedup?

    \[\begin{array}{l} x_m = \left|x\right| \\ x_s = \mathsf{copysign}\left(1, x\right) \\ x_s \cdot \begin{array}{l} \mathbf{if}\;x_m \leq 1.2:\\ \;\;\;\;x_m + -0.3333333333333333 \cdot {x_m}^{3}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
    x_m = (fabs.f64 x)
    x_s = (copysign.f64 1 x)
    (FPCore (x_s x_m)
     :precision binary64
     (* x_s (if (<= x_m 1.2) (+ x_m (* -0.3333333333333333 (pow x_m 3.0))) 1.0)))
    x_m = fabs(x);
    x_s = copysign(1.0, x);
    double code(double x_s, double x_m) {
    	double tmp;
    	if (x_m <= 1.2) {
    		tmp = x_m + (-0.3333333333333333 * pow(x_m, 3.0));
    	} else {
    		tmp = 1.0;
    	}
    	return x_s * tmp;
    }
    
    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
        real(8) :: tmp
        if (x_m <= 1.2d0) then
            tmp = x_m + ((-0.3333333333333333d0) * (x_m ** 3.0d0))
        else
            tmp = 1.0d0
        end if
        code = x_s * tmp
    end function
    
    x_m = Math.abs(x);
    x_s = Math.copySign(1.0, x);
    public static double code(double x_s, double x_m) {
    	double tmp;
    	if (x_m <= 1.2) {
    		tmp = x_m + (-0.3333333333333333 * Math.pow(x_m, 3.0));
    	} else {
    		tmp = 1.0;
    	}
    	return x_s * tmp;
    }
    
    x_m = math.fabs(x)
    x_s = math.copysign(1.0, x)
    def code(x_s, x_m):
    	tmp = 0
    	if x_m <= 1.2:
    		tmp = x_m + (-0.3333333333333333 * math.pow(x_m, 3.0))
    	else:
    		tmp = 1.0
    	return x_s * tmp
    
    x_m = abs(x)
    x_s = copysign(1.0, x)
    function code(x_s, x_m)
    	tmp = 0.0
    	if (x_m <= 1.2)
    		tmp = Float64(x_m + Float64(-0.3333333333333333 * (x_m ^ 3.0)));
    	else
    		tmp = 1.0;
    	end
    	return Float64(x_s * tmp)
    end
    
    x_m = abs(x);
    x_s = sign(x) * abs(1.0);
    function tmp_2 = code(x_s, x_m)
    	tmp = 0.0;
    	if (x_m <= 1.2)
    		tmp = x_m + (-0.3333333333333333 * (x_m ^ 3.0));
    	else
    		tmp = 1.0;
    	end
    	tmp_2 = 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_] := N[(x$95$s * If[LessEqual[x$95$m, 1.2], N[(x$95$m + N[(-0.3333333333333333 * N[Power[x$95$m, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.0]), $MachinePrecision]
    
    \begin{array}{l}
    x_m = \left|x\right|
    \\
    x_s = \mathsf{copysign}\left(1, x\right)
    
    \\
    x_s \cdot \begin{array}{l}
    \mathbf{if}\;x_m \leq 1.2:\\
    \;\;\;\;x_m + -0.3333333333333333 \cdot {x_m}^{3}\\
    
    \mathbf{else}:\\
    \;\;\;\;1\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if x < 1.19999999999999996

      1. Initial program 7.6%

        \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \]
      2. Step-by-step derivation
        1. remove-double-neg7.6%

          \[\leadsto \frac{e^{x} - e^{-x}}{e^{\color{blue}{-\left(-x\right)}} + e^{-x}} \]
        2. +-commutative7.6%

          \[\leadsto \frac{e^{x} - e^{-x}}{\color{blue}{e^{-x} + e^{-\left(-x\right)}}} \]
        3. div-sub7.6%

          \[\leadsto \color{blue}{\frac{e^{x}}{e^{-x} + e^{-\left(-x\right)}} - \frac{e^{-x}}{e^{-x} + e^{-\left(-x\right)}}} \]
      3. Simplified6.3%

        \[\leadsto \color{blue}{\mathsf{reciprocal}\left(\left(1 + {\left(e^{x}\right)}^{-2}\right)\right) - \mathsf{reciprocal}\left(\left(1 + {\left(e^{x}\right)}^{2}\right)\right)} \]
      4. Add Preprocessing
      5. Taylor expanded in x around 0 98.6%

        \[\leadsto \color{blue}{x + -0.3333333333333333 \cdot {x}^{3}} \]

      if 1.19999999999999996 < x

      1. Initial program 0.0%

        \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \]
      2. Step-by-step derivation
        1. remove-double-neg0.0%

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

          \[\leadsto \frac{e^{x} - e^{-x}}{\color{blue}{e^{-x} + e^{-\left(-x\right)}}} \]
        3. div-sub0.0%

          \[\leadsto \color{blue}{\frac{e^{x}}{e^{-x} + e^{-\left(-x\right)}} - \frac{e^{-x}}{e^{-x} + e^{-\left(-x\right)}}} \]
      3. Simplified100.0%

        \[\leadsto \color{blue}{\mathsf{reciprocal}\left(\left(1 + {\left(e^{x}\right)}^{-2}\right)\right) - \mathsf{reciprocal}\left(\left(1 + {\left(e^{x}\right)}^{2}\right)\right)} \]
      4. Add Preprocessing
      5. Taylor expanded in x around inf 100.0%

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

        \[\leadsto \frac{1}{1 + \frac{1}{{\left(e^{x}\right)}^{2}}} - \frac{1}{\color{blue}{2 + 2 \cdot x}} \]
      7. Step-by-step derivation
        1. *-commutative56.2%

          \[\leadsto \frac{1}{1 + \frac{1}{{\left(e^{x}\right)}^{2}}} - \frac{1}{2 + \color{blue}{x \cdot 2}} \]
      8. Simplified56.2%

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

        \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{1 + 2 \cdot x}}} - \frac{1}{2 + x \cdot 2} \]
      10. Step-by-step derivation
        1. *-commutative54.6%

          \[\leadsto \frac{1}{1 + \frac{1}{1 + \color{blue}{x \cdot 2}}} - \frac{1}{2 + x \cdot 2} \]
      11. Simplified54.6%

        \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{1 + x \cdot 2}}} - \frac{1}{2 + x \cdot 2} \]
      12. Taylor expanded in x around inf 100.0%

        \[\leadsto \color{blue}{1} \]
    3. Recombined 2 regimes into one program.
    4. Final simplification98.6%

      \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 1.2:\\ \;\;\;\;x + -0.3333333333333333 \cdot {x}^{3}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
    5. Add Preprocessing

    Alternative 8: 98.7% accurate, 68.0× speedup?

    \[\begin{array}{l} x_m = \left|x\right| \\ x_s = \mathsf{copysign}\left(1, x\right) \\ x_s \cdot \begin{array}{l} \mathbf{if}\;x_m \leq 1:\\ \;\;\;\;x_m\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
    x_m = (fabs.f64 x)
    x_s = (copysign.f64 1 x)
    (FPCore (x_s x_m) :precision binary64 (* x_s (if (<= x_m 1.0) x_m 1.0)))
    x_m = fabs(x);
    x_s = copysign(1.0, x);
    double code(double x_s, double x_m) {
    	double tmp;
    	if (x_m <= 1.0) {
    		tmp = x_m;
    	} else {
    		tmp = 1.0;
    	}
    	return x_s * tmp;
    }
    
    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
        real(8) :: tmp
        if (x_m <= 1.0d0) then
            tmp = x_m
        else
            tmp = 1.0d0
        end if
        code = x_s * tmp
    end function
    
    x_m = Math.abs(x);
    x_s = Math.copySign(1.0, x);
    public static double code(double x_s, double x_m) {
    	double tmp;
    	if (x_m <= 1.0) {
    		tmp = x_m;
    	} else {
    		tmp = 1.0;
    	}
    	return x_s * tmp;
    }
    
    x_m = math.fabs(x)
    x_s = math.copysign(1.0, x)
    def code(x_s, x_m):
    	tmp = 0
    	if x_m <= 1.0:
    		tmp = x_m
    	else:
    		tmp = 1.0
    	return x_s * tmp
    
    x_m = abs(x)
    x_s = copysign(1.0, x)
    function code(x_s, x_m)
    	tmp = 0.0
    	if (x_m <= 1.0)
    		tmp = x_m;
    	else
    		tmp = 1.0;
    	end
    	return Float64(x_s * tmp)
    end
    
    x_m = abs(x);
    x_s = sign(x) * abs(1.0);
    function tmp_2 = code(x_s, x_m)
    	tmp = 0.0;
    	if (x_m <= 1.0)
    		tmp = x_m;
    	else
    		tmp = 1.0;
    	end
    	tmp_2 = 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_] := N[(x$95$s * If[LessEqual[x$95$m, 1.0], x$95$m, 1.0]), $MachinePrecision]
    
    \begin{array}{l}
    x_m = \left|x\right|
    \\
    x_s = \mathsf{copysign}\left(1, x\right)
    
    \\
    x_s \cdot \begin{array}{l}
    \mathbf{if}\;x_m \leq 1:\\
    \;\;\;\;x_m\\
    
    \mathbf{else}:\\
    \;\;\;\;1\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if x < 1

      1. Initial program 7.6%

        \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \]
      2. Step-by-step derivation
        1. remove-double-neg7.6%

          \[\leadsto \frac{e^{x} - e^{-x}}{e^{\color{blue}{-\left(-x\right)}} + e^{-x}} \]
        2. +-commutative7.6%

          \[\leadsto \frac{e^{x} - e^{-x}}{\color{blue}{e^{-x} + e^{-\left(-x\right)}}} \]
        3. div-sub7.6%

          \[\leadsto \color{blue}{\frac{e^{x}}{e^{-x} + e^{-\left(-x\right)}} - \frac{e^{-x}}{e^{-x} + e^{-\left(-x\right)}}} \]
      3. Simplified6.3%

        \[\leadsto \color{blue}{\mathsf{reciprocal}\left(\left(1 + {\left(e^{x}\right)}^{-2}\right)\right) - \mathsf{reciprocal}\left(\left(1 + {\left(e^{x}\right)}^{2}\right)\right)} \]
      4. Add Preprocessing
      5. Taylor expanded in x around 0 98.6%

        \[\leadsto \color{blue}{x} \]

      if 1 < x

      1. Initial program 0.0%

        \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \]
      2. Step-by-step derivation
        1. remove-double-neg0.0%

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

          \[\leadsto \frac{e^{x} - e^{-x}}{\color{blue}{e^{-x} + e^{-\left(-x\right)}}} \]
        3. div-sub0.0%

          \[\leadsto \color{blue}{\frac{e^{x}}{e^{-x} + e^{-\left(-x\right)}} - \frac{e^{-x}}{e^{-x} + e^{-\left(-x\right)}}} \]
      3. Simplified100.0%

        \[\leadsto \color{blue}{\mathsf{reciprocal}\left(\left(1 + {\left(e^{x}\right)}^{-2}\right)\right) - \mathsf{reciprocal}\left(\left(1 + {\left(e^{x}\right)}^{2}\right)\right)} \]
      4. Add Preprocessing
      5. Taylor expanded in x around inf 100.0%

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

        \[\leadsto \frac{1}{1 + \frac{1}{{\left(e^{x}\right)}^{2}}} - \frac{1}{\color{blue}{2 + 2 \cdot x}} \]
      7. Step-by-step derivation
        1. *-commutative56.2%

          \[\leadsto \frac{1}{1 + \frac{1}{{\left(e^{x}\right)}^{2}}} - \frac{1}{2 + \color{blue}{x \cdot 2}} \]
      8. Simplified56.2%

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

        \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{1 + 2 \cdot x}}} - \frac{1}{2 + x \cdot 2} \]
      10. Step-by-step derivation
        1. *-commutative54.6%

          \[\leadsto \frac{1}{1 + \frac{1}{1 + \color{blue}{x \cdot 2}}} - \frac{1}{2 + x \cdot 2} \]
      11. Simplified54.6%

        \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{1 + x \cdot 2}}} - \frac{1}{2 + x \cdot 2} \]
      12. Taylor expanded in x around inf 100.0%

        \[\leadsto \color{blue}{1} \]
    3. Recombined 2 regimes into one program.
    4. Final simplification98.7%

      \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
    5. Add Preprocessing

    Alternative 9: 7.9% accurate, 409.0× speedup?

    \[\begin{array}{l} x_m = \left|x\right| \\ x_s = \mathsf{copysign}\left(1, x\right) \\ x_s \cdot 1 \end{array} \]
    x_m = (fabs.f64 x)
    x_s = (copysign.f64 1 x)
    (FPCore (x_s x_m) :precision binary64 (* x_s 1.0))
    x_m = fabs(x);
    x_s = copysign(1.0, x);
    double code(double x_s, double x_m) {
    	return x_s * 1.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 * 1.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 * 1.0;
    }
    
    x_m = math.fabs(x)
    x_s = math.copysign(1.0, x)
    def code(x_s, x_m):
    	return x_s * 1.0
    
    x_m = abs(x)
    x_s = copysign(1.0, x)
    function code(x_s, x_m)
    	return Float64(x_s * 1.0)
    end
    
    x_m = abs(x);
    x_s = sign(x) * abs(1.0);
    function tmp = code(x_s, x_m)
    	tmp = x_s * 1.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 * 1.0), $MachinePrecision]
    
    \begin{array}{l}
    x_m = \left|x\right|
    \\
    x_s = \mathsf{copysign}\left(1, x\right)
    
    \\
    x_s \cdot 1
    \end{array}
    
    Derivation
    1. Initial program 7.5%

      \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \]
    2. Step-by-step derivation
      1. remove-double-neg7.5%

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

        \[\leadsto \frac{e^{x} - e^{-x}}{\color{blue}{e^{-x} + e^{-\left(-x\right)}}} \]
      3. div-sub7.5%

        \[\leadsto \color{blue}{\frac{e^{x}}{e^{-x} + e^{-\left(-x\right)}} - \frac{e^{-x}}{e^{-x} + e^{-\left(-x\right)}}} \]
    3. Simplified7.4%

      \[\leadsto \color{blue}{\mathsf{reciprocal}\left(\left(1 + {\left(e^{x}\right)}^{-2}\right)\right) - \mathsf{reciprocal}\left(\left(1 + {\left(e^{x}\right)}^{2}\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around inf 9.0%

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

      \[\leadsto \frac{1}{1 + \frac{1}{{\left(e^{x}\right)}^{2}}} - \frac{1}{\color{blue}{2 + 2 \cdot x}} \]
    7. Step-by-step derivation
      1. *-commutative7.0%

        \[\leadsto \frac{1}{1 + \frac{1}{{\left(e^{x}\right)}^{2}}} - \frac{1}{2 + \color{blue}{x \cdot 2}} \]
    8. Simplified7.0%

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

      \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{1 + 2 \cdot x}}} - \frac{1}{2 + x \cdot 2} \]
    10. Step-by-step derivation
      1. *-commutative6.9%

        \[\leadsto \frac{1}{1 + \frac{1}{1 + \color{blue}{x \cdot 2}}} - \frac{1}{2 + x \cdot 2} \]
    11. Simplified6.9%

      \[\leadsto \frac{1}{1 + \frac{1}{\color{blue}{1 + x \cdot 2}}} - \frac{1}{2 + x \cdot 2} \]
    12. Taylor expanded in x around inf 4.9%

      \[\leadsto \color{blue}{1} \]
    13. Final simplification4.9%

      \[\leadsto 1 \]
    14. Add Preprocessing

    Reproduce

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