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

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

Specification

?
\[\frac{x + 16}{116} \]
(FPCore (x)
  :precision binary64
  :pre TRUE
  (/ (+ x 16.0) 116.0))
double code(double x) {
	return (x + 16.0) / 116.0;
}
real(8) function code(x)
use fmin_fmax_functions
    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]
f(x):
	x in [-inf, +inf]
code: THEORY
BEGIN
f(x: real): real =
	(x + (16)) / (116)
END code
\frac{x + 16}{116}

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?

\[\frac{x + 16}{116} \]
(FPCore (x)
  :precision binary64
  :pre TRUE
  (/ (+ x 16.0) 116.0))
double code(double x) {
	return (x + 16.0) / 116.0;
}
real(8) function code(x)
use fmin_fmax_functions
    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]
f(x):
	x in [-inf, +inf]
code: THEORY
BEGIN
f(x: real): real =
	(x + (16)) / (116)
END code
\frac{x + 16}{116}

Alternative 1: 99.9% accurate, 1.2× speedup?

\[\mathsf{fma}\left(0.008620689655172414, x, 0.13793103448275862\right) \]
(FPCore (x)
  :precision binary64
  :pre TRUE
  (fma 0.008620689655172414 x 0.13793103448275862))
double code(double x) {
	return fma(0.008620689655172414, x, 0.13793103448275862);
}
function code(x)
	return fma(0.008620689655172414, x, 0.13793103448275862)
end
code[x_] := N[(0.008620689655172414 * x + 0.13793103448275862), $MachinePrecision]
f(x):
	x in [-inf, +inf]
code: THEORY
BEGIN
f(x: real): real =
	((86206896551724136734673464843581314198672771453857421875e-58) * x) + (137931034482758618775477543749730102717876434326171875e-54)
