Average Error: 6.2 → 2.5
Time: 4.4s
Precision: binary64
\[x + \frac{y \cdot \left(z - x\right)}{t} \]
\[\begin{array}{l} \mathbf{if}\;t \leq -1 \cdot 10^{+94}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{z - x}{t}, x\right)\\ \mathbf{elif}\;t \leq 3.35 \cdot 10^{-150}:\\ \;\;\;\;\left(x + \frac{y \cdot z}{t}\right) - \frac{y \cdot x}{t}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, {\left(\frac{t}{z - x}\right)}^{-1}, x\right)\\ \end{array} \]
(FPCore (x y z t) :precision binary64 (+ x (/ (* y (- z x)) t)))
(FPCore (x y z t)
 :precision binary64
 (if (<= t -1e+94)
   (fma y (/ (- z x) t) x)
   (if (<= t 3.35e-150)
     (- (+ x (/ (* y z) t)) (/ (* y x) t))
     (fma y (pow (/ t (- z x)) -1.0) 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 tmp;
	if (t <= -1e+94) {
		tmp = fma(y, ((z - x) / t), x);
	} else if (t <= 3.35e-150) {
		tmp = (x + ((y * z) / t)) - ((y * x) / t);
	} else {
		tmp = fma(y, pow((t / (z - x)), -1.0), 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)
	tmp = 0.0
	if (t <= -1e+94)
		tmp = fma(y, Float64(Float64(z - x) / t), x);
	elseif (t <= 3.35e-150)
		tmp = Float64(Float64(x + Float64(Float64(y * z) / t)) - Float64(Float64(y * x) / t));
	else
		tmp = fma(y, (Float64(t / Float64(z - x)) ^ -1.0), 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_] := If[LessEqual[t, -1e+94], N[(y * N[(N[(z - x), $MachinePrecision] / t), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[t, 3.35e-150], N[(N[(x + N[(N[(y * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision] - N[(N[(y * x), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], N[(y * N[Power[N[(t / N[(z - x), $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision] + x), $MachinePrecision]]]
x + \frac{y \cdot \left(z - x\right)}{t}
\begin{array}{l}
\mathbf{if}\;t \leq -1 \cdot 10^{+94}:\\
\;\;\;\;\mathsf{fma}\left(y, \frac{z - x}{t}, x\right)\\

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

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, {\left(\frac{t}{z - x}\right)}^{-1}, 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
Herbie2.5
\[x - \left(x \cdot \frac{y}{t} + \left(-z\right) \cdot \frac{y}{t}\right) \]

Derivation

  1. Split input into 3 regimes
  2. if t < -1e94

    1. Initial program 11.2

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

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

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

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

    if -1e94 < t < 3.3499999999999998e-150

    1. Initial program 3.0

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

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

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

    if 3.3499999999999998e-150 < t

    1. Initial program 6.3

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

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

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

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

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

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

Reproduce

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