| Alternative 1 | |
|---|---|
| Error | 29.1 |
| Cost | 320 |
\[\frac{1}{y \cdot x}
\]
(FPCore (x y z) :precision binary64 (/ (/ 1.0 x) (* y (+ 1.0 (* z z)))))
(FPCore (x y z) :precision binary64 (if (<= (* y (+ 1.0 (* z z))) 5e+304) (/ (/ 1.0 x) (+ y (* y (* z z)))) (/ 1.0 (* z (* y (* z x))))))
double code(double x, double y, double z) {
return (1.0 / x) / (y * (1.0 + (z * z)));
}
double code(double x, double y, double z) {
double tmp;
if ((y * (1.0 + (z * z))) <= 5e+304) {
tmp = (1.0 / x) / (y + (y * (z * z)));
} else {
tmp = 1.0 / (z * (y * (z * x)));
}
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 = (1.0d0 / x) / (y * (1.0d0 + (z * 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 * (1.0d0 + (z * z))) <= 5d+304) then
tmp = (1.0d0 / x) / (y + (y * (z * z)))
else
tmp = 1.0d0 / (z * (y * (z * x)))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
return (1.0 / x) / (y * (1.0 + (z * z)));
}
public static double code(double x, double y, double z) {
double tmp;
if ((y * (1.0 + (z * z))) <= 5e+304) {
tmp = (1.0 / x) / (y + (y * (z * z)));
} else {
tmp = 1.0 / (z * (y * (z * x)));
}
return tmp;
}
def code(x, y, z): return (1.0 / x) / (y * (1.0 + (z * z)))
def code(x, y, z): tmp = 0 if (y * (1.0 + (z * z))) <= 5e+304: tmp = (1.0 / x) / (y + (y * (z * z))) else: tmp = 1.0 / (z * (y * (z * x))) return tmp
function code(x, y, z) return Float64(Float64(1.0 / x) / Float64(y * Float64(1.0 + Float64(z * z)))) end
function code(x, y, z) tmp = 0.0 if (Float64(y * Float64(1.0 + Float64(z * z))) <= 5e+304) tmp = Float64(Float64(1.0 / x) / Float64(y + Float64(y * Float64(z * z)))); else tmp = Float64(1.0 / Float64(z * Float64(y * Float64(z * x)))); end return tmp end
function tmp = code(x, y, z) tmp = (1.0 / x) / (y * (1.0 + (z * z))); end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y * (1.0 + (z * z))) <= 5e+304) tmp = (1.0 / x) / (y + (y * (z * z))); else tmp = 1.0 / (z * (y * (z * x))); end tmp_2 = tmp; end
code[x_, y_, z_] := N[(N[(1.0 / x), $MachinePrecision] / N[(y * N[(1.0 + N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := If[LessEqual[N[(y * N[(1.0 + N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e+304], N[(N[(1.0 / x), $MachinePrecision] / N[(y + N[(y * N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(z * N[(y * N[(z * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}
\begin{array}{l}
\mathbf{if}\;y \cdot \left(1 + z \cdot z\right) \leq 5 \cdot 10^{+304}:\\
\;\;\;\;\frac{\frac{1}{x}}{y + y \cdot \left(z \cdot z\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{z \cdot \left(y \cdot \left(z \cdot x\right)\right)}\\
\end{array}
Results
| Original | 6.2 |
|---|---|
| Target | 4.8 |
| Herbie | 1.9 |
if (*.f64 y (+.f64 1 (*.f64 z z))) < 4.9999999999999997e304Initial program 1.8
Applied egg-rr1.8
if 4.9999999999999997e304 < (*.f64 y (+.f64 1 (*.f64 z z))) Initial program 18.2
Simplified18.2
Applied egg-rr18.2
Taylor expanded in z around inf 13.8
Simplified2.1
Final simplification1.9
| Alternative 1 | |
|---|---|
| Error | 29.1 |
| Cost | 320 |
| Alternative 2 | |
|---|---|
| Error | 29.1 |
| Cost | 320 |

herbie shell --seed 2022289
(FPCore (x y z)
:name "Statistics.Distribution.CauchyLorentz:$cdensity from math-functions-0.1.5.2"
:precision binary64
:herbie-target
(if (< (* y (+ 1.0 (* z z))) (- INFINITY)) (/ (/ 1.0 y) (* (+ 1.0 (* z z)) x)) (if (< (* y (+ 1.0 (* z z))) 8.680743250567252e+305) (/ (/ 1.0 x) (* (+ 1.0 (* z z)) y)) (/ (/ 1.0 y) (* (+ 1.0 (* z z)) x))))
(/ (/ 1.0 x) (* y (+ 1.0 (* z z)))))