Average Error: 4.7 → 3.5
Time: 29.3s
Precision: 64
\[x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right)\]
\[\begin{array}{l} \mathbf{if}\;z \le -2.788516208276912227779895046453297670907 \cdot 10^{-97}:\\ \;\;\;\;x \cdot \left(\left(\frac{y}{z} + \left(-\frac{t}{1 - z}\right)\right) + \mathsf{fma}\left(-\frac{1}{1 - z}, t, \frac{1}{1 - z} \cdot t\right)\right)\\ \mathbf{elif}\;z \le 9547715461.5958919525146484375:\\ \;\;\;\;\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(\left(\frac{y}{z} + \left(-\frac{t}{1 - z}\right)\right) + \mathsf{fma}\left(-\frac{1}{1 - z}, t, \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.788516208276912227779895046453297670907 \cdot 10^{-97}:\\
\;\;\;\;x \cdot \left(\left(\frac{y}{z} + \left(-\frac{t}{1 - z}\right)\right) + \mathsf{fma}\left(-\frac{1}{1 - z}, t, \frac{1}{1 - z} \cdot t\right)\right)\\

\mathbf{elif}\;z \le 9547715461.5958919525146484375:\\
\;\;\;\;\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(\left(\frac{y}{z} + \left(-\frac{t}{1 - z}\right)\right) + \mathsf{fma}\left(-\frac{1}{1 - z}, t, \frac{1}{1 - z} \cdot t\right)\right)\\

\end{array}
double f(double x, double y, double z, double t) {
        double r62353178 = x;
        double r62353179 = y;
        double r62353180 = z;
        double r62353181 = r62353179 / r62353180;
        double r62353182 = t;
        double r62353183 = 1.0;
        double r62353184 = r62353183 - r62353180;
        double r62353185 = r62353182 / r62353184;
        double r62353186 = r62353181 - r62353185;
        double r62353187 = r62353178 * r62353186;
        return r62353187;
}

double f(double x, double y, double z, double t) {
        double r62353188 = z;
        double r62353189 = -2.788516208276912e-97;
        bool r62353190 = r62353188 <= r62353189;
        double r62353191 = x;
        double r62353192 = y;
        double r62353193 = r62353192 / r62353188;
        double r62353194 = t;
        double r62353195 = 1.0;
        double r62353196 = r62353195 - r62353188;
        double r62353197 = r62353194 / r62353196;
        double r62353198 = -r62353197;
        double r62353199 = r62353193 + r62353198;
        double r62353200 = 1.0;
        double r62353201 = r62353200 / r62353196;
        double r62353202 = -r62353201;
        double r62353203 = r62353201 * r62353194;
        double r62353204 = fma(r62353202, r62353194, r62353203);
        double r62353205 = r62353199 + r62353204;
        double r62353206 = r62353191 * r62353205;
        double r62353207 = 9547715461.595892;
        bool r62353208 = r62353188 <= r62353207;
        double r62353209 = r62353192 * r62353196;
        double r62353210 = r62353188 * r62353194;
        double r62353211 = r62353209 - r62353210;
        double r62353212 = r62353191 * r62353211;
        double r62353213 = r62353188 * r62353196;
        double r62353214 = r62353212 / r62353213;
        double r62353215 = r62353208 ? r62353214 : r62353206;
        double r62353216 = r62353190 ? r62353206 : r62353215;
        return r62353216;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original4.7
Target4.5
Herbie3.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 z < -2.788516208276912e-97 or 9547715461.595892 < z

    1. Initial program 2.2

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

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

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

      \[\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. Using strategy rm
    7. Applied associate-*l/2.2

      \[\leadsto x \cdot \left(\mathsf{fma}\left(y, \frac{1}{z}, -\color{blue}{\frac{1 \cdot t}{1 - z}}\right) + \mathsf{fma}\left(-\frac{1}{1 - z}, t, \frac{1}{1 - z} \cdot t\right)\right)\]
    8. Simplified2.2

      \[\leadsto x \cdot \left(\mathsf{fma}\left(y, \frac{1}{z}, -\frac{\color{blue}{t}}{1 - z}\right) + \mathsf{fma}\left(-\frac{1}{1 - z}, t, \frac{1}{1 - z} \cdot t\right)\right)\]
    9. Using strategy rm
    10. Applied fma-udef2.2

      \[\leadsto x \cdot \left(\color{blue}{\left(y \cdot \frac{1}{z} + \left(-\frac{t}{1 - z}\right)\right)} + \mathsf{fma}\left(-\frac{1}{1 - z}, t, \frac{1}{1 - z} \cdot t\right)\right)\]
    11. Simplified2.2

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

    if -2.788516208276912e-97 < z < 9547715461.595892

    1. Initial program 9.5

      \[x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right)\]
    2. Using strategy rm
    3. Applied frac-sub9.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/6.0

      \[\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 simplification3.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -2.788516208276912227779895046453297670907 \cdot 10^{-97}:\\ \;\;\;\;x \cdot \left(\left(\frac{y}{z} + \left(-\frac{t}{1 - z}\right)\right) + \mathsf{fma}\left(-\frac{1}{1 - z}, t, \frac{1}{1 - z} \cdot t\right)\right)\\ \mathbf{elif}\;z \le 9547715461.5958919525146484375:\\ \;\;\;\;\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(\left(\frac{y}{z} + \left(-\frac{t}{1 - z}\right)\right) + \mathsf{fma}\left(-\frac{1}{1 - z}, t, \frac{1}{1 - z} \cdot t\right)\right)\\ \end{array}\]

Reproduce

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