Average Error: 6.4 → 1.8
Time: 5.8s
Precision: binary64
\[[x, y] = \mathsf{sort}([x, y]) \\]
\[\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)} \]
\[\begin{array}{l} t_0 := \sqrt{\frac{1}{x}}\\ t_1 := y \cdot \mathsf{hypot}\left(1, z\right)\\ \mathbf{if}\;\frac{1}{x} \leq -8.457177207248513 \cdot 10^{-25}:\\ \;\;\;\;\frac{1}{t_1} \cdot \frac{\frac{1}{x}}{\mathsf{hypot}\left(1, z\right)}\\ \mathbf{elif}\;\frac{1}{x} \leq 7.441329606809936 \cdot 10^{+219}:\\ \;\;\;\;\frac{\frac{\frac{1}{x}}{y}}{\mathsf{fma}\left(z, z, 1\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0}{t_1} \cdot \frac{t_0}{\mathsf{hypot}\left(1, z\right)}\\ \end{array} \]
(FPCore (x y z) :precision binary64 (/ (/ 1.0 x) (* y (+ 1.0 (* z z)))))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (sqrt (/ 1.0 x))) (t_1 (* y (hypot 1.0 z))))
   (if (<= (/ 1.0 x) -8.457177207248513e-25)
     (* (/ 1.0 t_1) (/ (/ 1.0 x) (hypot 1.0 z)))
     (if (<= (/ 1.0 x) 7.441329606809936e+219)
       (/ (/ (/ 1.0 x) y) (fma z z 1.0))
       (* (/ t_0 t_1) (/ t_0 (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 t_0 = sqrt((1.0 / x));
	double t_1 = y * hypot(1.0, z);
	double tmp;
	if ((1.0 / x) <= -8.457177207248513e-25) {
		tmp = (1.0 / t_1) * ((1.0 / x) / hypot(1.0, z));
	} else if ((1.0 / x) <= 7.441329606809936e+219) {
		tmp = ((1.0 / x) / y) / fma(z, z, 1.0);
	} else {
		tmp = (t_0 / t_1) * (t_0 / 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)
	t_0 = sqrt(Float64(1.0 / x))
	t_1 = Float64(y * hypot(1.0, z))
	tmp = 0.0
	if (Float64(1.0 / x) <= -8.457177207248513e-25)
		tmp = Float64(Float64(1.0 / t_1) * Float64(Float64(1.0 / x) / hypot(1.0, z)));
	elseif (Float64(1.0 / x) <= 7.441329606809936e+219)
		tmp = Float64(Float64(Float64(1.0 / x) / y) / fma(z, z, 1.0));
	else
		tmp = Float64(Float64(t_0 / t_1) * Float64(t_0 / hypot(1.0, z)));
	end
	return 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[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(y * N[Sqrt[1.0 ^ 2 + z ^ 2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(1.0 / x), $MachinePrecision], -8.457177207248513e-25], N[(N[(1.0 / t$95$1), $MachinePrecision] * N[(N[(1.0 / x), $MachinePrecision] / N[Sqrt[1.0 ^ 2 + z ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / x), $MachinePrecision], 7.441329606809936e+219], N[(N[(N[(1.0 / x), $MachinePrecision] / y), $MachinePrecision] / N[(z * z + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 / t$95$1), $MachinePrecision] * N[(t$95$0 / 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}
t_0 := \sqrt{\frac{1}{x}}\\
t_1 := y \cdot \mathsf{hypot}\left(1, z\right)\\
\mathbf{if}\;\frac{1}{x} \leq -8.457177207248513 \cdot 10^{-25}:\\
\;\;\;\;\frac{1}{t_1} \cdot \frac{\frac{1}{x}}{\mathsf{hypot}\left(1, z\right)}\\

\mathbf{elif}\;\frac{1}{x} \leq 7.441329606809936 \cdot 10^{+219}:\\
\;\;\;\;\frac{\frac{\frac{1}{x}}{y}}{\mathsf{fma}\left(z, z, 1\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{t_0}{t_1} \cdot \frac{t_0}{\mathsf{hypot}\left(1, z\right)}\\


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original6.4
Target4.9
Herbie1.8
\[\begin{array}{l} \mathbf{if}\;y \cdot \left(1 + z \cdot z\right) < -\infty:\\ \;\;\;\;\frac{\frac{1}{y}}{\left(1 + z \cdot z\right) \cdot x}\\ \mathbf{elif}\;y \cdot \left(1 + z \cdot z\right) < 8.680743250567252 \cdot 10^{+305}:\\ \;\;\;\;\frac{\frac{1}{x}}{\left(1 + z \cdot z\right) \cdot y}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{y}}{\left(1 + z \cdot z\right) \cdot x}\\ \end{array} \]

Derivation

  1. Split input into 3 regimes
  2. if (/.f64 1 x) < -8.4571772072485133e-25

    1. Initial program 12.4

      \[\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)} \]
    2. Simplified12.4

      \[\leadsto \color{blue}{\frac{\frac{1}{x}}{y \cdot \mathsf{fma}\left(z, z, 1\right)}} \]
    3. Applied add-sqr-sqrt_binary6412.4

      \[\leadsto \frac{\frac{1}{x}}{y \cdot \color{blue}{\left(\sqrt{\mathsf{fma}\left(z, z, 1\right)} \cdot \sqrt{\mathsf{fma}\left(z, z, 1\right)}\right)}} \]
    4. Applied associate-*r*_binary6412.4

      \[\leadsto \frac{\frac{1}{x}}{\color{blue}{\left(y \cdot \sqrt{\mathsf{fma}\left(z, z, 1\right)}\right) \cdot \sqrt{\mathsf{fma}\left(z, z, 1\right)}}} \]
    5. Simplified12.4

      \[\leadsto \frac{\frac{1}{x}}{\color{blue}{\left(y \cdot \mathsf{hypot}\left(1, z\right)\right)} \cdot \sqrt{\mathsf{fma}\left(z, z, 1\right)}} \]
    6. Applied *-un-lft-identity_binary6412.4

      \[\leadsto \frac{\frac{1}{\color{blue}{1 \cdot x}}}{\left(y \cdot \mathsf{hypot}\left(1, z\right)\right) \cdot \sqrt{\mathsf{fma}\left(z, z, 1\right)}} \]
    7. Applied add-cube-cbrt_binary6412.4

      \[\leadsto \frac{\frac{\color{blue}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}}{1 \cdot x}}{\left(y \cdot \mathsf{hypot}\left(1, z\right)\right) \cdot \sqrt{\mathsf{fma}\left(z, z, 1\right)}} \]
    8. Applied times-frac_binary6412.4

      \[\leadsto \frac{\color{blue}{\frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{1} \cdot \frac{\sqrt[3]{1}}{x}}}{\left(y \cdot \mathsf{hypot}\left(1, z\right)\right) \cdot \sqrt{\mathsf{fma}\left(z, z, 1\right)}} \]
    9. Applied times-frac_binary6411.0

      \[\leadsto \color{blue}{\frac{\frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{1}}{y \cdot \mathsf{hypot}\left(1, z\right)} \cdot \frac{\frac{\sqrt[3]{1}}{x}}{\sqrt{\mathsf{fma}\left(z, z, 1\right)}}} \]
    10. Simplified11.0

      \[\leadsto \color{blue}{\frac{1}{y \cdot \mathsf{hypot}\left(1, z\right)}} \cdot \frac{\frac{\sqrt[3]{1}}{x}}{\sqrt{\mathsf{fma}\left(z, z, 1\right)}} \]
    11. Simplified1.5

      \[\leadsto \frac{1}{y \cdot \mathsf{hypot}\left(1, z\right)} \cdot \color{blue}{\frac{\frac{1}{x}}{\mathsf{hypot}\left(1, z\right)}} \]

    if -8.4571772072485133e-25 < (/.f64 1 x) < 7.4413296068099356e219

    1. Initial program 2.4

      \[\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)} \]
    2. Simplified2.4

      \[\leadsto \color{blue}{\frac{\frac{1}{x}}{y \cdot \mathsf{fma}\left(z, z, 1\right)}} \]
    3. Applied associate-/r*_binary641.8

      \[\leadsto \color{blue}{\frac{\frac{\frac{1}{x}}{y}}{\mathsf{fma}\left(z, z, 1\right)}} \]

    if 7.4413296068099356e219 < (/.f64 1 x)

    1. Initial program 19.6

      \[\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)} \]
    2. Simplified19.6

      \[\leadsto \color{blue}{\frac{\frac{1}{x}}{y \cdot \mathsf{fma}\left(z, z, 1\right)}} \]
    3. Applied add-sqr-sqrt_binary6419.6

      \[\leadsto \frac{\frac{1}{x}}{y \cdot \color{blue}{\left(\sqrt{\mathsf{fma}\left(z, z, 1\right)} \cdot \sqrt{\mathsf{fma}\left(z, z, 1\right)}\right)}} \]
    4. Applied associate-*r*_binary6419.6

      \[\leadsto \frac{\frac{1}{x}}{\color{blue}{\left(y \cdot \sqrt{\mathsf{fma}\left(z, z, 1\right)}\right) \cdot \sqrt{\mathsf{fma}\left(z, z, 1\right)}}} \]
    5. Simplified19.6

      \[\leadsto \frac{\frac{1}{x}}{\color{blue}{\left(y \cdot \mathsf{hypot}\left(1, z\right)\right)} \cdot \sqrt{\mathsf{fma}\left(z, z, 1\right)}} \]
    6. Applied add-sqr-sqrt_binary6419.8

      \[\leadsto \frac{\color{blue}{\sqrt{\frac{1}{x}} \cdot \sqrt{\frac{1}{x}}}}{\left(y \cdot \mathsf{hypot}\left(1, z\right)\right) \cdot \sqrt{\mathsf{fma}\left(z, z, 1\right)}} \]
    7. Applied times-frac_binary6416.4

      \[\leadsto \color{blue}{\frac{\sqrt{\frac{1}{x}}}{y \cdot \mathsf{hypot}\left(1, z\right)} \cdot \frac{\sqrt{\frac{1}{x}}}{\sqrt{\mathsf{fma}\left(z, z, 1\right)}}} \]
    8. Simplified4.3

      \[\leadsto \frac{\sqrt{\frac{1}{x}}}{y \cdot \mathsf{hypot}\left(1, z\right)} \cdot \color{blue}{\frac{\sqrt{\frac{1}{x}}}{\mathsf{hypot}\left(1, z\right)}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification1.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1}{x} \leq -8.457177207248513 \cdot 10^{-25}:\\ \;\;\;\;\frac{1}{y \cdot \mathsf{hypot}\left(1, z\right)} \cdot \frac{\frac{1}{x}}{\mathsf{hypot}\left(1, z\right)}\\ \mathbf{elif}\;\frac{1}{x} \leq 7.441329606809936 \cdot 10^{+219}:\\ \;\;\;\;\frac{\frac{\frac{1}{x}}{y}}{\mathsf{fma}\left(z, z, 1\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\frac{1}{x}}}{y \cdot \mathsf{hypot}\left(1, z\right)} \cdot \frac{\sqrt{\frac{1}{x}}}{\mathsf{hypot}\left(1, z\right)}\\ \end{array} \]

Reproduce

herbie shell --seed 2022131 
(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)))))