Questions tagged [core-language]

Questions on the basic structure of the Mathematica language (Wolfram language) including atomic data types, syntax etc

Filter by
Sorted by
Tagged with
549 votes
37 answers
131k views

What are the most common pitfalls awaiting new users?

As you may already know, Mathematica is a wonderful piece of software. However, it has a few characteristics that tend to confuse new (and sometimes not-so-new) users. That can be clearly seen from ...
115 votes
4 answers
27k views

Why should I avoid the For loop in Mathematica?

Some people advise against the use of For loops in Mathematica. Why? Should I heed this advice? What is wrong with For? What ...
Szabolcs's user avatar
  • 235k
34 votes
5 answers
2k views

What are the requirements for a well behaved indexed variable? Subscript, ToExpression, Downvalue?

On writing this answer I needed to call a function, (NonlinearModelFit) with an unknown number of parameters. We have learned that we should not use ...
rhermans's user avatar
  • 36.5k
52 votes
2 answers
8k views

Scan vs. Map vs. Apply

I cannot understand the difference between Apply, Scan, and Map. I have tried to play with ...
MOON's user avatar
  • 3,864
83 votes
1 answer
3k views

Incompatible Changes since Mathematica Version 7?

There is documentation of the incompatible changes made to Mathematica with each major release: Incompatible Changes since Mathematica Version 1 Unfortunately that documentation simply stopped ...
Mr.Wizard's user avatar
  • 272k
160 votes
3 answers
13k views

How to make use of Associations?

I have been curious about it for long. Now that Mathematica 10 arrives, I think it's time to ask the question: How the new Association data structure would be used ...
Yi Wang's user avatar
  • 7,347
25 votes
5 answers
1k views

How can one manually change the rule ordering

I have a function which has some general behavior, but that should act on some specific kinds of objects in some other way. I know that Mathematica is supposed to automatically order the rules so that ...
Lior Blech's user avatar
32 votes
1 answer
4k views

How does Return work?

It is not completely clear to me how Return[] works. The documentation says: Return[expr] returns the value expr from a ...
Szabolcs's user avatar
  • 235k
47 votes
3 answers
2k views

Why is the new PositionIndex horribly slow?

This issue has largely been mitigated in 10.0.1. New timings for the final test below are: ...
Mr.Wizard's user avatar
  • 272k
23 votes
1 answer
949 views

Shorter syntax for Fold and FoldList?

I find it tedious to write out the following: a = {1, 2, 3, 4}; Fold[f, First @ a, Rest @ a] f[f[f[1, 2], 3], 4] It ...
Mr.Wizard's user avatar
  • 272k
19 votes
3 answers
763 views

What does None mean in a control specification for Manipulate?

I am now struggling to understand code that contains the following (simplified) Manipulate structure. ...
David's user avatar
  • 14.9k
34 votes
3 answers
2k views

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

This answer in which I wrote about the Operator Precedence Table was unexpectedly popular. That got me thinking about similar things, and I am wondering: Does an "ordering table" exist for the ...
Mr.Wizard's user avatar
  • 272k
42 votes
3 answers
2k views

Is there a name for #1@#2&?

Why does the pure function # @ #2 & have no name? I'm asking because sometimes I find inelegant to write expressions like ...
Kuba's user avatar
  • 137k
51 votes
2 answers
74k views

What does # mean in Mathematica?

