Average Error: 14.0 → 0.8
Time: 12.4s
Precision: binary64
Cost: 8016
\[ \begin{array}{c}[x, y] = \mathsf{sort}([x, y])\\ \end{array} \]
\[\frac{x \cdot y}{\left(z \cdot z\right) \cdot \left(z + 1\right)} \]
\[\begin{array}{l} t_0 := \frac{\frac{x \cdot y}{\mathsf{fma}\left(z, z, z\right)}}{z}\\ \mathbf{if}\;x \cdot y \leq -\infty:\\ \;\;\;\;\frac{\frac{y}{z} \cdot \frac{x}{z}}{z}\\ \mathbf{elif}\;x \cdot y \leq -1 \cdot 10^{-270}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \cdot y \leq 4 \cdot 10^{-314}:\\ \;\;\;\;\frac{\frac{x}{\mathsf{fma}\left(z, z, z\right)}}{\frac{z}{y}}\\ \mathbf{elif}\;x \cdot y \leq 2 \cdot 10^{+179}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{z}}{z \cdot \frac{z + 1}{y}}\\ \end{array} \]
(FPCore (x y z) :precision binary64 (/ (* x y) (* (* z z) (+ z 1.0))))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (/ (/ (* x y) (fma z z z)) z)))
   (if (<= (* x y) (- INFINITY))
     (/ (* (/ y z) (/ x z)) z)
     (if (<= (* x y) -1e-270)
       t_0
       (if (<= (* x y) 4e-314)
         (/ (/ x (fma z z z)) (/ z y))
         (if (<= (* x y) 2e+179) t_0 (/ (/ x z) (* z (/ (+ z 1.0) y)))))))))
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 = ((x * y) / fma(z, z, z)) / z;
	double tmp;
	if ((x * y) <= -((double) INFINITY)) {
		tmp = ((y / z) * (x / z)) / z;
	} else if ((x * y) <= -1e-270) {
		tmp = t_0;
	} else if ((x * y) <= 4e-314) {
		tmp = (x / fma(z, z, z)) / (z / y);
	} else if ((x * y) <= 2e+179) {
		tmp = t_0;
	} else {
		tmp = (x / z) / (z * ((z + 1.0) / y));
	}
	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)
	t_0 = Float64(Float64(Float64(x * y) / fma(z, z, z)) / z)
	tmp = 0.0
	if (Float64(x * y) <= Float64(-Inf))
		tmp = Float64(Float64(Float64(y / z) * Float64(x / z)) / z);
	elseif (Float64(x * y) <= -1e-270)
		tmp = t_0;
	elseif (Float64(x * y) <= 4e-314)
		tmp = Float64(Float64(x / fma(z, z, z)) / Float64(z / y));
	elseif (Float64(x * y) <= 2e+179)
		tmp = t_0;
	else
		tmp = Float64(Float64(x / z) / Float64(z * Float64(Float64(z + 1.0) / y)));
	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_] := Block[{t$95$0 = N[(N[(N[(x * y), $MachinePrecision] / N[(z * z + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]}, If[LessEqual[N[(x * y), $MachinePrecision], (-Infinity)], N[(N[(N[(y / z), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], -1e-270], t$95$0, If[LessEqual[N[(x * y), $MachinePrecision], 4e-314], N[(N[(x / N[(z * z + z), $MachinePrecision]), $MachinePrecision] / N[(z / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 2e+179], t$95$0, N[(N[(x / z), $MachinePrecision] / N[(z * N[(N[(z + 1.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\frac{x \cdot y}{\left(z \cdot z\right) \cdot \left(z + 1\right)}
\begin{array}{l}
t_0 := \frac{\frac{x \cdot y}{\mathsf{fma}\left(z, z, z\right)}}{z}\\
\mathbf{if}\;x \cdot y \leq -\infty:\\
\;\;\;\;\frac{\frac{y}{z} \cdot \frac{x}{z}}{z}\\

\mathbf{elif}\;x \cdot y \leq -1 \cdot 10^{-270}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;x \cdot y \leq 2 \cdot 10^{+179}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{x}{z}}{z \cdot \frac{z + 1}{y}}\\


\end{array}

Error

Target

Original14.0
Target4.0
Herbie0.8
\[\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

    1. Initial program 64.0

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

      \[\leadsto \color{blue}{\frac{y}{z} \cdot \frac{x}{\mathsf{fma}\left(z, z, z\right)}} \]
      Proof
      (*.f64 (/.f64 y z) (/.f64 x (fma.f64 z z z))): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 y z) (/.f64 x (fma.f64 z z (Rewrite<= *-lft-identity_binary64 (*.f64 1 z))))): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 y z) (/.f64 x (Rewrite<= fma-def_binary64 (+.f64 (*.f64 z z) (*.f64 1 z))))): 1 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 y z) (/.f64 x (Rewrite<= distribute-rgt-in_binary64 (*.f64 z (+.f64 z 1))))): 0 points increase in error, 2 points decrease in error
      (Rewrite<= times-frac_binary64 (/.f64 (*.f64 y x) (*.f64 z (*.f64 z (+.f64 z 1))))): 68 points increase in error, 31 points decrease in error
      (/.f64 (Rewrite<= *-commutative_binary64 (*.f64 x y)) (*.f64 z (*.f64 z (+.f64 z 1)))): 0 points increase in error, 0 points decrease in error
      (/.f64 (*.f64 x y) (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 z z) (+.f64 z 1)))): 2 points increase in error, 4 points decrease in error
    3. Applied egg-rr64.0

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

      \[\leadsto \frac{\color{blue}{\frac{y \cdot x}{{z}^{2}}}}{z} \]
    5. Simplified5.9

      \[\leadsto \frac{\color{blue}{\frac{y}{z \cdot \frac{z}{x}}}}{z} \]
      Proof
      (/.f64 y (*.f64 z (/.f64 z x))): 0 points increase in error, 0 points decrease in error
      (/.f64 y (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 z z) x))): 26 points increase in error, 29 points decrease in error
      (/.f64 y (/.f64 (Rewrite<= unpow2_binary64 (pow.f64 z 2)) x)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 y x) (pow.f64 z 2))): 57 points increase in error, 17 points decrease in error
    6. Applied egg-rr4.4

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

    if -inf.0 < (*.f64 x y) < -1e-270 or 3.9999999999e-314 < (*.f64 x y) < 1.99999999999999996e179

    1. Initial program 6.8

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

      \[\leadsto \color{blue}{\frac{y}{z} \cdot \frac{x}{\mathsf{fma}\left(z, z, z\right)}} \]
      Proof
      (*.f64 (/.f64 y z) (/.f64 x (fma.f64 z z z))): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 y z) (/.f64 x (fma.f64 z z (Rewrite<= *-lft-identity_binary64 (*.f64 1 z))))): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 y z) (/.f64 x (Rewrite<= fma-def_binary64 (+.f64 (*.f64 z z) (*.f64 1 z))))): 1 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 y z) (/.f64 x (Rewrite<= distribute-rgt-in_binary64 (*.f64 z (+.f64 z 1))))): 0 points increase in error, 2 points decrease in error
      (Rewrite<= times-frac_binary64 (/.f64 (*.f64 y x) (*.f64 z (*.f64 z (+.f64 z 1))))): 68 points increase in error, 31 points decrease in error
      (/.f64 (Rewrite<= *-commutative_binary64 (*.f64 x y)) (*.f64 z (*.f64 z (+.f64 z 1)))): 0 points increase in error, 0 points decrease in error
      (/.f64 (*.f64 x y) (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 z z) (+.f64 z 1)))): 2 points increase in error, 4 points decrease in error
    3. Applied egg-rr0.6

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

    if -1e-270 < (*.f64 x y) < 3.9999999999e-314

    1. Initial program 22.4

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

      \[\leadsto \color{blue}{\frac{y}{z} \cdot \frac{x}{\mathsf{fma}\left(z, z, z\right)}} \]
      Proof
      (*.f64 (/.f64 y z) (/.f64 x (fma.f64 z z z))): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 y z) (/.f64 x (fma.f64 z z (Rewrite<= *-lft-identity_binary64 (*.f64 1 z))))): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 y z) (/.f64 x (Rewrite<= fma-def_binary64 (+.f64 (*.f64 z z) (*.f64 1 z))))): 1 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 y z) (/.f64 x (Rewrite<= distribute-rgt-in_binary64 (*.f64 z (+.f64 z 1))))): 0 points increase in error, 2 points decrease in error
      (Rewrite<= times-frac_binary64 (/.f64 (*.f64 y x) (*.f64 z (*.f64 z (+.f64 z 1))))): 68 points increase in error, 31 points decrease in error
      (/.f64 (Rewrite<= *-commutative_binary64 (*.f64 x y)) (*.f64 z (*.f64 z (+.f64 z 1)))): 0 points increase in error, 0 points decrease in error
      (/.f64 (*.f64 x y) (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 z z) (+.f64 z 1)))): 2 points increase in error, 4 points decrease in error
    3. Applied egg-rr0.1

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

    if 1.99999999999999996e179 < (*.f64 x y)

    1. Initial program 35.2

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

      \[\leadsto \color{blue}{\frac{y}{z + 1} \cdot \left(x \cdot {z}^{-2}\right)} \]
    3. Taylor expanded in x around 0 11.2

      \[\leadsto \frac{y}{z + 1} \cdot \color{blue}{\frac{x}{{z}^{2}}} \]
    4. Simplified11.2

      \[\leadsto \frac{y}{z + 1} \cdot \color{blue}{\frac{x}{z \cdot z}} \]
      Proof
      (/.f64 x (*.f64 z z)): 0 points increase in error, 0 points decrease in error
      (/.f64 x (Rewrite<= unpow2_binary64 (pow.f64 z 2))): 0 points increase in error, 0 points decrease in error
    5. Applied egg-rr2.0

      \[\leadsto \color{blue}{\frac{\frac{x}{z}}{\frac{z + 1}{y} \cdot z}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification0.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y \leq -\infty:\\ \;\;\;\;\frac{\frac{y}{z} \cdot \frac{x}{z}}{z}\\ \mathbf{elif}\;x \cdot y \leq -1 \cdot 10^{-270}:\\ \;\;\;\;\frac{\frac{x \cdot y}{\mathsf{fma}\left(z, z, z\right)}}{z}\\ \mathbf{elif}\;x \cdot y \leq 4 \cdot 10^{-314}:\\ \;\;\;\;\frac{\frac{x}{\mathsf{fma}\left(z, z, z\right)}}{\frac{z}{y}}\\ \mathbf{elif}\;x \cdot y \leq 2 \cdot 10^{+179}:\\ \;\;\;\;\frac{\frac{x \cdot y}{\mathsf{fma}\left(z, z, z\right)}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{z}}{z \cdot \frac{z + 1}{y}}\\ \end{array} \]

Alternatives

Alternative 1
Error0.8
Cost8016
\[\begin{array}{l} t_0 := \frac{\frac{x \cdot y}{\mathsf{fma}\left(z, z, z\right)}}{z}\\ t_1 := \frac{y}{z} \cdot \frac{x}{z}\\ \mathbf{if}\;x \cdot y \leq -\infty:\\ \;\;\;\;\frac{t_1}{z}\\ \mathbf{elif}\;x \cdot y \leq -4 \cdot 10^{-280}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \cdot y \leq 4 \cdot 10^{-314}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \cdot y \leq 2 \cdot 10^{+179}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{z}}{z \cdot \frac{z + 1}{y}}\\ \end{array} \]
Alternative 2
Error2.8
Cost1224
\[\begin{array}{l} t_0 := \frac{\frac{x}{z}}{z \cdot \frac{z + 1}{y}}\\ \mathbf{if}\;x \cdot y \leq 10^{-57}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \cdot y \leq 2 \cdot 10^{+179}:\\ \;\;\;\;\frac{x \cdot y}{\left(z + 1\right) \cdot \left(z \cdot z\right)}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error5.2
Cost840
\[\begin{array}{l} t_0 := \frac{x \cdot \frac{\frac{y}{z}}{z}}{z}\\ \mathbf{if}\;z \leq -2718407729970204700:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;\frac{\frac{x}{z}}{\frac{z}{y}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error5.0
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -2718407729970204700:\\ \;\;\;\;\frac{\frac{y}{z} \cdot \frac{x}{z}}{z}\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;\frac{\frac{x}{z}}{\frac{z}{y}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \frac{\frac{y}{z}}{z}}{z}\\ \end{array} \]
Alternative 5
Error4.7
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -2718407729970204700:\\ \;\;\;\;\frac{\frac{y}{z} \cdot \frac{x}{z}}{z}\\ \mathbf{elif}\;z \leq 0.01:\\ \;\;\;\;\frac{\frac{x}{z} - x}{\frac{z}{y}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \frac{\frac{y}{z}}{z}}{z}\\ \end{array} \]
Alternative 6
Error3.3
Cost704
\[\frac{\frac{x}{z}}{z \cdot \frac{z + 1}{y}} \]
Alternative 7
Error17.0
Cost580
\[\begin{array}{l} \mathbf{if}\;x \leq -1.7430456274312792 \cdot 10^{-44}:\\ \;\;\;\;x \cdot \frac{\frac{y}{z}}{z}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{\frac{x}{z}}{z}\\ \end{array} \]
Alternative 8
Error16.9
Cost580
\[\begin{array}{l} \mathbf{if}\;x \leq -7.175635036983987 \cdot 10^{-127}:\\ \;\;\;\;\frac{x}{\frac{z}{\frac{y}{z}}}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{\frac{x}{z}}{z}\\ \end{array} \]
Alternative 9
Error42.4
Cost452
\[\begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{+36}:\\ \;\;\;\;x \cdot \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \end{array} \]
Alternative 10
Error42.1
Cost452
\[\begin{array}{l} \mathbf{if}\;y \leq 3.8826789787260356 \cdot 10^{-81}:\\ \;\;\;\;\frac{x}{\frac{z}{y}}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \end{array} \]
Alternative 11
Error41.7
Cost452
\[\begin{array}{l} \mathbf{if}\;y \leq 3.8826789787260356 \cdot 10^{-81}:\\ \;\;\;\;\frac{x}{\frac{z}{y}}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{\frac{z}{x}}\\ \end{array} \]
Alternative 12
Error22.3
Cost448
\[y \cdot \frac{\frac{x}{z}}{z} \]
Alternative 13
Error45.3
Cost320
\[y \cdot \frac{x}{z} \]

Error

Reproduce

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