Average Error: 4.6 → 2.2
Time: 14.3s
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} = -\infty:\\ \;\;\;\;\frac{x \cdot \left(y \cdot \left(1 - z\right) - z \cdot t\right)}{z \cdot \left(1 - z\right)}\\ \mathbf{elif}\;\frac{y}{z} - \frac{t}{1 - z} \le -3.04221203646389 \cdot 10^{-150}:\\ \;\;\;\;x \cdot \mathsf{fma}\left(y, \frac{1}{z}, -\frac{t}{1 - z}\right)\\ \mathbf{elif}\;\frac{y}{z} - \frac{t}{1 - z} \le 1.9251048092248322 \cdot 10^{-232}:\\ \;\;\;\;\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}\;\frac{y}{z} - \frac{t}{1 - z} = -\infty:\\
\;\;\;\;\frac{x \cdot \left(y \cdot \left(1 - z\right) - z \cdot t\right)}{z \cdot \left(1 - z\right)}\\

\mathbf{elif}\;\frac{y}{z} - \frac{t}{1 - z} \le -3.04221203646389 \cdot 10^{-150}:\\
\;\;\;\;x \cdot \mathsf{fma}\left(y, \frac{1}{z}, -\frac{t}{1 - z}\right)\\

\mathbf{elif}\;\frac{y}{z} - \frac{t}{1 - z} \le 1.9251048092248322 \cdot 10^{-232}:\\
\;\;\;\;\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 r1806 = x;
        double r1807 = y;
        double r1808 = z;
        double r1809 = r1807 / r1808;
        double r1810 = t;
        double r1811 = 1.0;
        double r1812 = r1811 - r1808;
        double r1813 = r1810 / r1812;
        double r1814 = r1809 - r1813;
        double r1815 = r1806 * r1814;
        return r1815;
}

double f(double x, double y, double z, double t) {
        double r1816 = y;
        double r1817 = z;
        double r1818 = r1816 / r1817;
        double r1819 = t;
        double r1820 = 1.0;
        double r1821 = r1820 - r1817;
        double r1822 = r1819 / r1821;
        double r1823 = r1818 - r1822;
        double r1824 = -inf.0;
        bool r1825 = r1823 <= r1824;
        double r1826 = x;
        double r1827 = r1816 * r1821;
        double r1828 = r1817 * r1819;
        double r1829 = r1827 - r1828;
        double r1830 = r1826 * r1829;
        double r1831 = r1817 * r1821;
        double r1832 = r1830 / r1831;
        double r1833 = -3.04221203646389e-150;
        bool r1834 = r1823 <= r1833;
        double r1835 = 1.0;
        double r1836 = r1835 / r1817;
        double r1837 = -r1822;
        double r1838 = fma(r1816, r1836, r1837);
        double r1839 = r1826 * r1838;
        double r1840 = 1.9251048092248322e-232;
        bool r1841 = r1823 <= r1840;
        double r1842 = r1820 / r1817;
        double r1843 = r1842 + r1835;
        double r1844 = r1819 * r1826;
        double r1845 = r1844 / r1817;
        double r1846 = r1826 * r1816;
        double r1847 = r1846 / r1817;
        double r1848 = fma(r1843, r1845, r1847);
        double r1849 = r1841 ? r1848 : r1839;
        double r1850 = r1834 ? r1839 : r1849;
        double r1851 = r1825 ? r1832 : r1850;
        return r1851;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original4.6
Target4.0
Herbie2.2
\[\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))) < -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 < (- (/ y z) (/ t (- 1.0 z))) < -3.04221203646389e-150 or 1.9251048092248322e-232 < (- (/ y z) (/ t (- 1.0 z)))

    1. Initial program 2.1

      \[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 -3.04221203646389e-150 < (- (/ y z) (/ t (- 1.0 z))) < 1.9251048092248322e-232

    1. Initial program 8.9

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

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

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

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

      \[\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.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{y}{z} - \frac{t}{1 - z} = -\infty:\\ \;\;\;\;\frac{x \cdot \left(y \cdot \left(1 - z\right) - z \cdot t\right)}{z \cdot \left(1 - z\right)}\\ \mathbf{elif}\;\frac{y}{z} - \frac{t}{1 - z} \le -3.04221203646389 \cdot 10^{-150}:\\ \;\;\;\;x \cdot \mathsf{fma}\left(y, \frac{1}{z}, -\frac{t}{1 - z}\right)\\ \mathbf{elif}\;\frac{y}{z} - \frac{t}{1 - z} \le 1.9251048092248322 \cdot 10^{-232}:\\ \;\;\;\;\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)))))