Data.Colour.SRGB:transferFunction from colour-2.3.3

Percentage Accurate: 100.0% → 100.0%
Time: 3.5s
Alternatives: 9
Speedup: 1.0×

Specification

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

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

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

Alternative 1: 100.0% accurate, 1.0× speedup?

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

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

    \[\left(x + 1\right) \cdot y - x \]
  2. Taylor expanded in x around 0 100.0%

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

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

Alternative 2: 75.1% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -2.9 \cdot 10^{+215}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq -7 \cdot 10^{+169}:\\ \;\;\;\;y - x\\ \mathbf{elif}\;y \leq -2.4 \cdot 10^{+36}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 68000000000000:\\ \;\;\;\;y - x\\ \mathbf{elif}\;y \leq 6.2 \cdot 10^{+30}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 2.2 \cdot 10^{+74}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 8 \cdot 10^{+170}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 7.2 \cdot 10^{+283}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= y -2.9e+215)
   (* y x)
   (if (<= y -7e+169)
     (- y x)
     (if (<= y -2.4e+36)
       (* y x)
       (if (<= y 68000000000000.0)
         (- y x)
         (if (<= y 6.2e+30)
           (* y x)
           (if (<= y 2.2e+74)
             y
             (if (<= y 8e+170) (* y x) (if (<= y 7.2e+283) y (* y x))))))))))
