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

Percentage Accurate: 100.0% → 100.0%
Time: 3.6s
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) + z \cdot \left(x + y\right) \end{array} \]
(FPCore (x y z) :precision binary64 (+ (+ x y) (* z (+ x y))))
double code(double x, double y, double z) {
	return (x + y) + (z * (x + y));
}
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 * (x + y))
end function
public static double code(double x, double y, double z) {
	return (x + y) + (z * (x + y));
}
def code(x, y, z):
	return (x + y) + (z * (x + y))
function code(x, y, z)
	return Float64(Float64(x + y) + Float64(z * Float64(x + y)))
end
function tmp = code(x, y, z)
	tmp = (x + y) + (z * (x + y));
end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] + N[(z * N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

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

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

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

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

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

    \[\leadsto \left(x + y\right) + z \cdot \left(x + y\right) \]

Alternative 2: 50.3% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -0.56:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -3.8 \cdot 10^{-278}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 2.6 \cdot 10^{-265}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 6.4 \cdot 10^{-230}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 1.36 \cdot 10^{-8}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= z -0.56)
   (* y z)
   (if (<= z -3.8e-278)
     y
     (if (<= z 2.6e-265)
       x
       (if (<= z 6.4e-230) y (if (<= z 1.36e-8) x (* y z)))))))
