| 1184 | class Function_beta(GinacFunction): |
| 1185 | def __init__(self): |
| 1186 | r""" |
| 1187 | Return the beta function. This is defined by |
| 1188 | |
| 1189 | .. math:: |
| 1190 | |
| 1191 | B(p,q) = \int_0^1 t^{p-1}(1-t)^{1-q} dt |
| 1192 | |
| 1193 | for complex or symbolic input `p` and `q`. |
| 1194 | Note that the order of inputs does not matter: `B(p,q)=B(q,p)`. |
| 1195 | |
| 1196 | GiNaC is used to compute `B(p,q)`. However, complex inputs |
| 1197 | are not yet handled in general. When GiNaC raises an error on |
| 1198 | such inputs, we raise a NotImplementedError. |
| 1199 | |
| 1200 | If either input is 1, GiNaC returns the reciprocal of the |
| 1201 | other. In other cases, GiNaC uses one of the following |
| 1202 | formulas: |
| 1203 | |
| 1204 | .. math:: |
| 1205 | |
| 1206 | B(p,q) = \Gamma(p)\Gamma(q)/\Gamma(p+q) |
| 1207 | |
| 1208 | or |
| 1209 | |
| 1210 | .. math:: |
| 1211 | |
| 1212 | B(p,q) = (-1)^q B(1-p-q, q). |
| 1213 | |
| 1214 | |
| 1215 | For numerical inputs, GiNaC uses the formula |
| 1216 | |
| 1217 | .. math:: |
| 1218 | |
| 1219 | B(p,q) = \exp[\log\Gamma(p)+\log\Gamma(q)-\log\Gamma(p+q)] |
| 1220 | |
| 1221 | |
| 1222 | INPUT: |
| 1223 | |
| 1224 | - ``p`` - number or symbolic expression |
| 1225 | |
| 1226 | - ``q`` - number or symbolic expression |
| 1227 | |
| 1228 | |
| 1229 | OUTPUT: number or symbolic expression (if input is symbolic) |
| 1230 | |
| 1231 | EXAMPLES:: |
| 1232 | |
| 1233 | sage: beta(3,2) |
| 1234 | 1/12 |
| 1235 | sage: beta(3,1) |
| 1236 | 1/3 |
| 1237 | sage: beta(1/2,1/2) |
| 1238 | beta(1/2, 1/2) |
| 1239 | sage: beta(-1,1) |
| 1240 | -1 |
| 1241 | sage: beta(-1/2,-1/2) |
| 1242 | 0 |
| 1243 | sage: beta(x/2,3) |
| 1244 | beta(1/2*x, 3) |
| 1245 | sage: beta(.5,.5) |
| 1246 | 3.14159265358979 |
| 1247 | sage: beta(1,2.0+I) |
| 1248 | 0.400000000000000 - 0.200000000000000*I |
| 1249 | sage: beta(3,x+I) |
| 1250 | beta(x + I, 3) |
| 1251 | |
| 1252 | Note that the order of arguments does not matter:: |
| 1253 | |
| 1254 | sage: beta(1/2,3*x) |
| 1255 | beta(3*x, 1/2) |
| 1256 | |
| 1257 | The following must be fixed to remain symbolic:: |
| 1258 | |
| 1259 | sage: beta(2,1+5*I) |
| 1260 | -0.0305039787798408 - 0.0198938992042440*I |
| 1261 | |
| 1262 | """ |
| 1263 | GinacFunction.__init__(self, "beta", nargs=2, |
| 1264 | conversions=dict(maxima='beta', mathematica='Beta')) |
| 1265 | |
| 1266 | beta = Function_beta() |
| 1267 | |