Average Error: 5.6 → 1.5
Time: 18.7s
Precision: 64
\[x - \frac{y \cdot \left(z - t\right)}{a}\]
\[\begin{array}{l} \mathbf{if}\;x - \frac{y \cdot \left(z - t\right)}{a} = -\infty:\\ \;\;\;\;\mathsf{fma}\left(t - z, \frac{y}{a}, x\right)\\ \mathbf{elif}\;x - \frac{y \cdot \left(z - t\right)}{a} \le 9.136892539129485 \cdot 10^{-243}:\\ \;\;\;\;x - \frac{y \cdot \left(z - t\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(t - z, \frac{y}{a}, x\right)\\ \end{array}\]
x - \frac{y \cdot \left(z - t\right)}{a}
\begin{array}{l}
\mathbf{if}\;x - \frac{y \cdot \left(z - t\right)}{a} = -\infty:\\
\;\;\;\;\mathsf{fma}\left(t - z, \frac{y}{a}, x\right)\\

\mathbf{elif}\;x - \frac{y \cdot \left(z - t\right)}{a} \le 9.136892539129485 \cdot 10^{-243}:\\
\;\;\;\;x - \frac{y \cdot \left(z - t\right)}{a}\\

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

\end{array}
double f(double x, double y, double z, double t, double a) {
        double r13031694 = x;
        double r13031695 = y;
        double r13031696 = z;
        double r13031697 = t;
        double r13031698 = r13031696 - r13031697;
        double r13031699 = r13031695 * r13031698;
        double r13031700 = a;
        double r13031701 = r13031699 / r13031700;
        double r13031702 = r13031694 - r13031701;
        return r13031702;
}

double f(double x, double y, double z, double t, double a) {
        double r13031703 = x;
        double r13031704 = y;
        double r13031705 = z;
        double r13031706 = t;
        double r13031707 = r13031705 - r13031706;
        double r13031708 = r13031704 * r13031707;
        double r13031709 = a;
        double r13031710 = r13031708 / r13031709;
        double r13031711 = r13031703 - r13031710;
        double r13031712 = -inf.0;
        bool r13031713 = r13031711 <= r13031712;
        double r13031714 = r13031706 - r13031705;
        double r13031715 = r13031704 / r13031709;
        double r13031716 = fma(r13031714, r13031715, r13031703);
        double r13031717 = 9.136892539129485e-243;
        bool r13031718 = r13031711 <= r13031717;
        double r13031719 = r13031718 ? r13031711 : r13031716;
        double r13031720 = r13031713 ? r13031716 : r13031719;
        return r13031720;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Bits error versus a

Target

Original5.6
Target0.7
Herbie1.5
\[\begin{array}{l} \mathbf{if}\;y \lt -1.0761266216389975 \cdot 10^{-10}:\\ \;\;\;\;x - \frac{1}{\frac{\frac{a}{z - t}}{y}}\\ \mathbf{elif}\;y \lt 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 (- x (/ (* y (- z t)) a)) < -inf.0 or 9.136892539129485e-243 < (- x (/ (* y (- z t)) a))

    1. Initial program 10.1

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

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

    if -inf.0 < (- x (/ (* y (- z t)) a)) < 9.136892539129485e-243

    1. Initial program 0.5

      \[x - \frac{y \cdot \left(z - t\right)}{a}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification1.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;x - \frac{y \cdot \left(z - t\right)}{a} = -\infty:\\ \;\;\;\;\mathsf{fma}\left(t - z, \frac{y}{a}, x\right)\\ \mathbf{elif}\;x - \frac{y \cdot \left(z - t\right)}{a} \le 9.136892539129485 \cdot 10^{-243}:\\ \;\;\;\;x - \frac{y \cdot \left(z - t\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(t - z, \frac{y}{a}, x\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019164 +o rules:numerics
(FPCore (x y z t a)
  :name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, F"

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

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