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

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

Specification

?
\[x + \frac{y}{500} \]
(FPCore (x y)
  :precision binary64
  :pre TRUE
  (+ x (/ y 500.0)))
double code(double x, double y) {
	return x + (y / 500.0);
}
real(8) function code(x, y)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = x + (y / 500.0d0)
end function
public static double code(double x, double y) {
	return x + (y / 500.0);
}
def code(x, y):
	return x + (y / 500.0)
function code(x, y)
	return Float64(x + Float64(y / 500.0))
end
function tmp = code(x, y)
	tmp = x + (y / 500.0);
end
code[x_, y_] := N[(x + N[(y / 500.0), $MachinePrecision]), $MachinePrecision]
f(x, y):
	x in [-inf, +inf],
	y in [-inf, +inf]
code: THEORY
BEGIN
f(x, y: real): real =
	x + (y / (500))
END code
x + \frac{y}{500}

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?

\[x + \frac{y}{500} \]
(FPCore (x y)
  :precision binary64
  :pre TRUE
  (+ x (/ y 500.0)))
double code(double x, double y) {
	return x + (y / 500.0);
}
real(8) function code(x, y)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = x + (y / 500.0d0)
end function
public static double code(double x, double y) {
	return x + (y / 500.0);
}
def code(x, y):
	return x + (y / 500.0)
function code(x, y)
	return Float64(x + Float64(y / 500.0))
end
function tmp = code(x, y)
	tmp = x + (y / 500.0);
end
code[x_, y_] := N[(x + N[(y / 500.0), $MachinePrecision]), $MachinePrecision]
f(x, y):
	x in [-inf, +inf],
	y in [-inf, +inf]
code: THEORY
BEGIN
f(x, y: real): real =
	x + (y / (500))
END code
x + \frac{y}{500}

