Average Error: 26.0 → 0.8
Time: 24.9s
Precision: 64
\[\frac{\left(x - 2.0\right) \cdot \left(\left(\left(\left(x \cdot 4.16438922228 + 78.6994924154\right) \cdot x + 137.519416416\right) \cdot x + y\right) \cdot x + z\right)}{\left(\left(\left(x + 43.3400022514\right) \cdot x + 263.505074721\right) \cdot x + 313.399215894\right) \cdot x + 47.066876606}\]
\[\begin{array}{l} \mathbf{if}\;x \le -5.140336158145698 \cdot 10^{+17}:\\ \;\;\;\;\mathsf{fma}\left(4.16438922228, x, \frac{y}{x \cdot x} - 110.1139242984811\right)\\ \mathbf{elif}\;x \le 1.692613215272597 \cdot 10^{+44}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, \mathsf{fma}\left(x, \mathsf{fma}\left(\mathsf{fma}\left(4.16438922228, x, 78.6994924154\right), x, 137.519416416\right), y\right), z\right)}{\frac{\mathsf{fma}\left(x, \mathsf{fma}\left(x \cdot x, 43.3400022514, \mathsf{fma}\left(x, \mathsf{fma}\left(x, x, 263.505074721\right), 313.399215894\right)\right), 47.066876606\right)}{x - 2.0}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(4.16438922228, x, \frac{y}{x \cdot x} - 110.1139242984811\right)\\ \end{array}\]
\frac{\left(x - 2.0\right) \cdot \left(\left(\left(\left(x \cdot 4.16438922228 + 78.6994924154\right) \cdot x + 137.519416416\right) \cdot x + y\right) \cdot x + z\right)}{\left(\left(\left(x + 43.3400022514\right) \cdot x + 263.505074721\right) \cdot x + 313.399215894\right) \cdot x + 47.066876606}
\begin{array}{l}
\mathbf{if}\;x \le -5.140336158145698 \cdot 10^{+17}:\\
\;\;\;\;\mathsf{fma}\left(4.16438922228, x, \frac{y}{x \cdot x} - 110.1139242984811\right)\\

\mathbf{elif}\;x \le 1.692613215272597 \cdot 10^{+44}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x, \mathsf{fma}\left(x, \mathsf{fma}\left(\mathsf{fma}\left(4.16438922228, x, 78.6994924154\right), x, 137.519416416\right), y\right), z\right)}{\frac{\mathsf{fma}\left(x, \mathsf{fma}\left(x \cdot x, 43.3400022514, \mathsf{fma}\left(x, \mathsf{fma}\left(x, x, 263.505074721\right), 313.399215894\right)\right), 47.066876606\right)}{x - 2.0}}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(4.16438922228, x, \frac{y}{x \cdot x} - 110.1139242984811\right)\\

\end{array}
double f(double x, double y, double z) {
        double r15627233 = x;
        double r15627234 = 2.0;
        double r15627235 = r15627233 - r15627234;
        double r15627236 = 4.16438922228;
        double r15627237 = r15627233 * r15627236;
        double r15627238 = 78.6994924154;
        double r15627239 = r15627237 + r15627238;
        double r15627240 = r15627239 * r15627233;
        double r15627241 = 137.519416416;
        double r15627242 = r15627240 + r15627241;
        double r15627243 = r15627242 * r15627233;
        double r15627244 = y;
        double r15627245 = r15627243 + r15627244;
        double r15627246 = r15627245 * r15627233;
        double r15627247 = z;
        double r15627248 = r15627246 + r15627247;
        double r15627249 = r15627235 * r15627248;
        double r15627250 = 43.3400022514;
        double r15627251 = r15627233 + r15627250;
        double r15627252 = r15627251 * r15627233;
        double r15627253 = 263.505074721;
        double r15627254 = r15627252 + r15627253;
        double r15627255 = r15627254 * r15627233;
        double r15627256 = 313.399215894;
        double r15627257 = r15627255 + r15627256;
        double r15627258 = r15627257 * r15627233;
        double r15627259 = 47.066876606;
        double r15627260 = r15627258 + r15627259;
        double r15627261 = r15627249 / r15627260;
        return r15627261;
}