END code
\mathsf{fma}\left(0.008620689655172414, x, 0.13793103448275862\right)
Derivation
  1. Initial program 100.0%

    \[\frac{x + 16}{116} \]
  2. Step-by-step derivation
    1. Applied rewrites99.9%

      \[\leadsto \mathsf{fma}\left(0.008620689655172414, x, 0.13793103448275862\right) \]
    2. Add Preprocessing

    Alternative 2: 98.1% accurate, 0.4× speedup?

    \[\begin{array}{l} \mathbf{if}\;x + 16 \leq -0.5:\\ \;\;\;\;\frac{x}{116}\\ \mathbf{elif}\;x + 16 \leq 20:\\ \;\;\;\;0.13793103448275862\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{116}\\ \end{array} \]
    (FPCore (x)
      :precision binary64
      :pre TRUE
      (if (<= (+ x 16.0) -0.5)
      (/ x 116.0)
      (if (<= (+ x 16.0) 20.0) 0.13793103448275862 (/ x 116.0))))
    double code(double x) {
    	double tmp;
    	if ((x + 16.0) <= -0.5) {
    		tmp = x / 116.0;
    	} else if ((x + 16.0) <= 20.0) {
    		tmp = 0.13793103448275862;
    	} else {
    		tmp = x / 116.0;
    	}
    	return tmp;
    }
    
    real(8) function code(x)
    use fmin_fmax_functions
        real(8), intent (in) :: x
        real(8) :: tmp
        if ((x + 16.0d0) <= (-0.5d0)) then
            tmp = x / 116.0d0
        else if ((x + 16.0d0) <= 20.0d0) then
            tmp = 0.13793103448275862d0
        else
            tmp = x / 116.0d0
        end if
        code = tmp
    end function
    
    public static double code(double x) {
    	double tmp;
    	if ((x + 16.0) <= -0.5) {
    		tmp = x / 116.0;
    	} else if ((x + 16.0) <= 20.0) {
    		tmp = 0.13793103448275862;
    	} else {
    		tmp = x / 116.0;
    	}
    	return tmp;
    }
    
    def code(x):
    	tmp = 0
    	if (x + 16.0) <= -0.5:
    		tmp = x / 116.0
    	elif (x + 16.0) <= 20.0:
    		tmp = 0.13793103448275862
    	else:
    		tmp = x / 116.0
    	return tmp
    
    function code(x)
    	tmp = 0.0
    	if (Float64(x + 16.0) <= -0.5)
    		tmp = Float64(x / 116.0);
    	elseif (Float64(x + 16.0) <= 20.0)
    		tmp = 0.13793103448275862;
    	else
    		tmp = Float64(x / 116.0);
    	end
    	return tmp
    end
    
    function tmp_2 = code(x)
    	tmp = 0.0;
    	if ((x + 16.0) <= -0.5)
    		tmp = x / 116.0;
    	elseif ((x + 16.0) <= 20.0)
    		tmp = 0.13793103448275862;
    	else
    		tmp = x / 116.0;
    	end
    	tmp_2 = tmp;
    end
    
    code[x_] := If[LessEqual[N[(x + 16.0), $MachinePrecision], -0.5], N[(x / 116.0), $MachinePrecision], If[LessEqual[N[(x + 16.0), $MachinePrecision], 20.0], 0.13793103448275862, N[(x / 116.0), $MachinePrecision]]]
    
    f(x):
    	x in [-inf, +inf]
    code: THEORY
    BEGIN
    f(x: real): real =
    	LET tmp_1 = IF ((x + (16)) <= (20)) THEN (137931034482758618775477543749730102717876434326171875e-54) ELSE (x / (116)) ENDIF IN
    	LET tmp = IF ((x + (16)) <= (-5e-1)) THEN (x / (116)) ELSE tmp_1 ENDIF IN
    	tmp
    END code
    \begin{array}{l}
    \mathbf{if}\;x + 16 \leq -0.5:\\
    \;\;\;\;\frac{x}{116}\\
    
    \mathbf{elif}\;x + 16 \leq 20:\\
    \;\;\;\;0.13793103448275862\\
    
    \mathbf{else}:\\
    \;\;\;\;\frac{x}{116}\\
    
    
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if (+.f64 x #s(literal 16 binary64)) < -0.5 or 20 < (+.f64 x #s(literal 16 binary64))

      1. Initial program 100.0%

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

        \[\leadsto \frac{1}{116} \cdot x \]
      3. Step-by-step derivation
        1. Applied rewrites50.4%

          \[\leadsto 0.008620689655172414 \cdot x \]
        2. Step-by-step derivation
          1. Applied rewrites50.4%

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

          if -0.5 < (+.f64 x #s(literal 16 binary64)) < 20

          1. Initial program 100.0%

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

            \[\leadsto \frac{4}{29} \]
          3. Step-by-step derivation
            1. Applied rewrites51.2%

              \[\leadsto 0.13793103448275862 \]
          4. Recombined 2 regimes into one program.
          5. Add Preprocessing

          Alternative 3: 98.0% accurate, 0.4× speedup?

          \[\begin{array}{l} \mathbf{if}\;x + 16 \leq -0.5:\\ \;\;\;\;0.008620689655172414 \cdot x\\ \mathbf{elif}\;x + 16 \leq 20:\\ \;\;\;\;0.13793103448275862\\ \mathbf{else}:\\ \;\;\;\;0.008620689655172414 \cdot x\\ \end{array} \]
          (FPCore (x)
            :precision binary64
            :pre TRUE
            (if (<= (+ x 16.0) -0.5)
            (* 0.008620689655172414 x)
            (if (<= (+ x 16.0) 20.0)
              0.13793103448275862
              (* 0.008620689655172414 x))))
          double code(double x) {
          	double tmp;
          	if ((x + 16.0) <= -0.5) {
          		tmp = 0.008620689655172414 * x;
          	} else if ((x + 16.0) <= 20.0) {
          		tmp = 0.13793103448275862;
          	} else {
          		tmp = 0.008620689655172414 * x;
          	}
          	return tmp;
          }
          
          real(8) function code(x)
          use fmin_fmax_functions
              real(8), intent (in) :: x
              real(8) :: tmp
              if ((x + 16.0d0) <= (-0.5d0)) then
                  tmp = 0.008620689655172414d0 * x
              else if ((x + 16.0d0) <= 20.0d0) then
                  tmp = 0.13793103448275862d0
              else
                  tmp = 0.008620689655172414d0 * x
              end if
              code = tmp
          end function
          
          public static double code(double x) {
          	double tmp;
          	if ((x + 16.0) <= -0.5) {
          		tmp = 0.008620689655172414 * x;
          	} else if ((x + 16.0) <= 20.0) {
          		tmp = 0.13793103448275862;
          	} else {
          		tmp = 0.008620689655172414 * x;
          	}
          	return tmp;
          }
          
          def code(x):
          	tmp = 0
          	if (x + 16.0) <= -0.5:
          		tmp = 0.008620689655172414 * x
          	elif (x + 16.0) <= 20.0:
          		tmp = 0.13793103448275862
          	else:
          		tmp = 0.008620689655172414 * x
          	return tmp
          
          function code(x)
          	tmp = 0.0
          	if (Float64(x + 16.0) <= -0.5)
          		tmp = Float64(0.008620689655172414 * x);
          	elseif (Float64(x + 16.0) <= 20.0)
          		tmp = 0.13793103448275862;
          	else
          		tmp = Float64(0.008620689655172414 * x);
          	end
          	return tmp
          end
          
          function tmp_2 = code(x)
          	tmp = 0.0;
          	if ((x + 16.0) <= -0.5)
          		tmp = 0.008620689655172414 * x;
          	elseif ((x + 16.0) <= 20.0)
          		tmp = 0.13793103448275862;
          	else
          		tmp = 0.008620689655172414 * x;
          	end
          	tmp_2 = tmp;
          end
          
          code[x_] := If[LessEqual[N[(x + 16.0), $MachinePrecision], -0.5], N[(0.008620689655172414 * x), $MachinePrecision], If[LessEqual[N[(x + 16.0), $MachinePrecision], 20.0], 0.13793103448275862, N[(0.008620689655172414 * x), $MachinePrecision]]]
          
          f(x):
          	x in [-inf, +inf]
          code: THEORY
          BEGIN
          f(x: real): real =
          	LET tmp_1 = IF ((x + (16)) <= (20)) THEN (137931034482758618775477543749730102717876434326171875e-54) ELSE ((86206896551724136734673464843581314198672771453857421875e-58) * x) ENDIF IN
          	LET tmp = IF ((x + (16)) <= (-5e-1)) THEN ((86206896551724136734673464843581314198672771453857421875e-58) * x) ELSE tmp_1 ENDIF IN
          	tmp
          END code
          \begin{array}{l}
          \mathbf{if}\;x + 16 \leq -0.5:\\
          \;\;\;\;0.008620689655172414 \cdot x\\
          
          \mathbf{elif}\;x + 16 \leq 20:\\
          \;\;\;\;0.13793103448275862\\
          
          \mathbf{else}:\\
          \;\;\;\;0.008620689655172414 \cdot x\\
          
          
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if (+.f64 x #s(literal 16 binary64)) < -0.5 or 20 < (+.f64 x #s(literal 16 binary64))

            1. Initial program 100.0%

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

              \[\leadsto \frac{1}{116} \cdot x \]
            3. Step-by-step derivation
              1. Applied rewrites50.4%

                \[\leadsto 0.008620689655172414 \cdot x \]

              if -0.5 < (+.f64 x #s(literal 16 binary64)) < 20

              1. Initial program 100.0%

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

                \[\leadsto \frac{4}{29} \]
              3. Step-by-step derivation
                1. Applied rewrites51.2%

                  \[\leadsto 0.13793103448275862 \]
              4. Recombined 2 regimes into one program.
              5. Add Preprocessing

              Alternative 4: 51.2% accurate, 7.4× speedup?

              \[0.13793103448275862 \]
              (FPCore (x)
                :precision binary64
                :pre TRUE
                0.13793103448275862)
              double code(double x) {
              	return 0.13793103448275862;
              }
              
              real(8) function code(x)
              use fmin_fmax_functions
                  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
              
              f(x):
              	x in [-inf, +inf]
              code: THEORY
              BEGIN
              f(x: real): real =
              	137931034482758618775477543749730102717876434326171875e-54
              END code
              0.13793103448275862
              
              Derivation
              1. Initial program 100.0%

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

                \[\leadsto \frac{4}{29} \]
              3. Step-by-step derivation
                1. Applied rewrites51.2%

                  \[\leadsto 0.13793103448275862 \]
                2. Add Preprocessing

                Reproduce

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