Average Error: 19.9 → 0.7
Time: 4.7s
Precision: binary64
\[x + \frac{y \cdot \left(\left(z \cdot 0.0692910599291889 + 0.4917317610505968\right) \cdot z + 0.279195317918525\right)}{\left(z + 6.012459259764103\right) \cdot z + 3.350343815022304} \]
\[\begin{array}{l} t_0 := \mathsf{fma}\left(y, \left(\left(0.0692910599291889 + \frac{0.07512208616047561}{z}\right) - \frac{0.4046220386999212}{z \cdot z}\right) + \frac{2.181088706546648}{{z}^{3}}, x\right)\\ \mathbf{if}\;z \leq -5.35837927315707:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 4.770054248343753 \cdot 10^{-9}:\\ \;\;\;\;\mathsf{fma}\left(y, 0.08333333333333323, x\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
x + \frac{y \cdot \left(\left(z \cdot 0.0692910599291889 + 0.4917317610505968\right) \cdot z + 0.279195317918525\right)}{\left(z + 6.012459259764103\right) \cdot z + 3.350343815022304}
\begin{array}{l}
t_0 := \mathsf{fma}\left(y, \left(\left(0.0692910599291889 + \frac{0.07512208616047561}{z}\right) - \frac{0.4046220386999212}{z \cdot z}\right) + \frac{2.181088706546648}{{z}^{3}}, x\right)\\
\mathbf{if}\;z \leq -5.35837927315707:\\
\;\;\;\;t_0\\

\mathbf{elif}\;z \leq 4.770054248343753 \cdot 10^{-9}:\\
\;\;\;\;\mathsf{fma}\left(y, 0.08333333333333323, x\right)\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
(FPCore (x y z)
 :precision binary64
 (+
  x
  (/
   (*
    y
    (+
     (* (+ (* z 0.0692910599291889) 0.4917317610505968) z)
     0.279195317918525))
   (+ (* (+ z 6.012459259764103) z) 3.350343815022304))))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0
         (fma
          y
          (+
           (-
            (+ 0.0692910599291889 (/ 0.07512208616047561 z))
            (/ 0.4046220386999212 (* z z)))
           (/ 2.181088706546648 (pow z 3.0)))
          x)))
   (if (<= z -5.35837927315707)
     t_0
     (if (<= z 4.770054248343753e-9) (fma y 0.08333333333333323 x) t_0))))
