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

Percentage Accurate: 99.9% → 99.9%
Time: 4.7s
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. Add Preprocessing
  3. Add Preprocessing

Alternative 2: 46.6% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{x}{t \cdot 2}\\ t_2 := -0.5 \cdot \frac{z}{t}\\ \mathbf{if}\;x \leq -1.35 \cdot 10^{+140}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;x \leq -1.2 \cdot 10^{+114}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;x \leq -6.2 \cdot 10^{+75}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;x \leq 3.5 \cdot 10^{-200}:\\ \;\;\;\;t\_2\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{t \cdot 2}\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (/ x (* t 2.0))) (t_2 (* -0.5 (/ z t))))
   (if (<= x -1.35e+140)
     t_1
     (if (<= x -1.2e+114)
       t_2
       (if (<= x -6.2e+75) t_1 (if (<= x 3.5e-200) t_2 (/ y (* t 2.0))))))))
double code(double x, double y, double z, double t) {
	double t_1 = x / (t * 2.0);
	double t_2 = -0.5 * (z / t);
	double tmp;
	if (x <= -1.35e+140) {
		tmp = t_1;
	} else if (x <= -1.2e+114) {
		tmp = t_2;
	} else if (x <= -6.2e+75) {
		tmp = t_1;
	} else if (x <= 3.5e-200) {
		tmp = t_2;
	} else {
		tmp = y / (t * 2.0);
	}
	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 / (t * 2.0d0)
    t_2 = (-0.5d0) * (z / t)
    if (x <= (-1.35d+140)) then
        tmp = t_1
    else if (x <= (-1.2d+114)) then
        tmp = t_2
    else if (x <= (-6.2d+75)) then
        tmp = t_1
    else if (x <= 3.5d-200) then
        tmp = t_2
    else
        tmp = y / (t * 2.0d0)
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	double t_1 = x / (t * 2.0);
	double t_2 = -0.5 * (z / t);
	double tmp;
	if (x <= -1.35e+140) {
		tmp = t_1;
	} else if (x <= -1.2e+114) {
		tmp = t_2;
	} else if (x <= -6.2e+75) {
		tmp = t_1;
	} else if (x <= 3.5e-200) {
		tmp = t_2;
	} else {
		tmp = y / (t * 2.0);
	}
	return tmp;
}
def code(x, y, z, t):
	t_1 = x / (t * 2.0)
	t_2 = -0.5 * (z / t)
	tmp = 0
	if x <= -1.35e+140:
		tmp = t_1
	elif x <= -1.2e+114:
		tmp = t_2
	elif x <= -6.2e+75:
		tmp = t_1
	elif x <= 3.5e-200:
		tmp = t_2
	else:
		tmp = y / (t * 2.0)
	return tmp
function code(x, y, z, t)
	t_1 = Float64(x / Float64(t * 2.0))
	t_2 = Float64(-0.5 * Float64(z / t))
	tmp = 0.0
	if (x <= -1.35e+140)
		tmp = t_1;
	elseif (x <= -1.2e+114)
		tmp = t_2;
	elseif (x <= -6.2e+75)
		tmp = t_1;
	elseif (x <= 3.5e-200)
		tmp = t_2;
	else
		tmp = Float64(y / Float64(t * 2.0));
	end
	return tmp
