| Alternative 1 | |
|---|---|
| Error | 0.12% |
| Cost | 7880 |
(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 -480000000.0)
(+ x (/ y (+ 14.431876219268936 (/ -15.646356830292042 z))))
(if (<= z 1.12e+16)
(fma
(/
(-
-0.279195317918525
(* z (fma z 0.0692910599291889 0.4917317610505968)))
(+ -3.350343815022304 (* z (- -6.012459259764103 z))))
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 <= -480000000.0) {
tmp = x + (y / (14.431876219268936 + (-15.646356830292042 / z)));
} else if (z <= 1.12e+16) {
tmp = fma(((-0.279195317918525 - (z * fma(z, 0.0692910599291889, 0.4917317610505968))) / (-3.350343815022304 + (z * (-6.012459259764103 - z)))), 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 <= -480000000.0) tmp = Float64(x + Float64(y / Float64(14.431876219268936 + Float64(-15.646356830292042 / z)))); elseif (z <= 1.12e+16) tmp = fma(Float64(Float64(-0.279195317918525 - Float64(z * fma(z, 0.0692910599291889, 0.4917317610505968))) / Float64(-3.350343815022304 + Float64(z * Float64(-6.012459259764103 - z)))), 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, -480000000.0], N[(x + N[(y / N[(14.431876219268936 + N[(-15.646356830292042 / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.12e+16], N[(N[(N[(-0.279195317918525 - N[(z * N[(z * 0.0692910599291889 + 0.4917317610505968), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(-3.350343815022304 + N[(z * N[(-6.012459259764103 - z), $MachinePrecision]), $MachinePrecision]), $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 -480000000:\\
\;\;\;\;x + \frac{y}{14.431876219268936 + \frac{-15.646356830292042}{z}}\\
\mathbf{elif}\;z \leq 1.12 \cdot 10^{+16}:\\
\;\;\;\;\mathsf{fma}\left(\frac{-0.279195317918525 - z \cdot \mathsf{fma}\left(z, 0.0692910599291889, 0.4917317610505968\right)}{-3.350343815022304 + z \cdot \left(-6.012459259764103 - z\right)}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{14.431876219268936}\\
\end{array}
| Original | 31.63% |
|---|---|
| Target | 0.56% |
| Herbie | 0.12% |
if z < -4.8e8Initial program 63.22
Simplified50.21
[Start]63.22 | \[ 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}
\] |
|---|---|
associate-/l* [=>]50.21 | \[ x + \color{blue}{\frac{y}{\frac{\left(z + 6.012459259764103\right) \cdot z + 3.350343815022304}{\left(z \cdot 0.0692910599291889 + 0.4917317610505968\right) \cdot z + 0.279195317918525}}}
\] |
fma-def [=>]50.21 | \[ x + \frac{y}{\frac{\color{blue}{\mathsf{fma}\left(z + 6.012459259764103, z, 3.350343815022304\right)}}{\left(z \cdot 0.0692910599291889 + 0.4917317610505968\right) \cdot z + 0.279195317918525}}
\] |
fma-def [=>]50.21 | \[ x + \frac{y}{\frac{\mathsf{fma}\left(z + 6.012459259764103, z, 3.350343815022304\right)}{\color{blue}{\mathsf{fma}\left(z \cdot 0.0692910599291889 + 0.4917317610505968, z, 0.279195317918525\right)}}}
\] |
fma-def [=>]50.21 | \[ x + \frac{y}{\frac{\mathsf{fma}\left(z + 6.012459259764103, z, 3.350343815022304\right)}{\mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(z, 0.0692910599291889, 0.4917317610505968\right)}, z, 0.279195317918525\right)}}
\] |
Taylor expanded in z around inf 0.06
Simplified0.06
[Start]0.06 | \[ x + \frac{y}{14.431876219268936 - 15.646356830292042 \cdot \frac{1}{z}}
\] |
|---|---|
associate-*r/ [=>]0.06 | \[ x + \frac{y}{14.431876219268936 - \color{blue}{\frac{15.646356830292042 \cdot 1}{z}}}
\] |
metadata-eval [=>]0.06 | \[ x + \frac{y}{14.431876219268936 - \frac{\color{blue}{15.646356830292042}}{z}}
\] |
if -4.8e8 < z < 1.12e16Initial program 0.41
Simplified0.17
[Start]0.41 | \[ 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}
\] |
|---|---|
+-commutative [=>]0.41 | \[ \color{blue}{\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} + x}
\] |
associate-*r/ [<=]0.17 | \[ \color{blue}{y \cdot \frac{\left(z \cdot 0.0692910599291889 + 0.4917317610505968\right) \cdot z + 0.279195317918525}{\left(z + 6.012459259764103\right) \cdot z + 3.350343815022304}} + x
\] |
*-commutative [<=]0.17 | \[ \color{blue}{\frac{\left(z \cdot 0.0692910599291889 + 0.4917317610505968\right) \cdot z + 0.279195317918525}{\left(z + 6.012459259764103\right) \cdot z + 3.350343815022304} \cdot y} + x
\] |
fma-def [=>]0.16 | \[ \color{blue}{\mathsf{fma}\left(\frac{\left(z \cdot 0.0692910599291889 + 0.4917317610505968\right) \cdot z + 0.279195317918525}{\left(z + 6.012459259764103\right) \cdot z + 3.350343815022304}, y, x\right)}
\] |
*-commutative [=>]0.16 | \[ \mathsf{fma}\left(\frac{\color{blue}{z \cdot \left(z \cdot 0.0692910599291889 + 0.4917317610505968\right)} + 0.279195317918525}{\left(z + 6.012459259764103\right) \cdot z + 3.350343815022304}, y, x\right)
\] |
fma-def [=>]0.16 | \[ \mathsf{fma}\left(\frac{\color{blue}{\mathsf{fma}\left(z, z \cdot 0.0692910599291889 + 0.4917317610505968, 0.279195317918525\right)}}{\left(z + 6.012459259764103\right) \cdot z + 3.350343815022304}, y, x\right)
\] |
fma-def [=>]0.16 | \[ \mathsf{fma}\left(\frac{\mathsf{fma}\left(z, \color{blue}{\mathsf{fma}\left(z, 0.0692910599291889, 0.4917317610505968\right)}, 0.279195317918525\right)}{\left(z + 6.012459259764103\right) \cdot z + 3.350343815022304}, y, x\right)
\] |
*-commutative [=>]0.16 | \[ \mathsf{fma}\left(\frac{\mathsf{fma}\left(z, \mathsf{fma}\left(z, 0.0692910599291889, 0.4917317610505968\right), 0.279195317918525\right)}{\color{blue}{z \cdot \left(z + 6.012459259764103\right)} + 3.350343815022304}, y, x\right)
\] |
fma-def [=>]0.17 | \[ \mathsf{fma}\left(\frac{\mathsf{fma}\left(z, \mathsf{fma}\left(z, 0.0692910599291889, 0.4917317610505968\right), 0.279195317918525\right)}{\color{blue}{\mathsf{fma}\left(z, z + 6.012459259764103, 3.350343815022304\right)}}, y, x\right)
\] |
Applied egg-rr0.16
Simplified0.16
[Start]0.16 | \[ \mathsf{fma}\left(-\frac{\mathsf{fma}\left(z, \mathsf{fma}\left(z, 0.0692910599291889, 0.4917317610505968\right), 0.279195317918525\right)}{-3.350343815022304 - z \cdot \left(z + 6.012459259764103\right)}, y, x\right)
\] |
|---|---|
distribute-frac-neg [<=]0.16 | \[ \mathsf{fma}\left(\color{blue}{\frac{-\mathsf{fma}\left(z, \mathsf{fma}\left(z, 0.0692910599291889, 0.4917317610505968\right), 0.279195317918525\right)}{-3.350343815022304 - z \cdot \left(z + 6.012459259764103\right)}}, y, x\right)
\] |
fma-udef [=>]0.16 | \[ \mathsf{fma}\left(\frac{-\color{blue}{\left(z \cdot \mathsf{fma}\left(z, 0.0692910599291889, 0.4917317610505968\right) + 0.279195317918525\right)}}{-3.350343815022304 - z \cdot \left(z + 6.012459259764103\right)}, y, x\right)
\] |
fma-udef [=>]0.16 | \[ \mathsf{fma}\left(\frac{-\left(z \cdot \color{blue}{\left(z \cdot 0.0692910599291889 + 0.4917317610505968\right)} + 0.279195317918525\right)}{-3.350343815022304 - z \cdot \left(z + 6.012459259764103\right)}, y, x\right)
\] |
*-commutative [<=]0.16 | \[ \mathsf{fma}\left(\frac{-\left(z \cdot \left(\color{blue}{0.0692910599291889 \cdot z} + 0.4917317610505968\right) + 0.279195317918525\right)}{-3.350343815022304 - z \cdot \left(z + 6.012459259764103\right)}, y, x\right)
\] |
+-commutative [<=]0.16 | \[ \mathsf{fma}\left(\frac{-\left(z \cdot \color{blue}{\left(0.4917317610505968 + 0.0692910599291889 \cdot z\right)} + 0.279195317918525\right)}{-3.350343815022304 - z \cdot \left(z + 6.012459259764103\right)}, y, x\right)
\] |
*-commutative [<=]0.16 | \[ \mathsf{fma}\left(\frac{-\left(\color{blue}{\left(0.4917317610505968 + 0.0692910599291889 \cdot z\right) \cdot z} + 0.279195317918525\right)}{-3.350343815022304 - z \cdot \left(z + 6.012459259764103\right)}, y, x\right)
\] |
distribute-neg-in [=>]0.16 | \[ \mathsf{fma}\left(\frac{\color{blue}{\left(-\left(0.4917317610505968 + 0.0692910599291889 \cdot z\right) \cdot z\right) + \left(-0.279195317918525\right)}}{-3.350343815022304 - z \cdot \left(z + 6.012459259764103\right)}, y, x\right)
\] |
*-commutative [=>]0.16 | \[ \mathsf{fma}\left(\frac{\left(-\color{blue}{z \cdot \left(0.4917317610505968 + 0.0692910599291889 \cdot z\right)}\right) + \left(-0.279195317918525\right)}{-3.350343815022304 - z \cdot \left(z + 6.012459259764103\right)}, y, x\right)
\] |
+-commutative [=>]0.16 | \[ \mathsf{fma}\left(\frac{\left(-z \cdot \color{blue}{\left(0.0692910599291889 \cdot z + 0.4917317610505968\right)}\right) + \left(-0.279195317918525\right)}{-3.350343815022304 - z \cdot \left(z + 6.012459259764103\right)}, y, x\right)
\] |
*-commutative [=>]0.16 | \[ \mathsf{fma}\left(\frac{\left(-z \cdot \left(\color{blue}{z \cdot 0.0692910599291889} + 0.4917317610505968\right)\right) + \left(-0.279195317918525\right)}{-3.350343815022304 - z \cdot \left(z + 6.012459259764103\right)}, y, x\right)
\] |
fma-udef [<=]0.16 | \[ \mathsf{fma}\left(\frac{\left(-z \cdot \color{blue}{\mathsf{fma}\left(z, 0.0692910599291889, 0.4917317610505968\right)}\right) + \left(-0.279195317918525\right)}{-3.350343815022304 - z \cdot \left(z + 6.012459259764103\right)}, y, x\right)
\] |
metadata-eval [=>]0.16 | \[ \mathsf{fma}\left(\frac{\left(-z \cdot \mathsf{fma}\left(z, 0.0692910599291889, 0.4917317610505968\right)\right) + \color{blue}{-0.279195317918525}}{-3.350343815022304 - z \cdot \left(z + 6.012459259764103\right)}, y, x\right)
\] |
+-commutative [<=]0.16 | \[ \mathsf{fma}\left(\frac{\color{blue}{-0.279195317918525 + \left(-z \cdot \mathsf{fma}\left(z, 0.0692910599291889, 0.4917317610505968\right)\right)}}{-3.350343815022304 - z \cdot \left(z + 6.012459259764103\right)}, y, x\right)
\] |
sub-neg [<=]0.16 | \[ \mathsf{fma}\left(\frac{\color{blue}{-0.279195317918525 - z \cdot \mathsf{fma}\left(z, 0.0692910599291889, 0.4917317610505968\right)}}{-3.350343815022304 - z \cdot \left(z + 6.012459259764103\right)}, y, x\right)
\] |
if 1.12e16 < z Initial program 66.19
Simplified52.99
[Start]66.19 | \[ 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}
\] |
|---|---|
associate-/l* [=>]52.99 | \[ x + \color{blue}{\frac{y}{\frac{\left(z + 6.012459259764103\right) \cdot z + 3.350343815022304}{\left(z \cdot 0.0692910599291889 + 0.4917317610505968\right) \cdot z + 0.279195317918525}}}
\] |
fma-def [=>]52.99 | \[ x + \frac{y}{\frac{\color{blue}{\mathsf{fma}\left(z + 6.012459259764103, z, 3.350343815022304\right)}}{\left(z \cdot 0.0692910599291889 + 0.4917317610505968\right) \cdot z + 0.279195317918525}}
\] |
fma-def [=>]52.99 | \[ x + \frac{y}{\frac{\mathsf{fma}\left(z + 6.012459259764103, z, 3.350343815022304\right)}{\color{blue}{\mathsf{fma}\left(z \cdot 0.0692910599291889 + 0.4917317610505968, z, 0.279195317918525\right)}}}
\] |
fma-def [=>]52.99 | \[ x + \frac{y}{\frac{\mathsf{fma}\left(z + 6.012459259764103, z, 3.350343815022304\right)}{\mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(z, 0.0692910599291889, 0.4917317610505968\right)}, z, 0.279195317918525\right)}}
\] |
Taylor expanded in z around inf 0.08
Final simplification0.12
| Alternative 1 | |
|---|---|
| Error | 0.12% |
| Cost | 7880 |
| Alternative 2 | |
|---|---|
| Error | 0.25% |
| Cost | 1608 |
| Alternative 3 | |
|---|---|
| Error | 39.71% |
| Cost | 852 |
| Alternative 4 | |
|---|---|
| Error | 39.71% |
| Cost | 852 |
| Alternative 5 | |
|---|---|
| Error | 0.77% |
| Cost | 841 |
| Alternative 6 | |
|---|---|
| Error | 0.53% |
| Cost | 841 |
| Alternative 7 | |
|---|---|
| Error | 40.94% |
| Cost | 720 |
| Alternative 8 | |
|---|---|
| Error | 0.99% |
| Cost | 585 |
| Alternative 9 | |
|---|---|
| Error | 23.74% |
| Cost | 584 |
| Alternative 10 | |
|---|---|
| Error | 50.12% |
| Cost | 64 |
herbie shell --seed 2023090
(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))))