Average Error: 4.8 → 1.5
Time: 1.2m
Precision: 64
\[x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right)\]
\[\begin{array}{l} \mathbf{if}\;\frac{y}{z} - \frac{t}{1 - z} \le -2.748707763553094698981702531479295582825 \cdot 10^{297}:\\ \;\;\;\;\frac{y \cdot x}{z}\\ \mathbf{elif}\;\frac{y}{z} - \frac{t}{1 - z} \le 1.828810479255876918729862119811362710825 \cdot 10^{306}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{1}{z}, t \cdot \frac{-1}{1 - z}\right) \cdot x + x \cdot 0\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot x}{z}\\ \end{array}\]
x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right)
\begin{array}{l}
\mathbf{if}\;\frac{y}{z} - \frac{t}{1 - z} \le -2.748707763553094698981702531479295582825 \cdot 10^{297}:\\
\;\;\;\;\frac{y \cdot x}{z}\\

\mathbf{elif}\;\frac{y}{z} - \frac{t}{1 - z} \le 1.828810479255876918729862119811362710825 \cdot 10^{306}:\\
\;\;\;\;\mathsf{fma}\left(y, \frac{1}{z}, t \cdot \frac{-1}{1 - z}\right) \cdot x + x \cdot 0\\

\mathbf{else}:\\
\;\;\;\;\frac{y \cdot x}{z}\\

\end{array}
double f(double x, double y, double z, double t) {
        double r15776244 = x;
        double r15776245 = y;
        double r15776246 = z;
        double r15776247 = r15776245 / r15776246;
        double r15776248 = t;
        double r15776249 = 1.0;
        double r15776250 = r15776249 - r15776246;
        double r15776251 = r15776248 / r15776250;
        double r15776252 = r15776247 - r15776251;
        double r15776253 = r15776244 * r15776252;
        return r15776253;
}

double f(double x, double y, double z, double t) {
        double r15776254 = y;
        double r15776255 = z;
        double r15776256 = r15776254 / r15776255;
        double r15776257 = t;
        double r15776258 = 1.0;
        double r15776259 = r15776258 - r15776255;
        double r15776260 = r15776257 / r15776259;
        double r15776261 = r15776256 - r15776260;
        double r15776262 = -2.7487077635530947e+297;
        bool r15776263 = r15776261 <= r15776262;
        double r15776264 = x;
        double r15776265 = r15776254 * r15776264;
        double r15776266 = r15776265 / r15776255;
        double r15776267 = 1.828810479255877e+306;
        bool r15776268 = r15776261 <= r15776267;
        double r15776269 = 1.0;
        double r15776270 = r15776269 / r15776255;
        double r15776271 = -1.0;
        double r15776272 = r15776271 / r15776259;
        double r15776273 = r15776257 * r15776272;
        double r15776274 = fma(r15776254, r15776270, r15776273);
        double r15776275 = r15776274 * r15776264;
        double r15776276 = 0.0;
        double r15776277 = r15776264 * r15776276;
        double r15776278 = r15776275 + r15776277;
        double r15776279 = r15776268 ? r15776278 : r15776266;
        double r15776280 = r15776263 ? r15776266 : r15776279;
        return r15776280;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original4.8
Target4.4
Herbie1.5
\[\begin{array}{l} \mathbf{if}\;x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right) \lt -7.623226303312042442144691872793570510727 \cdot 10^{-196}:\\ \;\;\;\;x \cdot \left(\frac{y}{z} - t \cdot \frac{1}{1 - z}\right)\\ \mathbf{elif}\;x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right) \lt 1.413394492770230216018398633584271456447 \cdot 10^{-211}:\\ \;\;\;\;\frac{y \cdot x}{z} + \left(-\frac{t \cdot x}{1 - z}\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\frac{y}{z} - t \cdot \frac{1}{1 - z}\right)\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if (- (/ y z) (/ t (- 1.0 z))) < -2.7487077635530947e+297 or 1.828810479255877e+306 < (- (/ y z) (/ t (- 1.0 z)))

    1. Initial program 57.0

      \[x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right)\]
    2. Taylor expanded around 0 3.6

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

    if -2.7487077635530947e+297 < (- (/ y z) (/ t (- 1.0 z))) < 1.828810479255877e+306

    1. Initial program 1.3

      \[x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right)\]
    2. Using strategy rm
    3. Applied div-inv1.3

      \[\leadsto x \cdot \left(\frac{y}{z} - \color{blue}{t \cdot \frac{1}{1 - z}}\right)\]
    4. Applied div-inv1.4

      \[\leadsto x \cdot \left(\color{blue}{y \cdot \frac{1}{z}} - t \cdot \frac{1}{1 - z}\right)\]
    5. Applied prod-diff1.4

      \[\leadsto x \cdot \color{blue}{\left(\mathsf{fma}\left(y, \frac{1}{z}, -\frac{1}{1 - z} \cdot t\right) + \mathsf{fma}\left(-\frac{1}{1 - z}, t, \frac{1}{1 - z} \cdot t\right)\right)}\]
    6. Applied distribute-rgt-in1.4

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, \frac{1}{z}, -\frac{1}{1 - z} \cdot t\right) \cdot x + \mathsf{fma}\left(-\frac{1}{1 - z}, t, \frac{1}{1 - z} \cdot t\right) \cdot x}\]
    7. Taylor expanded around 0 1.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{y}{z} - \frac{t}{1 - z} \le -2.748707763553094698981702531479295582825 \cdot 10^{297}:\\ \;\;\;\;\frac{y \cdot x}{z}\\ \mathbf{elif}\;\frac{y}{z} - \frac{t}{1 - z} \le 1.828810479255876918729862119811362710825 \cdot 10^{306}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{1}{z}, t \cdot \frac{-1}{1 - z}\right) \cdot x + x \cdot 0\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot x}{z}\\ \end{array}\]

Reproduce

herbie shell --seed 2019168 +o rules:numerics
(FPCore (x y z t)
  :name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, C"

  :herbie-target
  (if (< (* x (- (/ y z) (/ t (- 1.0 z)))) -7.623226303312042e-196) (* x (- (/ y z) (* t (/ 1.0 (- 1.0 z))))) (if (< (* x (- (/ y z) (/ t (- 1.0 z)))) 1.4133944927702302e-211) (+ (/ (* y x) z) (- (/ (* t x) (- 1.0 z)))) (* x (- (/ y z) (* t (/ 1.0 (- 1.0 z)))))))

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