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

Percentage Accurate: 100.0% → 98.8%
Time: 6.3s
Alternatives: 10
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 10 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: 98.8% accurate, 0.1× speedup?

\[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \mathsf{fma}\left(z + 1, y, \left(z + 1\right) \cdot x\right) \end{array} \]
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z) :precision binary64 (fma (+ z 1.0) y (* (+ z 1.0) x)))
assert(x < y && y < z);
double code(double x, double y, double z) {
	return fma((z + 1.0), y, ((z + 1.0) * x));
}
x, y, z = sort([x, y, z])
function code(x, y, z)
	return fma(Float64(z + 1.0), y, Float64(Float64(z + 1.0) * x))
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := N[(N[(z + 1.0), $MachinePrecision] * y + N[(N[(z + 1.0), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\mathsf{fma}\left(z + 1, y, \left(z + 1\right) \cdot x\right)
\end{array}
Derivation
  1. Initial program 100.0%

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

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

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

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

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

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

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

Alternative 2: 50.2% accurate, 0.2× speedup?

\[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \begin{array}{l} \mathbf{if}\;z \leq -9 \cdot 10^{+183}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -1:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;z \leq 6 \cdot 10^{-158}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 4 \cdot 10^{+14}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 4 \cdot 10^{+110} \lor \neg \left(z \leq 4.4 \cdot 10^{+244}\right) \land z \leq 1.36 \cdot 10^{+293}:\\ \;\;\;\;z \cdot x\\ \mathbf{else}:\\ \;\;\;\;z \cdot y\\ \end{array} \end{array} \]
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
 :precision binary64
 (if (<= z -9e+183)
   (* z x)
   (if (<= z -1.0)
     (* z y)
     (if (<= z 6e-158)
       x
       (if (<= z 4e+14)
         y
         (if (or (<= z 4e+110) (and (not (<= z 4.4e+244)) (<= z 1.36e+293)))
           (* z x)
           (* z y)))))))
assert(x < y && y < z);
double code(double x, double y, double z) {
	double tmp;
	if (z <= -9e+183) {
		tmp = z * x;
	} else if (z <= -1.0) {
		tmp = z * y;
	} else if (z <= 6e-158) {
		tmp = x;
	} else if (z <= 4e+14) {
		tmp = y;
	} else if ((z <= 4e+110) || (!(z <= 4.4e+244) && (z <= 1.36e+293))) {
		tmp = z * x;
	} else {
		tmp = z * y;
	}
	return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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 <= (-9d+183)) then
        tmp = z * x
    else if (z <= (-1.0d0)) then
        tmp = z * y
    else if (z <= 6d-158) then
        tmp = x
    else if (z <= 4d+14) then
        tmp = y
    else if ((z <= 4d+110) .or. (.not. (z <= 4.4d+244)) .and. (z <= 1.36d+293)) then
        tmp = z * x
    else
        tmp = z * y
    end if
    code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
	double tmp;
	if (z <= -9e+183) {
		tmp = z * x;
	} else if (z <= -1.0) {
		tmp = z * y;
	} else if (z <= 6e-158) {
		tmp = x;
	} else if (z <= 4e+14) {
		tmp = y;
	} else if ((z <= 4e+110) || (!(z <= 4.4e+244) && (z <= 1.36e+293))) {
		tmp = z * x;
	} else {
		tmp = z * y;
	}
	return tmp;
}
[x, y, z] = sort([x, y, z])
def code(x, y, z):
	tmp = 0
	if z <= -9e+183:
		tmp = z * x
	elif z <= -1.0:
		tmp = z * y
	elif z <= 6e-158:
		tmp = x
	elif z <= 4e+14:
		tmp = y
	elif (z <= 4e+110) or (not (z <= 4.4e+244) and (z <= 1.36e+293)):
		tmp = z * x
	else:
		tmp = z * y
	return tmp
x, y, z = sort([x, y, z])
function code(x, y, z)
	tmp = 0.0
	if (z <= -9e+183)
		tmp = Float64(z * x);
	elseif (z <= -1.0)
		tmp = Float64(z * y);
	elseif (z <= 6e-158)
		tmp = x;
	elseif (z <= 4e+14)
		tmp = y;
	elseif ((z <= 4e+110) || (!(z <= 4.4e+244) && (z <= 1.36e+293)))
		tmp = Float64(z * x);
	else
		tmp = Float64(z * y);
	end
	return tmp
end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (z <= -9e+183)
		tmp = z * x;
	elseif (z <= -1.0)
		tmp = z * y;
	elseif (z <= 6e-158)
		tmp = x;
	elseif (z <= 4e+14)
		tmp = y;
	elseif ((z <= 4e+110) || (~((z <= 4.4e+244)) && (z <= 1.36e+293)))
		tmp = z * x;
	else
		tmp = z * y;
	end
	tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := If[LessEqual[z, -9e+183], N[(z * x), $MachinePrecision], If[LessEqual[z, -1.0], N[(z * y), $MachinePrecision], If[LessEqual[z, 6e-158], x, If[LessEqual[z, 4e+14], y, If[Or[LessEqual[z, 4e+110], And[N[Not[LessEqual[z, 4.4e+244]], $MachinePrecision], LessEqual[z, 1.36e+293]]], N[(z * x), $MachinePrecision], N[(z * y), $MachinePrecision]]]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9 \cdot 10^{+183}:\\
\;\;\;\;z \cdot x\\

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

\mathbf{elif}\;z \leq 6 \cdot 10^{-158}:\\
\;\;\;\;x\\

\mathbf{elif}\;z \leq 4 \cdot 10^{+14}:\\
\;\;\;\;y\\

\mathbf{elif}\;z \leq 4 \cdot 10^{+110} \lor \neg \left(z \leq 4.4 \cdot 10^{+244}\right) \land z \leq 1.36 \cdot 10^{+293}:\\
\;\;\;\;z \cdot x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if z < -9.00000000000000034e183 or 4e14 < z < 4.0000000000000001e110 or 4.40000000000000003e244 < z < 1.3600000000000001e293

    1. Initial program 100.0%

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(z + 1, y, \left(z + 1\right) \cdot x\right)} \]
    5. Taylor expanded in x around inf 85.2%

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

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

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

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

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

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

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

        \[\leadsto x \cdot \left(\left(z + 1\right) \cdot \frac{y}{x} + \color{blue}{\left(z + 1\right) \cdot 1}\right) \]
      8. distribute-lft-out86.6%

        \[\leadsto x \cdot \color{blue}{\left(\left(z + 1\right) \cdot \left(\frac{y}{x} + 1\right)\right)} \]
    7. Simplified86.6%

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

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

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

        \[\leadsto \color{blue}{z \cdot x} \]
    11. Simplified58.8%

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

    if -9.00000000000000034e183 < z < -1 or 4.0000000000000001e110 < z < 4.40000000000000003e244 or 1.3600000000000001e293 < z

    1. Initial program 100.0%

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

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

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

        \[\leadsto \color{blue}{z \cdot y} \]
    6. Simplified65.4%

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

    if -1 < z < 6e-158

    1. Initial program 100.0%

      \[\left(x + y\right) \cdot \left(z + 1\right) \]
    2. Add Preprocessing
    3. 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 \]
    4. Applied egg-rr100.0%

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

      \[\leadsto \color{blue}{x + x \cdot z} \]
    6. Taylor expanded in z around 0 46.0%

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

    if 6e-158 < z < 4e14

    1. Initial program 100.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -9 \cdot 10^{+183}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -1:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;z \leq 6 \cdot 10^{-158}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 4 \cdot 10^{+14}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 4 \cdot 10^{+110} \lor \neg \left(z \leq 4.4 \cdot 10^{+244}\right) \land z \leq 1.36 \cdot 10^{+293}:\\ \;\;\;\;z \cdot x\\ \mathbf{else}:\\ \;\;\;\;z \cdot y\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 74.8% accurate, 0.2× speedup?

\[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \begin{array}{l} \mathbf{if}\;z \leq -9.5 \cdot 10^{+182}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -1:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;z \leq 4 \cdot 10^{+14}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;z \leq 1.18 \cdot 10^{+111} \lor \neg \left(z \leq 1.05 \cdot 10^{+249}\right) \land z \leq 1.7 \cdot 10^{+292}:\\ \;\;\;\;z \cdot x\\ \mathbf{else}:\\ \;\;\;\;z \cdot y\\ \end{array} \end{array} \]
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
 :precision binary64
 (if (<= z -9.5e+182)
   (* z x)
   (if (<= z -1.0)
     (* z y)
     (if (<= z 4e+14)
       (+ y x)
       (if (or (<= z 1.18e+111) (and (not (<= z 1.05e+249)) (<= z 1.7e+292)))
         (* z x)
         (* z y))))))
assert(x < y && y < z);
double code(double x, double y, double z) {
	double tmp;
	if (z <= -9.5e+182) {
		tmp = z * x;
	} else if (z <= -1.0) {
		tmp = z * y;
	} else if (z <= 4e+14) {
		tmp = y + x;
	} else if ((z <= 1.18e+111) || (!(z <= 1.05e+249) && (z <= 1.7e+292))) {
		tmp = z * x;
	} else {
		tmp = z * y;
	}
	return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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 <= (-9.5d+182)) then
        tmp = z * x
    else if (z <= (-1.0d0)) then
        tmp = z * y
    else if (z <= 4d+14) then
        tmp = y + x
    else if ((z <= 1.18d+111) .or. (.not. (z <= 1.05d+249)) .and. (z <= 1.7d+292)) then
        tmp = z * x
    else
        tmp = z * y
    end if
    code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
	double tmp;
	if (z <= -9.5e+182) {
		tmp = z * x;
	} else if (z <= -1.0) {
		tmp = z * y;
	} else if (z <= 4e+14) {
		tmp = y + x;
	} else if ((z <= 1.18e+111) || (!(z <= 1.05e+249) && (z <= 1.7e+292))) {
		tmp = z * x;
	} else {
		tmp = z * y;
	}
	return tmp;
}
[x, y, z] = sort([x, y, z])
def code(x, y, z):
	tmp = 0
	if z <= -9.5e+182:
		tmp = z * x
	elif z <= -1.0:
		tmp = z * y
	elif z <= 4e+14:
		tmp = y + x
	elif (z <= 1.18e+111) or (not (z <= 1.05e+249) and (z <= 1.7e+292)):
		tmp = z * x
	else:
		tmp = z * y
	return tmp
x, y, z = sort([x, y, z])
function code(x, y, z)
	tmp = 0.0
	if (z <= -9.5e+182)
		tmp = Float64(z * x);
	elseif (z <= -1.0)
		tmp = Float64(z * y);
	elseif (z <= 4e+14)
		tmp = Float64(y + x);
	elseif ((z <= 1.18e+111) || (!(z <= 1.05e+249) && (z <= 1.7e+292)))
		tmp = Float64(z * x);
	else
		tmp = Float64(z * y);
	end
	return tmp
end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (z <= -9.5e+182)
		tmp = z * x;
	elseif (z <= -1.0)
		tmp = z * y;
	elseif (z <= 4e+14)
		tmp = y + x;
	elseif ((z <= 1.18e+111) || (~((z <= 1.05e+249)) && (z <= 1.7e+292)))
		tmp = z * x;
	else
		tmp = z * y;
	end
	tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := If[LessEqual[z, -9.5e+182], N[(z * x), $MachinePrecision], If[LessEqual[z, -1.0], N[(z * y), $MachinePrecision], If[LessEqual[z, 4e+14], N[(y + x), $MachinePrecision], If[Or[LessEqual[z, 1.18e+111], And[N[Not[LessEqual[z, 1.05e+249]], $MachinePrecision], LessEqual[z, 1.7e+292]]], N[(z * x), $MachinePrecision], N[(z * y), $MachinePrecision]]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.5 \cdot 10^{+182}:\\
\;\;\;\;z \cdot x\\

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

\mathbf{elif}\;z \leq 4 \cdot 10^{+14}:\\
\;\;\;\;y + x\\

\mathbf{elif}\;z \leq 1.18 \cdot 10^{+111} \lor \neg \left(z \leq 1.05 \cdot 10^{+249}\right) \land z \leq 1.7 \cdot 10^{+292}:\\
\;\;\;\;z \cdot x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -9.50000000000000002e182 or 4e14 < z < 1.1799999999999999e111 or 1.0499999999999999e249 < z < 1.7000000000000001e292

    1. Initial program 100.0%

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(z + 1, y, \left(z + 1\right) \cdot x\right)} \]
    5. Taylor expanded in x around inf 85.2%

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

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

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

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

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

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

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

        \[\leadsto x \cdot \left(\left(z + 1\right) \cdot \frac{y}{x} + \color{blue}{\left(z + 1\right) \cdot 1}\right) \]
      8. distribute-lft-out86.6%

        \[\leadsto x \cdot \color{blue}{\left(\left(z + 1\right) \cdot \left(\frac{y}{x} + 1\right)\right)} \]
    7. Simplified86.6%

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

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

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

        \[\leadsto \color{blue}{z \cdot x} \]
    11. Simplified58.8%

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

    if -9.50000000000000002e182 < z < -1 or 1.1799999999999999e111 < z < 1.0499999999999999e249 or 1.7000000000000001e292 < z

    1. Initial program 100.0%

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

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

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

        \[\leadsto \color{blue}{z \cdot y} \]
    6. Simplified65.4%

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

    if -1 < z < 4e14

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{x + y} \]
    4. Step-by-step derivation
      1. +-commutative95.2%

        \[\leadsto \color{blue}{y + x} \]
    5. Simplified95.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -9.5 \cdot 10^{+182}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -1:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;z \leq 4 \cdot 10^{+14}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;z \leq 1.18 \cdot 10^{+111} \lor \neg \left(z \leq 1.05 \cdot 10^{+249}\right) \land z \leq 1.7 \cdot 10^{+292}:\\ \;\;\;\;z \cdot x\\ \mathbf{else}:\\ \;\;\;\;z \cdot y\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 75.3% accurate, 0.2× speedup?

\[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \begin{array}{l} \mathbf{if}\;z \leq -2.4 \cdot 10^{+180}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -1:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;z \leq 2.05 \cdot 10^{-7}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;z \leq 1.5 \cdot 10^{+111}:\\ \;\;\;\;\left(z + 1\right) \cdot x\\ \mathbf{elif}\;z \leq 3.2 \cdot 10^{+249} \lor \neg \left(z \leq 6.8 \cdot 10^{+292}\right):\\ \;\;\;\;z \cdot y\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \end{array} \]
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
 :precision binary64
 (if (<= z -2.4e+180)
   (* z x)
   (if (<= z -1.0)
     (* z y)
     (if (<= z 2.05e-7)
       (+ y x)
       (if (<= z 1.5e+111)
         (* (+ z 1.0) x)
         (if (or (<= z 3.2e+249) (not (<= z 6.8e+292))) (* z y) (* z x)))))))
