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

Percentage Accurate: 100.0% → 100.0%
Time: 4.0s
Alternatives: 7
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 7 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 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: 74.9% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -4.6 \cdot 10^{+268}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -1.15 \cdot 10^{+184}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq -7.5 \cdot 10^{+114}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -9 \cdot 10^{+89}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq -1:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 5600:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq 2.7 \cdot 10^{+140} \lor \neg \left(z \leq 4.9 \cdot 10^{+204}\right):\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(z + 1\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= z -4.6e+268)
   (* y z)
   (if (<= z -1.15e+184)
     (* x z)
     (if (<= z -7.5e+114)
       (* y z)
       (if (<= z -9e+89)
         (* x z)
         (if (<= z -1.0)
           (* y z)
           (if (<= z 5600.0)
             (+ x y)
             (if (or (<= z 2.7e+140) (not (<= z 4.9e+204)))
               (* y z)
               (* x (+ z 1.0))))))))))
double code(double x, double y, double z) {
	double tmp;
	if (z <= -4.6e+268) {
		tmp = y * z;
	} else if (z <= -1.15e+184) {
		tmp = x * z;
	} else if (z <= -7.5e+114) {
		tmp = y * z;
	} else if (z <= -9e+89) {
		tmp = x * z;
	} else if (z <= -1.0) {
		tmp = y * z;
	} else if (z <= 5600.0) {
		tmp = x + y;
	} else if ((z <= 2.7e+140) || !(z <= 4.9e+204)) {
		tmp = y * z;
	} else {
		tmp = x * (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 (z <= (-4.6d+268)) then
        tmp = y * z
    else if (z <= (-1.15d+184)) then
        tmp = x * z
    else if (z <= (-7.5d+114)) then
        tmp = y * z
    else if (z <= (-9d+89)) then
        tmp = x * z
    else if (z <= (-1.0d0)) then
        tmp = y * z
    else if (z <= 5600.0d0) then
        tmp = x + y
    else if ((z <= 2.7d+140) .or. (.not. (z <= 4.9d+204))) then
        tmp = y * z
    else
        tmp = x * (z + 1.0d0)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (z <= -4.6e+268) {
		tmp = y * z;
	} else if (z <= -1.15e+184) {
		tmp = x * z;
	} else if (z <= -7.5e+114) {
		tmp = y * z;
	} else if (z <= -9e+89) {
		tmp = x * z;
	} else if (z <= -1.0) {
		tmp = y * z;
	} else if (z <= 5600.0) {
		tmp = x + y;
	} else if ((z <= 2.7e+140) || !(z <= 4.9e+204)) {
		tmp = y * z;
	} else {
		tmp = x * (z + 1.0);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if z <= -4.6e+268:
		tmp = y * z
	elif z <= -1.15e+184:
		tmp = x * z
	elif z <= -7.5e+114:
		tmp = y * z
	elif z <= -9e+89:
		tmp = x * z
	elif z <= -1.0:
		tmp = y * z
	elif z <= 5600.0:
		tmp = x + y
	elif (z <= 2.7e+140) or not (z <= 4.9e+204):
		tmp = y * z
	else:
		tmp = x * (z + 1.0)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (z <= -4.6e+268)
		tmp = Float64(y * z);
	elseif (z <= -1.15e+184)
		tmp = Float64(x * z);
	elseif (z <= -7.5e+114)
		tmp = Float64(y * z);
	elseif (z <= -9e+89)
		tmp = Float64(x * z);
	elseif (z <= -1.0)
		tmp = Float64(y * z);
	elseif (z <= 5600.0)
		tmp = Float64(x + y);
	elseif ((z <= 2.7e+140) || !(z <= 4.9e+204))
		tmp = Float64(y * z);
	else
		tmp = Float64(x * Float64(z + 1.0));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (z <= -4.6e+268)
		tmp = y * z;
	elseif (z <= -1.15e+184)
		tmp = x * z;
	elseif (z <= -7.5e+114)
		tmp = y * z;
	elseif (z <= -9e+89)
		tmp = x * z;
	elseif (z <= -1.0)
		tmp = y * z;
	elseif (z <= 5600.0)
		tmp = x + y;
	elseif ((z <= 2.7e+140) || ~((z <= 4.9e+204)))
		tmp = y * z;
	else
		tmp = x * (z + 1.0);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[z, -4.6e+268], N[(y * z), $MachinePrecision], If[LessEqual[z, -1.15e+184], N[(x * z), $MachinePrecision], If[LessEqual[z, -7.5e+114], N[(y * z), $MachinePrecision], If[LessEqual[z, -9e+89], N[(x * z), $MachinePrecision], If[LessEqual[z, -1.0], N[(y * z), $MachinePrecision], If[LessEqual[z, 5600.0], N[(x + y), $MachinePrecision], If[Or[LessEqual[z, 2.7e+140], N[Not[LessEqual[z, 4.9e+204]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.6 \cdot 10^{+268}:\\
\;\;\;\;y \cdot z\\

\mathbf{elif}\;z \leq -1.15 \cdot 10^{+184}:\\
\;\;\;\;x \cdot z\\

\mathbf{elif}\;z \leq -7.5 \cdot 10^{+114}:\\
\;\;\;\;y \cdot z\\

\mathbf{elif}\;z \leq -9 \cdot 10^{+89}:\\
\;\;\;\;x \cdot z\\

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

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

\mathbf{elif}\;z \leq 2.7 \cdot 10^{+140} \lor \neg \left(z \leq 4.9 \cdot 10^{+204}\right):\\
\;\;\;\;y \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if z < -4.60000000000000024e268 or -1.15e184 < z < -7.5000000000000001e114 or -9e89 < z < -1 or 5600 < z < 2.70000000000000018e140 or 4.8999999999999997e204 < z

    1. Initial program 100.0%

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

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

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

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

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

      \[\leadsto \color{blue}{z \cdot y + z \cdot x} \]
    7. Taylor expanded in y around inf 48.2%

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

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

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

    if -4.60000000000000024e268 < z < -1.15e184 or -7.5000000000000001e114 < z < -9e89

    1. Initial program 99.9%

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

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

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

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

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

      \[\leadsto \color{blue}{z \cdot y + z \cdot x} \]
    7. Taylor expanded in y around 0 46.8%

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

        \[\leadsto \color{blue}{z \cdot x} \]
    9. Simplified46.8%

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

    if -1 < z < 5600

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{y + x} \]
    4. Simplified96.8%

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

    if 2.70000000000000018e140 < z < 4.8999999999999997e204

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -4.6 \cdot 10^{+268}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -1.15 \cdot 10^{+184}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq -7.5 \cdot 10^{+114}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -9 \cdot 10^{+89}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq -1:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 5600:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq 2.7 \cdot 10^{+140} \lor \neg \left(z \leq 4.9 \cdot 10^{+204}\right):\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(z + 1\right)\\ \end{array} \]

Alternative 3: 75.0% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -4 \cdot 10^{+270}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -6.7 \cdot 10^{+182}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq -5.9 \cdot 10^{+113}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -1.4 \cdot 10^{+89}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq -1:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 5600:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq 1.2 \cdot 10^{+138} \lor \neg \left(z \leq 1.16 \cdot 10^{+207}\right):\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= z -4e+270)
   (* y z)
   (if (<= z -6.7e+182)
     (* x z)
     (if (<= z -5.9e+113)
       (* y z)
       (if (<= z -1.4e+89)
         (* x z)
         (if (<= z -1.0)
           (* y z)
           (if (<= z 5600.0)
             (+ x y)
             (if (or (<= z 1.2e+138) (not (<= z 1.16e+207)))
               (* y z)
               (* x z)))))))))
double code(double x, double y, double z) {
	double tmp;
	if (z <= -4e+270) {
		tmp = y * z;
	} else if (z <= -6.7e+182) {
		tmp = x * z;
	} else if (z <= -5.9e+113) {
		tmp = y * z;
	} else if (z <= -1.4e+89) {
		tmp = x * z;
	} else if (z <= -1.0) {
		tmp = y * z;
	} else if (z <= 5600.0) {
		tmp = x + y;
	} else if ((z <= 1.2e+138) || !(z <= 1.16e+207)) {
		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 <= (-4d+270)) then
        tmp = y * z
    else if (z <= (-6.7d+182)) then
        tmp = x * z
    else if (z <= (-5.9d+113)) then
        tmp = y * z
    else if (z <= (-1.4d+89)) then
        tmp = x * z
    else if (z <= (-1.0d0)) then
        tmp = y * z
    else if (z <= 5600.0d0) then
        tmp = x + y
    else if ((z <= 1.2d+138) .or. (.not. (z <= 1.16d+207))) 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 <= -4e+270) {
		tmp = y * z;
	} else if (z <= -6.7e+182) {
		tmp = x * z;
	} else if (z <= -5.9e+113) {
		tmp = y * z;
	} else if (z <= -1.4e+89) {
		tmp = x * z;
	} else if (z <= -1.0) {
		tmp = y * z;
	} else if (z <= 5600.0) {
		tmp = x + y;
	} else if ((z <= 1.2e+138) || !(z <= 1.16e+207)) {
		tmp = y * z;
	} else {
		tmp = x * z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if z <= -4e+270:
		tmp = y * z
	elif z <= -6.7e+182:
		tmp = x * z
	elif z <= -5.9e+113:
		tmp = y * z
	elif z <= -1.4e+89:
		tmp = x * z
	elif z <= -1.0:
		tmp = y * z
	elif z <= 5600.0:
		tmp = x + y
	elif (z <= 1.2e+138) or not (z <= 1.16e+207):
		tmp = y * z
	else:
		tmp = x * z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (z <= -4e+270)
		tmp = Float64(y * z);
	elseif (z <= -6.7e+182)
		tmp = Float64(x * z);
	elseif (z <= -5.9e+113)
		tmp = Float64(y * z);
	elseif (z <= -1.4e+89)
		tmp = Float64(x * z);
	elseif (z <= -1.0)
		tmp = Float64(y * z);
	elseif (z <= 5600.0)
		tmp = Float64(x + y);
	elseif ((z <= 1.2e+138) || !(z <= 1.16e+207))
		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 <= -4e+270)
		tmp = y * z;
	elseif (z <= -6.7e+182)
		tmp = x * z;
	elseif (z <= -5.9e+113)
		tmp = y * z;
	elseif (z <= -1.4e+89)
		tmp = x * z;
	elseif (z <= -1.0)
		tmp = y * z;
	elseif (z <= 5600.0)
		tmp = x + y;
	elseif ((z <= 1.2e+138) || ~((z <= 1.16e+207)))
		tmp = y * z;
	else
		tmp = x * z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[z, -4e+270], N[(y * z), $MachinePrecision], If[LessEqual[z, -6.7e+182], N[(x * z), $MachinePrecision], If[LessEqual[z, -5.9e+113], N[(y * z), $MachinePrecision], If[LessEqual[z, -1.4e+89], N[(x * z), $MachinePrecision], If[LessEqual[z, -1.0], N[(y * z), $MachinePrecision], If[LessEqual[z, 5600.0], N[(x + y), $MachinePrecision], If[Or[LessEqual[z, 1.2e+138], N[Not[LessEqual[z, 1.16e+207]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -4 \cdot 10^{+270}:\\
\;\;\;\;y \cdot z\\

\mathbf{elif}\;z \leq -6.7 \cdot 10^{+182}:\\
\;\;\;\;x \cdot z\\

\mathbf{elif}\;z \leq -5.9 \cdot 10^{+113}:\\
\;\;\;\;y \cdot z\\

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

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

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

\mathbf{elif}\;z \leq 1.2 \cdot 10^{+138} \lor \neg \left(z \leq 1.16 \cdot 10^{+207}\right):\\
\;\;\;\;y \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -4.0000000000000002e270 or -6.7000000000000006e182 < z < -5.90000000000000023e113 or -1.3999999999999999e89 < z < -1 or 5600 < z < 1.2e138 or 1.16e207 < z

    1. Initial program 100.0%

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

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

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

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

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

      \[\leadsto \color{blue}{z \cdot y + z \cdot x} \]
    7. Taylor expanded in y around inf 48.2%

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

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

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

    if -4.0000000000000002e270 < z < -6.7000000000000006e182 or -5.90000000000000023e113 < z < -1.3999999999999999e89 or 1.2e138 < z < 1.16e207

    1. Initial program 100.0%

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

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

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

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

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

      \[\leadsto \color{blue}{z \cdot y + z \cdot x} \]
    7. Taylor expanded in y around 0 53.2%

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

        \[\leadsto \color{blue}{z \cdot x} \]
    9. Simplified53.2%

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

    if -1 < z < 5600

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{y + x} \]
    4. Simplified96.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -4 \cdot 10^{+270}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -6.7 \cdot 10^{+182}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq -5.9 \cdot 10^{+113}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -1.4 \cdot 10^{+89}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq -1:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 5600:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq 1.2 \cdot 10^{+138} \lor \neg \left(z \leq 1.16 \cdot 10^{+207}\right):\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \]

Alternative 4: 97.9% 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 97.6%

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

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

      \[\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. Taylor expanded in z around 0 97.5%

      \[\leadsto \color{blue}{x + y} \]
    3. Step-by-step derivation
      1. +-commutative97.5%

        \[\leadsto \color{blue}{y + x} \]
    4. Simplified97.5%

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

    \[\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 5: 61.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 1.45 \cdot 10^{-127}:\\ \;\;\;\;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 (<= y 1.45e-127) (* x (+ z 1.0)) (* y (+ z 1.0))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= 1.45e-127) {
		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 (y <= 1.45d-127) 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 (y <= 1.45e-127) {
		tmp = x * (z + 1.0);
	} else {
		tmp = y * (z + 1.0);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= 1.45e-127:
		tmp = x * (z + 1.0)
	else:
		tmp = y * (z + 1.0)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= 1.45e-127)
		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 (y <= 1.45e-127)
		tmp = x * (z + 1.0);
	else
		tmp = y * (z + 1.0);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, 1.45e-127], N[(x * N[(z + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.45 \cdot 10^{-127}:\\
\;\;\;\;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 y < 1.45e-127

    1. Initial program 100.0%

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

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

    if 1.45e-127 < y

    1. Initial program 100.0%

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

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

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

Alternative 6: 31.6% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.65 \cdot 10^{-165}:\\
\;\;\;\;x \cdot z\\

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


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

    1. Initial program 100.0%

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

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

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

      \[\leadsto \color{blue}{z \cdot \left(y + x\right)} \]
    5. Step-by-step derivation
      1. distribute-lft-in46.7%

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

      \[\leadsto \color{blue}{z \cdot y + z \cdot x} \]
    7. Taylor expanded in y around 0 32.6%

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

        \[\leadsto \color{blue}{z \cdot x} \]
    9. Simplified32.6%

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

    if 1.6499999999999999e-165 < y

    1. Initial program 100.0%

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

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

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

      \[\leadsto \color{blue}{z \cdot \left(y + x\right)} \]
    5. Step-by-step derivation
      1. distribute-lft-in52.0%

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

      \[\leadsto \color{blue}{z \cdot y + z \cdot x} \]
    7. Taylor expanded in y around inf 35.9%

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

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

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

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

Alternative 7: 27.5% accurate, 2.3× speedup?

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

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

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

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

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

    \[\leadsto \color{blue}{z \cdot \left(y + x\right)} \]
  5. Step-by-step derivation
    1. distribute-lft-in48.9%

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

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

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

      \[\leadsto \color{blue}{z \cdot x} \]
  9. Simplified28.4%

    \[\leadsto \color{blue}{z \cdot x} \]
  10. Final simplification28.4%

    \[\leadsto x \cdot z \]

Reproduce

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