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

Percentage Accurate: 100.0% → 100.0%
Time: 5.0s
Alternatives: 8
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 8 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. Add Preprocessing
  3. Add Preprocessing

Alternative 2: 75.3% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -1.02 \cdot 10^{+222}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq -8.3 \cdot 10^{+155}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -3.7 \cdot 10^{+62}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq -1:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 14000:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq 2 \cdot 10^{+179} \lor \neg \left(z \leq 6 \cdot 10^{+226}\right):\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(z + 1\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= z -1.02e+222)
   (* x z)
   (if (<= z -8.3e+155)
     (* y z)
     (if (<= z -3.7e+62)
       (* x z)
       (if (<= z -1.0)
         (* y z)
         (if (<= z 14000.0)
           (+ x y)
           (if (or (<= z 2e+179) (not (<= z 6e+226)))
             (* y z)
             (* x (+ z 1.0)))))))))
double code(double x, double y, double z) {
	double tmp;
	if (z <= -1.02e+222) {
		tmp = x * z;
	} else if (z <= -8.3e+155) {
		tmp = y * z;
	} else if (z <= -3.7e+62) {
		tmp = x * z;
	} else if (z <= -1.0) {
		tmp = y * z;
	} else if (z <= 14000.0) {
		tmp = x + y;
	} else if ((z <= 2e+179) || !(z <= 6e+226)) {
		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 <= (-1.02d+222)) then
        tmp = x * z
    else if (z <= (-8.3d+155)) then
        tmp = y * z
    else if (z <= (-3.7d+62)) then
        tmp = x * z
    else if (z <= (-1.0d0)) then
        tmp = y * z
    else if (z <= 14000.0d0) then
        tmp = x + y
    else if ((z <= 2d+179) .or. (.not. (z <= 6d+226))) 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 <= -1.02e+222) {
		tmp = x * z;
	} else if (z <= -8.3e+155) {
		tmp = y * z;
	} else if (z <= -3.7e+62) {
		tmp = x * z;
	} else if (z <= -1.0) {
		tmp = y * z;
	} else if (z <= 14000.0) {
		tmp = x + y;
	} else if ((z <= 2e+179) || !(z <= 6e+226)) {
		tmp = y * z;
	} else {
		tmp = x * (z + 1.0);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if z <= -1.02e+222:
		tmp = x * z
	elif z <= -8.3e+155:
		tmp = y * z
	elif z <= -3.7e+62:
		tmp = x * z
	elif z <= -1.0:
		tmp = y * z
	elif z <= 14000.0:
		tmp = x + y
	elif (z <= 2e+179) or not (z <= 6e+226):
		tmp = y * z
	else:
		tmp = x * (z + 1.0)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (z <= -1.02e+222)
		tmp = Float64(x * z);
	elseif (z <= -8.3e+155)
		tmp = Float64(y * z);
	elseif (z <= -3.7e+62)
		tmp = Float64(x * z);
	elseif (z <= -1.0)
		tmp = Float64(y * z);
	elseif (z <= 14000.0)
		tmp = Float64(x + y);
	elseif ((z <= 2e+179) || !(z <= 6e+226))
		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 <= -1.02e+222)
		tmp = x * z;
	elseif (z <= -8.3e+155)
		tmp = y * z;
	elseif (z <= -3.7e+62)
		tmp = x * z;
	elseif (z <= -1.0)
		tmp = y * z;
	elseif (z <= 14000.0)
		tmp = x + y;
	elseif ((z <= 2e+179) || ~((z <= 6e+226)))
		tmp = y * z;
	else
		tmp = x * (z + 1.0);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[z, -1.02e+222], N[(x * z), $MachinePrecision], If[LessEqual[z, -8.3e+155], N[(y * z), $MachinePrecision], If[LessEqual[z, -3.7e+62], N[(x * z), $MachinePrecision], If[LessEqual[z, -1.0], N[(y * z), $MachinePrecision], If[LessEqual[z, 14000.0], N[(x + y), $MachinePrecision], If[Or[LessEqual[z, 2e+179], N[Not[LessEqual[z, 6e+226]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;z \leq -8.3 \cdot 10^{+155}:\\
\;\;\;\;y \cdot z\\

\mathbf{elif}\;z \leq -3.7 \cdot 10^{+62}:\\
\;\;\;\;x \cdot z\\

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

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

\mathbf{elif}\;z \leq 2 \cdot 10^{+179} \lor \neg \left(z \leq 6 \cdot 10^{+226}\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 < -1.01999999999999995e222 or -8.2999999999999998e155 < z < -3.70000000000000014e62

    1. Initial program 100.0%

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

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

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

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

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

    if -1.01999999999999995e222 < z < -8.2999999999999998e155 or -3.70000000000000014e62 < z < -1 or 14000 < z < 1.99999999999999996e179 or 5.9999999999999995e226 < 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 59.7%

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

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

    if -1 < z < 14000

    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.3%

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

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

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

    if 1.99999999999999996e179 < z < 5.9999999999999995e226

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.02 \cdot 10^{+222}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq -8.3 \cdot 10^{+155}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -3.7 \cdot 10^{+62}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq -1:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 14000:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq 2 \cdot 10^{+179} \lor \neg \left(z \leq 6 \cdot 10^{+226}\right):\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(z + 1\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 75.2% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -1.5 \cdot 10^{+221}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq -5.2 \cdot 10^{+155}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -3.1 \cdot 10^{+62}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq -1:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 14000:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq 1.02 \cdot 10^{+179} \lor \neg \left(z \leq 4.8 \cdot 10^{+230}\right):\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= z -1.5e+221)
   (* x z)
   (if (<= z -5.2e+155)
     (* y z)
     (if (<= z -3.1e+62)
       (* x z)
       (if (<= z -1.0)
         (* y z)
         (if (<= z 14000.0)
           (+ x y)
           (if (or (<= z 1.02e+179) (not (<= z 4.8e+230)))
             (* y z)
             (* x z))))))))
double code(double x, double y, double z) {
	double tmp;
	if (z <= -1.5e+221) {
		tmp = x * z;
	} else if (z <= -5.2e+155) {
		tmp = y * z;
	} else if (z <= -3.1e+62) {
		tmp = x * z;
	} else if (z <= -1.0) {
		tmp = y * z;
	} else if (z <= 14000.0) {
		tmp = x + y;
	} else if ((z <= 1.02e+179) || !(z <= 4.8e+230)) {
		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.5d+221)) then
        tmp = x * z
    else if (z <= (-5.2d+155)) then
        tmp = y * z
    else if (z <= (-3.1d+62)) then
        tmp = x * z
    else if (z <= (-1.0d0)) then
        tmp = y * z
    else if (z <= 14000.0d0) then
        tmp = x + y
    else if ((z <= 1.02d+179) .or. (.not. (z <= 4.8d+230))) 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.5e+221) {
		tmp = x * z;
	} else if (z <= -5.2e+155) {
		tmp = y * z;
	} else if (z <= -3.1e+62) {
		tmp = x * z;
	} else if (z <= -1.0) {
		tmp = y * z;
	} else if (z <= 14000.0) {
		tmp = x + y;
	} else if ((z <= 1.02e+179) || !(z <= 4.8e+230)) {
		tmp = y * z;
	} else {
		tmp = x * z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if z <= -1.5e+221:
		tmp = x * z
	elif z <= -5.2e+155:
		tmp = y * z
	elif z <= -3.1e+62:
		tmp = x * z
	elif z <= -1.0:
		tmp = y * z
	elif z <= 14000.0:
		tmp = x + y
	elif (z <= 1.02e+179) or not (z <= 4.8e+230):
		tmp = y * z
	else:
		tmp = x * z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (z <= -1.5e+221)
		tmp = Float64(x * z);
	elseif (z <= -5.2e+155)
		tmp = Float64(y * z);
	elseif (z <= -3.1e+62)
		tmp = Float64(x * z);
	elseif (z <= -1.0)
		tmp = Float64(y * z);
	elseif (z <= 14000.0)
		tmp = Float64(x + y);
	elseif ((z <= 1.02e+179) || !(z <= 4.8e+230))
		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.5e+221)
		tmp = x * z;
	elseif (z <= -5.2e+155)
		tmp = y * z;
	elseif (z <= -3.1e+62)
		tmp = x * z;
	elseif (z <= -1.0)
		tmp = y * z;
	elseif (z <= 14000.0)
		tmp = x + y;
	elseif ((z <= 1.02e+179) || ~((z <= 4.8e+230)))
		tmp = y * z;
	else
		tmp = x * z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[z, -1.5e+221], N[(x * z), $MachinePrecision], If[LessEqual[z, -5.2e+155], N[(y * z), $MachinePrecision], If[LessEqual[z, -3.1e+62], N[(x * z), $MachinePrecision], If[LessEqual[z, -1.0], N[(y * z), $MachinePrecision], If[LessEqual[z, 14000.0], N[(x + y), $MachinePrecision], If[Or[LessEqual[z, 1.02e+179], N[Not[LessEqual[z, 4.8e+230]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;z \leq -5.2 \cdot 10^{+155}:\\
\;\;\;\;y \cdot z\\

\mathbf{elif}\;z \leq -3.1 \cdot 10^{+62}:\\
\;\;\;\;x \cdot z\\

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

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

\mathbf{elif}\;z \leq 1.02 \cdot 10^{+179} \lor \neg \left(z \leq 4.8 \cdot 10^{+230}\right):\\
\;\;\;\;y \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -1.5000000000000001e221 or -5.2000000000000004e155 < z < -3.10000000000000014e62 or 1.0199999999999999e179 < z < 4.79999999999999996e230

    1. Initial program 100.0%

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

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

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

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

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

    if -1.5000000000000001e221 < z < -5.2000000000000004e155 or -3.10000000000000014e62 < z < -1 or 14000 < z < 1.0199999999999999e179 or 4.79999999999999996e230 < 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 59.7%

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

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

    if -1 < z < 14000

    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.3%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.5 \cdot 10^{+221}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq -5.2 \cdot 10^{+155}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -3.1 \cdot 10^{+62}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq -1:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 14000:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq 1.02 \cdot 10^{+179} \lor \neg \left(z \leq 4.8 \cdot 10^{+230}\right):\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 50.4% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -1.15 \cdot 10^{+221}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq -2.55 \cdot 10^{+156}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -3 \cdot 10^{+62}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq -1:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 5.8 \cdot 10^{-16}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 7.5 \cdot 10^{+178} \lor \neg \left(z \leq 2.45 \cdot 10^{+228}\right):\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= z -1.15e+221)
   (* x z)
   (if (<= z -2.55e+156)
     (* y z)
     (if (<= z -3e+62)
       (* x z)
       (if (<= z -1.0)
         (* y z)
         (if (<= z 5.8e-16)
           y
           (if (or (<= z 7.5e+178) (not (<= z 2.45e+228)))
             (* y z)
             (* x z))))))))
double code(double x, double y, double z) {
	double tmp;
	if (z <= -1.15e+221) {
		tmp = x * z;
	} else if (z <= -2.55e+156) {
		tmp = y * z;
	} else if (z <= -3e+62) {
		tmp = x * z;
	} else if (z <= -1.0) {
		tmp = y * z;
	} else if (z <= 5.8e-16) {
		tmp = y;
	} else if ((z <= 7.5e+178) || !(z <= 2.45e+228)) {
		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.15d+221)) then
        tmp = x * z
    else if (z <= (-2.55d+156)) then
        tmp = y * z
    else if (z <= (-3d+62)) then
        tmp = x * z
    else if (z <= (-1.0d0)) then
        tmp = y * z
    else if (z <= 5.8d-16) then
        tmp = y
    else if ((z <= 7.5d+178) .or. (.not. (z <= 2.45d+228))) 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.15e+221) {
		tmp = x * z;
	} else if (z <= -2.55e+156) {
		tmp = y * z;
	} else if (z <= -3e+62) {
		tmp = x * z;
	} else if (z <= -1.0) {
		tmp = y * z;
	} else if (z <= 5.8e-16) {
		tmp = y;
	} else if ((z <= 7.5e+178) || !(z <= 2.45e+228)) {
		tmp = y * z;
	} else {
		tmp = x * z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if z <= -1.15e+221:
		tmp = x * z
	elif z <= -2.55e+156:
		tmp = y * z
	elif z <= -3e+62:
		tmp = x * z
	elif z <= -1.0:
		tmp = y * z
	elif z <= 5.8e-16:
		tmp = y
	elif (z <= 7.5e+178) or not (z <= 2.45e+228):
		tmp = y * z
	else:
		tmp = x * z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (z <= -1.15e+221)
		tmp = Float64(x * z);
	elseif (z <= -2.55e+156)
		tmp = Float64(y * z);
	elseif (z <= -3e+62)
		tmp = Float64(x * z);
	elseif (z <= -1.0)
		tmp = Float64(y * z);
	elseif (z <= 5.8e-16)
		tmp = y;
	elseif ((z <= 7.5e+178) || !(z <= 2.45e+228))
		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.15e+221)
		tmp = x * z;
	elseif (z <= -2.55e+156)
		tmp = y * z;
	elseif (z <= -3e+62)
		tmp = x * z;
	elseif (z <= -1.0)
		tmp = y * z;
	elseif (z <= 5.8e-16)
		tmp = y;
	elseif ((z <= 7.5e+178) || ~((z <= 2.45e+228)))
		tmp = y * z;
	else
		tmp = x * z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[z, -1.15e+221], N[(x * z), $MachinePrecision], If[LessEqual[z, -2.55e+156], N[(y * z), $MachinePrecision], If[LessEqual[z, -3e+62], N[(x * z), $MachinePrecision], If[LessEqual[z, -1.0], N[(y * z), $MachinePrecision], If[LessEqual[z, 5.8e-16], y, If[Or[LessEqual[z, 7.5e+178], N[Not[LessEqual[z, 2.45e+228]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;z \leq -2.55 \cdot 10^{+156}:\\
\;\;\;\;y \cdot z\\

\mathbf{elif}\;z \leq -3 \cdot 10^{+62}:\\
\;\;\;\;x \cdot z\\

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

\mathbf{elif}\;z \leq 5.8 \cdot 10^{-16}:\\
\;\;\;\;y\\

\mathbf{elif}\;z \leq 7.5 \cdot 10^{+178} \lor \neg \left(z \leq 2.45 \cdot 10^{+228}\right):\\
\;\;\;\;y \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -1.14999999999999993e221 or -2.55000000000000007e156 < z < -3e62 or 7.4999999999999995e178 < z < 2.4500000000000001e228

    1. Initial program 100.0%

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

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

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

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

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

    if -1.14999999999999993e221 < z < -2.55000000000000007e156 or -3e62 < z < -1 or 5.7999999999999996e-16 < z < 7.4999999999999995e178 or 2.4500000000000001e228 < 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 58.8%

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

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

    if -1 < z < 5.7999999999999996e-16

    1. Initial program 100.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.15 \cdot 10^{+221}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq -2.55 \cdot 10^{+156}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -3 \cdot 10^{+62}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq -1:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 5.8 \cdot 10^{-16}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 7.5 \cdot 10^{+178} \lor \neg \left(z \leq 2.45 \cdot 10^{+228}\right):\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 61.9% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \left(z + 1\right)\\ \mathbf{if}\;x \leq -2.25 \cdot 10^{-62}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq -4.5 \cdot 10^{-138}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;x \leq -2.9 \cdot 10^{-148}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(z + 1\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* x (+ z 1.0))))
   (if (<= x -2.25e-62)
     t_0
     (if (<= x -4.5e-138) (+ x y) (if (<= x -2.9e-148) t_0 (* y (+ z 1.0)))))))
double code(double x, double y, double z) {
	double t_0 = x * (z + 1.0);
	double tmp;
	if (x <= -2.25e-62) {
		tmp = t_0;
	} else if (x <= -4.5e-138) {
		tmp = x + y;
	} else if (x <= -2.9e-148) {
		tmp = t_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) :: t_0
    real(8) :: tmp
    t_0 = x * (z + 1.0d0)
    if (x <= (-2.25d-62)) then
        tmp = t_0
    else if (x <= (-4.5d-138)) then
        tmp = x + y
    else if (x <= (-2.9d-148)) then
        tmp = t_0
    else
        tmp = y * (z + 1.0d0)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = x * (z + 1.0);
	double tmp;
	if (x <= -2.25e-62) {
		tmp = t_0;
	} else if (x <= -4.5e-138) {
		tmp = x + y;
	} else if (x <= -2.9e-148) {
		tmp = t_0;
	} else {
		tmp = y * (z + 1.0);
	}
	return tmp;
}
def code(x, y, z):
	t_0 = x * (z + 1.0)
	tmp = 0
	if x <= -2.25e-62:
		tmp = t_0
	elif x <= -4.5e-138:
		tmp = x + y
	elif x <= -2.9e-148:
		tmp = t_0
	else:
		tmp = y * (z + 1.0)
	return tmp
function code(x, y, z)
	t_0 = Float64(x * Float64(z + 1.0))
	tmp = 0.0
	if (x <= -2.25e-62)
		tmp = t_0;
	elseif (x <= -4.5e-138)
		tmp = Float64(x + y);
	elseif (x <= -2.9e-148)
		tmp = t_0;
	else
		tmp = Float64(y * Float64(z + 1.0));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = x * (z + 1.0);
	tmp = 0.0;
	if (x <= -2.25e-62)
		tmp = t_0;
	elseif (x <= -4.5e-138)
		tmp = x + y;
	elseif (x <= -2.9e-148)
		tmp = t_0;
	else
		tmp = y * (z + 1.0);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -2.25e-62], t$95$0, If[LessEqual[x, -4.5e-138], N[(x + y), $MachinePrecision], If[LessEqual[x, -2.9e-148], t$95$0, N[(y * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := x \cdot \left(z + 1\right)\\
\mathbf{if}\;x \leq -2.25 \cdot 10^{-62}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;x \leq -4.5 \cdot 10^{-138}:\\
\;\;\;\;x + y\\

\mathbf{elif}\;x \leq -2.9 \cdot 10^{-148}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -2.25000000000000009e-62 or -4.50000000000000008e-138 < x < -2.8999999999999998e-148

    1. Initial program 100.0%

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

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

    if -2.25000000000000009e-62 < x < -4.50000000000000008e-138

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{y + x} \]
    5. Simplified60.9%

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

    if -2.8999999999999998e-148 < x

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.25 \cdot 10^{-62}:\\ \;\;\;\;x \cdot \left(z + 1\right)\\ \mathbf{elif}\;x \leq -4.5 \cdot 10^{-138}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;x \leq -2.9 \cdot 10^{-148}:\\ \;\;\;\;x \cdot \left(z + 1\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(z + 1\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 98.0% accurate, 0.5× 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. Add Preprocessing
    3. Taylor expanded in z around inf 97.3%

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

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

      \[\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 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} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification98.4%

    \[\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} \]
  5. Add Preprocessing

Alternative 7: 50.4% accurate, 0.5× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -1 or 5.7999999999999996e-16 < 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 96.6%

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

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

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

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

    if -1 < z < 5.7999999999999996e-16

    1. Initial program 100.0%

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

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

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

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

Alternative 8: 26.5% accurate, 7.0× speedup?

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

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

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

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

    \[\leadsto \color{blue}{y} \]
  5. Add Preprocessing

Reproduce

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