Data.Colour.CIE:lightness from colour-2.3.3

Percentage Accurate: 100.0% → 100.0%
Time: 965.0ms
Alternatives: 3
Speedup: 1.1×

Specification

?
\[x \cdot 116 - 16 \]
(FPCore (x)
  :precision binary64
  :pre TRUE
  (- (* x 116.0) 16.0))
double code(double x) {
	return (x * 116.0) - 16.0;
}
real(8) function code(x)
use fmin_fmax_functions
    real(8), intent (in) :: x
    code = (x * 116.0d0) - 16.0d0
end function
public static double code(double x) {
	return (x * 116.0) - 16.0;
}
def code(x):
	return (x * 116.0) - 16.0
function code(x)
	return Float64(Float64(x * 116.0) - 16.0)
end
function tmp = code(x)
	tmp = (x * 116.0) - 16.0;
end
code[x_] := N[(N[(x * 116.0), $MachinePrecision] - 16.0), $MachinePrecision]
f(x):
	x in [-inf, +inf]
code: THEORY
BEGIN
f(x: real): real =
	(x * (116)) - (16)
END code
x \cdot 116 - 16

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

\[x \cdot 116 - 16 \]
(FPCore (x)
  :precision binary64
  :pre TRUE
  (- (* x 116.0) 16.0))
double code(double x) {
	return (x * 116.0) - 16.0;
}
real(8) function code(x)
use fmin_fmax_functions
    real(8), intent (in) :: x
    code = (x * 116.0d0) - 16.0d0
end function
public static double code(double x) {
	return (x * 116.0) - 16.0;
}
def code(x):
	return (x * 116.0) - 16.0
function code(x)
	return Float64(Float64(x * 116.0) - 16.0)
end
function tmp = code(x)
	tmp = (x * 116.0) - 16.0;
end
code[x_] := N[(N[(x * 116.0), $MachinePrecision] - 16.0), $MachinePrecision]
f(x):
	x in [-inf, +inf]
code: THEORY
BEGIN
f(x: real): real =
	(x * (116)) - (16)
END code
x \cdot 116 - 16

Alternative 1: 100.0% accurate, 1.1× speedup?

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

    \[x \cdot 116 - 16 \]
  2. Step-by-step derivation
    1. Applied rewrites100.0%

      \[\leadsto \mathsf{fma}\left(116, x, -16\right) \]
    2. Add Preprocessing

    Alternative 2: 97.5% accurate, 0.4× speedup?

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

      1. Initial program 100.0%

        \[x \cdot 116 - 16 \]
      2. Taylor expanded in x around 0

        \[\leadsto -16 \]
      3. Step-by-step derivation
        1. Applied rewrites50.8%

          \[\leadsto -16 \]
        2. Taylor expanded in x around inf

          \[\leadsto 116 \cdot x \]
        3. Step-by-step derivation
          1. Applied rewrites50.7%

            \[\leadsto 116 \cdot x \]

          if -1e3 < (*.f64 x #s(literal 116 binary64)) < 4.9999999999999999e-13

          1. Initial program 100.0%

            \[x \cdot 116 - 16 \]
          2. Taylor expanded in x around 0

            \[\leadsto -16 \]
          3. Step-by-step derivation
            1. Applied rewrites50.8%

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

          Alternative 3: 50.8% accurate, 6.6× speedup?

          \[-16 \]
          (FPCore (x)
            :precision binary64
            :pre TRUE
            -16.0)
          double code(double x) {
          	return -16.0;
          }
          
          real(8) function code(x)
          use fmin_fmax_functions
              real(8), intent (in) :: x
              code = -16.0d0
          end function
          
          public static double code(double x) {
          	return -16.0;
          }
          
          def code(x):
          	return -16.0
          
          function code(x)
          	return -16.0
          end
          
          function tmp = code(x)
          	tmp = -16.0;
          end
          
          code[x_] := -16.0
          
          f(x):
          	x in [-inf, +inf]
          code: THEORY
          BEGIN
          f(x: real): real =
          	-16
          END code
          -16
          
          Derivation
          1. Initial program 100.0%

            \[x \cdot 116 - 16 \]
          2. Taylor expanded in x around 0

            \[\leadsto -16 \]
          3. Step-by-step derivation
            1. Applied rewrites50.8%

              \[\leadsto -16 \]
            2. Add Preprocessing

            Reproduce

            ?
            herbie shell --seed 2026092 
            (FPCore (x)
              :name "Data.Colour.CIE:lightness from colour-2.3.3"
              :precision binary64
              (- (* x 116.0) 16.0))