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

Percentage Accurate: 100.0% → 100.0%
Time: 2.8s
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: 49.4% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -310:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -9.7 \cdot 10^{-195}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq -2.75 \cdot 10^{-260}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 3.9 \cdot 10^{-231}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 3.6 \cdot 10^{-172}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.2 \cdot 10^{-130}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 64:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= z -310.0)
   (* y z)
   (if (<= z -9.7e-195)
     y
     (if (<= z -2.75e-260)
       x
       (if (<= z 3.9e-231)
         y
         (if (<= z 3.6e-172)
           x
           (if (<= z 1.2e-130) y (if (<= z 64.0) x (* y z)))))))))
double code(double x, double y, double z) {
	double tmp;
	if (z <= -310.0) {
		tmp = y * z;
	} else if (z <= -9.7e-195) {
		tmp = y;
	} else if (z <= -2.75e-260) {
		tmp = x;
	} else if (z <= 3.9e-231) {
		tmp = y;
	} else if (z <= 3.6e-172) {
		tmp = x;
	} else if (z <= 1.2e-130) {
		tmp = y;
	} else if (z <= 64.0) {
		tmp = x;
	} 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 <= (-310.0d0)) then
        tmp = y * z
    else if (z <= (-9.7d-195)) then
        tmp = y
    else if (z <= (-2.75d-260)) then
        tmp = x
    else if (z <= 3.9d-231) then
        tmp = y
    else if (z <= 3.6d-172) then
        tmp = x
    else if (z <= 1.2d-130) then
        tmp = y
    else if (z <= 64.0d0) then
        tmp = x
    else
        tmp = y * z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (z <= -310.0) {
		tmp = y * z;
	} else if (z <= -9.7e-195) {
		tmp = y;
	} else if (z <= -2.75e-260) {
		tmp = x;
	} else if (z <= 3.9e-231) {
		tmp = y;
	} else if (z <= 3.6e-172) {
		tmp = x;
	} else if (z <= 1.2e-130) {
		tmp = y;
	} else if (z <= 64.0) {
		tmp = x;
	} else {
		tmp = y * z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if z <= -310.0:
		tmp = y * z
	elif z <= -9.7e-195:
		tmp = y
	elif z <= -2.75e-260:
		tmp = x
	elif z <= 3.9e-231:
		tmp = y
	elif z <= 3.6e-172:
		tmp = x
	elif z <= 1.2e-130:
		tmp = y
	elif z <= 64.0:
		tmp = x
	else:
		tmp = y * z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (z <= -310.0)
		tmp = Float64(y * z);
	elseif (z <= -9.7e-195)
		tmp = y;
	elseif (z <= -2.75e-260)
		tmp = x;
	elseif (z <= 3.9e-231)
		tmp = y;
	elseif (z <= 3.6e-172)
		tmp = x;
	elseif (z <= 1.2e-130)
		tmp = y;
	elseif (z <= 64.0)
		tmp = x;
	else
		tmp = Float64(y * z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (z <= -310.0)
		tmp = y * z;
	elseif (z <= -9.7e-195)
		tmp = y;
	elseif (z <= -2.75e-260)
		tmp = x;
	elseif (z <= 3.9e-231)
		tmp = y;
	elseif (z <= 3.6e-172)
		tmp = x;
	elseif (z <= 1.2e-130)
		tmp = y;
	elseif (z <= 64.0)
		tmp = x;
	else
		tmp = y * z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[z, -310.0], N[(y * z), $MachinePrecision], If[LessEqual[z, -9.7e-195], y, If[LessEqual[z, -2.75e-260], x, If[LessEqual[z, 3.9e-231], y, If[LessEqual[z, 3.6e-172], x, If[LessEqual[z, 1.2e-130], y, If[LessEqual[z, 64.0], x, N[(y * z), $MachinePrecision]]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;z \leq -9.7 \cdot 10^{-195}:\\
\;\;\;\;y\\

\mathbf{elif}\;z \leq -2.75 \cdot 10^{-260}:\\
\;\;\;\;x\\

\mathbf{elif}\;z \leq 3.9 \cdot 10^{-231}:\\
\;\;\;\;y\\

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

\mathbf{elif}\;z \leq 1.2 \cdot 10^{-130}:\\
\;\;\;\;y\\

\mathbf{elif}\;z \leq 64:\\
\;\;\;\;x\\

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


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

    1. Initial program 100.0%

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

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

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

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

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

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

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

    if -310 < z < -9.70000000000000019e-195 or -2.75000000000000012e-260 < z < 3.8999999999999998e-231 or 3.60000000000000015e-172 < z < 1.19999999999999998e-130

    1. Initial program 100.0%

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

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

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

    if -9.70000000000000019e-195 < z < -2.75000000000000012e-260 or 3.8999999999999998e-231 < z < 3.60000000000000015e-172 or 1.19999999999999998e-130 < z < 64

    1. Initial program 100.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -310:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -9.7 \cdot 10^{-195}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq -2.75 \cdot 10^{-260}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 3.9 \cdot 10^{-231}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 3.6 \cdot 10^{-172}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.2 \cdot 10^{-130}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 64:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]

Alternative 3: 62.8% accurate, 0.6× speedup?

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

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

\mathbf{elif}\;y \leq 8.2 \cdot 10^{-58} \lor \neg \left(y \leq 4.5 \cdot 10^{+23}\right):\\
\;\;\;\;y \cdot \left(z + 1\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < 1.3e-138

    1. Initial program 100.0%

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

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

    if 1.3e-138 < y < 8.20000000000000056e-58 or 4.49999999999999979e23 < y

    1. Initial program 100.0%

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

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

    if 8.20000000000000056e-58 < y < 4.49999999999999979e23

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 1.3 \cdot 10^{-138}:\\ \;\;\;\;x \cdot \left(z + 1\right)\\ \mathbf{elif}\;y \leq 8.2 \cdot 10^{-58} \lor \neg \left(y \leq 4.5 \cdot 10^{+23}\right):\\ \;\;\;\;y \cdot \left(z + 1\right)\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]

Alternative 4: 74.9% accurate, 0.8× speedup?

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

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

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


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

    1. Initial program 100.0%

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

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

    if -2.40000000000000005e-16 < z < 36

    1. Initial program 100.0%

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

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

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

Alternative 5: 97.8% 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 95.5%

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

    if -1 < z < 1

    1. Initial program 100.0%

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

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

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

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 6.5 \cdot 10^{-52}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 3500000:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 6.8 \cdot 10^{+52}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y 6.5e-52) x (if (<= y 3500000.0) y (if (<= y 6.8e+52) x y))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= 6.5e-52) {
		tmp = x;
	} else if (y <= 3500000.0) {
		tmp = y;
	} else if (y <= 6.8e+52) {
		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 (y <= 6.5d-52) then
        tmp = x
    else if (y <= 3500000.0d0) then
        tmp = y
    else if (y <= 6.8d+52) 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 (y <= 6.5e-52) {
		tmp = x;
	} else if (y <= 3500000.0) {
		tmp = y;
	} else if (y <= 6.8e+52) {
		tmp = x;
	} else {
		tmp = y;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= 6.5e-52:
		tmp = x
	elif y <= 3500000.0:
		tmp = y
	elif y <= 6.8e+52:
		tmp = x
	else:
		tmp = y
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= 6.5e-52)
		tmp = x;
	elseif (y <= 3500000.0)
		tmp = y;
	elseif (y <= 6.8e+52)
		tmp = x;
	else
		tmp = y;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= 6.5e-52)
		tmp = x;
	elseif (y <= 3500000.0)
		tmp = y;
	elseif (y <= 6.8e+52)
		tmp = x;
	else
		tmp = y;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, 6.5e-52], x, If[LessEqual[y, 3500000.0], y, If[LessEqual[y, 6.8e+52], x, y]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq 6.5 \cdot 10^{-52}:\\
\;\;\;\;x\\

\mathbf{elif}\;y \leq 3500000:\\
\;\;\;\;y\\

\mathbf{elif}\;y \leq 6.8 \cdot 10^{+52}:\\
\;\;\;\;x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 6.5e-52 or 3.5e6 < y < 6.8e52

    1. Initial program 100.0%

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

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

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

    if 6.5e-52 < y < 3.5e6 or 6.8e52 < y

    1. Initial program 100.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 6.5 \cdot 10^{-52}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 3500000:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 6.8 \cdot 10^{+52}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]

Alternative 7: 74.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -1:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 115:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= z -1.0) (* y z) (if (<= z 115.0) (+ x y) (* y z))))
double code(double x, double y, double z) {
	double tmp;
	if (z <= -1.0) {
		tmp = y * z;
	} else if (z <= 115.0) {
		tmp = x + 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 <= 115.0d0) then
        tmp = x + 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 <= 115.0) {
		tmp = x + y;
	} else {
		tmp = y * z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if z <= -1.0:
		tmp = y * z
	elif z <= 115.0:
		tmp = x + 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 <= 115.0)
		tmp = Float64(x + 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 <= 115.0)
		tmp = x + 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, 115.0], N[(x + y), $MachinePrecision], N[(y * z), $MachinePrecision]]]
\begin{array}{l}

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

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

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


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

    1. Initial program 100.0%

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

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

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

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

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

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

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

    if -1 < z < 115

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 115:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \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 54.6%

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

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

    \[\leadsto x \]

Reproduce

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