?

Average Error: 15.1 → 4.4
Time: 12.0s
Precision: binary64
Cost: 2768

?

\[ \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 := \left(z + 1\right) \cdot \left(z \cdot z\right)\\ t_1 := \frac{x}{z} \cdot \frac{y}{z}\\ \mathbf{if}\;t_0 \leq -100000:\\ \;\;\;\;\frac{t_1}{z}\\ \mathbf{elif}\;t_0 \leq 4 \cdot 10^{-286}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 10^{-72}:\\ \;\;\;\;\frac{y \cdot x}{z \cdot z}\\ \mathbf{elif}\;t_0 \leq 5000:\\ \;\;\;\;\frac{y}{z + 1} \cdot \frac{x}{z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{z}}{z \cdot \frac{z}{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 (* (+ z 1.0) (* z z))) (t_1 (* (/ x z) (/ y z))))
   (if (<= t_0 -100000.0)
     (/ t_1 z)
     (if (<= t_0 4e-286)
       t_1
       (if (<= t_0 1e-72)
         (/ (* y x) (* z z))
         (if (<= t_0 5000.0)
           (* (/ y (+ z 1.0)) (/ x (* z z)))
           (/ (/ x z) (* z (/ z 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 = (z + 1.0) * (z * z);
	double t_1 = (x / z) * (y / z);
	double tmp;
	if (t_0 <= -100000.0) {
		tmp = t_1 / z;
	} else if (t_0 <= 4e-286) {
		tmp = t_1;
	} else if (t_0 <= 1e-72) {
		tmp = (y * x) / (z * z);
	} else if (t_0 <= 5000.0) {
		tmp = (y / (z + 1.0)) * (x / (z * z));
	} else {
		tmp = (x / z) / (z * (z / y));
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (x * y) / ((z * z) * (z + 1.0d0))
end function
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = (z + 1.0d0) * (z * z)
    t_1 = (x / z) * (y / z)
    if (t_0 <= (-100000.0d0)) then
        tmp = t_1 / z
    else if (t_0 <= 4d-286) then
        tmp = t_1
    else if (t_0 <= 1d-72) then
        tmp = (y * x) / (z * z)
    else if (t_0 <= 5000.0d0) then
        tmp = (y / (z + 1.0d0)) * (x / (z * z))
    else
        tmp = (x / z) / (z * (z / y))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	return (x * y) / ((z * z) * (z + 1.0));
}
public static double code(double x, double y, double z) {
	double t_0 = (z + 1.0) * (z * z);
	double t_1 = (x / z) * (y / z);
	double tmp;
	if (t_0 <= -100000.0) {
		tmp = t_1 / z;
	} else if (t_0 <= 4e-286) {
		tmp = t_1;
	} else if (t_0 <= 1e-72) {
		tmp = (y * x) / (z * z);
	} else if (t_0 <= 5000.0) {
		tmp = (y / (z + 1.0)) * (x / (z * z));
	} else {
		tmp = (x / z) / (z * (z / y));
	}
	return tmp;
}
def code(x, y, z):
	return (x * y) / ((z * z) * (z + 1.0))
def code(x, y, z):
	t_0 = (z + 1.0) * (z * z)
	t_1 = (x / z) * (y / z)
	tmp = 0
	if t_0 <= -100000.0:
		tmp = t_1 / z
	elif t_0 <= 4e-286:
		tmp = t_1
	elif t_0 <= 1e-72:
		tmp = (y * x) / (z * z)
	elif t_0 <= 5000.0:
		tmp = (y / (z + 1.0)) * (x / (z * z))
	else:
		tmp = (x / z) / (z * (z / 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(z + 1.0) * Float64(z * z))
	t_1 = Float64(Float64(x / z) * Float64(y / z))
	tmp = 0.0
	if (t_0 <= -100000.0)
		tmp = Float64(t_1 / z);
	elseif (t_0 <= 4e-286)
		tmp = t_1;
	elseif (t_0 <= 1e-72)
		tmp = Float64(Float64(y * x) / Float64(z * z));
	elseif (t_0 <= 5000.0)
		tmp = Float64(Float64(y / Float64(z + 1.0)) * Float64(x / Float64(z * z)));
	else
		tmp = Float64(Float64(x / z) / Float64(z * Float64(z / y)));
	end
	return tmp
end
function tmp = code(x, y, z)
	tmp = (x * y) / ((z * z) * (z + 1.0));
end
function tmp_2 = code(x, y, z)
	t_0 = (z + 1.0) * (z * z);
	t_1 = (x / z) * (y / z);
	tmp = 0.0;
	if (t_0 <= -100000.0)
		tmp = t_1 / z;
	elseif (t_0 <= 4e-286)
		tmp = t_1;
	elseif (t_0 <= 1e-72)
		tmp = (y * x) / (z * z);
	elseif (t_0 <= 5000.0)
		tmp = (y / (z + 1.0)) * (x / (z * z));
	else
		tmp = (x / z) / (z * (z / y));
	end
	tmp_2 = 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[(z + 1.0), $MachinePrecision] * N[(z * z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x / z), $MachinePrecision] * N[(y / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -100000.0], N[(t$95$1 / z), $MachinePrecision], If[LessEqual[t$95$0, 4e-286], t$95$1, If[LessEqual[t$95$0, 1e-72], N[(N[(y * x), $MachinePrecision] / N[(z * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 5000.0], N[(N[(y / N[(z + 1.0), $MachinePrecision]), $MachinePrecision] * N[(x / N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x / z), $MachinePrecision] / N[(z * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]
\frac{x \cdot y}{\left(z \cdot z\right) \cdot \left(z + 1\right)}
\begin{array}{l}
t_0 := \left(z + 1\right) \cdot \left(z \cdot z\right)\\
t_1 := \frac{x}{z} \cdot \frac{y}{z}\\
\mathbf{if}\;t_0 \leq -100000:\\
\;\;\;\;\frac{t_1}{z}\\

\mathbf{elif}\;t_0 \leq 4 \cdot 10^{-286}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_0 \leq 10^{-72}:\\
\;\;\;\;\frac{y \cdot x}{z \cdot z}\\

\mathbf{elif}\;t_0 \leq 5000:\\
\;\;\;\;\frac{y}{z + 1} \cdot \frac{x}{z \cdot z}\\

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original15.1
Target4.4
Herbie4.4
\[\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 5 regimes
  2. if (*.f64 (*.f64 z z) (+.f64 z 1)) < -1e5

    1. Initial program 11.2

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

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

      [Start]11.2

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

      times-frac [=>]4.9

      \[ \color{blue}{\frac{x}{z \cdot z} \cdot \frac{y}{z + 1}} \]
    3. Applied egg-rr1.6

      \[\leadsto \color{blue}{\frac{\frac{y}{z + 1} \cdot \frac{x}{z}}{z}} \]
    4. Taylor expanded in z around inf 2.5

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

    if -1e5 < (*.f64 (*.f64 z z) (+.f64 z 1)) < 4.0000000000000002e-286

    1. Initial program 54.1

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

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

      [Start]54.1

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

      *-commutative [=>]54.1

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

      associate-*r/ [<=]54.5

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

      associate-*l* [=>]54.5

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

      associate-/r* [=>]25.7

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

      distribute-rgt-in [=>]25.7

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

      *-lft-identity [=>]25.7

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

      fma-def [=>]25.7

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

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

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

      [Start]55.5

      \[ \frac{y \cdot x}{{z}^{2}} \]

      *-commutative [=>]55.5

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

      unpow2 [=>]55.5

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

      times-frac [=>]6.6

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

    if 4.0000000000000002e-286 < (*.f64 (*.f64 z z) (+.f64 z 1)) < 9.9999999999999997e-73

    1. Initial program 9.5

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

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

      [Start]9.5

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

      *-commutative [=>]9.5

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

      associate-*r/ [<=]9.4

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

      associate-*l* [=>]9.4

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

      associate-/r* [=>]9.4

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

      distribute-rgt-in [=>]9.4

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

      *-lft-identity [=>]9.4

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

      fma-def [=>]9.4

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

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

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

      [Start]9.5

      \[ \frac{y \cdot x}{{z}^{2}} \]

      unpow2 [=>]9.5

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

    if 9.9999999999999997e-73 < (*.f64 (*.f64 z z) (+.f64 z 1)) < 5e3

    1. Initial program 2.4

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

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

      [Start]2.4

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

      times-frac [=>]2.9

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

    if 5e3 < (*.f64 (*.f64 z z) (+.f64 z 1))

    1. Initial program 10.2

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

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

      [Start]10.2

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

      times-frac [=>]4.7

      \[ \color{blue}{\frac{x}{z \cdot z} \cdot \frac{y}{z + 1}} \]
    3. Applied egg-rr2.5

      \[\leadsto \color{blue}{\frac{\frac{x}{z}}{\frac{z + 1}{y} \cdot z}} \]
    4. Taylor expanded in z around inf 3.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(z + 1\right) \cdot \left(z \cdot z\right) \leq -100000:\\ \;\;\;\;\frac{\frac{x}{z} \cdot \frac{y}{z}}{z}\\ \mathbf{elif}\;\left(z + 1\right) \cdot \left(z \cdot z\right) \leq 4 \cdot 10^{-286}:\\ \;\;\;\;\frac{x}{z} \cdot \frac{y}{z}\\ \mathbf{elif}\;\left(z + 1\right) \cdot \left(z \cdot z\right) \leq 10^{-72}:\\ \;\;\;\;\frac{y \cdot x}{z \cdot z}\\ \mathbf{elif}\;\left(z + 1\right) \cdot \left(z \cdot z\right) \leq 5000:\\ \;\;\;\;\frac{y}{z + 1} \cdot \frac{x}{z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{z}}{z \cdot \frac{z}{y}}\\ \end{array} \]

Alternatives

Alternative 1
Error16.9
Cost844
\[\begin{array}{l} \mathbf{if}\;y \leq 2.35 \cdot 10^{-200}:\\ \;\;\;\;\frac{x}{\frac{z}{\frac{y}{z}}}\\ \mathbf{elif}\;y \leq 2.4 \cdot 10^{-9}:\\ \;\;\;\;\frac{x}{z} \cdot \frac{y}{z}\\ \mathbf{elif}\;y \leq 10000000000000:\\ \;\;\;\;x \cdot \frac{\frac{y}{z}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{z \cdot \frac{z}{x}}\\ \end{array} \]
Alternative 2
Error17.0
Cost844
\[\begin{array}{l} \mathbf{if}\;y \leq 9.5 \cdot 10^{-200}:\\ \;\;\;\;\frac{x}{\frac{z}{\frac{y}{z}}}\\ \mathbf{elif}\;y \leq 1.9 \cdot 10^{-24}:\\ \;\;\;\;\frac{x}{z} \cdot \frac{y}{z}\\ \mathbf{elif}\;y \leq 2.1 \cdot 10^{+16}:\\ \;\;\;\;\frac{y \cdot x}{z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{z \cdot \frac{z}{x}}\\ \end{array} \]
Alternative 3
Error6.0
Cost841
\[\begin{array}{l} \mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 0.0066\right):\\ \;\;\;\;\frac{y}{z} \cdot \frac{x}{z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z} \cdot \left(\frac{y}{z} - y\right)\\ \end{array} \]
Alternative 4
Error6.0
Cost841
\[\begin{array}{l} \mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 0.0066\right):\\ \;\;\;\;\frac{y}{z} \cdot \frac{x}{z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{z} \cdot \left(\frac{x}{z} - x\right)\\ \end{array} \]
Alternative 5
Error3.7
Cost841
\[\begin{array}{l} \mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 0.0066\right):\\ \;\;\;\;\frac{\frac{x}{z} \cdot \frac{y}{z}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{z} \cdot \left(\frac{x}{z} - x\right)\\ \end{array} \]
Alternative 6
Error4.2
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -1:\\ \;\;\;\;\frac{\frac{x}{z} \cdot \frac{y}{z}}{z}\\ \mathbf{elif}\;z \leq 0.0066:\\ \;\;\;\;\frac{y}{z} \cdot \left(\frac{x}{z} - x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{z}}{z \cdot \frac{z}{y}}\\ \end{array} \]
Alternative 7
Error19.6
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -2 \cdot 10^{-93} \lor \neg \left(z \leq 7.2 \cdot 10^{-52}\right):\\ \;\;\;\;x \cdot \frac{\frac{y}{z}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z} \cdot \frac{y}{z}\\ \end{array} \]
Alternative 8
Error17.2
Cost712
\[\begin{array}{l} \mathbf{if}\;y \leq 1.5 \cdot 10^{-199}:\\ \;\;\;\;x \cdot \frac{\frac{y}{z}}{z}\\ \mathbf{elif}\;y \leq 2.95 \cdot 10^{+56}:\\ \;\;\;\;\frac{x}{z} \cdot \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{z \cdot z}\\ \end{array} \]
Alternative 9
Error17.1
Cost712
\[\begin{array}{l} \mathbf{if}\;y \leq 2 \cdot 10^{-200}:\\ \;\;\;\;\frac{x}{\frac{z}{\frac{y}{z}}}\\ \mathbf{elif}\;y \leq 10^{+57}:\\ \;\;\;\;\frac{x}{z} \cdot \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{z \cdot z}\\ \end{array} \]
Alternative 10
Error2.8
Cost704
\[\frac{\frac{y}{z + 1} \cdot \frac{x}{z}}{z} \]
Alternative 11
Error42.2
Cost516
\[\begin{array}{l} \mathbf{if}\;x \leq -6.2 \cdot 10^{-62}:\\ \;\;\;\;\frac{x}{\frac{z}{y}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-y}{\frac{z}{x}}\\ \end{array} \]
Alternative 12
Error43.1
Cost452
\[\begin{array}{l} \mathbf{if}\;x \leq -1.8 \cdot 10^{+68}:\\ \;\;\;\;x \cdot \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \end{array} \]
Alternative 13
Error42.5
Cost452
\[\begin{array}{l} \mathbf{if}\;x \leq -2 \cdot 10^{+25}:\\ \;\;\;\;\frac{x}{\frac{z}{y}}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \end{array} \]
Alternative 14
Error22.3
Cost448
\[x \cdot \frac{\frac{y}{z}}{z} \]
Alternative 15
Error45.7
Cost320
\[x \cdot \frac{y}{z} \]

Error

Reproduce?

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