Average Error: 6.5 → 1.6
Time: 3.5s
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{y} \cdot \mathsf{hypot}\left(1, z\right)\\ \mathbf{if}\;y \cdot \left(1 + z \cdot z\right) \leq 4.9570759986999974 \cdot 10^{+263}:\\ \;\;\;\;\frac{\frac{1}{y \cdot \mathsf{fma}\left(z, z, 1\right)}}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\frac{1}{x}}{t_0}}{t_0}\\ \end{array} \]
\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}
\begin{array}{l}
t_0 := \sqrt{y} \cdot \mathsf{hypot}\left(1, z\right)\\
\mathbf{if}\;y \cdot \left(1 + z \cdot z\right) \leq 4.9570759986999974 \cdot 10^{+263}:\\
\;\;\;\;\frac{\frac{1}{y \cdot \mathsf{fma}\left(z, z, 1\right)}}{x}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{\frac{1}{x}}{t_0}}{t_0}\\


\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 y) (hypot 1.0 z))))
   (if (<= (* y (+ 1.0 (* z z))) 4.9570759986999974e+263)
     (/ (/ 1.0 (* y (fma z z 1.0))) x)
     (/ (/ (/ 1.0 x) t_0) t_0))))
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(y) * hypot(1.0, z);
	double tmp;
	if ((y * (1.0 + (z * z))) <= 4.9570759986999974e+263) {
		tmp = (1.0 / (y * fma(z, z, 1.0))) / x;
	} else {
		tmp = ((1.0 / x) / t_0) / t_0;
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original6.5
Target5.1
Herbie1.6
\[\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 2 regimes
  2. if (*.f64 y (+.f64 1 (*.f64 z z))) < 4.95707599869999736e263

    1. Initial program 2.3

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

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

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

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

    if 4.95707599869999736e263 < (*.f64 y (+.f64 1 (*.f64 z z)))

    1. Initial program 15.8

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

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

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

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

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

Reproduce

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