Average Error: 4.6 → 2.1
Time: 6.2s
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) = -\infty:\\ \;\;\;\;\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 -4.981739169253245 \cdot 10^{-270}:\\ \;\;\;\;x \cdot \mathsf{fma}\left(y, \frac{1}{z}, -\frac{t}{1 - z}\right)\\ \mathbf{elif}\;x \cdot \left(\frac{y}{z} - \frac{t}{1 - z}\right) \le -0.0:\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{z} + 1, \frac{t \cdot x}{z}, \frac{x \cdot y}{z}\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \mathsf{fma}\left(y, \frac{1}{z}, -\frac{t}{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) = -\infty:\\
\;\;\;\;\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 -4.981739169253245 \cdot 10^{-270}:\\
\;\;\;\;x \cdot \mathsf{fma}\left(y, \frac{1}{z}, -\frac{t}{1 - z}\right)\\

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

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

\end{array}
double f(double x, double y, double z, double t) {
        double r417798 = x;
        double r417799 = y;
        double r417800 = z;
        double r417801 = r417799 / r417800;
        double r417802 = t;
        double r417803 = 1.0;
        double r417804 = r417803 - r417800;
        double r417805 = r417802 / r417804;
        double r417806 = r417801 - r417805;
        double r417807 = r417798 * r417806;
        return r417807;
}

double f(double x, double y, double z, double t) {
        double r417808 = x;
        double r417809 = y;
        double r417810 = z;
        double r417811 = r417809 / r417810;
        double r417812 = t;
        double r417813 = 1.0;
        double r417814 = r417813 - r417810;
        double r417815 = r417812 / r417814;
        double r417816 = r417811 - r417815;
        double r417817 = r417808 * r417816;
        double r417818 = -inf.0;
        bool r417819 = r417817 <= r417818;
        double r417820 = r417809 * r417814;
        double r417821 = r417810 * r417812;
        double r417822 = r417820 - r417821;
        double r417823 = r417808 * r417822;
        double r417824 = r417810 * r417814;
        double r417825 = r417823 / r417824;
        double r417826 = -4.981739169253245e-270;
        bool r417827 = r417817 <= r417826;
        double r417828 = 1.0;
        double r417829 = r417828 / r417810;
        double r417830 = -r417815;
        double r417831 = fma(r417809, r417829, r417830);
        double r417832 = r417808 * r417831;
        double r417833 = -0.0;
        bool r417834 = r417817 <= r417833;
        double r417835 = r417813 / r417810;
        double r417836 = r417835 + r417828;
        double r417837 = r417812 * r417808;
        double r417838 = r417837 / r417810;
        double r417839 = r417808 * r417809;
        double r417840 = r417839 / r417810;
        double r417841 = fma(r417836, r417838, r417840);
        double r417842 = r417834 ? r417841 : r417832;
        double r417843 = r417827 ? r417832 : r417842;
        double r417844 = r417819 ? r417825 : r417843;
        return r417844;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original4.6
Target4.0
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 (* x (- (/ y z) (/ t (- 1.0 z)))) < -inf.0

    1. Initial program 64.0

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

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

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

    if -inf.0 < (* x (- (/ y z) (/ t (- 1.0 z)))) < -4.981739169253245e-270 or -0.0 < (* x (- (/ 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 div-inv2.2

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

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

    if -4.981739169253245e-270 < (* x (- (/ y z) (/ t (- 1.0 z)))) < -0.0

    1. Initial program 9.0

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

      \[\leadsto x \cdot \left(\color{blue}{y \cdot \frac{1}{z}} - \frac{t}{1 - z}\right)\]
    4. Applied fma-neg9.0

      \[\leadsto x \cdot \color{blue}{\mathsf{fma}\left(y, \frac{1}{z}, -\frac{t}{1 - z}\right)}\]
    5. Taylor expanded around inf 1.9

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

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

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

Reproduce

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