Average Error: 14.5 → 1.1
Time: 12.2s
Precision: binary64
Cost: 8016
\[\frac{x \cdot y}{\left(z \cdot z\right) \cdot \left(z + 1\right)} \]
\[\begin{array}{l} t_0 := \frac{\frac{x}{z}}{z} \cdot \frac{y}{z}\\ \mathbf{if}\;x \cdot y \leq -5 \cdot 10^{+281}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \cdot y \leq -2.5 \cdot 10^{-52}:\\ \;\;\;\;{z}^{-2} \cdot \frac{x \cdot y}{z + 1}\\ \mathbf{elif}\;x \cdot y \leq 2 \cdot 10^{-267}:\\ \;\;\;\;\frac{y}{z} \cdot \frac{x}{\mathsf{fma}\left(z, z, z\right)}\\ \mathbf{elif}\;x \cdot y \leq 2 \cdot 10^{+241}:\\ \;\;\;\;\frac{\frac{x \cdot y}{\mathsf{fma}\left(z, z, z\right)}}{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 (* (/ (/ x z) z) (/ y z))))
   (if (<= (* x y) -5e+281)
     t_0
     (if (<= (* x y) -2.5e-52)
       (* (pow z -2.0) (/ (* x y) (+ z 1.0)))
       (if (<= (* x y) 2e-267)
         (* (/ y z) (/ x (fma z z z)))
         (if (<= (* x y) 2e+241) (/ (/ (* x y) (fma z z z)) 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 = ((x / z) / z) * (y / z);
	double tmp;
	if ((x * y) <= -5e+281) {
		tmp = t_0;
	} else if ((x * y) <= -2.5e-52) {
		tmp = pow(z, -2.0) * ((x * y) / (z + 1.0));
	} else if ((x * y) <= 2e-267) {
		tmp = (y / z) * (x / fma(z, z, z));
	} else if ((x * y) <= 2e+241) {
		tmp = ((x * y) / fma(z, z, z)) / z;
	} else {
		tmp = t_0;
	}
	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 / z) / z) * Float64(y / z))
	tmp = 0.0
	if (Float64(x * y) <= -5e+281)
		tmp = t_0;
	elseif (Float64(x * y) <= -2.5e-52)
		tmp = Float64((z ^ -2.0) * Float64(Float64(x * y) / Float64(z + 1.0)));
	elseif (Float64(x * y) <= 2e-267)
		tmp = Float64(Float64(y / z) * Float64(x / fma(z, z, z)));
	elseif (Float64(x * y) <= 2e+241)
		tmp = Float64(Float64(Float64(x * y) / fma(z, z, z)) / z);
	else
		tmp = t_0;
	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 / z), $MachinePrecision] / z), $MachinePrecision] * N[(y / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * y), $MachinePrecision], -5e+281], t$95$0, If[LessEqual[N[(x * y), $MachinePrecision], -2.5e-52], N[(N[Power[z, -2.0], $MachinePrecision] * N[(N[(x * y), $MachinePrecision] / N[(z + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 2e-267], N[(N[(y / z), $MachinePrecision] * N[(x / N[(z * z + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 2e+241], N[(N[(N[(x * y), $MachinePrecision] / N[(z * z + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], t$95$0]]]]]
\frac{x \cdot y}{\left(z \cdot z\right) \cdot \left(z + 1\right)}
\begin{array}{l}
t_0 := \frac{\frac{x}{z}}{z} \cdot \frac{y}{z}\\
\mathbf{if}\;x \cdot y \leq -5 \cdot 10^{+281}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \cdot y \leq -2.5 \cdot 10^{-52}:\\
\;\;\;\;{z}^{-2} \cdot \frac{x \cdot y}{z + 1}\\

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

\mathbf{elif}\;x \cdot y \leq 2 \cdot 10^{+241}:\\
\;\;\;\;\frac{\frac{x \cdot y}{\mathsf{fma}\left(z, z, z\right)}}{z}\\

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


\end{array}

Error

Target

Original14.5
Target4.1
Herbie1.1
\[\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) < -5.00000000000000016e281 or 2.0000000000000001e241 < (*.f64 x y)

    1. Initial program 50.1

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

      \[\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))))): 0 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, 0 points decrease in error
      (Rewrite<= times-frac_binary64 (/.f64 (*.f64 y x) (*.f64 z (*.f64 z (+.f64 z 1))))): 70 points increase in error, 26 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)))): 0 points increase in error, 0 points decrease in error
    3. Taylor expanded in z around inf 51.6

      \[\leadsto \color{blue}{\frac{y \cdot x}{{z}^{3}}} \]
    4. Simplified29.3

      \[\leadsto \color{blue}{\frac{x}{\frac{{z}^{3}}{y}}} \]
      Proof
      (/.f64 x (/.f64 (pow.f64 z 3) y)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 x y) (pow.f64 z 3))): 38 points increase in error, 16 points decrease in error
      (/.f64 (Rewrite<= *-commutative_binary64 (*.f64 y x)) (pow.f64 z 3)): 0 points increase in error, 0 points decrease in error
    5. Applied egg-rr19.1

      \[\leadsto \frac{x}{\color{blue}{\frac{z}{1} \cdot \frac{z \cdot z}{y}}} \]
    6. Applied egg-rr3.0

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

    if -5.00000000000000016e281 < (*.f64 x y) < -2.5e-52

    1. Initial program 5.6

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

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

    if -2.5e-52 < (*.f64 x y) < 2e-267

    1. Initial program 16.0

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

      \[\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))))): 0 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, 0 points decrease in error
      (Rewrite<= times-frac_binary64 (/.f64 (*.f64 y x) (*.f64 z (*.f64 z (+.f64 z 1))))): 70 points increase in error, 26 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)))): 0 points increase in error, 0 points decrease in error

    if 2e-267 < (*.f64 x y) < 2.0000000000000001e241

    1. Initial program 6.7

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

      \[\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))))): 0 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, 0 points decrease in error
      (Rewrite<= times-frac_binary64 (/.f64 (*.f64 y x) (*.f64 z (*.f64 z (+.f64 z 1))))): 70 points increase in error, 26 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)))): 0 points increase in error, 0 points decrease in error
    3. Applied egg-rr0.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y \leq -5 \cdot 10^{+281}:\\ \;\;\;\;\frac{\frac{x}{z}}{z} \cdot \frac{y}{z}\\ \mathbf{elif}\;x \cdot y \leq -2.5 \cdot 10^{-52}:\\ \;\;\;\;{z}^{-2} \cdot \frac{x \cdot y}{z + 1}\\ \mathbf{elif}\;x \cdot y \leq 2 \cdot 10^{-267}:\\ \;\;\;\;\frac{y}{z} \cdot \frac{x}{\mathsf{fma}\left(z, z, z\right)}\\ \mathbf{elif}\;x \cdot y \leq 2 \cdot 10^{+241}:\\ \;\;\;\;\frac{\frac{x \cdot y}{\mathsf{fma}\left(z, z, z\right)}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{z}}{z} \cdot \frac{y}{z}\\ \end{array} \]

