| Alternative 1 | |
|---|---|
| Error | 3.06% |
| Cost | 13769 |
(FPCore (x y z) :precision binary64 (/ (/ 1.0 x) (* y (+ 1.0 (* z z)))))
(FPCore (x y z) :precision binary64 (if (<= x -1.02e-98) (/ (/ 1.0 (hypot 1.0 z)) (* x (* (hypot 1.0 z) y))) (/ 1.0 (* y (+ x (* 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 (x <= -1.02e-98) {
tmp = (1.0 / hypot(1.0, z)) / (x * (hypot(1.0, z) * y));
} else {
tmp = 1.0 / (y * (x + (z * (x * 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 (x <= -1.02e-98) {
tmp = (1.0 / Math.hypot(1.0, z)) / (x * (Math.hypot(1.0, z) * y));
} else {
tmp = 1.0 / (y * (x + (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 x <= -1.02e-98: tmp = (1.0 / math.hypot(1.0, z)) / (x * (math.hypot(1.0, z) * y)) else: tmp = 1.0 / (y * (x + (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 (x <= -1.02e-98) tmp = Float64(Float64(1.0 / hypot(1.0, z)) / Float64(x * Float64(hypot(1.0, z) * y))); else tmp = Float64(1.0 / Float64(y * Float64(x + Float64(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 (x <= -1.02e-98) tmp = (1.0 / hypot(1.0, z)) / (x * (hypot(1.0, z) * y)); else tmp = 1.0 / (y * (x + (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[x, -1.02e-98], N[(N[(1.0 / N[Sqrt[1.0 ^ 2 + z ^ 2], $MachinePrecision]), $MachinePrecision] / N[(x * N[(N[Sqrt[1.0 ^ 2 + z ^ 2], $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(y * N[(x + N[(z * N[(x * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}
\begin{array}{l}
\mathbf{if}\;x \leq -1.02 \cdot 10^{-98}:\\
\;\;\;\;\frac{\frac{1}{\mathsf{hypot}\left(1, z\right)}}{x \cdot \left(\mathsf{hypot}\left(1, z\right) \cdot y\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{y \cdot \left(x + z \cdot \left(x \cdot z\right)\right)}\\
\end{array}
Results
| Original | 9.88% |
|---|---|
| Target | 8.1% |
| Herbie | 1.95% |
if x < -1.02e-98Initial program 4.21
Simplified8.24
[Start]4.21 | \[ \frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}
\] |
|---|---|
associate-/l/ [=>]4.75 | \[ \color{blue}{\frac{1}{\left(y \cdot \left(1 + z \cdot z\right)\right) \cdot x}}
\] |
associate-*l* [=>]8.24 | \[ \frac{1}{\color{blue}{y \cdot \left(\left(1 + z \cdot z\right) \cdot x\right)}}
\] |
+-commutative [=>]8.24 | \[ \frac{1}{y \cdot \left(\color{blue}{\left(z \cdot z + 1\right)} \cdot x\right)}
\] |
fma-def [=>]8.24 | \[ \frac{1}{y \cdot \left(\color{blue}{\mathsf{fma}\left(z, z, 1\right)} \cdot x\right)}
\] |
Applied egg-rr6.05
Simplified2.91
[Start]6.05 | \[ \frac{1}{\frac{\sqrt{\mathsf{fma}\left(z, z, 1\right)}}{\frac{\frac{1}{y}}{x \cdot \sqrt{\mathsf{fma}\left(z, z, 1\right)}}}}
\] |
|---|---|
associate-/l/ [=>]5.99 | \[ \frac{1}{\frac{\sqrt{\mathsf{fma}\left(z, z, 1\right)}}{\color{blue}{\frac{1}{\left(x \cdot \sqrt{\mathsf{fma}\left(z, z, 1\right)}\right) \cdot y}}}}
\] |
associate-/r* [=>]6.04 | \[ \frac{1}{\frac{\sqrt{\mathsf{fma}\left(z, z, 1\right)}}{\color{blue}{\frac{\frac{1}{x \cdot \sqrt{\mathsf{fma}\left(z, z, 1\right)}}}{y}}}}
\] |
associate-/r* [=>]5.82 | \[ \frac{1}{\frac{\sqrt{\mathsf{fma}\left(z, z, 1\right)}}{\frac{\color{blue}{\frac{\frac{1}{x}}{\sqrt{\mathsf{fma}\left(z, z, 1\right)}}}}{y}}}
\] |
associate-/l* [<=]5.84 | \[ \frac{1}{\color{blue}{\frac{\sqrt{\mathsf{fma}\left(z, z, 1\right)} \cdot y}{\frac{\frac{1}{x}}{\sqrt{\mathsf{fma}\left(z, z, 1\right)}}}}}
\] |
*-commutative [<=]5.84 | \[ \frac{1}{\frac{\color{blue}{y \cdot \sqrt{\mathsf{fma}\left(z, z, 1\right)}}}{\frac{\frac{1}{x}}{\sqrt{\mathsf{fma}\left(z, z, 1\right)}}}}
\] |
associate-/r* [<=]6.07 | \[ \frac{1}{\frac{y \cdot \sqrt{\mathsf{fma}\left(z, z, 1\right)}}{\color{blue}{\frac{1}{x \cdot \sqrt{\mathsf{fma}\left(z, z, 1\right)}}}}}
\] |
associate-/r/ [=>]5.99 | \[ \frac{1}{\color{blue}{\frac{y \cdot \sqrt{\mathsf{fma}\left(z, z, 1\right)}}{1} \cdot \left(x \cdot \sqrt{\mathsf{fma}\left(z, z, 1\right)}\right)}}
\] |
/-rgt-identity [=>]5.99 | \[ \frac{1}{\color{blue}{\left(y \cdot \sqrt{\mathsf{fma}\left(z, z, 1\right)}\right)} \cdot \left(x \cdot \sqrt{\mathsf{fma}\left(z, z, 1\right)}\right)}
\] |
fma-udef [=>]5.99 | \[ \frac{1}{\left(y \cdot \sqrt{\color{blue}{z \cdot z + 1}}\right) \cdot \left(x \cdot \sqrt{\mathsf{fma}\left(z, z, 1\right)}\right)}
\] |
+-commutative [<=]5.99 | \[ \frac{1}{\left(y \cdot \sqrt{\color{blue}{1 + z \cdot z}}\right) \cdot \left(x \cdot \sqrt{\mathsf{fma}\left(z, z, 1\right)}\right)}
\] |
hypot-1-def [=>]5.99 | \[ \frac{1}{\left(y \cdot \color{blue}{\mathsf{hypot}\left(1, z\right)}\right) \cdot \left(x \cdot \sqrt{\mathsf{fma}\left(z, z, 1\right)}\right)}
\] |
fma-udef [=>]5.99 | \[ \frac{1}{\left(y \cdot \mathsf{hypot}\left(1, z\right)\right) \cdot \left(x \cdot \sqrt{\color{blue}{z \cdot z + 1}}\right)}
\] |
+-commutative [<=]5.99 | \[ \frac{1}{\left(y \cdot \mathsf{hypot}\left(1, z\right)\right) \cdot \left(x \cdot \sqrt{\color{blue}{1 + z \cdot z}}\right)}
\] |
hypot-1-def [=>]2.91 | \[ \frac{1}{\left(y \cdot \mathsf{hypot}\left(1, z\right)\right) \cdot \left(x \cdot \color{blue}{\mathsf{hypot}\left(1, z\right)}\right)}
\] |
Applied egg-rr2.11
Simplified0.68
[Start]2.11 | \[ \frac{\frac{1}{y}}{\mathsf{hypot}\left(1, z\right)} \cdot \frac{\frac{1}{x}}{\mathsf{hypot}\left(1, z\right)}
\] |
|---|---|
associate-*r/ [=>]0.43 | \[ \color{blue}{\frac{\frac{\frac{1}{y}}{\mathsf{hypot}\left(1, z\right)} \cdot \frac{1}{x}}{\mathsf{hypot}\left(1, z\right)}}
\] |
associate-*r/ [=>]0.36 | \[ \frac{\color{blue}{\frac{\frac{\frac{1}{y}}{\mathsf{hypot}\left(1, z\right)} \cdot 1}{x}}}{\mathsf{hypot}\left(1, z\right)}
\] |
associate-*l/ [<=]0.36 | \[ \frac{\color{blue}{\frac{\frac{\frac{1}{y}}{\mathsf{hypot}\left(1, z\right)}}{x} \cdot 1}}{\mathsf{hypot}\left(1, z\right)}
\] |
associate-*r/ [<=]0.37 | \[ \color{blue}{\frac{\frac{\frac{1}{y}}{\mathsf{hypot}\left(1, z\right)}}{x} \cdot \frac{1}{\mathsf{hypot}\left(1, z\right)}}
\] |
associate-/r* [<=]2.33 | \[ \color{blue}{\frac{\frac{1}{y}}{\mathsf{hypot}\left(1, z\right) \cdot x}} \cdot \frac{1}{\mathsf{hypot}\left(1, z\right)}
\] |
associate-/l/ [=>]2.63 | \[ \color{blue}{\frac{1}{\left(\mathsf{hypot}\left(1, z\right) \cdot x\right) \cdot y}} \cdot \frac{1}{\mathsf{hypot}\left(1, z\right)}
\] |
associate-*r* [<=]1.74 | \[ \frac{1}{\color{blue}{\mathsf{hypot}\left(1, z\right) \cdot \left(x \cdot y\right)}} \cdot \frac{1}{\mathsf{hypot}\left(1, z\right)}
\] |
*-commutative [<=]1.74 | \[ \frac{1}{\mathsf{hypot}\left(1, z\right) \cdot \color{blue}{\left(y \cdot x\right)}} \cdot \frac{1}{\mathsf{hypot}\left(1, z\right)}
\] |
associate-*l/ [=>]1.73 | \[ \color{blue}{\frac{1 \cdot \frac{1}{\mathsf{hypot}\left(1, z\right)}}{\mathsf{hypot}\left(1, z\right) \cdot \left(y \cdot x\right)}}
\] |
*-lft-identity [=>]1.73 | \[ \frac{\color{blue}{\frac{1}{\mathsf{hypot}\left(1, z\right)}}}{\mathsf{hypot}\left(1, z\right) \cdot \left(y \cdot x\right)}
\] |
associate-*r* [=>]0.68 | \[ \frac{\frac{1}{\mathsf{hypot}\left(1, z\right)}}{\color{blue}{\left(\mathsf{hypot}\left(1, z\right) \cdot y\right) \cdot x}}
\] |
*-commutative [<=]0.68 | \[ \frac{\frac{1}{\mathsf{hypot}\left(1, z\right)}}{\color{blue}{\left(y \cdot \mathsf{hypot}\left(1, z\right)\right)} \cdot x}
\] |
*-commutative [=>]0.68 | \[ \frac{\frac{1}{\mathsf{hypot}\left(1, z\right)}}{\color{blue}{x \cdot \left(y \cdot \mathsf{hypot}\left(1, z\right)\right)}}
\] |
if -1.02e-98 < x Initial program 17.78
Simplified14.14
[Start]17.78 | \[ \frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}
\] |
|---|---|
associate-/l/ [=>]17.99 | \[ \color{blue}{\frac{1}{\left(y \cdot \left(1 + z \cdot z\right)\right) \cdot x}}
\] |
associate-*l* [=>]14.14 | \[ \frac{1}{\color{blue}{y \cdot \left(\left(1 + z \cdot z\right) \cdot x\right)}}
\] |
+-commutative [=>]14.14 | \[ \frac{1}{y \cdot \left(\color{blue}{\left(z \cdot z + 1\right)} \cdot x\right)}
\] |
fma-def [=>]14.14 | \[ \frac{1}{y \cdot \left(\color{blue}{\mathsf{fma}\left(z, z, 1\right)} \cdot x\right)}
\] |
Applied egg-rr14.14
Taylor expanded in x around 0 14.14
Simplified3.74
[Start]14.14 | \[ \frac{1}{y \cdot \left({z}^{2} \cdot x + x\right)}
\] |
|---|---|
unpow2 [=>]14.14 | \[ \frac{1}{y \cdot \left(\color{blue}{\left(z \cdot z\right)} \cdot x + x\right)}
\] |
associate-*l* [=>]3.74 | \[ \frac{1}{y \cdot \left(\color{blue}{z \cdot \left(z \cdot x\right)} + x\right)}
\] |
Final simplification1.95
| Alternative 1 | |
|---|---|
| Error | 3.06% |
| Cost | 13769 |
| Alternative 2 | |
|---|---|
| Error | 3.27% |
| Cost | 13636 |
| Alternative 3 | |
|---|---|
| Error | 1.82% |
| Cost | 1736 |
| Alternative 4 | |
|---|---|
| Error | 6.82% |
| Cost | 972 |
| Alternative 5 | |
|---|---|
| Error | 2.87% |
| Cost | 969 |
| Alternative 6 | |
|---|---|
| Error | 3.77% |
| Cost | 840 |
| Alternative 7 | |
|---|---|
| Error | 7.54% |
| Cost | 836 |
| Alternative 8 | |
|---|---|
| Error | 4.12% |
| Cost | 836 |
| Alternative 9 | |
|---|---|
| Error | 44.73% |
| Cost | 320 |
herbie shell --seed 2023121
(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)))))