Average Error: 20.6 → 0.1
Time: 13.8s
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} \mathbf{if}\;z \leq -33000000000000:\\ \;\;\;\;x + \frac{y}{14.431876219268936 + \frac{-15.646356830292042}{z}}\\ \mathbf{elif}\;z \leq 11000000:\\ \;\;\;\;\mathsf{fma}\left(\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)}, y, x\right)\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y}{14.431876219268936}\\ \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
 (if (<= z -33000000000000.0)
   (+ x (/ y (+ 14.431876219268936 (/ -15.646356830292042 z))))
   (if (<= z 11000000.0)
     (fma
      (/
       (fma z (fma z 0.0692910599291889 0.4917317610505968) 0.279195317918525)
       (fma z (+ z 6.012459259764103) 3.350343815022304))
      y
      x)
     (+ x (/ y 14.431876219268936)))))
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 tmp;
	if (z <= -33000000000000.0) {
		tmp = x + (y / (14.431876219268936 + (-15.646356830292042 / z)));
	} else if (z <= 11000000.0) {
		tmp = fma((fma(z, fma(z, 0.0692910599291889, 0.4917317610505968), 0.279195317918525) / fma(z, (z + 6.012459259764103), 3.350343815022304)), y, x);
	} else {
		tmp = x + (y / 14.431876219268936);
	}
	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)
	tmp = 0.0
	if (z <= -33000000000000.0)
		tmp = Float64(x + Float64(y / Float64(14.431876219268936 + Float64(-15.646356830292042 / z))));
	elseif (z <= 11000000.0)
		tmp = fma(Float64(fma(z, fma(z, 0.0692910599291889, 0.4917317610505968), 0.279195317918525) / fma(z, Float64(z + 6.012459259764103), 3.350343815022304)), y, x);
	else
		tmp = Float64(x + Float64(y / 14.431876219268936));
	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_] := If[LessEqual[z, -33000000000000.0], N[(x + N[(y / N[(14.431876219268936 + N[(-15.646356830292042 / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 11000000.0], N[(N[(N[(z * N[(z * 0.0692910599291889 + 0.4917317610505968), $MachinePrecision] + 0.279195317918525), $MachinePrecision] / N[(z * N[(z + 6.012459259764103), $MachinePrecision] + 3.350343815022304), $MachinePrecision]), $MachinePrecision] * y + x), $MachinePrecision], N[(x + N[(y / 14.431876219268936), $MachinePrecision]), $MachinePrecision]]]
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}
\mathbf{if}\;z \leq -33000000000000:\\
\;\;\;\;x + \frac{y}{14.431876219268936 + \frac{-15.646356830292042}{z}}\\

\mathbf{elif}\;z \leq 11000000:\\
\;\;\;\;\mathsf{fma}\left(\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)}, y, x\right)\\

\mathbf{else}:\\
\;\;\;\;x + \frac{y}{14.431876219268936}\\


\end{array}

Error

Target

Original20.6
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 3 regimes
  2. if z < -3.3e13

    1. Initial program 42.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} \]
    2. Simplified33.7

      \[\leadsto \color{blue}{x + \frac{y}{\frac{\mathsf{fma}\left(z + 6.012459259764103, z, 3.350343815022304\right)}{\mathsf{fma}\left(\mathsf{fma}\left(z, 0.0692910599291889, 0.4917317610505968\right), z, 0.279195317918525\right)}}} \]
      Proof
      (+.f64 x (/.f64 y (/.f64 (fma.f64 (+.f64 z 6012459259764103/1000000000000000) z 104698244219447/31250000000000) (fma.f64 (fma.f64 z 692910599291889/10000000000000000 307332350656623/625000000000000) z 11167812716741/40000000000000)))): 0 points increase in error, 0 points decrease in error
      (+.f64 x (/.f64 y (/.f64 (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (+.f64 z 6012459259764103/1000000000000000) z) 104698244219447/31250000000000)) (fma.f64 (fma.f64 z 692910599291889/10000000000000000 307332350656623/625000000000000) z 11167812716741/40000000000000)))): 0 points increase in error, 5 points decrease in error
      (+.f64 x (/.f64 y (/.f64 (+.f64 (*.f64 (+.f64 z 6012459259764103/1000000000000000) z) 104698244219447/31250000000000) (fma.f64 (Rewrite<= fma-def_binary64 (+.f64 (*.f64 z 692910599291889/10000000000000000) 307332350656623/625000000000000)) z 11167812716741/40000000000000)))): 0 points increase in error, 0 points decrease in error
      (+.f64 x (/.f64 y (/.f64 (+.f64 (*.f64 (+.f64 z 6012459259764103/1000000000000000) z) 104698244219447/31250000000000) (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (+.f64 (*.f64 z 692910599291889/10000000000000000) 307332350656623/625000000000000) z) 11167812716741/40000000000000))))): 0 points increase in error, 0 points decrease in error
      (+.f64 x (Rewrite<= associate-/l*_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)))): 5 points increase in error, 0 points decrease in error
    3. Taylor expanded in z around inf 0.0

      \[\leadsto x + \frac{y}{\color{blue}{14.431876219268936 - 15.646356830292042 \cdot \frac{1}{z}}} \]
    4. Simplified0.0

      \[\leadsto x + \frac{y}{\color{blue}{14.431876219268936 - \frac{15.646356830292042}{z}}} \]
      Proof
      (+.f64 x (/.f64 y (-.f64 10000000000000000/692910599291889 (/.f64 2504069538682520235663395798110/160041699537014921582740396107 z)))): 0 points increase in error, 0 points decrease in error
      (+.f64 x (/.f64 y (-.f64 10000000000000000/692910599291889 (/.f64 (Rewrite<= metadata-eval (*.f64 2504069538682520235663395798110/160041699537014921582740396107 1)) z)))): 3 points increase in error, 0 points decrease in error
      (+.f64 x (/.f64 y (-.f64 10000000000000000/692910599291889 (Rewrite<= associate-*r/_binary64 (*.f64 2504069538682520235663395798110/160041699537014921582740396107 (/.f64 1 z)))))): 0 points increase in error, 3 points decrease in error

    if -3.3e13 < z < 1.1e7

    1. Initial program 0.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. Simplified0.1

      \[\leadsto \color{blue}{\mathsf{fma}\left(\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)}, y, x\right)} \]
      Proof
      (+.f64 x (/.f64 y (/.f64 (fma.f64 (+.f64 z 6012459259764103/1000000000000000) z 104698244219447/31250000000000) (fma.f64 (fma.f64 z 692910599291889/10000000000000000 307332350656623/625000000000000) z 11167812716741/40000000000000)))): 0 points increase in error, 0 points decrease in error
      (+.f64 x (/.f64 y (/.f64 (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (+.f64 z 6012459259764103/1000000000000000) z) 104698244219447/31250000000000)) (fma.f64 (fma.f64 z 692910599291889/10000000000000000 307332350656623/625000000000000) z 11167812716741/40000000000000)))): 0 points increase in error, 5 points decrease in error
      (+.f64 x (/.f64 y (/.f64 (+.f64 (*.f64 (+.f64 z 6012459259764103/1000000000000000) z) 104698244219447/31250000000000) (fma.f64 (Rewrite<= fma-def_binary64 (+.f64 (*.f64 z 692910599291889/10000000000000000) 307332350656623/625000000000000)) z 11167812716741/40000000000000)))): 0 points increase in error, 0 points decrease in error
      (+.f64 x (/.f64 y (/.f64 (+.f64 (*.f64 (+.f64 z 6012459259764103/1000000000000000) z) 104698244219447/31250000000000) (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (+.f64 (*.f64 z 692910599291889/10000000000000000) 307332350656623/625000000000000) z) 11167812716741/40000000000000))))): 0 points increase in error, 0 points decrease in error
      (+.f64 x (Rewrite<= associate-/l*_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)))): 5 points increase in error, 0 points decrease in error

    if 1.1e7 < z

    1. Initial program 40.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.8

      \[\leadsto \color{blue}{x + \frac{y}{\frac{\mathsf{fma}\left(z + 6.012459259764103, z, 3.350343815022304\right)}{\mathsf{fma}\left(\mathsf{fma}\left(z, 0.0692910599291889, 0.4917317610505968\right), z, 0.279195317918525\right)}}} \]
      Proof
      (+.f64 x (/.f64 y (/.f64 (fma.f64 (+.f64 z 6012459259764103/1000000000000000) z 104698244219447/31250000000000) (fma.f64 (fma.f64 z 692910599291889/10000000000000000 307332350656623/625000000000000) z 11167812716741/40000000000000)))): 0 points increase in error, 0 points decrease in error
      (+.f64 x (/.f64 y (/.f64 (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (+.f64 z 6012459259764103/1000000000000000) z) 104698244219447/31250000000000)) (fma.f64 (fma.f64 z 692910599291889/10000000000000000 307332350656623/625000000000000) z 11167812716741/40000000000000)))): 0 points increase in error, 5 points decrease in error
      (+.f64 x (/.f64 y (/.f64 (+.f64 (*.f64 (+.f64 z 6012459259764103/1000000000000000) z) 104698244219447/31250000000000) (fma.f64 (Rewrite<= fma-def_binary64 (+.f64 (*.f64 z 692910599291889/10000000000000000) 307332350656623/625000000000000)) z 11167812716741/40000000000000)))): 0 points increase in error, 0 points decrease in error
      (+.f64 x (/.f64 y (/.f64 (+.f64 (*.f64 (+.f64 z 6012459259764103/1000000000000000) z) 104698244219447/31250000000000) (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (+.f64 (*.f64 z 692910599291889/10000000000000000) 307332350656623/625000000000000) z) 11167812716741/40000000000000))))): 0 points increase in error, 0 points decrease in error
      (+.f64 x (Rewrite<= associate-/l*_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)))): 5 points increase in error, 0 points decrease in error
    3. Taylor expanded in z around inf 0.2

      \[\leadsto x + \frac{y}{\color{blue}{14.431876219268936}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -33000000000000:\\ \;\;\;\;x + \frac{y}{14.431876219268936 + \frac{-15.646356830292042}{z}}\\ \mathbf{elif}\;z \leq 11000000:\\ \;\;\;\;\mathsf{fma}\left(\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)}, y, x\right)\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y}{14.431876219268936}\\ \end{array} \]

