Average Error: 4.8 → 2.1
Time: 12.1s
Precision: 64
\[x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right)\]
\[\begin{array}{l} \mathbf{if}\;\frac{y}{z} - \frac{t}{1 - z} \le -8.5037571974812515 \cdot 10^{236}:\\ \;\;\;\;\frac{x \cdot y}{z} + \left(-\frac{t}{1 - z}\right) \cdot x\\ \mathbf{elif}\;\frac{y}{z} - \frac{t}{1 - z} \le -9.4133434694620043 \cdot 10^{-214} \lor \neg \left(\frac{y}{z} - \frac{t}{1 - z} \le 0.0\right):\\ \;\;\;\;x \cdot \left(\mathsf{fma}\left(y, \frac{1}{z}, -\frac{t}{1 - z}\right) + \left(\frac{t}{1 - z} + \left(-\frac{t}{1 - z}\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1, \frac{t \cdot x}{{z}^{2}}, \frac{t \cdot x}{z}\right) + \frac{x \cdot y}{z}\\ \end{array}\]
x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right)
\begin{array}{l}
\mathbf{if}\;\frac{y}{z} - \frac{t}{1 - z} \le -8.5037571974812515 \cdot 10^{236}:\\
\;\;\;\;\frac{x \cdot y}{z} + \left(-\frac{t}{1 - z}\right) \cdot x\\

\mathbf{elif}\;\frac{y}{z} - \frac{t}{1 - z} \le -9.4133434694620043 \cdot 10^{-214} \lor \neg \left(\frac{y}{z} - \frac{t}{1 - z} \le 0.0\right):\\
\;\;\;\;x \cdot \left(\mathsf{fma}\left(y, \frac{1}{z}, -\frac{t}{1 - z}\right) + \left(\frac{t}{1 - z} + \left(-\frac{t}{1 - z}\right)\right)\right)\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r461627 = x;
        double r461628 = y;
        double r461629 = z;
        double r461630 = r461628 / r461629;
        double r461631 = t;
        double r461632 = 1.0;
        double r461633 = r461632 - r461629;
        double r461634 = r461631 / r461633;
        double r461635 = r461630 - r461634;
        double r461636 = r461627 * r461635;
        return r461636;
}

double f(double x, double y, double z, double t) {
        double r461637 = y;
        double r461638 = z;
        double r461639 = r461637 / r461638;
        double r461640 = t;
        double r461641 = 1.0;
        double r461642 = r461641 - r461638;
        double r461643 = r461640 / r461642;
        double r461644 = r461639 - r461643;
        double r461645 = -8.503757197481251e+236;
        bool r461646 = r461644 <= r461645;
        double r461647 = x;
        double r461648 = r461647 * r461637;
        double r461649 = r461648 / r461638;
        double r461650 = -r461643;
        double r461651 = r461650 * r461647;
        double r461652 = r461649 + r461651;
        double r461653 = -9.413343469462004e-214;
        bool r461654 = r461644 <= r461653;
        double r461655 = 0.0;
        bool r461656 = r461644 <= r461655;
        double r461657 = !r461656;
        bool r461658 = r461654 || r461657;
        double r461659 = 1.0;
        double r461660 = r461659 / r461638;
        double r461661 = fma(r461637, r461660, r461650);
        double r461662 = r461643 + r461650;
        double r461663 = r461661 + r461662;
        double r461664 = r461647 * r461663;
        double r461665 = r461640 * r461647;
        double r461666 = 2.0;
        double r461667 = pow(r461638, r461666);
        double r461668 = r461665 / r461667;
        double r461669 = r461665 / r461638;
        double r461670 = fma(r461641, r461668, r461669);
        double r461671 = r461670 + r461649;
        double r461672 = r461658 ? r461664 : r461671;
        double r461673 = r461646 ? r461652 : r461672;
        return r461673;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original4.8
Target4.4
Herbie2.1
\[\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 3 regimes
  2. if (- (/ y z) (/ t (- 1.0 z))) < -8.503757197481251e+236

    1. Initial program 28.2

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

      \[\leadsto x \cdot \color{blue}{\left(\frac{y}{z} + \left(-\frac{t}{1 - z}\right)\right)}\]
    4. Applied distribute-lft-in28.2

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

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

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

    if -8.503757197481251e+236 < (- (/ y z) (/ t (- 1.0 z))) < -9.413343469462004e-214 or 0.0 < (- (/ y z) (/ t (- 1.0 z)))

    1. Initial program 2.2

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

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

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

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

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

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

    if -9.413343469462004e-214 < (- (/ y z) (/ t (- 1.0 z))) < 0.0

    1. Initial program 13.3

      \[x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right)\]
    2. Taylor expanded around inf 1.3

      \[\leadsto \color{blue}{\frac{x \cdot y}{z} + \left(1 \cdot \frac{t \cdot x}{{z}^{2}} + \frac{t \cdot x}{z}\right)}\]
    3. Simplified1.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{y}{z} - \frac{t}{1 - z} \le -8.5037571974812515 \cdot 10^{236}:\\ \;\;\;\;\frac{x \cdot y}{z} + \left(-\frac{t}{1 - z}\right) \cdot x\\ \mathbf{elif}\;\frac{y}{z} - \frac{t}{1 - z} \le -9.4133434694620043 \cdot 10^{-214} \lor \neg \left(\frac{y}{z} - \frac{t}{1 - z} \le 0.0\right):\\ \;\;\;\;x \cdot \left(\mathsf{fma}\left(y, \frac{1}{z}, -\frac{t}{1 - z}\right) + \left(\frac{t}{1 - z} + \left(-\frac{t}{1 - z}\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1, \frac{t \cdot x}{{z}^{2}}, \frac{t \cdot x}{z}\right) + \frac{x \cdot y}{z}\\ \end{array}\]

Reproduce

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