Average Error: 29.5 → 1.3
Time: 16.9s
Precision: binary64
\[x + \frac{y \cdot \left(\left(\left(\left(z \cdot 3.13060547623 + 11.1667541262\right) \cdot z + t\right) \cdot z + a\right) \cdot z + b\right)}{\left(\left(\left(z + 15.234687407\right) \cdot z + 31.4690115749\right) \cdot z + 11.9400905721\right) \cdot z + 0.607771387771} \]
\[\begin{array}{l} t_1 := 3.13060547623 - \frac{36.527041698806414}{z}\\ \mathbf{if}\;z \leq -494793505743926.2:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{1}{z \cdot z} \cdot \left(t + 457.96100221584277\right) + t_1, x\right)\\ \mathbf{elif}\;z \leq 4.670877542172956 \cdot 10^{+62}:\\ \;\;\;\;\begin{array}{l} t_2 := \sqrt{\mathsf{fma}\left(z, \mathsf{fma}\left(z, \mathsf{fma}\left(z, z + 15.234687407, 31.4690115749\right), 11.9400905721\right), 0.607771387771\right)}\\ \mathsf{fma}\left(y, \frac{1}{t_2} \cdot \frac{\mathsf{fma}\left(z, \mathsf{fma}\left(z, \mathsf{fma}\left(z, \mathsf{fma}\left(z, 3.13060547623, 11.1667541262\right), t\right), a\right), b\right)}{t_2}, x\right) \end{array}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, t_1 + \left(\frac{457.96100221584277}{z \cdot z} + \frac{t}{z \cdot z}\right), x\right)\\ \end{array} \]
x + \frac{y \cdot \left(\left(\left(\left(z \cdot 3.13060547623 + 11.1667541262\right) \cdot z + t\right) \cdot z + a\right) \cdot z + b\right)}{\left(\left(\left(z + 15.234687407\right) \cdot z + 31.4690115749\right) \cdot z + 11.9400905721\right) \cdot z + 0.607771387771}
\begin{array}{l}
t_1 := 3.13060547623 - \frac{36.527041698806414}{z}\\
\mathbf{if}\;z \leq -494793505743926.2:\\
\;\;\;\;\mathsf{fma}\left(y, \frac{1}{z \cdot z} \cdot \left(t + 457.96100221584277\right) + t_1, x\right)\\

\mathbf{elif}\;z \leq 4.670877542172956 \cdot 10^{+62}:\\
\;\;\;\;\begin{array}{l}
t_2 := \sqrt{\mathsf{fma}\left(z, \mathsf{fma}\left(z, \mathsf{fma}\left(z, z + 15.234687407, 31.4690115749\right), 11.9400905721\right), 0.607771387771\right)}\\
\mathsf{fma}\left(y, \frac{1}{t_2} \cdot \frac{\mathsf{fma}\left(z, \mathsf{fma}\left(z, \mathsf{fma}\left(z, \mathsf{fma}\left(z, 3.13060547623, 11.1667541262\right), t\right), a\right), b\right)}{t_2}, x\right)
\end{array}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, t_1 + \left(\frac{457.96100221584277}{z \cdot z} + \frac{t}{z \cdot z}\right), x\right)\\


\end{array}
(FPCore (x y z t a b)
 :precision binary64
 (+
  x
  (/
   (*
    y
    (+ (* (+ (* (+ (* (+ (* z 3.13060547623) 11.1667541262) z) t) z) a) z) b))
   (+
    (* (+ (* (+ (* (+ z 15.234687407) z) 31.4690115749) z) 11.9400905721) z)
    0.607771387771))))
(FPCore (x y z t a b)
 :precision binary64
 (let* ((t_1 (- 3.13060547623 (/ 36.527041698806414 z))))
   (if (<= z -494793505743926.2)
     (fma y (+ (* (/ 1.0 (* z z)) (+ t 457.96100221584277)) t_1) x)
     (if (<= z 4.670877542172956e+62)
       (let* ((t_2
               (sqrt
                (fma
                 z
                 (fma z (fma z (+ z 15.234687407) 31.4690115749) 11.9400905721)
                 0.607771387771))))
         (fma
          y
          (*
           (/ 1.0 t_2)
           (/
            (fma z (fma z (fma z (fma z 3.13060547623 11.1667541262) t) a) b)
            t_2))
          x))
       (fma y (+ t_1 (+ (/ 457.96100221584277 (* z z)) (/ t (* z z)))) x)))))
