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

Percentage Accurate: 98.0% → 100.0%
Time: 5.7s
Alternatives: 7
Speedup: 1.7×

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 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: 98.0% 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, 1.7× speedup?

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

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

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

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

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

      \[\leadsto \color{blue}{\left(1 - x\right) \cdot z} + x \cdot y \]
    3. sub-negN/A

      \[\leadsto \color{blue}{\left(1 + \left(\mathsf{neg}\left(x\right)\right)\right)} \cdot z + x \cdot y \]
    4. mul-1-negN/A

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

      \[\leadsto \color{blue}{\left(-1 \cdot x + 1\right)} \cdot z + x \cdot y \]
    6. distribute-lft1-inN/A

      \[\leadsto \color{blue}{\left(\left(-1 \cdot x\right) \cdot z + z\right)} + x \cdot y \]
    7. associate-*r*N/A

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

      \[\leadsto \color{blue}{\left(z + -1 \cdot \left(x \cdot z\right)\right)} + x \cdot y \]
    9. mul-1-negN/A

      \[\leadsto \left(z + \color{blue}{\left(\mathsf{neg}\left(x \cdot z\right)\right)}\right) + x \cdot y \]
    10. unsub-negN/A

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

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

      \[\leadsto z - \color{blue}{x \cdot \left(z - y\right)} \]
    13. unsub-negN/A

      \[\leadsto z - x \cdot \color{blue}{\left(z + \left(\mathsf{neg}\left(y\right)\right)\right)} \]
    14. mul-1-negN/A

      \[\leadsto z - x \cdot \left(z + \color{blue}{-1 \cdot y}\right) \]
    15. sub-negN/A

      \[\leadsto \color{blue}{z + \left(\mathsf{neg}\left(x \cdot \left(z + -1 \cdot y\right)\right)\right)} \]
    16. mul-1-negN/A

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

      \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \left(z + -1 \cdot y\right)\right) + z} \]
    18. mul-1-negN/A

      \[\leadsto \color{blue}{\left(\mathsf{neg}\left(x \cdot \left(z + -1 \cdot y\right)\right)\right)} + z \]
    19. *-commutativeN/A

      \[\leadsto \left(\mathsf{neg}\left(\color{blue}{\left(z + -1 \cdot y\right) \cdot x}\right)\right) + z \]
    20. distribute-lft-neg-inN/A

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

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

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

Alternative 2: 61.1% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.9 \cdot 10^{-8}:\\
\;\;\;\;y \cdot x\\

\mathbf{elif}\;x \leq 1.45 \cdot 10^{-24}:\\
\;\;\;\;1 \cdot z\\

