Questions tagged [core-language]
Questions on the basic structure of the Mathematica language (Wolfram language) including atomic data types, syntax etc
144
questions
541
votes
37
answers
126k
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 ...
111
votes
4
answers
24k
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 ...
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 ...
52
votes
2
answers
7k
views
Scan vs. Map vs. Apply
I cannot understand the difference between Apply, Scan, and Map.
I have tried to play with ...
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 ...
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 ...
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 ...
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 ...
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:
...
23
votes
1
answer
943
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 ...
19
votes
3
answers
732
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.
...
42
votes
3
answers
1k
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
...
33
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 ...
48
votes
2
answers
68k
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 ...
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 ...
27
votes
2
answers
599
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 ...
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 ...
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 ...
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 ...
13
votes
4
answers
2k
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 ...
20
votes
2
answers
557
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 ...
11
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 ...
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 ...
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 ...
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 ...
31
votes
2
answers
864
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 ...
6
votes
2
answers
364
views
Why rule does not work if Flat attribute?
The following works:
...
3
votes
1
answer
276
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 ...
20
votes
1
answer
736
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:
...
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 ...
13
votes
2
answers
893
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 ...
11
votes
1
answer
302
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] ...
4
votes
1
answer
480
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 ...
46
votes
2
answers
2k
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 <...
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 ...
24
votes
2
answers
2k
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 ...
23
votes
0
answers
336
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, ...
23
votes
1
answer
531
views
Confused about how Partition works
I have a problem about the padding list about Partition command. For instance,
...
21
votes
2
answers
592
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 ...
19
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 ...
16
votes
1
answer
329
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 (...
15
votes
2
answers
321
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 ...
15
votes
4
answers
531
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 ...
12
votes
2
answers
277
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 ...
11
votes
2
answers
451
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:
...
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. ...
10
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.
...
6
votes
1
answer
286
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,
...
6
votes
2
answers
353
views
Overlapping pure functions
Let say I need and option for Plot:
RegionFunction -> (-6 < #2 < 6 &)
But I also want those ...
5
votes
3
answers
243
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.
...