Alternatives

Alternative 1
Error0.9
Cost8016
\[\begin{array}{l} t_0 := \frac{\frac{x \cdot y}{\mathsf{fma}\left(z, z, z\right)}}{z}\\ t_1 := \frac{\frac{x}{z}}{z} \cdot \frac{y}{z}\\ \mathbf{if}\;x \cdot y \leq -5 \cdot 10^{+236}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \cdot y \leq -2 \cdot 10^{-260}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \cdot y \leq 2 \cdot 10^{-267}:\\ \;\;\;\;\frac{x}{z} \cdot \frac{y}{z}\\ \mathbf{elif}\;x \cdot y \leq 2 \cdot 10^{+241}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error4.5
Cost1608
\[\begin{array}{l} t_0 := \left(z + 1\right) \cdot \left(z \cdot z\right)\\ \mathbf{if}\;t_0 \leq -1 \cdot 10^{+33}:\\ \;\;\;\;\frac{1}{z} \cdot \frac{x}{z \cdot \frac{z}{y}}\\ \mathbf{elif}\;t_0 \leq 10^{-5}:\\ \;\;\;\;\frac{x \cdot \frac{y}{z}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{z}}{z} \cdot \frac{y}{z}\\ \end{array} \]
Alternative 3
Error6.2
Cost840
\[\begin{array}{l} t_0 := \frac{x}{z \cdot \frac{z}{\frac{y}{z}}}\\ \mathbf{if}\;z \leq -1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;\frac{x \cdot \frac{y}{z}}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error5.8
Cost840
\[\begin{array}{l} t_0 := \frac{x}{z} \cdot \frac{y}{z \cdot z}\\ \mathbf{if}\;z \leq -1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;\frac{x \cdot \frac{y}{z}}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error4.1
Cost840
\[\begin{array}{l} t_0 := \frac{\frac{x}{z}}{z} \cdot \frac{y}{z}\\ \mathbf{if}\;z \leq -1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;\frac{x \cdot \frac{y}{z}}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error17.7
Cost712
\[\begin{array}{l} t_0 := y \cdot \frac{x}{z \cdot z}\\ \mathbf{if}\;z \leq -3.622141579876296 \cdot 10^{+110}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.9050106734224518 \cdot 10^{+101}:\\ \;\;\;\;\frac{\frac{x}{z}}{\frac{z}{y}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error19.4
Cost712
\[\begin{array}{l} \mathbf{if}\;y \leq 7.317746917121358 \cdot 10^{-180}:\\ \;\;\;\;\frac{x}{z \cdot \frac{z}{y}}\\ \mathbf{elif}\;y \leq 10^{+20}:\\ \;\;\;\;\frac{\frac{x}{z}}{\frac{z}{y}}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{z \cdot z}\\ \end{array} \]
Alternative 8
Error19.7
Cost580
\[\begin{array}{l} \mathbf{if}\;x \leq -1.7399818971949965 \cdot 10^{-65}:\\ \;\;\;\;\frac{x}{z \cdot \frac{z}{y}}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{\frac{z}{\frac{x}{z}}}\\ \end{array} \]
Alternative 9
Error19.7
Cost580
\[\begin{array}{l} \mathbf{if}\;x \leq -1.7399818971949965 \cdot 10^{-65}:\\ \;\;\;\;\frac{x}{\frac{z}{\frac{y}{z}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{\frac{z}{\frac{x}{z}}}\\ \end{array} \]
Alternative 10
Error44.1
Cost452
\[\begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{+21}:\\ \;\;\;\;x \cdot \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \end{array} \]
Alternative 11
Error43.7
Cost452
\[\begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{+21}:\\ \;\;\;\;x \cdot \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{\frac{z}{x}}\\ \end{array} \]
Alternative 12
Error21.5
Cost448
\[\frac{\frac{x}{z}}{\frac{z}{y}} \]
Alternative 13
Error45.6
Cost320
\[y \cdot \frac{x}{z} \]

Error

Reproduce

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