Average Error: 20.2 → 0.4
Time: 15.3s
Precision: binary64
Cost: 26696
\[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 := 0.0692910599291889 \cdot y + \left(0.07512208616047561 \cdot \frac{y}{z} + x\right)\\ \mathbf{if}\;z \leq -501374388.91305363:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 0.002277581244873426:\\ \;\;\;\;\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)\\ \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
         (+ (* 0.0692910599291889 y) (+ (* 0.07512208616047561 (/ y z)) x))))
   (if (<= z -501374388.91305363)
     t_0
     (if (<= z 0.002277581244873426)
       (fma
        y
        (/
         (fma
          z
          (fma z 0.0692910599291889 0.4917317610505968)
          0.279195317918525)
         (fma z (+ z 6.012459259764103) 3.350343815022304))
        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 = (0.0692910599291889 * y) + ((0.07512208616047561 * (y / z)) + x);
	double tmp;
	if (z <= -501374388.91305363) {
		tmp = t_0;
	} else if (z <= 0.002277581244873426) {
		tmp = fma(y, (fma(z, fma(z, 0.0692910599291889, 0.4917317610505968), 0.279195317918525) / fma(z, (z + 6.012459259764103), 3.350343815022304)), x);
	} else {
		tmp = t_0;
	}
	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 = Float64(Float64(0.0692910599291889 * y) + Float64(Float64(0.07512208616047561 * Float64(y / z)) + x))
	tmp = 0.0
	if (z <= -501374388.91305363)
		tmp = t_0;
	elseif (z <= 0.002277581244873426)
		tmp = fma(y, Float64(fma(z, fma(z, 0.0692910599291889, 0.4917317610505968), 0.279195317918525) / fma(z, Float64(z + 6.012459259764103), 3.350343815022304)), x);
	else
		tmp = t_0;
	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[(0.0692910599291889 * y), $MachinePrecision] + N[(N[(0.07512208616047561 * N[(y / z), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -501374388.91305363], t$95$0, If[LessEqual[z, 0.002277581244873426], N[(y * N[(N[(z * N[(z * 0.0692910599291889 + 0.4917317610505968), $MachinePrecision] + 0.279195317918525), $MachinePrecision] / N[(z * N[(z + 6.012459259764103), $MachinePrecision] + 3.350343815022304), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], t$95$0]]]
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 := 0.0692910599291889 \cdot y + \left(0.07512208616047561 \cdot \frac{y}{z} + x\right)\\
\mathbf{if}\;z \leq -501374388.91305363:\\
\;\;\;\;t_0\\

\mathbf{elif}\;z \leq 0.002277581244873426:\\
\;\;\;\;\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)\\

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


\end{array}

Error

Target

Original20.2
Target0.4
Herbie0.4
\[\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 < -501374388.91305363 or 0.0022775812448734261 < z

    1. Initial program 39.7

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

      \[\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)} \]
      Proof
      (fma.f64 y (/.f64 (fma.f64 z (fma.f64 z 692910599291889/10000000000000000 307332350656623/625000000000000) 11167812716741/40000000000000) (fma.f64 z (+.f64 z 6012459259764103/1000000000000000) 104698244219447/31250000000000)) x): 0 points increase in error, 0 points decrease in error
      (fma.f64 y (/.f64 (fma.f64 z (Rewrite<= fma-def_binary64 (+.f64 (*.f64 z 692910599291889/10000000000000000) 307332350656623/625000000000000)) 11167812716741/40000000000000) (fma.f64 z (+.f64 z 6012459259764103/1000000000000000) 104698244219447/31250000000000)) x): 0 points increase in error, 0 points decrease in error
      (fma.f64 y (/.f64 (Rewrite<= fma-def_binary64 (+.f64 (*.f64 z (+.f64 (*.f64 z 692910599291889/10000000000000000) 307332350656623/625000000000000)) 11167812716741/40000000000000)) (fma.f64 z (+.f64 z 6012459259764103/1000000000000000) 104698244219447/31250000000000)) x): 0 points increase in error, 0 points decrease in error
      (fma.f64 y (/.f64 (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 (+.f64 (*.f64 z 692910599291889/10000000000000000) 307332350656623/625000000000000) z)) 11167812716741/40000000000000) (fma.f64 z (+.f64 z 6012459259764103/1000000000000000) 104698244219447/31250000000000)) x): 0 points increase in error, 0 points decrease in error
      (fma.f64 y (/.f64 (+.f64 (*.f64 (+.f64 (*.f64 z 692910599291889/10000000000000000) 307332350656623/625000000000000) z) 11167812716741/40000000000000) (Rewrite<= fma-def_binary64 (+.f64 (*.f64 z (+.f64 z 6012459259764103/1000000000000000)) 104698244219447/31250000000000))) x): 0 points increase in error, 0 points decrease in error
      (fma.f64 y (/.f64 (+.f64 (*.f64 (+.f64 (*.f64 z 692910599291889/10000000000000000) 307332350656623/625000000000000) z) 11167812716741/40000000000000) (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 (+.f64 z 6012459259764103/1000000000000000) z)) 104698244219447/31250000000000)) x): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 y (/.f64 (+.f64 (*.f64 (+.f64 (*.f64 z 692910599291889/10000000000000000) 307332350656623/625000000000000) z) 11167812716741/40000000000000) (+.f64 (*.f64 (+.f64 z 6012459259764103/1000000000000000) z) 104698244219447/31250000000000))) x)): 0 points increase in error, 1 points decrease in error
      (+.f64 (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 y (+.f64 (*.f64 (+.f64 (*.f64 z 692910599291889/10000000000000000) 307332350656623/625000000000000) z) 11167812716741/40000000000000)) (+.f64 (*.f64 (+.f64 z 6012459259764103/1000000000000000) z) 104698244219447/31250000000000))) x): 50 points increase in error, 7 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 x (/.f64 (*.f64 y (+.f64 (*.f64 (+.f64 (*.f64 z 692910599291889/10000000000000000) 307332350656623/625000000000000) z) 11167812716741/40000000000000)) (+.f64 (*.f64 (+.f64 z 6012459259764103/1000000000000000) z) 104698244219447/31250000000000)))): 0 points increase in error, 0 points decrease in error
    3. Taylor expanded in z around inf 0.6

      \[\leadsto \color{blue}{0.0692910599291889 \cdot y + \left(0.07512208616047561 \cdot \frac{y}{z} + x\right)} \]

    if -501374388.91305363 < z < 0.0022775812448734261

    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)} \]
      Proof
      (fma.f64 y (/.f64 (fma.f64 z (fma.f64 z 692910599291889/10000000000000000 307332350656623/625000000000000) 11167812716741/40000000000000) (fma.f64 z (+.f64 z 6012459259764103/1000000000000000) 104698244219447/31250000000000)) x): 0 points increase in error, 0 points decrease in error
      (fma.f64 y (/.f64 (fma.f64 z (Rewrite<= fma-def_binary64 (+.f64 (*.f64 z 692910599291889/10000000000000000) 307332350656623/625000000000000)) 11167812716741/40000000000000) (fma.f64 z (+.f64 z 6012459259764103/1000000000000000) 104698244219447/31250000000000)) x): 0 points increase in error, 0 points decrease in error
      (fma.f64 y (/.f64 (Rewrite<= fma-def_binary64 (+.f64 (*.f64 z (+.f64 (*.f64 z 692910599291889/10000000000000000) 307332350656623/625000000000000)) 11167812716741/40000000000000)) (fma.f64 z (+.f64 z 6012459259764103/1000000000000000) 104698244219447/31250000000000)) x): 0 points increase in error, 0 points decrease in error
      (fma.f64 y (/.f64 (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 (+.f64 (*.f64 z 692910599291889/10000000000000000) 307332350656623/625000000000000) z)) 11167812716741/40000000000000) (fma.f64 z (+.f64 z 6012459259764103/1000000000000000) 104698244219447/31250000000000)) x): 0 points increase in error, 0 points decrease in error
      (fma.f64 y (/.f64 (+.f64 (*.f64 (+.f64 (*.f64 z 692910599291889/10000000000000000) 307332350656623/625000000000000) z) 11167812716741/40000000000000) (Rewrite<= fma-def_binary64 (+.f64 (*.f64 z (+.f64 z 6012459259764103/1000000000000000)) 104698244219447/31250000000000))) x): 0 points increase in error, 0 points decrease in error
      (fma.f64 y (/.f64 (+.f64 (*.f64 (+.f64 (*.f64 z 692910599291889/10000000000000000) 307332350656623/625000000000000) z) 11167812716741/40000000000000) (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 (+.f64 z 6012459259764103/1000000000000000) z)) 104698244219447/31250000000000)) x): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 y (/.f64 (+.f64 (*.f64 (+.f64 (*.f64 z 692910599291889/10000000000000000) 307332350656623/625000000000000) z) 11167812716741/40000000000000) (+.f64 (*.f64 (+.f64 z 6012459259764103/1000000000000000) z) 104698244219447/31250000000000))) x)): 0 points increase in error, 1 points decrease in error
      (+.f64 (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 y (+.f64 (*.f64 (+.f64 (*.f64 z 692910599291889/10000000000000000) 307332350656623/625000000000000) z) 11167812716741/40000000000000)) (+.f64 (*.f64 (+.f64 z 6012459259764103/1000000000000000) z) 104698244219447/31250000000000))) x): 50 points increase in error, 7 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 x (/.f64 (*.f64 y (+.f64 (*.f64 (+.f64 (*.f64 z 692910599291889/10000000000000000) 307332350656623/625000000000000) z) 11167812716741/40000000000000)) (+.f64 (*.f64 (+.f64 z 6012459259764103/1000000000000000) z) 104698244219447/31250000000000)))): 0 points increase in error, 0 points decrease in error
  3. Recombined 2 regimes into one program.
  4. Final simplification0.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -501374388.91305363:\\ \;\;\;\;0.0692910599291889 \cdot y + \left(0.07512208616047561 \cdot \frac{y}{z} + x\right)\\ \mathbf{elif}\;z \leq 0.002277581244873426:\\ \;\;\;\;\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)\\ \mathbf{else}:\\ \;\;\;\;0.0692910599291889 \cdot y + \left(0.07512208616047561 \cdot \frac{y}{z} + x\right)\\ \end{array} \]

