expax (section 3.5)

Percentage Accurate: 53.3% → 100.0%
Time: 9.9s
Alternatives: 6
Speedup: 11.7×

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 6 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 53.3% 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 54.2%

    \[e^{a \cdot x} - 1 \]
  2. Step-by-step derivation
    1. expm1-defineN/A

      \[\leadsto \mathsf{expm1}\left(a \cdot x\right) \]
    2. expm1-lowering-expm1.f64N/A

      \[\leadsto \mathsf{expm1.f64}\left(\left(a \cdot x\right)\right) \]
    3. *-lowering-*.f64100.0%

      \[\leadsto \mathsf{expm1.f64}\left(\mathsf{*.f64}\left(a, x\right)\right) \]
  3. Simplified100.0%

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

Alternative 2: 72.8% accurate, 7.0× speedup?

\[\begin{array}{l} \\ x \cdot \frac{1}{x \cdot \left(\frac{a}{a} + -1.5\right) + \frac{1}{a}} \end{array} \]
(FPCore (a x)
 :precision binary64
 (* x (/ 1.0 (+ (* x (+ (/ a a) -1.5)) (/ 1.0 a)))))
double code(double a, double x) {
	return x * (1.0 / ((x * ((a / a) + -1.5)) + (1.0 / a)));
}
real(8) function code(a, x)
    real(8), intent (in) :: a
    real(8), intent (in) :: x
    code = x * (1.0d0 / ((x * ((a / a) + (-1.5d0))) + (1.0d0 / a)))
end function
public static double code(double a, double x) {
	return x * (1.0 / ((x * ((a / a) + -1.5)) + (1.0 / a)));
}
def code(a, x):
	return x * (1.0 / ((x * ((a / a) + -1.5)) + (1.0 / a)))
function code(a, x)
	return Float64(x * Float64(1.0 / Float64(Float64(x * Float64(Float64(a / a) + -1.5)) + Float64(1.0 / a))))
end
function tmp = code(a, x)
	tmp = x * (1.0 / ((x * ((a / a) + -1.5)) + (1.0 / a)));
