Data.Colour.SRGB:invTransferFunction from colour-2.3.3

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

Specification

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

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

\\
\frac{x + y}{y + 1}
\end{array}

Alternative 1: 100.0% accurate, 1.0× speedup?

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

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

    \[\frac{x + y}{y + 1} \]
  2. Final simplification100.0%

    \[\leadsto \frac{x + y}{y + 1} \]

Alternative 2: 73.5% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{x}{y + 1}\\ \mathbf{if}\;x \leq -2.8 \cdot 10^{+78}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 3950000000000:\\ \;\;\;\;\frac{y}{y + 1}\\ \mathbf{elif}\;x \leq 9 \cdot 10^{+42}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 8 \cdot 10^{+69}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (/ x (+ y 1.0))))
   (if (<= x -2.8e+78)
     t_0
     (if (<= x 3950000000000.0)
       (/ y (+ y 1.0))
       (if (<= x 9e+42) x (if (<= x 8e+69) 1.0 t_0))))))
double code(double x, double y) {
	double t_0 = x / (y + 1.0);
	double tmp;
	if (x <= -2.8e+78) {
		tmp = t_0;
	} else if (x <= 3950000000000.0) {
		tmp = y / (y + 1.0);
	} else if (x <= 9e+42) {
		tmp = x;
	} else if (x <= 8e+69) {
		tmp = 1.0;
	} 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 = x / (y + 1.0d0)
    if (x <= (-2.8d+78)) then
        tmp = t_0
    else if (x <= 3950000000000.0d0) then
        tmp = y / (y + 1.0d0)
    else if (x <= 9d+42) then
        tmp = x
    else if (x <= 8d+69) then
        tmp = 1.0d0
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double t_0 = x / (y + 1.0);
	double tmp;
	if (x <= -2.8e+78) {
		tmp = t_0;
	} else if (x <= 3950000000000.0) {
		tmp = y / (y + 1.0);
	} else if (x <= 9e+42) {
		tmp = x;
	} else if (x <= 8e+69) {
		tmp = 1.0;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y):
	t_0 = x / (y + 1.0)
	tmp = 0
	if x <= -2.8e+78:
		tmp = t_0
	elif x <= 3950000000000.0:
		tmp = y / (y + 1.0)
	elif x <= 9e+42:
		tmp = x
	elif x <= 8e+69:
		tmp = 1.0
	else:
		tmp = t_0
	return tmp
function code(x, y)
	t_0 = Float64(x / Float64(y + 1.0))
	tmp = 0.0
	if (x <= -2.8e+78)
		tmp = t_0;
	elseif (x <= 3950000000000.0)
		tmp = Float64(y / Float64(y + 1.0));
	elseif (x <= 9e+42)
		tmp = x;
	elseif (x <= 8e+69)
		tmp = 1.0;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = x / (y + 1.0);
	tmp = 0.0;
	if (x <= -2.8e+78)
		tmp = t_0;
	elseif (x <= 3950000000000.0)
		tmp = y / (y + 1.0);
	elseif (x <= 9e+42)
		tmp = x;
	elseif (x <= 8e+69)
		tmp = 1.0;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -2.8e+78], t$95$0, If[LessEqual[x, 3950000000000.0], N[(y / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 9e+42], x, If[LessEqual[x, 8e+69], 1.0, t$95$0]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{x}{y + 1}\\
\mathbf{if}\;x \leq -2.8 \cdot 10^{+78}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq 3950000000000:\\
\;\;\;\;\frac{y}{y + 1}\\

\mathbf{elif}\;x \leq 9 \cdot 10^{+42}:\\
\;\;\;\;x\\

\mathbf{elif}\;x \leq 8 \cdot 10^{+69}:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if x < -2.8000000000000001e78 or 8.0000000000000006e69 < x

    1. Initial program 100.0%

      \[\frac{x + y}{y + 1} \]
    2. Taylor expanded in x around inf 82.1%

      \[\leadsto \color{blue}{\frac{x}{1 + y}} \]
    3. Step-by-step derivation
      1. +-commutative82.1%

        \[\leadsto \frac{x}{\color{blue}{y + 1}} \]
    4. Simplified82.1%

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

    if -2.8000000000000001e78 < x < 3.95e12

    1. Initial program 99.9%

      \[\frac{x + y}{y + 1} \]
    2. Taylor expanded in x around 0 79.9%

      \[\leadsto \color{blue}{\frac{y}{1 + y}} \]
    3. Step-by-step derivation
      1. +-commutative79.9%

        \[\leadsto \frac{y}{\color{blue}{y + 1}} \]
    4. Simplified79.9%

      \[\leadsto \color{blue}{\frac{y}{y + 1}} \]

    if 3.95e12 < x < 9.00000000000000025e42

    1. Initial program 100.0%

      \[\frac{x + y}{y + 1} \]
    2. Taylor expanded in y around 0 86.8%

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

    if 9.00000000000000025e42 < x < 8.0000000000000006e69

    1. Initial program 100.0%

      \[\frac{x + y}{y + 1} \]
    2. Taylor expanded in y around inf 100.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.8 \cdot 10^{+78}:\\ \;\;\;\;\frac{x}{y + 1}\\ \mathbf{elif}\;x \leq 3950000000000:\\ \;\;\;\;\frac{y}{y + 1}\\ \mathbf{elif}\;x \leq 9 \cdot 10^{+42}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 8 \cdot 10^{+69}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y + 1}\\ \end{array} \]

