Data.Colour.CIE:cieLABView from colour-2.3.3, A

Percentage Accurate: 99.9% → 99.9%
Time: 1.8s
Alternatives: 3
Speedup: 2.4×

Specification

?
\[\frac{841}{108} \cdot x + \frac{4}{29} \]
(FPCore (x)
  :precision binary64
  :pre TRUE
  (+ (* (/ 841.0 108.0) x) (/ 4.0 29.0)))
double code(double x) {
	return ((841.0 / 108.0) * x) + (4.0 / 29.0);
}
real(8) function code(x)
use fmin_fmax_functions
    real(8), intent (in) :: x
    code = ((841.0d0 / 108.0d0) * x) + (4.0d0 / 29.0d0)
end function
public static double code(double x) {
	return ((841.0 / 108.0) * x) + (4.0 / 29.0);
}
def code(x):
	return ((841.0 / 108.0) * x) + (4.0 / 29.0)
function code(x)
	return Float64(Float64(Float64(841.0 / 108.0) * x) + Float64(4.0 / 29.0))
end
function tmp = code(x)
	tmp = ((841.0 / 108.0) * x) + (4.0 / 29.0);
end
code[x_] := N[(N[(N[(841.0 / 108.0), $MachinePrecision] * x), $MachinePrecision] + N[(4.0 / 29.0), $MachinePrecision]), $MachinePrecision]
f(x):
	x in [-inf, +inf]
code: THEORY
BEGIN
f(x: real): real =
	(((841) / (108)) * x) + ((4) / (29))
END code
\frac{841}{108} \cdot x + \frac{4}{29}

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 3 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: 99.9% accurate, 1.0× speedup?

\[\frac{841}{108} \cdot x + \frac{4}{29} \]
(FPCore (x)
  :precision binary64
  :pre TRUE
  (+ (* (/ 841.0 108.0) x) (/ 4.0 29.0)))
double code(double x) {
	return ((841.0 / 108.0) * x) + (4.0 / 29.0);
}
real(8) function code(x)
use fmin_fmax_functions
    real(8), intent (in) :: x
    code = ((841.0d0 / 108.0d0) * x) + (4.0d0 / 29.0d0)
end function
public static double code(double x) {
	return ((841.0 / 108.0) * x) + (4.0 / 29.0);
}
def code(x):
	return ((841.0 / 108.0) * x) + (4.0 / 29.0)
function code(x)
	return Float64(Float64(Float64(841.0 / 108.0) * x) + Float64(4.0 / 29.0))
end
function tmp = code(x)
	tmp = ((841.0 / 108.0) * x) + (4.0 / 29.0);
end
code[x_] := N[(N[(N[(841.0 / 108.0), $MachinePrecision] * x), $MachinePrecision] + N[(4.0 / 29.0), $MachinePrecision]), $MachinePrecision]
f(x):
	x in [-inf, +inf]
code: THEORY
BEGIN
f(x: real): real =
	(((841) / (108)) * x) + ((4) / (29))
END code
\frac{841}{108} \cdot x + \frac{4}{29}