assert(x < y && y < z);
double code(double x, double y, double z) {
	double tmp;
	if (z <= -2.4e+180) {
		tmp = z * x;
	} else if (z <= -1.0) {
		tmp = z * y;
	} else if (z <= 2.05e-7) {
		tmp = y + x;
	} else if (z <= 1.5e+111) {
		tmp = (z + 1.0) * x;
	} else if ((z <= 3.2e+249) || !(z <= 6.8e+292)) {
		tmp = z * y;
	} else {
		tmp = z * x;
	}
	return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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 <= (-2.4d+180)) then
        tmp = z * x
    else if (z <= (-1.0d0)) then
        tmp = z * y
    else if (z <= 2.05d-7) then
        tmp = y + x
    else if (z <= 1.5d+111) then
        tmp = (z + 1.0d0) * x
    else if ((z <= 3.2d+249) .or. (.not. (z <= 6.8d+292))) then
        tmp = z * y
    else
        tmp = z * x
    end if
    code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
	double tmp;
	if (z <= -2.4e+180) {
		tmp = z * x;
	} else if (z <= -1.0) {
		tmp = z * y;
	} else if (z <= 2.05e-7) {
		tmp = y + x;
	} else if (z <= 1.5e+111) {
		tmp = (z + 1.0) * x;
	} else if ((z <= 3.2e+249) || !(z <= 6.8e+292)) {
		tmp = z * y;
	} else {
		tmp = z * x;
	}
	return tmp;
}
[x, y, z] = sort([x, y, z])
def code(x, y, z):
	tmp = 0
	if z <= -2.4e+180:
		tmp = z * x
	elif z <= -1.0:
		tmp = z * y
	elif z <= 2.05e-7:
		tmp = y + x
	elif z <= 1.5e+111:
		tmp = (z + 1.0) * x
	elif (z <= 3.2e+249) or not (z <= 6.8e+292):
		tmp = z * y
	else:
		tmp = z * x
	return tmp