double code(double x, double y, double z) {
	double tmp;
	if (z <= -0.56) {
		tmp = y * z;
	} else if (z <= -3.8e-278) {
		tmp = y;
	} else if (z <= 2.6e-265) {
		tmp = x;
	} else if (z <= 6.4e-230) {
		tmp = y;
	} else if (z <= 1.36e-8) {
		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 <= (-0.56d0)) then
        tmp = y * z
    else if (z <= (-3.8d-278)) then
        tmp = y
    else if (z <= 2.6d-265) then
        tmp = x
    else if (z <= 6.4d-230) then
        tmp = y
    else if (z <= 1.36d-8) 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 <= -0.56) {
		tmp = y * z;
	} else if (z <= -3.8e-278) {
		tmp = y;
	} else if (z <= 2.6e-265) {
		tmp = x;
	} else if (z <= 6.4e-230) {
		tmp = y;
	} else if (z <= 1.36e-8) {
		tmp = x;
	} else {
		tmp = y * z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if z <= -0.56:
		tmp = y * z
	elif z <= -3.8e-278:
		tmp = y
	elif z <= 2.6e-265:
		tmp = x
	elif z <= 6.4e-230:
		tmp = y
	elif z <= 1.36e-8:
		tmp = x
	else:
		tmp = y * z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (z <= -0.56)
		tmp = Float64(y * z);
	elseif (z <= -3.8e-278)
		tmp = y;
	elseif (z <= 2.6e-265)
		tmp = x;
	elseif (z <= 6.4e-230)
		tmp = y;
	elseif (z <= 1.36e-8)
		tmp = x;
	else
		tmp = Float64(y * z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (z <= -0.56)
		tmp = y * z;
	elseif (z <= -3.8e-278)
		tmp = y;
	elseif (z <= 2.6e-265)
		tmp = x;
	elseif (z <= 6.4e-230)
		tmp = y;
	elseif (z <= 1.36e-8)
		tmp = x;
	else
		tmp = y * z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[z, -0.56], N[(y * z), $MachinePrecision], If[LessEqual[z, -3.8e-278], y, If[LessEqual[z, 2.6e-265], x, If[LessEqual[z, 6.4e-230], y, If[LessEqual[z, 1.36e-8], x, N[(y * z), $MachinePrecision]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;z \leq -3.8 \cdot 10^{-278}:\\
\;\;\;\;y\\

\mathbf{elif}\;z \leq 2.6 \cdot 10^{-265}:\\
\;\;\;\;x\\

\mathbf{elif}\;z \leq 6.4 \cdot 10^{-230}:\\
\;\;\;\;y\\

\mathbf{elif}\;z \leq 1.36 \cdot 10^{-8}:\\
\;\;\;\;x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -0.56000000000000005 or 1.3599999999999999e-8 < z

    1. Initial program 100.0%

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

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

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

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

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

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

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

    if -0.56000000000000005 < z < -3.7999999999999999e-278 or 2.6000000000000001e-265 < z < 6.3999999999999999e-230

    1. Initial program 100.0%

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

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

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

    if -3.7999999999999999e-278 < z < 2.6000000000000001e-265 or 6.3999999999999999e-230 < z < 1.3599999999999999e-8

    1. Initial program 100.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -0.56:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -3.8 \cdot 10^{-278}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 2.6 \cdot 10^{-265}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 6.4 \cdot 10^{-230}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 1.36 \cdot 10^{-8}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]

Alternative 3: 50.2% accurate, 0.5× speedup?

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

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

\mathbf{elif}\;z \leq -2.5 \cdot 10^{-278}:\\
\;\;\;\;y\\

\mathbf{elif}\;z \leq 2.6 \cdot 10^{-265}:\\
\;\;\;\;x\\

\mathbf{elif}\;z \leq 6.5 \cdot 10^{-230}:\\
\;\;\;\;y\\

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

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


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

    1. Initial program 100.0%

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

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

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

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

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

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

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

    if -0.56000000000000005 < z < -2.49999999999999992e-278 or 2.6000000000000001e-265 < z < 6.5000000000000004e-230

    1. Initial program 100.0%

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

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

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

    if -2.49999999999999992e-278 < z < 2.6000000000000001e-265 or 6.5000000000000004e-230 < z < 2.15e12

    1. Initial program 99.9%

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

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

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

    if 2.15e12 < z

    1. Initial program 100.0%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -0.56:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -2.5 \cdot 10^{-278}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 2.6 \cdot 10^{-265}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 6.5 \cdot 10^{-230}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 2150000000000:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \]

Alternative 4: 75.4% accurate, 0.6× speedup?

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

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

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

\mathbf{elif}\;z \leq 44000000000000:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -4.6000000000000002e-8 or 1.3599999999999999e-8 < z < 4.4e13

    1. Initial program 100.0%

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

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

    if -4.6000000000000002e-8 < z < 1.3599999999999999e-8

    1. Initial program 100.0%

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

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

    if 4.4e13 < z

    1. Initial program 100.0%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -4.6 \cdot 10^{-8}:\\ \;\;\;\;y \cdot \left(z + 1\right)\\ \mathbf{elif}\;z \leq 1.36 \cdot 10^{-8}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq 44000000000000:\\ \;\;\;\;y \cdot \left(z + 1\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \]

Alternative 5: 97.9% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 1\right):\\ \;\;\;\;z \cdot \left(x + y\right)\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= z -1.0) (not (<= z 1.0))) (* z (+ x y)) (+ x y)))
double code(double x, double y, double z) {
	double tmp;
	if ((z <= -1.0) || !(z <= 1.0)) {
		tmp = z * (x + y);
	} else {
		tmp = x + y;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((z <= (-1.0d0)) .or. (.not. (z <= 1.0d0))) then
        tmp = z * (x + y)
    else
        tmp = x + y
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((z <= -1.0) || !(z <= 1.0)) {
		tmp = z * (x + y);
	} else {
		tmp = x + y;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (z <= -1.0) or not (z <= 1.0):
		tmp = z * (x + y)
	else:
		tmp = x + y
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((z <= -1.0) || !(z <= 1.0))
		tmp = Float64(z * Float64(x + y));
	else
		tmp = Float64(x + y);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((z <= -1.0) || ~((z <= 1.0)))
		tmp = z * (x + y);
	else
		tmp = x + y;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 1.0]], $MachinePrecision]], N[(z * N[(x + y), $MachinePrecision]), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;z \cdot \left(x + y\right)\\

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


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

    1. Initial program 100.0%

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

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

    if -1 < z < 1

    1. Initial program 100.0%

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

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

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

Alternative 6: 74.5% accurate, 1.0× speedup?

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

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

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

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


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

    1. Initial program 100.0%

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

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

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

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

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

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

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

    if -1 < z < 2.15e12

    1. Initial program 100.0%

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

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

    if 2.15e12 < z

    1. Initial program 100.0%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 2150000000000:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \]

Alternative 7: 62.0% accurate, 1.0× speedup?

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

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

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


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

    1. Initial program 100.0%

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

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

    if 7.9999999999999998e-121 < y

    1. Initial program 100.0%

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

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

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

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. Final simplification100.0%

    \[\leadsto \left(x + y\right) \cdot \left(z + 1\right) \]

Alternative 9: 30.9% accurate, 2.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.9 \cdot 10^{-167}:\\
\;\;\;\;x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.89999999999999984e-167

    1. Initial program 99.9%

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

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

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

    if -1.89999999999999984e-167 < x

    1. Initial program 100.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.9 \cdot 10^{-167}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]

Alternative 10: 26.2% accurate, 7.0× speedup?

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

\\
x
\end{array}
Derivation
  1. Initial program 100.0%

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

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

    \[\leadsto \color{blue}{x} \]
  4. Final simplification29.9%

    \[\leadsto x \]

Reproduce

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