Optimisation.CirclePacking:place from circle-packing-0.1.0.4, G

Percentage Accurate: 100.0% → 100.0%
Time: 4.2s
Alternatives: 9
Speedup: 1.0×

Specification

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

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

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

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

Alternative 1: 100.0% accurate, 1.0× speedup?

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

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

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

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

Alternative 2: 49.1% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -8.2 \cdot 10^{-29}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq -1.95 \cdot 10^{-140}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -2.75 \cdot 10^{-178}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 2.3 \cdot 10^{-43}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 80000:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 3.3 \cdot 10^{+87}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq 8.6 \cdot 10^{+153}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= z -8.2e-29)
   (* x z)
   (if (<= z -1.95e-140)
     x
     (if (<= z -2.75e-178)
       y
       (if (<= z 2.3e-43)
         x
         (if (<= z 80000.0)
           y
           (if (<= z 3.3e+87)
             (* x z)
             (if (<= z 8.6e+153) (* y z) (* x z)))))))))
double code(double x, double y, double z) {
	double tmp;
	if (z <= -8.2e-29) {
		tmp = x * z;
	} else if (z <= -1.95e-140) {
		tmp = x;
	} else if (z <= -2.75e-178) {
		tmp = y;
	} else if (z <= 2.3e-43) {
		tmp = x;
	} else if (z <= 80000.0) {
		tmp = y;
	} else if (z <= 3.3e+87) {
		tmp = x * z;
	} else if (z <= 8.6e+153) {
		tmp = y * z;
	} else {
		tmp = x * 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 <= (-8.2d-29)) then
        tmp = x * z
    else if (z <= (-1.95d-140)) then
        tmp = x
    else if (z <= (-2.75d-178)) then
        tmp = y
    else if (z <= 2.3d-43) then
        tmp = x
    else if (z <= 80000.0d0) then
        tmp = y
    else if (z <= 3.3d+87) then
        tmp = x * z
    else if (z <= 8.6d+153) then
        tmp = y * z
    else
        tmp = x * z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (z <= -8.2e-29) {
		tmp = x * z;
	} else if (z <= -1.95e-140) {
		tmp = x;
	} else if (z <= -2.75e-178) {
		tmp = y;
	} else if (z <= 2.3e-43) {
		tmp = x;
	} else if (z <= 80000.0) {
		tmp = y;
	} else if (z <= 3.3e+87) {
		tmp = x * z;
	} else if (z <= 8.6e+153) {
		tmp = y * z;
	} else {
		tmp = x * z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if z <= -8.2e-29:
		tmp = x * z
	elif z <= -1.95e-140:
		tmp = x
	elif z <= -2.75e-178:
		tmp = y
	elif z <= 2.3e-43:
		tmp = x
	elif z <= 80000.0:
		tmp = y
	elif z <= 3.3e+87:
		tmp = x * z
	elif z <= 8.6e+153:
		tmp = y * z
	else:
		tmp = x * z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (z <= -8.2e-29)
		tmp = Float64(x * z);
	elseif (z <= -1.95e-140)
		tmp = x;
	elseif (z <= -2.75e-178)
		tmp = y;
	elseif (z <= 2.3e-43)
		tmp = x;
	elseif (z <= 80000.0)
		tmp = y;
	elseif (z <= 3.3e+87)
		tmp = Float64(x * z);
	elseif (z <= 8.6e+153)
		tmp = Float64(y * z);
	else
		tmp = Float64(x * z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (z <= -8.2e-29)
		tmp = x * z;
	elseif (z <= -1.95e-140)
		tmp = x;
	elseif (z <= -2.75e-178)
		tmp = y;
	elseif (z <= 2.3e-43)
		tmp = x;
	elseif (z <= 80000.0)
		tmp = y;
	elseif (z <= 3.3e+87)
		tmp = x * z;
	elseif (z <= 8.6e+153)
		tmp = y * z;
	else
		tmp = x * z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[z, -8.2e-29], N[(x * z), $MachinePrecision], If[LessEqual[z, -1.95e-140], x, If[LessEqual[z, -2.75e-178], y, If[LessEqual[z, 2.3e-43], x, If[LessEqual[z, 80000.0], y, If[LessEqual[z, 3.3e+87], N[(x * z), $MachinePrecision], If[LessEqual[z, 8.6e+153], N[(y * z), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.2 \cdot 10^{-29}:\\
\;\;\;\;x \cdot z\\

\mathbf{elif}\;z \leq -1.95 \cdot 10^{-140}:\\
\;\;\;\;x\\

\mathbf{elif}\;z \leq -2.75 \cdot 10^{-178}:\\
\;\;\;\;y\\

\mathbf{elif}\;z \leq 2.3 \cdot 10^{-43}:\\
\;\;\;\;x\\

\mathbf{elif}\;z \leq 80000:\\
\;\;\;\;y\\

\mathbf{elif}\;z \leq 3.3 \cdot 10^{+87}:\\
\;\;\;\;x \cdot z\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if z < -8.1999999999999996e-29 or 8e4 < z < 3.3000000000000001e87 or 8.5999999999999995e153 < z

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{x \cdot x - \color{blue}{\mathsf{fma}\left(x + y, z, y\right)} \cdot \left(y + \left(x + y\right) \cdot z\right)}{x - \left(y + \left(x + y\right) \cdot z\right)} \]
      5. +-commutative21.8%

        \[\leadsto \frac{x \cdot x - \mathsf{fma}\left(x + y, z, y\right) \cdot \color{blue}{\left(\left(x + y\right) \cdot z + y\right)}}{x - \left(y + \left(x + y\right) \cdot z\right)} \]
      6. fma-def21.8%

        \[\leadsto \frac{x \cdot x - \mathsf{fma}\left(x + y, z, y\right) \cdot \color{blue}{\mathsf{fma}\left(x + y, z, y\right)}}{x - \left(y + \left(x + y\right) \cdot z\right)} \]
      7. +-commutative21.8%

        \[\leadsto \frac{x \cdot x - \mathsf{fma}\left(x + y, z, y\right) \cdot \mathsf{fma}\left(x + y, z, y\right)}{x - \color{blue}{\left(\left(x + y\right) \cdot z + y\right)}} \]
      8. fma-def21.8%

        \[\leadsto \frac{x \cdot x - \mathsf{fma}\left(x + y, z, y\right) \cdot \mathsf{fma}\left(x + y, z, y\right)}{x - \color{blue}{\mathsf{fma}\left(x + y, z, y\right)}} \]
    5. Applied egg-rr21.8%

      \[\leadsto \color{blue}{\frac{x \cdot x - \mathsf{fma}\left(x + y, z, y\right) \cdot \mathsf{fma}\left(x + y, z, y\right)}{x - \mathsf{fma}\left(x + y, z, y\right)}} \]
    6. Step-by-step derivation
      1. difference-of-squares22.6%

        \[\leadsto \frac{\color{blue}{\left(x + \mathsf{fma}\left(x + y, z, y\right)\right) \cdot \left(x - \mathsf{fma}\left(x + y, z, y\right)\right)}}{x - \mathsf{fma}\left(x + y, z, y\right)} \]
      2. +-commutative22.6%

        \[\leadsto \frac{\color{blue}{\left(\mathsf{fma}\left(x + y, z, y\right) + x\right)} \cdot \left(x - \mathsf{fma}\left(x + y, z, y\right)\right)}{x - \mathsf{fma}\left(x + y, z, y\right)} \]
      3. fma-udef22.6%

        \[\leadsto \frac{\left(\color{blue}{\left(\left(x + y\right) \cdot z + y\right)} + x\right) \cdot \left(x - \mathsf{fma}\left(x + y, z, y\right)\right)}{x - \mathsf{fma}\left(x + y, z, y\right)} \]
      4. associate-+r+22.6%

        \[\leadsto \frac{\color{blue}{\left(\left(x + y\right) \cdot z + \left(y + x\right)\right)} \cdot \left(x - \mathsf{fma}\left(x + y, z, y\right)\right)}{x - \mathsf{fma}\left(x + y, z, y\right)} \]
      5. +-commutative22.6%

        \[\leadsto \frac{\left(\left(x + y\right) \cdot z + \color{blue}{\left(x + y\right)}\right) \cdot \left(x - \mathsf{fma}\left(x + y, z, y\right)\right)}{x - \mathsf{fma}\left(x + y, z, y\right)} \]
      6. *-rgt-identity22.6%

        \[\leadsto \frac{\left(\left(x + y\right) \cdot z + \color{blue}{\left(x + y\right) \cdot 1}\right) \cdot \left(x - \mathsf{fma}\left(x + y, z, y\right)\right)}{x - \mathsf{fma}\left(x + y, z, y\right)} \]
      7. distribute-lft-in22.6%

        \[\leadsto \frac{\color{blue}{\left(\left(x + y\right) \cdot \left(z + 1\right)\right)} \cdot \left(x - \mathsf{fma}\left(x + y, z, y\right)\right)}{x - \mathsf{fma}\left(x + y, z, y\right)} \]
      8. associate-/l*54.2%

        \[\leadsto \color{blue}{\frac{\left(x + y\right) \cdot \left(z + 1\right)}{\frac{x - \mathsf{fma}\left(x + y, z, y\right)}{x - \mathsf{fma}\left(x + y, z, y\right)}}} \]
      9. *-inverses100.0%

        \[\leadsto \frac{\left(x + y\right) \cdot \left(z + 1\right)}{\color{blue}{1}} \]
      10. associate-/l*99.7%

        \[\leadsto \color{blue}{\frac{x + y}{\frac{1}{z + 1}}} \]
      11. +-commutative99.7%

        \[\leadsto \frac{\color{blue}{y + x}}{\frac{1}{z + 1}} \]
    7. Simplified99.7%

      \[\leadsto \color{blue}{\frac{y + x}{\frac{1}{z + 1}}} \]
    8. Taylor expanded in z around inf 95.2%

      \[\leadsto \frac{y + x}{\color{blue}{\frac{1}{z}}} \]
    9. Taylor expanded in y around 0 50.0%

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

    if -8.1999999999999996e-29 < z < -1.9500000000000001e-140 or -2.75000000000000014e-178 < z < 2.2999999999999999e-43

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{\left(1 + z\right) \cdot x} \]
    3. Taylor expanded in z around 0 49.9%

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

    if -1.9500000000000001e-140 < z < -2.75000000000000014e-178 or 2.2999999999999999e-43 < z < 8e4

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{y \cdot \left(1 + z\right)} \]
    3. Taylor expanded in z around 0 40.2%

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

    if 3.3000000000000001e87 < z < 8.5999999999999995e153

    1. Initial program 99.9%

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

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

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

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

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

      \[\leadsto \color{blue}{y \cdot z + y} \]
    5. Taylor expanded in z around inf 52.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -8.2 \cdot 10^{-29}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq -1.95 \cdot 10^{-140}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -2.75 \cdot 10^{-178}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 2.3 \cdot 10^{-43}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 80000:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 3.3 \cdot 10^{+87}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq 8.6 \cdot 10^{+153}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \]

Alternative 3: 50.4% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -1:\\
\;\;\;\;y \cdot z\\

\mathbf{elif}\;z \leq -3.6 \cdot 10^{-140}:\\
\;\;\;\;x\\

\mathbf{elif}\;z \leq -2.3 \cdot 10^{-178}:\\
\;\;\;\;y\\

\mathbf{elif}\;z \leq 6.8 \cdot 10^{-43}:\\
\;\;\;\;x\\

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

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


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

    1. Initial program 100.0%

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

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

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

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

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

      \[\leadsto \color{blue}{y \cdot z + y} \]
    5. Taylor expanded in z around inf 51.3%

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

    if -1 < z < -3.6e-140 or -2.29999999999999994e-178 < z < 6.8000000000000001e-43

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{\left(1 + z\right) \cdot x} \]
    3. Taylor expanded in z around 0 49.9%

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

    if -3.6e-140 < z < -2.29999999999999994e-178 or 6.8000000000000001e-43 < z < 1

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{y \cdot \left(1 + z\right)} \]
    3. Taylor expanded in z around 0 43.6%

      \[\leadsto \color{blue}{y} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification50.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -3.6 \cdot 10^{-140}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -2.3 \cdot 10^{-178}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 6.8 \cdot 10^{-43}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]

Alternative 4: 75.2% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.1 \cdot 10^{+63}:\\
\;\;\;\;x \cdot z\\

\mathbf{elif}\;z \leq -1.7 \cdot 10^{-6}:\\
\;\;\;\;y \cdot \left(z + 1\right)\\

\mathbf{elif}\;z \leq 80000:\\
\;\;\;\;x + y\\

\mathbf{elif}\;z \leq 3.6 \cdot 10^{+90}:\\
\;\;\;\;x \cdot z\\

\mathbf{elif}\;z \leq 1.25 \cdot 10^{+149}:\\
\;\;\;\;y \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if z < -6.09999999999999968e63 or 8e4 < z < 3.6e90 or 1.24999999999999998e149 < z

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{x \cdot x - \mathsf{fma}\left(x + y, z, y\right) \cdot \color{blue}{\left(\left(x + y\right) \cdot z + y\right)}}{x - \left(y + \left(x + y\right) \cdot z\right)} \]
      6. fma-def18.0%

        \[\leadsto \frac{x \cdot x - \mathsf{fma}\left(x + y, z, y\right) \cdot \color{blue}{\mathsf{fma}\left(x + y, z, y\right)}}{x - \left(y + \left(x + y\right) \cdot z\right)} \]
      7. +-commutative18.0%

        \[\leadsto \frac{x \cdot x - \mathsf{fma}\left(x + y, z, y\right) \cdot \mathsf{fma}\left(x + y, z, y\right)}{x - \color{blue}{\left(\left(x + y\right) \cdot z + y\right)}} \]
      8. fma-def18.0%

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

      \[\leadsto \color{blue}{\frac{x \cdot x - \mathsf{fma}\left(x + y, z, y\right) \cdot \mathsf{fma}\left(x + y, z, y\right)}{x - \mathsf{fma}\left(x + y, z, y\right)}} \]
    6. Step-by-step derivation
      1. difference-of-squares18.4%

        \[\leadsto \frac{\color{blue}{\left(x + \mathsf{fma}\left(x + y, z, y\right)\right) \cdot \left(x - \mathsf{fma}\left(x + y, z, y\right)\right)}}{x - \mathsf{fma}\left(x + y, z, y\right)} \]
      2. +-commutative18.4%

        \[\leadsto \frac{\color{blue}{\left(\mathsf{fma}\left(x + y, z, y\right) + x\right)} \cdot \left(x - \mathsf{fma}\left(x + y, z, y\right)\right)}{x - \mathsf{fma}\left(x + y, z, y\right)} \]
      3. fma-udef18.4%

        \[\leadsto \frac{\left(\color{blue}{\left(\left(x + y\right) \cdot z + y\right)} + x\right) \cdot \left(x - \mathsf{fma}\left(x + y, z, y\right)\right)}{x - \mathsf{fma}\left(x + y, z, y\right)} \]
      4. associate-+r+18.4%

        \[\leadsto \frac{\color{blue}{\left(\left(x + y\right) \cdot z + \left(y + x\right)\right)} \cdot \left(x - \mathsf{fma}\left(x + y, z, y\right)\right)}{x - \mathsf{fma}\left(x + y, z, y\right)} \]
      5. +-commutative18.4%

        \[\leadsto \frac{\left(\left(x + y\right) \cdot z + \color{blue}{\left(x + y\right)}\right) \cdot \left(x - \mathsf{fma}\left(x + y, z, y\right)\right)}{x - \mathsf{fma}\left(x + y, z, y\right)} \]
      6. *-rgt-identity18.4%

        \[\leadsto \frac{\left(\left(x + y\right) \cdot z + \color{blue}{\left(x + y\right) \cdot 1}\right) \cdot \left(x - \mathsf{fma}\left(x + y, z, y\right)\right)}{x - \mathsf{fma}\left(x + y, z, y\right)} \]
      7. distribute-lft-in18.4%

        \[\leadsto \frac{\color{blue}{\left(\left(x + y\right) \cdot \left(z + 1\right)\right)} \cdot \left(x - \mathsf{fma}\left(x + y, z, y\right)\right)}{x - \mathsf{fma}\left(x + y, z, y\right)} \]
      8. associate-/l*45.3%

        \[\leadsto \color{blue}{\frac{\left(x + y\right) \cdot \left(z + 1\right)}{\frac{x - \mathsf{fma}\left(x + y, z, y\right)}{x - \mathsf{fma}\left(x + y, z, y\right)}}} \]
      9. *-inverses100.0%

        \[\leadsto \frac{\left(x + y\right) \cdot \left(z + 1\right)}{\color{blue}{1}} \]
      10. associate-/l*99.8%

        \[\leadsto \color{blue}{\frac{x + y}{\frac{1}{z + 1}}} \]
      11. +-commutative99.8%

        \[\leadsto \frac{\color{blue}{y + x}}{\frac{1}{z + 1}} \]
    7. Simplified99.8%

      \[\leadsto \color{blue}{\frac{y + x}{\frac{1}{z + 1}}} \]
    8. Taylor expanded in z around inf 99.5%

      \[\leadsto \frac{y + x}{\color{blue}{\frac{1}{z}}} \]
    9. Taylor expanded in y around 0 50.3%

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

    if -6.09999999999999968e63 < z < -1.70000000000000003e-6

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{y \cdot \left(1 + z\right)} \]

    if -1.70000000000000003e-6 < z < 8e4

    1. Initial program 100.0%

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

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

    if 3.6e90 < z < 1.24999999999999998e149

    1. Initial program 99.9%

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

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

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

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

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

      \[\leadsto \color{blue}{y \cdot z + y} \]
    5. Taylor expanded in z around inf 52.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -6.1 \cdot 10^{+63}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq -1.7 \cdot 10^{-6}:\\ \;\;\;\;y \cdot \left(z + 1\right)\\ \mathbf{elif}\;z \leq 80000:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq 3.6 \cdot 10^{+90}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq 1.25 \cdot 10^{+149}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \]

Alternative 5: 74.8% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -1:\\
\;\;\;\;x \cdot z\\

\mathbf{elif}\;z \leq 80000:\\
\;\;\;\;x + y\\

\mathbf{elif}\;z \leq 1.4 \cdot 10^{+94}:\\
\;\;\;\;x \cdot z\\

\mathbf{elif}\;z \leq 4.4 \cdot 10^{+149}:\\
\;\;\;\;y \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -1 or 8e4 < z < 1.39999999999999999e94 or 4.4e149 < z

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{x \cdot x - \color{blue}{\mathsf{fma}\left(x + y, z, y\right)} \cdot \left(y + \left(x + y\right) \cdot z\right)}{x - \left(y + \left(x + y\right) \cdot z\right)} \]
      5. +-commutative21.3%

        \[\leadsto \frac{x \cdot x - \mathsf{fma}\left(x + y, z, y\right) \cdot \color{blue}{\left(\left(x + y\right) \cdot z + y\right)}}{x - \left(y + \left(x + y\right) \cdot z\right)} \]
      6. fma-def21.3%

        \[\leadsto \frac{x \cdot x - \mathsf{fma}\left(x + y, z, y\right) \cdot \color{blue}{\mathsf{fma}\left(x + y, z, y\right)}}{x - \left(y + \left(x + y\right) \cdot z\right)} \]
      7. +-commutative21.3%

        \[\leadsto \frac{x \cdot x - \mathsf{fma}\left(x + y, z, y\right) \cdot \mathsf{fma}\left(x + y, z, y\right)}{x - \color{blue}{\left(\left(x + y\right) \cdot z + y\right)}} \]
      8. fma-def21.3%

        \[\leadsto \frac{x \cdot x - \mathsf{fma}\left(x + y, z, y\right) \cdot \mathsf{fma}\left(x + y, z, y\right)}{x - \color{blue}{\mathsf{fma}\left(x + y, z, y\right)}} \]
    5. Applied egg-rr21.3%

      \[\leadsto \color{blue}{\frac{x \cdot x - \mathsf{fma}\left(x + y, z, y\right) \cdot \mathsf{fma}\left(x + y, z, y\right)}{x - \mathsf{fma}\left(x + y, z, y\right)}} \]
    6. Step-by-step derivation
      1. difference-of-squares22.1%

        \[\leadsto \frac{\color{blue}{\left(x + \mathsf{fma}\left(x + y, z, y\right)\right) \cdot \left(x - \mathsf{fma}\left(x + y, z, y\right)\right)}}{x - \mathsf{fma}\left(x + y, z, y\right)} \]
      2. +-commutative22.1%

        \[\leadsto \frac{\color{blue}{\left(\mathsf{fma}\left(x + y, z, y\right) + x\right)} \cdot \left(x - \mathsf{fma}\left(x + y, z, y\right)\right)}{x - \mathsf{fma}\left(x + y, z, y\right)} \]
      3. fma-udef22.1%

        \[\leadsto \frac{\left(\color{blue}{\left(\left(x + y\right) \cdot z + y\right)} + x\right) \cdot \left(x - \mathsf{fma}\left(x + y, z, y\right)\right)}{x - \mathsf{fma}\left(x + y, z, y\right)} \]
      4. associate-+r+22.1%

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

        \[\leadsto \frac{\left(\left(x + y\right) \cdot z + \color{blue}{\left(x + y\right)}\right) \cdot \left(x - \mathsf{fma}\left(x + y, z, y\right)\right)}{x - \mathsf{fma}\left(x + y, z, y\right)} \]
      6. *-rgt-identity22.1%

        \[\leadsto \frac{\left(\left(x + y\right) \cdot z + \color{blue}{\left(x + y\right) \cdot 1}\right) \cdot \left(x - \mathsf{fma}\left(x + y, z, y\right)\right)}{x - \mathsf{fma}\left(x + y, z, y\right)} \]
      7. distribute-lft-in22.1%

        \[\leadsto \frac{\color{blue}{\left(\left(x + y\right) \cdot \left(z + 1\right)\right)} \cdot \left(x - \mathsf{fma}\left(x + y, z, y\right)\right)}{x - \mathsf{fma}\left(x + y, z, y\right)} \]
      8. associate-/l*53.4%

        \[\leadsto \color{blue}{\frac{\left(x + y\right) \cdot \left(z + 1\right)}{\frac{x - \mathsf{fma}\left(x + y, z, y\right)}{x - \mathsf{fma}\left(x + y, z, y\right)}}} \]
      9. *-inverses100.0%

        \[\leadsto \frac{\left(x + y\right) \cdot \left(z + 1\right)}{\color{blue}{1}} \]
      10. associate-/l*99.7%

        \[\leadsto \color{blue}{\frac{x + y}{\frac{1}{z + 1}}} \]
      11. +-commutative99.7%

        \[\leadsto \frac{\color{blue}{y + x}}{\frac{1}{z + 1}} \]
    7. Simplified99.7%

      \[\leadsto \color{blue}{\frac{y + x}{\frac{1}{z + 1}}} \]
    8. Taylor expanded in z around inf 96.8%

      \[\leadsto \frac{y + x}{\color{blue}{\frac{1}{z}}} \]
    9. Taylor expanded in y around 0 50.8%

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

    if -1 < z < 8e4

    1. Initial program 100.0%

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

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

    if 1.39999999999999999e94 < z < 4.4e149

    1. Initial program 99.9%

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

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

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

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

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

      \[\leadsto \color{blue}{y \cdot z + y} \]
    5. Taylor expanded in z around inf 52.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq 80000:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq 1.4 \cdot 10^{+94}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq 4.4 \cdot 10^{+149}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \]