x, y, z = sort([x, y, z])
function code(x, y, z)
	tmp = 0.0
	if (z <= -2.4e+180)
		tmp = Float64(z * x);
	elseif (z <= -1.0)
		tmp = Float64(z * y);
	elseif (z <= 2.05e-7)
		tmp = Float64(y + x);
	elseif (z <= 1.5e+111)
		tmp = Float64(Float64(z + 1.0) * x);
	elseif ((z <= 3.2e+249) || !(z <= 6.8e+292))
		tmp = Float64(z * y);
	else
		tmp = Float64(z * x);
	end
	return tmp
end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (z <= -2.4e+180)
		tmp = z * x;
	elseif (z <= -1.0)
		tmp = z * y;
	elseif (z <= 2.05e-7)
		tmp = y + x;
	elseif (z <= 1.5e+111)
		tmp = (z + 1.0) * x;
	elseif ((z <= 3.2e+249) || ~((z <= 6.8e+292)))
		tmp = z * y;
	else
		tmp = z * x;
	end
	tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := If[LessEqual[z, -2.4e+180], N[(z * x), $MachinePrecision], If[LessEqual[z, -1.0], N[(z * y), $MachinePrecision], If[LessEqual[z, 2.05e-7], N[(y + x), $MachinePrecision], If[LessEqual[z, 1.5e+111], N[(N[(z + 1.0), $MachinePrecision] * x), $MachinePrecision], If[Or[LessEqual[z, 3.2e+249], N[Not[LessEqual[z, 6.8e+292]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(z * x), $MachinePrecision]]]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.4 \cdot 10^{+180}:\\
\;\;\;\;z \cdot x\\

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

\mathbf{elif}\;z \leq 2.05 \cdot 10^{-7}:\\
\;\;\;\;y + x\\

\mathbf{elif}\;z \leq 1.5 \cdot 10^{+111}:\\
\;\;\;\;\left(z + 1\right) \cdot x\\

\mathbf{elif}\;z \leq 3.2 \cdot 10^{+249} \lor \neg \left(z \leq 6.8 \cdot 10^{+292}\right):\\
\;\;\;\;z \cdot y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if z < -2.3999999999999998e180 or 3.20000000000000014e249 < z < 6.8000000000000003e292

    1. Initial program 100.0%

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(z + 1, y, \left(z + 1\right) \cdot x\right)} \]
    5. Taylor expanded in x around inf 86.6%

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

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

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

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

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

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

        \[\leadsto x \cdot \left(\color{blue}{\left(z + 1\right) \cdot \frac{y}{x}} + \left(z + 1\right)\right) \]
      7. *-rgt-identity88.8%

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

        \[\leadsto x \cdot \color{blue}{\left(\left(z + 1\right) \cdot \left(\frac{y}{x} + 1\right)\right)} \]
    7. Simplified88.8%

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

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

      \[\leadsto \color{blue}{x \cdot z} \]
    10. Step-by-step derivation
      1. *-commutative54.5%

        \[\leadsto \color{blue}{z \cdot x} \]
    11. Simplified54.5%

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

    if -2.3999999999999998e180 < z < -1 or 1.5e111 < z < 3.20000000000000014e249 or 6.8000000000000003e292 < z

    1. Initial program 100.0%

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

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

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

        \[\leadsto \color{blue}{z \cdot y} \]
    6. Simplified65.4%

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

    if -1 < z < 2.05e-7

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{y + x} \]
    5. Simplified99.7%

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

    if 2.05e-7 < z < 1.5e111

    1. Initial program 99.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -2.4 \cdot 10^{+180}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -1:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;z \leq 2.05 \cdot 10^{-7}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;z \leq 1.5 \cdot 10^{+111}:\\ \;\;\;\;\left(z + 1\right) \cdot x\\ \mathbf{elif}\;z \leq 3.2 \cdot 10^{+249} \lor \neg \left(z \leq 6.8 \cdot 10^{+292}\right):\\ \;\;\;\;z \cdot y\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 49.4% accurate, 0.2× speedup?

\[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \begin{array}{l} \mathbf{if}\;z \leq -5.4 \cdot 10^{-12}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -1.56 \cdot 10^{-208}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.15 \cdot 10^{-286}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 3.8 \cdot 10^{-157}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 4 \cdot 10^{+14}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \end{array} \]
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
 :precision binary64
 (if (<= z -5.4e-12)
   (* z x)
   (if (<= z -1.56e-208)
     x
     (if (<= z 1.15e-286)
       y
       (if (<= z 3.8e-157) x (if (<= z 4e+14) y (* z x)))))))
assert(x < y && y < z);
double code(double x, double y, double z) {
	double tmp;
	if (z <= -5.4e-12) {
		tmp = z * x;
	} else if (z <= -1.56e-208) {
		tmp = x;
	} else if (z <= 1.15e-286) {
		tmp = y;
	} else if (z <= 3.8e-157) {
		tmp = x;
	} else if (z <= 4e+14) {
		tmp = y;
	} else {
		tmp = z * x;
	}
	return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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 <= (-5.4d-12)) then
        tmp = z * x
    else if (z <= (-1.56d-208)) then
        tmp = x
    else if (z <= 1.15d-286) then
        tmp = y
    else if (z <= 3.8d-157) then
        tmp = x
    else if (z <= 4d+14) then
        tmp = y
    else
        tmp = z * x
    end if
    code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
	double tmp;
	if (z <= -5.4e-12) {
		tmp = z * x;
	} else if (z <= -1.56e-208) {
		tmp = x;
	} else if (z <= 1.15e-286) {
		tmp = y;
	} else if (z <= 3.8e-157) {
		tmp = x;
	} else if (z <= 4e+14) {
		tmp = y;
	} else {
		tmp = z * x;
	}
	return tmp;
}
[x, y, z] = sort([x, y, z])
def code(x, y, z):
	tmp = 0
	if z <= -5.4e-12:
		tmp = z * x
	elif z <= -1.56e-208:
		tmp = x
	elif z <= 1.15e-286:
		tmp = y
	elif z <= 3.8e-157:
		tmp = x
	elif z <= 4e+14:
		tmp = y
	else:
		tmp = z * x
	return tmp
