Skip to main content
123 votes

Why should I avoid the For loop in Mathematica?

If you are new to Mathematica, and were directed to this post, first see if you can use Table to solve your problem. I have often told people, especially beginners,...
Szabolcs's user avatar
  • 236k
33 votes

Why should I avoid the For loop in Mathematica?

Illustration of the timings required to compute the squares i^2 from i=1 to i=10^n for ...
33 votes
Accepted

Why it seems that there is no counterpart function as to multiplication, to `Total` as to addition?

In addition to the previous answer... I designed and implemented Total 17 years ago. Its first version was named ListSum. The ...
Anton Antonov's user avatar
30 votes

Difference between HashTable datastructure and Association datastructure

Summary Important differences between Association and CreateDataStructure["HashTable"] include: associations are ...
WReach's user avatar
  • 69.1k
28 votes

What are all the "magic" symbols in the Mathematica language?

uh oh, another "work in progress" answer from me that may never be finished. Unevaluated Robby Villegas, Working with Unevaluated Expressions: ...
Mr.Wizard's user avatar
  • 272k
27 votes

What is the use of FullForm in Mathematica?

Perhaps there are other uses, but I've primarily used FullForm to "see" what Mathematica "sees". This can be useful when you are trying to do replacements on ...
MassDefect's user avatar
  • 10.1k
26 votes
Accepted

Row vectors and column vectors (Mathematica vs. MATLAB)

This is a limitation of MATLAB, as MATLAB is only able to work with matrices. It does not have true vectors. It cannot even represent a character array as a 1D array or a structure array as a single ...
Szabolcs's user avatar
  • 236k
25 votes

Unexpected behaviour from Table[]

This is just a long comment trying to shed light on where the problem may be coming from. Since version 10.2, the following is valid syntax: Table[x, 5] Before ...
Szabolcs's user avatar
  • 236k
25 votes

Learn Mathematica (Wolfram) Language in one day

I would recommend these two, in the order listed: Wolfram Language: Fast introduction for programmers Besides the generic edition, there are currently two special editions of this tutorial available ...
C. E.'s user avatar
  • 70.9k
25 votes
Accepted

What's the difference between these 2 associations?

Preamble The real problem here seems somewhat deeper than what the (mostly correct) observations in comments indicate. In Mathematica, a number of objects, which are so-called raw objects (including ...
Leonid Shifrin's user avatar
24 votes
Accepted

Around usage results

There's a subtlety here. When operating together multiple Arounds, the two uncertainties will be considered separate and independent (in the statistical sense). ...
Szabolcs's user avatar
  • 236k
24 votes
Accepted

A clean way to conceptually extract Parts from a circular list

Perhaps ArrayPad: ClearAll[f1] f1 = ArrayPad[##, #] &; Examples: ...
kglr's user avatar
  • 399k
23 votes
Accepted

Why use pure functions?

Think of it as a macro. It shortens up your code. It stops your namespace from being polluted with extra function definitions. In some cases it can be faster than defining an auxiliary function. I ...
Greg Hurst's user avatar
  • 36.4k
21 votes

What are the most common pitfalls awaiting new users?

Fourier transforms do not return the expected result Many users know a particular definition of the Fourier transform. When Mathematica returns an unexpected result and users cannot comprehend what ...
21 votes
Accepted

Using Sequence to delete a part of an expression

What happens to the list after we assign an element to Sequence[] The answers given so far already contain most of the pieces needed to explain this behavior, but I ...
Leonid Shifrin's user avatar
21 votes
Accepted

PostScript-like drawing in Mathematica?

As J.M. notes in a comment, AnglePath allows paths to be specified in relative terms instead of absolute terms: ...
WReach's user avatar
  • 69.1k
21 votes
Accepted

Getting the "root" Head

With a few functions to try, defined in differentfunctions, try this headF: ...
MarcoB's user avatar
  • 67.5k
20 votes
Accepted

What is a function?

A function is really a mathematical idea. In Mathematica, we can represent, or denote, a function in a few ways. But Mathematica is really working with expressions. ...
lericr's user avatar
  • 30.4k
19 votes

Is there a "precedence table" for the canonical Sort ordering?

So I think the docs are mostly clear, if hard to visualize. Here's my version of such a table: ...
b3m2a1's user avatar
  • 47k
19 votes
Accepted

Using the Wolfram Language in a Commercial Product

Preface I feel inclined to answer because I live in both of the worlds you are describing. For one, I work in science where it is more than typical to write software that has sophisticated algorithms ...
halirutan's user avatar
  • 113k
18 votes

Learn Mathematica (Wolfram) Language in one day

The Official Elementary Introduction is also very good to learn some basic stuff.
Riccardo Cazzin's user avatar
18 votes
Accepted

Learn Mathematica (Wolfram) Language in one day

For learning what I consider "just the wolfram/mathematica language" I would proceed as follows and start at the very low-level basics: Learn what is meant by a symbolic expression: ...
masterxilo's user avatar
  • 5,739
18 votes

Nest list with two functions

Update: I think that the cleanest way is to use ComposeList (as suggested by kglr), but with PadRight to generate ...
Ray Shadow's user avatar
  • 7,846
18 votes

A clean way to conceptually extract Parts from a circular list

It turns out we can do all the required transformations using only Partition using the (undocumented) sixth argument to do arbitrary-post-processing: ...
kglr's user avatar
  • 399k
18 votes
Accepted

Broken ValueQ function in Mma12.2?

The behavior of ValueQ has changed in version 12.2. In fact, you can provide a Method -> "Legacy" option to match ...
MarcoB's user avatar
  • 67.5k
17 votes
Accepted

Is $2x$ documented?

From Your First Wolfram Language Calculations: 2x means 2*x. Examples of no-space multiplication from ...
Michael E2's user avatar
  • 239k
16 votes
Accepted

Taking the product of a list of matrices

Dot@@data should do what you're looking for. It replaces the main Head, List, with ...
Ben Kalziqi's user avatar
  • 1,092
16 votes

Learn Mathematica (Wolfram) Language in one day

Mathematica Programming: An Advanced Introduction by Leonid Shifrin is my personal favorite. It may not be a "24 hour" exercise, but it's a breezy and fairly comprehensive introduction to ...
Chris's user avatar
  • 1,086
16 votes
Accepted

Can a symbol have both OwnValues and DownValues?

Yes, a symbol can have both own-values and down-values, but it is usually bad practice to give a symbol both. Further, the order in which they are created matters, but there are problems both ways. ...
m_goldberg's user avatar
  • 108k
16 votes
Accepted

Why is listable not an attribute of the Set function?

Listable is not included because Set is not Listable, imagine what would happen: ...
Kuba's user avatar
  • 137k

Only top scored, non community-wiki answers of a minimum length are eligible