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

Percentage Accurate: 100.0% → 100.0%
Time: 3.8s
Alternatives: 8
Speedup: 1.2×

Specification

?
\[\begin{array}{l} \\ \left(x + y\right) - x \cdot y \end{array} \]
(FPCore (x y) :precision binary64 (- (+ x y) (* x y)))
double code(double x, double y) {
	return (x + y) - (x * y);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = (x + y) - (x * y)
end function
public static double code(double x, double y) {
	return (x + y) - (x * y);
}
def code(x, y):
	return (x + y) - (x * y)
function code(x, y)
	return Float64(Float64(x + y) - Float64(x * y))
end
function tmp = code(x, y)
	tmp = (x + y) - (x * y);
end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(x + y\right) - x \cdot y
\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 8 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} \\ \left(x + y\right) - x \cdot y \end{array} \]
(FPCore (x y) :precision binary64 (- (+ x y) (* x y)))
double code(double x, double y) {
	return (x + y) - (x * y);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = (x + y) - (x * y)
end function
public static double code(double x, double y) {
	return (x + y) - (x * y);
}
def code(x, y):
	return (x + y) - (x * y)
function code(x, y)
	return Float64(Float64(x + y) - Float64(x * y))
end
function tmp = code(x, y)
	tmp = (x + y) - (x * y);
end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(x + y\right) - x \cdot y
\end{array}

Alternative 1: 100.0% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(1 - x, y, x\right) \end{array} \]
(FPCore (x y) :precision binary64 (fma (- 1.0 x) y x))
double code(double x, double y) {
	return fma((1.0 - x), y, x);
}
function code(x, y)
	return fma(Float64(1.0 - x), y, x)
end
code[x_, y_] := N[(N[(1.0 - x), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(1 - x, y, x\right)
\end{array}
Derivation
  1. Initial program 100.0%

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

    \[\leadsto \color{blue}{y + x \cdot \left(1 - y\right)} \]
  4. Applied rewrites100.0%

    \[\leadsto \color{blue}{\mathsf{fma}\left(1 - x, y, x\right)} \]
  5. Add Preprocessing

Alternative 2: 86.6% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(x + y\right) - x \cdot y\\ \mathbf{if}\;t\_0 \leq -\infty \lor \neg \left(t\_0 \leq 10^{+302}\right):\\ \;\;\;\;\left(-y\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1, y, x\right)\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (- (+ x y) (* x y))))
   (if (or (<= t_0 (- INFINITY)) (not (<= t_0 1e+302)))
     (* (- y) x)
     (fma 1.0 y x))))
double code(double x, double y) {
	double t_0 = (x + y) - (x * y);
	double tmp;
	if ((t_0 <= -((double) INFINITY)) || !(t_0 <= 1e+302)) {
		tmp = -y * x;
	} else {
		tmp = fma(1.0, y, x);
	}
	return tmp;
}
function code(x, y)
	t_0 = Float64(Float64(x + y) - Float64(x * y))
	tmp = 0.0
	if ((t_0 <= Float64(-Inf)) || !(t_0 <= 1e+302))
		tmp = Float64(Float64(-y) * x);
	else
		tmp = fma(1.0, y, x);
	end
	return tmp
