?

Average Error: 41.75% → 1.61%
Time: 1.1min
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 := {\left(\frac{1}{x}\right)}^{2}\\ t_1 := \mathsf{fma}\left(\mathsf{fma}\left(x, \mathsf{fma}\left(x, \mathsf{fma}\left(x, 4.16438922228, 78.6994924154\right), 137.519416416\right), y\right), x, z\right) \cdot \left(x - 2\right)\\ t_2 := \mathsf{fma}\left(\mathsf{fma}\left(43.3400022514, {x}^{2}, \mathsf{fma}\left(263.505074721, x, {x}^{3}\right)\right) + 313.399215894, x, 47.066876606\right)\\ t_3 := \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x, 4.16438922228, 78.6994924154\right), x, 137.519416416\right), x, y\right), x, z\right)\\ \mathbf{if}\;x \leq -5.2 \cdot 10^{+51}:\\ \;\;\;\;\left(4.16438922228 \cdot x + \left(\left(y - 130977.50649958357\right) \cdot t_0 + 3655.1204654076414 \cdot \frac{1}{x}\right)\right) - 110.1139242984811\\ \mathbf{elif}\;x \leq 1.72 \cdot 10^{+65}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;x - 2 \ne 0:\\ \;\;\;\;\frac{t_3}{\frac{t_2}{x - 2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(x - 2\right) \cdot t_3}{t_2}\\ \end{array}\\ \mathbf{elif}\;t_1 \ne 0:\\ \;\;\;\;{\left(\frac{0.24013125253755718 + \left(-55.572073733743466 \cdot t_0 + 5.86923874282773 \cdot \frac{1}{x}\right)}{x - 2}\right)}^{-1}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_1}{\mathsf{fma}\left(x, \mathsf{fma}\left(x, \mathsf{fma}\left(x + 43.3400022514, x, 263.505074721\right), 313.399215894\right), 47.066876606\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 (/ 1.0 x) 2.0))
        (t_1
         (*
          (fma
           (fma x (fma x (fma x 4.16438922228 78.6994924154) 137.519416416) y)
           x
           z)
          (- x 2.0)))
        (t_2
         (fma
          (+
           (fma 43.3400022514 (pow x 2.0) (fma 263.505074721 x (pow x 3.0)))
           313.399215894)
          x
          47.066876606))
        (t_3
         (fma
          (fma (fma (fma x 4.16438922228 78.6994924154) x 137.519416416) x y)
          x
          z)))
   (if (<= x -5.2e+51)
     (-
      (+
       (* 4.16438922228 x)
       (+ (* (- y 130977.50649958357) t_0) (* 3655.1204654076414 (/ 1.0 x))))
      110.1139242984811)
     (if (<= x 1.72e+65)
       (if (!= (- x 2.0) 0.0)
         (/ t_3 (/ t_2 (- x 2.0)))
         (/ (* (- x 2.0) t_3) t_2))
       (if (!= t_1 0.0)
         (pow
          (/
           (+
            0.24013125253755718
            (+ (* -55.572073733743466 t_0) (* 5.86923874282773 (/ 1.0 x))))
           (- x 2.0))
          -1.0)
         (/
          t_1
          (fma
           x
           (fma x (fma (+ x 43.3400022514) x 263.505074721) 313.399215894)
           47.066876606)))))))
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((1.0 / x), 2.0);
	double t_1 = fma(fma(x, fma(x, fma(x, 4.16438922228, 78.6994924154), 137.519416416), y), x, z) * (x - 2.0);
	double t_2 = fma((fma(43.3400022514, pow(x, 2.0), fma(263.505074721, x, pow(x, 3.0))) + 313.399215894), x, 47.066876606);
	double t_3 = fma(fma(fma(fma(x, 4.16438922228, 78.6994924154), x, 137.519416416), x, y), x, z);
	double tmp;
	if (x <= -5.2e+51) {
		tmp = ((4.16438922228 * x) + (((y - 130977.50649958357) * t_0) + (3655.1204654076414 * (1.0 / x)))) - 110.1139242984811;
	} else if (x <= 1.72e+65) {
		double tmp_1;
		if ((x - 2.0) != 0.0) {
			tmp_1 = t_3 / (t_2 / (x - 2.0));
		} else {
			tmp_1 = ((x - 2.0) * t_3) / t_2;
		}
		tmp = tmp_1;
	} else if (t_1 != 0.0) {
		tmp = pow(((0.24013125253755718 + ((-55.572073733743466 * t_0) + (5.86923874282773 * (1.0 / x)))) / (x - 2.0)), -1.0);
	} else {
		tmp = t_1 / fma(x, fma(x, fma((x + 43.3400022514), x, 263.505074721), 313.399215894), 47.066876606);
	}
	return tmp;
}
function code(x, y, z)
	return Float64(Float64(Float64(x - 2.0) * Float64(Float64(Float64(Float64(Float64(Float64(Float64(Float64(x * 4.16438922228) + 78.6994924154) * x) + 137.519416416) * x) + y) * x) + z)) / Float64(Float64(Float64(Float64(Float64(Float64(Float64(x + 43.3400022514) * x) + 263.505074721) * x) + 313.399215894) * x) + 47.066876606))
