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

Percentage Accurate: 100.0% → 100.0%
Time: 6.5s
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, 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: 49.6% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -4.9 \cdot 10^{+117}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -1.7 \cdot 10^{+70}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq -1:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -7.4 \cdot 10^{-69}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -7.2 \cdot 10^{-112}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq -2.2 \cdot 10^{-201}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 0.0165:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 8.2 \cdot 10^{+138}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= z -4.9e+117)
   (* y z)
   (if (<= z -1.7e+70)
     (* x z)
     (if (<= z -1.0)
       (* y z)
       (if (<= z -7.4e-69)
         x
         (if (<= z -7.2e-112)
           y
           (if (<= z -2.2e-201)
             x
             (if (<= z 0.0165) y (if (<= z 8.2e+138) (* y z) (* x z))))))))))
double code(double x, double y, double z) {
	double tmp;
	if (z <= -4.9e+117) {
		tmp = y * z;
	} else if (z <= -1.7e+70) {
		tmp = x * z;
	} else if (z <= -1.0) {
		tmp = y * z;
	} else if (z <= -7.4e-69) {
		tmp = x;
	} else if (z <= -7.2e-112) {
		tmp = y;
	} else if (z <= -2.2e-201) {
		tmp = x;
	} else if (z <= 0.0165) {
		tmp = y;
	} else if (z <= 8.2e+138) {
		tmp = y * z;
	} else {
		tmp = x * z;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (z <= (-4.9d+117)) then
        tmp = y * z
    else if (z <= (-1.7d+70)) then
        tmp = x * z
    else if (z <= (-1.0d0)) then
        tmp = y * z
    else if (z <= (-7.4d-69)) then
        tmp = x
    else if (z <= (-7.2d-112)) then
        tmp = y
    else if (z <= (-2.2d-201)) then
        tmp = x
    else if (z <= 0.0165d0) then
        tmp = y
    else if (z <= 8.2d+138) then
        tmp = y * z
    else
        tmp = x * z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (z <= -4.9e+117) {
		tmp = y * z;
	} else if (z <= -1.7e+70) {
		tmp = x * z;
	} else if (z <= -1.0) {
		tmp = y * z;
	} else if (z <= -7.4e-69) {
		tmp = x;
	} else if (z <= -7.2e-112) {
		tmp = y;
	} else if (z <= -2.2e-201) {
		tmp = x;
	} else if (z <= 0.0165) {
		tmp = y;
	} else if (z <= 8.2e+138) {
		tmp = y * z;
	} else {
		tmp = x * z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if z <= -4.9e+117:
		tmp = y * z
	elif z <= -1.7e+70:
		tmp = x * z
	elif z <= -1.0:
		tmp = y * z
	elif z <= -7.4e-69:
		tmp = x
	elif z <= -7.2e-112:
		tmp = y
	elif z <= -2.2e-201:
		tmp = x
	elif z <= 0.0165:
		tmp = y
	elif z <= 8.2e+138:
		tmp = y * z
	else:
		tmp = x * z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (z <= -4.9e+117)
		tmp = Float64(y * z);
	elseif (z <= -1.7e+70)
		tmp = Float64(x * z);
	elseif (z <= -1.0)
		tmp = Float64(y * z);
	elseif (z <= -7.4e-69)
		tmp = x;
	elseif (z <= -7.2e-112)
		tmp = y;
	elseif (z <= -2.2e-201)
		tmp = x;
	elseif (z <= 0.0165)
		tmp = y;
	elseif (z <= 8.2e+138)
		tmp = Float64(y * z);
	else
		tmp = Float64(x * z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (z <= -4.9e+117)
		tmp = y * z;
	elseif (z <= -1.7e+70)
		tmp = x * z;
	elseif (z <= -1.0)
		tmp = y * z;
	elseif (z <= -7.4e-69)
		tmp = x;
	elseif (z <= -7.2e-112)
		tmp = y;
	elseif (z <= -2.2e-201)
		tmp = x;
	elseif (z <= 0.0165)
		tmp = y;
	elseif (z <= 8.2e+138)
		tmp = y * z;
	else
		tmp = x * z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[z, -4.9e+117], N[(y * z), $MachinePrecision], If[LessEqual[z, -1.7e+70], N[(x * z), $MachinePrecision], If[LessEqual[z, -1.0], N[(y * z), $MachinePrecision], If[LessEqual[z, -7.4e-69], x, If[LessEqual[z, -7.2e-112], y, If[LessEqual[z, -2.2e-201], x, If[LessEqual[z, 0.0165], y, If[LessEqual[z, 8.2e+138], N[(y * z), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.9 \cdot 10^{+117}:\\
\;\;\;\;y \cdot z\\

\mathbf{elif}\;z \leq -1.7 \cdot 10^{+70}:\\
\;\;\;\;x \cdot z\\

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

\mathbf{elif}\;z \leq -7.4 \cdot 10^{-69}:\\
\;\;\;\;x\\

\mathbf{elif}\;z \leq -7.2 \cdot 10^{-112}:\\
\;\;\;\;y\\

\mathbf{elif}\;z \leq -2.2 \cdot 10^{-201}:\\
\;\;\;\;x\\

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

\mathbf{elif}\;z \leq 8.2 \cdot 10^{+138}:\\
\;\;\;\;y \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if z < -4.9000000000000001e117 or -1.7e70 < z < -1 or 0.016500000000000001 < z < 8.19999999999999961e138

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

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

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

    if -4.9000000000000001e117 < z < -1.7e70 or 8.19999999999999961e138 < 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 100.0%

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

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

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

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

    if -1 < z < -7.4000000000000005e-69 or -7.2000000000000002e-112 < z < -2.2e-201

    1. Initial program 100.0%

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

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

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

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

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

    if -7.4000000000000005e-69 < z < -7.2000000000000002e-112 or -2.2e-201 < z < 0.016500000000000001

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -4.9 \cdot 10^{+117}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -1.7 \cdot 10^{+70}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq -1:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -7.4 \cdot 10^{-69}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -7.2 \cdot 10^{-112}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq -2.2 \cdot 10^{-201}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 0.0165:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 8.2 \cdot 10^{+138}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 50.0% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -1:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -7.4 \cdot 10^{-69}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -1.1 \cdot 10^{-109}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq -1.9 \cdot 10^{-198}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 2.6 \cdot 10^{-227}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 2.8 \cdot 10^{-198}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 0.0165:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= z -1.0)
   (* y z)
   (if (<= z -7.4e-69)
     x
     (if (<= z -1.1e-109)
       y
       (if (<= z -1.9e-198)
         x
         (if (<= z 2.6e-227)
           y
           (if (<= z 2.8e-198) x (if (<= z 0.0165) y (* y z)))))))))
double code(double x, double y, double z) {
	double tmp;
	if (z <= -1.0) {
		tmp = y * z;
	} else if (z <= -7.4e-69) {
		tmp = x;
	} else if (z <= -1.1e-109) {
		tmp = y;
	} else if (z <= -1.9e-198) {
		tmp = x;
	} else if (z <= 2.6e-227) {
		tmp = y;
	} else if (z <= 2.8e-198) {
		tmp = x;
	} else if (z <= 0.0165) {
		tmp = y;
	} else {
		tmp = y * z;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (z <= (-1.0d0)) then
        tmp = y * z
    else if (z <= (-7.4d-69)) then
        tmp = x
    else if (z <= (-1.1d-109)) then
        tmp = y
    else if (z <= (-1.9d-198)) then
        tmp = x
    else if (z <= 2.6d-227) then
        tmp = y
    else if (z <= 2.8d-198) then
        tmp = x
    else if (z <= 0.0165d0) then
        tmp = y
    else
        tmp = y * z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (z <= -1.0) {
		tmp = y * z;
	} else if (z <= -7.4e-69) {
		tmp = x;
	} else if (z <= -1.1e-109) {
		tmp = y;
	} else if (z <= -1.9e-198) {
		tmp = x;
	} else if (z <= 2.6e-227) {
		tmp = y;
	} else if (z <= 2.8e-198) {
		tmp = x;
	} else if (z <= 0.0165) {
		tmp = y;
	} else {
		tmp = y * z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if z <= -1.0:
		tmp = y * z
	elif z <= -7.4e-69:
		tmp = x
	elif z <= -1.1e-109:
		tmp = y
	elif z <= -1.9e-198:
		tmp = x
	elif z <= 2.6e-227:
		tmp = y
	elif z <= 2.8e-198:
		tmp = x
	elif z <= 0.0165:
		tmp = y
	else:
		tmp = y * z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (z <= -1.0)
		tmp = Float64(y * z);
	elseif (z <= -7.4e-69)
		tmp = x;
	elseif (z <= -1.1e-109)
		tmp = y;
	elseif (z <= -1.9e-198)
		tmp = x;
	elseif (z <= 2.6e-227)
		tmp = y;
	elseif (z <= 2.8e-198)
		tmp = x;
	elseif (z <= 0.0165)
		tmp = y;
	else
		tmp = Float64(y * z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (z <= -1.0)
		tmp = y * z;
	elseif (z <= -7.4e-69)
		tmp = x;
	elseif (z <= -1.1e-109)
		tmp = y;
	elseif (z <= -1.9e-198)
		tmp = x;
	elseif (z <= 2.6e-227)
		tmp = y;
	elseif (z <= 2.8e-198)
		tmp = x;
	elseif (z <= 0.0165)
		tmp = y;
	else
		tmp = y * z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[z, -1.0], N[(y * z), $MachinePrecision], If[LessEqual[z, -7.4e-69], x, If[LessEqual[z, -1.1e-109], y, If[LessEqual[z, -1.9e-198], x, If[LessEqual[z, 2.6e-227], y, If[LessEqual[z, 2.8e-198], x, If[LessEqual[z, 0.0165], y, N[(y * z), $MachinePrecision]]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;z \leq -7.4 \cdot 10^{-69}:\\
\;\;\;\;x\\

\mathbf{elif}\;z \leq -1.1 \cdot 10^{-109}:\\
\;\;\;\;y\\

\mathbf{elif}\;z \leq -1.9 \cdot 10^{-198}:\\
\;\;\;\;x\\

\mathbf{elif}\;z \leq 2.6 \cdot 10^{-227}:\\
\;\;\;\;y\\

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

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

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


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

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

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

    if -1 < z < -7.4000000000000005e-69 or -1.1e-109 < z < -1.9000000000000001e-198 or 2.60000000000000011e-227 < z < 2.7999999999999999e-198

    1. Initial program 100.0%

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

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

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

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

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

    if -7.4000000000000005e-69 < z < -1.1e-109 or -1.9000000000000001e-198 < z < 2.60000000000000011e-227 or 2.7999999999999999e-198 < z < 0.016500000000000001

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

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

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

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

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

Alternative 4: 74.4% accurate, 0.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z + 1 \leq -2 \cdot 10^{+118}:\\
\;\;\;\;y \cdot z\\

\mathbf{elif}\;z + 1 \leq -2 \cdot 10^{+70}:\\
\;\;\;\;x \cdot z\\

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

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

\mathbf{elif}\;z + 1 \leq 4 \cdot 10^{+138}:\\
\;\;\;\;y \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (+.f64 z #s(literal 1 binary64)) < -1.99999999999999993e118 or -2.00000000000000015e70 < (+.f64 z #s(literal 1 binary64)) < -5e3 or 1e13 < (+.f64 z #s(literal 1 binary64)) < 4.0000000000000001e138

    1. Initial program 100.0%

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

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

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

    if -1.99999999999999993e118 < (+.f64 z #s(literal 1 binary64)) < -2.00000000000000015e70 or 4.0000000000000001e138 < (+.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 100.0%

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

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

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

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

    if -5e3 < (+.f64 z #s(literal 1 binary64)) < 1e13

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z + 1 \leq -2 \cdot 10^{+118}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z + 1 \leq -2 \cdot 10^{+70}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z + 1 \leq -5000:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z + 1 \leq 10000000000000:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z + 1 \leq 4 \cdot 10^{+138}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 51.8% accurate, 0.6× speedup?

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

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

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


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

    1. Initial program 100.0%

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

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

    if -4.0000000000000001e-224 < (+.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 51.4%

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

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

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

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

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

Alternative 6: 51.8% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x + y \leq -4 \cdot 10^{-224}:\\ \;\;\;\;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) -4e-224) (* x (+ z 1.0)) (* y (+ z 1.0))))
double code(double x, double y, double z) {
	double tmp;
	if ((x + y) <= -4e-224) {
		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) <= (-4d-224)) 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) <= -4e-224) {
		tmp = x * (z + 1.0);
	} else {
		tmp = y * (z + 1.0);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (x + y) <= -4e-224:
		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) <= -4e-224)
		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) <= -4e-224)
		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], -4e-224], 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 -4 \cdot 10^{-224}:\\
\;\;\;\;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) < -4.0000000000000001e-224

    1. Initial program 100.0%

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

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

    if -4.0000000000000001e-224 < (+.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 51.4%

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

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

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

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

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


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

    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 0 37.6%

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

    if 2.29999999999999997e-148 < 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 43.1%

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

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

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

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

Alternative 9: 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. Add Preprocessing
  3. Taylor expanded in z around 0 51.7%

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

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

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

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

Reproduce

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