Data.Colour.CIE:cieLAB from colour-2.3.3, B

Percentage Accurate: 100.0% → 100.0%
Time: 1.5s
Alternatives: 5
Speedup: 1.0×

Specification

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

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

\\
\frac{x + 16}{116}
\end{array}

Alternative 1: 100.0% accurate, 1.0× speedup?

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

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

    \[\frac{x + 16}{116} \]
  2. Final simplification100.0%

    \[\leadsto \frac{x + 16}{116} \]

Alternative 2: 97.8% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -16 \lor \neg \left(x \leq 16\right):\\ \;\;\;\;\frac{-x}{-116}\\ \mathbf{else}:\\ \;\;\;\;0.13793103448275862\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (or (<= x -16.0) (not (<= x 16.0))) (/ (- x) -116.0) 0.13793103448275862))
double code(double x) {
	double tmp;
	if ((x <= -16.0) || !(x <= 16.0)) {
		tmp = -x / -116.0;
	} else {
		tmp = 0.13793103448275862;
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if ((x <= (-16.0d0)) .or. (.not. (x <= 16.0d0))) then
        tmp = -x / (-116.0d0)
    else
        tmp = 0.13793103448275862d0
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if ((x <= -16.0) || !(x <= 16.0)) {
		tmp = -x / -116.0;
	} else {
		tmp = 0.13793103448275862;
	}
	return tmp;
}
def code(x):
	tmp = 0
	if (x <= -16.0) or not (x <= 16.0):
		tmp = -x / -116.0
	else:
		tmp = 0.13793103448275862
	return tmp
function code(x)
	tmp = 0.0
	if ((x <= -16.0) || !(x <= 16.0))
		tmp = Float64(Float64(-x) / -116.0);
	else
		tmp = 0.13793103448275862;
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if ((x <= -16.0) || ~((x <= 16.0)))
		tmp = -x / -116.0;
	else
		tmp = 0.13793103448275862;
	end
	tmp_2 = tmp;
end
code[x_] := If[Or[LessEqual[x, -16.0], N[Not[LessEqual[x, 16.0]], $MachinePrecision]], N[((-x) / -116.0), $MachinePrecision], 0.13793103448275862]
\begin{array}{l}

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

\mathbf{else}:\\
\;\;\;\;0.13793103448275862\\


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

    1. Initial program 100.0%

      \[\frac{x + 16}{116} \]
    2. Taylor expanded in x around inf 96.8%

      \[\leadsto \color{blue}{0.008620689655172414 \cdot x} \]
    3. Step-by-step derivation
      1. *-commutative96.8%

        \[\leadsto \color{blue}{x \cdot 0.008620689655172414} \]
      2. metadata-eval96.8%

        \[\leadsto x \cdot \color{blue}{\left(--0.008620689655172414\right)} \]
      3. metadata-eval96.8%

        \[\leadsto x \cdot \left(-\color{blue}{\frac{1}{-116}}\right) \]
      4. distribute-rgt-neg-in96.8%

        \[\leadsto \color{blue}{-x \cdot \frac{1}{-116}} \]
      5. div-inv96.8%

        \[\leadsto -\color{blue}{\frac{x}{-116}} \]
      6. distribute-neg-frac96.8%

        \[\leadsto \color{blue}{\frac{-x}{-116}} \]
    4. Applied egg-rr96.8%

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

    if -16 < x < 16

    1. Initial program 100.0%

      \[\frac{x + 16}{116} \]
    2. Taylor expanded in x around 0 97.2%

      \[\leadsto \color{blue}{0.13793103448275862} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification97.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -16 \lor \neg \left(x \leq 16\right):\\ \;\;\;\;\frac{-x}{-116}\\ \mathbf{else}:\\ \;\;\;\;0.13793103448275862\\ \end{array} \]

Alternative 3: 97.7% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -16:\\ \;\;\;\;x \cdot 0.008620689655172414\\ \mathbf{elif}\;x \leq 16:\\ \;\;\;\;0.13793103448275862\\ \mathbf{else}:\\ \;\;\;\;x \cdot 0.008620689655172414\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x -16.0)
   (* x 0.008620689655172414)
   (if (<= x 16.0) 0.13793103448275862 (* x 0.008620689655172414))))
