| Alternative 1 | |
|---|---|
| Error | 10.4 |
| Cost | 6980 |
\[\begin{array}{l}
\mathbf{if}\;y \leq 1.837728219707568 \cdot 10^{+127}:\\
\;\;\;\;\left(x + \log y \cdot -0.5\right) - z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - \log y\right)\\
\end{array}
\]
(FPCore (x y z) :precision binary64 (- (+ (- x (* (+ y 0.5) (log y))) y) z))
(FPCore (x y z) :precision binary64 (if (<= y 9.989230204048188e-18) (- (+ x (* (log y) -0.5)) z) (- (+ y (- x (* y (log y)))) z)))
double code(double x, double y, double z) {
return ((x - ((y + 0.5) * log(y))) + y) - z;
}
double code(double x, double y, double z) {
double tmp;
if (y <= 9.989230204048188e-18) {
tmp = (x + (log(y) * -0.5)) - z;
} else {
tmp = (y + (x - (y * log(y)))) - z;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = ((x - ((y + 0.5d0) * log(y))) + y) - z
end function
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (y <= 9.989230204048188d-18) then
tmp = (x + (log(y) * (-0.5d0))) - z
else
tmp = (y + (x - (y * log(y)))) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
return ((x - ((y + 0.5) * Math.log(y))) + y) - z;
}
public static double code(double x, double y, double z) {
double tmp;
if (y <= 9.989230204048188e-18) {
tmp = (x + (Math.log(y) * -0.5)) - z;
} else {
tmp = (y + (x - (y * Math.log(y)))) - z;
}
return tmp;
}
def code(x, y, z): return ((x - ((y + 0.5) * math.log(y))) + y) - z
def code(x, y, z): tmp = 0 if y <= 9.989230204048188e-18: tmp = (x + (math.log(y) * -0.5)) - z else: tmp = (y + (x - (y * math.log(y)))) - z return tmp
function code(x, y, z) return Float64(Float64(Float64(x - Float64(Float64(y + 0.5) * log(y))) + y) - z) end
function code(x, y, z) tmp = 0.0 if (y <= 9.989230204048188e-18) tmp = Float64(Float64(x + Float64(log(y) * -0.5)) - z); else tmp = Float64(Float64(y + Float64(x - Float64(y * log(y)))) - z); end return tmp end
function tmp = code(x, y, z) tmp = ((x - ((y + 0.5) * log(y))) + y) - z; end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 9.989230204048188e-18) tmp = (x + (log(y) * -0.5)) - z; else tmp = (y + (x - (y * log(y)))) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := N[(N[(N[(x - N[(N[(y + 0.5), $MachinePrecision] * N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + y), $MachinePrecision] - z), $MachinePrecision]
code[x_, y_, z_] := If[LessEqual[y, 9.989230204048188e-18], N[(N[(x + N[(N[Log[y], $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision], N[(N[(y + N[(x - N[(y * N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]]
\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z
\begin{array}{l}
\mathbf{if}\;y \leq 9.989230204048188 \cdot 10^{-18}:\\
\;\;\;\;\left(x + \log y \cdot -0.5\right) - z\\
\mathbf{else}:\\
\;\;\;\;\left(y + \left(x - y \cdot \log y\right)\right) - z\\
\end{array}
Results
| Original | 0.1 |
|---|---|
| Target | 0.1 |
| Herbie | 0.8 |
if y < 9.9892302040481884e-18Initial program 0.0
Taylor expanded in y around 0 0.0
if 9.9892302040481884e-18 < y Initial program 0.2
Taylor expanded in y around inf 1.5
Simplified1.5
Final simplification0.8
| Alternative 1 | |
|---|---|
| Error | 10.4 |
| Cost | 6980 |
| Alternative 2 | |
|---|---|
| Error | 6.9 |
| Cost | 6980 |
| Alternative 3 | |
|---|---|
| Error | 18.9 |
| Cost | 6852 |
| Alternative 4 | |
|---|---|
| Error | 32.3 |
| Cost | 392 |
| Alternative 5 | |
|---|---|
| Error | 25.7 |
| Cost | 192 |
| Alternative 6 | |
|---|---|
| Error | 44.4 |
| Cost | 64 |

herbie shell --seed 2022228
(FPCore (x y z)
:name "Numeric.SpecFunctions:stirlingError from math-functions-0.1.5.2"
:precision binary64
:herbie-target
(- (- (+ y x) z) (* (+ y 0.5) (log y)))
(- (+ (- x (* (+ y 0.5) (log y))) y) z))