I asked Mathematica to compute the following Solve[c (1-x)^2-x^(1/4) == 0, x] and it returned this: x = Root[#1^8 c^4 - 8 #1^7 c^4 + 28 #1^6 c^4 - 56 #1^5 c^4 ...
ronanymous's user avatar
27 votes
4 answers
2k views

ReadList problem related to Record type

A simple file reading issue is baffling me here. I am reading a around 200 MB textual file in .dat format. Now the file contains many lines but to phrase my problem ...
PlatoManiac's user avatar
  • 14.7k
27 votes
2 answers
611 views

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

I just came across some weird behaviour. Take this function definition: ClearAll[f] f[vs_List : All] := "match" The default value of ...
Szabolcs's user avatar
  • 235k
23 votes
3 answers
2k views

When must I use the Return function?

In a comment to my answer to this question, QuantumDot asks, "Where can I find more information on when I must use the 'Return' function?". I found this too deep a question to be answered by leaving a ...
m_goldberg's user avatar
  • 108k
20 votes
6 answers
8k views

How to completely delete the head of a function expression

Is there any way to completely remove the head of an expression function? For example, how would I remove the head Cos from ...
Basheer Algohi's user avatar
22 votes
2 answers
1k views

I define a variable as local to a module BUT then the module uses its global value! Why?

I have a question about modules and local variables. Here's my example: h = 5; Module[{a, h}, a[h_]= h^2; a[4]] (*Out[2] = 25*) I expected the module to ...
pan_e_gaban's user avatar
13 votes
4 answers
3k views

Capital Letters that are built-in symbols

I'm trying to search for an answer to "What is the complete list of single capital letters that represent built-in Mathematica commands, symbols, or uses?" For example: C, D, E, I, N, O Is this ...
David's user avatar
  • 14.9k
20 votes
2 answers
576 views

Using Sequence to delete a part of an expression

I thought that assigning Sequence[] to a part of an expression is an effective way to remove it. For example, the following code yields ...
Hector's user avatar
  • 6,438
12 votes
1 answer
2k views

Row vectors and column vectors (Mathematica vs. MATLAB)

As far as I know, Mathematica does not distinguish between row vectors and column vectors: all vectors are seen as lists. I know ways to bypass this as suggested in Product between a column vector and ...
Dimitris's user avatar
  • 4,794
6 votes
1 answer
2k views

Behavior of expression evaluation in Plot

I'm confused with Mathematica's way of parsing expressions. I've been struggling with this for a while and never found an exhaustive answer, sometimes things don't parse the way I think they would ...
user61865's user avatar
47 votes
1 answer
5k views

++ is dangerous for C programmers

I noticed this fact, that may be misleading for programmers used to C language. In Mathematica, if you have a function f[] and an array ...
Giovanni Resta's user avatar
44 votes
2 answers
3k views

Is Mathematica comparable to C++ for creating standalone applications?

At my university, I have a yearly essay. I'm allowed to use any technology for implementing it. I've been coding it in C++ with Qt. I thought of about Wolfram Mathematica because I have some ...
Tebe's user avatar
  • 571
32 votes
2 answers
879 views

Why is Query so much slower than Part?

Time for another of these(1),(2) as yet another new-in-10 function appears to have poor performance compared to older alternatives. This time: Query appears to be ...
Mr.Wizard's user avatar
  • 272k
6 votes
2 answers
366 views

Why rule does not work if Flat attribute?

The following works: ...
Suzan Cioc's user avatar
  • 2,023
3 votes
1 answer
287 views

Can I define $y=y(x)$?

I believe this a question that most of us have encountered when we were beginners but forgot when we got more familiar with Mathematica. We know the notation $y=y(x)$ for functions, where $y$ here ...
xzczd's user avatar
  • 66.2k
20 votes
3 answers
3k views

How do I make a string literal without having to escape backslashes?

I'd like to say something like: foo = @"\abc\def\ghi" instead of foo = "\\abc\\def\\ghi" How do I do this? This would ...
epylar's user avatar
  • 347
20 votes
1 answer
759 views

Why won't SparseArray let me store values with the head List?

When you attempt to define a SparseArray with elements that have the head List it complains: ...
Mr.Wizard's user avatar
  • 272k
18 votes
2 answers
1k views

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

Times and Plus have the same grammar, and so do Product and ...
Αλέξανδρος Ζεγγ's user avatar
13 votes
2 answers
928 views

How to restore function attributes to default

Adding an attribute to a function is easy and clearing attribute is easy also. But I don't know really how to restore the attributes of a function to its defaults. All I do is quit the kernel or close ...
Basheer Algohi's user avatar
11 votes
1 answer
307 views

Why can't a string be formed by head String?

Since everything is an expression in Mathematica, why must a string object be formed by "abc" but not by a String[abc] ...
Naitree's user avatar
  • 1,235
4 votes
1 answer
509 views

ControlType -> None Vs. Module inside Manipulate (i.e. making everything local)

I'm building a program on another one made available in the Wolfram Demonstration Project. I've noticed that in the original code (working flawlessly) many variables were made local inside the ...
Luca M's user avatar
  • 997
47 votes
3 answers
3k views

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

Leonid Shifrin once wrote (excerpted): (Unevaluated) is one of a very few "magic symbols", along with Sequence and <...
Mr.Wizard's user avatar
  • 272k
35 votes
7 answers
6k views

Learn Mathematica (Wolfram) Language in one day

Currently I am trying to learn Python. Searching for relevant material I came across X in Y minutes and books with titles such as Learn Python in one day, in 24 hours, etc. Similar material exists ...
Dimitris's user avatar
  • 4,794
24 votes
2 answers
3k views

Unexpected behaviour from Table[]

The following code in Mathematica 11: iList = {i, -10, 10, 2}; Table[i, iList] produces this result: {i, i, i, i} Where in ...
Bruce Crawford's user avatar
23 votes
0 answers
342 views

What has changed in pattern matching functions with the Orderless attribute?

Bug introduced in 10.1 and fixed in 11.0(.1) In making an attempt to answer this question, we ran into a version-dependent pattern-matching issue. An extended discussion in the comments transpired, ...
march's user avatar
  • 23.5k
23 votes
1 answer
533 views

Confused about how Partition works

I have a problem about the padding list about Partition command. For instance, ...
xyz's user avatar
  • 625
22 votes
2 answers
610 views

What does f_[whoCalled]^:=f really mean?

I came across the following post by John Doty in this Google Groups discussion: On Friday, January 11, 2013 8:23:16 PM UTC-7, amzoti wrote: It is clear the Mathematica uses Lisp as one ...
Shredderroy's user avatar
  • 5,249
16 votes
1 answer
330 views

How does Plus work on machine precision Real arguments?

I thought Kahan's summation method would make a nice example for students to use to think about round-off error [W. Kahan, Pracniques: Further Remarks on Reducing Truncation Errors, Commun. ACM 8  (...
Michael E2's user avatar
  • 236k
15 votes
4 answers
536 views

Make mathematica treat $e_i^2$ as numeric

With NumericQ[symbol] = True, I can declare that a symbol is numeric. I want the expressions matching: $$e_{\text{i$\_$}?\text{IntegerQ}}^2$$ to be treated as ...
comco's user avatar
  • 253
15 votes
2 answers
343 views

Is anonymous pure function a scoping construct?

In recent thread was raised the question: why anonymous pure functions Function[body] (or body &) do not rename symbols in ...
Alexey Popkov's user avatar
12 votes
2 answers
281 views

Why is Graph an atomic expression in Mathematica?

Actually, the title says it all. I am a little confused why such a complicated object as Graph, with many different parts, was designed to be atomic in Mathematica ...
Artem's user avatar
  • 1,037
11 votes
1 answer
1k views

Treat all variables as local in a module [duplicate]

In most languages, any variable defined inside a function is considered local. ...
tba's user avatar
  • 585
11 votes
2 answers
474 views

Unexpected variable renaming depending on form of a pure function

I encountered unexpected difference in variable renaming behavior depending on whether a pure function with a named parameter, or a pure function with a slot is used: ...
Vladimir Reshetnikov's user avatar
10 votes
1 answer
1k views

Proper use of arbitrary number of variables

So, I'm working on a project where the number of independent variables is not fixed. Consider a problem of $N$ independent variables, $\boldsymbol{r}$. I want to perform different things with them. ...
Jorge Leitao's user avatar
6 votes
2 answers
354 views

Overlapping pure functions

Let say I need and option for Plot: RegionFunction -> (-6 < #2 < 6 &) But I also want those ...
Kuba's user avatar
  • 137k
6 votes
1 answer
427 views

Is K is a function? [duplicate]

Some of the capitalized single letters are functions. Starting a fresh kernel and typing in the 24 capital letters, the following letters turn black since they are special functions, ...
Kai's user avatar
  • 2,099
5 votes
3 answers
248 views

Pick bug? level 0 matching

A previous discussion of this issue (Is there a bug in Pick?) accepted that matching at level 0 is not a bug in Pick. Was that correct? I am not yet persuaded. ...
Alan's user avatar
  • 13.7k