| Alternative 1 | |
|---|---|
| Error | 21.6 |
| Cost | 192 |
\[a \cdot x
\]
(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}
Results
| Original | 29.3 |
|---|---|
| Target | 0.1 |
| Herbie | 0.8 |
if (*.f64 a x) < -1.00000000000000008e-5Initial program 0.1
if -1.00000000000000008e-5 < (*.f64 a x) Initial program 44.5
Taylor expanded in a around 0 1.2
Final simplification0.8
| Alternative 1 | |
|---|---|
| Error | 21.6 |
| Cost | 192 |
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))