Alternative 1: 99.9% accurate, 1.2× speedup?

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

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

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

    Alternative 2: 74.9% accurate, 0.4× speedup?

    \[\begin{array}{l} \mathbf{if}\;\frac{y}{500} \leq -5 \cdot 10^{+30}:\\ \;\;\;\;\frac{y}{500}\\ \mathbf{elif}\;\frac{y}{500} \leq 5 \cdot 10^{+37}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{500}\\ \end{array} \]
    (FPCore (x y)
      :precision binary64
      :pre TRUE
      (if (<= (/ y 500.0) -5e+30)
      (/ y 500.0)
      (if (<= (/ y 500.0) 5e+37) x (/ y 500.0))))
    double code(double x, double y) {
    	double tmp;
    	if ((y / 500.0) <= -5e+30) {
    		tmp = y / 500.0;
    	} else if ((y / 500.0) <= 5e+37) {
    		tmp = x;
    	} else {
    		tmp = y / 500.0;
    	}
    	return tmp;
    }
    
    real(8) function code(x, y)
    use fmin_fmax_functions
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        real(8) :: tmp
        if ((y / 500.0d0) <= (-5d+30)) then
            tmp = y / 500.0d0
        else if ((y / 500.0d0) <= 5d+37) then
            tmp = x
        else
            tmp = y / 500.0d0
        end if
        code = tmp
    end function
    
    public static double code(double x, double y) {
    	double tmp;
    	if ((y / 500.0) <= -5e+30) {
    		tmp = y / 500.0;
    	} else if ((y / 500.0) <= 5e+37) {
    		tmp = x;
    	} else {
    		tmp = y / 500.0;
    	}
    	return tmp;
    }
    
    def code(x, y):
    	tmp = 0
    	if (y / 500.0) <= -5e+30:
    		tmp = y / 500.0
    	elif (y / 500.0) <= 5e+37:
    		tmp = x
    	else:
    		tmp = y / 500.0
    	return tmp
    
    function code(x, y)
    	tmp = 0.0
    	if (Float64(y / 500.0) <= -5e+30)
    		tmp = Float64(y / 500.0);
    	elseif (Float64(y / 500.0) <= 5e+37)
    		tmp = x;
    	else
    		tmp = Float64(y / 500.0);
    	end
    	return tmp
    end
    
    function tmp_2 = code(x, y)
    	tmp = 0.0;
    	if ((y / 500.0) <= -5e+30)
    		tmp = y / 500.0;
    	elseif ((y / 500.0) <= 5e+37)
    		tmp = x;
    	else
    		tmp = y / 500.0;
    	end
    	tmp_2 = tmp;
    end
    
    code[x_, y_] := If[LessEqual[N[(y / 500.0), $MachinePrecision], -5e+30], N[(y / 500.0), $MachinePrecision], If[LessEqual[N[(y / 500.0), $MachinePrecision], 5e+37], x, N[(y / 500.0), $MachinePrecision]]]
    
    f(x, y):
    	x in [-inf, +inf],
    	y in [-inf, +inf]
    code: THEORY
    BEGIN
    f(x, y: real): real =
    	LET tmp_1 = IF ((y / (500)) <= (49999999999999998874404911728017014784)) THEN x ELSE (y / (500)) ENDIF IN
    	LET tmp = IF ((y / (500)) <= (-4999999999999999817948147482624)) THEN (y / (500)) ELSE tmp_1 ENDIF IN
    	tmp
    END code
    \begin{array}{l}
    \mathbf{if}\;\frac{y}{500} \leq -5 \cdot 10^{+30}:\\
    \;\;\;\;\frac{y}{500}\\
    
    \mathbf{elif}\;\frac{y}{500} \leq 5 \cdot 10^{+37}:\\
    \;\;\;\;x\\
    
    \mathbf{else}:\\
    \;\;\;\;\frac{y}{500}\\
    
    
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if (/.f64 y #s(literal 500 binary64)) < -4.9999999999999998e30 or 4.9999999999999999e37 < (/.f64 y #s(literal 500 binary64))

      1. Initial program 100.0%

        \[x + \frac{y}{500} \]
      2. Taylor expanded in x around 0

        \[\leadsto \frac{1}{500} \cdot y \]
      3. Step-by-step derivation
        1. Applied rewrites49.7%

          \[\leadsto 0.002 \cdot y \]
        2. Step-by-step derivation
          1. Applied rewrites49.8%

            \[\leadsto \frac{y}{500} \]

          if -4.9999999999999998e30 < (/.f64 y #s(literal 500 binary64)) < 4.9999999999999999e37

          1. Initial program 100.0%

            \[x + \frac{y}{500} \]
          2. Taylor expanded in x around 0

            \[\leadsto \frac{1}{500} \cdot y \]
          3. Step-by-step derivation
            1. Applied rewrites49.7%

              \[\leadsto 0.002 \cdot y \]
            2. Step-by-step derivation
              1. Applied rewrites49.8%

                \[\leadsto \frac{y}{500} \]
              2. Taylor expanded in x around inf

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

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

              Alternative 3: 74.9% accurate, 0.4× speedup?

              \[\begin{array}{l} \mathbf{if}\;\frac{y}{500} \leq -5 \cdot 10^{+30}:\\ \;\;\;\;0.002 \cdot y\\ \mathbf{elif}\;\frac{y}{500} \leq 5 \cdot 10^{+37}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;0.002 \cdot y\\ \end{array} \]
              (FPCore (x y)
                :precision binary64
                :pre TRUE
                (if (<= (/ y 500.0) -5e+30)
                (* 0.002 y)
                (if (<= (/ y 500.0) 5e+37) x (* 0.002 y))))
              double code(double x, double y) {
              	double tmp;
              	if ((y / 500.0) <= -5e+30) {
              		tmp = 0.002 * y;
              	} else if ((y / 500.0) <= 5e+37) {
              		tmp = x;
              	} else {
              		tmp = 0.002 * y;
              	}
              	return tmp;
              }
              
              real(8) function code(x, y)
              use fmin_fmax_functions
                  real(8), intent (in) :: x
                  real(8), intent (in) :: y
                  real(8) :: tmp
                  if ((y / 500.0d0) <= (-5d+30)) then
                      tmp = 0.002d0 * y
                  else if ((y / 500.0d0) <= 5d+37) then
                      tmp = x
                  else
                      tmp = 0.002d0 * y
                  end if
                  code = tmp
              end function
              
              public static double code(double x, double y) {
              	double tmp;
              	if ((y / 500.0) <= -5e+30) {
              		tmp = 0.002 * y;
              	} else if ((y / 500.0) <= 5e+37) {
              		tmp = x;
              	} else {
              		tmp = 0.002 * y;
              	}
              	return tmp;
              }
              
              def code(x, y):
              	tmp = 0
              	if (y / 500.0) <= -5e+30:
              		tmp = 0.002 * y
              	elif (y / 500.0) <= 5e+37:
              		tmp = x
              	else:
              		tmp = 0.002 * y
              	return tmp
              
              function code(x, y)
              	tmp = 0.0
              	if (Float64(y / 500.0) <= -5e+30)
              		tmp = Float64(0.002 * y);
              	elseif (Float64(y / 500.0) <= 5e+37)
              		tmp = x;
              	else
              		tmp = Float64(0.002 * y);
              	end
              	return tmp
              end
              
              function tmp_2 = code(x, y)
              	tmp = 0.0;
              	if ((y / 500.0) <= -5e+30)
              		tmp = 0.002 * y;
              	elseif ((y / 500.0) <= 5e+37)
              		tmp = x;
              	else
              		tmp = 0.002 * y;
              	end
              	tmp_2 = tmp;
              end
              
              code[x_, y_] := If[LessEqual[N[(y / 500.0), $MachinePrecision], -5e+30], N[(0.002 * y), $MachinePrecision], If[LessEqual[N[(y / 500.0), $MachinePrecision], 5e+37], x, N[(0.002 * y), $MachinePrecision]]]
              
              f(x, y):
              	x in [-inf, +inf],
              	y in [-inf, +inf]
              code: THEORY
              BEGIN
              f(x, y: real): real =
              	LET tmp_1 = IF ((y / (500)) <= (49999999999999998874404911728017014784)) THEN x ELSE ((200000000000000004163336342344337026588618755340576171875e-59) * y) ENDIF IN
              	LET tmp = IF ((y / (500)) <= (-4999999999999999817948147482624)) THEN ((200000000000000004163336342344337026588618755340576171875e-59) * y) ELSE tmp_1 ENDIF IN
              	tmp
              END code
              \begin{array}{l}
              \mathbf{if}\;\frac{y}{500} \leq -5 \cdot 10^{+30}:\\
              \;\;\;\;0.002 \cdot y\\
              
              \mathbf{elif}\;\frac{y}{500} \leq 5 \cdot 10^{+37}:\\
              \;\;\;\;x\\
              
              \mathbf{else}:\\
              \;\;\;\;0.002 \cdot y\\
              
              
              \end{array}
              
              Derivation
              1. Split input into 2 regimes
              2. if (/.f64 y #s(literal 500 binary64)) < -4.9999999999999998e30 or 4.9999999999999999e37 < (/.f64 y #s(literal 500 binary64))

                1. Initial program 100.0%

                  \[x + \frac{y}{500} \]
                2. Taylor expanded in x around 0

                  \[\leadsto \frac{1}{500} \cdot y \]
                3. Step-by-step derivation
                  1. Applied rewrites49.7%

                    \[\leadsto 0.002 \cdot y \]

                  if -4.9999999999999998e30 < (/.f64 y #s(literal 500 binary64)) < 4.9999999999999999e37

                  1. Initial program 100.0%

                    \[x + \frac{y}{500} \]
                  2. Taylor expanded in x around 0

                    \[\leadsto \frac{1}{500} \cdot y \]
                  3. Step-by-step derivation
                    1. Applied rewrites49.7%

                      \[\leadsto 0.002 \cdot y \]
                    2. Step-by-step derivation
                      1. Applied rewrites49.8%

                        \[\leadsto \frac{y}{500} \]
                      2. Taylor expanded in x around inf

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

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

                      Alternative 4: 51.7% accurate, 7.4× speedup?

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

                        \[x + \frac{y}{500} \]
                      2. Taylor expanded in x around 0

                        \[\leadsto \frac{1}{500} \cdot y \]
                      3. Step-by-step derivation
                        1. Applied rewrites49.7%

                          \[\leadsto 0.002 \cdot y \]
                        2. Step-by-step derivation
                          1. Applied rewrites49.8%

                            \[\leadsto \frac{y}{500} \]
                          2. Taylor expanded in x around inf

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

                              \[\leadsto x \]
                            2. Add Preprocessing

                            Reproduce

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