Average Error: 16.4 → 7.5
Time: 20.6s
Precision: 64
\[\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t}\]
\[\begin{array}{l} \mathbf{if}\;a \le -6.922040009532223355771178672816769705828 \cdot 10^{-88}:\\ \;\;\;\;x + \mathsf{fma}\left(y, \frac{t - z}{a - t}, y\right)\\ \mathbf{elif}\;a \le 1.131036177709714559868169922982302657782 \cdot 10^{-203}:\\ \;\;\;\;\frac{y \cdot z}{t} + x\\ \mathbf{else}:\\ \;\;\;\;x + \mathsf{fma}\left(y, \frac{t - z}{a - t}, y\right)\\ \end{array}\]
\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t}
\begin{array}{l}
\mathbf{if}\;a \le -6.922040009532223355771178672816769705828 \cdot 10^{-88}:\\
\;\;\;\;x + \mathsf{fma}\left(y, \frac{t - z}{a - t}, y\right)\\

\mathbf{elif}\;a \le 1.131036177709714559868169922982302657782 \cdot 10^{-203}:\\
\;\;\;\;\frac{y \cdot z}{t} + x\\

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

\end{array}
double f(double x, double y, double z, double t, double a) {
        double r21099462 = x;
        double r21099463 = y;
        double r21099464 = r21099462 + r21099463;
        double r21099465 = z;
        double r21099466 = t;
        double r21099467 = r21099465 - r21099466;
        double r21099468 = r21099467 * r21099463;
        double r21099469 = a;
        double r21099470 = r21099469 - r21099466;
        double r21099471 = r21099468 / r21099470;
        double r21099472 = r21099464 - r21099471;
        return r21099472;
}

double f(double x, double y, double z, double t, double a) {
        double r21099473 = a;
        double r21099474 = -6.922040009532223e-88;
        bool r21099475 = r21099473 <= r21099474;
        double r21099476 = x;
        double r21099477 = y;
        double r21099478 = t;
        double r21099479 = z;
        double r21099480 = r21099478 - r21099479;
        double r21099481 = r21099473 - r21099478;
        double r21099482 = r21099480 / r21099481;
        double r21099483 = fma(r21099477, r21099482, r21099477);
        double r21099484 = r21099476 + r21099483;
        double r21099485 = 1.1310361777097146e-203;
        bool r21099486 = r21099473 <= r21099485;
        double r21099487 = r21099477 * r21099479;
        double r21099488 = r21099487 / r21099478;
        double r21099489 = r21099488 + r21099476;
        double r21099490 = r21099486 ? r21099489 : r21099484;
        double r21099491 = r21099475 ? r21099484 : r21099490;
        return r21099491;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Bits error versus a

Target

Original16.4
Target8.6
Herbie7.5
\[\begin{array}{l} \mathbf{if}\;\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t} \lt -1.366497088939072697550672266103566343531 \cdot 10^{-7}:\\ \;\;\;\;\left(y + x\right) - \left(\left(z - t\right) \cdot \frac{1}{a - t}\right) \cdot y\\ \mathbf{elif}\;\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t} \lt 1.475429344457723334351036314450840066235 \cdot 10^{-239}:\\ \;\;\;\;\frac{y \cdot \left(a - z\right) - x \cdot t}{a - t}\\ \mathbf{else}:\\ \;\;\;\;\left(y + x\right) - \left(\left(z - t\right) \cdot \frac{1}{a - t}\right) \cdot y\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if a < -6.922040009532223e-88 or 1.1310361777097146e-203 < a

    1. Initial program 15.0

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, \frac{t - z}{a - t}, y + x\right)}\]
    3. Using strategy rm
    4. Applied fma-udef9.2

      \[\leadsto \color{blue}{y \cdot \frac{t - z}{a - t} + \left(y + x\right)}\]
    5. Using strategy rm
    6. Applied associate-+r+6.4

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

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

    if -6.922040009532223e-88 < a < 1.1310361777097146e-203

    1. Initial program 20.9

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, \frac{t - z}{a - t}, y + x\right)}\]
    3. Using strategy rm
    4. Applied fma-udef19.9

      \[\leadsto \color{blue}{y \cdot \frac{t - z}{a - t} + \left(y + x\right)}\]
    5. Using strategy rm
    6. Applied associate-+r+13.1

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, \frac{t - z}{a - t}, y\right)} + x\]
    8. Taylor expanded around inf 11.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \le -6.922040009532223355771178672816769705828 \cdot 10^{-88}:\\ \;\;\;\;x + \mathsf{fma}\left(y, \frac{t - z}{a - t}, y\right)\\ \mathbf{elif}\;a \le 1.131036177709714559868169922982302657782 \cdot 10^{-203}:\\ \;\;\;\;\frac{y \cdot z}{t} + x\\ \mathbf{else}:\\ \;\;\;\;x + \mathsf{fma}\left(y, \frac{t - z}{a - t}, y\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019171 +o rules:numerics
(FPCore (x y z t a)
  :name "Graphics.Rendering.Plot.Render.Plot.Axis:renderAxisTick from plot-0.2.3.4, B"

  :herbie-target
  (if (< (- (+ x y) (/ (* (- z t) y) (- a t))) -1.3664970889390727e-07) (- (+ y x) (* (* (- z t) (/ 1.0 (- a t))) y)) (if (< (- (+ x y) (/ (* (- z t) y) (- a t))) 1.4754293444577233e-239) (/ (- (* y (- a z)) (* x t)) (- a t)) (- (+ y x) (* (* (- z t) (/ 1.0 (- a t))) y))))

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