Average Error: 14.6 → 2.7
Time: 3.6s
Precision: binary64
\[\frac{x \cdot y}{\left(z \cdot z\right) \cdot \left(z + 1\right)} \]
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot y}{\left(z \cdot z\right) \cdot \left(z + 1\right)} \leq 1.9691177182928483 \cdot 10^{+301}:\\ \;\;\;\;\frac{x \cdot \frac{y}{z}}{\mathsf{fma}\left(z, z, z\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{y}{z}}{\mathsf{fma}\left(\frac{z}{x}, z, \frac{z}{x}\right)}\\ \end{array} \]
(FPCore (x y z) :precision binary64 (/ (* x y) (* (* z z) (+ z 1.0))))
(FPCore (x y z)
 :precision binary64
 (if (<= (/ (* x y) (* (* z z) (+ z 1.0))) 1.9691177182928483e+301)
   (/ (* x (/ y z)) (fma z z z))
   (/ (/ y z) (fma (/ z x) z (/ z x)))))
double code(double x, double y, double z) {
	return (x * y) / ((z * z) * (z + 1.0));
}
double code(double x, double y, double z) {
	double tmp;
	if (((x * y) / ((z * z) * (z + 1.0))) <= 1.9691177182928483e+301) {
		tmp = (x * (y / z)) / fma(z, z, z);
	} else {
		tmp = (y / z) / fma((z / x), z, (z / x));
	}
	return tmp;
}
function code(x, y, z)
	return Float64(Float64(x * y) / Float64(Float64(z * z) * Float64(z + 1.0)))
end
function code(x, y, z)
	tmp = 0.0
	if (Float64(Float64(x * y) / Float64(Float64(z * z) * Float64(z + 1.0))) <= 1.9691177182928483e+301)
		tmp = Float64(Float64(x * Float64(y / z)) / fma(z, z, z));
	else
		tmp = Float64(Float64(y / z) / fma(Float64(z / x), z, Float64(z / x)));
	end
	return tmp
end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] / N[(N[(z * z), $MachinePrecision] * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := If[LessEqual[N[(N[(x * y), $MachinePrecision] / N[(N[(z * z), $MachinePrecision] * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.9691177182928483e+301], N[(N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision] / N[(z * z + z), $MachinePrecision]), $MachinePrecision], N[(N[(y / z), $MachinePrecision] / N[(N[(z / x), $MachinePrecision] * z + N[(z / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\frac{x \cdot y}{\left(z \cdot z\right) \cdot \left(z + 1\right)}
\begin{array}{l}
\mathbf{if}\;\frac{x \cdot y}{\left(z \cdot z\right) \cdot \left(z + 1\right)} \leq 1.9691177182928483 \cdot 10^{+301}:\\
\;\;\;\;\frac{x \cdot \frac{y}{z}}{\mathsf{fma}\left(z, z, z\right)}\\

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


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original14.6
Target4.2
Herbie2.7
\[\begin{array}{l} \mathbf{if}\;z < 249.6182814532307:\\ \;\;\;\;\frac{y \cdot \frac{x}{z}}{z + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\frac{y}{z}}{1 + z} \cdot x}{z}\\ \end{array} \]

Derivation

  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 x y) (*.f64 (*.f64 z z) (+.f64 z 1))) < 1.96911771829284827e301

    1. Initial program 7.5

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

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

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

    if 1.96911771829284827e301 < (/.f64 (*.f64 x y) (*.f64 (*.f64 z z) (+.f64 z 1)))

    1. Initial program 63.3

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

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

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

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

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

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

Reproduce

herbie shell --seed 2022153 
(FPCore (x y z)
  :name "Statistics.Distribution.Beta:$cvariance from math-functions-0.1.5.2"
  :precision binary64

  :herbie-target
  (if (< z 249.6182814532307) (/ (* y (/ x z)) (+ z (* z z))) (/ (* (/ (/ y z) (+ 1.0 z)) x) z))

  (/ (* x y) (* (* z z) (+ z 1.0))))