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

Percentage Accurate: 100.0% → 100.0%
Time: 4.7s
Alternatives: 8
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 8 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-define100.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. Add Preprocessing
  5. Add Preprocessing

Alternative 2: 59.9% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \left(-z\right)\\ \mathbf{if}\;z \leq -2.35 \cdot 10^{+191}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;z \leq -4.8 \cdot 10^{+153}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -4 \cdot 10^{+89}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;z \leq -8 \cdot 10^{-90}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.7 \cdot 10^{+240}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* x (- z))))
   (if (<= z -2.35e+191)
     t_0
     (if (<= z -4.8e+153)
       (* y z)
       (if (<= z -4e+89)
         t_0
         (if (<= z -8e-90)
           (* y z)
           (if (<= z 1.0) x (if (<= z 1.7e+240) t_0 (* y z)))))))))
double code(double x, double y, double z) {
	double t_0 = x * -z;
	double tmp;
	if (z <= -2.35e+191) {
		tmp = t_0;
	} else if (z <= -4.8e+153) {
		tmp = y * z;
	} else if (z <= -4e+89) {
		tmp = t_0;
	} else if (z <= -8e-90) {
		tmp = y * z;
	} else if (z <= 1.0) {
		tmp = x;
	} else if (z <= 1.7e+240) {
		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 = x * -z
    if (z <= (-2.35d+191)) then
        tmp = t_0
    else if (z <= (-4.8d+153)) then
        tmp = y * z
    else if (z <= (-4d+89)) then
        tmp = t_0
    else if (z <= (-8d-90)) then
        tmp = y * z
    else if (z <= 1.0d0) then
        tmp = x
    else if (z <= 1.7d+240) 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 = x * -z;
	double tmp;
	if (z <= -2.35e+191) {
		tmp = t_0;
	} else if (z <= -4.8e+153) {
		tmp = y * z;
	} else if (z <= -4e+89) {
		tmp = t_0;
	} else if (z <= -8e-90) {
		tmp = y * z;
	} else if (z <= 1.0) {
		tmp = x;
	} else if (z <= 1.7e+240) {
		tmp = t_0;
	} else {
		tmp = y * z;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = x * -z
	tmp = 0
	if z <= -2.35e+191:
		tmp = t_0
	elif z <= -4.8e+153:
		tmp = y * z
	elif z <= -4e+89:
		tmp = t_0
	elif z <= -8e-90:
		tmp = y * z
	elif z <= 1.0:
		tmp = x
	elif z <= 1.7e+240:
		tmp = t_0
	else:
		tmp = y * z
	return tmp
function code(x, y, z)
	t_0 = Float64(x * Float64(-z))
	tmp = 0.0
	if (z <= -2.35e+191)
		tmp = t_0;
	elseif (z <= -4.8e+153)
		tmp = Float64(y * z);
	elseif (z <= -4e+89)
		tmp = t_0;
	elseif (z <= -8e-90)
		tmp = Float64(y * z);
	elseif (z <= 1.0)
		tmp = x;
	elseif (z <= 1.7e+240)
		tmp = t_0;
	else
		tmp = Float64(y * z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = x * -z;
	tmp = 0.0;
	if (z <= -2.35e+191)
		tmp = t_0;
	elseif (z <= -4.8e+153)
		tmp = y * z;
	elseif (z <= -4e+89)
		tmp = t_0;
	elseif (z <= -8e-90)
		tmp = y * z;
	elseif (z <= 1.0)
		tmp = x;
	elseif (z <= 1.7e+240)
		tmp = t_0;
	else
		tmp = y * z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-z)), $MachinePrecision]}, If[LessEqual[z, -2.35e+191], t$95$0, If[LessEqual[z, -4.8e+153], N[(y * z), $MachinePrecision], If[LessEqual[z, -4e+89], t$95$0, If[LessEqual[z, -8e-90], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.0], x, If[LessEqual[z, 1.7e+240], t$95$0, N[(y * z), $MachinePrecision]]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;z \leq -4.8 \cdot 10^{+153}:\\
\;\;\;\;y \cdot z\\

\mathbf{elif}\;z \leq -4 \cdot 10^{+89}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;z \leq -8 \cdot 10^{-90}:\\
\;\;\;\;y \cdot z\\

\mathbf{elif}\;z \leq 1:\\
\;\;\;\;x\\

\mathbf{elif}\;z \leq 1.7 \cdot 10^{+240}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -2.35000000000000005e191 or -4.79999999999999985e153 < z < -3.99999999999999998e89 or 1 < z < 1.70000000000000004e240

    1. Initial program 100.0%

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

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

        \[\leadsto x \cdot \left(1 + \color{blue}{\left(-z\right)}\right) \]
      2. unsub-neg62.6%

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

      \[\leadsto \color{blue}{x \cdot \left(1 - z\right)} \]
    6. Step-by-step derivation
      1. sub-neg62.6%

        \[\leadsto x \cdot \color{blue}{\left(1 + \left(-z\right)\right)} \]
      2. distribute-rgt-in62.5%

        \[\leadsto \color{blue}{1 \cdot x + \left(-z\right) \cdot x} \]
      3. *-un-lft-identity62.5%

        \[\leadsto \color{blue}{x} + \left(-z\right) \cdot x \]
      4. distribute-lft-neg-in62.5%

        \[\leadsto x + \color{blue}{\left(-z \cdot x\right)} \]
      5. unsub-neg62.5%

        \[\leadsto \color{blue}{x - z \cdot x} \]
    7. Applied egg-rr62.5%

      \[\leadsto \color{blue}{x - z \cdot x} \]
    8. Taylor expanded in z around inf 61.6%

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

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

        \[\leadsto \color{blue}{x \cdot \left(-z\right)} \]
    10. Simplified61.6%

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

    if -2.35000000000000005e191 < z < -4.79999999999999985e153 or -3.99999999999999998e89 < z < -7.99999999999999996e-90 or 1.70000000000000004e240 < z

    1. Initial program 100.0%

      \[x + \left(y - x\right) \cdot z \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. *-commutative100.0%

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

        \[\leadsto x + z \cdot \color{blue}{\left(y + \left(-x\right)\right)} \]
      3. distribute-lft-in98.6%

        \[\leadsto x + \color{blue}{\left(z \cdot y + z \cdot \left(-x\right)\right)} \]
    4. Applied egg-rr98.6%

      \[\leadsto x + \color{blue}{\left(z \cdot y + z \cdot \left(-x\right)\right)} \]
    5. Step-by-step derivation
      1. associate-+r+98.6%

        \[\leadsto \color{blue}{\left(x + z \cdot y\right) + z \cdot \left(-x\right)} \]
      2. distribute-rgt-neg-out98.6%

        \[\leadsto \left(x + z \cdot y\right) + \color{blue}{\left(-z \cdot x\right)} \]
      3. unsub-neg98.6%

        \[\leadsto \color{blue}{\left(x + z \cdot y\right) - z \cdot x} \]
      4. +-commutative98.6%

        \[\leadsto \color{blue}{\left(z \cdot y + x\right)} - z \cdot x \]
    6. Applied egg-rr98.6%

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

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

        \[\leadsto \color{blue}{z \cdot y} \]
    9. Simplified69.9%

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

    if -7.99999999999999996e-90 < z < 1

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -2.35 \cdot 10^{+191}:\\ \;\;\;\;x \cdot \left(-z\right)\\ \mathbf{elif}\;z \leq -4.8 \cdot 10^{+153}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -4 \cdot 10^{+89}:\\ \;\;\;\;x \cdot \left(-z\right)\\ \mathbf{elif}\;z \leq -8 \cdot 10^{-90}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.7 \cdot 10^{+240}:\\ \;\;\;\;x \cdot \left(-z\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 84.0% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -10.5 \lor \neg \left(z \leq -4.8 \cdot 10^{-41}\right) \land \left(z \leq -8 \cdot 10^{-90} \lor \neg \left(z \leq 2600000000000\right)\right):\\ \;\;\;\;\left(y - x\right) \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 - z\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= z -10.5)
         (and (not (<= z -4.8e-41))
              (or (<= z -8e-90) (not (<= z 2600000000000.0)))))
   (* (- y x) z)
   (* x (- 1.0 z))))
double code(double x, double y, double z) {
	double tmp;
	if ((z <= -10.5) || (!(z <= -4.8e-41) && ((z <= -8e-90) || !(z <= 2600000000000.0)))) {
		tmp = (y - x) * z;
	} else {
		tmp = x * (1.0 - 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 <= (-10.5d0)) .or. (.not. (z <= (-4.8d-41))) .and. (z <= (-8d-90)) .or. (.not. (z <= 2600000000000.0d0))) then
        tmp = (y - x) * z
    else
        tmp = x * (1.0d0 - z)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((z <= -10.5) || (!(z <= -4.8e-41) && ((z <= -8e-90) || !(z <= 2600000000000.0)))) {
		tmp = (y - x) * z;
	} else {
		tmp = x * (1.0 - z);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (z <= -10.5) or (not (z <= -4.8e-41) and ((z <= -8e-90) or not (z <= 2600000000000.0))):
		tmp = (y - x) * z
	else:
		tmp = x * (1.0 - z)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((z <= -10.5) || (!(z <= -4.8e-41) && ((z <= -8e-90) || !(z <= 2600000000000.0))))
		tmp = Float64(Float64(y - x) * z);
	else
		tmp = Float64(x * Float64(1.0 - z));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((z <= -10.5) || (~((z <= -4.8e-41)) && ((z <= -8e-90) || ~((z <= 2600000000000.0)))))
		tmp = (y - x) * z;
	else
		tmp = x * (1.0 - z);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[z, -10.5], And[N[Not[LessEqual[z, -4.8e-41]], $MachinePrecision], Or[LessEqual[z, -8e-90], N[Not[LessEqual[z, 2600000000000.0]], $MachinePrecision]]]], N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -10.5 \lor \neg \left(z \leq -4.8 \cdot 10^{-41}\right) \land \left(z \leq -8 \cdot 10^{-90} \lor \neg \left(z \leq 2600000000000\right)\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\

\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -10.5 or -4.80000000000000044e-41 < z < -7.99999999999999996e-90 or 2.6e12 < z

    1. Initial program 100.0%

      \[x + \left(y - x\right) \cdot z \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. *-commutative100.0%

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

        \[\leadsto x + z \cdot \color{blue}{\left(y + \left(-x\right)\right)} \]
      3. distribute-lft-in94.3%

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

      \[\leadsto x + \color{blue}{\left(z \cdot y + z \cdot \left(-x\right)\right)} \]
    5. Step-by-step derivation
      1. associate-+r+94.3%

        \[\leadsto \color{blue}{\left(x + z \cdot y\right) + z \cdot \left(-x\right)} \]
      2. distribute-rgt-neg-out94.3%

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

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

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

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

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

    if -10.5 < z < -4.80000000000000044e-41 or -7.99999999999999996e-90 < z < 2.6e12

    1. Initial program 100.0%

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

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

        \[\leadsto x \cdot \left(1 + \color{blue}{\left(-z\right)}\right) \]
      2. unsub-neg84.0%

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

      \[\leadsto \color{blue}{x \cdot \left(1 - z\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification90.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -10.5 \lor \neg \left(z \leq -4.8 \cdot 10^{-41}\right) \land \left(z \leq -8 \cdot 10^{-90} \lor \neg \left(z \leq 2600000000000\right)\right):\\ \;\;\;\;\left(y - x\right) \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 - z\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 72.7% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -5400000000000 \lor \neg \left(y \leq 7.8 \cdot 10^{+147} \lor \neg \left(y \leq 3.9 \cdot 10^{+232}\right) \land y \leq 1.15 \cdot 10^{+268}\right):\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 - z\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= y -5400000000000.0)
         (not
          (or (<= y 7.8e+147) (and (not (<= y 3.9e+232)) (<= y 1.15e+268)))))
   (* y z)
   (* x (- 1.0 z))))
double code(double x, double y, double z) {
	double tmp;
	if ((y <= -5400000000000.0) || !((y <= 7.8e+147) || (!(y <= 3.9e+232) && (y <= 1.15e+268)))) {
		tmp = y * z;
	} else {
		tmp = x * (1.0 - 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 ((y <= (-5400000000000.0d0)) .or. (.not. (y <= 7.8d+147) .or. (.not. (y <= 3.9d+232)) .and. (y <= 1.15d+268))) then
        tmp = y * z
    else
        tmp = x * (1.0d0 - z)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((y <= -5400000000000.0) || !((y <= 7.8e+147) || (!(y <= 3.9e+232) && (y <= 1.15e+268)))) {
		tmp = y * z;
	} else {
		tmp = x * (1.0 - z);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (y <= -5400000000000.0) or not ((y <= 7.8e+147) or (not (y <= 3.9e+232) and (y <= 1.15e+268))):
		tmp = y * z
	else:
		tmp = x * (1.0 - z)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((y <= -5400000000000.0) || !((y <= 7.8e+147) || (!(y <= 3.9e+232) && (y <= 1.15e+268))))
		tmp = Float64(y * z);
	else
		tmp = Float64(x * Float64(1.0 - z));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((y <= -5400000000000.0) || ~(((y <= 7.8e+147) || (~((y <= 3.9e+232)) && (y <= 1.15e+268)))))
		tmp = y * z;
	else
		tmp = x * (1.0 - z);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[y, -5400000000000.0], N[Not[Or[LessEqual[y, 7.8e+147], And[N[Not[LessEqual[y, 3.9e+232]], $MachinePrecision], LessEqual[y, 1.15e+268]]]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -5400000000000 \lor \neg \left(y \leq 7.8 \cdot 10^{+147} \lor \neg \left(y \leq 3.9 \cdot 10^{+232}\right) \land y \leq 1.15 \cdot 10^{+268}\right):\\
\;\;\;\;y \cdot z\\

\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -5.4e12 or 7.80000000000000033e147 < y < 3.8999999999999999e232 or 1.15000000000000006e268 < y

    1. Initial program 100.0%

      \[x + \left(y - x\right) \cdot z \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. *-commutative100.0%

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

        \[\leadsto x + z \cdot \color{blue}{\left(y + \left(-x\right)\right)} \]
      3. distribute-lft-in94.7%

        \[\leadsto x + \color{blue}{\left(z \cdot y + z \cdot \left(-x\right)\right)} \]
    4. Applied egg-rr94.7%

      \[\leadsto x + \color{blue}{\left(z \cdot y + z \cdot \left(-x\right)\right)} \]
    5. Step-by-step derivation
      1. associate-+r+94.7%

        \[\leadsto \color{blue}{\left(x + z \cdot y\right) + z \cdot \left(-x\right)} \]
      2. distribute-rgt-neg-out94.7%

        \[\leadsto \left(x + z \cdot y\right) + \color{blue}{\left(-z \cdot x\right)} \]
      3. unsub-neg94.7%

        \[\leadsto \color{blue}{\left(x + z \cdot y\right) - z \cdot x} \]
      4. +-commutative94.7%

        \[\leadsto \color{blue}{\left(z \cdot y + x\right)} - z \cdot x \]
    6. Applied egg-rr94.7%

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

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

        \[\leadsto \color{blue}{z \cdot y} \]
    9. Simplified76.6%

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

    if -5.4e12 < y < 7.80000000000000033e147 or 3.8999999999999999e232 < y < 1.15000000000000006e268

    1. Initial program 100.0%

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

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

        \[\leadsto x \cdot \left(1 + \color{blue}{\left(-z\right)}\right) \]
      2. unsub-neg83.4%

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

      \[\leadsto \color{blue}{x \cdot \left(1 - z\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification80.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -5400000000000 \lor \neg \left(y \leq 7.8 \cdot 10^{+147} \lor \neg \left(y \leq 3.9 \cdot 10^{+232}\right) \land y \leq 1.15 \cdot 10^{+268}\right):\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 - z\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 99.0% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 1\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 1.0))) (* (- y x) z) (+ x (* y z))))
double code(double x, double y, double z) {
	double tmp;
	if ((z <= -1.0) || !(z <= 1.0)) {
		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 <= 1.0d0))) 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 <= 1.0)) {
		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 <= 1.0):
		tmp = (y - x) * z
	else:
		tmp = x + (y * z)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((z <= -1.0) || !(z <= 1.0))
		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 <= 1.0)))
		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, 1.0]], $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 1\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 1 < z

    1. Initial program 100.0%

      \[x + \left(y - x\right) \cdot z \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. *-commutative100.0%

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

        \[\leadsto x + z \cdot \color{blue}{\left(y + \left(-x\right)\right)} \]
      3. distribute-lft-in93.8%

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

      \[\leadsto x + \color{blue}{\left(z \cdot y + z \cdot \left(-x\right)\right)} \]
    5. Step-by-step derivation
      1. associate-+r+93.8%

        \[\leadsto \color{blue}{\left(x + z \cdot y\right) + z \cdot \left(-x\right)} \]
      2. distribute-rgt-neg-out93.8%

        \[\leadsto \left(x + z \cdot y\right) + \color{blue}{\left(-z \cdot x\right)} \]
      3. unsub-neg93.8%

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

        \[\leadsto \color{blue}{\left(z \cdot y + x\right)} - z \cdot x \]
    6. Applied egg-rr93.8%

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

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

    if -1 < z < 1

    1. Initial program 100.0%

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

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

        \[\leadsto x + \color{blue}{z \cdot y} \]
    5. Simplified99.0%

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

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

Alternative 6: 60.6% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -8 \cdot 10^{-90} \lor \neg \left(z \leq 2.2 \cdot 10^{-6}\right):\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= z -8e-90) (not (<= z 2.2e-6))) (* y z) x))
double code(double x, double y, double z) {
	double tmp;
	if ((z <= -8e-90) || !(z <= 2.2e-6)) {
		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 ((z <= (-8d-90)) .or. (.not. (z <= 2.2d-6))) 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 ((z <= -8e-90) || !(z <= 2.2e-6)) {
		tmp = y * z;
	} else {
		tmp = x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (z <= -8e-90) or not (z <= 2.2e-6):
		tmp = y * z
	else:
		tmp = x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((z <= -8e-90) || !(z <= 2.2e-6))
		tmp = Float64(y * z);
	else
		tmp = x;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((z <= -8e-90) || ~((z <= 2.2e-6)))
		tmp = y * z;
	else
		tmp = x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[z, -8e-90], N[Not[LessEqual[z, 2.2e-6]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}

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

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


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

    1. Initial program 100.0%

      \[x + \left(y - x\right) \cdot z \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. *-commutative100.0%

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

        \[\leadsto x + z \cdot \color{blue}{\left(y + \left(-x\right)\right)} \]
      3. distribute-lft-in94.6%

        \[\leadsto x + \color{blue}{\left(z \cdot y + z \cdot \left(-x\right)\right)} \]
    4. Applied egg-rr94.6%

      \[\leadsto x + \color{blue}{\left(z \cdot y + z \cdot \left(-x\right)\right)} \]
    5. Step-by-step derivation
      1. associate-+r+94.6%

        \[\leadsto \color{blue}{\left(x + z \cdot y\right) + z \cdot \left(-x\right)} \]
      2. distribute-rgt-neg-out94.6%

        \[\leadsto \left(x + z \cdot y\right) + \color{blue}{\left(-z \cdot x\right)} \]
      3. unsub-neg94.6%

        \[\leadsto \color{blue}{\left(x + z \cdot y\right) - z \cdot x} \]
      4. +-commutative94.6%

        \[\leadsto \color{blue}{\left(z \cdot y + x\right)} - z \cdot x \]
    6. Applied egg-rr94.6%

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

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

        \[\leadsto \color{blue}{z \cdot y} \]
    9. Simplified55.1%

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

    if -7.99999999999999996e-90 < z < 2.2000000000000001e-6

    1. Initial program 100.0%

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

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

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

Alternative 7: 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. Add Preprocessing
  3. Add Preprocessing

Alternative 8: 36.1% 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. Add Preprocessing
  3. Taylor expanded in z around 0 39.6%

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

Reproduce

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