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

Percentage Accurate: 99.9% → 99.9%
Time: 5.6s
Alternatives: 7
Speedup: 0.1×

Specification

?
\[\begin{array}{l} \\ \left(x \cdot y\right) \cdot \left(1 - y\right) \end{array} \]
(FPCore (x y) :precision binary64 (* (* x y) (- 1.0 y)))
double code(double x, double y) {
	return (x * y) * (1.0 - y);
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = (x * y) * (1.0d0 - y)
end function
public static double code(double x, double y) {
	return (x * y) * (1.0 - y);
}
def code(x, y):
	return (x * y) * (1.0 - y)
function code(x, y)
	return Float64(Float64(x * y) * Float64(1.0 - y))
end
function tmp = code(x, y)
	tmp = (x * y) * (1.0 - y);
end
code[x_, y_] := N[(N[(x * y), $MachinePrecision] * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(x \cdot y\right) \cdot \left(1 - y\right)
\end{array}

Sampling outcomes in binary64 precision:

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.

Accuracy vs Speed?

Herbie found 7 alternatives:

AlternativeAccuracySpeedup
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.

Initial Program: 99.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(x \cdot y\right) \cdot \left(1 - y\right) \end{array} \]
(FPCore (x y) :precision binary64 (* (* x y) (- 1.0 y)))
double code(double x, double y) {
	return (x * y) * (1.0 - y);
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = (x * y) * (1.0d0 - y)
end function
public static double code(double x, double y) {
	return (x * y) * (1.0 - y);
}
def code(x, y):
	return (x * y) * (1.0 - y)
function code(x, y)
	return Float64(Float64(x * y) * Float64(1.0 - y))
end
function tmp = code(x, y)
	tmp = (x * y) * (1.0 - y);
end
code[x_, y_] := N[(N[(x * y), $MachinePrecision] * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(x \cdot y\right) \cdot \left(1 - y\right)
\end{array}

Alternative 1: 99.9% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(y, x, y \cdot \left(y \cdot \left(-x\right)\right)\right) \end{array} \]
(FPCore (x y) :precision binary64 (fma y x (* y (* y (- x)))))
double code(double x, double y) {
	return fma(y, x, (y * (y * -x)));
}
function code(x, y)
	return fma(y, x, Float64(y * Float64(y * Float64(-x))))
end
code[x_, y_] := N[(y * x + N[(y * N[(y * (-x)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(y, x, y \cdot \left(y \cdot \left(-x\right)\right)\right)
\end{array}
Derivation
  1. Initial program 99.9%

    \[\left(x \cdot y\right) \cdot \left(1 - y\right) \]
  2. Step-by-step derivation
    1. associate-*l*96.2%

      \[\leadsto \color{blue}{x \cdot \left(y \cdot \left(1 - y\right)\right)} \]
  3. Simplified96.2%

    \[\leadsto \color{blue}{x \cdot \left(y \cdot \left(1 - y\right)\right)} \]
  4. Step-by-step derivation
    1. associate-*r*99.9%

      \[\leadsto \color{blue}{\left(x \cdot y\right) \cdot \left(1 - y\right)} \]
    2. sub-neg99.9%

      \[\leadsto \left(x \cdot y\right) \cdot \color{blue}{\left(1 + \left(-y\right)\right)} \]
    3. distribute-lft-in95.2%

      \[\leadsto \color{blue}{\left(x \cdot y\right) \cdot 1 + \left(x \cdot y\right) \cdot \left(-y\right)} \]
    4. *-commutative95.2%

      \[\leadsto \color{blue}{1 \cdot \left(x \cdot y\right)} + \left(x \cdot y\right) \cdot \left(-y\right) \]
    5. *-un-lft-identity95.2%

      \[\leadsto \color{blue}{x \cdot y} + \left(x \cdot y\right) \cdot \left(-y\right) \]
    6. *-commutative95.2%

      \[\leadsto \color{blue}{y \cdot x} + \left(x \cdot y\right) \cdot \left(-y\right) \]
    7. fma-def99.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, \left(x \cdot y\right) \cdot \left(-y\right)\right)} \]
  5. Applied egg-rr99.9%

    \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, \left(x \cdot y\right) \cdot \left(-y\right)\right)} \]
  6. Final simplification99.9%

    \[\leadsto \mathsf{fma}\left(y, x, y \cdot \left(y \cdot \left(-x\right)\right)\right) \]

Alternative 2: 97.7% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1\right):\\ \;\;\;\;y \cdot \left(y \cdot \left(-x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (or (<= y -1.0) (not (<= y 1.0))) (* y (* y (- x))) (* y x)))
double code(double x, double y) {
	double tmp;
	if ((y <= -1.0) || !(y <= 1.0)) {
		tmp = y * (y * -x);
	} else {
		tmp = y * x;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if ((y <= (-1.0d0)) .or. (.not. (y <= 1.0d0))) then
        tmp = y * (y * -x)
    else
        tmp = y * x
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if ((y <= -1.0) || !(y <= 1.0)) {
		tmp = y * (y * -x);
	} else {
		tmp = y * x;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if (y <= -1.0) or not (y <= 1.0):
		tmp = y * (y * -x)
	else:
		tmp = y * x
	return tmp
function code(x, y)
	tmp = 0.0
	if ((y <= -1.0) || !(y <= 1.0))
		tmp = Float64(y * Float64(y * Float64(-x)));
	else
		tmp = Float64(y * x);
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if ((y <= -1.0) || ~((y <= 1.0)))
		tmp = y * (y * -x);
	else
		tmp = y * x;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(y * N[(y * (-x)), $MachinePrecision]), $MachinePrecision], N[(y * x), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot \left(y \cdot \left(-x\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1 or 1 < y

    1. Initial program 99.8%

      \[\left(x \cdot y\right) \cdot \left(1 - y\right) \]
    2. Step-by-step derivation
      1. associate-*l*92.8%

        \[\leadsto \color{blue}{x \cdot \left(y \cdot \left(1 - y\right)\right)} \]
    3. Simplified92.8%

      \[\leadsto \color{blue}{x \cdot \left(y \cdot \left(1 - y\right)\right)} \]
    4. Step-by-step derivation
      1. associate-*r*99.8%

        \[\leadsto \color{blue}{\left(x \cdot y\right) \cdot \left(1 - y\right)} \]
      2. sub-neg99.8%

        \[\leadsto \left(x \cdot y\right) \cdot \color{blue}{\left(1 + \left(-y\right)\right)} \]
      3. distribute-lft-in90.7%

        \[\leadsto \color{blue}{\left(x \cdot y\right) \cdot 1 + \left(x \cdot y\right) \cdot \left(-y\right)} \]
      4. *-commutative90.7%

        \[\leadsto \color{blue}{1 \cdot \left(x \cdot y\right)} + \left(x \cdot y\right) \cdot \left(-y\right) \]
      5. *-un-lft-identity90.7%

        \[\leadsto \color{blue}{x \cdot y} + \left(x \cdot y\right) \cdot \left(-y\right) \]
      6. *-commutative90.7%

        \[\leadsto \color{blue}{y \cdot x} + \left(x \cdot y\right) \cdot \left(-y\right) \]
      7. fma-def99.8%

        \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, \left(x \cdot y\right) \cdot \left(-y\right)\right)} \]
    5. Applied egg-rr99.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, \left(x \cdot y\right) \cdot \left(-y\right)\right)} \]
    6. Step-by-step derivation
      1. fma-udef90.7%

        \[\leadsto \color{blue}{y \cdot x + \left(x \cdot y\right) \cdot \left(-y\right)} \]
      2. *-commutative90.7%

        \[\leadsto \color{blue}{x \cdot y} + \left(x \cdot y\right) \cdot \left(-y\right) \]
      3. distribute-rgt-neg-out90.7%

        \[\leadsto x \cdot y + \color{blue}{\left(-\left(x \cdot y\right) \cdot y\right)} \]
      4. distribute-lft-neg-in90.7%

        \[\leadsto x \cdot y + \color{blue}{\left(-x \cdot y\right) \cdot y} \]
      5. add-sqr-sqrt41.5%

        \[\leadsto x \cdot y + \left(-x \cdot y\right) \cdot \color{blue}{\left(\sqrt{y} \cdot \sqrt{y}\right)} \]
      6. sqrt-unprod36.8%

        \[\leadsto x \cdot y + \left(-x \cdot y\right) \cdot \color{blue}{\sqrt{y \cdot y}} \]
      7. sqr-neg36.8%

        \[\leadsto x \cdot y + \left(-x \cdot y\right) \cdot \sqrt{\color{blue}{\left(-y\right) \cdot \left(-y\right)}} \]
      8. sqrt-unprod0.3%

        \[\leadsto x \cdot y + \left(-x \cdot y\right) \cdot \color{blue}{\left(\sqrt{-y} \cdot \sqrt{-y}\right)} \]
      9. add-sqr-sqrt0.6%

        \[\leadsto x \cdot y + \left(-x \cdot y\right) \cdot \color{blue}{\left(-y\right)} \]
      10. cancel-sign-sub-inv0.6%

        \[\leadsto \color{blue}{x \cdot y - \left(x \cdot y\right) \cdot \left(-y\right)} \]
      11. add-sqr-sqrt0.3%

        \[\leadsto x \cdot y - \color{blue}{\sqrt{\left(x \cdot y\right) \cdot \left(-y\right)} \cdot \sqrt{\left(x \cdot y\right) \cdot \left(-y\right)}} \]
      12. cancel-sign-sub-inv0.3%

        \[\leadsto \color{blue}{x \cdot y + \left(-\sqrt{\left(x \cdot y\right) \cdot \left(-y\right)}\right) \cdot \sqrt{\left(x \cdot y\right) \cdot \left(-y\right)}} \]
    7. Applied egg-rr45.2%

      \[\leadsto \color{blue}{x \cdot y + \left(-\sqrt{x} \cdot y\right) \cdot \left(\sqrt{x} \cdot y\right)} \]
    8. Step-by-step derivation
      1. add-sqr-sqrt26.4%

        \[\leadsto x \cdot y + \color{blue}{\left(\sqrt{-\sqrt{x} \cdot y} \cdot \sqrt{-\sqrt{x} \cdot y}\right)} \cdot \left(\sqrt{x} \cdot y\right) \]
      2. sqrt-unprod26.5%

        \[\leadsto x \cdot y + \color{blue}{\sqrt{\left(-\sqrt{x} \cdot y\right) \cdot \left(-\sqrt{x} \cdot y\right)}} \cdot \left(\sqrt{x} \cdot y\right) \]
      3. sqr-neg26.5%

        \[\leadsto x \cdot y + \sqrt{\color{blue}{\left(\sqrt{x} \cdot y\right) \cdot \left(\sqrt{x} \cdot y\right)}} \cdot \left(\sqrt{x} \cdot y\right) \]
      4. sqrt-unprod0.1%

        \[\leadsto x \cdot y + \color{blue}{\left(\sqrt{\sqrt{x} \cdot y} \cdot \sqrt{\sqrt{x} \cdot y}\right)} \cdot \left(\sqrt{x} \cdot y\right) \]
      5. add-sqr-sqrt0.3%

        \[\leadsto x \cdot y + \color{blue}{\left(\sqrt{x} \cdot y\right)} \cdot \left(\sqrt{x} \cdot y\right) \]
      6. cancel-sign-sub0.3%

        \[\leadsto \color{blue}{x \cdot y - \left(-\sqrt{x} \cdot y\right) \cdot \left(\sqrt{x} \cdot y\right)} \]
      7. associate-*r*0.3%

        \[\leadsto x \cdot y - \color{blue}{\left(\left(-\sqrt{x} \cdot y\right) \cdot \sqrt{x}\right) \cdot y} \]
      8. distribute-rgt-out--0.3%

        \[\leadsto \color{blue}{y \cdot \left(x - \left(-\sqrt{x} \cdot y\right) \cdot \sqrt{x}\right)} \]
      9. *-commutative0.3%

        \[\leadsto y \cdot \left(x - \color{blue}{\sqrt{x} \cdot \left(-\sqrt{x} \cdot y\right)}\right) \]
      10. add-sqr-sqrt0.1%

        \[\leadsto y \cdot \left(x - \sqrt{x} \cdot \color{blue}{\left(\sqrt{-\sqrt{x} \cdot y} \cdot \sqrt{-\sqrt{x} \cdot y}\right)}\right) \]
      11. sqrt-unprod22.7%

        \[\leadsto y \cdot \left(x - \sqrt{x} \cdot \color{blue}{\sqrt{\left(-\sqrt{x} \cdot y\right) \cdot \left(-\sqrt{x} \cdot y\right)}}\right) \]
      12. sqr-neg22.7%

        \[\leadsto y \cdot \left(x - \sqrt{x} \cdot \sqrt{\color{blue}{\left(\sqrt{x} \cdot y\right) \cdot \left(\sqrt{x} \cdot y\right)}}\right) \]
      13. sqrt-unprod22.6%

        \[\leadsto y \cdot \left(x - \sqrt{x} \cdot \color{blue}{\left(\sqrt{\sqrt{x} \cdot y} \cdot \sqrt{\sqrt{x} \cdot y}\right)}\right) \]
    9. Applied egg-rr99.8%

      \[\leadsto \color{blue}{y \cdot \left(x - x \cdot y\right)} \]
    10. Taylor expanded in y around inf 97.7%

      \[\leadsto y \cdot \color{blue}{\left(-1 \cdot \left(x \cdot y\right)\right)} \]
    11. Step-by-step derivation
      1. associate-*r*97.7%

        \[\leadsto y \cdot \color{blue}{\left(\left(-1 \cdot x\right) \cdot y\right)} \]
      2. neg-mul-197.7%

        \[\leadsto y \cdot \left(\color{blue}{\left(-x\right)} \cdot y\right) \]
      3. *-commutative97.7%

        \[\leadsto y \cdot \color{blue}{\left(y \cdot \left(-x\right)\right)} \]
    12. Simplified97.7%

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

    if -1 < y < 1

    1. Initial program 99.9%

      \[\left(x \cdot y\right) \cdot \left(1 - y\right) \]
    2. Step-by-step derivation
      1. associate-*l*99.9%

        \[\leadsto \color{blue}{x \cdot \left(y \cdot \left(1 - y\right)\right)} \]
    3. Simplified99.9%

      \[\leadsto \color{blue}{x \cdot \left(y \cdot \left(1 - y\right)\right)} \]
    4. Taylor expanded in y around 0 96.2%

      \[\leadsto \color{blue}{x \cdot y} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification97.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1\right):\\ \;\;\;\;y \cdot \left(y \cdot \left(-x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]

Alternative 3: 97.1% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 1.5 \cdot 10^{+126}:\\ \;\;\;\;x \cdot \left(y \cdot \left(1 - y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(y \cdot \left(-x\right)\right)\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= y 1.5e+126) (* x (* y (- 1.0 y))) (* y (* y (- x)))))
double code(double x, double y) {
	double tmp;
	if (y <= 1.5e+126) {
		tmp = x * (y * (1.0 - y));
	} else {
		tmp = y * (y * -x);
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (y <= 1.5d+126) then
        tmp = x * (y * (1.0d0 - y))
    else
        tmp = y * (y * -x)
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (y <= 1.5e+126) {
		tmp = x * (y * (1.0 - y));
	} else {
		tmp = y * (y * -x);
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if y <= 1.5e+126:
		tmp = x * (y * (1.0 - y))
	else:
		tmp = y * (y * -x)
	return tmp
function code(x, y)
	tmp = 0.0
	if (y <= 1.5e+126)
		tmp = Float64(x * Float64(y * Float64(1.0 - y)));
	else
		tmp = Float64(y * Float64(y * Float64(-x)));
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= 1.5e+126)
		tmp = x * (y * (1.0 - y));
	else
		tmp = y * (y * -x);
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[y, 1.5e+126], N[(x * N[(y * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * N[(y * (-x)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.5 \cdot 10^{+126}:\\
\;\;\;\;x \cdot \left(y \cdot \left(1 - y\right)\right)\\

\mathbf{else}:\\
\;\;\;\;y \cdot \left(y \cdot \left(-x\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 1.5000000000000001e126

    1. Initial program 99.9%

      \[\left(x \cdot y\right) \cdot \left(1 - y\right) \]
    2. Step-by-step derivation
      1. associate-*l*98.6%

        \[\leadsto \color{blue}{x \cdot \left(y \cdot \left(1 - y\right)\right)} \]
    3. Simplified98.6%

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

    if 1.5000000000000001e126 < y

    1. Initial program 99.9%

      \[\left(x \cdot y\right) \cdot \left(1 - y\right) \]
    2. Step-by-step derivation
      1. associate-*l*82.1%

        \[\leadsto \color{blue}{x \cdot \left(y \cdot \left(1 - y\right)\right)} \]
    3. Simplified82.1%

      \[\leadsto \color{blue}{x \cdot \left(y \cdot \left(1 - y\right)\right)} \]
    4. Step-by-step derivation
      1. associate-*r*99.9%

        \[\leadsto \color{blue}{\left(x \cdot y\right) \cdot \left(1 - y\right)} \]
      2. sub-neg99.9%

        \[\leadsto \left(x \cdot y\right) \cdot \color{blue}{\left(1 + \left(-y\right)\right)} \]
      3. distribute-lft-in67.5%

        \[\leadsto \color{blue}{\left(x \cdot y\right) \cdot 1 + \left(x \cdot y\right) \cdot \left(-y\right)} \]
      4. *-commutative67.5%

        \[\leadsto \color{blue}{1 \cdot \left(x \cdot y\right)} + \left(x \cdot y\right) \cdot \left(-y\right) \]
      5. *-un-lft-identity67.5%

        \[\leadsto \color{blue}{x \cdot y} + \left(x \cdot y\right) \cdot \left(-y\right) \]
      6. *-commutative67.5%

        \[\leadsto \color{blue}{y \cdot x} + \left(x \cdot y\right) \cdot \left(-y\right) \]
      7. fma-def99.9%

        \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, \left(x \cdot y\right) \cdot \left(-y\right)\right)} \]
    5. Applied egg-rr99.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, \left(x \cdot y\right) \cdot \left(-y\right)\right)} \]
    6. Step-by-step derivation
      1. fma-udef67.5%

        \[\leadsto \color{blue}{y \cdot x + \left(x \cdot y\right) \cdot \left(-y\right)} \]
      2. *-commutative67.5%

        \[\leadsto \color{blue}{x \cdot y} + \left(x \cdot y\right) \cdot \left(-y\right) \]
      3. distribute-rgt-neg-out67.5%

        \[\leadsto x \cdot y + \color{blue}{\left(-\left(x \cdot y\right) \cdot y\right)} \]
      4. distribute-lft-neg-in67.5%

        \[\leadsto x \cdot y + \color{blue}{\left(-x \cdot y\right) \cdot y} \]
      5. add-sqr-sqrt67.4%

        \[\leadsto x \cdot y + \left(-x \cdot y\right) \cdot \color{blue}{\left(\sqrt{y} \cdot \sqrt{y}\right)} \]
      6. sqrt-unprod49.7%

        \[\leadsto x \cdot y + \left(-x \cdot y\right) \cdot \color{blue}{\sqrt{y \cdot y}} \]
      7. sqr-neg49.7%

        \[\leadsto x \cdot y + \left(-x \cdot y\right) \cdot \sqrt{\color{blue}{\left(-y\right) \cdot \left(-y\right)}} \]
      8. sqrt-unprod0.0%

        \[\leadsto x \cdot y + \left(-x \cdot y\right) \cdot \color{blue}{\left(\sqrt{-y} \cdot \sqrt{-y}\right)} \]
      9. add-sqr-sqrt0.2%

        \[\leadsto x \cdot y + \left(-x \cdot y\right) \cdot \color{blue}{\left(-y\right)} \]
      10. cancel-sign-sub-inv0.2%

        \[\leadsto \color{blue}{x \cdot y - \left(x \cdot y\right) \cdot \left(-y\right)} \]
      11. add-sqr-sqrt0.1%

        \[\leadsto x \cdot y - \color{blue}{\sqrt{\left(x \cdot y\right) \cdot \left(-y\right)} \cdot \sqrt{\left(x \cdot y\right) \cdot \left(-y\right)}} \]
      12. cancel-sign-sub-inv0.1%

        \[\leadsto \color{blue}{x \cdot y + \left(-\sqrt{\left(x \cdot y\right) \cdot \left(-y\right)}\right) \cdot \sqrt{\left(x \cdot y\right) \cdot \left(-y\right)}} \]
    7. Applied egg-rr37.6%

      \[\leadsto \color{blue}{x \cdot y + \left(-\sqrt{x} \cdot y\right) \cdot \left(\sqrt{x} \cdot y\right)} \]
    8. Step-by-step derivation
      1. add-sqr-sqrt0.0%

        \[\leadsto x \cdot y + \color{blue}{\left(\sqrt{-\sqrt{x} \cdot y} \cdot \sqrt{-\sqrt{x} \cdot y}\right)} \cdot \left(\sqrt{x} \cdot y\right) \]
      2. sqrt-unprod0.1%

        \[\leadsto x \cdot y + \color{blue}{\sqrt{\left(-\sqrt{x} \cdot y\right) \cdot \left(-\sqrt{x} \cdot y\right)}} \cdot \left(\sqrt{x} \cdot y\right) \]
      3. sqr-neg0.1%

        \[\leadsto x \cdot y + \sqrt{\color{blue}{\left(\sqrt{x} \cdot y\right) \cdot \left(\sqrt{x} \cdot y\right)}} \cdot \left(\sqrt{x} \cdot y\right) \]
      4. sqrt-unprod0.1%

        \[\leadsto x \cdot y + \color{blue}{\left(\sqrt{\sqrt{x} \cdot y} \cdot \sqrt{\sqrt{x} \cdot y}\right)} \cdot \left(\sqrt{x} \cdot y\right) \]
      5. add-sqr-sqrt0.1%

        \[\leadsto x \cdot y + \color{blue}{\left(\sqrt{x} \cdot y\right)} \cdot \left(\sqrt{x} \cdot y\right) \]
      6. cancel-sign-sub0.1%

        \[\leadsto \color{blue}{x \cdot y - \left(-\sqrt{x} \cdot y\right) \cdot \left(\sqrt{x} \cdot y\right)} \]
      7. associate-*r*0.1%

        \[\leadsto x \cdot y - \color{blue}{\left(\left(-\sqrt{x} \cdot y\right) \cdot \sqrt{x}\right) \cdot y} \]
      8. distribute-rgt-out--0.1%

        \[\leadsto \color{blue}{y \cdot \left(x - \left(-\sqrt{x} \cdot y\right) \cdot \sqrt{x}\right)} \]
      9. *-commutative0.1%

        \[\leadsto y \cdot \left(x - \color{blue}{\sqrt{x} \cdot \left(-\sqrt{x} \cdot y\right)}\right) \]
      10. add-sqr-sqrt0.0%

        \[\leadsto y \cdot \left(x - \sqrt{x} \cdot \color{blue}{\left(\sqrt{-\sqrt{x} \cdot y} \cdot \sqrt{-\sqrt{x} \cdot y}\right)}\right) \]
      11. sqrt-unprod51.2%

        \[\leadsto y \cdot \left(x - \sqrt{x} \cdot \color{blue}{\sqrt{\left(-\sqrt{x} \cdot y\right) \cdot \left(-\sqrt{x} \cdot y\right)}}\right) \]
      12. sqr-neg51.2%

        \[\leadsto y \cdot \left(x - \sqrt{x} \cdot \sqrt{\color{blue}{\left(\sqrt{x} \cdot y\right) \cdot \left(\sqrt{x} \cdot y\right)}}\right) \]
      13. sqrt-unprod51.2%

        \[\leadsto y \cdot \left(x - \sqrt{x} \cdot \color{blue}{\left(\sqrt{\sqrt{x} \cdot y} \cdot \sqrt{\sqrt{x} \cdot y}\right)}\right) \]
    9. Applied egg-rr99.9%

      \[\leadsto \color{blue}{y \cdot \left(x - x \cdot y\right)} \]
    10. Taylor expanded in y around inf 99.9%

      \[\leadsto y \cdot \color{blue}{\left(-1 \cdot \left(x \cdot y\right)\right)} \]
    11. Step-by-step derivation
      1. associate-*r*99.9%

        \[\leadsto y \cdot \color{blue}{\left(\left(-1 \cdot x\right) \cdot y\right)} \]
      2. neg-mul-199.9%

        \[\leadsto y \cdot \left(\color{blue}{\left(-x\right)} \cdot y\right) \]
      3. *-commutative99.9%

        \[\leadsto y \cdot \color{blue}{\left(y \cdot \left(-x\right)\right)} \]
    12. Simplified99.9%

      \[\leadsto y \cdot \color{blue}{\left(y \cdot \left(-x\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification98.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 1.5 \cdot 10^{+126}:\\ \;\;\;\;x \cdot \left(y \cdot \left(1 - y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(y \cdot \left(-x\right)\right)\\ \end{array} \]

Alternative 4: 99.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ y \cdot \left(x - y \cdot x\right) \end{array} \]
(FPCore (x y) :precision binary64 (* y (- x (* y x))))
double code(double x, double y) {
	return y * (x - (y * x));
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = y * (x - (y * x))
end function
public static double code(double x, double y) {
	return y * (x - (y * x));
}
def code(x, y):
	return y * (x - (y * x))
function code(x, y)
	return Float64(y * Float64(x - Float64(y * x)))
end
function tmp = code(x, y)
	tmp = y * (x - (y * x));
end
code[x_, y_] := N[(y * N[(x - N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
y \cdot \left(x - y \cdot x\right)
\end{array}
Derivation
  1. Initial program 99.9%

    \[\left(x \cdot y\right) \cdot \left(1 - y\right) \]
  2. Step-by-step derivation
    1. associate-*l*96.2%

      \[\leadsto \color{blue}{x \cdot \left(y \cdot \left(1 - y\right)\right)} \]
  3. Simplified96.2%

    \[\leadsto \color{blue}{x \cdot \left(y \cdot \left(1 - y\right)\right)} \]
  4. Step-by-step derivation
    1. associate-*r*99.9%

      \[\leadsto \color{blue}{\left(x \cdot y\right) \cdot \left(1 - y\right)} \]
    2. sub-neg99.9%

      \[\leadsto \left(x \cdot y\right) \cdot \color{blue}{\left(1 + \left(-y\right)\right)} \]
    3. distribute-lft-in95.2%

      \[\leadsto \color{blue}{\left(x \cdot y\right) \cdot 1 + \left(x \cdot y\right) \cdot \left(-y\right)} \]
    4. *-commutative95.2%

      \[\leadsto \color{blue}{1 \cdot \left(x \cdot y\right)} + \left(x \cdot y\right) \cdot \left(-y\right) \]
    5. *-un-lft-identity95.2%

      \[\leadsto \color{blue}{x \cdot y} + \left(x \cdot y\right) \cdot \left(-y\right) \]
    6. *-commutative95.2%

      \[\leadsto \color{blue}{y \cdot x} + \left(x \cdot y\right) \cdot \left(-y\right) \]
    7. fma-def99.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, \left(x \cdot y\right) \cdot \left(-y\right)\right)} \]
  5. Applied egg-rr99.9%

    \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, \left(x \cdot y\right) \cdot \left(-y\right)\right)} \]
  6. Step-by-step derivation
    1. fma-udef95.2%

      \[\leadsto \color{blue}{y \cdot x + \left(x \cdot y\right) \cdot \left(-y\right)} \]
    2. *-commutative95.2%

      \[\leadsto \color{blue}{x \cdot y} + \left(x \cdot y\right) \cdot \left(-y\right) \]
    3. distribute-rgt-neg-out95.2%

      \[\leadsto x \cdot y + \color{blue}{\left(-\left(x \cdot y\right) \cdot y\right)} \]
    4. distribute-lft-neg-in95.2%

      \[\leadsto x \cdot y + \color{blue}{\left(-x \cdot y\right) \cdot y} \]
    5. add-sqr-sqrt43.6%

      \[\leadsto x \cdot y + \left(-x \cdot y\right) \cdot \color{blue}{\left(\sqrt{y} \cdot \sqrt{y}\right)} \]
    6. sqrt-unprod66.3%

      \[\leadsto x \cdot y + \left(-x \cdot y\right) \cdot \color{blue}{\sqrt{y \cdot y}} \]
    7. sqr-neg66.3%

      \[\leadsto x \cdot y + \left(-x \cdot y\right) \cdot \sqrt{\color{blue}{\left(-y\right) \cdot \left(-y\right)}} \]
    8. sqrt-unprod25.2%

      \[\leadsto x \cdot y + \left(-x \cdot y\right) \cdot \color{blue}{\left(\sqrt{-y} \cdot \sqrt{-y}\right)} \]
    9. add-sqr-sqrt46.9%

      \[\leadsto x \cdot y + \left(-x \cdot y\right) \cdot \color{blue}{\left(-y\right)} \]
    10. cancel-sign-sub-inv46.9%

      \[\leadsto \color{blue}{x \cdot y - \left(x \cdot y\right) \cdot \left(-y\right)} \]
    11. add-sqr-sqrt35.3%

      \[\leadsto x \cdot y - \color{blue}{\sqrt{\left(x \cdot y\right) \cdot \left(-y\right)} \cdot \sqrt{\left(x \cdot y\right) \cdot \left(-y\right)}} \]
    12. cancel-sign-sub-inv35.3%

      \[\leadsto \color{blue}{x \cdot y + \left(-\sqrt{\left(x \cdot y\right) \cdot \left(-y\right)}\right) \cdot \sqrt{\left(x \cdot y\right) \cdot \left(-y\right)}} \]
  7. Applied egg-rr47.5%

    \[\leadsto \color{blue}{x \cdot y + \left(-\sqrt{x} \cdot y\right) \cdot \left(\sqrt{x} \cdot y\right)} \]
  8. Step-by-step derivation
    1. add-sqr-sqrt29.6%

      \[\leadsto x \cdot y + \color{blue}{\left(\sqrt{-\sqrt{x} \cdot y} \cdot \sqrt{-\sqrt{x} \cdot y}\right)} \cdot \left(\sqrt{x} \cdot y\right) \]
    2. sqrt-unprod37.9%

      \[\leadsto x \cdot y + \color{blue}{\sqrt{\left(-\sqrt{x} \cdot y\right) \cdot \left(-\sqrt{x} \cdot y\right)}} \cdot \left(\sqrt{x} \cdot y\right) \]
    3. sqr-neg37.9%

      \[\leadsto x \cdot y + \sqrt{\color{blue}{\left(\sqrt{x} \cdot y\right) \cdot \left(\sqrt{x} \cdot y\right)}} \cdot \left(\sqrt{x} \cdot y\right) \]
    4. sqrt-unprod12.2%

      \[\leadsto x \cdot y + \color{blue}{\left(\sqrt{\sqrt{x} \cdot y} \cdot \sqrt{\sqrt{x} \cdot y}\right)} \cdot \left(\sqrt{x} \cdot y\right) \]
    5. add-sqr-sqrt23.3%

      \[\leadsto x \cdot y + \color{blue}{\left(\sqrt{x} \cdot y\right)} \cdot \left(\sqrt{x} \cdot y\right) \]
    6. cancel-sign-sub23.3%

      \[\leadsto \color{blue}{x \cdot y - \left(-\sqrt{x} \cdot y\right) \cdot \left(\sqrt{x} \cdot y\right)} \]
    7. associate-*r*23.3%

      \[\leadsto x \cdot y - \color{blue}{\left(\left(-\sqrt{x} \cdot y\right) \cdot \sqrt{x}\right) \cdot y} \]
    8. distribute-rgt-out--23.3%

      \[\leadsto \color{blue}{y \cdot \left(x - \left(-\sqrt{x} \cdot y\right) \cdot \sqrt{x}\right)} \]
    9. *-commutative23.3%

      \[\leadsto y \cdot \left(x - \color{blue}{\sqrt{x} \cdot \left(-\sqrt{x} \cdot y\right)}\right) \]
    10. add-sqr-sqrt15.0%

      \[\leadsto y \cdot \left(x - \sqrt{x} \cdot \color{blue}{\left(\sqrt{-\sqrt{x} \cdot y} \cdot \sqrt{-\sqrt{x} \cdot y}\right)}\right) \]
    11. sqrt-unprod34.9%

      \[\leadsto y \cdot \left(x - \sqrt{x} \cdot \color{blue}{\sqrt{\left(-\sqrt{x} \cdot y\right) \cdot \left(-\sqrt{x} \cdot y\right)}}\right) \]
    12. sqr-neg34.9%

      \[\leadsto y \cdot \left(x - \sqrt{x} \cdot \sqrt{\color{blue}{\left(\sqrt{x} \cdot y\right) \cdot \left(\sqrt{x} \cdot y\right)}}\right) \]
    13. sqrt-unprod23.8%

      \[\leadsto y \cdot \left(x - \sqrt{x} \cdot \color{blue}{\left(\sqrt{\sqrt{x} \cdot y} \cdot \sqrt{\sqrt{x} \cdot y}\right)}\right) \]
  9. Applied egg-rr99.9%

    \[\leadsto \color{blue}{y \cdot \left(x - x \cdot y\right)} \]
  10. Final simplification99.9%

    \[\leadsto y \cdot \left(x - y \cdot x\right) \]

Alternative 5: 63.1% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 1:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \end{array} \end{array} \]
(FPCore (x y) :precision binary64 (if (<= y 1.0) (* y x) (* y (- x))))
double code(double x, double y) {
	double tmp;
	if (y <= 1.0) {
		tmp = y * x;
	} else {
		tmp = y * -x;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (y <= 1.0d0) then
        tmp = y * x
    else
        tmp = y * -x
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (y <= 1.0) {
		tmp = y * x;
	} else {
		tmp = y * -x;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if y <= 1.0:
		tmp = y * x
	else:
		tmp = y * -x
	return tmp
function code(x, y)
	tmp = 0.0
	if (y <= 1.0)
		tmp = Float64(y * x);
	else
		tmp = Float64(y * Float64(-x));
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= 1.0)
		tmp = y * x;
	else
		tmp = y * -x;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[y, 1.0], N[(y * x), $MachinePrecision], N[(y * (-x)), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq 1:\\
\;\;\;\;y \cdot x\\

\mathbf{else}:\\
\;\;\;\;y \cdot \left(-x\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 1

    1. Initial program 99.9%

      \[\left(x \cdot y\right) \cdot \left(1 - y\right) \]
    2. Step-by-step derivation
      1. associate-*l*98.4%

        \[\leadsto \color{blue}{x \cdot \left(y \cdot \left(1 - y\right)\right)} \]
    3. Simplified98.4%

      \[\leadsto \color{blue}{x \cdot \left(y \cdot \left(1 - y\right)\right)} \]
    4. Taylor expanded in y around 0 74.3%

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

    if 1 < y

    1. Initial program 99.8%

      \[\left(x \cdot y\right) \cdot \left(1 - y\right) \]
    2. Step-by-step derivation
      1. associate-*l*90.1%

        \[\leadsto \color{blue}{x \cdot \left(y \cdot \left(1 - y\right)\right)} \]
    3. Simplified90.1%

      \[\leadsto \color{blue}{x \cdot \left(y \cdot \left(1 - y\right)\right)} \]
    4. Step-by-step derivation
      1. associate-*r*99.8%

        \[\leadsto \color{blue}{\left(x \cdot y\right) \cdot \left(1 - y\right)} \]
      2. flip--89.9%

        \[\leadsto \left(x \cdot y\right) \cdot \color{blue}{\frac{1 \cdot 1 - y \cdot y}{1 + y}} \]
      3. associate-*r/83.1%

        \[\leadsto \color{blue}{\frac{\left(x \cdot y\right) \cdot \left(1 \cdot 1 - y \cdot y\right)}{1 + y}} \]
      4. metadata-eval83.1%

        \[\leadsto \frac{\left(x \cdot y\right) \cdot \left(\color{blue}{1} - y \cdot y\right)}{1 + y} \]
      5. pow283.1%

        \[\leadsto \frac{\left(x \cdot y\right) \cdot \left(1 - \color{blue}{{y}^{2}}\right)}{1 + y} \]
      6. +-commutative83.1%

        \[\leadsto \frac{\left(x \cdot y\right) \cdot \left(1 - {y}^{2}\right)}{\color{blue}{y + 1}} \]
    5. Applied egg-rr83.1%

      \[\leadsto \color{blue}{\frac{\left(x \cdot y\right) \cdot \left(1 - {y}^{2}\right)}{y + 1}} \]
    6. Step-by-step derivation
      1. associate-*l*78.8%

        \[\leadsto \frac{\color{blue}{x \cdot \left(y \cdot \left(1 - {y}^{2}\right)\right)}}{y + 1} \]
      2. associate-/l*80.0%

        \[\leadsto \color{blue}{\frac{x}{\frac{y + 1}{y \cdot \left(1 - {y}^{2}\right)}}} \]
      3. sub-neg80.0%

        \[\leadsto \frac{x}{\frac{y + 1}{y \cdot \color{blue}{\left(1 + \left(-{y}^{2}\right)\right)}}} \]
      4. distribute-lft-in80.0%

        \[\leadsto \frac{x}{\frac{y + 1}{\color{blue}{y \cdot 1 + y \cdot \left(-{y}^{2}\right)}}} \]
      5. *-rgt-identity80.0%

        \[\leadsto \frac{x}{\frac{y + 1}{\color{blue}{y} + y \cdot \left(-{y}^{2}\right)}} \]
      6. distribute-rgt-neg-in80.0%

        \[\leadsto \frac{x}{\frac{y + 1}{y + \color{blue}{\left(-y \cdot {y}^{2}\right)}}} \]
      7. unpow280.0%

        \[\leadsto \frac{x}{\frac{y + 1}{y + \left(-y \cdot \color{blue}{\left(y \cdot y\right)}\right)}} \]
      8. cube-mult80.1%

        \[\leadsto \frac{x}{\frac{y + 1}{y + \left(-\color{blue}{{y}^{3}}\right)}} \]
      9. unsub-neg80.1%

        \[\leadsto \frac{x}{\frac{y + 1}{\color{blue}{y - {y}^{3}}}} \]
    7. Simplified80.1%

      \[\leadsto \color{blue}{\frac{x}{\frac{y + 1}{y - {y}^{3}}}} \]
    8. Taylor expanded in y around 0 0.9%

      \[\leadsto \frac{x}{\color{blue}{\frac{1}{y}}} \]
    9. Step-by-step derivation
      1. associate-/r/0.9%

        \[\leadsto \color{blue}{\frac{x}{1} \cdot y} \]
      2. /-rgt-identity0.9%

        \[\leadsto \color{blue}{x} \cdot y \]
      3. add-sqr-sqrt0.3%

        \[\leadsto \color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right)} \cdot y \]
      4. associate-*l*0.3%

        \[\leadsto \color{blue}{\sqrt{x} \cdot \left(\sqrt{x} \cdot y\right)} \]
      5. add-sqr-sqrt0.3%

        \[\leadsto \sqrt{x} \cdot \color{blue}{\left(\sqrt{\sqrt{x} \cdot y} \cdot \sqrt{\sqrt{x} \cdot y}\right)} \]
      6. sqrt-unprod0.3%

        \[\leadsto \sqrt{x} \cdot \color{blue}{\sqrt{\left(\sqrt{x} \cdot y\right) \cdot \left(\sqrt{x} \cdot y\right)}} \]
      7. sqr-neg0.3%

        \[\leadsto \sqrt{x} \cdot \sqrt{\color{blue}{\left(-\sqrt{x} \cdot y\right) \cdot \left(-\sqrt{x} \cdot y\right)}} \]
      8. sqrt-unprod0.0%

        \[\leadsto \sqrt{x} \cdot \color{blue}{\left(\sqrt{-\sqrt{x} \cdot y} \cdot \sqrt{-\sqrt{x} \cdot y}\right)} \]
      9. add-sqr-sqrt9.8%

        \[\leadsto \sqrt{x} \cdot \color{blue}{\left(-\sqrt{x} \cdot y\right)} \]
      10. *-commutative9.8%

        \[\leadsto \color{blue}{\left(-\sqrt{x} \cdot y\right) \cdot \sqrt{x}} \]
      11. neg-mul-19.8%

        \[\leadsto \color{blue}{\left(-1 \cdot \left(\sqrt{x} \cdot y\right)\right)} \cdot \sqrt{x} \]
      12. associate-*l*9.8%

        \[\leadsto \color{blue}{-1 \cdot \left(\left(\sqrt{x} \cdot y\right) \cdot \sqrt{x}\right)} \]
      13. *-commutative9.8%

        \[\leadsto -1 \cdot \left(\color{blue}{\left(y \cdot \sqrt{x}\right)} \cdot \sqrt{x}\right) \]
      14. associate-*r*9.8%

        \[\leadsto -1 \cdot \color{blue}{\left(y \cdot \left(\sqrt{x} \cdot \sqrt{x}\right)\right)} \]
      15. add-sqr-sqrt23.5%

        \[\leadsto -1 \cdot \left(y \cdot \color{blue}{x}\right) \]
      16. *-commutative23.5%

        \[\leadsto -1 \cdot \color{blue}{\left(x \cdot y\right)} \]
    10. Applied egg-rr23.5%

      \[\leadsto \color{blue}{-1 \cdot \left(x \cdot y\right)} \]
    11. Step-by-step derivation
      1. neg-mul-123.5%

        \[\leadsto \color{blue}{-x \cdot y} \]
      2. distribute-rgt-neg-in23.5%

        \[\leadsto \color{blue}{x \cdot \left(-y\right)} \]
    12. Simplified23.5%

      \[\leadsto \color{blue}{x \cdot \left(-y\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification61.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 1:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \end{array} \]

Alternative 6: 55.3% accurate, 2.3× speedup?

\[\begin{array}{l} \\ y \cdot x \end{array} \]
(FPCore (x y) :precision binary64 (* y x))
double code(double x, double y) {
	return y * x;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = y * x
end function
public static double code(double x, double y) {
	return y * x;
}
def code(x, y):
	return y * x
function code(x, y)
	return Float64(y * x)
end
function tmp = code(x, y)
	tmp = y * x;
end
code[x_, y_] := N[(y * x), $MachinePrecision]
\begin{array}{l}

\\
y \cdot x
\end{array}
Derivation
  1. Initial program 99.9%

    \[\left(x \cdot y\right) \cdot \left(1 - y\right) \]
  2. Step-by-step derivation
    1. associate-*l*96.2%

      \[\leadsto \color{blue}{x \cdot \left(y \cdot \left(1 - y\right)\right)} \]
  3. Simplified96.2%

    \[\leadsto \color{blue}{x \cdot \left(y \cdot \left(1 - y\right)\right)} \]
  4. Taylor expanded in y around 0 55.1%

    \[\leadsto \color{blue}{x \cdot y} \]
  5. Final simplification55.1%

    \[\leadsto y \cdot x \]

Alternative 7: 2.8% accurate, 7.0× speedup?

\[\begin{array}{l} \\ x \end{array} \]
(FPCore (x y) :precision binary64 x)
double code(double x, double y) {
	return x;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = x
end function
public static double code(double x, double y) {
	return x;
}
def code(x, y):
	return x
function code(x, y)
	return x
end
function tmp = code(x, y)
	tmp = x;
end
code[x_, y_] := x
\begin{array}{l}

\\
x
\end{array}
Derivation
  1. Initial program 99.9%

    \[\left(x \cdot y\right) \cdot \left(1 - y\right) \]
  2. Step-by-step derivation
    1. associate-*l*96.2%

      \[\leadsto \color{blue}{x \cdot \left(y \cdot \left(1 - y\right)\right)} \]
  3. Simplified96.2%

    \[\leadsto \color{blue}{x \cdot \left(y \cdot \left(1 - y\right)\right)} \]
  4. Step-by-step derivation
    1. associate-*r*99.9%

      \[\leadsto \color{blue}{\left(x \cdot y\right) \cdot \left(1 - y\right)} \]
    2. flip--96.2%

      \[\leadsto \left(x \cdot y\right) \cdot \color{blue}{\frac{1 \cdot 1 - y \cdot y}{1 + y}} \]
    3. associate-*r/92.3%

      \[\leadsto \color{blue}{\frac{\left(x \cdot y\right) \cdot \left(1 \cdot 1 - y \cdot y\right)}{1 + y}} \]
    4. metadata-eval92.3%

      \[\leadsto \frac{\left(x \cdot y\right) \cdot \left(\color{blue}{1} - y \cdot y\right)}{1 + y} \]
    5. pow292.3%

      \[\leadsto \frac{\left(x \cdot y\right) \cdot \left(1 - \color{blue}{{y}^{2}}\right)}{1 + y} \]
    6. +-commutative92.3%

      \[\leadsto \frac{\left(x \cdot y\right) \cdot \left(1 - {y}^{2}\right)}{\color{blue}{y + 1}} \]
  5. Applied egg-rr92.3%

    \[\leadsto \color{blue}{\frac{\left(x \cdot y\right) \cdot \left(1 - {y}^{2}\right)}{y + 1}} \]
  6. Step-by-step derivation
    1. associate-*l*89.7%

      \[\leadsto \frac{\color{blue}{x \cdot \left(y \cdot \left(1 - {y}^{2}\right)\right)}}{y + 1} \]
    2. associate-/l*91.2%

      \[\leadsto \color{blue}{\frac{x}{\frac{y + 1}{y \cdot \left(1 - {y}^{2}\right)}}} \]
    3. sub-neg91.2%

      \[\leadsto \frac{x}{\frac{y + 1}{y \cdot \color{blue}{\left(1 + \left(-{y}^{2}\right)\right)}}} \]
    4. distribute-lft-in91.2%

      \[\leadsto \frac{x}{\frac{y + 1}{\color{blue}{y \cdot 1 + y \cdot \left(-{y}^{2}\right)}}} \]
    5. *-rgt-identity91.2%

      \[\leadsto \frac{x}{\frac{y + 1}{\color{blue}{y} + y \cdot \left(-{y}^{2}\right)}} \]
    6. distribute-rgt-neg-in91.2%

      \[\leadsto \frac{x}{\frac{y + 1}{y + \color{blue}{\left(-y \cdot {y}^{2}\right)}}} \]
    7. unpow291.2%

      \[\leadsto \frac{x}{\frac{y + 1}{y + \left(-y \cdot \color{blue}{\left(y \cdot y\right)}\right)}} \]
    8. cube-mult91.3%

      \[\leadsto \frac{x}{\frac{y + 1}{y + \left(-\color{blue}{{y}^{3}}\right)}} \]
    9. unsub-neg91.3%

      \[\leadsto \frac{x}{\frac{y + 1}{\color{blue}{y - {y}^{3}}}} \]
  7. Simplified91.3%

    \[\leadsto \color{blue}{\frac{x}{\frac{y + 1}{y - {y}^{3}}}} \]
  8. Taylor expanded in y around 0 47.5%

    \[\leadsto \frac{x}{\color{blue}{1 + \frac{1}{y}}} \]
  9. Taylor expanded in y around inf 2.8%

    \[\leadsto \color{blue}{x} \]
  10. Final simplification2.8%

    \[\leadsto x \]

Reproduce

?
herbie shell --seed 2023322 
(FPCore (x y)
  :name "Statistics.Distribution.Binomial:$cvariance from math-functions-0.1.5.2"
  :precision binary64
  (* (* x y) (- 1.0 y)))