\mathbf{elif}\;x \leq 8.8 \cdot 10^{+108}:\\
\;\;\;\;y \cdot x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -4.9000000000000002e-8 or 1.4499999999999999e-24 < x < 8.8000000000000005e108

    1. Initial program 92.4%

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

      \[\leadsto \color{blue}{x \cdot y} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{y \cdot x} \]
      2. lower-*.f6462.1

        \[\leadsto \color{blue}{y \cdot x} \]
    5. Applied rewrites62.1%

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

    if -4.9000000000000002e-8 < x < 1.4499999999999999e-24

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{z \cdot \left(1 - x\right)} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{\left(1 - x\right) \cdot z} \]
      2. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(1 - x\right) \cdot z} \]
      3. lower--.f6470.4

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

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

      \[\leadsto 1 \cdot z \]
    7. Step-by-step derivation
      1. Applied rewrites70.4%

        \[\leadsto 1 \cdot z \]

      if 8.8000000000000005e108 < x

      1. Initial program 89.1%

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

        \[\leadsto \color{blue}{x \cdot \left(y + -1 \cdot z\right)} \]
      4. Step-by-step derivation
        1. *-commutativeN/A

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

          \[\leadsto \color{blue}{\left(-1 \cdot z + y\right)} \cdot x \]
        3. remove-double-negN/A

          \[\leadsto \left(-1 \cdot z + \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)\right)}\right) \cdot x \]
        4. mul-1-negN/A

          \[\leadsto \left(-1 \cdot z + \left(\mathsf{neg}\left(\color{blue}{-1 \cdot y}\right)\right)\right) \cdot x \]
        5. mul-1-negN/A

          \[\leadsto \left(\color{blue}{\left(\mathsf{neg}\left(z\right)\right)} + \left(\mathsf{neg}\left(-1 \cdot y\right)\right)\right) \cdot x \]
        6. distribute-neg-inN/A

          \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\left(z + -1 \cdot y\right)\right)\right)} \cdot x \]
        7. lower-*.f64N/A

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

          \[\leadsto \left(\mathsf{neg}\left(\color{blue}{\left(-1 \cdot y + z\right)}\right)\right) \cdot x \]
        9. distribute-neg-inN/A

          \[\leadsto \color{blue}{\left(\left(\mathsf{neg}\left(-1 \cdot y\right)\right) + \left(\mathsf{neg}\left(z\right)\right)\right)} \cdot x \]
        10. mul-1-negN/A

          \[\leadsto \left(\left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(y\right)\right)}\right)\right) + \left(\mathsf{neg}\left(z\right)\right)\right) \cdot x \]
        11. remove-double-negN/A

          \[\leadsto \left(\color{blue}{y} + \left(\mathsf{neg}\left(z\right)\right)\right) \cdot x \]
        12. unsub-negN/A

          \[\leadsto \color{blue}{\left(y - z\right)} \cdot x \]
        13. lower--.f64100.0

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

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

        \[\leadsto \left(-1 \cdot z\right) \cdot x \]
      7. Step-by-step derivation
        1. Applied rewrites70.6%

          \[\leadsto \left(-z\right) \cdot x \]
      8. Recombined 3 regimes into one program.
      9. Add Preprocessing

      Alternative 3: 78.9% accurate, 0.8× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(y - z\right) \cdot x\\ \mathbf{if}\;y \leq -2.9 \cdot 10^{-79}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 2.8 \cdot 10^{+25}:\\ \;\;\;\;\mathsf{fma}\left(-z, x, z\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
      (FPCore (x y z)
       :precision binary64
       (let* ((t_0 (* (- y z) x)))
         (if (<= y -2.9e-79) t_0 (if (<= y 2.8e+25) (fma (- z) x z) t_0))))
      double code(double x, double y, double z) {
      	double t_0 = (y - z) * x;
      	double tmp;
      	if (y <= -2.9e-79) {
      		tmp = t_0;
      	} else if (y <= 2.8e+25) {
      		tmp = fma(-z, x, z);
      	} else {
      		tmp = t_0;
      	}
      	return tmp;
      }
      
      function code(x, y, z)
      	t_0 = Float64(Float64(y - z) * x)
      	tmp = 0.0
      	if (y <= -2.9e-79)
      		tmp = t_0;
      	elseif (y <= 2.8e+25)
      		tmp = fma(Float64(-z), x, z);
      	else
      		tmp = t_0;
      	end
      	return tmp
      end
      
      code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y - z), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[y, -2.9e-79], t$95$0, If[LessEqual[y, 2.8e+25], N[((-z) * x + z), $MachinePrecision], t$95$0]]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      t_0 := \left(y - z\right) \cdot x\\
      \mathbf{if}\;y \leq -2.9 \cdot 10^{-79}:\\
      \;\;\;\;t\_0\\
      
      \mathbf{elif}\;y \leq 2.8 \cdot 10^{+25}:\\
      \;\;\;\;\mathsf{fma}\left(-z, x, z\right)\\
      
      \mathbf{else}:\\
      \;\;\;\;t\_0\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if y < -2.9000000000000001e-79 or 2.8000000000000002e25 < y

        1. Initial program 91.1%

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

          \[\leadsto \color{blue}{x \cdot \left(y + -1 \cdot z\right)} \]
        4. Step-by-step derivation
          1. *-commutativeN/A

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

            \[\leadsto \color{blue}{\left(-1 \cdot z + y\right)} \cdot x \]
          3. remove-double-negN/A

            \[\leadsto \left(-1 \cdot z + \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)\right)}\right) \cdot x \]
          4. mul-1-negN/A

            \[\leadsto \left(-1 \cdot z + \left(\mathsf{neg}\left(\color{blue}{-1 \cdot y}\right)\right)\right) \cdot x \]
          5. mul-1-negN/A

            \[\leadsto \left(\color{blue}{\left(\mathsf{neg}\left(z\right)\right)} + \left(\mathsf{neg}\left(-1 \cdot y\right)\right)\right) \cdot x \]
          6. distribute-neg-inN/A

            \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\left(z + -1 \cdot y\right)\right)\right)} \cdot x \]
          7. lower-*.f64N/A

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

            \[\leadsto \left(\mathsf{neg}\left(\color{blue}{\left(-1 \cdot y + z\right)}\right)\right) \cdot x \]
          9. distribute-neg-inN/A

            \[\leadsto \color{blue}{\left(\left(\mathsf{neg}\left(-1 \cdot y\right)\right) + \left(\mathsf{neg}\left(z\right)\right)\right)} \cdot x \]
          10. mul-1-negN/A

            \[\leadsto \left(\left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(y\right)\right)}\right)\right) + \left(\mathsf{neg}\left(z\right)\right)\right) \cdot x \]
          11. remove-double-negN/A

            \[\leadsto \left(\color{blue}{y} + \left(\mathsf{neg}\left(z\right)\right)\right) \cdot x \]
          12. unsub-negN/A

            \[\leadsto \color{blue}{\left(y - z\right)} \cdot x \]
          13. lower--.f6484.3

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

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

        if -2.9000000000000001e-79 < y < 2.8000000000000002e25

        1. Initial program 100.0%

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

          \[\leadsto \color{blue}{z \cdot \left(1 - x\right)} \]
        4. Step-by-step derivation
          1. *-commutativeN/A

            \[\leadsto \color{blue}{\left(1 - x\right) \cdot z} \]
          2. lower-*.f64N/A

            \[\leadsto \color{blue}{\left(1 - x\right) \cdot z} \]
          3. lower--.f6487.5

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

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

            \[\leadsto \mathsf{fma}\left(-z, \color{blue}{x}, z\right) \]
        7. Recombined 2 regimes into one program.
        8. Add Preprocessing

        Alternative 4: 78.9% accurate, 0.8× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(y - z\right) \cdot x\\ \mathbf{if}\;y \leq -2.9 \cdot 10^{-79}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 2.8 \cdot 10^{+25}:\\ \;\;\;\;\left(1 - x\right) \cdot z\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
        (FPCore (x y z)
         :precision binary64
         (let* ((t_0 (* (- y z) x)))
           (if (<= y -2.9e-79) t_0 (if (<= y 2.8e+25) (* (- 1.0 x) z) t_0))))
        double code(double x, double y, double z) {
        	double t_0 = (y - z) * x;
        	double tmp;
        	if (y <= -2.9e-79) {
        		tmp = t_0;
        	} else if (y <= 2.8e+25) {
        		tmp = (1.0 - x) * 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 = (y - z) * x
            if (y <= (-2.9d-79)) then
                tmp = t_0
            else if (y <= 2.8d+25) then
                tmp = (1.0d0 - x) * z
            else
                tmp = t_0
            end if
            code = tmp
        end function
        
        public static double code(double x, double y, double z) {
        	double t_0 = (y - z) * x;
        	double tmp;
        	if (y <= -2.9e-79) {
        		tmp = t_0;
        	} else if (y <= 2.8e+25) {
        		tmp = (1.0 - x) * z;
        	} else {
        		tmp = t_0;
        	}
        	return tmp;
        }
        
        def code(x, y, z):
        	t_0 = (y - z) * x
        	tmp = 0
        	if y <= -2.9e-79:
        		tmp = t_0
        	elif y <= 2.8e+25:
        		tmp = (1.0 - x) * z
        	else:
        		tmp = t_0
        	return tmp
        
        function code(x, y, z)
        	t_0 = Float64(Float64(y - z) * x)
        	tmp = 0.0
        	if (y <= -2.9e-79)
        		tmp = t_0;
        	elseif (y <= 2.8e+25)
        		tmp = Float64(Float64(1.0 - x) * z);
        	else
        		tmp = t_0;
        	end
        	return tmp
        end
        
        function tmp_2 = code(x, y, z)
        	t_0 = (y - z) * x;
        	tmp = 0.0;
        	if (y <= -2.9e-79)
        		tmp = t_0;
        	elseif (y <= 2.8e+25)
        		tmp = (1.0 - x) * z;
        	else
        		tmp = t_0;
        	end
        	tmp_2 = tmp;
        end
        
        code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y - z), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[y, -2.9e-79], t$95$0, If[LessEqual[y, 2.8e+25], N[(N[(1.0 - x), $MachinePrecision] * z), $MachinePrecision], t$95$0]]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        t_0 := \left(y - z\right) \cdot x\\
        \mathbf{if}\;y \leq -2.9 \cdot 10^{-79}:\\
        \;\;\;\;t\_0\\
        
        \mathbf{elif}\;y \leq 2.8 \cdot 10^{+25}:\\
        \;\;\;\;\left(1 - x\right) \cdot z\\
        
        \mathbf{else}:\\
        \;\;\;\;t\_0\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if y < -2.9000000000000001e-79 or 2.8000000000000002e25 < y

          1. Initial program 91.1%

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

            \[\leadsto \color{blue}{x \cdot \left(y + -1 \cdot z\right)} \]
          4. Step-by-step derivation
            1. *-commutativeN/A

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

              \[\leadsto \color{blue}{\left(-1 \cdot z + y\right)} \cdot x \]
            3. remove-double-negN/A

              \[\leadsto \left(-1 \cdot z + \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)\right)}\right) \cdot x \]
            4. mul-1-negN/A

              \[\leadsto \left(-1 \cdot z + \left(\mathsf{neg}\left(\color{blue}{-1 \cdot y}\right)\right)\right) \cdot x \]
            5. mul-1-negN/A

              \[\leadsto \left(\color{blue}{\left(\mathsf{neg}\left(z\right)\right)} + \left(\mathsf{neg}\left(-1 \cdot y\right)\right)\right) \cdot x \]
            6. distribute-neg-inN/A

              \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\left(z + -1 \cdot y\right)\right)\right)} \cdot x \]
            7. lower-*.f64N/A

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

              \[\leadsto \left(\mathsf{neg}\left(\color{blue}{\left(-1 \cdot y + z\right)}\right)\right) \cdot x \]
            9. distribute-neg-inN/A

              \[\leadsto \color{blue}{\left(\left(\mathsf{neg}\left(-1 \cdot y\right)\right) + \left(\mathsf{neg}\left(z\right)\right)\right)} \cdot x \]
            10. mul-1-negN/A

              \[\leadsto \left(\left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(y\right)\right)}\right)\right) + \left(\mathsf{neg}\left(z\right)\right)\right) \cdot x \]
            11. remove-double-negN/A

              \[\leadsto \left(\color{blue}{y} + \left(\mathsf{neg}\left(z\right)\right)\right) \cdot x \]
            12. unsub-negN/A

              \[\leadsto \color{blue}{\left(y - z\right)} \cdot x \]
            13. lower--.f6484.3

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

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

          if -2.9000000000000001e-79 < y < 2.8000000000000002e25

          1. Initial program 100.0%

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

            \[\leadsto \color{blue}{z \cdot \left(1 - x\right)} \]
          4. Step-by-step derivation
            1. *-commutativeN/A

              \[\leadsto \color{blue}{\left(1 - x\right) \cdot z} \]
            2. lower-*.f64N/A

              \[\leadsto \color{blue}{\left(1 - x\right) \cdot z} \]
            3. lower--.f6487.5

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

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

        Alternative 5: 75.1% accurate, 0.8× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1.65 \cdot 10^{+99}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 2.8 \cdot 10^{+25}:\\ \;\;\;\;\left(1 - x\right) \cdot z\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \end{array} \]
        (FPCore (x y z)
         :precision binary64
         (if (<= y -1.65e+99) (* y x) (if (<= y 2.8e+25) (* (- 1.0 x) z) (* y x))))
        double code(double x, double y, double z) {
        	double tmp;
        	if (y <= -1.65e+99) {
        		tmp = y * x;
        	} else if (y <= 2.8e+25) {
        		tmp = (1.0 - x) * z;
        	} else {
        		tmp = y * 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 (y <= (-1.65d+99)) then
                tmp = y * x
            else if (y <= 2.8d+25) then
                tmp = (1.0d0 - x) * z
            else
                tmp = y * x
            end if
            code = tmp
        end function
        
        public static double code(double x, double y, double z) {
        	double tmp;
        	if (y <= -1.65e+99) {
        		tmp = y * x;
        	} else if (y <= 2.8e+25) {
        		tmp = (1.0 - x) * z;
        	} else {
        		tmp = y * x;
        	}
        	return tmp;
        }
        
        def code(x, y, z):
        	tmp = 0
        	if y <= -1.65e+99:
        		tmp = y * x
        	elif y <= 2.8e+25:
        		tmp = (1.0 - x) * z
        	else:
        		tmp = y * x
        	return tmp
        
        function code(x, y, z)
        	tmp = 0.0
        	if (y <= -1.65e+99)
        		tmp = Float64(y * x);
        	elseif (y <= 2.8e+25)
        		tmp = Float64(Float64(1.0 - x) * z);
        	else
        		tmp = Float64(y * x);
        	end
        	return tmp
        end
        
        function tmp_2 = code(x, y, z)
        	tmp = 0.0;
        	if (y <= -1.65e+99)
        		tmp = y * x;
        	elseif (y <= 2.8e+25)
        		tmp = (1.0 - x) * z;
        	else
        		tmp = y * x;
        	end
        	tmp_2 = tmp;
        end
        
        code[x_, y_, z_] := If[LessEqual[y, -1.65e+99], N[(y * x), $MachinePrecision], If[LessEqual[y, 2.8e+25], N[(N[(1.0 - x), $MachinePrecision] * z), $MachinePrecision], N[(y * x), $MachinePrecision]]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        \mathbf{if}\;y \leq -1.65 \cdot 10^{+99}:\\
        \;\;\;\;y \cdot x\\
        
        \mathbf{elif}\;y \leq 2.8 \cdot 10^{+25}:\\
        \;\;\;\;\left(1 - x\right) \cdot z\\
        
        \mathbf{else}:\\
        \;\;\;\;y \cdot x\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if y < -1.65e99 or 2.8000000000000002e25 < y

          1. Initial program 88.7%

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

            \[\leadsto \color{blue}{x \cdot y} \]
          4. Step-by-step derivation
            1. *-commutativeN/A

              \[\leadsto \color{blue}{y \cdot x} \]
            2. lower-*.f6477.3

              \[\leadsto \color{blue}{y \cdot x} \]
          5. Applied rewrites77.3%

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

          if -1.65e99 < y < 2.8000000000000002e25

          1. Initial program 100.0%

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

            \[\leadsto \color{blue}{z \cdot \left(1 - x\right)} \]
          4. Step-by-step derivation
            1. *-commutativeN/A

              \[\leadsto \color{blue}{\left(1 - x\right) \cdot z} \]
            2. lower-*.f64N/A

              \[\leadsto \color{blue}{\left(1 - x\right) \cdot z} \]
            3. lower--.f6481.0

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

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

        Alternative 6: 55.7% accurate, 0.9× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -2 \cdot 10^{-42}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 2.8 \cdot 10^{+25}:\\ \;\;\;\;1 \cdot z\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \end{array} \]
        (FPCore (x y z)
         :precision binary64
         (if (<= y -2e-42) (* y x) (if (<= y 2.8e+25) (* 1.0 z) (* y x))))
        double code(double x, double y, double z) {
        	double tmp;
        	if (y <= -2e-42) {
        		tmp = y * x;
        	} else if (y <= 2.8e+25) {
        		tmp = 1.0 * z;
        	} else {
        		tmp = y * 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 (y <= (-2d-42)) then
                tmp = y * x
            else if (y <= 2.8d+25) then
                tmp = 1.0d0 * z
            else
                tmp = y * x
            end if
            code = tmp
        end function
        
        public static double code(double x, double y, double z) {
        	double tmp;
        	if (y <= -2e-42) {
        		tmp = y * x;
        	} else if (y <= 2.8e+25) {
        		tmp = 1.0 * z;
        	} else {
        		tmp = y * x;
        	}
        	return tmp;
        }
        
        def code(x, y, z):
        	tmp = 0
        	if y <= -2e-42:
        		tmp = y * x
        	elif y <= 2.8e+25:
        		tmp = 1.0 * z
        	else:
        		tmp = y * x
        	return tmp
        
        function code(x, y, z)
        	tmp = 0.0
        	if (y <= -2e-42)
        		tmp = Float64(y * x);
        	elseif (y <= 2.8e+25)
        		tmp = Float64(1.0 * z);
        	else
        		tmp = Float64(y * x);
        	end
        	return tmp
        end
        
        function tmp_2 = code(x, y, z)
        	tmp = 0.0;
        	if (y <= -2e-42)
        		tmp = y * x;
        	elseif (y <= 2.8e+25)
        		tmp = 1.0 * z;
        	else
        		tmp = y * x;
        	end
        	tmp_2 = tmp;
        end
        
        code[x_, y_, z_] := If[LessEqual[y, -2e-42], N[(y * x), $MachinePrecision], If[LessEqual[y, 2.8e+25], N[(1.0 * z), $MachinePrecision], N[(y * x), $MachinePrecision]]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        \mathbf{if}\;y \leq -2 \cdot 10^{-42}:\\
        \;\;\;\;y \cdot x\\
        
        \mathbf{elif}\;y \leq 2.8 \cdot 10^{+25}:\\
        \;\;\;\;1 \cdot z\\
        
        \mathbf{else}:\\
        \;\;\;\;y \cdot x\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if y < -2.00000000000000008e-42 or 2.8000000000000002e25 < y

          1. Initial program 90.8%

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

            \[\leadsto \color{blue}{x \cdot y} \]
          4. Step-by-step derivation
            1. *-commutativeN/A

              \[\leadsto \color{blue}{y \cdot x} \]
            2. lower-*.f6472.4

              \[\leadsto \color{blue}{y \cdot x} \]
          5. Applied rewrites72.4%

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

          if -2.00000000000000008e-42 < y < 2.8000000000000002e25

          1. Initial program 100.0%

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

            \[\leadsto \color{blue}{z \cdot \left(1 - x\right)} \]
          4. Step-by-step derivation
            1. *-commutativeN/A

              \[\leadsto \color{blue}{\left(1 - x\right) \cdot z} \]
            2. lower-*.f64N/A

              \[\leadsto \color{blue}{\left(1 - x\right) \cdot z} \]
            3. lower--.f6486.5

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

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

            \[\leadsto 1 \cdot z \]
          7. Step-by-step derivation
            1. Applied rewrites52.6%

              \[\leadsto 1 \cdot z \]
          8. Recombined 2 regimes into one program.
          9. Add Preprocessing

          Alternative 7: 42.0% accurate, 2.8× speedup?

          \[\begin{array}{l} \\ y \cdot x \end{array} \]
          (FPCore (x y z) :precision binary64 (* y x))
          double code(double x, double y, double z) {
          	return y * x;
          }
          
          real(8) function code(x, y, z)
              real(8), intent (in) :: x
              real(8), intent (in) :: y
              real(8), intent (in) :: z
              code = y * x
          end function
          
          public static double code(double x, double y, double z) {
          	return y * x;
          }
          
          def code(x, y, z):
          	return y * x
          
          function code(x, y, z)
          	return Float64(y * x)
          end
          
          function tmp = code(x, y, z)
          	tmp = y * x;
          end
          
          code[x_, y_, z_] := N[(y * x), $MachinePrecision]
          
          \begin{array}{l}
          
          \\
          y \cdot x
          \end{array}
          
          Derivation
          1. Initial program 95.3%

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

            \[\leadsto \color{blue}{x \cdot y} \]
          4. Step-by-step derivation
            1. *-commutativeN/A

              \[\leadsto \color{blue}{y \cdot x} \]
            2. lower-*.f6444.1

              \[\leadsto \color{blue}{y \cdot x} \]
          5. Applied rewrites44.1%

            \[\leadsto \color{blue}{y \cdot x} \]
          6. Add Preprocessing

          Reproduce

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