| Alternative 1 | |
|---|---|
| Accuracy | 97.7% |
| Cost | 964 |

(FPCore (x y z) :precision binary64 (/ (/ 1.0 x) (* y (+ 1.0 (* z z)))))
(FPCore (x y z) :precision binary64 (if (<= (* z z) 1e+212) (/ (/ (/ 1.0 x) y) (+ 1.0 (* z z))) (/ (/ (/ 1.0 y) z) (* x 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 * z) <= 1e+212) {
tmp = ((1.0 / x) / y) / (1.0 + (z * z));
} else {
tmp = ((1.0 / y) / z) / (x * 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 * z) <= 1d+212) then
tmp = ((1.0d0 / x) / y) / (1.0d0 + (z * z))
else
tmp = ((1.0d0 / y) / z) / (x * 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 * z) <= 1e+212) {
tmp = ((1.0 / x) / y) / (1.0 + (z * z));
} else {
tmp = ((1.0 / y) / z) / (x * 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 * z) <= 1e+212: tmp = ((1.0 / x) / y) / (1.0 + (z * z)) else: tmp = ((1.0 / y) / z) / (x * 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 (Float64(z * z) <= 1e+212) tmp = Float64(Float64(Float64(1.0 / x) / y) / Float64(1.0 + Float64(z * z))); else tmp = Float64(Float64(Float64(1.0 / y) / z) / Float64(x * 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 * z) <= 1e+212) tmp = ((1.0 / x) / y) / (1.0 + (z * z)); else tmp = ((1.0 / y) / z) / (x * 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[N[(z * z), $MachinePrecision], 1e+212], N[(N[(N[(1.0 / x), $MachinePrecision] / y), $MachinePrecision] / N[(1.0 + N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(1.0 / y), $MachinePrecision] / z), $MachinePrecision] / N[(x * z), $MachinePrecision]), $MachinePrecision]]
\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 10^{+212}:\\
\;\;\;\;\frac{\frac{\frac{1}{x}}{y}}{1 + z \cdot z}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\frac{1}{y}}{z}}{x \cdot z}\\
\end{array}
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 90.8% |
|---|---|
| Target | 92.6% |
| Herbie | 97.7% |
if (*.f64 z z) < 9.9999999999999991e211Initial program 99.0%
Simplified99.0%
[Start]99.0% | \[ \frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}
\] |
|---|---|
associate-/r* [=>]99.0% | \[ \color{blue}{\frac{\frac{\frac{1}{x}}{y}}{1 + z \cdot z}}
\] |
if 9.9999999999999991e211 < (*.f64 z z) Initial program 75.1%
Simplified75.0%
[Start]75.1% | \[ \frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}
\] |
|---|---|
associate-/r* [<=]75.0% | \[ \color{blue}{\frac{1}{x \cdot \left(y \cdot \left(1 + z \cdot z\right)\right)}}
\] |
+-commutative [=>]75.0% | \[ \frac{1}{x \cdot \left(y \cdot \color{blue}{\left(z \cdot z + 1\right)}\right)}
\] |
fma-def [=>]75.0% | \[ \frac{1}{x \cdot \left(y \cdot \color{blue}{\mathsf{fma}\left(z, z, 1\right)}\right)}
\] |
Taylor expanded in z around inf 76.9%
Simplified85.0%
[Start]76.9% | \[ \frac{1}{y \cdot \left({z}^{2} \cdot x\right)}
\] |
|---|---|
unpow2 [=>]76.9% | \[ \frac{1}{y \cdot \left(\color{blue}{\left(z \cdot z\right)} \cdot x\right)}
\] |
*-commutative [=>]76.9% | \[ \frac{1}{y \cdot \color{blue}{\left(x \cdot \left(z \cdot z\right)\right)}}
\] |
associate-*l* [<=]73.5% | \[ \frac{1}{\color{blue}{\left(y \cdot x\right) \cdot \left(z \cdot z\right)}}
\] |
*-commutative [=>]73.5% | \[ \frac{1}{\color{blue}{\left(z \cdot z\right) \cdot \left(y \cdot x\right)}}
\] |
associate-*l* [=>]85.0% | \[ \frac{1}{\color{blue}{z \cdot \left(z \cdot \left(y \cdot x\right)\right)}}
\] |
Applied egg-rr94.9%
[Start]85.0% | \[ \frac{1}{z \cdot \left(z \cdot \left(y \cdot x\right)\right)}
\] |
|---|---|
clear-num [=>]85.0% | \[ \color{blue}{\frac{1}{\frac{z \cdot \left(z \cdot \left(y \cdot x\right)\right)}{1}}}
\] |
associate-/r/ [=>]85.0% | \[ \color{blue}{\frac{1}{z \cdot \left(z \cdot \left(y \cdot x\right)\right)} \cdot 1}
\] |
associate-/r* [=>]85.7% | \[ \color{blue}{\frac{\frac{1}{z}}{z \cdot \left(y \cdot x\right)}} \cdot 1
\] |
associate-*r* [=>]94.9% | \[ \frac{\frac{1}{z}}{\color{blue}{\left(z \cdot y\right) \cdot x}} \cdot 1
\] |
*-commutative [=>]94.9% | \[ \frac{\frac{1}{z}}{\color{blue}{x \cdot \left(z \cdot y\right)}} \cdot 1
\] |
Taylor expanded in z around 0 76.9%
Simplified97.9%
[Start]76.9% | \[ \frac{1}{y \cdot \left({z}^{2} \cdot x\right)} \cdot 1
\] |
|---|---|
associate-/r* [=>]76.9% | \[ \color{blue}{\frac{\frac{1}{y}}{{z}^{2} \cdot x}} \cdot 1
\] |
unpow2 [=>]76.9% | \[ \frac{\frac{1}{y}}{\color{blue}{\left(z \cdot z\right)} \cdot x} \cdot 1
\] |
associate-*r* [<=]92.8% | \[ \frac{\frac{1}{y}}{\color{blue}{z \cdot \left(z \cdot x\right)}} \cdot 1
\] |
*-commutative [<=]92.8% | \[ \frac{\frac{1}{y}}{z \cdot \color{blue}{\left(x \cdot z\right)}} \cdot 1
\] |
associate-/r* [=>]97.9% | \[ \color{blue}{\frac{\frac{\frac{1}{y}}{z}}{x \cdot z}} \cdot 1
\] |
*-commutative [=>]97.9% | \[ \frac{\frac{\frac{1}{y}}{z}}{\color{blue}{z \cdot x}} \cdot 1
\] |
Final simplification98.6%
| Alternative 1 | |
|---|---|
| Accuracy | 97.7% |
| Cost | 964 |
| Alternative 2 | |
|---|---|
| Accuracy | 98.0% |
| Cost | 13632 |
| Alternative 3 | |
|---|---|
| Accuracy | 97.8% |
| Cost | 13504 |
| Alternative 4 | |
|---|---|
| Accuracy | 97.8% |
| Cost | 964 |
| Alternative 5 | |
|---|---|
| Accuracy | 93.8% |
| Cost | 836 |
| Alternative 6 | |
|---|---|
| Accuracy | 96.7% |
| Cost | 836 |
| Alternative 7 | |
|---|---|
| Accuracy | 96.8% |
| Cost | 836 |
| Alternative 8 | |
|---|---|
| Accuracy | 97.1% |
| Cost | 836 |
| Alternative 9 | |
|---|---|
| Accuracy | 97.1% |
| Cost | 836 |
| Alternative 10 | |
|---|---|
| Accuracy | 58.6% |
| Cost | 320 |
| Alternative 11 | |
|---|---|
| Accuracy | 58.7% |
| Cost | 320 |
herbie shell --seed 2023263
(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)))))