?

Average Error: 29.3 → 0.8
Time: 4.1s
Precision: binary64
Cost: 6980

?

\[e^{a \cdot x} - 1 \]
\[\begin{array}{l} \mathbf{if}\;a \cdot x \leq -1 \cdot 10^{-5}:\\ \;\;\;\;e^{a \cdot x} - 1\\ \mathbf{else}:\\ \;\;\;\;a \cdot x\\ \end{array} \]
(FPCore (a x) :precision binary64 (- (exp (* a x)) 1.0))
(FPCore (a x)
 :precision binary64
 (if (<= (* a x) -1e-5) (- (exp (* a x)) 1.0) (* a x)))
double code(double a, double x) {
	return exp((a * x)) - 1.0;
}
double code(double a, double x) {
	double tmp;
	if ((a * x) <= -1e-5) {
		tmp = exp((a * x)) - 1.0;
	} else {
		tmp = a * x;
	}
	return tmp;
}
real(8) function code(a, x)
    real(8), intent (in) :: a
    real(8), intent (in) :: x
    code = exp((a * x)) - 1.0d0
end function
real(8) function code(a, x)
    real(8), intent (in) :: a
    real(8), intent (in) :: x
    real(8) :: tmp
    if ((a * x) <= (-1d-5)) then
        tmp = exp((a * x)) - 1.0d0
    else
        tmp = a * x
    end if
    code = tmp
end function
public static double code(double a, double x) {
	return Math.exp((a * x)) - 1.0;
}
public static double code(double a, double x) {
	double tmp;
	if ((a * x) <= -1e-5) {
		tmp = Math.exp((a * x)) - 1.0;
	} else {
		tmp = a * x;
	}
	return tmp;
}
def code(a, x):
	return math.exp((a * x)) - 1.0
def code(a, x):
	tmp = 0
	if (a * x) <= -1e-5:
		tmp = math.exp((a * x)) - 1.0
	else:
		tmp = a * x
	return tmp
function code(a, x)
	return Float64(exp(Float64(a * x)) - 1.0)
end
function code(a, x)
	tmp = 0.0
	if (Float64(a * x) <= -1e-5)
		tmp = Float64(exp(Float64(a * x)) - 1.0);
	else
		tmp = Float64(a * x);
	end
	return tmp
end
function tmp = code(a, x)
	tmp = exp((a * x)) - 1.0;
end
function tmp_2 = code(a, x)
	tmp = 0.0;
	if ((a * x) <= -1e-5)
		tmp = exp((a * x)) - 1.0;
	else
		tmp = a * x;
	end
	tmp_2 = tmp;
end
code[a_, x_] := N[(N[Exp[N[(a * x), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision]
code[a_, x_] := If[LessEqual[N[(a * x), $MachinePrecision], -1e-5], N[(N[Exp[N[(a * x), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision], N[(a * x), $MachinePrecision]]
e^{a \cdot x} - 1
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -1 \cdot 10^{-5}:\\
\;\;\;\;e^{a \cdot x} - 1\\

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original29.3
Target0.1
Herbie0.8
\[\begin{array}{l} \mathbf{if}\;\left|a \cdot x\right| < 0.1:\\ \;\;\;\;\left(a \cdot x\right) \cdot \left(1 + \left(\frac{a \cdot x}{2} + \frac{{\left(a \cdot x\right)}^{2}}{6}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;e^{a \cdot x} - 1\\ \end{array} \]

Derivation?

  1. Split input into 2 regimes
  2. if (*.f64 a x) < -1.00000000000000008e-5

    1. Initial program 0.1

      \[e^{a \cdot x} - 1 \]

    if -1.00000000000000008e-5 < (*.f64 a x)

    1. Initial program 44.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot x \leq -1 \cdot 10^{-5}:\\ \;\;\;\;e^{a \cdot x} - 1\\ \mathbf{else}:\\ \;\;\;\;a \cdot x\\ \end{array} \]

Alternatives

Alternative 1
Error21.6
Cost192
\[a \cdot x \]

Error

Reproduce?

herbie shell --seed 2023090 
(FPCore (a x)
  :name "expax (section 3.5)"
  :precision binary64

  :herbie-target
  (if (< (fabs (* a x)) 0.1) (* (* a x) (+ 1.0 (+ (/ (* a x) 2.0) (/ (pow (* a x) 2.0) 6.0)))) (- (exp (* a x)) 1.0))

  (- (exp (* a x)) 1.0))