Average Error: 6.2 → 0.5
Time: 2.6s
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 r303184 = x;
        double r303185 = y;
        double r303186 = z;
        double r303187 = t;
        double r303188 = r303186 - r303187;
        double r303189 = r303185 * r303188;
        double r303190 = a;
        double r303191 = r303189 / r303190;
        double r303192 = r303184 + r303191;
        return r303192;
}

double f(double x, double y, double z, double t, double a) {
        double r303193 = y;
        double r303194 = z;
        double r303195 = t;
        double r303196 = r303194 - r303195;
        double r303197 = r303193 * r303196;
        double r303198 = -1.844830222125782e+209;
        bool r303199 = r303197 <= r303198;
        double r303200 = a;
        double r303201 = r303193 / r303200;
        double r303202 = x;
        double r303203 = fma(r303201, r303196, r303202);
        double r303204 = 4.770519707327167e+192;
        bool r303205 = r303197 <= r303204;
        double r303206 = 1.0;
        double r303207 = r303200 / r303197;
        double r303208 = r303206 / r303207;
        double r303209 = r303202 + r303208;
        double r303210 = r303196 / r303200;
        double r303211 = r303193 * r303210;
        double r303212 = r303202 + r303211;
        double r303213 = r303205 ? r303209 : r303212;
        double r303214 = r303199 ? r303203 : r303213;
        return r303214;
}

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)))