Alternative 3: 85.1% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 1 - \frac{1 - x}{y}\\ \mathbf{if}\;y \leq -150:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 8.3 \cdot 10^{-112}:\\ \;\;\;\;\frac{x}{y + 1}\\ \mathbf{elif}\;y \leq 31000000:\\ \;\;\;\;\frac{y}{y + 1}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (- 1.0 (/ (- 1.0 x) y))))
   (if (<= y -150.0)
     t_0
     (if (<= y 8.3e-112)
       (/ x (+ y 1.0))
       (if (<= y 31000000.0) (/ y (+ y 1.0)) t_0)))))
double code(double x, double y) {
	double t_0 = 1.0 - ((1.0 - x) / y);
	double tmp;
	if (y <= -150.0) {
		tmp = t_0;
	} else if (y <= 8.3e-112) {
		tmp = x / (y + 1.0);
	} else if (y <= 31000000.0) {
		tmp = y / (y + 1.0);
	} 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 = 1.0d0 - ((1.0d0 - x) / y)
    if (y <= (-150.0d0)) then
        tmp = t_0
    else if (y <= 8.3d-112) then
        tmp = x / (y + 1.0d0)
    else if (y <= 31000000.0d0) then
        tmp = y / (y + 1.0d0)
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double t_0 = 1.0 - ((1.0 - x) / y);
	double tmp;
	if (y <= -150.0) {
		tmp = t_0;
	} else if (y <= 8.3e-112) {
		tmp = x / (y + 1.0);
	} else if (y <= 31000000.0) {
		tmp = y / (y + 1.0);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y):
	t_0 = 1.0 - ((1.0 - x) / y)
	tmp = 0
	if y <= -150.0:
		tmp = t_0
	elif y <= 8.3e-112:
		tmp = x / (y + 1.0)
	elif y <= 31000000.0:
		tmp = y / (y + 1.0)
	else:
		tmp = t_0
	return tmp
function code(x, y)
	t_0 = Float64(1.0 - Float64(Float64(1.0 - x) / y))
	tmp = 0.0
	if (y <= -150.0)
		tmp = t_0;
	elseif (y <= 8.3e-112)
		tmp = Float64(x / Float64(y + 1.0));
	elseif (y <= 31000000.0)
		tmp = Float64(y / Float64(y + 1.0));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = 1.0 - ((1.0 - x) / y);
	tmp = 0.0;
	if (y <= -150.0)
		tmp = t_0;
	elseif (y <= 8.3e-112)
		tmp = x / (y + 1.0);
	elseif (y <= 31000000.0)
		tmp = y / (y + 1.0);
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[(1.0 - N[(N[(1.0 - x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -150.0], t$95$0, If[LessEqual[y, 8.3e-112], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 31000000.0], N[(y / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 1 - \frac{1 - x}{y}\\
\mathbf{if}\;y \leq -150:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq 8.3 \cdot 10^{-112}:\\
\;\;\;\;\frac{x}{y + 1}\\

\mathbf{elif}\;y \leq 31000000:\\
\;\;\;\;\frac{y}{y + 1}\\

\mathbf{else}:\\
\;\;\;\;t_0\\


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

    1. Initial program 100.0%

      \[\frac{x + y}{y + 1} \]
    2. Taylor expanded in y around -inf 99.6%

      \[\leadsto \color{blue}{1 + -1 \cdot \frac{1 + -1 \cdot x}{y}} \]
    3. Step-by-step derivation
      1. mul-1-neg99.6%

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

        \[\leadsto \color{blue}{1 - \frac{1 + -1 \cdot x}{y}} \]
      3. mul-1-neg99.6%

        \[\leadsto 1 - \frac{1 + \color{blue}{\left(-x\right)}}{y} \]
      4. sub-neg99.6%

        \[\leadsto 1 - \frac{\color{blue}{1 - x}}{y} \]
    4. Simplified99.6%

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

    if -150 < y < 8.29999999999999961e-112

    1. Initial program 100.0%

      \[\frac{x + y}{y + 1} \]
    2. Taylor expanded in x around inf 77.8%

      \[\leadsto \color{blue}{\frac{x}{1 + y}} \]
    3. Step-by-step derivation
      1. +-commutative77.8%

        \[\leadsto \frac{x}{\color{blue}{y + 1}} \]
    4. Simplified77.8%

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

    if 8.29999999999999961e-112 < y < 3.1e7

    1. Initial program 99.8%

      \[\frac{x + y}{y + 1} \]
    2. Taylor expanded in x around 0 69.1%

      \[\leadsto \color{blue}{\frac{y}{1 + y}} \]
    3. Step-by-step derivation
      1. +-commutative69.1%

        \[\leadsto \frac{y}{\color{blue}{y + 1}} \]
    4. Simplified69.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -150:\\ \;\;\;\;1 - \frac{1 - x}{y}\\ \mathbf{elif}\;y \leq 8.3 \cdot 10^{-112}:\\ \;\;\;\;\frac{x}{y + 1}\\ \mathbf{elif}\;y \leq 31000000:\\ \;\;\;\;\frac{y}{y + 1}\\ \mathbf{else}:\\ \;\;\;\;1 - \frac{1 - x}{y}\\ \end{array} \]

Alternative 4: 72.8% accurate, 0.6× speedup?

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

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

\mathbf{elif}\;y \leq 1.7 \cdot 10^{-111}:\\
\;\;\;\;x\\

\mathbf{elif}\;y \leq 0.76:\\
\;\;\;\;y - y \cdot y\\

\mathbf{else}:\\
\;\;\;\;1\\


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

    1. Initial program 100.0%

      \[\frac{x + y}{y + 1} \]
    2. Taylor expanded in y around inf 75.9%

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

    if -1 < y < 1.69999999999999998e-111

    1. Initial program 100.0%

      \[\frac{x + y}{y + 1} \]
    2. Taylor expanded in y around 0 76.0%

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

    if 1.69999999999999998e-111 < y < 0.76000000000000001

    1. Initial program 99.7%

      \[\frac{x + y}{y + 1} \]
    2. Taylor expanded in x around 0 67.4%

      \[\leadsto \color{blue}{\frac{y}{1 + y}} \]
    3. Step-by-step derivation
      1. +-commutative67.4%

        \[\leadsto \frac{y}{\color{blue}{y + 1}} \]
    4. Simplified67.4%

      \[\leadsto \color{blue}{\frac{y}{y + 1}} \]
    5. Taylor expanded in y around 0 67.6%

      \[\leadsto \color{blue}{-1 \cdot {y}^{2} + y} \]
    6. Step-by-step derivation
      1. neg-mul-167.6%

        \[\leadsto \color{blue}{\left(-{y}^{2}\right)} + y \]
      2. +-commutative67.6%

        \[\leadsto \color{blue}{y + \left(-{y}^{2}\right)} \]
      3. unsub-neg67.6%

        \[\leadsto \color{blue}{y - {y}^{2}} \]
      4. unpow267.6%

        \[\leadsto y - \color{blue}{y \cdot y} \]
    7. Simplified67.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 1.7 \cdot 10^{-111}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 0.76:\\ \;\;\;\;y - y \cdot y\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]

Alternative 5: 73.1% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -150:\\
\;\;\;\;1\\

\mathbf{elif}\;y \leq 1.25 \cdot 10^{-111}:\\
\;\;\;\;\frac{x}{y + 1}\\

\mathbf{elif}\;y \leq 0.76:\\
\;\;\;\;y - y \cdot y\\

\mathbf{else}:\\
\;\;\;\;1\\


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

    1. Initial program 100.0%

      \[\frac{x + y}{y + 1} \]
    2. Taylor expanded in y around inf 75.9%

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

    if -150 < y < 1.2500000000000001e-111

    1. Initial program 100.0%

      \[\frac{x + y}{y + 1} \]
    2. Taylor expanded in x around inf 77.8%

      \[\leadsto \color{blue}{\frac{x}{1 + y}} \]
    3. Step-by-step derivation
      1. +-commutative77.8%

        \[\leadsto \frac{x}{\color{blue}{y + 1}} \]
    4. Simplified77.8%

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

    if 1.2500000000000001e-111 < y < 0.76000000000000001

    1. Initial program 99.7%

      \[\frac{x + y}{y + 1} \]
    2. Taylor expanded in x around 0 67.4%

      \[\leadsto \color{blue}{\frac{y}{1 + y}} \]
    3. Step-by-step derivation
      1. +-commutative67.4%

        \[\leadsto \frac{y}{\color{blue}{y + 1}} \]
    4. Simplified67.4%

      \[\leadsto \color{blue}{\frac{y}{y + 1}} \]
    5. Taylor expanded in y around 0 67.6%

      \[\leadsto \color{blue}{-1 \cdot {y}^{2} + y} \]
    6. Step-by-step derivation
      1. neg-mul-167.6%

        \[\leadsto \color{blue}{\left(-{y}^{2}\right)} + y \]
      2. +-commutative67.6%

        \[\leadsto \color{blue}{y + \left(-{y}^{2}\right)} \]
      3. unsub-neg67.6%

        \[\leadsto \color{blue}{y - {y}^{2}} \]
      4. unpow267.6%

        \[\leadsto y - \color{blue}{y \cdot y} \]
    7. Simplified67.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -150:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 1.25 \cdot 10^{-111}:\\ \;\;\;\;\frac{x}{y + 1}\\ \mathbf{elif}\;y \leq 0.76:\\ \;\;\;\;y - y \cdot y\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]

Alternative 6: 84.8% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 1 + \frac{x}{y}\\ \mathbf{if}\;y \leq -150:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.7 \cdot 10^{-111}:\\ \;\;\;\;\frac{x}{y + 1}\\ \mathbf{elif}\;y \leq 1.65 \cdot 10^{+14}:\\ \;\;\;\;\frac{y}{y + 1}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (+ 1.0 (/ x y))))
   (if (<= y -150.0)
     t_0
     (if (<= y 1.7e-111)
       (/ x (+ y 1.0))
       (if (<= y 1.65e+14) (/ y (+ y 1.0)) t_0)))))
double code(double x, double y) {
	double t_0 = 1.0 + (x / y);
	double tmp;
	if (y <= -150.0) {
		tmp = t_0;
	} else if (y <= 1.7e-111) {
		tmp = x / (y + 1.0);
	} else if (y <= 1.65e+14) {
		tmp = y / (y + 1.0);
	} 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 = 1.0d0 + (x / y)
    if (y <= (-150.0d0)) then
        tmp = t_0
    else if (y <= 1.7d-111) then
        tmp = x / (y + 1.0d0)
    else if (y <= 1.65d+14) then
        tmp = y / (y + 1.0d0)
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double t_0 = 1.0 + (x / y);
	double tmp;
	if (y <= -150.0) {
		tmp = t_0;
	} else if (y <= 1.7e-111) {
		tmp = x / (y + 1.0);
	} else if (y <= 1.65e+14) {
		tmp = y / (y + 1.0);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y):
	t_0 = 1.0 + (x / y)
	tmp = 0
	if y <= -150.0:
		tmp = t_0
	elif y <= 1.7e-111:
		tmp = x / (y + 1.0)
	elif y <= 1.65e+14:
		tmp = y / (y + 1.0)
	else:
		tmp = t_0
	return tmp
function code(x, y)
	t_0 = Float64(1.0 + Float64(x / y))
	tmp = 0.0
	if (y <= -150.0)
		tmp = t_0;
	elseif (y <= 1.7e-111)
		tmp = Float64(x / Float64(y + 1.0));
	elseif (y <= 1.65e+14)
		tmp = Float64(y / Float64(y + 1.0));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = 1.0 + (x / y);
	tmp = 0.0;
	if (y <= -150.0)
		tmp = t_0;
	elseif (y <= 1.7e-111)
		tmp = x / (y + 1.0);
	elseif (y <= 1.65e+14)
		tmp = y / (y + 1.0);
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -150.0], t$95$0, If[LessEqual[y, 1.7e-111], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.65e+14], N[(y / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 1 + \frac{x}{y}\\
\mathbf{if}\;y \leq -150:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq 1.7 \cdot 10^{-111}:\\
\;\;\;\;\frac{x}{y + 1}\\

\mathbf{elif}\;y \leq 1.65 \cdot 10^{+14}:\\
\;\;\;\;\frac{y}{y + 1}\\

\mathbf{else}:\\
\;\;\;\;t_0\\


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

    1. Initial program 100.0%

      \[\frac{x + y}{y + 1} \]
    2. Taylor expanded in y around -inf 99.6%

      \[\leadsto \color{blue}{1 + -1 \cdot \frac{1 + -1 \cdot x}{y}} \]
    3. Step-by-step derivation
      1. mul-1-neg99.6%

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

        \[\leadsto \color{blue}{1 - \frac{1 + -1 \cdot x}{y}} \]
      3. mul-1-neg99.6%

        \[\leadsto 1 - \frac{1 + \color{blue}{\left(-x\right)}}{y} \]
      4. sub-neg99.6%

        \[\leadsto 1 - \frac{\color{blue}{1 - x}}{y} \]
    4. Simplified99.6%

      \[\leadsto \color{blue}{1 - \frac{1 - x}{y}} \]
    5. Taylor expanded in x around inf 99.0%

      \[\leadsto 1 - \color{blue}{-1 \cdot \frac{x}{y}} \]
    6. Step-by-step derivation
      1. neg-mul-199.0%

        \[\leadsto 1 - \color{blue}{\left(-\frac{x}{y}\right)} \]
      2. distribute-neg-frac99.0%

        \[\leadsto 1 - \color{blue}{\frac{-x}{y}} \]
    7. Simplified99.0%

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

    if -150 < y < 1.69999999999999998e-111

    1. Initial program 100.0%

      \[\frac{x + y}{y + 1} \]
    2. Taylor expanded in x around inf 77.8%

      \[\leadsto \color{blue}{\frac{x}{1 + y}} \]
    3. Step-by-step derivation
      1. +-commutative77.8%

        \[\leadsto \frac{x}{\color{blue}{y + 1}} \]
    4. Simplified77.8%

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

    if 1.69999999999999998e-111 < y < 1.65e14

    1. Initial program 99.8%

      \[\frac{x + y}{y + 1} \]
    2. Taylor expanded in x around 0 70.6%

      \[\leadsto \color{blue}{\frac{y}{1 + y}} \]
    3. Step-by-step derivation
      1. +-commutative70.6%

        \[\leadsto \frac{y}{\color{blue}{y + 1}} \]
    4. Simplified70.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -150:\\ \;\;\;\;1 + \frac{x}{y}\\ \mathbf{elif}\;y \leq 1.7 \cdot 10^{-111}:\\ \;\;\;\;\frac{x}{y + 1}\\ \mathbf{elif}\;y \leq 1.65 \cdot 10^{+14}:\\ \;\;\;\;\frac{y}{y + 1}\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{x}{y}\\ \end{array} \]

Alternative 7: 72.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 1.25 \cdot 10^{-111}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 1:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= y -1.0) 1.0 (if (<= y 1.25e-111) x (if (<= y 1.0) y 1.0))))
double code(double x, double y) {
	double tmp;
	if (y <= -1.0) {
		tmp = 1.0;
	} else if (y <= 1.25e-111) {
		tmp = x;
	} else if (y <= 1.0) {
		tmp = y;
	} else {
		tmp = 1.0;
	}
	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 = 1.0d0
    else if (y <= 1.25d-111) then
        tmp = x
    else if (y <= 1.0d0) then
        tmp = y
    else
        tmp = 1.0d0
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (y <= -1.0) {
		tmp = 1.0;
	} else if (y <= 1.25e-111) {
		tmp = x;
	} else if (y <= 1.0) {
		tmp = y;
	} else {
		tmp = 1.0;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if y <= -1.0:
		tmp = 1.0
	elif y <= 1.25e-111:
		tmp = x
	elif y <= 1.0:
		tmp = y
	else:
		tmp = 1.0
	return tmp
function code(x, y)
	tmp = 0.0
	if (y <= -1.0)
		tmp = 1.0;
	elseif (y <= 1.25e-111)
		tmp = x;
	elseif (y <= 1.0)
		tmp = y;
	else
		tmp = 1.0;
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= -1.0)
		tmp = 1.0;
	elseif (y <= 1.25e-111)
		tmp = x;
	elseif (y <= 1.0)
		tmp = y;
	else
		tmp = 1.0;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[y, -1.0], 1.0, If[LessEqual[y, 1.25e-111], x, If[LessEqual[y, 1.0], y, 1.0]]]
