Data.Colour.SRGB:transferFunction from colour-2.3.3

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

Specification

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

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?

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

Alternative 1: 100.0% accurate, 1.1× speedup?

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

    \[\left(x + 1\right) \cdot y - x \]
  2. Step-by-step derivation
    1. Applied rewrites100.0%

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

    Alternative 2: 98.9% accurate, 0.6× speedup?

    \[\begin{array}{l} t_0 := x \cdot \left(y - 1\right)\\ \mathbf{if}\;x \leq -618.7610523406546:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq 246929.50132633775:\\ \;\;\;\;y - x\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \]
    (FPCore (x y)
      :precision binary64
      :pre TRUE
      (let* ((t_0 (* x (- y 1.0))))
      (if (<= x -618.7610523406546)
        t_0
        (if (<= x 246929.50132633775) (- y x) t_0))))
    double code(double x, double y) {
    	double t_0 = x * (y - 1.0);
    	double tmp;
    	if (x <= -618.7610523406546) {
    		tmp = t_0;
    	} else if (x <= 246929.50132633775) {
    		tmp = y - x;
    	} 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 = x * (y - 1.0d0)
        if (x <= (-618.7610523406546d0)) then
            tmp = t_0
        else if (x <= 246929.50132633775d0) then
            tmp = y - x
        else
            tmp = t_0
        end if
        code = tmp
    end function
    
    public static double code(double x, double y) {
    	double t_0 = x * (y - 1.0);
    	double tmp;
    	if (x <= -618.7610523406546) {
    		tmp = t_0;
    	} else if (x <= 246929.50132633775) {
    		tmp = y - x;
    	} else {
    		tmp = t_0;
    	}
    	return tmp;
    }
    
    def code(x, y):
    	t_0 = x * (y - 1.0)
    	tmp = 0
    	if x <= -618.7610523406546:
    		tmp = t_0
    	elif x <= 246929.50132633775:
    		tmp = y - x
    	else:
    		tmp = t_0
    	return tmp
    
    function code(x, y)
    	t_0 = Float64(x * Float64(y - 1.0))
    	tmp = 0.0
    	if (x <= -618.7610523406546)
    		tmp = t_0;
    	elseif (x <= 246929.50132633775)
    		tmp = Float64(y - x);
    	else
    		tmp = t_0;
    	end
    	return tmp
    end
    
    function tmp_2 = code(x, y)
    	t_0 = x * (y - 1.0);
    	tmp = 0.0;
    	if (x <= -618.7610523406546)
    		tmp = t_0;
    	elseif (x <= 246929.50132633775)
    		tmp = y - x;
    	else
    		tmp = t_0;
    	end
    	tmp_2 = tmp;
    end
    
    code[x_, y_] := Block[{t$95$0 = N[(x * N[(y - 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -618.7610523406546], t$95$0, If[LessEqual[x, 246929.50132633775], N[(y - x), $MachinePrecision], t$95$0]]]
    
    f(x, y):
    	x in [-inf, +inf],
    	y in [-inf, +inf]
    code: THEORY
    BEGIN
    f(x, y: real): real =
    	LET t_0 = (x * (y - (1))) IN
    		LET tmp_1 = IF (x <= (2469295013263377477414906024932861328125e-34)) THEN (y - x) ELSE t_0 ENDIF IN
    		LET tmp = IF (x <= (-6187610523406546008118311874568462371826171875e-43)) THEN t_0 ELSE tmp_1 ENDIF IN
    	tmp
    END code
    \begin{array}{l}
    t_0 := x \cdot \left(y - 1\right)\\
    \mathbf{if}\;x \leq -618.7610523406546:\\
    \;\;\;\;t\_0\\
    
    \mathbf{elif}\;x \leq 246929.50132633775:\\
    \;\;\;\;y - x\\
    
    \mathbf{else}:\\
    \;\;\;\;t\_0\\
    
    
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if x < -618.7610523406546 or 246929.50132633775 < x

      1. Initial program 100.0%

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

        \[\leadsto x \cdot \left(y - 1\right) \]
      3. Step-by-step derivation
        1. Applied rewrites63.5%

          \[\leadsto x \cdot \left(y - 1\right) \]

        if -618.7610523406546 < x < 246929.50132633775

        1. Initial program 100.0%

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

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

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

        Alternative 3: 74.8% accurate, 2.6× speedup?

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

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

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

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

          Alternative 4: 62.0% accurate, 1.0× speedup?

          \[\begin{array}{l} \mathbf{if}\;x \leq -3.712143610141413 \cdot 10^{-15}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \leq 2.394325450771144 \cdot 10^{-33}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;-x\\ \end{array} \]
          (FPCore (x y)
            :precision binary64
            :pre TRUE
            (if (<= x -3.712143610141413e-15)
            (- x)
            (if (<= x 2.394325450771144e-33) y (- x))))
          double code(double x, double y) {
          	double tmp;
          	if (x <= -3.712143610141413e-15) {
          		tmp = -x;
          	} else if (x <= 2.394325450771144e-33) {
          		tmp = y;
          	} else {
          		tmp = -x;
          	}
          	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 (x <= (-3.712143610141413d-15)) then
                  tmp = -x
              else if (x <= 2.394325450771144d-33) then
                  tmp = y
              else
                  tmp = -x
              end if
              code = tmp
          end function
          
          public static double code(double x, double y) {
          	double tmp;
          	if (x <= -3.712143610141413e-15) {
          		tmp = -x;
          	} else if (x <= 2.394325450771144e-33) {
          		tmp = y;
          	} else {
          		tmp = -x;
          	}
          	return tmp;
          }
          
          def code(x, y):
          	tmp = 0
          	if x <= -3.712143610141413e-15:
          		tmp = -x
          	elif x <= 2.394325450771144e-33:
          		tmp = y
          	else:
          		tmp = -x
          	return tmp
          
          function code(x, y)
          	tmp = 0.0
          	if (x <= -3.712143610141413e-15)
          		tmp = Float64(-x);
          	elseif (x <= 2.394325450771144e-33)
          		tmp = y;
          	else
          		tmp = Float64(-x);
          	end
          	return tmp
          end
          
          function tmp_2 = code(x, y)
          	tmp = 0.0;
          	if (x <= -3.712143610141413e-15)
          		tmp = -x;
          	elseif (x <= 2.394325450771144e-33)
          		tmp = y;
          	else
          		tmp = -x;
          	end
          	tmp_2 = tmp;
          end
          
          code[x_, y_] := If[LessEqual[x, -3.712143610141413e-15], (-x), If[LessEqual[x, 2.394325450771144e-33], y, (-x)]]
          
          f(x, y):
          	x in [-inf, +inf],
          	y in [-inf, +inf]
          code: THEORY
          BEGIN
          f(x, y: real): real =
          	LET tmp_1 = IF (x <= (23943254507711438993143429196243359042823939859644038686053973230752092945912903125516534019734393723410903476178646087646484375e-160)) THEN y ELSE (- x) ENDIF IN
          	LET tmp = IF (x <= (-37121436101414133244504551030812255985592254710347948076787361060269176959991455078125e-100)) THEN (- x) ELSE tmp_1 ENDIF IN
          	tmp
          END code
          \begin{array}{l}
          \mathbf{if}\;x \leq -3.712143610141413 \cdot 10^{-15}:\\
          \;\;\;\;-x\\
          
          \mathbf{elif}\;x \leq 2.394325450771144 \cdot 10^{-33}:\\
          \;\;\;\;y\\
          
          \mathbf{else}:\\
          \;\;\;\;-x\\
          
          
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if x < -3.7121436101414133e-15 or 2.3943254507711439e-33 < x

            1. Initial program 100.0%

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

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

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

                  \[\leadsto -x \]

                if -3.7121436101414133e-15 < x < 2.3943254507711439e-33

                1. Initial program 100.0%

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

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

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

                      \[\leadsto -x \]
                    2. Taylor expanded in undef-var around zero

                      \[\leadsto -0 \]
                    3. Step-by-step derivation
                      1. Applied rewrites2.6%

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

                        \[\leadsto y \]
                      3. Step-by-step derivation
                        1. Applied rewrites38.0%

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

                      Alternative 5: 38.0% accurate, 9.2× 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 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%

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

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

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

                            \[\leadsto -x \]
                          2. Taylor expanded in undef-var around zero

                            \[\leadsto -0 \]
                          3. Step-by-step derivation
                            1. Applied rewrites2.6%

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

                              \[\leadsto y \]
                            3. Step-by-step derivation
                              1. Applied rewrites38.0%

                                \[\leadsto y \]
                              2. Add Preprocessing

                              Reproduce

                              ?
                              herbie shell --seed 2026092 
                              (FPCore (x y)
                                :name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
                                :precision binary64
                                (- (* (+ x 1.0) y) x))