end
function tmp_2 = code(x, y, z, t)
	t_1 = x / (t * 2.0);
	t_2 = -0.5 * (z / t);
	tmp = 0.0;
	if (x <= -1.35e+140)
		tmp = t_1;
	elseif (x <= -1.2e+114)
		tmp = t_2;
	elseif (x <= -6.2e+75)
		tmp = t_1;
	elseif (x <= 3.5e-200)
		tmp = t_2;
	else
		tmp = y / (t * 2.0);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x / N[(t * 2.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(-0.5 * N[(z / t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.35e+140], t$95$1, If[LessEqual[x, -1.2e+114], t$95$2, If[LessEqual[x, -6.2e+75], t$95$1, If[LessEqual[x, 3.5e-200], t$95$2, N[(y / N[(t * 2.0), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;x \leq -1.2 \cdot 10^{+114}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;x \leq -6.2 \cdot 10^{+75}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;x \leq 3.5 \cdot 10^{-200}:\\
\;\;\;\;t\_2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -1.35000000000000009e140 or -1.2e114 < x < -6.2000000000000002e75

    1. Initial program 100.0%

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

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

    if -1.35000000000000009e140 < x < -1.2e114 or -6.2000000000000002e75 < x < 3.50000000000000023e-200

    1. Initial program 100.0%

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

      \[\leadsto \frac{\color{blue}{x - z}}{t \cdot 2} \]
    4. Taylor expanded in x around 0 53.5%

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

    if 3.50000000000000023e-200 < x

    1. Initial program 100.0%

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

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

Alternative 3: 86.8% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -2 \cdot 10^{+40} \lor \neg \left(z \leq 1.6 \cdot 10^{-15}\right):\\
\;\;\;\;\frac{x - z}{t \cdot 2}\\

\mathbf{else}:\\
\;\;\;\;\frac{x + y}{t \cdot 2}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -2.00000000000000006e40 or 1.6e-15 < z

    1. Initial program 100.0%

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

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

    if -2.00000000000000006e40 < z < 1.6e-15

    1. Initial program 100.0%

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

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

        \[\leadsto \frac{\color{blue}{y + x}}{t \cdot 2} \]
    5. Simplified95.2%

      \[\leadsto \frac{\color{blue}{y + x}}{t \cdot 2} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification91.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -2 \cdot 10^{+40} \lor \neg \left(z \leq 1.6 \cdot 10^{-15}\right):\\ \;\;\;\;\frac{x - z}{t \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{x + y}{t \cdot 2}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 82.6% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.6 \cdot 10^{+142} \lor \neg \left(z \leq 7.8 \cdot 10^{+108}\right):\\
\;\;\;\;-0.5 \cdot \frac{z}{t}\\

\mathbf{else}:\\
\;\;\;\;\frac{x + y}{t \cdot 2}\\


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

    1. Initial program 100.0%

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

      \[\leadsto \frac{\color{blue}{x - z}}{t \cdot 2} \]
    4. Taylor expanded in x around 0 83.0%

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

    if -6.6000000000000004e142 < z < 7.79999999999999969e108

    1. Initial program 100.0%

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

      \[\leadsto \frac{\color{blue}{x + y}}{t \cdot 2} \]
    4. Step-by-step derivation
      1. +-commutative88.0%

        \[\leadsto \frac{\color{blue}{y + x}}{t \cdot 2} \]
    5. Simplified88.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -6.6 \cdot 10^{+142} \lor \neg \left(z \leq 7.8 \cdot 10^{+108}\right):\\ \;\;\;\;-0.5 \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;\frac{x + y}{t \cdot 2}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 55.8% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.6 \cdot 10^{+114} \lor \neg \left(z \leq 6.3 \cdot 10^{+72}\right):\\
\;\;\;\;-0.5 \cdot \frac{z}{t}\\

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


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

    1. Initial program 100.0%

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

      \[\leadsto \frac{\color{blue}{x - z}}{t \cdot 2} \]
    4. Taylor expanded in x around 0 78.2%

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

    if -4.6000000000000001e114 < z < 6.29999999999999963e72

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -4.6 \cdot 10^{+114} \lor \neg \left(z \leq 6.3 \cdot 10^{+72}\right):\\ \;\;\;\;-0.5 \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{t \cdot 2}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 76.3% accurate, 0.7× speedup?

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

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

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


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

    1. Initial program 100.0%

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

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

    if 6.00000000000000033e-77 < y

    1. Initial program 100.0%

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

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

Alternative 7: 36.7% accurate, 1.8× speedup?

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

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

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

    \[\leadsto \frac{\color{blue}{x - z}}{t \cdot 2} \]
  4. Taylor expanded in x around 0 36.8%

    \[\leadsto \color{blue}{-0.5 \cdot \frac{z}{t}} \]
  5. Add Preprocessing

Reproduce

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