Average Error: 14.7 → 3.2
Time: 11.8s
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 := \sqrt[3]{\mathsf{fma}\left(z, z, z\right)}\\ t_1 := t_0 \cdot t_0\\ \mathbf{if}\;x \cdot y \leq -1.3650421800487005 \cdot 10^{-257}:\\ \;\;\;\;\left(x \cdot \frac{\sqrt{y}}{t_1}\right) \cdot \frac{\frac{\sqrt{y}}{t_0}}{z}\\ \mathbf{elif}\;x \cdot y \leq 6.5683273668649 \cdot 10^{-238}:\\ \;\;\;\;\frac{y}{z} \cdot \left(\frac{x}{z} - x\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot \frac{\sqrt[3]{y} \cdot \sqrt[3]{y}}{t_1}\right) \cdot \frac{\frac{\sqrt[3]{y}}{t_0}}{z}\\ \end{array} \]
\frac{x \cdot y}{\left(z \cdot z\right) \cdot \left(z + 1\right)}
\begin{array}{l}
t_0 := \sqrt[3]{\mathsf{fma}\left(z, z, z\right)}\\
t_1 := t_0 \cdot t_0\\
\mathbf{if}\;x \cdot y \leq -1.3650421800487005 \cdot 10^{-257}:\\
\;\;\;\;\left(x \cdot \frac{\sqrt{y}}{t_1}\right) \cdot \frac{\frac{\sqrt{y}}{t_0}}{z}\\

\mathbf{elif}\;x \cdot y \leq 6.5683273668649 \cdot 10^{-238}:\\
\;\;\;\;\frac{y}{z} \cdot \left(\frac{x}{z} - x\right)\\

\mathbf{else}:\\
\;\;\;\;\left(x \cdot \frac{\sqrt[3]{y} \cdot \sqrt[3]{y}}{t_1}\right) \cdot \frac{\frac{\sqrt[3]{y}}{t_0}}{z}\\


\end{array}
(FPCore (x y z) :precision binary64 (/ (* x y) (* (* z z) (+ z 1.0))))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (cbrt (fma z z z))) (t_1 (* t_0 t_0)))
   (if (<= (* x y) -1.3650421800487005e-257)
     (* (* x (/ (sqrt y) t_1)) (/ (/ (sqrt y) t_0) z))
     (if (<= (* x y) 6.5683273668649e-238)
       (* (/ y z) (- (/ x z) x))
       (* (* x (/ (* (cbrt y) (cbrt y)) t_1)) (/ (/ (cbrt y) t_0) z))))))
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 = cbrt(fma(z, z, z));
	double t_1 = t_0 * t_0;
	double tmp;
	if ((x * y) <= -1.3650421800487005e-257) {
		tmp = (x * (sqrt(y) / t_1)) * ((sqrt(y) / t_0) / z);
	} else if ((x * y) <= 6.5683273668649e-238) {
		tmp = (y / z) * ((x / z) - x);
	} else {
		tmp = (x * ((cbrt(y) * cbrt(y)) / t_1)) * ((cbrt(y) / t_0) / z);
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original14.7
Target4.2
Herbie3.2
\[\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 3 regimes
  2. if (*.f64 x y) < -1.3650421800487005e-257

    1. Initial program 12.8

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

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

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

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

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

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

      \[\leadsto x \cdot \color{blue}{\left(\frac{\frac{\sqrt{y}}{\sqrt[3]{\mathsf{fma}\left(z, z, z\right)} \cdot \sqrt[3]{\mathsf{fma}\left(z, z, z\right)}}}{1} \cdot \frac{\frac{\sqrt{y}}{\sqrt[3]{\mathsf{fma}\left(z, z, z\right)}}}{z}\right)} \]
    8. Applied associate-*r*_binary643.9

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

    if -1.3650421800487005e-257 < (*.f64 x y) < 6.5683273668649002e-238

    1. Initial program 20.8

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

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

      \[\leadsto \color{blue}{\frac{y \cdot x}{{z}^{2}} - \frac{y \cdot x}{z}} \]
    4. Simplified1.2

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

    if 6.5683273668649002e-238 < (*.f64 x y)

    1. Initial program 12.9

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

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

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

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

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

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

      \[\leadsto x \cdot \color{blue}{\left(\frac{\frac{\sqrt[3]{y} \cdot \sqrt[3]{y}}{\sqrt[3]{\mathsf{fma}\left(z, z, z\right)} \cdot \sqrt[3]{\mathsf{fma}\left(z, z, z\right)}}}{1} \cdot \frac{\frac{\sqrt[3]{y}}{\sqrt[3]{\mathsf{fma}\left(z, z, z\right)}}}{z}\right)} \]
    8. Applied associate-*r*_binary643.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y \leq -1.3650421800487005 \cdot 10^{-257}:\\ \;\;\;\;\left(x \cdot \frac{\sqrt{y}}{\sqrt[3]{\mathsf{fma}\left(z, z, z\right)} \cdot \sqrt[3]{\mathsf{fma}\left(z, z, z\right)}}\right) \cdot \frac{\frac{\sqrt{y}}{\sqrt[3]{\mathsf{fma}\left(z, z, z\right)}}}{z}\\ \mathbf{elif}\;x \cdot y \leq 6.5683273668649 \cdot 10^{-238}:\\ \;\;\;\;\frac{y}{z} \cdot \left(\frac{x}{z} - x\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot \frac{\sqrt[3]{y} \cdot \sqrt[3]{y}}{\sqrt[3]{\mathsf{fma}\left(z, z, z\right)} \cdot \sqrt[3]{\mathsf{fma}\left(z, z, z\right)}}\right) \cdot \frac{\frac{\sqrt[3]{y}}{\sqrt[3]{\mathsf{fma}\left(z, z, z\right)}}}{z}\\ \end{array} \]

Reproduce

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