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

Percentage Accurate: 100.0% → 100.0%
Time: 4.1s
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. Final simplification100.0%

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

Alternative 2: 75.5% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \left(z + 1\right)\\ \mathbf{if}\;z \leq -4 \cdot 10^{+78}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -4.9 \cdot 10^{+55}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -3.8 \cdot 10^{+34}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 2.85 \cdot 10^{-5}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq 1.26 \cdot 10^{+270} \lor \neg \left(z \leq 4.1 \cdot 10^{+278}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* x (+ z 1.0))))
   (if (<= z -4e+78)
     t_0
     (if (<= z -4.9e+55)
       (* y z)
       (if (<= z -3.8e+34)
         t_0
         (if (<= z -1.0)
           (* y z)
           (if (<= z 2.85e-5)
             (+ x y)
             (if (or (<= z 1.26e+270) (not (<= z 4.1e+278)))
               t_0
               (* y z)))))))))
double code(double x, double y, double z) {
	double t_0 = x * (z + 1.0);
	double tmp;
	if (z <= -4e+78) {
		tmp = t_0;
	} else if (z <= -4.9e+55) {
		tmp = y * z;
	} else if (z <= -3.8e+34) {
		tmp = t_0;
	} else if (z <= -1.0) {
		tmp = y * z;
	} else if (z <= 2.85e-5) {
		tmp = x + y;
	} else if ((z <= 1.26e+270) || !(z <= 4.1e+278)) {
		tmp = t_0;
	} 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) :: t_0
    real(8) :: tmp
    t_0 = x * (z + 1.0d0)
    if (z <= (-4d+78)) then
        tmp = t_0
    else if (z <= (-4.9d+55)) then
        tmp = y * z
    else if (z <= (-3.8d+34)) then
        tmp = t_0
    else if (z <= (-1.0d0)) then
        tmp = y * z
    else if (z <= 2.85d-5) then
        tmp = x + y
    else if ((z <= 1.26d+270) .or. (.not. (z <= 4.1d+278))) then
        tmp = t_0
    else
        tmp = y * z
    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 (z <= -4e+78) {
		tmp = t_0;
	} else if (z <= -4.9e+55) {
		tmp = y * z;
	} else if (z <= -3.8e+34) {
		tmp = t_0;
	} else if (z <= -1.0) {
		tmp = y * z;
	} else if (z <= 2.85e-5) {
		tmp = x + y;
	} else if ((z <= 1.26e+270) || !(z <= 4.1e+278)) {
		tmp = t_0;
	} else {
		tmp = y * z;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = x * (z + 1.0)
	tmp = 0
	if z <= -4e+78:
		tmp = t_0
	elif z <= -4.9e+55:
		tmp = y * z
	elif z <= -3.8e+34:
		tmp = t_0
	elif z <= -1.0:
		tmp = y * z
	elif z <= 2.85e-5:
		tmp = x + y
	elif (z <= 1.26e+270) or not (z <= 4.1e+278):
		tmp = t_0
	else:
		tmp = y * z
	return tmp
function code(x, y, z)
	t_0 = Float64(x * Float64(z + 1.0))
	tmp = 0.0
	if (z <= -4e+78)
		tmp = t_0;
	elseif (z <= -4.9e+55)
		tmp = Float64(y * z);
	elseif (z <= -3.8e+34)
		tmp = t_0;
	elseif (z <= -1.0)
		tmp = Float64(y * z);
	elseif (z <= 2.85e-5)
		tmp = Float64(x + y);
	elseif ((z <= 1.26e+270) || !(z <= 4.1e+278))
		tmp = t_0;
	else
		tmp = Float64(y * z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = x * (z + 1.0);
	tmp = 0.0;
	if (z <= -4e+78)
		tmp = t_0;
	elseif (z <= -4.9e+55)
		tmp = y * z;
	elseif (z <= -3.8e+34)
		tmp = t_0;
	elseif (z <= -1.0)
		tmp = y * z;
	elseif (z <= 2.85e-5)
		tmp = x + y;
	elseif ((z <= 1.26e+270) || ~((z <= 4.1e+278)))
		tmp = t_0;
	else
		tmp = y * z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -4e+78], t$95$0, If[LessEqual[z, -4.9e+55], N[(y * z), $MachinePrecision], If[LessEqual[z, -3.8e+34], t$95$0, If[LessEqual[z, -1.0], N[(y * z), $MachinePrecision], If[LessEqual[z, 2.85e-5], N[(x + y), $MachinePrecision], If[Or[LessEqual[z, 1.26e+270], N[Not[LessEqual[z, 4.1e+278]], $MachinePrecision]], t$95$0, N[(y * z), $MachinePrecision]]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;z \leq -4.9 \cdot 10^{+55}:\\
\;\;\;\;y \cdot z\\

\mathbf{elif}\;z \leq -3.8 \cdot 10^{+34}:\\
\;\;\;\;t_0\\

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

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

\mathbf{elif}\;z \leq 1.26 \cdot 10^{+270} \lor \neg \left(z \leq 4.1 \cdot 10^{+278}\right):\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -4.00000000000000003e78 or -4.90000000000000015e55 < z < -3.8000000000000001e34 or 2.8500000000000002e-5 < z < 1.2600000000000001e270 or 4.10000000000000015e278 < z

    1. Initial program 100.0%

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

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

    if -4.00000000000000003e78 < z < -4.90000000000000015e55 or -3.8000000000000001e34 < z < -1 or 1.2600000000000001e270 < z < 4.10000000000000015e278

    1. Initial program 99.9%

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

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

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

        \[\leadsto \color{blue}{y \cdot z + y \cdot 1} \]
      3. *-rgt-identity49.5%

        \[\leadsto y \cdot z + \color{blue}{y} \]
    4. Applied egg-rr49.5%

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

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

    if -1 < z < 2.8500000000000002e-5

    1. Initial program 100.0%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -4 \cdot 10^{+78}:\\ \;\;\;\;x \cdot \left(z + 1\right)\\ \mathbf{elif}\;z \leq -4.9 \cdot 10^{+55}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -3.8 \cdot 10^{+34}:\\ \;\;\;\;x \cdot \left(z + 1\right)\\ \mathbf{elif}\;z \leq -1:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 2.85 \cdot 10^{-5}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq 1.26 \cdot 10^{+270} \lor \neg \left(z \leq 4.1 \cdot 10^{+278}\right):\\ \;\;\;\;x \cdot \left(z + 1\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]

Alternative 3: 50.9% accurate, 0.5× speedup?

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

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

\mathbf{elif}\;z \leq -1.45 \cdot 10^{-140}:\\
\;\;\;\;y\\

\mathbf{elif}\;z \leq -1.65 \cdot 10^{-178}:\\
\;\;\;\;x\\

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

\mathbf{elif}\;z \leq 2 \cdot 10^{-118}:\\
\;\;\;\;x\\

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

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


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

    1. Initial program 100.0%

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

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

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

        \[\leadsto \color{blue}{y \cdot z + y \cdot 1} \]
      3. *-rgt-identity54.9%

        \[\leadsto y \cdot z + \color{blue}{y} \]
    4. Applied egg-rr54.9%

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

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

    if -1 < z < -1.44999999999999999e-140 or -1.6500000000000001e-178 < z < 5.4999999999999998e-286 or 1.99999999999999997e-118 < z < 1

    1. Initial program 100.0%

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

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

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

    if -1.44999999999999999e-140 < z < -1.6500000000000001e-178 or 5.4999999999999998e-286 < z < 1.99999999999999997e-118

    1. Initial program 100.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -1.45 \cdot 10^{-140}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq -1.65 \cdot 10^{-178}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 5.5 \cdot 10^{-286}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 2 \cdot 10^{-118}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;y \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.4%

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

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

      \[\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.2%

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

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

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

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

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

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

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


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

    1. Initial program 100.0%

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

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

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

        \[\leadsto \color{blue}{y \cdot z + y \cdot 1} \]
      3. *-rgt-identity54.9%

        \[\leadsto y \cdot z + \color{blue}{y} \]
    4. Applied egg-rr54.9%

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

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

    if -1 < z < 102

    1. Initial program 100.0%

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

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

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

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

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

Alternative 6: 63.4% accurate, 1.0× speedup?

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

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

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


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

    1. Initial program 100.0%

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

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

    if -1.05000000000000001e-44 < x

    1. Initial program 100.0%

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

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

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

Alternative 7: 32.5% accurate, 2.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.05 \cdot 10^{-44}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \end{array} \]
(FPCore (x y z) :precision binary64 (if (<= x -1.05e-44) x y))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -1.05e-44) {
		tmp = x;
	} else {
		tmp = y;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (x <= (-1.05d-44)) then
        tmp = x
    else
        tmp = y
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (x <= -1.05e-44) {
		tmp = x;
	} else {
		tmp = y;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if x <= -1.05e-44:
		tmp = x
	else:
		tmp = y
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (x <= -1.05e-44)
		tmp = x;
	else
		tmp = y;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (x <= -1.05e-44)
		tmp = x;
	else
		tmp = y;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[x, -1.05e-44], x, y]
\begin{array}{l}

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

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


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

    1. Initial program 100.0%

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

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

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

    if -1.05000000000000001e-44 < x

    1. Initial program 100.0%

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

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

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

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

Alternative 8: 26.7% accurate, 7.0× speedup?

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

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

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

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

    \[\leadsto \color{blue}{x} \]
  4. Final simplification26.2%

    \[\leadsto x \]

Reproduce

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