Average Error: 4.7 → 2.4
Time: 39.5s
Precision: 64
\[x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right)\]
\[\begin{array}{l} \mathbf{if}\;x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right) \le -3.006775102161663892319928169149832221608 \cdot 10^{300}:\\ \;\;\;\;\frac{x \cdot \left(y \cdot \left(1 - z\right) - z \cdot t\right)}{z \cdot \left(1 - z\right)}\\ \mathbf{elif}\;x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right) \le 1.593236886321844752796035591518825767997 \cdot 10^{249}:\\ \;\;\;\;x \cdot \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)\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \left(y \cdot \left(1 - z\right) - z \cdot t\right)}{z \cdot \left(1 - z\right)}\\ \end{array}\]
x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right)
\begin{array}{l}
\mathbf{if}\;x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right) \le -3.006775102161663892319928169149832221608 \cdot 10^{300}:\\
\;\;\;\;\frac{x \cdot \left(y \cdot \left(1 - z\right) - z \cdot t\right)}{z \cdot \left(1 - z\right)}\\

\mathbf{elif}\;x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right) \le 1.593236886321844752796035591518825767997 \cdot 10^{249}:\\
\;\;\;\;x \cdot \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)\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r31493175 = x;
        double r31493176 = y;
        double r31493177 = z;
        double r31493178 = r31493176 / r31493177;
        double r31493179 = t;
        double r31493180 = 1.0;
        double r31493181 = r31493180 - r31493177;
        double r31493182 = r31493179 / r31493181;
        double r31493183 = r31493178 - r31493182;
        double r31493184 = r31493175 * r31493183;
        return r31493184;
}

double f(double x, double y, double z, double t) {
        double r31493185 = x;
        double r31493186 = y;
        double r31493187 = z;
        double r31493188 = r31493186 / r31493187;
        double r31493189 = t;
        double r31493190 = 1.0;
        double r31493191 = r31493190 - r31493187;
        double r31493192 = r31493189 / r31493191;
        double r31493193 = r31493188 - r31493192;
        double r31493194 = r31493185 * r31493193;
        double r31493195 = -3.006775102161664e+300;
        bool r31493196 = r31493194 <= r31493195;
        double r31493197 = r31493186 * r31493191;
        double r31493198 = r31493187 * r31493189;
        double r31493199 = r31493197 - r31493198;
        double r31493200 = r31493185 * r31493199;
        double r31493201 = r31493187 * r31493191;
        double r31493202 = r31493200 / r31493201;
        double r31493203 = 1.5932368863218448e+249;
        bool r31493204 = r31493194 <= r31493203;
        double r31493205 = 1.0;
        double r31493206 = r31493205 / r31493187;
        double r31493207 = r31493205 / r31493191;
        double r31493208 = r31493207 * r31493189;
        double r31493209 = -r31493208;
        double r31493210 = fma(r31493186, r31493206, r31493209);
        double r31493211 = -r31493207;
        double r31493212 = fma(r31493211, r31493189, r31493208);
        double r31493213 = r31493210 + r31493212;
        double r31493214 = r31493185 * r31493213;
        double r31493215 = r31493204 ? r31493214 : r31493202;
        double r31493216 = r31493196 ? r31493202 : r31493215;
        return r31493216;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original4.7
Target4.4
Herbie2.4
\[\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 (* x (- (/ y z) (/ t (- 1.0 z)))) < -3.006775102161664e+300 or 1.5932368863218448e+249 < (* x (- (/ y z) (/ t (- 1.0 z))))

    1. Initial program 36.7

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

      \[\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/11.7

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

    if -3.006775102161664e+300 < (* x (- (/ y z) (/ t (- 1.0 z)))) < 1.5932368863218448e+249

    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)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification2.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right) \le -3.006775102161663892319928169149832221608 \cdot 10^{300}:\\ \;\;\;\;\frac{x \cdot \left(y \cdot \left(1 - z\right) - z \cdot t\right)}{z \cdot \left(1 - z\right)}\\ \mathbf{elif}\;x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right) \le 1.593236886321844752796035591518825767997 \cdot 10^{249}:\\ \;\;\;\;x \cdot \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)\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \left(y \cdot \left(1 - z\right) - z \cdot t\right)}{z \cdot \left(1 - z\right)}\\ \end{array}\]

Reproduce

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