| Alternative 1 | |
|---|---|
| Accuracy | 97.3% |
| Cost | 1736 |

(FPCore (x y z) :precision binary64 (/ (/ 1.0 x) (* y (+ 1.0 (* z z)))))
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (+ 1.0 (* z z)))))
(if (<= t_0 -2e+72)
(/ 1.0 (* z (* y (* x z))))
(if (<= t_0 4e+297) (/ (/ 1.0 x) t_0) (/ (/ (/ 1.0 y) (* x z)) 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 t_0 = y * (1.0 + (z * z));
double tmp;
if (t_0 <= -2e+72) {
tmp = 1.0 / (z * (y * (x * z)));
} else if (t_0 <= 4e+297) {
tmp = (1.0 / x) / t_0;
} else {
tmp = ((1.0 / y) / (x * z)) / 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) :: t_0
real(8) :: tmp
t_0 = y * (1.0d0 + (z * z))
if (t_0 <= (-2d+72)) then
tmp = 1.0d0 / (z * (y * (x * z)))
else if (t_0 <= 4d+297) then
tmp = (1.0d0 / x) / t_0
else
tmp = ((1.0d0 / y) / (x * z)) / 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 t_0 = y * (1.0 + (z * z));
double tmp;
if (t_0 <= -2e+72) {
tmp = 1.0 / (z * (y * (x * z)));
} else if (t_0 <= 4e+297) {
tmp = (1.0 / x) / t_0;
} else {
tmp = ((1.0 / y) / (x * z)) / z;
}
return tmp;
}
def code(x, y, z): return (1.0 / x) / (y * (1.0 + (z * z)))
def code(x, y, z): t_0 = y * (1.0 + (z * z)) tmp = 0 if t_0 <= -2e+72: tmp = 1.0 / (z * (y * (x * z))) elif t_0 <= 4e+297: tmp = (1.0 / x) / t_0 else: tmp = ((1.0 / y) / (x * z)) / 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) t_0 = Float64(y * Float64(1.0 + Float64(z * z))) tmp = 0.0 if (t_0 <= -2e+72) tmp = Float64(1.0 / Float64(z * Float64(y * Float64(x * z)))); elseif (t_0 <= 4e+297) tmp = Float64(Float64(1.0 / x) / t_0); else tmp = Float64(Float64(Float64(1.0 / y) / Float64(x * z)) / 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) t_0 = y * (1.0 + (z * z)); tmp = 0.0; if (t_0 <= -2e+72) tmp = 1.0 / (z * (y * (x * z))); elseif (t_0 <= 4e+297) tmp = (1.0 / x) / t_0; else tmp = ((1.0 / y) / (x * z)) / 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_] := Block[{t$95$0 = N[(y * N[(1.0 + N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2e+72], N[(1.0 / N[(z * N[(y * N[(x * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 4e+297], N[(N[(1.0 / x), $MachinePrecision] / t$95$0), $MachinePrecision], N[(N[(N[(1.0 / y), $MachinePrecision] / N[(x * z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]]]]
\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}
\begin{array}{l}
t_0 := y \cdot \left(1 + z \cdot z\right)\\
\mathbf{if}\;t_0 \leq -2 \cdot 10^{+72}:\\
\;\;\;\;\frac{1}{z \cdot \left(y \cdot \left(x \cdot z\right)\right)}\\
\mathbf{elif}\;t_0 \leq 4 \cdot 10^{+297}:\\
\;\;\;\;\frac{\frac{1}{x}}{t_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\frac{1}{y}}{x \cdot z}}{z}\\
\end{array}
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 90.9% |
|---|---|
| Target | 92.9% |
| Herbie | 97.3% |
if (*.f64 y (+.f64 1 (*.f64 z z))) < -1.99999999999999989e72Initial program 79.1%
Simplified79.1%
[Start]79.1% | \[ \frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}
\] |
|---|---|
associate-/r* [<=]79.1% | \[ \color{blue}{\frac{1}{x \cdot \left(y \cdot \left(1 + z \cdot z\right)\right)}}
\] |
+-commutative [=>]79.1% | \[ \frac{1}{x \cdot \left(y \cdot \color{blue}{\left(z \cdot z + 1\right)}\right)}
\] |
fma-def [=>]79.1% | \[ \frac{1}{x \cdot \left(y \cdot \color{blue}{\mathsf{fma}\left(z, z, 1\right)}\right)}
\] |
Applied egg-rr84.1%
[Start]79.1% | \[ \frac{1}{x \cdot \left(y \cdot \mathsf{fma}\left(z, z, 1\right)\right)}
\] |
|---|---|
fma-udef [=>]79.1% | \[ \frac{1}{x \cdot \left(y \cdot \color{blue}{\left(z \cdot z + 1\right)}\right)}
\] |
+-commutative [<=]79.1% | \[ \frac{1}{x \cdot \left(y \cdot \color{blue}{\left(1 + z \cdot z\right)}\right)}
\] |
associate-/r* [=>]79.1% | \[ \color{blue}{\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}}
\] |
associate-/r* [=>]79.8% | \[ \color{blue}{\frac{\frac{\frac{1}{x}}{y}}{1 + z \cdot z}}
\] |
add-sqr-sqrt [=>]79.8% | \[ \frac{\frac{\frac{1}{x}}{y}}{\color{blue}{\sqrt{1 + z \cdot z} \cdot \sqrt{1 + z \cdot z}}}
\] |
*-un-lft-identity [=>]79.8% | \[ \frac{\color{blue}{1 \cdot \frac{\frac{1}{x}}{y}}}{\sqrt{1 + z \cdot z} \cdot \sqrt{1 + z \cdot z}}
\] |
times-frac [=>]79.9% | \[ \color{blue}{\frac{1}{\sqrt{1 + z \cdot z}} \cdot \frac{\frac{\frac{1}{x}}{y}}{\sqrt{1 + z \cdot z}}}
\] |
hypot-1-def [=>]79.9% | \[ \frac{1}{\color{blue}{\mathsf{hypot}\left(1, z\right)}} \cdot \frac{\frac{\frac{1}{x}}{y}}{\sqrt{1 + z \cdot z}}
\] |
associate-/l/ [=>]79.8% | \[ \frac{1}{\mathsf{hypot}\left(1, z\right)} \cdot \frac{\color{blue}{\frac{1}{y \cdot x}}}{\sqrt{1 + z \cdot z}}
\] |
hypot-1-def [=>]84.1% | \[ \frac{1}{\mathsf{hypot}\left(1, z\right)} \cdot \frac{\frac{1}{y \cdot x}}{\color{blue}{\mathsf{hypot}\left(1, z\right)}}
\] |
Simplified98.4%
[Start]84.1% | \[ \frac{1}{\mathsf{hypot}\left(1, z\right)} \cdot \frac{\frac{1}{y \cdot x}}{\mathsf{hypot}\left(1, z\right)}
\] |
|---|---|
associate-*l/ [=>]84.1% | \[ \color{blue}{\frac{1 \cdot \frac{\frac{1}{y \cdot x}}{\mathsf{hypot}\left(1, z\right)}}{\mathsf{hypot}\left(1, z\right)}}
\] |
*-lft-identity [=>]84.1% | \[ \frac{\color{blue}{\frac{\frac{1}{y \cdot x}}{\mathsf{hypot}\left(1, z\right)}}}{\mathsf{hypot}\left(1, z\right)}
\] |
associate-/r* [=>]84.1% | \[ \frac{\frac{\color{blue}{\frac{\frac{1}{y}}{x}}}{\mathsf{hypot}\left(1, z\right)}}{\mathsf{hypot}\left(1, z\right)}
\] |
associate-/l/ [=>]98.4% | \[ \frac{\color{blue}{\frac{\frac{1}{y}}{\mathsf{hypot}\left(1, z\right) \cdot x}}}{\mathsf{hypot}\left(1, z\right)}
\] |
*-commutative [=>]98.4% | \[ \frac{\frac{\frac{1}{y}}{\color{blue}{x \cdot \mathsf{hypot}\left(1, z\right)}}}{\mathsf{hypot}\left(1, z\right)}
\] |
Taylor expanded in z around inf 57.0%
Simplified57.0%
[Start]57.0% | \[ \frac{1}{y \cdot \left({z}^{2} \cdot x\right)}
\] |
|---|---|
unpow2 [=>]57.0% | \[ \frac{1}{y \cdot \left(\color{blue}{\left(z \cdot z\right)} \cdot x\right)}
\] |
Taylor expanded in y around 0 57.0%
Simplified76.4%
[Start]57.0% | \[ \frac{1}{y \cdot \left({z}^{2} \cdot x\right)}
\] |
|---|---|
*-commutative [=>]57.0% | \[ \frac{1}{\color{blue}{\left({z}^{2} \cdot x\right) \cdot y}}
\] |
unpow2 [=>]57.0% | \[ \frac{1}{\left(\color{blue}{\left(z \cdot z\right)} \cdot x\right) \cdot y}
\] |
associate-*r* [<=]60.2% | \[ \frac{1}{\color{blue}{\left(z \cdot z\right) \cdot \left(x \cdot y\right)}}
\] |
*-commutative [<=]60.2% | \[ \frac{1}{\left(z \cdot z\right) \cdot \color{blue}{\left(y \cdot x\right)}}
\] |
associate-*l* [=>]67.2% | \[ \frac{1}{\color{blue}{z \cdot \left(z \cdot \left(y \cdot x\right)\right)}}
\] |
*-commutative [=>]67.2% | \[ \frac{1}{z \cdot \left(z \cdot \color{blue}{\left(x \cdot y\right)}\right)}
\] |
associate-*l* [<=]76.4% | \[ \frac{1}{z \cdot \color{blue}{\left(\left(z \cdot x\right) \cdot y\right)}}
\] |
*-commutative [<=]76.4% | \[ \frac{1}{z \cdot \left(\color{blue}{\left(x \cdot z\right)} \cdot y\right)}
\] |
*-commutative [=>]76.4% | \[ \frac{1}{z \cdot \color{blue}{\left(y \cdot \left(x \cdot z\right)\right)}}
\] |
*-commutative [=>]76.4% | \[ \frac{1}{z \cdot \left(y \cdot \color{blue}{\left(z \cdot x\right)}\right)}
\] |
if -1.99999999999999989e72 < (*.f64 y (+.f64 1 (*.f64 z z))) < 4.0000000000000001e297Initial program 99.7%
if 4.0000000000000001e297 < (*.f64 y (+.f64 1 (*.f64 z z))) Initial program 67.3%
Simplified67.3%
[Start]67.3% | \[ \frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}
\] |
|---|---|
associate-/r* [<=]67.3% | \[ \color{blue}{\frac{1}{x \cdot \left(y \cdot \left(1 + z \cdot z\right)\right)}}
\] |
+-commutative [=>]67.3% | \[ \frac{1}{x \cdot \left(y \cdot \color{blue}{\left(z \cdot z + 1\right)}\right)}
\] |
fma-def [=>]67.3% | \[ \frac{1}{x \cdot \left(y \cdot \color{blue}{\mathsf{fma}\left(z, z, 1\right)}\right)}
\] |
Applied egg-rr75.4%
[Start]67.3% | \[ \frac{1}{x \cdot \left(y \cdot \mathsf{fma}\left(z, z, 1\right)\right)}
\] |
|---|---|
associate-/r* [=>]67.3% | \[ \color{blue}{\frac{\frac{1}{x}}{y \cdot \mathsf{fma}\left(z, z, 1\right)}}
\] |
*-un-lft-identity [=>]67.3% | \[ \frac{\color{blue}{1 \cdot \frac{1}{x}}}{y \cdot \mathsf{fma}\left(z, z, 1\right)}
\] |
fma-udef [=>]67.3% | \[ \frac{1 \cdot \frac{1}{x}}{y \cdot \color{blue}{\left(z \cdot z + 1\right)}}
\] |
+-commutative [<=]67.3% | \[ \frac{1 \cdot \frac{1}{x}}{y \cdot \color{blue}{\left(1 + z \cdot z\right)}}
\] |
times-frac [=>]75.4% | \[ \color{blue}{\frac{1}{y} \cdot \frac{\frac{1}{x}}{1 + z \cdot z}}
\] |
+-commutative [=>]75.4% | \[ \frac{1}{y} \cdot \frac{\frac{1}{x}}{\color{blue}{z \cdot z + 1}}
\] |
fma-udef [<=]75.4% | \[ \frac{1}{y} \cdot \frac{\frac{1}{x}}{\color{blue}{\mathsf{fma}\left(z, z, 1\right)}}
\] |
Taylor expanded in z around inf 75.4%
Simplified83.7%
[Start]75.4% | \[ \frac{1}{y} \cdot \frac{1}{{z}^{2} \cdot x}
\] |
|---|---|
unpow2 [=>]75.4% | \[ \frac{1}{y} \cdot \frac{1}{\color{blue}{\left(z \cdot z\right)} \cdot x}
\] |
associate-*l* [=>]83.7% | \[ \frac{1}{y} \cdot \frac{1}{\color{blue}{z \cdot \left(z \cdot x\right)}}
\] |
Applied egg-rr99.8%
[Start]83.7% | \[ \frac{1}{y} \cdot \frac{1}{z \cdot \left(z \cdot x\right)}
\] |
|---|---|
un-div-inv [=>]83.7% | \[ \color{blue}{\frac{\frac{1}{y}}{z \cdot \left(z \cdot x\right)}}
\] |
*-commutative [=>]83.7% | \[ \frac{\frac{1}{y}}{\color{blue}{\left(z \cdot x\right) \cdot z}}
\] |
associate-/r* [=>]99.8% | \[ \color{blue}{\frac{\frac{\frac{1}{y}}{z \cdot x}}{z}}
\] |
*-commutative [=>]99.8% | \[ \frac{\frac{\frac{1}{y}}{\color{blue}{x \cdot z}}}{z}
\] |
Final simplification93.0%
| Alternative 1 | |
|---|---|
| Accuracy | 97.3% |
| Cost | 1736 |
| Alternative 2 | |
|---|---|
| Accuracy | 97.7% |
| Cost | 13504 |
| Alternative 3 | |
|---|---|
| Accuracy | 97.5% |
| Cost | 964 |
| Alternative 4 | |
|---|---|
| Accuracy | 93.4% |
| Cost | 836 |
| Alternative 5 | |
|---|---|
| Accuracy | 96.5% |
| Cost | 836 |
| Alternative 6 | |
|---|---|
| Accuracy | 96.6% |
| Cost | 836 |
| Alternative 7 | |
|---|---|
| Accuracy | 58.3% |
| Cost | 384 |
| Alternative 8 | |
|---|---|
| Accuracy | 58.2% |
| Cost | 320 |
| Alternative 9 | |
|---|---|
| Accuracy | 58.3% |
| Cost | 320 |
herbie shell --seed 2023165
(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)))))