end
code[a_, x_] := N[(x * N[(1.0 / N[(N[(x * N[(N[(a / a), $MachinePrecision] + -1.5), $MachinePrecision]), $MachinePrecision] + N[(1.0 / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x \cdot \frac{1}{x \cdot \left(\frac{a}{a} + -1.5\right) + \frac{1}{a}}
\end{array}
Derivation
  1. Initial program 54.2%

    \[e^{a \cdot x} - 1 \]
  2. Step-by-step derivation
    1. expm1-defineN/A

      \[\leadsto \mathsf{expm1}\left(a \cdot x\right) \]
    2. expm1-lowering-expm1.f64N/A

      \[\leadsto \mathsf{expm1.f64}\left(\left(a \cdot x\right)\right) \]
    3. *-lowering-*.f64100.0%

      \[\leadsto \mathsf{expm1.f64}\left(\mathsf{*.f64}\left(a, x\right)\right) \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\mathsf{expm1}\left(a \cdot x\right)} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. sub-negN/A

      \[\leadsto e^{a \cdot x} + \color{blue}{\left(\mathsf{neg}\left(1\right)\right)} \]
    2. flip3-+N/A

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

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

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

      \[\leadsto \frac{{\left(e^{a \cdot x}\right)}^{3} + \left(\mathsf{neg}\left(1\right)\right)}{e^{a \cdot x} \cdot \color{blue}{e^{a \cdot x}} + \left(\left(\mathsf{neg}\left(1\right)\right) \cdot \left(\mathsf{neg}\left(1\right)\right) - e^{a \cdot x} \cdot \left(\mathsf{neg}\left(1\right)\right)\right)} \]
    6. sub-negN/A

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

      \[\leadsto \frac{{\left(e^{a \cdot x}\right)}^{3} - {1}^{3}}{e^{a \cdot x} \cdot \color{blue}{e^{a \cdot x}} + \left(\left(\mathsf{neg}\left(1\right)\right) \cdot \left(\mathsf{neg}\left(1\right)\right) - e^{a \cdot x} \cdot \left(\mathsf{neg}\left(1\right)\right)\right)} \]
    8. clear-numN/A

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

      \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left(\frac{e^{a \cdot x} \cdot e^{a \cdot x} + \left(\left(\mathsf{neg}\left(1\right)\right) \cdot \left(\mathsf{neg}\left(1\right)\right) - e^{a \cdot x} \cdot \left(\mathsf{neg}\left(1\right)\right)\right)}{{\left(e^{a \cdot x}\right)}^{3} - {1}^{3}}\right)}\right) \]
    10. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\left(e^{a \cdot x} \cdot e^{a \cdot x} + \left(\left(\mathsf{neg}\left(1\right)\right) \cdot \left(\mathsf{neg}\left(1\right)\right) - e^{a \cdot x} \cdot \left(\mathsf{neg}\left(1\right)\right)\right)\right), \color{blue}{\left({\left(e^{a \cdot x}\right)}^{3} - {1}^{3}\right)}\right)\right) \]
  6. Applied egg-rr99.1%

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

    \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left(\frac{x \cdot \left(\frac{1}{3} \cdot \frac{2 \cdot a - -1 \cdot a}{a} - \frac{3}{2}\right) + \frac{1}{a}}{x}\right)}\right) \]
  8. Step-by-step derivation
    1. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\left(x \cdot \left(\frac{1}{3} \cdot \frac{2 \cdot a - -1 \cdot a}{a} - \frac{3}{2}\right) + \frac{1}{a}\right), \color{blue}{x}\right)\right) \]
    2. +-lowering-+.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\left(x \cdot \left(\frac{1}{3} \cdot \frac{2 \cdot a - -1 \cdot a}{a} - \frac{3}{2}\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \left(\frac{1}{3} \cdot \frac{2 \cdot a - -1 \cdot a}{a} - \frac{3}{2}\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
    4. sub-negN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \left(\frac{1}{3} \cdot \frac{2 \cdot a - -1 \cdot a}{a} + \left(\mathsf{neg}\left(\frac{3}{2}\right)\right)\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
    5. +-lowering-+.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\left(\frac{1}{3} \cdot \frac{2 \cdot a - -1 \cdot a}{a}\right), \left(\mathsf{neg}\left(\frac{3}{2}\right)\right)\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
    6. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{3}, \left(\frac{2 \cdot a - -1 \cdot a}{a}\right)\right), \left(\mathsf{neg}\left(\frac{3}{2}\right)\right)\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
    7. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{3}, \mathsf{/.f64}\left(\left(2 \cdot a - -1 \cdot a\right), a\right)\right), \left(\mathsf{neg}\left(\frac{3}{2}\right)\right)\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
    8. distribute-rgt-out--N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{3}, \mathsf{/.f64}\left(\left(a \cdot \left(2 - -1\right)\right), a\right)\right), \left(\mathsf{neg}\left(\frac{3}{2}\right)\right)\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
    9. metadata-evalN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{3}, \mathsf{/.f64}\left(\left(a \cdot 3\right), a\right)\right), \left(\mathsf{neg}\left(\frac{3}{2}\right)\right)\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
    10. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{3}, \mathsf{/.f64}\left(\mathsf{*.f64}\left(a, 3\right), a\right)\right), \left(\mathsf{neg}\left(\frac{3}{2}\right)\right)\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
    11. metadata-evalN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{3}, \mathsf{/.f64}\left(\mathsf{*.f64}\left(a, 3\right), a\right)\right), \frac{-3}{2}\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
    12. /-lowering-/.f6471.2%

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{3}, \mathsf{/.f64}\left(\mathsf{*.f64}\left(a, 3\right), a\right)\right), \frac{-3}{2}\right)\right), \mathsf{/.f64}\left(1, a\right)\right), x\right)\right) \]
  9. Simplified71.2%

    \[\leadsto \frac{1}{\color{blue}{\frac{x \cdot \left(0.3333333333333333 \cdot \frac{a \cdot 3}{a} + -1.5\right) + \frac{1}{a}}{x}}} \]
  10. Step-by-step derivation
    1. associate-/r/N/A

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

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(1, \left(x \cdot \left(\frac{1}{3} \cdot \frac{a \cdot 3}{a} + \frac{-3}{2}\right) + \frac{1}{a}\right)\right), x\right) \]
    4. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(1, \mathsf{+.f64}\left(\left(x \cdot \left(\frac{1}{3} \cdot \frac{a \cdot 3}{a} + \frac{-3}{2}\right)\right), \left(\frac{1}{a}\right)\right)\right), x\right) \]
    5. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(1, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \left(\frac{1}{3} \cdot \frac{a \cdot 3}{a} + \frac{-3}{2}\right)\right), \left(\frac{1}{a}\right)\right)\right), x\right) \]
    6. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(1, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\left(\frac{1}{3} \cdot \frac{a \cdot 3}{a}\right), \frac{-3}{2}\right)\right), \left(\frac{1}{a}\right)\right)\right), x\right) \]
    7. associate-*r/N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(1, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\left(\frac{\frac{1}{3} \cdot \left(a \cdot 3\right)}{a}\right), \frac{-3}{2}\right)\right), \left(\frac{1}{a}\right)\right)\right), x\right) \]
    8. /-lowering-/.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(1, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(\left(\frac{1}{3} \cdot \left(a \cdot 3\right)\right), a\right), \frac{-3}{2}\right)\right), \left(\frac{1}{a}\right)\right)\right), x\right) \]
    9. *-commutativeN/A

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(1, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(\left(\left(\frac{1}{3} \cdot 3\right) \cdot a\right), a\right), \frac{-3}{2}\right)\right), \left(\frac{1}{a}\right)\right)\right), x\right) \]
    11. metadata-evalN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(1, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(\left(1 \cdot a\right), a\right), \frac{-3}{2}\right)\right), \left(\frac{1}{a}\right)\right)\right), x\right) \]
    12. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(1, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(1, a\right), a\right), \frac{-3}{2}\right)\right), \left(\frac{1}{a}\right)\right)\right), x\right) \]
    13. /-lowering-/.f6471.9%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(1, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(1, a\right), a\right), \frac{-3}{2}\right)\right), \mathsf{/.f64}\left(1, a\right)\right)\right), x\right) \]
  11. Applied egg-rr71.9%

    \[\leadsto \color{blue}{\frac{1}{x \cdot \left(\frac{1 \cdot a}{a} + -1.5\right) + \frac{1}{a}} \cdot x} \]
  12. Final simplification71.9%

    \[\leadsto x \cdot \frac{1}{x \cdot \left(\frac{a}{a} + -1.5\right) + \frac{1}{a}} \]
  13. Add Preprocessing

