| Alternative 1 | |
|---|---|
| Accuracy | 97.9% |
| Cost | 13764 |

(FPCore (x y z) :precision binary64 (/ (/ 1.0 x) (* y (+ 1.0 (* z z)))))
(FPCore (x y z) :precision binary64 (if (<= y 2e-121) (/ (/ 1.0 (+ y (* z (* y z)))) x) (* (/ 1.0 (hypot 1.0 z)) (/ (/ (/ 1.0 x) y) (hypot 1.0 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 (y <= 2e-121) {
tmp = (1.0 / (y + (z * (y * z)))) / x;
} else {
tmp = (1.0 / hypot(1.0, z)) * (((1.0 / x) / y) / hypot(1.0, z));
}
return tmp;
}
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 <= 2e-121) {
tmp = (1.0 / (y + (z * (y * z)))) / x;
} else {
tmp = (1.0 / Math.hypot(1.0, z)) * (((1.0 / x) / y) / Math.hypot(1.0, 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 y <= 2e-121: tmp = (1.0 / (y + (z * (y * z)))) / x else: tmp = (1.0 / math.hypot(1.0, z)) * (((1.0 / x) / y) / math.hypot(1.0, 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 (y <= 2e-121) tmp = Float64(Float64(1.0 / Float64(y + Float64(z * Float64(y * z)))) / x); else tmp = Float64(Float64(1.0 / hypot(1.0, z)) * Float64(Float64(Float64(1.0 / x) / y) / hypot(1.0, 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 (y <= 2e-121) tmp = (1.0 / (y + (z * (y * z)))) / x; else tmp = (1.0 / hypot(1.0, z)) * (((1.0 / x) / y) / hypot(1.0, 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[y, 2e-121], N[(N[(1.0 / N[(y + N[(z * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], N[(N[(1.0 / N[Sqrt[1.0 ^ 2 + z ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(N[(1.0 / x), $MachinePrecision] / y), $MachinePrecision] / N[Sqrt[1.0 ^ 2 + z ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}
\begin{array}{l}
\mathbf{if}\;y \leq 2 \cdot 10^{-121}:\\
\;\;\;\;\frac{\frac{1}{y + z \cdot \left(y \cdot z\right)}}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(1, z\right)} \cdot \frac{\frac{\frac{1}{x}}{y}}{\mathsf{hypot}\left(1, z\right)}\\
\end{array}
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 90.9% |
|---|---|
| Target | 92.9% |
| Herbie | 97.9% |
if y < 2e-121Initial program 90.9%
Simplified90.0%
[Start]90.9% | \[ \frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}
\] |
|---|---|
associate-/r* [<=]90.0% | \[ \color{blue}{\frac{1}{x \cdot \left(y \cdot \left(1 + z \cdot z\right)\right)}}
\] |
+-commutative [=>]90.0% | \[ \frac{1}{x \cdot \left(y \cdot \color{blue}{\left(z \cdot z + 1\right)}\right)}
\] |
fma-def [=>]90.0% | \[ \frac{1}{x \cdot \left(y \cdot \color{blue}{\mathsf{fma}\left(z, z, 1\right)}\right)}
\] |
Taylor expanded in x around 0 88.4%
Simplified95.3%
[Start]88.4% | \[ \frac{1}{y \cdot \left(\left({z}^{2} + 1\right) \cdot x\right)}
\] |
|---|---|
associate-*r* [=>]90.0% | \[ \frac{1}{\color{blue}{\left(y \cdot \left({z}^{2} + 1\right)\right) \cdot x}}
\] |
*-commutative [<=]90.0% | \[ \frac{1}{\color{blue}{\left(\left({z}^{2} + 1\right) \cdot y\right)} \cdot x}
\] |
associate-*r* [<=]85.6% | \[ \frac{1}{\color{blue}{\left({z}^{2} + 1\right) \cdot \left(y \cdot x\right)}}
\] |
associate-/r* [=>]86.1% | \[ \color{blue}{\frac{\frac{1}{{z}^{2} + 1}}{y \cdot x}}
\] |
unpow2 [=>]86.1% | \[ \frac{\frac{1}{\color{blue}{z \cdot z} + 1}}{y \cdot x}
\] |
fma-udef [<=]86.1% | \[ \frac{\frac{1}{\color{blue}{\mathsf{fma}\left(z, z, 1\right)}}}{y \cdot x}
\] |
associate-/r* [=>]91.0% | \[ \color{blue}{\frac{\frac{\frac{1}{\mathsf{fma}\left(z, z, 1\right)}}{y}}{x}}
\] |
associate-/l/ [=>]90.9% | \[ \frac{\color{blue}{\frac{1}{y \cdot \mathsf{fma}\left(z, z, 1\right)}}}{x}
\] |
fma-udef [=>]90.9% | \[ \frac{\frac{1}{y \cdot \color{blue}{\left(z \cdot z + 1\right)}}}{x}
\] |
distribute-lft-in [=>]90.9% | \[ \frac{\frac{1}{\color{blue}{y \cdot \left(z \cdot z\right) + y \cdot 1}}}{x}
\] |
*-rgt-identity [=>]90.9% | \[ \frac{\frac{1}{y \cdot \left(z \cdot z\right) + \color{blue}{y}}}{x}
\] |
fma-def [=>]90.9% | \[ \frac{\frac{1}{\color{blue}{\mathsf{fma}\left(y, z \cdot z, y\right)}}}{x}
\] |
fma-def [<=]90.9% | \[ \frac{\frac{1}{\color{blue}{y \cdot \left(z \cdot z\right) + y}}}{x}
\] |
*-commutative [=>]90.9% | \[ \frac{\frac{1}{\color{blue}{\left(z \cdot z\right) \cdot y} + y}}{x}
\] |
associate-*r* [<=]95.3% | \[ \frac{\frac{1}{\color{blue}{z \cdot \left(z \cdot y\right)} + y}}{x}
\] |
fma-udef [<=]95.3% | \[ \frac{\frac{1}{\color{blue}{\mathsf{fma}\left(z, z \cdot y, y\right)}}}{x}
\] |
Applied egg-rr95.3%
[Start]95.3% | \[ \frac{\frac{1}{\mathsf{fma}\left(z, z \cdot y, y\right)}}{x}
\] |
|---|---|
fma-udef [=>]95.3% | \[ \frac{\frac{1}{\color{blue}{z \cdot \left(z \cdot y\right) + y}}}{x}
\] |
if 2e-121 < y Initial program 95.0%
Simplified95.2%
[Start]95.0% | \[ \frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}
\] |
|---|---|
associate-/r* [<=]95.2% | \[ \color{blue}{\frac{1}{x \cdot \left(y \cdot \left(1 + z \cdot z\right)\right)}}
\] |
+-commutative [=>]95.2% | \[ \frac{1}{x \cdot \left(y \cdot \color{blue}{\left(z \cdot z + 1\right)}\right)}
\] |
fma-def [=>]95.2% | \[ \frac{1}{x \cdot \left(y \cdot \color{blue}{\mathsf{fma}\left(z, z, 1\right)}\right)}
\] |
Applied egg-rr99.6%
[Start]95.2% | \[ \frac{1}{x \cdot \left(y \cdot \mathsf{fma}\left(z, z, 1\right)\right)}
\] |
|---|---|
fma-udef [=>]95.2% | \[ \frac{1}{x \cdot \left(y \cdot \color{blue}{\left(z \cdot z + 1\right)}\right)}
\] |
+-commutative [<=]95.2% | \[ \frac{1}{x \cdot \left(y \cdot \color{blue}{\left(1 + z \cdot z\right)}\right)}
\] |
associate-/r* [=>]95.0% | \[ \color{blue}{\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}}
\] |
associate-/r* [=>]97.4% | \[ \color{blue}{\frac{\frac{\frac{1}{x}}{y}}{1 + z \cdot z}}
\] |
add-sqr-sqrt [=>]97.4% | \[ \frac{\frac{\frac{1}{x}}{y}}{\color{blue}{\sqrt{1 + z \cdot z} \cdot \sqrt{1 + z \cdot z}}}
\] |
*-un-lft-identity [=>]97.4% | \[ \frac{\color{blue}{1 \cdot \frac{\frac{1}{x}}{y}}}{\sqrt{1 + z \cdot z} \cdot \sqrt{1 + z \cdot z}}
\] |
times-frac [=>]97.4% | \[ \color{blue}{\frac{1}{\sqrt{1 + z \cdot z}} \cdot \frac{\frac{\frac{1}{x}}{y}}{\sqrt{1 + z \cdot z}}}
\] |
hypot-1-def [=>]97.4% | \[ \frac{1}{\color{blue}{\mathsf{hypot}\left(1, z\right)}} \cdot \frac{\frac{\frac{1}{x}}{y}}{\sqrt{1 + z \cdot z}}
\] |
hypot-1-def [=>]99.6% | \[ \frac{1}{\mathsf{hypot}\left(1, z\right)} \cdot \frac{\frac{\frac{1}{x}}{y}}{\color{blue}{\mathsf{hypot}\left(1, z\right)}}
\] |
Final simplification96.7%
| Alternative 1 | |
|---|---|
| Accuracy | 97.9% |
| Cost | 13764 |
| Alternative 2 | |
|---|---|
| Accuracy | 94.8% |
| Cost | 1220 |
| Alternative 3 | |
|---|---|
| Accuracy | 97.2% |
| Cost | 964 |
| Alternative 4 | |
|---|---|
| Accuracy | 97.5% |
| Cost | 964 |
| Alternative 5 | |
|---|---|
| Accuracy | 96.2% |
| Cost | 900 |
| Alternative 6 | |
|---|---|
| Accuracy | 89.9% |
| Cost | 836 |
| Alternative 7 | |
|---|---|
| Accuracy | 93.3% |
| Cost | 836 |
| Alternative 8 | |
|---|---|
| Accuracy | 96.4% |
| Cost | 836 |
| Alternative 9 | |
|---|---|
| Accuracy | 96.4% |
| Cost | 836 |
| Alternative 10 | |
|---|---|
| Accuracy | 96.7% |
| Cost | 836 |
| Alternative 11 | |
|---|---|
| Accuracy | 59.0% |
| Cost | 320 |
| Alternative 12 | |
|---|---|
| Accuracy | 59.0% |
| Cost | 320 |
herbie shell --seed 2023272
(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)))))