Average Error: 26.7 → 0.7
Time: 29.8s
Precision: 64
\[\frac{\left(x - 2\right) \cdot \left(\left(\left(\left(x \cdot 4.16438922227999963610045597306452691555 + 78.69949241540000173245061887428164482117\right) \cdot x + 137.5194164160000127594685181975364685059\right) \cdot x + y\right) \cdot x + z\right)}{\left(\left(\left(x + 43.3400022514000013984514225739985704422\right) \cdot x + 263.5050747210000281484099105000495910645\right) \cdot x + 313.3992158940000081202015280723571777344\right) \cdot x + 47.06687660600000100430406746454536914825}\]
\[\begin{array}{l} \mathbf{if}\;x \le -41468195884167556148326040140678955008 \lor \neg \left(x \le 4.185814178876573776200097393718801150489 \cdot 10^{51}\right):\\ \;\;\;\;\mathsf{fma}\left(x, 4.16438922227999963610045597306452691555, \frac{y}{{x}^{2}}\right) - 110.1139242984810806547102401964366436005\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{fma}\left(x, x, 2 \cdot \left(x + 2\right)\right)} \cdot \frac{{x}^{3} - {2}^{3}}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x + 43.3400022514000013984514225739985704422, x, 263.5050747210000281484099105000495910645\right), x, 313.3992158940000081202015280723571777344\right), x, 47.06687660600000100430406746454536914825\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x, 4.16438922227999963610045597306452691555, 78.69949241540000173245061887428164482117\right), x, 137.5194164160000127594685181975364685059\right), x, y\right), x, z\right)}}\\ \end{array}\]
\frac{\left(x - 2\right) \cdot \left(\left(\left(\left(x \cdot 4.16438922227999963610045597306452691555 + 78.69949241540000173245061887428164482117\right) \cdot x + 137.5194164160000127594685181975364685059\right) \cdot x + y\right) \cdot x + z\right)}{\left(\left(\left(x + 43.3400022514000013984514225739985704422\right) \cdot x + 263.5050747210000281484099105000495910645\right) \cdot x + 313.3992158940000081202015280723571777344\right) \cdot x + 47.06687660600000100430406746454536914825}
\begin{array}{l}
\mathbf{if}\;x \le -41468195884167556148326040140678955008 \lor \neg \left(x \le 4.185814178876573776200097393718801150489 \cdot 10^{51}\right):\\
\;\;\;\;\mathsf{fma}\left(x, 4.16438922227999963610045597306452691555, \frac{y}{{x}^{2}}\right) - 110.1139242984810806547102401964366436005\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(x, x, 2 \cdot \left(x + 2\right)\right)} \cdot \frac{{x}^{3} - {2}^{3}}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x + 43.3400022514000013984514225739985704422, x, 263.5050747210000281484099105000495910645\right), x, 313.3992158940000081202015280723571777344\right), x, 47.06687660600000100430406746454536914825\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x, 4.16438922227999963610045597306452691555, 78.69949241540000173245061887428164482117\right), x, 137.5194164160000127594685181975364685059\right), x, y\right), x, z\right)}}\\

\end{array}
double f(double x, double y, double z) {
        double r288875 = x;
        double r288876 = 2.0;
        double r288877 = r288875 - r288876;
        double r288878 = 4.16438922228;
        double r288879 = r288875 * r288878;
        double r288880 = 78.6994924154;
        double r288881 = r288879 + r288880;
        double r288882 = r288881 * r288875;
        double r288883 = 137.519416416;
        double r288884 = r288882 + r288883;
        double r288885 = r288884 * r288875;
        double r288886 = y;
        double r288887 = r288885 + r288886;
        double r288888 = r288887 * r288875;
        double r288889 = z;
        double r288890 = r288888 + r288889;
        double r288891 = r288877 * r288890;
        double r288892 = 43.3400022514;
        double r288893 = r288875 + r288892;
        double r288894 = r288893 * r288875;
        double r288895 = 263.505074721;
        double r288896 = r288894 + r288895;
        double r288897 = r288896 * r288875;
        double r288898 = 313.399215894;
        double r288899 = r288897 + r288898;
        double r288900 = r288899 * r288875;
        double r288901 = 47.066876606;
        double r288902 = r288900 + r288901;
        double r288903 = r288891 / r288902;
        return r288903;
}

