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

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

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \left(z + 1\right)\\ \mathbf{if}\;z + 1 \leq -4 \cdot 10^{+94}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z + 1 \leq 1:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;z + 1 \leq 1.0000002:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z + 1 \leq 5 \cdot 10^{+68}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;z + 1 \leq 5 \cdot 10^{+256}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* x (+ z 1.0))))
   (if (<= (+ z 1.0) -4e+94)
     (* y z)
     (if (<= (+ z 1.0) 1.0)
       t_0
       (if (<= (+ z 1.0) 1.0000002)
         (+ x y)
         (if (<= (+ z 1.0) 5e+68)
           t_0
           (if (<= (+ z 1.0) 5e+256) (* y z) (* x z))))))))
double code(double x, double y, double z) {
	double t_0 = x * (z + 1.0);
	double tmp;
	if ((z + 1.0) <= -4e+94) {
		tmp = y * z;
	} else if ((z + 1.0) <= 1.0) {
		tmp = t_0;
	} else if ((z + 1.0) <= 1.0000002) {
		tmp = x + y;
	} else if ((z + 1.0) <= 5e+68) {
		tmp = t_0;
	} else if ((z + 1.0) <= 5e+256) {
		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) :: t_0
    real(8) :: tmp
    t_0 = x * (z + 1.0d0)
    if ((z + 1.0d0) <= (-4d+94)) then
        tmp = y * z
    else if ((z + 1.0d0) <= 1.0d0) then
        tmp = t_0
    else if ((z + 1.0d0) <= 1.0000002d0) then
        tmp = x + y
    else if ((z + 1.0d0) <= 5d+68) then
        tmp = t_0
    else if ((z + 1.0d0) <= 5d+256) 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 t_0 = x * (z + 1.0);
	double tmp;
	if ((z + 1.0) <= -4e+94) {
		tmp = y * z;
	} else if ((z + 1.0) <= 1.0) {
		tmp = t_0;
	} else if ((z + 1.0) <= 1.0000002) {
		tmp = x + y;
	} else if ((z + 1.0) <= 5e+68) {
		tmp = t_0;
	} else if ((z + 1.0) <= 5e+256) {
		tmp = y * z;
	} else {
		tmp = x * z;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = x * (z + 1.0)
	tmp = 0
	if (z + 1.0) <= -4e+94:
		tmp = y * z
	elif (z + 1.0) <= 1.0:
		tmp = t_0
	elif (z + 1.0) <= 1.0000002:
		tmp = x + y
	elif (z + 1.0) <= 5e+68:
		tmp = t_0
	elif (z + 1.0) <= 5e+256:
		tmp = y * z
	else:
		tmp = x * z
	return tmp
function code(x, y, z)
	t_0 = Float64(x * Float64(z + 1.0))
	tmp = 0.0
	if (Float64(z + 1.0) <= -4e+94)
		tmp = Float64(y * z);
	elseif (Float64(z + 1.0) <= 1.0)
		tmp = t_0;
	elseif (Float64(z + 1.0) <= 1.0000002)
		tmp = Float64(x + y);
	elseif (Float64(z + 1.0) <= 5e+68)
		tmp = t_0;
	elseif (Float64(z + 1.0) <= 5e+256)
		tmp = Float64(y * z);
	else
		tmp = Float64(x * z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = x * (z + 1.0);
	tmp = 0.0;
	if ((z + 1.0) <= -4e+94)
		tmp = y * z;
	elseif ((z + 1.0) <= 1.0)
		tmp = t_0;
	elseif ((z + 1.0) <= 1.0000002)
		tmp = x + y;
	elseif ((z + 1.0) <= 5e+68)
		tmp = t_0;
	elseif ((z + 1.0) <= 5e+256)
		tmp = y * z;
	else
		tmp = x * z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(z + 1.0), $MachinePrecision], -4e+94], N[(y * z), $MachinePrecision], If[LessEqual[N[(z + 1.0), $MachinePrecision], 1.0], t$95$0, If[LessEqual[N[(z + 1.0), $MachinePrecision], 1.0000002], N[(x + y), $MachinePrecision], If[LessEqual[N[(z + 1.0), $MachinePrecision], 5e+68], t$95$0, If[LessEqual[N[(z + 1.0), $MachinePrecision], 5e+256], N[(y * z), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;z + 1 \leq 1:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;z + 1 \leq 5 \cdot 10^{+68}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;z + 1 \leq 5 \cdot 10^{+256}:\\
\;\;\;\;y \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (+.f64 z #s(literal 1 binary64)) < -4.0000000000000001e94 or 5.0000000000000004e68 < (+.f64 z #s(literal 1 binary64)) < 5.00000000000000015e256

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

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

    if -4.0000000000000001e94 < (+.f64 z #s(literal 1 binary64)) < 1 or 1.00000019999999989 < (+.f64 z #s(literal 1 binary64)) < 5.0000000000000004e68

    1. Initial program 100.0%

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

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

    if 1 < (+.f64 z #s(literal 1 binary64)) < 1.00000019999999989

    1. Initial program 100.0%

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

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

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

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

    if 5.00000000000000015e256 < (+.f64 z #s(literal 1 binary64))

    1. Initial program 99.8%

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

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

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

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

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

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

Alternative 3: 51.4% accurate, 0.2× speedup?

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

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

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

\mathbf{elif}\;z \leq 4.6 \cdot 10^{-113}:\\
\;\;\;\;y\\

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

\mathbf{elif}\;z \leq 4.1 \cdot 10^{+256}:\\
\;\;\;\;y \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if z < -9.4999999999999991e93 or 1.45e7 < z < 4.10000000000000006e256

    1. Initial program 100.0%

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

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

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

    if -9.4999999999999991e93 < z < -1 or 4.10000000000000006e256 < 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.1%

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

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

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

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

    if -1 < z < 4.60000000000000016e-113

    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} \]
    6. Taylor expanded in y around inf 46.3%

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

    if 4.60000000000000016e-113 < z < 1.45e7

    1. Initial program 99.9%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -9.5 \cdot 10^{+93}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -1:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq 4.6 \cdot 10^{-113}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 14500000:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 4.1 \cdot 10^{+256}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 74.2% accurate, 0.3× speedup?

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

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

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

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

\mathbf{elif}\;z \leq 7 \cdot 10^{+256}:\\
\;\;\;\;y \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -1.10000000000000006e94 or 1.45e7 < z < 6.9999999999999995e256

    1. Initial program 100.0%

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

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

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

    if -1.10000000000000006e94 < z < -1 or 6.9999999999999995e256 < 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.1%

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

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

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

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

    if -1 < z < 1.45e7

    1. Initial program 100.0%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.1 \cdot 10^{+94}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -1:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq 14500000:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq 7 \cdot 10^{+256}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 51.6% accurate, 0.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.6 \cdot 10^{-16}:\\
\;\;\;\;y \cdot z\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -1.60000000000000011e-16 or 1.45e7 < 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 51.8%

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

    if -1.60000000000000011e-16 < z < 1.9999999999999999e-112

    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 inf 47.4%

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

    if 1.9999999999999999e-112 < z < 1.45e7

    1. Initial program 99.9%

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

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

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

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

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

Alternative 6: 52.3% accurate, 0.6× speedup?

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

    1. Initial program 100.0%

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

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

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

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

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

    if -1.00000000000000002e-287 < (+.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.7%

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

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

Alternative 7: 52.3% accurate, 0.6× speedup?

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

    1. Initial program 100.0%

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

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

    if -1.00000000000000002e-287 < (+.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.7%

      \[\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: 31.6% 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 47.4%

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

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

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

      \[\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 46.8%

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

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

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

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

Alternative 10: 24.9% 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 47.3%

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

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

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

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

Reproduce

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