Average Error: 6.3 → 1.4
Time: 2.7s
Precision: 64
\[x - \frac{y \cdot \left(z - t\right)}{a}\]
\[\begin{array}{l} \mathbf{if}\;y \cdot \left(z - t\right) \le -4.9168923767645714 \cdot 10^{80}:\\ \;\;\;\;x - y \cdot \frac{z - t}{a}\\ \mathbf{elif}\;y \cdot \left(z - t\right) \le 2.08730857278766648 \cdot 10^{115}:\\ \;\;\;\;x - \frac{y \cdot \left(z - t\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{a}, t - z, x\right)\\ \end{array}\]
x - \frac{y \cdot \left(z - t\right)}{a}
\begin{array}{l}
\mathbf{if}\;y \cdot \left(z - t\right) \le -4.9168923767645714 \cdot 10^{80}:\\
\;\;\;\;x - y \cdot \frac{z - t}{a}\\

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

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

\end{array}
double f(double x, double y, double z, double t, double a) {
        double r295618 = x;
        double r295619 = y;
        double r295620 = z;
        double r295621 = t;
        double r295622 = r295620 - r295621;
        double r295623 = r295619 * r295622;
        double r295624 = a;
        double r295625 = r295623 / r295624;
        double r295626 = r295618 - r295625;
        return r295626;
}

double f(double x, double y, double z, double t, double a) {
        double r295627 = y;
        double r295628 = z;
        double r295629 = t;
        double r295630 = r295628 - r295629;
        double r295631 = r295627 * r295630;
        double r295632 = -4.916892376764571e+80;
        bool r295633 = r295631 <= r295632;
        double r295634 = x;
        double r295635 = a;
        double r295636 = r295630 / r295635;
        double r295637 = r295627 * r295636;
        double r295638 = r295634 - r295637;
        double r295639 = 2.0873085727876665e+115;
        bool r295640 = r295631 <= r295639;
        double r295641 = r295631 / r295635;
        double r295642 = r295634 - r295641;
        double r295643 = r295627 / r295635;
        double r295644 = r295629 - r295628;
        double r295645 = fma(r295643, r295644, r295634);
        double r295646 = r295640 ? r295642 : r295645;
        double r295647 = r295633 ? r295638 : r295646;
        return r295647;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Bits error versus a

Target

Original6.3
Target0.7
Herbie1.4
\[\begin{array}{l} \mathbf{if}\;y \lt -1.07612662163899753 \cdot 10^{-10}:\\ \;\;\;\;x - \frac{1}{\frac{\frac{a}{z - t}}{y}}\\ \mathbf{elif}\;y \lt 2.8944268627920891 \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 (* y (- z t)) < -4.916892376764571e+80

    1. Initial program 14.6

      \[x - \frac{y \cdot \left(z - t\right)}{a}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity14.6

      \[\leadsto x - \frac{y \cdot \left(z - t\right)}{\color{blue}{1 \cdot a}}\]
    4. Applied times-frac3.8

      \[\leadsto x - \color{blue}{\frac{y}{1} \cdot \frac{z - t}{a}}\]
    5. Simplified3.8

      \[\leadsto x - \color{blue}{y} \cdot \frac{z - t}{a}\]

    if -4.916892376764571e+80 < (* y (- z t)) < 2.0873085727876665e+115

    1. Initial program 0.5

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

    if 2.0873085727876665e+115 < (* y (- z t))

    1. Initial program 18.1

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

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

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

Reproduce

herbie shell --seed 2020046 +o rules:numerics
(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 (/ (/ a (- z t)) y))) (if (< y 2.894426862792089e-49) (- x (/ (* y (- z t)) a)) (- x (/ y (/ a (- z t))))))

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