double f(double x, double y, double z) {
        double r288904 = x;
        double r288905 = -4.1468195884167556e+37;
        bool r288906 = r288904 <= r288905;
        double r288907 = 4.185814178876574e+51;
        bool r288908 = r288904 <= r288907;
        double r288909 = !r288908;
        bool r288910 = r288906 || r288909;
        double r288911 = 4.16438922228;
        double r288912 = y;
        double r288913 = 2.0;
        double r288914 = pow(r288904, r288913);
        double r288915 = r288912 / r288914;
        double r288916 = fma(r288904, r288911, r288915);
        double r288917 = 110.11392429848108;
        double r288918 = r288916 - r288917;
        double r288919 = 1.0;
        double r288920 = 2.0;
        double r288921 = r288904 + r288920;
        double r288922 = r288920 * r288921;
        double r288923 = fma(r288904, r288904, r288922);
        double r288924 = r288919 / r288923;
        double r288925 = 3.0;
        double r288926 = pow(r288904, r288925);
        double r288927 = pow(r288920, r288925);
        double r288928 = r288926 - r288927;
        double r288929 = 43.3400022514;
        double r288930 = r288904 + r288929;
        double r288931 = 263.505074721;
        double r288932 = fma(r288930, r288904, r288931);
        double r288933 = 313.399215894;
        double r288934 = fma(r288932, r288904, r288933);
        double r288935 = 47.066876606;
        double r288936 = fma(r288934, r288904, r288935);
        double r288937 = 78.6994924154;
        double r288938 = fma(r288904, r288911, r288937);
        double r288939 = 137.519416416;
        double r288940 = fma(r288938, r288904, r288939);
        double r288941 = fma(r288940, r288904, r288912);
        double r288942 = z;
        double r288943 = fma(r288941, r288904, r288942);
        double r288944 = r288936 / r288943;
        double r288945 = r288928 / r288944;
        double r288946 = r288924 * r288945;
        double r288947 = r288910 ? r288918 : r288946;
        return r288947;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original26.7
Target0.4
Herbie0.7
\[\begin{array}{l} \mathbf{if}\;x \lt -3.326128725870004842699683658678411714981 \cdot 10^{62}:\\ \;\;\;\;\left(\frac{y}{x \cdot x} + 4.16438922227999963610045597306452691555 \cdot x\right) - 110.1139242984810948655649553984403610229\\ \mathbf{elif}\;x \lt 9.429991714554672672712552870340896976735 \cdot 10^{55}:\\ \;\;\;\;\frac{x - 2}{1} \cdot \frac{\left(\left(\left(x \cdot 4.16438922227999963610045597306452691555 + 78.69949241540000173245061887428164482117\right) \cdot x + 137.5194164160000127594685181975364685059\right) \cdot x + y\right) \cdot x + z}{\left(\left(263.5050747210000281484099105000495910645 \cdot x + \left(43.3400022514000013984514225739985704422 \cdot \left(x \cdot x\right) + x \cdot \left(x \cdot x\right)\right)\right) + 313.3992158940000081202015280723571777344\right) \cdot x + 47.06687660600000100430406746454536914825}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{y}{x \cdot x} + 4.16438922227999963610045597306452691555 \cdot x\right) - 110.1139242984810948655649553984403610229\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if x < -4.1468195884167556e+37 or 4.185814178876574e+51 < x

    1. Initial program 60.8

      \[\frac{\left(x - 2\right) \cdot \left(\left(\left(\left(x \cdot 4.16438922227999963610045597306452691555 + 78.69949241540000173245061887428164482117\right) \cdot x + 137.5194164160000127594685181975364685059\right) \cdot x + y\right) \cdot x + z\right)}{\left(\left(\left(x + 43.3400022514000013984514225739985704422\right) \cdot x + 263.5050747210000281484099105000495910645\right) \cdot x + 313.3992158940000081202015280723571777344\right) \cdot x + 47.06687660600000100430406746454536914825}\]
    2. Simplified57.5

      \[\leadsto \color{blue}{\frac{x - 2}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x + 43.3400022514000013984514225739985704422, x, 263.5050747210000281484099105000495910645\right), x, 313.3992158940000081202015280723571777344\right), x, 47.06687660600000100430406746454536914825\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x, 4.16438922227999963610045597306452691555, 78.69949241540000173245061887428164482117\right), x, 137.5194164160000127594685181975364685059\right), x, y\right), x, z\right)}}}\]
    3. Using strategy rm
    4. Applied flip3--57.5

      \[\leadsto \frac{\color{blue}{\frac{{x}^{3} - {2}^{3}}{x \cdot x + \left(2 \cdot 2 + x \cdot 2\right)}}}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x + 43.3400022514000013984514225739985704422, x, 263.5050747210000281484099105000495910645\right), x, 313.3992158940000081202015280723571777344\right), x, 47.06687660600000100430406746454536914825\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x, 4.16438922227999963610045597306452691555, 78.69949241540000173245061887428164482117\right), x, 137.5194164160000127594685181975364685059\right), x, y\right), x, z\right)}}\]
    5. Applied associate-/l/57.5

      \[\leadsto \color{blue}{\frac{{x}^{3} - {2}^{3}}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x + 43.3400022514000013984514225739985704422, x, 263.5050747210000281484099105000495910645\right), x, 313.3992158940000081202015280723571777344\right), x, 47.06687660600000100430406746454536914825\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x, 4.16438922227999963610045597306452691555, 78.69949241540000173245061887428164482117\right), x, 137.5194164160000127594685181975364685059\right), x, y\right), x, z\right)} \cdot \left(x \cdot x + \left(2 \cdot 2 + x \cdot 2\right)\right)}}\]
    6. Simplified57.5

      \[\leadsto \frac{{x}^{3} - {2}^{3}}{\color{blue}{\mathsf{fma}\left(x, x, 2 \cdot \left(x + 2\right)\right) \cdot \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x + 43.3400022514000013984514225739985704422, x, 263.5050747210000281484099105000495910645\right), x, 313.3992158940000081202015280723571777344\right), x, 47.06687660600000100430406746454536914825\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x, 4.16438922227999963610045597306452691555, 78.69949241540000173245061887428164482117\right), x, 137.5194164160000127594685181975364685059\right), x, y\right), x, z\right)}}}\]
    7. Taylor expanded around inf 0.7

      \[\leadsto \color{blue}{\left(\frac{y}{{x}^{2}} + 4.16438922227999963610045597306452691555 \cdot x\right) - 110.1139242984810806547102401964366436005}\]
    8. Simplified0.7

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, 4.16438922227999963610045597306452691555, \frac{y}{{x}^{2}}\right) - 110.1139242984810806547102401964366436005}\]

    if -4.1468195884167556e+37 < x < 4.185814178876574e+51

    1. Initial program 0.9

      \[\frac{\left(x - 2\right) \cdot \left(\left(\left(\left(x \cdot 4.16438922227999963610045597306452691555 + 78.69949241540000173245061887428164482117\right) \cdot x + 137.5194164160000127594685181975364685059\right) \cdot x + y\right) \cdot x + z\right)}{\left(\left(\left(x + 43.3400022514000013984514225739985704422\right) \cdot x + 263.5050747210000281484099105000495910645\right) \cdot x + 313.3992158940000081202015280723571777344\right) \cdot x + 47.06687660600000100430406746454536914825}\]
    2. Simplified0.7

      \[\leadsto \color{blue}{\frac{x - 2}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x + 43.3400022514000013984514225739985704422, x, 263.5050747210000281484099105000495910645\right), x, 313.3992158940000081202015280723571777344\right), x, 47.06687660600000100430406746454536914825\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x, 4.16438922227999963610045597306452691555, 78.69949241540000173245061887428164482117\right), x, 137.5194164160000127594685181975364685059\right), x, y\right), x, z\right)}}}\]
    3. Using strategy rm
    4. Applied flip3--0.7

      \[\leadsto \frac{\color{blue}{\frac{{x}^{3} - {2}^{3}}{x \cdot x + \left(2 \cdot 2 + x \cdot 2\right)}}}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x + 43.3400022514000013984514225739985704422, x, 263.5050747210000281484099105000495910645\right), x, 313.3992158940000081202015280723571777344\right), x, 47.06687660600000100430406746454536914825\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x, 4.16438922227999963610045597306452691555, 78.69949241540000173245061887428164482117\right), x, 137.5194164160000127594685181975364685059\right), x, y\right), x, z\right)}}\]
    5. Applied associate-/l/0.7

      \[\leadsto \color{blue}{\frac{{x}^{3} - {2}^{3}}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x + 43.3400022514000013984514225739985704422, x, 263.5050747210000281484099105000495910645\right), x, 313.3992158940000081202015280723571777344\right), x, 47.06687660600000100430406746454536914825\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x, 4.16438922227999963610045597306452691555, 78.69949241540000173245061887428164482117\right), x, 137.5194164160000127594685181975364685059\right), x, y\right), x, z\right)} \cdot \left(x \cdot x + \left(2 \cdot 2 + x \cdot 2\right)\right)}}\]
    6. Simplified0.7

      \[\leadsto \frac{{x}^{3} - {2}^{3}}{\color{blue}{\mathsf{fma}\left(x, x, 2 \cdot \left(x + 2\right)\right) \cdot \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x + 43.3400022514000013984514225739985704422, x, 263.5050747210000281484099105000495910645\right), x, 313.3992158940000081202015280723571777344\right), x, 47.06687660600000100430406746454536914825\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x, 4.16438922227999963610045597306452691555, 78.69949241540000173245061887428164482117\right), x, 137.5194164160000127594685181975364685059\right), x, y\right), x, z\right)}}}\]
    7. Using strategy rm
    8. Applied *-un-lft-identity0.7

      \[\leadsto \frac{\color{blue}{1 \cdot \left({x}^{3} - {2}^{3}\right)}}{\mathsf{fma}\left(x, x, 2 \cdot \left(x + 2\right)\right) \cdot \frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x + 43.3400022514000013984514225739985704422, x, 263.5050747210000281484099105000495910645\right), x, 313.3992158940000081202015280723571777344\right), x, 47.06687660600000100430406746454536914825\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x, 4.16438922227999963610045597306452691555, 78.69949241540000173245061887428164482117\right), x, 137.5194164160000127594685181975364685059\right), x, y\right), x, z\right)}}\]
    9. Applied times-frac0.7

      \[\leadsto \color{blue}{\frac{1}{\mathsf{fma}\left(x, x, 2 \cdot \left(x + 2\right)\right)} \cdot \frac{{x}^{3} - {2}^{3}}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x + 43.3400022514000013984514225739985704422, x, 263.5050747210000281484099105000495910645\right), x, 313.3992158940000081202015280723571777344\right), x, 47.06687660600000100430406746454536914825\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x, 4.16438922227999963610045597306452691555, 78.69949241540000173245061887428164482117\right), x, 137.5194164160000127594685181975364685059\right), x, y\right), x, z\right)}}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -41468195884167556148326040140678955008 \lor \neg \left(x \le 4.185814178876573776200097393718801150489 \cdot 10^{51}\right):\\ \;\;\;\;\mathsf{fma}\left(x, 4.16438922227999963610045597306452691555, \frac{y}{{x}^{2}}\right) - 110.1139242984810806547102401964366436005\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{fma}\left(x, x, 2 \cdot \left(x + 2\right)\right)} \cdot \frac{{x}^{3} - {2}^{3}}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x + 43.3400022514000013984514225739985704422, x, 263.5050747210000281484099105000495910645\right), x, 313.3992158940000081202015280723571777344\right), x, 47.06687660600000100430406746454536914825\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x, 4.16438922227999963610045597306452691555, 78.69949241540000173245061887428164482117\right), x, 137.5194164160000127594685181975364685059\right), x, y\right), x, z\right)}}\\ \end{array}\]

Reproduce

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

  :herbie-target
  (if (< x -3.3261287258700048e62) (- (+ (/ y (* x x)) (* 4.16438922227999964 x)) 110.11392429848109) (if (< x 9.4299917145546727e55) (* (/ (- x 2) 1) (/ (+ (* (+ (* (+ (* (+ (* x 4.16438922227999964) 78.6994924154000017) x) 137.51941641600001) x) y) x) z) (+ (* (+ (+ (* 263.50507472100003 x) (+ (* 43.3400022514000014 (* x x)) (* x (* x x)))) 313.399215894) x) 47.066876606000001))) (- (+ (/ y (* x x)) (* 4.16438922227999964 x)) 110.11392429848109)))

  (/ (* (- x 2) (+ (* (+ (* (+ (* (+ (* x 4.16438922227999964) 78.6994924154000017) x) 137.51941641600001) x) y) x) z)) (+ (* (+ (* (+ (* (+ x 43.3400022514000014) x) 263.50507472100003) x) 313.399215894) x) 47.066876606000001)))