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: 47.6% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.3 \cdot 10^{+72}:\\ \;\;\;\;x \cdot \frac{0.5}{t}\\ \mathbf{elif}\;x \leq -1.25 \cdot 10^{-183} \lor \neg \left(x \leq -8.8 \cdot 10^{-262}\right) \land \left(x \leq -1.25 \cdot 10^{-296} \lor \neg \left(x \leq 2.1 \cdot 10^{-286}\right) \land x \leq 1.62 \cdot 10^{-236}\right):\\ \;\;\;\;\frac{z}{t} \cdot -0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot 0.5}{t}\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (if (<= x -1.3e+72)
   (* x (/ 0.5 t))
   (if (or (<= x -1.25e-183)
           (and (not (<= x -8.8e-262))
                (or (<= x -1.25e-296)
                    (and (not (<= x 2.1e-286)) (<= x 1.62e-236)))))
     (* (/ z t) -0.5)
     (/ (* y 0.5) t))))
double code(double x, double y, double z, double t) {
	double tmp;
	if (x <= -1.3e+72) {
		tmp = x * (0.5 / t);
	} else if ((x <= -1.25e-183) || (!(x <= -8.8e-262) && ((x <= -1.25e-296) || (!(x <= 2.1e-286) && (x <= 1.62e-236))))) {
		tmp = (z / t) * -0.5;
	} else {
		tmp = (y * 0.5) / 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.3d+72)) then
        tmp = x * (0.5d0 / t)
    else if ((x <= (-1.25d-183)) .or. (.not. (x <= (-8.8d-262))) .and. (x <= (-1.25d-296)) .or. (.not. (x <= 2.1d-286)) .and. (x <= 1.62d-236)) then
        tmp = (z / t) * (-0.5d0)
    else
        tmp = (y * 0.5d0) / t
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	double tmp;
	if (x <= -1.3e+72) {
		tmp = x * (0.5 / t);
	} else if ((x <= -1.25e-183) || (!(x <= -8.8e-262) && ((x <= -1.25e-296) || (!(x <= 2.1e-286) && (x <= 1.62e-236))))) {
		tmp = (z / t) * -0.5;
	} else {
		tmp = (y * 0.5) / t;
	}
	return tmp;
}
def code(x, y, z, t):
	tmp = 0
	if x <= -1.3e+72:
		tmp = x * (0.5 / t)
	elif (x <= -1.25e-183) or (not (x <= -8.8e-262) and ((x <= -1.25e-296) or (not (x <= 2.1e-286) and (x <= 1.62e-236)))):
		tmp = (z / t) * -0.5
	else:
		tmp = (y * 0.5) / t
	return tmp
function code(x, y, z, t)
	tmp = 0.0
	if (x <= -1.3e+72)
		tmp = Float64(x * Float64(0.5 / t));
	elseif ((x <= -1.25e-183) || (!(x <= -8.8e-262) && ((x <= -1.25e-296) || (!(x <= 2.1e-286) && (x <= 1.62e-236)))))
		tmp = Float64(Float64(z / t) * -0.5);
	else
		tmp = Float64(Float64(y * 0.5) / t);
	end
	return tmp
