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

Percentage Accurate: 99.7% → 99.8%
Time: 2.5s
Alternatives: 8
Speedup: 1.1×

Specification

?
\[x + \left(\left(y - x\right) \cdot 6\right) \cdot z \]
(FPCore (x y z) :precision binary64 (+ x (* (* (- y x) 6.0) z)))
double code(double x, double y, double z) {
	return x + (((y - x) * 6.0) * z);
}
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, z)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = x + (((y - x) * 6.0d0) * z)
end function
public static double code(double x, double y, double z) {
	return x + (((y - x) * 6.0) * z);
}
def code(x, y, z):
	return x + (((y - x) * 6.0) * z)
function code(x, y, z)
	return Float64(x + Float64(Float64(Float64(y - x) * 6.0) * z))
end
function tmp = code(x, y, z)
	tmp = x + (((y - x) * 6.0) * z);
end
code[x_, y_, z_] := N[(x + N[(N[(N[(y - x), $MachinePrecision] * 6.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
x + \left(\left(y - x\right) \cdot 6\right) \cdot z

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: 99.7% accurate, 1.0× speedup?

\[x + \left(\left(y - x\right) \cdot 6\right) \cdot z \]
(FPCore (x y z) :precision binary64 (+ x (* (* (- y x) 6.0) z)))
double code(double x, double y, double z) {
	return x + (((y - x) * 6.0) * z);
}
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, z)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = x + (((y - x) * 6.0d0) * z)
end function
public static double code(double x, double y, double z) {
	return x + (((y - x) * 6.0) * z);
}
def code(x, y, z):
	return x + (((y - x) * 6.0) * z)
function code(x, y, z)
	return Float64(x + Float64(Float64(Float64(y - x) * 6.0) * z))
end
function tmp = code(x, y, z)
	tmp = x + (((y - x) * 6.0) * z);
end
code[x_, y_, z_] := N[(x + N[(N[(N[(y - x), $MachinePrecision] * 6.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
x + \left(\left(y - x\right) \cdot 6\right) \cdot z

Alternative 1: 99.8% accurate, 1.1× speedup?

\[\mathsf{fma}\left(y - x, z \cdot 6, x\right) \]
(FPCore (x y z) :precision binary64 (fma (- y x) (* z 6.0) x))
double code(double x, double y, double z) {
	return fma((y - x), (z * 6.0), x);
}
function code(x, y, z)
	return fma(Float64(y - x), Float64(z * 6.0), x)
end
code[x_, y_, z_] := N[(N[(y - x), $MachinePrecision] * N[(z * 6.0), $MachinePrecision] + x), $MachinePrecision]
\mathsf{fma}\left(y - x, z \cdot 6, x\right)
Derivation
  1. Initial program 99.7%

    \[x + \left(\left(y - x\right) \cdot 6\right) \cdot z \]
  2. Step-by-step derivation
    1. lift-+.f64N/A

      \[\leadsto \color{blue}{x + \left(\left(y - x\right) \cdot 6\right) \cdot z} \]
    2. +-commutativeN/A

      \[\leadsto \color{blue}{\left(\left(y - x\right) \cdot 6\right) \cdot z + x} \]
    3. lift-*.f64N/A

      \[\leadsto \color{blue}{\left(\left(y - x\right) \cdot 6\right) \cdot z} + x \]
    4. lift-*.f64N/A

      \[\leadsto \color{blue}{\left(\left(y - x\right) \cdot 6\right)} \cdot z + x \]
    5. associate-*l*N/A

      \[\leadsto \color{blue}{\left(y - x\right) \cdot \left(6 \cdot z\right)} + x \]
    6. lower-fma.f64N/A

      \[\leadsto \color{blue}{\mathsf{fma}\left(y - x, 6 \cdot z, x\right)} \]
    7. *-commutativeN/A

      \[\leadsto \mathsf{fma}\left(y - x, \color{blue}{z \cdot 6}, x\right) \]
    8. lower-*.f6499.8%

      \[\leadsto \mathsf{fma}\left(y - x, \color{blue}{z \cdot 6}, x\right) \]
  3. Applied rewrites99.8%

    \[\leadsto \color{blue}{\mathsf{fma}\left(y - x, z \cdot 6, x\right)} \]
  4. Add Preprocessing

Alternative 2: 99.7% accurate, 1.1× speedup?

\[\mathsf{fma}\left(6 \cdot \left(y - x\right), z, x\right) \]
(FPCore (x y z) :precision binary64 (fma (* 6.0 (- y x)) z x))
double code(double x, double y, double z) {
	return fma((6.0 * (y - x)), z, x);
}
function code(x, y, z)
	return fma(Float64(6.0 * Float64(y - x)), z, x)
end
code[x_, y_, z_] := N[(N[(6.0 * N[(y - x), $MachinePrecision]), $MachinePrecision] * z + x), $MachinePrecision]
\mathsf{fma}\left(6 \cdot \left(y - x\right), z, x\right)
Derivation
  1. Initial program 99.7%

    \[x + \left(\left(y - x\right) \cdot 6\right) \cdot z \]
  2. Step-by-step derivation
    1. lift-+.f64N/A

      \[\leadsto \color{blue}{x + \left(\left(y - x\right) \cdot 6\right) \cdot z} \]
    2. +-commutativeN/A

      \[\leadsto \color{blue}{\left(\left(y - x\right) \cdot 6\right) \cdot z + x} \]
    3. lift-*.f64N/A

      \[\leadsto \color{blue}{\left(\left(y - x\right) \cdot 6\right) \cdot z} + x \]
    4. lower-fma.f6499.7%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\left(y - x\right) \cdot 6, z, x\right)} \]
    5. lift-*.f64N/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{\left(y - x\right) \cdot 6}, z, x\right) \]
    6. *-commutativeN/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{6 \cdot \left(y - x\right)}, z, x\right) \]
    7. lower-*.f6499.7%

      \[\leadsto \mathsf{fma}\left(\color{blue}{6 \cdot \left(y - x\right)}, z, x\right) \]
  3. Applied rewrites99.7%

    \[\leadsto \color{blue}{\mathsf{fma}\left(6 \cdot \left(y - x\right), z, x\right)} \]
  4. Add Preprocessing

Alternative 3: 98.1% accurate, 0.7× speedup?

\[\begin{array}{l} t_0 := 6 \cdot \left(z \cdot \left(y - x\right)\right)\\ \mathbf{if}\;z \leq -2.5 \cdot 10^{+18}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;z \leq 1100000:\\ \;\;\;\;\mathsf{fma}\left(z \cdot y, 6, x\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* 6.0 (* z (- y x)))))
   (if (<= z -2.5e+18) t_0 (if (<= z 1100000.0) (fma (* z y) 6.0 x) t_0))))
double code(double x, double y, double z) {
	double t_0 = 6.0 * (z * (y - x));
	double tmp;
	if (z <= -2.5e+18) {
		tmp = t_0;
	} else if (z <= 1100000.0) {
		tmp = fma((z * y), 6.0, x);
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(x, y, z)
	t_0 = Float64(6.0 * Float64(z * Float64(y - x)))
	tmp = 0.0
	if (z <= -2.5e+18)
		tmp = t_0;
	elseif (z <= 1100000.0)
		tmp = fma(Float64(z * y), 6.0, x);
	else
		tmp = t_0;
	end
	return tmp
end
code[x_, y_, z_] := Block[{t$95$0 = N[(6.0 * N[(z * N[(y - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -2.5e+18], t$95$0, If[LessEqual[z, 1100000.0], N[(N[(z * y), $MachinePrecision] * 6.0 + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
t_0 := 6 \cdot \left(z \cdot \left(y - x\right)\right)\\
\mathbf{if}\;z \leq -2.5 \cdot 10^{+18}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;z \leq 1100000:\\
\;\;\;\;\mathsf{fma}\left(z \cdot y, 6, x\right)\\

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


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -2.5e18 or 1.1e6 < z

    1. Initial program 99.7%

      \[x + \left(\left(y - x\right) \cdot 6\right) \cdot z \]
    2. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \color{blue}{x + \left(\left(y - x\right) \cdot 6\right) \cdot z} \]
      2. +-commutativeN/A

        \[\leadsto \color{blue}{\left(\left(y - x\right) \cdot 6\right) \cdot z + x} \]
      3. lift-*.f64N/A

        \[\leadsto \color{blue}{\left(\left(y - x\right) \cdot 6\right) \cdot z} + x \]
      4. lower-fma.f6499.7%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\left(y - x\right) \cdot 6, z, x\right)} \]
      5. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\left(y - x\right) \cdot 6}, z, x\right) \]
      6. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{6 \cdot \left(y - x\right)}, z, x\right) \]
      7. lower-*.f6499.7%

        \[\leadsto \mathsf{fma}\left(\color{blue}{6 \cdot \left(y - x\right)}, z, x\right) \]
    3. Applied rewrites99.7%

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

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

        \[\leadsto \mathsf{fma}\left(6 \cdot \color{blue}{y}, z, x\right) \]
      2. Taylor expanded in z around inf

        \[\leadsto \color{blue}{6 \cdot \left(z \cdot \left(y - x\right)\right)} \]
      3. Step-by-step derivation
        1. lower-*.f64N/A

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

          \[\leadsto 6 \cdot \left(z \cdot \color{blue}{\left(y - x\right)}\right) \]
        3. lower--.f6465.9%

          \[\leadsto 6 \cdot \left(z \cdot \left(y - \color{blue}{x}\right)\right) \]
      4. Applied rewrites65.9%

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

      if -2.5e18 < z < 1.1e6

      1. Initial program 99.7%

        \[x + \left(\left(y - x\right) \cdot 6\right) \cdot z \]
      2. Step-by-step derivation
        1. lift-+.f64N/A

          \[\leadsto \color{blue}{x + \left(\left(y - x\right) \cdot 6\right) \cdot z} \]
        2. +-commutativeN/A

          \[\leadsto \color{blue}{\left(\left(y - x\right) \cdot 6\right) \cdot z + x} \]
        3. lift-*.f64N/A

          \[\leadsto \color{blue}{\left(\left(y - x\right) \cdot 6\right) \cdot z} + x \]
        4. lower-fma.f6499.7%

          \[\leadsto \color{blue}{\mathsf{fma}\left(\left(y - x\right) \cdot 6, z, x\right)} \]
        5. lift-*.f64N/A

          \[\leadsto \mathsf{fma}\left(\color{blue}{\left(y - x\right) \cdot 6}, z, x\right) \]
        6. *-commutativeN/A

          \[\leadsto \mathsf{fma}\left(\color{blue}{6 \cdot \left(y - x\right)}, z, x\right) \]
        7. lower-*.f6499.7%

          \[\leadsto \mathsf{fma}\left(\color{blue}{6 \cdot \left(y - x\right)}, z, x\right) \]
      3. Applied rewrites99.7%

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

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

          \[\leadsto \mathsf{fma}\left(6 \cdot \color{blue}{y}, z, x\right) \]
        2. Step-by-step derivation
          1. lift-fma.f64N/A

            \[\leadsto \color{blue}{\left(6 \cdot y\right) \cdot z + x} \]
          2. lift-*.f64N/A

            \[\leadsto \color{blue}{\left(6 \cdot y\right)} \cdot z + x \]
          3. associate-*l*N/A

            \[\leadsto \color{blue}{6 \cdot \left(y \cdot z\right)} + x \]
          4. *-commutativeN/A

            \[\leadsto \color{blue}{\left(y \cdot z\right) \cdot 6} + x \]
          5. lower-fma.f64N/A

            \[\leadsto \color{blue}{\mathsf{fma}\left(y \cdot z, 6, x\right)} \]
          6. *-commutativeN/A

            \[\leadsto \mathsf{fma}\left(\color{blue}{z \cdot y}, 6, x\right) \]
          7. lower-*.f6476.1%

            \[\leadsto \mathsf{fma}\left(\color{blue}{z \cdot y}, 6, x\right) \]
        3. Applied rewrites76.1%

          \[\leadsto \color{blue}{\mathsf{fma}\left(z \cdot y, 6, x\right)} \]
      6. Recombined 2 regimes into one program.
      7. Add Preprocessing

      Alternative 4: 85.6% accurate, 0.7× speedup?

      \[\begin{array}{l} t_0 := \mathsf{fma}\left(-6 \cdot x, z, x\right)\\ \mathbf{if}\;x \leq -3.3 \cdot 10^{+30}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq 3.25 \cdot 10^{+77}:\\ \;\;\;\;\mathsf{fma}\left(6 \cdot y, z, x\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \]
      (FPCore (x y z)
       :precision binary64
       (let* ((t_0 (fma (* -6.0 x) z x)))
         (if (<= x -3.3e+30) t_0 (if (<= x 3.25e+77) (fma (* 6.0 y) z x) t_0))))
      double code(double x, double y, double z) {
      	double t_0 = fma((-6.0 * x), z, x);
      	double tmp;
      	if (x <= -3.3e+30) {
      		tmp = t_0;
      	} else if (x <= 3.25e+77) {
      		tmp = fma((6.0 * y), z, x);
      	} else {
      		tmp = t_0;
      	}
      	return tmp;
      }
      
      function code(x, y, z)
      	t_0 = fma(Float64(-6.0 * x), z, x)
      	tmp = 0.0
      	if (x <= -3.3e+30)
      		tmp = t_0;
      	elseif (x <= 3.25e+77)
      		tmp = fma(Float64(6.0 * y), z, x);
      	else
      		tmp = t_0;
      	end
      	return tmp
      end
      
      code[x_, y_, z_] := Block[{t$95$0 = N[(N[(-6.0 * x), $MachinePrecision] * z + x), $MachinePrecision]}, If[LessEqual[x, -3.3e+30], t$95$0, If[LessEqual[x, 3.25e+77], N[(N[(6.0 * y), $MachinePrecision] * z + x), $MachinePrecision], t$95$0]]]
      
      \begin{array}{l}
      t_0 := \mathsf{fma}\left(-6 \cdot x, z, x\right)\\
      \mathbf{if}\;x \leq -3.3 \cdot 10^{+30}:\\
      \;\;\;\;t\_0\\
      
      \mathbf{elif}\;x \leq 3.25 \cdot 10^{+77}:\\
      \;\;\;\;\mathsf{fma}\left(6 \cdot y, z, x\right)\\
      
      \mathbf{else}:\\
      \;\;\;\;t\_0\\
      
      
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if x < -3.30000000000000026e30 or 3.25e77 < x

        1. Initial program 99.7%

          \[x + \left(\left(y - x\right) \cdot 6\right) \cdot z \]
        2. Step-by-step derivation
          1. lift-+.f64N/A

            \[\leadsto \color{blue}{x + \left(\left(y - x\right) \cdot 6\right) \cdot z} \]
          2. +-commutativeN/A

            \[\leadsto \color{blue}{\left(\left(y - x\right) \cdot 6\right) \cdot z + x} \]
          3. lift-*.f64N/A

            \[\leadsto \color{blue}{\left(\left(y - x\right) \cdot 6\right) \cdot z} + x \]
          4. lower-fma.f6499.7%

            \[\leadsto \color{blue}{\mathsf{fma}\left(\left(y - x\right) \cdot 6, z, x\right)} \]
          5. lift-*.f64N/A

            \[\leadsto \mathsf{fma}\left(\color{blue}{\left(y - x\right) \cdot 6}, z, x\right) \]
          6. *-commutativeN/A

            \[\leadsto \mathsf{fma}\left(\color{blue}{6 \cdot \left(y - x\right)}, z, x\right) \]
          7. lower-*.f6499.7%

            \[\leadsto \mathsf{fma}\left(\color{blue}{6 \cdot \left(y - x\right)}, z, x\right) \]
        3. Applied rewrites99.7%

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

          \[\leadsto \mathsf{fma}\left(\color{blue}{-6 \cdot x}, z, x\right) \]
        5. Step-by-step derivation
          1. lower-*.f6460.7%

            \[\leadsto \mathsf{fma}\left(-6 \cdot \color{blue}{x}, z, x\right) \]
        6. Applied rewrites60.7%

          \[\leadsto \mathsf{fma}\left(\color{blue}{-6 \cdot x}, z, x\right) \]

        if -3.30000000000000026e30 < x < 3.25e77

        1. Initial program 99.7%

          \[x + \left(\left(y - x\right) \cdot 6\right) \cdot z \]
        2. Step-by-step derivation
          1. lift-+.f64N/A

            \[\leadsto \color{blue}{x + \left(\left(y - x\right) \cdot 6\right) \cdot z} \]
          2. +-commutativeN/A

            \[\leadsto \color{blue}{\left(\left(y - x\right) \cdot 6\right) \cdot z + x} \]
          3. lift-*.f64N/A

            \[\leadsto \color{blue}{\left(\left(y - x\right) \cdot 6\right) \cdot z} + x \]
          4. lower-fma.f6499.7%

            \[\leadsto \color{blue}{\mathsf{fma}\left(\left(y - x\right) \cdot 6, z, x\right)} \]
          5. lift-*.f64N/A

            \[\leadsto \mathsf{fma}\left(\color{blue}{\left(y - x\right) \cdot 6}, z, x\right) \]
          6. *-commutativeN/A

            \[\leadsto \mathsf{fma}\left(\color{blue}{6 \cdot \left(y - x\right)}, z, x\right) \]
          7. lower-*.f6499.7%

            \[\leadsto \mathsf{fma}\left(\color{blue}{6 \cdot \left(y - x\right)}, z, x\right) \]
        3. Applied rewrites99.7%

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

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

            \[\leadsto \mathsf{fma}\left(6 \cdot \color{blue}{y}, z, x\right) \]
        6. Recombined 2 regimes into one program.
        7. Add Preprocessing

        Alternative 5: 74.6% accurate, 0.7× speedup?

        \[\begin{array}{l} t_0 := \mathsf{fma}\left(-6 \cdot x, z, x\right)\\ \mathbf{if}\;x \leq -2.1 \cdot 10^{-17}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq 6.2 \cdot 10^{-38}:\\ \;\;\;\;\left(6 \cdot z\right) \cdot y\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \]
        (FPCore (x y z)
         :precision binary64
         (let* ((t_0 (fma (* -6.0 x) z x)))
           (if (<= x -2.1e-17) t_0 (if (<= x 6.2e-38) (* (* 6.0 z) y) t_0))))
        double code(double x, double y, double z) {
        	double t_0 = fma((-6.0 * x), z, x);
        	double tmp;
        	if (x <= -2.1e-17) {
        		tmp = t_0;
        	} else if (x <= 6.2e-38) {
        		tmp = (6.0 * z) * y;
        	} else {
        		tmp = t_0;
        	}
        	return tmp;
        }
        
        function code(x, y, z)
        	t_0 = fma(Float64(-6.0 * x), z, x)
        	tmp = 0.0
        	if (x <= -2.1e-17)
        		tmp = t_0;
        	elseif (x <= 6.2e-38)
        		tmp = Float64(Float64(6.0 * z) * y);
        	else
        		tmp = t_0;
        	end
        	return tmp
        end
        
        code[x_, y_, z_] := Block[{t$95$0 = N[(N[(-6.0 * x), $MachinePrecision] * z + x), $MachinePrecision]}, If[LessEqual[x, -2.1e-17], t$95$0, If[LessEqual[x, 6.2e-38], N[(N[(6.0 * z), $MachinePrecision] * y), $MachinePrecision], t$95$0]]]
        
        \begin{array}{l}
        t_0 := \mathsf{fma}\left(-6 \cdot x, z, x\right)\\
        \mathbf{if}\;x \leq -2.1 \cdot 10^{-17}:\\
        \;\;\;\;t\_0\\
        
        \mathbf{elif}\;x \leq 6.2 \cdot 10^{-38}:\\
        \;\;\;\;\left(6 \cdot z\right) \cdot y\\
        
        \mathbf{else}:\\
        \;\;\;\;t\_0\\
        
        
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if x < -2.09999999999999992e-17 or 6.19999999999999966e-38 < x

          1. Initial program 99.7%

            \[x + \left(\left(y - x\right) \cdot 6\right) \cdot z \]
          2. Step-by-step derivation
            1. lift-+.f64N/A

              \[\leadsto \color{blue}{x + \left(\left(y - x\right) \cdot 6\right) \cdot z} \]
            2. +-commutativeN/A

              \[\leadsto \color{blue}{\left(\left(y - x\right) \cdot 6\right) \cdot z + x} \]
            3. lift-*.f64N/A

              \[\leadsto \color{blue}{\left(\left(y - x\right) \cdot 6\right) \cdot z} + x \]
            4. lower-fma.f6499.7%

              \[\leadsto \color{blue}{\mathsf{fma}\left(\left(y - x\right) \cdot 6, z, x\right)} \]
            5. lift-*.f64N/A

              \[\leadsto \mathsf{fma}\left(\color{blue}{\left(y - x\right) \cdot 6}, z, x\right) \]
            6. *-commutativeN/A

              \[\leadsto \mathsf{fma}\left(\color{blue}{6 \cdot \left(y - x\right)}, z, x\right) \]
            7. lower-*.f6499.7%

              \[\leadsto \mathsf{fma}\left(\color{blue}{6 \cdot \left(y - x\right)}, z, x\right) \]
          3. Applied rewrites99.7%

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

            \[\leadsto \mathsf{fma}\left(\color{blue}{-6 \cdot x}, z, x\right) \]
          5. Step-by-step derivation
            1. lower-*.f6460.7%

              \[\leadsto \mathsf{fma}\left(-6 \cdot \color{blue}{x}, z, x\right) \]
          6. Applied rewrites60.7%

            \[\leadsto \mathsf{fma}\left(\color{blue}{-6 \cdot x}, z, x\right) \]

          if -2.09999999999999992e-17 < x < 6.19999999999999966e-38

          1. Initial program 99.7%

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

            \[\leadsto \color{blue}{6 \cdot \left(y \cdot z\right)} \]
          3. Step-by-step derivation
            1. lower-*.f64N/A

              \[\leadsto 6 \cdot \color{blue}{\left(y \cdot z\right)} \]
            2. lower-*.f6442.9%

              \[\leadsto 6 \cdot \left(y \cdot \color{blue}{z}\right) \]
          4. Applied rewrites42.9%

            \[\leadsto \color{blue}{6 \cdot \left(y \cdot z\right)} \]
          5. Step-by-step derivation
            1. lift-*.f64N/A

              \[\leadsto 6 \cdot \color{blue}{\left(y \cdot z\right)} \]
            2. lift-*.f64N/A

              \[\leadsto 6 \cdot \left(y \cdot \color{blue}{z}\right) \]
            3. *-commutativeN/A

              \[\leadsto 6 \cdot \left(z \cdot \color{blue}{y}\right) \]
            4. associate-*r*N/A

              \[\leadsto \left(6 \cdot z\right) \cdot \color{blue}{y} \]
            5. *-commutativeN/A

              \[\leadsto \left(z \cdot 6\right) \cdot y \]
            6. lift-*.f64N/A

              \[\leadsto \left(z \cdot 6\right) \cdot y \]
            7. lower-*.f6442.9%

              \[\leadsto \left(z \cdot 6\right) \cdot \color{blue}{y} \]
            8. lift-*.f64N/A

              \[\leadsto \left(z \cdot 6\right) \cdot y \]
            9. *-commutativeN/A

              \[\leadsto \left(6 \cdot z\right) \cdot y \]
            10. lower-*.f6442.9%

              \[\leadsto \left(6 \cdot z\right) \cdot y \]
          6. Applied rewrites42.9%

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

        Alternative 6: 42.9% accurate, 1.8× speedup?

        \[\left(6 \cdot z\right) \cdot y \]
        (FPCore (x y z) :precision binary64 (* (* 6.0 z) y))
        double code(double x, double y, double z) {
        	return (6.0 * z) * 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, z)
        use fmin_fmax_functions
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            real(8), intent (in) :: z
            code = (6.0d0 * z) * y
        end function
        
        public static double code(double x, double y, double z) {
        	return (6.0 * z) * y;
        }
        
        def code(x, y, z):
        	return (6.0 * z) * y
        
        function code(x, y, z)
        	return Float64(Float64(6.0 * z) * y)
        end
        
        function tmp = code(x, y, z)
        	tmp = (6.0 * z) * y;
        end
        
        code[x_, y_, z_] := N[(N[(6.0 * z), $MachinePrecision] * y), $MachinePrecision]
        
        \left(6 \cdot z\right) \cdot y
        
        Derivation
        1. Initial program 99.7%

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

          \[\leadsto \color{blue}{6 \cdot \left(y \cdot z\right)} \]
        3. Step-by-step derivation
          1. lower-*.f64N/A

            \[\leadsto 6 \cdot \color{blue}{\left(y \cdot z\right)} \]
          2. lower-*.f6442.9%

            \[\leadsto 6 \cdot \left(y \cdot \color{blue}{z}\right) \]
        4. Applied rewrites42.9%

          \[\leadsto \color{blue}{6 \cdot \left(y \cdot z\right)} \]
        5. Step-by-step derivation
          1. lift-*.f64N/A

            \[\leadsto 6 \cdot \color{blue}{\left(y \cdot z\right)} \]
          2. lift-*.f64N/A

            \[\leadsto 6 \cdot \left(y \cdot \color{blue}{z}\right) \]
          3. *-commutativeN/A

            \[\leadsto 6 \cdot \left(z \cdot \color{blue}{y}\right) \]
          4. associate-*r*N/A

            \[\leadsto \left(6 \cdot z\right) \cdot \color{blue}{y} \]
          5. *-commutativeN/A

            \[\leadsto \left(z \cdot 6\right) \cdot y \]
          6. lift-*.f64N/A

            \[\leadsto \left(z \cdot 6\right) \cdot y \]
          7. lower-*.f6442.9%

            \[\leadsto \left(z \cdot 6\right) \cdot \color{blue}{y} \]
          8. lift-*.f64N/A

            \[\leadsto \left(z \cdot 6\right) \cdot y \]
          9. *-commutativeN/A

            \[\leadsto \left(6 \cdot z\right) \cdot y \]
          10. lower-*.f6442.9%

            \[\leadsto \left(6 \cdot z\right) \cdot y \]
        6. Applied rewrites42.9%

          \[\leadsto \left(6 \cdot z\right) \cdot \color{blue}{y} \]
        7. Add Preprocessing

        Alternative 7: 42.9% accurate, 1.8× speedup?

        \[\left(6 \cdot y\right) \cdot z \]
        (FPCore (x y z) :precision binary64 (* (* 6.0 y) z))
        double code(double x, double y, double z) {
        	return (6.0 * y) * z;
        }
        
        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, z)
        use fmin_fmax_functions
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            real(8), intent (in) :: z
            code = (6.0d0 * y) * z
        end function
        
        public static double code(double x, double y, double z) {
        	return (6.0 * y) * z;
        }
        
        def code(x, y, z):
        	return (6.0 * y) * z
        
        function code(x, y, z)
        	return Float64(Float64(6.0 * y) * z)
        end
        
        function tmp = code(x, y, z)
        	tmp = (6.0 * y) * z;
        end
        
        code[x_, y_, z_] := N[(N[(6.0 * y), $MachinePrecision] * z), $MachinePrecision]
        
        \left(6 \cdot y\right) \cdot z
        
        Derivation
        1. Initial program 99.7%

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

          \[\leadsto \color{blue}{6 \cdot \left(y \cdot z\right)} \]
        3. Step-by-step derivation
          1. lower-*.f64N/A

            \[\leadsto 6 \cdot \color{blue}{\left(y \cdot z\right)} \]
          2. lower-*.f6442.9%

            \[\leadsto 6 \cdot \left(y \cdot \color{blue}{z}\right) \]
        4. Applied rewrites42.9%

          \[\leadsto \color{blue}{6 \cdot \left(y \cdot z\right)} \]
        5. Step-by-step derivation
          1. lift-*.f64N/A

            \[\leadsto 6 \cdot \color{blue}{\left(y \cdot z\right)} \]
          2. lift-*.f64N/A

            \[\leadsto 6 \cdot \left(y \cdot \color{blue}{z}\right) \]
          3. associate-*r*N/A

            \[\leadsto \left(6 \cdot y\right) \cdot \color{blue}{z} \]
          4. lower-*.f64N/A

            \[\leadsto \left(6 \cdot y\right) \cdot \color{blue}{z} \]
          5. lower-*.f6442.8%

            \[\leadsto \left(6 \cdot y\right) \cdot z \]
        6. Applied rewrites42.8%

          \[\leadsto \left(6 \cdot y\right) \cdot \color{blue}{z} \]
        7. Add Preprocessing

        Alternative 8: 42.8% accurate, 1.8× speedup?

        \[6 \cdot \left(y \cdot z\right) \]
        (FPCore (x y z) :precision binary64 (* 6.0 (* y z)))
        double code(double x, double y, double z) {
        	return 6.0 * (y * z);
        }
        
        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, z)
        use fmin_fmax_functions
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            real(8), intent (in) :: z
            code = 6.0d0 * (y * z)
        end function
        
        public static double code(double x, double y, double z) {
        	return 6.0 * (y * z);
        }
        
        def code(x, y, z):
        	return 6.0 * (y * z)
        
        function code(x, y, z)
        	return Float64(6.0 * Float64(y * z))
        end
        
        function tmp = code(x, y, z)
        	tmp = 6.0 * (y * z);
        end
        
        code[x_, y_, z_] := N[(6.0 * N[(y * z), $MachinePrecision]), $MachinePrecision]
        
        6 \cdot \left(y \cdot z\right)
        
        Derivation
        1. Initial program 99.7%

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

          \[\leadsto \color{blue}{6 \cdot \left(y \cdot z\right)} \]
        3. Step-by-step derivation
          1. lower-*.f64N/A

            \[\leadsto 6 \cdot \color{blue}{\left(y \cdot z\right)} \]
          2. lower-*.f6442.9%

            \[\leadsto 6 \cdot \left(y \cdot \color{blue}{z}\right) \]
        4. Applied rewrites42.9%

          \[\leadsto \color{blue}{6 \cdot \left(y \cdot z\right)} \]
        5. Add Preprocessing

        Reproduce

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