Log doesn't work properly in MMA

  • Thread starter Nile3
  • Start date
  • Tags
    Log Work
In summary: I asked about this on the MaT forum and there was no response.SameQ, or ===, is a very narrow definition of equality. Two expressions that might "obviously be the same" to someone with mathematical skill will sometimes be SameQ and sometimes not. SameQ is sometimes exactly what is needed to solve a challenging programming problem. If I remember correctly, long long ago, back in the dark ages of the old plain LISP programming language, the equivalent of SameQ in LISP would just look at the memory address of the left hand side and right hand side and if those were the same then they were SameQ. That saved all the processor cycles needed to climb up and down the tree that made
  • #1
Nile3
42
0
In[48]:= 2 Log[3] === Log[3^2]

Out[48]= False

Why? Seems basic enough, it should find it.

In[49]:= Simplify[2 Log[3]]

Out[49]= Log[9]

He gets it with simplify... What am I missing this time?

Thank you in advance.
 
Physics news on Phys.org
  • #2
If you look at the documentation you see that SameQ yields true if the lhs is "identical" to the rhs and that word "identical" means much more in that statement than many might think.

SameQ, or ===, is a very narrow definition of equality.

Two expressions that might "obviously be the same" to someone with mathematical skill will sometimes be SameQ and sometimes not. SameQ is sometimes exactly what is needed to solve a challenging programming problem.

If I remember correctly, long long ago, back in the dark ages of the old plain LISP programming language, the equivalent of SameQ in LISP would just look at the memory address of the left hand side and right hand side and if those were the same then they were SameQ. That saved all the processor cycles needed to climb up and down the tree that made up each expression and compare each pair of words in memory to determine whether these two expressions were the same or not.

That is the reason there is an == and an === in LISP and in Mathematica and those are completely different things.

With Mathematica and the automatic mandatory simplifications of some parts of some expressions I think it is a little more difficult to describe PRECISELY EXACTLY what SameQ will do in every case. But I don't believe that SameQ will invoke Simplify against each expression and spend the cycles doing that and then see if the result turns out to be SameQ or not. I vaguely remember, but can't give you examples at the moment, of some what seem to be really simple examples that you might think are "the same", but that are not SameQ.

It isn't quite true, but there is some truth in the statement that Mathematica does not have "mathematical maturity." That means that Mathematica sometimes cannot see what is obviously, or relatively obviously, true to a person trained and experienced in mathematics. But, to be fair, there are probably tens of thousands of rules inside Mathematica and some or many of those might be missed by a person who is even relatively skilled in mathematics.

Even 2 Log[3] == Log[3^2] fails in Mathematica because it drops the ball and starts playing around with approximate mathematics rather than taking the result from Simplify and seeing that both sides are SameQ. Fortunately Simplify[2 Log[3]] === Simplify[Log[3^2]] and Simplify[2 Log[3]] == Simplify[Log[3^2]] both get it right.

Buried somewhere in the Wolfram website there should be a detailed explanation that explains all this, but I can't put my finger on it at the moment.
 
Last edited:
  • #3
Hey thank you for the lengthy but thorough reply. I do find mathematica behavior strange sometimes when it seems obvious it should be designed to do maths first and foremost. I guess I'll use simplify for now.

They should make a manual just for these strange cases.
 
  • #4
Mathematica has an attitude and a learning curve that have been known since before it was ever released. This almost certainly is in part because of the history of where this came from.

The support people are also notoriously resistant for even improving the documentation in small ways. I don't think the SameQ help has changed in twenty five years.

But your example has provoked me to make one more try at getting them to add a few sentences of explanation for "identical" in SameQ and for a couple of my favorite misleading help pages. Who knows, maybe a miracle will happen and in a year they might release an improved explanation.

I was very surprised to find in the second edition of "Mathematica Navigator" a claim that SameQ would yield True if Mathematica could determine that the two expressions were identical and False otherwise, but no further explanation about what identical meant, AND a claim that for numerical expressions that SameQ would yield True if the two values if the difference were less than the uncertainty of either one of them. I did not realize that last case was there.
 
  • #5


As a scientist, it is important to understand that the computer program Mathematica (MMA) is not always perfect and may have glitches or inconsistencies. In this case, it appears that the function Log is not behaving as expected.

The reason for this is most likely due to the fact that Mathematica uses a branch cut convention for complex logarithms. This means that the result of Log[z] is not uniquely defined for all complex numbers z. Instead, it depends on the path taken to reach z.

In the first expression, 2 Log[3] is interpreted as Log[3^2], which follows a different path than Log[9]. This results in the two expressions not being equal.

However, when using the function Simplify, Mathematica is able to find a simplified form for 2 Log[3] that follows the same path as Log[9]. This is why the two expressions are equal after simplification.

In conclusion, the issue with Log not working properly in MMA is most likely due to the branch cut convention used for complex logarithms. It is important to keep in mind that computer programs, like any scientific tool, have their limitations and it is always important to critically evaluate the results obtained.
 

Related to Log doesn't work properly in MMA

1. Why is my log function not producing the expected output in MMA?

There could be several reasons for this. One possibility is that the input values are not appropriate for the log function, such as negative numbers or zero. Another reason could be that the log function is being used in the wrong context, for example, if it is being used to calculate a probability rather than a logarithmic value. It is also possible that there is an error in the code or a bug in the software.

2. How can I fix the log function in MMA?

First, check the input values to make sure they are appropriate for the log function. If that is not the issue, try using a different context or adjusting the code to ensure it is working correctly. If the problem persists, it may be a bug in the software, in which case reporting it to the developers can help get it fixed.

3. Is there a specific syntax for using the log function in MMA?

Yes, the syntax for the log function in MMA is "Log[x]" where x is the input value. It is important to note that the input value should be a positive number, otherwise it will not produce a valid output.

4. Can I use the log function in MMA to calculate complex numbers?

Yes, the log function in MMA can be used to calculate complex numbers. However, the result will also be a complex number, so make sure to use appropriate notation and data types in your code.

5. Are there any alternatives to the log function in MMA?

Yes, MMA offers several alternatives to the log function, such as the NaturalLog function, which calculates the natural logarithm, and the Log10 function, which calculates the base-10 logarithm. There are also other mathematical functions that can be used in place of the log function, depending on the specific problem at hand.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
1K
  • Linear and Abstract Algebra
Replies
1
Views
801
  • Precalculus Mathematics Homework Help
Replies
10
Views
764
  • Programming and Computer Science
Replies
2
Views
814
Replies
7
Views
2K
  • General Math
Replies
15
Views
3K
  • Topology and Analysis
Replies
2
Views
1K
Replies
3
Views
1K
  • Calculus and Beyond Homework Help
Replies
8
Views
1K
  • Precalculus Mathematics Homework Help
Replies
11
Views
2K
Back
Top