Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B

Percentage Accurate: 100.0% → 100.0%
Time: 5.2s
Alternatives: 6
Speedup: 1.2×

Specification

?
\[\begin{array}{l} \\ x + \left(y - x\right) \cdot z \end{array} \]
(FPCore (x y z) :precision binary64 (+ x (* (- y x) z)))
double code(double x, double y, double z) {
	return 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 = x + ((y - x) * z)
end function
public static double code(double x, double y, double z) {
	return x + ((y - x) * z);
}
def code(x, y, z):
	return x + ((y - x) * z)
function code(x, y, z)
	return Float64(x + Float64(Float64(y - x) * z))
end
function tmp = code(x, y, z)
	tmp = x + ((y - x) * z);
end
code[x_, y_, z_] := N[(x + N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x + \left(y - x\right) \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 6 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ x + \left(y - x\right) \cdot z \end{array} \]
(FPCore (x y z) :precision binary64 (+ x (* (- y x) z)))
double code(double x, double y, double z) {
	return 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 = x + ((y - x) * z)
end function
public static double code(double x, double y, double z) {
	return x + ((y - x) * z);
}
def code(x, y, z):
	return x + ((y - x) * z)
function code(x, y, z)
	return Float64(x + Float64(Float64(y - x) * z))
end
function tmp = code(x, y, z)
	tmp = x + ((y - x) * z);
end
code[x_, y_, z_] := N[(x + N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

Alternative 1: 100.0% accurate, 1.2× speedup?

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

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

    \[x + \left(y - x\right) \cdot z \]
  2. Add Preprocessing
  3. Applied rewrites100.0%

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

Alternative 2: 54.4% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1.66 \cdot 10^{-44}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;y \leq -3 \cdot 10^{-305}:\\ \;\;\;\;1 \cdot x\\ \mathbf{elif}\;y \leq 4.05 \cdot 10^{-25}:\\ \;\;\;\;\left(-z\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;z \cdot y\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y -1.66e-44)
   (* z y)
   (if (<= y -3e-305) (* 1.0 x) (if (<= y 4.05e-25) (* (- z) x) (* z y)))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= -1.66e-44) {
		tmp = z * y;
	} else if (y <= -3e-305) {
		tmp = 1.0 * x;
	} else if (y <= 4.05e-25) {
		tmp = -z * x;
	} else {
		tmp = z * 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 (y <= (-1.66d-44)) then
        tmp = z * y
    else if (y <= (-3d-305)) then
        tmp = 1.0d0 * x
    else if (y <= 4.05d-25) then
        tmp = -z * x
    else
        tmp = z * y
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= -1.66e-44) {
		tmp = z * y;
	} else if (y <= -3e-305) {
		tmp = 1.0 * x;
	} else if (y <= 4.05e-25) {
		tmp = -z * x;
	} else {
		tmp = z * y;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= -1.66e-44:
		tmp = z * y
	elif y <= -3e-305:
		tmp = 1.0 * x
	elif y <= 4.05e-25:
		tmp = -z * x
	else:
		tmp = z * y
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= -1.66e-44)
		tmp = Float64(z * y);
	elseif (y <= -3e-305)
		tmp = Float64(1.0 * x);
	elseif (y <= 4.05e-25)
		tmp = Float64(Float64(-z) * x);
	else
		tmp = Float64(z * y);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= -1.66e-44)
		tmp = z * y;
	elseif (y <= -3e-305)
		tmp = 1.0 * x;
	elseif (y <= 4.05e-25)
		tmp = -z * x;
	else
		tmp = z * y;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, -1.66e-44], N[(z * y), $MachinePrecision], If[LessEqual[y, -3e-305], N[(1.0 * x), $MachinePrecision], If[LessEqual[y, 4.05e-25], N[((-z) * x), $MachinePrecision], N[(z * y), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.66 \cdot 10^{-44}:\\
\;\;\;\;z \cdot y\\

\mathbf{elif}\;y \leq -3 \cdot 10^{-305}:\\
\;\;\;\;1 \cdot x\\

\mathbf{elif}\;y \leq 4.05 \cdot 10^{-25}:\\
\;\;\;\;\left(-z\right) \cdot x\\

\mathbf{else}:\\
\;\;\;\;z \cdot y\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -1.6600000000000001e-44 or 4.05000000000000001e-25 < y

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{z \cdot y} \]
      2. lower-*.f6471.2

        \[\leadsto \color{blue}{z \cdot y} \]
    5. Applied rewrites71.2%

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

    if -1.6600000000000001e-44 < y < -3.0000000000000001e-305

    1. Initial program 100.0%

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

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

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

        \[\leadsto \color{blue}{\left(1 + -1 \cdot z\right) \cdot x} \]
      3. fp-cancel-sign-sub-invN/A

        \[\leadsto \color{blue}{\left(1 - \left(\mathsf{neg}\left(-1\right)\right) \cdot z\right)} \cdot x \]
      4. metadata-evalN/A

        \[\leadsto \left(1 - \color{blue}{1} \cdot z\right) \cdot x \]
      5. *-lft-identityN/A

        \[\leadsto \left(1 - \color{blue}{z}\right) \cdot x \]
      6. lower--.f6490.5

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

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

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

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

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

          \[\leadsto 1 \cdot x \]

        if -3.0000000000000001e-305 < y < 4.05000000000000001e-25

        1. Initial program 100.0%

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

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

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

            \[\leadsto \color{blue}{\left(1 + -1 \cdot z\right) \cdot x} \]
          3. fp-cancel-sign-sub-invN/A

            \[\leadsto \color{blue}{\left(1 - \left(\mathsf{neg}\left(-1\right)\right) \cdot z\right)} \cdot x \]
          4. metadata-evalN/A

            \[\leadsto \left(1 - \color{blue}{1} \cdot z\right) \cdot x \]
          5. *-lft-identityN/A

            \[\leadsto \left(1 - \color{blue}{z}\right) \cdot x \]
          6. lower--.f6494.5

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

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

          \[\leadsto \left(-1 \cdot z\right) \cdot x \]
        7. Step-by-step derivation
          1. Applied rewrites58.6%

            \[\leadsto \left(-z\right) \cdot x \]
        8. Recombined 3 regimes into one program.
        9. Final simplification68.1%

          \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.66 \cdot 10^{-44}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;y \leq -3 \cdot 10^{-305}:\\ \;\;\;\;1 \cdot x\\ \mathbf{elif}\;y \leq 4.05 \cdot 10^{-25}:\\ \;\;\;\;\left(-z\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;z \cdot y\\ \end{array} \]
        10. Add Preprocessing

        Alternative 3: 77.7% accurate, 0.6× speedup?

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

          1. Initial program 100.0%

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

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

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

              \[\leadsto \color{blue}{\left(1 + -1 \cdot z\right) \cdot x} \]
            3. fp-cancel-sign-sub-invN/A

              \[\leadsto \color{blue}{\left(1 - \left(\mathsf{neg}\left(-1\right)\right) \cdot z\right)} \cdot x \]
            4. metadata-evalN/A

              \[\leadsto \left(1 - \color{blue}{1} \cdot z\right) \cdot x \]
            5. *-lft-identityN/A

              \[\leadsto \left(1 - \color{blue}{z}\right) \cdot x \]
            6. lower--.f6435.1

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

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

            \[\leadsto \left(-1 \cdot z\right) \cdot x \]
          7. Step-by-step derivation
            1. Applied rewrites20.6%

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

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

                \[\leadsto 1 \cdot x \]
              2. Taylor expanded in z around inf

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

                  \[\leadsto \color{blue}{z \cdot \left(y - x\right)} \]
                2. lower--.f6483.8

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

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

              if -2.8499999999999999e-9 < y < 3.00000000000000021e-109

              1. Initial program 100.0%

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

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

                  \[\leadsto x + \color{blue}{\frac{y \cdot y - x \cdot x}{y + x}} \cdot z \]
                3. difference-of-squaresN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                  \[\leadsto \color{blue}{\mathsf{fma}\left(-1 \cdot z, x, x\right)} \]
                7. mul-1-negN/A

                  \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{neg}\left(z\right)}, x, x\right) \]
                8. lower-neg.f6492.6

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

                \[\leadsto \color{blue}{\mathsf{fma}\left(-z, x, x\right)} \]
            4. Recombined 2 regimes into one program.
            5. Final simplification87.7%

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

            Alternative 4: 75.4% accurate, 0.6× speedup?

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

              1. Initial program 100.0%

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

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

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

                  \[\leadsto \color{blue}{z \cdot y} \]
              5. Applied rewrites82.9%

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

              if -1.01999999999999998e99 < y < 2.2000000000000001e55

              1. Initial program 100.0%

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

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

                  \[\leadsto x + \color{blue}{\frac{y \cdot y - x \cdot x}{y + x}} \cdot z \]
                3. difference-of-squaresN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                  \[\leadsto \color{blue}{\mathsf{fma}\left(-1 \cdot z, x, x\right)} \]
                7. mul-1-negN/A

                  \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{neg}\left(z\right)}, x, x\right) \]
                8. lower-neg.f6485.3

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

                \[\leadsto \color{blue}{\mathsf{fma}\left(-z, x, x\right)} \]
            3. Recombined 2 regimes into one program.
            4. Final simplification84.4%

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

            Alternative 5: 55.3% accurate, 0.7× speedup?

            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1.66 \cdot 10^{-44} \lor \neg \left(y \leq 2.3 \cdot 10^{-87}\right):\\ \;\;\;\;z \cdot y\\ \mathbf{else}:\\ \;\;\;\;1 \cdot x\\ \end{array} \end{array} \]
            (FPCore (x y z)
             :precision binary64
             (if (or (<= y -1.66e-44) (not (<= y 2.3e-87))) (* z y) (* 1.0 x)))
            double code(double x, double y, double z) {
            	double tmp;
            	if ((y <= -1.66e-44) || !(y <= 2.3e-87)) {
            		tmp = z * y;
            	} else {
            		tmp = 1.0 * x;
            	}
            	return tmp;
            }
            
            module fmin_fmax_functions
                implicit none
                private
                public fmax
                public fmin
            
                interface fmax
                    module procedure fmax88
                    module procedure fmax44
                    module procedure fmax84
                    module procedure fmax48
                end interface
                interface fmin
                    module procedure fmin88
                    module procedure fmin44
                    module procedure fmin84
                    module procedure fmin48
                end interface
            contains
                real(8) function fmax88(x, y) result (res)
                    real(8), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                end function
                real(4) function fmax44(x, y) result (res)
                    real(4), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                end function
                real(8) function fmax84(x, y) result(res)
                    real(8), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                end function
                real(8) function fmax48(x, y) result(res)
                    real(4), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                end function
                real(8) function fmin88(x, y) result (res)
                    real(8), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                end function
                real(4) function fmin44(x, y) result (res)
                    real(4), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                end function
                real(8) function fmin84(x, y) result(res)
                    real(8), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                end function
                real(8) function fmin48(x, y) result(res)
                    real(4), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                end function
            end module
            
            real(8) function code(x, y, z)
            use fmin_fmax_functions
                real(8), intent (in) :: x
                real(8), intent (in) :: y
                real(8), intent (in) :: z
                real(8) :: tmp
                if ((y <= (-1.66d-44)) .or. (.not. (y <= 2.3d-87))) then
                    tmp = z * y
                else
                    tmp = 1.0d0 * x
                end if
                code = tmp
            end function
            
            public static double code(double x, double y, double z) {
            	double tmp;
            	if ((y <= -1.66e-44) || !(y <= 2.3e-87)) {
            		tmp = z * y;
            	} else {
            		tmp = 1.0 * x;
            	}
            	return tmp;
            }
            
            def code(x, y, z):
            	tmp = 0
            	if (y <= -1.66e-44) or not (y <= 2.3e-87):
            		tmp = z * y
            	else:
            		tmp = 1.0 * x
            	return tmp
            
            function code(x, y, z)
            	tmp = 0.0
            	if ((y <= -1.66e-44) || !(y <= 2.3e-87))
            		tmp = Float64(z * y);
            	else
            		tmp = Float64(1.0 * x);
            	end
            	return tmp
            end
            
            function tmp_2 = code(x, y, z)
            	tmp = 0.0;
            	if ((y <= -1.66e-44) || ~((y <= 2.3e-87)))
            		tmp = z * y;
            	else
            		tmp = 1.0 * x;
            	end
            	tmp_2 = tmp;
            end
            
            code[x_, y_, z_] := If[Or[LessEqual[y, -1.66e-44], N[Not[LessEqual[y, 2.3e-87]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]
            
            \begin{array}{l}
            
            \\
            \begin{array}{l}
            \mathbf{if}\;y \leq -1.66 \cdot 10^{-44} \lor \neg \left(y \leq 2.3 \cdot 10^{-87}\right):\\
            \;\;\;\;z \cdot y\\
            
            \mathbf{else}:\\
            \;\;\;\;1 \cdot x\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 2 regimes
            2. if y < -1.6600000000000001e-44 or 2.3000000000000001e-87 < y

              1. Initial program 100.0%

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

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

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

                  \[\leadsto \color{blue}{z \cdot y} \]
              5. Applied rewrites68.9%

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

              if -1.6600000000000001e-44 < y < 2.3000000000000001e-87

              1. Initial program 100.0%

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

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

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

                  \[\leadsto \color{blue}{\left(1 + -1 \cdot z\right) \cdot x} \]
                3. fp-cancel-sign-sub-invN/A

                  \[\leadsto \color{blue}{\left(1 - \left(\mathsf{neg}\left(-1\right)\right) \cdot z\right)} \cdot x \]
                4. metadata-evalN/A

                  \[\leadsto \left(1 - \color{blue}{1} \cdot z\right) \cdot x \]
                5. *-lft-identityN/A

                  \[\leadsto \left(1 - \color{blue}{z}\right) \cdot x \]
                6. lower--.f6494.2

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

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

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

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

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

                    \[\leadsto 1 \cdot x \]
                4. Recombined 2 regimes into one program.
                5. Final simplification64.5%

                  \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.66 \cdot 10^{-44} \lor \neg \left(y \leq 2.3 \cdot 10^{-87}\right):\\ \;\;\;\;z \cdot y\\ \mathbf{else}:\\ \;\;\;\;1 \cdot x\\ \end{array} \]
                6. Add Preprocessing

                Alternative 6: 42.4% accurate, 2.0× speedup?

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

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

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

                    \[\leadsto \color{blue}{z \cdot y} \]
                  2. lower-*.f6442.1

                    \[\leadsto \color{blue}{z \cdot y} \]
                5. Applied rewrites42.1%

                  \[\leadsto \color{blue}{z \cdot y} \]
                6. Final simplification42.1%

                  \[\leadsto z \cdot y \]
                7. Add Preprocessing

                Reproduce

                ?
                herbie shell --seed 2024359 
                (FPCore (x y z)
                  :name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
                  :precision binary64
                  (+ x (* (- y x) z)))