121 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
  • 234k
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
32 votes
Accepted

++ is dangerous for C programmers

I believe Increment (more accurately PreIncrement as george2079 noted) is essentially this: ...
Mr.Wizard's user avatar
  • 271k
29 votes

Difference between HashTable datastructure and Association datastructure

Summary Important differences between Association and CreateDataStructure["HashTable"] include: associations are ...
WReach's user avatar
  • 68.7k
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
  • 271k
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

Resolving my Entity* Crisis

As an employee at Wolfram who is partly involved with development of the entity framework, let me give my take on things. Particularly, I want to address the following points raised by the OP and in ...
Paco Jain's user avatar
  • 897
25 votes
Accepted

How can one manually change the rule ordering

General The definitions get reordered at definition-time by a part of the pattern matcher, that takes care of automatic rule reordering. It does so, based on relative generality of rules, as far as ...
Leonid Shifrin's user avatar
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
  • 234k
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.4k
25 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
  • 234k
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
  • 234k
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
  • 392k
24 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
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
  • 35.8k
22 votes

How can one manually change the rule ordering

Actually we have direct control over this via a System Option. Set: SetSystemOptions["DefinitionsReordering" -> "None"]; Then: ...
Mr.Wizard's user avatar
  • 271k
22 votes
Accepted

Version inconsistency with optional arguments: what if the default value doesn't match the pattern?

Update: Daniel Lichtblau authoritatively comments: This change was intentional, and per request of the boss. I can find no mention of this in the documentation, though I am still looking. My ...
Mr.Wizard's user avatar
  • 271k
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
  • 68.7k
21 votes
Accepted

Getting the "root" Head

With a few functions to try, defined in differentfunctions, try this headF: ...
MarcoB's user avatar
  • 66.6k
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
  • 26.4k
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

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
  • 46.8k
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,729
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,806
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
  • 392k
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
  • 66.6k

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