Average Error: 4.6 → 4.2
Time: 22.5s
Precision: 64
\[x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right)\]
\[\begin{array}{l} \mathbf{if}\;z \le -2.217796665303530773920617159755679745171 \cdot 10^{63}:\\ \;\;\;\;x \cdot \left(\mathsf{fma}\left(\frac{-1}{1 - z}, t, \frac{1}{1 - z} \cdot t\right) + \mathsf{fma}\left(y, \frac{1}{z}, \frac{-1}{1 - z} \cdot t\right)\right)\\ \mathbf{elif}\;z \le 1.498822532020549452647469645076704014499 \cdot 10^{-298}:\\ \;\;\;\;\frac{x \cdot \left(y \cdot \left(1 - z\right) - z \cdot t\right)}{z \cdot \left(1 - z\right)}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\mathsf{fma}\left(\frac{-1}{1 - z}, t, \frac{1}{1 - z} \cdot t\right) + \mathsf{fma}\left(y, \frac{1}{z}, \frac{-1}{1 - z} \cdot t\right)\right)\\ \end{array}\]
x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right)
\begin{array}{l}
\mathbf{if}\;z \le -2.217796665303530773920617159755679745171 \cdot 10^{63}:\\
\;\;\;\;x \cdot \left(\mathsf{fma}\left(\frac{-1}{1 - z}, t, \frac{1}{1 - z} \cdot t\right) + \mathsf{fma}\left(y, \frac{1}{z}, \frac{-1}{1 - z} \cdot t\right)\right)\\

\mathbf{elif}\;z \le 1.498822532020549452647469645076704014499 \cdot 10^{-298}:\\
\;\;\;\;\frac{x \cdot \left(y \cdot \left(1 - z\right) - z \cdot t\right)}{z \cdot \left(1 - z\right)}\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r16103153 = x;
        double r16103154 = y;
        double r16103155 = z;
        double r16103156 = r16103154 / r16103155;
        double r16103157 = t;
        double r16103158 = 1.0;
        double r16103159 = r16103158 - r16103155;
        double r16103160 = r16103157 / r16103159;
        double r16103161 = r16103156 - r16103160;
        double r16103162 = r16103153 * r16103161;
        return r16103162;
}

double f(double x, double y, double z, double t) {
        double r16103163 = z;
        double r16103164 = -2.2177966653035308e+63;
        bool r16103165 = r16103163 <= r16103164;
        double r16103166 = x;
        double r16103167 = -1.0;
        double r16103168 = 1.0;
        double r16103169 = r16103168 - r16103163;
        double r16103170 = r16103167 / r16103169;
        double r16103171 = t;
        double r16103172 = 1.0;
        double r16103173 = r16103172 / r16103169;
        double r16103174 = r16103173 * r16103171;
        double r16103175 = fma(r16103170, r16103171, r16103174);
        double r16103176 = y;
        double r16103177 = r16103172 / r16103163;
        double r16103178 = r16103170 * r16103171;
        double r16103179 = fma(r16103176, r16103177, r16103178);
        double r16103180 = r16103175 + r16103179;
        double r16103181 = r16103166 * r16103180;
        double r16103182 = 1.4988225320205495e-298;
        bool r16103183 = r16103163 <= r16103182;
        double r16103184 = r16103176 * r16103169;
        double r16103185 = r16103163 * r16103171;
        double r16103186 = r16103184 - r16103185;
        double r16103187 = r16103166 * r16103186;
        double r16103188 = r16103163 * r16103169;
        double r16103189 = r16103187 / r16103188;
        double r16103190 = r16103183 ? r16103189 : r16103181;
        double r16103191 = r16103165 ? r16103181 : r16103190;
        return r16103191;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original4.6
Target4.2
Herbie4.2
\[\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 z < -2.2177966653035308e+63 or 1.4988225320205495e-298 < z

    1. Initial program 3.6

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

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

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

      \[\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)}\]

    if -2.2177966653035308e+63 < z < 1.4988225320205495e-298

    1. Initial program 7.6

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -2.217796665303530773920617159755679745171 \cdot 10^{63}:\\ \;\;\;\;x \cdot \left(\mathsf{fma}\left(\frac{-1}{1 - z}, t, \frac{1}{1 - z} \cdot t\right) + \mathsf{fma}\left(y, \frac{1}{z}, \frac{-1}{1 - z} \cdot t\right)\right)\\ \mathbf{elif}\;z \le 1.498822532020549452647469645076704014499 \cdot 10^{-298}:\\ \;\;\;\;\frac{x \cdot \left(y \cdot \left(1 - z\right) - z \cdot t\right)}{z \cdot \left(1 - z\right)}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\mathsf{fma}\left(\frac{-1}{1 - z}, t, \frac{1}{1 - z} \cdot t\right) + \mathsf{fma}\left(y, \frac{1}{z}, \frac{-1}{1 - z} \cdot t\right)\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019172 +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)))))