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

Percentage Accurate: 99.9% → 99.7%
Time: 7.2s
Alternatives: 9
Speedup: N/A×

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.7% accurate, 1.0× speedup?

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

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

    \[\frac{\left(x + y\right) - z}{t \cdot 2} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto \color{blue}{\frac{\left(x + y\right) - z}{t \cdot 2}} \]
    2. clear-numN/A

      \[\leadsto \color{blue}{\frac{1}{\frac{t \cdot 2}{\left(x + y\right) - z}}} \]
    3. associate-/r/N/A

      \[\leadsto \color{blue}{\frac{1}{t \cdot 2} \cdot \left(\left(x + y\right) - z\right)} \]
    4. lower-*.f64N/A

      \[\leadsto \color{blue}{\frac{1}{t \cdot 2} \cdot \left(\left(x + y\right) - z\right)} \]
    5. lift-*.f64N/A

      \[\leadsto \frac{1}{\color{blue}{t \cdot 2}} \cdot \left(\left(x + y\right) - z\right) \]
    6. *-commutativeN/A

      \[\leadsto \frac{1}{\color{blue}{2 \cdot t}} \cdot \left(\left(x + y\right) - z\right) \]
    7. associate-/r*N/A

      \[\leadsto \color{blue}{\frac{\frac{1}{2}}{t}} \cdot \left(\left(x + y\right) - z\right) \]
    8. lower-/.f64N/A

      \[\leadsto \color{blue}{\frac{\frac{1}{2}}{t}} \cdot \left(\left(x + y\right) - z\right) \]
    9. metadata-eval99.7

      \[\leadsto \frac{\color{blue}{0.5}}{t} \cdot \left(\left(x + y\right) - z\right) \]
    10. lift--.f64N/A

      \[\leadsto \frac{\frac{1}{2}}{t} \cdot \color{blue}{\left(\left(x + y\right) - z\right)} \]
    11. lift-+.f64N/A

      \[\leadsto \frac{\frac{1}{2}}{t} \cdot \left(\color{blue}{\left(x + y\right)} - z\right) \]
    12. associate--l+N/A

      \[\leadsto \frac{\frac{1}{2}}{t} \cdot \color{blue}{\left(x + \left(y - z\right)\right)} \]
    13. lower-+.f64N/A

      \[\leadsto \frac{\frac{1}{2}}{t} \cdot \color{blue}{\left(x + \left(y - z\right)\right)} \]
    14. lower--.f6499.7

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

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

Alternative 2: 37.0% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\frac{\left(x + y\right) - z}{t \cdot 2} \leq 0:\\
\;\;\;\;\frac{0.5 \cdot x}{t}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (-.f64 (+.f64 x y) z) (*.f64 t #s(literal 2 binary64))) < 0.0

    1. Initial program 99.3%

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

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{x}{t}} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{\frac{x}{t} \cdot \frac{1}{2}} \]
      2. associate-*l/N/A

        \[\leadsto \color{blue}{\frac{x \cdot \frac{1}{2}}{t}} \]
      3. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{x \cdot \frac{1}{2}}{t}} \]
      4. *-commutativeN/A

        \[\leadsto \frac{\color{blue}{\frac{1}{2} \cdot x}}{t} \]
      5. lower-*.f6445.1

        \[\leadsto \frac{\color{blue}{0.5 \cdot x}}{t} \]
    5. Applied rewrites45.1%

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

    if 0.0 < (/.f64 (-.f64 (+.f64 x y) z) (*.f64 t #s(literal 2 binary64)))

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{y}{t}} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{\frac{y}{t} \cdot \frac{1}{2}} \]
      2. associate-*l/N/A

        \[\leadsto \color{blue}{\frac{y \cdot \frac{1}{2}}{t}} \]
      3. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{y \cdot \frac{1}{2}}{t}} \]
      4. *-commutativeN/A

        \[\leadsto \frac{\color{blue}{\frac{1}{2} \cdot y}}{t} \]
      5. lower-*.f6432.1

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

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

Alternative 3: 49.1% accurate, 0.7× speedup?

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

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

