Average Error: 16.8 → 8.9
Time: 5.4s
Precision: 64
\[\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t}\]
\[\begin{array}{l} \mathbf{if}\;t \le -4.4429033246165504 \cdot 10^{125} \lor \neg \left(t \le 2.5348533825902453 \cdot 10^{87}\right):\\ \;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{t - z}{\frac{a}{y} - \frac{t}{y}} + \left(x + y\right)\\ \end{array}\]
\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t}
\begin{array}{l}
\mathbf{if}\;t \le -4.4429033246165504 \cdot 10^{125} \lor \neg \left(t \le 2.5348533825902453 \cdot 10^{87}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\

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

\end{array}
double f(double x, double y, double z, double t, double a) {
        double r683814 = x;
        double r683815 = y;
        double r683816 = r683814 + r683815;
        double r683817 = z;
        double r683818 = t;
        double r683819 = r683817 - r683818;
        double r683820 = r683819 * r683815;
        double r683821 = a;
        double r683822 = r683821 - r683818;
        double r683823 = r683820 / r683822;
        double r683824 = r683816 - r683823;
        return r683824;
}

double f(double x, double y, double z, double t, double a) {
        double r683825 = t;
        double r683826 = -4.4429033246165504e+125;
        bool r683827 = r683825 <= r683826;
        double r683828 = 2.5348533825902453e+87;
        bool r683829 = r683825 <= r683828;
        double r683830 = !r683829;
        bool r683831 = r683827 || r683830;
        double r683832 = z;
        double r683833 = r683832 / r683825;
        double r683834 = y;
        double r683835 = x;
        double r683836 = fma(r683833, r683834, r683835);
        double r683837 = r683825 - r683832;
        double r683838 = a;
        double r683839 = r683838 / r683834;
        double r683840 = r683825 / r683834;
        double r683841 = r683839 - r683840;
        double r683842 = r683837 / r683841;
        double r683843 = r683835 + r683834;
        double r683844 = r683842 + r683843;
        double r683845 = r683831 ? r683836 : r683844;
        return r683845;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Bits error versus a

Target

Original16.8
Target8.6
Herbie8.9
\[\begin{array}{l} \mathbf{if}\;\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t} \lt -1.3664970889390727 \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.47542934445772333 \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 t < -4.4429033246165504e+125 or 2.5348533825902453e+87 < t

    1. Initial program 30.8

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

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

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{1}{\frac{a - t}{y}}}, t - z, x + y\right)\]
    5. Using strategy rm
    6. Applied fma-udef21.8

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

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

      \[\leadsto \color{blue}{\frac{z \cdot y}{t} + x}\]
    9. Simplified12.4

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

    if -4.4429033246165504e+125 < t < 2.5348533825902453e+87

    1. Initial program 9.1

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

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

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{1}{\frac{a - t}{y}}}, t - z, x + y\right)\]
    5. Using strategy rm
    6. Applied fma-udef6.8

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

      \[\leadsto \color{blue}{\frac{t - z}{\frac{a - t}{y}}} + \left(x + y\right)\]
    8. Using strategy rm
    9. Applied div-sub7.0

      \[\leadsto \frac{t - z}{\color{blue}{\frac{a}{y} - \frac{t}{y}}} + \left(x + y\right)\]
  3. Recombined 2 regimes into one program.
  4. Final simplification8.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;t \le -4.4429033246165504 \cdot 10^{125} \lor \neg \left(t \le 2.5348533825902453 \cdot 10^{87}\right):\\ \;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{t - z}{\frac{a}{y} - \frac{t}{y}} + \left(x + y\right)\\ \end{array}\]

Reproduce

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

  :herbie-target
  (if (< (- (+ x y) (/ (* (- z t) y) (- a t))) -1.3664970889390727e-07) (- (+ y x) (* (* (- z t) (/ 1 (- 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 (- a t))) y))))

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