Statistics.Distribution.Beta:$cvariance from math-functions-0.1.5.2

?

Percentage Accurate: 83.1% → 94.5%
Time: 14.9s
Precision: binary64
Cost: 2249

?

\[ \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{x \cdot y}{\left(z + 1\right) \cdot \left(z \cdot z\right)}\\ \mathbf{if}\;t_0 \leq 0 \lor \neg \left(t_0 \leq 2 \cdot 10^{+283}\right):\\ \;\;\;\;\frac{\frac{x}{z}}{z} \cdot \frac{y}{z + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x \cdot y}{z + 1}}{z \cdot 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 (/ (* x y) (* (+ z 1.0) (* z z)))))
   (if (or (<= t_0 0.0) (not (<= t_0 2e+283)))
     (* (/ (/ x z) z) (/ y (+ z 1.0)))
     (/ (/ (* x y) (+ z 1.0)) (* z 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 = (x * y) / ((z + 1.0) * (z * z));
	double tmp;
	if ((t_0 <= 0.0) || !(t_0 <= 2e+283)) {
		tmp = ((x / z) / z) * (y / (z + 1.0));
	} else {
		tmp = ((x * y) / (z + 1.0)) / (z * z);
	}
	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) :: tmp
    t_0 = (x * y) / ((z + 1.0d0) * (z * z))
    if ((t_0 <= 0.0d0) .or. (.not. (t_0 <= 2d+283))) then
        tmp = ((x / z) / z) * (y / (z + 1.0d0))
    else
        tmp = ((x * y) / (z + 1.0d0)) / (z * z)
    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 = (x * y) / ((z + 1.0) * (z * z));
	double tmp;
	if ((t_0 <= 0.0) || !(t_0 <= 2e+283)) {
		tmp = ((x / z) / z) * (y / (z + 1.0));
	} else {
		tmp = ((x * y) / (z + 1.0)) / (z * z);
	}
	return tmp;
}
def code(x, y, z):
	return (x * y) / ((z * z) * (z + 1.0))
def code(x, y, z):
	t_0 = (x * y) / ((z + 1.0) * (z * z))
	tmp = 0
	if (t_0 <= 0.0) or not (t_0 <= 2e+283):
		tmp = ((x / z) / z) * (y / (z + 1.0))
	else:
		tmp = ((x * y) / (z + 1.0)) / (z * z)
	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(x * y) / Float64(Float64(z + 1.0) * Float64(z * z)))
	tmp = 0.0
	if ((t_0 <= 0.0) || !(t_0 <= 2e+283))
		tmp = Float64(Float64(Float64(x / z) / z) * Float64(y / Float64(z + 1.0)));
	else
		tmp = Float64(Float64(Float64(x * y) / Float64(z + 1.0)) / Float64(z * z));
	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 = (x * y) / ((z + 1.0) * (z * z));
	tmp = 0.0;
	if ((t_0 <= 0.0) || ~((t_0 <= 2e+283)))
		tmp = ((x / z) / z) * (y / (z + 1.0));
	else
		tmp = ((x * y) / (z + 1.0)) / (z * z);
	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[(x * y), $MachinePrecision] / N[(N[(z + 1.0), $MachinePrecision] * N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, 0.0], N[Not[LessEqual[t$95$0, 2e+283]], $MachinePrecision]], N[(N[(N[(x / z), $MachinePrecision] / z), $MachinePrecision] * N[(y / N[(z + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x * y), $MachinePrecision] / N[(z + 1.0), $MachinePrecision]), $MachinePrecision] / N[(z * z), $MachinePrecision]), $MachinePrecision]]]
\frac{x \cdot y}{\left(z \cdot z\right) \cdot \left(z + 1\right)}
\begin{array}{l}
t_0 := \frac{x \cdot y}{\left(z + 1\right) \cdot \left(z \cdot z\right)}\\
\mathbf{if}\;t_0 \leq 0 \lor \neg \left(t_0 \leq 2 \cdot 10^{+283}\right):\\
\;\;\;\;\frac{\frac{x}{z}}{z} \cdot \frac{y}{z + 1}\\

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


\end{array}

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Herbie found 19 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Bogosity?

