Average Error: 4.6 → 1.5
Time: 20.3s
Precision: 64
\[x \cdot \left(\frac{y}{z} - \frac{t}{1.0 - z}\right)\]
\[\begin{array}{l} \mathbf{if}\;\frac{y}{z} - \frac{t}{1.0 - z} \le -2.7487077635530947 \cdot 10^{+297}:\\ \;\;\;\;\frac{y \cdot x}{z}\\ \mathbf{elif}\;\frac{y}{z} - \frac{t}{1.0 - z} \le 1.828810479255877 \cdot 10^{+306}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{1}{z}, t \cdot \frac{-1}{1.0 - z}\right) \cdot x + x \cdot \mathsf{fma}\left(\frac{-1}{1.0 - z}, t, t \cdot \frac{1}{1.0 - z}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot x}{z}\\ \end{array}\]
x \cdot \left(\frac{y}{z} - \frac{t}{1.0 - z}\right)
\begin{array}{l}
\mathbf{if}\;\frac{y}{z} - \frac{t}{1.0 - z} \le -2.7487077635530947 \cdot 10^{+297}:\\
\;\;\;\;\frac{y \cdot x}{z}\\

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

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

\end{array}
double f(double x, double y, double z, double t) {
        double r18611876 = x;
        double r18611877 = y;
        double r18611878 = z;
        double r18611879 = r18611877 / r18611878;
        double r18611880 = t;
        double r18611881 = 1.0;
        double r18611882 = r18611881 - r18611878;
        double r18611883 = r18611880 / r18611882;
        double r18611884 = r18611879 - r18611883;
        double r18611885 = r18611876 * r18611884;
        return r18611885;
}

double f(double x, double y, double z, double t) {
        double r18611886 = y;
        double r18611887 = z;
        double r18611888 = r18611886 / r18611887;
        double r18611889 = t;
        double r18611890 = 1.0;
        double r18611891 = r18611890 - r18611887;
        double r18611892 = r18611889 / r18611891;
        double r18611893 = r18611888 - r18611892;
        double r18611894 = -2.7487077635530947e+297;
        bool r18611895 = r18611893 <= r18611894;
        double r18611896 = x;
        double r18611897 = r18611886 * r18611896;
        double r18611898 = r18611897 / r18611887;
        double r18611899 = 1.828810479255877e+306;
        bool r18611900 = r18611893 <= r18611899;
        double r18611901 = 1.0;
        double r18611902 = r18611901 / r18611887;
        double r18611903 = -1.0;
        double r18611904 = r18611903 / r18611891;
        double r18611905 = r18611889 * r18611904;
        double r18611906 = fma(r18611886, r18611902, r18611905);
        double r18611907 = r18611906 * r18611896;
        double r18611908 = r18611901 / r18611891;
        double r18611909 = r18611889 * r18611908;
        double r18611910 = fma(r18611904, r18611889, r18611909);
        double r18611911 = r18611896 * r18611910;
        double r18611912 = r18611907 + r18611911;
        double r18611913 = r18611900 ? r18611912 : r18611898;
        double r18611914 = r18611895 ? r18611898 : r18611913;
        return r18611914;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original4.6
Target4.2
Herbie1.5
\[\begin{array}{l} \mathbf{if}\;x \cdot \left(\frac{y}{z} - \frac{t}{1.0 - z}\right) \lt -7.623226303312042 \cdot 10^{-196}:\\ \;\;\;\;x \cdot \left(\frac{y}{z} - t \cdot \frac{1}{1.0 - z}\right)\\ \mathbf{elif}\;x \cdot \left(\frac{y}{z} - \frac{t}{1.0 - z}\right) \lt 1.4133944927702302 \cdot 10^{-211}:\\ \;\;\;\;\frac{y \cdot x}{z} + \left(-\frac{t \cdot x}{1.0 - z}\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\frac{y}{z} - t \cdot \frac{1}{1.0 - 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 53.5

      \[x \cdot \left(\frac{y}{z} - \frac{t}{1.0 - 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.0 - 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.0 - z}}\right)\]
    4. Applied div-inv1.4

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{y}{z} - \frac{t}{1.0 - z} \le -2.7487077635530947 \cdot 10^{+297}:\\ \;\;\;\;\frac{y \cdot x}{z}\\ \mathbf{elif}\;\frac{y}{z} - \frac{t}{1.0 - z} \le 1.828810479255877 \cdot 10^{+306}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{1}{z}, t \cdot \frac{-1}{1.0 - z}\right) \cdot x + x \cdot \mathsf{fma}\left(\frac{-1}{1.0 - z}, t, t \cdot \frac{1}{1.0 - z}\right)\\ \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 (- 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 (- 1.0 z)))))))

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