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

Percentage Accurate: 100.0% → 100.0%
Time: 10.1s
Alternatives: 10
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 10 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, 0.8× speedup?

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

\\
\left(x + y\right) + \left(x + y\right) \cdot z
\end{array}
Derivation
  1. Initial program 100.0%

    \[\left(x + y\right) \cdot \left(z + 1\right) \]
  2. Add Preprocessing
  3. 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 \]
  4. Applied egg-rr100.0%

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

Alternative 2: 51.2% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -43:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -1.3 \cdot 10^{-146}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 2.5 \cdot 10^{-293}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 3.6 \cdot 10^{-185}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 5.4 \cdot 10^{-11}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 2.8 \cdot 10^{+260}:\\ \;\;\;\;x \cdot z\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= z -43.0)
   (* y z)
   (if (<= z -1.3e-146)
     y
     (if (<= z 2.5e-293)
       x
       (if (<= z 3.6e-185)
         y
         (if (<= z 5.4e-11) x (if (<= z 2.8e+260) (* x z) (* y z))))))))
double code(double x, double y, double z) {
	double tmp;
	if (z <= -43.0) {
		tmp = y * z;
	} else if (z <= -1.3e-146) {
		tmp = y;
	} else if (z <= 2.5e-293) {
		tmp = x;
	} else if (z <= 3.6e-185) {
		tmp = y;
	} else if (z <= 5.4e-11) {
		tmp = x;
	} else if (z <= 2.8e+260) {
		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 <= (-43.0d0)) then
        tmp = y * z
    else if (z <= (-1.3d-146)) then
        tmp = y
    else if (z <= 2.5d-293) then
        tmp = x
    else if (z <= 3.6d-185) then
        tmp = y
    else if (z <= 5.4d-11) then
        tmp = x
    else if (z <= 2.8d+260) 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 <= -43.0) {
		tmp = y * z;
	} else if (z <= -1.3e-146) {
		tmp = y;
	} else if (z <= 2.5e-293) {
		tmp = x;
	} else if (z <= 3.6e-185) {
		tmp = y;
	} else if (z <= 5.4e-11) {
		tmp = x;
	} else if (z <= 2.8e+260) {
		tmp = x * z;
	} else {
		tmp = y * z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if z <= -43.0:
		tmp = y * z
	elif z <= -1.3e-146:
		tmp = y
	elif z <= 2.5e-293:
		tmp = x
	elif z <= 3.6e-185:
		tmp = y
	elif z <= 5.4e-11:
		tmp = x
	elif z <= 2.8e+260:
		tmp = x * z
	else:
		tmp = y * z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (z <= -43.0)
		tmp = Float64(y * z);
	elseif (z <= -1.3e-146)
		tmp = y;
	elseif (z <= 2.5e-293)
		tmp = x;
	elseif (z <= 3.6e-185)
		tmp = y;
	elseif (z <= 5.4e-11)
		tmp = x;
	elseif (z <= 2.8e+260)
		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 <= -43.0)
		tmp = y * z;
	elseif (z <= -1.3e-146)
		tmp = y;
	elseif (z <= 2.5e-293)
		tmp = x;
	elseif (z <= 3.6e-185)
		tmp = y;
	elseif (z <= 5.4e-11)
		tmp = x;
	elseif (z <= 2.8e+260)
		tmp = x * z;
	else
		tmp = y * z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[z, -43.0], N[(y * z), $MachinePrecision], If[LessEqual[z, -1.3e-146], y, If[LessEqual[z, 2.5e-293], x, If[LessEqual[z, 3.6e-185], y, If[LessEqual[z, 5.4e-11], x, If[LessEqual[z, 2.8e+260], N[(x * z), $MachinePrecision], N[(y * z), $MachinePrecision]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;z \leq -1.3 \cdot 10^{-146}:\\
\;\;\;\;y\\

\mathbf{elif}\;z \leq 2.5 \cdot 10^{-293}:\\
\;\;\;\;x\\

\mathbf{elif}\;z \leq 3.6 \cdot 10^{-185}:\\
\;\;\;\;y\\

\mathbf{elif}\;z \leq 5.4 \cdot 10^{-11}:\\
\;\;\;\;x\\

\mathbf{elif}\;z \leq 2.8 \cdot 10^{+260}:\\
\;\;\;\;x \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if z < -43 or 2.7999999999999998e260 < 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.3%

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

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

    if -43 < z < -1.29999999999999993e-146 or 2.5000000000000001e-293 < z < 3.5999999999999998e-185

    1. Initial program 100.0%

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

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

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

      \[\leadsto \color{blue}{y + x} \]
    6. Taylor expanded in y around inf 53.7%

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

    if -1.29999999999999993e-146 < z < 2.5000000000000001e-293 or 3.5999999999999998e-185 < z < 5.40000000000000009e-11

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

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

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

      \[\leadsto \color{blue}{y + x} \]
    6. Taylor expanded in y around 0 56.2%

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

    if 5.40000000000000009e-11 < z < 2.7999999999999998e260

    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 \left(x + y\right) \cdot \color{blue}{z} \]
    4. Taylor expanded in x around inf 48.1%

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

        \[\leadsto \color{blue}{z \cdot x} \]
    6. Simplified48.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -43:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -1.3 \cdot 10^{-146}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 2.5 \cdot 10^{-293}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 3.6 \cdot 10^{-185}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 5.4 \cdot 10^{-11}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 2.8 \cdot 10^{+260}:\\ \;\;\;\;x \cdot z\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 50.9% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -43:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -3.95 \cdot 10^{-146}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 2.8 \cdot 10^{-294}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 6.8 \cdot 10^{-182}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 5.4 \cdot 10^{-11}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= z -43.0)
   (* y z)
   (if (<= z -3.95e-146)
     y
     (if (<= z 2.8e-294)
       x
       (if (<= z 6.8e-182) y (if (<= z 5.4e-11) x (* y z)))))))
double code(double x, double y, double z) {
	double tmp;
	if (z <= -43.0) {
		tmp = y * z;
	} else if (z <= -3.95e-146) {
		tmp = y;
	} else if (z <= 2.8e-294) {
		tmp = x;
	} else if (z <= 6.8e-182) {
		tmp = y;
	} else if (z <= 5.4e-11) {
		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 <= (-43.0d0)) then
        tmp = y * z
    else if (z <= (-3.95d-146)) then
        tmp = y
    else if (z <= 2.8d-294) then
        tmp = x
    else if (z <= 6.8d-182) then
        tmp = y
    else if (z <= 5.4d-11) 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 <= -43.0) {
		tmp = y * z;
	} else if (z <= -3.95e-146) {
		tmp = y;
	} else if (z <= 2.8e-294) {
		tmp = x;
	} else if (z <= 6.8e-182) {
		tmp = y;
	} else if (z <= 5.4e-11) {
		tmp = x;
	} else {
		tmp = y * z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if z <= -43.0:
		tmp = y * z
	elif z <= -3.95e-146:
		tmp = y
	elif z <= 2.8e-294:
		tmp = x
	elif z <= 6.8e-182:
		tmp = y
	elif z <= 5.4e-11:
		tmp = x
	else:
		tmp = y * z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (z <= -43.0)
		tmp = Float64(y * z);
	elseif (z <= -3.95e-146)
		tmp = y;
	elseif (z <= 2.8e-294)
		tmp = x;
	elseif (z <= 6.8e-182)
		tmp = y;
	elseif (z <= 5.4e-11)
		tmp = x;
	else
		tmp = Float64(y * z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (z <= -43.0)
		tmp = y * z;
	elseif (z <= -3.95e-146)
		tmp = y;
	elseif (z <= 2.8e-294)
		tmp = x;
	elseif (z <= 6.8e-182)
		tmp = y;
	elseif (z <= 5.4e-11)
		tmp = x;
	else
		tmp = y * z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[z, -43.0], N[(y * z), $MachinePrecision], If[LessEqual[z, -3.95e-146], y, If[LessEqual[z, 2.8e-294], x, If[LessEqual[z, 6.8e-182], y, If[LessEqual[z, 5.4e-11], x, N[(y * z), $MachinePrecision]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;z \leq -3.95 \cdot 10^{-146}:\\
\;\;\;\;y\\

\mathbf{elif}\;z \leq 2.8 \cdot 10^{-294}:\\
\;\;\;\;x\\

\mathbf{elif}\;z \leq 6.8 \cdot 10^{-182}:\\
\;\;\;\;y\\

\mathbf{elif}\;z \leq 5.4 \cdot 10^{-11}:\\
\;\;\;\;x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -43 or 5.40000000000000009e-11 < 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.8%

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

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

    if -43 < z < -3.95000000000000006e-146 or 2.79999999999999991e-294 < z < 6.79999999999999979e-182

    1. Initial program 100.0%

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

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

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

      \[\leadsto \color{blue}{y + x} \]
    6. Taylor expanded in y around inf 53.7%

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

    if -3.95000000000000006e-146 < z < 2.79999999999999991e-294 or 6.79999999999999979e-182 < z < 5.40000000000000009e-11

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

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

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

      \[\leadsto \color{blue}{y + x} \]
    6. Taylor expanded in y around 0 56.2%

      \[\leadsto \color{blue}{x} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 4: 75.2% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z + 1 \leq -40:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z + 1 \leq 100:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z + 1 \leq 10^{+260}:\\ \;\;\;\;x \cdot \left(z + 1\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= (+ z 1.0) -40.0)
   (* y z)
   (if (<= (+ z 1.0) 100.0)
     (+ x y)
     (if (<= (+ z 1.0) 1e+260) (* x (+ z 1.0)) (* y z)))))
double code(double x, double y, double z) {
	double tmp;
	if ((z + 1.0) <= -40.0) {
		tmp = y * z;
	} else if ((z + 1.0) <= 100.0) {
		tmp = x + y;
	} else if ((z + 1.0) <= 1e+260) {
		tmp = x * (z + 1.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) :: tmp
    if ((z + 1.0d0) <= (-40.0d0)) then
        tmp = y * z
    else if ((z + 1.0d0) <= 100.0d0) then
        tmp = x + y
    else if ((z + 1.0d0) <= 1d+260) then
        tmp = x * (z + 1.0d0)
    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) <= -40.0) {
		tmp = y * z;
	} else if ((z + 1.0) <= 100.0) {
		tmp = x + y;
	} else if ((z + 1.0) <= 1e+260) {
		tmp = x * (z + 1.0);
	} else {
		tmp = y * z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (z + 1.0) <= -40.0:
		tmp = y * z
	elif (z + 1.0) <= 100.0:
		tmp = x + y
	elif (z + 1.0) <= 1e+260:
		tmp = x * (z + 1.0)
	else:
		tmp = y * z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (Float64(z + 1.0) <= -40.0)
		tmp = Float64(y * z);
	elseif (Float64(z + 1.0) <= 100.0)
		tmp = Float64(x + y);
	elseif (Float64(z + 1.0) <= 1e+260)
		tmp = Float64(x * Float64(z + 1.0));
	else
		tmp = Float64(y * z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((z + 1.0) <= -40.0)
		tmp = y * z;
	elseif ((z + 1.0) <= 100.0)
		tmp = x + y;
	elseif ((z + 1.0) <= 1e+260)
		tmp = x * (z + 1.0);
	else
		tmp = y * z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[N[(z + 1.0), $MachinePrecision], -40.0], N[(y * z), $MachinePrecision], If[LessEqual[N[(z + 1.0), $MachinePrecision], 100.0], N[(x + y), $MachinePrecision], If[LessEqual[N[(z + 1.0), $MachinePrecision], 1e+260], N[(x * N[(z + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;z + 1 \leq 10^{+260}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (+.f64 z #s(literal 1 binary64)) < -40 or 1.00000000000000007e260 < (+.f64 z #s(literal 1 binary64))

    1. Initial program 100.0%

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

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

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

    if -40 < (+.f64 z #s(literal 1 binary64)) < 100

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

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

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

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

    if 100 < (+.f64 z #s(literal 1 binary64)) < 1.00000000000000007e260

    1. Initial program 100.0%

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

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

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

Alternative 5: 75.0% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -1:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 480:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq 1.15 \cdot 10^{+260}:\\ \;\;\;\;x \cdot z\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= z -1.0)
   (* y z)
   (if (<= z 480.0) (+ x y) (if (<= z 1.15e+260) (* x z) (* y z)))))
double code(double x, double y, double z) {
	double tmp;
	if (z <= -1.0) {
		tmp = y * z;
	} else if (z <= 480.0) {
		tmp = x + y;
	} else if (z <= 1.15e+260) {
		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 = y * z
    else if (z <= 480.0d0) then
        tmp = x + y
    else if (z <= 1.15d+260) 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 = y * z;
	} else if (z <= 480.0) {
		tmp = x + y;
	} else if (z <= 1.15e+260) {
		tmp = x * z;
	} else {
		tmp = y * z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if z <= -1.0:
		tmp = y * z
	elif z <= 480.0:
		tmp = x + y
	elif z <= 1.15e+260:
		tmp = x * z
	else:
		tmp = y * z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (z <= -1.0)
		tmp = Float64(y * z);
	elseif (z <= 480.0)
		tmp = Float64(x + y);
	elseif (z <= 1.15e+260)
		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 = y * z;
	elseif (z <= 480.0)
		tmp = x + y;
	elseif (z <= 1.15e+260)
		tmp = x * z;
	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, 480.0], N[(x + y), $MachinePrecision], If[LessEqual[z, 1.15e+260], N[(x * z), $MachinePrecision], N[(y * z), $MachinePrecision]]]]
\begin{array}{l}

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -1 or 1.15000000000000005e260 < 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 95.3%

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

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

    if -1 < z < 480

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

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

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

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

    if 480 < z < 1.15000000000000005e260

    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 \left(x + y\right) \cdot \color{blue}{z} \]
    4. Taylor expanded in x around inf 49.3%

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

        \[\leadsto \color{blue}{z \cdot x} \]
    6. Simplified49.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 480:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq 1.15 \cdot 10^{+260}:\\ \;\;\;\;x \cdot z\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 52.5% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x + y \leq -5 \cdot 10^{-297}:\\
\;\;\;\;x + x \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (+.f64 x y) < -5e-297

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

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

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

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

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

    if -5e-297 < (+.f64 x 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 56.8%

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

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

Alternative 7: 52.5% accurate, 0.6× speedup?

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

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

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

    if -5e-297 < (+.f64 x 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 56.8%

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

Alternative 8: 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 9: 32.5% accurate, 1.2× speedup?

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

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

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


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

    1. Initial program 100.0%

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

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

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

      \[\leadsto \color{blue}{y + x} \]
    6. Taylor expanded in y around 0 31.7%

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

    if 3.6000000000000001e-19 < y

    1. Initial program 100.0%

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

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

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

      \[\leadsto \color{blue}{y + x} \]
    6. Taylor expanded in y around inf 44.2%

      \[\leadsto \color{blue}{y} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 10: 26.0% 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 z around 0 50.7%

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

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

    \[\leadsto \color{blue}{y + x} \]
  6. Taylor expanded in y around 0 27.0%

    \[\leadsto \color{blue}{x} \]
  7. Add Preprocessing

Reproduce

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