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

Percentage Accurate: 92.5% → 97.8%
Time: 8.1s
Alternatives: 8
Speedup: 1.1×

Specification

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

\\
x + \frac{y \cdot \left(z - x\right)}{t}
\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: 92.5% accurate, 1.0× speedup?

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

\\
x + \frac{y \cdot \left(z - x\right)}{t}
\end{array}

Alternative 1: 97.8% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(\frac{y}{t}, z - x, x\right) \end{array} \]
(FPCore (x y z t) :precision binary64 (fma (/ y t) (- z x) x))
double code(double x, double y, double z, double t) {
	return fma((y / t), (z - x), x);
}
function code(x, y, z, t)
	return fma(Float64(y / t), Float64(z - x), x)
end
code[x_, y_, z_, t_] := N[(N[(y / t), $MachinePrecision] * N[(z - x), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(\frac{y}{t}, z - x, x\right)
\end{array}
Derivation
  1. Initial program 95.1%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y}{t}, z - x, x\right)} \]
    9. lower-/.f6497.4

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{y}{t}}, z - x, x\right) \]
  4. Applied rewrites97.4%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y}{t}, z - x, x\right)} \]
  5. Add Preprocessing

Alternative 2: 84.3% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
t_1 := y \cdot \frac{z - x}{t}\\
\mathbf{if}\;y \leq -0.0001:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;y \leq 1.55 \cdot 10^{+123}:\\
\;\;\;\;x + \frac{y \cdot z}{t}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1.00000000000000005e-4 or 1.55000000000000003e123 < y

    1. Initial program 88.1%

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

      \[\leadsto \color{blue}{y \cdot \left(\frac{z}{t} - \frac{x}{t}\right)} \]
    4. Step-by-step derivation
      1. div-subN/A

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

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

        \[\leadsto y \cdot \color{blue}{\frac{z - x}{t}} \]
      4. lower--.f6489.4

        \[\leadsto y \cdot \frac{\color{blue}{z - x}}{t} \]
    5. Applied rewrites89.4%

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

    if -1.00000000000000005e-4 < y < 1.55000000000000003e123

    1. Initial program 99.9%

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

      \[\leadsto x + \frac{\color{blue}{y \cdot z}}{t} \]
    4. Step-by-step derivation
      1. lower-*.f6489.1

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

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

Alternative 3: 76.2% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
t_1 := y \cdot \frac{z - x}{t}\\
\mathbf{if}\;y \leq -1.25 \cdot 10^{-62}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;y \leq 9.5 \cdot 10^{-51}:\\
\;\;\;\;x - \frac{y \cdot x}{t}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1.25e-62 or 9.4999999999999998e-51 < y

    1. Initial program 91.5%

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

      \[\leadsto \color{blue}{y \cdot \left(\frac{z}{t} - \frac{x}{t}\right)} \]
    4. Step-by-step derivation
      1. div-subN/A

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

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

        \[\leadsto y \cdot \color{blue}{\frac{z - x}{t}} \]
      4. lower--.f6481.5

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

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

    if -1.25e-62 < y < 9.4999999999999998e-51

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{x \cdot \left(1 + -1 \cdot \frac{y}{t}\right)} \]
    4. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto x \cdot \left(1 + \color{blue}{\left(\mathsf{neg}\left(\frac{y}{t}\right)\right)}\right) \]
      2. unsub-negN/A

        \[\leadsto x \cdot \color{blue}{\left(1 - \frac{y}{t}\right)} \]
      3. distribute-lft-out--N/A

        \[\leadsto \color{blue}{x \cdot 1 - x \cdot \frac{y}{t}} \]
      4. *-rgt-identityN/A

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

        \[\leadsto x - \color{blue}{\frac{x \cdot y}{t}} \]
      6. lower--.f64N/A

        \[\leadsto \color{blue}{x - \frac{x \cdot y}{t}} \]
      7. lower-/.f64N/A

        \[\leadsto x - \color{blue}{\frac{x \cdot y}{t}} \]
      8. *-commutativeN/A

        \[\leadsto x - \frac{\color{blue}{y \cdot x}}{t} \]
      9. lower-*.f6481.4

        \[\leadsto x - \frac{\color{blue}{y \cdot x}}{t} \]
    5. Applied rewrites81.4%

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

Alternative 4: 47.8% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.2 \cdot 10^{+24}:\\
\;\;\;\;\frac{y}{t} \cdot z\\

