1
$\begingroup$

Consider the function: $f(x)=\log_3x+\log_316-\log_34$. This can be simplified to $\log_34x$. To simplify this function in Mathematica, I would use the command

Simplify[f[x]]

Which would output $\frac{\log4x}{\log3}$. One could argue whether this was more simple than $\log_34x$, but I would prefer for the base not to be changed when simplifying. This would only be applicable when all of the $\log$s in the function are to the same base.

So how can you tell Mathematica to not simplify the base of a logarithim?

$\endgroup$
  • $\begingroup$ Log[3, 4] gets evaluated to Log[4]/Log[3] immediately. This is not done by Simplify. It is an evaluation rule of Log. $\endgroup$ – Szabolcs May 13 '17 at 11:33
  • $\begingroup$ @Szabolcs Ok, so would this type of functionality not be possible in Mathematica? $\endgroup$ – Tom Eaton May 13 '17 at 11:37
  • $\begingroup$ It depends on what you want to do specifically. It's more complicated than you assumed. Try HoldForm[Log[3,4]]. It stays as it is, but it cannot be used for computations. It is for display purposes. An end result could be post-processed using Log[x_]/Log[y_] -> HoldForm@Log[y, x] to put it back into the form you wanted. There's also Inactive, e.g. Inactive[Log][3, 4]. Inactive is usable in some computations, but I am not sure it is helpful here. $\endgroup$ – Szabolcs May 13 '17 at 11:43
1
$\begingroup$

As Szabolcs points out in the comments, you can't do this the way you would like because it isn't a display rule but an evaluation rule that causes Log[x,y] to turn into Log[y]/Log[x]. You can try to edit the display for this expression after the fact but it quickly becomes intractable; to demonstrate, we could overload the MakeBoxes function for the fraction form:

MakeBoxes[expr : Log[x_]/Log[y_], form_] := MakeBoxes[Log[y, x], form];
Log[x,y]

Log[x,y]

This works, but if we enter something a little more complicated...

2*Log[x,y]

2 Log[y] / Log[x]

This happens because the latter expression gets evaluated into Times[2, Log[y], Power[Log[x], -1]] which is then passed to MakeBoxes, and this expression doesn't match MakeBoxes argument. We could further modify MakeBoxes:

MakeBoxes[Times[a___, Log[x_], b___, Power[Log[y_], -1], c___], form_] := 
  MakeBoxes[#, form] &@Times[a, HoldForm[Log[y, x]], b, c];
MakeBoxes[Times[a___, Power[Log[y_], -1], b___, Log[x_], c___], form_] := 
  MakeBoxes[#, form] &@Times[a, HoldForm[Log[y, x]], b, c];
10*Log[3,4]/2

5 Log[3,4]

But even here we get unexpected results when the expression gets a little more complicated:

Exp[2 * Log[3, 4]]

4 ^ (2 / Log[3])

I think this result is preferable to leaving Log[3,4] in the exponent, but the point is that you won't be able to control the display of this function very easily.

Another thing that might occur to someone is to overload how Log actually works; something like this:

(* This is a bad idea! *)
Unprotect[Log];
Log[x_, y_] =.;
Log /: N[Log[x_, y_]] := N[Log[y]/Log[x]];

I doubt that code would work, but even if it did and you could successfully handle all the cases in which Log is passed to N, you would probably break all sorts of Mathematica internals like Solve, Minimize, Simplify, etc., all of which expect Log to simplify itself.

| improve this answer | |
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.