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

Percentage Accurate: 100.0% → 100.0%
Time: 4.3s
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.8% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := z \cdot \left(-x\right)\\ \mathbf{if}\;z \leq -6.6 \cdot 10^{+247}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -5 \cdot 10^{+189}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -2.9 \cdot 10^{+67}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -3.5 \cdot 10^{-65}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 1.12 \cdot 10^{-175}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.1 \cdot 10^{-123}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 4 \cdot 10^{-20}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 3.4 \cdot 10^{+80} \lor \neg \left(z \leq 8 \cdot 10^{+237}\right) \land z \leq 9.5 \cdot 10^{+261}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* z (- x))))
   (if (<= z -6.6e+247)
     t_0
     (if (<= z -5e+189)
       (* y z)
       (if (<= z -2.9e+67)
         t_0
         (if (<= z -3.5e-65)
           (* y z)
           (if (<= z 1.12e-175)
             x
             (if (<= z 1.1e-123)
               (* y z)
               (if (<= z 4e-20)
                 x
                 (if (or (<= z 3.4e+80)
                         (and (not (<= z 8e+237)) (<= z 9.5e+261)))
                   (* y z)
                   t_0))))))))))
double code(double x, double y, double z) {
	double t_0 = z * -x;
	double tmp;
	if (z <= -6.6e+247) {
		tmp = t_0;
	} else if (z <= -5e+189) {
		tmp = y * z;
	} else if (z <= -2.9e+67) {
		tmp = t_0;
	} else if (z <= -3.5e-65) {
		tmp = y * z;
	} else if (z <= 1.12e-175) {
		tmp = x;
	} else if (z <= 1.1e-123) {
		tmp = y * z;
	} else if (z <= 4e-20) {
		tmp = x;
	} else if ((z <= 3.4e+80) || (!(z <= 8e+237) && (z <= 9.5e+261))) {
		tmp = y * z;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: tmp
    t_0 = z * -x
    if (z <= (-6.6d+247)) then
        tmp = t_0
    else if (z <= (-5d+189)) then
        tmp = y * z
    else if (z <= (-2.9d+67)) then
        tmp = t_0
    else if (z <= (-3.5d-65)) then
        tmp = y * z
    else if (z <= 1.12d-175) then
        tmp = x
    else if (z <= 1.1d-123) then
        tmp = y * z
    else if (z <= 4d-20) then
        tmp = x
    else if ((z <= 3.4d+80) .or. (.not. (z <= 8d+237)) .and. (z <= 9.5d+261)) then
        tmp = y * z
    else
        tmp = t_0
    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 <= -6.6e+247) {
		tmp = t_0;
	} else if (z <= -5e+189) {
		tmp = y * z;
	} else if (z <= -2.9e+67) {
		tmp = t_0;
	} else if (z <= -3.5e-65) {
		tmp = y * z;
	} else if (z <= 1.12e-175) {
		tmp = x;
	} else if (z <= 1.1e-123) {
		tmp = y * z;
	} else if (z <= 4e-20) {
		tmp = x;
	} else if ((z <= 3.4e+80) || (!(z <= 8e+237) && (z <= 9.5e+261))) {
		tmp = y * z;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = z * -x
	tmp = 0
	if z <= -6.6e+247:
		tmp = t_0
	elif z <= -5e+189:
		tmp = y * z
	elif z <= -2.9e+67:
		tmp = t_0
	elif z <= -3.5e-65:
		tmp = y * z
	elif z <= 1.12e-175:
		tmp = x
	elif z <= 1.1e-123:
		tmp = y * z
	elif z <= 4e-20:
		tmp = x
	elif (z <= 3.4e+80) or (not (z <= 8e+237) and (z <= 9.5e+261)):
		tmp = y * z
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(z * Float64(-x))
	tmp = 0.0
	if (z <= -6.6e+247)
		tmp = t_0;
	elseif (z <= -5e+189)
		tmp = Float64(y * z);
	elseif (z <= -2.9e+67)
		tmp = t_0;
	elseif (z <= -3.5e-65)
		tmp = Float64(y * z);
	elseif (z <= 1.12e-175)
		tmp = x;
	elseif (z <= 1.1e-123)
		tmp = Float64(y * z);
	elseif (z <= 4e-20)
		tmp = x;
	elseif ((z <= 3.4e+80) || (!(z <= 8e+237) && (z <= 9.5e+261)))
		tmp = Float64(y * z);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = z * -x;
	tmp = 0.0;
	if (z <= -6.6e+247)
		tmp = t_0;
	elseif (z <= -5e+189)
		tmp = y * z;
	elseif (z <= -2.9e+67)
		tmp = t_0;
	elseif (z <= -3.5e-65)
		tmp = y * z;
	elseif (z <= 1.12e-175)
		tmp = x;
	elseif (z <= 1.1e-123)
		tmp = y * z;
	elseif (z <= 4e-20)
		tmp = x;
	elseif ((z <= 3.4e+80) || (~((z <= 8e+237)) && (z <= 9.5e+261)))
		tmp = y * z;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * (-x)), $MachinePrecision]}, If[LessEqual[z, -6.6e+247], t$95$0, If[LessEqual[z, -5e+189], N[(y * z), $MachinePrecision], If[LessEqual[z, -2.9e+67], t$95$0, If[LessEqual[z, -3.5e-65], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.12e-175], x, If[LessEqual[z, 1.1e-123], N[(y * z), $MachinePrecision], If[LessEqual[z, 4e-20], x, If[Or[LessEqual[z, 3.4e+80], And[N[Not[LessEqual[z, 8e+237]], $MachinePrecision], LessEqual[z, 9.5e+261]]], N[(y * z), $MachinePrecision], t$95$0]]]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;z \leq -5 \cdot 10^{+189}:\\
\;\;\;\;y \cdot z\\

\mathbf{elif}\;z \leq -2.9 \cdot 10^{+67}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;z \leq -3.5 \cdot 10^{-65}:\\
\;\;\;\;y \cdot z\\

\mathbf{elif}\;z \leq 1.12 \cdot 10^{-175}:\\
\;\;\;\;x\\

\mathbf{elif}\;z \leq 1.1 \cdot 10^{-123}:\\
\;\;\;\;y \cdot z\\

\mathbf{elif}\;z \leq 4 \cdot 10^{-20}:\\
\;\;\;\;x\\

\mathbf{elif}\;z \leq 3.4 \cdot 10^{+80} \lor \neg \left(z \leq 8 \cdot 10^{+237}\right) \land z \leq 9.5 \cdot 10^{+261}:\\
\;\;\;\;y \cdot z\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -6.60000000000000003e247 or -5.0000000000000004e189 < z < -2.90000000000000023e67 or 3.39999999999999992e80 < z < 7.99999999999999952e237 or 9.50000000000000085e261 < z

    1. Initial program 100.0%

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

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

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

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

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

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

    if -6.60000000000000003e247 < z < -5.0000000000000004e189 or -2.90000000000000023e67 < z < -3.50000000000000005e-65 or 1.1200000000000001e-175 < z < 1.10000000000000003e-123 or 3.99999999999999978e-20 < z < 3.39999999999999992e80 or 7.99999999999999952e237 < z < 9.50000000000000085e261

    1. Initial program 100.0%

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

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

    if -3.50000000000000005e-65 < z < 1.1200000000000001e-175 or 1.10000000000000003e-123 < z < 3.99999999999999978e-20

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -6.6 \cdot 10^{+247}:\\ \;\;\;\;z \cdot \left(-x\right)\\ \mathbf{elif}\;z \leq -5 \cdot 10^{+189}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -2.9 \cdot 10^{+67}:\\ \;\;\;\;z \cdot \left(-x\right)\\ \mathbf{elif}\;z \leq -3.5 \cdot 10^{-65}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 1.12 \cdot 10^{-175}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.1 \cdot 10^{-123}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 4 \cdot 10^{-20}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 3.4 \cdot 10^{+80} \lor \neg \left(z \leq 8 \cdot 10^{+237}\right) \land z \leq 9.5 \cdot 10^{+261}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(-x\right)\\ \end{array} \]

Alternative 3: 82.5% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(y - x\right) \cdot z\\ \mathbf{if}\;z \leq -6.8 \cdot 10^{-66}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.12 \cdot 10^{-175}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 6.2 \cdot 10^{-122}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 9.5 \cdot 10^{-19}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* (- y x) z)))
   (if (<= z -6.8e-66)
     t_0
     (if (<= z 1.12e-175)
       x
       (if (<= z 6.2e-122) (* y z) (if (<= z 9.5e-19) x t_0))))))
