| Alternative 1 | |
|---|---|
| Accuracy | 97.7% |
| Cost | 13632 |
(FPCore (x y z) :precision binary64 (/ (/ 1.0 x) (* y (+ 1.0 (* z z)))))
(FPCore (x y z)
:precision binary64
(if (<= z -1.6e+145)
(/ (/ 1.0 (* x z)) (* z y))
(if (<= z 2e+129)
(/ (/ (/ 1.0 x) y) (+ 1.0 (* z z)))
(* (/ (/ -1.0 z) x) (/ (/ -1.0 y) z)))))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 (z <= -1.6e+145) {
tmp = (1.0 / (x * z)) / (z * y);
} else if (z <= 2e+129) {
tmp = ((1.0 / x) / y) / (1.0 + (z * z));
} else {
tmp = ((-1.0 / z) / x) * ((-1.0 / 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 = (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 (z <= (-1.6d+145)) then
tmp = (1.0d0 / (x * z)) / (z * y)
else if (z <= 2d+129) then
tmp = ((1.0d0 / x) / y) / (1.0d0 + (z * z))
else
tmp = (((-1.0d0) / z) / x) * (((-1.0d0) / y) / z)
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 (z <= -1.6e+145) {
tmp = (1.0 / (x * z)) / (z * y);
} else if (z <= 2e+129) {
tmp = ((1.0 / x) / y) / (1.0 + (z * z));
} else {
tmp = ((-1.0 / z) / x) * ((-1.0 / y) / z);
}
return tmp;
}
def code(x, y, z): return (1.0 / x) / (y * (1.0 + (z * z)))
def code(x, y, z): tmp = 0 if z <= -1.6e+145: tmp = (1.0 / (x * z)) / (z * y) elif z <= 2e+129: tmp = ((1.0 / x) / y) / (1.0 + (z * z)) else: tmp = ((-1.0 / z) / x) * ((-1.0 / y) / z) 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 (z <= -1.6e+145) tmp = Float64(Float64(1.0 / Float64(x * z)) / Float64(z * y)); elseif (z <= 2e+129) tmp = Float64(Float64(Float64(1.0 / x) / y) / Float64(1.0 + Float64(z * z))); else tmp = Float64(Float64(Float64(-1.0 / z) / x) * Float64(Float64(-1.0 / y) / z)); 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 (z <= -1.6e+145) tmp = (1.0 / (x * z)) / (z * y); elseif (z <= 2e+129) tmp = ((1.0 / x) / y) / (1.0 + (z * z)); else tmp = ((-1.0 / z) / x) * ((-1.0 / y) / z); 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[z, -1.6e+145], N[(N[(1.0 / N[(x * z), $MachinePrecision]), $MachinePrecision] / N[(z * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2e+129], N[(N[(N[(1.0 / x), $MachinePrecision] / y), $MachinePrecision] / N[(1.0 + N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(-1.0 / z), $MachinePrecision] / x), $MachinePrecision] * N[(N[(-1.0 / y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]]]
\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}
\begin{array}{l}
\mathbf{if}\;z \leq -1.6 \cdot 10^{+145}:\\
\;\;\;\;\frac{\frac{1}{x \cdot z}}{z \cdot y}\\
\mathbf{elif}\;z \leq 2 \cdot 10^{+129}:\\
\;\;\;\;\frac{\frac{\frac{1}{x}}{y}}{1 + z \cdot z}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{-1}{z}}{x} \cdot \frac{\frac{-1}{y}}{z}\\
\end{array}
Results
| Original | 89.9% |
|---|---|
| Target | 92.0% |
| Herbie | 97.0% |
if z < -1.60000000000000004e145Initial program 72.3%
Simplified72.2%
[Start]72.3 | \[ \frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}
\] |
|---|---|
associate-/r* [<=]72.2 | \[ \color{blue}{\frac{1}{x \cdot \left(y \cdot \left(1 + z \cdot z\right)\right)}}
\] |
+-commutative [=>]72.2 | \[ \frac{1}{x \cdot \left(y \cdot \color{blue}{\left(z \cdot z + 1\right)}\right)}
\] |
fma-def [=>]72.2 | \[ \frac{1}{x \cdot \left(y \cdot \color{blue}{\mathsf{fma}\left(z, z, 1\right)}\right)}
\] |
Taylor expanded in z around inf 72.2%
Simplified88.3%
[Start]72.2 | \[ \frac{1}{x \cdot \left(y \cdot {z}^{2}\right)}
\] |
|---|---|
unpow2 [=>]72.2 | \[ \frac{1}{x \cdot \left(y \cdot \color{blue}{\left(z \cdot z\right)}\right)}
\] |
*-commutative [=>]72.2 | \[ \frac{1}{x \cdot \color{blue}{\left(\left(z \cdot z\right) \cdot y\right)}}
\] |
associate-*l* [=>]88.3 | \[ \frac{1}{x \cdot \color{blue}{\left(z \cdot \left(z \cdot y\right)\right)}}
\] |
Taylor expanded in x around 0 72.4%
Simplified97.7%
[Start]72.4 | \[ \frac{1}{y \cdot \left({z}^{2} \cdot x\right)}
\] |
|---|---|
associate-*r* [=>]72.2 | \[ \frac{1}{\color{blue}{\left(y \cdot {z}^{2}\right) \cdot x}}
\] |
*-commutative [=>]72.2 | \[ \frac{1}{\color{blue}{\left({z}^{2} \cdot y\right)} \cdot x}
\] |
unpow2 [=>]72.2 | \[ \frac{1}{\left(\color{blue}{\left(z \cdot z\right)} \cdot y\right) \cdot x}
\] |
associate-*r* [<=]88.3 | \[ \frac{1}{\color{blue}{\left(z \cdot \left(z \cdot y\right)\right)} \cdot x}
\] |
associate-/l/ [<=]88.6 | \[ \color{blue}{\frac{\frac{1}{x}}{z \cdot \left(z \cdot y\right)}}
\] |
associate-/r* [=>]97.7 | \[ \color{blue}{\frac{\frac{\frac{1}{x}}{z}}{z \cdot y}}
\] |
associate-/r* [<=]97.7 | \[ \frac{\color{blue}{\frac{1}{x \cdot z}}}{z \cdot y}
\] |
*-commutative [=>]97.7 | \[ \frac{\frac{1}{\color{blue}{z \cdot x}}}{z \cdot y}
\] |
*-commutative [=>]97.7 | \[ \frac{\frac{1}{z \cdot x}}{\color{blue}{y \cdot z}}
\] |
if -1.60000000000000004e145 < z < 2e129Initial program 97.1%
Simplified97.0%
[Start]97.1 | \[ \frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}
\] |
|---|---|
associate-/r* [=>]97.0 | \[ \color{blue}{\frac{\frac{\frac{1}{x}}{y}}{1 + z \cdot z}}
\] |
if 2e129 < z Initial program 74.0%
Simplified73.6%
[Start]74.0 | \[ \frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}
\] |
|---|---|
associate-/r* [=>]73.6 | \[ \color{blue}{\frac{\frac{\frac{1}{x}}{y}}{1 + z \cdot z}}
\] |
Applied egg-rr96.4%
[Start]73.6 | \[ \frac{\frac{\frac{1}{x}}{y}}{1 + z \cdot z}
\] |
|---|---|
div-inv [=>]73.6 | \[ \frac{\color{blue}{\frac{1}{x} \cdot \frac{1}{y}}}{1 + z \cdot z}
\] |
add-sqr-sqrt [=>]73.6 | \[ \frac{\frac{1}{x} \cdot \frac{1}{y}}{\color{blue}{\sqrt{1 + z \cdot z} \cdot \sqrt{1 + z \cdot z}}}
\] |
times-frac [=>]74.2 | \[ \color{blue}{\frac{\frac{1}{x}}{\sqrt{1 + z \cdot z}} \cdot \frac{\frac{1}{y}}{\sqrt{1 + z \cdot z}}}
\] |
hypot-1-def [=>]74.2 | \[ \frac{\frac{1}{x}}{\color{blue}{\mathsf{hypot}\left(1, z\right)}} \cdot \frac{\frac{1}{y}}{\sqrt{1 + z \cdot z}}
\] |
hypot-1-def [=>]96.4 | \[ \frac{\frac{1}{x}}{\mathsf{hypot}\left(1, z\right)} \cdot \frac{\frac{1}{y}}{\color{blue}{\mathsf{hypot}\left(1, z\right)}}
\] |
Taylor expanded in z around -inf 67.4%
Simplified67.4%
[Start]67.4 | \[ \frac{-1}{z \cdot x} \cdot \frac{\frac{1}{y}}{\mathsf{hypot}\left(1, z\right)}
\] |
|---|---|
associate-/r* [=>]67.4 | \[ \color{blue}{\frac{\frac{-1}{z}}{x}} \cdot \frac{\frac{1}{y}}{\mathsf{hypot}\left(1, z\right)}
\] |
Taylor expanded in z around -inf 96.1%
Simplified96.4%
[Start]96.1 | \[ \frac{\frac{-1}{z}}{x} \cdot \frac{-1}{y \cdot z}
\] |
|---|---|
associate-/r* [=>]96.4 | \[ \frac{\frac{-1}{z}}{x} \cdot \color{blue}{\frac{\frac{-1}{y}}{z}}
\] |
Final simplification97.0%
| Alternative 1 | |
|---|---|
| Accuracy | 97.7% |
| Cost | 13632 |
| Alternative 2 | |
|---|---|
| Accuracy | 96.5% |
| Cost | 968 |
| Alternative 3 | |
|---|---|
| Accuracy | 97.5% |
| Cost | 968 |
| Alternative 4 | |
|---|---|
| Accuracy | 96.2% |
| Cost | 841 |
| Alternative 5 | |
|---|---|
| Accuracy | 96.1% |
| Cost | 840 |
| Alternative 6 | |
|---|---|
| Accuracy | 96.2% |
| Cost | 840 |
| Alternative 7 | |
|---|---|
| Accuracy | 96.3% |
| Cost | 840 |
| Alternative 8 | |
|---|---|
| Accuracy | 93.5% |
| Cost | 836 |
| Alternative 9 | |
|---|---|
| Accuracy | 67.4% |
| Cost | 713 |
| Alternative 10 | |
|---|---|
| Accuracy | 55.4% |
| Cost | 320 |
herbie shell --seed 2023151
(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)))))