end
code[x_, y_] := Block[{t$95$0 = N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, (-Infinity)], N[Not[LessEqual[t$95$0, 1e+302]], $MachinePrecision]], N[((-y) * x), $MachinePrecision], N[(1.0 * y + x), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(x + y\right) - x \cdot y\\
\mathbf{if}\;t\_0 \leq -\infty \lor \neg \left(t\_0 \leq 10^{+302}\right):\\
\;\;\;\;\left(-y\right) \cdot x\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(1, y, x\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (+.f64 x y) (*.f64 x y)) < -inf.0 or 1.0000000000000001e302 < (-.f64 (+.f64 x y) (*.f64 x y))

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{x \cdot \left(1 - y\right)} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{\left(1 - y\right) \cdot x} \]
      2. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(1 - y\right) \cdot x} \]
      3. lower--.f64100.0

        \[\leadsto \color{blue}{\left(1 - y\right)} \cdot x \]
    5. Applied rewrites100.0%

      \[\leadsto \color{blue}{\left(1 - y\right) \cdot x} \]
    6. Taylor expanded in y around inf

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

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

      if -inf.0 < (-.f64 (+.f64 x y) (*.f64 x y)) < 1.0000000000000001e302

      1. Initial program 100.0%

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

        \[\leadsto \color{blue}{y + x \cdot \left(1 - y\right)} \]
      4. Applied rewrites100.0%

        \[\leadsto \color{blue}{\mathsf{fma}\left(1 - x, y, x\right)} \]
      5. Taylor expanded in x around 0

        \[\leadsto \mathsf{fma}\left(1, y, x\right) \]
      6. Step-by-step derivation
        1. Applied rewrites83.5%

          \[\leadsto \mathsf{fma}\left(1, y, x\right) \]
      7. Recombined 2 regimes into one program.
      8. Final simplification85.3%

        \[\leadsto \begin{array}{l} \mathbf{if}\;\left(x + y\right) - x \cdot y \leq -\infty \lor \neg \left(\left(x + y\right) - x \cdot y \leq 10^{+302}\right):\\ \;\;\;\;\left(-y\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1, y, x\right)\\ \end{array} \]
      9. Add Preprocessing

      Alternative 3: 61.9% accurate, 0.5× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left(x + y\right) - x \cdot y \leq -5 \cdot 10^{-205}:\\ \;\;\;\;\mathsf{fma}\left(-x, y, x\right)\\ \mathbf{else}:\\ \;\;\;\;y - y \cdot x\\ \end{array} \end{array} \]
      (FPCore (x y)
       :precision binary64
       (if (<= (- (+ x y) (* x y)) -5e-205) (fma (- x) y x) (- y (* y x))))
      double code(double x, double y) {
      	double tmp;
      	if (((x + y) - (x * y)) <= -5e-205) {
      		tmp = fma(-x, y, x);
      	} else {
      		tmp = y - (y * x);
      	}
      	return tmp;
      }
      
      function code(x, y)
      	tmp = 0.0
      	if (Float64(Float64(x + y) - Float64(x * y)) <= -5e-205)
      		tmp = fma(Float64(-x), y, x);
      	else
      		tmp = Float64(y - Float64(y * x));
      	end
      	return tmp
      end
      
      code[x_, y_] := If[LessEqual[N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision], -5e-205], N[((-x) * y + x), $MachinePrecision], N[(y - N[(y * x), $MachinePrecision]), $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;\left(x + y\right) - x \cdot y \leq -5 \cdot 10^{-205}:\\
      \;\;\;\;\mathsf{fma}\left(-x, y, x\right)\\
      
      \mathbf{else}:\\
      \;\;\;\;y - y \cdot x\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if (-.f64 (+.f64 x y) (*.f64 x y)) < -5.00000000000000001e-205

        1. Initial program 100.0%

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

          \[\leadsto \color{blue}{y + x \cdot \left(1 - y\right)} \]
        4. Applied rewrites100.0%

          \[\leadsto \color{blue}{\mathsf{fma}\left(1 - x, y, x\right)} \]
        5. Taylor expanded in x around inf

          \[\leadsto \mathsf{fma}\left(-1 \cdot x, y, x\right) \]
        6. Step-by-step derivation
          1. Applied rewrites60.0%

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

          if -5.00000000000000001e-205 < (-.f64 (+.f64 x y) (*.f64 x y))

          1. Initial program 100.0%

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

            \[\leadsto \color{blue}{y \cdot \left(1 - x\right)} \]
          4. Step-by-step derivation
            1. *-commutativeN/A

              \[\leadsto \color{blue}{\left(1 - x\right) \cdot y} \]
            2. lower-*.f64N/A

              \[\leadsto \color{blue}{\left(1 - x\right) \cdot y} \]
            3. lower--.f6456.8

              \[\leadsto \color{blue}{\left(1 - x\right)} \cdot y \]
          5. Applied rewrites56.8%

            \[\leadsto \color{blue}{\left(1 - x\right) \cdot y} \]
          6. Step-by-step derivation
            1. Applied rewrites56.8%

              \[\leadsto y - \color{blue}{y \cdot x} \]
          7. Recombined 2 regimes into one program.
          8. Add Preprocessing

          Alternative 4: 61.9% accurate, 0.5× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left(x + y\right) - x \cdot y \leq -5 \cdot 10^{-205}:\\ \;\;\;\;\left(1 - y\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;y - y \cdot x\\ \end{array} \end{array} \]
          (FPCore (x y)
           :precision binary64
           (if (<= (- (+ x y) (* x y)) -5e-205) (* (- 1.0 y) x) (- y (* y x))))
          double code(double x, double y) {
          	double tmp;
          	if (((x + y) - (x * y)) <= -5e-205) {
          		tmp = (1.0 - y) * x;
          	} else {
          		tmp = y - (y * x);
          	}
          	return tmp;
          }
          
          module fmin_fmax_functions
              implicit none
              private
              public fmax
              public fmin
          
              interface fmax
                  module procedure fmax88
                  module procedure fmax44
                  module procedure fmax84
                  module procedure fmax48
              end interface
              interface fmin
                  module procedure fmin88
                  module procedure fmin44
                  module procedure fmin84
                  module procedure fmin48
              end interface
          contains
              real(8) function fmax88(x, y) result (res)
                  real(8), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
              end function
              real(4) function fmax44(x, y) result (res)
                  real(4), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
              end function
              real(8) function fmax84(x, y) result(res)
                  real(8), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
              end function
              real(8) function fmax48(x, y) result(res)
                  real(4), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
              end function
              real(8) function fmin88(x, y) result (res)
                  real(8), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
              end function
              real(4) function fmin44(x, y) result (res)
                  real(4), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
              end function
              real(8) function fmin84(x, y) result(res)
                  real(8), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
              end function
              real(8) function fmin48(x, y) result(res)
                  real(4), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
              end function
          end module
          
          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 + y) - (x * y)) <= (-5d-205)) then
                  tmp = (1.0d0 - y) * x
              else
                  tmp = y - (y * x)
              end if
              code = tmp
          end function
          
          public static double code(double x, double y) {
          	double tmp;
          	if (((x + y) - (x * y)) <= -5e-205) {
          		tmp = (1.0 - y) * x;
          	} else {
          		tmp = y - (y * x);
          	}
          	return tmp;
          }
          
          def code(x, y):
          	tmp = 0
          	if ((x + y) - (x * y)) <= -5e-205:
          		tmp = (1.0 - y) * x
          	else:
          		tmp = y - (y * x)
          	return tmp
          
          function code(x, y)
          	tmp = 0.0
          	if (Float64(Float64(x + y) - Float64(x * y)) <= -5e-205)
          		tmp = Float64(Float64(1.0 - y) * x);
          	else
          		tmp = Float64(y - Float64(y * x));
          	end
          	return tmp
          end
          
          function tmp_2 = code(x, y)
          	tmp = 0.0;
          	if (((x + y) - (x * y)) <= -5e-205)
          		tmp = (1.0 - y) * x;
          	else
          		tmp = y - (y * x);
          	end
          	tmp_2 = tmp;
          end
          
          code[x_, y_] := If[LessEqual[N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision], -5e-205], N[(N[(1.0 - y), $MachinePrecision] * x), $MachinePrecision], N[(y - N[(y * x), $MachinePrecision]), $MachinePrecision]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;\left(x + y\right) - x \cdot y \leq -5 \cdot 10^{-205}:\\
          \;\;\;\;\left(1 - y\right) \cdot x\\
          
          \mathbf{else}:\\
          \;\;\;\;y - y \cdot x\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if (-.f64 (+.f64 x y) (*.f64 x y)) < -5.00000000000000001e-205

            1. Initial program 100.0%

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

              \[\leadsto \color{blue}{x \cdot \left(1 - y\right)} \]
            4. Step-by-step derivation
              1. *-commutativeN/A

                \[\leadsto \color{blue}{\left(1 - y\right) \cdot x} \]
              2. lower-*.f64N/A

                \[\leadsto \color{blue}{\left(1 - y\right) \cdot x} \]
              3. lower--.f6460.0

                \[\leadsto \color{blue}{\left(1 - y\right)} \cdot x \]
            5. Applied rewrites60.0%

              \[\leadsto \color{blue}{\left(1 - y\right) \cdot x} \]

            if -5.00000000000000001e-205 < (-.f64 (+.f64 x y) (*.f64 x y))

            1. Initial program 100.0%

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

              \[\leadsto \color{blue}{y \cdot \left(1 - x\right)} \]
            4. Step-by-step derivation
              1. *-commutativeN/A

                \[\leadsto \color{blue}{\left(1 - x\right) \cdot y} \]
              2. lower-*.f64N/A

                \[\leadsto \color{blue}{\left(1 - x\right) \cdot y} \]
              3. lower--.f6456.8

                \[\leadsto \color{blue}{\left(1 - x\right)} \cdot y \]
            5. Applied rewrites56.8%

              \[\leadsto \color{blue}{\left(1 - x\right) \cdot y} \]
            6. Step-by-step derivation
              1. Applied rewrites56.8%

                \[\leadsto y - \color{blue}{y \cdot x} \]
            7. Recombined 2 regimes into one program.
            8. Add Preprocessing

            Alternative 5: 61.9% accurate, 0.5× speedup?

            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left(x + y\right) - x \cdot y \leq -5 \cdot 10^{-205}:\\ \;\;\;\;\left(1 - y\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\left(1 - x\right) \cdot y\\ \end{array} \end{array} \]
            (FPCore (x y)
             :precision binary64
             (if (<= (- (+ x y) (* x y)) -5e-205) (* (- 1.0 y) x) (* (- 1.0 x) y)))
            double code(double x, double y) {
            	double tmp;
            	if (((x + y) - (x * y)) <= -5e-205) {
            		tmp = (1.0 - y) * x;
            	} else {
            		tmp = (1.0 - x) * y;
            	}
            	return tmp;
            }
            
            module fmin_fmax_functions
                implicit none
                private
                public fmax
                public fmin
            
                interface fmax
                    module procedure fmax88
                    module procedure fmax44
                    module procedure fmax84
                    module procedure fmax48
                end interface
                interface fmin
                    module procedure fmin88
                    module procedure fmin44
                    module procedure fmin84
                    module procedure fmin48
                end interface
            contains
                real(8) function fmax88(x, y) result (res)
                    real(8), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                end function
                real(4) function fmax44(x, y) result (res)
                    real(4), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                end function
                real(8) function fmax84(x, y) result(res)
                    real(8), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                end function
                real(8) function fmax48(x, y) result(res)
                    real(4), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                end function
                real(8) function fmin88(x, y) result (res)
                    real(8), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                end function
                real(4) function fmin44(x, y) result (res)
                    real(4), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                end function
                real(8) function fmin84(x, y) result(res)
                    real(8), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                end function
                real(8) function fmin48(x, y) result(res)
                    real(4), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                end function
            end module
            
            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 + y) - (x * y)) <= (-5d-205)) then
                    tmp = (1.0d0 - y) * x
                else
                    tmp = (1.0d0 - x) * y
                end if
                code = tmp
            end function
            
            public static double code(double x, double y) {
            	double tmp;
            	if (((x + y) - (x * y)) <= -5e-205) {
            		tmp = (1.0 - y) * x;
            	} else {
            		tmp = (1.0 - x) * y;
            	}
            	return tmp;
            }
            
            def code(x, y):
            	tmp = 0
            	if ((x + y) - (x * y)) <= -5e-205:
            		tmp = (1.0 - y) * x
            	else:
            		tmp = (1.0 - x) * y
            	return tmp
            
            function code(x, y)
            	tmp = 0.0
            	if (Float64(Float64(x + y) - Float64(x * y)) <= -5e-205)
            		tmp = Float64(Float64(1.0 - y) * x);
            	else
            		tmp = Float64(Float64(1.0 - x) * y);
            	end
            	return tmp
            end
            
            function tmp_2 = code(x, y)
            	tmp = 0.0;
            	if (((x + y) - (x * y)) <= -5e-205)
            		tmp = (1.0 - y) * x;
            	else
            		tmp = (1.0 - x) * y;
            	end
            	tmp_2 = tmp;
            end
            
            code[x_, y_] := If[LessEqual[N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision], -5e-205], N[(N[(1.0 - y), $MachinePrecision] * x), $MachinePrecision], N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision]]
            
            \begin{array}{l}
            
            \\
            \begin{array}{l}
            \mathbf{if}\;\left(x + y\right) - x \cdot y \leq -5 \cdot 10^{-205}:\\
            \;\;\;\;\left(1 - y\right) \cdot x\\
            
            \mathbf{else}:\\
            \;\;\;\;\left(1 - x\right) \cdot y\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 2 regimes
            2. if (-.f64 (+.f64 x y) (*.f64 x y)) < -5.00000000000000001e-205

              1. Initial program 100.0%

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

                \[\leadsto \color{blue}{x \cdot \left(1 - y\right)} \]
              4. Step-by-step derivation
                1. *-commutativeN/A

                  \[\leadsto \color{blue}{\left(1 - y\right) \cdot x} \]
                2. lower-*.f64N/A

                  \[\leadsto \color{blue}{\left(1 - y\right) \cdot x} \]
                3. lower--.f6460.0

                  \[\leadsto \color{blue}{\left(1 - y\right)} \cdot x \]
              5. Applied rewrites60.0%

                \[\leadsto \color{blue}{\left(1 - y\right) \cdot x} \]

              if -5.00000000000000001e-205 < (-.f64 (+.f64 x y) (*.f64 x y))

              1. Initial program 100.0%

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

                \[\leadsto \color{blue}{y \cdot \left(1 - x\right)} \]
              4. Step-by-step derivation
                1. *-commutativeN/A

                  \[\leadsto \color{blue}{\left(1 - x\right) \cdot y} \]
                2. lower-*.f64N/A

                  \[\leadsto \color{blue}{\left(1 - x\right) \cdot y} \]
                3. lower--.f6456.8

                  \[\leadsto \color{blue}{\left(1 - x\right)} \cdot y \]
              5. Applied rewrites56.8%

                \[\leadsto \color{blue}{\left(1 - x\right) \cdot y} \]
            3. Recombined 2 regimes into one program.
            4. Add Preprocessing

            Alternative 6: 86.0% accurate, 0.6× speedup?

            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -110:\\ \;\;\;\;\left(-y\right) \cdot x\\ \mathbf{elif}\;y \leq 4.2 \cdot 10^{-12}:\\ \;\;\;\;\mathsf{fma}\left(1, y, x\right)\\ \mathbf{else}:\\ \;\;\;\;\left(1 - x\right) \cdot y\\ \end{array} \end{array} \]
            (FPCore (x y)
             :precision binary64
             (if (<= y -110.0)
               (* (- y) x)
               (if (<= y 4.2e-12) (fma 1.0 y x) (* (- 1.0 x) y))))
            double code(double x, double y) {
            	double tmp;
            	if (y <= -110.0) {
            		tmp = -y * x;
            	} else if (y <= 4.2e-12) {
            		tmp = fma(1.0, y, x);
            	} else {
            		tmp = (1.0 - x) * y;
            	}
            	return tmp;
            }
            
            function code(x, y)
            	tmp = 0.0
            	if (y <= -110.0)
            		tmp = Float64(Float64(-y) * x);
            	elseif (y <= 4.2e-12)
            		tmp = fma(1.0, y, x);
            	else
            		tmp = Float64(Float64(1.0 - x) * y);
            	end
            	return tmp
            end
            
            code[x_, y_] := If[LessEqual[y, -110.0], N[((-y) * x), $MachinePrecision], If[LessEqual[y, 4.2e-12], N[(1.0 * y + x), $MachinePrecision], N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision]]]
            
            \begin{array}{l}
            
            \\
            \begin{array}{l}
            \mathbf{if}\;y \leq -110:\\
            \;\;\;\;\left(-y\right) \cdot x\\
            
            \mathbf{elif}\;y \leq 4.2 \cdot 10^{-12}:\\
            \;\;\;\;\mathsf{fma}\left(1, y, x\right)\\
            
            \mathbf{else}:\\
            \;\;\;\;\left(1 - x\right) \cdot y\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 3 regimes
            2. if y < -110

              1. Initial program 100.0%

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

                \[\leadsto \color{blue}{x \cdot \left(1 - y\right)} \]
              4. Step-by-step derivation
                1. *-commutativeN/A

                  \[\leadsto \color{blue}{\left(1 - y\right) \cdot x} \]
                2. lower-*.f64N/A

                  \[\leadsto \color{blue}{\left(1 - y\right) \cdot x} \]
                3. lower--.f6444.6

                  \[\leadsto \color{blue}{\left(1 - y\right)} \cdot x \]
              5. Applied rewrites44.6%

                \[\leadsto \color{blue}{\left(1 - y\right) \cdot x} \]
              6. Taylor expanded in y around inf

                \[\leadsto \left(-1 \cdot y\right) \cdot x \]
              7. Step-by-step derivation
                1. Applied rewrites43.4%

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

                if -110 < y < 4.19999999999999988e-12

                1. Initial program 100.0%

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

                  \[\leadsto \color{blue}{y + x \cdot \left(1 - y\right)} \]
                4. Applied rewrites100.0%

                  \[\leadsto \color{blue}{\mathsf{fma}\left(1 - x, y, x\right)} \]
                5. Taylor expanded in x around 0

                  \[\leadsto \mathsf{fma}\left(1, y, x\right) \]
                6. Step-by-step derivation
                  1. Applied rewrites98.3%

                    \[\leadsto \mathsf{fma}\left(1, y, x\right) \]

                  if 4.19999999999999988e-12 < y

                  1. Initial program 100.0%

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

                    \[\leadsto \color{blue}{y \cdot \left(1 - x\right)} \]
                  4. Step-by-step derivation
                    1. *-commutativeN/A

                      \[\leadsto \color{blue}{\left(1 - x\right) \cdot y} \]
                    2. lower-*.f64N/A

                      \[\leadsto \color{blue}{\left(1 - x\right) \cdot y} \]
                    3. lower--.f6498.5

                      \[\leadsto \color{blue}{\left(1 - x\right)} \cdot y \]
                  5. Applied rewrites98.5%

                    \[\leadsto \color{blue}{\left(1 - x\right) \cdot y} \]
                7. Recombined 3 regimes into one program.
                8. Add Preprocessing

                Alternative 7: 75.3% accurate, 1.7× speedup?

                \[\begin{array}{l} \\ \mathsf{fma}\left(1, y, x\right) \end{array} \]
                (FPCore (x y) :precision binary64 (fma 1.0 y x))
                double code(double x, double y) {
                	return fma(1.0, y, x);
                }
                
                function code(x, y)
                	return fma(1.0, y, x)
                end
                
                code[x_, y_] := N[(1.0 * y + x), $MachinePrecision]
                
                \begin{array}{l}
                
                \\
                \mathsf{fma}\left(1, y, x\right)
                \end{array}
                
                Derivation
                1. Initial program 100.0%

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

                  \[\leadsto \color{blue}{y + x \cdot \left(1 - y\right)} \]
                4. Applied rewrites100.0%

                  \[\leadsto \color{blue}{\mathsf{fma}\left(1 - x, y, x\right)} \]
                5. Taylor expanded in x around 0

                  \[\leadsto \mathsf{fma}\left(1, y, x\right) \]
                6. Step-by-step derivation
                  1. Applied rewrites75.2%

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

                  Alternative 8: 39.2% accurate, 2.0× speedup?

                  \[\begin{array}{l} \\ 1 \cdot y \end{array} \]
                  (FPCore (x y) :precision binary64 (* 1.0 y))
                  double code(double x, double y) {
                  	return 1.0 * y;
                  }
                  
                  module fmin_fmax_functions
                      implicit none
                      private
                      public fmax
                      public fmin
                  
                      interface fmax
                          module procedure fmax88
                          module procedure fmax44
                          module procedure fmax84
                          module procedure fmax48
                      end interface
                      interface fmin
                          module procedure fmin88
                          module procedure fmin44
                          module procedure fmin84
                          module procedure fmin48
                      end interface
                  contains
                      real(8) function fmax88(x, y) result (res)
                          real(8), intent (in) :: x
                          real(8), intent (in) :: y
                          res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                      end function
                      real(4) function fmax44(x, y) result (res)
                          real(4), intent (in) :: x
                          real(4), intent (in) :: y
                          res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                      end function
                      real(8) function fmax84(x, y) result(res)
                          real(8), intent (in) :: x
                          real(4), intent (in) :: y
                          res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                      end function
                      real(8) function fmax48(x, y) result(res)
                          real(4), intent (in) :: x
                          real(8), intent (in) :: y
                          res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                      end function
                      real(8) function fmin88(x, y) result (res)
                          real(8), intent (in) :: x
                          real(8), intent (in) :: y
                          res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                      end function
                      real(4) function fmin44(x, y) result (res)
                          real(4), intent (in) :: x
                          real(4), intent (in) :: y
                          res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                      end function
                      real(8) function fmin84(x, y) result(res)
                          real(8), intent (in) :: x
                          real(4), intent (in) :: y
                          res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                      end function
                      real(8) function fmin48(x, y) result(res)
                          real(4), intent (in) :: x
                          real(8), intent (in) :: y
                          res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                      end function
                  end module
                  
                  real(8) function code(x, y)
                  use fmin_fmax_functions
                      real(8), intent (in) :: x
                      real(8), intent (in) :: y
                      code = 1.0d0 * y
                  end function
                  
                  public static double code(double x, double y) {
                  	return 1.0 * y;
                  }
                  
                  def code(x, y):
                  	return 1.0 * y
                  
                  function code(x, y)
                  	return Float64(1.0 * y)
                  end
                  
                  function tmp = code(x, y)
                  	tmp = 1.0 * y;
                  end
                  
                  code[x_, y_] := N[(1.0 * y), $MachinePrecision]
                  
                  \begin{array}{l}
                  
                  \\
                  1 \cdot y
                  \end{array}
                  
                  Derivation
                  1. Initial program 100.0%

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

                    \[\leadsto \color{blue}{y \cdot \left(1 - x\right)} \]
                  4. Step-by-step derivation
                    1. *-commutativeN/A

                      \[\leadsto \color{blue}{\left(1 - x\right) \cdot y} \]
                    2. lower-*.f64N/A

                      \[\leadsto \color{blue}{\left(1 - x\right) \cdot y} \]
                    3. lower--.f6461.2

                      \[\leadsto \color{blue}{\left(1 - x\right)} \cdot y \]
                  5. Applied rewrites61.2%

                    \[\leadsto \color{blue}{\left(1 - x\right) \cdot y} \]
                  6. Taylor expanded in x around 0

                    \[\leadsto 1 \cdot y \]
                  7. Step-by-step derivation
                    1. Applied rewrites37.5%

                      \[\leadsto 1 \cdot y \]
                    2. Add Preprocessing

                    Reproduce

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