| Alternative 1 | |
|---|---|
| Error | 1.9 |
| Cost | 13504 |
\[\frac{1}{\mathsf{hypot}\left(1, z\right) \cdot \left(\left(\mathsf{hypot}\left(1, z\right) \cdot y\right) \cdot x\right)}
\]
(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 (- INFINITY))
(/ (/ 1.0 (* z (* z y))) x)
(if (<= t_0 2e+306) (/ (/ 1.0 x) t_0) (/ (/ (/ 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 t_0 = y * (1.0 + (z * z));
double tmp;
if (t_0 <= -((double) INFINITY)) {
tmp = (1.0 / (z * (z * y))) / x;
} else if (t_0 <= 2e+306) {
tmp = (1.0 / x) / t_0;
} else {
tmp = ((1.0 / y) / (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 t_0 = y * (1.0 + (z * z));
double tmp;
if (t_0 <= -Double.POSITIVE_INFINITY) {
tmp = (1.0 / (z * (z * y))) / x;
} else if (t_0 <= 2e+306) {
tmp = (1.0 / x) / t_0;
} 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): t_0 = y * (1.0 + (z * z)) tmp = 0 if t_0 <= -math.inf: tmp = (1.0 / (z * (z * y))) / x elif t_0 <= 2e+306: tmp = (1.0 / x) / t_0 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) t_0 = Float64(y * Float64(1.0 + Float64(z * z))) tmp = 0.0 if (t_0 <= Float64(-Inf)) tmp = Float64(Float64(1.0 / Float64(z * Float64(z * y))) / x); elseif (t_0 <= 2e+306) tmp = Float64(Float64(1.0 / x) / t_0); else tmp = Float64(Float64(Float64(1.0 / y) / Float64(z * 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) t_0 = y * (1.0 + (z * z)); tmp = 0.0; if (t_0 <= -Inf) tmp = (1.0 / (z * (z * y))) / x; elseif (t_0 <= 2e+306) tmp = (1.0 / x) / t_0; 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_] := Block[{t$95$0 = N[(y * N[(1.0 + N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(N[(1.0 / N[(z * N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], If[LessEqual[t$95$0, 2e+306], N[(N[(1.0 / x), $MachinePrecision] / t$95$0), $MachinePrecision], N[(N[(N[(1.0 / y), $MachinePrecision] / N[(z * x), $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 -\infty:\\
\;\;\;\;\frac{\frac{1}{z \cdot \left(z \cdot y\right)}}{x}\\
\mathbf{elif}\;t_0 \leq 2 \cdot 10^{+306}:\\
\;\;\;\;\frac{\frac{1}{x}}{t_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\frac{1}{y}}{z \cdot x}}{z}\\
\end{array}
Results
| Original | 6.6 |
|---|---|
| Target | 5.3 |
| Herbie | 0.7 |
if (*.f64 y (+.f64 1 (*.f64 z z))) < -inf.0Initial program 17.2
Taylor expanded in z around inf 17.2
Simplified2.6
[Start]17.2 | \[ \frac{1}{y \cdot \left({z}^{2} \cdot x\right)}
\] |
|---|---|
associate-*r* [=>]17.2 | \[ \frac{1}{\color{blue}{\left(y \cdot {z}^{2}\right) \cdot x}}
\] |
*-commutative [=>]17.2 | \[ \frac{1}{\color{blue}{\left({z}^{2} \cdot y\right)} \cdot x}
\] |
unpow2 [=>]17.2 | \[ \frac{1}{\left(\color{blue}{\left(z \cdot z\right)} \cdot y\right) \cdot x}
\] |
associate-*r* [<=]2.9 | \[ \frac{1}{\color{blue}{\left(z \cdot \left(z \cdot y\right)\right)} \cdot x}
\] |
associate-/r* [=>]2.6 | \[ \color{blue}{\frac{\frac{1}{z \cdot \left(z \cdot y\right)}}{x}}
\] |
if -inf.0 < (*.f64 y (+.f64 1 (*.f64 z z))) < 2.00000000000000003e306Initial program 0.3
if 2.00000000000000003e306 < (*.f64 y (+.f64 1 (*.f64 z z))) Initial program 19.0
Simplified14.5
[Start]19.0 | \[ \frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}
\] |
|---|---|
associate-/r* [=>]14.5 | \[ \color{blue}{\frac{\frac{\frac{1}{x}}{y}}{1 + z \cdot z}}
\] |
Taylor expanded in z around inf 14.8
Simplified14.9
[Start]14.8 | \[ \frac{1}{y \cdot \left({z}^{2} \cdot x\right)}
\] |
|---|---|
*-commutative [=>]14.8 | \[ \frac{1}{\color{blue}{\left({z}^{2} \cdot x\right) \cdot y}}
\] |
associate-*l* [=>]14.9 | \[ \frac{1}{\color{blue}{{z}^{2} \cdot \left(x \cdot y\right)}}
\] |
unpow2 [=>]14.9 | \[ \frac{1}{\color{blue}{\left(z \cdot z\right)} \cdot \left(x \cdot y\right)}
\] |
*-commutative [<=]14.9 | \[ \frac{1}{\left(z \cdot z\right) \cdot \color{blue}{\left(y \cdot x\right)}}
\] |
Applied egg-rr6.7
Taylor expanded in z around 0 14.8
Simplified1.3
[Start]14.8 | \[ \frac{1}{y \cdot \left({z}^{2} \cdot x\right)}
\] |
|---|---|
associate-/r* [=>]14.7 | \[ \color{blue}{\frac{\frac{1}{y}}{{z}^{2} \cdot x}}
\] |
unpow2 [=>]14.7 | \[ \frac{\frac{1}{y}}{\color{blue}{\left(z \cdot z\right)} \cdot x}
\] |
associate-*l* [=>]5.7 | \[ \frac{\frac{1}{y}}{\color{blue}{z \cdot \left(z \cdot x\right)}}
\] |
associate-/l/ [<=]1.3 | \[ \color{blue}{\frac{\frac{\frac{1}{y}}{z \cdot x}}{z}}
\] |
associate-/r* [<=]1.3 | \[ \frac{\color{blue}{\frac{1}{y \cdot \left(z \cdot x\right)}}}{z}
\] |
Applied egg-rr14.1
Simplified1.3
[Start]14.1 | \[ \frac{e^{\mathsf{log1p}\left(\frac{\frac{\frac{1}{y}}{z}}{x}\right)} - 1}{z}
\] |
|---|---|
expm1-def [=>]8.5 | \[ \frac{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\frac{\frac{1}{y}}{z}}{x}\right)\right)}}{z}
\] |
expm1-log1p [=>]3.2 | \[ \frac{\color{blue}{\frac{\frac{\frac{1}{y}}{z}}{x}}}{z}
\] |
associate-/r* [<=]1.3 | \[ \frac{\color{blue}{\frac{\frac{1}{y}}{z \cdot x}}}{z}
\] |
Final simplification0.7
| Alternative 1 | |
|---|---|
| Error | 1.9 |
| Cost | 13504 |
| Alternative 2 | |
|---|---|
| Error | 2.5 |
| Cost | 972 |
| Alternative 3 | |
|---|---|
| Error | 2.4 |
| Cost | 972 |
| Alternative 4 | |
|---|---|
| Error | 1.7 |
| Cost | 969 |
| Alternative 5 | |
|---|---|
| Error | 4.5 |
| Cost | 841 |
| Alternative 6 | |
|---|---|
| Error | 4.3 |
| Cost | 841 |
| Alternative 7 | |
|---|---|
| Error | 2.2 |
| Cost | 840 |
| Alternative 8 | |
|---|---|
| Error | 2.2 |
| Cost | 840 |
| Alternative 9 | |
|---|---|
| Error | 28.6 |
| Cost | 580 |
| Alternative 10 | |
|---|---|
| Error | 29.4 |
| Cost | 320 |
herbie shell --seed 2023010
(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)))))