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

Percentage Accurate: 92.9% → 97.7%
Time: 6.9s
Alternatives: 7
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 7 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 92.9% 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.7% 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 91.5%

    \[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.3

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

    \[\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} \mathbf{if}\;t \leq -4 \cdot 10^{+17} \lor \neg \left(t \leq 9.4 \cdot 10^{-101}\right):\\ \;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(z - x\right) \cdot y}{t}\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (if (or (<= t -4e+17) (not (<= t 9.4e-101)))
   (fma (/ z t) y x)
   (/ (* (- z x) y) t)))
double code(double x, double y, double z, double t) {
	double tmp;
	if ((t <= -4e+17) || !(t <= 9.4e-101)) {
		tmp = fma((z / t), y, x);
	} else {
		tmp = ((z - x) * y) / t;
	}
	return tmp;
}
function code(x, y, z, t)
	tmp = 0.0
	if ((t <= -4e+17) || !(t <= 9.4e-101))
		tmp = fma(Float64(z / t), y, x);
	else
		tmp = Float64(Float64(Float64(z - x) * y) / t);
	end
	return tmp
end
code[x_, y_, z_, t_] := If[Or[LessEqual[t, -4e+17], N[Not[LessEqual[t, 9.4e-101]], $MachinePrecision]], N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision], N[(N[(N[(z - x), $MachinePrecision] * y), $MachinePrecision] / t), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;t \leq -4 \cdot 10^{+17} \lor \neg \left(t \leq 9.4 \cdot 10^{-101}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if t < -4e17 or 9.3999999999999999e-101 < t

    1. Initial program 86.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. associate-/l*N/A

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{z - x}{t}, y, x\right)} \]
    5. Taylor expanded in x around 0

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{z}{t}}, y, x\right) \]
    6. Step-by-step derivation
      1. lower-/.f6487.4

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

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

    if -4e17 < t < 9.3999999999999999e-101

    1. Initial program 97.6%

      \[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-/.f6496.0

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y}{t}, z - x, x\right)} \]
    5. Taylor expanded in y around inf

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\left(z - x\right) \cdot y}}{t} \]
      6. lower--.f6484.5

        \[\leadsto \frac{\color{blue}{\left(z - x\right)} \cdot y}{t} \]
    7. Applied rewrites84.5%

      \[\leadsto \color{blue}{\frac{\left(z - x\right) \cdot y}{t}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification86.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;t \leq -4 \cdot 10^{+17} \lor \neg \left(t \leq 9.4 \cdot 10^{-101}\right):\\ \;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(z - x\right) \cdot y}{t}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 82.0% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -5.8 \cdot 10^{+72} \lor \neg \left(z \leq 2.65 \cdot 10^{-5}\right):\\ \;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\ \mathbf{else}:\\ \;\;\;\;\left(1 - \frac{y}{t}\right) \cdot x\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (if (or (<= z -5.8e+72) (not (<= z 2.65e-5)))
   (fma (/ z t) y x)
   (* (- 1.0 (/ y t)) x)))
double code(double x, double y, double z, double t) {
	double tmp;
	if ((z <= -5.8e+72) || !(z <= 2.65e-5)) {
		tmp = fma((z / t), y, x);
	} else {
		tmp = (1.0 - (y / t)) * x;
	}
	return tmp;
}
function code(x, y, z, t)
	tmp = 0.0
	if ((z <= -5.8e+72) || !(z <= 2.65e-5))
		tmp = fma(Float64(z / t), y, x);
	else
		tmp = Float64(Float64(1.0 - Float64(y / t)) * x);
	end
	return tmp
