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

Percentage Accurate: 99.9% → 99.9%
Time: 9.1s
Alternatives: 5
Speedup: 1.0×

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 5 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.4× speedup?

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

\\
\begin{array}{l}
t_0 := 0 - y \cdot \left(y \cdot x\right)\\
\mathbf{if}\;y \leq -2 \cdot 10^{+94}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;y \leq 10^{+56}:\\
\;\;\;\;x \cdot \left(y \cdot \left(1 - y\right)\right)\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


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

    1. Initial program 99.9%

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

        \[\leadsto x \cdot \color{blue}{\left(y \cdot \left(1 - y\right)\right)} \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{\left(y \cdot \left(1 - y\right)\right)}\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(y, \color{blue}{\left(1 - y\right)}\right)\right) \]
      4. --lowering--.f6486.6%

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(y, \mathsf{\_.f64}\left(1, \color{blue}{y}\right)\right)\right) \]
    3. Simplified86.6%

      \[\leadsto \color{blue}{x \cdot \left(y \cdot \left(1 - y\right)\right)} \]
    4. Add Preprocessing
    5. Applied egg-rr86.6%

      \[\leadsto \color{blue}{\frac{y}{y + 1} \cdot \frac{x}{\frac{-1}{-1 + y \cdot y}}} \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \frac{x}{\frac{-1}{-1 + y \cdot y}} \cdot \color{blue}{\frac{y}{y + 1}} \]
      2. clear-numN/A

        \[\leadsto \frac{x}{\frac{-1}{-1 + y \cdot y}} \cdot \frac{1}{\color{blue}{\frac{y + 1}{y}}} \]
      3. frac-timesN/A

        \[\leadsto \frac{x \cdot 1}{\color{blue}{\frac{-1}{-1 + y \cdot y} \cdot \frac{y + 1}{y}}} \]
      4. times-fracN/A

        \[\leadsto \frac{x \cdot 1}{\frac{-1 \cdot \left(y + 1\right)}{\color{blue}{\left(-1 + y \cdot y\right) \cdot y}}} \]
      5. neg-mul-1N/A

        \[\leadsto \frac{x \cdot 1}{\frac{\mathsf{neg}\left(\left(y + 1\right)\right)}{\color{blue}{\left(-1 + y \cdot y\right)} \cdot y}} \]
      6. remove-double-negN/A

        \[\leadsto \frac{x \cdot 1}{\frac{\mathsf{neg}\left(\left(y + 1\right)\right)}{\mathsf{neg}\left(\left(\mathsf{neg}\left(\left(-1 + y \cdot y\right) \cdot y\right)\right)\right)}} \]
      7. frac-2negN/A

        \[\leadsto \frac{x \cdot 1}{\frac{y + 1}{\color{blue}{\mathsf{neg}\left(\left(-1 + y \cdot y\right) \cdot y\right)}}} \]
      8. associate-*r/N/A

        \[\leadsto x \cdot \color{blue}{\frac{1}{\frac{y + 1}{\mathsf{neg}\left(\left(-1 + y \cdot y\right) \cdot y\right)}}} \]
      9. un-div-invN/A

        \[\leadsto \frac{x}{\color{blue}{\frac{y + 1}{\mathsf{neg}\left(\left(-1 + y \cdot y\right) \cdot y\right)}}} \]
      10. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \color{blue}{\left(\frac{y + 1}{\mathsf{neg}\left(\left(-1 + y \cdot y\right) \cdot y\right)}\right)}\right) \]
      11. clear-numN/A

        \[\leadsto \mathsf{/.f64}\left(x, \left(\frac{1}{\color{blue}{\frac{\mathsf{neg}\left(\left(-1 + y \cdot y\right) \cdot y\right)}{y + 1}}}\right)\right) \]
      12. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{/.f64}\left(1, \color{blue}{\left(\frac{\mathsf{neg}\left(\left(-1 + y \cdot y\right) \cdot y\right)}{y + 1}\right)}\right)\right) \]
      13. distribute-frac-negN/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{/.f64}\left(1, \left(\mathsf{neg}\left(\frac{\left(-1 + y \cdot y\right) \cdot y}{y + 1}\right)\right)\right)\right) \]
      14. neg-sub0N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{/.f64}\left(1, \left(0 - \color{blue}{\frac{\left(-1 + y \cdot y\right) \cdot y}{y + 1}}\right)\right)\right) \]
      15. --lowering--.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{/.f64}\left(1, \mathsf{\_.f64}\left(0, \color{blue}{\left(\frac{\left(-1 + y \cdot y\right) \cdot y}{y + 1}\right)}\right)\right)\right) \]
      16. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{/.f64}\left(1, \mathsf{\_.f64}\left(0, \left(\frac{y \cdot \left(-1 + y \cdot y\right)}{\color{blue}{y} + 1}\right)\right)\right)\right) \]
      17. associate-/l*N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{/.f64}\left(1, \mathsf{\_.f64}\left(0, \left(y \cdot \color{blue}{\frac{-1 + y \cdot y}{y + 1}}\right)\right)\right)\right) \]
    7. Applied egg-rr86.6%

      \[\leadsto \color{blue}{\frac{x}{\frac{1}{0 - y \cdot \left(y + -1\right)}}} \]
    8. Taylor expanded in y around inf

      \[\leadsto \mathsf{/.f64}\left(x, \color{blue}{\left(\frac{-1}{{y}^{2}}\right)}\right) \]
    9. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{/.f64}\left(-1, \color{blue}{\left({y}^{2}\right)}\right)\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{/.f64}\left(-1, \left(y \cdot \color{blue}{y}\right)\right)\right) \]
      3. *-lowering-*.f6486.6%

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{/.f64}\left(-1, \mathsf{*.f64}\left(y, \color{blue}{y}\right)\right)\right) \]
    10. Simplified86.6%

      \[\leadsto \frac{x}{\color{blue}{\frac{-1}{y \cdot y}}} \]
    11. Step-by-step derivation
      1. associate-/r*N/A

        \[\leadsto \frac{x}{\frac{\frac{-1}{y}}{\color{blue}{y}}} \]
      2. associate-/r/N/A

        \[\leadsto \frac{x}{\frac{-1}{y}} \cdot \color{blue}{y} \]
      3. associate-*l/N/A

        \[\leadsto \frac{x \cdot y}{\color{blue}{\frac{-1}{y}}} \]
      4. *-commutativeN/A

        \[\leadsto \frac{y \cdot x}{\frac{\color{blue}{-1}}{y}} \]
      5. clear-numN/A

        \[\leadsto \frac{y \cdot x}{\frac{1}{\color{blue}{\frac{y}{-1}}}} \]
      6. inv-powN/A

        \[\leadsto \frac{y \cdot x}{{\left(\frac{y}{-1}\right)}^{\color{blue}{-1}}} \]
      7. sqr-powN/A

        \[\leadsto \frac{y \cdot x}{{\left(\frac{y}{-1}\right)}^{\left(\frac{-1}{2}\right)} \cdot \color{blue}{{\left(\frac{y}{-1}\right)}^{\left(\frac{-1}{2}\right)}}} \]
      8. pow-prod-downN/A

        \[\leadsto \frac{y \cdot x}{{\left(\frac{y}{-1} \cdot \frac{y}{-1}\right)}^{\color{blue}{\left(\frac{-1}{2}\right)}}} \]
      9. div-invN/A

        \[\leadsto \frac{y \cdot x}{{\left(\left(y \cdot \frac{1}{-1}\right) \cdot \frac{y}{-1}\right)}^{\left(\frac{-1}{2}\right)}} \]
      10. metadata-evalN/A

        \[\leadsto \frac{y \cdot x}{{\left(\left(y \cdot -1\right) \cdot \frac{y}{-1}\right)}^{\left(\frac{-1}{2}\right)}} \]
      11. div-invN/A

        \[\leadsto \frac{y \cdot x}{{\left(\left(y \cdot -1\right) \cdot \left(y \cdot \frac{1}{-1}\right)\right)}^{\left(\frac{-1}{2}\right)}} \]
      12. metadata-evalN/A

        \[\leadsto \frac{y \cdot x}{{\left(\left(y \cdot -1\right) \cdot \left(y \cdot -1\right)\right)}^{\left(\frac{-1}{2}\right)}} \]
      13. swap-sqrN/A

        \[\leadsto \frac{y \cdot x}{{\left(\left(y \cdot y\right) \cdot \left(-1 \cdot -1\right)\right)}^{\left(\frac{\color{blue}{-1}}{2}\right)}} \]
      14. metadata-evalN/A

        \[\leadsto \frac{y \cdot x}{{\left(\left(y \cdot y\right) \cdot 1\right)}^{\left(\frac{-1}{2}\right)}} \]
      15. *-rgt-identityN/A

        \[\leadsto \frac{y \cdot x}{{\left(y \cdot y\right)}^{\left(\frac{\color{blue}{-1}}{2}\right)}} \]
      16. pow-prod-downN/A

        \[\leadsto \frac{y \cdot x}{{y}^{\left(\frac{-1}{2}\right)} \cdot \color{blue}{{y}^{\left(\frac{-1}{2}\right)}}} \]
      17. sqr-powN/A

        \[\leadsto \frac{y \cdot x}{{y}^{\color{blue}{-1}}} \]
      18. inv-powN/A

        \[\leadsto \frac{y \cdot x}{\frac{1}{\color{blue}{y}}} \]
      19. frac-2negN/A

        \[\leadsto \frac{\mathsf{neg}\left(y \cdot x\right)}{\color{blue}{\mathsf{neg}\left(\frac{1}{y}\right)}} \]
      20. neg-mul-1N/A

        \[\leadsto \frac{\mathsf{neg}\left(y \cdot x\right)}{-1 \cdot \color{blue}{\frac{1}{y}}} \]
      21. div-invN/A

        \[\leadsto \frac{\mathsf{neg}\left(y \cdot x\right)}{\frac{-1}{\color{blue}{y}}} \]
      22. distribute-frac-negN/A

        \[\leadsto \mathsf{neg}\left(\frac{y \cdot x}{\frac{-1}{y}}\right) \]
      23. neg-lowering-neg.f64N/A

        \[\leadsto \mathsf{neg.f64}\left(\left(\frac{y \cdot x}{\frac{-1}{y}}\right)\right) \]
      24. clear-numN/A

        \[\leadsto \mathsf{neg.f64}\left(\left(\frac{y \cdot x}{\frac{1}{\frac{y}{-1}}}\right)\right) \]
      25. inv-powN/A

        \[\leadsto \mathsf{neg.f64}\left(\left(\frac{y \cdot x}{{\left(\frac{y}{-1}\right)}^{-1}}\right)\right) \]
      26. sqr-powN/A

        \[\leadsto \mathsf{neg.f64}\left(\left(\frac{y \cdot x}{{\left(\frac{y}{-1}\right)}^{\left(\frac{-1}{2}\right)} \cdot {\left(\frac{y}{-1}\right)}^{\left(\frac{-1}{2}\right)}}\right)\right) \]
    12. Applied egg-rr99.9%

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

    if -2e94 < y < 1.00000000000000009e56

    1. Initial program 99.8%

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

        \[\leadsto x \cdot \color{blue}{\left(y \cdot \left(1 - y\right)\right)} \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{\left(y \cdot \left(1 - y\right)\right)}\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(y, \color{blue}{\left(1 - y\right)}\right)\right) \]
      4. --lowering--.f6499.9%

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(y, \mathsf{\_.f64}\left(1, \color{blue}{y}\right)\right)\right) \]
    3. Simplified99.9%

      \[\leadsto \color{blue}{x \cdot \left(y \cdot \left(1 - y\right)\right)} \]
    4. Add Preprocessing
  3. Recombined 2 regimes into one program.
  4. Final simplification99.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -2 \cdot 10^{+94}:\\ \;\;\;\;0 - y \cdot \left(y \cdot x\right)\\ \mathbf{elif}\;y \leq 10^{+56}:\\ \;\;\;\;x \cdot \left(y \cdot \left(1 - y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;0 - y \cdot \left(y \cdot x\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 97.9% accurate, 0.4× speedup?

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

\\
\begin{array}{l}
t_0 := 0 - y \cdot \left(y \cdot x\right)\\
\mathbf{if}\;y \leq -1:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;y \leq 1:\\
\;\;\;\;y \cdot x\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\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*N/A

        \[\leadsto x \cdot \color{blue}{\left(y \cdot \left(1 - y\right)\right)} \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{\left(y \cdot \left(1 - y\right)\right)}\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(y, \color{blue}{\left(1 - y\right)}\right)\right) \]
      4. --lowering--.f6490.2%

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(y, \mathsf{\_.f64}\left(1, \color{blue}{y}\right)\right)\right) \]
    3. Simplified90.2%

      \[\leadsto \color{blue}{x \cdot \left(y \cdot \left(1 - y\right)\right)} \]
    4. Add Preprocessing
    5. Applied egg-rr90.1%

      \[\leadsto \color{blue}{\frac{y}{y + 1} \cdot \frac{x}{\frac{-1}{-1 + y \cdot y}}} \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \frac{x}{\frac{-1}{-1 + y \cdot y}} \cdot \color{blue}{\frac{y}{y + 1}} \]
      2. clear-numN/A

        \[\leadsto \frac{x}{\frac{-1}{-1 + y \cdot y}} \cdot \frac{1}{\color{blue}{\frac{y + 1}{y}}} \]
      3. frac-timesN/A

        \[\leadsto \frac{x \cdot 1}{\color{blue}{\frac{-1}{-1 + y \cdot y} \cdot \frac{y + 1}{y}}} \]
      4. times-fracN/A

        \[\leadsto \frac{x \cdot 1}{\frac{-1 \cdot \left(y + 1\right)}{\color{blue}{\left(-1 + y \cdot y\right) \cdot y}}} \]
      5. neg-mul-1N/A

        \[\leadsto \frac{x \cdot 1}{\frac{\mathsf{neg}\left(\left(y + 1\right)\right)}{\color{blue}{\left(-1 + y \cdot y\right)} \cdot y}} \]
      6. remove-double-negN/A

        \[\leadsto \frac{x \cdot 1}{\frac{\mathsf{neg}\left(\left(y + 1\right)\right)}{\mathsf{neg}\left(\left(\mathsf{neg}\left(\left(-1 + y \cdot y\right) \cdot y\right)\right)\right)}} \]
      7. frac-2negN/A

        \[\leadsto \frac{x \cdot 1}{\frac{y + 1}{\color{blue}{\mathsf{neg}\left(\left(-1 + y \cdot y\right) \cdot y\right)}}} \]
      8. associate-*r/N/A

        \[\leadsto x \cdot \color{blue}{\frac{1}{\frac{y + 1}{\mathsf{neg}\left(\left(-1 + y \cdot y\right) \cdot y\right)}}} \]
      9. un-div-invN/A

        \[\leadsto \frac{x}{\color{blue}{\frac{y + 1}{\mathsf{neg}\left(\left(-1 + y \cdot y\right) \cdot y\right)}}} \]
      10. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \color{blue}{\left(\frac{y + 1}{\mathsf{neg}\left(\left(-1 + y \cdot y\right) \cdot y\right)}\right)}\right) \]
      11. clear-numN/A

        \[\leadsto \mathsf{/.f64}\left(x, \left(\frac{1}{\color{blue}{\frac{\mathsf{neg}\left(\left(-1 + y \cdot y\right) \cdot y\right)}{y + 1}}}\right)\right) \]
      12. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{/.f64}\left(1, \color{blue}{\left(\frac{\mathsf{neg}\left(\left(-1 + y \cdot y\right) \cdot y\right)}{y + 1}\right)}\right)\right) \]
      13. distribute-frac-negN/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{/.f64}\left(1, \left(\mathsf{neg}\left(\frac{\left(-1 + y \cdot y\right) \cdot y}{y + 1}\right)\right)\right)\right) \]
      14. neg-sub0N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{/.f64}\left(1, \left(0 - \color{blue}{\frac{\left(-1 + y \cdot y\right) \cdot y}{y + 1}}\right)\right)\right) \]
      15. --lowering--.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{/.f64}\left(1, \mathsf{\_.f64}\left(0, \color{blue}{\left(\frac{\left(-1 + y \cdot y\right) \cdot y}{y + 1}\right)}\right)\right)\right) \]
      16. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{/.f64}\left(1, \mathsf{\_.f64}\left(0, \left(\frac{y \cdot \left(-1 + y \cdot y\right)}{\color{blue}{y} + 1}\right)\right)\right)\right) \]
      17. associate-/l*N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{/.f64}\left(1, \mathsf{\_.f64}\left(0, \left(y \cdot \color{blue}{\frac{-1 + y \cdot y}{y + 1}}\right)\right)\right)\right) \]
    7. Applied egg-rr90.1%

      \[\leadsto \color{blue}{\frac{x}{\frac{1}{0 - y \cdot \left(y + -1\right)}}} \]
    8. Taylor expanded in y around inf

      \[\leadsto \mathsf{/.f64}\left(x, \color{blue}{\left(\frac{-1}{{y}^{2}}\right)}\right) \]
    9. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{/.f64}\left(-1, \color{blue}{\left({y}^{2}\right)}\right)\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{/.f64}\left(-1, \left(y \cdot \color{blue}{y}\right)\right)\right) \]
      3. *-lowering-*.f6489.2%

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{/.f64}\left(-1, \mathsf{*.f64}\left(y, \color{blue}{y}\right)\right)\right) \]
    10. Simplified89.2%

      \[\leadsto \frac{x}{\color{blue}{\frac{-1}{y \cdot y}}} \]
    11. Step-by-step derivation
      1. associate-/r*N/A

        \[\leadsto \frac{x}{\frac{\frac{-1}{y}}{\color{blue}{y}}} \]
      2. associate-/r/N/A

        \[\leadsto \frac{x}{\frac{-1}{y}} \cdot \color{blue}{y} \]
      3. associate-*l/N/A

        \[\leadsto \frac{x \cdot y}{\color{blue}{\frac{-1}{y}}} \]
      4. *-commutativeN/A

        \[\leadsto \frac{y \cdot x}{\frac{\color{blue}{-1}}{y}} \]
      5. clear-numN/A

        \[\leadsto \frac{y \cdot x}{\frac{1}{\color{blue}{\frac{y}{-1}}}} \]
      6. inv-powN/A

        \[\leadsto \frac{y \cdot x}{{\left(\frac{y}{-1}\right)}^{\color{blue}{-1}}} \]
      7. sqr-powN/A

        \[\leadsto \frac{y \cdot x}{{\left(\frac{y}{-1}\right)}^{\left(\frac{-1}{2}\right)} \cdot \color{blue}{{\left(\frac{y}{-1}\right)}^{\left(\frac{-1}{2}\right)}}} \]
      8. pow-prod-downN/A

        \[\leadsto \frac{y \cdot x}{{\left(\frac{y}{-1} \cdot \frac{y}{-1}\right)}^{\color{blue}{\left(\frac{-1}{2}\right)}}} \]
      9. div-invN/A

        \[\leadsto \frac{y \cdot x}{{\left(\left(y \cdot \frac{1}{-1}\right) \cdot \frac{y}{-1}\right)}^{\left(\frac{-1}{2}\right)}} \]
      10. metadata-evalN/A

        \[\leadsto \frac{y \cdot x}{{\left(\left(y \cdot -1\right) \cdot \frac{y}{-1}\right)}^{\left(\frac{-1}{2}\right)}} \]
      11. div-invN/A

        \[\leadsto \frac{y \cdot x}{{\left(\left(y \cdot -1\right) \cdot \left(y \cdot \frac{1}{-1}\right)\right)}^{\left(\frac{-1}{2}\right)}} \]
      12. metadata-evalN/A

        \[\leadsto \frac{y \cdot x}{{\left(\left(y \cdot -1\right) \cdot \left(y \cdot -1\right)\right)}^{\left(\frac{-1}{2}\right)}} \]
      13. swap-sqrN/A

        \[\leadsto \frac{y \cdot x}{{\left(\left(y \cdot y\right) \cdot \left(-1 \cdot -1\right)\right)}^{\left(\frac{\color{blue}{-1}}{2}\right)}} \]
      14. metadata-evalN/A

        \[\leadsto \frac{y \cdot x}{{\left(\left(y \cdot y\right) \cdot 1\right)}^{\left(\frac{-1}{2}\right)}} \]
      15. *-rgt-identityN/A

        \[\leadsto \frac{y \cdot x}{{\left(y \cdot y\right)}^{\left(\frac{\color{blue}{-1}}{2}\right)}} \]
      16. pow-prod-downN/A

        \[\leadsto \frac{y \cdot x}{{y}^{\left(\frac{-1}{2}\right)} \cdot \color{blue}{{y}^{\left(\frac{-1}{2}\right)}}} \]
      17. sqr-powN/A

        \[\leadsto \frac{y \cdot x}{{y}^{\color{blue}{-1}}} \]
      18. inv-powN/A

        \[\leadsto \frac{y \cdot x}{\frac{1}{\color{blue}{y}}} \]
      19. frac-2negN/A

        \[\leadsto \frac{\mathsf{neg}\left(y \cdot x\right)}{\color{blue}{\mathsf{neg}\left(\frac{1}{y}\right)}} \]
      20. neg-mul-1N/A

        \[\leadsto \frac{\mathsf{neg}\left(y \cdot x\right)}{-1 \cdot \color{blue}{\frac{1}{y}}} \]
      21. div-invN/A

        \[\leadsto \frac{\mathsf{neg}\left(y \cdot x\right)}{\frac{-1}{\color{blue}{y}}} \]
      22. distribute-frac-negN/A

        \[\leadsto \mathsf{neg}\left(\frac{y \cdot x}{\frac{-1}{y}}\right) \]
      23. neg-lowering-neg.f64N/A

        \[\leadsto \mathsf{neg.f64}\left(\left(\frac{y \cdot x}{\frac{-1}{y}}\right)\right) \]
      24. clear-numN/A

        \[\leadsto \mathsf{neg.f64}\left(\left(\frac{y \cdot x}{\frac{1}{\frac{y}{-1}}}\right)\right) \]
      25. inv-powN/A

        \[\leadsto \mathsf{neg.f64}\left(\left(\frac{y \cdot x}{{\left(\frac{y}{-1}\right)}^{-1}}\right)\right) \]
      26. sqr-powN/A

        \[\leadsto \mathsf{neg.f64}\left(\left(\frac{y \cdot x}{{\left(\frac{y}{-1}\right)}^{\left(\frac{-1}{2}\right)} \cdot {\left(\frac{y}{-1}\right)}^{\left(\frac{-1}{2}\right)}}\right)\right) \]
    12. Applied egg-rr98.9%

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

    if -1 < y < 1

    1. Initial program 100.0%

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

        \[\leadsto x \cdot \color{blue}{\left(y \cdot \left(1 - y\right)\right)} \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{\left(y \cdot \left(1 - y\right)\right)}\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(y, \color{blue}{\left(1 - y\right)}\right)\right) \]
      4. --lowering--.f64100.0%

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(y, \mathsf{\_.f64}\left(1, \color{blue}{y}\right)\right)\right) \]
    3. Simplified100.0%

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

      \[\leadsto \color{blue}{x \cdot y} \]
    6. Step-by-step derivation
      1. *-lowering-*.f6496.3%

        \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{y}\right) \]
    7. Simplified96.3%

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

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

Alternative 3: 63.4% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 1:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;0 - y \cdot x\\ \end{array} \end{array} \]
(FPCore (x y) :precision binary64 (if (<= y 1.0) (* y x) (- 0.0 (* y x))))
double code(double x, double y) {
	double tmp;
	if (y <= 1.0) {
		tmp = y * x;
	} else {
		tmp = 0.0 - (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 = 0.0d0 - (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 = 0.0 - (y * x);
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if y <= 1.0:
		tmp = y * x
	else:
		tmp = 0.0 - (y * x)
	return tmp
function code(x, y)
	tmp = 0.0
	if (y <= 1.0)
		tmp = Float64(y * x);
	else
		tmp = Float64(0.0 - Float64(y * x));
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= 1.0)
		tmp = y * x;
	else
		tmp = 0.0 - (y * x);
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[y, 1.0], N[(y * x), $MachinePrecision], N[(0.0 - N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

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

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


\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*N/A

        \[\leadsto x \cdot \color{blue}{\left(y \cdot \left(1 - y\right)\right)} \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{\left(y \cdot \left(1 - y\right)\right)}\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(y, \color{blue}{\left(1 - y\right)}\right)\right) \]
      4. --lowering--.f6497.5%

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(y, \mathsf{\_.f64}\left(1, \color{blue}{y}\right)\right)\right) \]
    3. Simplified97.5%

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

      \[\leadsto \color{blue}{x \cdot y} \]
    6. Step-by-step derivation
      1. *-lowering-*.f6473.7%

        \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{y}\right) \]
    7. Simplified73.7%

      \[\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*N/A

        \[\leadsto x \cdot \color{blue}{\left(y \cdot \left(1 - y\right)\right)} \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{\left(y \cdot \left(1 - y\right)\right)}\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(y, \color{blue}{\left(1 - y\right)}\right)\right) \]
      4. --lowering--.f6487.6%

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(y, \mathsf{\_.f64}\left(1, \color{blue}{y}\right)\right)\right) \]
    3. Simplified87.6%

      \[\leadsto \color{blue}{x \cdot \left(y \cdot \left(1 - y\right)\right)} \]
    4. Add Preprocessing
    5. Applied egg-rr87.5%

      \[\leadsto \color{blue}{\frac{y}{y + 1} \cdot \frac{x}{\frac{-1}{-1 + y \cdot y}}} \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \frac{x}{\frac{-1}{-1 + y \cdot y}} \cdot \color{blue}{\frac{y}{y + 1}} \]
      2. clear-numN/A

        \[\leadsto \frac{x}{\frac{-1}{-1 + y \cdot y}} \cdot \frac{1}{\color{blue}{\frac{y + 1}{y}}} \]
      3. frac-timesN/A

        \[\leadsto \frac{x \cdot 1}{\color{blue}{\frac{-1}{-1 + y \cdot y} \cdot \frac{y + 1}{y}}} \]
      4. times-fracN/A

        \[\leadsto \frac{x \cdot 1}{\frac{-1 \cdot \left(y + 1\right)}{\color{blue}{\left(-1 + y \cdot y\right) \cdot y}}} \]
      5. neg-mul-1N/A

        \[\leadsto \frac{x \cdot 1}{\frac{\mathsf{neg}\left(\left(y + 1\right)\right)}{\color{blue}{\left(-1 + y \cdot y\right)} \cdot y}} \]
      6. remove-double-negN/A

        \[\leadsto \frac{x \cdot 1}{\frac{\mathsf{neg}\left(\left(y + 1\right)\right)}{\mathsf{neg}\left(\left(\mathsf{neg}\left(\left(-1 + y \cdot y\right) \cdot y\right)\right)\right)}} \]
      7. frac-2negN/A

        \[\leadsto \frac{x \cdot 1}{\frac{y + 1}{\color{blue}{\mathsf{neg}\left(\left(-1 + y \cdot y\right) \cdot y\right)}}} \]
      8. associate-*r/N/A

        \[\leadsto x \cdot \color{blue}{\frac{1}{\frac{y + 1}{\mathsf{neg}\left(\left(-1 + y \cdot y\right) \cdot y\right)}}} \]
      9. un-div-invN/A

        \[\leadsto \frac{x}{\color{blue}{\frac{y + 1}{\mathsf{neg}\left(\left(-1 + y \cdot y\right) \cdot y\right)}}} \]
      10. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \color{blue}{\left(\frac{y + 1}{\mathsf{neg}\left(\left(-1 + y \cdot y\right) \cdot y\right)}\right)}\right) \]
      11. clear-numN/A

        \[\leadsto \mathsf{/.f64}\left(x, \left(\frac{1}{\color{blue}{\frac{\mathsf{neg}\left(\left(-1 + y \cdot y\right) \cdot y\right)}{y + 1}}}\right)\right) \]
      12. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{/.f64}\left(1, \color{blue}{\left(\frac{\mathsf{neg}\left(\left(-1 + y \cdot y\right) \cdot y\right)}{y + 1}\right)}\right)\right) \]
      13. distribute-frac-negN/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{/.f64}\left(1, \left(\mathsf{neg}\left(\frac{\left(-1 + y \cdot y\right) \cdot y}{y + 1}\right)\right)\right)\right) \]
      14. neg-sub0N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{/.f64}\left(1, \left(0 - \color{blue}{\frac{\left(-1 + y \cdot y\right) \cdot y}{y + 1}}\right)\right)\right) \]
      15. --lowering--.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{/.f64}\left(1, \mathsf{\_.f64}\left(0, \color{blue}{\left(\frac{\left(-1 + y \cdot y\right) \cdot y}{y + 1}\right)}\right)\right)\right) \]
      16. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{/.f64}\left(1, \mathsf{\_.f64}\left(0, \left(\frac{y \cdot \left(-1 + y \cdot y\right)}{\color{blue}{y} + 1}\right)\right)\right)\right) \]
      17. associate-/l*N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{/.f64}\left(1, \mathsf{\_.f64}\left(0, \left(y \cdot \color{blue}{\frac{-1 + y \cdot y}{y + 1}}\right)\right)\right)\right) \]
    7. Applied egg-rr87.6%

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

      \[\leadsto \mathsf{/.f64}\left(x, \color{blue}{\left(\frac{1}{y}\right)}\right) \]
    9. Step-by-step derivation
      1. /-lowering-/.f640.8%

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{/.f64}\left(1, \color{blue}{y}\right)\right) \]
    10. Simplified0.8%

      \[\leadsto \frac{x}{\color{blue}{\frac{1}{y}}} \]
    11. Step-by-step derivation
      1. inv-powN/A

        \[\leadsto \frac{x}{{y}^{\color{blue}{-1}}} \]
      2. sqr-powN/A

        \[\leadsto \frac{x}{{y}^{\left(\frac{-1}{2}\right)} \cdot \color{blue}{{y}^{\left(\frac{-1}{2}\right)}}} \]
      3. pow-prod-downN/A

        \[\leadsto \frac{x}{{\left(y \cdot y\right)}^{\color{blue}{\left(\frac{-1}{2}\right)}}} \]
      4. *-rgt-identityN/A

        \[\leadsto \frac{x}{{\left(\left(y \cdot y\right) \cdot 1\right)}^{\left(\frac{\color{blue}{-1}}{2}\right)}} \]
      5. metadata-evalN/A

        \[\leadsto \frac{x}{{\left(\left(y \cdot y\right) \cdot \left(-1 \cdot -1\right)\right)}^{\left(\frac{-1}{2}\right)}} \]
      6. swap-sqrN/A

        \[\leadsto \frac{x}{{\left(\left(y \cdot -1\right) \cdot \left(y \cdot -1\right)\right)}^{\left(\frac{\color{blue}{-1}}{2}\right)}} \]
      7. metadata-evalN/A

        \[\leadsto \frac{x}{{\left(\left(y \cdot \frac{1}{-1}\right) \cdot \left(y \cdot -1\right)\right)}^{\left(\frac{-1}{2}\right)}} \]
      8. div-invN/A

        \[\leadsto \frac{x}{{\left(\frac{y}{-1} \cdot \left(y \cdot -1\right)\right)}^{\left(\frac{-1}{2}\right)}} \]
      9. metadata-evalN/A

        \[\leadsto \frac{x}{{\left(\frac{y}{-1} \cdot \left(y \cdot \frac{1}{-1}\right)\right)}^{\left(\frac{-1}{2}\right)}} \]
      10. div-invN/A

        \[\leadsto \frac{x}{{\left(\frac{y}{-1} \cdot \frac{y}{-1}\right)}^{\left(\frac{-1}{2}\right)}} \]
      11. pow-prod-downN/A

        \[\leadsto \frac{x}{{\left(\frac{y}{-1}\right)}^{\left(\frac{-1}{2}\right)} \cdot \color{blue}{{\left(\frac{y}{-1}\right)}^{\left(\frac{-1}{2}\right)}}} \]
      12. sqr-powN/A

        \[\leadsto \frac{x}{{\left(\frac{y}{-1}\right)}^{\color{blue}{-1}}} \]
      13. inv-powN/A

        \[\leadsto \frac{x}{\frac{1}{\color{blue}{\frac{y}{-1}}}} \]
      14. clear-numN/A

        \[\leadsto \frac{x}{\frac{-1}{\color{blue}{y}}} \]
      15. clear-numN/A

        \[\leadsto \frac{1}{\color{blue}{\frac{\frac{-1}{y}}{x}}} \]
      16. associate-/r/N/A

        \[\leadsto \frac{1}{\frac{-1}{y}} \cdot \color{blue}{x} \]
      17. frac-2negN/A

        \[\leadsto \frac{1}{\frac{\mathsf{neg}\left(-1\right)}{\mathsf{neg}\left(y\right)}} \cdot x \]
      18. metadata-evalN/A

        \[\leadsto \frac{1}{\frac{1}{\mathsf{neg}\left(y\right)}} \cdot x \]
      19. remove-double-divN/A

        \[\leadsto \left(\mathsf{neg}\left(y\right)\right) \cdot x \]
      20. distribute-lft-neg-inN/A

        \[\leadsto \mathsf{neg}\left(y \cdot x\right) \]
      21. neg-lowering-neg.f64N/A

        \[\leadsto \mathsf{neg.f64}\left(\left(y \cdot x\right)\right) \]
      22. *-lowering-*.f6424.6%

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(y, x\right)\right) \]
    12. Applied egg-rr24.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 1:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;0 - y \cdot x\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 99.9% accurate, 1.0× speedup?

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

