Data.Colour.SRGB:transferFunction from colour-2.3.3

Percentage Accurate: 100.0% → 100.0%
Time: 4.1s
Alternatives: 7
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 7 alternatives:

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

Initial Program: 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, 0.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 62.3% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -4 \cdot 10^{+270}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -3.6 \cdot 10^{+210}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \leq -2.8 \cdot 10^{+48}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -2.2 \cdot 10^{-58}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \leq 3.9 \cdot 10^{-29}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \leq 2.9 \cdot 10^{+32} \lor \neg \left(x \leq 4.9 \cdot 10^{+182}\right) \land x \leq 1.85 \cdot 10^{+203}:\\ \;\;\;\;-x\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= x -4e+270)
   (* x y)
   (if (<= x -3.6e+210)
     (- x)
     (if (<= x -2.8e+48)
       (* x y)
       (if (<= x -2.2e-58)
         (- x)
         (if (<= x 3.9e-29)
           y
           (if (or (<= x 2.9e+32) (and (not (<= x 4.9e+182)) (<= x 1.85e+203)))
             (- x)
             (* x y))))))))
double code(double x, double y) {
	double tmp;
	if (x <= -4e+270) {
		tmp = x * y;
	} else if (x <= -3.6e+210) {
		tmp = -x;
	} else if (x <= -2.8e+48) {
		tmp = x * y;
	} else if (x <= -2.2e-58) {
		tmp = -x;
	} else if (x <= 3.9e-29) {
		tmp = y;
	} else if ((x <= 2.9e+32) || (!(x <= 4.9e+182) && (x <= 1.85e+203))) {
		tmp = -x;
	} 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 <= (-4d+270)) then
        tmp = x * y
    else if (x <= (-3.6d+210)) then
        tmp = -x
    else if (x <= (-2.8d+48)) then
        tmp = x * y
    else if (x <= (-2.2d-58)) then
        tmp = -x
    else if (x <= 3.9d-29) then
        tmp = y
    else if ((x <= 2.9d+32) .or. (.not. (x <= 4.9d+182)) .and. (x <= 1.85d+203)) then
        tmp = -x
    else
        tmp = x * y
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (x <= -4e+270) {
		tmp = x * y;
	} else if (x <= -3.6e+210) {
		tmp = -x;
	} else if (x <= -2.8e+48) {
		tmp = x * y;
	} else if (x <= -2.2e-58) {
		tmp = -x;
	} else if (x <= 3.9e-29) {
		tmp = y;
	} else if ((x <= 2.9e+32) || (!(x <= 4.9e+182) && (x <= 1.85e+203))) {
		tmp = -x;
	} else {
		tmp = x * y;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if x <= -4e+270:
		tmp = x * y
	elif x <= -3.6e+210:
		tmp = -x
	elif x <= -2.8e+48:
		tmp = x * y
	elif x <= -2.2e-58:
		tmp = -x
	elif x <= 3.9e-29:
		tmp = y
	elif (x <= 2.9e+32) or (not (x <= 4.9e+182) and (x <= 1.85e+203)):
		tmp = -x
	else:
		tmp = x * y
	return tmp
function code(x, y)
	tmp = 0.0
	if (x <= -4e+270)
		tmp = Float64(x * y);
	elseif (x <= -3.6e+210)
		tmp = Float64(-x);
	elseif (x <= -2.8e+48)
		tmp = Float64(x * y);
	elseif (x <= -2.2e-58)
		tmp = Float64(-x);
	elseif (x <= 3.9e-29)
		tmp = y;
	elseif ((x <= 2.9e+32) || (!(x <= 4.9e+182) && (x <= 1.85e+203)))
		tmp = Float64(-x);
	else
		tmp = Float64(x * y);
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (x <= -4e+270)
		tmp = x * y;
	elseif (x <= -3.6e+210)
		tmp = -x;
	elseif (x <= -2.8e+48)
		tmp = x * y;
	elseif (x <= -2.2e-58)
		tmp = -x;
	elseif (x <= 3.9e-29)
		tmp = y;
	elseif ((x <= 2.9e+32) || (~((x <= 4.9e+182)) && (x <= 1.85e+203)))
		tmp = -x;
	else
		tmp = x * y;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[x, -4e+270], N[(x * y), $MachinePrecision], If[LessEqual[x, -3.6e+210], (-x), If[LessEqual[x, -2.8e+48], N[(x * y), $MachinePrecision], If[LessEqual[x, -2.2e-58], (-x), If[LessEqual[x, 3.9e-29], y, If[Or[LessEqual[x, 2.9e+32], And[N[Not[LessEqual[x, 4.9e+182]], $MachinePrecision], LessEqual[x, 1.85e+203]]], (-x), N[(x * y), $MachinePrecision]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;x \leq -3.6 \cdot 10^{+210}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \leq -2.8 \cdot 10^{+48}:\\
\;\;\;\;x \cdot y\\

\mathbf{elif}\;x \leq -2.2 \cdot 10^{-58}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \leq 3.9 \cdot 10^{-29}:\\
\;\;\;\;y\\

\mathbf{elif}\;x \leq 2.9 \cdot 10^{+32} \lor \neg \left(x \leq 4.9 \cdot 10^{+182}\right) \land x \leq 1.85 \cdot 10^{+203}:\\
\;\;\;\;-x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -4.0000000000000002e270 or -3.6000000000000003e210 < x < -2.80000000000000012e48 or 2.90000000000000003e32 < x < 4.9e182 or 1.85e203 < x

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{y \cdot \left(1 + x\right)} \]
    4. Step-by-step derivation
      1. distribute-lft-in64.5%

        \[\leadsto \color{blue}{y \cdot 1 + y \cdot x} \]
      2. *-rgt-identity64.5%

        \[\leadsto \color{blue}{y} + y \cdot x \]
      3. +-commutative64.5%

        \[\leadsto \color{blue}{y \cdot x + y} \]
    5. Applied egg-rr64.5%

      \[\leadsto \color{blue}{y \cdot x + y} \]
    6. Taylor expanded in x around inf 64.5%

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

        \[\leadsto \color{blue}{y \cdot x} \]
    8. Simplified64.5%

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

    if -4.0000000000000002e270 < x < -3.6000000000000003e210 or -2.80000000000000012e48 < x < -2.20000000000000006e-58 or 3.8999999999999998e-29 < x < 2.90000000000000003e32 or 4.9e182 < x < 1.85e203

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{-x} \]
    5. Simplified63.5%

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

    if -2.20000000000000006e-58 < x < 3.8999999999999998e-29

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -4 \cdot 10^{+270}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -3.6 \cdot 10^{+210}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \leq -2.8 \cdot 10^{+48}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -2.2 \cdot 10^{-58}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \leq 3.9 \cdot 10^{-29}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \leq 2.9 \cdot 10^{+32} \lor \neg \left(x \leq 4.9 \cdot 10^{+182}\right) \land x \leq 1.85 \cdot 10^{+203}:\\ \;\;\;\;-x\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 75.5% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -5.8 \cdot 10^{+205}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq -1.05 \cdot 10^{+163}:\\ \;\;\;\;y - x\\ \mathbf{elif}\;y \leq -2.1 \cdot 10^{+145}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq -4 \cdot 10^{+118}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq -1 \cdot 10^{+85} \lor \neg \left(y \leq 1.06 \cdot 10^{+54}\right):\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;y - x\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= y -5.8e+205)
   (* x y)
   (if (<= y -1.05e+163)
     (- y x)
     (if (<= y -2.1e+145)
       (* x y)
       (if (<= y -4e+118)
         y
         (if (or (<= y -1e+85) (not (<= y 1.06e+54))) (* x y) (- y x)))))))
double code(double x, double y) {
	double tmp;
	if (y <= -5.8e+205) {
		tmp = x * y;
	} else if (y <= -1.05e+163) {
		tmp = y - x;
	} else if (y <= -2.1e+145) {
		tmp = x * y;
	} else if (y <= -4e+118) {
		tmp = y;
	} else if ((y <= -1e+85) || !(y <= 1.06e+54)) {
		tmp = x * 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 <= (-5.8d+205)) then
        tmp = x * y
    else if (y <= (-1.05d+163)) then
        tmp = y - x
    else if (y <= (-2.1d+145)) then
        tmp = x * y
    else if (y <= (-4d+118)) then
        tmp = y
    else if ((y <= (-1d+85)) .or. (.not. (y <= 1.06d+54))) then
        tmp = x * y
    else
        tmp = y - x
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (y <= -5.8e+205) {
		tmp = x * y;
	} else if (y <= -1.05e+163) {
		tmp = y - x;
	} else if (y <= -2.1e+145) {
		tmp = x * y;
	} else if (y <= -4e+118) {
		tmp = y;
	} else if ((y <= -1e+85) || !(y <= 1.06e+54)) {
		tmp = x * y;
	} else {
		tmp = y - x;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if y <= -5.8e+205:
		tmp = x * y
	elif y <= -1.05e+163:
		tmp = y - x
	elif y <= -2.1e+145:
		tmp = x * y
	elif y <= -4e+118:
		tmp = y
	elif (y <= -1e+85) or not (y <= 1.06e+54):
		tmp = x * y
	else:
		tmp = y - x
	return tmp
function code(x, y)
	tmp = 0.0
	if (y <= -5.8e+205)
		tmp = Float64(x * y);
	elseif (y <= -1.05e+163)
		tmp = Float64(y - x);
	elseif (y <= -2.1e+145)
		tmp = Float64(x * y);
	elseif (y <= -4e+118)
		tmp = y;
	elseif ((y <= -1e+85) || !(y <= 1.06e+54))
		tmp = Float64(x * y);
	else
		tmp = Float64(y - x);
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= -5.8e+205)
		tmp = x * y;
	elseif (y <= -1.05e+163)
		tmp = y - x;
	elseif (y <= -2.1e+145)
		tmp = x * y;
	elseif (y <= -4e+118)
		tmp = y;
	elseif ((y <= -1e+85) || ~((y <= 1.06e+54)))
		tmp = x * y;
	else
		tmp = y - x;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[y, -5.8e+205], N[(x * y), $MachinePrecision], If[LessEqual[y, -1.05e+163], N[(y - x), $MachinePrecision], If[LessEqual[y, -2.1e+145], N[(x * y), $MachinePrecision], If[LessEqual[y, -4e+118], y, If[Or[LessEqual[y, -1e+85], N[Not[LessEqual[y, 1.06e+54]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(y - x), $MachinePrecision]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;y \leq -1.05 \cdot 10^{+163}:\\
\;\;\;\;y - x\\

\mathbf{elif}\;y \leq -2.1 \cdot 10^{+145}:\\
\;\;\;\;x \cdot y\\

\mathbf{elif}\;y \leq -4 \cdot 10^{+118}:\\
\;\;\;\;y\\

\mathbf{elif}\;y \leq -1 \cdot 10^{+85} \lor \neg \left(y \leq 1.06 \cdot 10^{+54}\right):\\
\;\;\;\;x \cdot y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -5.8000000000000003e205 or -1.05e163 < y < -2.09999999999999989e145 or -3.99999999999999987e118 < y < -1e85 or 1.06e54 < y

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{y \cdot \left(1 + x\right)} \]
    4. Step-by-step derivation
      1. distribute-lft-in100.0%

        \[\leadsto \color{blue}{y \cdot 1 + y \cdot x} \]
      2. *-rgt-identity100.0%

        \[\leadsto \color{blue}{y} + y \cdot x \]
      3. +-commutative100.0%

        \[\leadsto \color{blue}{y \cdot x + y} \]
    5. Applied egg-rr100.0%

      \[\leadsto \color{blue}{y \cdot x + y} \]
    6. Taylor expanded in x around inf 62.7%

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

        \[\leadsto \color{blue}{y \cdot x} \]
    8. Simplified62.7%

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

    if -5.8000000000000003e205 < y < -1.05e163 or -1e85 < y < 1.06e54

    1. Initial program 100.0%

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

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

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

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

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

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

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

    if -2.09999999999999989e145 < y < -3.99999999999999987e118

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -5.8 \cdot 10^{+205}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq -1.05 \cdot 10^{+163}:\\ \;\;\;\;y - x\\ \mathbf{elif}\;y \leq -2.1 \cdot 10^{+145}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq -4 \cdot 10^{+118}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq -1 \cdot 10^{+85} \lor \neg \left(y \leq 1.06 \cdot 10^{+54}\right):\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;y - x\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 97.9% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -360000000000 \lor \neg \left(x \leq 8.6 \cdot 10^{-30}\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 < -3.6e11 or 8.59999999999999932e-30 < x

    1. Initial program 100.0%

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

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

    if -3.6e11 < x < 8.59999999999999932e-30

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

Alternative 5: 63.4% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.65 \cdot 10^{-34} \lor \neg \left(x \leq 3.5 \cdot 10^{-30}\right):\\
\;\;\;\;-x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -2.6499999999999998e-34 or 3.5000000000000003e-30 < x

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{-x} \]
    5. Simplified45.3%

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

    if -2.6499999999999998e-34 < x < 3.5000000000000003e-30

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.65 \cdot 10^{-34} \lor \neg \left(x \leq 3.5 \cdot 10^{-30}\right):\\ \;\;\;\;-x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 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 100.0%

    \[\left(x + 1\right) \cdot y - x \]
  2. Add Preprocessing
  3. Final simplification100.0%

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

Alternative 7: 38.5% 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 + 1\right) \cdot y - x \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0 39.2%

    \[\leadsto \color{blue}{y} \]
  4. Add Preprocessing

Reproduce

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