end
function code(x, y, z)
	t_0 = Float64(1.0 / x) ^ 2.0
	t_1 = Float64(fma(fma(x, fma(x, fma(x, 4.16438922228, 78.6994924154), 137.519416416), y), x, z) * Float64(x - 2.0))
	t_2 = fma(Float64(fma(43.3400022514, (x ^ 2.0), fma(263.505074721, x, (x ^ 3.0))) + 313.399215894), x, 47.066876606)
	t_3 = fma(fma(fma(fma(x, 4.16438922228, 78.6994924154), x, 137.519416416), x, y), x, z)
	tmp = 0.0
	if (x <= -5.2e+51)
		tmp = Float64(Float64(Float64(4.16438922228 * x) + Float64(Float64(Float64(y - 130977.50649958357) * t_0) + Float64(3655.1204654076414 * Float64(1.0 / x)))) - 110.1139242984811);
	elseif (x <= 1.72e+65)
		tmp_1 = 0.0
		if (Float64(x - 2.0) != 0.0)
			tmp_1 = Float64(t_3 / Float64(t_2 / Float64(x - 2.0)));
		else
			tmp_1 = Float64(Float64(Float64(x - 2.0) * t_3) / t_2);
		end
		tmp = tmp_1;
	elseif (t_1 != 0.0)
		tmp = Float64(Float64(0.24013125253755718 + Float64(Float64(-55.572073733743466 * t_0) + Float64(5.86923874282773 * Float64(1.0 / x)))) / Float64(x - 2.0)) ^ -1.0;
	else
		tmp = Float64(t_1 / fma(x, fma(x, fma(Float64(x + 43.3400022514), x, 263.505074721), 313.399215894), 47.066876606));
	end
	return tmp