double code(double x, double y, double z, double t, double a, double b) {
	return x + ((y * ((((((((z * 3.13060547623) + 11.1667541262) * z) + t) * z) + a) * z) + b)) / (((((((z + 15.234687407) * z) + 31.4690115749) * z) + 11.9400905721) * z) + 0.607771387771));
}
double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = 3.13060547623 - (36.527041698806414 / z);
	double tmp;
	if (z <= -494793505743926.2) {
		tmp = fma(y, (((1.0 / (z * z)) * (t + 457.96100221584277)) + t_1), x);
	} else if (z <= 4.670877542172956e+62) {
		double t_2 = sqrt(fma(z, fma(z, fma(z, (z + 15.234687407), 31.4690115749), 11.9400905721), 0.607771387771));
		tmp = fma(y, ((1.0 / t_2) * (fma(z, fma(z, fma(z, fma(z, 3.13060547623, 11.1667541262), t), a), b) / t_2)), x);
	} else {
		tmp = fma(y, (t_1 + ((457.96100221584277 / (z * z)) + (t / (z * z)))), x);
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Bits error versus a

Bits error versus b

Target

Original29.5
Target0.9
Herbie1.3
\[\begin{array}{l} \mathbf{if}\;z < -6.499344996252632 \cdot 10^{+53}:\\ \;\;\;\;x + \left(\left(3.13060547623 - \frac{36.527041698806414}{z}\right) + \frac{t}{z \cdot z}\right) \cdot \frac{y}{1}\\ \mathbf{elif}\;z < 7.066965436914287 \cdot 10^{+59}:\\ \;\;\;\;x + \frac{y}{\frac{\left(\left(\left(z + 15.234687407\right) \cdot z + 31.4690115749\right) \cdot z + 11.9400905721\right) \cdot z + 0.607771387771}{\left(\left(\left(z \cdot 3.13060547623 + 11.1667541262\right) \cdot z + t\right) \cdot z + a\right) \cdot z + b}}\\ \mathbf{else}:\\ \;\;\;\;x + \left(\left(3.13060547623 - \frac{36.527041698806414}{z}\right) + \frac{t}{z \cdot z}\right) \cdot \frac{y}{1}\\ \end{array} \]

Derivation

  1. Split input into 3 regimes
  2. if z < -494793505743926.188

    1. Initial program 57.3

      \[x + \frac{y \cdot \left(\left(\left(\left(z \cdot 3.13060547623 + 11.1667541262\right) \cdot z + t\right) \cdot z + a\right) \cdot z + b\right)}{\left(\left(\left(z + 15.234687407\right) \cdot z + 31.4690115749\right) \cdot z + 11.9400905721\right) \cdot z + 0.607771387771} \]
    2. Simplified54.1

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, \frac{\mathsf{fma}\left(z, \mathsf{fma}\left(z, \mathsf{fma}\left(z, \mathsf{fma}\left(z, 3.13060547623, 11.1667541262\right), t\right), a\right), b\right)}{\mathsf{fma}\left(z, \mathsf{fma}\left(z, \mathsf{fma}\left(z, z + 15.234687407, 31.4690115749\right), 11.9400905721\right), 0.607771387771\right)}, x\right)} \]
    3. Taylor expanded in z around inf 2.2

      \[\leadsto \mathsf{fma}\left(y, \color{blue}{\left(3.13060547623 + \left(457.96100221584277 \cdot \frac{1}{{z}^{2}} + \frac{t}{{z}^{2}}\right)\right) - 36.527041698806414 \cdot \frac{1}{z}}, x\right) \]
    4. Simplified2.2

      \[\leadsto \mathsf{fma}\left(y, \color{blue}{\left(\frac{457.96100221584277}{z \cdot z} + \frac{t}{z \cdot z}\right) + \left(3.13060547623 - \frac{36.527041698806414}{z}\right)}, x\right) \]
    5. Applied div-inv_binary642.2

      \[\leadsto \mathsf{fma}\left(y, \left(\frac{457.96100221584277}{z \cdot z} + \color{blue}{t \cdot \frac{1}{z \cdot z}}\right) + \left(3.13060547623 - \frac{36.527041698806414}{z}\right), x\right) \]
    6. Applied div-inv_binary642.2

      \[\leadsto \mathsf{fma}\left(y, \left(\color{blue}{457.96100221584277 \cdot \frac{1}{z \cdot z}} + t \cdot \frac{1}{z \cdot z}\right) + \left(3.13060547623 - \frac{36.527041698806414}{z}\right), x\right) \]
    7. Applied distribute-rgt-out_binary642.2

      \[\leadsto \mathsf{fma}\left(y, \color{blue}{\frac{1}{z \cdot z} \cdot \left(457.96100221584277 + t\right)} + \left(3.13060547623 - \frac{36.527041698806414}{z}\right), x\right) \]
    8. Simplified2.2

      \[\leadsto \mathsf{fma}\left(y, \frac{1}{z \cdot z} \cdot \color{blue}{\left(t + 457.96100221584277\right)} + \left(3.13060547623 - \frac{36.527041698806414}{z}\right), x\right) \]

    if -494793505743926.188 < z < 4.67087754217295609e62

    1. Initial program 2.0

      \[x + \frac{y \cdot \left(\left(\left(\left(z \cdot 3.13060547623 + 11.1667541262\right) \cdot z + t\right) \cdot z + a\right) \cdot z + b\right)}{\left(\left(\left(z + 15.234687407\right) \cdot z + 31.4690115749\right) \cdot z + 11.9400905721\right) \cdot z + 0.607771387771} \]
    2. Simplified0.8

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, \frac{\mathsf{fma}\left(z, \mathsf{fma}\left(z, \mathsf{fma}\left(z, \mathsf{fma}\left(z, 3.13060547623, 11.1667541262\right), t\right), a\right), b\right)}{\mathsf{fma}\left(z, \mathsf{fma}\left(z, \mathsf{fma}\left(z, z + 15.234687407, 31.4690115749\right), 11.9400905721\right), 0.607771387771\right)}, x\right)} \]
    3. Applied add-sqr-sqrt_binary641.3

      \[\leadsto \mathsf{fma}\left(y, \frac{\mathsf{fma}\left(z, \mathsf{fma}\left(z, \mathsf{fma}\left(z, \mathsf{fma}\left(z, 3.13060547623, 11.1667541262\right), t\right), a\right), b\right)}{\color{blue}{\sqrt{\mathsf{fma}\left(z, \mathsf{fma}\left(z, \mathsf{fma}\left(z, z + 15.234687407, 31.4690115749\right), 11.9400905721\right), 0.607771387771\right)} \cdot \sqrt{\mathsf{fma}\left(z, \mathsf{fma}\left(z, \mathsf{fma}\left(z, z + 15.234687407, 31.4690115749\right), 11.9400905721\right), 0.607771387771\right)}}}, x\right) \]
    4. Applied *-un-lft-identity_binary641.3

      \[\leadsto \mathsf{fma}\left(y, \frac{\color{blue}{1 \cdot \mathsf{fma}\left(z, \mathsf{fma}\left(z, \mathsf{fma}\left(z, \mathsf{fma}\left(z, 3.13060547623, 11.1667541262\right), t\right), a\right), b\right)}}{\sqrt{\mathsf{fma}\left(z, \mathsf{fma}\left(z, \mathsf{fma}\left(z, z + 15.234687407, 31.4690115749\right), 11.9400905721\right), 0.607771387771\right)} \cdot \sqrt{\mathsf{fma}\left(z, \mathsf{fma}\left(z, \mathsf{fma}\left(z, z + 15.234687407, 31.4690115749\right), 11.9400905721\right), 0.607771387771\right)}}, x\right) \]
    5. Applied times-frac_binary641.1

      \[\leadsto \mathsf{fma}\left(y, \color{blue}{\frac{1}{\sqrt{\mathsf{fma}\left(z, \mathsf{fma}\left(z, \mathsf{fma}\left(z, z + 15.234687407, 31.4690115749\right), 11.9400905721\right), 0.607771387771\right)}} \cdot \frac{\mathsf{fma}\left(z, \mathsf{fma}\left(z, \mathsf{fma}\left(z, \mathsf{fma}\left(z, 3.13060547623, 11.1667541262\right), t\right), a\right), b\right)}{\sqrt{\mathsf{fma}\left(z, \mathsf{fma}\left(z, \mathsf{fma}\left(z, z + 15.234687407, 31.4690115749\right), 11.9400905721\right), 0.607771387771\right)}}}, x\right) \]

    if 4.67087754217295609e62 < z

    1. Initial program 63.0

      \[x + \frac{y \cdot \left(\left(\left(\left(z \cdot 3.13060547623 + 11.1667541262\right) \cdot z + t\right) \cdot z + a\right) \cdot z + b\right)}{\left(\left(\left(z + 15.234687407\right) \cdot z + 31.4690115749\right) \cdot z + 11.9400905721\right) \cdot z + 0.607771387771} \]
    2. Simplified61.6

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, \frac{\mathsf{fma}\left(z, \mathsf{fma}\left(z, \mathsf{fma}\left(z, \mathsf{fma}\left(z, 3.13060547623, 11.1667541262\right), t\right), a\right), b\right)}{\mathsf{fma}\left(z, \mathsf{fma}\left(z, \mathsf{fma}\left(z, z + 15.234687407, 31.4690115749\right), 11.9400905721\right), 0.607771387771\right)}, x\right)} \]
    3. Taylor expanded in z around inf 0.6

      \[\leadsto \mathsf{fma}\left(y, \color{blue}{\left(3.13060547623 + \left(457.96100221584277 \cdot \frac{1}{{z}^{2}} + \frac{t}{{z}^{2}}\right)\right) - 36.527041698806414 \cdot \frac{1}{z}}, x\right) \]
    4. Simplified0.6

      \[\leadsto \mathsf{fma}\left(y, \color{blue}{\left(\frac{457.96100221584277}{z \cdot z} + \frac{t}{z \cdot z}\right) + \left(3.13060547623 - \frac{36.527041698806414}{z}\right)}, x\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification1.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -494793505743926.2:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{1}{z \cdot z} \cdot \left(t + 457.96100221584277\right) + \left(3.13060547623 - \frac{36.527041698806414}{z}\right), x\right)\\ \mathbf{elif}\;z \leq 4.670877542172956 \cdot 10^{+62}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{1}{\sqrt{\mathsf{fma}\left(z, \mathsf{fma}\left(z, \mathsf{fma}\left(z, z + 15.234687407, 31.4690115749\right), 11.9400905721\right), 0.607771387771\right)}} \cdot \frac{\mathsf{fma}\left(z, \mathsf{fma}\left(z, \mathsf{fma}\left(z, \mathsf{fma}\left(z, 3.13060547623, 11.1667541262\right), t\right), a\right), b\right)}{\sqrt{\mathsf{fma}\left(z, \mathsf{fma}\left(z, \mathsf{fma}\left(z, z + 15.234687407, 31.4690115749\right), 11.9400905721\right), 0.607771387771\right)}}, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, \left(3.13060547623 - \frac{36.527041698806414}{z}\right) + \left(\frac{457.96100221584277}{z \cdot z} + \frac{t}{z \cdot z}\right), x\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2021215 
(FPCore (x y z t a b)
  :name "Numeric.SpecFunctions:logGamma from math-functions-0.1.5.2, D"
  :precision binary64

  :herbie-target
  (if (< z -6.499344996252632e+53) (+ x (* (+ (- 3.13060547623 (/ 36.527041698806414 z)) (/ t (* z z))) (/ y 1.0))) (if (< z 7.066965436914287e+59) (+ x (/ y (/ (+ (* (+ (* (+ (* (+ z 15.234687407) z) 31.4690115749) z) 11.9400905721) z) 0.607771387771) (+ (* (+ (* (+ (* (+ (* z 3.13060547623) 11.1667541262) z) t) z) a) z) b)))) (+ x (* (+ (- 3.13060547623 (/ 36.527041698806414 z)) (/ t (* z z))) (/ y 1.0)))))

  (+ x (/ (* y (+ (* (+ (* (+ (* (+ (* z 3.13060547623) 11.1667541262) z) t) z) a) z) b)) (+ (* (+ (* (+ (* (+ z 15.234687407) z) 31.4690115749) z) 11.9400905721) z) 0.607771387771))))