Alternatives

Alternative 1
Error0.2
Cost1736
\[\begin{array}{l} \mathbf{if}\;z \leq -170000000:\\ \;\;\;\;x + \frac{y}{14.431876219268936 + \frac{-15.646356830292042}{z}}\\ \mathbf{elif}\;z \leq 11000000:\\ \;\;\;\;x + \frac{y \cdot \left(0.279195317918525 + z \cdot \left(0.4917317610505968 + z \cdot 0.0692910599291889\right)\right)}{3.350343815022304 + \left(z \cdot z + z \cdot 6.012459259764103\right)}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y}{14.431876219268936}\\ \end{array} \]
Alternative 2
Error0.2
Cost1608
\[\begin{array}{l} \mathbf{if}\;z \leq -245000000:\\ \;\;\;\;x + \frac{y}{14.431876219268936 + \frac{-15.646356830292042}{z}}\\ \mathbf{elif}\;z \leq 11000000:\\ \;\;\;\;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}:\\ \;\;\;\;x + \frac{y}{14.431876219268936}\\ \end{array} \]
Alternative 3
Error0.4
Cost1225
\[\begin{array}{l} \mathbf{if}\;z \leq -5.4 \lor \neg \left(z \leq 6.2\right):\\ \;\;\;\;x + \frac{y}{\frac{101.23733352003822}{z \cdot z} + \left(14.431876219268936 + \frac{-15.646356830292042}{z}\right)}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y}{z \cdot 0.39999999996247915 + 12.000000000000014}\\ \end{array} \]
Alternative 4
Error14.8
Cost849
\[\begin{array}{l} \mathbf{if}\;z \leq -3.5 \cdot 10^{+204}:\\ \;\;\;\;y \cdot 0.0692910599291889\\ \mathbf{elif}\;z \leq 2.3 \cdot 10^{+29} \lor \neg \left(z \leq 8 \cdot 10^{+120}\right) \land z \leq 5 \cdot 10^{+254}:\\ \;\;\;\;x + \frac{y}{12.000000000000014}\\ \mathbf{else}:\\ \;\;\;\;y \cdot 0.0692910599291889\\ \end{array} \]
Alternative 5
Error0.4
Cost841
\[\begin{array}{l} \mathbf{if}\;z \leq -5.4 \lor \neg \left(z \leq 6.2\right):\\ \;\;\;\;x + \frac{y}{14.431876219268936 + \frac{-15.646356830292042}{z}}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y}{z \cdot 0.39999999996247915 + 12.000000000000014}\\ \end{array} \]
Alternative 6
Error0.6
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -5.4:\\ \;\;\;\;x + y \cdot \left(0.0692910599291889 + \frac{0.07512208616047561}{z}\right)\\ \mathbf{elif}\;z \leq 6.1:\\ \;\;\;\;x + \frac{y}{z \cdot 0.39999999996247915 + 12.000000000000014}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y}{14.431876219268936}\\ \end{array} \]
Alternative 7
Error25.0
Cost720
\[\begin{array}{l} \mathbf{if}\;x \leq -6.9 \cdot 10^{-68}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 2 \cdot 10^{-112}:\\ \;\;\;\;y \cdot 0.08333333333333323\\ \mathbf{elif}\;x \leq 1.35 \cdot 10^{-40}:\\ \;\;\;\;y \cdot 0.0692910599291889\\ \mathbf{elif}\;x \leq 1.85 \cdot 10^{-8}:\\ \;\;\;\;y \cdot 0.08333333333333323\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 8
Error0.7
Cost708
\[\begin{array}{l} \mathbf{if}\;z \leq -5.4:\\ \;\;\;\;x + y \cdot \left(0.0692910599291889 + \frac{0.07512208616047561}{z}\right)\\ \mathbf{elif}\;z \leq 5.6:\\ \;\;\;\;x + \frac{y}{12.000000000000014}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y}{14.431876219268936}\\ \end{array} \]
Alternative 9
Error0.7
Cost585
\[\begin{array}{l} \mathbf{if}\;z \leq -5.4 \lor \neg \left(z \leq 6.1\right):\\ \;\;\;\;x + \frac{y}{14.431876219268936}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y}{12.000000000000014}\\ \end{array} \]
Alternative 10
Error25.1
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -4 \cdot 10^{-68}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 4.3 \cdot 10^{-9}:\\ \;\;\;\;y \cdot 0.08333333333333323\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 11
Error31.7
Cost64
\[x \]

Error

Reproduce

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