double code(double x, double y) {
	double tmp;
	if (y <= -2.9e+215) {
		tmp = y * x;
	} else if (y <= -7e+169) {
		tmp = y - x;
	} else if (y <= -2.4e+36) {
		tmp = y * x;
	} else if (y <= 68000000000000.0) {
		tmp = y - x;
	} else if (y <= 6.2e+30) {
		tmp = y * x;
	} else if (y <= 2.2e+74) {
		tmp = y;
	} else if (y <= 8e+170) {
		tmp = y * x;
	} else if (y <= 7.2e+283) {
		tmp = y;
	} 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 <= (-2.9d+215)) then
        tmp = y * x
    else if (y <= (-7d+169)) then
        tmp = y - x
    else if (y <= (-2.4d+36)) then
        tmp = y * x
    else if (y <= 68000000000000.0d0) then
        tmp = y - x
    else if (y <= 6.2d+30) then
        tmp = y * x
    else if (y <= 2.2d+74) then
        tmp = y
    else if (y <= 8d+170) then
        tmp = y * x
    else if (y <= 7.2d+283) then
        tmp = y
    else
        tmp = y * x
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (y <= -2.9e+215) {
		tmp = y * x;
	} else if (y <= -7e+169) {
		tmp = y - x;
	} else if (y <= -2.4e+36) {
		tmp = y * x;
	} else if (y <= 68000000000000.0) {
		tmp = y - x;
	} else if (y <= 6.2e+30) {
		tmp = y * x;
	} else if (y <= 2.2e+74) {
		tmp = y;
	} else if (y <= 8e+170) {
		tmp = y * x;
	} else if (y <= 7.2e+283) {
		tmp = y;
	} else {
		tmp = y * x;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if y <= -2.9e+215:
		tmp = y * x
	elif y <= -7e+169:
		tmp = y - x
	elif y <= -2.4e+36:
		tmp = y * x
	elif y <= 68000000000000.0:
		tmp = y - x
	elif y <= 6.2e+30:
		tmp = y * x
	elif y <= 2.2e+74:
		tmp = y
	elif y <= 8e+170:
		tmp = y * x
	elif y <= 7.2e+283:
		tmp = y
	else:
		tmp = y * x
	return tmp
function code(x, y)
	tmp = 0.0
	if (y <= -2.9e+215)
		tmp = Float64(y * x);
	elseif (y <= -7e+169)
		tmp = Float64(y - x);
	elseif (y <= -2.4e+36)
		tmp = Float64(y * x);
	elseif (y <= 68000000000000.0)
		tmp = Float64(y - x);
	elseif (y <= 6.2e+30)
		tmp = Float64(y * x);
	elseif (y <= 2.2e+74)
		tmp = y;
	elseif (y <= 8e+170)
		tmp = Float64(y * x);
	elseif (y <= 7.2e+283)
		tmp = y;
	else
		tmp = Float64(y * x);
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= -2.9e+215)
		tmp = y * x;
	elseif (y <= -7e+169)
		tmp = y - x;
	elseif (y <= -2.4e+36)
		tmp = y * x;
	elseif (y <= 68000000000000.0)
		tmp = y - x;
	elseif (y <= 6.2e+30)
		tmp = y * x;
	elseif (y <= 2.2e+74)
		tmp = y;
	elseif (y <= 8e+170)
		tmp = y * x;
	elseif (y <= 7.2e+283)
		tmp = y;
	else
		tmp = y * x;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[y, -2.9e+215], N[(y * x), $MachinePrecision], If[LessEqual[y, -7e+169], N[(y - x), $MachinePrecision], If[LessEqual[y, -2.4e+36], N[(y * x), $MachinePrecision], If[LessEqual[y, 68000000000000.0], N[(y - x), $MachinePrecision], If[LessEqual[y, 6.2e+30], N[(y * x), $MachinePrecision], If[LessEqual[y, 2.2e+74], y, If[LessEqual[y, 8e+170], N[(y * x), $MachinePrecision], If[LessEqual[y, 7.2e+283], y, N[(y * x), $MachinePrecision]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.9 \cdot 10^{+215}:\\
\;\;\;\;y \cdot x\\

\mathbf{elif}\;y \leq -7 \cdot 10^{+169}:\\
\;\;\;\;y - x\\

\mathbf{elif}\;y \leq -2.4 \cdot 10^{+36}:\\
\;\;\;\;y \cdot x\\

\mathbf{elif}\;y \leq 68000000000000:\\
\;\;\;\;y - x\\

\mathbf{elif}\;y \leq 6.2 \cdot 10^{+30}:\\
\;\;\;\;y \cdot x\\

\mathbf{elif}\;y \leq 2.2 \cdot 10^{+74}:\\
\;\;\;\;y\\

\mathbf{elif}\;y \leq 8 \cdot 10^{+170}:\\
\;\;\;\;y \cdot x\\

\mathbf{elif}\;y \leq 7.2 \cdot 10^{+283}:\\
\;\;\;\;y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -2.8999999999999999e215 or -7.00000000000000038e169 < y < -2.39999999999999992e36 or 6.8e13 < y < 6.1999999999999995e30 or 2.2000000000000001e74 < y < 8.00000000000000028e170 or 7.20000000000000034e283 < y

    1. Initial program 99.9%

      \[\left(x + 1\right) \cdot y - x \]
    2. Taylor expanded in x around inf 72.8%

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

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

    if -2.8999999999999999e215 < y < -7.00000000000000038e169 or -2.39999999999999992e36 < y < 6.8e13

    1. Initial program 99.9%

      \[\left(x + 1\right) \cdot y - x \]
    2. Taylor expanded in x around 0 94.5%

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

    if 6.1999999999999995e30 < y < 2.2000000000000001e74 or 8.00000000000000028e170 < y < 7.20000000000000034e283

    1. Initial program 99.9%

      \[\left(x + 1\right) \cdot y - x \]
    2. Taylor expanded in x around 0 100.0%

      \[\leadsto \color{blue}{\left(y \cdot x + y\right)} - x \]
    3. Taylor expanded in x around 0 73.2%

      \[\leadsto \color{blue}{y} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification86.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -2.9 \cdot 10^{+215}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq -7 \cdot 10^{+169}:\\ \;\;\;\;y - x\\ \mathbf{elif}\;y \leq -2.4 \cdot 10^{+36}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 68000000000000:\\ \;\;\;\;y - x\\ \mathbf{elif}\;y \leq 6.2 \cdot 10^{+30}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 2.2 \cdot 10^{+74}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 8 \cdot 10^{+170}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 7.2 \cdot 10^{+283}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]

Alternative 3: 62.0% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -3.4 \cdot 10^{+215}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq -6.5 \cdot 10^{+169}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq -1.2 \cdot 10^{+22}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq -9 \cdot 10^{-51}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 1.35 \cdot 10^{-15}:\\ \;\;\;\;-x\\ \mathbf{elif}\;y \leq 2.9 \cdot 10^{+170}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 9.5 \cdot 10^{+282}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= y -3.4e+215)
   (* y x)
   (if (<= y -6.5e+169)
     y
     (if (<= y -1.2e+22)
       (* y x)
       (if (<= y -9e-51)
         y
         (if (<= y 1.35e-15)
           (- x)
           (if (<= y 2.9e+170) (* y x) (if (<= y 9.5e+282) y (* y x)))))))))
double code(double x, double y) {
	double tmp;
	if (y <= -3.4e+215) {
		tmp = y * x;
	} else if (y <= -6.5e+169) {
		tmp = y;
	} else if (y <= -1.2e+22) {
		tmp = y * x;
	} else if (y <= -9e-51) {
		tmp = y;
	} else if (y <= 1.35e-15) {
		tmp = -x;
	} else if (y <= 2.9e+170) {
		tmp = y * x;
	} else if (y <= 9.5e+282) {
		tmp = y;
	} 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 <= (-3.4d+215)) then
        tmp = y * x
    else if (y <= (-6.5d+169)) then
        tmp = y
    else if (y <= (-1.2d+22)) then
        tmp = y * x
    else if (y <= (-9d-51)) then
        tmp = y
    else if (y <= 1.35d-15) then
        tmp = -x
    else if (y <= 2.9d+170) then
        tmp = y * x
    else if (y <= 9.5d+282) then
        tmp = y
    else
        tmp = y * x
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (y <= -3.4e+215) {
		tmp = y * x;
	} else if (y <= -6.5e+169) {
		tmp = y;
	} else if (y <= -1.2e+22) {
		tmp = y * x;
	} else if (y <= -9e-51) {
		tmp = y;
	} else if (y <= 1.35e-15) {
		tmp = -x;
	} else if (y <= 2.9e+170) {
		tmp = y * x;
	} else if (y <= 9.5e+282) {
		tmp = y;
	} else {
		tmp = y * x;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if y <= -3.4e+215:
		tmp = y * x
	elif y <= -6.5e+169:
		tmp = y
	elif y <= -1.2e+22:
		tmp = y * x
	elif y <= -9e-51:
		tmp = y
	elif y <= 1.35e-15:
		tmp = -x
	elif y <= 2.9e+170:
		tmp = y * x
	elif y <= 9.5e+282:
		tmp = y
	else:
		tmp = y * x
	return tmp
function code(x, y)
	tmp = 0.0
	if (y <= -3.4e+215)
		tmp = Float64(y * x);
	elseif (y <= -6.5e+169)
		tmp = y;
	elseif (y <= -1.2e+22)
		tmp = Float64(y * x);
	elseif (y <= -9e-51)
		tmp = y;
	elseif (y <= 1.35e-15)
		tmp = Float64(-x);
	elseif (y <= 2.9e+170)
		tmp = Float64(y * x);
	elseif (y <= 9.5e+282)
		tmp = y;
	else
		tmp = Float64(y * x);
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= -3.4e+215)
		tmp = y * x;
	elseif (y <= -6.5e+169)
		tmp = y;
	elseif (y <= -1.2e+22)
		tmp = y * x;
	elseif (y <= -9e-51)
		tmp = y;
	elseif (y <= 1.35e-15)
		tmp = -x;
	elseif (y <= 2.9e+170)
		tmp = y * x;
	elseif (y <= 9.5e+282)
		tmp = y;
	else
		tmp = y * x;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[y, -3.4e+215], N[(y * x), $MachinePrecision], If[LessEqual[y, -6.5e+169], y, If[LessEqual[y, -1.2e+22], N[(y * x), $MachinePrecision], If[LessEqual[y, -9e-51], y, If[LessEqual[y, 1.35e-15], (-x), If[LessEqual[y, 2.9e+170], N[(y * x), $MachinePrecision], If[LessEqual[y, 9.5e+282], y, N[(y * x), $MachinePrecision]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.4 \cdot 10^{+215}:\\
\;\;\;\;y \cdot x\\

\mathbf{elif}\;y \leq -6.5 \cdot 10^{+169}:\\
\;\;\;\;y\\

\mathbf{elif}\;y \leq -1.2 \cdot 10^{+22}:\\
\;\;\;\;y \cdot x\\

\mathbf{elif}\;y \leq -9 \cdot 10^{-51}:\\
\;\;\;\;y\\

\mathbf{elif}\;y \leq 1.35 \cdot 10^{-15}:\\
\;\;\;\;-x\\

\mathbf{elif}\;y \leq 2.9 \cdot 10^{+170}:\\
\;\;\;\;y \cdot x\\

\mathbf{elif}\;y \leq 9.5 \cdot 10^{+282}:\\
\;\;\;\;y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -3.40000000000000018e215 or -6.4999999999999995e169 < y < -1.2e22 or 1.35000000000000005e-15 < y < 2.9000000000000001e170 or 9.5000000000000005e282 < y

    1. Initial program 99.9%

      \[\left(x + 1\right) \cdot y - x \]
    2. Taylor expanded in x around inf 64.9%

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

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

    if -3.40000000000000018e215 < y < -6.4999999999999995e169 or -1.2e22 < y < -8.99999999999999948e-51 or 2.9000000000000001e170 < y < 9.5000000000000005e282

    1. Initial program 99.9%

      \[\left(x + 1\right) \cdot y - x \]
    2. Taylor expanded in x around 0 100.0%

      \[\leadsto \color{blue}{\left(y \cdot x + y\right)} - x \]
    3. Taylor expanded in x around 0 72.8%

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

    if -8.99999999999999948e-51 < y < 1.35000000000000005e-15

    1. Initial program 100.0%

      \[\left(x + 1\right) \cdot y - x \]
    2. Taylor expanded in y around 0 80.8%

      \[\leadsto \color{blue}{-1 \cdot x} \]
    3. Step-by-step derivation
      1. neg-mul-180.8%

        \[\leadsto \color{blue}{-x} \]
    4. Simplified80.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -3.4 \cdot 10^{+215}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq -6.5 \cdot 10^{+169}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq -1.2 \cdot 10^{+22}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq -9 \cdot 10^{-51}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 1.35 \cdot 10^{-15}:\\ \;\;\;\;-x\\ \mathbf{elif}\;y \leq 2.9 \cdot 10^{+170}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 9.5 \cdot 10^{+282}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]

Alternative 4: 98.6% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -4.2 \lor \neg \left(y \leq 1.35 \cdot 10^{-15}\right):\\ \;\;\;\;y \cdot \left(x + 1\right)\\ \mathbf{else}:\\ \;\;\;\;y - x\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (or (<= y -4.2) (not (<= y 1.35e-15))) (* y (+ x 1.0)) (- y x)))
double code(double x, double y) {
	double tmp;
	if ((y <= -4.2) || !(y <= 1.35e-15)) {
		tmp = y * (x + 1.0);
	} 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 <= (-4.2d0)) .or. (.not. (y <= 1.35d-15))) then
        tmp = y * (x + 1.0d0)
    else
        tmp = y - x
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if ((y <= -4.2) || !(y <= 1.35e-15)) {
		tmp = y * (x + 1.0);
	} else {
		tmp = y - x;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if (y <= -4.2) or not (y <= 1.35e-15):
		tmp = y * (x + 1.0)
	else:
		tmp = y - x
	return tmp
function code(x, y)
	tmp = 0.0
	if ((y <= -4.2) || !(y <= 1.35e-15))
		tmp = Float64(y * Float64(x + 1.0));
	else
		tmp = Float64(y - x);
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if ((y <= -4.2) || ~((y <= 1.35e-15)))
		tmp = y * (x + 1.0);
	else
		tmp = y - x;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[Or[LessEqual[y, -4.2], N[Not[LessEqual[y, 1.35e-15]], $MachinePrecision]], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.2 \lor \neg \left(y \leq 1.35 \cdot 10^{-15}\right):\\
\;\;\;\;y \cdot \left(x + 1\right)\\

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


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

    1. Initial program 99.9%

      \[\left(x + 1\right) \cdot y - x \]
    2. Taylor expanded in x around 0 99.9%

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

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

    if -4.20000000000000018 < y < 1.35000000000000005e-15

    1. Initial program 100.0%

      \[\left(x + 1\right) \cdot y - x \]
    2. Taylor expanded in x around 0 99.8%

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

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

Alternative 5: 98.9% accurate, 0.8× speedup?

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

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

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


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

    1. Initial program 99.9%

      \[\left(x + 1\right) \cdot y - x \]
    2. Taylor expanded in x around inf 98.6%

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

    if -1 < x < 1

    1. Initial program 99.9%

      \[\left(x + 1\right) \cdot y - x \]
    2. Taylor expanded in x around 0 98.1%

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

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

Alternative 6: 98.6% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -4.2 \lor \neg \left(y \leq 1.35 \cdot 10^{-15}\right):\\ \;\;\;\;y + y \cdot x\\ \mathbf{else}:\\ \;\;\;\;y - x\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (or (<= y -4.2) (not (<= y 1.35e-15))) (+ y (* y x)) (- y x)))
double code(double x, double y) {
	double tmp;
	if ((y <= -4.2) || !(y <= 1.35e-15)) {
		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 <= (-4.2d0)) .or. (.not. (y <= 1.35d-15))) 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 <= -4.2) || !(y <= 1.35e-15)) {
		tmp = y + (y * x);
	} else {
		tmp = y - x;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if (y <= -4.2) or not (y <= 1.35e-15):
		tmp = y + (y * x)
	else:
		tmp = y - x
	return tmp
function code(x, y)
	tmp = 0.0
	if ((y <= -4.2) || !(y <= 1.35e-15))
		tmp = Float64(y + Float64(y * x));
	else
		tmp = Float64(y - x);
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if ((y <= -4.2) || ~((y <= 1.35e-15)))
		tmp = y + (y * x);
	else
		tmp = y - x;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[Or[LessEqual[y, -4.2], N[Not[LessEqual[y, 1.35e-15]], $MachinePrecision]], N[(y + N[(y * x), $MachinePrecision]), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.2 \lor \neg \left(y \leq 1.35 \cdot 10^{-15}\right):\\
\;\;\;\;y + y \cdot x\\

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


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

    1. Initial program 99.9%

      \[\left(x + 1\right) \cdot y - x \]
    2. Taylor expanded in x around 0 99.9%

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

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

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

    if -4.20000000000000018 < y < 1.35000000000000005e-15

    1. Initial program 100.0%

      \[\left(x + 1\right) \cdot y - x \]
    2. Taylor expanded in x around 0 99.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -4.2 \lor \neg \left(y \leq 1.35 \cdot 10^{-15}\right):\\ \;\;\;\;y + y \cdot x\\ \mathbf{else}:\\ \;\;\;\;y - x\\ \end{array} \]

Alternative 7: 100.0% accurate, 1.0× speedup?

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

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

    \[\left(x + 1\right) \cdot y - x \]
  2. Final simplification99.9%

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

Alternative 8: 62.9% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -4.4 \cdot 10^{-51}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 3.8 \cdot 10^{-17}:\\ \;\;\;\;-x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= y -4.4e-51) y (if (<= y 3.8e-17) (- x) y)))
double code(double x, double y) {
	double tmp;
	if (y <= -4.4e-51) {
		tmp = y;
	} else if (y <= 3.8e-17) {
		tmp = -x;
	} else {
		tmp = y;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (y <= (-4.4d-51)) then
        tmp = y
    else if (y <= 3.8d-17) then
        tmp = -x
    else
        tmp = y
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (y <= -4.4e-51) {
		tmp = y;
	} else if (y <= 3.8e-17) {
		tmp = -x;
	} else {
		tmp = y;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if y <= -4.4e-51:
		tmp = y
	elif y <= 3.8e-17:
		tmp = -x
	else:
		tmp = y
	return tmp
function code(x, y)
	tmp = 0.0
	if (y <= -4.4e-51)
		tmp = y;
	elseif (y <= 3.8e-17)
		tmp = Float64(-x);
	else
		tmp = y;
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= -4.4e-51)
		tmp = y;
	elseif (y <= 3.8e-17)
		tmp = -x;
	else
		tmp = y;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[y, -4.4e-51], y, If[LessEqual[y, 3.8e-17], (-x), y]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.4 \cdot 10^{-51}:\\
\;\;\;\;y\\

\mathbf{elif}\;y \leq 3.8 \cdot 10^{-17}:\\
\;\;\;\;-x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -4.4e-51 or 3.8000000000000001e-17 < y

    1. Initial program 99.9%

      \[\left(x + 1\right) \cdot y - x \]
    2. Taylor expanded in x around 0 99.9%

      \[\leadsto \color{blue}{\left(y \cdot x + y\right)} - x \]
    3. Taylor expanded in x around 0 48.1%

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

    if -4.4e-51 < y < 3.8000000000000001e-17

    1. Initial program 100.0%

      \[\left(x + 1\right) \cdot y - x \]
    2. Taylor expanded in y around 0 80.8%

      \[\leadsto \color{blue}{-1 \cdot x} \]
    3. Step-by-step derivation
      1. neg-mul-180.8%

        \[\leadsto \color{blue}{-x} \]
    4. Simplified80.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -4.4 \cdot 10^{-51}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 3.8 \cdot 10^{-17}:\\ \;\;\;\;-x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]

Alternative 9: 38.2% 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 99.9%

    \[\left(x + 1\right) \cdot y - x \]
  2. Taylor expanded in x around 0 100.0%

    \[\leadsto \color{blue}{\left(y \cdot x + y\right)} - x \]
  3. Taylor expanded in x around 0 34.5%

    \[\leadsto \color{blue}{y} \]
  4. Final simplification34.5%

    \[\leadsto y \]

Reproduce

?
herbie shell --seed 2023252 
(FPCore (x y)
  :name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
  :precision binary64
  (- (* (+ x 1.0) y) x))