| | 5253 | def simplify_log(self,coeff='integers'): |
| | 5254 | r""" |
| | 5255 | Simplifies this symbolic expression, which can contain logs |
| | 5256 | |
| | 5257 | INPUT:: |
| | 5258 | self -- expression to be simplified |
| | 5259 | |
| | 5260 | coeff -- if 'integers' then only integers multiples are |
| | 5261 | contracted as powers inside logarithm. If 'ratios', |
| | 5262 | then also quotients of integers are treated this way. |
| | 5263 | |
| | 5264 | |
| | 5265 | DETAILS: This uses the Maxima logcontract() command. From the |
| | 5266 | Maxima documentation: "Recursively scans the expression expr, |
| | 5267 | transforming subexpressions of the form a1*log(b1) + |
| | 5268 | a2*log(b2) + c into log(ratsimp(b1^a1 * b2^a2)) + c. The user |
| | 5269 | can control which coefficients are contracted by setting the |
| | 5270 | option logconcoeffp to the name of a predicate function of one |
| | 5271 | argument. E.g. if you like to generate SQRTs, you can do |
| | 5272 | logconcoeffp:'logconfun$ logconfun(m):=featurep(m,integer) or |
| | 5273 | ratnump(m)$ . Then logcontract(1/2*log(x)); will give |
| | 5274 | log(sqrt(x))." |
| | 5275 | |
| | 5276 | ALIAS: log_simplify is the same |
| | 5277 | |
| | 5278 | EXAMPLES:: |
| | 5279 | |
| | 5280 | sage: x,y,t=var('x y t') |
| | 5281 | |
| | 5282 | :: |
| | 5283 | |
| | 5284 | sage: f = log(x)+2*log(y)+1/2*log(t) |
| | 5285 | sage: f.simplify_log() |
| | 5286 | log(x*y^2) + 1/2*log(t) |
| | 5287 | sage: f.simplify_log(coeff='ratios') |
| | 5288 | log(sqrt(t)*x*y^2) |
| | 5289 | |
| | 5290 | """ |
| | 5291 | from sage.calculus.calculus import maxima |
| | 5292 | maxima.eval('domain: real$') |
| | 5293 | if coeff == 'ratios': |
| | 5294 | maxima.eval('logconcoeffp:\'logconfun$') |
| | 5295 | maxima.eval('logconfun(m):=featurep(m,integer) or ratnump(m)$') |
| | 5296 | res = self.parent()(self._maxima_().logcontract()) |
| | 5297 | maxima.eval('domain: complex$') |
| | 5298 | if coeff == 'ratios': |
| | 5299 | maxima.eval('logconcoeffp:false$') |
| | 5300 | return res |
| | 5301 | |
| | 5302 | log_simplify = simplify_log |
| | 5303 | |