Average Error: 6.2 → 3.3
Time: 5.0s
Precision: binary64
\[[x, y] = \mathsf{sort}([x, y]) \\]
\[\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)} \]
\[\begin{array}{l} \mathbf{if}\;y \leq 1.3416652531759415 \cdot 10^{-303}:\\ \;\;\;\;\frac{\frac{1}{x}}{y + y \cdot {z}^{2}}\\ \mathbf{elif}\;y \leq 8.980294761979465 \cdot 10^{-80}:\\ \;\;\;\;\begin{array}{l} t_0 := \sqrt{y} \cdot \mathsf{hypot}\left(1, z\right)\\ \frac{\frac{1}{x}}{t_0 \cdot t_0} \end{array}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{\mathsf{fma}\left(x, z \cdot z, x\right)}}{y}\\ \end{array} \]
\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}
\begin{array}{l}
\mathbf{if}\;y \leq 1.3416652531759415 \cdot 10^{-303}:\\
\;\;\;\;\frac{\frac{1}{x}}{y + y \cdot {z}^{2}}\\

\mathbf{elif}\;y \leq 8.980294761979465 \cdot 10^{-80}:\\
\;\;\;\;\begin{array}{l}
t_0 := \sqrt{y} \cdot \mathsf{hypot}\left(1, z\right)\\
\frac{\frac{1}{x}}{t_0 \cdot t_0}
\end{array}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{\mathsf{fma}\left(x, z \cdot z, x\right)}}{y}\\


\end{array}
(FPCore (x y z) :precision binary64 (/ (/ 1.0 x) (* y (+ 1.0 (* z z)))))
(FPCore (x y z)
 :precision binary64
 (if (<= y 1.3416652531759415e-303)
   (/ (/ 1.0 x) (+ y (* y (pow z 2.0))))
   (if (<= y 8.980294761979465e-80)
     (let* ((t_0 (* (sqrt y) (hypot 1.0 z)))) (/ (/ 1.0 x) (* t_0 t_0)))
     (/ (/ 1.0 (fma x (* z z) x)) y))))
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 (y <= 1.3416652531759415e-303) {
		tmp = (1.0 / x) / (y + (y * pow(z, 2.0)));
	} else if (y <= 8.980294761979465e-80) {
		double t_0 = sqrt(y) * hypot(1.0, z);
		tmp = (1.0 / x) / (t_0 * t_0);
	} else {
		tmp = (1.0 / fma(x, (z * z), x)) / y;
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original6.2
Target4.9
Herbie3.3
\[\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 y < 1.34166525317594154e-303

    1. Initial program 4.7

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

      \[\leadsto \color{blue}{\frac{\frac{1}{x}}{y \cdot \mathsf{fma}\left(z, z, 1\right)}} \]
    3. Taylor expanded in z around 0 4.7

      \[\leadsto \frac{\frac{1}{x}}{\color{blue}{y + y \cdot {z}^{2}}} \]

    if 1.34166525317594154e-303 < y < 8.98029476197946492e-80

    1. Initial program 13.7

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

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

      \[\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 add-sqr-sqrt_binary6413.9

      \[\leadsto \frac{\frac{1}{x}}{\color{blue}{\left(\sqrt{y} \cdot \sqrt{y}\right)} \cdot \left(\sqrt{\mathsf{fma}\left(z, z, 1\right)} \cdot \sqrt{\mathsf{fma}\left(z, z, 1\right)}\right)} \]
    5. Applied unswap-sqr_binary6413.9

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

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

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

    if 8.98029476197946492e-80 < y

    1. Initial program 4.5

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

      \[\leadsto \color{blue}{\frac{\frac{1}{x}}{y \cdot \mathsf{fma}\left(z, z, 1\right)}} \]
    3. Applied *-un-lft-identity_binary644.5

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

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

      \[\leadsto \frac{\color{blue}{\frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{1} \cdot \frac{\sqrt[3]{1}}{x}}}{y \cdot \mathsf{fma}\left(z, z, 1\right)} \]
    6. Applied times-frac_binary642.2

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

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

      \[\leadsto \frac{1}{y} \cdot \color{blue}{\frac{1}{\mathsf{fma}\left(z, z, 1\right) \cdot x}} \]
    9. Applied associate-*l/_binary642.2

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

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

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

Reproduce

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