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

Percentage Accurate: 99.9% → 99.9%
Time: 5.1s
Alternatives: 9
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 9 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: 87.2% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -3.6 \cdot 10^{+81} \lor \neg \left(z \leq 80\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 -3.6e+81) (not (<= z 80.0)))
   (/ (- x z) (* t 2.0))
   (/ (+ x y) (* t 2.0))))
double code(double x, double y, double z, double t) {
	double tmp;
	if ((z <= -3.6e+81) || !(z <= 80.0)) {
		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 <= (-3.6d+81)) .or. (.not. (z <= 80.0d0))) 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 <= -3.6e+81) || !(z <= 80.0)) {
		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 <= -3.6e+81) or not (z <= 80.0):
		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 <= -3.6e+81) || !(z <= 80.0))
		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 <= -3.6e+81) || ~((z <= 80.0)))
		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, -3.6e+81], N[Not[LessEqual[z, 80.0]], $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 -3.6 \cdot 10^{+81} \lor \neg \left(z \leq 80\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 < -3.60000000000000005e81 or 80 < 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.2%

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

    if -3.60000000000000005e81 < z < 80

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

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

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

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

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

Alternative 3: 81.9% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.6 \cdot 10^{+143} \lor \neg \left(z \leq 6.8 \cdot 10^{+60}\right):\\
\;\;\;\;\frac{z \cdot -0.5}{t}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -5.59999999999999996e143 or 6.7999999999999999e60 < z

    1. Initial program 100.0%

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

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

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

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

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

    if -5.59999999999999996e143 < z < 6.7999999999999999e60

    1. Initial program 100.0%

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

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

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

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

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

Alternative 4: 47.3% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.5 \cdot 10^{+84}:\\
\;\;\;\;\frac{x}{t \cdot 2}\\

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

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


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

    1. Initial program 100.0%

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

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

    if -4.4999999999999997e84 < x < -2.05e-171

    1. Initial program 100.0%

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

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

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

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

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

    if -2.05e-171 < 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 35.7%

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

Alternative 5: 47.4% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.8 \cdot 10^{+32}:\\
\;\;\;\;\frac{x}{t \cdot 2}\\

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

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


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

    1. Initial program 100.0%

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

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

    if -3.8000000000000003e32 < x < -7.20000000000000029e-172

    1. Initial program 100.0%

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

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

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

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

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

        \[\leadsto \color{blue}{z \cdot \frac{-0.5}{t}} \]
      2. *-commutative45.5%

        \[\leadsto \color{blue}{\frac{-0.5}{t} \cdot z} \]
    7. Applied egg-rr45.5%

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

    if -7.20000000000000029e-172 < 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 35.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -3.8 \cdot 10^{+32}:\\ \;\;\;\;\frac{x}{t \cdot 2}\\ \mathbf{elif}\;x \leq -7.2 \cdot 10^{-172}:\\ \;\;\;\;z \cdot \frac{-0.5}{t}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{t \cdot 2}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 77.0% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.4 \cdot 10^{-60}:\\ \;\;\;\;\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 (<= x -1.4e-60) (/ (- x z) (* t 2.0)) (/ (- y z) (* t 2.0))))
double code(double x, double y, double z, double t) {
	double tmp;
	if (x <= -1.4e-60) {
		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 (x <= (-1.4d-60)) 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 (x <= -1.4e-60) {
		tmp = (x - z) / (t * 2.0);
	} else {
		tmp = (y - z) / (t * 2.0);
	}
	return tmp;
}
def code(x, y, z, t):
	tmp = 0
	if x <= -1.4e-60:
		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 (x <= -1.4e-60)
		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 (x <= -1.4e-60)
		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[x, -1.4e-60], 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}\;x \leq -1.4 \cdot 10^{-60}:\\
\;\;\;\;\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 x < -1.4000000000000001e-60

    1. Initial program 100.0%

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

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

    if -1.4000000000000001e-60 < x

    1. Initial program 100.0%

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

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

Alternative 7: 46.6% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.1 \cdot 10^{+32}:\\
\;\;\;\;\frac{x}{t \cdot 2}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -6.10000000000000027e32

    1. Initial program 100.0%

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

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

    if -6.10000000000000027e32 < x

    1. Initial program 100.0%

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

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

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

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

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

        \[\leadsto \color{blue}{z \cdot \frac{-0.5}{t}} \]
      2. *-commutative43.0%

        \[\leadsto \color{blue}{\frac{-0.5}{t} \cdot z} \]
    7. Applied egg-rr43.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -6.1 \cdot 10^{+32}:\\ \;\;\;\;\frac{x}{t \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \frac{-0.5}{t}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 46.4% accurate, 0.9× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -4.5999999999999998e84

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{\frac{1}{\frac{t \cdot 2}{x}}} \]
      2. associate-/r/77.3%

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

        \[\leadsto \frac{1}{\color{blue}{2 \cdot t}} \cdot x \]
      4. associate-/r*77.3%

        \[\leadsto \color{blue}{\frac{\frac{1}{2}}{t}} \cdot x \]
      5. metadata-eval77.3%

        \[\leadsto \frac{\color{blue}{0.5}}{t} \cdot x \]
    5. Applied egg-rr77.3%

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

    if -4.5999999999999998e84 < x

    1. Initial program 100.0%

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

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

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

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

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

        \[\leadsto \color{blue}{z \cdot \frac{-0.5}{t}} \]
      2. *-commutative42.9%

        \[\leadsto \color{blue}{\frac{-0.5}{t} \cdot z} \]
    7. Applied egg-rr42.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -4.6 \cdot 10^{+84}:\\ \;\;\;\;x \cdot \frac{0.5}{t}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \frac{-0.5}{t}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 37.1% accurate, 1.8× speedup?

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

\\
z \cdot \frac{-0.5}{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 z around inf 35.8%

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

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

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

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

      \[\leadsto \color{blue}{z \cdot \frac{-0.5}{t}} \]
    2. *-commutative35.7%

      \[\leadsto \color{blue}{\frac{-0.5}{t} \cdot z} \]
  7. Applied egg-rr35.7%

    \[\leadsto \color{blue}{\frac{-0.5}{t} \cdot z} \]
  8. Final simplification35.7%

    \[\leadsto z \cdot \frac{-0.5}{t} \]
  9. Add Preprocessing

Reproduce

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