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

Percentage Accurate: 99.9% → 99.9%
Time: 4.4s
Alternatives: 7
Speedup: 1.0×

Specification

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

\\
\frac{\left(x + y\right) - z}{t \cdot 2}
\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 7 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: 99.9% accurate, 1.0× speedup?

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

\\
\frac{\left(x + y\right) - z}{t \cdot 2}
\end{array}

Alternative 1: 99.9% accurate, 1.0× speedup?

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

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

    \[\frac{\left(x + y\right) - z}{t \cdot 2} \]
  2. Final simplification100.0%

    \[\leadsto \frac{\left(x + y\right) - z}{t \cdot 2} \]

Alternative 2: 46.2% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := x \cdot \frac{0.5}{t}\\ t_2 := \frac{z}{t} \cdot -0.5\\ \mathbf{if}\;x \leq -2.2 \cdot 10^{+129}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.75 \cdot 10^{+89}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -470:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.25 \cdot 10^{-145} \lor \neg \left(x \leq -4.6 \cdot 10^{-191}\right) \land x \leq 3.3 \cdot 10^{-257}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{y}{t}\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (* x (/ 0.5 t))) (t_2 (* (/ z t) -0.5)))
   (if (<= x -2.2e+129)
     t_1
     (if (<= x -1.75e+89)
       t_2
       (if (<= x -470.0)
         t_1
         (if (or (<= x -1.25e-145)
                 (and (not (<= x -4.6e-191)) (<= x 3.3e-257)))
           t_2
           (* 0.5 (/ y t))))))))
double code(double x, double y, double z, double t) {
	double t_1 = x * (0.5 / t);
	double t_2 = (z / t) * -0.5;
	double tmp;
	if (x <= -2.2e+129) {
		tmp = t_1;
	} else if (x <= -1.75e+89) {
		tmp = t_2;
	} else if (x <= -470.0) {
		tmp = t_1;
	} else if ((x <= -1.25e-145) || (!(x <= -4.6e-191) && (x <= 3.3e-257))) {
		tmp = t_2;
	} else {
		tmp = 0.5 * (y / t);
	}
	return tmp;
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_1 = x * (0.5d0 / t)
    t_2 = (z / t) * (-0.5d0)
    if (x <= (-2.2d+129)) then
        tmp = t_1
    else if (x <= (-1.75d+89)) then
        tmp = t_2
    else if (x <= (-470.0d0)) then
        tmp = t_1
    else if ((x <= (-1.25d-145)) .or. (.not. (x <= (-4.6d-191))) .and. (x <= 3.3d-257)) then
        tmp = t_2
    else
        tmp = 0.5d0 * (y / t)
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	double t_1 = x * (0.5 / t);
	double t_2 = (z / t) * -0.5;
	double tmp;
	if (x <= -2.2e+129) {
		tmp = t_1;
	} else if (x <= -1.75e+89) {
		tmp = t_2;
	} else if (x <= -470.0) {
		tmp = t_1;
	} else if ((x <= -1.25e-145) || (!(x <= -4.6e-191) && (x <= 3.3e-257))) {
		tmp = t_2;
	} else {
		tmp = 0.5 * (y / t);
	}
	return tmp;
}
def code(x, y, z, t):
	t_1 = x * (0.5 / t)
	t_2 = (z / t) * -0.5
	tmp = 0
	if x <= -2.2e+129:
		tmp = t_1
	elif x <= -1.75e+89:
		tmp = t_2
	elif x <= -470.0:
		tmp = t_1
	elif (x <= -1.25e-145) or (not (x <= -4.6e-191) and (x <= 3.3e-257)):
		tmp = t_2
	else:
		tmp = 0.5 * (y / t)
	return tmp
function code(x, y, z, t)
	t_1 = Float64(x * Float64(0.5 / t))
	t_2 = Float64(Float64(z / t) * -0.5)
	tmp = 0.0
	if (x <= -2.2e+129)
		tmp = t_1;
	elseif (x <= -1.75e+89)
		tmp = t_2;
	elseif (x <= -470.0)
		tmp = t_1;
	elseif ((x <= -1.25e-145) || (!(x <= -4.6e-191) && (x <= 3.3e-257)))
		tmp = t_2;
	else
		tmp = Float64(0.5 * Float64(y / t));
	end
	return tmp
