Average Error: 6.0 → 2.6
Time: 7.7s
Precision: 64
\[\left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.9189385332046700050057097541866824030876\right) + \frac{\left(\left(y + 7.936500793651000149400709382518925849581 \cdot 10^{-4}\right) \cdot z - 0.002777777777777800001512975569539776188321\right) \cdot z + 0.08333333333333299564049667651488562114537}{x}\]
\[\begin{array}{l} \mathbf{if}\;x \le 8.802051227216260578823091484650999242207 \cdot 10^{100}:\\ \;\;\;\;\log x \cdot \left(x - 0.5\right) + \left(\frac{\left(\left(y + 7.936500793651000149400709382518925849581 \cdot 10^{-4}\right) \cdot z - 0.002777777777777800001512975569539776188321\right) \cdot z + 0.08333333333333299564049667651488562114537}{x} - \left(x - 0.9189385332046700050057097541866824030876\right)\right)\\ \mathbf{elif}\;x \le 4.717658198318118893542685725997000036653 \cdot 10^{216}:\\ \;\;\;\;\mathsf{fma}\left(\frac{{z}^{2}}{x}, y, 7.936500793651000149400709382518925849581 \cdot 10^{-4} \cdot \frac{{z}^{2}}{x} - \mathsf{fma}\left(\log \left(\frac{1}{x}\right), x, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\log x, x - 0.5, \frac{1}{\mathsf{fma}\left(0.4000000000000064059868520871532382443547 \cdot x, z, 12.00000000000004796163466380676254630089 \cdot x - 0.1009522780952416126654114236771420110017 \cdot \left(x \cdot {z}^{2}\right)\right)} - \left(x - 0.9189385332046700050057097541866824030876\right)\right)\\ \end{array}\]
\left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.9189385332046700050057097541866824030876\right) + \frac{\left(\left(y + 7.936500793651000149400709382518925849581 \cdot 10^{-4}\right) \cdot z - 0.002777777777777800001512975569539776188321\right) \cdot z + 0.08333333333333299564049667651488562114537}{x}
\begin{array}{l}
\mathbf{if}\;x \le 8.802051227216260578823091484650999242207 \cdot 10^{100}:\\
\;\;\;\;\log x \cdot \left(x - 0.5\right) + \left(\frac{\left(\left(y + 7.936500793651000149400709382518925849581 \cdot 10^{-4}\right) \cdot z - 0.002777777777777800001512975569539776188321\right) \cdot z + 0.08333333333333299564049667651488562114537}{x} - \left(x - 0.9189385332046700050057097541866824030876\right)\right)\\

