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

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

\\
z \cdot \left(x + y\right) + \left(x + y\right)
\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. Final simplification100.0%

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

Alternative 2: 51.6% accurate, 0.4× speedup?

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

\\
\begin{array}{l}
t_0 := z + 1 \leq 1\\
\mathbf{if}\;t\_0 \lor \neg t\_0:\\
\;\;\;\;x \cdot \left(z + 1\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (+.f64 z #s(literal 1 binary64)) < 1 or 1 < (+.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 x around inf 51.7%

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

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

    1. Initial program 100.0%

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

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

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

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

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

Alternative 3: 50.2% accurate, 0.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.8 \cdot 10^{+16}:\\
\;\;\;\;x \cdot z\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -1.8e16 or 4.1e5 < 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 99.6%

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

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

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

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

    if -1.8e16 < z < -7.9999999999999994e-129

    1. Initial program 99.9%

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

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

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

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

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

    if -7.9999999999999994e-129 < z < 4.1e5

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.8 \cdot 10^{+16}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq -8 \cdot 10^{-129}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 410000:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 50.0% accurate, 0.4× speedup?

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

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

\mathbf{elif}\;z \leq -6.2 \cdot 10^{-130}:\\
\;\;\;\;x\\

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

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


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

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

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

    if -1 < z < -6.20000000000000021e-130

    1. Initial program 100.0%

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

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

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

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

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

    if -6.20000000000000021e-130 < z < 3.5499999999999998

    1. Initial program 100.0%

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

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

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

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

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

Alternative 5: 74.8% accurate, 0.5× speedup?

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

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

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


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

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

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

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

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

    if -1 < z < 4.1e5

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

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

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

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

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

Alternative 6: 50.1% accurate, 0.6× speedup?

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

    1. Initial program 100.0%

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

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

    if -9.9999999999999998e-249 < (+.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 48.5%

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

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

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

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

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

Alternative 7: 50.1% accurate, 0.6× speedup?

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

    1. Initial program 100.0%

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

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

    if -9.9999999999999998e-249 < (+.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 48.5%

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

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

    \[\left(x + y\right) \cdot \left(z + 1\right) \]
  2. Add Preprocessing
  3. Final simplification100.0%

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

Alternative 9: 31.6% accurate, 1.2× speedup?

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

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

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


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

    1. Initial program 100.0%

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

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

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

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

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

    if -2.39999999999999996e-23 < x

    1. Initial program 100.0%

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

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

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

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

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

Alternative 10: 25.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 54.7%

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

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

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

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

Reproduce

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