Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3

Percentage Accurate: 97.9% → 100.0%
Time: 6.9s
Alternatives: 9
Speedup: 1.3×

Specification

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

\\
x \cdot y + \left(1 - 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 9 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: 97.9% accurate, 1.0× speedup?

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

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

Alternative 1: 100.0% accurate, 0.1× speedup?

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

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

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

      \[\leadsto x \cdot y + \color{blue}{z \cdot \left(1 - x\right)} \]
    2. distribute-lft-out--98.0%

      \[\leadsto x \cdot y + \color{blue}{\left(z \cdot 1 - z \cdot x\right)} \]
    3. *-rgt-identity98.0%

      \[\leadsto x \cdot y + \left(\color{blue}{z} - z \cdot x\right) \]
    4. cancel-sign-sub-inv98.0%

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

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

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

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

      \[\leadsto \left(\left(-z\right) \cdot x + \color{blue}{y \cdot x}\right) + z \]
    9. distribute-rgt-out100.0%

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

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

      \[\leadsto \mathsf{fma}\left(x, \color{blue}{y + \left(-z\right)}, z\right) \]
    12. unsub-neg100.0%

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

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

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

Alternative 2: 60.8% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \left(-z\right)\\ \mathbf{if}\;x \leq -2.6 \cdot 10^{+231}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -1.05 \cdot 10^{+40}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq -3 \cdot 10^{-109}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 6.2 \cdot 10^{-34}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq 1.65 \cdot 10^{+41} \lor \neg \left(x \leq 1.95 \cdot 10^{+76} \lor \neg \left(x \leq 7.5 \cdot 10^{+140}\right) \land \left(x \leq 1.3 \cdot 10^{+215} \lor \neg \left(x \leq 1.2 \cdot 10^{+278}\right) \land x \leq 2.5 \cdot 10^{+297}\right)\right):\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* x (- z))))
   (if (<= x -2.6e+231)
     (* x y)
     (if (<= x -1.05e+40)
       t_0
       (if (<= x -3e-109)
         (* x y)
         (if (<= x 6.2e-34)
           z
           (if (or (<= x 1.65e+41)
                   (not
                    (or (<= x 1.95e+76)
                        (and (not (<= x 7.5e+140))
                             (or (<= x 1.3e+215)
                                 (and (not (<= x 1.2e+278))
                                      (<= x 2.5e+297)))))))
             (* x y)
             t_0)))))))
double code(double x, double y, double z) {
	double t_0 = x * -z;
	double tmp;
	if (x <= -2.6e+231) {
		tmp = x * y;
	} else if (x <= -1.05e+40) {
		tmp = t_0;
	} else if (x <= -3e-109) {
		tmp = x * y;
	} else if (x <= 6.2e-34) {
		tmp = z;
	} else if ((x <= 1.65e+41) || !((x <= 1.95e+76) || (!(x <= 7.5e+140) && ((x <= 1.3e+215) || (!(x <= 1.2e+278) && (x <= 2.5e+297)))))) {
		tmp = x * y;
	} 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 = x * -z
    if (x <= (-2.6d+231)) then
        tmp = x * y
    else if (x <= (-1.05d+40)) then
        tmp = t_0
    else if (x <= (-3d-109)) then
        tmp = x * y
    else if (x <= 6.2d-34) then
        tmp = z
    else if ((x <= 1.65d+41) .or. (.not. (x <= 1.95d+76) .or. (.not. (x <= 7.5d+140)) .and. (x <= 1.3d+215) .or. (.not. (x <= 1.2d+278)) .and. (x <= 2.5d+297))) then
        tmp = x * y
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = x * -z;
	double tmp;
	if (x <= -2.6e+231) {
		tmp = x * y;
	} else if (x <= -1.05e+40) {
		tmp = t_0;
	} else if (x <= -3e-109) {
		tmp = x * y;
	} else if (x <= 6.2e-34) {
		tmp = z;
	} else if ((x <= 1.65e+41) || !((x <= 1.95e+76) || (!(x <= 7.5e+140) && ((x <= 1.3e+215) || (!(x <= 1.2e+278) && (x <= 2.5e+297)))))) {
		tmp = x * y;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = x * -z
	tmp = 0
	if x <= -2.6e+231:
		tmp = x * y
	elif x <= -1.05e+40:
		tmp = t_0
	elif x <= -3e-109:
		tmp = x * y
	elif x <= 6.2e-34:
		tmp = z
	elif (x <= 1.65e+41) or not ((x <= 1.95e+76) or (not (x <= 7.5e+140) and ((x <= 1.3e+215) or (not (x <= 1.2e+278) and (x <= 2.5e+297))))):
		tmp = x * y
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(x * Float64(-z))
	tmp = 0.0
	if (x <= -2.6e+231)
		tmp = Float64(x * y);
	elseif (x <= -1.05e+40)
		tmp = t_0;
	elseif (x <= -3e-109)
		tmp = Float64(x * y);
	elseif (x <= 6.2e-34)
		tmp = z;
	elseif ((x <= 1.65e+41) || !((x <= 1.95e+76) || (!(x <= 7.5e+140) && ((x <= 1.3e+215) || (!(x <= 1.2e+278) && (x <= 2.5e+297))))))
		tmp = Float64(x * y);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = x * -z;
	tmp = 0.0;
	if (x <= -2.6e+231)
		tmp = x * y;
	elseif (x <= -1.05e+40)
		tmp = t_0;
	elseif (x <= -3e-109)
		tmp = x * y;
	elseif (x <= 6.2e-34)
		tmp = z;
	elseif ((x <= 1.65e+41) || ~(((x <= 1.95e+76) || (~((x <= 7.5e+140)) && ((x <= 1.3e+215) || (~((x <= 1.2e+278)) && (x <= 2.5e+297)))))))
		tmp = x * y;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-z)), $MachinePrecision]}, If[LessEqual[x, -2.6e+231], N[(x * y), $MachinePrecision], If[LessEqual[x, -1.05e+40], t$95$0, If[LessEqual[x, -3e-109], N[(x * y), $MachinePrecision], If[LessEqual[x, 6.2e-34], z, If[Or[LessEqual[x, 1.65e+41], N[Not[Or[LessEqual[x, 1.95e+76], And[N[Not[LessEqual[x, 7.5e+140]], $MachinePrecision], Or[LessEqual[x, 1.3e+215], And[N[Not[LessEqual[x, 1.2e+278]], $MachinePrecision], LessEqual[x, 2.5e+297]]]]]], $MachinePrecision]], N[(x * y), $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;x \leq -1.05 \cdot 10^{+40}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;x \leq 6.2 \cdot 10^{-34}:\\
\;\;\;\;z\\

\mathbf{elif}\;x \leq 1.65 \cdot 10^{+41} \lor \neg \left(x \leq 1.95 \cdot 10^{+76} \lor \neg \left(x \leq 7.5 \cdot 10^{+140}\right) \land \left(x \leq 1.3 \cdot 10^{+215} \lor \neg \left(x \leq 1.2 \cdot 10^{+278}\right) \land x \leq 2.5 \cdot 10^{+297}\right)\right):\\
\;\;\;\;x \cdot y\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -2.5999999999999999e231 or -1.05000000000000005e40 < x < -3.00000000000000021e-109 or 6.1999999999999996e-34 < x < 1.65e41 or 1.94999999999999995e76 < x < 7.4999999999999997e140 or 1.3e215 < x < 1.19999999999999992e278 or 2.4999999999999999e297 < x

    1. Initial program 95.6%

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

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

    if -2.5999999999999999e231 < x < -1.05000000000000005e40 or 1.65e41 < x < 1.94999999999999995e76 or 7.4999999999999997e140 < x < 1.3e215 or 1.19999999999999992e278 < x < 2.4999999999999999e297

    1. Initial program 98.7%

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(x \cdot z\right)} \]
    7. Step-by-step derivation
      1. associate-*r*69.1%

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

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

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

    if -3.00000000000000021e-109 < x < 6.1999999999999996e-34

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.6 \cdot 10^{+231}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -1.05 \cdot 10^{+40}:\\ \;\;\;\;x \cdot \left(-z\right)\\ \mathbf{elif}\;x \leq -3 \cdot 10^{-109}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 6.2 \cdot 10^{-34}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq 1.65 \cdot 10^{+41} \lor \neg \left(x \leq 1.95 \cdot 10^{+76} \lor \neg \left(x \leq 7.5 \cdot 10^{+140}\right) \land \left(x \leq 1.3 \cdot 10^{+215} \lor \neg \left(x \leq 1.2 \cdot 10^{+278}\right) \land x \leq 2.5 \cdot 10^{+297}\right)\right):\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(-z\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 61.1% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \left(-z\right)\\ \mathbf{if}\;x \leq -5.2 \cdot 10^{+230}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -1.1 \cdot 10^{+40}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq -3 \cdot 10^{-109}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 7.2 \cdot 10^{-41}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq 7.2 \cdot 10^{+36}:\\ \;\;\;\;x \cdot \left(y + z\right)\\ \mathbf{elif}\;x \leq 8.8 \cdot 10^{+76} \lor \neg \left(x \leq 3.1 \cdot 10^{+140}\right) \land \left(x \leq 1.5 \cdot 10^{+218} \lor \neg \left(x \leq 3.2 \cdot 10^{+281}\right) \land x \leq 3.8 \cdot 10^{+297}\right):\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* x (- z))))
   (if (<= x -5.2e+230)
     (* x y)
     (if (<= x -1.1e+40)
       t_0
       (if (<= x -3e-109)
         (* x y)
         (if (<= x 7.2e-41)
           z
           (if (<= x 7.2e+36)
             (* x (+ y z))
             (if (or (<= x 8.8e+76)
                     (and (not (<= x 3.1e+140))
                          (or (<= x 1.5e+218)
                              (and (not (<= x 3.2e+281)) (<= x 3.8e+297)))))
               t_0
               (* x y)))))))))
double code(double x, double y, double z) {
	double t_0 = x * -z;
	double tmp;
	if (x <= -5.2e+230) {
		tmp = x * y;
	} else if (x <= -1.1e+40) {
		tmp = t_0;
	} else if (x <= -3e-109) {
		tmp = x * y;
	} else if (x <= 7.2e-41) {
		tmp = z;
	} else if (x <= 7.2e+36) {
		tmp = x * (y + z);
	} else if ((x <= 8.8e+76) || (!(x <= 3.1e+140) && ((x <= 1.5e+218) || (!(x <= 3.2e+281) && (x <= 3.8e+297))))) {
		tmp = t_0;
	} else {
		tmp = x * y;
	}
	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 (x <= (-5.2d+230)) then
        tmp = x * y
    else if (x <= (-1.1d+40)) then
        tmp = t_0
    else if (x <= (-3d-109)) then
        tmp = x * y
    else if (x <= 7.2d-41) then
        tmp = z
    else if (x <= 7.2d+36) then
        tmp = x * (y + z)
    else if ((x <= 8.8d+76) .or. (.not. (x <= 3.1d+140)) .and. (x <= 1.5d+218) .or. (.not. (x <= 3.2d+281)) .and. (x <= 3.8d+297)) then
        tmp = t_0
    else
        tmp = x * y
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = x * -z;
	double tmp;
	if (x <= -5.2e+230) {
		tmp = x * y;
	} else if (x <= -1.1e+40) {
		tmp = t_0;
	} else if (x <= -3e-109) {
		tmp = x * y;
	} else if (x <= 7.2e-41) {
		tmp = z;
	} else if (x <= 7.2e+36) {
		tmp = x * (y + z);
	} else if ((x <= 8.8e+76) || (!(x <= 3.1e+140) && ((x <= 1.5e+218) || (!(x <= 3.2e+281) && (x <= 3.8e+297))))) {
		tmp = t_0;
	} else {
		tmp = x * y;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = x * -z
	tmp = 0
	if x <= -5.2e+230:
		tmp = x * y
	elif x <= -1.1e+40:
		tmp = t_0
	elif x <= -3e-109:
		tmp = x * y
	elif x <= 7.2e-41:
		tmp = z
	elif x <= 7.2e+36:
		tmp = x * (y + z)
	elif (x <= 8.8e+76) or (not (x <= 3.1e+140) and ((x <= 1.5e+218) or (not (x <= 3.2e+281) and (x <= 3.8e+297)))):
		tmp = t_0
	else:
		tmp = x * y
	return tmp
function code(x, y, z)
	t_0 = Float64(x * Float64(-z))
	tmp = 0.0
	if (x <= -5.2e+230)
		tmp = Float64(x * y);
	elseif (x <= -1.1e+40)
		tmp = t_0;
	elseif (x <= -3e-109)
		tmp = Float64(x * y);
	elseif (x <= 7.2e-41)
		tmp = z;
	elseif (x <= 7.2e+36)
		tmp = Float64(x * Float64(y + z));
	elseif ((x <= 8.8e+76) || (!(x <= 3.1e+140) && ((x <= 1.5e+218) || (!(x <= 3.2e+281) && (x <= 3.8e+297)))))
		tmp = t_0;
	else
		tmp = Float64(x * y);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = x * -z;
	tmp = 0.0;
	if (x <= -5.2e+230)
		tmp = x * y;
	elseif (x <= -1.1e+40)
		tmp = t_0;
	elseif (x <= -3e-109)
		tmp = x * y;
	elseif (x <= 7.2e-41)
		tmp = z;
	elseif (x <= 7.2e+36)
		tmp = x * (y + z);
	elseif ((x <= 8.8e+76) || (~((x <= 3.1e+140)) && ((x <= 1.5e+218) || (~((x <= 3.2e+281)) && (x <= 3.8e+297)))))
		tmp = t_0;
	else
		tmp = x * y;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-z)), $MachinePrecision]}, If[LessEqual[x, -5.2e+230], N[(x * y), $MachinePrecision], If[LessEqual[x, -1.1e+40], t$95$0, If[LessEqual[x, -3e-109], N[(x * y), $MachinePrecision], If[LessEqual[x, 7.2e-41], z, If[LessEqual[x, 7.2e+36], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[x, 8.8e+76], And[N[Not[LessEqual[x, 3.1e+140]], $MachinePrecision], Or[LessEqual[x, 1.5e+218], And[N[Not[LessEqual[x, 3.2e+281]], $MachinePrecision], LessEqual[x, 3.8e+297]]]]], t$95$0, N[(x * y), $MachinePrecision]]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;x \leq -1.1 \cdot 10^{+40}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;x \leq 7.2 \cdot 10^{-41}:\\
\;\;\;\;z\\

\mathbf{elif}\;x \leq 7.2 \cdot 10^{+36}:\\
\;\;\;\;x \cdot \left(y + z\right)\\

\mathbf{elif}\;x \leq 8.8 \cdot 10^{+76} \lor \neg \left(x \leq 3.1 \cdot 10^{+140}\right) \land \left(x \leq 1.5 \cdot 10^{+218} \lor \neg \left(x \leq 3.2 \cdot 10^{+281}\right) \land x \leq 3.8 \cdot 10^{+297}\right):\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if x < -5.1999999999999997e230 or -1.0999999999999999e40 < x < -3.00000000000000021e-109 or 8.8000000000000002e76 < x < 3.1e140 or 1.5e218 < x < 3.2000000000000001e281 or 3.7999999999999999e297 < x

    1. Initial program 94.3%

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

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

    if -5.1999999999999997e230 < x < -1.0999999999999999e40 or 7.1999999999999995e36 < x < 8.8000000000000002e76 or 3.1e140 < x < 1.5e218 or 3.2000000000000001e281 < x < 3.7999999999999999e297

    1. Initial program 98.7%

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(x \cdot z\right)} \]
    7. Step-by-step derivation
      1. associate-*r*69.1%

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

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

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

    if -3.00000000000000021e-109 < x < 7.2e-41

    1. Initial program 100.0%

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

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

    if 7.2e-41 < x < 7.1999999999999995e36

    1. Initial program 99.9%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{x \cdot y} + \left(-z\right) \cdot x \]
      4. add-sqr-sqrt66.1%

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

        \[\leadsto x \cdot y + \left(-z\right) \cdot \color{blue}{\sqrt{x \cdot x}} \]
      6. sqr-neg66.1%

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

        \[\leadsto x \cdot y + \left(-z\right) \cdot \color{blue}{\left(\sqrt{-x} \cdot \sqrt{-x}\right)} \]
      8. add-sqr-sqrt57.6%

        \[\leadsto x \cdot y + \left(-z\right) \cdot \color{blue}{\left(-x\right)} \]
      9. cancel-sign-sub-inv57.6%

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

        \[\leadsto x \cdot y - \color{blue}{\left(-x\right) \cdot z} \]
      11. cancel-sign-sub57.6%

        \[\leadsto \color{blue}{x \cdot y + x \cdot z} \]
    7. Applied egg-rr57.6%

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

        \[\leadsto \color{blue}{x \cdot z + x \cdot y} \]
      2. distribute-lft-out57.6%

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

      \[\leadsto \color{blue}{x \cdot \left(z + y\right)} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification72.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -5.2 \cdot 10^{+230}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -1.1 \cdot 10^{+40}:\\ \;\;\;\;x \cdot \left(-z\right)\\ \mathbf{elif}\;x \leq -3 \cdot 10^{-109}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 7.2 \cdot 10^{-41}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq 7.2 \cdot 10^{+36}:\\ \;\;\;\;x \cdot \left(y + z\right)\\ \mathbf{elif}\;x \leq 8.8 \cdot 10^{+76} \lor \neg \left(x \leq 3.1 \cdot 10^{+140}\right) \land \left(x \leq 1.5 \cdot 10^{+218} \lor \neg \left(x \leq 3.2 \cdot 10^{+281}\right) \land x \leq 3.8 \cdot 10^{+297}\right):\\ \;\;\;\;x \cdot \left(-z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 84.0% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.25 \cdot 10^{-112} \lor \neg \left(x \leq 8.5 \cdot 10^{-33}\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -3.24999999999999978e-112 or 8.49999999999999945e-33 < x

    1. Initial program 97.1%

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

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

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

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

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

    if -3.24999999999999978e-112 < x < 8.49999999999999945e-33

    1. Initial program 100.0%

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

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

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

Alternative 5: 84.3% accurate, 0.6× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -3.00000000000000021e-109 or 280 < x

    1. Initial program 96.9%

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

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

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

        \[\leadsto x \cdot \color{blue}{\left(y - z\right)} \]
    5. Simplified94.9%

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

    if -3.00000000000000021e-109 < x < 280

    1. Initial program 100.0%

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

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

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

Alternative 6: 99.1% accurate, 0.6× speedup?

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

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

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


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

    1. Initial program 96.4%

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

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

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

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

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

    if -1 < x < 1

    1. Initial program 99.9%

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

        \[\leadsto \color{blue}{\left(1 - x\right) \cdot z + x \cdot y} \]
      2. remove-double-neg99.9%

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

        \[\leadsto \left(-\color{blue}{\left(1 - x\right) \cdot \left(-z\right)}\right) + x \cdot y \]
      4. neg-sub099.9%

        \[\leadsto \color{blue}{\left(0 - \left(1 - x\right) \cdot \left(-z\right)\right)} + x \cdot y \]
      5. neg-sub099.9%

        \[\leadsto \color{blue}{\left(-\left(1 - x\right) \cdot \left(-z\right)\right)} + x \cdot y \]
      6. *-commutative99.9%

        \[\leadsto \left(-\color{blue}{\left(-z\right) \cdot \left(1 - x\right)}\right) + x \cdot y \]
      7. distribute-lft-neg-in99.9%

        \[\leadsto \color{blue}{\left(-\left(-z\right)\right) \cdot \left(1 - x\right)} + x \cdot y \]
      8. remove-double-neg99.9%

        \[\leadsto \color{blue}{z} \cdot \left(1 - x\right) + x \cdot y \]
      9. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{\left(1 \cdot z - x \cdot z\right)} + x \cdot y \]
      10. *-lft-identity100.0%

        \[\leadsto \left(\color{blue}{z} - x \cdot z\right) + x \cdot y \]
      11. associate-+l-100.0%

        \[\leadsto \color{blue}{z - \left(x \cdot z - x \cdot y\right)} \]
      12. distribute-lft-out--100.0%

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

      \[\leadsto \color{blue}{z - x \cdot \left(z - y\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in z around 0 98.1%

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

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

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

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

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

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

        \[\leadsto \left(-\color{blue}{\left(-x \cdot y\right)}\right) + z \]
      4. remove-double-neg98.1%

        \[\leadsto \color{blue}{x \cdot y} + z \]
    9. Applied egg-rr98.1%

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

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

Alternative 7: 60.3% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -3 \cdot 10^{-109} \lor \neg \left(x \leq 2.75 \cdot 10^{-33}\right):\\
\;\;\;\;x \cdot y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -3.00000000000000021e-109 or 2.75e-33 < x

    1. Initial program 97.1%

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

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

    if -3.00000000000000021e-109 < x < 2.75e-33

    1. Initial program 100.0%

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

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

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

Alternative 8: 100.0% accurate, 1.3× speedup?

\[\begin{array}{l} \\ z + x \cdot \left(y - z\right) \end{array} \]
(FPCore (x y z) :precision binary64 (+ z (* x (- y z))))
double code(double x, double y, double z) {
	return z + (x * (y - z));
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = z + (x * (y - z))
end function
public static double code(double x, double y, double z) {
	return z + (x * (y - z));
}
def code(x, y, z):
	return z + (x * (y - z))
function code(x, y, z)
	return Float64(z + Float64(x * Float64(y - z)))
end
function tmp = code(x, y, z)
	tmp = z + (x * (y - z));
end
code[x_, y_, z_] := N[(z + N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
z + x \cdot \left(y - z\right)
\end{array}
Derivation
  1. Initial program 98.0%

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

      \[\leadsto \color{blue}{\left(1 - x\right) \cdot z + x \cdot y} \]
    2. remove-double-neg98.0%

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

      \[\leadsto \left(-\color{blue}{\left(1 - x\right) \cdot \left(-z\right)}\right) + x \cdot y \]
    4. neg-sub098.0%

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

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

      \[\leadsto \left(-\color{blue}{\left(-z\right) \cdot \left(1 - x\right)}\right) + x \cdot y \]
    7. distribute-lft-neg-in98.0%

      \[\leadsto \color{blue}{\left(-\left(-z\right)\right) \cdot \left(1 - x\right)} + x \cdot y \]
    8. remove-double-neg98.0%

      \[\leadsto \color{blue}{z} \cdot \left(1 - x\right) + x \cdot y \]
    9. distribute-rgt-out--98.0%

      \[\leadsto \color{blue}{\left(1 \cdot z - x \cdot z\right)} + x \cdot y \]
    10. *-lft-identity98.0%

      \[\leadsto \left(\color{blue}{z} - x \cdot z\right) + x \cdot y \]
    11. associate-+l-98.0%

      \[\leadsto \color{blue}{z - \left(x \cdot z - x \cdot y\right)} \]
    12. distribute-lft-out--100.0%

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

    \[\leadsto \color{blue}{z - x \cdot \left(z - y\right)} \]
  4. Add Preprocessing
  5. Final simplification100.0%

    \[\leadsto z + x \cdot \left(y - z\right) \]
  6. Add Preprocessing

Alternative 9: 35.3% accurate, 9.0× speedup?

\[\begin{array}{l} \\ z \end{array} \]
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
	return z;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = z
end function
public static double code(double x, double y, double z) {
	return z;
}
def code(x, y, z):
	return z
function code(x, y, z)
	return z
end
function tmp = code(x, y, z)
	tmp = z;
end
code[x_, y_, z_] := z
\begin{array}{l}

\\
z
\end{array}
Derivation
  1. Initial program 98.0%

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

    \[\leadsto \color{blue}{z} \]
  4. Final simplification30.9%

    \[\leadsto z \]
  5. Add Preprocessing

Reproduce

?
herbie shell --seed 2024059 
(FPCore (x y z)
  :name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
  :precision binary64
  (+ (* x y) (* (- 1.0 x) z)))