\mathbf{elif}\;x \le 4.717658198318118893542685725997000036653 \cdot 10^{216}:\\
\;\;\;\;\mathsf{fma}\left(\frac{{z}^{2}}{x}, y, 7.936500793651000149400709382518925849581 \cdot 10^{-4} \cdot \frac{{z}^{2}}{x} - \mathsf{fma}\left(\log \left(\frac{1}{x}\right), x, x\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\log x, x - 0.5, \frac{1}{\mathsf{fma}\left(0.4000000000000064059868520871532382443547 \cdot x, z, 12.00000000000004796163466380676254630089 \cdot x - 0.1009522780952416126654114236771420110017 \cdot \left(x \cdot {z}^{2}\right)\right)} - \left(x - 0.9189385332046700050057097541866824030876\right)\right)\\

\end{array}
double f(double x, double y, double z) {
        double r462626 = x;
        double r462627 = 0.5;
        double r462628 = r462626 - r462627;
        double r462629 = log(r462626);
        double r462630 = r462628 * r462629;
        double r462631 = r462630 - r462626;
        double r462632 = 0.91893853320467;
        double r462633 = r462631 + r462632;
        double r462634 = y;
        double r462635 = 0.0007936500793651;
        double r462636 = r462634 + r462635;
        double r462637 = z;
        double r462638 = r462636 * r462637;
        double r462639 = 0.0027777777777778;
        double r462640 = r462638 - r462639;
        double r462641 = r462640 * r462637;
        double r462642 = 0.083333333333333;
        double r462643 = r462641 + r462642;
        double r462644 = r462643 / r462626;
        double r462645 = r462633 + r462644;
        return r462645;
}

double f(double x, double y, double z) {
        double r462646 = x;
        double r462647 = 8.80205122721626e+100;
        bool r462648 = r462646 <= r462647;
        double r462649 = log(r462646);
        double r462650 = 0.5;
        double r462651 = r462646 - r462650;
        double r462652 = r462649 * r462651;
        double r462653 = y;
        double r462654 = 0.0007936500793651;
        double r462655 = r462653 + r462654;
        double r462656 = z;
        double r462657 = r462655 * r462656;
        double r462658 = 0.0027777777777778;
        double r462659 = r462657 - r462658;
        double r462660 = r462659 * r462656;
        double r462661 = 0.083333333333333;
        double r462662 = r462660 + r462661;
        double r462663 = r462662 / r462646;
        double r462664 = 0.91893853320467;
        double r462665 = r462646 - r462664;
        double r462666 = r462663 - r462665;
        double r462667 = r462652 + r462666;
        double r462668 = 4.717658198318119e+216;
        bool r462669 = r462646 <= r462668;
        double r462670 = 2.0;
        double r462671 = pow(r462656, r462670);
        double r462672 = r462671 / r462646;
        double r462673 = r462654 * r462672;
        double r462674 = 1.0;
        double r462675 = r462674 / r462646;
        double r462676 = log(r462675);
        double r462677 = fma(r462676, r462646, r462646);
        double r462678 = r462673 - r462677;
        double r462679 = fma(r462672, r462653, r462678);
        double r462680 = 0.4000000000000064;
        double r462681 = r462680 * r462646;
        double r462682 = 12.000000000000048;
        double r462683 = r462682 * r462646;
        double r462684 = 0.10095227809524161;
        double r462685 = r462646 * r462671;
        double r462686 = r462684 * r462685;
        double r462687 = r462683 - r462686;
        double r462688 = fma(r462681, r462656, r462687);
        double r462689 = r462674 / r462688;
        double r462690 = r462689 - r462665;
        double r462691 = fma(r462649, r462651, r462690);
        double r462692 = r462669 ? r462679 : r462691;
        double r462693 = r462648 ? r462667 : r462692;
        return r462693;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original6.0
Target1.2
Herbie2.6
\[\left(\left(\left(x - 0.5\right) \cdot \log x + \left(0.9189385332046700050057097541866824030876 - x\right)\right) + \frac{0.08333333333333299564049667651488562114537}{x}\right) + \frac{z}{x} \cdot \left(z \cdot \left(y + 7.936500793651000149400709382518925849581 \cdot 10^{-4}\right) - 0.002777777777777800001512975569539776188321\right)\]

Derivation

  1. Split input into 3 regimes
  2. if x < 8.80205122721626e+100

    1. Initial program 1.2

      \[\left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.9189385332046700050057097541866824030876\right) + \frac{\left(\left(y + 7.936500793651000149400709382518925849581 \cdot 10^{-4}\right) \cdot z - 0.002777777777777800001512975569539776188321\right) \cdot z + 0.08333333333333299564049667651488562114537}{x}\]
    2. Simplified1.2

      \[\leadsto \color{blue}{\mathsf{fma}\left(\log x, x - 0.5, \frac{\left(\left(y + 7.936500793651000149400709382518925849581 \cdot 10^{-4}\right) \cdot z - 0.002777777777777800001512975569539776188321\right) \cdot z + 0.08333333333333299564049667651488562114537}{x} - \left(x - 0.9189385332046700050057097541866824030876\right)\right)}\]
    3. Using strategy rm
    4. Applied fma-udef1.2

      \[\leadsto \color{blue}{\log x \cdot \left(x - 0.5\right) + \left(\frac{\left(\left(y + 7.936500793651000149400709382518925849581 \cdot 10^{-4}\right) \cdot z - 0.002777777777777800001512975569539776188321\right) \cdot z + 0.08333333333333299564049667651488562114537}{x} - \left(x - 0.9189385332046700050057097541866824030876\right)\right)}\]

    if 8.80205122721626e+100 < x < 4.717658198318119e+216

    1. Initial program 10.0

      \[\left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.9189385332046700050057097541866824030876\right) + \frac{\left(\left(y + 7.936500793651000149400709382518925849581 \cdot 10^{-4}\right) \cdot z - 0.002777777777777800001512975569539776188321\right) \cdot z + 0.08333333333333299564049667651488562114537}{x}\]
    2. Simplified10.0

      \[\leadsto \color{blue}{\mathsf{fma}\left(\log x, x - 0.5, \frac{\left(\left(y + 7.936500793651000149400709382518925849581 \cdot 10^{-4}\right) \cdot z - 0.002777777777777800001512975569539776188321\right) \cdot z + 0.08333333333333299564049667651488562114537}{x} - \left(x - 0.9189385332046700050057097541866824030876\right)\right)}\]
    3. Taylor expanded around inf 10.1

      \[\leadsto \color{blue}{\left(7.936500793651000149400709382518925849581 \cdot 10^{-4} \cdot \frac{{z}^{2}}{x} + \frac{{z}^{2} \cdot y}{x}\right) - \left(x + x \cdot \log \left(\frac{1}{x}\right)\right)}\]
    4. Simplified6.0

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{{z}^{2}}{x}, y, 7.936500793651000149400709382518925849581 \cdot 10^{-4} \cdot \frac{{z}^{2}}{x} - \mathsf{fma}\left(\log \left(\frac{1}{x}\right), x, x\right)\right)}\]

    if 4.717658198318119e+216 < x

    1. Initial program 15.7

      \[\left(\left(\left(x - 0.5\right) \cdot \log x - x\right) + 0.9189385332046700050057097541866824030876\right) + \frac{\left(\left(y + 7.936500793651000149400709382518925849581 \cdot 10^{-4}\right) \cdot z - 0.002777777777777800001512975569539776188321\right) \cdot z + 0.08333333333333299564049667651488562114537}{x}\]
    2. Simplified15.6

      \[\leadsto \color{blue}{\mathsf{fma}\left(\log x, x - 0.5, \frac{\left(\left(y + 7.936500793651000149400709382518925849581 \cdot 10^{-4}\right) \cdot z - 0.002777777777777800001512975569539776188321\right) \cdot z + 0.08333333333333299564049667651488562114537}{x} - \left(x - 0.9189385332046700050057097541866824030876\right)\right)}\]
    3. Using strategy rm
    4. Applied clear-num15.6

      \[\leadsto \mathsf{fma}\left(\log x, x - 0.5, \color{blue}{\frac{1}{\frac{x}{\left(\left(y + 7.936500793651000149400709382518925849581 \cdot 10^{-4}\right) \cdot z - 0.002777777777777800001512975569539776188321\right) \cdot z + 0.08333333333333299564049667651488562114537}}} - \left(x - 0.9189385332046700050057097541866824030876\right)\right)\]
    5. Taylor expanded around 0 14.1

      \[\leadsto \mathsf{fma}\left(\log x, x - 0.5, \frac{1}{\color{blue}{\left(0.4000000000000064059868520871532382443547 \cdot \left(x \cdot z\right) + 12.00000000000004796163466380676254630089 \cdot x\right) - 0.1009522780952416126654114236771420110017 \cdot \left(x \cdot {z}^{2}\right)}} - \left(x - 0.9189385332046700050057097541866824030876\right)\right)\]
    6. Simplified2.9

      \[\leadsto \mathsf{fma}\left(\log x, x - 0.5, \frac{1}{\color{blue}{\mathsf{fma}\left(0.4000000000000064059868520871532382443547 \cdot x, z, 12.00000000000004796163466380676254630089 \cdot x - 0.1009522780952416126654114236771420110017 \cdot \left(x \cdot {z}^{2}\right)\right)}} - \left(x - 0.9189385332046700050057097541866824030876\right)\right)\]
  3. Recombined 3 regimes into one program.
  4. Final simplification2.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le 8.802051227216260578823091484650999242207 \cdot 10^{100}:\\ \;\;\;\;\log x \cdot \left(x - 0.5\right) + \left(\frac{\left(\left(y + 7.936500793651000149400709382518925849581 \cdot 10^{-4}\right) \cdot z - 0.002777777777777800001512975569539776188321\right) \cdot z + 0.08333333333333299564049667651488562114537}{x} - \left(x - 0.9189385332046700050057097541866824030876\right)\right)\\ \mathbf{elif}\;x \le 4.717658198318118893542685725997000036653 \cdot 10^{216}:\\ \;\;\;\;\mathsf{fma}\left(\frac{{z}^{2}}{x}, y, 7.936500793651000149400709382518925849581 \cdot 10^{-4} \cdot \frac{{z}^{2}}{x} - \mathsf{fma}\left(\log \left(\frac{1}{x}\right), x, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\log x, x - 0.5, \frac{1}{\mathsf{fma}\left(0.4000000000000064059868520871532382443547 \cdot x, z, 12.00000000000004796163466380676254630089 \cdot x - 0.1009522780952416126654114236771420110017 \cdot \left(x \cdot {z}^{2}\right)\right)} - \left(x - 0.9189385332046700050057097541866824030876\right)\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020001 +o rules:numerics
(FPCore (x y z)
  :name "Numeric.SpecFunctions:$slogFactorial from math-functions-0.1.5.2, B"
  :precision binary64

  :herbie-target
  (+ (+ (+ (* (- x 0.5) (log x)) (- 0.91893853320467 x)) (/ 0.083333333333333 x)) (* (/ z x) (- (* z (+ y 0.0007936500793651)) 0.0027777777777778)))

  (+ (+ (- (* (- x 0.5) (log x)) x) 0.91893853320467) (/ (+ (* (- (* (+ y 0.0007936500793651) z) 0.0027777777777778) z) 0.083333333333333) x)))