Data.Colour.CIE.Chromaticity:chromaCoords from colour-2.3.3

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

Specification

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

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

Alternative 1: 99.0% accurate, 0.3× speedup?

\[\begin{array}{l} t_0 := 1 - \mathsf{min}\left(x, y\right)\\ \mathbf{if}\;t\_0 - \mathsf{max}\left(x, y\right) \leq 0.9999999999999998:\\ \;\;\;\;1 - \mathsf{max}\left(x, y\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \]
(FPCore (x y)
  :precision binary64
  :pre TRUE
  (let* ((t_0 (- 1.0 (fmin x y))))
  (if (<= (- t_0 (fmax x y)) 0.9999999999999998)
    (- 1.0 (fmax x y))
    t_0)))
double code(double x, double y) {
	double t_0 = 1.0 - fmin(x, y);
	double tmp;
	if ((t_0 - fmax(x, y)) <= 0.9999999999999998) {
		tmp = 1.0 - fmax(x, y);
	} else {
		tmp = t_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) :: t_0
    real(8) :: tmp
    t_0 = 1.0d0 - fmin(x, y)
    if ((t_0 - fmax(x, y)) <= 0.9999999999999998d0) then
        tmp = 1.0d0 - fmax(x, y)
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double t_0 = 1.0 - fmin(x, y);
	double tmp;
	if ((t_0 - fmax(x, y)) <= 0.9999999999999998) {
		tmp = 1.0 - fmax(x, y);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y):
	t_0 = 1.0 - fmin(x, y)
	tmp = 0
	if (t_0 - fmax(x, y)) <= 0.9999999999999998:
		tmp = 1.0 - fmax(x, y)
	else:
		tmp = t_0
	return tmp
function code(x, y)
	t_0 = Float64(1.0 - fmin(x, y))
	tmp = 0.0
	if (Float64(t_0 - fmax(x, y)) <= 0.9999999999999998)
		tmp = Float64(1.0 - fmax(x, y));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = 1.0 - min(x, y);
	tmp = 0.0;
	if ((t_0 - max(x, y)) <= 0.9999999999999998)
		tmp = 1.0 - max(x, y);
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[(1.0 - N[Min[x, y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$0 - N[Max[x, y], $MachinePrecision]), $MachinePrecision], 0.9999999999999998], N[(1.0 - N[Max[x, y], $MachinePrecision]), $MachinePrecision], t$95$0]]
f(x, y):
	x in [-inf, +inf],
	y in [-inf, +inf]
code: THEORY
BEGIN
f(x, y: real): real =
	LET tmp = IF (x < y) THEN x ELSE y ENDIF IN
	LET t_0 = ((1) - tmp) IN
		LET tmp_3 = IF (x > y) THEN x ELSE y ENDIF IN
		LET tmp_4 = IF (x > y) THEN x ELSE y ENDIF IN
		LET tmp_2 = IF ((t_0 - tmp_3) <= (9999999999999997779553950749686919152736663818359375e-52)) THEN ((1) - tmp_4) ELSE t_0 ENDIF IN
	tmp_2
END code
\begin{array}{l}
t_0 := 1 - \mathsf{min}\left(x, y\right)\\
\mathbf{if}\;t\_0 - \mathsf{max}\left(x, y\right) \leq 0.9999999999999998:\\
\;\;\;\;1 - \mathsf{max}\left(x, y\right)\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (-.f64 #s(literal 1 binary64) x) y) < 0.99999999999999978

    1. Initial program 100.0%

      \[\left(1 - x\right) - y \]
    2. Taylor expanded in x around 0

      \[\leadsto 1 - y \]
    3. Step-by-step derivation
      1. Applied rewrites62.9%

        \[\leadsto 1 - y \]

      if 0.99999999999999978 < (-.f64 (-.f64 #s(literal 1 binary64) x) y)

      1. Initial program 100.0%

        \[\left(1 - x\right) - y \]
      2. Taylor expanded in y around 0

        \[\leadsto 1 - x \]
      3. Step-by-step derivation
        1. Applied rewrites62.8%

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

      Alternative 2: 61.8% accurate, 0.9× speedup?

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

        \[\left(1 - x\right) - y \]
      2. Taylor expanded in y around 0

        \[\leadsto 1 - x \]
      3. Step-by-step derivation
        1. Applied rewrites62.8%

          \[\leadsto 1 - x \]
        2. Add Preprocessing

        Alternative 3: 26.4% accurate, 6.2× speedup?

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

          \[\left(1 - x\right) - y \]
        2. Taylor expanded in y around 0

          \[\leadsto 1 - x \]
        3. Step-by-step derivation
          1. Applied rewrites62.8%

            \[\leadsto 1 - x \]
          2. Taylor expanded in x around 0

            \[\leadsto 1 \]
          3. Step-by-step derivation
            1. Applied rewrites26.4%

              \[\leadsto 1 \]
            2. Add Preprocessing

            Reproduce

            ?
            herbie shell --seed 2026092 
            (FPCore (x y)
              :name "Data.Colour.CIE.Chromaticity:chromaCoords from colour-2.3.3"
              :precision binary64
              (- (- 1.0 x) y))