end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -5.8e+72], N[Not[LessEqual[z, 2.65e-5]], $MachinePrecision]], N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision], N[(N[(1.0 - N[(y / t), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.8 \cdot 10^{+72} \lor \neg \left(z \leq 2.65 \cdot 10^{-5}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -5.80000000000000034e72 or 2.65e-5 < z

    1. Initial program 87.5%

      \[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. associate-/l*N/A

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{z - x}{t}, y, x\right)} \]
    5. Taylor expanded in x around 0

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{z}{t}}, y, x\right) \]
    6. Step-by-step derivation
      1. lower-/.f6483.2

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{z}{t}}, y, x\right) \]
    7. Applied rewrites83.2%

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

    if -5.80000000000000034e72 < z < 2.65e-5

    1. Initial program 95.1%

      \[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. *-commutativeN/A

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

        \[\leadsto \color{blue}{\left(1 + -1 \cdot \frac{y}{t}\right) \cdot x} \]
      3. fp-cancel-sign-sub-invN/A

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

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

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

        \[\leadsto \color{blue}{\left(1 - \frac{y}{t}\right)} \cdot x \]
      7. lower-/.f6486.6

        \[\leadsto \left(1 - \color{blue}{\frac{y}{t}}\right) \cdot x \]
    5. Applied rewrites86.6%

      \[\leadsto \color{blue}{\left(1 - \frac{y}{t}\right) \cdot x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification85.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -5.8 \cdot 10^{+72} \lor \neg \left(z \leq 2.65 \cdot 10^{-5}\right):\\ \;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\ \mathbf{else}:\\ \;\;\;\;\left(1 - \frac{y}{t}\right) \cdot x\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 82.0% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -5.8 \cdot 10^{+72}:\\ \;\;\;\;x + \frac{z \cdot y}{t}\\ \mathbf{elif}\;z \leq 2.65 \cdot 10^{-5}:\\ \;\;\;\;\left(1 - \frac{y}{t}\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (if (<= z -5.8e+72)
   (+ x (/ (* z y) t))
   (if (<= z 2.65e-5) (* (- 1.0 (/ y t)) x) (fma (/ z t) y x))))
double code(double x, double y, double z, double t) {
	double tmp;
	if (z <= -5.8e+72) {
		tmp = x + ((z * y) / t);
	} else if (z <= 2.65e-5) {
		tmp = (1.0 - (y / t)) * x;
	} else {
		tmp = fma((z / t), y, x);
	}
	return tmp;
}
function code(x, y, z, t)
	tmp = 0.0
	if (z <= -5.8e+72)
		tmp = Float64(x + Float64(Float64(z * y) / t));
	elseif (z <= 2.65e-5)
		tmp = Float64(Float64(1.0 - Float64(y / t)) * x);
	else
		tmp = fma(Float64(z / t), y, x);
	end
	return tmp
end
code[x_, y_, z_, t_] := If[LessEqual[z, -5.8e+72], N[(x + N[(N[(z * y), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2.65e-5], N[(N[(1.0 - N[(y / t), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision], N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision]]]
\begin{array}{l}

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

\mathbf{elif}\;z \leq 2.65 \cdot 10^{-5}:\\
\;\;\;\;\left(1 - \frac{y}{t}\right) \cdot x\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\


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

    1. Initial program 91.1%

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

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

        \[\leadsto x + \frac{\color{blue}{z \cdot y}}{t} \]
      2. lower-*.f6491.0

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

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

    if -5.80000000000000034e72 < z < 2.65e-5

    1. Initial program 95.1%

      \[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. *-commutativeN/A

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

        \[\leadsto \color{blue}{\left(1 + -1 \cdot \frac{y}{t}\right) \cdot x} \]
      3. fp-cancel-sign-sub-invN/A

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

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

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

        \[\leadsto \color{blue}{\left(1 - \frac{y}{t}\right)} \cdot x \]
      7. lower-/.f6486.6

        \[\leadsto \left(1 - \color{blue}{\frac{y}{t}}\right) \cdot x \]
    5. Applied rewrites86.6%

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

    if 2.65e-5 < z

    1. Initial program 84.7%

      \[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. associate-/l*N/A

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{z - x}{t}, y, x\right)} \]
    5. Taylor expanded in x around 0

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{z}{t}}, y, x\right) \]
    6. Step-by-step derivation
      1. lower-/.f6482.7

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

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{z}{t}}, y, x\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification86.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -5.8 \cdot 10^{+72}:\\ \;\;\;\;x + \frac{z \cdot y}{t}\\ \mathbf{elif}\;z \leq 2.65 \cdot 10^{-5}:\\ \;\;\;\;\left(1 - \frac{y}{t}\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 72.6% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -1.8 \cdot 10^{-249} \lor \neg \left(z \leq -1.15 \cdot 10^{-299}\right):\\ \;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\ \mathbf{else}:\\ \;\;\;\;\left(-x\right) \cdot \frac{y}{t}\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (if (or (<= z -1.8e-249) (not (<= z -1.15e-299)))
   (fma (/ z t) y x)
   (* (- x) (/ y t))))
double code(double x, double y, double z, double t) {
	double tmp;
	if ((z <= -1.8e-249) || !(z <= -1.15e-299)) {
		tmp = fma((z / t), y, x);
	} else {
		tmp = -x * (y / t);
	}
	return tmp;
}
function code(x, y, z, t)
	tmp = 0.0
	if ((z <= -1.8e-249) || !(z <= -1.15e-299))
		tmp = fma(Float64(z / t), y, x);
	else
		tmp = Float64(Float64(-x) * Float64(y / t));
	end
	return tmp
end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -1.8e-249], N[Not[LessEqual[z, -1.15e-299]], $MachinePrecision]], N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision], N[((-x) * N[(y / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.8 \cdot 10^{-249} \lor \neg \left(z \leq -1.15 \cdot 10^{-299}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -1.79999999999999997e-249 or -1.15e-299 < z

    1. Initial program 91.3%

      \[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. associate-/l*N/A

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{z - x}{t}, y, x\right)} \]
    5. Taylor expanded in x around 0

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{z}{t}}, y, x\right) \]
    6. Step-by-step derivation
      1. lower-/.f6473.4

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

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

    if -1.79999999999999997e-249 < z < -1.15e-299

    1. Initial program 99.7%

      \[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. *-commutativeN/A

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

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

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

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

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

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

        \[\leadsto \left(-x\right) \cdot \color{blue}{\frac{y}{t}} \]
    8. Recombined 2 regimes into one program.
    9. Final simplification74.3%

      \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.8 \cdot 10^{-249} \lor \neg \left(z \leq -1.15 \cdot 10^{-299}\right):\\ \;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\ \mathbf{else}:\\ \;\;\;\;\left(-x\right) \cdot \frac{y}{t}\\ \end{array} \]
    10. Add Preprocessing

    Alternative 6: 73.0% accurate, 1.3× speedup?

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

      \[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. associate-/l*N/A

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{z - x}{t}, y, x\right)} \]
    5. Taylor expanded in x around 0

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{z}{t}}, y, x\right) \]
    6. Step-by-step derivation
      1. lower-/.f6470.9

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{z}{t}}, y, x\right) \]
    7. Applied rewrites70.9%

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

    Alternative 7: 40.5% accurate, 1.4× speedup?

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

      \[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. associate-/l*N/A

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

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

        \[\leadsto \color{blue}{\frac{z}{t} \cdot y} \]
      4. lower-/.f6434.9

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

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

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

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

      Developer Target 1: 90.6% 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 2024337 
      (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)))