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

Percentage Accurate: 100.0% → 100.0%
Time: 2.5s
Alternatives: 7
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 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: 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. Step-by-step derivation
    1. lift-+.f64N/A

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

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

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

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

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

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

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

Alternative 2: 98.7% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -8000000 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\

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


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

    1. Initial program 100.0%

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

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

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

      if -8e6 < z < 1

      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 \color{blue}{x + \left(y - x\right) \cdot z} \]
        2. lift--.f64N/A

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

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

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

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

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

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

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

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

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

      Alternative 3: 85.7% accurate, 0.6× speedup?

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

        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 \color{blue}{x + \left(y - x\right) \cdot z} \]
          2. lift--.f64N/A

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

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

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

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

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

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

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

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

          if -1.72e50 < y < 4.49999999999999962e-50

          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. Applied rewrites87.4%

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

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

          Alternative 4: 75.2% accurate, 0.6× speedup?

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

            1. Initial program 100.0%

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

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

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

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

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

                if -5.4999999999999999e220 < z < 1.8499999999999999e260

                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 \color{blue}{x + \left(y - x\right) \cdot z} \]
                  2. lift--.f64N/A

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

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

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

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

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

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

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

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

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

                Alternative 5: 61.2% accurate, 0.7× speedup?

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

                  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. Applied rewrites53.3%

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

                    if -5.19999999999999954e-4 < z < 3.1e-7

                    1. Initial program 100.0%

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

                      \[\leadsto \color{blue}{x} \]
                    4. Step-by-step derivation
                      1. Applied rewrites75.3%

                        \[\leadsto \color{blue}{x} \]
                    5. Recombined 2 regimes into one program.
                    6. Final simplification64.2%

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

                    Alternative 6: 75.5% accurate, 1.7× speedup?

                    \[\begin{array}{l} \\ \mathsf{fma}\left(y, z, x\right) \end{array} \]
                    (FPCore (x y z) :precision binary64 (fma y z x))
                    double code(double x, double y, double z) {
                    	return fma(y, z, x);
                    }
                    
                    function code(x, y, z)
                    	return fma(y, z, x)
                    end
                    
                    code[x_, y_, z_] := N[(y * z + x), $MachinePrecision]
                    
                    \begin{array}{l}
                    
                    \\
                    \mathsf{fma}\left(y, z, x\right)
                    \end{array}
                    
                    Derivation
                    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 \color{blue}{x + \left(y - x\right) \cdot z} \]
                      2. lift--.f64N/A

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

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

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

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

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

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

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

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

                      Alternative 7: 35.8% accurate, 12.0× speedup?

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

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

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

                          \[\leadsto \color{blue}{x} \]
                        2. Add Preprocessing

                        Reproduce

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