end
function tmp_2 = code(x, y, z, t)
	tmp = 0.0;
	if (x <= -1.3e+72)
		tmp = x * (0.5 / t);
	elseif ((x <= -1.25e-183) || (~((x <= -8.8e-262)) && ((x <= -1.25e-296) || (~((x <= 2.1e-286)) && (x <= 1.62e-236)))))
		tmp = (z / t) * -0.5;
	else
		tmp = (y * 0.5) / t;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := If[LessEqual[x, -1.3e+72], N[(x * N[(0.5 / t), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[x, -1.25e-183], And[N[Not[LessEqual[x, -8.8e-262]], $MachinePrecision], Or[LessEqual[x, -1.25e-296], And[N[Not[LessEqual[x, 2.1e-286]], $MachinePrecision], LessEqual[x, 1.62e-236]]]]], N[(N[(z / t), $MachinePrecision] * -0.5), $MachinePrecision], N[(N[(y * 0.5), $MachinePrecision] / t), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.3 \cdot 10^{+72}:\\
\;\;\;\;x \cdot \frac{0.5}{t}\\

\mathbf{elif}\;x \leq -1.25 \cdot 10^{-183} \lor \neg \left(x \leq -8.8 \cdot 10^{-262}\right) \land \left(x \leq -1.25 \cdot 10^{-296} \lor \neg \left(x \leq 2.1 \cdot 10^{-286}\right) \land x \leq 1.62 \cdot 10^{-236}\right):\\
\;\;\;\;\frac{z}{t} \cdot -0.5\\

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


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

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{0.5 \cdot \frac{x}{t} + 0.5 \cdot \frac{y - z}{t}} \]
    3. Step-by-step derivation
      1. div-sub81.6%

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

        \[\leadsto \color{blue}{0.5 \cdot \left(\frac{x}{t} + \left(\frac{y}{t} - \frac{z}{t}\right)\right)} \]
      3. div-sub83.5%

        \[\leadsto 0.5 \cdot \left(\frac{x}{t} + \color{blue}{\frac{y - z}{t}}\right) \]
    4. Simplified83.5%

      \[\leadsto \color{blue}{0.5 \cdot \left(\frac{x}{t} + \frac{y - z}{t}\right)} \]
    5. Taylor expanded in x around inf 64.4%

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

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

        \[\leadsto \frac{\color{blue}{x \cdot 0.5}}{t} \]
      3. associate-*r/65.7%

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

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

    if -1.29999999999999991e72 < x < -1.2500000000000001e-183 or -8.79999999999999954e-262 < x < -1.25000000000000008e-296 or 2.09999999999999988e-286 < x < 1.62e-236

    1. Initial program 100.0%

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

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

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

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

    if -1.2500000000000001e-183 < x < -8.79999999999999954e-262 or -1.25000000000000008e-296 < x < 2.09999999999999988e-286 or 1.62e-236 < x

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{\frac{0.5 \cdot y}{t}} \]
    4. Simplified46.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.3 \cdot 10^{+72}:\\ \;\;\;\;x \cdot \frac{0.5}{t}\\ \mathbf{elif}\;x \leq -1.25 \cdot 10^{-183} \lor \neg \left(x \leq -8.8 \cdot 10^{-262}\right) \land \left(x \leq -1.25 \cdot 10^{-296} \lor \neg \left(x \leq 2.1 \cdot 10^{-286}\right) \land x \leq 1.62 \cdot 10^{-236}\right):\\ \;\;\;\;\frac{z}{t} \cdot -0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot 0.5}{t}\\ \end{array} \]

Alternative 3: 55.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -950000000000 \lor \neg \left(z \leq 3.8 \cdot 10^{+115}\right):\\ \;\;\;\;\frac{z}{t} \cdot -0.5\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{x}{t}\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (if (or (<= z -950000000000.0) (not (<= z 3.8e+115)))
   (* (/ z t) -0.5)
   (* 0.5 (/ x t))))
