Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit 0086ec0

Browse files
committed
18970: always simplify log(a^m,a) if possible
1 parent edb1b08 commit 0086ec0

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/sage/functions/log.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,17 @@ def __call__(self, *args, **kwds):
306306
...
307307
TypeError: Symbolic function log must be called as log(x),
308308
log(x, base=b) or log(x, b)
309+
310+
Check if :trac:`18970` is fixed::
311+
312+
sage: log(int(8), 2)
313+
3
314+
sage: log(8, int(2))
315+
3
316+
sage: log(1/8, 2)
317+
-3
318+
sage: log(1/8, int(2))
319+
-3
309320
"""
310321
base = kwds.pop('base', None)
311322
if base is None:
@@ -319,8 +330,18 @@ def __call__(self, *args, **kwds):
319330
raise TypeError("Symbolic function log must be called as "
320331
"log(x), log(x, base=b) or log(x, b)")
321332

333+
arg = args[0]
334+
try:
335+
arg = QQ.coerce(arg)
336+
base = ZZ.coerce(base)
337+
except (AttributeError, TypeError):
338+
pass
339+
else:
340+
v = valuation(arg, base)
341+
if arg == base**v:
342+
return v
322343
try:
323-
return args[0].log(base)
344+
return arg.log(base)
324345
except (AttributeError, TypeError):
325346
return GinacFunction.__call__(self, *args, **kwds) / \
326347
GinacFunction.__call__(self, base, **kwds)

0 commit comments

Comments
 (0)