x, y, z = sort([x, y, z])
function code(x, y, z)
	tmp = 0.0
	if (z <= -5.4e-12)
		tmp = Float64(z * x);
	elseif (z <= -1.56e-208)
		tmp = x;
	elseif (z <= 1.15e-286)
		tmp = y;
	elseif (z <= 3.8e-157)
		tmp = x;
	elseif (z <= 4e+14)
		tmp = y;
	else
		tmp = Float64(z * x);
	end
	return tmp
end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (z <= -5.4e-12)
		tmp = z * x;
	elseif (z <= -1.56e-208)
		tmp = x;
	elseif (z <= 1.15e-286)
		tmp = y;
	elseif (z <= 3.8e-157)
		tmp = x;
	elseif (z <= 4e+14)
		tmp = y;
	else
		tmp = z * x;
	end
	tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := If[LessEqual[z, -5.4e-12], N[(z * x), $MachinePrecision], If[LessEqual[z, -1.56e-208], x, If[LessEqual[z, 1.15e-286], y, If[LessEqual[z, 3.8e-157], x, If[LessEqual[z, 4e+14], y, N[(z * x), $MachinePrecision]]]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.4 \cdot 10^{-12}:\\
\;\;\;\;z \cdot x\\

\mathbf{elif}\;z \leq -1.56 \cdot 10^{-208}:\\
\;\;\;\;x\\

\mathbf{elif}\;z \leq 1.15 \cdot 10^{-286}:\\
\;\;\;\;y\\

\mathbf{elif}\;z \leq 3.8 \cdot 10^{-157}:\\
\;\;\;\;x\\

\mathbf{elif}\;z \leq 4 \cdot 10^{+14}:\\
\;\;\;\;y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -5.39999999999999961e-12 or 4e14 < z

    1. Initial program 100.0%

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(z + 1, y, \left(z + 1\right) \cdot x\right)} \]
    5. Taylor expanded in x around inf 82.6%

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

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

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

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

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

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

        \[\leadsto x \cdot \left(\color{blue}{\left(z + 1\right) \cdot \frac{y}{x}} + \left(z + 1\right)\right) \]
      7. *-rgt-identity83.2%

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

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

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

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

      \[\leadsto \color{blue}{x \cdot z} \]
    10. Step-by-step derivation
      1. *-commutative46.5%

        \[\leadsto \color{blue}{z \cdot x} \]
    11. Simplified46.5%

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

    if -5.39999999999999961e-12 < z < -1.56e-208 or 1.1500000000000001e-286 < z < 3.8000000000000002e-157

    1. Initial program 100.0%

      \[\left(x + y\right) \cdot \left(z + 1\right) \]
    2. Add Preprocessing
    3. 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 \]
    4. Applied egg-rr100.0%

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

      \[\leadsto \color{blue}{x + x \cdot z} \]
    6. Taylor expanded in z around 0 42.0%

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

    if -1.56e-208 < z < 1.1500000000000001e-286 or 3.8000000000000002e-157 < z < 4e14

    1. Initial program 100.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -5.4 \cdot 10^{-12}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -1.56 \cdot 10^{-208}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.15 \cdot 10^{-286}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 3.8 \cdot 10^{-157}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 4 \cdot 10^{+14}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 97.9% accurate, 0.5× speedup?