Alternative 3: 72.2% accurate, 7.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \cdot x \leq -500:\\ \;\;\;\;-2 + \frac{-4}{a \cdot x}\\ \mathbf{else}:\\ \;\;\;\;a \cdot x\\ \end{array} \end{array} \]
(FPCore (a x)
 :precision binary64
 (if (<= (* a x) -500.0) (+ -2.0 (/ -4.0 (* a x))) (* a x)))
double code(double a, double x) {
	double tmp;
	if ((a * x) <= -500.0) {
		tmp = -2.0 + (-4.0 / (a * x));
	} else {
		tmp = a * x;
	}
	return tmp;
}
real(8) function code(a, x)
    real(8), intent (in) :: a
    real(8), intent (in) :: x
    real(8) :: tmp
    if ((a * x) <= (-500.0d0)) then
        tmp = (-2.0d0) + ((-4.0d0) / (a * x))
    else
        tmp = a * x
    end if
    code = tmp
end function
public static double code(double a, double x) {
	double tmp;
	if ((a * x) <= -500.0) {
		tmp = -2.0 + (-4.0 / (a * x));
	} else {
		tmp = a * x;
	}
	return tmp;
}
def code(a, x):
	tmp = 0
	if (a * x) <= -500.0:
		tmp = -2.0 + (-4.0 / (a * x))
	else:
		tmp = a * x
	return tmp
function code(a, x)
	tmp = 0.0
	if (Float64(a * x) <= -500.0)
		tmp = Float64(-2.0 + Float64(-4.0 / Float64(a * x)));
	else
		tmp = Float64(a * x);
	end
	return tmp
end
function tmp_2 = code(a, x)
	tmp = 0.0;
	if ((a * x) <= -500.0)
		tmp = -2.0 + (-4.0 / (a * x));
	else
		tmp = a * x;
	end
	tmp_2 = tmp;
