expax (section 3.5)

Percentage Accurate: 54.1% → 100.0%
Time: 9.5s
Alternatives: 8
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 8 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: 54.1% 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: 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 52.5%

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

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

      \[\leadsto \color{blue}{e^{a \cdot x}} - 1 \]
    3. 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 2: 98.5% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \cdot x \leq -20:\\ \;\;\;\;\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 \cdot x, \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) -20.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) <= -20.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) <= -20.0)
		tmp = Float64(Float64(-1.0 / fma(a, x, -1.0)) + -1.0);
	else
		tmp = Float64(a * fma(Float64(Float64(a * x) * fma(Float64(a * 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], -20.0], N[(N[(-1.0 / N[(a * x + -1.0), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(a * N[(N[(N[(a * x), $MachinePrecision] * N[(N[(a * x), $MachinePrecision] * N[(a * N[(x * 0.041666666666666664), $MachinePrecision] + 0.16666666666666666), $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision] * x + x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -20:\\
\;\;\;\;\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 \cdot x, \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) < -20

    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.4

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

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

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

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

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

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

          if -20 < (*.f64 a x)

          1. Initial program 28.9%

            \[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 rewrites92.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. Applied rewrites99.5%

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

            \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot x \leq -20:\\ \;\;\;\;\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 \cdot x, \mathsf{fma}\left(a, x \cdot 0.041666666666666664, 0.16666666666666666\right), 0.5\right), x, x\right)\\ \end{array} \]
          8. Add Preprocessing

          Alternative 3: 98.5% accurate, 2.2× speedup?

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

            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.4

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

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

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

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

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

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

                  if -20 < (*.f64 a x)

                  1. Initial program 28.9%

                    \[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 rewrites92.5%

                    \[\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. Applied rewrites99.4%

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

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

                  Alternative 4: 98.4% accurate, 2.5× speedup?

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

                    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.4

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

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

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

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

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

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

                          if -20 < (*.f64 a x)

                          1. Initial program 28.9%

                            \[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 rewrites92.5%

                            \[\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. Applied rewrites99.4%

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

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

                          Alternative 5: 98.2% accurate, 3.3× speedup?

                          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \cdot x \leq -20:\\ \;\;\;\;\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) -20.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) <= -20.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) <= -20.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], -20.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 -20:\\
                          \;\;\;\;\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) < -20

                            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.4

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

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

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

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

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

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

                                  if -20 < (*.f64 a x)

                                  1. Initial program 28.9%

                                    \[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 rewrites92.5%

                                    \[\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. Taylor expanded in a around 0

                                    \[\leadsto a \cdot \left(x + \color{blue}{\frac{1}{2} \cdot \left(a \cdot {x}^{2}\right)}\right) \]
                                  7. Step-by-step derivation
                                    1. Applied rewrites98.8%

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

                                    \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot x \leq -20:\\ \;\;\;\;\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} \]
                                  10. Add Preprocessing

                                  Alternative 6: 97.6% accurate, 3.4× speedup?

                                  \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \cdot x \leq -1 \cdot 10^{-6}:\\ \;\;\;\;\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) -1e-6) (+ (/ -1.0 (fma a x -1.0)) -1.0) (* a x)))
                                  double code(double a, double x) {
                                  	double tmp;
                                  	if ((a * x) <= -1e-6) {
                                  		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) <= -1e-6)
                                  		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], -1e-6], 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 -1 \cdot 10^{-6}:\\
                                  \;\;\;\;\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) < -9.99999999999999955e-7

                                    1. Initial program 99.6%

                                      \[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.f646.4

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

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

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

                                        \[\leadsto -1 \cdot \frac{\color{blue}{1}}{\mathsf{fma}\left(a, x, -1\right)} - 1 \]
                                      3. Step-by-step derivation
                                        1. Applied rewrites93.8%

                                          \[\leadsto -1 \cdot \frac{\color{blue}{1}}{\mathsf{fma}\left(a, x, -1\right)} - 1 \]
                                        2. Step-by-step derivation
                                          1. Applied rewrites93.8%

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

                                          if -9.99999999999999955e-7 < (*.f64 a x)

                                          1. Initial program 27.8%

                                            \[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.5

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

                                            \[\leadsto \color{blue}{a \cdot x} \]
                                        3. Recombined 2 regimes into one program.
                                        4. Final simplification96.9%

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

                                        Alternative 7: 67.3% 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 52.5%

                                          \[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-*.f6466.8

                                            \[\leadsto \color{blue}{a \cdot x} \]
                                        5. Applied rewrites66.8%

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

                                        Alternative 8: 20.2% accurate, 27.3× speedup?

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

                                          \[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.8%

                                            \[\leadsto \color{blue}{1} - 1 \]
                                          2. Final simplification17.8%

                                            \[\leadsto 1 + -1 \]
                                          3. 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 2024225 
                                          (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))