\[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \begin{array}{l} \mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 1\right):\\ \;\;\;\;z \cdot \left(y + x\right)\\ \mathbf{else}:\\ \;\;\;\;y + x\\ \end{array} \end{array} \]
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
 :precision binary64
 (if (or (<= z -1.0) (not (<= z 1.0))) (* z (+ y x)) (+ y x)))
assert(x < y && y < z);
double code(double x, double y, double z) {
	double tmp;
	if ((z <= -1.0) || !(z <= 1.0)) {
		tmp = z * (y + x);
	} else {
		tmp = y + x;
	}
	return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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 * (y + x)
    else
        tmp = y + x
    end if
    code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
	double tmp;
	if ((z <= -1.0) || !(z <= 1.0)) {
		tmp = z * (y + x);
	} else {
		tmp = y + x;
	}
	return tmp;
}
[x, y, z] = sort([x, y, z])
def code(x, y, z):
	tmp = 0
	if (z <= -1.0) or not (z <= 1.0):
		tmp = z * (y + x)
	else:
		tmp = y + x
	return tmp
x, y, z = sort([x, y, z])
function code(x, y, z)
	tmp = 0.0
	if ((z <= -1.0) || !(z <= 1.0))
		tmp = Float64(z * Float64(y + x));
	else
		tmp = Float64(y + x);
	end
	return tmp
