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

Percentage Accurate: 98.1% → 100.0%
Time: 3.2s
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);
}
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 = ((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: 98.1% 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);
}
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 = ((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 98.0%

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

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

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

Alternative 2: 98.8% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -44000 \lor \neg \left(x \leq 2.8 \cdot 10^{-5}\right):\\ \;\;\;\;\left(z - y\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, x, y\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= x -44000.0) (not (<= x 2.8e-5))) (* (- z y) x) (fma z x y)))
double code(double x, double y, double z) {
	double tmp;
	if ((x <= -44000.0) || !(x <= 2.8e-5)) {
		tmp = (z - y) * x;
	} else {
		tmp = fma(z, x, y);
	}
	return tmp;
}
function code(x, y, z)
	tmp = 0.0
	if ((x <= -44000.0) || !(x <= 2.8e-5))
		tmp = Float64(Float64(z - y) * x);
	else
		tmp = fma(z, x, y);
	end
	return tmp
end
code[x_, y_, z_] := If[Or[LessEqual[x, -44000.0], N[Not[LessEqual[x, 2.8e-5]], $MachinePrecision]], N[(N[(z - y), $MachinePrecision] * x), $MachinePrecision], N[(z * x + y), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -44000 \lor \neg \left(x \leq 2.8 \cdot 10^{-5}\right):\\
\;\;\;\;\left(z - y\right) \cdot x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -44000 or 2.79999999999999996e-5 < x

    1. Initial program 96.2%

      \[\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. Applied rewrites98.6%

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

      if -44000 < x < 2.79999999999999996e-5

      1. Initial program 100.0%

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

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

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

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

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

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

      Alternative 3: 86.9% accurate, 0.8× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -5.5 \cdot 10^{-41} \lor \neg \left(z \leq 0.235\right):\\ \;\;\;\;\mathsf{fma}\left(z, x, y\right)\\ \mathbf{else}:\\ \;\;\;\;\left(1 - x\right) \cdot y\\ \end{array} \end{array} \]
      (FPCore (x y z)
       :precision binary64
       (if (or (<= z -5.5e-41) (not (<= z 0.235))) (fma z x y) (* (- 1.0 x) y)))
      double code(double x, double y, double z) {
      	double tmp;
      	if ((z <= -5.5e-41) || !(z <= 0.235)) {
      		tmp = fma(z, x, y);
      	} else {
      		tmp = (1.0 - x) * y;
      	}
      	return tmp;
      }
      
      function code(x, y, z)
      	tmp = 0.0
      	if ((z <= -5.5e-41) || !(z <= 0.235))
      		tmp = fma(z, x, y);
      	else
      		tmp = Float64(Float64(1.0 - x) * y);
      	end
      	return tmp
      end
      
      code[x_, y_, z_] := If[Or[LessEqual[z, -5.5e-41], N[Not[LessEqual[z, 0.235]], $MachinePrecision]], N[(z * x + y), $MachinePrecision], N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;z \leq -5.5 \cdot 10^{-41} \lor \neg \left(z \leq 0.235\right):\\
      \;\;\;\;\mathsf{fma}\left(z, x, y\right)\\
      
      \mathbf{else}:\\
      \;\;\;\;\left(1 - x\right) \cdot y\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if z < -5.50000000000000022e-41 or 0.23499999999999999 < z

        1. Initial program 96.4%

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

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

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

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

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

          if -5.50000000000000022e-41 < z < 0.23499999999999999

          1. Initial program 100.0%

            \[\left(1 - x\right) \cdot y + x \cdot z \]
          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. Applied rewrites87.7%

              \[\leadsto \color{blue}{\left(1 - x\right) \cdot y} \]
          5. Recombined 2 regimes into one program.
          6. Final simplification89.8%

            \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -5.5 \cdot 10^{-41} \lor \neg \left(z \leq 0.235\right):\\ \;\;\;\;\mathsf{fma}\left(z, x, y\right)\\ \mathbf{else}:\\ \;\;\;\;\left(1 - x\right) \cdot y\\ \end{array} \]
          7. Add Preprocessing

          Alternative 4: 59.5% accurate, 0.9× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -9 \cdot 10^{-55} \lor \neg \left(x \leq 1.2 \cdot 10^{-144}\right):\\ \;\;\;\;z \cdot x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \end{array} \]
          (FPCore (x y z)
           :precision binary64
           (if (or (<= x -9e-55) (not (<= x 1.2e-144))) (* z x) y))
          double code(double x, double y, double z) {
          	double tmp;
          	if ((x <= -9e-55) || !(x <= 1.2e-144)) {
          		tmp = z * x;
          	} else {
          		tmp = 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, z)
          use fmin_fmax_functions
              real(8), intent (in) :: x
              real(8), intent (in) :: y
              real(8), intent (in) :: z
              real(8) :: tmp
              if ((x <= (-9d-55)) .or. (.not. (x <= 1.2d-144))) then
                  tmp = z * x
              else
                  tmp = y
              end if
              code = tmp
          end function
          
          public static double code(double x, double y, double z) {
          	double tmp;
          	if ((x <= -9e-55) || !(x <= 1.2e-144)) {
          		tmp = z * x;
          	} else {
          		tmp = y;
          	}
          	return tmp;
          }
          
          def code(x, y, z):
          	tmp = 0
          	if (x <= -9e-55) or not (x <= 1.2e-144):
          		tmp = z * x
          	else:
          		tmp = y
          	return tmp
          
          function code(x, y, z)
          	tmp = 0.0
          	if ((x <= -9e-55) || !(x <= 1.2e-144))
          		tmp = Float64(z * x);
          	else
          		tmp = y;
          	end
          	return tmp
          end
          
          function tmp_2 = code(x, y, z)
          	tmp = 0.0;
          	if ((x <= -9e-55) || ~((x <= 1.2e-144)))
          		tmp = z * x;
          	else
          		tmp = y;
          	end
          	tmp_2 = tmp;
          end
          
          code[x_, y_, z_] := If[Or[LessEqual[x, -9e-55], N[Not[LessEqual[x, 1.2e-144]], $MachinePrecision]], N[(z * x), $MachinePrecision], y]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;x \leq -9 \cdot 10^{-55} \lor \neg \left(x \leq 1.2 \cdot 10^{-144}\right):\\
          \;\;\;\;z \cdot x\\
          
          \mathbf{else}:\\
          \;\;\;\;y\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if x < -8.99999999999999941e-55 or 1.19999999999999997e-144 < x

            1. Initial program 97.0%

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

              \[\leadsto \color{blue}{x \cdot z} \]
            4. Step-by-step derivation
              1. Applied rewrites56.9%

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

              if -8.99999999999999941e-55 < x < 1.19999999999999997e-144

              1. Initial program 100.0%

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

                \[\leadsto \color{blue}{y} \]
              4. Step-by-step derivation
                1. Applied rewrites80.8%

                  \[\leadsto \color{blue}{y} \]
              5. Recombined 2 regimes into one program.
              6. Final simplification65.1%

                \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -9 \cdot 10^{-55} \lor \neg \left(x \leq 1.2 \cdot 10^{-144}\right):\\ \;\;\;\;z \cdot x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
              7. Add Preprocessing

              Alternative 5: 75.4% accurate, 1.2× speedup?

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

                1. Initial program 98.7%

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

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

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

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

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

                  if 1.1999999999999999e245 < y

                  1. Initial program 87.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. Applied rewrites81.6%

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

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

                        \[\leadsto \left(-y\right) \cdot x \]
                    4. Recombined 2 regimes into one program.
                    5. Add Preprocessing

                    Alternative 6: 76.0% accurate, 2.4× speedup?

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

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

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

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

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

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

                      Alternative 7: 35.8% accurate, 17.0× speedup?

                      \[\begin{array}{l} \\ y \end{array} \]
                      (FPCore (x y z) :precision binary64 y)
                      double code(double x, double y, double z) {
                      	return 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 = y
                      end function
                      
                      public static double code(double x, double y, double z) {
                      	return y;
                      }
                      
                      def code(x, y, z):
                      	return y
                      
                      function code(x, y, z)
                      	return y
                      end
                      
                      function tmp = code(x, y, z)
                      	tmp = y;
                      end
                      
                      code[x_, y_, z_] := y
                      
                      \begin{array}{l}
                      
                      \\
                      y
                      \end{array}
                      
                      Derivation
                      1. Initial program 98.0%

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

                        \[\leadsto \color{blue}{y} \]
                      4. Step-by-step derivation
                        1. Applied rewrites34.6%

                          \[\leadsto \color{blue}{y} \]
                        2. 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));
                        }
                        
                        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 = 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 2025018 
                        (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)))