Average Error: 6.4 → 0.9
Time: 4.2s
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 -2 \cdot 10^{+300}:\\ \;\;\;\;\mathsf{fma}\left(z - x, \frac{y}{t}, x\right)\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+276}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x + \frac{z - x}{\frac{t}{y}}\\ \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 -2e+300)
     (fma (- z x) (/ y t) x)
     (if (<= t_1 2e+276) t_1 (+ x (/ (- z x) (/ t y)))))))
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 <= -2e+300) {
		tmp = fma((z - x), (y / t), x);
	} else if (t_1 <= 2e+276) {
		tmp = t_1;
	} else {
		tmp = x + ((z - x) / (t / y));
	}
	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 <= -2e+300)
		tmp = fma(Float64(z - x), Float64(y / t), x);
	elseif (t_1 <= 2e+276)
		tmp = t_1;
	else
		tmp = Float64(x + Float64(Float64(z - x) / Float64(t / y)));
	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, -2e+300], N[(N[(z - x), $MachinePrecision] * N[(y / t), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[t$95$1, 2e+276], t$95$1, N[(x + N[(N[(z - x), $MachinePrecision] / N[(t / y), $MachinePrecision]), $MachinePrecision]), $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 -2 \cdot 10^{+300}:\\
\;\;\;\;\mathsf{fma}\left(z - x, \frac{y}{t}, x\right)\\

\mathbf{elif}\;t_1 \leq 2 \cdot 10^{+276}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;x + \frac{z - x}{\frac{t}{y}}\\


\end{array}

Error

Target

Original6.4
Target2.2
Herbie0.9
\[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)) < -2.0000000000000001e300

    1. Initial program 56.6

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

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

    if -2.0000000000000001e300 < (+.f64 x (/.f64 (*.f64 y (-.f64 z x)) t)) < 2.0000000000000001e276

    1. Initial program 0.8

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

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

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

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

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

    if 2.0000000000000001e276 < (+.f64 x (/.f64 (*.f64 y (-.f64 z x)) t))

    1. Initial program 36.8

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

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

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

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

      \[\leadsto \color{blue}{x + \frac{z - x}{\frac{t}{y}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.9

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

Reproduce

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