Average Error: 6.2 → 0.4
Time: 3.0s
Precision: binary64
\[ \begin{array}{c}[x, y] = \mathsf{sort}([x, y])\\ \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 5 \cdot 10^{+297}:\\ \;\;\;\;\frac{\frac{-1}{x}}{-\mathsf{fma}\left(z, y \cdot z, y\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{t_0} \cdot \frac{\frac{1}{x}}{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))) 5e+297)
     (/ (/ -1.0 x) (- (fma z (* y z) y)))
     (* (/ 1.0 t_0) (/ (/ 1.0 x) 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))) <= 5e+297) {
		tmp = (-1.0 / x) / -fma(z, (y * z), y);
	} else {
		tmp = (1.0 / t_0) * ((1.0 / x) / t_0);
	}
	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(sqrt(y) * hypot(1.0, z))
	tmp = 0.0
	if (Float64(y * Float64(1.0 + Float64(z * z))) <= 5e+297)
		tmp = Float64(Float64(-1.0 / x) / Float64(-fma(z, Float64(y * z), y)));
	else
		tmp = Float64(Float64(1.0 / t_0) * Float64(Float64(1.0 / x) / t_0));
	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[(N[Sqrt[y], $MachinePrecision] * N[Sqrt[1.0 ^ 2 + z ^ 2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(y * N[(1.0 + N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e+297], N[(N[(-1.0 / x), $MachinePrecision] / (-N[(z * N[(y * z), $MachinePrecision] + y), $MachinePrecision])), $MachinePrecision], N[(N[(1.0 / t$95$0), $MachinePrecision] * N[(N[(1.0 / x), $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision]]]
\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 5 \cdot 10^{+297}:\\
\;\;\;\;\frac{\frac{-1}{x}}{-\mathsf{fma}\left(z, y \cdot z, y\right)}\\

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


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original6.2
Target5.0
Herbie0.4
\[\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.9999999999999998e297

    1. Initial program 1.9

      \[\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)} \]
    2. Applied egg-rr0.5

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

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

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

    if 4.9999999999999998e297 < (*.f64 y (+.f64 1 (*.f64 z z)))

    1. Initial program 18.0

      \[\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)} \]
    2. Applied egg-rr0.2

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

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

Reproduce

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