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

Percentage Accurate: 99.9% → 99.9%
Time: 6.5s
Alternatives: 8
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 8 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: 74.2% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{y \cdot 0.5}{t}\\ t_2 := 0.5 \cdot \frac{x - z}{t}\\ \mathbf{if}\;y \leq 1.7 \cdot 10^{+28}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;y \leq 1.3 \cdot 10^{+55}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;y \leq 2.8 \cdot 10^{+55}:\\ \;\;\;\;0.5 \cdot \frac{x}{t}\\ \mathbf{elif}\;y \leq 1.4 \cdot 10^{+95} \lor \neg \left(y \leq 1.32 \cdot 10^{+97} \lor \neg \left(y \leq 4.6 \cdot 10^{+123}\right) \land y \leq 2 \cdot 10^{+145}\right):\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;t\_2\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (/ (* y 0.5) t)) (t_2 (* 0.5 (/ (- x z) t))))
   (if (<= y 1.7e+28)
     t_2
     (if (<= y 1.3e+55)
       t_1
       (if (<= y 2.8e+55)
         (* 0.5 (/ x t))
         (if (or (<= y 1.4e+95)
                 (not
                  (or (<= y 1.32e+97)
                      (and (not (<= y 4.6e+123)) (<= y 2e+145)))))
           t_1
           t_2))))))
double code(double x, double y, double z, double t) {
	double t_1 = (y * 0.5) / t;
	double t_2 = 0.5 * ((x - z) / t);
	double tmp;
	if (y <= 1.7e+28) {
		tmp = t_2;
	} else if (y <= 1.3e+55) {
		tmp = t_1;
	} else if (y <= 2.8e+55) {
		tmp = 0.5 * (x / t);
	} else if ((y <= 1.4e+95) || !((y <= 1.32e+97) || (!(y <= 4.6e+123) && (y <= 2e+145)))) {
		tmp = t_1;
	} else {
		tmp = t_2;
	}
	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 = (y * 0.5d0) / t
    t_2 = 0.5d0 * ((x - z) / t)
    if (y <= 1.7d+28) then
        tmp = t_2
    else if (y <= 1.3d+55) then
        tmp = t_1
    else if (y <= 2.8d+55) then
        tmp = 0.5d0 * (x / t)
    else if ((y <= 1.4d+95) .or. (.not. (y <= 1.32d+97) .or. (.not. (y <= 4.6d+123)) .and. (y <= 2d+145))) then
        tmp = t_1
    else
        tmp = t_2
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	double t_1 = (y * 0.5) / t;
	double t_2 = 0.5 * ((x - z) / t);
	double tmp;
	if (y <= 1.7e+28) {
		tmp = t_2;
	} else if (y <= 1.3e+55) {
		tmp = t_1;
	} else if (y <= 2.8e+55) {
		tmp = 0.5 * (x / t);
	} else if ((y <= 1.4e+95) || !((y <= 1.32e+97) || (!(y <= 4.6e+123) && (y <= 2e+145)))) {
		tmp = t_1;
	} else {
		tmp = t_2;
	}
	return tmp;
}
def code(x, y, z, t):
	t_1 = (y * 0.5) / t
	t_2 = 0.5 * ((x - z) / t)
	tmp = 0
	if y <= 1.7e+28:
		tmp = t_2
	elif y <= 1.3e+55:
		tmp = t_1
	elif y <= 2.8e+55:
		tmp = 0.5 * (x / t)
	elif (y <= 1.4e+95) or not ((y <= 1.32e+97) or (not (y <= 4.6e+123) and (y <= 2e+145))):
		tmp = t_1
	else:
		tmp = t_2
	return tmp
function code(x, y, z, t)
	t_1 = Float64(Float64(y * 0.5) / t)
	t_2 = Float64(0.5 * Float64(Float64(x - z) / t))
	tmp = 0.0
	if (y <= 1.7e+28)
		tmp = t_2;
	elseif (y <= 1.3e+55)
		tmp = t_1;
	elseif (y <= 2.8e+55)
		tmp = Float64(0.5 * Float64(x / t));
	elseif ((y <= 1.4e+95) || !((y <= 1.32e+97) || (!(y <= 4.6e+123) && (y <= 2e+145))))
		tmp = t_1;
	else
		tmp = t_2;
	end
	return tmp
