Group Abstract Group Abstract

Message Boards Message Boards

0
|
12.1K Views
|
2 Replies
|
1 Total Like
View groups...
Share
Share this post:

Limitations of Wolfram|Alpha concerning mathematics?

Posted 10 years ago
POSTED BY: Jan Pernicka
2 Replies

Specifically to the question of summing the sub-lists of a list of lists like {{1,2}, {3,4,5}}, in Mathematica (with Wolfram Language), the full form of this would be List[List[1,2], List[3,4,5]]. For the task at hand, we want to operate on the sub-Lists themselves (by doing Plus on their arguments instead of List) while leaving the outer List essentially intact. The WL function Apply (operator form: @@) is used for swapping out an expression's head, so: Apply[Plus, List[1,2]] or Plus @@ {1,2} Would be the first step to sum a single given list.

The other step is to realize that we have a higher level List structure which we want to keep essentially intact, and only operate on its arguments (the sub-Lists). To do that, you want to use a common idea in WL of "level specification" which many functions support, to act specifically at certain "levels" of the expression: https://reference.wolfram.com/language/ref/Apply.html

We want Apply to act at level 1 of the overall expression (e.g. on the sub-Lists), so we can do: Apply[Plus, List[List[1,2], List[3,4,5]], {1}] ...which conveniently has a shorthand but not at all obvious operator form of "@@@" !

So, shortest form (I think) would be: Plus @@@ {{1,2},{3,4,5}} ...which returns the desired: {3,12}

POSTED BY: Andrew Walters

For that kind of things you may consider trying the free Wolfram programming lab http://www.wolfram.com/programming-lab/

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