Average Error: 15.1 → 1.5
Time: 6.7s
Precision: binary64
\[[x, y] = \mathsf{sort}([x, y]) \\]
\[\frac{x \cdot y}{\left(z \cdot z\right) \cdot \left(z + 1\right)} \]
\[\begin{array}{l} t_0 := \frac{\frac{1}{z}}{\frac{z \cdot \frac{z}{y}}{x}}\\ \mathbf{if}\;x \cdot y \leq -\infty:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \cdot y \leq -3.2880636115797007 \cdot 10^{-102}:\\ \;\;\;\;\frac{{\left(\frac{\mathsf{fma}\left(z, z, z\right)}{x \cdot y}\right)}^{-1}}{z}\\ \mathbf{elif}\;x \cdot y \leq 3.290464648854404 \cdot 10^{-127}:\\ \;\;\;\;\frac{x}{z} \cdot \frac{y}{\mathsf{fma}\left(z, z, z\right)}\\ \mathbf{elif}\;x \cdot y \leq 8.738469963482544 \cdot 10^{+280}:\\ \;\;\;\;\frac{\frac{x \cdot y}{z + {z}^{2}}}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
\frac{x \cdot y}{\left(z \cdot z\right) \cdot \left(z + 1\right)}
\begin{array}{l}
t_0 := \frac{\frac{1}{z}}{\frac{z \cdot \frac{z}{y}}{x}}\\
\mathbf{if}\;x \cdot y \leq -\infty:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \cdot y \leq -3.2880636115797007 \cdot 10^{-102}:\\
\;\;\;\;\frac{{\left(\frac{\mathsf{fma}\left(z, z, z\right)}{x \cdot y}\right)}^{-1}}{z}\\

\mathbf{elif}\;x \cdot y \leq 3.290464648854404 \cdot 10^{-127}:\\
\;\;\;\;\frac{x}{z} \cdot \frac{y}{\mathsf{fma}\left(z, z, z\right)}\\

\mathbf{elif}\;x \cdot y \leq 8.738469963482544 \cdot 10^{+280}:\\
\;\;\;\;\frac{\frac{x \cdot y}{z + {z}^{2}}}{z}\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
(FPCore (x y z) :precision binary64 (/ (* x y) (* (* z z) (+ z 1.0))))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (/ (/ 1.0 z) (/ (* z (/ z y)) x))))
   (if (<= (* x y) (- INFINITY))
     t_0
     (if (<= (* x y) -3.2880636115797007e-102)
       (/ (pow (/ (fma z z z) (* x y)) -1.0) z)
       (if (<= (* x y) 3.290464648854404e-127)
         (* (/ x z) (/ y (fma z z z)))
         (if (<= (* x y) 8.738469963482544e+280)
           (/ (/ (* x y) (+ z (pow z 2.0))) z)
           t_0))))))
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 t_0 = (1.0 / z) / ((z * (z / y)) / x);
	double tmp;
	if ((x * y) <= -((double) INFINITY)) {
		tmp = t_0;
	} else if ((x * y) <= -3.2880636115797007e-102) {
		tmp = pow((fma(z, z, z) / (x * y)), -1.0) / z;
	} else if ((x * y) <= 3.290464648854404e-127) {
		tmp = (x / z) * (y / fma(z, z, z));
	} else if ((x * y) <= 8.738469963482544e+280) {
		tmp = ((x * y) / (z + pow(z, 2.0))) / z;
	} else {
		tmp = t_0;
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original15.1
Target4.0
Herbie1.5
\[\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 4 regimes
  2. if (*.f64 x y) < -inf.0 or 8.738469963482544e280 < (*.f64 x y)

    1. Initial program 59.9

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

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

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

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

      \[\leadsto \color{blue}{\frac{\frac{1}{z}}{\frac{\frac{\mathsf{fma}\left(z, z, z\right)}{y}}{x}}} \]
    6. Taylor expanded in z around inf 22.3

      \[\leadsto \frac{\frac{1}{z}}{\frac{\color{blue}{\frac{{z}^{2}}{y}}}{x}} \]
    7. Simplified5.3

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

    if -inf.0 < (*.f64 x y) < -3.28806361157970073e-102

    1. Initial program 5.6

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

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

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

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

    if -3.28806361157970073e-102 < (*.f64 x y) < 3.290464648854404e-127

    1. Initial program 17.3

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

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

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

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

    if 3.290464648854404e-127 < (*.f64 x y) < 8.738469963482544e280

    1. Initial program 5.2

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{y \cdot x}{{z}^{2} + z}}}{z} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification1.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y \leq -\infty:\\ \;\;\;\;\frac{\frac{1}{z}}{\frac{z \cdot \frac{z}{y}}{x}}\\ \mathbf{elif}\;x \cdot y \leq -3.2880636115797007 \cdot 10^{-102}:\\ \;\;\;\;\frac{{\left(\frac{\mathsf{fma}\left(z, z, z\right)}{x \cdot y}\right)}^{-1}}{z}\\ \mathbf{elif}\;x \cdot y \leq 3.290464648854404 \cdot 10^{-127}:\\ \;\;\;\;\frac{x}{z} \cdot \frac{y}{\mathsf{fma}\left(z, z, z\right)}\\ \mathbf{elif}\;x \cdot y \leq 8.738469963482544 \cdot 10^{+280}:\\ \;\;\;\;\frac{\frac{x \cdot y}{z + {z}^{2}}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{z}}{\frac{z \cdot \frac{z}{y}}{x}}\\ \end{array} \]

Reproduce

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