Average Error: 6.1 → 0.7
Time: 5.0s
Precision: binary64
\[x - \frac{y \cdot \left(z - t\right)}{a} \]
\[\begin{array}{l} t_1 := y \cdot \left(z - t\right)\\ \mathbf{if}\;t_1 \leq -5.499918093307507 \cdot 10^{+269}:\\ \;\;\;\;\mathsf{fma}\left(y, \left(z - t\right) \cdot \frac{1}{-a}, x\right)\\ \mathbf{elif}\;t_1 \leq 5.9398726778860405 \cdot 10^{+71}:\\ \;\;\;\;\left(x + \frac{y \cdot t}{a}\right) - \frac{y \cdot z}{a}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(t - z, \frac{y}{a}, x\right)\\ \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 (* y (- z t))))
   (if (<= t_1 -5.499918093307507e+269)
     (fma y (* (- z t) (/ 1.0 (- a))) x)
     (if (<= t_1 5.9398726778860405e+71)
       (- (+ x (/ (* y t) a)) (/ (* y z) a))
       (fma (- t z) (/ y a) x)))))
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 = y * (z - t);
	double tmp;
	if (t_1 <= -5.499918093307507e+269) {
		tmp = fma(y, ((z - t) * (1.0 / -a)), x);
	} else if (t_1 <= 5.9398726778860405e+71) {
		tmp = (x + ((y * t) / a)) - ((y * z) / a);
	} else {
		tmp = fma((t - z), (y / a), x);
	}
	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 = Float64(y * Float64(z - t))
	tmp = 0.0
	if (t_1 <= -5.499918093307507e+269)
		tmp = fma(y, Float64(Float64(z - t) * Float64(1.0 / Float64(-a))), x);
	elseif (t_1 <= 5.9398726778860405e+71)
		tmp = Float64(Float64(x + Float64(Float64(y * t) / a)) - Float64(Float64(y * z) / a));
	else
		tmp = fma(Float64(t - z), Float64(y / a), x);
	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[(z - t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -5.499918093307507e+269], N[(y * N[(N[(z - t), $MachinePrecision] * N[(1.0 / (-a)), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[t$95$1, 5.9398726778860405e+71], N[(N[(x + N[(N[(y * t), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision] - N[(N[(y * z), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(t - z), $MachinePrecision] * N[(y / a), $MachinePrecision] + x), $MachinePrecision]]]]
x - \frac{y \cdot \left(z - t\right)}{a}
\begin{array}{l}
t_1 := y \cdot \left(z - t\right)\\
\mathbf{if}\;t_1 \leq -5.499918093307507 \cdot 10^{+269}:\\
\;\;\;\;\mathsf{fma}\left(y, \left(z - t\right) \cdot \frac{1}{-a}, x\right)\\

\mathbf{elif}\;t_1 \leq 5.9398726778860405 \cdot 10^{+71}:\\
\;\;\;\;\left(x + \frac{y \cdot t}{a}\right) - \frac{y \cdot z}{a}\\

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


\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.1
Target0.6
Herbie0.7
\[\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 3 regimes
  2. if (*.f64 y (-.f64 z t)) < -5.49991809330750669e269

    1. Initial program 46.9

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

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

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

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

    if -5.49991809330750669e269 < (*.f64 y (-.f64 z t)) < 5.9398726778860405e71

    1. Initial program 0.4

      \[x - \frac{y \cdot \left(z - t\right)}{a} \]
    2. Simplified6.9

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

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

    if 5.9398726778860405e71 < (*.f64 y (-.f64 z t))

    1. Initial program 13.3

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

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

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

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

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

Reproduce

herbie shell --seed 2022133 
(FPCore (x y z t a)
  :name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, F"
  :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)))