\mathbf{elif}\;z \leq 7 \cdot 10^{+60}:\\
\;\;\;\;\frac{y}{t} \cdot \left(-x\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -6.20000000000000022e24

    1. Initial program 96.0%

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

      \[\leadsto \color{blue}{\frac{y \cdot z}{t}} \]
    4. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{y \cdot z}{t}} \]
      2. lower-*.f6469.2

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

      \[\leadsto \color{blue}{\frac{y \cdot z}{t}} \]
    6. Step-by-step derivation
      1. Applied rewrites71.2%

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

      if -6.20000000000000022e24 < z < 7.0000000000000004e60

      1. Initial program 94.3%

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

        \[\leadsto \color{blue}{y \cdot \left(\frac{z}{t} - \frac{x}{t}\right)} \]
      4. Step-by-step derivation
        1. div-subN/A

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

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

          \[\leadsto y \cdot \color{blue}{\frac{z - x}{t}} \]
        4. lower--.f6448.0

          \[\leadsto y \cdot \frac{\color{blue}{z - x}}{t} \]
      5. Applied rewrites48.0%

        \[\leadsto \color{blue}{y \cdot \frac{z - x}{t}} \]
      6. Taylor expanded in z around 0

        \[\leadsto y \cdot \frac{-1 \cdot x}{t} \]
      7. Step-by-step derivation
        1. Applied rewrites39.8%

          \[\leadsto y \cdot \frac{-x}{t} \]
        2. Step-by-step derivation
          1. Applied rewrites41.8%

            \[\leadsto \color{blue}{\frac{y}{t} \cdot \left(-x\right)} \]

          if 7.0000000000000004e60 < z

          1. Initial program 96.3%

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

            \[\leadsto \color{blue}{\frac{y \cdot z}{t}} \]
          4. Step-by-step derivation
            1. lower-/.f64N/A

              \[\leadsto \color{blue}{\frac{y \cdot z}{t}} \]
            2. lower-*.f6461.8

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

            \[\leadsto \color{blue}{\frac{y \cdot z}{t}} \]
          6. Step-by-step derivation
            1. Applied rewrites64.5%

              \[\leadsto \frac{z}{t} \cdot \color{blue}{y} \]
          7. Recombined 3 regimes into one program.
          8. Final simplification52.3%

            \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -6.2 \cdot 10^{+24}:\\ \;\;\;\;\frac{y}{t} \cdot z\\ \mathbf{elif}\;z \leq 7 \cdot 10^{+60}:\\ \;\;\;\;\frac{y}{t} \cdot \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{z}{t}\\ \end{array} \]
          9. Add Preprocessing

          Alternative 5: 47.1% accurate, 0.7× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -3.9 \cdot 10^{+24}:\\ \;\;\;\;\frac{y}{t} \cdot z\\ \mathbf{elif}\;z \leq 8.6 \cdot 10^{+57}:\\ \;\;\;\;y \cdot \frac{-x}{t}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{z}{t}\\ \end{array} \end{array} \]
          (FPCore (x y z t)
           :precision binary64
           (if (<= z -3.9e+24)
             (* (/ y t) z)
             (if (<= z 8.6e+57) (* y (/ (- x) t)) (* y (/ z t)))))
          double code(double x, double y, double z, double t) {
          	double tmp;
          	if (z <= -3.9e+24) {
          		tmp = (y / t) * z;
          	} else if (z <= 8.6e+57) {
          		tmp = y * (-x / t);
          	} else {
          		tmp = y * (z / t);
          	}
          	return tmp;
          }
          
          real(8) function code(x, y, z, t)
              real(8), intent (in) :: x
              real(8), intent (in) :: y
              real(8), intent (in) :: z
              real(8), intent (in) :: t
              real(8) :: tmp
              if (z <= (-3.9d+24)) then
                  tmp = (y / t) * z
              else if (z <= 8.6d+57) then
                  tmp = y * (-x / t)
              else
                  tmp = y * (z / t)
              end if
              code = tmp
          end function
          
          public static double code(double x, double y, double z, double t) {
          	double tmp;
          	if (z <= -3.9e+24) {
          		tmp = (y / t) * z;
          	} else if (z <= 8.6e+57) {
          		tmp = y * (-x / t);
          	} else {
          		tmp = y * (z / t);
          	}
          	return tmp;
          }
          
          def code(x, y, z, t):
          	tmp = 0
          	if z <= -3.9e+24:
          		tmp = (y / t) * z
          	elif z <= 8.6e+57:
          		tmp = y * (-x / t)
          	else:
          		tmp = y * (z / t)
          	return tmp
          
          function code(x, y, z, t)
          	tmp = 0.0
          	if (z <= -3.9e+24)
          		tmp = Float64(Float64(y / t) * z);
          	elseif (z <= 8.6e+57)
          		tmp = Float64(y * Float64(Float64(-x) / t));
          	else
          		tmp = Float64(y * Float64(z / t));
          	end
          	return tmp
          end
          
          function tmp_2 = code(x, y, z, t)
          	tmp = 0.0;
          	if (z <= -3.9e+24)
          		tmp = (y / t) * z;
          	elseif (z <= 8.6e+57)
          		tmp = y * (-x / t);
          	else
          		tmp = y * (z / t);
          	end
          	tmp_2 = tmp;
          end
          
          code[x_, y_, z_, t_] := If[LessEqual[z, -3.9e+24], N[(N[(y / t), $MachinePrecision] * z), $MachinePrecision], If[LessEqual[z, 8.6e+57], N[(y * N[((-x) / t), $MachinePrecision]), $MachinePrecision], N[(y * N[(z / t), $MachinePrecision]), $MachinePrecision]]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;z \leq -3.9 \cdot 10^{+24}:\\
          \;\;\;\;\frac{y}{t} \cdot z\\
          
          \mathbf{elif}\;z \leq 8.6 \cdot 10^{+57}:\\
          \;\;\;\;y \cdot \frac{-x}{t}\\
          
          \mathbf{else}:\\
          \;\;\;\;y \cdot \frac{z}{t}\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 3 regimes
          2. if z < -3.8999999999999998e24

            1. Initial program 96.0%

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

              \[\leadsto \color{blue}{\frac{y \cdot z}{t}} \]
            4. Step-by-step derivation
              1. lower-/.f64N/A

                \[\leadsto \color{blue}{\frac{y \cdot z}{t}} \]
              2. lower-*.f6469.2

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

              \[\leadsto \color{blue}{\frac{y \cdot z}{t}} \]
            6. Step-by-step derivation
              1. Applied rewrites71.2%

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

              if -3.8999999999999998e24 < z < 8.60000000000000066e57

              1. Initial program 94.3%

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

                \[\leadsto \color{blue}{y \cdot \left(\frac{z}{t} - \frac{x}{t}\right)} \]
              4. Step-by-step derivation
                1. div-subN/A

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

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

                  \[\leadsto y \cdot \color{blue}{\frac{z - x}{t}} \]
                4. lower--.f6448.0

                  \[\leadsto y \cdot \frac{\color{blue}{z - x}}{t} \]
              5. Applied rewrites48.0%

                \[\leadsto \color{blue}{y \cdot \frac{z - x}{t}} \]
              6. Taylor expanded in z around 0

                \[\leadsto y \cdot \frac{-1 \cdot x}{t} \]
              7. Step-by-step derivation
                1. Applied rewrites39.8%

                  \[\leadsto y \cdot \frac{-x}{t} \]

                if 8.60000000000000066e57 < z

                1. Initial program 96.3%

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

                  \[\leadsto \color{blue}{\frac{y \cdot z}{t}} \]
                4. Step-by-step derivation
                  1. lower-/.f64N/A

                    \[\leadsto \color{blue}{\frac{y \cdot z}{t}} \]
                  2. lower-*.f6461.8

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

                  \[\leadsto \color{blue}{\frac{y \cdot z}{t}} \]
                6. Step-by-step derivation
                  1. Applied rewrites64.5%

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

                  \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -3.9 \cdot 10^{+24}:\\ \;\;\;\;\frac{y}{t} \cdot z\\ \mathbf{elif}\;z \leq 8.6 \cdot 10^{+57}:\\ \;\;\;\;y \cdot \frac{-x}{t}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{z}{t}\\ \end{array} \]
                9. Add Preprocessing

                Alternative 6: 47.0% accurate, 0.7× speedup?

                \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -4.2 \cdot 10^{+17}:\\ \;\;\;\;\frac{y}{t} \cdot z\\ \mathbf{elif}\;z \leq 8.6 \cdot 10^{+57}:\\ \;\;\;\;\frac{x \cdot \left(-y\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{z}{t}\\ \end{array} \end{array} \]
                (FPCore (x y z t)
                 :precision binary64
                 (if (<= z -4.2e+17)
                   (* (/ y t) z)
                   (if (<= z 8.6e+57) (/ (* x (- y)) t) (* y (/ z t)))))
                double code(double x, double y, double z, double t) {
                	double tmp;
                	if (z <= -4.2e+17) {
                		tmp = (y / t) * z;
                	} else if (z <= 8.6e+57) {
                		tmp = (x * -y) / t;
                	} else {
                		tmp = y * (z / t);
                	}
                	return tmp;
                }
                
                real(8) function code(x, y, z, t)
                    real(8), intent (in) :: x
                    real(8), intent (in) :: y
                    real(8), intent (in) :: z
                    real(8), intent (in) :: t
                    real(8) :: tmp
                    if (z <= (-4.2d+17)) then
                        tmp = (y / t) * z
                    else if (z <= 8.6d+57) then
                        tmp = (x * -y) / t
                    else
                        tmp = y * (z / t)
                    end if
                    code = tmp
                end function
                
                public static double code(double x, double y, double z, double t) {
                	double tmp;
                	if (z <= -4.2e+17) {
                		tmp = (y / t) * z;
                	} else if (z <= 8.6e+57) {
                		tmp = (x * -y) / t;
                	} else {
                		tmp = y * (z / t);
                	}
                	return tmp;
                }
                
                def code(x, y, z, t):
                	tmp = 0
                	if z <= -4.2e+17:
                		tmp = (y / t) * z
                	elif z <= 8.6e+57:
                		tmp = (x * -y) / t
                	else:
                		tmp = y * (z / t)
                	return tmp
                
                function code(x, y, z, t)
                	tmp = 0.0
                	if (z <= -4.2e+17)
                		tmp = Float64(Float64(y / t) * z);
                	elseif (z <= 8.6e+57)
                		tmp = Float64(Float64(x * Float64(-y)) / t);
                	else
                		tmp = Float64(y * Float64(z / t));
                	end
                	return tmp
                end
                
                function tmp_2 = code(x, y, z, t)
                	tmp = 0.0;
                	if (z <= -4.2e+17)
                		tmp = (y / t) * z;
                	elseif (z <= 8.6e+57)
                		tmp = (x * -y) / t;
                	else
                		tmp = y * (z / t);
                	end
                	tmp_2 = tmp;
                end
                
                code[x_, y_, z_, t_] := If[LessEqual[z, -4.2e+17], N[(N[(y / t), $MachinePrecision] * z), $MachinePrecision], If[LessEqual[z, 8.6e+57], N[(N[(x * (-y)), $MachinePrecision] / t), $MachinePrecision], N[(y * N[(z / t), $MachinePrecision]), $MachinePrecision]]]
                
                \begin{array}{l}
                
                \\
                \begin{array}{l}
                \mathbf{if}\;z \leq -4.2 \cdot 10^{+17}:\\
                \;\;\;\;\frac{y}{t} \cdot z\\
                
                \mathbf{elif}\;z \leq 8.6 \cdot 10^{+57}:\\
                \;\;\;\;\frac{x \cdot \left(-y\right)}{t}\\
                
                \mathbf{else}:\\
                \;\;\;\;y \cdot \frac{z}{t}\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 3 regimes
                2. if z < -4.2e17

                  1. Initial program 94.4%

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

                    \[\leadsto \color{blue}{\frac{y \cdot z}{t}} \]
                  4. Step-by-step derivation
                    1. lower-/.f64N/A

                      \[\leadsto \color{blue}{\frac{y \cdot z}{t}} \]
                    2. lower-*.f6466.8

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

                    \[\leadsto \color{blue}{\frac{y \cdot z}{t}} \]
                  6. Step-by-step derivation
                    1. Applied rewrites68.7%

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

                    if -4.2e17 < z < 8.60000000000000066e57

                    1. Initial program 94.9%

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

                      \[\leadsto \color{blue}{x \cdot \left(1 + -1 \cdot \frac{y}{t}\right)} \]
                    4. Step-by-step derivation
                      1. mul-1-negN/A

                        \[\leadsto x \cdot \left(1 + \color{blue}{\left(\mathsf{neg}\left(\frac{y}{t}\right)\right)}\right) \]
                      2. unsub-negN/A

                        \[\leadsto x \cdot \color{blue}{\left(1 - \frac{y}{t}\right)} \]
                      3. distribute-lft-out--N/A

                        \[\leadsto \color{blue}{x \cdot 1 - x \cdot \frac{y}{t}} \]
                      4. *-rgt-identityN/A

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

                        \[\leadsto x - \color{blue}{\frac{x \cdot y}{t}} \]
                      6. lower--.f64N/A

                        \[\leadsto \color{blue}{x - \frac{x \cdot y}{t}} \]
                      7. lower-/.f64N/A

                        \[\leadsto x - \color{blue}{\frac{x \cdot y}{t}} \]
                      8. *-commutativeN/A

                        \[\leadsto x - \frac{\color{blue}{y \cdot x}}{t} \]
                      9. lower-*.f6484.2

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

                      \[\leadsto \color{blue}{x - \frac{y \cdot x}{t}} \]
                    6. Taylor expanded in y around inf

                      \[\leadsto -1 \cdot \color{blue}{\frac{x \cdot y}{t}} \]
                    7. Step-by-step derivation
                      1. Applied rewrites39.8%

                        \[\leadsto \frac{x \cdot \left(-y\right)}{\color{blue}{t}} \]

                      if 8.60000000000000066e57 < z

                      1. Initial program 96.3%

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

                        \[\leadsto \color{blue}{\frac{y \cdot z}{t}} \]
                      4. Step-by-step derivation
                        1. lower-/.f64N/A

                          \[\leadsto \color{blue}{\frac{y \cdot z}{t}} \]
                        2. lower-*.f6461.8

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

                        \[\leadsto \color{blue}{\frac{y \cdot z}{t}} \]
                      6. Step-by-step derivation
                        1. Applied rewrites64.5%

                          \[\leadsto \frac{z}{t} \cdot \color{blue}{y} \]
                      7. Recombined 3 regimes into one program.
                      8. Final simplification50.9%

                        \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -4.2 \cdot 10^{+17}:\\ \;\;\;\;\frac{y}{t} \cdot z\\ \mathbf{elif}\;z \leq 8.6 \cdot 10^{+57}:\\ \;\;\;\;\frac{x \cdot \left(-y\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{z}{t}\\ \end{array} \]
                      9. Add Preprocessing

                      Alternative 7: 58.6% accurate, 1.2× speedup?

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

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

                        \[\leadsto \color{blue}{y \cdot \left(\frac{z}{t} - \frac{x}{t}\right)} \]
                      4. Step-by-step derivation
                        1. div-subN/A

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

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

                          \[\leadsto y \cdot \color{blue}{\frac{z - x}{t}} \]
                        4. lower--.f6456.8

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

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

                      Alternative 8: 41.1% accurate, 1.4× speedup?

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

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

                        \[\leadsto \color{blue}{\frac{y \cdot z}{t}} \]
                      4. Step-by-step derivation
                        1. lower-/.f64N/A

                          \[\leadsto \color{blue}{\frac{y \cdot z}{t}} \]
                        2. lower-*.f6435.7

                          \[\leadsto \frac{\color{blue}{y \cdot z}}{t} \]
                      5. Applied rewrites35.7%

                        \[\leadsto \color{blue}{\frac{y \cdot z}{t}} \]
                      6. Step-by-step derivation
                        1. Applied rewrites36.7%

                          \[\leadsto z \cdot \color{blue}{\frac{y}{t}} \]
                        2. Final simplification36.7%

                          \[\leadsto \frac{y}{t} \cdot z \]
                        3. Add Preprocessing

                        Developer Target 1: 90.7% accurate, 0.6× speedup?

                        \[\begin{array}{l} \\ x - \left(x \cdot \frac{y}{t} + \left(-z\right) \cdot \frac{y}{t}\right) \end{array} \]
                        (FPCore (x y z t)
                         :precision binary64
                         (- x (+ (* x (/ y t)) (* (- z) (/ y t)))))
                        double code(double x, double y, double z, double t) {
                        	return x - ((x * (y / t)) + (-z * (y / t)));
                        }
                        
                        real(8) function code(x, y, z, t)
                            real(8), intent (in) :: x
                            real(8), intent (in) :: y
                            real(8), intent (in) :: z
                            real(8), intent (in) :: t
                            code = x - ((x * (y / t)) + (-z * (y / t)))
                        end function
                        
                        public static double code(double x, double y, double z, double t) {
                        	return x - ((x * (y / t)) + (-z * (y / t)));
                        }
                        
                        def code(x, y, z, t):
                        	return x - ((x * (y / t)) + (-z * (y / t)))
                        
                        function code(x, y, z, t)
                        	return Float64(x - Float64(Float64(x * Float64(y / t)) + Float64(Float64(-z) * Float64(y / t))))
                        end
                        
                        function tmp = code(x, y, z, t)
                        	tmp = x - ((x * (y / t)) + (-z * (y / t)));
                        end
                        
                        code[x_, y_, z_, t_] := N[(x - N[(N[(x * N[(y / t), $MachinePrecision]), $MachinePrecision] + N[((-z) * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
                        
                        \begin{array}{l}
                        
                        \\
                        x - \left(x \cdot \frac{y}{t} + \left(-z\right) \cdot \frac{y}{t}\right)
                        \end{array}
                        

                        Reproduce

                        ?
                        herbie shell --seed 2024221 
                        (FPCore (x y z t)
                          :name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, D"
                          :precision binary64
                        
                          :alt
                          (! :herbie-platform default (- x (+ (* x (/ y t)) (* (- z) (/ y t)))))
                        
                          (+ x (/ (* y (- z x)) t)))