Message Boards Message Boards

0
|
190 Views
|
6 Replies
|
3 Total Likes
View groups...
Share
Share this post:

@@ doesn't work on TraditionalForm input

Hi Community,

I seem to experience some problems when I try to use @@ to TraditionalForm input. I was expecting that Times@@a+b+c would return abc. As you can see from my notebook below, it doesn't. Times@@Plus[a,b,c] yields the expected result. Anyone who can shine some light on this?

Many thanks in advance!

POSTED BY: Fredrik Erling
6 Replies
Posted 15 days ago

Try:

Times @@ (a + b + c)
POSTED BY: Hans Milton
Posted 15 days ago

Side note, you're not actually using TraditionalForm anywhere, and it's not relevant to the issue. The issue is purely one of precedence.

POSTED BY: Eric Rimbey
Posted 15 days ago

Apply and Plus have different precedences:

In[1]:= Precedence[Apply]
Out[1]= 620.

In[2]:= Precedence[Plus]
Out[2]= 310.

The higher the precedence, the tighter it will bind a function/argument pair. This matters only when using infix notation. Bracketing overrides the precedence pairings.

Prefix notation is not affected by precedences, since the syntax itself decides order of evaluation:

Apply[Times, Plus[a, b, c]]

Postfix notation also generally works Ok:

a + b + c // Times @@ # &
POSTED BY: Hans Milton

Thank you Hans,

That worked. But why? What magic is hidden in the addition of the brackets?

Head[(a+b+c)] yields Plus. Exactly like Head[a+b+c].

POSTED BY: Fredrik Erling
Posted 15 days ago
Times @@ a + b + c

is the same as

(Times @@ a) + b + c

and

Times @@ a

is just a.

POSTED BY: Eric Rimbey

Gentlemen,

Thank you for your excelent bits of wisdom that you so generously have shared with me. I know feel that my existence on this planet has reached a higher dimension. Made my day!

POSTED BY: Fredrik Erling
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract