Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A

Percentage Accurate: 100.0% → 100.0%
Time: 2.9s
Alternatives: 6
Speedup: 0.1×

Specification

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

\\
\left(x + y\right) - x \cdot y
\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 6 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: 100.0% accurate, 1.0× speedup?

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

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

Alternative 1: 100.0% accurate, 0.1× speedup?

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

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

    \[\left(x + y\right) - x \cdot y \]
  2. Step-by-step derivation
    1. +-commutative100.0%

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

      \[\leadsto \left(y + x\right) - \color{blue}{y \cdot x} \]
    3. associate--l+100.0%

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

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

      \[\leadsto \left(\color{blue}{1 \cdot x} - y \cdot x\right) + y \]
    6. metadata-eval100.0%

      \[\leadsto \left(\color{blue}{\left(--1\right)} \cdot x - y \cdot x\right) + y \]
    7. distribute-rgt-out--100.0%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \left(--1\right) - y, y\right)} \]
    9. metadata-eval100.0%

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, 1 - y, y\right)} \]
  4. Add Preprocessing
  5. Final simplification100.0%

    \[\leadsto \mathsf{fma}\left(x, 1 - y, y\right) \]
  6. Add Preprocessing

Alternative 2: 74.8% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.15 \cdot 10^{+286} \lor \neg \left(x \leq -1.05 \cdot 10^{+260}\right) \land \left(x \leq -2.7 \cdot 10^{+248} \lor \neg \left(x \leq -9.2 \cdot 10^{+220}\right) \land \left(x \leq -8.8 \cdot 10^{+153} \lor \neg \left(x \leq 350\right)\right)\right):\\ \;\;\;\;x \cdot \left(-y\right)\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (or (<= x -1.15e+286)
         (and (not (<= x -1.05e+260))
              (or (<= x -2.7e+248)
                  (and (not (<= x -9.2e+220))
                       (or (<= x -8.8e+153) (not (<= x 350.0)))))))
   (* x (- y))
   (+ x y)))
double code(double x, double y) {
	double tmp;
	if ((x <= -1.15e+286) || (!(x <= -1.05e+260) && ((x <= -2.7e+248) || (!(x <= -9.2e+220) && ((x <= -8.8e+153) || !(x <= 350.0)))))) {
		tmp = x * -y;
	} else {
		tmp = x + y;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if ((x <= (-1.15d+286)) .or. (.not. (x <= (-1.05d+260))) .and. (x <= (-2.7d+248)) .or. (.not. (x <= (-9.2d+220))) .and. (x <= (-8.8d+153)) .or. (.not. (x <= 350.0d0))) then
        tmp = x * -y
    else
        tmp = x + y
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if ((x <= -1.15e+286) || (!(x <= -1.05e+260) && ((x <= -2.7e+248) || (!(x <= -9.2e+220) && ((x <= -8.8e+153) || !(x <= 350.0)))))) {
		tmp = x * -y;
	} else {
		tmp = x + y;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if (x <= -1.15e+286) or (not (x <= -1.05e+260) and ((x <= -2.7e+248) or (not (x <= -9.2e+220) and ((x <= -8.8e+153) or not (x <= 350.0))))):
		tmp = x * -y
	else:
		tmp = x + y
	return tmp
function code(x, y)
	tmp = 0.0
	if ((x <= -1.15e+286) || (!(x <= -1.05e+260) && ((x <= -2.7e+248) || (!(x <= -9.2e+220) && ((x <= -8.8e+153) || !(x <= 350.0))))))
		tmp = Float64(x * Float64(-y));
	else
		tmp = Float64(x + y);
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if ((x <= -1.15e+286) || (~((x <= -1.05e+260)) && ((x <= -2.7e+248) || (~((x <= -9.2e+220)) && ((x <= -8.8e+153) || ~((x <= 350.0)))))))
		tmp = x * -y;
	else
		tmp = x + y;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[Or[LessEqual[x, -1.15e+286], And[N[Not[LessEqual[x, -1.05e+260]], $MachinePrecision], Or[LessEqual[x, -2.7e+248], And[N[Not[LessEqual[x, -9.2e+220]], $MachinePrecision], Or[LessEqual[x, -8.8e+153], N[Not[LessEqual[x, 350.0]], $MachinePrecision]]]]]], N[(x * (-y)), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.15 \cdot 10^{+286} \lor \neg \left(x \leq -1.05 \cdot 10^{+260}\right) \land \left(x \leq -2.7 \cdot 10^{+248} \lor \neg \left(x \leq -9.2 \cdot 10^{+220}\right) \land \left(x \leq -8.8 \cdot 10^{+153} \lor \neg \left(x \leq 350\right)\right)\right):\\
\;\;\;\;x \cdot \left(-y\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.1500000000000001e286 or -1.05000000000000006e260 < x < -2.69999999999999989e248 or -9.19999999999999987e220 < x < -8.7999999999999998e153 or 350 < x

    1. Initial program 99.9%

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

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

        \[\leadsto \color{blue}{\left(y - x \cdot y\right) + x} \]
      3. remove-double-neg99.9%

        \[\leadsto \left(y - x \cdot y\right) + \color{blue}{\left(-\left(-x\right)\right)} \]
      4. unsub-neg99.9%

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

        \[\leadsto \color{blue}{\left(y + \left(-x\right) \cdot y\right)} - \left(-x\right) \]
      6. associate--l+99.9%

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

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

        \[\leadsto y + \color{blue}{\left(\left(-x\right) \cdot y + \left(--1\right) \cdot x\right)} \]
      9. distribute-lft-neg-out99.9%

        \[\leadsto y + \left(\color{blue}{\left(-x \cdot y\right)} + \left(--1\right) \cdot x\right) \]
      10. distribute-rgt-neg-out99.9%

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

        \[\leadsto y + \left(\color{blue}{\left(-y\right) \cdot x} + \left(--1\right) \cdot x\right) \]
      12. distribute-rgt-out99.9%

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

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

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

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

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

      \[\leadsto \color{blue}{y \cdot \left(1 + -1 \cdot x\right)} \]
    6. Step-by-step derivation
      1. mul-1-neg63.4%

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

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

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

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

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

        \[\leadsto \color{blue}{x \cdot \left(-y\right)} \]
    10. Simplified61.4%

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

    if -1.1500000000000001e286 < x < -1.05000000000000006e260 or -2.69999999999999989e248 < x < -9.19999999999999987e220 or -8.7999999999999998e153 < x < 350

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{\left(y - x \cdot y\right) + x} \]
      3. remove-double-neg100.0%

        \[\leadsto \left(y - x \cdot y\right) + \color{blue}{\left(-\left(-x\right)\right)} \]
      4. unsub-neg100.0%

        \[\leadsto \color{blue}{\left(y - x \cdot y\right) - \left(-x\right)} \]
      5. cancel-sign-sub-inv100.0%

        \[\leadsto \color{blue}{\left(y + \left(-x\right) \cdot y\right)} - \left(-x\right) \]
      6. associate--l+100.0%

        \[\leadsto \color{blue}{y + \left(\left(-x\right) \cdot y - \left(-x\right)\right)} \]
      7. neg-mul-1100.0%

        \[\leadsto y + \left(\left(-x\right) \cdot y - \color{blue}{-1 \cdot x}\right) \]
      8. cancel-sign-sub-inv100.0%

        \[\leadsto y + \color{blue}{\left(\left(-x\right) \cdot y + \left(--1\right) \cdot x\right)} \]
      9. distribute-lft-neg-out100.0%

        \[\leadsto y + \left(\color{blue}{\left(-x \cdot y\right)} + \left(--1\right) \cdot x\right) \]
      10. distribute-rgt-neg-out100.0%

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

        \[\leadsto y + \left(\color{blue}{\left(-y\right) \cdot x} + \left(--1\right) \cdot x\right) \]
      12. distribute-rgt-out100.0%

        \[\leadsto y + \color{blue}{x \cdot \left(\left(-y\right) + \left(--1\right)\right)} \]
      13. +-commutative100.0%

        \[\leadsto y + x \cdot \color{blue}{\left(\left(--1\right) + \left(-y\right)\right)} \]
      14. sub-neg100.0%

        \[\leadsto y + x \cdot \color{blue}{\left(\left(--1\right) - y\right)} \]
      15. metadata-eval100.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.15 \cdot 10^{+286} \lor \neg \left(x \leq -1.05 \cdot 10^{+260}\right) \land \left(x \leq -2.7 \cdot 10^{+248} \lor \neg \left(x \leq -9.2 \cdot 10^{+220}\right) \land \left(x \leq -8.8 \cdot 10^{+153} \lor \neg \left(x \leq 350\right)\right)\right):\\ \;\;\;\;x \cdot \left(-y\right)\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 86.9% accurate, 0.5× speedup?

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

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

\mathbf{elif}\;y \leq 2.3 \cdot 10^{-5}:\\
\;\;\;\;x + y\\

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


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

    1. Initial program 99.9%

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

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

        \[\leadsto \color{blue}{\left(y - x \cdot y\right) + x} \]
      3. remove-double-neg99.9%

        \[\leadsto \left(y - x \cdot y\right) + \color{blue}{\left(-\left(-x\right)\right)} \]
      4. unsub-neg99.9%

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

        \[\leadsto \color{blue}{\left(y + \left(-x\right) \cdot y\right)} - \left(-x\right) \]
      6. associate--l+99.9%

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

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

        \[\leadsto y + \color{blue}{\left(\left(-x\right) \cdot y + \left(--1\right) \cdot x\right)} \]
      9. distribute-lft-neg-out99.9%

        \[\leadsto y + \left(\color{blue}{\left(-x \cdot y\right)} + \left(--1\right) \cdot x\right) \]
      10. distribute-rgt-neg-out99.9%

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

        \[\leadsto y + \left(\color{blue}{\left(-y\right) \cdot x} + \left(--1\right) \cdot x\right) \]
      12. distribute-rgt-out99.9%

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

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

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

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

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

      \[\leadsto \color{blue}{y \cdot \left(1 + -1 \cdot x\right)} \]
    6. Step-by-step derivation
      1. mul-1-neg98.7%

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

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

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

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

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

        \[\leadsto \color{blue}{x \cdot \left(-y\right)} \]
    10. Simplified50.6%

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

    if -8e7 < y < 2.3e-5

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{\left(y - x \cdot y\right) + x} \]
      3. remove-double-neg100.0%

        \[\leadsto \left(y - x \cdot y\right) + \color{blue}{\left(-\left(-x\right)\right)} \]
      4. unsub-neg100.0%

        \[\leadsto \color{blue}{\left(y - x \cdot y\right) - \left(-x\right)} \]
      5. cancel-sign-sub-inv100.0%

        \[\leadsto \color{blue}{\left(y + \left(-x\right) \cdot y\right)} - \left(-x\right) \]
      6. associate--l+100.0%

        \[\leadsto \color{blue}{y + \left(\left(-x\right) \cdot y - \left(-x\right)\right)} \]
      7. neg-mul-1100.0%

        \[\leadsto y + \left(\left(-x\right) \cdot y - \color{blue}{-1 \cdot x}\right) \]
      8. cancel-sign-sub-inv100.0%

        \[\leadsto y + \color{blue}{\left(\left(-x\right) \cdot y + \left(--1\right) \cdot x\right)} \]
      9. distribute-lft-neg-out100.0%

        \[\leadsto y + \left(\color{blue}{\left(-x \cdot y\right)} + \left(--1\right) \cdot x\right) \]
      10. distribute-rgt-neg-out100.0%

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

        \[\leadsto y + \left(\color{blue}{\left(-y\right) \cdot x} + \left(--1\right) \cdot x\right) \]
      12. distribute-rgt-out100.0%

        \[\leadsto y + \color{blue}{x \cdot \left(\left(-y\right) + \left(--1\right)\right)} \]
      13. +-commutative100.0%

        \[\leadsto y + x \cdot \color{blue}{\left(\left(--1\right) + \left(-y\right)\right)} \]
      14. sub-neg100.0%

        \[\leadsto y + x \cdot \color{blue}{\left(\left(--1\right) - y\right)} \]
      15. metadata-eval100.0%

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

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

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

    if 2.3e-5 < y

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{\left(y - x \cdot y\right) + x} \]
      3. remove-double-neg100.0%

        \[\leadsto \left(y - x \cdot y\right) + \color{blue}{\left(-\left(-x\right)\right)} \]
      4. unsub-neg100.0%

        \[\leadsto \color{blue}{\left(y - x \cdot y\right) - \left(-x\right)} \]
      5. cancel-sign-sub-inv100.0%

        \[\leadsto \color{blue}{\left(y + \left(-x\right) \cdot y\right)} - \left(-x\right) \]
      6. associate--l+100.0%

        \[\leadsto \color{blue}{y + \left(\left(-x\right) \cdot y - \left(-x\right)\right)} \]
      7. neg-mul-1100.0%

        \[\leadsto y + \left(\left(-x\right) \cdot y - \color{blue}{-1 \cdot x}\right) \]
      8. cancel-sign-sub-inv100.0%

        \[\leadsto y + \color{blue}{\left(\left(-x\right) \cdot y + \left(--1\right) \cdot x\right)} \]
      9. distribute-lft-neg-out100.0%

        \[\leadsto y + \left(\color{blue}{\left(-x \cdot y\right)} + \left(--1\right) \cdot x\right) \]
      10. distribute-rgt-neg-out100.0%

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

        \[\leadsto y + \left(\color{blue}{\left(-y\right) \cdot x} + \left(--1\right) \cdot x\right) \]
      12. distribute-rgt-out100.0%

        \[\leadsto y + \color{blue}{x \cdot \left(\left(-y\right) + \left(--1\right)\right)} \]
      13. +-commutative100.0%

        \[\leadsto y + x \cdot \color{blue}{\left(\left(--1\right) + \left(-y\right)\right)} \]
      14. sub-neg100.0%

        \[\leadsto y + x \cdot \color{blue}{\left(\left(--1\right) - y\right)} \]
      15. metadata-eval100.0%

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

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

      \[\leadsto \color{blue}{y \cdot \left(1 + -1 \cdot x\right)} \]
    6. Step-by-step derivation
      1. mul-1-neg100.0%

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

        \[\leadsto y \cdot \color{blue}{\left(1 - x\right)} \]
    7. Simplified100.0%

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

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

Alternative 4: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ y + x \cdot \left(1 - y\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 + x \cdot \left(1 - y\right)
\end{array}
Derivation
  1. Initial program 100.0%

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

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

      \[\leadsto \color{blue}{\left(y - x \cdot y\right) + x} \]
    3. remove-double-neg100.0%

      \[\leadsto \left(y - x \cdot y\right) + \color{blue}{\left(-\left(-x\right)\right)} \]
    4. unsub-neg100.0%

      \[\leadsto \color{blue}{\left(y - x \cdot y\right) - \left(-x\right)} \]
    5. cancel-sign-sub-inv100.0%

      \[\leadsto \color{blue}{\left(y + \left(-x\right) \cdot y\right)} - \left(-x\right) \]
    6. associate--l+100.0%

      \[\leadsto \color{blue}{y + \left(\left(-x\right) \cdot y - \left(-x\right)\right)} \]
    7. neg-mul-1100.0%

      \[\leadsto y + \left(\left(-x\right) \cdot y - \color{blue}{-1 \cdot x}\right) \]
    8. cancel-sign-sub-inv100.0%

      \[\leadsto y + \color{blue}{\left(\left(-x\right) \cdot y + \left(--1\right) \cdot x\right)} \]
    9. distribute-lft-neg-out100.0%

      \[\leadsto y + \left(\color{blue}{\left(-x \cdot y\right)} + \left(--1\right) \cdot x\right) \]
    10. distribute-rgt-neg-out100.0%

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

      \[\leadsto y + \left(\color{blue}{\left(-y\right) \cdot x} + \left(--1\right) \cdot x\right) \]
    12. distribute-rgt-out100.0%

      \[\leadsto y + \color{blue}{x \cdot \left(\left(-y\right) + \left(--1\right)\right)} \]
    13. +-commutative100.0%

      \[\leadsto y + x \cdot \color{blue}{\left(\left(--1\right) + \left(-y\right)\right)} \]
    14. sub-neg100.0%

      \[\leadsto y + x \cdot \color{blue}{\left(\left(--1\right) - y\right)} \]
    15. metadata-eval100.0%

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

    \[\leadsto \color{blue}{y + x \cdot \left(1 - y\right)} \]
  4. Add Preprocessing
  5. Final simplification100.0%

    \[\leadsto y + x \cdot \left(1 - y\right) \]
  6. Add Preprocessing

Alternative 5: 75.0% accurate, 2.3× speedup?

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

\\
x + y
\end{array}
Derivation
  1. Initial program 100.0%

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

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

      \[\leadsto \color{blue}{\left(y - x \cdot y\right) + x} \]
    3. remove-double-neg100.0%

      \[\leadsto \left(y - x \cdot y\right) + \color{blue}{\left(-\left(-x\right)\right)} \]
    4. unsub-neg100.0%

      \[\leadsto \color{blue}{\left(y - x \cdot y\right) - \left(-x\right)} \]
    5. cancel-sign-sub-inv100.0%

      \[\leadsto \color{blue}{\left(y + \left(-x\right) \cdot y\right)} - \left(-x\right) \]
    6. associate--l+100.0%

      \[\leadsto \color{blue}{y + \left(\left(-x\right) \cdot y - \left(-x\right)\right)} \]
    7. neg-mul-1100.0%

      \[\leadsto y + \left(\left(-x\right) \cdot y - \color{blue}{-1 \cdot x}\right) \]
    8. cancel-sign-sub-inv100.0%

      \[\leadsto y + \color{blue}{\left(\left(-x\right) \cdot y + \left(--1\right) \cdot x\right)} \]
    9. distribute-lft-neg-out100.0%

      \[\leadsto y + \left(\color{blue}{\left(-x \cdot y\right)} + \left(--1\right) \cdot x\right) \]
    10. distribute-rgt-neg-out100.0%

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

      \[\leadsto y + \left(\color{blue}{\left(-y\right) \cdot x} + \left(--1\right) \cdot x\right) \]
    12. distribute-rgt-out100.0%

      \[\leadsto y + \color{blue}{x \cdot \left(\left(-y\right) + \left(--1\right)\right)} \]
    13. +-commutative100.0%

      \[\leadsto y + x \cdot \color{blue}{\left(\left(--1\right) + \left(-y\right)\right)} \]
    14. sub-neg100.0%

      \[\leadsto y + x \cdot \color{blue}{\left(\left(--1\right) - y\right)} \]
    15. metadata-eval100.0%

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

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

    \[\leadsto y + \color{blue}{x} \]
  6. Final simplification74.4%

    \[\leadsto x + y \]
  7. Add Preprocessing

Alternative 6: 38.6% accurate, 7.0× speedup?

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

\\
y
\end{array}
Derivation
  1. Initial program 100.0%

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

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

      \[\leadsto \color{blue}{\left(y - x \cdot y\right) + x} \]
    3. remove-double-neg100.0%

      \[\leadsto \left(y - x \cdot y\right) + \color{blue}{\left(-\left(-x\right)\right)} \]
    4. unsub-neg100.0%

      \[\leadsto \color{blue}{\left(y - x \cdot y\right) - \left(-x\right)} \]
    5. cancel-sign-sub-inv100.0%

      \[\leadsto \color{blue}{\left(y + \left(-x\right) \cdot y\right)} - \left(-x\right) \]
    6. associate--l+100.0%

      \[\leadsto \color{blue}{y + \left(\left(-x\right) \cdot y - \left(-x\right)\right)} \]
    7. neg-mul-1100.0%

      \[\leadsto y + \left(\left(-x\right) \cdot y - \color{blue}{-1 \cdot x}\right) \]
    8. cancel-sign-sub-inv100.0%

      \[\leadsto y + \color{blue}{\left(\left(-x\right) \cdot y + \left(--1\right) \cdot x\right)} \]
    9. distribute-lft-neg-out100.0%

      \[\leadsto y + \left(\color{blue}{\left(-x \cdot y\right)} + \left(--1\right) \cdot x\right) \]
    10. distribute-rgt-neg-out100.0%

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

      \[\leadsto y + \left(\color{blue}{\left(-y\right) \cdot x} + \left(--1\right) \cdot x\right) \]
    12. distribute-rgt-out100.0%

      \[\leadsto y + \color{blue}{x \cdot \left(\left(-y\right) + \left(--1\right)\right)} \]
    13. +-commutative100.0%

      \[\leadsto y + x \cdot \color{blue}{\left(\left(--1\right) + \left(-y\right)\right)} \]
    14. sub-neg100.0%

      \[\leadsto y + x \cdot \color{blue}{\left(\left(--1\right) - y\right)} \]
    15. metadata-eval100.0%

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

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

    \[\leadsto \color{blue}{y} \]
  6. Final simplification41.1%

    \[\leadsto y \]
  7. Add Preprocessing

Reproduce

?
herbie shell --seed 2024027 
(FPCore (x y)
  :name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
  :precision binary64
  (- (+ x y) (* x y)))