\begin{array}{l}

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

\mathbf{elif}\;y \leq 1.25 \cdot 10^{-111}:\\
\;\;\;\;x\\

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

\mathbf{else}:\\
\;\;\;\;1\\


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

    1. Initial program 100.0%

      \[\frac{x + y}{y + 1} \]
    2. Taylor expanded in y around inf 75.9%

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

    if -1 < y < 1.2500000000000001e-111

    1. Initial program 100.0%

      \[\frac{x + y}{y + 1} \]
    2. Taylor expanded in y around 0 76.0%

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

    if 1.2500000000000001e-111 < y < 1

    1. Initial program 99.7%

      \[\frac{x + y}{y + 1} \]
    2. Taylor expanded in x around 0 67.4%

      \[\leadsto \color{blue}{\frac{y}{1 + y}} \]
    3. Step-by-step derivation
      1. +-commutative67.4%

        \[\leadsto \frac{y}{\color{blue}{y + 1}} \]
    4. Simplified67.4%

      \[\leadsto \color{blue}{\frac{y}{y + 1}} \]
    5. Taylor expanded in y around 0 65.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 1.25 \cdot 10^{-111}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 1:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]

Alternative 8: 74.5% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 3.5 \cdot 10^{-9}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= y -1.0) 1.0 (if (<= y 3.5e-9) x 1.0)))
double code(double x, double y) {
	double tmp;
	if (y <= -1.0) {
		tmp = 1.0;
	} else if (y <= 3.5e-9) {
		tmp = x;
	} else {
		tmp = 1.0;
	}
	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 = 1.0d0
    else if (y <= 3.5d-9) then
        tmp = x
    else
        tmp = 1.0d0
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (y <= -1.0) {
		tmp = 1.0;
	} else if (y <= 3.5e-9) {
		tmp = x;
	} else {
		tmp = 1.0;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if y <= -1.0:
		tmp = 1.0
	elif y <= 3.5e-9:
		tmp = x
	else:
		tmp = 1.0
	return tmp
function code(x, y)
	tmp = 0.0
	if (y <= -1.0)
		tmp = 1.0;
	elseif (y <= 3.5e-9)
		tmp = x;
	else
		tmp = 1.0;
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= -1.0)
		tmp = 1.0;
	elseif (y <= 3.5e-9)
		tmp = x;
	else
		tmp = 1.0;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[y, -1.0], 1.0, If[LessEqual[y, 3.5e-9], x, 1.0]]
\begin{array}{l}

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

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

\mathbf{else}:\\
\;\;\;\;1\\


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

    1. Initial program 100.0%

      \[\frac{x + y}{y + 1} \]
    2. Taylor expanded in y around inf 75.4%

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

    if -1 < y < 3.4999999999999999e-9

    1. Initial program 100.0%

      \[\frac{x + y}{y + 1} \]
    2. Taylor expanded in y around 0 70.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 3.5 \cdot 10^{-9}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]

Alternative 9: 39.3% accurate, 7.0× speedup?

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

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

    \[\frac{x + y}{y + 1} \]
  2. Taylor expanded in y around inf 43.2%

    \[\leadsto \color{blue}{1} \]
  3. Final simplification43.2%

    \[\leadsto 1 \]

Reproduce

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