double code(double x, double y, double z) {
	return x + ((y * ((((z * 0.0692910599291889) + 0.4917317610505968) * z) + 0.279195317918525)) / (((z + 6.012459259764103) * z) + 3.350343815022304));
}
double code(double x, double y, double z) {
	double t_0 = fma(y, (((0.0692910599291889 + (0.07512208616047561 / z)) - (0.4046220386999212 / (z * z))) + (2.181088706546648 / pow(z, 3.0))), x);
	double tmp;
	if (z <= -5.35837927315707) {
		tmp = t_0;
	} else if (z <= 4.770054248343753e-9) {
		tmp = fma(y, 0.08333333333333323, x);
	} else {
		tmp = t_0;
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original19.9
Target0.4
Herbie0.7
\[\begin{array}{l} \mathbf{if}\;z < -8120153.652456675:\\ \;\;\;\;\left(\frac{0.07512208616047561}{z} + 0.0692910599291889\right) \cdot y - \left(\frac{0.40462203869992125 \cdot y}{z \cdot z} - x\right)\\ \mathbf{elif}\;z < 6.576118972787377 \cdot 10^{+20}:\\ \;\;\;\;x + \left(y \cdot \left(\left(z \cdot 0.0692910599291889 + 0.4917317610505968\right) \cdot z + 0.279195317918525\right)\right) \cdot \frac{1}{\left(z + 6.012459259764103\right) \cdot z + 3.350343815022304}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{0.07512208616047561}{z} + 0.0692910599291889\right) \cdot y - \left(\frac{0.40462203869992125 \cdot y}{z \cdot z} - x\right)\\ \end{array} \]

Derivation

  1. Split input into 2 regimes
  2. if z < -5.3583792731570696 or 4.77005424834375259e-9 < z

    1. Initial program 39.2

      \[x + \frac{y \cdot \left(\left(z \cdot 0.0692910599291889 + 0.4917317610505968\right) \cdot z + 0.279195317918525\right)}{\left(z + 6.012459259764103\right) \cdot z + 3.350343815022304} \]
    2. Simplified30.7

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, \frac{\mathsf{fma}\left(z, \mathsf{fma}\left(z, 0.0692910599291889, 0.4917317610505968\right), 0.279195317918525\right)}{\mathsf{fma}\left(z, z + 6.012459259764103, 3.350343815022304\right)}, x\right)} \]
    3. Taylor expanded in z around inf 0.8

      \[\leadsto \mathsf{fma}\left(y, \color{blue}{\left(0.0692910599291889 + \left(2.181088706546648 \cdot \frac{1}{{z}^{3}} + 0.07512208616047561 \cdot \frac{1}{z}\right)\right) - 0.4046220386999212 \cdot \frac{1}{{z}^{2}}}, x\right) \]
    4. Simplified0.8

      \[\leadsto \mathsf{fma}\left(y, \color{blue}{\left(\left(0.0692910599291889 + \frac{0.07512208616047561}{z}\right) - \frac{0.4046220386999212}{z \cdot z}\right) + \frac{2.181088706546648}{{z}^{3}}}, x\right) \]

    if -5.3583792731570696 < z < 4.77005424834375259e-9

    1. Initial program 0.2

      \[x + \frac{y \cdot \left(\left(z \cdot 0.0692910599291889 + 0.4917317610505968\right) \cdot z + 0.279195317918525\right)}{\left(z + 6.012459259764103\right) \cdot z + 3.350343815022304} \]
    2. Simplified0.1

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, \frac{\mathsf{fma}\left(z, \mathsf{fma}\left(z, 0.0692910599291889, 0.4917317610505968\right), 0.279195317918525\right)}{\mathsf{fma}\left(z, z + 6.012459259764103, 3.350343815022304\right)}, x\right)} \]
    3. Taylor expanded in z around 0 0.5

      \[\leadsto \mathsf{fma}\left(y, \color{blue}{0.08333333333333323}, x\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -5.35837927315707:\\ \;\;\;\;\mathsf{fma}\left(y, \left(\left(0.0692910599291889 + \frac{0.07512208616047561}{z}\right) - \frac{0.4046220386999212}{z \cdot z}\right) + \frac{2.181088706546648}{{z}^{3}}, x\right)\\ \mathbf{elif}\;z \leq 4.770054248343753 \cdot 10^{-9}:\\ \;\;\;\;\mathsf{fma}\left(y, 0.08333333333333323, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, \left(\left(0.0692910599291889 + \frac{0.07512208616047561}{z}\right) - \frac{0.4046220386999212}{z \cdot z}\right) + \frac{2.181088706546648}{{z}^{3}}, x\right)\\ \end{array} \]

Reproduce

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

  :herbie-target
  (if (< z -8120153.652456675) (- (* (+ (/ 0.07512208616047561 z) 0.0692910599291889) y) (- (/ (* 0.40462203869992125 y) (* z z)) x)) (if (< z 6.576118972787377e+20) (+ x (* (* y (+ (* (+ (* z 0.0692910599291889) 0.4917317610505968) z) 0.279195317918525)) (/ 1.0 (+ (* (+ z 6.012459259764103) z) 3.350343815022304)))) (- (* (+ (/ 0.07512208616047561 z) 0.0692910599291889) y) (- (/ (* 0.40462203869992125 y) (* z z)) x))))

  (+ x (/ (* y (+ (* (+ (* z 0.0692910599291889) 0.4917317610505968) z) 0.279195317918525)) (+ (* (+ z 6.012459259764103) z) 3.350343815022304))))