Average Error: 27.2 → 2.0
Time: 19.2s
Precision: binary64
\[\frac{\left(x - 2\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} t_0 := {x}^{4} + \left(47.066876606 + \mathsf{fma}\left(x, 313.399215894, x \cdot \left(x \cdot \left(263.505074721 + x \cdot 43.3400022514\right)\right)\right)\right)\\ \mathbf{if}\;\frac{\left(x - 2\right) \cdot \left(x \cdot \left(x \cdot \left(x \cdot \left(x \cdot 4.16438922228 + 78.6994924154\right) + 137.519416416\right) + y\right) + z\right)}{x \cdot \left(x \cdot \left(x \cdot \left(x + 43.3400022514\right) + 263.505074721\right) + 313.399215894\right) + 47.066876606} \leq 2.9467826638862636 \cdot 10^{+294}:\\ \;\;\;\;\mathsf{fma}\left(70.37071397084, \frac{{x}^{4}}{t_0}, \mathsf{fma}\left(4.16438922228, \frac{{x}^{5}}{t_0}, \frac{x \cdot z}{t_0}\right)\right) + \left(\left(x - 2\right) \cdot \frac{x \cdot y}{t_0} - \mathsf{fma}\left(2, \frac{z}{t_0}, \mathsf{fma}\left(275.038832832, \frac{x \cdot x}{t_0}, 19.8795684148 \cdot \frac{{x}^{3}}{t_0}\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\mathsf{fma}\left(x, 4.16438922228, \frac{3655.1204654076414}{x}\right) + \frac{y}{x \cdot x}\right) - \left(110.1139242984811 + \frac{130977.50649958357}{x \cdot x}\right)\\ \end{array} \]
\frac{\left(x - 2\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}
t_0 := {x}^{4} + \left(47.066876606 + \mathsf{fma}\left(x, 313.399215894, x \cdot \left(x \cdot \left(263.505074721 + x \cdot 43.3400022514\right)\right)\right)\right)\\
\mathbf{if}\;\frac{\left(x - 2\right) \cdot \left(x \cdot \left(x \cdot \left(x \cdot \left(x \cdot 4.16438922228 + 78.6994924154\right) + 137.519416416\right) + y\right) + z\right)}{x \cdot \left(x \cdot \left(x \cdot \left(x + 43.3400022514\right) + 263.505074721\right) + 313.399215894\right) + 47.066876606} \leq 2.9467826638862636 \cdot 10^{+294}:\\
\;\;\;\;\mathsf{fma}\left(70.37071397084, \frac{{x}^{4}}{t_0}, \mathsf{fma}\left(4.16438922228, \frac{{x}^{5}}{t_0}, \frac{x \cdot z}{t_0}\right)\right) + \left(\left(x - 2\right) \cdot \frac{x \cdot y}{t_0} - \mathsf{fma}\left(2, \frac{z}{t_0}, \mathsf{fma}\left(275.038832832, \frac{x \cdot x}{t_0}, 19.8795684148 \cdot \frac{{x}^{3}}{t_0}\right)\right)\right)\\

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


\end{array}
(FPCore (x y z)
 :precision binary64
 (/
  (*
   (- 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)))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0
         (+
          (pow x 4.0)
          (+
           47.066876606
           (fma
            x
            313.399215894
            (* x (* x (+ 263.505074721 (* x 43.3400022514)))))))))
   (if (<=
        (/
         (*
          (- x 2.0)
          (+
           (*
            x
            (+
             (*
              x
              (+ (* x (+ (* x 4.16438922228) 78.6994924154)) 137.519416416))
             y))
           z))
         (+
          (*
           x
           (+ (* x (+ (* x (+ x 43.3400022514)) 263.505074721)) 313.399215894))
          47.066876606))
        2.9467826638862636e+294)
     (+
      (fma
       70.37071397084
       (/ (pow x 4.0) t_0)
       (fma 4.16438922228 (/ (pow x 5.0) t_0) (/ (* x z) t_0)))
      (-
       (* (- x 2.0) (/ (* x y) t_0))
       (fma
        2.0
        (/ z t_0)
        (fma
         275.038832832
         (/ (* x x) t_0)
         (* 19.8795684148 (/ (pow x 3.0) t_0))))))
     (-
      (+ (fma x 4.16438922228 (/ 3655.1204654076414 x)) (/ y (* x x)))
      (+ 110.1139242984811 (/ 130977.50649958357 (* x x)))))))
double code(double x, double y, double z) {
	return ((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);
}
double code(double x, double y, double z) {
	double t_0 = pow(x, 4.0) + (47.066876606 + fma(x, 313.399215894, (x * (x * (263.505074721 + (x * 43.3400022514))))));
	double tmp;
	if ((((x - 2.0) * ((x * ((x * ((x * ((x * 4.16438922228) + 78.6994924154)) + 137.519416416)) + y)) + z)) / ((x * ((x * ((x * (x + 43.3400022514)) + 263.505074721)) + 313.399215894)) + 47.066876606)) <= 2.9467826638862636e+294) {
		tmp = fma(70.37071397084, (pow(x, 4.0) / t_0), fma(4.16438922228, (pow(x, 5.0) / t_0), ((x * z) / t_0))) + (((x - 2.0) * ((x * y) / t_0)) - fma(2.0, (z / t_0), fma(275.038832832, ((x * x) / t_0), (19.8795684148 * (pow(x, 3.0) / t_0)))));
	} else {
		tmp = (fma(x, 4.16438922228, (3655.1204654076414 / x)) + (y / (x * x))) - (110.1139242984811 + (130977.50649958357 / (x * x)));
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original27.2
Target0.8
Herbie2.0
\[\begin{array}{l} \mathbf{if}\;x < -3.326128725870005 \cdot 10^{+62}:\\ \;\;\;\;\left(\frac{y}{x \cdot x} + 4.16438922228 \cdot x\right) - 110.1139242984811\\ \mathbf{elif}\;x < 9.429991714554673 \cdot 10^{+55}:\\ \;\;\;\;\frac{x - 2}{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 (/.f64 (*.f64 (-.f64 x 2) (+.f64 (*.f64 (+.f64 (*.f64 (+.f64 (*.f64 (+.f64 (*.f64 x 104109730557/25000000000) 393497462077/5000000000) x) 4297481763/31250000) x) y) x) z)) (+.f64 (*.f64 (+.f64 (*.f64 (+.f64 (*.f64 (+.f64 x 216700011257/5000000000) x) 263505074721/1000000000) x) 156699607947/500000000) x) 23533438303/500000000)) < 2.9467826638862636e294

    1. Initial program 2.4

      \[\frac{\left(x - 2\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. Taylor expanded in y around 0 2.3

      \[\leadsto \color{blue}{\left(70.37071397084 \cdot \frac{{x}^{4}}{{x}^{4} + \left(47.066876606 + \left(263.505074721 \cdot {x}^{2} + \left(43.3400022514 \cdot {x}^{3} + 313.399215894 \cdot x\right)\right)\right)} + \left(\frac{y \cdot {x}^{2}}{{x}^{4} + \left(47.066876606 + \left(263.505074721 \cdot {x}^{2} + \left(43.3400022514 \cdot {x}^{3} + 313.399215894 \cdot x\right)\right)\right)} + \left(4.16438922228 \cdot \frac{{x}^{5}}{{x}^{4} + \left(47.066876606 + \left(263.505074721 \cdot {x}^{2} + \left(43.3400022514 \cdot {x}^{3} + 313.399215894 \cdot x\right)\right)\right)} + \frac{z \cdot x}{{x}^{4} + \left(47.066876606 + \left(263.505074721 \cdot {x}^{2} + \left(43.3400022514 \cdot {x}^{3} + 313.399215894 \cdot x\right)\right)\right)}\right)\right)\right) - \left(2 \cdot \frac{y \cdot x}{{x}^{4} + \left(47.066876606 + \left(263.505074721 \cdot {x}^{2} + \left(43.3400022514 \cdot {x}^{3} + 313.399215894 \cdot x\right)\right)\right)} + \left(2 \cdot \frac{z}{{x}^{4} + \left(47.066876606 + \left(263.505074721 \cdot {x}^{2} + \left(43.3400022514 \cdot {x}^{3} + 313.399215894 \cdot x\right)\right)\right)} + \left(275.038832832 \cdot \frac{{x}^{2}}{{x}^{4} + \left(47.066876606 + \left(263.505074721 \cdot {x}^{2} + \left(43.3400022514 \cdot {x}^{3} + 313.399215894 \cdot x\right)\right)\right)} + 19.8795684148 \cdot \frac{{x}^{3}}{{x}^{4} + \left(47.066876606 + \left(263.505074721 \cdot {x}^{2} + \left(43.3400022514 \cdot {x}^{3} + 313.399215894 \cdot x\right)\right)\right)}\right)\right)\right)} \]
    3. Simplified2.1

      \[\leadsto \color{blue}{\mathsf{fma}\left(70.37071397084, \frac{{x}^{4}}{{x}^{4} + \left(47.066876606 + \mathsf{fma}\left(x, 313.399215894, x \cdot \left(x \cdot \left(263.505074721 + 43.3400022514 \cdot x\right)\right)\right)\right)}, \mathsf{fma}\left(4.16438922228, \frac{{x}^{5}}{{x}^{4} + \left(47.066876606 + \mathsf{fma}\left(x, 313.399215894, x \cdot \left(x \cdot \left(263.505074721 + 43.3400022514 \cdot x\right)\right)\right)\right)}, \frac{z \cdot x}{{x}^{4} + \left(47.066876606 + \mathsf{fma}\left(x, 313.399215894, x \cdot \left(x \cdot \left(263.505074721 + 43.3400022514 \cdot x\right)\right)\right)\right)}\right)\right) + \left(\frac{x \cdot y}{{x}^{4} + \left(47.066876606 + \mathsf{fma}\left(x, 313.399215894, x \cdot \left(x \cdot \left(263.505074721 + 43.3400022514 \cdot x\right)\right)\right)\right)} \cdot \left(x - 2\right) - \mathsf{fma}\left(2, \frac{z}{{x}^{4} + \left(47.066876606 + \mathsf{fma}\left(x, 313.399215894, x \cdot \left(x \cdot \left(263.505074721 + 43.3400022514 \cdot x\right)\right)\right)\right)}, \mathsf{fma}\left(275.038832832, \frac{x \cdot x}{{x}^{4} + \left(47.066876606 + \mathsf{fma}\left(x, 313.399215894, x \cdot \left(x \cdot \left(263.505074721 + 43.3400022514 \cdot x\right)\right)\right)\right)}, 19.8795684148 \cdot \frac{{x}^{3}}{{x}^{4} + \left(47.066876606 + \mathsf{fma}\left(x, 313.399215894, x \cdot \left(x \cdot \left(263.505074721 + 43.3400022514 \cdot x\right)\right)\right)\right)}\right)\right)\right)} \]

    if 2.9467826638862636e294 < (/.f64 (*.f64 (-.f64 x 2) (+.f64 (*.f64 (+.f64 (*.f64 (+.f64 (*.f64 (+.f64 (*.f64 x 104109730557/25000000000) 393497462077/5000000000) x) 4297481763/31250000) x) y) x) z)) (+.f64 (*.f64 (+.f64 (*.f64 (+.f64 (*.f64 (+.f64 x 216700011257/5000000000) x) 263505074721/1000000000) x) 156699607947/500000000) x) 23533438303/500000000))

    1. Initial program 63.3

      \[\frac{\left(x - 2\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. Taylor expanded in x around inf 1.7

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

      \[\leadsto \color{blue}{\left(\mathsf{fma}\left(x, 4.16438922228, \frac{3655.1204654076414}{x}\right) + \frac{y}{x \cdot x}\right) - \left(110.1139242984811 + \frac{130977.50649958357}{x \cdot x}\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification2.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\left(x - 2\right) \cdot \left(x \cdot \left(x \cdot \left(x \cdot \left(x \cdot 4.16438922228 + 78.6994924154\right) + 137.519416416\right) + y\right) + z\right)}{x \cdot \left(x \cdot \left(x \cdot \left(x + 43.3400022514\right) + 263.505074721\right) + 313.399215894\right) + 47.066876606} \leq 2.9467826638862636 \cdot 10^{+294}:\\ \;\;\;\;\mathsf{fma}\left(70.37071397084, \frac{{x}^{4}}{{x}^{4} + \left(47.066876606 + \mathsf{fma}\left(x, 313.399215894, x \cdot \left(x \cdot \left(263.505074721 + x \cdot 43.3400022514\right)\right)\right)\right)}, \mathsf{fma}\left(4.16438922228, \frac{{x}^{5}}{{x}^{4} + \left(47.066876606 + \mathsf{fma}\left(x, 313.399215894, x \cdot \left(x \cdot \left(263.505074721 + x \cdot 43.3400022514\right)\right)\right)\right)}, \frac{x \cdot z}{{x}^{4} + \left(47.066876606 + \mathsf{fma}\left(x, 313.399215894, x \cdot \left(x \cdot \left(263.505074721 + x \cdot 43.3400022514\right)\right)\right)\right)}\right)\right) + \left(\left(x - 2\right) \cdot \frac{x \cdot y}{{x}^{4} + \left(47.066876606 + \mathsf{fma}\left(x, 313.399215894, x \cdot \left(x \cdot \left(263.505074721 + x \cdot 43.3400022514\right)\right)\right)\right)} - \mathsf{fma}\left(2, \frac{z}{{x}^{4} + \left(47.066876606 + \mathsf{fma}\left(x, 313.399215894, x \cdot \left(x \cdot \left(263.505074721 + x \cdot 43.3400022514\right)\right)\right)\right)}, \mathsf{fma}\left(275.038832832, \frac{x \cdot x}{{x}^{4} + \left(47.066876606 + \mathsf{fma}\left(x, 313.399215894, x \cdot \left(x \cdot \left(263.505074721 + x \cdot 43.3400022514\right)\right)\right)\right)}, 19.8795684148 \cdot \frac{{x}^{3}}{{x}^{4} + \left(47.066876606 + \mathsf{fma}\left(x, 313.399215894, x \cdot \left(x \cdot \left(263.505074721 + x \cdot 43.3400022514\right)\right)\right)\right)}\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\mathsf{fma}\left(x, 4.16438922228, \frac{3655.1204654076414}{x}\right) + \frac{y}{x \cdot x}\right) - \left(110.1139242984811 + \frac{130977.50649958357}{x \cdot x}\right)\\ \end{array} \]

Reproduce

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

  :herbie-target
  (if (< x -3.326128725870005e+62) (- (+ (/ y (* x x)) (* 4.16438922228 x)) 110.1139242984811) (if (< x 9.429991714554673e+55) (* (/ (- x 2.0) 1.0) (/ (+ (* (+ (* (+ (* (+ (* 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)))