Data.Colour.SRGB:invTransferFunction from colour-2.3.3

Percentage Accurate: 100.0% → 100.0%
Time: 5.0s
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. Add Preprocessing
  3. Add Preprocessing

Alternative 2: 86.4% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 1 + \frac{x + -1}{y}\\ t_1 := \frac{x}{y + 1}\\ \mathbf{if}\;y \leq -320000:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 5.5 \cdot 10^{-123}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;y \leq 2.1 \cdot 10^{-79}:\\ \;\;\;\;\frac{y}{y + 1}\\ \mathbf{elif}\;y \leq 59:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (+ 1.0 (/ (+ x -1.0) y))) (t_1 (/ x (+ y 1.0))))
   (if (<= y -320000.0)
     t_0
     (if (<= y 5.5e-123)
       t_1
       (if (<= y 2.1e-79) (/ y (+ y 1.0)) (if (<= y 59.0) t_1 t_0))))))
double code(double x, double y) {
	double t_0 = 1.0 + ((x + -1.0) / y);
	double t_1 = x / (y + 1.0);
	double tmp;
	if (y <= -320000.0) {
		tmp = t_0;
	} else if (y <= 5.5e-123) {
		tmp = t_1;
	} else if (y <= 2.1e-79) {
		tmp = y / (y + 1.0);
	} else if (y <= 59.0) {
		tmp = t_1;
	} 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) :: t_1
    real(8) :: tmp
    t_0 = 1.0d0 + ((x + (-1.0d0)) / y)
    t_1 = x / (y + 1.0d0)
    if (y <= (-320000.0d0)) then
        tmp = t_0
    else if (y <= 5.5d-123) then
        tmp = t_1
    else if (y <= 2.1d-79) then
        tmp = y / (y + 1.0d0)
    else if (y <= 59.0d0) then
        tmp = t_1
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double t_0 = 1.0 + ((x + -1.0) / y);
	double t_1 = x / (y + 1.0);
	double tmp;
	if (y <= -320000.0) {
		tmp = t_0;
	} else if (y <= 5.5e-123) {
		tmp = t_1;
	} else if (y <= 2.1e-79) {
		tmp = y / (y + 1.0);
	} else if (y <= 59.0) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y):
	t_0 = 1.0 + ((x + -1.0) / y)
	t_1 = x / (y + 1.0)
	tmp = 0
	if y <= -320000.0:
		tmp = t_0
	elif y <= 5.5e-123:
		tmp = t_1
	elif y <= 2.1e-79:
		tmp = y / (y + 1.0)
	elif y <= 59.0:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(x, y)
	t_0 = Float64(1.0 + Float64(Float64(x + -1.0) / y))
	t_1 = Float64(x / Float64(y + 1.0))
	tmp = 0.0
	if (y <= -320000.0)
		tmp = t_0;
	elseif (y <= 5.5e-123)
		tmp = t_1;
	elseif (y <= 2.1e-79)
		tmp = Float64(y / Float64(y + 1.0));
	elseif (y <= 59.0)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = 1.0 + ((x + -1.0) / y);
	t_1 = x / (y + 1.0);
	tmp = 0.0;
	if (y <= -320000.0)
		tmp = t_0;
	elseif (y <= 5.5e-123)
		tmp = t_1;
	elseif (y <= 2.1e-79)
		tmp = y / (y + 1.0);
	elseif (y <= 59.0)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[(1.0 + N[(N[(x + -1.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -320000.0], t$95$0, If[LessEqual[y, 5.5e-123], t$95$1, If[LessEqual[y, 2.1e-79], N[(y / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 59.0], t$95$1, t$95$0]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 1 + \frac{x + -1}{y}\\
t_1 := \frac{x}{y + 1}\\
\mathbf{if}\;y \leq -320000:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;y \leq 5.5 \cdot 10^{-123}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;y \leq 2.1 \cdot 10^{-79}:\\
\;\;\;\;\frac{y}{y + 1}\\

\mathbf{elif}\;y \leq 59:\\
\;\;\;\;t\_1\\

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


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

    1. Initial program 100.0%

      \[\frac{x + y}{y + 1} \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf 99.3%

      \[\leadsto \color{blue}{\left(1 + \frac{x}{y}\right) - \frac{1}{y}} \]
    4. Step-by-step derivation
      1. associate--l+99.3%

        \[\leadsto \color{blue}{1 + \left(\frac{x}{y} - \frac{1}{y}\right)} \]
      2. div-sub99.3%

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

        \[\leadsto 1 + \frac{\color{blue}{x + \left(-1\right)}}{y} \]
      4. metadata-eval99.3%

        \[\leadsto 1 + \frac{x + \color{blue}{-1}}{y} \]
    5. Simplified99.3%

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

    if -3.2e5 < y < 5.5e-123 or 2.0999999999999999e-79 < y < 59

    1. Initial program 99.9%

      \[\frac{x + y}{y + 1} \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 75.3%

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

        \[\leadsto \frac{x}{\color{blue}{y + 1}} \]
    5. Simplified75.3%

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

    if 5.5e-123 < y < 2.0999999999999999e-79

    1. Initial program 100.0%

      \[\frac{x + y}{y + 1} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 87.7%

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

        \[\leadsto \frac{y}{\color{blue}{y + 1}} \]
    5. Simplified87.7%

      \[\leadsto \color{blue}{\frac{y}{y + 1}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 3: 74.5% accurate, 0.3× speedup?

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

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

\mathbf{elif}\;y \leq 4.8 \cdot 10^{-123}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;y \leq 1.3 \cdot 10^{-77}:\\
\;\;\;\;y\\

\mathbf{elif}\;y \leq 1.7 \cdot 10^{+43}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 100.0%

      \[\frac{x + y}{y + 1} \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf 81.1%

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

    if -3.5000000000000001e35 < y < 4.8e-123 or 1.3000000000000001e-77 < y < 1.70000000000000006e43

    1. Initial program 99.9%

      \[\frac{x + y}{y + 1} \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 71.6%

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

        \[\leadsto \frac{x}{\color{blue}{y + 1}} \]
    5. Simplified71.6%

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

    if 4.8e-123 < y < 1.3000000000000001e-77

    1. Initial program 100.0%

      \[\frac{x + y}{y + 1} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 87.7%

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

        \[\leadsto \frac{y}{\color{blue}{y + 1}} \]
    5. Simplified87.7%

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

      \[\leadsto \color{blue}{y} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 4: 73.7% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \left(1 - y\right)\\ \mathbf{if}\;y \leq -1:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 5.5 \cdot 10^{-123}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 1.18 \cdot 10^{-79}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 0.64:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (* x (- 1.0 y))))
   (if (<= y -1.0)
     1.0
     (if (<= y 5.5e-123)
       t_0
       (if (<= y 1.18e-79) y (if (<= y 0.64) t_0 1.0))))))
double code(double x, double y) {
	double t_0 = x * (1.0 - y);
	double tmp;
	if (y <= -1.0) {
		tmp = 1.0;
	} else if (y <= 5.5e-123) {
		tmp = t_0;
	} else if (y <= 1.18e-79) {
		tmp = y;
	} else if (y <= 0.64) {
		tmp = t_0;
	} else {
		tmp = 1.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 * (1.0d0 - y)
    if (y <= (-1.0d0)) then
        tmp = 1.0d0
    else if (y <= 5.5d-123) then
        tmp = t_0
    else if (y <= 1.18d-79) then
        tmp = y
    else if (y <= 0.64d0) then
        tmp = t_0
    else
        tmp = 1.0d0
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double t_0 = x * (1.0 - y);
	double tmp;
	if (y <= -1.0) {
		tmp = 1.0;
	} else if (y <= 5.5e-123) {
		tmp = t_0;
	} else if (y <= 1.18e-79) {
		tmp = y;
	} else if (y <= 0.64) {
		tmp = t_0;
	} else {
		tmp = 1.0;
	}
	return tmp;
}
def code(x, y):
	t_0 = x * (1.0 - y)
	tmp = 0
	if y <= -1.0:
		tmp = 1.0
	elif y <= 5.5e-123:
		tmp = t_0
	elif y <= 1.18e-79:
		tmp = y
	elif y <= 0.64:
		tmp = t_0
	else:
		tmp = 1.0
	return tmp
function code(x, y)
	t_0 = Float64(x * Float64(1.0 - y))
	tmp = 0.0
	if (y <= -1.0)
		tmp = 1.0;
	elseif (y <= 5.5e-123)
		tmp = t_0;
	elseif (y <= 1.18e-79)
		tmp = y;
	elseif (y <= 0.64)
		tmp = t_0;
	else
		tmp = 1.0;
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = x * (1.0 - y);
	tmp = 0.0;
	if (y <= -1.0)
		tmp = 1.0;
	elseif (y <= 5.5e-123)
		tmp = t_0;
	elseif (y <= 1.18e-79)
		tmp = y;
	elseif (y <= 0.64)
		tmp = t_0;
	else
		tmp = 1.0;
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.0], 1.0, If[LessEqual[y, 5.5e-123], t$95$0, If[LessEqual[y, 1.18e-79], y, If[LessEqual[y, 0.64], t$95$0, 1.0]]]]]
\begin{array}{l}

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

\mathbf{elif}\;y \leq 5.5 \cdot 10^{-123}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;y \leq 1.18 \cdot 10^{-79}:\\
\;\;\;\;y\\

\mathbf{elif}\;y \leq 0.64:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 100.0%

      \[\frac{x + y}{y + 1} \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf 74.0%

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

    if -1 < y < 5.5e-123 or 1.18e-79 < y < 0.640000000000000013

    1. Initial program 99.9%

      \[\frac{x + y}{y + 1} \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 75.1%

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

        \[\leadsto \frac{x}{\color{blue}{y + 1}} \]
    5. Simplified75.1%

      \[\leadsto \color{blue}{\frac{x}{y + 1}} \]
    6. Taylor expanded in y around 0 74.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 5.5e-123 < y < 1.18e-79

    1. Initial program 100.0%

      \[\frac{x + y}{y + 1} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 87.7%

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

        \[\leadsto \frac{y}{\color{blue}{y + 1}} \]
    5. Simplified87.7%

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

      \[\leadsto \color{blue}{y} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 5: 73.3% accurate, 0.3× speedup?

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

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

\mathbf{elif}\;y \leq 4.6 \cdot 10^{-128}:\\
\;\;\;\;x\\

\mathbf{elif}\;y \leq 8 \cdot 10^{-79}:\\
\;\;\;\;y\\

\mathbf{elif}\;y \leq 0.39:\\
\;\;\;\;x\\

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


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

    1. Initial program 100.0%

      \[\frac{x + y}{y + 1} \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf 74.0%

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

    if -1 < y < 4.6000000000000002e-128 or 8e-79 < y < 0.39000000000000001

    1. Initial program 99.9%

      \[\frac{x + y}{y + 1} \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0 71.5%

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

    if 4.6000000000000002e-128 < y < 8e-79

    1. Initial program 100.0%

      \[\frac{x + y}{y + 1} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 87.7%

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

        \[\leadsto \frac{y}{\color{blue}{y + 1}} \]
    5. Simplified87.7%

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

      \[\leadsto \color{blue}{y} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 6: 98.3% accurate, 0.4× speedup?

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

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

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


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

    1. Initial program 100.0%

      \[\frac{x + y}{y + 1} \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf 98.9%

      \[\leadsto \color{blue}{\left(1 + \frac{x}{y}\right) - \frac{1}{y}} \]
    4. Step-by-step derivation
      1. associate--l+98.9%

        \[\leadsto \color{blue}{1 + \left(\frac{x}{y} - \frac{1}{y}\right)} \]
      2. div-sub98.9%

        \[\leadsto 1 + \color{blue}{\frac{x - 1}{y}} \]
      3. sub-neg98.9%

        \[\leadsto 1 + \frac{\color{blue}{x + \left(-1\right)}}{y} \]
      4. metadata-eval98.9%

        \[\leadsto 1 + \frac{x + \color{blue}{-1}}{y} \]
    5. Simplified98.9%

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

    if -1 < y < 1

    1. Initial program 99.9%

      \[\frac{x + y}{y + 1} \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0 97.4%

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

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

Alternative 7: 75.0% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -4.6 \cdot 10^{-46} \lor \neg \left(x \leq 1.75 \cdot 10^{-44}\right):\\ \;\;\;\;\frac{x}{y + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{y + 1}\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (or (<= x -4.6e-46) (not (<= x 1.75e-44)))
   (/ x (+ y 1.0))
   (/ y (+ y 1.0))))
double code(double x, double y) {
	double tmp;
	if ((x <= -4.6e-46) || !(x <= 1.75e-44)) {
		tmp = x / (y + 1.0);
	} else {
		tmp = y / (y + 1.0);
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if ((x <= (-4.6d-46)) .or. (.not. (x <= 1.75d-44))) then
        tmp = x / (y + 1.0d0)
    else
        tmp = y / (y + 1.0d0)
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if ((x <= -4.6e-46) || !(x <= 1.75e-44)) {
		tmp = x / (y + 1.0);
	} else {
		tmp = y / (y + 1.0);
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if (x <= -4.6e-46) or not (x <= 1.75e-44):
		tmp = x / (y + 1.0)
	else:
		tmp = y / (y + 1.0)
	return tmp
function code(x, y)
	tmp = 0.0
	if ((x <= -4.6e-46) || !(x <= 1.75e-44))
		tmp = Float64(x / Float64(y + 1.0));
	else
		tmp = Float64(y / Float64(y + 1.0));
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if ((x <= -4.6e-46) || ~((x <= 1.75e-44)))
		tmp = x / (y + 1.0);
	else
		tmp = y / (y + 1.0);
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[Or[LessEqual[x, -4.6e-46], N[Not[LessEqual[x, 1.75e-44]], $MachinePrecision]], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], N[(y / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.6 \cdot 10^{-46} \lor \neg \left(x \leq 1.75 \cdot 10^{-44}\right):\\
\;\;\;\;\frac{x}{y + 1}\\

\mathbf{else}:\\
\;\;\;\;\frac{y}{y + 1}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -4.5999999999999998e-46 or 1.7499999999999999e-44 < x

    1. Initial program 99.9%

      \[\frac{x + y}{y + 1} \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 74.2%

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

        \[\leadsto \frac{x}{\color{blue}{y + 1}} \]
    5. Simplified74.2%

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

    if -4.5999999999999998e-46 < x < 1.7499999999999999e-44

    1. Initial program 100.0%

      \[\frac{x + y}{y + 1} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 87.4%

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

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

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

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

Alternative 8: 74.7% accurate, 0.6× speedup?

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

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

\mathbf{elif}\;y \leq 2.4:\\
\;\;\;\;x\\

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


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

    1. Initial program 100.0%

      \[\frac{x + y}{y + 1} \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf 74.0%

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

    if -1 < y < 2.39999999999999991

    1. Initial program 99.9%

      \[\frac{x + y}{y + 1} \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0 68.0%

      \[\leadsto \color{blue}{x} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 9: 38.6% 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. Add Preprocessing
  3. Taylor expanded in y around inf 40.8%

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

Reproduce

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