end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((z <= -1.0) || ~((z <= 1.0)))
		tmp = z * (y + x);
	else
		tmp = y + x;
	end
	tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 1.0]], $MachinePrecision]], N[(z * N[(y + x), $MachinePrecision]), $MachinePrecision], N[(y + x), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;z \cdot \left(y + x\right)\\

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


\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. Add Preprocessing
    3. Taylor expanded in z around inf 97.8%

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

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

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

    if -1 < z < 1

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{x + y} \]
    4. Step-by-step derivation
      1. +-commutative98.8%

        \[\leadsto \color{blue}{y + x} \]
    5. Simplified98.8%

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

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

Alternative 7: 82.9% accurate, 0.7× speedup?

\[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \begin{array}{l} \mathbf{if}\;y \leq 1.56 \cdot 10^{-146}:\\ \;\;\;\;\left(z + 1\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\left(z + 1\right) \cdot y\\ \end{array} \end{array} \]
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
 :precision binary64
 (if (<= y 1.56e-146) (* (+ z 1.0) x) (* (+ z 1.0) y)))
assert(x < y && y < z);
double code(double x, double y, double z) {
	double tmp;
	if (y <= 1.56e-146) {
		tmp = (z + 1.0) * x;
	} else {
		tmp = (z + 1.0) * y;
	}
	return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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.56d-146) then
        tmp = (z + 1.0d0) * x
    else
        tmp = (z + 1.0d0) * y
    end if
    code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= 1.56e-146) {
		tmp = (z + 1.0) * x;
	} else {
		tmp = (z + 1.0) * y;
	}
	return tmp;
}
[x, y, z] = sort([x, y, z])
def code(x, y, z):
	tmp = 0
	if y <= 1.56e-146:
		tmp = (z + 1.0) * x
	else:
		tmp = (z + 1.0) * y
	return tmp