Alternatives

Alternative 1
Error0.2
Cost20424
\[\begin{array}{l} t_0 := 0.0692910599291889 \cdot y + x\\ \mathbf{if}\;z \leq -1.4581111926112835 \cdot 10^{+46}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 15100167204118444000:\\ \;\;\;\;x + \mathsf{fma}\left(z, \mathsf{fma}\left(0.0692910599291889, z, 0.4917317610505968\right), 0.279195317918525\right) \cdot \frac{y}{\mathsf{fma}\left(z, z + 6.012459259764103, 3.350343815022304\right)}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error0.6
Cost1352
\[\begin{array}{l} t_0 := 0.0692910599291889 \cdot y + \left(0.07512208616047561 \cdot \frac{y}{z} + x\right)\\ \mathbf{if}\;z \leq -501374388.91305363:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 0.002277581244873426:\\ \;\;\;\;x + y \cdot \left(0.08333333333333323 + z \cdot \left(-0.00277777777751721 + z \cdot \left(0.0007936505811533442 + z \cdot -0.0005951669793454025\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error0.6
Cost1096
\[\begin{array}{l} t_0 := 0.0692910599291889 \cdot y + \left(0.07512208616047561 \cdot \frac{y}{z} + x\right)\\ \mathbf{if}\;z \leq -501374388.91305363:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 0.002277581244873426:\\ \;\;\;\;x + y \cdot \left(0.08333333333333323 + z \cdot \left(-0.00277777777751721 + z \cdot 0.0007936505811533442\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error0.6
Cost968
\[\begin{array}{l} t_0 := 0.0692910599291889 \cdot y + \left(0.07512208616047561 \cdot \frac{y}{z} + x\right)\\ \mathbf{if}\;z \leq -501374388.91305363:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 0.002277581244873426:\\ \;\;\;\;x + y \cdot \left(0.08333333333333323 + z \cdot -0.00277777777751721\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error0.6
Cost968
\[\begin{array}{l} t_0 := 0.0692910599291889 \cdot y + \left(0.07512208616047561 \cdot \frac{y}{z} + x\right)\\ \mathbf{if}\;z \leq -501374388.91305363:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 0.002277581244873426:\\ \;\;\;\;y \cdot 0.08333333333333323 + \left(x + -0.00277777777751721 \cdot \left(z \cdot y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error14.7
Cost848
\[\begin{array}{l} t_0 := x + y \cdot 0.08333333333333323\\ \mathbf{if}\;z \leq -1.675055515619273 \cdot 10^{+133}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -3.090133067761423 \cdot 10^{+113}:\\ \;\;\;\;0.0692910599291889 \cdot y\\ \mathbf{elif}\;z \leq 0.002277581244873426:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.024133803219259 \cdot 10^{+208}:\\ \;\;\;\;0.0692910599291889 \cdot y\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error0.7
Cost840
\[\begin{array}{l} t_0 := 0.0692910599291889 \cdot y + x\\ \mathbf{if}\;z \leq -501374388.91305363:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 0.002277581244873426:\\ \;\;\;\;x + y \cdot \left(0.08333333333333323 + z \cdot -0.00277777777751721\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Error25.6
Cost720
\[\begin{array}{l} \mathbf{if}\;y \leq -1.873716716388878 \cdot 10^{+149}:\\ \;\;\;\;0.0692910599291889 \cdot y\\ \mathbf{elif}\;y \leq -5.712620842304471 \cdot 10^{+93}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -0.4961783606216699:\\ \;\;\;\;0.0692910599291889 \cdot y\\ \mathbf{elif}\;y \leq 2.7852011623771005 \cdot 10^{+118}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;0.0692910599291889 \cdot y\\ \end{array} \]
Alternative 9
Error25.7
Cost720
\[\begin{array}{l} \mathbf{if}\;y \leq -1.873716716388878 \cdot 10^{+149}:\\ \;\;\;\;0.0692910599291889 \cdot y\\ \mathbf{elif}\;y \leq -5.712620842304471 \cdot 10^{+93}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -0.4961783606216699:\\ \;\;\;\;0.0692910599291889 \cdot y\\ \mathbf{elif}\;y \leq 2.7852011623771005 \cdot 10^{+118}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot 0.08333333333333323\\ \end{array} \]
Alternative 10
Error0.8
Cost584
\[\begin{array}{l} t_0 := 0.0692910599291889 \cdot y + x\\ \mathbf{if}\;z \leq -501374388.91305363:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 0.002277581244873426:\\ \;\;\;\;x + y \cdot 0.08333333333333323\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 11
Error31.3
Cost64
\[x \]

Error

Reproduce

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