Average Error: 4.5 → 3.7
Time: 6.5s
Precision: 64
\[x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right)\]
\[\begin{array}{l} \mathbf{if}\;z \le -5.8122912729738608 \cdot 10^{-84} \lor \neg \left(z \le 6.4885262988621568 \cdot 10^{-152}\right):\\ \;\;\;\;x \cdot \left(\frac{y}{z} + \left(-\frac{t}{1 - z}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y, 1 - z, z \cdot \left(-t\right)\right) \cdot x}{z \cdot \left(1 - z\right)}\\ \end{array}\]
x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right)
\begin{array}{l}
\mathbf{if}\;z \le -5.8122912729738608 \cdot 10^{-84} \lor \neg \left(z \le 6.4885262988621568 \cdot 10^{-152}\right):\\
\;\;\;\;x \cdot \left(\frac{y}{z} + \left(-\frac{t}{1 - z}\right)\right)\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r390232 = x;
        double r390233 = y;
        double r390234 = z;
        double r390235 = r390233 / r390234;
        double r390236 = t;
        double r390237 = 1.0;
        double r390238 = r390237 - r390234;
        double r390239 = r390236 / r390238;
        double r390240 = r390235 - r390239;
        double r390241 = r390232 * r390240;
        return r390241;
}

double f(double x, double y, double z, double t) {
        double r390242 = z;
        double r390243 = -5.812291272973861e-84;
        bool r390244 = r390242 <= r390243;
        double r390245 = 6.488526298862157e-152;
        bool r390246 = r390242 <= r390245;
        double r390247 = !r390246;
        bool r390248 = r390244 || r390247;
        double r390249 = x;
        double r390250 = y;
        double r390251 = r390250 / r390242;
        double r390252 = t;
        double r390253 = 1.0;
        double r390254 = r390253 - r390242;
        double r390255 = r390252 / r390254;
        double r390256 = -r390255;
        double r390257 = r390251 + r390256;
        double r390258 = r390249 * r390257;
        double r390259 = -r390252;
        double r390260 = r390242 * r390259;
        double r390261 = fma(r390250, r390254, r390260);
        double r390262 = r390261 * r390249;
        double r390263 = r390242 * r390254;
        double r390264 = r390262 / r390263;
        double r390265 = r390248 ? r390258 : r390264;
        return r390265;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original4.5
Target4.1
Herbie3.7
\[\begin{array}{l} \mathbf{if}\;x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right) \lt -7.62322630331204244 \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.41339449277023022 \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 z < -5.812291272973861e-84 or 6.488526298862157e-152 < z

    1. Initial program 2.5

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

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

    if -5.812291272973861e-84 < z < 6.488526298862157e-152

    1. Initial program 11.0

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

      \[\leadsto x \cdot \color{blue}{\left(\frac{y}{z} + \left(-\frac{t}{1 - z}\right)\right)}\]
    4. Using strategy rm
    5. Applied distribute-neg-frac11.0

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

      \[\leadsto x \cdot \color{blue}{\frac{y \cdot \left(1 - z\right) + z \cdot \left(-t\right)}{z \cdot \left(1 - z\right)}}\]
    7. Applied associate-*r/7.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -5.8122912729738608 \cdot 10^{-84} \lor \neg \left(z \le 6.4885262988621568 \cdot 10^{-152}\right):\\ \;\;\;\;x \cdot \left(\frac{y}{z} + \left(-\frac{t}{1 - z}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y, 1 - z, z \cdot \left(-t\right)\right) \cdot x}{z \cdot \left(1 - z\right)}\\ \end{array}\]

Reproduce

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

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

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