\\
y \cdot \left(x \cdot \left(1 - y\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*N/A

      \[\leadsto x \cdot \color{blue}{\left(y \cdot \left(1 - y\right)\right)} \]
    2. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{\left(y \cdot \left(1 - y\right)\right)}\right) \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(y, \color{blue}{\left(1 - y\right)}\right)\right) \]
    4. --lowering--.f6495.2%

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(y, \mathsf{\_.f64}\left(1, \color{blue}{y}\right)\right)\right) \]
  3. Simplified95.2%

    \[\leadsto \color{blue}{x \cdot \left(y \cdot \left(1 - y\right)\right)} \]
  4. Add Preprocessing
  5. Applied egg-rr95.1%

    \[\leadsto \color{blue}{\frac{y}{y + 1} \cdot \frac{x}{\frac{-1}{-1 + y \cdot y}}} \]
  6. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \frac{x}{\frac{-1}{-1 + y \cdot y}} \cdot \color{blue}{\frac{y}{y + 1}} \]
    2. clear-numN/A

      \[\leadsto \frac{x}{\frac{-1}{-1 + y \cdot y}} \cdot \frac{1}{\color{blue}{\frac{y + 1}{y}}} \]
    3. un-div-invN/A

      \[\leadsto \frac{\frac{x}{\frac{-1}{-1 + y \cdot y}}}{\color{blue}{\frac{y + 1}{y}}} \]
    4. associate-/r/N/A

      \[\leadsto \frac{\frac{x}{-1} \cdot \left(-1 + y \cdot y\right)}{\frac{\color{blue}{y + 1}}{y}} \]
    5. *-commutativeN/A

      \[\leadsto \frac{\left(-1 + y \cdot y\right) \cdot \frac{x}{-1}}{\frac{\color{blue}{y + 1}}{y}} \]
    6. div-invN/A

      \[\leadsto \frac{\left(-1 + y \cdot y\right) \cdot \frac{x}{-1}}{\left(y + 1\right) \cdot \color{blue}{\frac{1}{y}}} \]
    7. times-fracN/A

      \[\leadsto \frac{-1 + y \cdot y}{y + 1} \cdot \color{blue}{\frac{\frac{x}{-1}}{\frac{1}{y}}} \]
    8. +-commutativeN/A

      \[\leadsto \frac{y \cdot y + -1}{y + 1} \cdot \frac{\frac{\color{blue}{x}}{-1}}{\frac{1}{y}} \]
    9. metadata-evalN/A

      \[\leadsto \frac{y \cdot y + \left(\mathsf{neg}\left(1\right)\right)}{y + 1} \cdot \frac{\frac{x}{-1}}{\frac{1}{y}} \]
    10. sub-negN/A

      \[\leadsto \frac{y \cdot y - 1}{y + 1} \cdot \frac{\frac{\color{blue}{x}}{-1}}{\frac{1}{y}} \]
    11. metadata-evalN/A

      \[\leadsto \frac{y \cdot y - 1 \cdot 1}{y + 1} \cdot \frac{\frac{x}{-1}}{\frac{1}{y}} \]
    12. flip--N/A

      \[\leadsto \left(y - 1\right) \cdot \frac{\color{blue}{\frac{x}{-1}}}{\frac{1}{y}} \]
    13. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\left(y - 1\right), \color{blue}{\left(\frac{\frac{x}{-1}}{\frac{1}{y}}\right)}\right) \]
    14. sub-negN/A

      \[\leadsto \mathsf{*.f64}\left(\left(y + \left(\mathsf{neg}\left(1\right)\right)\right), \left(\frac{\color{blue}{\frac{x}{-1}}}{\frac{1}{y}}\right)\right) \]
    15. metadata-evalN/A

      \[\leadsto \mathsf{*.f64}\left(\left(y + -1\right), \left(\frac{\frac{x}{\color{blue}{-1}}}{\frac{1}{y}}\right)\right) \]
    16. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(y, -1\right), \left(\frac{\color{blue}{\frac{x}{-1}}}{\frac{1}{y}}\right)\right) \]
    17. /-lowering-/.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(y, -1\right), \mathsf{/.f64}\left(\left(\frac{x}{-1}\right), \color{blue}{\left(\frac{1}{y}\right)}\right)\right) \]
    18. /-lowering-/.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(y, -1\right), \mathsf{/.f64}\left(\mathsf{/.f64}\left(x, -1\right), \left(\frac{\color{blue}{1}}{y}\right)\right)\right) \]
    19. /-lowering-/.f6499.7%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(y, -1\right), \mathsf{/.f64}\left(\mathsf{/.f64}\left(x, -1\right), \mathsf{/.f64}\left(1, \color{blue}{y}\right)\right)\right) \]
  7. Applied egg-rr99.7%

    \[\leadsto \color{blue}{\left(y + -1\right) \cdot \frac{\frac{x}{-1}}{\frac{1}{y}}} \]
  8. Step-by-step derivation
    1. associate-/r/N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(y, -1\right), \left(\frac{\frac{x}{-1}}{1} \cdot \color{blue}{y}\right)\right) \]
    2. clear-numN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(y, -1\right), \left(\frac{1}{\frac{1}{\frac{x}{-1}}} \cdot y\right)\right) \]
    3. clear-numN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(y, -1\right), \left(\frac{1}{\frac{-1}{x}} \cdot y\right)\right) \]
    4. associate-*l/N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(y, -1\right), \left(\frac{1 \cdot y}{\color{blue}{\frac{-1}{x}}}\right)\right) \]
    5. *-commutativeN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(y, -1\right), \left(\frac{y \cdot 1}{\frac{\color{blue}{-1}}{x}}\right)\right) \]
    6. *-rgt-identityN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(y, -1\right), \left(\frac{y}{\frac{\color{blue}{-1}}{x}}\right)\right) \]
    7. /-lowering-/.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(y, -1\right), \mathsf{/.f64}\left(y, \color{blue}{\left(\frac{-1}{x}\right)}\right)\right) \]
    8. /-lowering-/.f6499.7%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(y, -1\right), \mathsf{/.f64}\left(y, \mathsf{/.f64}\left(-1, \color{blue}{x}\right)\right)\right) \]
  9. Applied egg-rr99.7%

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

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

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

Alternative 5: 56.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*N/A

      \[\leadsto x \cdot \color{blue}{\left(y \cdot \left(1 - y\right)\right)} \]
    2. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{\left(y \cdot \left(1 - y\right)\right)}\right) \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(y, \color{blue}{\left(1 - y\right)}\right)\right) \]
    4. --lowering--.f6495.2%

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(y, \mathsf{\_.f64}\left(1, \color{blue}{y}\right)\right)\right) \]
  3. Simplified95.2%

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

    \[\leadsto \color{blue}{x \cdot y} \]
  6. Step-by-step derivation
    1. *-lowering-*.f6456.3%

      \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{y}\right) \]
  7. Simplified56.3%

    \[\leadsto \color{blue}{x \cdot y} \]
  8. Final simplification56.3%

    \[\leadsto y \cdot x \]
  9. Add Preprocessing

Reproduce

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