x, y, z = sort([x, y, z])
function code(x, y, z)
	tmp = 0.0
	if (y <= 1.56e-146)
		tmp = Float64(Float64(z + 1.0) * x);
	else
		tmp = Float64(Float64(z + 1.0) * y);
	end
	return tmp
end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= 1.56e-146)
		tmp = (z + 1.0) * x;
	else
		tmp = (z + 1.0) * y;
	end
	tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := If[LessEqual[y, 1.56e-146], N[(N[(z + 1.0), $MachinePrecision] * x), $MachinePrecision], N[(N[(z + 1.0), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.56 \cdot 10^{-146}:\\
\;\;\;\;\left(z + 1\right) \cdot x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 1.5599999999999999e-146

    1. Initial program 100.0%

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

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

    if 1.5599999999999999e-146 < y

    1. Initial program 100.0%

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

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

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

Alternative 8: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \left(z + 1\right) \cdot \left(y + x\right) \end{array} \]
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z) :precision binary64 (* (+ z 1.0) (+ y x)))
assert(x < y && y < z);
double code(double x, double y, double z) {
	return (z + 1.0) * (y + x);
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (z + 1.0d0) * (y + x)
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
	return (z + 1.0) * (y + x);
}
[x, y, z] = sort([x, y, z])
def code(x, y, z):
	return (z + 1.0) * (y + x)
x, y, z = sort([x, y, z])
function code(x, y, z)
	return Float64(Float64(z + 1.0) * Float64(y + x))
end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
	tmp = (z + 1.0) * (y + x);
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := N[(N[(z + 1.0), $MachinePrecision] * N[(y + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\left(z + 1\right) \cdot \left(y + x\right)
\end{array}
Derivation
  1. Initial program 100.0%

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

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

Alternative 9: 42.1% accurate, 1.2× speedup?

\[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \begin{array}{l} \mathbf{if}\;y \leq 8.8 \cdot 10^{-132}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \end{array} \]
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z) :precision binary64 (if (<= y 8.8e-132) x y))
assert(x < y && y < z);
double code(double x, double y, double z) {
	double tmp;
	if (y <= 8.8e-132) {
		tmp = x;
	} else {
		tmp = y;
	}
	return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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 <= 8.8d-132) then
        tmp = x
    else
        tmp = y
    end if
    code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= 8.8e-132) {
		tmp = x;
	} else {
		tmp = y;
	}
	return tmp;
}
[x, y, z] = sort([x, y, z])
def code(x, y, z):
	tmp = 0
	if y <= 8.8e-132:
		tmp = x
	else:
		tmp = y
	return tmp
x, y, z = sort([x, y, z])
function code(x, y, z)
	tmp = 0.0
	if (y <= 8.8e-132)
		tmp = x;
	else
		tmp = y;
	end
	return tmp
end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= 8.8e-132)
		tmp = x;
	else
		tmp = y;
	end
	tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := If[LessEqual[y, 8.8e-132], x, y]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 8.8 \cdot 10^{-132}:\\
