Average Error: 6.2 → 0.5
Time: 3.0s
Precision: 64
\[x + \frac{y \cdot \left(z - t\right)}{a}\]
\[\begin{array}{l} \mathbf{if}\;y \cdot \left(z - t\right) \le -1.8448302221257819 \cdot 10^{209}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{a}, z - t, x\right)\\ \mathbf{elif}\;y \cdot \left(z - t\right) \le 4.77051970732716704 \cdot 10^{192}:\\ \;\;\;\;x + \frac{1}{\frac{a}{y \cdot \left(z - t\right)}}\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \frac{z - t}{a}\\ \end{array}\]
x + \frac{y \cdot \left(z - t\right)}{a}
\begin{array}{l}
\mathbf{if}\;y \cdot \left(z - t\right) \le -1.8448302221257819 \cdot 10^{209}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{a}, z - t, x\right)\\

\mathbf{elif}\;y \cdot \left(z - t\right) \le 4.77051970732716704 \cdot 10^{192}:\\
\;\;\;\;x + \frac{1}{\frac{a}{y \cdot \left(z - t\right)}}\\

\mathbf{else}:\\
\;\;\;\;x + y \cdot \frac{z - t}{a}\\

\end{array}
double f(double x, double y, double z, double t, double a) {
        double r311768 = x;
        double r311769 = y;
        double r311770 = z;
        double r311771 = t;
        double r311772 = r311770 - r311771;
        double r311773 = r311769 * r311772;
        double r311774 = a;
        double r311775 = r311773 / r311774;
        double r311776 = r311768 + r311775;
        return r311776;
}

double f(double x, double y, double z, double t, double a) {
        double r311777 = y;
        double r311778 = z;
        double r311779 = t;
        double r311780 = r311778 - r311779;
        double r311781 = r311777 * r311780;
        double r311782 = -1.844830222125782e+209;
        bool r311783 = r311781 <= r311782;
        double r311784 = a;
        double r311785 = r311777 / r311784;
        double r311786 = x;
        double r311787 = fma(r311785, r311780, r311786);
        double r311788 = 4.770519707327167e+192;
        bool r311789 = r311781 <= r311788;
        double r311790 = 1.0;
        double r311791 = r311784 / r311781;
        double r311792 = r311790 / r311791;
        double r311793 = r311786 + r311792;
        double r311794 = r311780 / r311784;
        double r311795 = r311777 * r311794;
        double r311796 = r311786 + r311795;
        double r311797 = r311789 ? r311793 : r311796;
        double r311798 = r311783 ? r311787 : r311797;
        return r311798;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Bits error versus a

Target

Original6.2
Target0.7
Herbie0.5
\[\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)) < -1.844830222125782e+209

    1. Initial program 30.2

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

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

    if -1.844830222125782e+209 < (* y (- z t)) < 4.770519707327167e+192

    1. Initial program 0.3

      \[x + \frac{y \cdot \left(z - t\right)}{a}\]
    2. Using strategy rm
    3. Applied clear-num0.4

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

    if 4.770519707327167e+192 < (* y (- z t))

    1. Initial program 27.1

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

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

      \[\leadsto x + \color{blue}{\frac{y}{1} \cdot \frac{z - t}{a}}\]
    5. Simplified1.0

      \[\leadsto x + \color{blue}{y} \cdot \frac{z - t}{a}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot \left(z - t\right) \le -1.8448302221257819 \cdot 10^{209}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{a}, z - t, x\right)\\ \mathbf{elif}\;y \cdot \left(z - t\right) \le 4.77051970732716704 \cdot 10^{192}:\\ \;\;\;\;x + \frac{1}{\frac{a}{y \cdot \left(z - t\right)}}\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \frac{z - t}{a}\\ \end{array}\]

Reproduce

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

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