Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, C

Percentage Accurate: 100.0% → 100.0%
Time: 1.3s
Alternatives: 3
Speedup: 1.1×

Specification

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

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 2 - y \]
(FPCore (x y)
  :precision binary64
  :pre TRUE
  (- (* x 2.0) y))
double code(double x, double y) {
	return (x * 2.0) - y;
}
real(8) function code(x, y)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = (x * 2.0d0) - y
end function
public static double code(double x, double y) {
	return (x * 2.0) - y;
}
def code(x, y):
	return (x * 2.0) - y
function code(x, y)
	return Float64(Float64(x * 2.0) - y)
end
function tmp = code(x, y)
	tmp = (x * 2.0) - y;
end
code[x_, y_] := N[(N[(x * 2.0), $MachinePrecision] - y), $MachinePrecision]
f(x, y):
	x in [-inf, +inf],
	y in [-inf, +inf]
code: THEORY
BEGIN
f(x, y: real): real =
	(x * (2)) - y
END code
x \cdot 2 - y

Alternative 1: 100.0% accurate, 1.1× speedup?

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

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

      \[\leadsto \left(x + x\right) - y \]
    2. Add Preprocessing

    Alternative 2: 74.7% accurate, 0.6× speedup?

    \[\begin{array}{l} \mathbf{if}\;y \leq -4.155509726251822 \cdot 10^{+46}:\\ \;\;\;\;-y\\ \mathbf{elif}\;y \leq 2.426229654520916 \cdot 10^{+48}:\\ \;\;\;\;x + x\\ \mathbf{else}:\\ \;\;\;\;-y\\ \end{array} \]
    (FPCore (x y)
      :precision binary64
      :pre TRUE
      (if (<= y -4.155509726251822e+46)
      (- y)
      (if (<= y 2.426229654520916e+48) (+ x x) (- y))))
    double code(double x, double y) {
    	double tmp;
    	if (y <= -4.155509726251822e+46) {
    		tmp = -y;
    	} else if (y <= 2.426229654520916e+48) {
    		tmp = x + x;
    	} else {
    		tmp = -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 <= (-4.155509726251822d+46)) then
            tmp = -y
        else if (y <= 2.426229654520916d+48) then
            tmp = x + x
        else
            tmp = -y
        end if
        code = tmp
    end function
    
    public static double code(double x, double y) {
    	double tmp;
    	if (y <= -4.155509726251822e+46) {
    		tmp = -y;
    	} else if (y <= 2.426229654520916e+48) {
    		tmp = x + x;
    	} else {
    		tmp = -y;
    	}
    	return tmp;
    }
    
    def code(x, y):
    	tmp = 0
    	if y <= -4.155509726251822e+46:
    		tmp = -y
    	elif y <= 2.426229654520916e+48:
    		tmp = x + x
    	else:
    		tmp = -y
    	return tmp
    
    function code(x, y)
    	tmp = 0.0
    	if (y <= -4.155509726251822e+46)
    		tmp = Float64(-y);
    	elseif (y <= 2.426229654520916e+48)
    		tmp = Float64(x + x);
    	else
    		tmp = Float64(-y);
    	end
    	return tmp
    end
    
    function tmp_2 = code(x, y)
    	tmp = 0.0;
    	if (y <= -4.155509726251822e+46)
    		tmp = -y;
    	elseif (y <= 2.426229654520916e+48)
    		tmp = x + x;
    	else
    		tmp = -y;
    	end
    	tmp_2 = tmp;
    end
    
    code[x_, y_] := If[LessEqual[y, -4.155509726251822e+46], (-y), If[LessEqual[y, 2.426229654520916e+48], N[(x + x), $MachinePrecision], (-y)]]
    
    f(x, y):
    	x in [-inf, +inf],
    	y in [-inf, +inf]
    code: THEORY
    BEGIN
    f(x, y: real): real =
    	LET tmp_1 = IF (y <= (2426229654520915891643607200729785382101422440448)) THEN (x + x) ELSE (- y) ENDIF IN
    	LET tmp = IF (y <= (-41555097262518219140230899091581622926874509312)) THEN (- y) ELSE tmp_1 ENDIF IN
    	tmp
    END code
    \begin{array}{l}
    \mathbf{if}\;y \leq -4.155509726251822 \cdot 10^{+46}:\\
    \;\;\;\;-y\\
    
    \mathbf{elif}\;y \leq 2.426229654520916 \cdot 10^{+48}:\\
    \;\;\;\;x + x\\
    
    \mathbf{else}:\\
    \;\;\;\;-y\\
    
    
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if y < -4.1555097262518219e46 or 2.4262296545209159e48 < y

      1. Initial program 100.0%

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

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

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

            \[\leadsto -y \]

          if -4.1555097262518219e46 < y < 2.4262296545209159e48

          1. Initial program 100.0%

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

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

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

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

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

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

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

                Alternative 3: 50.1% accurate, 3.3× speedup?

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

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

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

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

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

                    Reproduce

                    ?
                    herbie shell --seed 2026092 
                    (FPCore (x y)
                      :name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, C"
                      :precision binary64
                      (- (* x 2.0) y))