| Alternative 1 | |
|---|---|
| Error | 0.5 |
| Cost | 26688 |
\[\left(0.08333333333333333 \cdot {x}^{4} + 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8}\right) + \left({x}^{2} + 0.002777777777777778 \cdot {x}^{6}\right)
\]
(FPCore (x) :precision binary64 (+ (- (exp x) 2.0) (exp (- x))))
(FPCore (x)
:precision binary64
(let* ((t_0 (exp (- x))))
(if (<= (+ (- (exp x) 2.0) t_0) 1e-10)
(pow x 2.0)
(+ (exp x) (- t_0 2.0)))))double code(double x) {
return (exp(x) - 2.0) + exp(-x);
}
double code(double x) {
double t_0 = exp(-x);
double tmp;
if (((exp(x) - 2.0) + t_0) <= 1e-10) {
tmp = pow(x, 2.0);
} else {
tmp = exp(x) + (t_0 - 2.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (exp(x) - 2.0d0) + exp(-x)
end function
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = exp(-x)
if (((exp(x) - 2.0d0) + t_0) <= 1d-10) then
tmp = x ** 2.0d0
else
tmp = exp(x) + (t_0 - 2.0d0)
end if
code = tmp
end function
public static double code(double x) {
return (Math.exp(x) - 2.0) + Math.exp(-x);
}
public static double code(double x) {
double t_0 = Math.exp(-x);
double tmp;
if (((Math.exp(x) - 2.0) + t_0) <= 1e-10) {
tmp = Math.pow(x, 2.0);
} else {
tmp = Math.exp(x) + (t_0 - 2.0);
}
return tmp;
}
def code(x): return (math.exp(x) - 2.0) + math.exp(-x)
def code(x): t_0 = math.exp(-x) tmp = 0 if ((math.exp(x) - 2.0) + t_0) <= 1e-10: tmp = math.pow(x, 2.0) else: tmp = math.exp(x) + (t_0 - 2.0) return tmp
function code(x) return Float64(Float64(exp(x) - 2.0) + exp(Float64(-x))) end
function code(x) t_0 = exp(Float64(-x)) tmp = 0.0 if (Float64(Float64(exp(x) - 2.0) + t_0) <= 1e-10) tmp = x ^ 2.0; else tmp = Float64(exp(x) + Float64(t_0 - 2.0)); end return tmp end
function tmp = code(x) tmp = (exp(x) - 2.0) + exp(-x); end
function tmp_2 = code(x) t_0 = exp(-x); tmp = 0.0; if (((exp(x) - 2.0) + t_0) <= 1e-10) tmp = x ^ 2.0; else tmp = exp(x) + (t_0 - 2.0); end tmp_2 = tmp; end
code[x_] := N[(N[(N[Exp[x], $MachinePrecision] - 2.0), $MachinePrecision] + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]
code[x_] := Block[{t$95$0 = N[Exp[(-x)], $MachinePrecision]}, If[LessEqual[N[(N[(N[Exp[x], $MachinePrecision] - 2.0), $MachinePrecision] + t$95$0), $MachinePrecision], 1e-10], N[Power[x, 2.0], $MachinePrecision], N[(N[Exp[x], $MachinePrecision] + N[(t$95$0 - 2.0), $MachinePrecision]), $MachinePrecision]]]
\left(e^{x} - 2\right) + e^{-x}
\begin{array}{l}
t_0 := e^{-x}\\
\mathbf{if}\;\left(e^{x} - 2\right) + t_0 \leq 10^{-10}:\\
\;\;\;\;{x}^{2}\\
\mathbf{else}:\\
\;\;\;\;e^{x} + \left(t_0 - 2\right)\\
\end{array}
Results
| Original | 29.9 |
|---|---|
| Target | 0.0 |
| Herbie | 0.3 |
if (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x))) < 1.00000000000000004e-10Initial program 30.4
Simplified30.4
[Start]30.4 | \[ \left(e^{x} - 2\right) + e^{-x}
\] |
|---|---|
rational_best_oopsla_all_46_json_45_simplify-35 [=>]30.4 | \[ \color{blue}{e^{-x} + \left(e^{x} - 2\right)}
\] |
rational_best_oopsla_all_46_json_45_simplify-108 [=>]30.5 | \[ \color{blue}{\left(e^{x} + e^{-x}\right) - 2}
\] |
rational_best_oopsla_all_46_json_45_simplify-35 [=>]30.5 | \[ \color{blue}{\left(e^{-x} + e^{x}\right)} - 2
\] |
rational_best_oopsla_all_46_json_45_simplify-107 [=>]30.4 | \[ \color{blue}{e^{x} + \left(e^{-x} - 2\right)}
\] |
Taylor expanded in x around 0 0.1
if 1.00000000000000004e-10 < (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x))) Initial program 10.5
Simplified10.6
[Start]10.5 | \[ \left(e^{x} - 2\right) + e^{-x}
\] |
|---|---|
rational_best_oopsla_all_46_json_45_simplify-35 [=>]10.5 | \[ \color{blue}{e^{-x} + \left(e^{x} - 2\right)}
\] |
rational_best_oopsla_all_46_json_45_simplify-108 [=>]11.1 | \[ \color{blue}{\left(e^{x} + e^{-x}\right) - 2}
\] |
rational_best_oopsla_all_46_json_45_simplify-35 [=>]11.1 | \[ \color{blue}{\left(e^{-x} + e^{x}\right)} - 2
\] |
rational_best_oopsla_all_46_json_45_simplify-107 [=>]10.6 | \[ \color{blue}{e^{x} + \left(e^{-x} - 2\right)}
\] |
Final simplification0.3
| Alternative 1 | |
|---|---|
| Error | 0.5 |
| Cost | 26688 |
| Alternative 2 | |
|---|---|
| Error | 0.6 |
| Cost | 19968 |
| Alternative 3 | |
|---|---|
| Error | 0.7 |
| Cost | 13248 |
| Alternative 4 | |
|---|---|
| Error | 1.1 |
| Cost | 6528 |
| Alternative 5 | |
|---|---|
| Error | 60.2 |
| Cost | 128 |
herbie shell --seed 2023090
(FPCore (x)
:name "exp2 (problem 3.3.7)"
:precision binary64
:herbie-target
(* 4.0 (pow (sinh (/ x 2.0)) 2.0))
(+ (- (exp x) 2.0) (exp (- x))))