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

Percentage Accurate: 100.0% → 100.0%
Time: 3.5s
Alternatives: 7
Speedup: 1.0×

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);
}
real(8) function code(x, y, z)
    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);
}
real(8) function code(x, y, z)
    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, 0.1× 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. Step-by-step derivation
    1. +-commutative100.0%

      \[\leadsto \color{blue}{\left(y - x\right) \cdot z + x} \]
    2. fma-def100.0%

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

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

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

Alternative 2: 59.1% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := z \cdot \left(-x\right)\\ \mathbf{if}\;z \leq -1.8 \cdot 10^{+152}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -8.5 \cdot 10^{+131}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -3.5 \cdot 10^{+16}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.2 \cdot 10^{-155}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 2 \cdot 10^{-60}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 6400000000000:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 1.08 \cdot 10^{+70}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* z (- x))))
   (if (<= z -1.8e+152)
     t_0
     (if (<= z -8.5e+131)
       (* y z)
       (if (<= z -3.5e+16)
         t_0
         (if (<= z -1.2e-155)
           (* y z)
           (if (<= z 2e-60)
             x
             (if (<= z 6400000000000.0)
               (* y z)
               (if (<= z 1.08e+70) t_0 (* y z))))))))))
double code(double x, double y, double z) {
	double t_0 = z * -x;
	double tmp;
	if (z <= -1.8e+152) {
		tmp = t_0;
	} else if (z <= -8.5e+131) {
		tmp = y * z;
	} else if (z <= -3.5e+16) {
		tmp = t_0;
	} else if (z <= -1.2e-155) {
		tmp = y * z;
	} else if (z <= 2e-60) {
		tmp = x;
	} else if (z <= 6400000000000.0) {
		tmp = y * z;
	} else if (z <= 1.08e+70) {
		tmp = t_0;
	} else {
		tmp = y * z;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: tmp
    t_0 = z * -x
    if (z <= (-1.8d+152)) then
        tmp = t_0
    else if (z <= (-8.5d+131)) then
        tmp = y * z
    else if (z <= (-3.5d+16)) then
        tmp = t_0
    else if (z <= (-1.2d-155)) then
        tmp = y * z
    else if (z <= 2d-60) then
        tmp = x
    else if (z <= 6400000000000.0d0) then
        tmp = y * z
    else if (z <= 1.08d+70) then
        tmp = t_0
    else
        tmp = y * z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = z * -x;
	double tmp;
	if (z <= -1.8e+152) {
		tmp = t_0;
	} else if (z <= -8.5e+131) {
		tmp = y * z;
	} else if (z <= -3.5e+16) {
		tmp = t_0;
	} else if (z <= -1.2e-155) {
		tmp = y * z;
	} else if (z <= 2e-60) {
		tmp = x;
	} else if (z <= 6400000000000.0) {
		tmp = y * z;
	} else if (z <= 1.08e+70) {
		tmp = t_0;
	} else {
		tmp = y * z;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = z * -x
	tmp = 0
	if z <= -1.8e+152:
		tmp = t_0
	elif z <= -8.5e+131:
		tmp = y * z
	elif z <= -3.5e+16:
		tmp = t_0
	elif z <= -1.2e-155:
		tmp = y * z
	elif z <= 2e-60:
		tmp = x
	elif z <= 6400000000000.0:
		tmp = y * z
	elif z <= 1.08e+70:
		tmp = t_0
	else:
		tmp = y * z
	return tmp
function code(x, y, z)
	t_0 = Float64(z * Float64(-x))
	tmp = 0.0
	if (z <= -1.8e+152)
		tmp = t_0;
	elseif (z <= -8.5e+131)
		tmp = Float64(y * z);
	elseif (z <= -3.5e+16)
		tmp = t_0;
	elseif (z <= -1.2e-155)
		tmp = Float64(y * z);
	elseif (z <= 2e-60)
		tmp = x;
	elseif (z <= 6400000000000.0)
		tmp = Float64(y * z);
	elseif (z <= 1.08e+70)
		tmp = t_0;
	else
		tmp = Float64(y * z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = z * -x;
	tmp = 0.0;
	if (z <= -1.8e+152)
		tmp = t_0;
	elseif (z <= -8.5e+131)
		tmp = y * z;
	elseif (z <= -3.5e+16)
		tmp = t_0;
	elseif (z <= -1.2e-155)
		tmp = y * z;
	elseif (z <= 2e-60)
		tmp = x;
	elseif (z <= 6400000000000.0)
		tmp = y * z;
	elseif (z <= 1.08e+70)
		tmp = t_0;
	else
		tmp = y * z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * (-x)), $MachinePrecision]}, If[LessEqual[z, -1.8e+152], t$95$0, If[LessEqual[z, -8.5e+131], N[(y * z), $MachinePrecision], If[LessEqual[z, -3.5e+16], t$95$0, If[LessEqual[z, -1.2e-155], N[(y * z), $MachinePrecision], If[LessEqual[z, 2e-60], x, If[LessEqual[z, 6400000000000.0], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.08e+70], t$95$0, N[(y * z), $MachinePrecision]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := z \cdot \left(-x\right)\\
\mathbf{if}\;z \leq -1.8 \cdot 10^{+152}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;z \leq -8.5 \cdot 10^{+131}:\\
\;\;\;\;y \cdot z\\

\mathbf{elif}\;z \leq -3.5 \cdot 10^{+16}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;z \leq -1.2 \cdot 10^{-155}:\\
\;\;\;\;y \cdot z\\

\mathbf{elif}\;z \leq 2 \cdot 10^{-60}:\\
\;\;\;\;x\\

\mathbf{elif}\;z \leq 6400000000000:\\
\;\;\;\;y \cdot z\\

\mathbf{elif}\;z \leq 1.08 \cdot 10^{+70}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -1.7999999999999999e152 or -8.50000000000000063e131 < z < -3.5e16 or 6.4e12 < z < 1.0799999999999999e70

    1. Initial program 99.9%

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(z \cdot x\right)} \]
    4. Step-by-step derivation
      1. mul-1-neg65.2%

        \[\leadsto \color{blue}{-z \cdot x} \]
      2. distribute-rgt-neg-out65.2%

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

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

    if -1.7999999999999999e152 < z < -8.50000000000000063e131 or -3.5e16 < z < -1.2e-155 or 1.9999999999999999e-60 < z < 6.4e12 or 1.0799999999999999e70 < z

    1. Initial program 100.0%

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

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

      \[\leadsto \color{blue}{y \cdot z} \]
    4. Step-by-step derivation
      1. *-commutative59.7%

        \[\leadsto \color{blue}{z \cdot y} \]
    5. Simplified59.7%

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

    if -1.2e-155 < z < 1.9999999999999999e-60

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{x} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification68.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.8 \cdot 10^{+152}:\\ \;\;\;\;z \cdot \left(-x\right)\\ \mathbf{elif}\;z \leq -8.5 \cdot 10^{+131}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -3.5 \cdot 10^{+16}:\\ \;\;\;\;z \cdot \left(-x\right)\\ \mathbf{elif}\;z \leq -1.2 \cdot 10^{-155}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 2 \cdot 10^{-60}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 6400000000000:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 1.08 \cdot 10^{+70}:\\ \;\;\;\;z \cdot \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]

Alternative 3: 82.4% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -1.2 \cdot 10^{-155} \lor \neg \left(z \leq 1.26 \cdot 10^{-52}\right):\\ \;\;\;\;\left(y - x\right) \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= z -1.2e-155) (not (<= z 1.26e-52))) (* (- y x) z) x))
double code(double x, double y, double z) {
	double tmp;
	if ((z <= -1.2e-155) || !(z <= 1.26e-52)) {
		tmp = (y - x) * z;
	} else {
		tmp = x;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((z <= (-1.2d-155)) .or. (.not. (z <= 1.26d-52))) then
        tmp = (y - x) * z
    else
        tmp = x
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((z <= -1.2e-155) || !(z <= 1.26e-52)) {
		tmp = (y - x) * z;
	} else {
		tmp = x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (z <= -1.2e-155) or not (z <= 1.26e-52):
		tmp = (y - x) * z
	else:
		tmp = x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((z <= -1.2e-155) || !(z <= 1.26e-52))
		tmp = Float64(Float64(y - x) * z);
	else
		tmp = x;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((z <= -1.2e-155) || ~((z <= 1.26e-52)))
		tmp = (y - x) * z;
	else
		tmp = x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.2e-155], N[Not[LessEqual[z, 1.26e-52]], $MachinePrecision]], N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision], x]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.2 \cdot 10^{-155} \lor \neg \left(z \leq 1.26 \cdot 10^{-52}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\

\mathbf{else}:\\
\;\;\;\;x\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -1.2e-155 or 1.25999999999999996e-52 < z

    1. Initial program 100.0%

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

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

    if -1.2e-155 < z < 1.25999999999999996e-52

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification85.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.2 \cdot 10^{-155} \lor \neg \left(z \leq 1.26 \cdot 10^{-52}\right):\\ \;\;\;\;\left(y - x\right) \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]

