Diagrams.Color.HSV:lerp from diagrams-contrib-1.3.0.5

Percentage Accurate: 97.9% → 100.0%
Time: 4.9s
Alternatives: 7
Speedup: 1.7×

Specification

?
\[\begin{array}{l} \\ \left(1 - x\right) \cdot y + x \cdot z \end{array} \]
(FPCore (x y z) :precision binary64 (+ (* (- 1.0 x) y) (* x z)))
double code(double x, double y, double z) {
	return ((1.0 - x) * y) + (x * z);
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = ((1.0d0 - x) * y) + (x * z)
end function
public static double code(double x, double y, double z) {
	return ((1.0 - x) * y) + (x * z);
}
def code(x, y, z):
	return ((1.0 - x) * y) + (x * z)
function code(x, y, z)
	return Float64(Float64(Float64(1.0 - x) * y) + Float64(x * z))
end
function tmp = code(x, y, z)
	tmp = ((1.0 - x) * y) + (x * z);
end
code[x_, y_, z_] := N[(N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision] + N[(x * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(1 - x\right) \cdot y + x \cdot z
\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 7 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: 97.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(1 - x\right) \cdot y + x \cdot z \end{array} \]
(FPCore (x y z) :precision binary64 (+ (* (- 1.0 x) y) (* x z)))
double code(double x, double y, double z) {
	return ((1.0 - x) * y) + (x * z);
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = ((1.0d0 - x) * y) + (x * z)
end function
public static double code(double x, double y, double z) {
	return ((1.0 - x) * y) + (x * z);
}
def code(x, y, z):
	return ((1.0 - x) * y) + (x * z)
function code(x, y, z)
	return Float64(Float64(Float64(1.0 - x) * y) + Float64(x * z))
end
function tmp = code(x, y, z)
	tmp = ((1.0 - x) * y) + (x * z);
end
code[x_, y_, z_] := N[(N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision] + N[(x * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

Alternative 1: 100.0% accurate, 1.7× speedup?

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

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

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

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

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

      \[\leadsto \color{blue}{\left(1 - x\right) \cdot y} + x \cdot z \]
    3. sub-negN/A

      \[\leadsto \color{blue}{\left(1 + \left(\mathsf{neg}\left(x\right)\right)\right)} \cdot y + x \cdot z \]
    4. mul-1-negN/A

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

      \[\leadsto \color{blue}{\left(-1 \cdot x + 1\right)} \cdot y + x \cdot z \]
    6. distribute-lft1-inN/A

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

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

      \[\leadsto \color{blue}{\left(y + -1 \cdot \left(x \cdot y\right)\right)} + x \cdot z \]
    9. mul-1-negN/A

      \[\leadsto \left(y + \color{blue}{\left(\mathsf{neg}\left(x \cdot y\right)\right)}\right) + x \cdot z \]
    10. unsub-negN/A

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

      \[\leadsto \color{blue}{y - \left(x \cdot y - x \cdot z\right)} \]
    12. distribute-lft-out--N/A

      \[\leadsto y - \color{blue}{x \cdot \left(y - z\right)} \]
    13. unsub-negN/A

      \[\leadsto y - x \cdot \color{blue}{\left(y + \left(\mathsf{neg}\left(z\right)\right)\right)} \]
    14. mul-1-negN/A

      \[\leadsto y - x \cdot \left(y + \color{blue}{-1 \cdot z}\right) \]
    15. sub-negN/A

      \[\leadsto \color{blue}{y + \left(\mathsf{neg}\left(x \cdot \left(y + -1 \cdot z\right)\right)\right)} \]
    16. mul-1-negN/A

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

      \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \left(y + -1 \cdot z\right)\right) + y} \]
    18. mul-1-negN/A

      \[\leadsto \color{blue}{\left(\mathsf{neg}\left(x \cdot \left(y + -1 \cdot z\right)\right)\right)} + y \]
    19. *-commutativeN/A

      \[\leadsto \left(\mathsf{neg}\left(\color{blue}{\left(y + -1 \cdot z\right) \cdot x}\right)\right) + y \]
    20. distribute-lft-neg-inN/A

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{neg}\left(\left(y + -1 \cdot z\right)\right), x, y\right)} \]
  5. Applied rewrites100.0%

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

Alternative 2: 61.5% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -0.028:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;x \leq 3.5 \cdot 10^{-38}:\\ \;\;\;\;1 \cdot y\\ \mathbf{elif}\;x \leq 29000000000000:\\ \;\;\;\;z \cdot x\\ \mathbf{else}:\\ \;\;\;\;\left(-y\right) \cdot x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= x -0.028)
   (* z x)
   (if (<= x 3.5e-38)
     (* 1.0 y)
     (if (<= x 29000000000000.0) (* z x) (* (- y) x)))))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -0.028) {
		tmp = z * x;
	} else if (x <= 3.5e-38) {
		tmp = 1.0 * y;
	} else if (x <= 29000000000000.0) {
		tmp = z * x;
	} else {
		tmp = -y * x;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (x <= (-0.028d0)) then
        tmp = z * x
    else if (x <= 3.5d-38) then
        tmp = 1.0d0 * y
    else if (x <= 29000000000000.0d0) then
        tmp = z * x
    else
        tmp = -y * x
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (x <= -0.028) {
		tmp = z * x;
	} else if (x <= 3.5e-38) {
		tmp = 1.0 * y;
	} else if (x <= 29000000000000.0) {
		tmp = z * x;
	} else {
		tmp = -y * x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if x <= -0.028:
		tmp = z * x
	elif x <= 3.5e-38:
		tmp = 1.0 * y
	elif x <= 29000000000000.0:
		tmp = z * x
	else:
		tmp = -y * x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (x <= -0.028)
		tmp = Float64(z * x);
	elseif (x <= 3.5e-38)
		tmp = Float64(1.0 * y);
	elseif (x <= 29000000000000.0)
		tmp = Float64(z * x);
	else
		tmp = Float64(Float64(-y) * x);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (x <= -0.028)
		tmp = z * x;
	elseif (x <= 3.5e-38)
		tmp = 1.0 * y;
	elseif (x <= 29000000000000.0)
		tmp = z * x;
	else
		tmp = -y * x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[x, -0.028], N[(z * x), $MachinePrecision], If[LessEqual[x, 3.5e-38], N[(1.0 * y), $MachinePrecision], If[LessEqual[x, 29000000000000.0], N[(z * x), $MachinePrecision], N[((-y) * x), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.028:\\
\;\;\;\;z \cdot x\\

\mathbf{elif}\;x \leq 3.5 \cdot 10^{-38}:\\
\;\;\;\;1 \cdot y\\

\mathbf{elif}\;x \leq 29000000000000:\\
\;\;\;\;z \cdot x\\

\mathbf{else}:\\
\;\;\;\;\left(-y\right) \cdot x\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -0.0280000000000000006 or 3.5000000000000001e-38 < x < 2.9e13

    1. Initial program 95.9%

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

      \[\leadsto \color{blue}{x \cdot z} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{z \cdot x} \]
      2. lower-*.f6460.5

        \[\leadsto \color{blue}{z \cdot x} \]
    5. Applied rewrites60.5%

      \[\leadsto \color{blue}{z \cdot x} \]

    if -0.0280000000000000006 < x < 3.5000000000000001e-38

    1. Initial program 99.9%

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

      \[\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--.f6476.1

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

      \[\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 rewrites74.4%

        \[\leadsto 1 \cdot y \]

      if 2.9e13 < x

      1. Initial program 92.5%

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

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

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

          \[\leadsto \left(z + \color{blue}{\left(\mathsf{neg}\left(y\right)\right)}\right) \cdot x \]
        3. remove-double-negN/A

          \[\leadsto \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(z\right)\right)\right)\right)} + \left(\mathsf{neg}\left(y\right)\right)\right) \cdot x \]
        4. mul-1-negN/A

          \[\leadsto \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot z}\right)\right) + \left(\mathsf{neg}\left(y\right)\right)\right) \cdot x \]
        5. distribute-neg-inN/A

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

          \[\leadsto \left(\mathsf{neg}\left(\color{blue}{\left(y + -1 \cdot z\right)}\right)\right) \cdot x \]
        7. lower-*.f64N/A

          \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\left(y + -1 \cdot z\right)\right)\right) \cdot x} \]
        8. +-commutativeN/A

          \[\leadsto \left(\mathsf{neg}\left(\color{blue}{\left(-1 \cdot z + y\right)}\right)\right) \cdot x \]
        9. distribute-neg-inN/A

          \[\leadsto \color{blue}{\left(\left(\mathsf{neg}\left(-1 \cdot z\right)\right) + \left(\mathsf{neg}\left(y\right)\right)\right)} \cdot x \]
        10. mul-1-negN/A

          \[\leadsto \left(\left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(z\right)\right)}\right)\right) + \left(\mathsf{neg}\left(y\right)\right)\right) \cdot x \]
        11. remove-double-negN/A

          \[\leadsto \left(\color{blue}{z} + \left(\mathsf{neg}\left(y\right)\right)\right) \cdot x \]
        12. unsub-negN/A

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

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

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

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

          \[\leadsto \left(-y\right) \cdot x \]
      8. Recombined 3 regimes into one program.
      9. Add Preprocessing

      Alternative 3: 85.0% accurate, 0.8× speedup?

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

        1. Initial program 94.7%

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

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

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

            \[\leadsto \left(z + \color{blue}{\left(\mathsf{neg}\left(y\right)\right)}\right) \cdot x \]
          3. remove-double-negN/A

            \[\leadsto \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(z\right)\right)\right)\right)} + \left(\mathsf{neg}\left(y\right)\right)\right) \cdot x \]
          4. mul-1-negN/A

            \[\leadsto \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot z}\right)\right) + \left(\mathsf{neg}\left(y\right)\right)\right) \cdot x \]
          5. distribute-neg-inN/A

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

            \[\leadsto \left(\mathsf{neg}\left(\color{blue}{\left(y + -1 \cdot z\right)}\right)\right) \cdot x \]
          7. lower-*.f64N/A

            \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\left(y + -1 \cdot z\right)\right)\right) \cdot x} \]
          8. +-commutativeN/A

            \[\leadsto \left(\mathsf{neg}\left(\color{blue}{\left(-1 \cdot z + y\right)}\right)\right) \cdot x \]
          9. distribute-neg-inN/A

            \[\leadsto \color{blue}{\left(\left(\mathsf{neg}\left(-1 \cdot z\right)\right) + \left(\mathsf{neg}\left(y\right)\right)\right)} \cdot x \]
          10. mul-1-negN/A

            \[\leadsto \left(\left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(z\right)\right)}\right)\right) + \left(\mathsf{neg}\left(y\right)\right)\right) \cdot x \]
          11. remove-double-negN/A

            \[\leadsto \left(\color{blue}{z} + \left(\mathsf{neg}\left(y\right)\right)\right) \cdot x \]
          12. unsub-negN/A

            \[\leadsto \color{blue}{\left(z - y\right)} \cdot x \]
          13. lower--.f6496.7

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

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

        if -0.409999999999999976 < x < 3.5000000000000001e-38

        1. Initial program 99.9%

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

          \[\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--.f6476.1

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

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

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

        Alternative 4: 85.0% accurate, 0.8× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(z - y\right) \cdot x\\ \mathbf{if}\;x \leq -0.41:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq 3.5 \cdot 10^{-38}:\\ \;\;\;\;\left(1 - x\right) \cdot y\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
        (FPCore (x y z)
         :precision binary64
         (let* ((t_0 (* (- z y) x)))
           (if (<= x -0.41) t_0 (if (<= x 3.5e-38) (* (- 1.0 x) y) t_0))))
        double code(double x, double y, double z) {
        	double t_0 = (z - y) * x;
        	double tmp;
        	if (x <= -0.41) {
        		tmp = t_0;
        	} else if (x <= 3.5e-38) {
        		tmp = (1.0 - x) * y;
        	} else {
        		tmp = t_0;
        	}
        	return tmp;
        }
        
        real(8) function code(x, y, z)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            real(8), intent (in) :: z
            real(8) :: t_0
            real(8) :: tmp
            t_0 = (z - y) * x
            if (x <= (-0.41d0)) then
                tmp = t_0
            else if (x <= 3.5d-38) then
                tmp = (1.0d0 - x) * y
            else
                tmp = t_0
            end if
            code = tmp
        end function
        
        public static double code(double x, double y, double z) {
        	double t_0 = (z - y) * x;
        	double tmp;
        	if (x <= -0.41) {
        		tmp = t_0;
        	} else if (x <= 3.5e-38) {
        		tmp = (1.0 - x) * y;
        	} else {
        		tmp = t_0;
        	}
        	return tmp;
        }
        
        def code(x, y, z):
        	t_0 = (z - y) * x
        	tmp = 0
        	if x <= -0.41:
        		tmp = t_0
        	elif x <= 3.5e-38:
        		tmp = (1.0 - x) * y
        	else:
        		tmp = t_0
        	return tmp
        
        function code(x, y, z)
        	t_0 = Float64(Float64(z - y) * x)
        	tmp = 0.0
        	if (x <= -0.41)
        		tmp = t_0;
        	elseif (x <= 3.5e-38)
        		tmp = Float64(Float64(1.0 - x) * y);
        	else
        		tmp = t_0;
        	end
        	return tmp
        end
        
        function tmp_2 = code(x, y, z)
        	t_0 = (z - y) * x;
        	tmp = 0.0;
        	if (x <= -0.41)
        		tmp = t_0;
        	elseif (x <= 3.5e-38)
        		tmp = (1.0 - x) * y;
        	else
        		tmp = t_0;
        	end
        	tmp_2 = tmp;
        end
        
        code[x_, y_, z_] := Block[{t$95$0 = N[(N[(z - y), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[x, -0.41], t$95$0, If[LessEqual[x, 3.5e-38], N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision], t$95$0]]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        t_0 := \left(z - y\right) \cdot x\\
        \mathbf{if}\;x \leq -0.41:\\
        \;\;\;\;t\_0\\
        
        \mathbf{elif}\;x \leq 3.5 \cdot 10^{-38}:\\
        \;\;\;\;\left(1 - x\right) \cdot y\\
        
        \mathbf{else}:\\
        \;\;\;\;t\_0\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if x < -0.409999999999999976 or 3.5000000000000001e-38 < x

          1. Initial program 94.7%

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

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

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

              \[\leadsto \left(z + \color{blue}{\left(\mathsf{neg}\left(y\right)\right)}\right) \cdot x \]
            3. remove-double-negN/A

              \[\leadsto \left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(z\right)\right)\right)\right)} + \left(\mathsf{neg}\left(y\right)\right)\right) \cdot x \]
            4. mul-1-negN/A

              \[\leadsto \left(\left(\mathsf{neg}\left(\color{blue}{-1 \cdot z}\right)\right) + \left(\mathsf{neg}\left(y\right)\right)\right) \cdot x \]
            5. distribute-neg-inN/A

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

              \[\leadsto \left(\mathsf{neg}\left(\color{blue}{\left(y + -1 \cdot z\right)}\right)\right) \cdot x \]
            7. lower-*.f64N/A

              \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\left(y + -1 \cdot z\right)\right)\right) \cdot x} \]
            8. +-commutativeN/A

              \[\leadsto \left(\mathsf{neg}\left(\color{blue}{\left(-1 \cdot z + y\right)}\right)\right) \cdot x \]
            9. distribute-neg-inN/A

              \[\leadsto \color{blue}{\left(\left(\mathsf{neg}\left(-1 \cdot z\right)\right) + \left(\mathsf{neg}\left(y\right)\right)\right)} \cdot x \]
            10. mul-1-negN/A

              \[\leadsto \left(\left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(z\right)\right)}\right)\right) + \left(\mathsf{neg}\left(y\right)\right)\right) \cdot x \]
            11. remove-double-negN/A

              \[\leadsto \left(\color{blue}{z} + \left(\mathsf{neg}\left(y\right)\right)\right) \cdot x \]
            12. unsub-negN/A

              \[\leadsto \color{blue}{\left(z - y\right)} \cdot x \]
            13. lower--.f6496.7

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

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

          if -0.409999999999999976 < x < 3.5000000000000001e-38

          1. Initial program 99.9%

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

            \[\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--.f6476.1

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

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

        Alternative 5: 76.0% accurate, 0.8× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(1 - x\right) \cdot y\\ \mathbf{if}\;y \leq -1.35 \cdot 10^{-132}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 3.5 \cdot 10^{-51}:\\ \;\;\;\;z \cdot x\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
        (FPCore (x y z)
         :precision binary64
         (let* ((t_0 (* (- 1.0 x) y)))
           (if (<= y -1.35e-132) t_0 (if (<= y 3.5e-51) (* z x) t_0))))
        double code(double x, double y, double z) {
        	double t_0 = (1.0 - x) * y;
        	double tmp;
        	if (y <= -1.35e-132) {
        		tmp = t_0;
        	} else if (y <= 3.5e-51) {
        		tmp = z * x;
        	} else {
        		tmp = t_0;
        	}
        	return tmp;
        }
        
        real(8) function code(x, y, z)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            real(8), intent (in) :: z
            real(8) :: t_0
            real(8) :: tmp
            t_0 = (1.0d0 - x) * y
            if (y <= (-1.35d-132)) then
                tmp = t_0
            else if (y <= 3.5d-51) then
                tmp = z * x
            else
                tmp = t_0
            end if
            code = tmp
        end function
        
        public static double code(double x, double y, double z) {
        	double t_0 = (1.0 - x) * y;
        	double tmp;
        	if (y <= -1.35e-132) {
        		tmp = t_0;
        	} else if (y <= 3.5e-51) {
        		tmp = z * x;
        	} else {
        		tmp = t_0;
        	}
        	return tmp;
        }
        
        def code(x, y, z):
        	t_0 = (1.0 - x) * y
        	tmp = 0
        	if y <= -1.35e-132:
        		tmp = t_0
        	elif y <= 3.5e-51:
        		tmp = z * x
        	else:
        		tmp = t_0
        	return tmp
        
        function code(x, y, z)
        	t_0 = Float64(Float64(1.0 - x) * y)
        	tmp = 0.0
        	if (y <= -1.35e-132)
        		tmp = t_0;
        	elseif (y <= 3.5e-51)
        		tmp = Float64(z * x);
        	else
        		tmp = t_0;
        	end
        	return tmp
        end
        
        function tmp_2 = code(x, y, z)
        	t_0 = (1.0 - x) * y;
        	tmp = 0.0;
        	if (y <= -1.35e-132)
        		tmp = t_0;
        	elseif (y <= 3.5e-51)
        		tmp = z * x;
        	else
        		tmp = t_0;
        	end
        	tmp_2 = tmp;
        end
        
        code[x_, y_, z_] := Block[{t$95$0 = N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -1.35e-132], t$95$0, If[LessEqual[y, 3.5e-51], N[(z * x), $MachinePrecision], t$95$0]]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        t_0 := \left(1 - x\right) \cdot y\\
        \mathbf{if}\;y \leq -1.35 \cdot 10^{-132}:\\
        \;\;\;\;t\_0\\
        
        \mathbf{elif}\;y \leq 3.5 \cdot 10^{-51}:\\
        \;\;\;\;z \cdot x\\
        
        \mathbf{else}:\\
        \;\;\;\;t\_0\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if y < -1.34999999999999995e-132 or 3.4999999999999997e-51 < y

          1. Initial program 94.9%

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

            \[\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--.f6480.9

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

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

          if -1.34999999999999995e-132 < y < 3.4999999999999997e-51

          1. Initial program 99.9%

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

            \[\leadsto \color{blue}{x \cdot z} \]
          4. Step-by-step derivation
            1. *-commutativeN/A

              \[\leadsto \color{blue}{z \cdot x} \]
            2. lower-*.f6475.9

              \[\leadsto \color{blue}{z \cdot x} \]
          5. Applied rewrites75.9%

            \[\leadsto \color{blue}{z \cdot x} \]
        3. Recombined 2 regimes into one program.
        4. Add Preprocessing

        Alternative 6: 61.1% accurate, 0.9× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -0.028:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;x \leq 3.5 \cdot 10^{-38}:\\ \;\;\;\;1 \cdot y\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \end{array} \]
        (FPCore (x y z)
         :precision binary64
         (if (<= x -0.028) (* z x) (if (<= x 3.5e-38) (* 1.0 y) (* z x))))
        double code(double x, double y, double z) {
        	double tmp;
        	if (x <= -0.028) {
        		tmp = z * x;
        	} else if (x <= 3.5e-38) {
        		tmp = 1.0 * y;
        	} else {
        		tmp = z * x;
        	}
        	return tmp;
        }
        
        real(8) function code(x, y, z)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            real(8), intent (in) :: z
            real(8) :: tmp
            if (x <= (-0.028d0)) then
                tmp = z * x
            else if (x <= 3.5d-38) then
                tmp = 1.0d0 * y
            else
                tmp = z * x
            end if
            code = tmp
        end function
        
        public static double code(double x, double y, double z) {
        	double tmp;
        	if (x <= -0.028) {
        		tmp = z * x;
        	} else if (x <= 3.5e-38) {
        		tmp = 1.0 * y;
        	} else {
        		tmp = z * x;
        	}
        	return tmp;
        }
        
        def code(x, y, z):
        	tmp = 0
        	if x <= -0.028:
        		tmp = z * x
        	elif x <= 3.5e-38:
        		tmp = 1.0 * y
        	else:
        		tmp = z * x
        	return tmp
        
        function code(x, y, z)
        	tmp = 0.0
        	if (x <= -0.028)
        		tmp = Float64(z * x);
        	elseif (x <= 3.5e-38)
        		tmp = Float64(1.0 * y);
        	else
        		tmp = Float64(z * x);
        	end
        	return tmp
        end
        
        function tmp_2 = code(x, y, z)
        	tmp = 0.0;
        	if (x <= -0.028)
        		tmp = z * x;
        	elseif (x <= 3.5e-38)
        		tmp = 1.0 * y;
        	else
        		tmp = z * x;
        	end
        	tmp_2 = tmp;
        end
        
        code[x_, y_, z_] := If[LessEqual[x, -0.028], N[(z * x), $MachinePrecision], If[LessEqual[x, 3.5e-38], N[(1.0 * y), $MachinePrecision], N[(z * x), $MachinePrecision]]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        \mathbf{if}\;x \leq -0.028:\\
        \;\;\;\;z \cdot x\\
        
        \mathbf{elif}\;x \leq 3.5 \cdot 10^{-38}:\\
        \;\;\;\;1 \cdot y\\
        
        \mathbf{else}:\\
        \;\;\;\;z \cdot x\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if x < -0.0280000000000000006 or 3.5000000000000001e-38 < x

          1. Initial program 94.7%

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

            \[\leadsto \color{blue}{x \cdot z} \]
          4. Step-by-step derivation
            1. *-commutativeN/A

              \[\leadsto \color{blue}{z \cdot x} \]
            2. lower-*.f6455.7

              \[\leadsto \color{blue}{z \cdot x} \]
          5. Applied rewrites55.7%

            \[\leadsto \color{blue}{z \cdot x} \]

          if -0.0280000000000000006 < x < 3.5000000000000001e-38

          1. Initial program 99.9%

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

            \[\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--.f6476.1

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

            \[\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 rewrites74.4%

              \[\leadsto 1 \cdot y \]
          8. Recombined 2 regimes into one program.
          9. Add Preprocessing

          Alternative 7: 40.3% accurate, 2.8× speedup?

          \[\begin{array}{l} \\ z \cdot x \end{array} \]
          (FPCore (x y z) :precision binary64 (* z x))
          double code(double x, double y, double z) {
          	return z * x;
          }
          
          real(8) function code(x, y, z)
              real(8), intent (in) :: x
              real(8), intent (in) :: y
              real(8), intent (in) :: z
              code = z * x
          end function
          
          public static double code(double x, double y, double z) {
          	return z * x;
          }
          
          def code(x, y, z):
          	return z * x
          
          function code(x, y, z)
          	return Float64(z * x)
          end
          
          function tmp = code(x, y, z)
          	tmp = z * x;
          end
          
          code[x_, y_, z_] := N[(z * x), $MachinePrecision]
          
          \begin{array}{l}
          
          \\
          z \cdot x
          \end{array}
          
          Derivation
          1. Initial program 96.8%

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

            \[\leadsto \color{blue}{x \cdot z} \]
          4. Step-by-step derivation
            1. *-commutativeN/A

              \[\leadsto \color{blue}{z \cdot x} \]
            2. lower-*.f6443.5

              \[\leadsto \color{blue}{z \cdot x} \]
          5. Applied rewrites43.5%

            \[\leadsto \color{blue}{z \cdot x} \]
          6. Add Preprocessing

          Developer Target 1: 100.0% accurate, 1.4× speedup?

          \[\begin{array}{l} \\ y - x \cdot \left(y - z\right) \end{array} \]
          (FPCore (x y z) :precision binary64 (- y (* x (- y z))))
          double code(double x, double y, double z) {
          	return y - (x * (y - z));
          }
          
          real(8) function code(x, y, z)
              real(8), intent (in) :: x
              real(8), intent (in) :: y
              real(8), intent (in) :: z
              code = y - (x * (y - z))
          end function
          
          public static double code(double x, double y, double z) {
          	return y - (x * (y - z));
          }
          
          def code(x, y, z):
          	return y - (x * (y - z))
          
          function code(x, y, z)
          	return Float64(y - Float64(x * Float64(y - z)))
          end
          
          function tmp = code(x, y, z)
          	tmp = y - (x * (y - z));
          end
          
          code[x_, y_, z_] := N[(y - N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
          
          \begin{array}{l}
          
          \\
          y - x \cdot \left(y - z\right)
          \end{array}
          

          Reproduce

          ?
          herbie shell --seed 2024249 
          (FPCore (x y z)
            :name "Diagrams.Color.HSV:lerp  from diagrams-contrib-1.3.0.5"
            :precision binary64
          
            :alt
            (! :herbie-platform default (- y (* x (- y z))))
          
            (+ (* (- 1.0 x) y) (* x z)))