Average Error: 29.5 → 1.2
Time: 20.5s
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 := \mathsf{fma}\left(3.13060547623, y, \mathsf{fma}\left(457.9610022158428, \frac{y}{z \cdot z}, x\right)\right) + \frac{y}{z} \cdot \left(\frac{t}{z} - 36.52704169880642\right)\\ \mathbf{if}\;z \leq -1.3893820671621353 \cdot 10^{+41}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 5.935878230367541 \cdot 10^{+41}:\\ \;\;\;\;\mathsf{fma}\left(y, \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) \cdot \frac{1}{\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}:\\ \;\;\;\;t_1\\ \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
         (+
          (fma 3.13060547623 y (fma 457.9610022158428 (/ y (* z z)) x))
          (* (/ y z) (- (/ t z) 36.52704169880642)))))
   (if (<= z -1.3893820671621353e+41)
     t_1
     (if (<= z 5.935878230367541e+41)
       (fma
        y
        (*
         (fma z (fma z (fma z (fma z 3.13060547623 11.1667541262) t) a) b)
         (/
          1.0
          (fma
           z
           (fma z (fma z (+ z 15.234687407) 31.4690115749) 11.9400905721)
           0.607771387771)))
        x)
       t_1))))
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 = fma(3.13060547623, y, fma(457.9610022158428, (y / (z * z)), x)) + ((y / z) * ((t / z) - 36.52704169880642));
	double tmp;
	if (z <= -1.3893820671621353e+41) {
		tmp = t_1;
	} else if (z <= 5.935878230367541e+41) {
		tmp = fma(y, (fma(z, fma(z, fma(z, fma(z, 3.13060547623, 11.1667541262), t), a), b) * (1.0 / fma(z, fma(z, fma(z, (z + 15.234687407), 31.4690115749), 11.9400905721), 0.607771387771))), x);
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(x, y, z, t, a, b)
	return Float64(x + Float64(Float64(y * Float64(Float64(Float64(Float64(Float64(Float64(Float64(Float64(z * 3.13060547623) + 11.1667541262) * z) + t) * z) + a) * z) + b)) / Float64(Float64(Float64(Float64(Float64(Float64(Float64(z + 15.234687407) * z) + 31.4690115749) * z) + 11.9400905721) * z) + 0.607771387771)))
end
function code(x, y, z, t, a, b)
	t_1 = Float64(fma(3.13060547623, y, fma(457.9610022158428, Float64(y / Float64(z * z)), x)) + Float64(Float64(y / z) * Float64(Float64(t / z) - 36.52704169880642)))
	tmp = 0.0
	if (z <= -1.3893820671621353e+41)
		tmp = t_1;
	elseif (z <= 5.935878230367541e+41)
		tmp = fma(y, Float64(fma(z, fma(z, fma(z, fma(z, 3.13060547623, 11.1667541262), t), a), b) * Float64(1.0 / fma(z, fma(z, fma(z, Float64(z + 15.234687407), 31.4690115749), 11.9400905721), 0.607771387771))), x);
	else
		tmp = t_1;
	end
	return tmp
end
code[x_, y_, z_, t_, a_, b_] := N[(x + N[(N[(y * N[(N[(N[(N[(N[(N[(N[(N[(z * 3.13060547623), $MachinePrecision] + 11.1667541262), $MachinePrecision] * z), $MachinePrecision] + t), $MachinePrecision] * z), $MachinePrecision] + a), $MachinePrecision] * z), $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision] / N[(N[(N[(N[(N[(N[(N[(z + 15.234687407), $MachinePrecision] * z), $MachinePrecision] + 31.4690115749), $MachinePrecision] * z), $MachinePrecision] + 11.9400905721), $MachinePrecision] * z), $MachinePrecision] + 0.607771387771), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(N[(3.13060547623 * y + N[(457.9610022158428 * N[(y / N[(z * z), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision] + N[(N[(y / z), $MachinePrecision] * N[(N[(t / z), $MachinePrecision] - 36.52704169880642), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.3893820671621353e+41], t$95$1, If[LessEqual[z, 5.935878230367541e+41], N[(y * N[(N[(z * N[(z * N[(z * N[(z * 3.13060547623 + 11.1667541262), $MachinePrecision] + t), $MachinePrecision] + a), $MachinePrecision] + b), $MachinePrecision] * N[(1.0 / N[(z * N[(z * N[(z * N[(z + 15.234687407), $MachinePrecision] + 31.4690115749), $MachinePrecision] + 11.9400905721), $MachinePrecision] + 0.607771387771), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], t$95$1]]]
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 := \mathsf{fma}\left(3.13060547623, y, \mathsf{fma}\left(457.9610022158428, \frac{y}{z \cdot z}, x\right)\right) + \frac{y}{z} \cdot \left(\frac{t}{z} - 36.52704169880642\right)\\
\mathbf{if}\;z \leq -1.3893820671621353 \cdot 10^{+41}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;z \leq 5.935878230367541 \cdot 10^{+41}:\\
\;\;\;\;\mathsf{fma}\left(y, \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) \cdot \frac{1}{\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}:\\
\;\;\;\;t_1\\


\end{array}

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
Target1.1
Herbie1.2
\[\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 2 regimes
  2. if z < -1.38938206716213526e41 or 5.935878230367541e41 < z

    1. Initial program 60.4

      \[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. Simplified57.7

      \[\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 9.1

      \[\leadsto \color{blue}{\left(\frac{y \cdot t}{{z}^{2}} + \left(3.13060547623 \cdot y + \left(457.9610022158428 \cdot \frac{y}{{z}^{2}} + x\right)\right)\right) - 36.52704169880642 \cdot \frac{y}{z}} \]
    4. Simplified1.7

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

    if -1.38938206716213526e41 < z < 5.935878230367541e41

    1. Initial program 1.8

      \[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.7

      \[\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 div-inv_binary640.7

      \[\leadsto \mathsf{fma}\left(y, \color{blue}{\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) \cdot \frac{1}{\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. Recombined 2 regimes into one program.
  4. Final simplification1.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.3893820671621353 \cdot 10^{+41}:\\ \;\;\;\;\mathsf{fma}\left(3.13060547623, y, \mathsf{fma}\left(457.9610022158428, \frac{y}{z \cdot z}, x\right)\right) + \frac{y}{z} \cdot \left(\frac{t}{z} - 36.52704169880642\right)\\ \mathbf{elif}\;z \leq 5.935878230367541 \cdot 10^{+41}:\\ \;\;\;\;\mathsf{fma}\left(y, \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) \cdot \frac{1}{\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(3.13060547623, y, \mathsf{fma}\left(457.9610022158428, \frac{y}{z \cdot z}, x\right)\right) + \frac{y}{z} \cdot \left(\frac{t}{z} - 36.52704169880642\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2022131 
(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))))