\mathbf{elif}\;x + y \leq 10^{-25}:\\
\;\;\;\;\frac{z \cdot -0.5}{t}\\

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


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

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{x}{t}} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{\frac{x}{t} \cdot \frac{1}{2}} \]
      2. associate-*l/N/A

        \[\leadsto \color{blue}{\frac{x \cdot \frac{1}{2}}{t}} \]
      3. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{x \cdot \frac{1}{2}}{t}} \]
      4. *-commutativeN/A

        \[\leadsto \frac{\color{blue}{\frac{1}{2} \cdot x}}{t} \]
      5. lower-*.f6452.9

        \[\leadsto \frac{\color{blue}{0.5 \cdot x}}{t} \]
    5. Applied rewrites52.9%

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

    if -4.99999999999999977e-7 < (+.f64 x y) < 1.00000000000000004e-25

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{\frac{-1}{2} \cdot \frac{z}{t}} \]
    4. Step-by-step derivation
      1. associate-*r/N/A

        \[\leadsto \color{blue}{\frac{\frac{-1}{2} \cdot z}{t}} \]
      2. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{\frac{-1}{2} \cdot z}{t}} \]
      3. *-commutativeN/A

        \[\leadsto \frac{\color{blue}{z \cdot \frac{-1}{2}}}{t} \]
      4. lower-*.f6466.7

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

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

    if 1.00000000000000004e-25 < (+.f64 x y)

    1. Initial program 99.0%

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

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{y}{t}} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{\frac{y}{t} \cdot \frac{1}{2}} \]
      2. associate-*l/N/A

        \[\leadsto \color{blue}{\frac{y \cdot \frac{1}{2}}{t}} \]
      3. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{y \cdot \frac{1}{2}}{t}} \]
      4. *-commutativeN/A

        \[\leadsto \frac{\color{blue}{\frac{1}{2} \cdot y}}{t} \]
      5. lower-*.f6436.1

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

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

Alternative 4: 86.0% accurate, 0.7× speedup?

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

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

\mathbf{elif}\;z \leq 4.5 \cdot 10^{+89}:\\
\;\;\;\;\frac{x + y}{t \cdot 2}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -5.50000000000000001e103 or 4.5e89 < z

    1. Initial program 98.9%

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

      \[\leadsto \frac{\color{blue}{x - z}}{t \cdot 2} \]
    4. Step-by-step derivation
      1. lower--.f6481.7

        \[\leadsto \frac{\color{blue}{x - z}}{t \cdot 2} \]
    5. Applied rewrites81.7%

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

    if -5.50000000000000001e103 < z < 4.5e89

    1. Initial program 100.0%

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

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

        \[\leadsto \frac{\color{blue}{y + x}}{t \cdot 2} \]
      2. lower-+.f6493.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -5.5 \cdot 10^{+103}:\\ \;\;\;\;\frac{x - z}{t \cdot 2}\\ \mathbf{elif}\;z \leq 4.5 \cdot 10^{+89}:\\ \;\;\;\;\frac{x + y}{t \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{x - z}{t \cdot 2}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 81.5% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
t_1 := \frac{z \cdot -0.5}{t}\\
\mathbf{if}\;z \leq -6.7 \cdot 10^{+109}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;z \leq 9 \cdot 10^{+146}:\\
\;\;\;\;\frac{x + y}{t \cdot 2}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -6.70000000000000036e109 or 9.00000000000000051e146 < z

    1. Initial program 98.7%

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

      \[\leadsto \color{blue}{\frac{-1}{2} \cdot \frac{z}{t}} \]
    4. Step-by-step derivation
      1. associate-*r/N/A

        \[\leadsto \color{blue}{\frac{\frac{-1}{2} \cdot z}{t}} \]
      2. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{\frac{-1}{2} \cdot z}{t}} \]
      3. *-commutativeN/A

        \[\leadsto \frac{\color{blue}{z \cdot \frac{-1}{2}}}{t} \]
      4. lower-*.f6477.0

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

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

    if -6.70000000000000036e109 < z < 9.00000000000000051e146

    1. Initial program 100.0%

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

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

        \[\leadsto \frac{\color{blue}{y + x}}{t \cdot 2} \]
      2. lower-+.f6490.4

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

      \[\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.7 \cdot 10^{+109}:\\ \;\;\;\;\frac{z \cdot -0.5}{t}\\ \mathbf{elif}\;z \leq 9 \cdot 10^{+146}:\\ \;\;\;\;\frac{x + y}{t \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{z \cdot -0.5}{t}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 81.4% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
t_1 := \frac{z \cdot -0.5}{t}\\
\mathbf{if}\;z \leq -6.7 \cdot 10^{+109}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;z \leq 9 \cdot 10^{+146}:\\
\;\;\;\;\frac{0.5}{t} \cdot \left(x + y\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -6.70000000000000036e109 or 9.00000000000000051e146 < z

    1. Initial program 98.7%

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

      \[\leadsto \color{blue}{\frac{-1}{2} \cdot \frac{z}{t}} \]
    4. Step-by-step derivation
      1. associate-*r/N/A

        \[\leadsto \color{blue}{\frac{\frac{-1}{2} \cdot z}{t}} \]
      2. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{\frac{-1}{2} \cdot z}{t}} \]
      3. *-commutativeN/A

        \[\leadsto \frac{\color{blue}{z \cdot \frac{-1}{2}}}{t} \]
      4. lower-*.f6477.0

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

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

    if -6.70000000000000036e109 < z < 9.00000000000000051e146

    1. Initial program 100.0%

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

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

        \[\leadsto \frac{\color{blue}{y + x}}{t \cdot 2} \]
      2. lower-+.f6490.4

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

      \[\leadsto \frac{\color{blue}{y + x}}{t \cdot 2} \]
    6. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{y + x}{t \cdot 2}} \]
      2. clear-numN/A

        \[\leadsto \color{blue}{\frac{1}{\frac{t \cdot 2}{y + x}}} \]
      3. associate-/r/N/A

        \[\leadsto \color{blue}{\frac{1}{t \cdot 2} \cdot \left(y + x\right)} \]
      4. lift-*.f64N/A

        \[\leadsto \frac{1}{\color{blue}{t \cdot 2}} \cdot \left(y + x\right) \]
      5. *-commutativeN/A

        \[\leadsto \frac{1}{\color{blue}{2 \cdot t}} \cdot \left(y + x\right) \]
      6. associate-/r*N/A

        \[\leadsto \color{blue}{\frac{\frac{1}{2}}{t}} \cdot \left(y + x\right) \]
      7. metadata-evalN/A

        \[\leadsto \frac{\color{blue}{\frac{1}{2}}}{t} \cdot \left(y + x\right) \]
      8. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{\frac{1}{2}}{t}} \cdot \left(y + x\right) \]
      9. lower-*.f6490.1

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

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