double code(double x, double y, double z) {
	double t_0 = (y - x) * z;
	double tmp;
	if (z <= -6.8e-66) {
		tmp = t_0;
	} else if (z <= 1.12e-175) {
		tmp = x;
	} else if (z <= 6.2e-122) {
		tmp = y * z;
	} else if (z <= 9.5e-19) {
		tmp = x;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (y - x) * z
    if (z <= (-6.8d-66)) then
        tmp = t_0
    else if (z <= 1.12d-175) then
        tmp = x
    else if (z <= 6.2d-122) then
        tmp = y * z
    else if (z <= 9.5d-19) then
        tmp = x
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = (y - x) * z;
	double tmp;
	if (z <= -6.8e-66) {
		tmp = t_0;
	} else if (z <= 1.12e-175) {
		tmp = x;
	} else if (z <= 6.2e-122) {
		tmp = y * z;
	} else if (z <= 9.5e-19) {
		tmp = x;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = (y - x) * z
	tmp = 0
	if z <= -6.8e-66:
		tmp = t_0
	elif z <= 1.12e-175:
		tmp = x
	elif z <= 6.2e-122:
		tmp = y * z
	elif z <= 9.5e-19:
		tmp = x
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(Float64(y - x) * z)
	tmp = 0.0
	if (z <= -6.8e-66)
		tmp = t_0;
	elseif (z <= 1.12e-175)
		tmp = x;
	elseif (z <= 6.2e-122)
		tmp = Float64(y * z);
	elseif (z <= 9.5e-19)
		tmp = x;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = (y - x) * z;
	tmp = 0.0;
	if (z <= -6.8e-66)
		tmp = t_0;
	elseif (z <= 1.12e-175)
		tmp = x;
	elseif (z <= 6.2e-122)
		tmp = y * z;
	elseif (z <= 9.5e-19)
		tmp = x;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[z, -6.8e-66], t$95$0, If[LessEqual[z, 1.12e-175], x, If[LessEqual[z, 6.2e-122], N[(y * z), $MachinePrecision], If[LessEqual[z, 9.5e-19], x, t$95$0]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(y - x\right) \cdot z\\
\mathbf{if}\;z \leq -6.8 \cdot 10^{-66}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;z \leq 1.12 \cdot 10^{-175}:\\
\;\;\;\;x\\

\mathbf{elif}\;z \leq 6.2 \cdot 10^{-122}:\\
\;\;\;\;y \cdot z\\

\mathbf{elif}\;z \leq 9.5 \cdot 10^{-19}:\\
\;\;\;\;x\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -6.79999999999999994e-66 or 9.4999999999999995e-19 < z

    1. Initial program 100.0%

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

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

    if -6.79999999999999994e-66 < z < 1.1200000000000001e-175 or 6.1999999999999997e-122 < z < 9.4999999999999995e-19

    1. Initial program 100.0%

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

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

    if 1.1200000000000001e-175 < z < 6.1999999999999997e-122

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -6.8 \cdot 10^{-66}:\\ \;\;\;\;\left(y - x\right) \cdot z\\ \mathbf{elif}\;z \leq 1.12 \cdot 10^{-175}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 6.2 \cdot 10^{-122}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 9.5 \cdot 10^{-19}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\left(y - x\right) \cdot z\\ \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 0.00086\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 0.00086))) (* (- y x) z) (+ x (* y z))))
double code(double x, double y, double z) {
	double tmp;
	if ((z <= -1.0) || !(z <= 0.00086)) {
		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 <= 0.00086d0))) 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 <= 0.00086)) {
		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 <= 0.00086):
		tmp = (y - x) * z
	else:
		tmp = x + (y * z)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((z <= -1.0) || !(z <= 0.00086))
		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 <= 0.00086)))
		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, 0.00086]], $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 0.00086\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 8.59999999999999979e-4 < z

    1. Initial program 100.0%

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

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

    if -1 < z < 8.59999999999999979e-4

    1. Initial program 100.0%

      \[x + \left(y - x\right) \cdot z \]
    2. Step-by-step derivation
      1. flip--48.0%

        \[\leadsto x + \color{blue}{\frac{y \cdot y - x \cdot x}{y + x}} \cdot z \]
      2. associate-*l/47.9%

        \[\leadsto x + \color{blue}{\frac{\left(y \cdot y - x \cdot x\right) \cdot z}{y + x}} \]
      3. +-commutative47.9%

        \[\leadsto x + \frac{\left(y \cdot y - x \cdot x\right) \cdot z}{\color{blue}{x + y}} \]
    3. Applied egg-rr47.9%

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

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

        \[\leadsto x + \color{blue}{z \cdot y} \]
    6. Simplified98.9%

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

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

