expax (section 3.5)

Percentage Accurate: 53.7% → 99.9%
Time: 9.7s
Alternatives: 9
Speedup: 18.2×

Specification

?
\[710 > a \cdot x\]
\[\begin{array}{l} \\ e^{a \cdot x} - 1 \end{array} \]
(FPCore (a x) :precision binary64 (- (exp (* a x)) 1.0))
double code(double a, double x) {
	return exp((a * x)) - 1.0;
}
real(8) function code(a, x)
    real(8), intent (in) :: a
    real(8), intent (in) :: x
    code = exp((a * x)) - 1.0d0
end function
public static double code(double a, double x) {
	return Math.exp((a * x)) - 1.0;
}
def code(a, x):
	return math.exp((a * x)) - 1.0
function code(a, x)
	return Float64(exp(Float64(a * x)) - 1.0)
end
function tmp = code(a, x)
	tmp = exp((a * x)) - 1.0;
end
code[a_, x_] := N[(N[Exp[N[(a * x), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision]
\begin{array}{l}

\\
e^{a \cdot x} - 1
\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: 53.7% accurate, 1.0× speedup?

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

\\
e^{a \cdot x} - 1
\end{array}

Alternative 1: 99.9% accurate, 0.3× speedup?

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

\\
\frac{\mathsf{expm1}\left(a \cdot \left(x + x\right)\right)}{{\left(e^{2}\right)}^{\left(0.5 \cdot \left(a \cdot x\right)\right)} + 1}
\end{array}
Derivation
  1. Initial program 50.6%

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

      \[\leadsto e^{\color{blue}{a \cdot x}} - 1 \]
    2. lift-exp.f64N/A

      \[\leadsto \color{blue}{e^{a \cdot x}} - 1 \]
    3. flip--N/A

      \[\leadsto \color{blue}{\frac{e^{a \cdot x} \cdot e^{a \cdot x} - 1 \cdot 1}{e^{a \cdot x} + 1}} \]
    4. lower-/.f64N/A

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

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

      \[\leadsto \frac{e^{a \cdot x} \cdot \color{blue}{e^{a \cdot x}} - 1 \cdot 1}{e^{a \cdot x} + 1} \]
    7. prod-expN/A

      \[\leadsto \frac{\color{blue}{e^{a \cdot x + a \cdot x}} - 1 \cdot 1}{e^{a \cdot x} + 1} \]
    8. metadata-evalN/A

      \[\leadsto \frac{e^{a \cdot x + a \cdot x} - \color{blue}{1}}{e^{a \cdot x} + 1} \]
    9. lower-expm1.f64N/A

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

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

      \[\leadsto \frac{\mathsf{expm1}\left(a \cdot x + \color{blue}{a \cdot x}\right)}{e^{a \cdot x} + 1} \]
    12. distribute-lft-outN/A

      \[\leadsto \frac{\mathsf{expm1}\left(\color{blue}{a \cdot \left(x + x\right)}\right)}{e^{a \cdot x} + 1} \]
    13. lower-*.f64N/A

      \[\leadsto \frac{\mathsf{expm1}\left(\color{blue}{a \cdot \left(x + x\right)}\right)}{e^{a \cdot x} + 1} \]
    14. lower-+.f64N/A

      \[\leadsto \frac{\mathsf{expm1}\left(a \cdot \color{blue}{\left(x + x\right)}\right)}{e^{a \cdot x} + 1} \]
    15. lower-+.f64100.0

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

    \[\leadsto \color{blue}{\frac{\mathsf{expm1}\left(a \cdot \left(x + x\right)\right)}{e^{a \cdot x} + 1}} \]
  5. Step-by-step derivation
    1. exp-prodN/A

      \[\leadsto \frac{\mathsf{expm1}\left(a \cdot \left(x + x\right)\right)}{\color{blue}{{\left(e^{a}\right)}^{x}} + 1} \]
    2. sqr-powN/A

      \[\leadsto \frac{\mathsf{expm1}\left(a \cdot \left(x + x\right)\right)}{\color{blue}{{\left(e^{a}\right)}^{\left(\frac{x}{2}\right)} \cdot {\left(e^{a}\right)}^{\left(\frac{x}{2}\right)}} + 1} \]
    3. pow2N/A

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

      \[\leadsto \frac{\mathsf{expm1}\left(a \cdot \left(x + x\right)\right)}{\color{blue}{{\left({\left(e^{a}\right)}^{\left(\frac{x}{2}\right)}\right)}^{2}} + 1} \]
    5. pow-expN/A

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

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

      \[\leadsto \frac{\mathsf{expm1}\left(a \cdot \left(x + x\right)\right)}{{\left(e^{\color{blue}{a \cdot \frac{x}{2}}}\right)}^{2} + 1} \]
    8. div-invN/A

      \[\leadsto \frac{\mathsf{expm1}\left(a \cdot \left(x + x\right)\right)}{{\left(e^{a \cdot \color{blue}{\left(x \cdot \frac{1}{2}\right)}}\right)}^{2} + 1} \]
    9. metadata-evalN/A

      \[\leadsto \frac{\mathsf{expm1}\left(a \cdot \left(x + x\right)\right)}{{\left(e^{a \cdot \left(x \cdot \color{blue}{\frac{1}{2}}\right)}\right)}^{2} + 1} \]
    10. lower-*.f64100.0

      \[\leadsto \frac{\mathsf{expm1}\left(a \cdot \left(x + x\right)\right)}{{\left(e^{a \cdot \color{blue}{\left(x \cdot 0.5\right)}}\right)}^{2} + 1} \]
  6. Applied rewrites100.0%

    \[\leadsto \frac{\mathsf{expm1}\left(a \cdot \left(x + x\right)\right)}{\color{blue}{{\left(e^{a \cdot \left(x \cdot 0.5\right)}\right)}^{2}} + 1} \]
  7. Step-by-step derivation
    1. lift-*.f64N/A

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

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

      \[\leadsto \frac{\mathsf{expm1}\left(a \cdot \left(x + x\right)\right)}{{\color{blue}{\left(e^{a \cdot \left(x \cdot \frac{1}{2}\right)}\right)}}^{2} + 1} \]
    4. unpow1N/A

      \[\leadsto \frac{\mathsf{expm1}\left(a \cdot \left(x + x\right)\right)}{{\color{blue}{\left({\left(e^{a \cdot \left(x \cdot \frac{1}{2}\right)}\right)}^{1}\right)}}^{2} + 1} \]
    5. metadata-evalN/A

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

      \[\leadsto \frac{\mathsf{expm1}\left(a \cdot \left(x + x\right)\right)}{{\left({\left(e^{a \cdot \left(x \cdot \frac{1}{2}\right)}\right)}^{\color{blue}{1}}\right)}^{2} + 1} \]
    7. unpow1N/A

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

      \[\leadsto \frac{\mathsf{expm1}\left(a \cdot \left(x + x\right)\right)}{{\color{blue}{\left(e^{a \cdot \left(x \cdot \frac{1}{2}\right)}\right)}}^{2} + 1} \]
    9. pow-expN/A

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

      \[\leadsto \frac{\mathsf{expm1}\left(a \cdot \left(x + x\right)\right)}{e^{\color{blue}{2 \cdot \left(a \cdot \left(x \cdot \frac{1}{2}\right)\right)}} + 1} \]
    11. exp-prodN/A

      \[\leadsto \frac{\mathsf{expm1}\left(a \cdot \left(x + x\right)\right)}{\color{blue}{{\left(e^{2}\right)}^{\left(a \cdot \left(x \cdot \frac{1}{2}\right)\right)}} + 1} \]
    12. lower-pow.f64N/A

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

      \[\leadsto \frac{\mathsf{expm1}\left(a \cdot \left(x + x\right)\right)}{{\color{blue}{\left(e^{2}\right)}}^{\left(a \cdot \left(x \cdot 0.5\right)\right)} + 1} \]
    14. lift-*.f64N/A

      \[\leadsto \frac{\mathsf{expm1}\left(a \cdot \left(x + x\right)\right)}{{\left(e^{2}\right)}^{\color{blue}{\left(a \cdot \left(x \cdot \frac{1}{2}\right)\right)}} + 1} \]
    15. lift-*.f64N/A

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

      \[\leadsto \frac{\mathsf{expm1}\left(a \cdot \left(x + x\right)\right)}{{\left(e^{2}\right)}^{\color{blue}{\left(\left(a \cdot x\right) \cdot \frac{1}{2}\right)}} + 1} \]
    17. lift-*.f64N/A

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

      \[\leadsto \frac{\mathsf{expm1}\left(a \cdot \left(x + x\right)\right)}{{\left(e^{2}\right)}^{\color{blue}{\left(\frac{1}{2} \cdot \left(a \cdot x\right)\right)}} + 1} \]
    19. lower-*.f64100.0

      \[\leadsto \frac{\mathsf{expm1}\left(a \cdot \left(x + x\right)\right)}{{\left(e^{2}\right)}^{\color{blue}{\left(0.5 \cdot \left(a \cdot x\right)\right)}} + 1} \]
  8. Applied rewrites100.0%

    \[\leadsto \frac{\mathsf{expm1}\left(a \cdot \left(x + x\right)\right)}{\color{blue}{{\left(e^{2}\right)}^{\left(0.5 \cdot \left(a \cdot x\right)\right)}} + 1} \]
  9. Add Preprocessing

Alternative 2: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \mathsf{expm1}\left(a \cdot x\right) \end{array} \]
(FPCore (a x) :precision binary64 (expm1 (* a x)))
double code(double a, double x) {
	return expm1((a * x));
}
public static double code(double a, double x) {
	return Math.expm1((a * x));
}
def code(a, x):
	return math.expm1((a * x))
function code(a, x)
	return expm1(Float64(a * x))
end
code[a_, x_] := N[(Exp[N[(a * x), $MachinePrecision]] - 1), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{expm1}\left(a \cdot x\right)
\end{array}
Derivation
  1. Initial program 50.6%

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

      \[\leadsto e^{\color{blue}{a \cdot x}} - 1 \]
    2. lower-expm1.f64100.0

      \[\leadsto \color{blue}{\mathsf{expm1}\left(a \cdot x\right)} \]
  4. Applied rewrites100.0%

    \[\leadsto \color{blue}{\mathsf{expm1}\left(a \cdot x\right)} \]
  5. Add Preprocessing

Alternative 3: 98.8% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \cdot x \leq -20000:\\ \;\;\;\;\frac{-1}{\mathsf{fma}\left(a, x, -1\right)} + -1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(a \cdot \left(a \cdot x\right), x \cdot \mathsf{fma}\left(a, x \cdot \mathsf{fma}\left(a, x \cdot 0.041666666666666664, 0.16666666666666666\right), 0.5\right), a \cdot x\right)\\ \end{array} \end{array} \]
(FPCore (a x)
 :precision binary64
 (if (<= (* a x) -20000.0)
   (+ (/ -1.0 (fma a x -1.0)) -1.0)
   (fma
    (* a (* a x))
    (*
     x
     (fma a (* x (fma a (* x 0.041666666666666664) 0.16666666666666666)) 0.5))
    (* a x))))
double code(double a, double x) {
	double tmp;
	if ((a * x) <= -20000.0) {
		tmp = (-1.0 / fma(a, x, -1.0)) + -1.0;
	} else {
		tmp = fma((a * (a * x)), (x * fma(a, (x * fma(a, (x * 0.041666666666666664), 0.16666666666666666)), 0.5)), (a * x));
	}
	return tmp;
}
function code(a, x)
	tmp = 0.0
	if (Float64(a * x) <= -20000.0)
		tmp = Float64(Float64(-1.0 / fma(a, x, -1.0)) + -1.0);
	else
		tmp = fma(Float64(a * Float64(a * x)), Float64(x * fma(a, Float64(x * fma(a, Float64(x * 0.041666666666666664), 0.16666666666666666)), 0.5)), Float64(a * x));
	end
	return tmp
end
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -20000.0], N[(N[(-1.0 / N[(a * x + -1.0), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(N[(a * N[(a * x), $MachinePrecision]), $MachinePrecision] * N[(x * N[(a * N[(x * N[(a * N[(x * 0.041666666666666664), $MachinePrecision] + 0.16666666666666666), $MachinePrecision]), $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision] + N[(a * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -20000:\\
\;\;\;\;\frac{-1}{\mathsf{fma}\left(a, x, -1\right)} + -1\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a \cdot \left(a \cdot x\right), x \cdot \mathsf{fma}\left(a, x \cdot \mathsf{fma}\left(a, x \cdot 0.041666666666666664, 0.16666666666666666\right), 0.5\right), a \cdot x\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 a x) < -2e4

    1. Initial program 100.0%

      \[e^{a \cdot x} - 1 \]
    2. Add Preprocessing
    3. Taylor expanded in a around 0

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

        \[\leadsto \color{blue}{\left(a \cdot x + 1\right)} - 1 \]
      2. lower-fma.f645.1

        \[\leadsto \color{blue}{\mathsf{fma}\left(a, x, 1\right)} - 1 \]
    5. Applied rewrites5.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(a, x, 1\right)} - 1 \]
    6. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \left(\color{blue}{a \cdot x} + 1\right) - 1 \]
      2. flip-+N/A

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

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

        \[\leadsto \frac{\left(a \cdot x\right) \cdot \left(a \cdot x\right) - \color{blue}{1}}{a \cdot x - 1} - 1 \]
      5. sub-negN/A

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

        \[\leadsto \frac{\color{blue}{\left(a \cdot x\right)} \cdot \left(a \cdot x\right) + \left(\mathsf{neg}\left(1\right)\right)}{a \cdot x - 1} - 1 \]
      7. associate-*l*N/A

        \[\leadsto \frac{\color{blue}{a \cdot \left(x \cdot \left(a \cdot x\right)\right)} + \left(\mathsf{neg}\left(1\right)\right)}{a \cdot x - 1} - 1 \]
      8. *-commutativeN/A

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

        \[\leadsto \frac{a \cdot \left(\color{blue}{\left(a \cdot x\right)} \cdot x\right) + \left(\mathsf{neg}\left(1\right)\right)}{a \cdot x - 1} - 1 \]
      10. associate-*r*N/A

        \[\leadsto \frac{a \cdot \color{blue}{\left(a \cdot \left(x \cdot x\right)\right)} + \left(\mathsf{neg}\left(1\right)\right)}{a \cdot x - 1} - 1 \]
      11. lift-*.f64N/A

        \[\leadsto \frac{a \cdot \left(a \cdot \color{blue}{\left(x \cdot x\right)}\right) + \left(\mathsf{neg}\left(1\right)\right)}{a \cdot x - 1} - 1 \]
      12. lift-*.f64N/A

        \[\leadsto \frac{a \cdot \color{blue}{\left(a \cdot \left(x \cdot x\right)\right)} + \left(\mathsf{neg}\left(1\right)\right)}{a \cdot x - 1} - 1 \]
      13. lower-fma.f64N/A

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(a, a \cdot \left(x \cdot x\right), \mathsf{neg}\left(1\right)\right)}}{a \cdot x - 1} - 1 \]
      14. metadata-evalN/A

        \[\leadsto \frac{\mathsf{fma}\left(a, a \cdot \left(x \cdot x\right), \color{blue}{-1}\right)}{a \cdot x - 1} - 1 \]
      15. sub-negN/A

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

        \[\leadsto \frac{\mathsf{fma}\left(a, a \cdot \left(x \cdot x\right), -1\right)}{\color{blue}{a \cdot x} + \left(\mathsf{neg}\left(1\right)\right)} - 1 \]
      17. lower-fma.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(a, a \cdot \left(x \cdot x\right), -1\right)}{\color{blue}{\mathsf{fma}\left(a, x, \mathsf{neg}\left(1\right)\right)}} - 1 \]
      18. metadata-eval8.5

        \[\leadsto \frac{\mathsf{fma}\left(a, a \cdot \left(x \cdot x\right), -1\right)}{\mathsf{fma}\left(a, x, \color{blue}{-1}\right)} - 1 \]
    7. Applied rewrites8.5%

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

      \[\leadsto \frac{\color{blue}{-1}}{\mathsf{fma}\left(a, x, -1\right)} - 1 \]
    9. Step-by-step derivation
      1. Applied rewrites98.4%

        \[\leadsto \frac{\color{blue}{-1}}{\mathsf{fma}\left(a, x, -1\right)} - 1 \]

      if -2e4 < (*.f64 a x)

      1. Initial program 25.7%

        \[e^{a \cdot x} - 1 \]
      2. Add Preprocessing
      3. Taylor expanded in a around 0

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

        \[\leadsto \color{blue}{a \cdot \mathsf{fma}\left(a, x \cdot \left(x \cdot \mathsf{fma}\left(a \cdot x, \mathsf{fma}\left(a \cdot x, 0.041666666666666664, 0.16666666666666666\right), 0.5\right)\right), x\right)} \]
      5. Step-by-step derivation
        1. lift-*.f64N/A

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

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

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

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

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

          \[\leadsto a \cdot \left(a \cdot \color{blue}{\left(x \cdot \left(x \cdot \mathsf{fma}\left(a \cdot x, \mathsf{fma}\left(a \cdot x, \frac{1}{24}, \frac{1}{6}\right), \frac{1}{2}\right)\right)\right)} + x\right) \]
        7. distribute-lft-inN/A

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

          \[\leadsto a \cdot \left(a \cdot \left(x \cdot \left(x \cdot \mathsf{fma}\left(a \cdot x, \mathsf{fma}\left(a \cdot x, \frac{1}{24}, \frac{1}{6}\right), \frac{1}{2}\right)\right)\right)\right) + \color{blue}{a \cdot x} \]
      6. Applied rewrites99.1%

        \[\leadsto \color{blue}{\mathsf{fma}\left(a \cdot \left(a \cdot x\right), x \cdot \mathsf{fma}\left(a, x \cdot \mathsf{fma}\left(a, x \cdot 0.041666666666666664, 0.16666666666666666\right), 0.5\right), a \cdot x\right)} \]
    10. Recombined 2 regimes into one program.
    11. Final simplification98.9%

      \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot x \leq -20000:\\ \;\;\;\;\frac{-1}{\mathsf{fma}\left(a, x, -1\right)} + -1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(a \cdot \left(a \cdot x\right), x \cdot \mathsf{fma}\left(a, x \cdot \mathsf{fma}\left(a, x \cdot 0.041666666666666664, 0.16666666666666666\right), 0.5\right), a \cdot x\right)\\ \end{array} \]
    12. Add Preprocessing

    Alternative 4: 98.8% accurate, 2.0× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \cdot x \leq -20000:\\ \;\;\;\;\frac{-1}{\mathsf{fma}\left(a, x, -1\right)} + -1\\ \mathbf{else}:\\ \;\;\;\;a \cdot \mathsf{fma}\left(\left(a \cdot x\right) \cdot \mathsf{fma}\left(a, x \cdot \mathsf{fma}\left(a, x \cdot 0.041666666666666664, 0.16666666666666666\right), 0.5\right), x, x\right)\\ \end{array} \end{array} \]
    (FPCore (a x)
     :precision binary64
     (if (<= (* a x) -20000.0)
       (+ (/ -1.0 (fma a x -1.0)) -1.0)
       (*
        a
        (fma
         (*
          (* a x)
          (fma a (* x (fma a (* x 0.041666666666666664) 0.16666666666666666)) 0.5))
         x
         x))))
    double code(double a, double x) {
    	double tmp;
    	if ((a * x) <= -20000.0) {
    		tmp = (-1.0 / fma(a, x, -1.0)) + -1.0;
    	} else {
    		tmp = a * fma(((a * x) * fma(a, (x * fma(a, (x * 0.041666666666666664), 0.16666666666666666)), 0.5)), x, x);
    	}
    	return tmp;
    }
    
    function code(a, x)
    	tmp = 0.0
    	if (Float64(a * x) <= -20000.0)
    		tmp = Float64(Float64(-1.0 / fma(a, x, -1.0)) + -1.0);
    	else
    		tmp = Float64(a * fma(Float64(Float64(a * x) * fma(a, Float64(x * fma(a, Float64(x * 0.041666666666666664), 0.16666666666666666)), 0.5)), x, x));
    	end
    	return tmp
    end
    
    code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -20000.0], N[(N[(-1.0 / N[(a * x + -1.0), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(a * N[(N[(N[(a * x), $MachinePrecision] * N[(a * N[(x * N[(a * N[(x * 0.041666666666666664), $MachinePrecision] + 0.16666666666666666), $MachinePrecision]), $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision] * x + x), $MachinePrecision]), $MachinePrecision]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;a \cdot x \leq -20000:\\
    \;\;\;\;\frac{-1}{\mathsf{fma}\left(a, x, -1\right)} + -1\\
    
    \mathbf{else}:\\
    \;\;\;\;a \cdot \mathsf{fma}\left(\left(a \cdot x\right) \cdot \mathsf{fma}\left(a, x \cdot \mathsf{fma}\left(a, x \cdot 0.041666666666666664, 0.16666666666666666\right), 0.5\right), x, x\right)\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if (*.f64 a x) < -2e4

      1. Initial program 100.0%

        \[e^{a \cdot x} - 1 \]
      2. Add Preprocessing
      3. Taylor expanded in a around 0

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

          \[\leadsto \color{blue}{\left(a \cdot x + 1\right)} - 1 \]
        2. lower-fma.f645.1

          \[\leadsto \color{blue}{\mathsf{fma}\left(a, x, 1\right)} - 1 \]
      5. Applied rewrites5.1%

        \[\leadsto \color{blue}{\mathsf{fma}\left(a, x, 1\right)} - 1 \]
      6. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto \left(\color{blue}{a \cdot x} + 1\right) - 1 \]
        2. flip-+N/A

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

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

          \[\leadsto \frac{\left(a \cdot x\right) \cdot \left(a \cdot x\right) - \color{blue}{1}}{a \cdot x - 1} - 1 \]
        5. sub-negN/A

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

          \[\leadsto \frac{\color{blue}{\left(a \cdot x\right)} \cdot \left(a \cdot x\right) + \left(\mathsf{neg}\left(1\right)\right)}{a \cdot x - 1} - 1 \]
        7. associate-*l*N/A

          \[\leadsto \frac{\color{blue}{a \cdot \left(x \cdot \left(a \cdot x\right)\right)} + \left(\mathsf{neg}\left(1\right)\right)}{a \cdot x - 1} - 1 \]
        8. *-commutativeN/A

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

          \[\leadsto \frac{a \cdot \left(\color{blue}{\left(a \cdot x\right)} \cdot x\right) + \left(\mathsf{neg}\left(1\right)\right)}{a \cdot x - 1} - 1 \]
        10. associate-*r*N/A

          \[\leadsto \frac{a \cdot \color{blue}{\left(a \cdot \left(x \cdot x\right)\right)} + \left(\mathsf{neg}\left(1\right)\right)}{a \cdot x - 1} - 1 \]
        11. lift-*.f64N/A

          \[\leadsto \frac{a \cdot \left(a \cdot \color{blue}{\left(x \cdot x\right)}\right) + \left(\mathsf{neg}\left(1\right)\right)}{a \cdot x - 1} - 1 \]
        12. lift-*.f64N/A

          \[\leadsto \frac{a \cdot \color{blue}{\left(a \cdot \left(x \cdot x\right)\right)} + \left(\mathsf{neg}\left(1\right)\right)}{a \cdot x - 1} - 1 \]
        13. lower-fma.f64N/A

          \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(a, a \cdot \left(x \cdot x\right), \mathsf{neg}\left(1\right)\right)}}{a \cdot x - 1} - 1 \]
        14. metadata-evalN/A

          \[\leadsto \frac{\mathsf{fma}\left(a, a \cdot \left(x \cdot x\right), \color{blue}{-1}\right)}{a \cdot x - 1} - 1 \]
        15. sub-negN/A

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

          \[\leadsto \frac{\mathsf{fma}\left(a, a \cdot \left(x \cdot x\right), -1\right)}{\color{blue}{a \cdot x} + \left(\mathsf{neg}\left(1\right)\right)} - 1 \]
        17. lower-fma.f64N/A

          \[\leadsto \frac{\mathsf{fma}\left(a, a \cdot \left(x \cdot x\right), -1\right)}{\color{blue}{\mathsf{fma}\left(a, x, \mathsf{neg}\left(1\right)\right)}} - 1 \]
        18. metadata-eval8.5

          \[\leadsto \frac{\mathsf{fma}\left(a, a \cdot \left(x \cdot x\right), -1\right)}{\mathsf{fma}\left(a, x, \color{blue}{-1}\right)} - 1 \]
      7. Applied rewrites8.5%

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

        \[\leadsto \frac{\color{blue}{-1}}{\mathsf{fma}\left(a, x, -1\right)} - 1 \]
      9. Step-by-step derivation
        1. Applied rewrites98.4%

          \[\leadsto \frac{\color{blue}{-1}}{\mathsf{fma}\left(a, x, -1\right)} - 1 \]

        if -2e4 < (*.f64 a x)

        1. Initial program 25.7%

          \[e^{a \cdot x} - 1 \]
        2. Add Preprocessing
        3. Taylor expanded in a around 0

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

          \[\leadsto \color{blue}{a \cdot \mathsf{fma}\left(a, x \cdot \left(x \cdot \mathsf{fma}\left(a \cdot x, \mathsf{fma}\left(a \cdot x, 0.041666666666666664, 0.16666666666666666\right), 0.5\right)\right), x\right)} \]
        5. Step-by-step derivation
          1. lift-*.f64N/A

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

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

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

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

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

            \[\leadsto a \cdot \left(a \cdot \color{blue}{\left(x \cdot \left(x \cdot \mathsf{fma}\left(a \cdot x, \mathsf{fma}\left(a \cdot x, \frac{1}{24}, \frac{1}{6}\right), \frac{1}{2}\right)\right)\right)} + x\right) \]
        6. Applied rewrites99.1%

          \[\leadsto a \cdot \color{blue}{\mathsf{fma}\left(\left(a \cdot x\right) \cdot \mathsf{fma}\left(a, x \cdot \mathsf{fma}\left(a, x \cdot 0.041666666666666664, 0.16666666666666666\right), 0.5\right), x, x\right)} \]
      10. Recombined 2 regimes into one program.
      11. Final simplification98.9%

        \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot x \leq -20000:\\ \;\;\;\;\frac{-1}{\mathsf{fma}\left(a, x, -1\right)} + -1\\ \mathbf{else}:\\ \;\;\;\;a \cdot \mathsf{fma}\left(\left(a \cdot x\right) \cdot \mathsf{fma}\left(a, x \cdot \mathsf{fma}\left(a, x \cdot 0.041666666666666664, 0.16666666666666666\right), 0.5\right), x, x\right)\\ \end{array} \]
      12. Add Preprocessing

      Alternative 5: 98.7% accurate, 2.5× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \cdot x \leq -20000:\\ \;\;\;\;\frac{-1}{\mathsf{fma}\left(a, x, -1\right)} + -1\\ \mathbf{else}:\\ \;\;\;\;a \cdot \mathsf{fma}\left(\left(a \cdot x\right) \cdot \mathsf{fma}\left(a, x \cdot 0.16666666666666666, 0.5\right), x, x\right)\\ \end{array} \end{array} \]
      (FPCore (a x)
       :precision binary64
       (if (<= (* a x) -20000.0)
         (+ (/ -1.0 (fma a x -1.0)) -1.0)
         (* a (fma (* (* a x) (fma a (* x 0.16666666666666666) 0.5)) x x))))
      double code(double a, double x) {
      	double tmp;
      	if ((a * x) <= -20000.0) {
      		tmp = (-1.0 / fma(a, x, -1.0)) + -1.0;
      	} else {
      		tmp = a * fma(((a * x) * fma(a, (x * 0.16666666666666666), 0.5)), x, x);
      	}
      	return tmp;
      }
      
      function code(a, x)
      	tmp = 0.0
      	if (Float64(a * x) <= -20000.0)
      		tmp = Float64(Float64(-1.0 / fma(a, x, -1.0)) + -1.0);
      	else
      		tmp = Float64(a * fma(Float64(Float64(a * x) * fma(a, Float64(x * 0.16666666666666666), 0.5)), x, x));
      	end
      	return tmp
      end
      
      code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -20000.0], N[(N[(-1.0 / N[(a * x + -1.0), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(a * N[(N[(N[(a * x), $MachinePrecision] * N[(a * N[(x * 0.16666666666666666), $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision] * x + x), $MachinePrecision]), $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;a \cdot x \leq -20000:\\
      \;\;\;\;\frac{-1}{\mathsf{fma}\left(a, x, -1\right)} + -1\\
      
      \mathbf{else}:\\
      \;\;\;\;a \cdot \mathsf{fma}\left(\left(a \cdot x\right) \cdot \mathsf{fma}\left(a, x \cdot 0.16666666666666666, 0.5\right), x, x\right)\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if (*.f64 a x) < -2e4

        1. Initial program 100.0%

          \[e^{a \cdot x} - 1 \]
        2. Add Preprocessing
        3. Taylor expanded in a around 0

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

            \[\leadsto \color{blue}{\left(a \cdot x + 1\right)} - 1 \]
          2. lower-fma.f645.1

            \[\leadsto \color{blue}{\mathsf{fma}\left(a, x, 1\right)} - 1 \]
        5. Applied rewrites5.1%

          \[\leadsto \color{blue}{\mathsf{fma}\left(a, x, 1\right)} - 1 \]
        6. Step-by-step derivation
          1. lift-*.f64N/A

            \[\leadsto \left(\color{blue}{a \cdot x} + 1\right) - 1 \]
          2. flip-+N/A

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

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

            \[\leadsto \frac{\left(a \cdot x\right) \cdot \left(a \cdot x\right) - \color{blue}{1}}{a \cdot x - 1} - 1 \]
          5. sub-negN/A

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

            \[\leadsto \frac{\color{blue}{\left(a \cdot x\right)} \cdot \left(a \cdot x\right) + \left(\mathsf{neg}\left(1\right)\right)}{a \cdot x - 1} - 1 \]
          7. associate-*l*N/A

            \[\leadsto \frac{\color{blue}{a \cdot \left(x \cdot \left(a \cdot x\right)\right)} + \left(\mathsf{neg}\left(1\right)\right)}{a \cdot x - 1} - 1 \]
          8. *-commutativeN/A

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

            \[\leadsto \frac{a \cdot \left(\color{blue}{\left(a \cdot x\right)} \cdot x\right) + \left(\mathsf{neg}\left(1\right)\right)}{a \cdot x - 1} - 1 \]
          10. associate-*r*N/A

            \[\leadsto \frac{a \cdot \color{blue}{\left(a \cdot \left(x \cdot x\right)\right)} + \left(\mathsf{neg}\left(1\right)\right)}{a \cdot x - 1} - 1 \]
          11. lift-*.f64N/A

            \[\leadsto \frac{a \cdot \left(a \cdot \color{blue}{\left(x \cdot x\right)}\right) + \left(\mathsf{neg}\left(1\right)\right)}{a \cdot x - 1} - 1 \]
          12. lift-*.f64N/A

            \[\leadsto \frac{a \cdot \color{blue}{\left(a \cdot \left(x \cdot x\right)\right)} + \left(\mathsf{neg}\left(1\right)\right)}{a \cdot x - 1} - 1 \]
          13. lower-fma.f64N/A

            \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(a, a \cdot \left(x \cdot x\right), \mathsf{neg}\left(1\right)\right)}}{a \cdot x - 1} - 1 \]
          14. metadata-evalN/A

            \[\leadsto \frac{\mathsf{fma}\left(a, a \cdot \left(x \cdot x\right), \color{blue}{-1}\right)}{a \cdot x - 1} - 1 \]
          15. sub-negN/A

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

            \[\leadsto \frac{\mathsf{fma}\left(a, a \cdot \left(x \cdot x\right), -1\right)}{\color{blue}{a \cdot x} + \left(\mathsf{neg}\left(1\right)\right)} - 1 \]
          17. lower-fma.f64N/A

            \[\leadsto \frac{\mathsf{fma}\left(a, a \cdot \left(x \cdot x\right), -1\right)}{\color{blue}{\mathsf{fma}\left(a, x, \mathsf{neg}\left(1\right)\right)}} - 1 \]
          18. metadata-eval8.5

            \[\leadsto \frac{\mathsf{fma}\left(a, a \cdot \left(x \cdot x\right), -1\right)}{\mathsf{fma}\left(a, x, \color{blue}{-1}\right)} - 1 \]
        7. Applied rewrites8.5%

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

          \[\leadsto \frac{\color{blue}{-1}}{\mathsf{fma}\left(a, x, -1\right)} - 1 \]
        9. Step-by-step derivation
          1. Applied rewrites98.4%

            \[\leadsto \frac{\color{blue}{-1}}{\mathsf{fma}\left(a, x, -1\right)} - 1 \]

          if -2e4 < (*.f64 a x)

          1. Initial program 25.7%

            \[e^{a \cdot x} - 1 \]
          2. Add Preprocessing
          3. Taylor expanded in a around 0

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

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

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

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

              \[\leadsto a \cdot \left(a \cdot \left(\frac{1}{2} \cdot {x}^{2} + \color{blue}{\left(\frac{1}{6} \cdot a\right) \cdot {x}^{3}}\right) + x\right) \]
            5. cube-multN/A

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

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

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

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

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

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

              \[\leadsto a \cdot \color{blue}{\mathsf{fma}\left(a \cdot {x}^{2}, \left(\frac{1}{6} \cdot a\right) \cdot x + \frac{1}{2}, x\right)} \]
          5. Applied rewrites90.6%

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto a \cdot \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(a, x \cdot \frac{1}{6}, \frac{1}{2}\right) \cdot \left(a \cdot x\right), x, x\right)} \]
            12. lower-*.f6499.1

              \[\leadsto a \cdot \mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(a, x \cdot 0.16666666666666666, 0.5\right) \cdot \left(a \cdot x\right)}, x, x\right) \]
          7. Applied rewrites99.1%

            \[\leadsto a \cdot \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(a, x \cdot 0.16666666666666666, 0.5\right) \cdot \left(a \cdot x\right), x, x\right)} \]
        10. Recombined 2 regimes into one program.
        11. Final simplification98.9%

          \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot x \leq -20000:\\ \;\;\;\;\frac{-1}{\mathsf{fma}\left(a, x, -1\right)} + -1\\ \mathbf{else}:\\ \;\;\;\;a \cdot \mathsf{fma}\left(\left(a \cdot x\right) \cdot \mathsf{fma}\left(a, x \cdot 0.16666666666666666, 0.5\right), x, x\right)\\ \end{array} \]
        12. Add Preprocessing

        Alternative 6: 98.4% accurate, 3.3× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \cdot x \leq -20000:\\ \;\;\;\;\frac{-1}{\mathsf{fma}\left(a, x, -1\right)} + -1\\ \mathbf{else}:\\ \;\;\;\;a \cdot \mathsf{fma}\left(x, a \cdot \left(x \cdot 0.5\right), x\right)\\ \end{array} \end{array} \]
        (FPCore (a x)
         :precision binary64
         (if (<= (* a x) -20000.0)
           (+ (/ -1.0 (fma a x -1.0)) -1.0)
           (* a (fma x (* a (* x 0.5)) x))))
        double code(double a, double x) {
        	double tmp;
        	if ((a * x) <= -20000.0) {
        		tmp = (-1.0 / fma(a, x, -1.0)) + -1.0;
        	} else {
        		tmp = a * fma(x, (a * (x * 0.5)), x);
        	}
        	return tmp;
        }
        
        function code(a, x)
        	tmp = 0.0
        	if (Float64(a * x) <= -20000.0)
        		tmp = Float64(Float64(-1.0 / fma(a, x, -1.0)) + -1.0);
        	else
        		tmp = Float64(a * fma(x, Float64(a * Float64(x * 0.5)), x));
        	end
        	return tmp
        end
        
        code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -20000.0], N[(N[(-1.0 / N[(a * x + -1.0), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(a * N[(x * N[(a * N[(x * 0.5), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        \mathbf{if}\;a \cdot x \leq -20000:\\
        \;\;\;\;\frac{-1}{\mathsf{fma}\left(a, x, -1\right)} + -1\\
        
        \mathbf{else}:\\
        \;\;\;\;a \cdot \mathsf{fma}\left(x, a \cdot \left(x \cdot 0.5\right), x\right)\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if (*.f64 a x) < -2e4

          1. Initial program 100.0%

            \[e^{a \cdot x} - 1 \]
          2. Add Preprocessing
          3. Taylor expanded in a around 0

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

              \[\leadsto \color{blue}{\left(a \cdot x + 1\right)} - 1 \]
            2. lower-fma.f645.1

              \[\leadsto \color{blue}{\mathsf{fma}\left(a, x, 1\right)} - 1 \]
          5. Applied rewrites5.1%

            \[\leadsto \color{blue}{\mathsf{fma}\left(a, x, 1\right)} - 1 \]
          6. Step-by-step derivation
            1. lift-*.f64N/A

              \[\leadsto \left(\color{blue}{a \cdot x} + 1\right) - 1 \]
            2. flip-+N/A

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

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

              \[\leadsto \frac{\left(a \cdot x\right) \cdot \left(a \cdot x\right) - \color{blue}{1}}{a \cdot x - 1} - 1 \]
            5. sub-negN/A

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

              \[\leadsto \frac{\color{blue}{\left(a \cdot x\right)} \cdot \left(a \cdot x\right) + \left(\mathsf{neg}\left(1\right)\right)}{a \cdot x - 1} - 1 \]
            7. associate-*l*N/A

              \[\leadsto \frac{\color{blue}{a \cdot \left(x \cdot \left(a \cdot x\right)\right)} + \left(\mathsf{neg}\left(1\right)\right)}{a \cdot x - 1} - 1 \]
            8. *-commutativeN/A

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

              \[\leadsto \frac{a \cdot \left(\color{blue}{\left(a \cdot x\right)} \cdot x\right) + \left(\mathsf{neg}\left(1\right)\right)}{a \cdot x - 1} - 1 \]
            10. associate-*r*N/A

              \[\leadsto \frac{a \cdot \color{blue}{\left(a \cdot \left(x \cdot x\right)\right)} + \left(\mathsf{neg}\left(1\right)\right)}{a \cdot x - 1} - 1 \]
            11. lift-*.f64N/A

              \[\leadsto \frac{a \cdot \left(a \cdot \color{blue}{\left(x \cdot x\right)}\right) + \left(\mathsf{neg}\left(1\right)\right)}{a \cdot x - 1} - 1 \]
            12. lift-*.f64N/A

              \[\leadsto \frac{a \cdot \color{blue}{\left(a \cdot \left(x \cdot x\right)\right)} + \left(\mathsf{neg}\left(1\right)\right)}{a \cdot x - 1} - 1 \]
            13. lower-fma.f64N/A

              \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(a, a \cdot \left(x \cdot x\right), \mathsf{neg}\left(1\right)\right)}}{a \cdot x - 1} - 1 \]
            14. metadata-evalN/A

              \[\leadsto \frac{\mathsf{fma}\left(a, a \cdot \left(x \cdot x\right), \color{blue}{-1}\right)}{a \cdot x - 1} - 1 \]
            15. sub-negN/A

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

              \[\leadsto \frac{\mathsf{fma}\left(a, a \cdot \left(x \cdot x\right), -1\right)}{\color{blue}{a \cdot x} + \left(\mathsf{neg}\left(1\right)\right)} - 1 \]
            17. lower-fma.f64N/A

              \[\leadsto \frac{\mathsf{fma}\left(a, a \cdot \left(x \cdot x\right), -1\right)}{\color{blue}{\mathsf{fma}\left(a, x, \mathsf{neg}\left(1\right)\right)}} - 1 \]
            18. metadata-eval8.5

              \[\leadsto \frac{\mathsf{fma}\left(a, a \cdot \left(x \cdot x\right), -1\right)}{\mathsf{fma}\left(a, x, \color{blue}{-1}\right)} - 1 \]
          7. Applied rewrites8.5%

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

            \[\leadsto \frac{\color{blue}{-1}}{\mathsf{fma}\left(a, x, -1\right)} - 1 \]
          9. Step-by-step derivation
            1. Applied rewrites98.4%

              \[\leadsto \frac{\color{blue}{-1}}{\mathsf{fma}\left(a, x, -1\right)} - 1 \]

            if -2e4 < (*.f64 a x)

            1. Initial program 25.7%

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

                \[\leadsto e^{\color{blue}{a \cdot x}} - 1 \]
              2. lift-exp.f64N/A

                \[\leadsto \color{blue}{e^{a \cdot x}} - 1 \]
              3. flip--N/A

                \[\leadsto \color{blue}{\frac{e^{a \cdot x} \cdot e^{a \cdot x} - 1 \cdot 1}{e^{a \cdot x} + 1}} \]
              4. lower-/.f64N/A

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

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

                \[\leadsto \frac{e^{a \cdot x} \cdot \color{blue}{e^{a \cdot x}} - 1 \cdot 1}{e^{a \cdot x} + 1} \]
              7. prod-expN/A

                \[\leadsto \frac{\color{blue}{e^{a \cdot x + a \cdot x}} - 1 \cdot 1}{e^{a \cdot x} + 1} \]
              8. metadata-evalN/A

                \[\leadsto \frac{e^{a \cdot x + a \cdot x} - \color{blue}{1}}{e^{a \cdot x} + 1} \]
              9. lower-expm1.f64N/A

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

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

                \[\leadsto \frac{\mathsf{expm1}\left(a \cdot x + \color{blue}{a \cdot x}\right)}{e^{a \cdot x} + 1} \]
              12. distribute-lft-outN/A

                \[\leadsto \frac{\mathsf{expm1}\left(\color{blue}{a \cdot \left(x + x\right)}\right)}{e^{a \cdot x} + 1} \]
              13. lower-*.f64N/A

                \[\leadsto \frac{\mathsf{expm1}\left(\color{blue}{a \cdot \left(x + x\right)}\right)}{e^{a \cdot x} + 1} \]
              14. lower-+.f64N/A

                \[\leadsto \frac{\mathsf{expm1}\left(a \cdot \color{blue}{\left(x + x\right)}\right)}{e^{a \cdot x} + 1} \]
              15. lower-+.f6499.9

                \[\leadsto \frac{\mathsf{expm1}\left(a \cdot \left(x + x\right)\right)}{\color{blue}{e^{a \cdot x} + 1}} \]
            4. Applied rewrites99.9%

              \[\leadsto \color{blue}{\frac{\mathsf{expm1}\left(a \cdot \left(x + x\right)\right)}{e^{a \cdot x} + 1}} \]
            5. Step-by-step derivation
              1. exp-prodN/A

                \[\leadsto \frac{\mathsf{expm1}\left(a \cdot \left(x + x\right)\right)}{\color{blue}{{\left(e^{a}\right)}^{x}} + 1} \]
              2. sqr-powN/A

                \[\leadsto \frac{\mathsf{expm1}\left(a \cdot \left(x + x\right)\right)}{\color{blue}{{\left(e^{a}\right)}^{\left(\frac{x}{2}\right)} \cdot {\left(e^{a}\right)}^{\left(\frac{x}{2}\right)}} + 1} \]
              3. pow2N/A

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

                \[\leadsto \frac{\mathsf{expm1}\left(a \cdot \left(x + x\right)\right)}{\color{blue}{{\left({\left(e^{a}\right)}^{\left(\frac{x}{2}\right)}\right)}^{2}} + 1} \]
              5. pow-expN/A

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

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

                \[\leadsto \frac{\mathsf{expm1}\left(a \cdot \left(x + x\right)\right)}{{\left(e^{\color{blue}{a \cdot \frac{x}{2}}}\right)}^{2} + 1} \]
              8. div-invN/A

                \[\leadsto \frac{\mathsf{expm1}\left(a \cdot \left(x + x\right)\right)}{{\left(e^{a \cdot \color{blue}{\left(x \cdot \frac{1}{2}\right)}}\right)}^{2} + 1} \]
              9. metadata-evalN/A

                \[\leadsto \frac{\mathsf{expm1}\left(a \cdot \left(x + x\right)\right)}{{\left(e^{a \cdot \left(x \cdot \color{blue}{\frac{1}{2}}\right)}\right)}^{2} + 1} \]
              10. lower-*.f6499.9

                \[\leadsto \frac{\mathsf{expm1}\left(a \cdot \left(x + x\right)\right)}{{\left(e^{a \cdot \color{blue}{\left(x \cdot 0.5\right)}}\right)}^{2} + 1} \]
            6. Applied rewrites99.9%

              \[\leadsto \frac{\mathsf{expm1}\left(a \cdot \left(x + x\right)\right)}{\color{blue}{{\left(e^{a \cdot \left(x \cdot 0.5\right)}\right)}^{2}} + 1} \]
            7. Taylor expanded in a around 0

              \[\leadsto \color{blue}{a \cdot \left(x + a \cdot \left({x}^{2} - \frac{1}{2} \cdot {x}^{2}\right)\right)} \]
            8. Step-by-step derivation
              1. distribute-rgt-inN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                \[\leadsto a \cdot \color{blue}{\left(\left(\frac{1}{2} \cdot {x}^{2}\right) \cdot a + x\right)} \]
            9. Applied rewrites99.0%

              \[\leadsto \color{blue}{a \cdot \mathsf{fma}\left(x, a \cdot \left(x \cdot 0.5\right), x\right)} \]
          10. Recombined 2 regimes into one program.
          11. Final simplification98.8%

            \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot x \leq -20000:\\ \;\;\;\;\frac{-1}{\mathsf{fma}\left(a, x, -1\right)} + -1\\ \mathbf{else}:\\ \;\;\;\;a \cdot \mathsf{fma}\left(x, a \cdot \left(x \cdot 0.5\right), x\right)\\ \end{array} \]
          12. Add Preprocessing

          Alternative 7: 97.8% accurate, 3.4× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \cdot x \leq -20000:\\ \;\;\;\;\frac{-1}{\mathsf{fma}\left(a, x, -1\right)} + -1\\ \mathbf{else}:\\ \;\;\;\;a \cdot x\\ \end{array} \end{array} \]
          (FPCore (a x)
           :precision binary64
           (if (<= (* a x) -20000.0) (+ (/ -1.0 (fma a x -1.0)) -1.0) (* a x)))
          double code(double a, double x) {
          	double tmp;
          	if ((a * x) <= -20000.0) {
          		tmp = (-1.0 / fma(a, x, -1.0)) + -1.0;
          	} else {
          		tmp = a * x;
          	}
          	return tmp;
          }
          
          function code(a, x)
          	tmp = 0.0
          	if (Float64(a * x) <= -20000.0)
          		tmp = Float64(Float64(-1.0 / fma(a, x, -1.0)) + -1.0);
          	else
          		tmp = Float64(a * x);
          	end
          	return tmp
          end
          
          code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -20000.0], N[(N[(-1.0 / N[(a * x + -1.0), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(a * x), $MachinePrecision]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;a \cdot x \leq -20000:\\
          \;\;\;\;\frac{-1}{\mathsf{fma}\left(a, x, -1\right)} + -1\\
          
          \mathbf{else}:\\
          \;\;\;\;a \cdot x\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if (*.f64 a x) < -2e4

            1. Initial program 100.0%

              \[e^{a \cdot x} - 1 \]
            2. Add Preprocessing
            3. Taylor expanded in a around 0

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

                \[\leadsto \color{blue}{\left(a \cdot x + 1\right)} - 1 \]
              2. lower-fma.f645.1

                \[\leadsto \color{blue}{\mathsf{fma}\left(a, x, 1\right)} - 1 \]
            5. Applied rewrites5.1%

              \[\leadsto \color{blue}{\mathsf{fma}\left(a, x, 1\right)} - 1 \]
            6. Step-by-step derivation
              1. lift-*.f64N/A

                \[\leadsto \left(\color{blue}{a \cdot x} + 1\right) - 1 \]
              2. flip-+N/A

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

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

                \[\leadsto \frac{\left(a \cdot x\right) \cdot \left(a \cdot x\right) - \color{blue}{1}}{a \cdot x - 1} - 1 \]
              5. sub-negN/A

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

                \[\leadsto \frac{\color{blue}{\left(a \cdot x\right)} \cdot \left(a \cdot x\right) + \left(\mathsf{neg}\left(1\right)\right)}{a \cdot x - 1} - 1 \]
              7. associate-*l*N/A

                \[\leadsto \frac{\color{blue}{a \cdot \left(x \cdot \left(a \cdot x\right)\right)} + \left(\mathsf{neg}\left(1\right)\right)}{a \cdot x - 1} - 1 \]
              8. *-commutativeN/A

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

                \[\leadsto \frac{a \cdot \left(\color{blue}{\left(a \cdot x\right)} \cdot x\right) + \left(\mathsf{neg}\left(1\right)\right)}{a \cdot x - 1} - 1 \]
              10. associate-*r*N/A

                \[\leadsto \frac{a \cdot \color{blue}{\left(a \cdot \left(x \cdot x\right)\right)} + \left(\mathsf{neg}\left(1\right)\right)}{a \cdot x - 1} - 1 \]
              11. lift-*.f64N/A

                \[\leadsto \frac{a \cdot \left(a \cdot \color{blue}{\left(x \cdot x\right)}\right) + \left(\mathsf{neg}\left(1\right)\right)}{a \cdot x - 1} - 1 \]
              12. lift-*.f64N/A

                \[\leadsto \frac{a \cdot \color{blue}{\left(a \cdot \left(x \cdot x\right)\right)} + \left(\mathsf{neg}\left(1\right)\right)}{a \cdot x - 1} - 1 \]
              13. lower-fma.f64N/A

                \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(a, a \cdot \left(x \cdot x\right), \mathsf{neg}\left(1\right)\right)}}{a \cdot x - 1} - 1 \]
              14. metadata-evalN/A

                \[\leadsto \frac{\mathsf{fma}\left(a, a \cdot \left(x \cdot x\right), \color{blue}{-1}\right)}{a \cdot x - 1} - 1 \]
              15. sub-negN/A

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

                \[\leadsto \frac{\mathsf{fma}\left(a, a \cdot \left(x \cdot x\right), -1\right)}{\color{blue}{a \cdot x} + \left(\mathsf{neg}\left(1\right)\right)} - 1 \]
              17. lower-fma.f64N/A

                \[\leadsto \frac{\mathsf{fma}\left(a, a \cdot \left(x \cdot x\right), -1\right)}{\color{blue}{\mathsf{fma}\left(a, x, \mathsf{neg}\left(1\right)\right)}} - 1 \]
              18. metadata-eval8.5

                \[\leadsto \frac{\mathsf{fma}\left(a, a \cdot \left(x \cdot x\right), -1\right)}{\mathsf{fma}\left(a, x, \color{blue}{-1}\right)} - 1 \]
            7. Applied rewrites8.5%

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

              \[\leadsto \frac{\color{blue}{-1}}{\mathsf{fma}\left(a, x, -1\right)} - 1 \]
            9. Step-by-step derivation
              1. Applied rewrites98.4%

                \[\leadsto \frac{\color{blue}{-1}}{\mathsf{fma}\left(a, x, -1\right)} - 1 \]

              if -2e4 < (*.f64 a x)

              1. Initial program 25.7%

                \[e^{a \cdot x} - 1 \]
              2. Add Preprocessing
              3. Taylor expanded in a around 0

                \[\leadsto \color{blue}{a \cdot x} \]
              4. Step-by-step derivation
                1. lower-*.f6498.7

                  \[\leadsto \color{blue}{a \cdot x} \]
              5. Applied rewrites98.7%

                \[\leadsto \color{blue}{a \cdot x} \]
            10. Recombined 2 regimes into one program.
            11. Final simplification98.6%

              \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot x \leq -20000:\\ \;\;\;\;\frac{-1}{\mathsf{fma}\left(a, x, -1\right)} + -1\\ \mathbf{else}:\\ \;\;\;\;a \cdot x\\ \end{array} \]
            12. Add Preprocessing

            Alternative 8: 66.9% accurate, 18.2× speedup?

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

              \[e^{a \cdot x} - 1 \]
            2. Add Preprocessing
            3. Taylor expanded in a around 0

              \[\leadsto \color{blue}{a \cdot x} \]
            4. Step-by-step derivation
              1. lower-*.f6467.2

                \[\leadsto \color{blue}{a \cdot x} \]
            5. Applied rewrites67.2%

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

            Alternative 9: 19.3% accurate, 109.0× speedup?

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

              \[e^{a \cdot x} - 1 \]
            2. Add Preprocessing
            3. Taylor expanded in a around 0

              \[\leadsto \color{blue}{1} - 1 \]
            4. Step-by-step derivation
              1. Applied rewrites17.0%

                \[\leadsto \color{blue}{1} - 1 \]
              2. Step-by-step derivation
                1. metadata-eval17.0

                  \[\leadsto \color{blue}{0} \]
              3. Applied rewrites17.0%

                \[\leadsto \color{blue}{0} \]
              4. Add Preprocessing

              Developer Target 1: 100.0% accurate, 1.0× speedup?

              \[\begin{array}{l} \\ \mathsf{expm1}\left(a \cdot x\right) \end{array} \]
              (FPCore (a x) :precision binary64 (expm1 (* a x)))
              double code(double a, double x) {
              	return expm1((a * x));
              }
              
              public static double code(double a, double x) {
              	return Math.expm1((a * x));
              }
              
              def code(a, x):
              	return math.expm1((a * x))
              
              function code(a, x)
              	return expm1(Float64(a * x))
              end
              
              code[a_, x_] := N[(Exp[N[(a * x), $MachinePrecision]] - 1), $MachinePrecision]
              
              \begin{array}{l}
              
              \\
              \mathsf{expm1}\left(a \cdot x\right)
              \end{array}
              

              Reproduce

              ?
              herbie shell --seed 2024219 
              (FPCore (a x)
                :name "expax (section 3.5)"
                :precision binary64
                :pre (> 710.0 (* a x))
              
                :alt
                (! :herbie-platform default (expm1 (* a x)))
              
                (- (exp (* a x)) 1.0))