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 r469430 = x;
        double r469431 = 0.5;
        double r469432 = r469430 - r469431;
        double r469433 = log(r469430);
        double r469434 = r469432 * r469433;
        double r469435 = r469434 - r469430;
        double r469436 = 0.91893853320467;
        double r469437 = r469435 + r469436;
        double r469438 = y;
        double r469439 = 0.0007936500793651;
        double r469440 = r469438 + r469439;
        double r469441 = z;
        double r469442 = r469440 * r469441;
        double r469443 = 0.0027777777777778;
        double r469444 = r469442 - r469443;
        double r469445 = r469444 * r469441;
        double r469446 = 0.083333333333333;
        double r469447 = r469445 + r469446;
        double r469448 = r469447 / r469430;
        double r469449 = r469437 + r469448;
        return r469449;
}

double f(double x, double y, double z) {
        double r469450 = x;
        double r469451 = 8.80205122721626e+100;
        bool r469452 = r469450 <= r469451;
        double r469453 = log(r469450);
        double r469454 = 0.5;
        double r469455 = r469450 - r469454;
        double r469456 = r469453 * r469455;
        double r469457 = y;
        double r469458 = 0.0007936500793651;
        double r469459 = r469457 + r469458;
        double r469460 = z;
        double r469461 = r469459 * r469460;
        double r469462 = 0.0027777777777778;
        double r469463 = r469461 - r469462;
        double r469464 = r469463 * r469460;
        double r469465 = 0.083333333333333;
        double r469466 = r469464 + r469465;
        double r469467 = r469466 / r469450;
        double r469468 = 0.91893853320467;
        double r469469 = r469450 - r469468;
        double r469470 = r469467 - r469469;
        double r469471 = r469456 + r469470;
        double r469472 = 4.717658198318119e+216;
        bool r469473 = r469450 <= r469472;
        double r469474 = 2.0;
        double r469475 = pow(r469460, r469474);
        double r469476 = r469475 / r469450;
        double r469477 = r469458 * r469476;
        double r469478 = 1.0;
        double r469479 = r469478 / r469450;
        double r469480 = log(r469479);
        double r469481 = fma(r469480, r469450, r469450);
        double r469482 = r469477 - r469481;
        double r469483 = fma(r469476, r469457, r469482);
        double r469484 = 0.4000000000000064;
        double r469485 = r469484 * r469450;
        double r469486 = 12.000000000000048;
        double r469487 = r469486 * r469450;
        double r469488 = 0.10095227809524161;
        double r469489 = r469450 * r469475;
        double r469490 = r469488 * r469489;
        double r469491 = r469487 - r469490;
        double r469492 = fma(r469485, r469460, r469491);
        double r469493 = r469478 / r469492;
        double r469494 = r469493 - r469469;
        double r469495 = fma(r469453, r469455, r469494);
        double r469496 = r469473 ? r469483 : r469495;
        double r469497 = r469452 ? r469471 : r469496;
        return r469497;
}

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)))