Average Error: 6.2 → 1.2
Time: 14.3s
Precision: binary64
\[x + \frac{y \cdot \left(z - x\right)}{t} \]
\[\begin{array}{l} t_1 := x + \frac{y \cdot \left(z - x\right)}{t}\\ \mathbf{if}\;t_1 \leq -1.3132758008782921 \cdot 10^{+247}:\\ \;\;\;\;x + \frac{z - x}{\frac{t}{y}}\\ \mathbf{elif}\;t_1 \leq 9.012799917002246 \cdot 10^{+291}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z - x, \frac{y}{t}, x\right)\\ \end{array} \]
(FPCore (x y z t) :precision binary64 (+ x (/ (* y (- z x)) t)))
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (+ x (/ (* y (- z x)) t))))
   (if (<= t_1 -1.3132758008782921e+247)
     (+ x (/ (- z x) (/ t y)))
     (if (<= t_1 9.012799917002246e+291) t_1 (fma (- z x) (/ y t) x)))))
double code(double x, double y, double z, double t) {
	return x + ((y * (z - x)) / t);
}
double code(double x, double y, double z, double t) {
	double t_1 = x + ((y * (z - x)) / t);
	double tmp;
	if (t_1 <= -1.3132758008782921e+247) {
		tmp = x + ((z - x) / (t / y));
	} else if (t_1 <= 9.012799917002246e+291) {
		tmp = t_1;
	} else {
		tmp = fma((z - x), (y / t), x);
	}
	return tmp;
}
function code(x, y, z, t)
	return Float64(x + Float64(Float64(y * Float64(z - x)) / t))
end
function code(x, y, z, t)
	t_1 = Float64(x + Float64(Float64(y * Float64(z - x)) / t))
	tmp = 0.0
	if (t_1 <= -1.3132758008782921e+247)
		tmp = Float64(x + Float64(Float64(z - x) / Float64(t / y)));
	elseif (t_1 <= 9.012799917002246e+291)
		tmp = t_1;
	else
		tmp = fma(Float64(z - x), Float64(y / t), x);
	end
	return tmp
end
code[x_, y_, z_, t_] := N[(x + N[(N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x + N[(N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -1.3132758008782921e+247], N[(x + N[(N[(z - x), $MachinePrecision] / N[(t / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 9.012799917002246e+291], t$95$1, N[(N[(z - x), $MachinePrecision] * N[(y / t), $MachinePrecision] + x), $MachinePrecision]]]]
x + \frac{y \cdot \left(z - x\right)}{t}
\begin{array}{l}
t_1 := x + \frac{y \cdot \left(z - x\right)}{t}\\
\mathbf{if}\;t_1 \leq -1.3132758008782921 \cdot 10^{+247}:\\
\;\;\;\;x + \frac{z - x}{\frac{t}{y}}\\

\mathbf{elif}\;t_1 \leq 9.012799917002246 \cdot 10^{+291}:\\
\;\;\;\;t_1\\

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


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original6.2
Target2.2
Herbie1.2
\[x - \left(x \cdot \frac{y}{t} + \left(-z\right) \cdot \frac{y}{t}\right) \]

Derivation

  1. Split input into 3 regimes
  2. if (+.f64 x (/.f64 (*.f64 y (-.f64 z x)) t)) < -1.3132758008782921e247

    1. Initial program 27.5

      \[x + \frac{y \cdot \left(z - x\right)}{t} \]
    2. Simplified4.2

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

      \[\leadsto \color{blue}{{\left(\sqrt[3]{\mathsf{fma}\left(z - x, \frac{y}{t}, x\right)}\right)}^{3}} \]
    4. Applied egg-rr4.8

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

      \[\leadsto \color{blue}{\left(\frac{y \cdot z}{t} + x\right) - \frac{y \cdot x}{t}} \]
    6. Simplified9.3

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

      \[\leadsto x + \color{blue}{\frac{y \cdot \left(z - x\right)}{t}} \]
    8. Simplified4.0

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

    if -1.3132758008782921e247 < (+.f64 x (/.f64 (*.f64 y (-.f64 z x)) t)) < 9.0127999170022464e291

    1. Initial program 0.8

      \[x + \frac{y \cdot \left(z - x\right)}{t} \]

    if 9.0127999170022464e291 < (+.f64 x (/.f64 (*.f64 y (-.f64 z x)) t))

    1. Initial program 47.2

      \[x + \frac{y \cdot \left(z - x\right)}{t} \]
    2. Simplified2.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x + \frac{y \cdot \left(z - x\right)}{t} \leq -1.3132758008782921 \cdot 10^{+247}:\\ \;\;\;\;x + \frac{z - x}{\frac{t}{y}}\\ \mathbf{elif}\;x + \frac{y \cdot \left(z - x\right)}{t} \leq 9.012799917002246 \cdot 10^{+291}:\\ \;\;\;\;x + \frac{y \cdot \left(z - x\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z - x, \frac{y}{t}, x\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2022153 
(FPCore (x y z t)
  :name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, D"
  :precision binary64

  :herbie-target
  (- x (+ (* x (/ y t)) (* (- z) (/ y t))))

  (+ x (/ (* y (- z x)) t)))