Bogosity

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original83.1%
Target95.9%
Herbie94.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 2 regimes
  2. if (/.f64 (*.f64 x y) (*.f64 (*.f64 z z) (+.f64 z 1))) < 0.0 or 1.99999999999999991e283 < (/.f64 (*.f64 x y) (*.f64 (*.f64 z z) (+.f64 z 1)))

    1. Initial program 82.9%

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

      \[\leadsto \color{blue}{\frac{x}{z \cdot z} \cdot \frac{y}{z + 1}} \]
      Step-by-step derivation

      [Start]82.9%

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

      times-frac [=>]91.9%

      \[ \color{blue}{\frac{x}{z \cdot z} \cdot \frac{y}{z + 1}} \]
    3. Taylor expanded in x around 0 91.9%

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

      \[\leadsto \color{blue}{\frac{\frac{x}{z}}{z}} \cdot \frac{y}{z + 1} \]
      Step-by-step derivation

      [Start]91.9%

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

      unpow2 [=>]91.9%

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

      associate-/l/ [<=]97.3%

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

    if 0.0 < (/.f64 (*.f64 x y) (*.f64 (*.f64 z z) (+.f64 z 1))) < 1.99999999999999991e283

    1. Initial program 98.9%

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

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

      [Start]98.9%

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

      associate-*l* [=>]98.9%

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

      times-frac [=>]88.7%

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

      distribute-lft-in [=>]88.7%

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

      fma-def [=>]88.7%

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

      *-rgt-identity [=>]88.7%

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

      \[\leadsto \color{blue}{\frac{\frac{y \cdot x}{z + 1}}{z \cdot z}} \]
      Step-by-step derivation

      [Start]88.7%

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

      frac-times [=>]98.9%

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

      fma-udef [=>]98.9%

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

      distribute-lft-in [=>]98.9%

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

      distribute-lft1-in [=>]98.9%

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

      associate-/r* [=>]99.0%

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

      *-commutative [=>]99.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x \cdot y}{\left(z + 1\right) \cdot \left(z \cdot z\right)} \leq 0 \lor \neg \left(\frac{x \cdot y}{\left(z + 1\right) \cdot \left(z \cdot z\right)} \leq 2 \cdot 10^{+283}\right):\\ \;\;\;\;\frac{\frac{x}{z}}{z} \cdot \frac{y}{z + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x \cdot y}{z + 1}}{z \cdot z}\\ \end{array} \]

Alternatives