Alternative 5: 54.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -5.5 \cdot 10^{+66}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 8.5 \cdot 10^{+72}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= x -5.5e+66) x (if (<= x 8.5e+72) (* y z) x)))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -5.5e+66) {
		tmp = x;
	} else if (x <= 8.5e+72) {
		tmp = y * 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 (x <= (-5.5d+66)) then
        tmp = x
    else if (x <= 8.5d+72) then
        tmp = y * z
    else
        tmp = x
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (x <= -5.5e+66) {
		tmp = x;
	} else if (x <= 8.5e+72) {
		tmp = y * z;
	} else {
		tmp = x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if x <= -5.5e+66:
		tmp = x
	elif x <= 8.5e+72:
		tmp = y * z
	else:
		tmp = x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (x <= -5.5e+66)
		tmp = x;
	elseif (x <= 8.5e+72)
		tmp = Float64(y * z);
	else
		tmp = x;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (x <= -5.5e+66)
		tmp = x;
	elseif (x <= 8.5e+72)
		tmp = y * z;
	else
		tmp = x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[x, -5.5e+66], x, If[LessEqual[x, 8.5e+72], N[(y * z), $MachinePrecision], x]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.5 \cdot 10^{+66}:\\
\;\;\;\;x\\

\mathbf{elif}\;x \leq 8.5 \cdot 10^{+72}:\\
\;\;\;\;y \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -5.5e66 or 8.5000000000000004e72 < x

    1. Initial program 100.0%

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

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

    if -5.5e66 < x < 8.5000000000000004e72

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -5.5 \cdot 10^{+66}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 8.5 \cdot 10^{+72}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\\ \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: 36.2% 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 32.2%

    \[\leadsto \color{blue}{x} \]
  3. Final simplification32.2%

    \[\leadsto x \]

Reproduce

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