Average Error: 20.7 → 0.2
Time: 17.0s
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 + x\\ \mathbf{if}\;z \leq -2.822842289411817 \cdot 10^{+25}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 4.2974891031269454 \cdot 10^{+119}:\\ \;\;\;\;\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) x)))
   (if (<= z -2.822842289411817e+25)
     t_0
     (if (<= z 4.2974891031269454e+119)
       (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) + x;
	double tmp;
	if (z <= -2.822842289411817e+25) {
		tmp = t_0;
	} else if (z <= 4.2974891031269454e+119) {
		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) + x)
	tmp = 0.0
	if (z <= -2.822842289411817e+25)
		tmp = t_0;
	elseif (z <= 4.2974891031269454e+119)
		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] + x), $MachinePrecision]}, If[LessEqual[z, -2.822842289411817e+25], t$95$0, If[LessEqual[z, 4.2974891031269454e+119], 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 + x\\
\mathbf{if}\;z \leq -2.822842289411817 \cdot 10^{+25}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;z \leq 4.2974891031269454 \cdot 10^{+119}:\\
\;\;\;\;\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.7
Target0.4
Herbie0.2
\[\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 < -2.82284228941181707e25 or 4.2974891031269454e119 < z

    1. Initial program 49.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. Simplified42.6

      \[\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): 1 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, 0 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): 33 points increase in error, 5 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.3

      \[\leadsto \color{blue}{0.0692910599291889 \cdot y + x} \]

    if -2.82284228941181707e25 < z < 4.2974891031269454e119

    1. Initial program 2.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} \]
    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): 1 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, 0 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): 33 points increase in error, 5 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.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -2.822842289411817 \cdot 10^{+25}:\\ \;\;\;\;0.0692910599291889 \cdot y + x\\ \mathbf{elif}\;z \leq 4.2974891031269454 \cdot 10^{+119}:\\ \;\;\;\;\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 + x\\ \end{array} \]

Alternatives

Alternative 1
Error0.2
Cost26696
\[\begin{array}{l} t_0 := 0.0692910599291889 \cdot y + x\\ \mathbf{if}\;z \leq -1.3302824826989348 \cdot 10^{+20}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 5.3271563536342204 \cdot 10^{+44}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{\mathsf{fma}\left(z, z + 6.012459259764103, 3.350343815022304\right)}, \mathsf{fma}\left(z, \mathsf{fma}\left(z, 0.0692910599291889, 0.4917317610505968\right), 0.279195317918525\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error0.2
Cost20424
\[\begin{array}{l} t_0 := 0.0692910599291889 \cdot y + x\\ \mathbf{if}\;z \leq -1.3302824826989348 \cdot 10^{+20}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 5.3271563536342204 \cdot 10^{+44}:\\ \;\;\;\;x + \frac{y}{\mathsf{fma}\left(z, z + 6.012459259764103, 3.350343815022304\right)} \cdot \mathsf{fma}\left(z, \mathsf{fma}\left(0.0692910599291889, z, 0.4917317610505968\right), 0.279195317918525\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error0.4
Cost1608
\[\begin{array}{l} \mathbf{if}\;z \leq -8562836124190.338:\\ \;\;\;\;0.0692910599291889 \cdot y + \left(x + 0.07512208616047561 \cdot \frac{y}{z}\right)\\ \mathbf{elif}\;z \leq 5.3271563536342204 \cdot 10^{+44}:\\ \;\;\;\;x + \frac{y \cdot \left(0.279195317918525 + z \cdot \left(0.4917317610505968 + z \cdot 0.0692910599291889\right)\right)}{3.350343815022304 + z \cdot \left(z + 6.012459259764103\right)}\\ \mathbf{else}:\\ \;\;\;\;0.0692910599291889 \cdot y + x\\ \end{array} \]
Alternative 4
Error32.0
Cost1512
\[\begin{array}{l} \mathbf{if}\;z \leq -1.752844745083735 \cdot 10^{+282}:\\ \;\;\;\;0.0692910599291889 \cdot y\\ \mathbf{elif}\;z \leq -1.7461040763347044 \cdot 10^{+196}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -1.2786702621535797 \cdot 10^{+172}:\\ \;\;\;\;0.0692910599291889 \cdot y\\ \mathbf{elif}\;z \leq -3.5774549189288865 \cdot 10^{+92}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -2.714892720631347 \cdot 10^{+30}:\\ \;\;\;\;0.0692910599291889 \cdot y\\ \mathbf{elif}\;z \leq -7610318.28165248:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -3.107910489514938 \cdot 10^{-84}:\\ \;\;\;\;y \cdot 0.08333333333333323\\ \mathbf{elif}\;z \leq 1.6687991962542373 \cdot 10^{-254}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 9.758115665880322 \cdot 10^{-20}:\\ \;\;\;\;y \cdot 0.08333333333333323\\ \mathbf{elif}\;z \leq 1.478206090031915 \cdot 10^{+160}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;0.0692910599291889 \cdot y\\ \end{array} \]
Alternative 5
Error0.7
Cost1352
\[\begin{array}{l} t_0 := 0.0692910599291889 \cdot y + \left(x + 0.07512208616047561 \cdot \frac{y}{z}\right)\\ \mathbf{if}\;z \leq -8562836124190.338:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 6.407940699222548 \cdot 10^{-5}:\\ \;\;\;\;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 6
Error14.6
Cost1112
\[\begin{array}{l} t_0 := x + y \cdot 0.08333333333333323\\ \mathbf{if}\;z \leq -1.752844745083735 \cdot 10^{+282}:\\ \;\;\;\;0.0692910599291889 \cdot y\\ \mathbf{elif}\;z \leq -1.7461040763347044 \cdot 10^{+196}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.2786702621535797 \cdot 10^{+172}:\\ \;\;\;\;0.0692910599291889 \cdot y\\ \mathbf{elif}\;z \leq -3.5774549189288865 \cdot 10^{+92}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -2.714892720631347 \cdot 10^{+30}:\\ \;\;\;\;0.0692910599291889 \cdot y\\ \mathbf{elif}\;z \leq 2.65345052850626 \cdot 10^{+248}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;0.0692910599291889 \cdot y\\ \end{array} \]
Alternative 7
Error0.8
Cost968
\[\begin{array}{l} t_0 := 0.0692910599291889 \cdot y + \left(x + 0.07512208616047561 \cdot \frac{y}{z}\right)\\ \mathbf{if}\;z \leq -8562836124190.338:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 6.407940699222548 \cdot 10^{-5}:\\ \;\;\;\;x + y \cdot \left(0.08333333333333323 + z \cdot -0.00277777777751721\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Error0.9
Cost840
\[\begin{array}{l} t_0 := 0.0692910599291889 \cdot y + x\\ \mathbf{if}\;z \leq -8562836124190.338:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.3371276342301388 \cdot 10^{-8}:\\ \;\;\;\;x + y \cdot \left(0.08333333333333323 + z \cdot -0.00277777777751721\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 9
Error1.0
Cost584
\[\begin{array}{l} t_0 := 0.0692910599291889 \cdot y + x\\ \mathbf{if}\;z \leq -8562836124190.338:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.3371276342301388 \cdot 10^{-8}:\\ \;\;\;\;x + y \cdot 0.08333333333333323\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 10
Error25.1
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -1.8653995828294563 \cdot 10^{+29}:\\ \;\;\;\;0.0692910599291889 \cdot y\\ \mathbf{elif}\;y \leq 4279.132091661539:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;0.0692910599291889 \cdot y\\ \end{array} \]
Alternative 11
Error31.2
Cost64
\[x \]

Error

Reproduce

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