\;\;\;\;x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 8.79999999999999963e-132

    1. Initial program 100.0%

      \[\left(x + y\right) \cdot \left(z + 1\right) \]
    2. Add Preprocessing
    3. 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 \]
    4. Applied egg-rr100.0%

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

      \[\leadsto \color{blue}{x + x \cdot z} \]
    6. Taylor expanded in z around 0 28.4%

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

    if 8.79999999999999963e-132 < y

    1. Initial program 100.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 8.8 \cdot 10^{-132}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 25.9% accurate, 7.0× speedup?

\[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ x \end{array} \]
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z) :precision binary64 x)
assert(x < y && y < z);
double code(double x, double y, double z) {
	return x;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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
assert x < y && y < z;
public static double code(double x, double y, double z) {
	return x;
}
[x, y, z] = sort([x, y, z])
def code(x, y, z):
	return x
x, y, z = sort([x, y, z])
function code(x, y, z)
	return x
end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
	tmp = x;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := x
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
x
\end{array}
Derivation
  1. Initial program 100.0%

    \[\left(x + y\right) \cdot \left(z + 1\right) \]
  2. Add Preprocessing
  3. 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 \]
  4. Applied egg-rr100.0%

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

    \[\leadsto \color{blue}{x + x \cdot z} \]
  6. Taylor expanded in z around 0 23.5%

    \[\leadsto \color{blue}{x} \]
  7. Final simplification23.5%

    \[\leadsto x \]
  8. Add Preprocessing

Reproduce

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