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

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

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

Alternative 2: 50.8% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -6:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq 1.8 \cdot 10^{-124}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 2 \cdot 10^{-75}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 10000:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 4 \cdot 10^{+77} \lor \neg \left(z \leq 1.03 \cdot 10^{+130}\right):\\ \;\;\;\;x \cdot z\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= z -6.0)
   (* x z)
   (if (<= z 1.8e-124)
     x
     (if (<= z 2e-75)
       y
       (if (<= z 10000.0)
         x
         (if (or (<= z 4e+77) (not (<= z 1.03e+130))) (* x z) (* y z)))))))
double code(double x, double y, double z) {
	double tmp;
	if (z <= -6.0) {
		tmp = x * z;
	} else if (z <= 1.8e-124) {
		tmp = x;
	} else if (z <= 2e-75) {
		tmp = y;
	} else if (z <= 10000.0) {
		tmp = x;
	} else if ((z <= 4e+77) || !(z <= 1.03e+130)) {
		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 (z <= (-6.0d0)) then
        tmp = x * z
    else if (z <= 1.8d-124) then
        tmp = x
    else if (z <= 2d-75) then
        tmp = y
    else if (z <= 10000.0d0) then
        tmp = x
    else if ((z <= 4d+77) .or. (.not. (z <= 1.03d+130))) 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 (z <= -6.0) {
		tmp = x * z;
	} else if (z <= 1.8e-124) {
		tmp = x;
	} else if (z <= 2e-75) {
		tmp = y;
	} else if (z <= 10000.0) {
		tmp = x;
	} else if ((z <= 4e+77) || !(z <= 1.03e+130)) {
		tmp = x * z;
	} else {
		tmp = y * z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if z <= -6.0:
		tmp = x * z
	elif z <= 1.8e-124:
		tmp = x
	elif z <= 2e-75:
		tmp = y
	elif z <= 10000.0:
		tmp = x
	elif (z <= 4e+77) or not (z <= 1.03e+130):
		tmp = x * z
	else:
		tmp = y * z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (z <= -6.0)
		tmp = Float64(x * z);
	elseif (z <= 1.8e-124)
		tmp = x;
	elseif (z <= 2e-75)
		tmp = y;
	elseif (z <= 10000.0)
		tmp = x;
	elseif ((z <= 4e+77) || !(z <= 1.03e+130))
		tmp = Float64(x * z);
	else
		tmp = Float64(y * z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (z <= -6.0)
		tmp = x * z;
	elseif (z <= 1.8e-124)
		tmp = x;
	elseif (z <= 2e-75)
		tmp = y;
	elseif (z <= 10000.0)
		tmp = x;
	elseif ((z <= 4e+77) || ~((z <= 1.03e+130)))
		tmp = x * z;
	else
		tmp = y * z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[z, -6.0], N[(x * z), $MachinePrecision], If[LessEqual[z, 1.8e-124], x, If[LessEqual[z, 2e-75], y, If[LessEqual[z, 10000.0], x, If[Or[LessEqual[z, 4e+77], N[Not[LessEqual[z, 1.03e+130]], $MachinePrecision]], N[(x * z), $MachinePrecision], N[(y * z), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -6:\\
\;\;\;\;x \cdot z\\

\mathbf{elif}\;z \leq 1.8 \cdot 10^{-124}:\\
\;\;\;\;x\\

\mathbf{elif}\;z \leq 2 \cdot 10^{-75}:\\
\;\;\;\;y\\

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

\mathbf{elif}\;z \leq 4 \cdot 10^{+77} \lor \neg \left(z \leq 1.03 \cdot 10^{+130}\right):\\
\;\;\;\;x \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if z < -6 or 1e4 < z < 3.99999999999999993e77 or 1.03e130 < z

    1. Initial program 100.0%

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

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

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

        \[\leadsto \color{blue}{x \cdot z + x \cdot 1} \]
      3. *-rgt-identity57.7%

        \[\leadsto x \cdot z + \color{blue}{x} \]
    5. Applied egg-rr57.7%

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

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

    if -6 < z < 1.80000000000000005e-124 or 1.9999999999999999e-75 < z < 1e4

    1. Initial program 100.0%

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

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

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

    if 1.80000000000000005e-124 < z < 1.9999999999999999e-75

    1. Initial program 100.0%

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

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

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

    if 3.99999999999999993e77 < z < 1.03e130

    1. Initial program 100.0%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{z \cdot y} \]
    8. Simplified69.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -6:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq 1.8 \cdot 10^{-124}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 2 \cdot 10^{-75}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 10000:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 4 \cdot 10^{+77} \lor \neg \left(z \leq 1.03 \cdot 10^{+130}\right):\\ \;\;\;\;x \cdot z\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 75.7% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \left(z + 1\right)\\ \mathbf{if}\;z \leq -1.45 \cdot 10^{-9}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 8.5 \cdot 10^{-10}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq 4.1 \cdot 10^{+77} \lor \neg \left(z \leq 5.8 \cdot 10^{+126}\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 -1.45e-9)
     t_0
     (if (<= z 8.5e-10)
       (+ x y)
       (if (or (<= z 4.1e+77) (not (<= z 5.8e+126))) t_0 (* y z))))))
double code(double x, double y, double z) {
	double t_0 = x * (z + 1.0);
	double tmp;
	if (z <= -1.45e-9) {
		tmp = t_0;
	} else if (z <= 8.5e-10) {
		tmp = x + y;
	} else if ((z <= 4.1e+77) || !(z <= 5.8e+126)) {
		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 <= (-1.45d-9)) then
        tmp = t_0
    else if (z <= 8.5d-10) then
        tmp = x + y
    else if ((z <= 4.1d+77) .or. (.not. (z <= 5.8d+126))) 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 <= -1.45e-9) {
		tmp = t_0;
	} else if (z <= 8.5e-10) {
		tmp = x + y;
	} else if ((z <= 4.1e+77) || !(z <= 5.8e+126)) {
		tmp = t_0;
	} else {
		tmp = y * z;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = x * (z + 1.0)
	tmp = 0
	if z <= -1.45e-9:
		tmp = t_0
	elif z <= 8.5e-10:
		tmp = x + y
	elif (z <= 4.1e+77) or not (z <= 5.8e+126):
		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 <= -1.45e-9)
		tmp = t_0;
	elseif (z <= 8.5e-10)
		tmp = Float64(x + y);
	elseif ((z <= 4.1e+77) || !(z <= 5.8e+126))
		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 <= -1.45e-9)
		tmp = t_0;
	elseif (z <= 8.5e-10)
		tmp = x + y;
	elseif ((z <= 4.1e+77) || ~((z <= 5.8e+126)))
		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, -1.45e-9], t$95$0, If[LessEqual[z, 8.5e-10], N[(x + y), $MachinePrecision], If[Or[LessEqual[z, 4.1e+77], N[Not[LessEqual[z, 5.8e+126]], $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 -1.45 \cdot 10^{-9}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;z \leq 4.1 \cdot 10^{+77} \lor \neg \left(z \leq 5.8 \cdot 10^{+126}\right):\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -1.44999999999999996e-9 or 8.4999999999999996e-10 < z < 4.1000000000000001e77 or 5.79999999999999971e126 < z

    1. Initial program 100.0%

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

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

    if -1.44999999999999996e-9 < z < 8.4999999999999996e-10

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

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

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

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

    if 4.1000000000000001e77 < z < 5.79999999999999971e126

    1. Initial program 100.0%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{z \cdot y} \]
    8. Simplified69.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.45 \cdot 10^{-9}:\\ \;\;\;\;x \cdot \left(z + 1\right)\\ \mathbf{elif}\;z \leq 8.5 \cdot 10^{-10}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq 4.1 \cdot 10^{+77} \lor \neg \left(z \leq 5.8 \cdot 10^{+126}\right):\\ \;\;\;\;x \cdot \left(z + 1\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 74.9% accurate, 0.3× speedup?

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

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

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

\mathbf{elif}\;z \leq 4.35 \cdot 10^{+77} \lor \neg \left(z \leq 8.5 \cdot 10^{+133}\right):\\
\;\;\;\;x \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -1 or 1e4 < z < 4.3500000000000003e77 or 8.50000000000000044e133 < z

    1. Initial program 100.0%

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

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

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

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

        \[\leadsto x \cdot z + \color{blue}{x} \]
    5. Applied egg-rr58.5%

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

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

    if -1 < z < 1e4

    1. Initial program 100.0%

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

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

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

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

    if 4.3500000000000003e77 < z < 8.50000000000000044e133

    1. Initial program 100.0%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{z \cdot y} \]
    8. Simplified69.4%

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

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

Alternative 5: 50.5% accurate, 0.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -6:\\
\;\;\;\;x \cdot z\\

\mathbf{elif}\;z \leq 2.25 \cdot 10^{-124}:\\
\;\;\;\;x\\

\mathbf{elif}\;z \leq 3.2 \cdot 10^{-72}:\\
\;\;\;\;y\\

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

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


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

    1. Initial program 100.0%

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

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

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

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

        \[\leadsto x \cdot z + \color{blue}{x} \]
    5. Applied egg-rr54.8%

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

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

    if -6 < z < 2.2499999999999998e-124 or 3.19999999999999999e-72 < z < 1e4

    1. Initial program 100.0%

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

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

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

    if 2.2499999999999998e-124 < z < 3.19999999999999999e-72

    1. Initial program 100.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -6:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq 2.25 \cdot 10^{-124}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 3.2 \cdot 10^{-72}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 10000:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 97.7% 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.0%

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

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

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

    if -1 < z < 1

    1. Initial program 100.0%

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

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

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

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

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

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

    1. Initial program 100.0%

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

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

    if 8.1999999999999995e-63 < y

    1. Initial program 100.0%

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

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

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

Alternative 8: 32.4% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 4500000:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \end{array} \]
(FPCore (x y z) :precision binary64 (if (<= y 4500000.0) x y))
double code(double x, double y, double z) {
	double tmp;
	if (y <= 4500000.0) {
		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 <= 4500000.0d0) 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 <= 4500000.0) {
		tmp = x;
	} else {
		tmp = y;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= 4500000.0:
		tmp = x
	else:
		tmp = y
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= 4500000.0)
		tmp = x;
	else
		tmp = y;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= 4500000.0)
		tmp = x;
	else
		tmp = y;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, 4500000.0], x, y]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq 4500000:\\
\;\;\;\;x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 4.5e6

    1. Initial program 100.0%

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

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

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

    if 4.5e6 < y

    1. Initial program 100.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 4500000:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 26.4% 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. Add Preprocessing
  3. Taylor expanded in x around inf 53.8%

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

    \[\leadsto \color{blue}{x} \]
  5. Final simplification26.9%

    \[\leadsto x \]
  6. Add Preprocessing

Reproduce

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