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

\mathbf{elif}\;a \leq 6.2 \cdot 10^{-5}:\\
\;\;\;\;x + \frac{\mathsf{fma}\left(z, y, y \cdot \left(-t\right)\right)}{a}\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Bits error versus a

Target

Original6.5
Target0.6
Herbie0.6
\[\begin{array}{l} \mathbf{if}\;y < -1.0761266216389975 \cdot 10^{-10}:\\ \;\;\;\;x + \frac{1}{\frac{\frac{a}{z - t}}{y}}\\ \mathbf{elif}\;y < 2.894426862792089 \cdot 10^{-49}:\\ \;\;\;\;x + \frac{y \cdot \left(z - t\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y}{\frac{a}{z - t}}\\ \end{array} \]

Derivation

  1. Split input into 2 regimes
  2. if a < -6.00000000000000057e-20 or 6.20000000000000027e-5 < a

    1. Initial program 9.6

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

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

    if -6.00000000000000057e-20 < a < 6.20000000000000027e-5

    1. Initial program 0.8

      \[x + \frac{y \cdot \left(z - t\right)}{a} \]
    2. Applied egg-rr0.8

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

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

Reproduce

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

  :herbie-target
  (if (< y -1.0761266216389975e-10) (+ x (/ 1.0 (/ (/ a (- z t)) y))) (if (< y 2.894426862792089e-49) (+ x (/ (* y (- z t)) a)) (+ x (/ y (/ a (- z t))))))

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