end
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -500.0], N[(-2.0 + N[(-4.0 / N[(a * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(a * x), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -500:\\
\;\;\;\;-2 + \frac{-4}{a \cdot x}\\

\mathbf{else}:\\
\;\;\;\;a \cdot x\\


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

    1. Initial program 100.0%

      \[e^{a \cdot x} - 1 \]
    2. Step-by-step derivation
      1. expm1-defineN/A

        \[\leadsto \mathsf{expm1}\left(a \cdot x\right) \]
      2. expm1-lowering-expm1.f64N/A

        \[\leadsto \mathsf{expm1.f64}\left(\left(a \cdot x\right)\right) \]
      3. *-lowering-*.f64100.0%

        \[\leadsto \mathsf{expm1.f64}\left(\mathsf{*.f64}\left(a, x\right)\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(a \cdot x\right)} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. sub-negN/A

        \[\leadsto e^{a \cdot x} + \color{blue}{\left(\mathsf{neg}\left(1\right)\right)} \]
      2. flip3-+N/A

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

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

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

        \[\leadsto \frac{{\left(e^{a \cdot x}\right)}^{3} + \left(\mathsf{neg}\left(1\right)\right)}{e^{a \cdot x} \cdot \color{blue}{e^{a \cdot x}} + \left(\left(\mathsf{neg}\left(1\right)\right) \cdot \left(\mathsf{neg}\left(1\right)\right) - e^{a \cdot x} \cdot \left(\mathsf{neg}\left(1\right)\right)\right)} \]
      6. sub-negN/A

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

        \[\leadsto \frac{{\left(e^{a \cdot x}\right)}^{3} - {1}^{3}}{e^{a \cdot x} \cdot \color{blue}{e^{a \cdot x}} + \left(\left(\mathsf{neg}\left(1\right)\right) \cdot \left(\mathsf{neg}\left(1\right)\right) - e^{a \cdot x} \cdot \left(\mathsf{neg}\left(1\right)\right)\right)} \]
      8. clear-numN/A

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

        \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left(\frac{e^{a \cdot x} \cdot e^{a \cdot x} + \left(\left(\mathsf{neg}\left(1\right)\right) \cdot \left(\mathsf{neg}\left(1\right)\right) - e^{a \cdot x} \cdot \left(\mathsf{neg}\left(1\right)\right)\right)}{{\left(e^{a \cdot x}\right)}^{3} - {1}^{3}}\right)}\right) \]
      10. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\left(e^{a \cdot x} \cdot e^{a \cdot x} + \left(\left(\mathsf{neg}\left(1\right)\right) \cdot \left(\mathsf{neg}\left(1\right)\right) - e^{a \cdot x} \cdot \left(\mathsf{neg}\left(1\right)\right)\right)\right), \color{blue}{\left({\left(e^{a \cdot x}\right)}^{3} - {1}^{3}\right)}\right)\right) \]
    6. Applied egg-rr100.0%

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

      \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left(\frac{x \cdot \left(\frac{1}{3} \cdot \frac{2 \cdot a - -1 \cdot a}{a} - \frac{3}{2}\right) + \frac{1}{a}}{x}\right)}\right) \]
    8. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\left(x \cdot \left(\frac{1}{3} \cdot \frac{2 \cdot a - -1 \cdot a}{a} - \frac{3}{2}\right) + \frac{1}{a}\right), \color{blue}{x}\right)\right) \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\left(x \cdot \left(\frac{1}{3} \cdot \frac{2 \cdot a - -1 \cdot a}{a} - \frac{3}{2}\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \left(\frac{1}{3} \cdot \frac{2 \cdot a - -1 \cdot a}{a} - \frac{3}{2}\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
      4. sub-negN/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \left(\frac{1}{3} \cdot \frac{2 \cdot a - -1 \cdot a}{a} + \left(\mathsf{neg}\left(\frac{3}{2}\right)\right)\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
      5. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\left(\frac{1}{3} \cdot \frac{2 \cdot a - -1 \cdot a}{a}\right), \left(\mathsf{neg}\left(\frac{3}{2}\right)\right)\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
      6. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{3}, \left(\frac{2 \cdot a - -1 \cdot a}{a}\right)\right), \left(\mathsf{neg}\left(\frac{3}{2}\right)\right)\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{3}, \mathsf{/.f64}\left(\left(2 \cdot a - -1 \cdot a\right), a\right)\right), \left(\mathsf{neg}\left(\frac{3}{2}\right)\right)\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
      8. distribute-rgt-out--N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{3}, \mathsf{/.f64}\left(\left(a \cdot \left(2 - -1\right)\right), a\right)\right), \left(\mathsf{neg}\left(\frac{3}{2}\right)\right)\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
      9. metadata-evalN/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{3}, \mathsf{/.f64}\left(\left(a \cdot 3\right), a\right)\right), \left(\mathsf{neg}\left(\frac{3}{2}\right)\right)\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
      10. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{3}, \mathsf{/.f64}\left(\mathsf{*.f64}\left(a, 3\right), a\right)\right), \left(\mathsf{neg}\left(\frac{3}{2}\right)\right)\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
      11. metadata-evalN/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{3}, \mathsf{/.f64}\left(\mathsf{*.f64}\left(a, 3\right), a\right)\right), \frac{-3}{2}\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
      12. /-lowering-/.f6418.8%

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{3}, \mathsf{/.f64}\left(\mathsf{*.f64}\left(a, 3\right), a\right)\right), \frac{-3}{2}\right)\right), \mathsf{/.f64}\left(1, a\right)\right), x\right)\right) \]
    9. Simplified18.8%

      \[\leadsto \frac{1}{\color{blue}{\frac{x \cdot \left(0.3333333333333333 \cdot \frac{a \cdot 3}{a} + -1.5\right) + \frac{1}{a}}{x}}} \]
    10. Taylor expanded in x around inf

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

        \[\leadsto \mathsf{neg}\left(\left(2 + 4 \cdot \frac{1}{a \cdot x}\right)\right) \]
      2. distribute-neg-inN/A

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

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

        \[\leadsto \mathsf{+.f64}\left(-2, \left(\mathsf{neg}\left(\color{blue}{4 \cdot \frac{1}{a \cdot x}}\right)\right)\right) \]
      5. mul-1-negN/A

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

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

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

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

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

        \[\leadsto \mathsf{+.f64}\left(-2, \left(\frac{\mathsf{neg}\left(4\right)}{\color{blue}{a} \cdot x}\right)\right) \]
      11. /-lowering-/.f64N/A

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

        \[\leadsto \mathsf{+.f64}\left(-2, \mathsf{/.f64}\left(-4, \left(\color{blue}{a} \cdot x\right)\right)\right) \]
      13. *-lowering-*.f6418.8%

        \[\leadsto \mathsf{+.f64}\left(-2, \mathsf{/.f64}\left(-4, \mathsf{*.f64}\left(a, \color{blue}{x}\right)\right)\right) \]
    12. Simplified18.8%

      \[\leadsto \color{blue}{-2 + \frac{-4}{a \cdot x}} \]

    if -500 < (*.f64 a x)

    1. Initial program 31.0%

      \[e^{a \cdot x} - 1 \]
    2. Step-by-step derivation
      1. expm1-defineN/A

        \[\leadsto \mathsf{expm1}\left(a \cdot x\right) \]
      2. expm1-lowering-expm1.f64N/A

        \[\leadsto \mathsf{expm1.f64}\left(\left(a \cdot x\right)\right) \]
      3. *-lowering-*.f64100.0%

        \[\leadsto \mathsf{expm1.f64}\left(\mathsf{*.f64}\left(a, x\right)\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(a \cdot x\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in a around 0

      \[\leadsto \color{blue}{a \cdot x} \]
    6. Step-by-step derivation
      1. *-lowering-*.f6498.6%

        \[\leadsto \mathsf{*.f64}\left(a, \color{blue}{x}\right) \]
    7. Simplified98.6%

      \[\leadsto \color{blue}{a \cdot x} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 72.2% accurate, 10.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \cdot x \leq -2:\\ \;\;\;\;-2\\ \mathbf{else}:\\ \;\;\;\;a \cdot x\\ \end{array} \end{array} \]
(FPCore (a x) :precision binary64 (if (<= (* a x) -2.0) -2.0 (* a x)))
double code(double a, double x) {
	double tmp;
	if ((a * x) <= -2.0) {
		tmp = -2.0;
	} else {
		tmp = a * x;
	}
	return tmp;
}
real(8) function code(a, x)
    real(8), intent (in) :: a
    real(8), intent (in) :: x
    real(8) :: tmp
    if ((a * x) <= (-2.0d0)) then
        tmp = -2.0d0
    else
        tmp = a * x
    end if
    code = tmp
end function
public static double code(double a, double x) {
	double tmp;
	if ((a * x) <= -2.0) {
		tmp = -2.0;
	} else {
		tmp = a * x;
	}
	return tmp;
}
def code(a, x):
	tmp = 0
	if (a * x) <= -2.0:
		tmp = -2.0
	else:
		tmp = a * x
	return tmp
function code(a, x)
	tmp = 0.0
	if (Float64(a * x) <= -2.0)
		tmp = -2.0;
	else
		tmp = Float64(a * x);
	end
	return tmp
end
function tmp_2 = code(a, x)
	tmp = 0.0;
	if ((a * x) <= -2.0)
		tmp = -2.0;
	else
		tmp = a * x;
	end
	tmp_2 = tmp;
end
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -2.0], -2.0, N[(a * x), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -2:\\
\;\;\;\;-2\\

\mathbf{else}:\\
\;\;\;\;a \cdot x\\


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

    1. Initial program 100.0%

      \[e^{a \cdot x} - 1 \]
    2. Step-by-step derivation
      1. expm1-defineN/A

        \[\leadsto \mathsf{expm1}\left(a \cdot x\right) \]
      2. expm1-lowering-expm1.f64N/A

        \[\leadsto \mathsf{expm1.f64}\left(\left(a \cdot x\right)\right) \]
      3. *-lowering-*.f64100.0%

        \[\leadsto \mathsf{expm1.f64}\left(\mathsf{*.f64}\left(a, x\right)\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(a \cdot x\right)} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. sub-negN/A

        \[\leadsto e^{a \cdot x} + \color{blue}{\left(\mathsf{neg}\left(1\right)\right)} \]
      2. flip3-+N/A

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

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

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

        \[\leadsto \frac{{\left(e^{a \cdot x}\right)}^{3} + \left(\mathsf{neg}\left(1\right)\right)}{e^{a \cdot x} \cdot \color{blue}{e^{a \cdot x}} + \left(\left(\mathsf{neg}\left(1\right)\right) \cdot \left(\mathsf{neg}\left(1\right)\right) - e^{a \cdot x} \cdot \left(\mathsf{neg}\left(1\right)\right)\right)} \]
      6. sub-negN/A

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

        \[\leadsto \frac{{\left(e^{a \cdot x}\right)}^{3} - {1}^{3}}{e^{a \cdot x} \cdot \color{blue}{e^{a \cdot x}} + \left(\left(\mathsf{neg}\left(1\right)\right) \cdot \left(\mathsf{neg}\left(1\right)\right) - e^{a \cdot x} \cdot \left(\mathsf{neg}\left(1\right)\right)\right)} \]
      8. clear-numN/A

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

        \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left(\frac{e^{a \cdot x} \cdot e^{a \cdot x} + \left(\left(\mathsf{neg}\left(1\right)\right) \cdot \left(\mathsf{neg}\left(1\right)\right) - e^{a \cdot x} \cdot \left(\mathsf{neg}\left(1\right)\right)\right)}{{\left(e^{a \cdot x}\right)}^{3} - {1}^{3}}\right)}\right) \]
      10. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\left(e^{a \cdot x} \cdot e^{a \cdot x} + \left(\left(\mathsf{neg}\left(1\right)\right) \cdot \left(\mathsf{neg}\left(1\right)\right) - e^{a \cdot x} \cdot \left(\mathsf{neg}\left(1\right)\right)\right)\right), \color{blue}{\left({\left(e^{a \cdot x}\right)}^{3} - {1}^{3}\right)}\right)\right) \]
    6. Applied egg-rr100.0%

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

      \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left(\frac{x \cdot \left(\frac{1}{3} \cdot \frac{2 \cdot a - -1 \cdot a}{a} - \frac{3}{2}\right) + \frac{1}{a}}{x}\right)}\right) \]
    8. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\left(x \cdot \left(\frac{1}{3} \cdot \frac{2 \cdot a - -1 \cdot a}{a} - \frac{3}{2}\right) + \frac{1}{a}\right), \color{blue}{x}\right)\right) \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\left(x \cdot \left(\frac{1}{3} \cdot \frac{2 \cdot a - -1 \cdot a}{a} - \frac{3}{2}\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \left(\frac{1}{3} \cdot \frac{2 \cdot a - -1 \cdot a}{a} - \frac{3}{2}\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
      4. sub-negN/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \left(\frac{1}{3} \cdot \frac{2 \cdot a - -1 \cdot a}{a} + \left(\mathsf{neg}\left(\frac{3}{2}\right)\right)\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
      5. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\left(\frac{1}{3} \cdot \frac{2 \cdot a - -1 \cdot a}{a}\right), \left(\mathsf{neg}\left(\frac{3}{2}\right)\right)\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
      6. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{3}, \left(\frac{2 \cdot a - -1 \cdot a}{a}\right)\right), \left(\mathsf{neg}\left(\frac{3}{2}\right)\right)\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{3}, \mathsf{/.f64}\left(\left(2 \cdot a - -1 \cdot a\right), a\right)\right), \left(\mathsf{neg}\left(\frac{3}{2}\right)\right)\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
      8. distribute-rgt-out--N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{3}, \mathsf{/.f64}\left(\left(a \cdot \left(2 - -1\right)\right), a\right)\right), \left(\mathsf{neg}\left(\frac{3}{2}\right)\right)\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
      9. metadata-evalN/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{3}, \mathsf{/.f64}\left(\left(a \cdot 3\right), a\right)\right), \left(\mathsf{neg}\left(\frac{3}{2}\right)\right)\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
      10. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{3}, \mathsf{/.f64}\left(\mathsf{*.f64}\left(a, 3\right), a\right)\right), \left(\mathsf{neg}\left(\frac{3}{2}\right)\right)\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
      11. metadata-evalN/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{3}, \mathsf{/.f64}\left(\mathsf{*.f64}\left(a, 3\right), a\right)\right), \frac{-3}{2}\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
      12. /-lowering-/.f6418.8%

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{3}, \mathsf{/.f64}\left(\mathsf{*.f64}\left(a, 3\right), a\right)\right), \frac{-3}{2}\right)\right), \mathsf{/.f64}\left(1, a\right)\right), x\right)\right) \]
    9. Simplified18.8%

      \[\leadsto \frac{1}{\color{blue}{\frac{x \cdot \left(0.3333333333333333 \cdot \frac{a \cdot 3}{a} + -1.5\right) + \frac{1}{a}}{x}}} \]
    10. Taylor expanded in x around inf

      \[\leadsto \color{blue}{-2} \]
    11. Step-by-step derivation
      1. Simplified18.8%

        \[\leadsto \color{blue}{-2} \]

      if -2 < (*.f64 a x)

      1. Initial program 31.0%

        \[e^{a \cdot x} - 1 \]
      2. Step-by-step derivation
        1. expm1-defineN/A

          \[\leadsto \mathsf{expm1}\left(a \cdot x\right) \]
        2. expm1-lowering-expm1.f64N/A

          \[\leadsto \mathsf{expm1.f64}\left(\left(a \cdot x\right)\right) \]
        3. *-lowering-*.f64100.0%

          \[\leadsto \mathsf{expm1.f64}\left(\mathsf{*.f64}\left(a, x\right)\right) \]
      3. Simplified100.0%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(a \cdot x\right)} \]
      4. Add Preprocessing
      5. Taylor expanded in a around 0

        \[\leadsto \color{blue}{a \cdot x} \]
      6. Step-by-step derivation
        1. *-lowering-*.f6498.6%

          \[\leadsto \mathsf{*.f64}\left(a, \color{blue}{x}\right) \]
      7. Simplified98.6%

        \[\leadsto \color{blue}{a \cdot x} \]
    12. Recombined 2 regimes into one program.
    13. Add Preprocessing

    Alternative 5: 72.0% accurate, 11.7× speedup?

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

      \[e^{a \cdot x} - 1 \]
    2. Step-by-step derivation
      1. expm1-defineN/A

        \[\leadsto \mathsf{expm1}\left(a \cdot x\right) \]
      2. expm1-lowering-expm1.f64N/A

        \[\leadsto \mathsf{expm1.f64}\left(\left(a \cdot x\right)\right) \]
      3. *-lowering-*.f64100.0%

        \[\leadsto \mathsf{expm1.f64}\left(\mathsf{*.f64}\left(a, x\right)\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(a \cdot x\right)} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. sub-negN/A

        \[\leadsto e^{a \cdot x} + \color{blue}{\left(\mathsf{neg}\left(1\right)\right)} \]
      2. flip3-+N/A

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

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

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

        \[\leadsto \frac{{\left(e^{a \cdot x}\right)}^{3} + \left(\mathsf{neg}\left(1\right)\right)}{e^{a \cdot x} \cdot \color{blue}{e^{a \cdot x}} + \left(\left(\mathsf{neg}\left(1\right)\right) \cdot \left(\mathsf{neg}\left(1\right)\right) - e^{a \cdot x} \cdot \left(\mathsf{neg}\left(1\right)\right)\right)} \]
      6. sub-negN/A

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

        \[\leadsto \frac{{\left(e^{a \cdot x}\right)}^{3} - {1}^{3}}{e^{a \cdot x} \cdot \color{blue}{e^{a \cdot x}} + \left(\left(\mathsf{neg}\left(1\right)\right) \cdot \left(\mathsf{neg}\left(1\right)\right) - e^{a \cdot x} \cdot \left(\mathsf{neg}\left(1\right)\right)\right)} \]
      8. clear-numN/A

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

        \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left(\frac{e^{a \cdot x} \cdot e^{a \cdot x} + \left(\left(\mathsf{neg}\left(1\right)\right) \cdot \left(\mathsf{neg}\left(1\right)\right) - e^{a \cdot x} \cdot \left(\mathsf{neg}\left(1\right)\right)\right)}{{\left(e^{a \cdot x}\right)}^{3} - {1}^{3}}\right)}\right) \]
      10. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\left(e^{a \cdot x} \cdot e^{a \cdot x} + \left(\left(\mathsf{neg}\left(1\right)\right) \cdot \left(\mathsf{neg}\left(1\right)\right) - e^{a \cdot x} \cdot \left(\mathsf{neg}\left(1\right)\right)\right)\right), \color{blue}{\left({\left(e^{a \cdot x}\right)}^{3} - {1}^{3}\right)}\right)\right) \]
    6. Applied egg-rr99.1%

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

      \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left(\frac{x \cdot \left(\frac{1}{3} \cdot \frac{2 \cdot a - -1 \cdot a}{a} - \frac{3}{2}\right) + \frac{1}{a}}{x}\right)}\right) \]
    8. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\left(x \cdot \left(\frac{1}{3} \cdot \frac{2 \cdot a - -1 \cdot a}{a} - \frac{3}{2}\right) + \frac{1}{a}\right), \color{blue}{x}\right)\right) \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\left(x \cdot \left(\frac{1}{3} \cdot \frac{2 \cdot a - -1 \cdot a}{a} - \frac{3}{2}\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \left(\frac{1}{3} \cdot \frac{2 \cdot a - -1 \cdot a}{a} - \frac{3}{2}\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
      4. sub-negN/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \left(\frac{1}{3} \cdot \frac{2 \cdot a - -1 \cdot a}{a} + \left(\mathsf{neg}\left(\frac{3}{2}\right)\right)\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
      5. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\left(\frac{1}{3} \cdot \frac{2 \cdot a - -1 \cdot a}{a}\right), \left(\mathsf{neg}\left(\frac{3}{2}\right)\right)\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
      6. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{3}, \left(\frac{2 \cdot a - -1 \cdot a}{a}\right)\right), \left(\mathsf{neg}\left(\frac{3}{2}\right)\right)\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{3}, \mathsf{/.f64}\left(\left(2 \cdot a - -1 \cdot a\right), a\right)\right), \left(\mathsf{neg}\left(\frac{3}{2}\right)\right)\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
      8. distribute-rgt-out--N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{3}, \mathsf{/.f64}\left(\left(a \cdot \left(2 - -1\right)\right), a\right)\right), \left(\mathsf{neg}\left(\frac{3}{2}\right)\right)\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
      9. metadata-evalN/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{3}, \mathsf{/.f64}\left(\left(a \cdot 3\right), a\right)\right), \left(\mathsf{neg}\left(\frac{3}{2}\right)\right)\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
      10. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{3}, \mathsf{/.f64}\left(\mathsf{*.f64}\left(a, 3\right), a\right)\right), \left(\mathsf{neg}\left(\frac{3}{2}\right)\right)\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
      11. metadata-evalN/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{3}, \mathsf{/.f64}\left(\mathsf{*.f64}\left(a, 3\right), a\right)\right), \frac{-3}{2}\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
      12. /-lowering-/.f6471.2%

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{3}, \mathsf{/.f64}\left(\mathsf{*.f64}\left(a, 3\right), a\right)\right), \frac{-3}{2}\right)\right), \mathsf{/.f64}\left(1, a\right)\right), x\right)\right) \]
    9. Simplified71.2%

      \[\leadsto \frac{1}{\color{blue}{\frac{x \cdot \left(0.3333333333333333 \cdot \frac{a \cdot 3}{a} + -1.5\right) + \frac{1}{a}}{x}}} \]
    10. Taylor expanded in x around inf

      \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left(\frac{1}{a \cdot x} - \frac{1}{2}\right)}\right) \]
    11. Step-by-step derivation
      1. sub-negN/A

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

        \[\leadsto \mathsf{/.f64}\left(1, \left(\frac{1}{a \cdot x} + \frac{-1}{2}\right)\right) \]
      3. +-lowering-+.f64N/A

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

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{+.f64}\left(\mathsf{/.f64}\left(1, \left(a \cdot x\right)\right), \frac{-1}{2}\right)\right) \]
      5. *-lowering-*.f6471.3%

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{+.f64}\left(\mathsf{/.f64}\left(1, \mathsf{*.f64}\left(a, x\right)\right), \frac{-1}{2}\right)\right) \]
    12. Simplified71.3%

      \[\leadsto \frac{1}{\color{blue}{\frac{1}{a \cdot x} + -0.5}} \]
    13. Add Preprocessing

    Alternative 6: 8.6% accurate, 105.0× speedup?

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

      \[e^{a \cdot x} - 1 \]
    2. Step-by-step derivation
      1. expm1-defineN/A

        \[\leadsto \mathsf{expm1}\left(a \cdot x\right) \]
      2. expm1-lowering-expm1.f64N/A

        \[\leadsto \mathsf{expm1.f64}\left(\left(a \cdot x\right)\right) \]
      3. *-lowering-*.f64100.0%

        \[\leadsto \mathsf{expm1.f64}\left(\mathsf{*.f64}\left(a, x\right)\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(a \cdot x\right)} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. sub-negN/A

        \[\leadsto e^{a \cdot x} + \color{blue}{\left(\mathsf{neg}\left(1\right)\right)} \]
      2. flip3-+N/A

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

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

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

        \[\leadsto \frac{{\left(e^{a \cdot x}\right)}^{3} + \left(\mathsf{neg}\left(1\right)\right)}{e^{a \cdot x} \cdot \color{blue}{e^{a \cdot x}} + \left(\left(\mathsf{neg}\left(1\right)\right) \cdot \left(\mathsf{neg}\left(1\right)\right) - e^{a \cdot x} \cdot \left(\mathsf{neg}\left(1\right)\right)\right)} \]
      6. sub-negN/A

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

        \[\leadsto \frac{{\left(e^{a \cdot x}\right)}^{3} - {1}^{3}}{e^{a \cdot x} \cdot \color{blue}{e^{a \cdot x}} + \left(\left(\mathsf{neg}\left(1\right)\right) \cdot \left(\mathsf{neg}\left(1\right)\right) - e^{a \cdot x} \cdot \left(\mathsf{neg}\left(1\right)\right)\right)} \]
      8. clear-numN/A

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

        \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left(\frac{e^{a \cdot x} \cdot e^{a \cdot x} + \left(\left(\mathsf{neg}\left(1\right)\right) \cdot \left(\mathsf{neg}\left(1\right)\right) - e^{a \cdot x} \cdot \left(\mathsf{neg}\left(1\right)\right)\right)}{{\left(e^{a \cdot x}\right)}^{3} - {1}^{3}}\right)}\right) \]
      10. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\left(e^{a \cdot x} \cdot e^{a \cdot x} + \left(\left(\mathsf{neg}\left(1\right)\right) \cdot \left(\mathsf{neg}\left(1\right)\right) - e^{a \cdot x} \cdot \left(\mathsf{neg}\left(1\right)\right)\right)\right), \color{blue}{\left({\left(e^{a \cdot x}\right)}^{3} - {1}^{3}\right)}\right)\right) \]
    6. Applied egg-rr99.1%

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

      \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left(\frac{x \cdot \left(\frac{1}{3} \cdot \frac{2 \cdot a - -1 \cdot a}{a} - \frac{3}{2}\right) + \frac{1}{a}}{x}\right)}\right) \]
    8. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\left(x \cdot \left(\frac{1}{3} \cdot \frac{2 \cdot a - -1 \cdot a}{a} - \frac{3}{2}\right) + \frac{1}{a}\right), \color{blue}{x}\right)\right) \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\left(x \cdot \left(\frac{1}{3} \cdot \frac{2 \cdot a - -1 \cdot a}{a} - \frac{3}{2}\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \left(\frac{1}{3} \cdot \frac{2 \cdot a - -1 \cdot a}{a} - \frac{3}{2}\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
      4. sub-negN/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \left(\frac{1}{3} \cdot \frac{2 \cdot a - -1 \cdot a}{a} + \left(\mathsf{neg}\left(\frac{3}{2}\right)\right)\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
      5. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\left(\frac{1}{3} \cdot \frac{2 \cdot a - -1 \cdot a}{a}\right), \left(\mathsf{neg}\left(\frac{3}{2}\right)\right)\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
      6. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{3}, \left(\frac{2 \cdot a - -1 \cdot a}{a}\right)\right), \left(\mathsf{neg}\left(\frac{3}{2}\right)\right)\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{3}, \mathsf{/.f64}\left(\left(2 \cdot a - -1 \cdot a\right), a\right)\right), \left(\mathsf{neg}\left(\frac{3}{2}\right)\right)\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
      8. distribute-rgt-out--N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{3}, \mathsf{/.f64}\left(\left(a \cdot \left(2 - -1\right)\right), a\right)\right), \left(\mathsf{neg}\left(\frac{3}{2}\right)\right)\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
      9. metadata-evalN/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{3}, \mathsf{/.f64}\left(\left(a \cdot 3\right), a\right)\right), \left(\mathsf{neg}\left(\frac{3}{2}\right)\right)\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
      10. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{3}, \mathsf{/.f64}\left(\mathsf{*.f64}\left(a, 3\right), a\right)\right), \left(\mathsf{neg}\left(\frac{3}{2}\right)\right)\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
      11. metadata-evalN/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{3}, \mathsf{/.f64}\left(\mathsf{*.f64}\left(a, 3\right), a\right)\right), \frac{-3}{2}\right)\right), \left(\frac{1}{a}\right)\right), x\right)\right) \]
      12. /-lowering-/.f6471.2%

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{3}, \mathsf{/.f64}\left(\mathsf{*.f64}\left(a, 3\right), a\right)\right), \frac{-3}{2}\right)\right), \mathsf{/.f64}\left(1, a\right)\right), x\right)\right) \]
    9. Simplified71.2%

      \[\leadsto \frac{1}{\color{blue}{\frac{x \cdot \left(0.3333333333333333 \cdot \frac{a \cdot 3}{a} + -1.5\right) + \frac{1}{a}}{x}}} \]
    10. Taylor expanded in x around inf

      \[\leadsto \color{blue}{-2} \]
    11. Step-by-step derivation
      1. Simplified8.7%

        \[\leadsto \color{blue}{-2} \]
      2. 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 2024161 
      (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))