Average Error: 19.9 → 0.1
Time: 25.1s
Precision: binary64
Cost: 20556
\[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(\mathsf{fma}\left(z, 0.0692910599291889, 0.4917317610505968\right), z, 0.279195317918525\right)\\ t_1 := \frac{y}{14.431876219268936} + x\\ t_2 := \mathsf{fma}\left(z + 6.012459259764103, z, 3.350343815022304\right)\\ \mathbf{if}\;z \leq -8 \cdot 10^{+25}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 6.6 \cdot 10^{+15}:\\ \;\;\;\;x + \begin{array}{l} \mathbf{if}\;y \ne 0:\\ \;\;\;\;\frac{t_0}{\frac{t_2}{y}}\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot t_0}{t_2}\\ \end{array}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \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
          (fma z 0.0692910599291889 0.4917317610505968)
          z
          0.279195317918525))
        (t_1 (+ (/ y 14.431876219268936) x))
        (t_2 (fma (+ z 6.012459259764103) z 3.350343815022304)))
   (if (<= z -8e+25)
     t_1
     (if (<= z 6.6e+15)
       (+ x (if (!= y 0.0) (/ t_0 (/ t_2 y)) (/ (* y t_0) t_2)))
       t_1))))
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(fma(z, 0.0692910599291889, 0.4917317610505968), z, 0.279195317918525);
	double t_1 = (y / 14.431876219268936) + x;
	double t_2 = fma((z + 6.012459259764103), z, 3.350343815022304);
	double tmp;
	if (z <= -8e+25) {
		tmp = t_1;
	} else if (z <= 6.6e+15) {
		double tmp_1;
		if (y != 0.0) {
			tmp_1 = t_0 / (t_2 / y);
		} else {
			tmp_1 = (y * t_0) / t_2;
		}
		tmp = x + tmp_1;
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(x, y, z)
	return Float64(x + Float64(Float64(y * Float64(Float64(Float64(Float64(z * 0.0692910599291889) + 0.4917317610505968) * z) + 0.279195317918525)) / Float64(Float64(Float64(z + 6.012459259764103) * z) + 3.350343815022304)))
end
function code(x, y, z)
	t_0 = fma(fma(z, 0.0692910599291889, 0.4917317610505968), z, 0.279195317918525)
	t_1 = Float64(Float64(y / 14.431876219268936) + x)
	t_2 = fma(Float64(z + 6.012459259764103), z, 3.350343815022304)
	tmp = 0.0
	if (z <= -8e+25)
		tmp = t_1;
	elseif (z <= 6.6e+15)
		tmp_1 = 0.0
		if (y != 0.0)
			tmp_1 = Float64(t_0 / Float64(t_2 / y));
		else
			tmp_1 = Float64(Float64(y * t_0) / t_2);
		end
		tmp = Float64(x + tmp_1);
	else
		tmp = t_1;
	end
	return tmp
end
code[x_, y_, z_] := N[(x + N[(N[(y * N[(N[(N[(N[(z * 0.0692910599291889), $MachinePrecision] + 0.4917317610505968), $MachinePrecision] * z), $MachinePrecision] + 0.279195317918525), $MachinePrecision]), $MachinePrecision] / N[(N[(N[(z + 6.012459259764103), $MachinePrecision] * z), $MachinePrecision] + 3.350343815022304), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(z * 0.0692910599291889 + 0.4917317610505968), $MachinePrecision] * z + 0.279195317918525), $MachinePrecision]}, Block[{t$95$1 = N[(N[(y / 14.431876219268936), $MachinePrecision] + x), $MachinePrecision]}, Block[{t$95$2 = N[(N[(z + 6.012459259764103), $MachinePrecision] * z + 3.350343815022304), $MachinePrecision]}, If[LessEqual[z, -8e+25], t$95$1, If[LessEqual[z, 6.6e+15], N[(x + If[Unequal[y, 0.0], N[(t$95$0 / N[(t$95$2 / y), $MachinePrecision]), $MachinePrecision], N[(N[(y * t$95$0), $MachinePrecision] / t$95$2), $MachinePrecision]]), $MachinePrecision], t$95$1]]]]]
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(\mathsf{fma}\left(z, 0.0692910599291889, 0.4917317610505968\right), z, 0.279195317918525\right)\\
t_1 := \frac{y}{14.431876219268936} + x\\
t_2 := \mathsf{fma}\left(z + 6.012459259764103, z, 3.350343815022304\right)\\
\mathbf{if}\;z \leq -8 \cdot 10^{+25}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;z \leq 6.6 \cdot 10^{+15}:\\
\;\;\;\;x + \begin{array}{l}
\mathbf{if}\;y \ne 0:\\
\;\;\;\;\frac{t_0}{\frac{t_2}{y}}\\

\mathbf{else}:\\
\;\;\;\;\frac{y \cdot t_0}{t_2}\\


\end{array}\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error

Target

Original19.9
Target0.4
Herbie0.1
\[\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 < -8.00000000000000072e25 or 6.6e15 < z

    1. Initial program 42.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. Simplified35.5

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

      \[\leadsto \color{blue}{0.0692910599291889 \cdot y + x} \]
    4. Applied egg-rr0.2

      \[\leadsto \color{blue}{\left(y \cdot \sqrt[3]{0.0692910599291889}\right) \cdot \sqrt[3]{0.004801250986110448}} + x \]
    5. Applied egg-rr0.3

      \[\leadsto \color{blue}{\frac{3 \cdot \left(y \cdot 0.0692910599291889\right)}{3}} + x \]
    6. Simplified0.3

      \[\leadsto \color{blue}{\frac{\left(3 \cdot y\right) \cdot 0.0692910599291889}{3}} + x \]
      Proof
    7. Applied egg-rr0.0

      \[\leadsto \color{blue}{\frac{y}{14.431876219268936}} + x \]

    if -8.00000000000000072e25 < z < 6.6e15

    1. Initial program 0.4

      \[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. Applied egg-rr0.2

      \[\leadsto x + \color{blue}{\begin{array}{l} \color{blue}{\mathbf{if}\;y \ne 0:\\ \;\;\;\;\frac{\mathsf{fma}\left(\mathsf{fma}\left(z, 0.0692910599291889, 0.4917317610505968\right), z, 0.279195317918525\right)}{\frac{\mathsf{fma}\left(z + 6.012459259764103, z, 3.350343815022304\right)}{y}}\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot \mathsf{fma}\left(\mathsf{fma}\left(z, 0.0692910599291889, 0.4917317610505968\right), z, 0.279195317918525\right)}{\mathsf{fma}\left(z + 6.012459259764103, z, 3.350343815022304\right)}\\ } \end{array}} \]
  3. Recombined 2 regimes into one program.

Alternatives

Alternative 1
Error0.1
Cost20552
\[\begin{array}{l} t_0 := \frac{y}{14.431876219268936} + x\\ \mathbf{if}\;z \leq -6 \cdot 10^{+21}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 6.6 \cdot 10^{+15}:\\ \;\;\;\;\mathsf{fma}\left(0.279195317918525 + \mathsf{fma}\left(0.4917317610505968, z, 0.0692910599291889 \cdot \left(z \cdot z\right)\right), \frac{y}{\mathsf{fma}\left(z + 6.012459259764103, z, 3.350343815022304\right)}, x\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error0.1
Cost14344
\[\begin{array}{l} t_0 := \frac{y}{14.431876219268936} + x\\ \mathbf{if}\;z \leq -6 \cdot 10^{+21}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 5 \cdot 10^{+15}:\\ \;\;\;\;x + \frac{-\mathsf{fma}\left(\mathsf{fma}\left(z, 0.0692910599291889, 0.4917317610505968\right), z, 0.279195317918525\right)}{1} \cdot \frac{y}{-3.350343815022304 - \left(z + 6.012459259764103\right) \cdot z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error0.2
Cost8716
\[\begin{array}{l} t_0 := \frac{y}{14.431876219268936} + x\\ \mathbf{if}\;z \leq -6 \cdot 10^{+21}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 22000000000000:\\ \;\;\;\;x + \frac{y \cdot \left(\left(z \cdot 0.0692910599291889 + 0.4917317610505968\right) \cdot z + 0.279195317918525\right)}{\begin{array}{l} \mathbf{if}\;z \ne 0:\\ \;\;\;\;\frac{{z}^{3} + 217.34839618538297}{\frac{36.1496663503231 + z \cdot \left(z + -6.012459259764103\right)}{z}}\\ \mathbf{else}:\\ \;\;\;\;\left(z + 6.012459259764103\right) \cdot z\\ \end{array} + 3.350343815022304}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error0.2
Cost1608
\[\begin{array}{l} t_0 := \frac{y}{14.431876219268936} + x\\ \mathbf{if}\;z \leq -6 \cdot 10^{+21}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 46000000000000:\\ \;\;\;\;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}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error27.7
Cost1248
\[\begin{array}{l} \mathbf{if}\;y \leq -1.8 \cdot 10^{+218}:\\ \;\;\;\;y \cdot 0.0692910599291889\\ \mathbf{elif}\;y \leq -3.1 \cdot 10^{+169}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -5.8 \cdot 10^{+115}:\\ \;\;\;\;y \cdot 0.0692910599291889\\ \mathbf{elif}\;y \leq 4.1 \cdot 10^{-89}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 3.7 \cdot 10^{-40}:\\ \;\;\;\;y \cdot 0.0692910599291889\\ \mathbf{elif}\;y \leq 10^{+35}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 2.85 \cdot 10^{+54}:\\ \;\;\;\;y \cdot 0.0692910599291889\\ \mathbf{elif}\;y \leq 9 \cdot 10^{+195}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot 0.0692910599291889\\ \end{array} \]
Alternative 6
Error0.7
Cost1224
\[\begin{array}{l} \mathbf{if}\;z \leq -2.4 \cdot 10^{+14}:\\ \;\;\;\;\frac{y}{14.431876219268936} + x\\ \mathbf{elif}\;z \leq 0.00044:\\ \;\;\;\;0.08333333333333323 \cdot y + \left(z \cdot \left(-0.14954831483277858 \cdot y + 0.14677053705526136 \cdot y\right) + x\right)\\ \mathbf{else}:\\ \;\;\;\;x + \left(\left(-\frac{y \cdot \left(-0.4917317610505968 - -0.4166096748901212\right)}{z}\right) + 0.0692910599291889 \cdot y\right)\\ \end{array} \]
Alternative 7
Error0.8
Cost1160
\[\begin{array}{l} \mathbf{if}\;z \leq -2.4 \cdot 10^{+14}:\\ \;\;\;\;\frac{y}{14.431876219268936} + x\\ \mathbf{elif}\;z \leq 0.00044:\\ \;\;\;\;0.08333333333333323 \cdot y + x\\ \mathbf{else}:\\ \;\;\;\;x + \left(\left(-\frac{y \cdot \left(-0.4917317610505968 - -0.4166096748901212\right)}{z}\right) + 0.0692910599291889 \cdot y\right)\\ \end{array} \]
Alternative 8
Error25.1
Cost720
\[\begin{array}{l} \mathbf{if}\;x \leq -3.6 \cdot 10^{-69}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -2.55 \cdot 10^{-306}:\\ \;\;\;\;y \cdot 0.08333333333333323\\ \mathbf{elif}\;x \leq 3.9 \cdot 10^{-203}:\\ \;\;\;\;y \cdot 0.0692910599291889\\ \mathbf{elif}\;x \leq 2.5 \cdot 10^{-122}:\\ \;\;\;\;y \cdot 0.08333333333333323\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 9
Error13.3
Cost584
\[\begin{array}{l} t_0 := 0.0692910599291889 \cdot y + x\\ \mathbf{if}\;z \leq 1.28 \cdot 10^{-85}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 4.8 \cdot 10^{-16}:\\ \;\;\;\;y \cdot 0.08333333333333323\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 10
Error0.9
Cost584
\[\begin{array}{l} t_0 := 0.0692910599291889 \cdot y + x\\ \mathbf{if}\;z \leq -2.4 \cdot 10^{+14}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 0.00044:\\ \;\;\;\;0.08333333333333323 \cdot y + x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 11
Error0.8
Cost584
\[\begin{array}{l} t_0 := \frac{y}{14.431876219268936} + x\\ \mathbf{if}\;z \leq -2.4 \cdot 10^{+14}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 0.00044:\\ \;\;\;\;0.08333333333333323 \cdot y + x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 12
Error31.9
Cost64
\[x \]

Error

Reproduce

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