Alternative 1: 99.9% accurate, 2.4× speedup?

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

    \[\frac{841}{108} \cdot x + \frac{4}{29} \]
  2. Step-by-step derivation
    1. Applied rewrites99.9%

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

    Alternative 2: 97.5% accurate, 0.6× speedup?

    \[\begin{array}{l} t_0 := \frac{841}{108} \cdot x\\ \mathbf{if}\;t\_0 \leq -100:\\ \;\;\;\;x \cdot 7.787037037037037\\ \mathbf{elif}\;t\_0 \leq 2 \cdot 10^{-14}:\\ \;\;\;\;0.13793103448275862\\ \mathbf{else}:\\ \;\;\;\;x \cdot 7.787037037037037\\ \end{array} \]
    (FPCore (x)
      :precision binary64
      :pre TRUE
      (let* ((t_0 (* (/ 841.0 108.0) x)))
      (if (<= t_0 -100.0)
        (* x 7.787037037037037)
        (if (<= t_0 2e-14) 0.13793103448275862 (* x 7.787037037037037)))))
    double code(double x) {
    	double t_0 = (841.0 / 108.0) * x;
    	double tmp;
    	if (t_0 <= -100.0) {
    		tmp = x * 7.787037037037037;
    	} else if (t_0 <= 2e-14) {
    		tmp = 0.13793103448275862;
    	} else {
    		tmp = x * 7.787037037037037;
    	}
    	return tmp;
    }
    
    real(8) function code(x)
    use fmin_fmax_functions
        real(8), intent (in) :: x
        real(8) :: t_0
        real(8) :: tmp
        t_0 = (841.0d0 / 108.0d0) * x
        if (t_0 <= (-100.0d0)) then
            tmp = x * 7.787037037037037d0
        else if (t_0 <= 2d-14) then
            tmp = 0.13793103448275862d0
        else
            tmp = x * 7.787037037037037d0
        end if
        code = tmp
    end function
    
    public static double code(double x) {
    	double t_0 = (841.0 / 108.0) * x;
    	double tmp;
    	if (t_0 <= -100.0) {
    		tmp = x * 7.787037037037037;
    	} else if (t_0 <= 2e-14) {
    		tmp = 0.13793103448275862;
    	} else {
    		tmp = x * 7.787037037037037;
    	}
    	return tmp;
    }
    
    def code(x):
    	t_0 = (841.0 / 108.0) * x
    	tmp = 0
    	if t_0 <= -100.0:
    		tmp = x * 7.787037037037037
    	elif t_0 <= 2e-14:
    		tmp = 0.13793103448275862
    	else:
    		tmp = x * 7.787037037037037
    	return tmp
    
    function code(x)
    	t_0 = Float64(Float64(841.0 / 108.0) * x)
    	tmp = 0.0
    	if (t_0 <= -100.0)
    		tmp = Float64(x * 7.787037037037037);
    	elseif (t_0 <= 2e-14)
    		tmp = 0.13793103448275862;
    	else
    		tmp = Float64(x * 7.787037037037037);
    	end
    	return tmp
    end
    
    function tmp_2 = code(x)
    	t_0 = (841.0 / 108.0) * x;
    	tmp = 0.0;
    	if (t_0 <= -100.0)
    		tmp = x * 7.787037037037037;
    	elseif (t_0 <= 2e-14)
    		tmp = 0.13793103448275862;
    	else
    		tmp = x * 7.787037037037037;
    	end
    	tmp_2 = tmp;
    end
    
    code[x_] := Block[{t$95$0 = N[(N[(841.0 / 108.0), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[t$95$0, -100.0], N[(x * 7.787037037037037), $MachinePrecision], If[LessEqual[t$95$0, 2e-14], 0.13793103448275862, N[(x * 7.787037037037037), $MachinePrecision]]]]
    
    f(x):
    	x in [-inf, +inf]
    code: THEORY
    BEGIN
    f(x: real): real =
    	LET t_0 = (((841) / (108)) * x) IN
    		LET tmp_1 = IF (t_0 <= (1999999999999999997638618709119797394268658145832784356343836407177150249481201171875e-98)) THEN (137931034482758618775477543749730102717876434326171875e-54) ELSE (x * (778703703703703720151452216668985784053802490234375e-50)) ENDIF IN
    		LET tmp = IF (t_0 <= (-100)) THEN (x * (778703703703703720151452216668985784053802490234375e-50)) ELSE tmp_1 ENDIF IN
    	tmp
    END code
    \begin{array}{l}
    t_0 := \frac{841}{108} \cdot x\\
    \mathbf{if}\;t\_0 \leq -100:\\
    \;\;\;\;x \cdot 7.787037037037037\\
    
    \mathbf{elif}\;t\_0 \leq 2 \cdot 10^{-14}:\\
    \;\;\;\;0.13793103448275862\\
    
    \mathbf{else}:\\
    \;\;\;\;x \cdot 7.787037037037037\\
    
    
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if (*.f64 (/.f64 #s(literal 841 binary64) #s(literal 108 binary64)) x) < -100 or 2e-14 < (*.f64 (/.f64 #s(literal 841 binary64) #s(literal 108 binary64)) x)

      1. Initial program 99.9%

        \[\frac{841}{108} \cdot x + \frac{4}{29} \]
      2. Taylor expanded in x around inf

        \[\leadsto x \cdot \left(\frac{841}{108} + \frac{4}{29} \cdot \frac{1}{x}\right) \]
      3. Step-by-step derivation
        1. Applied rewrites99.8%

          \[\leadsto x \cdot \left(7.787037037037037 + 0.13793103448275862 \cdot \frac{1}{x}\right) \]
        2. Taylor expanded in x around inf

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

            \[\leadsto x \cdot 7.787037037037037 \]

          if -100 < (*.f64 (/.f64 #s(literal 841 binary64) #s(literal 108 binary64)) x) < 2e-14

          1. Initial program 99.9%

            \[\frac{841}{108} \cdot x + \frac{4}{29} \]
          2. Taylor expanded in x around 0

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

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

          Alternative 3: 50.8% accurate, 14.2× 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 99.9%

            \[\frac{841}{108} \cdot x + \frac{4}{29} \]
          2. Taylor expanded in x around 0

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

              \[\leadsto 0.13793103448275862 \]
            2. Add Preprocessing

            Reproduce

            ?
            herbie shell --seed 2026092 
            (FPCore (x)
              :name "Data.Colour.CIE:cieLABView from colour-2.3.3, A"
              :precision binary64
              (+ (* (/ 841.0 108.0) x) (/ 4.0 29.0)))