Average Error: 6.2 → 2.8
Time: 20.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 1.168436591191916115391152254672141623167 \cdot 10^{48}:\\ \;\;\;\;\mathsf{fma}\left(x - 0.5, \log x, \mathsf{fma}\left(z \cdot \left(7.936500793651000149400709382518925849581 \cdot 10^{-4} + y\right) - 0.002777777777777800001512975569539776188321, z, 0.08333333333333299564049667651488562114537\right) \cdot \frac{1}{x} + \left(0.9189385332046700050057097541866824030876 - x\right)\right) + \mathsf{fma}\left(-\sqrt{x}, \sqrt{x}, \sqrt{x} \cdot \sqrt{x}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x - 0.5, \log x, \mathsf{fma}\left(\frac{z}{\frac{x}{z}}, 7.936500793651000149400709382518925849581 \cdot 10^{-4}, \frac{0.08333333333333299564049667651488562114537}{x} - 0.002777777777777800001512975569539776188321 \cdot \frac{z}{x}\right) + \left(0.9189385332046700050057097541866824030876 - x\right)\right) + \mathsf{fma}\left(-\sqrt{x}, \sqrt{x}, \sqrt{x} \cdot \sqrt{x}\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 1.168436591191916115391152254672141623167 \cdot 10^{48}:\\
\;\;\;\;\mathsf{fma}\left(x - 0.5, \log x, \mathsf{fma}\left(z \cdot \left(7.936500793651000149400709382518925849581 \cdot 10^{-4} + y\right) - 0.002777777777777800001512975569539776188321, z, 0.08333333333333299564049667651488562114537\right) \cdot \frac{1}{x} + \left(0.9189385332046700050057097541866824030876 - x\right)\right) + \mathsf{fma}\left(-\sqrt{x}, \sqrt{x}, \sqrt{x} \cdot \sqrt{x}\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x - 0.5, \log x, \mathsf{fma}\left(\frac{z}{\frac{x}{z}}, 7.936500793651000149400709382518925849581 \cdot 10^{-4}, \frac{0.08333333333333299564049667651488562114537}{x} - 0.002777777777777800001512975569539776188321 \cdot \frac{z}{x}\right) + \left(0.9189385332046700050057097541866824030876 - x\right)\right) + \mathsf{fma}\left(-\sqrt{x}, \sqrt{x}, \sqrt{x} \cdot \sqrt{x}\right)\\

\end{array}
double f(double x, double y, double z) {
        double r318207 = x;
        double r318208 = 0.5;
        double r318209 = r318207 - r318208;
        double r318210 = log(r318207);
        double r318211 = r318209 * r318210;
        double r318212 = r318211 - r318207;
        double r318213 = 0.91893853320467;
        double r318214 = r318212 + r318213;
        double r318215 = y;
        double r318216 = 0.0007936500793651;
        double r318217 = r318215 + r318216;
        double r318218 = z;
        double r318219 = r318217 * r318218;
        double r318220 = 0.0027777777777778;
        double r318221 = r318219 - r318220;
        double r318222 = r318221 * r318218;
        double r318223 = 0.083333333333333;
        double r318224 = r318222 + r318223;
        double r318225 = r318224 / r318207;
        double r318226 = r318214 + r318225;
        return r318226;
}

double f(double x, double y, double z) {
        double r318227 = x;
        double r318228 = 1.1684365911919161e+48;
        bool r318229 = r318227 <= r318228;
        double r318230 = 0.5;
        double r318231 = r318227 - r318230;
        double r318232 = log(r318227);
        double r318233 = z;
        double r318234 = 0.0007936500793651;
        double r318235 = y;
        double r318236 = r318234 + r318235;
        double r318237 = r318233 * r318236;
        double r318238 = 0.0027777777777778;
        double r318239 = r318237 - r318238;
        double r318240 = 0.083333333333333;
        double r318241 = fma(r318239, r318233, r318240);
        double r318242 = 1.0;
        double r318243 = r318242 / r318227;
        double r318244 = r318241 * r318243;
        double r318245 = 0.91893853320467;
        double r318246 = r318245 - r318227;
        double r318247 = r318244 + r318246;
        double r318248 = fma(r318231, r318232, r318247);
        double r318249 = sqrt(r318227);
        double r318250 = -r318249;
        double r318251 = r318249 * r318249;
        double r318252 = fma(r318250, r318249, r318251);
        double r318253 = r318248 + r318252;
        double r318254 = r318227 / r318233;
        double r318255 = r318233 / r318254;
        double r318256 = r318240 / r318227;
        double r318257 = r318233 / r318227;
        double r318258 = r318238 * r318257;
        double r318259 = r318256 - r318258;
        double r318260 = fma(r318255, r318234, r318259);
        double r318261 = r318260 + r318246;
        double r318262 = fma(r318231, r318232, r318261);
        double r318263 = r318262 + r318252;
        double r318264 = r318229 ? r318253 : r318263;
        return r318264;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original6.2
Target1.2
Herbie2.8
\[\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 2 regimes
  2. if x < 1.1684365911919161e+48

    1. Initial program 0.5

      \[\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. Simplified0.5

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

      \[\leadsto \mathsf{fma}\left(\log x, x - 0.5, \frac{\mathsf{fma}\left(z, \left(y + 7.936500793651000149400709382518925849581 \cdot 10^{-4}\right) \cdot z - 0.002777777777777800001512975569539776188321, 0.08333333333333299564049667651488562114537\right)}{x}\right) + \left(0.9189385332046700050057097541866824030876 - \color{blue}{\sqrt{x} \cdot \sqrt{x}}\right)\]
    5. Applied add-sqr-sqrt0.5

      \[\leadsto \mathsf{fma}\left(\log x, x - 0.5, \frac{\mathsf{fma}\left(z, \left(y + 7.936500793651000149400709382518925849581 \cdot 10^{-4}\right) \cdot z - 0.002777777777777800001512975569539776188321, 0.08333333333333299564049667651488562114537\right)}{x}\right) + \left(\color{blue}{\sqrt{0.9189385332046700050057097541866824030876} \cdot \sqrt{0.9189385332046700050057097541866824030876}} - \sqrt{x} \cdot \sqrt{x}\right)\]
    6. Applied prod-diff0.5

      \[\leadsto \mathsf{fma}\left(\log x, x - 0.5, \frac{\mathsf{fma}\left(z, \left(y + 7.936500793651000149400709382518925849581 \cdot 10^{-4}\right) \cdot z - 0.002777777777777800001512975569539776188321, 0.08333333333333299564049667651488562114537\right)}{x}\right) + \color{blue}{\left(\mathsf{fma}\left(\sqrt{0.9189385332046700050057097541866824030876}, \sqrt{0.9189385332046700050057097541866824030876}, -\sqrt{x} \cdot \sqrt{x}\right) + \mathsf{fma}\left(-\sqrt{x}, \sqrt{x}, \sqrt{x} \cdot \sqrt{x}\right)\right)}\]
    7. Applied associate-+r+0.5

      \[\leadsto \color{blue}{\left(\mathsf{fma}\left(\log x, x - 0.5, \frac{\mathsf{fma}\left(z, \left(y + 7.936500793651000149400709382518925849581 \cdot 10^{-4}\right) \cdot z - 0.002777777777777800001512975569539776188321, 0.08333333333333299564049667651488562114537\right)}{x}\right) + \mathsf{fma}\left(\sqrt{0.9189385332046700050057097541866824030876}, \sqrt{0.9189385332046700050057097541866824030876}, -\sqrt{x} \cdot \sqrt{x}\right)\right) + \mathsf{fma}\left(-\sqrt{x}, \sqrt{x}, \sqrt{x} \cdot \sqrt{x}\right)}\]
    8. Simplified0.5

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

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

    if 1.1684365911919161e+48 < x

    1. Initial program 11.9

      \[\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. Simplified11.9

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

      \[\leadsto \mathsf{fma}\left(\log x, x - 0.5, \frac{\mathsf{fma}\left(z, \left(y + 7.936500793651000149400709382518925849581 \cdot 10^{-4}\right) \cdot z - 0.002777777777777800001512975569539776188321, 0.08333333333333299564049667651488562114537\right)}{x}\right) + \left(0.9189385332046700050057097541866824030876 - \color{blue}{\sqrt{x} \cdot \sqrt{x}}\right)\]
    5. Applied add-sqr-sqrt11.9

      \[\leadsto \mathsf{fma}\left(\log x, x - 0.5, \frac{\mathsf{fma}\left(z, \left(y + 7.936500793651000149400709382518925849581 \cdot 10^{-4}\right) \cdot z - 0.002777777777777800001512975569539776188321, 0.08333333333333299564049667651488562114537\right)}{x}\right) + \left(\color{blue}{\sqrt{0.9189385332046700050057097541866824030876} \cdot \sqrt{0.9189385332046700050057097541866824030876}} - \sqrt{x} \cdot \sqrt{x}\right)\]
    6. Applied prod-diff11.9

      \[\leadsto \mathsf{fma}\left(\log x, x - 0.5, \frac{\mathsf{fma}\left(z, \left(y + 7.936500793651000149400709382518925849581 \cdot 10^{-4}\right) \cdot z - 0.002777777777777800001512975569539776188321, 0.08333333333333299564049667651488562114537\right)}{x}\right) + \color{blue}{\left(\mathsf{fma}\left(\sqrt{0.9189385332046700050057097541866824030876}, \sqrt{0.9189385332046700050057097541866824030876}, -\sqrt{x} \cdot \sqrt{x}\right) + \mathsf{fma}\left(-\sqrt{x}, \sqrt{x}, \sqrt{x} \cdot \sqrt{x}\right)\right)}\]
    7. Applied associate-+r+11.9

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

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

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

      \[\leadsto \mathsf{fma}\left(x - 0.5, \log x, \color{blue}{\left(\left(7.936500793651000149400709382518925849581 \cdot 10^{-4} \cdot \frac{{z}^{2}}{x} + 0.08333333333333299564049667651488562114537 \cdot \frac{1}{x}\right) - 0.002777777777777800001512975569539776188321 \cdot \frac{z}{x}\right)} + \left(0.9189385332046700050057097541866824030876 - x\right)\right) + \mathsf{fma}\left(-\sqrt{x}, \sqrt{x}, \sqrt{x} \cdot \sqrt{x}\right)\]
    12. Simplified4.7

      \[\leadsto \mathsf{fma}\left(x - 0.5, \log x, \color{blue}{\mathsf{fma}\left(\frac{z}{\frac{x}{z}}, 7.936500793651000149400709382518925849581 \cdot 10^{-4}, \frac{0.08333333333333299564049667651488562114537}{x} - \frac{z}{x} \cdot 0.002777777777777800001512975569539776188321\right)} + \left(0.9189385332046700050057097541866824030876 - x\right)\right) + \mathsf{fma}\left(-\sqrt{x}, \sqrt{x}, \sqrt{x} \cdot \sqrt{x}\right)\]
  3. Recombined 2 regimes into one program.
  4. Final simplification2.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le 1.168436591191916115391152254672141623167 \cdot 10^{48}:\\ \;\;\;\;\mathsf{fma}\left(x - 0.5, \log x, \mathsf{fma}\left(z \cdot \left(7.936500793651000149400709382518925849581 \cdot 10^{-4} + y\right) - 0.002777777777777800001512975569539776188321, z, 0.08333333333333299564049667651488562114537\right) \cdot \frac{1}{x} + \left(0.9189385332046700050057097541866824030876 - x\right)\right) + \mathsf{fma}\left(-\sqrt{x}, \sqrt{x}, \sqrt{x} \cdot \sqrt{x}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x - 0.5, \log x, \mathsf{fma}\left(\frac{z}{\frac{x}{z}}, 7.936500793651000149400709382518925849581 \cdot 10^{-4}, \frac{0.08333333333333299564049667651488562114537}{x} - 0.002777777777777800001512975569539776188321 \cdot \frac{z}{x}\right) + \left(0.9189385332046700050057097541866824030876 - x\right)\right) + \mathsf{fma}\left(-\sqrt{x}, \sqrt{x}, \sqrt{x} \cdot \sqrt{x}\right)\\ \end{array}\]

Reproduce

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

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