double f(double x, double y, double z) {
        double r15627262 = x;
        double r15627263 = -5.140336158145698e+17;
        bool r15627264 = r15627262 <= r15627263;
        double r15627265 = 4.16438922228;
        double r15627266 = y;
        double r15627267 = r15627262 * r15627262;
        double r15627268 = r15627266 / r15627267;
        double r15627269 = 110.1139242984811;
        double r15627270 = r15627268 - r15627269;
        double r15627271 = fma(r15627265, r15627262, r15627270);
        double r15627272 = 1.692613215272597e+44;
        bool r15627273 = r15627262 <= r15627272;
        double r15627274 = 78.6994924154;
        double r15627275 = fma(r15627265, r15627262, r15627274);
        double r15627276 = 137.519416416;
        double r15627277 = fma(r15627275, r15627262, r15627276);
        double r15627278 = fma(r15627262, r15627277, r15627266);
        double r15627279 = z;
        double r15627280 = fma(r15627262, r15627278, r15627279);
        double r15627281 = 43.3400022514;
        double r15627282 = 263.505074721;
        double r15627283 = fma(r15627262, r15627262, r15627282);
        double r15627284 = 313.399215894;
        double r15627285 = fma(r15627262, r15627283, r15627284);
        double r15627286 = fma(r15627267, r15627281, r15627285);
        double r15627287 = 47.066876606;
        double r15627288 = fma(r15627262, r15627286, r15627287);
        double r15627289 = 2.0;
        double r15627290 = r15627262 - r15627289;
        double r15627291 = r15627288 / r15627290;
        double r15627292 = r15627280 / r15627291;
        double r15627293 = r15627273 ? r15627292 : r15627271;
        double r15627294 = r15627264 ? r15627271 : r15627293;
        return r15627294;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original26.0
Target0.4
Herbie0.8
\[\begin{array}{l} \mathbf{if}\;x \lt -3.326128725870005 \cdot 10^{+62}:\\ \;\;\;\;\left(\frac{y}{x \cdot x} + 4.16438922228 \cdot x\right) - 110.1139242984811\\ \mathbf{elif}\;x \lt 9.429991714554673 \cdot 10^{+55}:\\ \;\;\;\;\frac{x - 2.0}{1} \cdot \frac{\left(\left(\left(x \cdot 4.16438922228 + 78.6994924154\right) \cdot x + 137.519416416\right) \cdot x + y\right) \cdot x + z}{\left(\left(263.505074721 \cdot x + \left(43.3400022514 \cdot \left(x \cdot x\right) + x \cdot \left(x \cdot x\right)\right)\right) + 313.399215894\right) \cdot x + 47.066876606}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{y}{x \cdot x} + 4.16438922228 \cdot x\right) - 110.1139242984811\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if x < -5.140336158145698e+17 or 1.692613215272597e+44 < x

    1. Initial program 56.2

      \[\frac{\left(x - 2.0\right) \cdot \left(\left(\left(\left(x \cdot 4.16438922228 + 78.6994924154\right) \cdot x + 137.519416416\right) \cdot x + y\right) \cdot x + z\right)}{\left(\left(\left(x + 43.3400022514\right) \cdot x + 263.505074721\right) \cdot x + 313.399215894\right) \cdot x + 47.066876606}\]
    2. Simplified52.9

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \mathsf{fma}\left(x, \mathsf{fma}\left(x, \mathsf{fma}\left(x, 4.16438922228, 78.6994924154\right), 137.519416416\right), y\right), z\right) \cdot \frac{x - 2.0}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(43.3400022514 + x, x, 263.505074721\right), x, 313.399215894\right), x, 47.066876606\right)}}\]
    3. Taylor expanded around inf 1.3

      \[\leadsto \color{blue}{\left(\frac{y}{{x}^{2}} + 4.16438922228 \cdot x\right) - 110.1139242984811}\]
    4. Simplified1.3

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

    if -5.140336158145698e+17 < x < 1.692613215272597e+44

    1. Initial program 0.7

      \[\frac{\left(x - 2.0\right) \cdot \left(\left(\left(\left(x \cdot 4.16438922228 + 78.6994924154\right) \cdot x + 137.519416416\right) \cdot x + y\right) \cdot x + z\right)}{\left(\left(\left(x + 43.3400022514\right) \cdot x + 263.505074721\right) \cdot x + 313.399215894\right) \cdot x + 47.066876606}\]
    2. Simplified0.7

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \mathsf{fma}\left(x, \mathsf{fma}\left(x, \mathsf{fma}\left(x, 4.16438922228, 78.6994924154\right), 137.519416416\right), y\right), z\right) \cdot \frac{x - 2.0}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(43.3400022514 + x, x, 263.505074721\right), x, 313.399215894\right), x, 47.066876606\right)}}\]
    3. Using strategy rm
    4. Applied fma-udef0.7

      \[\leadsto \mathsf{fma}\left(x, \mathsf{fma}\left(x, \mathsf{fma}\left(x, \mathsf{fma}\left(x, 4.16438922228, 78.6994924154\right), 137.519416416\right), y\right), z\right) \cdot \frac{x - 2.0}{\mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(43.3400022514 + x, x, 263.505074721\right) \cdot x + 313.399215894}, x, 47.066876606\right)}\]
    5. Taylor expanded around 0 0.7

      \[\leadsto \mathsf{fma}\left(x, \mathsf{fma}\left(x, \mathsf{fma}\left(x, \mathsf{fma}\left(x, 4.16438922228, 78.6994924154\right), 137.519416416\right), y\right), z\right) \cdot \frac{x - 2.0}{\mathsf{fma}\left(\color{blue}{\left(263.505074721 \cdot x + \left({x}^{3} + 43.3400022514 \cdot {x}^{2}\right)\right)} + 313.399215894, x, 47.066876606\right)}\]
    6. Simplified0.7

      \[\leadsto \mathsf{fma}\left(x, \mathsf{fma}\left(x, \mathsf{fma}\left(x, \mathsf{fma}\left(x, 4.16438922228, 78.6994924154\right), 137.519416416\right), y\right), z\right) \cdot \frac{x - 2.0}{\mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(x \cdot x, 43.3400022514, x \cdot \left(263.505074721 + x \cdot x\right)\right)} + 313.399215894, x, 47.066876606\right)}\]
    7. Using strategy rm
    8. Applied *-un-lft-identity0.7

      \[\leadsto \color{blue}{\left(1 \cdot \mathsf{fma}\left(x, \mathsf{fma}\left(x, \mathsf{fma}\left(x, \mathsf{fma}\left(x, 4.16438922228, 78.6994924154\right), 137.519416416\right), y\right), z\right)\right)} \cdot \frac{x - 2.0}{\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 43.3400022514, x \cdot \left(263.505074721 + x \cdot x\right)\right) + 313.399215894, x, 47.066876606\right)}\]
    9. Applied associate-*l*0.7

      \[\leadsto \color{blue}{1 \cdot \left(\mathsf{fma}\left(x, \mathsf{fma}\left(x, \mathsf{fma}\left(x, \mathsf{fma}\left(x, 4.16438922228, 78.6994924154\right), 137.519416416\right), y\right), z\right) \cdot \frac{x - 2.0}{\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 43.3400022514, x \cdot \left(263.505074721 + x \cdot x\right)\right) + 313.399215894, x, 47.066876606\right)}\right)}\]
    10. Simplified0.3

      \[\leadsto 1 \cdot \color{blue}{\frac{\mathsf{fma}\left(x, \mathsf{fma}\left(x, \mathsf{fma}\left(\mathsf{fma}\left(4.16438922228, x, 78.6994924154\right), x, 137.519416416\right), y\right), z\right)}{\frac{\mathsf{fma}\left(x, \mathsf{fma}\left(x \cdot x, 43.3400022514, \mathsf{fma}\left(x, \mathsf{fma}\left(x, x, 263.505074721\right), 313.399215894\right)\right), 47.066876606\right)}{x - 2.0}}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -5.140336158145698 \cdot 10^{+17}:\\ \;\;\;\;\mathsf{fma}\left(4.16438922228, x, \frac{y}{x \cdot x} - 110.1139242984811\right)\\ \mathbf{elif}\;x \le 1.692613215272597 \cdot 10^{+44}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, \mathsf{fma}\left(x, \mathsf{fma}\left(\mathsf{fma}\left(4.16438922228, x, 78.6994924154\right), x, 137.519416416\right), y\right), z\right)}{\frac{\mathsf{fma}\left(x, \mathsf{fma}\left(x \cdot x, 43.3400022514, \mathsf{fma}\left(x, \mathsf{fma}\left(x, x, 263.505074721\right), 313.399215894\right)\right), 47.066876606\right)}{x - 2.0}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(4.16438922228, x, \frac{y}{x \cdot x} - 110.1139242984811\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019163 +o rules:numerics
(FPCore (x y z)
  :name "Numeric.SpecFunctions:logGamma from math-functions-0.1.5.2, C"

  :herbie-target
  (if (< x -3.326128725870005e+62) (- (+ (/ y (* x x)) (* 4.16438922228 x)) 110.1139242984811) (if (< x 9.429991714554673e+55) (* (/ (- x 2.0) 1) (/ (+ (* (+ (* (+ (* (+ (* x 4.16438922228) 78.6994924154) x) 137.519416416) x) y) x) z) (+ (* (+ (+ (* 263.505074721 x) (+ (* 43.3400022514 (* x x)) (* x (* x x)))) 313.399215894) x) 47.066876606))) (- (+ (/ y (* x x)) (* 4.16438922228 x)) 110.1139242984811)))

  (/ (* (- x 2.0) (+ (* (+ (* (+ (* (+ (* x 4.16438922228) 78.6994924154) x) 137.519416416) x) y) x) z)) (+ (* (+ (* (+ (* (+ x 43.3400022514) x) 263.505074721) x) 313.399215894) x) 47.066876606)))