(exp (n * log1p (x)) - exp (n * log1p (-x))) / 2

Percentage Accurate: 82.3% → 99.3%
Time: 6.2s
Alternatives: 9
Speedup: 0.7×

Specification

?
\[\left(1 \leq n \land n \leq 100\right) \land \left(10^{-10} \leq x \land x \leq 1\right)\]
\[\begin{array}{l} \\ \frac{e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{n \cdot \mathsf{log1p}\left(-x\right)}}{2} \end{array} \]
(FPCore (n x)
 :precision binary64
 (/ (- (exp (* n (log1p x))) (exp (* n (log1p (- x))))) 2.0))
double code(double n, double x) {
	return (exp((n * log1p(x))) - exp((n * log1p(-x)))) / 2.0;
}
public static double code(double n, double x) {
	return (Math.exp((n * Math.log1p(x))) - Math.exp((n * Math.log1p(-x)))) / 2.0;
}
def code(n, x):
	return (math.exp((n * math.log1p(x))) - math.exp((n * math.log1p(-x)))) / 2.0
function code(n, x)
	return Float64(Float64(exp(Float64(n * log1p(x))) - exp(Float64(n * log1p(Float64(-x))))) / 2.0)
end
code[n_, x_] := N[(N[(N[Exp[N[(n * N[Log[1 + x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - N[Exp[N[(n * N[Log[1 + (-x)], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}

\\
\frac{e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{n \cdot \mathsf{log1p}\left(-x\right)}}{2}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 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: 82.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{n \cdot \mathsf{log1p}\left(-x\right)}}{2} \end{array} \]
(FPCore (n x)
 :precision binary64
 (/ (- (exp (* n (log1p x))) (exp (* n (log1p (- x))))) 2.0))
double code(double n, double x) {
	return (exp((n * log1p(x))) - exp((n * log1p(-x)))) / 2.0;
}
public static double code(double n, double x) {
	return (Math.exp((n * Math.log1p(x))) - Math.exp((n * Math.log1p(-x)))) / 2.0;
}
def code(n, x):
	return (math.exp((n * math.log1p(x))) - math.exp((n * math.log1p(-x)))) / 2.0
function code(n, x)
	return Float64(Float64(exp(Float64(n * log1p(x))) - exp(Float64(n * log1p(Float64(-x))))) / 2.0)
end
code[n_, x_] := N[(N[(N[Exp[N[(n * N[Log[1 + x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - N[Exp[N[(n * N[Log[1 + (-x)], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}

\\
\frac{e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{n \cdot \mathsf{log1p}\left(-x\right)}}{2}
\end{array}

Alternative 1: 99.3% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{n \cdot \mathsf{log1p}\left(-x\right)}\\ \mathbf{if}\;t\_0 \leq 0.178:\\ \;\;\;\;\mathsf{fma}\left(0.5 \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(n \cdot n, -0.35, \mathsf{fma}\left({n}^{4}, -0.14583333333333334, \mathsf{fma}\left({n}^{6}, -0.004166666666666667, \mathsf{fma}\left({n}^{7}, 0.0001984126984126984, \mathsf{fma}\left({n}^{5}, 0.034722222222222224, \mathsf{fma}\left({n}^{3}, 0.32222222222222224, 0.14285714285714285 \cdot n\right)\right)\right)\right)\right)\right) - \mathsf{fma}\left(-0.14285714285714285, n, \mathsf{fma}\left({n}^{3}, -0.32222222222222224, \mathsf{fma}\left({n}^{5}, -0.034722222222222224, \mathsf{fma}\left(-0.0001984126984126984, {n}^{7}, \mathsf{fma}\left(0.004166666666666667, {n}^{6}, \mathsf{fma}\left({n}^{4}, 0.0625, \mathsf{fma}\left(n \cdot n, 0.35, 0.08333333333333333 \cdot {n}^{4}\right)\right)\right)\right)\right)\right)\right), x \cdot x, \mathsf{fma}\left(n \cdot n, -0.4166666666666667, \mathsf{fma}\left({n}^{4}, -0.08333333333333333, \mathsf{fma}\left({n}^{5}, 0.008333333333333333, \mathsf{fma}\left({n}^{3}, 0.2916666666666667, 0.2 \cdot n\right)\right)\right)\right) - \mathsf{fma}\left(-0.2, n, \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.008333333333333333, n, 0.08333333333333333\right), n, -0.2916666666666667\right), n, 0.4166666666666667\right) \cdot \left(n \cdot n\right)\right)\right), x \cdot x, \mathsf{fma}\left(n \cdot n, \mathsf{fma}\left(0.16666666666666666, n, -0.5\right), n \cdot 0.6666666666666666\right) - \left(n \cdot n\right) \cdot \mathsf{fma}\left(-0.16666666666666666, n, 0.5\right)\right), x \cdot x, n\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\frac{t\_0}{2}\\ \end{array} \end{array} \]
(FPCore (n x)
 :precision binary64
 (let* ((t_0 (- (exp (* n (log1p x))) (exp (* n (log1p (- x)))))))
   (if (<= t_0 0.178)
     (*
      (fma
       (*
        0.5
        (fma
         (fma
          (-
           (fma
            (* n n)
            -0.35
            (fma
             (pow n 4.0)
             -0.14583333333333334
             (fma
              (pow n 6.0)
              -0.004166666666666667
              (fma
               (pow n 7.0)
               0.0001984126984126984
               (fma
                (pow n 5.0)
                0.034722222222222224
                (fma
                 (pow n 3.0)
                 0.32222222222222224
                 (* 0.14285714285714285 n)))))))
           (fma
            -0.14285714285714285
            n
            (fma
             (pow n 3.0)
             -0.32222222222222224
             (fma
              (pow n 5.0)
              -0.034722222222222224
              (fma
               -0.0001984126984126984
               (pow n 7.0)
               (fma
                0.004166666666666667
                (pow n 6.0)
                (fma
                 (pow n 4.0)
                 0.0625
                 (fma (* n n) 0.35 (* 0.08333333333333333 (pow n 4.0))))))))))
          (* x x)
          (-
           (fma
            (* n n)
            -0.4166666666666667
            (fma
             (pow n 4.0)
             -0.08333333333333333
             (fma
              (pow n 5.0)
              0.008333333333333333
              (fma (pow n 3.0) 0.2916666666666667 (* 0.2 n)))))
           (fma
            -0.2
            n
            (*
             (fma
              (fma
               (fma -0.008333333333333333 n 0.08333333333333333)
               n
               -0.2916666666666667)
              n
              0.4166666666666667)
             (* n n)))))
         (* x x)
         (-
          (fma
           (* n n)
           (fma 0.16666666666666666 n -0.5)
           (* n 0.6666666666666666))
          (* (* n n) (fma -0.16666666666666666 n 0.5)))))
       (* x x)
       n)
      x)
     (/ t_0 2.0))))
double code(double n, double x) {
	double t_0 = exp((n * log1p(x))) - exp((n * log1p(-x)));
	double tmp;
	if (t_0 <= 0.178) {
		tmp = fma((0.5 * fma(fma((fma((n * n), -0.35, fma(pow(n, 4.0), -0.14583333333333334, fma(pow(n, 6.0), -0.004166666666666667, fma(pow(n, 7.0), 0.0001984126984126984, fma(pow(n, 5.0), 0.034722222222222224, fma(pow(n, 3.0), 0.32222222222222224, (0.14285714285714285 * n))))))) - fma(-0.14285714285714285, n, fma(pow(n, 3.0), -0.32222222222222224, fma(pow(n, 5.0), -0.034722222222222224, fma(-0.0001984126984126984, pow(n, 7.0), fma(0.004166666666666667, pow(n, 6.0), fma(pow(n, 4.0), 0.0625, fma((n * n), 0.35, (0.08333333333333333 * pow(n, 4.0)))))))))), (x * x), (fma((n * n), -0.4166666666666667, fma(pow(n, 4.0), -0.08333333333333333, fma(pow(n, 5.0), 0.008333333333333333, fma(pow(n, 3.0), 0.2916666666666667, (0.2 * n))))) - fma(-0.2, n, (fma(fma(fma(-0.008333333333333333, n, 0.08333333333333333), n, -0.2916666666666667), n, 0.4166666666666667) * (n * n))))), (x * x), (fma((n * n), fma(0.16666666666666666, n, -0.5), (n * 0.6666666666666666)) - ((n * n) * fma(-0.16666666666666666, n, 0.5))))), (x * x), n) * x;
	} else {
		tmp = t_0 / 2.0;
	}
	return tmp;
}
function code(n, x)
	t_0 = Float64(exp(Float64(n * log1p(x))) - exp(Float64(n * log1p(Float64(-x)))))
	tmp = 0.0
	if (t_0 <= 0.178)
		tmp = Float64(fma(Float64(0.5 * fma(fma(Float64(fma(Float64(n * n), -0.35, fma((n ^ 4.0), -0.14583333333333334, fma((n ^ 6.0), -0.004166666666666667, fma((n ^ 7.0), 0.0001984126984126984, fma((n ^ 5.0), 0.034722222222222224, fma((n ^ 3.0), 0.32222222222222224, Float64(0.14285714285714285 * n))))))) - fma(-0.14285714285714285, n, fma((n ^ 3.0), -0.32222222222222224, fma((n ^ 5.0), -0.034722222222222224, fma(-0.0001984126984126984, (n ^ 7.0), fma(0.004166666666666667, (n ^ 6.0), fma((n ^ 4.0), 0.0625, fma(Float64(n * n), 0.35, Float64(0.08333333333333333 * (n ^ 4.0)))))))))), Float64(x * x), Float64(fma(Float64(n * n), -0.4166666666666667, fma((n ^ 4.0), -0.08333333333333333, fma((n ^ 5.0), 0.008333333333333333, fma((n ^ 3.0), 0.2916666666666667, Float64(0.2 * n))))) - fma(-0.2, n, Float64(fma(fma(fma(-0.008333333333333333, n, 0.08333333333333333), n, -0.2916666666666667), n, 0.4166666666666667) * Float64(n * n))))), Float64(x * x), Float64(fma(Float64(n * n), fma(0.16666666666666666, n, -0.5), Float64(n * 0.6666666666666666)) - Float64(Float64(n * n) * fma(-0.16666666666666666, n, 0.5))))), Float64(x * x), n) * x);
	else
		tmp = Float64(t_0 / 2.0);
	end
	return tmp
end
code[n_, x_] := Block[{t$95$0 = N[(N[Exp[N[(n * N[Log[1 + x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - N[Exp[N[(n * N[Log[1 + (-x)], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 0.178], N[(N[(N[(0.5 * N[(N[(N[(N[(N[(n * n), $MachinePrecision] * -0.35 + N[(N[Power[n, 4.0], $MachinePrecision] * -0.14583333333333334 + N[(N[Power[n, 6.0], $MachinePrecision] * -0.004166666666666667 + N[(N[Power[n, 7.0], $MachinePrecision] * 0.0001984126984126984 + N[(N[Power[n, 5.0], $MachinePrecision] * 0.034722222222222224 + N[(N[Power[n, 3.0], $MachinePrecision] * 0.32222222222222224 + N[(0.14285714285714285 * n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(-0.14285714285714285 * n + N[(N[Power[n, 3.0], $MachinePrecision] * -0.32222222222222224 + N[(N[Power[n, 5.0], $MachinePrecision] * -0.034722222222222224 + N[(-0.0001984126984126984 * N[Power[n, 7.0], $MachinePrecision] + N[(0.004166666666666667 * N[Power[n, 6.0], $MachinePrecision] + N[(N[Power[n, 4.0], $MachinePrecision] * 0.0625 + N[(N[(n * n), $MachinePrecision] * 0.35 + N[(0.08333333333333333 * N[Power[n, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(x * x), $MachinePrecision] + N[(N[(N[(n * n), $MachinePrecision] * -0.4166666666666667 + N[(N[Power[n, 4.0], $MachinePrecision] * -0.08333333333333333 + N[(N[Power[n, 5.0], $MachinePrecision] * 0.008333333333333333 + N[(N[Power[n, 3.0], $MachinePrecision] * 0.2916666666666667 + N[(0.2 * n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(-0.2 * n + N[(N[(N[(N[(-0.008333333333333333 * n + 0.08333333333333333), $MachinePrecision] * n + -0.2916666666666667), $MachinePrecision] * n + 0.4166666666666667), $MachinePrecision] * N[(n * n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(x * x), $MachinePrecision] + N[(N[(N[(n * n), $MachinePrecision] * N[(0.16666666666666666 * n + -0.5), $MachinePrecision] + N[(n * 0.6666666666666666), $MachinePrecision]), $MachinePrecision] - N[(N[(n * n), $MachinePrecision] * N[(-0.16666666666666666 * n + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(x * x), $MachinePrecision] + n), $MachinePrecision] * x), $MachinePrecision], N[(t$95$0 / 2.0), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{n \cdot \mathsf{log1p}\left(-x\right)}\\
\mathbf{if}\;t\_0 \leq 0.178:\\
\;\;\;\;\mathsf{fma}\left(0.5 \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(n \cdot n, -0.35, \mathsf{fma}\left({n}^{4}, -0.14583333333333334, \mathsf{fma}\left({n}^{6}, -0.004166666666666667, \mathsf{fma}\left({n}^{7}, 0.0001984126984126984, \mathsf{fma}\left({n}^{5}, 0.034722222222222224, \mathsf{fma}\left({n}^{3}, 0.32222222222222224, 0.14285714285714285 \cdot n\right)\right)\right)\right)\right)\right) - \mathsf{fma}\left(-0.14285714285714285, n, \mathsf{fma}\left({n}^{3}, -0.32222222222222224, \mathsf{fma}\left({n}^{5}, -0.034722222222222224, \mathsf{fma}\left(-0.0001984126984126984, {n}^{7}, \mathsf{fma}\left(0.004166666666666667, {n}^{6}, \mathsf{fma}\left({n}^{4}, 0.0625, \mathsf{fma}\left(n \cdot n, 0.35, 0.08333333333333333 \cdot {n}^{4}\right)\right)\right)\right)\right)\right)\right), x \cdot x, \mathsf{fma}\left(n \cdot n, -0.4166666666666667, \mathsf{fma}\left({n}^{4}, -0.08333333333333333, \mathsf{fma}\left({n}^{5}, 0.008333333333333333, \mathsf{fma}\left({n}^{3}, 0.2916666666666667, 0.2 \cdot n\right)\right)\right)\right) - \mathsf{fma}\left(-0.2, n, \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.008333333333333333, n, 0.08333333333333333\right), n, -0.2916666666666667\right), n, 0.4166666666666667\right) \cdot \left(n \cdot n\right)\right)\right), x \cdot x, \mathsf{fma}\left(n \cdot n, \mathsf{fma}\left(0.16666666666666666, n, -0.5\right), n \cdot 0.6666666666666666\right) - \left(n \cdot n\right) \cdot \mathsf{fma}\left(-0.16666666666666666, n, 0.5\right)\right), x \cdot x, n\right) \cdot x\\

\mathbf{else}:\\
\;\;\;\;\frac{t\_0}{2}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 (*.f64 n (log1p.f64 x))) (exp.f64 (*.f64 n (log1p.f64 (neg.f64 x))))) < 0.17799999999999999

    1. Initial program 77.5%

      \[\frac{e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{n \cdot \mathsf{log1p}\left(-x\right)}}{2} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \color{blue}{x \cdot \left(\frac{1}{2} \cdot \left(n - -1 \cdot n\right) + {x}^{2} \cdot \left(\frac{1}{2} \cdot \left(\left(\frac{-1}{2} \cdot {n}^{2} + \left(\frac{1}{6} \cdot {n}^{3} + \frac{1}{3} \cdot n\right)\right) - \left(\frac{-1}{3} \cdot n + \left(\frac{-1}{6} \cdot {n}^{3} + \frac{1}{2} \cdot {n}^{2}\right)\right)\right) + {x}^{2} \cdot \left(\frac{1}{2} \cdot \left({x}^{2} \cdot \left(\left(\frac{-1}{6} \cdot {n}^{2} + \left(\frac{-1}{10} \cdot {n}^{2} + \left(\frac{-1}{12} \cdot {n}^{2} + \left(\frac{-1}{12} \cdot {n}^{4} + \left(\frac{-1}{24} \cdot {n}^{4} + \left(\frac{-1}{48} \cdot {n}^{4} + \left(\frac{-1}{240} \cdot {n}^{6} + \left(\frac{1}{5040} \cdot {n}^{7} + \left(\frac{1}{72} \cdot {n}^{5} + \left(\frac{1}{48} \cdot {n}^{5} + \left(\frac{1}{24} \cdot {n}^{3} + \left(\frac{1}{18} \cdot {n}^{3} + \left(\frac{1}{10} \cdot {n}^{3} + \left(\frac{1}{8} \cdot {n}^{3} + \frac{1}{7} \cdot n\right)\right)\right)\right)\right)\right)\right)\right)\right)\right)\right)\right)\right)\right) - \left(\frac{-1}{7} \cdot n + \left(\frac{-1}{8} \cdot {n}^{3} + \left(\frac{-1}{10} \cdot {n}^{3} + \left(\frac{-1}{18} \cdot {n}^{3} + \left(\frac{-1}{24} \cdot {n}^{3} + \left(\frac{-1}{48} \cdot {n}^{5} + \left(\frac{-1}{72} \cdot {n}^{5} + \left(\frac{-1}{5040} \cdot {n}^{7} + \left(\frac{1}{240} \cdot {n}^{6} + \left(\frac{1}{48} \cdot {n}^{4} + \left(\frac{1}{24} \cdot {n}^{4} + \left(\frac{1}{12} \cdot {n}^{2} + \left(\frac{1}{12} \cdot {n}^{4} + \left(\frac{1}{10} \cdot {n}^{2} + \frac{1}{6} \cdot {n}^{2}\right)\right)\right)\right)\right)\right)\right)\right)\right)\right)\right)\right)\right)\right)\right)\right) + \frac{1}{2} \cdot \left(\left(\frac{-1}{4} \cdot {n}^{2} + \left(\frac{-1}{6} \cdot {n}^{2} + \left(\frac{-1}{12} \cdot {n}^{4} + \left(\frac{1}{120} \cdot {n}^{5} + \left(\frac{1}{8} \cdot {n}^{3} + \left(\frac{1}{6} \cdot {n}^{3} + \frac{1}{5} \cdot n\right)\right)\right)\right)\right)\right) - \left(\frac{-1}{5} \cdot n + \left(\frac{-1}{6} \cdot {n}^{3} + \left(\frac{-1}{8} \cdot {n}^{3} + \left(\frac{-1}{120} \cdot {n}^{5} + \left(\frac{1}{12} \cdot {n}^{4} + \left(\frac{1}{6} \cdot {n}^{2} + \frac{1}{4} \cdot {n}^{2}\right)\right)\right)\right)\right)\right)\right)\right)\right)\right)} \]
    4. Applied rewrites99.7%

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.5 \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(n \cdot n, -0.35, \mathsf{fma}\left({n}^{4}, -0.14583333333333334, \mathsf{fma}\left({n}^{6}, -0.004166666666666667, \mathsf{fma}\left({n}^{7}, 0.0001984126984126984, \mathsf{fma}\left({n}^{5}, 0.034722222222222224, \mathsf{fma}\left({n}^{3}, 0.32222222222222224, 0.14285714285714285 \cdot n\right)\right)\right)\right)\right)\right) - \mathsf{fma}\left(-0.14285714285714285, n, \mathsf{fma}\left({n}^{3}, -0.32222222222222224, \mathsf{fma}\left({n}^{5}, -0.034722222222222224, \mathsf{fma}\left(-0.0001984126984126984, {n}^{7}, \mathsf{fma}\left(0.004166666666666667, {n}^{6}, \mathsf{fma}\left({n}^{4}, 0.0625, \mathsf{fma}\left(n \cdot n, 0.35, 0.08333333333333333 \cdot {n}^{4}\right)\right)\right)\right)\right)\right)\right), x \cdot x, \mathsf{fma}\left(n \cdot n, -0.4166666666666667, \mathsf{fma}\left({n}^{4}, -0.08333333333333333, \mathsf{fma}\left({n}^{5}, 0.008333333333333333, \mathsf{fma}\left({n}^{3}, 0.2916666666666667, 0.2 \cdot n\right)\right)\right)\right) - \mathsf{fma}\left(-0.2, n, \mathsf{fma}\left({n}^{3}, -0.2916666666666667, \mathsf{fma}\left(-0.008333333333333333, {n}^{5}, \mathsf{fma}\left(0.4166666666666667, n \cdot n, 0.08333333333333333 \cdot {n}^{4}\right)\right)\right)\right)\right), x \cdot x, \mathsf{fma}\left(n \cdot n, \mathsf{fma}\left(0.16666666666666666, n, -0.5\right), n \cdot 0.6666666666666666\right) - \left(n \cdot n\right) \cdot \mathsf{fma}\left(-0.16666666666666666, n, 0.5\right)\right), x \cdot x, n\right) \cdot x} \]
    5. Taylor expanded in n around 0

      \[\leadsto \mathsf{fma}\left(\frac{1}{2} \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(n \cdot n, \frac{-7}{20}, \mathsf{fma}\left({n}^{4}, \frac{-7}{48}, \mathsf{fma}\left({n}^{6}, \frac{-1}{240}, \mathsf{fma}\left({n}^{7}, \frac{1}{5040}, \mathsf{fma}\left({n}^{5}, \frac{5}{144}, \mathsf{fma}\left({n}^{3}, \frac{29}{90}, \frac{1}{7} \cdot n\right)\right)\right)\right)\right)\right) - \mathsf{fma}\left(\frac{-1}{7}, n, \mathsf{fma}\left({n}^{3}, \frac{-29}{90}, \mathsf{fma}\left({n}^{5}, \frac{-5}{144}, \mathsf{fma}\left(\frac{-1}{5040}, {n}^{7}, \mathsf{fma}\left(\frac{1}{240}, {n}^{6}, \mathsf{fma}\left({n}^{4}, \frac{1}{16}, \mathsf{fma}\left(n \cdot n, \frac{7}{20}, \frac{1}{12} \cdot {n}^{4}\right)\right)\right)\right)\right)\right)\right), x \cdot x, \mathsf{fma}\left(n \cdot n, \frac{-5}{12}, \mathsf{fma}\left({n}^{4}, \frac{-1}{12}, \mathsf{fma}\left({n}^{5}, \frac{1}{120}, \mathsf{fma}\left({n}^{3}, \frac{7}{24}, \frac{1}{5} \cdot n\right)\right)\right)\right) - \mathsf{fma}\left(\frac{-1}{5}, n, {n}^{2} \cdot \left(\frac{5}{12} + n \cdot \left(n \cdot \left(\frac{1}{12} + \frac{-1}{120} \cdot n\right) - \frac{7}{24}\right)\right)\right)\right), x \cdot x, \mathsf{fma}\left(n \cdot n, \mathsf{fma}\left(\frac{1}{6}, n, \frac{-1}{2}\right), n \cdot \frac{2}{3}\right) - \left(n \cdot n\right) \cdot \mathsf{fma}\left(\frac{-1}{6}, n, \frac{1}{2}\right)\right), x \cdot x, n\right) \cdot x \]
    6. Step-by-step derivation
      1. Applied rewrites99.7%

        \[\leadsto \mathsf{fma}\left(0.5 \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(n \cdot n, -0.35, \mathsf{fma}\left({n}^{4}, -0.14583333333333334, \mathsf{fma}\left({n}^{6}, -0.004166666666666667, \mathsf{fma}\left({n}^{7}, 0.0001984126984126984, \mathsf{fma}\left({n}^{5}, 0.034722222222222224, \mathsf{fma}\left({n}^{3}, 0.32222222222222224, 0.14285714285714285 \cdot n\right)\right)\right)\right)\right)\right) - \mathsf{fma}\left(-0.14285714285714285, n, \mathsf{fma}\left({n}^{3}, -0.32222222222222224, \mathsf{fma}\left({n}^{5}, -0.034722222222222224, \mathsf{fma}\left(-0.0001984126984126984, {n}^{7}, \mathsf{fma}\left(0.004166666666666667, {n}^{6}, \mathsf{fma}\left({n}^{4}, 0.0625, \mathsf{fma}\left(n \cdot n, 0.35, 0.08333333333333333 \cdot {n}^{4}\right)\right)\right)\right)\right)\right)\right), x \cdot x, \mathsf{fma}\left(n \cdot n, -0.4166666666666667, \mathsf{fma}\left({n}^{4}, -0.08333333333333333, \mathsf{fma}\left({n}^{5}, 0.008333333333333333, \mathsf{fma}\left({n}^{3}, 0.2916666666666667, 0.2 \cdot n\right)\right)\right)\right) - \mathsf{fma}\left(-0.2, n, \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.008333333333333333, n, 0.08333333333333333\right), n, -0.2916666666666667\right), n, 0.4166666666666667\right) \cdot \left(n \cdot n\right)\right)\right), x \cdot x, \mathsf{fma}\left(n \cdot n, \mathsf{fma}\left(0.16666666666666666, n, -0.5\right), n \cdot 0.6666666666666666\right) - \left(n \cdot n\right) \cdot \mathsf{fma}\left(-0.16666666666666666, n, 0.5\right)\right), x \cdot x, n\right) \cdot x \]

      if 0.17799999999999999 < (-.f64 (exp.f64 (*.f64 n (log1p.f64 x))) (exp.f64 (*.f64 n (log1p.f64 (neg.f64 x)))))

      1. Initial program 98.3%

        \[\frac{e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{n \cdot \mathsf{log1p}\left(-x\right)}}{2} \]
      2. Add Preprocessing
    7. Recombined 2 regimes into one program.
    8. Add Preprocessing

    Alternative 2: 99.0% accurate, 0.3× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 0.0021:\\ \;\;\;\;\mathsf{fma}\left(0.5 \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(n \cdot n, -0.35, \mathsf{fma}\left({n}^{4}, -0.14583333333333334, \mathsf{fma}\left({n}^{6}, -0.004166666666666667, \mathsf{fma}\left({n}^{7}, 0.0001984126984126984, \mathsf{fma}\left({n}^{5}, 0.034722222222222224, \mathsf{fma}\left({n}^{3}, 0.32222222222222224, 0.14285714285714285 \cdot n\right)\right)\right)\right)\right)\right) - \left(-\left(0.0001984126984126984 - \frac{0.004166666666666667 - \frac{0.034722222222222224 - \frac{0.14583333333333334}{n}}{n}}{n}\right)\right) \cdot {n}^{7}, x \cdot x, \mathsf{fma}\left(n \cdot n, -0.4166666666666667, \mathsf{fma}\left({n}^{4}, -0.08333333333333333, \mathsf{fma}\left({n}^{5}, 0.008333333333333333, \mathsf{fma}\left({n}^{3}, 0.2916666666666667, 0.2 \cdot n\right)\right)\right)\right) - \mathsf{fma}\left(-0.2, n, \mathsf{fma}\left({n}^{3}, -0.2916666666666667, \mathsf{fma}\left(-0.008333333333333333, {n}^{5}, \mathsf{fma}\left(0.4166666666666667, n \cdot n, 0.08333333333333333 \cdot {n}^{4}\right)\right)\right)\right)\right), x \cdot x, \mathsf{fma}\left(n \cdot n, \mathsf{fma}\left(0.16666666666666666, n, -0.5\right), n \cdot 0.6666666666666666\right) - \left(n \cdot n\right) \cdot \mathsf{fma}\left(-0.16666666666666666, n, 0.5\right)\right), x \cdot x, n\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{n \cdot \mathsf{log1p}\left(-x\right)}}{2}\\ \end{array} \end{array} \]
    (FPCore (n x)
     :precision binary64
     (if (<= x 0.0021)
       (*
        (fma
         (*
          0.5
          (fma
           (fma
            (-
             (fma
              (* n n)
              -0.35
              (fma
               (pow n 4.0)
               -0.14583333333333334
               (fma
                (pow n 6.0)
                -0.004166666666666667
                (fma
                 (pow n 7.0)
                 0.0001984126984126984
                 (fma
                  (pow n 5.0)
                  0.034722222222222224
                  (fma
                   (pow n 3.0)
                   0.32222222222222224
                   (* 0.14285714285714285 n)))))))
             (*
              (-
               (-
                0.0001984126984126984
                (/
                 (-
                  0.004166666666666667
                  (/ (- 0.034722222222222224 (/ 0.14583333333333334 n)) n))
                 n)))
              (pow n 7.0)))
            (* x x)
            (-
             (fma
              (* n n)
              -0.4166666666666667
              (fma
               (pow n 4.0)
               -0.08333333333333333
               (fma
                (pow n 5.0)
                0.008333333333333333
                (fma (pow n 3.0) 0.2916666666666667 (* 0.2 n)))))
             (fma
              -0.2
              n
              (fma
               (pow n 3.0)
               -0.2916666666666667
               (fma
                -0.008333333333333333
                (pow n 5.0)
                (fma
                 0.4166666666666667
                 (* n n)
                 (* 0.08333333333333333 (pow n 4.0))))))))
           (* x x)
           (-
            (fma (* n n) (fma 0.16666666666666666 n -0.5) (* n 0.6666666666666666))
            (* (* n n) (fma -0.16666666666666666 n 0.5)))))
         (* x x)
         n)
        x)
       (/ (- (exp (* n (log1p x))) (exp (* n (log1p (- x))))) 2.0)))
    double code(double n, double x) {
    	double tmp;
    	if (x <= 0.0021) {
    		tmp = fma((0.5 * fma(fma((fma((n * n), -0.35, fma(pow(n, 4.0), -0.14583333333333334, fma(pow(n, 6.0), -0.004166666666666667, fma(pow(n, 7.0), 0.0001984126984126984, fma(pow(n, 5.0), 0.034722222222222224, fma(pow(n, 3.0), 0.32222222222222224, (0.14285714285714285 * n))))))) - (-(0.0001984126984126984 - ((0.004166666666666667 - ((0.034722222222222224 - (0.14583333333333334 / n)) / n)) / n)) * pow(n, 7.0))), (x * x), (fma((n * n), -0.4166666666666667, fma(pow(n, 4.0), -0.08333333333333333, fma(pow(n, 5.0), 0.008333333333333333, fma(pow(n, 3.0), 0.2916666666666667, (0.2 * n))))) - fma(-0.2, n, fma(pow(n, 3.0), -0.2916666666666667, fma(-0.008333333333333333, pow(n, 5.0), fma(0.4166666666666667, (n * n), (0.08333333333333333 * pow(n, 4.0)))))))), (x * x), (fma((n * n), fma(0.16666666666666666, n, -0.5), (n * 0.6666666666666666)) - ((n * n) * fma(-0.16666666666666666, n, 0.5))))), (x * x), n) * x;
    	} else {
    		tmp = (exp((n * log1p(x))) - exp((n * log1p(-x)))) / 2.0;
    	}
    	return tmp;
    }
    
    function code(n, x)
    	tmp = 0.0
    	if (x <= 0.0021)
    		tmp = Float64(fma(Float64(0.5 * fma(fma(Float64(fma(Float64(n * n), -0.35, fma((n ^ 4.0), -0.14583333333333334, fma((n ^ 6.0), -0.004166666666666667, fma((n ^ 7.0), 0.0001984126984126984, fma((n ^ 5.0), 0.034722222222222224, fma((n ^ 3.0), 0.32222222222222224, Float64(0.14285714285714285 * n))))))) - Float64(Float64(-Float64(0.0001984126984126984 - Float64(Float64(0.004166666666666667 - Float64(Float64(0.034722222222222224 - Float64(0.14583333333333334 / n)) / n)) / n))) * (n ^ 7.0))), Float64(x * x), Float64(fma(Float64(n * n), -0.4166666666666667, fma((n ^ 4.0), -0.08333333333333333, fma((n ^ 5.0), 0.008333333333333333, fma((n ^ 3.0), 0.2916666666666667, Float64(0.2 * n))))) - fma(-0.2, n, fma((n ^ 3.0), -0.2916666666666667, fma(-0.008333333333333333, (n ^ 5.0), fma(0.4166666666666667, Float64(n * n), Float64(0.08333333333333333 * (n ^ 4.0)))))))), Float64(x * x), Float64(fma(Float64(n * n), fma(0.16666666666666666, n, -0.5), Float64(n * 0.6666666666666666)) - Float64(Float64(n * n) * fma(-0.16666666666666666, n, 0.5))))), Float64(x * x), n) * x);
    	else
    		tmp = Float64(Float64(exp(Float64(n * log1p(x))) - exp(Float64(n * log1p(Float64(-x))))) / 2.0);
    	end
    	return tmp
    end
    
    code[n_, x_] := If[LessEqual[x, 0.0021], N[(N[(N[(0.5 * N[(N[(N[(N[(N[(n * n), $MachinePrecision] * -0.35 + N[(N[Power[n, 4.0], $MachinePrecision] * -0.14583333333333334 + N[(N[Power[n, 6.0], $MachinePrecision] * -0.004166666666666667 + N[(N[Power[n, 7.0], $MachinePrecision] * 0.0001984126984126984 + N[(N[Power[n, 5.0], $MachinePrecision] * 0.034722222222222224 + N[(N[Power[n, 3.0], $MachinePrecision] * 0.32222222222222224 + N[(0.14285714285714285 * n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[((-N[(0.0001984126984126984 - N[(N[(0.004166666666666667 - N[(N[(0.034722222222222224 - N[(0.14583333333333334 / n), $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision]), $MachinePrecision]) * N[Power[n, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(x * x), $MachinePrecision] + N[(N[(N[(n * n), $MachinePrecision] * -0.4166666666666667 + N[(N[Power[n, 4.0], $MachinePrecision] * -0.08333333333333333 + N[(N[Power[n, 5.0], $MachinePrecision] * 0.008333333333333333 + N[(N[Power[n, 3.0], $MachinePrecision] * 0.2916666666666667 + N[(0.2 * n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(-0.2 * n + N[(N[Power[n, 3.0], $MachinePrecision] * -0.2916666666666667 + N[(-0.008333333333333333 * N[Power[n, 5.0], $MachinePrecision] + N[(0.4166666666666667 * N[(n * n), $MachinePrecision] + N[(0.08333333333333333 * N[Power[n, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(x * x), $MachinePrecision] + N[(N[(N[(n * n), $MachinePrecision] * N[(0.16666666666666666 * n + -0.5), $MachinePrecision] + N[(n * 0.6666666666666666), $MachinePrecision]), $MachinePrecision] - N[(N[(n * n), $MachinePrecision] * N[(-0.16666666666666666 * n + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(x * x), $MachinePrecision] + n), $MachinePrecision] * x), $MachinePrecision], N[(N[(N[Exp[N[(n * N[Log[1 + x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - N[Exp[N[(n * N[Log[1 + (-x)], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;x \leq 0.0021:\\
    \;\;\;\;\mathsf{fma}\left(0.5 \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(n \cdot n, -0.35, \mathsf{fma}\left({n}^{4}, -0.14583333333333334, \mathsf{fma}\left({n}^{6}, -0.004166666666666667, \mathsf{fma}\left({n}^{7}, 0.0001984126984126984, \mathsf{fma}\left({n}^{5}, 0.034722222222222224, \mathsf{fma}\left({n}^{3}, 0.32222222222222224, 0.14285714285714285 \cdot n\right)\right)\right)\right)\right)\right) - \left(-\left(0.0001984126984126984 - \frac{0.004166666666666667 - \frac{0.034722222222222224 - \frac{0.14583333333333334}{n}}{n}}{n}\right)\right) \cdot {n}^{7}, x \cdot x, \mathsf{fma}\left(n \cdot n, -0.4166666666666667, \mathsf{fma}\left({n}^{4}, -0.08333333333333333, \mathsf{fma}\left({n}^{5}, 0.008333333333333333, \mathsf{fma}\left({n}^{3}, 0.2916666666666667, 0.2 \cdot n\right)\right)\right)\right) - \mathsf{fma}\left(-0.2, n, \mathsf{fma}\left({n}^{3}, -0.2916666666666667, \mathsf{fma}\left(-0.008333333333333333, {n}^{5}, \mathsf{fma}\left(0.4166666666666667, n \cdot n, 0.08333333333333333 \cdot {n}^{4}\right)\right)\right)\right)\right), x \cdot x, \mathsf{fma}\left(n \cdot n, \mathsf{fma}\left(0.16666666666666666, n, -0.5\right), n \cdot 0.6666666666666666\right) - \left(n \cdot n\right) \cdot \mathsf{fma}\left(-0.16666666666666666, n, 0.5\right)\right), x \cdot x, n\right) \cdot x\\
    
    \mathbf{else}:\\
    \;\;\;\;\frac{e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{n \cdot \mathsf{log1p}\left(-x\right)}}{2}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if x < 0.00209999999999999987

      1. Initial program 76.0%

        \[\frac{e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{n \cdot \mathsf{log1p}\left(-x\right)}}{2} \]
      2. Add Preprocessing
      3. Taylor expanded in x around 0

        \[\leadsto \color{blue}{x \cdot \left(\frac{1}{2} \cdot \left(n - -1 \cdot n\right) + {x}^{2} \cdot \left(\frac{1}{2} \cdot \left(\left(\frac{-1}{2} \cdot {n}^{2} + \left(\frac{1}{6} \cdot {n}^{3} + \frac{1}{3} \cdot n\right)\right) - \left(\frac{-1}{3} \cdot n + \left(\frac{-1}{6} \cdot {n}^{3} + \frac{1}{2} \cdot {n}^{2}\right)\right)\right) + {x}^{2} \cdot \left(\frac{1}{2} \cdot \left({x}^{2} \cdot \left(\left(\frac{-1}{6} \cdot {n}^{2} + \left(\frac{-1}{10} \cdot {n}^{2} + \left(\frac{-1}{12} \cdot {n}^{2} + \left(\frac{-1}{12} \cdot {n}^{4} + \left(\frac{-1}{24} \cdot {n}^{4} + \left(\frac{-1}{48} \cdot {n}^{4} + \left(\frac{-1}{240} \cdot {n}^{6} + \left(\frac{1}{5040} \cdot {n}^{7} + \left(\frac{1}{72} \cdot {n}^{5} + \left(\frac{1}{48} \cdot {n}^{5} + \left(\frac{1}{24} \cdot {n}^{3} + \left(\frac{1}{18} \cdot {n}^{3} + \left(\frac{1}{10} \cdot {n}^{3} + \left(\frac{1}{8} \cdot {n}^{3} + \frac{1}{7} \cdot n\right)\right)\right)\right)\right)\right)\right)\right)\right)\right)\right)\right)\right)\right) - \left(\frac{-1}{7} \cdot n + \left(\frac{-1}{8} \cdot {n}^{3} + \left(\frac{-1}{10} \cdot {n}^{3} + \left(\frac{-1}{18} \cdot {n}^{3} + \left(\frac{-1}{24} \cdot {n}^{3} + \left(\frac{-1}{48} \cdot {n}^{5} + \left(\frac{-1}{72} \cdot {n}^{5} + \left(\frac{-1}{5040} \cdot {n}^{7} + \left(\frac{1}{240} \cdot {n}^{6} + \left(\frac{1}{48} \cdot {n}^{4} + \left(\frac{1}{24} \cdot {n}^{4} + \left(\frac{1}{12} \cdot {n}^{2} + \left(\frac{1}{12} \cdot {n}^{4} + \left(\frac{1}{10} \cdot {n}^{2} + \frac{1}{6} \cdot {n}^{2}\right)\right)\right)\right)\right)\right)\right)\right)\right)\right)\right)\right)\right)\right)\right)\right) + \frac{1}{2} \cdot \left(\left(\frac{-1}{4} \cdot {n}^{2} + \left(\frac{-1}{6} \cdot {n}^{2} + \left(\frac{-1}{12} \cdot {n}^{4} + \left(\frac{1}{120} \cdot {n}^{5} + \left(\frac{1}{8} \cdot {n}^{3} + \left(\frac{1}{6} \cdot {n}^{3} + \frac{1}{5} \cdot n\right)\right)\right)\right)\right)\right) - \left(\frac{-1}{5} \cdot n + \left(\frac{-1}{6} \cdot {n}^{3} + \left(\frac{-1}{8} \cdot {n}^{3} + \left(\frac{-1}{120} \cdot {n}^{5} + \left(\frac{1}{12} \cdot {n}^{4} + \left(\frac{1}{6} \cdot {n}^{2} + \frac{1}{4} \cdot {n}^{2}\right)\right)\right)\right)\right)\right)\right)\right)\right)\right)} \]
      4. Applied rewrites99.7%

        \[\leadsto \color{blue}{\mathsf{fma}\left(0.5 \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(n \cdot n, -0.35, \mathsf{fma}\left({n}^{4}, -0.14583333333333334, \mathsf{fma}\left({n}^{6}, -0.004166666666666667, \mathsf{fma}\left({n}^{7}, 0.0001984126984126984, \mathsf{fma}\left({n}^{5}, 0.034722222222222224, \mathsf{fma}\left({n}^{3}, 0.32222222222222224, 0.14285714285714285 \cdot n\right)\right)\right)\right)\right)\right) - \mathsf{fma}\left(-0.14285714285714285, n, \mathsf{fma}\left({n}^{3}, -0.32222222222222224, \mathsf{fma}\left({n}^{5}, -0.034722222222222224, \mathsf{fma}\left(-0.0001984126984126984, {n}^{7}, \mathsf{fma}\left(0.004166666666666667, {n}^{6}, \mathsf{fma}\left({n}^{4}, 0.0625, \mathsf{fma}\left(n \cdot n, 0.35, 0.08333333333333333 \cdot {n}^{4}\right)\right)\right)\right)\right)\right)\right), x \cdot x, \mathsf{fma}\left(n \cdot n, -0.4166666666666667, \mathsf{fma}\left({n}^{4}, -0.08333333333333333, \mathsf{fma}\left({n}^{5}, 0.008333333333333333, \mathsf{fma}\left({n}^{3}, 0.2916666666666667, 0.2 \cdot n\right)\right)\right)\right) - \mathsf{fma}\left(-0.2, n, \mathsf{fma}\left({n}^{3}, -0.2916666666666667, \mathsf{fma}\left(-0.008333333333333333, {n}^{5}, \mathsf{fma}\left(0.4166666666666667, n \cdot n, 0.08333333333333333 \cdot {n}^{4}\right)\right)\right)\right)\right), x \cdot x, \mathsf{fma}\left(n \cdot n, \mathsf{fma}\left(0.16666666666666666, n, -0.5\right), n \cdot 0.6666666666666666\right) - \left(n \cdot n\right) \cdot \mathsf{fma}\left(-0.16666666666666666, n, 0.5\right)\right), x \cdot x, n\right) \cdot x} \]
      5. Taylor expanded in n around -inf

        \[\leadsto \mathsf{fma}\left(\frac{1}{2} \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(n \cdot n, \frac{-7}{20}, \mathsf{fma}\left({n}^{4}, \frac{-7}{48}, \mathsf{fma}\left({n}^{6}, \frac{-1}{240}, \mathsf{fma}\left({n}^{7}, \frac{1}{5040}, \mathsf{fma}\left({n}^{5}, \frac{5}{144}, \mathsf{fma}\left({n}^{3}, \frac{29}{90}, \frac{1}{7} \cdot n\right)\right)\right)\right)\right)\right) - -1 \cdot \left({n}^{7} \cdot \left(\frac{1}{5040} + -1 \cdot \frac{\frac{1}{240} + -1 \cdot \frac{\frac{5}{144} - \frac{7}{48} \cdot \frac{1}{n}}{n}}{n}\right)\right), x \cdot x, \mathsf{fma}\left(n \cdot n, \frac{-5}{12}, \mathsf{fma}\left({n}^{4}, \frac{-1}{12}, \mathsf{fma}\left({n}^{5}, \frac{1}{120}, \mathsf{fma}\left({n}^{3}, \frac{7}{24}, \frac{1}{5} \cdot n\right)\right)\right)\right) - \mathsf{fma}\left(\frac{-1}{5}, n, \mathsf{fma}\left({n}^{3}, \frac{-7}{24}, \mathsf{fma}\left(\frac{-1}{120}, {n}^{5}, \mathsf{fma}\left(\frac{5}{12}, n \cdot n, \frac{1}{12} \cdot {n}^{4}\right)\right)\right)\right)\right), x \cdot x, \mathsf{fma}\left(n \cdot n, \mathsf{fma}\left(\frac{1}{6}, n, \frac{-1}{2}\right), n \cdot \frac{2}{3}\right) - \left(n \cdot n\right) \cdot \mathsf{fma}\left(\frac{-1}{6}, n, \frac{1}{2}\right)\right), x \cdot x, n\right) \cdot x \]
      6. Step-by-step derivation
        1. Applied rewrites99.7%

          \[\leadsto \mathsf{fma}\left(0.5 \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(n \cdot n, -0.35, \mathsf{fma}\left({n}^{4}, -0.14583333333333334, \mathsf{fma}\left({n}^{6}, -0.004166666666666667, \mathsf{fma}\left({n}^{7}, 0.0001984126984126984, \mathsf{fma}\left({n}^{5}, 0.034722222222222224, \mathsf{fma}\left({n}^{3}, 0.32222222222222224, 0.14285714285714285 \cdot n\right)\right)\right)\right)\right)\right) - \left(-\left(0.0001984126984126984 - \frac{0.004166666666666667 - \frac{0.034722222222222224 - \frac{0.14583333333333334}{n}}{n}}{n}\right)\right) \cdot {n}^{7}, x \cdot x, \mathsf{fma}\left(n \cdot n, -0.4166666666666667, \mathsf{fma}\left({n}^{4}, -0.08333333333333333, \mathsf{fma}\left({n}^{5}, 0.008333333333333333, \mathsf{fma}\left({n}^{3}, 0.2916666666666667, 0.2 \cdot n\right)\right)\right)\right) - \mathsf{fma}\left(-0.2, n, \mathsf{fma}\left({n}^{3}, -0.2916666666666667, \mathsf{fma}\left(-0.008333333333333333, {n}^{5}, \mathsf{fma}\left(0.4166666666666667, n \cdot n, 0.08333333333333333 \cdot {n}^{4}\right)\right)\right)\right)\right), x \cdot x, \mathsf{fma}\left(n \cdot n, \mathsf{fma}\left(0.16666666666666666, n, -0.5\right), n \cdot 0.6666666666666666\right) - \left(n \cdot n\right) \cdot \mathsf{fma}\left(-0.16666666666666666, n, 0.5\right)\right), x \cdot x, n\right) \cdot x \]

        if 0.00209999999999999987 < x

        1. Initial program 97.8%

          \[\frac{e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{n \cdot \mathsf{log1p}\left(-x\right)}}{2} \]
        2. Add Preprocessing
      7. Recombined 2 regimes into one program.
      8. Add Preprocessing

      Alternative 3: 99.1% accurate, 0.4× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{n \cdot \mathsf{log1p}\left(-x\right)}\\ \mathbf{if}\;t\_0 \leq 0.028:\\ \;\;\;\;\mathsf{fma}\left(\left(x \cdot x\right) \cdot 0.5, \mathsf{fma}\left(\left(\mathsf{fma}\left(n \cdot n, -0.4166666666666667, \mathsf{fma}\left({n}^{4}, -0.08333333333333333, \mathsf{fma}\left({n}^{5}, 0.008333333333333333, \mathsf{fma}\left({n}^{3}, 0.2916666666666667, 0.2 \cdot n\right)\right)\right)\right) - \mathsf{fma}\left(-0.2, n, \mathsf{fma}\left({n}^{3}, -0.2916666666666667, \mathsf{fma}\left(-0.008333333333333333, {n}^{5}, \mathsf{fma}\left(0.4166666666666667, n \cdot n, 0.08333333333333333 \cdot {n}^{4}\right)\right)\right)\right)\right) \cdot x, x, \mathsf{fma}\left(n \cdot n, \mathsf{fma}\left(0.16666666666666666, n, -0.5\right), n \cdot 0.6666666666666666\right) - \left(n \cdot n\right) \cdot \mathsf{fma}\left(-0.16666666666666666, n, 0.5\right)\right), n\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\frac{t\_0}{2}\\ \end{array} \end{array} \]
      (FPCore (n x)
       :precision binary64
       (let* ((t_0 (- (exp (* n (log1p x))) (exp (* n (log1p (- x)))))))
         (if (<= t_0 0.028)
           (*
            (fma
             (* (* x x) 0.5)
             (fma
              (*
               (-
                (fma
                 (* n n)
                 -0.4166666666666667
                 (fma
                  (pow n 4.0)
                  -0.08333333333333333
                  (fma
                   (pow n 5.0)
                   0.008333333333333333
                   (fma (pow n 3.0) 0.2916666666666667 (* 0.2 n)))))
                (fma
                 -0.2
                 n
                 (fma
                  (pow n 3.0)
                  -0.2916666666666667
                  (fma
                   -0.008333333333333333
                   (pow n 5.0)
                   (fma
                    0.4166666666666667
                    (* n n)
                    (* 0.08333333333333333 (pow n 4.0)))))))
               x)
              x
              (-
               (fma
                (* n n)
                (fma 0.16666666666666666 n -0.5)
                (* n 0.6666666666666666))
               (* (* n n) (fma -0.16666666666666666 n 0.5))))
             n)
            x)
           (/ t_0 2.0))))
      double code(double n, double x) {
      	double t_0 = exp((n * log1p(x))) - exp((n * log1p(-x)));
      	double tmp;
      	if (t_0 <= 0.028) {
      		tmp = fma(((x * x) * 0.5), fma(((fma((n * n), -0.4166666666666667, fma(pow(n, 4.0), -0.08333333333333333, fma(pow(n, 5.0), 0.008333333333333333, fma(pow(n, 3.0), 0.2916666666666667, (0.2 * n))))) - fma(-0.2, n, fma(pow(n, 3.0), -0.2916666666666667, fma(-0.008333333333333333, pow(n, 5.0), fma(0.4166666666666667, (n * n), (0.08333333333333333 * pow(n, 4.0))))))) * x), x, (fma((n * n), fma(0.16666666666666666, n, -0.5), (n * 0.6666666666666666)) - ((n * n) * fma(-0.16666666666666666, n, 0.5)))), n) * x;
      	} else {
      		tmp = t_0 / 2.0;
      	}
      	return tmp;
      }
      
      function code(n, x)
      	t_0 = Float64(exp(Float64(n * log1p(x))) - exp(Float64(n * log1p(Float64(-x)))))
      	tmp = 0.0
      	if (t_0 <= 0.028)
      		tmp = Float64(fma(Float64(Float64(x * x) * 0.5), fma(Float64(Float64(fma(Float64(n * n), -0.4166666666666667, fma((n ^ 4.0), -0.08333333333333333, fma((n ^ 5.0), 0.008333333333333333, fma((n ^ 3.0), 0.2916666666666667, Float64(0.2 * n))))) - fma(-0.2, n, fma((n ^ 3.0), -0.2916666666666667, fma(-0.008333333333333333, (n ^ 5.0), fma(0.4166666666666667, Float64(n * n), Float64(0.08333333333333333 * (n ^ 4.0))))))) * x), x, Float64(fma(Float64(n * n), fma(0.16666666666666666, n, -0.5), Float64(n * 0.6666666666666666)) - Float64(Float64(n * n) * fma(-0.16666666666666666, n, 0.5)))), n) * x);
      	else
      		tmp = Float64(t_0 / 2.0);
      	end
      	return tmp
      end
      
      code[n_, x_] := Block[{t$95$0 = N[(N[Exp[N[(n * N[Log[1 + x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - N[Exp[N[(n * N[Log[1 + (-x)], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 0.028], N[(N[(N[(N[(x * x), $MachinePrecision] * 0.5), $MachinePrecision] * N[(N[(N[(N[(N[(n * n), $MachinePrecision] * -0.4166666666666667 + N[(N[Power[n, 4.0], $MachinePrecision] * -0.08333333333333333 + N[(N[Power[n, 5.0], $MachinePrecision] * 0.008333333333333333 + N[(N[Power[n, 3.0], $MachinePrecision] * 0.2916666666666667 + N[(0.2 * n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(-0.2 * n + N[(N[Power[n, 3.0], $MachinePrecision] * -0.2916666666666667 + N[(-0.008333333333333333 * N[Power[n, 5.0], $MachinePrecision] + N[(0.4166666666666667 * N[(n * n), $MachinePrecision] + N[(0.08333333333333333 * N[Power[n, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision] * x + N[(N[(N[(n * n), $MachinePrecision] * N[(0.16666666666666666 * n + -0.5), $MachinePrecision] + N[(n * 0.6666666666666666), $MachinePrecision]), $MachinePrecision] - N[(N[(n * n), $MachinePrecision] * N[(-0.16666666666666666 * n + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + n), $MachinePrecision] * x), $MachinePrecision], N[(t$95$0 / 2.0), $MachinePrecision]]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      t_0 := e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{n \cdot \mathsf{log1p}\left(-x\right)}\\
      \mathbf{if}\;t\_0 \leq 0.028:\\
      \;\;\;\;\mathsf{fma}\left(\left(x \cdot x\right) \cdot 0.5, \mathsf{fma}\left(\left(\mathsf{fma}\left(n \cdot n, -0.4166666666666667, \mathsf{fma}\left({n}^{4}, -0.08333333333333333, \mathsf{fma}\left({n}^{5}, 0.008333333333333333, \mathsf{fma}\left({n}^{3}, 0.2916666666666667, 0.2 \cdot n\right)\right)\right)\right) - \mathsf{fma}\left(-0.2, n, \mathsf{fma}\left({n}^{3}, -0.2916666666666667, \mathsf{fma}\left(-0.008333333333333333, {n}^{5}, \mathsf{fma}\left(0.4166666666666667, n \cdot n, 0.08333333333333333 \cdot {n}^{4}\right)\right)\right)\right)\right) \cdot x, x, \mathsf{fma}\left(n \cdot n, \mathsf{fma}\left(0.16666666666666666, n, -0.5\right), n \cdot 0.6666666666666666\right) - \left(n \cdot n\right) \cdot \mathsf{fma}\left(-0.16666666666666666, n, 0.5\right)\right), n\right) \cdot x\\
      
      \mathbf{else}:\\
      \;\;\;\;\frac{t\_0}{2}\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if (-.f64 (exp.f64 (*.f64 n (log1p.f64 x))) (exp.f64 (*.f64 n (log1p.f64 (neg.f64 x))))) < 0.0280000000000000006

        1. Initial program 75.7%

          \[\frac{e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{n \cdot \mathsf{log1p}\left(-x\right)}}{2} \]
        2. Add Preprocessing
        3. Taylor expanded in x around 0

          \[\leadsto \color{blue}{x \cdot \left(\frac{1}{2} \cdot \left(n - -1 \cdot n\right) + {x}^{2} \cdot \left(\frac{1}{2} \cdot \left({x}^{2} \cdot \left(\left(\frac{-1}{4} \cdot {n}^{2} + \left(\frac{-1}{6} \cdot {n}^{2} + \left(\frac{-1}{12} \cdot {n}^{4} + \left(\frac{1}{120} \cdot {n}^{5} + \left(\frac{1}{8} \cdot {n}^{3} + \left(\frac{1}{6} \cdot {n}^{3} + \frac{1}{5} \cdot n\right)\right)\right)\right)\right)\right) - \left(\frac{-1}{5} \cdot n + \left(\frac{-1}{6} \cdot {n}^{3} + \left(\frac{-1}{8} \cdot {n}^{3} + \left(\frac{-1}{120} \cdot {n}^{5} + \left(\frac{1}{12} \cdot {n}^{4} + \left(\frac{1}{6} \cdot {n}^{2} + \frac{1}{4} \cdot {n}^{2}\right)\right)\right)\right)\right)\right)\right)\right) + \frac{1}{2} \cdot \left(\left(\frac{-1}{2} \cdot {n}^{2} + \left(\frac{1}{6} \cdot {n}^{3} + \frac{1}{3} \cdot n\right)\right) - \left(\frac{-1}{3} \cdot n + \left(\frac{-1}{6} \cdot {n}^{3} + \frac{1}{2} \cdot {n}^{2}\right)\right)\right)\right)\right)} \]
        4. Applied rewrites99.7%

          \[\leadsto \color{blue}{\mathsf{fma}\left(\left(x \cdot x\right) \cdot 0.5, \mathsf{fma}\left(\left(\mathsf{fma}\left(n \cdot n, -0.4166666666666667, \mathsf{fma}\left({n}^{4}, -0.08333333333333333, \mathsf{fma}\left({n}^{5}, 0.008333333333333333, \mathsf{fma}\left({n}^{3}, 0.2916666666666667, 0.2 \cdot n\right)\right)\right)\right) - \mathsf{fma}\left(-0.2, n, \mathsf{fma}\left({n}^{3}, -0.2916666666666667, \mathsf{fma}\left(-0.008333333333333333, {n}^{5}, \mathsf{fma}\left(0.4166666666666667, n \cdot n, 0.08333333333333333 \cdot {n}^{4}\right)\right)\right)\right)\right) \cdot x, x, \mathsf{fma}\left(n \cdot n, \mathsf{fma}\left(0.16666666666666666, n, -0.5\right), n \cdot 0.6666666666666666\right) - \left(n \cdot n\right) \cdot \mathsf{fma}\left(-0.16666666666666666, n, 0.5\right)\right), n\right) \cdot x} \]

        if 0.0280000000000000006 < (-.f64 (exp.f64 (*.f64 n (log1p.f64 x))) (exp.f64 (*.f64 n (log1p.f64 (neg.f64 x)))))

        1. Initial program 97.8%

          \[\frac{e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{n \cdot \mathsf{log1p}\left(-x\right)}}{2} \]
        2. Add Preprocessing
      3. Recombined 2 regimes into one program.
      4. Add Preprocessing

      Alternative 4: 98.2% accurate, 0.4× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{n \cdot \mathsf{log1p}\left(x\right)}\\ \mathbf{if}\;t\_0 - e^{n \cdot \mathsf{log1p}\left(-x\right)} \leq 0.0035:\\ \;\;\;\;\mathsf{fma}\left(\left(x \cdot x\right) \cdot 0.5, \mathsf{fma}\left(n \cdot n, \mathsf{fma}\left(0.16666666666666666, n, -0.5\right), n \cdot 0.6666666666666666\right) - \left(n \cdot n\right) \cdot \mathsf{fma}\left(-0.16666666666666666, n, 0.5\right), n\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\frac{t\_0 - e^{\mathsf{fma}\left(\mathsf{log1p}\left({\left(-x\right)}^{3}\right), n, \mathsf{log1p}\left(\mathsf{fma}\left(x, x, x\right)\right) \cdot \left(-n\right)\right)}}{2}\\ \end{array} \end{array} \]
      (FPCore (n x)
       :precision binary64
       (let* ((t_0 (exp (* n (log1p x)))))
         (if (<= (- t_0 (exp (* n (log1p (- x))))) 0.0035)
           (*
            (fma
             (* (* x x) 0.5)
             (-
              (fma (* n n) (fma 0.16666666666666666 n -0.5) (* n 0.6666666666666666))
              (* (* n n) (fma -0.16666666666666666 n 0.5)))
             n)
            x)
           (/
            (-
             t_0
             (exp (fma (log1p (pow (- x) 3.0)) n (* (log1p (fma x x x)) (- n)))))
            2.0))))
      double code(double n, double x) {
      	double t_0 = exp((n * log1p(x)));
      	double tmp;
      	if ((t_0 - exp((n * log1p(-x)))) <= 0.0035) {
      		tmp = fma(((x * x) * 0.5), (fma((n * n), fma(0.16666666666666666, n, -0.5), (n * 0.6666666666666666)) - ((n * n) * fma(-0.16666666666666666, n, 0.5))), n) * x;
      	} else {
      		tmp = (t_0 - exp(fma(log1p(pow(-x, 3.0)), n, (log1p(fma(x, x, x)) * -n)))) / 2.0;
      	}
      	return tmp;
      }
      
      function code(n, x)
      	t_0 = exp(Float64(n * log1p(x)))
      	tmp = 0.0
      	if (Float64(t_0 - exp(Float64(n * log1p(Float64(-x))))) <= 0.0035)
      		tmp = Float64(fma(Float64(Float64(x * x) * 0.5), Float64(fma(Float64(n * n), fma(0.16666666666666666, n, -0.5), Float64(n * 0.6666666666666666)) - Float64(Float64(n * n) * fma(-0.16666666666666666, n, 0.5))), n) * x);
      	else
      		tmp = Float64(Float64(t_0 - exp(fma(log1p((Float64(-x) ^ 3.0)), n, Float64(log1p(fma(x, x, x)) * Float64(-n))))) / 2.0);
      	end
      	return tmp
      end
      
      code[n_, x_] := Block[{t$95$0 = N[Exp[N[(n * N[Log[1 + x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(t$95$0 - N[Exp[N[(n * N[Log[1 + (-x)], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 0.0035], N[(N[(N[(N[(x * x), $MachinePrecision] * 0.5), $MachinePrecision] * N[(N[(N[(n * n), $MachinePrecision] * N[(0.16666666666666666 * n + -0.5), $MachinePrecision] + N[(n * 0.6666666666666666), $MachinePrecision]), $MachinePrecision] - N[(N[(n * n), $MachinePrecision] * N[(-0.16666666666666666 * n + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + n), $MachinePrecision] * x), $MachinePrecision], N[(N[(t$95$0 - N[Exp[N[(N[Log[1 + N[Power[(-x), 3.0], $MachinePrecision]], $MachinePrecision] * n + N[(N[Log[1 + N[(x * x + x), $MachinePrecision]], $MachinePrecision] * (-n)), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      t_0 := e^{n \cdot \mathsf{log1p}\left(x\right)}\\
      \mathbf{if}\;t\_0 - e^{n \cdot \mathsf{log1p}\left(-x\right)} \leq 0.0035:\\
      \;\;\;\;\mathsf{fma}\left(\left(x \cdot x\right) \cdot 0.5, \mathsf{fma}\left(n \cdot n, \mathsf{fma}\left(0.16666666666666666, n, -0.5\right), n \cdot 0.6666666666666666\right) - \left(n \cdot n\right) \cdot \mathsf{fma}\left(-0.16666666666666666, n, 0.5\right), n\right) \cdot x\\
      
      \mathbf{else}:\\
      \;\;\;\;\frac{t\_0 - e^{\mathsf{fma}\left(\mathsf{log1p}\left({\left(-x\right)}^{3}\right), n, \mathsf{log1p}\left(\mathsf{fma}\left(x, x, x\right)\right) \cdot \left(-n\right)\right)}}{2}\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if (-.f64 (exp.f64 (*.f64 n (log1p.f64 x))) (exp.f64 (*.f64 n (log1p.f64 (neg.f64 x))))) < 0.00350000000000000007

        1. Initial program 73.3%

          \[\frac{e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{n \cdot \mathsf{log1p}\left(-x\right)}}{2} \]
        2. Add Preprocessing
        3. Taylor expanded in x around 0

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

          \[\leadsto \color{blue}{\mathsf{fma}\left(\left(x \cdot x\right) \cdot 0.5, \mathsf{fma}\left(n \cdot n, \mathsf{fma}\left(0.16666666666666666, n, -0.5\right), n \cdot 0.6666666666666666\right) - \left(n \cdot n\right) \cdot \mathsf{fma}\left(-0.16666666666666666, n, 0.5\right), n\right) \cdot x} \]

        if 0.00350000000000000007 < (-.f64 (exp.f64 (*.f64 n (log1p.f64 x))) (exp.f64 (*.f64 n (log1p.f64 (neg.f64 x)))))

        1. Initial program 96.4%

          \[\frac{e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{n \cdot \mathsf{log1p}\left(-x\right)}}{2} \]
        2. Add Preprocessing
        3. Applied rewrites94.2%

          \[\leadsto \frac{e^{n \cdot \mathsf{log1p}\left(x\right)} - \color{blue}{{\left(1 - {x}^{3}\right)}^{n} \cdot e^{\left(-\mathsf{log1p}\left(\mathsf{fma}\left(x, x, x\right)\right)\right) \cdot n}}}{2} \]
        4. Step-by-step derivation
          1. lift-*.f64N/A

            \[\leadsto \frac{e^{n \cdot \mathsf{log1p}\left(x\right)} - \color{blue}{{\left(1 - {x}^{3}\right)}^{n} \cdot e^{\left(-\mathsf{log1p}\left(\mathsf{fma}\left(x, x, x\right)\right)\right) \cdot n}}}{2} \]
          2. lift-pow.f64N/A

            \[\leadsto \frac{e^{n \cdot \mathsf{log1p}\left(x\right)} - \color{blue}{{\left(1 - {x}^{3}\right)}^{n}} \cdot e^{\left(-\mathsf{log1p}\left(\mathsf{fma}\left(x, x, x\right)\right)\right) \cdot n}}{2} \]
          3. pow-to-expN/A

            \[\leadsto \frac{e^{n \cdot \mathsf{log1p}\left(x\right)} - \color{blue}{e^{\log \left(1 - {x}^{3}\right) \cdot n}} \cdot e^{\left(-\mathsf{log1p}\left(\mathsf{fma}\left(x, x, x\right)\right)\right) \cdot n}}{2} \]
          4. lift-exp.f64N/A

            \[\leadsto \frac{e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{\log \left(1 - {x}^{3}\right) \cdot n} \cdot \color{blue}{e^{\left(-\mathsf{log1p}\left(\mathsf{fma}\left(x, x, x\right)\right)\right) \cdot n}}}{2} \]
          5. prod-expN/A

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

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

            \[\leadsto \frac{e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{\color{blue}{\mathsf{fma}\left(\log \left(1 - {x}^{3}\right), n, \left(-\mathsf{log1p}\left(\mathsf{fma}\left(x, x, x\right)\right)\right) \cdot n\right)}}}{2} \]
          8. lift--.f64N/A

            \[\leadsto \frac{e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{\mathsf{fma}\left(\log \color{blue}{\left(1 - {x}^{3}\right)}, n, \left(-\mathsf{log1p}\left(\mathsf{fma}\left(x, x, x\right)\right)\right) \cdot n\right)}}{2} \]
          9. sub-negN/A

            \[\leadsto \frac{e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{\mathsf{fma}\left(\log \color{blue}{\left(1 + \left(\mathsf{neg}\left({x}^{3}\right)\right)\right)}, n, \left(-\mathsf{log1p}\left(\mathsf{fma}\left(x, x, x\right)\right)\right) \cdot n\right)}}{2} \]
          10. metadata-evalN/A

            \[\leadsto \frac{e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{\mathsf{fma}\left(\log \left(\color{blue}{{1}^{3}} + \left(\mathsf{neg}\left({x}^{3}\right)\right)\right), n, \left(-\mathsf{log1p}\left(\mathsf{fma}\left(x, x, x\right)\right)\right) \cdot n\right)}}{2} \]
          11. lift-pow.f64N/A

            \[\leadsto \frac{e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{\mathsf{fma}\left(\log \left({1}^{3} + \left(\mathsf{neg}\left(\color{blue}{{x}^{3}}\right)\right)\right), n, \left(-\mathsf{log1p}\left(\mathsf{fma}\left(x, x, x\right)\right)\right) \cdot n\right)}}{2} \]
          12. cube-negN/A

            \[\leadsto \frac{e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{\mathsf{fma}\left(\log \left({1}^{3} + \color{blue}{{\left(\mathsf{neg}\left(x\right)\right)}^{3}}\right), n, \left(-\mathsf{log1p}\left(\mathsf{fma}\left(x, x, x\right)\right)\right) \cdot n\right)}}{2} \]
          13. metadata-evalN/A

            \[\leadsto \frac{e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{\mathsf{fma}\left(\log \left(\color{blue}{1} + {\left(\mathsf{neg}\left(x\right)\right)}^{3}\right), n, \left(-\mathsf{log1p}\left(\mathsf{fma}\left(x, x, x\right)\right)\right) \cdot n\right)}}{2} \]
          14. lower-log1p.f64N/A

            \[\leadsto \frac{e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{\mathsf{fma}\left(\color{blue}{\mathsf{log1p}\left({\left(\mathsf{neg}\left(x\right)\right)}^{3}\right)}, n, \left(-\mathsf{log1p}\left(\mathsf{fma}\left(x, x, x\right)\right)\right) \cdot n\right)}}{2} \]
          15. lower-pow.f64N/A

            \[\leadsto \frac{e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{\mathsf{fma}\left(\mathsf{log1p}\left(\color{blue}{{\left(\mathsf{neg}\left(x\right)\right)}^{3}}\right), n, \left(-\mathsf{log1p}\left(\mathsf{fma}\left(x, x, x\right)\right)\right) \cdot n\right)}}{2} \]
          16. lower-neg.f6496.4

            \[\leadsto \frac{e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{\mathsf{fma}\left(\mathsf{log1p}\left({\color{blue}{\left(-x\right)}}^{3}\right), n, \left(-\mathsf{log1p}\left(\mathsf{fma}\left(x, x, x\right)\right)\right) \cdot n\right)}}{2} \]
          17. lift-*.f64N/A

            \[\leadsto \frac{e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{\mathsf{fma}\left(\mathsf{log1p}\left({\left(-x\right)}^{3}\right), n, \color{blue}{\left(-\mathsf{log1p}\left(\mathsf{fma}\left(x, x, x\right)\right)\right) \cdot n}\right)}}{2} \]
          18. lift-neg.f64N/A

            \[\leadsto \frac{e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{\mathsf{fma}\left(\mathsf{log1p}\left({\left(-x\right)}^{3}\right), n, \color{blue}{\left(\mathsf{neg}\left(\mathsf{log1p}\left(\mathsf{fma}\left(x, x, x\right)\right)\right)\right)} \cdot n\right)}}{2} \]
        5. Applied rewrites96.4%

          \[\leadsto \frac{e^{n \cdot \mathsf{log1p}\left(x\right)} - \color{blue}{e^{\mathsf{fma}\left(\mathsf{log1p}\left({\left(-x\right)}^{3}\right), n, \mathsf{log1p}\left(\mathsf{fma}\left(x, x, x\right)\right) \cdot \left(-n\right)\right)}}}{2} \]
      3. Recombined 2 regimes into one program.
      4. Add Preprocessing

      Alternative 5: 98.2% accurate, 0.5× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{n \cdot \mathsf{log1p}\left(-x\right)}\\ \mathbf{if}\;t\_0 \leq 0.0035:\\ \;\;\;\;\mathsf{fma}\left(\left(x \cdot x\right) \cdot 0.5, \mathsf{fma}\left(n \cdot n, \mathsf{fma}\left(0.16666666666666666, n, -0.5\right), n \cdot 0.6666666666666666\right) - \left(n \cdot n\right) \cdot \mathsf{fma}\left(-0.16666666666666666, n, 0.5\right), n\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\frac{t\_0}{2}\\ \end{array} \end{array} \]
      (FPCore (n x)
       :precision binary64
       (let* ((t_0 (- (exp (* n (log1p x))) (exp (* n (log1p (- x)))))))
         (if (<= t_0 0.0035)
           (*
            (fma
             (* (* x x) 0.5)
             (-
              (fma (* n n) (fma 0.16666666666666666 n -0.5) (* n 0.6666666666666666))
              (* (* n n) (fma -0.16666666666666666 n 0.5)))
             n)
            x)
           (/ t_0 2.0))))
      double code(double n, double x) {
      	double t_0 = exp((n * log1p(x))) - exp((n * log1p(-x)));
      	double tmp;
      	if (t_0 <= 0.0035) {
      		tmp = fma(((x * x) * 0.5), (fma((n * n), fma(0.16666666666666666, n, -0.5), (n * 0.6666666666666666)) - ((n * n) * fma(-0.16666666666666666, n, 0.5))), n) * x;
      	} else {
      		tmp = t_0 / 2.0;
      	}
      	return tmp;
      }
      
      function code(n, x)
      	t_0 = Float64(exp(Float64(n * log1p(x))) - exp(Float64(n * log1p(Float64(-x)))))
      	tmp = 0.0
      	if (t_0 <= 0.0035)
      		tmp = Float64(fma(Float64(Float64(x * x) * 0.5), Float64(fma(Float64(n * n), fma(0.16666666666666666, n, -0.5), Float64(n * 0.6666666666666666)) - Float64(Float64(n * n) * fma(-0.16666666666666666, n, 0.5))), n) * x);
      	else
      		tmp = Float64(t_0 / 2.0);
      	end
      	return tmp
      end
      
      code[n_, x_] := Block[{t$95$0 = N[(N[Exp[N[(n * N[Log[1 + x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - N[Exp[N[(n * N[Log[1 + (-x)], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 0.0035], N[(N[(N[(N[(x * x), $MachinePrecision] * 0.5), $MachinePrecision] * N[(N[(N[(n * n), $MachinePrecision] * N[(0.16666666666666666 * n + -0.5), $MachinePrecision] + N[(n * 0.6666666666666666), $MachinePrecision]), $MachinePrecision] - N[(N[(n * n), $MachinePrecision] * N[(-0.16666666666666666 * n + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + n), $MachinePrecision] * x), $MachinePrecision], N[(t$95$0 / 2.0), $MachinePrecision]]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      t_0 := e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{n \cdot \mathsf{log1p}\left(-x\right)}\\
      \mathbf{if}\;t\_0 \leq 0.0035:\\
      \;\;\;\;\mathsf{fma}\left(\left(x \cdot x\right) \cdot 0.5, \mathsf{fma}\left(n \cdot n, \mathsf{fma}\left(0.16666666666666666, n, -0.5\right), n \cdot 0.6666666666666666\right) - \left(n \cdot n\right) \cdot \mathsf{fma}\left(-0.16666666666666666, n, 0.5\right), n\right) \cdot x\\
      
      \mathbf{else}:\\
      \;\;\;\;\frac{t\_0}{2}\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if (-.f64 (exp.f64 (*.f64 n (log1p.f64 x))) (exp.f64 (*.f64 n (log1p.f64 (neg.f64 x))))) < 0.00350000000000000007

        1. Initial program 73.3%

          \[\frac{e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{n \cdot \mathsf{log1p}\left(-x\right)}}{2} \]
        2. Add Preprocessing
        3. Taylor expanded in x around 0

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

          \[\leadsto \color{blue}{\mathsf{fma}\left(\left(x \cdot x\right) \cdot 0.5, \mathsf{fma}\left(n \cdot n, \mathsf{fma}\left(0.16666666666666666, n, -0.5\right), n \cdot 0.6666666666666666\right) - \left(n \cdot n\right) \cdot \mathsf{fma}\left(-0.16666666666666666, n, 0.5\right), n\right) \cdot x} \]

        if 0.00350000000000000007 < (-.f64 (exp.f64 (*.f64 n (log1p.f64 x))) (exp.f64 (*.f64 n (log1p.f64 (neg.f64 x)))))

        1. Initial program 96.4%

          \[\frac{e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{n \cdot \mathsf{log1p}\left(-x\right)}}{2} \]
        2. Add Preprocessing
      3. Recombined 2 regimes into one program.
      4. Add Preprocessing

      Alternative 6: 97.4% accurate, 0.6× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{n \cdot \mathsf{log1p}\left(x\right)}\\ \mathbf{if}\;t\_0 - e^{n \cdot \mathsf{log1p}\left(-x\right)} \leq 0.006:\\ \;\;\;\;\mathsf{fma}\left(\left(x \cdot x\right) \cdot 0.5, \mathsf{fma}\left(n \cdot n, \mathsf{fma}\left(0.16666666666666666, n, -0.5\right), n \cdot 0.6666666666666666\right) - \left(n \cdot n\right) \cdot \mathsf{fma}\left(-0.16666666666666666, n, 0.5\right), n\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\frac{t\_0 - {\left(1 - x\right)}^{n}}{2}\\ \end{array} \end{array} \]
      (FPCore (n x)
       :precision binary64
       (let* ((t_0 (exp (* n (log1p x)))))
         (if (<= (- t_0 (exp (* n (log1p (- x))))) 0.006)
           (*
            (fma
             (* (* x x) 0.5)
             (-
              (fma (* n n) (fma 0.16666666666666666 n -0.5) (* n 0.6666666666666666))
              (* (* n n) (fma -0.16666666666666666 n 0.5)))
             n)
            x)
           (/ (- t_0 (pow (- 1.0 x) n)) 2.0))))
      double code(double n, double x) {
      	double t_0 = exp((n * log1p(x)));
      	double tmp;
      	if ((t_0 - exp((n * log1p(-x)))) <= 0.006) {
      		tmp = fma(((x * x) * 0.5), (fma((n * n), fma(0.16666666666666666, n, -0.5), (n * 0.6666666666666666)) - ((n * n) * fma(-0.16666666666666666, n, 0.5))), n) * x;
      	} else {
      		tmp = (t_0 - pow((1.0 - x), n)) / 2.0;
      	}
      	return tmp;
      }
      
      function code(n, x)
      	t_0 = exp(Float64(n * log1p(x)))
      	tmp = 0.0
      	if (Float64(t_0 - exp(Float64(n * log1p(Float64(-x))))) <= 0.006)
      		tmp = Float64(fma(Float64(Float64(x * x) * 0.5), Float64(fma(Float64(n * n), fma(0.16666666666666666, n, -0.5), Float64(n * 0.6666666666666666)) - Float64(Float64(n * n) * fma(-0.16666666666666666, n, 0.5))), n) * x);
      	else
      		tmp = Float64(Float64(t_0 - (Float64(1.0 - x) ^ n)) / 2.0);
      	end
      	return tmp
      end
      
      code[n_, x_] := Block[{t$95$0 = N[Exp[N[(n * N[Log[1 + x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(t$95$0 - N[Exp[N[(n * N[Log[1 + (-x)], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 0.006], N[(N[(N[(N[(x * x), $MachinePrecision] * 0.5), $MachinePrecision] * N[(N[(N[(n * n), $MachinePrecision] * N[(0.16666666666666666 * n + -0.5), $MachinePrecision] + N[(n * 0.6666666666666666), $MachinePrecision]), $MachinePrecision] - N[(N[(n * n), $MachinePrecision] * N[(-0.16666666666666666 * n + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + n), $MachinePrecision] * x), $MachinePrecision], N[(N[(t$95$0 - N[Power[N[(1.0 - x), $MachinePrecision], n], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      t_0 := e^{n \cdot \mathsf{log1p}\left(x\right)}\\
      \mathbf{if}\;t\_0 - e^{n \cdot \mathsf{log1p}\left(-x\right)} \leq 0.006:\\
      \;\;\;\;\mathsf{fma}\left(\left(x \cdot x\right) \cdot 0.5, \mathsf{fma}\left(n \cdot n, \mathsf{fma}\left(0.16666666666666666, n, -0.5\right), n \cdot 0.6666666666666666\right) - \left(n \cdot n\right) \cdot \mathsf{fma}\left(-0.16666666666666666, n, 0.5\right), n\right) \cdot x\\
      
      \mathbf{else}:\\
      \;\;\;\;\frac{t\_0 - {\left(1 - x\right)}^{n}}{2}\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if (-.f64 (exp.f64 (*.f64 n (log1p.f64 x))) (exp.f64 (*.f64 n (log1p.f64 (neg.f64 x))))) < 0.0060000000000000001

        1. Initial program 74.0%

          \[\frac{e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{n \cdot \mathsf{log1p}\left(-x\right)}}{2} \]
        2. Add Preprocessing
        3. Taylor expanded in x around 0

          \[\leadsto \color{blue}{x \cdot \left(\frac{1}{2} \cdot \left({x}^{2} \cdot \left(\left(\frac{-1}{2} \cdot {n}^{2} + \left(\frac{1}{6} \cdot {n}^{3} + \frac{1}{3} \cdot n\right)\right) - \left(\frac{-1}{3} \cdot n + \left(\frac{-1}{6} \cdot {n}^{3} + \frac{1}{2} \cdot {n}^{2}\right)\right)\right)\right) + \frac{1}{2} \cdot \left(n - -1 \cdot n\right)\right)} \]
        4. Applied rewrites98.8%

          \[\leadsto \color{blue}{\mathsf{fma}\left(\left(x \cdot x\right) \cdot 0.5, \mathsf{fma}\left(n \cdot n, \mathsf{fma}\left(0.16666666666666666, n, -0.5\right), n \cdot 0.6666666666666666\right) - \left(n \cdot n\right) \cdot \mathsf{fma}\left(-0.16666666666666666, n, 0.5\right), n\right) \cdot x} \]

        if 0.0060000000000000001 < (-.f64 (exp.f64 (*.f64 n (log1p.f64 x))) (exp.f64 (*.f64 n (log1p.f64 (neg.f64 x)))))

        1. Initial program 96.7%

          \[\frac{e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{n \cdot \mathsf{log1p}\left(-x\right)}}{2} \]
        2. Add Preprocessing
        3. Applied rewrites95.1%

          \[\leadsto \frac{e^{n \cdot \mathsf{log1p}\left(x\right)} - \color{blue}{{\left(1 - x\right)}^{n}}}{2} \]
      3. Recombined 2 regimes into one program.
      4. Add Preprocessing

      Alternative 7: 96.8% accurate, 0.7× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{n \cdot \mathsf{log1p}\left(-x\right)} \leq 0.0055:\\ \;\;\;\;\mathsf{fma}\left(\left(x \cdot x\right) \cdot 0.5, \mathsf{fma}\left(n \cdot n, \mathsf{fma}\left(0.16666666666666666, n, -0.5\right), n \cdot 0.6666666666666666\right) - \left(n \cdot n\right) \cdot \mathsf{fma}\left(-0.16666666666666666, n, 0.5\right), n\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\left({\left(1 + x\right)}^{n} - {\left(1 - x\right)}^{n}\right) \cdot 0.5\\ \end{array} \end{array} \]
      (FPCore (n x)
       :precision binary64
       (if (<= (- (exp (* n (log1p x))) (exp (* n (log1p (- x))))) 0.0055)
         (*
          (fma
           (* (* x x) 0.5)
           (-
            (fma (* n n) (fma 0.16666666666666666 n -0.5) (* n 0.6666666666666666))
            (* (* n n) (fma -0.16666666666666666 n 0.5)))
           n)
          x)
         (* (- (pow (+ 1.0 x) n) (pow (- 1.0 x) n)) 0.5)))
      double code(double n, double x) {
      	double tmp;
      	if ((exp((n * log1p(x))) - exp((n * log1p(-x)))) <= 0.0055) {
      		tmp = fma(((x * x) * 0.5), (fma((n * n), fma(0.16666666666666666, n, -0.5), (n * 0.6666666666666666)) - ((n * n) * fma(-0.16666666666666666, n, 0.5))), n) * x;
      	} else {
      		tmp = (pow((1.0 + x), n) - pow((1.0 - x), n)) * 0.5;
      	}
      	return tmp;
      }
      
      function code(n, x)
      	tmp = 0.0
      	if (Float64(exp(Float64(n * log1p(x))) - exp(Float64(n * log1p(Float64(-x))))) <= 0.0055)
      		tmp = Float64(fma(Float64(Float64(x * x) * 0.5), Float64(fma(Float64(n * n), fma(0.16666666666666666, n, -0.5), Float64(n * 0.6666666666666666)) - Float64(Float64(n * n) * fma(-0.16666666666666666, n, 0.5))), n) * x);
      	else
      		tmp = Float64(Float64((Float64(1.0 + x) ^ n) - (Float64(1.0 - x) ^ n)) * 0.5);
      	end
      	return tmp
      end
      
      code[n_, x_] := If[LessEqual[N[(N[Exp[N[(n * N[Log[1 + x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - N[Exp[N[(n * N[Log[1 + (-x)], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 0.0055], N[(N[(N[(N[(x * x), $MachinePrecision] * 0.5), $MachinePrecision] * N[(N[(N[(n * n), $MachinePrecision] * N[(0.16666666666666666 * n + -0.5), $MachinePrecision] + N[(n * 0.6666666666666666), $MachinePrecision]), $MachinePrecision] - N[(N[(n * n), $MachinePrecision] * N[(-0.16666666666666666 * n + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + n), $MachinePrecision] * x), $MachinePrecision], N[(N[(N[Power[N[(1.0 + x), $MachinePrecision], n], $MachinePrecision] - N[Power[N[(1.0 - x), $MachinePrecision], n], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{n \cdot \mathsf{log1p}\left(-x\right)} \leq 0.0055:\\
      \;\;\;\;\mathsf{fma}\left(\left(x \cdot x\right) \cdot 0.5, \mathsf{fma}\left(n \cdot n, \mathsf{fma}\left(0.16666666666666666, n, -0.5\right), n \cdot 0.6666666666666666\right) - \left(n \cdot n\right) \cdot \mathsf{fma}\left(-0.16666666666666666, n, 0.5\right), n\right) \cdot x\\
      
      \mathbf{else}:\\
      \;\;\;\;\left({\left(1 + x\right)}^{n} - {\left(1 - x\right)}^{n}\right) \cdot 0.5\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if (-.f64 (exp.f64 (*.f64 n (log1p.f64 x))) (exp.f64 (*.f64 n (log1p.f64 (neg.f64 x))))) < 0.0054999999999999997

        1. Initial program 73.9%

          \[\frac{e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{n \cdot \mathsf{log1p}\left(-x\right)}}{2} \]
        2. Add Preprocessing
        3. Taylor expanded in x around 0

          \[\leadsto \color{blue}{x \cdot \left(\frac{1}{2} \cdot \left({x}^{2} \cdot \left(\left(\frac{-1}{2} \cdot {n}^{2} + \left(\frac{1}{6} \cdot {n}^{3} + \frac{1}{3} \cdot n\right)\right) - \left(\frac{-1}{3} \cdot n + \left(\frac{-1}{6} \cdot {n}^{3} + \frac{1}{2} \cdot {n}^{2}\right)\right)\right)\right) + \frac{1}{2} \cdot \left(n - -1 \cdot n\right)\right)} \]
        4. Applied rewrites98.9%

          \[\leadsto \color{blue}{\mathsf{fma}\left(\left(x \cdot x\right) \cdot 0.5, \mathsf{fma}\left(n \cdot n, \mathsf{fma}\left(0.16666666666666666, n, -0.5\right), n \cdot 0.6666666666666666\right) - \left(n \cdot n\right) \cdot \mathsf{fma}\left(-0.16666666666666666, n, 0.5\right), n\right) \cdot x} \]

        if 0.0054999999999999997 < (-.f64 (exp.f64 (*.f64 n (log1p.f64 x))) (exp.f64 (*.f64 n (log1p.f64 (neg.f64 x)))))

        1. Initial program 96.7%

          \[\frac{e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{n \cdot \mathsf{log1p}\left(-x\right)}}{2} \]
        2. Add Preprocessing
        3. Taylor expanded in n around inf

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

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

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

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

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

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

            \[\leadsto \left({\left(1 + x\right)}^{n} - \color{blue}{{\left(1 - x\right)}^{n}}\right) \cdot \frac{1}{2} \]
          7. lower--.f6493.4

            \[\leadsto \left({\left(1 + x\right)}^{n} - {\color{blue}{\left(1 - x\right)}}^{n}\right) \cdot 0.5 \]
        5. Applied rewrites93.4%

          \[\leadsto \color{blue}{\left({\left(1 + x\right)}^{n} - {\left(1 - x\right)}^{n}\right) \cdot 0.5} \]
      3. Recombined 2 regimes into one program.
      4. Add Preprocessing

      Alternative 8: 80.8% accurate, 6.8× speedup?

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

        \[\frac{e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{n \cdot \mathsf{log1p}\left(-x\right)}}{2} \]
      2. Add Preprocessing
      3. Taylor expanded in x around 0

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(\left(x \cdot x\right) \cdot 0.5, \mathsf{fma}\left(n \cdot n, \mathsf{fma}\left(0.16666666666666666, n, -0.5\right), n \cdot 0.6666666666666666\right) - \left(n \cdot n\right) \cdot \mathsf{fma}\left(-0.16666666666666666, n, 0.5\right), n\right) \cdot x} \]
      5. Add Preprocessing

      Alternative 9: 63.7% accurate, 71.2× speedup?

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

        \[\frac{e^{n \cdot \mathsf{log1p}\left(x\right)} - e^{n \cdot \mathsf{log1p}\left(-x\right)}}{2} \]
      2. Add Preprocessing
      3. Taylor expanded in x around 0

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

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

          \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \left(n - -1 \cdot n\right)\right) \cdot x} \]
        3. cancel-sign-sub-invN/A

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

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

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

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

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

          \[\leadsto \left(n \cdot \color{blue}{1}\right) \cdot x \]
        9. *-rgt-identityN/A

          \[\leadsto \color{blue}{n} \cdot x \]
        10. *-commutativeN/A

          \[\leadsto \color{blue}{x \cdot n} \]
        11. lower-*.f6466.9

          \[\leadsto \color{blue}{x \cdot n} \]
      5. Applied rewrites66.9%

        \[\leadsto \color{blue}{x \cdot n} \]
      6. Add Preprocessing

      Reproduce

      ?
      herbie shell --seed 1 
      (FPCore (n x)
        :name "(exp (n * log1p (x)) - exp (n * log1p (-x))) / 2"
        :precision binary64
        :pre (and (and (<= 1.0 n) (<= n 100.0)) (and (<= 1e-10 x) (<= x 1.0)))
        (/ (- (exp (* n (log1p x))) (exp (* n (log1p (- x))))) 2.0))