Average Error: 26.0 → 0.8
Time: 23.3s
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 r16836183 = x;
        double r16836184 = 2.0;
        double r16836185 = r16836183 - r16836184;
        double r16836186 = 4.16438922228;
        double r16836187 = r16836183 * r16836186;
        double r16836188 = 78.6994924154;
        double r16836189 = r16836187 + r16836188;
        double r16836190 = r16836189 * r16836183;
        double r16836191 = 137.519416416;
        double r16836192 = r16836190 + r16836191;
        double r16836193 = r16836192 * r16836183;
        double r16836194 = y;
        double r16836195 = r16836193 + r16836194;
        double r16836196 = r16836195 * r16836183;
        double r16836197 = z;
        double r16836198 = r16836196 + r16836197;
        double r16836199 = r16836185 * r16836198;
        double r16836200 = 43.3400022514;
        double r16836201 = r16836183 + r16836200;
        double r16836202 = r16836201 * r16836183;
        double r16836203 = 263.505074721;
        double r16836204 = r16836202 + r16836203;
        double r16836205 = r16836204 * r16836183;
        double r16836206 = 313.399215894;
        double r16836207 = r16836205 + r16836206;
        double r16836208 = r16836207 * r16836183;
        double r16836209 = 47.066876606;
        double r16836210 = r16836208 + r16836209;
        double r16836211 = r16836199 / r16836210;
        return r16836211;
}

double f(double x, double y, double z) {
        double r16836212 = x;
        double r16836213 = -5.140336158145698e+17;
        bool r16836214 = r16836212 <= r16836213;
        double r16836215 = 4.16438922228;
        double r16836216 = y;
        double r16836217 = r16836212 * r16836212;
        double r16836218 = r16836216 / r16836217;
        double r16836219 = 110.1139242984811;
        double r16836220 = r16836218 - r16836219;
        double r16836221 = fma(r16836215, r16836212, r16836220);
        double r16836222 = 1.692613215272597e+44;
        bool r16836223 = r16836212 <= r16836222;
        double r16836224 = 78.6994924154;
        double r16836225 = fma(r16836215, r16836212, r16836224);
        double r16836226 = 137.519416416;
        double r16836227 = fma(r16836225, r16836212, r16836226);
        double r16836228 = fma(r16836212, r16836227, r16836216);
        double r16836229 = z;
        double r16836230 = fma(r16836212, r16836228, r16836229);
        double r16836231 = 43.3400022514;
        double r16836232 = 263.505074721;
        double r16836233 = fma(r16836212, r16836212, r16836232);
        double r16836234 = 313.399215894;
        double r16836235 = fma(r16836212, r16836233, r16836234);
        double r16836236 = fma(r16836217, r16836231, r16836235);
        double r16836237 = 47.066876606;
        double r16836238 = fma(r16836212, r16836236, r16836237);
        double r16836239 = 2.0;
        double r16836240 = r16836212 - r16836239;
        double r16836241 = r16836238 / r16836240;
        double r16836242 = r16836230 / r16836241;
        double r16836243 = r16836223 ? r16836242 : r16836221;
        double r16836244 = r16836214 ? r16836221 : r16836243;
        return r16836244;
}

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