Alternative 7: 69.5% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x + y \leq -5 \cdot 10^{-236}:\\ \;\;\;\;\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 y) -5e-236) (/ (- x z) (* t 2.0)) (/ (- y z) (* t 2.0))))
double code(double x, double y, double z, double t) {
	double tmp;
	if ((x + y) <= -5e-236) {
		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 + y) <= (-5d-236)) 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 + y) <= -5e-236) {
		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 + y) <= -5e-236:
		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 (Float64(x + y) <= -5e-236)
		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 + y) <= -5e-236)
		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[N[(x + y), $MachinePrecision], -5e-236], 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 + y \leq -5 \cdot 10^{-236}:\\
\;\;\;\;\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 (+.f64 x y) < -4.9999999999999998e-236

    1. Initial program 100.0%

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

      \[\leadsto \frac{\color{blue}{x - z}}{t \cdot 2} \]
    4. Step-by-step derivation
      1. lower--.f6470.2

        \[\leadsto \frac{\color{blue}{x - z}}{t \cdot 2} \]
    5. Applied rewrites70.2%

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

    if -4.9999999999999998e-236 < (+.f64 x y)

    1. Initial program 99.2%

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

      \[\leadsto \frac{\color{blue}{y - z}}{t \cdot 2} \]
    4. Step-by-step derivation
      1. lower--.f6461.8

        \[\leadsto \frac{\color{blue}{y - z}}{t \cdot 2} \]
    5. Applied rewrites61.8%

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

Alternative 8: 37.1% accurate, 1.4× speedup?

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

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

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

    \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{x}{t}} \]
  4. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \color{blue}{\frac{x}{t} \cdot \frac{1}{2}} \]
    2. associate-*l/N/A

      \[\leadsto \color{blue}{\frac{x \cdot \frac{1}{2}}{t}} \]
    3. lower-/.f64N/A

      \[\leadsto \color{blue}{\frac{x \cdot \frac{1}{2}}{t}} \]
    4. *-commutativeN/A

      \[\leadsto \frac{\color{blue}{\frac{1}{2} \cdot x}}{t} \]
    5. lower-*.f6446.2

      \[\leadsto \frac{\color{blue}{0.5 \cdot x}}{t} \]
  5. Applied rewrites46.2%

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

Alternative 9: 37.0% accurate, 1.4× speedup?

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

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

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

    \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{x}{t}} \]
  4. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \color{blue}{\frac{x}{t} \cdot \frac{1}{2}} \]
    2. associate-*l/N/A

      \[\leadsto \color{blue}{\frac{x \cdot \frac{1}{2}}{t}} \]
    3. lower-/.f64N/A

      \[\leadsto \color{blue}{\frac{x \cdot \frac{1}{2}}{t}} \]
    4. *-commutativeN/A

      \[\leadsto \frac{\color{blue}{\frac{1}{2} \cdot x}}{t} \]
    5. lower-*.f6446.2

      \[\leadsto \frac{\color{blue}{0.5 \cdot x}}{t} \]
  5. Applied rewrites46.2%

    \[\leadsto \color{blue}{\frac{0.5 \cdot x}{t}} \]
  6. Step-by-step derivation
    1. Applied rewrites46.0%

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

    Reproduce

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