Average Error: 20.2 → 0.3
Time: 14.9s
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 := x + 0.0692910599291889 \cdot y\\ \mathbf{if}\;z \leq -1.0221162349914275 \cdot 10^{+53}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1471805.4873247154:\\ \;\;\;\;\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 (+ x (* 0.0692910599291889 y))))
   (if (<= z -1.0221162349914275e+53)
     t_0
     (if (<= z 1471805.4873247154)
       (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 = x + (0.0692910599291889 * y);
	double tmp;
	if (z <= -1.0221162349914275e+53) {
		tmp = t_0;
	} else if (z <= 1471805.4873247154) {
		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(x + Float64(0.0692910599291889 * y))
	tmp = 0.0
	if (z <= -1.0221162349914275e+53)
		tmp = t_0;
	elseif (z <= 1471805.4873247154)
		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[(x + N[(0.0692910599291889 * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.0221162349914275e+53], t$95$0, If[LessEqual[z, 1471805.4873247154], 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 := x + 0.0692910599291889 \cdot y\\
\mathbf{if}\;z \leq -1.0221162349914275 \cdot 10^{+53}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;z \leq 1471805.4873247154:\\
\;\;\;\;\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.3
\[\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 < -1.02211623499142751e53 or 1471805.48732471536 < z

    1. Initial program 44.3

      \[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.8

      \[\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)): 1 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): 42 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.4

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

    if -1.02211623499142751e53 < z < 1471805.48732471536

    1. Initial program 0.6

      \[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)): 1 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): 42 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.3

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

Alternatives

Alternative 1
Error0.4
Cost8264
\[\begin{array}{l} t_0 := x + 0.0692910599291889 \cdot y\\ \mathbf{if}\;z \leq -2.2752541744177127 \cdot 10^{+29}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1471805.4873247154:\\ \;\;\;\;x + \frac{y \cdot \left(0.279195317918525 + z \cdot \left(0.4917317610505968 + z \cdot 0.0692910599291889\right)\right)}{3.350343815022304 + \frac{z \cdot \mathsf{fma}\left(z, z, -36.1496663503231\right)}{z + -6.012459259764103}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error0.4
Cost1608
\[\begin{array}{l} t_0 := x + 0.0692910599291889 \cdot y\\ \mathbf{if}\;z \leq -2.2752541744177127 \cdot 10^{+29}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1471805.4873247154:\\ \;\;\;\;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}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error1.0
Cost1096
\[\begin{array}{l} \mathbf{if}\;z \leq -2.2752541744177127 \cdot 10^{+29}:\\ \;\;\;\;x + 0.0692910599291889 \cdot y\\ \mathbf{elif}\;z \leq 0.8838364277377165:\\ \;\;\;\;x + y \cdot \left(z \cdot \left(-0.00277777777751721 + z \cdot 0.0007936505811533442\right) + 0.08333333333333323\right)\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \left(0.0692910599291889 + \frac{0.07512208616047561}{z}\right)\\ \end{array} \]
Alternative 4
Error15.2
Cost848
\[\begin{array}{l} t_0 := x + 0.0692910599291889 \cdot y\\ \mathbf{if}\;z \leq -1.3879532758813494 \cdot 10^{-105}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -4.7427448818999964 \cdot 10^{-181}:\\ \;\;\;\;y \cdot 0.08333333333333323\\ \mathbf{elif}\;z \leq -1.9678374791934845 \cdot 10^{-258}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.3928009268607053 \cdot 10^{-56}:\\ \;\;\;\;y \cdot 0.08333333333333323\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error1.1
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -2.2752541744177127 \cdot 10^{+29}:\\ \;\;\;\;x + 0.0692910599291889 \cdot y\\ \mathbf{elif}\;z \leq 0.8838364277377165:\\ \;\;\;\;x + y \cdot 0.08333333333333323\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \left(0.0692910599291889 + \frac{0.07512208616047561}{z}\right)\\ \end{array} \]
Alternative 6
Error1.1
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -2.2752541744177127 \cdot 10^{+29}:\\ \;\;\;\;x + 0.0692910599291889 \cdot y\\ \mathbf{elif}\;z \leq 0.8838364277377165:\\ \;\;\;\;x + y \cdot \left(0.08333333333333323 + z \cdot -0.00277777777751721\right)\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \left(0.0692910599291889 + \frac{0.07512208616047561}{z}\right)\\ \end{array} \]
Alternative 7
Error24.8
Cost588
\[\begin{array}{l} \mathbf{if}\;y \leq -4.0897272770333066 \cdot 10^{+34}:\\ \;\;\;\;y \cdot 0.08333333333333323\\ \mathbf{elif}\;y \leq 3.989343468259983 \cdot 10^{+75}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 2.9223606757574226 \cdot 10^{+184}:\\ \;\;\;\;y \cdot 0.08333333333333323\\ \mathbf{else}:\\ \;\;\;\;0.0692910599291889 \cdot y\\ \end{array} \]
Alternative 8
Error1.2
Cost584
\[\begin{array}{l} t_0 := x + 0.0692910599291889 \cdot y\\ \mathbf{if}\;z \leq -2.2752541744177127 \cdot 10^{+29}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 0.8838364277377165:\\ \;\;\;\;x + y \cdot 0.08333333333333323\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 9
Error24.7
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -4.0897272770333066 \cdot 10^{+34}:\\ \;\;\;\;y \cdot 0.08333333333333323\\ \mathbf{elif}\;y \leq 3.989343468259983 \cdot 10^{+75}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot 0.08333333333333323\\ \end{array} \]
Alternative 10
Error31.5
Cost64
\[x \]

Error

Reproduce

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