Can one do something similar to +[1, 2]? The point is that with one symbol you would be able to write expressions like #/+@@# &@{1, 2, 3} and yet benefit from Mathematica's algebraic capabilities, so that expressions like 1+1*2 would output 3 not 4.
Asked
Active
Viewed 719 times
6
J. M.'s missing motivation
- 124,525
- 11
- 401
- 574
user
- 1,877
- 10
- 19
3 Answers
13
You can use the Notation package. It requires a GUI palette though.
Needs["Notation`"]
Once you have this package loaded, you can use the template to define:
Notation[+[x___] ==> Plus[x___]]
and then
+[1,2,3]
(* 6 *)
Similarly,
Notation[*[x___] ==> Times[x___]]
and so
*[2,3,4]
(* 24 *)
Note: A * typed as the first character of a cell converts it to an "Item Cell."
Eric Brown
- 4,406
- 1
- 18
- 36
-
1Quite useful edit. I also propose to write
x___to handle zero number of arguments (sometimes it is useful). – ybeltukov Nov 15 '15 at 22:49 -
1@EricBrown Since Mathematica 10, typing
*as the first character on the line converts it to an item cell. It's similar to how typing=as the first character is also special. – Szabolcs Nov 16 '15 at 11:09 -
@Szabolcs That's what it is! Thanks. I was confused because I had Notation working for * then not. – Eric Brown Nov 16 '15 at 12:52
9
For Plus, there's this, from How would I add together any list of arguments as a pure function?:
+Sequence[1, 2, 3]
(* 6 *)
Michael E2
- 235,386
- 17
- 334
- 747
6
You can use any character without built-in meaning like + or * (they differ from standard + and *). However, it is difficult to type them. So I propose to use meaningful Greek letters Σ and Π with shortcuts EscSEsc and EscPEsc respectively
Σ = Plus;
Π = Times;
Σ[1, 2]
Π[1, 2]
(* 3 *)
(* 2 *)
You can use this notation in other syntax constructions
Π @@ {1, 2, 3, 4}
(* 24 *)
Eric Brown
- 4,406
- 1
- 18
- 36
ybeltukov
- 43,673
- 5
- 108
- 212
-
2You know,
Plusis just one more keystroke and escape is far from home row. I'm rather with Sjoerd on this. – Michael E2 Nov 15 '15 at 23:06 -
-
@bills It was my first thought, but I decided that it is not very intuitive. – ybeltukov Nov 16 '15 at 03:12
-
It would be most useful if what ever symbol is used to denote summation would be used for both infix notation, like
1+1, and for function Head, like+[1,1]. Could one use one of these symbols in place of the current + symbol everywhere? – user Nov 16 '15 at 09:33 -
Sure you can write
1~Plus~1~Times~2, but the evaluation order isn't right: the output of the previous expression is 4 not 3. – user Nov 16 '15 at 09:45
+@@#&/@{{1,2},{3,4}}and yet benefit from Mathematica's algebraic capabilities, so that expressions like1+1*2would output 3 not 4. – user Nov 16 '15 at 09:551+1*2already outputs3. – shrx Nov 16 '15 at 10:04#/+@@# &@{1, 2, 3}doesn't output {1/6, 1/3, 1/2}. You can't use the same symbol for both infix and function head. – user Nov 16 '15 at 10:07Normalize[]was meant for… – J. M.'s missing motivation Nov 16 '15 at 10:58+/ 2 3 4gives result9, and*/2 3 4the result24(and^/ 2 3 4the result2.41785e24, where what^/does is to insert the power operator^between successive items of its argument). – murray Nov 16 '15 at 15:04