Alternative 1
Accuracy94.5%
Cost2249
\[\begin{array}{l} t_0 := \frac{x \cdot y}{\left(z + 1\right) \cdot \left(z \cdot z\right)}\\ \mathbf{if}\;t_0 \leq 0 \lor \neg \left(t_0 \leq 2 \cdot 10^{+283}\right):\\ \;\;\;\;\frac{\frac{x}{z}}{z} \cdot \frac{y}{z + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x \cdot y}{z + 1}}{z \cdot z}\\ \end{array} \]
Alternative 2
Accuracy95.7%
Cost7236
\[\begin{array}{l} \mathbf{if}\;x \cdot y \leq 10^{-15}:\\ \;\;\;\;\frac{x}{z} \cdot \frac{y}{\mathsf{fma}\left(z, z, z\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{z}}{z} \cdot \frac{y}{z + 1}\\ \end{array} \]
Alternative 3
Accuracy94.5%
Cost2249
\[\begin{array}{l} t_0 := \frac{x \cdot y}{\left(z + 1\right) \cdot \left(z \cdot z\right)}\\ \mathbf{if}\;t_0 \leq 0 \lor \neg \left(t_0 \leq 2 \cdot 10^{+283}\right):\\ \;\;\;\;\frac{\frac{x}{z}}{z} \cdot \frac{y}{z + 1}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Accuracy95.2%
Cost1232
\[\begin{array}{l} t_0 := \frac{y}{z + 1} \cdot \frac{x}{z \cdot z}\\ \mathbf{if}\;z \leq -3.5 \cdot 10^{+64}:\\ \;\;\;\;\frac{\frac{y}{z}}{z \cdot \frac{z}{x}}\\ \mathbf{elif}\;z \leq -8 \cdot 10^{-59}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -4.8 \cdot 10^{-167}:\\ \;\;\;\;\frac{\frac{x \cdot y}{z}}{z}\\ \mathbf{elif}\;z \leq 1.2 \cdot 10^{-72}:\\ \;\;\;\;\frac{x}{z} \cdot \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Accuracy96.6%
Cost969
\[\begin{array}{l} \mathbf{if}\;z \leq -5 \cdot 10^{-54} \lor \neg \left(z \leq 1.42 \cdot 10^{-83}\right):\\ \;\;\;\;\frac{\frac{x}{z}}{z} \cdot \frac{y}{z + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{y}{z} - y}{\frac{z}{x}}\\ \end{array} \]
Alternative 6
Accuracy93.4%
Cost841
\[\begin{array}{l} \mathbf{if}\;z \leq -20 \lor \neg \left(z \leq 0.75\right):\\ \;\;\;\;\frac{x}{z} \cdot \frac{y}{z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z} \cdot \left(\frac{y}{z} - y\right)\\ \end{array} \]
Alternative 7
Accuracy95.3%
Cost841
\[\begin{array}{l} \mathbf{if}\;z \leq -20 \lor \neg \left(z \leq 0.8\right):\\ \;\;\;\;\frac{x}{z} \cdot \frac{\frac{y}{z}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z} \cdot \left(\frac{y}{z} - y\right)\\ \end{array} \]
Alternative 8
Accuracy95.4%
Cost841
\[\begin{array}{l} \mathbf{if}\;z \leq -20 \lor \neg \left(z \leq 0.75\right):\\ \;\;\;\;\frac{x}{z} \cdot \frac{\frac{y}{z}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{y}{z} - y}{\frac{z}{x}}\\ \end{array} \]
Alternative 9
Accuracy95.4%
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -20:\\ \;\;\;\;\frac{\frac{x}{z}}{z \cdot \frac{z}{y}}\\ \mathbf{elif}\;z \leq 0.75:\\ \;\;\;\;\frac{\frac{y}{z} - y}{\frac{z}{x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z} \cdot \frac{\frac{y}{z}}{z}\\ \end{array} \]
Alternative 10
Accuracy95.3%
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -20:\\ \;\;\;\;\frac{\frac{y}{z}}{z \cdot \frac{z}{x}}\\ \mathbf{elif}\;z \leq 0.75:\\ \;\;\;\;\frac{\frac{y}{z} - y}{\frac{z}{x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z} \cdot \frac{\frac{y}{z}}{z}\\ \end{array} \]
Alternative 11
Accuracy95.2%
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -20:\\ \;\;\;\;\frac{\frac{y}{z}}{z \cdot \frac{z}{x}}\\ \mathbf{elif}\;z \leq 0.75:\\ \;\;\;\;\frac{\frac{y}{z} - y}{\frac{z}{x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\frac{y}{z}}{z}}{\frac{z}{x}}\\ \end{array} \]
Alternative 12
Accuracy78.3%
Cost580
\[\begin{array}{l} \mathbf{if}\;y \leq 3.1 \cdot 10^{+74}:\\ \;\;\;\;\frac{x}{z} \cdot \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{z \cdot z}\\ \end{array} \]
Alternative 13
Accuracy79.1%
Cost580
\[\begin{array}{l} \mathbf{if}\;x \leq -9 \cdot 10^{-61}:\\ \;\;\;\;x \cdot \frac{\frac{y}{z}}{z}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{\frac{x}{z}}{z}\\ \end{array} \]
Alternative 14
Accuracy79.4%
Cost580
\[\begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{-61}:\\ \;\;\;\;\frac{x}{z \cdot \frac{z}{y}}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{\frac{x}{z}}{z}\\ \end{array} \]
Alternative 15
Accuracy40.2%
Cost516
\[\begin{array}{l} \mathbf{if}\;z \leq -2 \cdot 10^{-310}:\\ \;\;\;\;\frac{x}{z} \cdot \left(-y\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{\frac{z}{x}}\\ \end{array} \]
Alternative 16
Accuracy40.3%
Cost516
\[\begin{array}{l} \mathbf{if}\;z \leq -2 \cdot 10^{-310}:\\ \;\;\;\;\frac{y}{\frac{-z}{x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{\frac{z}{x}}\\ \end{array} \]
Alternative 17
Accuracy72.6%
Cost448
\[y \cdot \frac{x}{z \cdot z} \]
Alternative 18
Accuracy31.1%
Cost320
\[\frac{x}{\frac{z}{y}} \]
Alternative 19
Accuracy31.0%
Cost320
\[\frac{y}{\frac{z}{x}} \]

Reproduce?

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