Alternative 6: 98.0% accurate, 0.8× speedup?

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

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

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


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

    1. Initial program 100.0%

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

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

    if -1 < z < 1

    1. Initial program 100.0%

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

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

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

Alternative 7: 63.8% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.1 \cdot 10^{-54}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\

\mathbf{else}:\\
\;\;\;\;y \cdot \left(z + 1\right)\\


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

    1. Initial program 100.0%

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

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

    if -3.10000000000000004e-54 < x

    1. Initial program 100.0%

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

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

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

Alternative 8: 32.1% accurate, 2.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.3 \cdot 10^{-126}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \end{array} \]
(FPCore (x y z) :precision binary64 (if (<= x -1.3e-126) x y))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -1.3e-126) {
		tmp = x;
	} else {
		tmp = 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.3d-126)) then
        tmp = x
    else
        tmp = y
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (x <= -1.3e-126) {
		tmp = x;
	} else {
		tmp = y;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if x <= -1.3e-126:
		tmp = x
	else:
		tmp = y
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (x <= -1.3e-126)
		tmp = x;
	else
		tmp = y;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (x <= -1.3e-126)
		tmp = x;
	else
		tmp = y;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[x, -1.3e-126], x, y]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.3 \cdot 10^{-126}:\\
\;\;\;\;x\\

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


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

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{\left(1 + z\right) \cdot x} \]
    3. Taylor expanded in z around 0 35.5%

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

    if -1.3e-126 < x

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{y \cdot \left(1 + z\right)} \]
    3. Taylor expanded in z around 0 34.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.3 \cdot 10^{-126}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]

Alternative 9: 26.2% accurate, 7.0× speedup?

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

\\
x
\end{array}
Derivation
  1. Initial program 100.0%

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

    \[\leadsto \color{blue}{\left(1 + z\right) \cdot x} \]
  3. Taylor expanded in z around 0 25.1%

    \[\leadsto \color{blue}{x} \]
  4. Final simplification25.1%

    \[\leadsto x \]

Reproduce

?
herbie shell --seed 2023200 
(FPCore (x y z)
  :name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, G"
  :precision binary64
  (* (+ x y) (+ z 1.0)))