double code(double x) {
	double tmp;
	if (x <= -16.0) {
		tmp = x * 0.008620689655172414;
	} else if (x <= 16.0) {
		tmp = 0.13793103448275862;
	} else {
		tmp = x * 0.008620689655172414;
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= (-16.0d0)) then
        tmp = x * 0.008620689655172414d0
    else if (x <= 16.0d0) then
        tmp = 0.13793103448275862d0
    else
        tmp = x * 0.008620689655172414d0
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= -16.0) {
		tmp = x * 0.008620689655172414;
	} else if (x <= 16.0) {
		tmp = 0.13793103448275862;
	} else {
		tmp = x * 0.008620689655172414;
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= -16.0:
		tmp = x * 0.008620689655172414
	elif x <= 16.0:
		tmp = 0.13793103448275862
	else:
		tmp = x * 0.008620689655172414
	return tmp
function code(x)
	tmp = 0.0
	if (x <= -16.0)
		tmp = Float64(x * 0.008620689655172414);
	elseif (x <= 16.0)
		tmp = 0.13793103448275862;
	else
		tmp = Float64(x * 0.008620689655172414);
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= -16.0)
		tmp = x * 0.008620689655172414;
	elseif (x <= 16.0)
		tmp = 0.13793103448275862;
	else
		tmp = x * 0.008620689655172414;
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, -16.0], N[(x * 0.008620689655172414), $MachinePrecision], If[LessEqual[x, 16.0], 0.13793103448275862, N[(x * 0.008620689655172414), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -16:\\
\;\;\;\;x \cdot 0.008620689655172414\\

\mathbf{elif}\;x \leq 16:\\
\;\;\;\;0.13793103448275862\\

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


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

    1. Initial program 100.0%

      \[\frac{x + 16}{116} \]
    2. Taylor expanded in x around inf 96.8%

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

    if -16 < x < 16

    1. Initial program 100.0%

      \[\frac{x + 16}{116} \]
    2. Taylor expanded in x around 0 97.2%

      \[\leadsto \color{blue}{0.13793103448275862} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification97.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -16:\\ \;\;\;\;x \cdot 0.008620689655172414\\ \mathbf{elif}\;x \leq 16:\\ \;\;\;\;0.13793103448275862\\ \mathbf{else}:\\ \;\;\;\;x \cdot 0.008620689655172414\\ \end{array} \]

Alternative 4: 100.0% accurate, 1.0× speedup?

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

\\
0.13793103448275862 - \frac{x}{-116}
\end{array}
Derivation
  1. Initial program 100.0%

    \[\frac{x + 16}{116} \]
  2. Step-by-step derivation
    1. frac-2neg100.0%

      \[\leadsto \color{blue}{\frac{-\left(x + 16\right)}{-116}} \]
    2. distribute-frac-neg100.0%

      \[\leadsto \color{blue}{-\frac{x + 16}{-116}} \]
    3. metadata-eval100.0%

      \[\leadsto -\frac{x + 16}{\color{blue}{-116}} \]
  3. Applied egg-rr100.0%

    \[\leadsto \color{blue}{-\frac{x + 16}{-116}} \]
  4. Step-by-step derivation
    1. distribute-neg-frac100.0%

      \[\leadsto \color{blue}{\frac{-\left(x + 16\right)}{-116}} \]
    2. distribute-neg-in100.0%

      \[\leadsto \frac{\color{blue}{\left(-x\right) + \left(-16\right)}}{-116} \]
    3. metadata-eval100.0%

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

      \[\leadsto \frac{\color{blue}{-16 + \left(-x\right)}}{-116} \]
    5. unsub-neg100.0%

      \[\leadsto \frac{\color{blue}{-16 - x}}{-116} \]
    6. div-sub100.0%

      \[\leadsto \color{blue}{\frac{-16}{-116} - \frac{x}{-116}} \]
    7. metadata-eval100.0%

      \[\leadsto \color{blue}{0.13793103448275862} - \frac{x}{-116} \]
  5. Simplified100.0%

    \[\leadsto \color{blue}{0.13793103448275862 - \frac{x}{-116}} \]
  6. Final simplification100.0%

    \[\leadsto 0.13793103448275862 - \frac{x}{-116} \]

Alternative 5: 51.4% accurate, 5.0× speedup?

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

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

    \[\frac{x + 16}{116} \]
  2. Taylor expanded in x around 0 50.1%

    \[\leadsto \color{blue}{0.13793103448275862} \]
  3. Final simplification50.1%

    \[\leadsto 0.13793103448275862 \]

Reproduce

?
herbie shell --seed 2023196 
(FPCore (x)
  :name "Data.Colour.CIE:cieLAB from colour-2.3.3, B"
  :precision binary64
  (/ (+ x 16.0) 116.0))