end
function tmp_2 = code(x, y, z, t)
	t_1 = x * (0.5 / t);
	t_2 = (z / t) * -0.5;
	tmp = 0.0;
	if (x <= -2.2e+129)
		tmp = t_1;
	elseif (x <= -1.75e+89)
		tmp = t_2;
	elseif (x <= -470.0)
		tmp = t_1;
	elseif ((x <= -1.25e-145) || (~((x <= -4.6e-191)) && (x <= 3.3e-257)))
		tmp = t_2;
	else
		tmp = 0.5 * (y / t);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x * N[(0.5 / t), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(z / t), $MachinePrecision] * -0.5), $MachinePrecision]}, If[LessEqual[x, -2.2e+129], t$95$1, If[LessEqual[x, -1.75e+89], t$95$2, If[LessEqual[x, -470.0], t$95$1, If[Or[LessEqual[x, -1.25e-145], And[N[Not[LessEqual[x, -4.6e-191]], $MachinePrecision], LessEqual[x, 3.3e-257]]], t$95$2, N[(0.5 * N[(y / t), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := x \cdot \frac{0.5}{t}\\
t_2 := \frac{z}{t} \cdot -0.5\\
\mathbf{if}\;x \leq -2.2 \cdot 10^{+129}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x \leq -1.75 \cdot 10^{+89}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;x \leq -470:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x \leq -1.25 \cdot 10^{-145} \lor \neg \left(x \leq -4.6 \cdot 10^{-191}\right) \land x \leq 3.3 \cdot 10^{-257}:\\
\;\;\;\;t_2\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{y}{t}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -2.1999999999999999e129 or -1.75e89 < x < -470

    1. Initial program 99.9%

      \[\frac{\left(x + y\right) - z}{t \cdot 2} \]
    2. Taylor expanded in z around 0 92.3%

      \[\leadsto \color{blue}{0.5 \cdot \frac{y + x}{t}} \]
    3. Step-by-step derivation
      1. associate-*r/92.3%

        \[\leadsto \color{blue}{\frac{0.5 \cdot \left(y + x\right)}{t}} \]
      2. +-commutative92.3%

        \[\leadsto \frac{0.5 \cdot \color{blue}{\left(x + y\right)}}{t} \]
      3. associate-/l*92.1%

        \[\leadsto \color{blue}{\frac{0.5}{\frac{t}{x + y}}} \]
      4. +-commutative92.1%

        \[\leadsto \frac{0.5}{\frac{t}{\color{blue}{y + x}}} \]
    4. Simplified92.1%

      \[\leadsto \color{blue}{\frac{0.5}{\frac{t}{y + x}}} \]
    5. Taylor expanded in y around 0 78.1%

      \[\leadsto \color{blue}{0.5 \cdot \frac{x}{t}} \]
    6. Step-by-step derivation
      1. associate-*r/78.1%

        \[\leadsto \color{blue}{\frac{0.5 \cdot x}{t}} \]
      2. associate-*l/77.9%

        \[\leadsto \color{blue}{\frac{0.5}{t} \cdot x} \]
      3. *-commutative77.9%

        \[\leadsto \color{blue}{x \cdot \frac{0.5}{t}} \]
    7. Simplified77.9%

      \[\leadsto \color{blue}{x \cdot \frac{0.5}{t}} \]

    if -2.1999999999999999e129 < x < -1.75e89 or -470 < x < -1.2499999999999999e-145 or -4.60000000000000021e-191 < x < 3.3e-257

    1. Initial program 100.0%

      \[\frac{\left(x + y\right) - z}{t \cdot 2} \]
    2. Taylor expanded in z around inf 56.6%

      \[\leadsto \color{blue}{-0.5 \cdot \frac{z}{t}} \]
    3. Step-by-step derivation
      1. *-commutative56.6%

        \[\leadsto \color{blue}{\frac{z}{t} \cdot -0.5} \]
    4. Simplified56.6%

      \[\leadsto \color{blue}{\frac{z}{t} \cdot -0.5} \]

    if -1.2499999999999999e-145 < x < -4.60000000000000021e-191 or 3.3e-257 < x

    1. Initial program 100.0%

      \[\frac{\left(x + y\right) - z}{t \cdot 2} \]
    2. Taylor expanded in y around inf 39.7%

      \[\leadsto \color{blue}{0.5 \cdot \frac{y}{t}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification52.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.2 \cdot 10^{+129}:\\ \;\;\;\;x \cdot \frac{0.5}{t}\\ \mathbf{elif}\;x \leq -1.75 \cdot 10^{+89}:\\ \;\;\;\;\frac{z}{t} \cdot -0.5\\ \mathbf{elif}\;x \leq -470:\\ \;\;\;\;x \cdot \frac{0.5}{t}\\ \mathbf{elif}\;x \leq -1.25 \cdot 10^{-145} \lor \neg \left(x \leq -4.6 \cdot 10^{-191}\right) \land x \leq 3.3 \cdot 10^{-257}:\\ \;\;\;\;\frac{z}{t} \cdot -0.5\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{y}{t}\\ \end{array} \]

Alternative 3: 46.2% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{x \cdot 0.5}{t}\\ t_2 := \frac{z}{t} \cdot -0.5\\ \mathbf{if}\;x \leq -2.65 \cdot 10^{+129}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -8.5 \cdot 10^{+88}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -246:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1 \cdot 10^{-144} \lor \neg \left(x \leq -1.1 \cdot 10^{-193}\right) \land x \leq 8 \cdot 10^{-250}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{y}{t}\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (/ (* x 0.5) t)) (t_2 (* (/ z t) -0.5)))
   (if (<= x -2.65e+129)
     t_1
     (if (<= x -8.5e+88)
       t_2
       (if (<= x -246.0)
         t_1
         (if (or (<= x -1e-144) (and (not (<= x -1.1e-193)) (<= x 8e-250)))
           t_2
           (* 0.5 (/ y t))))))))
double code(double x, double y, double z, double t) {
	double t_1 = (x * 0.5) / t;
	double t_2 = (z / t) * -0.5;
	double tmp;
	if (x <= -2.65e+129) {
		tmp = t_1;
	} else if (x <= -8.5e+88) {
		tmp = t_2;
	} else if (x <= -246.0) {
		tmp = t_1;
	} else if ((x <= -1e-144) || (!(x <= -1.1e-193) && (x <= 8e-250))) {
		tmp = t_2;
	} else {
		tmp = 0.5 * (y / t);
	}
	return tmp;
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_1 = (x * 0.5d0) / t
    t_2 = (z / t) * (-0.5d0)
    if (x <= (-2.65d+129)) then
        tmp = t_1
    else if (x <= (-8.5d+88)) then
        tmp = t_2
    else if (x <= (-246.0d0)) then
        tmp = t_1
    else if ((x <= (-1d-144)) .or. (.not. (x <= (-1.1d-193))) .and. (x <= 8d-250)) then
        tmp = t_2
    else
        tmp = 0.5d0 * (y / t)
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	double t_1 = (x * 0.5) / t;
	double t_2 = (z / t) * -0.5;
	double tmp;
	if (x <= -2.65e+129) {
		tmp = t_1;
	} else if (x <= -8.5e+88) {
		tmp = t_2;
	} else if (x <= -246.0) {
		tmp = t_1;
	} else if ((x <= -1e-144) || (!(x <= -1.1e-193) && (x <= 8e-250))) {
		tmp = t_2;
	} else {
		tmp = 0.5 * (y / t);
	}
	return tmp;
}
def code(x, y, z, t):
	t_1 = (x * 0.5) / t
	t_2 = (z / t) * -0.5
	tmp = 0
	if x <= -2.65e+129:
		tmp = t_1
	elif x <= -8.5e+88:
		tmp = t_2
	elif x <= -246.0:
		tmp = t_1
	elif (x <= -1e-144) or (not (x <= -1.1e-193) and (x <= 8e-250)):
		tmp = t_2
	else:
		tmp = 0.5 * (y / t)
	return tmp
function code(x, y, z, t)
	t_1 = Float64(Float64(x * 0.5) / t)
	t_2 = Float64(Float64(z / t) * -0.5)
	tmp = 0.0
	if (x <= -2.65e+129)
		tmp = t_1;
	elseif (x <= -8.5e+88)
		tmp = t_2;
	elseif (x <= -246.0)
		tmp = t_1;
	elseif ((x <= -1e-144) || (!(x <= -1.1e-193) && (x <= 8e-250)))
		tmp = t_2;
	else
		tmp = Float64(0.5 * Float64(y / t));
	end
	return tmp
end
function tmp_2 = code(x, y, z, t)
	t_1 = (x * 0.5) / t;
	t_2 = (z / t) * -0.5;
	tmp = 0.0;
	if (x <= -2.65e+129)
		tmp = t_1;
	elseif (x <= -8.5e+88)
		tmp = t_2;
	elseif (x <= -246.0)
		tmp = t_1;
	elseif ((x <= -1e-144) || (~((x <= -1.1e-193)) && (x <= 8e-250)))
		tmp = t_2;
	else
		tmp = 0.5 * (y / t);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(x * 0.5), $MachinePrecision] / t), $MachinePrecision]}, Block[{t$95$2 = N[(N[(z / t), $MachinePrecision] * -0.5), $MachinePrecision]}, If[LessEqual[x, -2.65e+129], t$95$1, If[LessEqual[x, -8.5e+88], t$95$2, If[LessEqual[x, -246.0], t$95$1, If[Or[LessEqual[x, -1e-144], And[N[Not[LessEqual[x, -1.1e-193]], $MachinePrecision], LessEqual[x, 8e-250]]], t$95$2, N[(0.5 * N[(y / t), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \frac{x \cdot 0.5}{t}\\
t_2 := \frac{z}{t} \cdot -0.5\\
\mathbf{if}\;x \leq -2.65 \cdot 10^{+129}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x \leq -8.5 \cdot 10^{+88}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;x \leq -246:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x \leq -1 \cdot 10^{-144} \lor \neg \left(x \leq -1.1 \cdot 10^{-193}\right) \land x \leq 8 \cdot 10^{-250}:\\
\;\;\;\;t_2\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{y}{t}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -2.6499999999999999e129 or -8.5000000000000005e88 < x < -246

    1. Initial program 99.9%

      \[\frac{\left(x + y\right) - z}{t \cdot 2} \]
    2. Taylor expanded in x around inf 78.1%

      \[\leadsto \color{blue}{0.5 \cdot \frac{x}{t}} \]
    3. Step-by-step derivation
      1. associate-*r/78.1%

        \[\leadsto \color{blue}{\frac{0.5 \cdot x}{t}} \]
    4. Simplified78.1%

      \[\leadsto \color{blue}{\frac{0.5 \cdot x}{t}} \]

    if -2.6499999999999999e129 < x < -8.5000000000000005e88 or -246 < x < -9.9999999999999995e-145 or -1.09999999999999988e-193 < x < 8.0000000000000004e-250

    1. Initial program 100.0%

      \[\frac{\left(x + y\right) - z}{t \cdot 2} \]
    2. Taylor expanded in z around inf 56.6%

      \[\leadsto \color{blue}{-0.5 \cdot \frac{z}{t}} \]
    3. Step-by-step derivation
      1. *-commutative56.6%

        \[\leadsto \color{blue}{\frac{z}{t} \cdot -0.5} \]
    4. Simplified56.6%

      \[\leadsto \color{blue}{\frac{z}{t} \cdot -0.5} \]

    if -9.9999999999999995e-145 < x < -1.09999999999999988e-193 or 8.0000000000000004e-250 < x

    1. Initial program 100.0%

      \[\frac{\left(x + y\right) - z}{t \cdot 2} \]
    2. Taylor expanded in y around inf 39.7%

      \[\leadsto \color{blue}{0.5 \cdot \frac{y}{t}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification52.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.65 \cdot 10^{+129}:\\ \;\;\;\;\frac{x \cdot 0.5}{t}\\ \mathbf{elif}\;x \leq -8.5 \cdot 10^{+88}:\\ \;\;\;\;\frac{z}{t} \cdot -0.5\\ \mathbf{elif}\;x \leq -246:\\ \;\;\;\;\frac{x \cdot 0.5}{t}\\ \mathbf{elif}\;x \leq -1 \cdot 10^{-144} \lor \neg \left(x \leq -1.1 \cdot 10^{-193}\right) \land x \leq 8 \cdot 10^{-250}:\\ \;\;\;\;\frac{z}{t} \cdot -0.5\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{y}{t}\\ \end{array} \]

Alternative 4: 69.3% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x + y \leq -2 \cdot 10^{-237}:\\
\;\;\;\;0.5 \cdot \frac{x - z}{t}\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{y - z}{t}\\


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

    1. Initial program 100.0%

      \[\frac{\left(x + y\right) - z}{t \cdot 2} \]
    2. Taylor expanded in y around 0 69.8%

      \[\leadsto \color{blue}{0.5 \cdot \frac{x - z}{t}} \]

    if -2e-237 < (+.f64 x y)

    1. Initial program 100.0%

      \[\frac{\left(x + y\right) - z}{t \cdot 2} \]
    2. Taylor expanded in x around 0 64.0%

      \[\leadsto \color{blue}{0.5 \cdot \frac{y - z}{t}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification67.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x + y \leq -2 \cdot 10^{-237}:\\ \;\;\;\;0.5 \cdot \frac{x - z}{t}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{y - z}{t}\\ \end{array} \]

Alternative 5: 75.8% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq 4.2 \cdot 10^{+125}:\\
\;\;\;\;0.5 \cdot \frac{x - z}{t}\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{y}{t}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 4.2000000000000001e125

    1. Initial program 100.0%

      \[\frac{\left(x + y\right) - z}{t \cdot 2} \]
    2. Taylor expanded in y around 0 76.2%

      \[\leadsto \color{blue}{0.5 \cdot \frac{x - z}{t}} \]

    if 4.2000000000000001e125 < y

    1. Initial program 100.0%

      \[\frac{\left(x + y\right) - z}{t \cdot 2} \]
    2. Taylor expanded in y around inf 68.7%

      \[\leadsto \color{blue}{0.5 \cdot \frac{y}{t}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification75.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 4.2 \cdot 10^{+125}:\\ \;\;\;\;0.5 \cdot \frac{x - z}{t}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{y}{t}\\ \end{array} \]

Alternative 6: 46.1% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.7 \cdot 10^{-14}:\\
\;\;\;\;x \cdot \frac{0.5}{t}\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{y}{t}\\


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

    1. Initial program 100.0%

      \[\frac{\left(x + y\right) - z}{t \cdot 2} \]
    2. Taylor expanded in z around 0 84.6%

      \[\leadsto \color{blue}{0.5 \cdot \frac{y + x}{t}} \]
    3. Step-by-step derivation
      1. associate-*r/84.6%

        \[\leadsto \color{blue}{\frac{0.5 \cdot \left(y + x\right)}{t}} \]
      2. +-commutative84.6%

        \[\leadsto \frac{0.5 \cdot \color{blue}{\left(x + y\right)}}{t} \]
      3. associate-/l*84.4%

        \[\leadsto \color{blue}{\frac{0.5}{\frac{t}{x + y}}} \]
      4. +-commutative84.4%

        \[\leadsto \frac{0.5}{\frac{t}{\color{blue}{y + x}}} \]
    4. Simplified84.4%

      \[\leadsto \color{blue}{\frac{0.5}{\frac{t}{y + x}}} \]
    5. Taylor expanded in y around 0 69.4%

      \[\leadsto \color{blue}{0.5 \cdot \frac{x}{t}} \]
    6. Step-by-step derivation
      1. associate-*r/69.4%

        \[\leadsto \color{blue}{\frac{0.5 \cdot x}{t}} \]
      2. associate-*l/69.2%

        \[\leadsto \color{blue}{\frac{0.5}{t} \cdot x} \]
      3. *-commutative69.2%

        \[\leadsto \color{blue}{x \cdot \frac{0.5}{t}} \]
    7. Simplified69.2%

      \[\leadsto \color{blue}{x \cdot \frac{0.5}{t}} \]

    if -1.70000000000000001e-14 < x

    1. Initial program 100.0%

      \[\frac{\left(x + y\right) - z}{t \cdot 2} \]
    2. Taylor expanded in y around inf 39.1%

      \[\leadsto \color{blue}{0.5 \cdot \frac{y}{t}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification46.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.7 \cdot 10^{-14}:\\ \;\;\;\;x \cdot \frac{0.5}{t}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{y}{t}\\ \end{array} \]

Alternative 7: 37.5% accurate, 1.8× speedup?

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

\\
0.5 \cdot \frac{y}{t}
\end{array}
Derivation
  1. Initial program 100.0%

    \[\frac{\left(x + y\right) - z}{t \cdot 2} \]
  2. Taylor expanded in y around inf 34.2%

    \[\leadsto \color{blue}{0.5 \cdot \frac{y}{t}} \]
  3. Final simplification34.2%

    \[\leadsto 0.5 \cdot \frac{y}{t} \]

Reproduce

?
herbie shell --seed 2023195 
(FPCore (x y z t)
  :name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, B"
  :precision binary64
  (/ (- (+ x y) z) (* t 2.0)))