Alternative 4: 98.9% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 2.4 \cdot 10^{-6}\right):\\ \;\;\;\;\left(y - x\right) \cdot z\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= z -1.0) (not (<= z 2.4e-6))) (* (- y x) z) (+ x (* y z))))
double code(double x, double y, double z) {
	double tmp;
	if ((z <= -1.0) || !(z <= 2.4e-6)) {
		tmp = (y - x) * z;
	} else {
		tmp = x + (y * z);
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((z <= (-1.0d0)) .or. (.not. (z <= 2.4d-6))) then
        tmp = (y - x) * z
    else
        tmp = x + (y * z)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((z <= -1.0) || !(z <= 2.4e-6)) {
		tmp = (y - x) * z;
	} else {
		tmp = x + (y * z);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (z <= -1.0) or not (z <= 2.4e-6):
		tmp = (y - x) * z
	else:
		tmp = x + (y * z)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((z <= -1.0) || !(z <= 2.4e-6))
		tmp = Float64(Float64(y - x) * z);
	else
		tmp = Float64(x + Float64(y * z));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((z <= -1.0) || ~((z <= 2.4e-6)))
		tmp = (y - x) * z;
	else
		tmp = x + (y * z);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 2.4e-6]], $MachinePrecision]], N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -1 or 2.3999999999999999e-6 < z

    1. Initial program 100.0%

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

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

    if -1 < z < 2.3999999999999999e-6

    1. Initial program 100.0%

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

      \[\leadsto x + \color{blue}{y \cdot z} \]
    3. Step-by-step derivation
      1. *-commutative32.9%

        \[\leadsto \color{blue}{z \cdot y} \]
    4. Simplified98.8%

      \[\leadsto x + \color{blue}{z \cdot y} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 2.4 \cdot 10^{-6}\right):\\ \;\;\;\;\left(y - x\right) \cdot z\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot z\\ \end{array} \]

Alternative 5: 59.1% accurate, 1.0× speedup?

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

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

\mathbf{elif}\;z \leq 1.6 \cdot 10^{-52}:\\
\;\;\;\;x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -1.2e-155 or 1.60000000000000005e-52 < z

    1. Initial program 100.0%

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

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

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

        \[\leadsto \color{blue}{z \cdot y} \]
    5. Simplified52.4%

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

    if -1.2e-155 < z < 1.60000000000000005e-52

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification62.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.2 \cdot 10^{-155}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 1.6 \cdot 10^{-52}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]

Alternative 6: 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);
}
real(8) function code(x, y, z)
    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}
Derivation
  1. Initial program 100.0%

    \[x + \left(y - x\right) \cdot z \]
  2. Final simplification100.0%

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

Alternative 7: 35.9% accurate, 7.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;
}
real(8) function code(x, y, z)
    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. Taylor expanded in z around 0 36.7%

    \[\leadsto \color{blue}{x} \]
  3. Final simplification36.7%

    \[\leadsto x \]

Reproduce

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