end
function tmp_2 = code(x, y, z, t)
	t_1 = (y * 0.5) / t;
	t_2 = 0.5 * ((x - z) / t);
	tmp = 0.0;
	if (y <= 1.7e+28)
		tmp = t_2;
	elseif (y <= 1.3e+55)
		tmp = t_1;
	elseif (y <= 2.8e+55)
		tmp = 0.5 * (x / t);
	elseif ((y <= 1.4e+95) || ~(((y <= 1.32e+97) || (~((y <= 4.6e+123)) && (y <= 2e+145)))))
		tmp = t_1;
	else
		tmp = t_2;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(y * 0.5), $MachinePrecision] / t), $MachinePrecision]}, Block[{t$95$2 = N[(0.5 * N[(N[(x - z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, 1.7e+28], t$95$2, If[LessEqual[y, 1.3e+55], t$95$1, If[LessEqual[y, 2.8e+55], N[(0.5 * N[(x / t), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 1.4e+95], N[Not[Or[LessEqual[y, 1.32e+97], And[N[Not[LessEqual[y, 4.6e+123]], $MachinePrecision], LessEqual[y, 2e+145]]]], $MachinePrecision]], t$95$1, t$95$2]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;y \leq 1.3 \cdot 10^{+55}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;y \leq 2.8 \cdot 10^{+55}:\\
\;\;\;\;0.5 \cdot \frac{x}{t}\\

\mathbf{elif}\;y \leq 1.4 \cdot 10^{+95} \lor \neg \left(y \leq 1.32 \cdot 10^{+97} \lor \neg \left(y \leq 4.6 \cdot 10^{+123}\right) \land y \leq 2 \cdot 10^{+145}\right):\\
\;\;\;\;t\_1\\

\mathbf{else}:\\
\;\;\;\;t\_2\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < 1.7e28 or 1.3999999999999999e95 < y < 1.31999999999999994e97 or 4.59999999999999981e123 < y < 2e145

    1. Initial program 100.0%

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

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

    if 1.7e28 < y < 1.3e55 or 2.8000000000000001e55 < y < 1.3999999999999999e95 or 1.31999999999999994e97 < y < 4.59999999999999981e123 or 2e145 < y

    1. Initial program 99.9%

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

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

        \[\leadsto \color{blue}{\frac{0.5 \cdot y}{t}} \]
    5. Simplified75.1%

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

    if 1.3e55 < y < 2.8000000000000001e55

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 1.7 \cdot 10^{+28}:\\ \;\;\;\;0.5 \cdot \frac{x - z}{t}\\ \mathbf{elif}\;y \leq 1.3 \cdot 10^{+55}:\\ \;\;\;\;\frac{y \cdot 0.5}{t}\\ \mathbf{elif}\;y \leq 2.8 \cdot 10^{+55}:\\ \;\;\;\;0.5 \cdot \frac{x}{t}\\ \mathbf{elif}\;y \leq 1.4 \cdot 10^{+95} \lor \neg \left(y \leq 1.32 \cdot 10^{+97} \lor \neg \left(y \leq 4.6 \cdot 10^{+123}\right) \land y \leq 2 \cdot 10^{+145}\right):\\ \;\;\;\;\frac{y \cdot 0.5}{t}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{x - z}{t}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 85.0% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.55 \cdot 10^{+178} \lor \neg \left(z \leq 1.42 \cdot 10^{+57}\right):\\
\;\;\;\;0.5 \cdot \frac{x - z}{t}\\

\mathbf{else}:\\
\;\;\;\;\left(x + y\right) \cdot \frac{0.5}{t}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -1.54999999999999996e178 or 1.42e57 < 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 83.7%

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

    if -1.54999999999999996e178 < z < 1.42e57

    1. Initial program 100.0%

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

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

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

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

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

        \[\leadsto \color{blue}{\left(y + x\right)} \cdot \frac{0.5}{t} \]
    5. Simplified89.1%

      \[\leadsto \color{blue}{\left(y + x\right) \cdot \frac{0.5}{t}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification87.5%

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

Alternative 4: 55.8% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.4 \cdot 10^{+55} \lor \neg \left(x \leq 8.5 \cdot 10^{+67}\right):\\
\;\;\;\;0.5 \cdot \frac{x}{t}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -4.40000000000000021e55 or 8.50000000000000038e67 < x

    1. Initial program 99.9%

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

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

    if -4.40000000000000021e55 < x < 8.50000000000000038e67

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{-0.5 \cdot \frac{z}{t}} \]
    4. Step-by-step derivation
      1. *-commutative42.0%

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

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

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

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

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

Alternative 5: 47.3% accurate, 0.6× speedup?

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

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

\mathbf{elif}\;x \leq -2.45 \cdot 10^{-79}:\\
\;\;\;\;\frac{z \cdot -0.5}{t}\\

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


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

    1. Initial program 100.0%

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

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

    if -5.80000000000000023e68 < x < -2.45e-79

    1. Initial program 100.0%

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

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

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

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

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

    if -2.45e-79 < 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 46.3%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -5.8 \cdot 10^{+68}:\\ \;\;\;\;0.5 \cdot \frac{x}{t}\\ \mathbf{elif}\;x \leq -2.45 \cdot 10^{-79}:\\ \;\;\;\;\frac{z \cdot -0.5}{t}\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot 0.5}{t}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 47.2% accurate, 0.6× speedup?

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

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

\mathbf{elif}\;x \leq -1.35 \cdot 10^{-70}:\\
\;\;\;\;z \cdot \frac{-0.5}{t}\\

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


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

    1. Initial program 100.0%

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

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

    if -4.3e52 < x < -1.3500000000000001e-70

    1. Initial program 100.0%

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

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

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

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

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

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

    if -1.3500000000000001e-70 < 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 46.1%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -4.3 \cdot 10^{+52}:\\ \;\;\;\;0.5 \cdot \frac{x}{t}\\ \mathbf{elif}\;x \leq -1.35 \cdot 10^{-70}:\\ \;\;\;\;z \cdot \frac{-0.5}{t}\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot 0.5}{t}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 69.0% accurate, 0.6× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\left(y - z\right) \cdot \frac{0.5}{t}\\


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

    1. Initial program 100.0%

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

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

    if -1e-84 < (+.f64 x 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 65.7%

      \[\leadsto \color{blue}{0.5 \cdot \frac{y - z}{t}} \]
    4. Step-by-step derivation
      1. *-commutative65.7%

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

        \[\leadsto \color{blue}{\frac{\left(y - z\right) \cdot 0.5}{t}} \]
      3. associate-*r/65.6%

        \[\leadsto \color{blue}{\left(y - z\right) \cdot \frac{0.5}{t}} \]
    5. Simplified65.6%

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

Alternative 8: 36.7% 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. Add Preprocessing
  3. Taylor expanded in x around inf 38.4%

    \[\leadsto \color{blue}{0.5 \cdot \frac{x}{t}} \]
  4. Add Preprocessing

Reproduce

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