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

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

Specification

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

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

\\
x - \frac{y}{200}
\end{array}

Alternative 1: 100.0% accurate, 1.0× speedup?

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

\\
x - \frac{y}{200}
\end{array}
Derivation
  1. Initial program 100.0%

    \[x - \frac{y}{200} \]
  2. Add Preprocessing
  3. Add Preprocessing

Alternative 2: 73.8% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.85 \cdot 10^{+96}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 2.2 \cdot 10^{-43}:\\ \;\;\;\;\frac{y}{-200}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= x -1.85e+96) x (if (<= x 2.2e-43) (/ y -200.0) x)))
double code(double x, double y) {
	double tmp;
	if (x <= -1.85e+96) {
		tmp = x;
	} else if (x <= 2.2e-43) {
		tmp = y / -200.0;
	} else {
		tmp = x;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (x <= (-1.85d+96)) then
        tmp = x
    else if (x <= 2.2d-43) then
        tmp = y / (-200.0d0)
    else
        tmp = x
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (x <= -1.85e+96) {
		tmp = x;
	} else if (x <= 2.2e-43) {
		tmp = y / -200.0;
	} else {
		tmp = x;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if x <= -1.85e+96:
		tmp = x
	elif x <= 2.2e-43:
		tmp = y / -200.0
	else:
		tmp = x
	return tmp
function code(x, y)
	tmp = 0.0
	if (x <= -1.85e+96)
		tmp = x;
	elseif (x <= 2.2e-43)
		tmp = Float64(y / -200.0);
	else
		tmp = x;
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (x <= -1.85e+96)
		tmp = x;
	elseif (x <= 2.2e-43)
		tmp = y / -200.0;
	else
		tmp = x;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[x, -1.85e+96], x, If[LessEqual[x, 2.2e-43], N[(y / -200.0), $MachinePrecision], x]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.85 \cdot 10^{+96}:\\
\;\;\;\;x\\

\mathbf{elif}\;x \leq 2.2 \cdot 10^{-43}:\\
\;\;\;\;\frac{y}{-200}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.84999999999999996e96 or 2.19999999999999997e-43 < x

    1. Initial program 100.0%

      \[x - \frac{y}{200} \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf

      \[\leadsto \color{blue}{x} \]
    4. Step-by-step derivation
      1. Simplified82.0%

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

      if -1.84999999999999996e96 < x < 2.19999999999999997e-43

      1. Initial program 100.0%

        \[x - \frac{y}{200} \]
      2. Add Preprocessing
      3. Taylor expanded in x around 0

        \[\leadsto \color{blue}{\frac{-1}{200} \cdot y} \]
      4. Step-by-step derivation
        1. *-lowering-*.f6477.6%

          \[\leadsto \mathsf{*.f64}\left(\frac{-1}{200}, \color{blue}{y}\right) \]
      5. Simplified77.6%

        \[\leadsto \color{blue}{-0.005 \cdot y} \]
      6. Step-by-step derivation
        1. metadata-evalN/A

          \[\leadsto \left(\mathsf{neg}\left(\frac{1}{200}\right)\right) \cdot y \]
        2. metadata-evalN/A

          \[\leadsto \left(\mathsf{neg}\left(\frac{1}{200}\right)\right) \cdot y \]
        3. distribute-lft-neg-inN/A

          \[\leadsto \mathsf{neg}\left(\frac{1}{200} \cdot y\right) \]
        4. associate-/r/N/A

          \[\leadsto \mathsf{neg}\left(\frac{1}{\frac{200}{y}}\right) \]
        5. clear-numN/A

          \[\leadsto \mathsf{neg}\left(\frac{y}{200}\right) \]
        6. distribute-neg-frac2N/A

          \[\leadsto \frac{y}{\color{blue}{\mathsf{neg}\left(200\right)}} \]
        7. /-lowering-/.f64N/A

          \[\leadsto \mathsf{/.f64}\left(y, \color{blue}{\left(\mathsf{neg}\left(200\right)\right)}\right) \]
        8. metadata-eval77.8%

          \[\leadsto \mathsf{/.f64}\left(y, -200\right) \]
      7. Applied egg-rr77.8%

        \[\leadsto \color{blue}{\frac{y}{-200}} \]
    5. Recombined 2 regimes into one program.
    6. Add Preprocessing

    Alternative 3: 73.9% accurate, 0.4× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.85 \cdot 10^{+96}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.35 \cdot 10^{-41}:\\ \;\;\;\;y \cdot -0.005\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
    (FPCore (x y)
     :precision binary64
     (if (<= x -1.85e+96) x (if (<= x 1.35e-41) (* y -0.005) x)))
    double code(double x, double y) {
    	double tmp;
    	if (x <= -1.85e+96) {
    		tmp = x;
    	} else if (x <= 1.35e-41) {
    		tmp = y * -0.005;
    	} else {
    		tmp = x;
    	}
    	return tmp;
    }
    
    real(8) function code(x, y)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        real(8) :: tmp
        if (x <= (-1.85d+96)) then
            tmp = x
        else if (x <= 1.35d-41) then
            tmp = y * (-0.005d0)
        else
            tmp = x
        end if
        code = tmp
    end function
    
    public static double code(double x, double y) {
    	double tmp;
    	if (x <= -1.85e+96) {
    		tmp = x;
    	} else if (x <= 1.35e-41) {
    		tmp = y * -0.005;
    	} else {
    		tmp = x;
    	}
    	return tmp;
    }
    
    def code(x, y):
    	tmp = 0
    	if x <= -1.85e+96:
    		tmp = x
    	elif x <= 1.35e-41:
    		tmp = y * -0.005
    	else:
    		tmp = x
    	return tmp
    
    function code(x, y)
    	tmp = 0.0
    	if (x <= -1.85e+96)
    		tmp = x;
    	elseif (x <= 1.35e-41)
    		tmp = Float64(y * -0.005);
    	else
    		tmp = x;
    	end
    	return tmp
    end
    
    function tmp_2 = code(x, y)
    	tmp = 0.0;
    	if (x <= -1.85e+96)
    		tmp = x;
    	elseif (x <= 1.35e-41)
    		tmp = y * -0.005;
    	else
    		tmp = x;
    	end
    	tmp_2 = tmp;
    end
    
    code[x_, y_] := If[LessEqual[x, -1.85e+96], x, If[LessEqual[x, 1.35e-41], N[(y * -0.005), $MachinePrecision], x]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;x \leq -1.85 \cdot 10^{+96}:\\
    \;\;\;\;x\\
    
    \mathbf{elif}\;x \leq 1.35 \cdot 10^{-41}:\\
    \;\;\;\;y \cdot -0.005\\
    
    \mathbf{else}:\\
    \;\;\;\;x\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if x < -1.84999999999999996e96 or 1.35e-41 < x

      1. Initial program 100.0%

        \[x - \frac{y}{200} \]
      2. Add Preprocessing
      3. Taylor expanded in x around inf

        \[\leadsto \color{blue}{x} \]
      4. Step-by-step derivation
        1. Simplified82.0%

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

        if -1.84999999999999996e96 < x < 1.35e-41

        1. Initial program 100.0%

          \[x - \frac{y}{200} \]
        2. Add Preprocessing
        3. Taylor expanded in x around 0

          \[\leadsto \color{blue}{\frac{-1}{200} \cdot y} \]
        4. Step-by-step derivation
          1. *-lowering-*.f6477.6%

            \[\leadsto \mathsf{*.f64}\left(\frac{-1}{200}, \color{blue}{y}\right) \]
        5. Simplified77.6%

          \[\leadsto \color{blue}{-0.005 \cdot y} \]
      5. Recombined 2 regimes into one program.
      6. Final simplification79.5%

        \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.85 \cdot 10^{+96}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.35 \cdot 10^{-41}:\\ \;\;\;\;y \cdot -0.005\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
      7. Add Preprocessing

      Alternative 4: 51.6% accurate, 5.0× speedup?

      \[\begin{array}{l} \\ x \end{array} \]
      (FPCore (x y) :precision binary64 x)
      double code(double x, double y) {
      	return x;
      }
      
      real(8) function code(x, y)
          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
      
      \begin{array}{l}
      
      \\
      x
      \end{array}
      
      Derivation
      1. Initial program 100.0%

        \[x - \frac{y}{200} \]
      2. Add Preprocessing
      3. Taylor expanded in x around inf

        \[\leadsto \color{blue}{x} \]
      4. Step-by-step derivation
        1. Simplified49.4%

          \[\leadsto \color{blue}{x} \]
        2. Add Preprocessing

        Reproduce

        ?
        herbie shell --seed 2024139 
        (FPCore (x y)
          :name "Data.Colour.CIE:cieLAB from colour-2.3.3, D"
          :precision binary64
          (- x (/ y 200.0)))