end
code[x_, y_, z_] := N[(N[(N[(x - 2.0), $MachinePrecision] * N[(N[(N[(N[(N[(N[(N[(N[(x * 4.16438922228), $MachinePrecision] + 78.6994924154), $MachinePrecision] * x), $MachinePrecision] + 137.519416416), $MachinePrecision] * x), $MachinePrecision] + y), $MachinePrecision] * x), $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision] / N[(N[(N[(N[(N[(N[(N[(x + 43.3400022514), $MachinePrecision] * x), $MachinePrecision] + 263.505074721), $MachinePrecision] * x), $MachinePrecision] + 313.399215894), $MachinePrecision] * x), $MachinePrecision] + 47.066876606), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := Block[{t$95$0 = N[Power[N[(1.0 / x), $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(x * N[(x * N[(x * 4.16438922228 + 78.6994924154), $MachinePrecision] + 137.519416416), $MachinePrecision] + y), $MachinePrecision] * x + z), $MachinePrecision] * N[(x - 2.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(43.3400022514 * N[Power[x, 2.0], $MachinePrecision] + N[(263.505074721 * x + N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + 313.399215894), $MachinePrecision] * x + 47.066876606), $MachinePrecision]}, Block[{t$95$3 = N[(N[(N[(N[(x * 4.16438922228 + 78.6994924154), $MachinePrecision] * x + 137.519416416), $MachinePrecision] * x + y), $MachinePrecision] * x + z), $MachinePrecision]}, If[LessEqual[x, -5.2e+51], N[(N[(N[(4.16438922228 * x), $MachinePrecision] + N[(N[(N[(y - 130977.50649958357), $MachinePrecision] * t$95$0), $MachinePrecision] + N[(3655.1204654076414 * N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 110.1139242984811), $MachinePrecision], If[LessEqual[x, 1.72e+65], If[Unequal[N[(x - 2.0), $MachinePrecision], 0.0], N[(t$95$3 / N[(t$95$2 / N[(x - 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x - 2.0), $MachinePrecision] * t$95$3), $MachinePrecision] / t$95$2), $MachinePrecision]], If[Unequal[t$95$1, 0.0], N[Power[N[(N[(0.24013125253755718 + N[(N[(-55.572073733743466 * t$95$0), $MachinePrecision] + N[(5.86923874282773 * N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x - 2.0), $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision], N[(t$95$1 / N[(x * N[(x * N[(N[(x + 43.3400022514), $MachinePrecision] * x + 263.505074721), $MachinePrecision] + 313.399215894), $MachinePrecision] + 47.066876606), $MachinePrecision]), $MachinePrecision]]]]]]]]
\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 := {\left(\frac{1}{x}\right)}^{2}\\
t_1 := \mathsf{fma}\left(\mathsf{fma}\left(x, \mathsf{fma}\left(x, \mathsf{fma}\left(x, 4.16438922228, 78.6994924154\right), 137.519416416\right), y\right), x, z\right) \cdot \left(x - 2\right)\\
t_2 := \mathsf{fma}\left(\mathsf{fma}\left(43.3400022514, {x}^{2}, \mathsf{fma}\left(263.505074721, x, {x}^{3}\right)\right) + 313.399215894, x, 47.066876606\right)\\
t_3 := \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x, 4.16438922228, 78.6994924154\right), x, 137.519416416\right), x, y\right), x, z\right)\\
\mathbf{if}\;x \leq -5.2 \cdot 10^{+51}:\\
\;\;\;\;\left(4.16438922228 \cdot x + \left(\left(y - 130977.50649958357\right) \cdot t_0 + 3655.1204654076414 \cdot \frac{1}{x}\right)\right) - 110.1139242984811\\

\mathbf{elif}\;x \leq 1.72 \cdot 10^{+65}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;x - 2 \ne 0:\\
\;\;\;\;\frac{t_3}{\frac{t_2}{x - 2}}\\

\mathbf{else}:\\
\;\;\;\;\frac{\left(x - 2\right) \cdot t_3}{t_2}\\


\end{array}\\

\mathbf{elif}\;t_1 \ne 0:\\
\;\;\;\;{\left(\frac{0.24013125253755718 + \left(-55.572073733743466 \cdot t_0 + 5.86923874282773 \cdot \frac{1}{x}\right)}{x - 2}\right)}^{-1}\\

\mathbf{else}:\\
\;\;\;\;\frac{t_1}{\mathsf{fma}\left(x, \mathsf{fma}\left(x, \mathsf{fma}\left(x + 43.3400022514, x, 263.505074721\right), 313.399215894\right), 47.066876606\right)}\\


\end{array}

Error?

Target

Original41.75%
Target1.35%
Herbie1.61%
\[\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 3 regimes
  2. if x < -5.2000000000000002e51

    1. Initial program 97.81

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

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

    if -5.2000000000000002e51 < x < 1.7199999999999999e65

    1. Initial program 3.03

      \[\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 0 3.02

      \[\leadsto \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(\color{blue}{\left(43.3400022514 \cdot {x}^{2} + \left(263.505074721 \cdot x + {x}^{3}\right)\right)} + 313.399215894\right) \cdot x + 47.066876606} \]
    3. Applied egg-rr1.3

      \[\leadsto \color{blue}{\begin{array}{l} \color{blue}{\mathbf{if}\;x - 2 \ne 0:\\ \;\;\;\;\frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x, 4.16438922228, 78.6994924154\right), x, 137.519416416\right), x, y\right), x, z\right)}{\frac{\mathsf{fma}\left(\mathsf{fma}\left(43.3400022514, {x}^{2}, \mathsf{fma}\left(263.505074721, x, {x}^{3}\right)\right) + 313.399215894, x, 47.066876606\right)}{x - 2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(x - 2\right) \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x, 4.16438922228, 78.6994924154\right), x, 137.519416416\right), x, y\right), x, z\right)}{\mathsf{fma}\left(\mathsf{fma}\left(43.3400022514, {x}^{2}, \mathsf{fma}\left(263.505074721, x, {x}^{3}\right)\right) + 313.399215894, x, 47.066876606\right)}\\ } \end{array}} \]

    if 1.7199999999999999e65 < x

    1. Initial program 100

      \[\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. Applied egg-rr95.71

      \[\leadsto \color{blue}{\begin{array}{l} \color{blue}{\mathbf{if}\;\mathsf{fma}\left(\mathsf{fma}\left(x, \mathsf{fma}\left(x, \mathsf{fma}\left(x, 4.16438922228, 78.6994924154\right), 137.519416416\right), y\right), x, z\right) \cdot \left(x - 2\right) \ne 0:\\ \;\;\;\;{\left(\frac{\frac{\mathsf{fma}\left(x, \mathsf{fma}\left(x, \mathsf{fma}\left(x + 43.3400022514, x, 263.505074721\right), 313.399215894\right), 47.066876606\right)}{\mathsf{fma}\left(\mathsf{fma}\left(x, \mathsf{fma}\left(x, \mathsf{fma}\left(x, 4.16438922228, 78.6994924154\right), 137.519416416\right), y\right), x, z\right)}}{x - 2}\right)}^{-1}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\mathsf{fma}\left(x, \mathsf{fma}\left(x, \mathsf{fma}\left(x, 4.16438922228, 78.6994924154\right), 137.519416416\right), y\right), x, z\right) \cdot \left(x - 2\right)}{\mathsf{fma}\left(x, \mathsf{fma}\left(x, \mathsf{fma}\left(x + 43.3400022514, x, 263.505074721\right), 313.399215894\right), 47.066876606\right)}\\ } \end{array}} \]
    3. Taylor expanded in x around inf 2.07

      \[\leadsto \begin{array}{l} \mathbf{if}\;\mathsf{fma}\left(\mathsf{fma}\left(x, \mathsf{fma}\left(x, \mathsf{fma}\left(x, 4.16438922228, 78.6994924154\right), 137.519416416\right), y\right), x, z\right) \cdot \left(x - 2\right) \ne 0:\\ \;\;\;\;{\left(\frac{\color{blue}{0.24013125253755718 + \left(-55.572073733743466 \cdot {\left(\frac{1}{x}\right)}^{2} + 5.86923874282773 \cdot \frac{1}{x}\right)}}{x - 2}\right)}^{-1}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\mathsf{fma}\left(x, \mathsf{fma}\left(x, \mathsf{fma}\left(x, 4.16438922228, 78.6994924154\right), 137.519416416\right), y\right), x, z\right) \cdot \left(x - 2\right)}{\mathsf{fma}\left(x, \mathsf{fma}\left(x, \mathsf{fma}\left(x + 43.3400022514, x, 263.505074721\right), 313.399215894\right), 47.066876606\right)}\\ \end{array} \]
  3. Recombined 3 regimes into one program.

Reproduce?

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