0

I noticed that for the input a*b/c, b/c is evaluated first, and then a*(b/c).

In[1]:=FullForm@Hold[a*b/c]
Out[1]=Hold[Times[a,Times[b,Power[c,-1]]]]

But I don't know why.

Later I found a built-in function Precedence (which seems to not be in the official document, but it is in my Mathematica 14.0 software). With it, I found out that the precedence of Divide is higher than Times.

In[2]:=Precedence@# & /@ {Times, Divide, Plus, Subtract}
Out[2]={400., 470., 310., 310.}

Well, it's pretty easy to show that the result is correct although we give Divide a higher precedence than Times (as long as they are both left associative). But in most programming languages, * and / have the same precedence. It also makes sense to us.

So, why does Mathematica give Divide higher precedence? Is it to make the evaluation faster? Or are there other reasons?

If there are some good reasons for the unequal precedence, why does Plus and Subtract have the same precedence? (The result is correct even if - is higher than +, as long as they are both left associative)

3
  • 1
    Here's the precedence table, and wow, it is the craziest precedence table I've ever seen. Looks like they wanted to put a bunch of stuff between * and / in precedence for some reason. Commented Apr 21, 2024 at 7:56
  • @user2357112, That's amazing. I've evaluated their Precedence and get 410 to 460. Commented Apr 21, 2024 at 8:37
  • a*b/c translates to a/1 * b/1 * 1/c. Commented Apr 21, 2024 at 9:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.