double code(double x, double y, double z, double t) {
	double tmp;
	if ((z <= -950000000000.0) || !(z <= 3.8e+115)) {
		tmp = (z / t) * -0.5;
	} else {
		tmp = 0.5 * (x / 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 ((z <= (-950000000000.0d0)) .or. (.not. (z <= 3.8d+115))) then
        tmp = (z / t) * (-0.5d0)
    else
        tmp = 0.5d0 * (x / t)
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	double tmp;
	if ((z <= -950000000000.0) || !(z <= 3.8e+115)) {
		tmp = (z / t) * -0.5;
	} else {
		tmp = 0.5 * (x / t);
	}
	return tmp;
}
def code(x, y, z, t):
	tmp = 0
	if (z <= -950000000000.0) or not (z <= 3.8e+115):
		tmp = (z / t) * -0.5
	else:
		tmp = 0.5 * (x / t)
	return tmp
function code(x, y, z, t)
	tmp = 0.0
	if ((z <= -950000000000.0) || !(z <= 3.8e+115))
		tmp = Float64(Float64(z / t) * -0.5);
	else
		tmp = Float64(0.5 * Float64(x / t));
	end
	return tmp
end
function tmp_2 = code(x, y, z, t)
	tmp = 0.0;
	if ((z <= -950000000000.0) || ~((z <= 3.8e+115)))
		tmp = (z / t) * -0.5;
	else
		tmp = 0.5 * (x / t);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -950000000000.0], N[Not[LessEqual[z, 3.8e+115]], $MachinePrecision]], N[(N[(z / t), $MachinePrecision] * -0.5), $MachinePrecision], N[(0.5 * N[(x / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -950000000000 \lor \neg \left(z \leq 3.8 \cdot 10^{+115}\right):\\
\;\;\;\;\frac{z}{t} \cdot -0.5\\

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


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

    1. Initial program 100.0%

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

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

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

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

    if -9.5e11 < z < 3.8000000000000001e115

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -950000000000 \lor \neg \left(z \leq 3.8 \cdot 10^{+115}\right):\\ \;\;\;\;\frac{z}{t} \cdot -0.5\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{x}{t}\\ \end{array} \]

Alternative 4: 74.1% accurate, 1.0× speedup?

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

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

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


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

    1. Initial program 100.0%

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

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

    if 2.60000000000000021e43 < y

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{\frac{0.5 \cdot y}{t}} \]
    4. Simplified63.2%

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

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

Alternative 5: 78.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -2.1 \cdot 10^{+15}:\\ \;\;\;\;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 -2.1e+15) (* 0.5 (/ (- x z) t)) (* 0.5 (/ (- y z) t))))
double code(double x, double y, double z, double t) {
	double tmp;
	if (x <= -2.1e+15) {
		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 <= (-2.1d+15)) 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 <= -2.1e+15) {
		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 <= -2.1e+15:
		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 (x <= -2.1e+15)
		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 <= -2.1e+15)
		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[x, -2.1e+15], 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 \leq -2.1 \cdot 10^{+15}:\\
\;\;\;\;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 x < -2.1e15

    1. Initial program 99.9%

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

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

    if -2.1e15 < x

    1. Initial program 100.0%

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

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

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

Alternative 6: 37.6% accurate, 1.8× speedup?

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

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

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

    \[\leadsto \color{blue}{0.5 \cdot \frac{x}{t}} \]
  3. Final simplification36.4%

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

Alternative 7: 37.5% accurate, 1.8× speedup?

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

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

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

    \[\leadsto \color{blue}{0.5 \cdot \frac{x}{t} + 0.5 \cdot \frac{y - z}{t}} \]
  3. Step-by-step derivation
    1. div-sub93.0%

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

      \[\leadsto \color{blue}{0.5 \cdot \left(\frac{x}{t} + \left(\frac{y}{t} - \frac{z}{t}\right)\right)} \]
    3. div-sub95.4%

      \[\leadsto 0.5 \cdot \left(\frac{x}{t} + \color{blue}{\frac{y - z}{t}}\right) \]
  4. Simplified95.4%

    \[\leadsto \color{blue}{0.5 \cdot \left(\frac{x}{t} + \frac{y - z}{t}\right)} \]
  5. Taylor expanded in x around inf 36.4%

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

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

      \[\leadsto \frac{\color{blue}{x \cdot 0.5}}{t} \]
    3. associate-*r/36.6%

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

    \[\leadsto \color{blue}{x \cdot \frac{0.5}{t}} \]
  8. Final simplification36.6%

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

Reproduce

?
herbie shell --seed 2023320 
(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)))