Questions tagged [syntax]

Questions on the correct (or improved) formulation of Mathematica code to achieve particular results. Use this tag (not "symbol") for questions about all those odd @@ /@ # & and _ characters, which are keyboard shortcuts for the Wolfram Language named functions Apply, Map, Slot, Function, and Blank.

Syntax refers to the rules of how to construct well formed Mathematica-code. Syntax is primarily not about the meaning of the code but is about whether Mathematica understands the input or not. Questions about built-in operators and other special characters of Mathematica, argument order for functions and the proper use of functions and symbols should use this tag.

Questions about the syntax highlighter might use the tag . Questions about introducing custom syntax should use the tag . Questions about the handling, removing, generating and passing of symbols (labels for data) should use the tag .

Useful Links:

Some of the more common syntax and special operators

1014 questions
20
votes
5 answers

Change syntax from other programs to mathematica syntax

Is there a good way to transform syntax from other computer algebra systems or from latex to mathematica syntax?
Phira
  • 755
  • 7
  • 13
14
votes
1 answer

What does ` symbol in ClearAll["Global`*"] mean?

I have found an example for clearing all symbol definition by: ClearAll["Global`*"] But what does the symbol ` mean? It isn't the apostrophe ', yet it is not documented in Mathematica help. Jim
JimmyLin
  • 573
  • 2
  • 11
12
votes
1 answer

Explain a Mathematica winning one-liner

Dynamic[Refresh[ Graphics3D[ Sphere[l -= MapIndexed[ Plus @@ (Function[ x, (d = # - x)/(d = Sqrt[d.d]) Log@d/2^(2 + 2 d)] /@ Drop[l, #2]) &, l], E^-1]], UpdateInterval -> 1], l = RandomReal[7, {21, 3}]] This…
fizzix
  • 121
  • 3
12
votes
1 answer

Should I add a semicolon after a function definition?

should I write the program like this: f[x_]:=x^2; g[x_]:=x+2; or should I write the program like this: f[x_]:=x^2 g[x_]:=x+2 Which one is good practice, does any of them have side effect?
an offer can't refuse
  • 1,745
  • 12
  • 23
10
votes
2 answers

Constructing a Summation with a Variable Number of Inner Sums

I have a question regarding multiple sums. And my second index depends on the first index. Here it is: $$ \sum_{d=1}^{P}e^{-d}\sum_{\substack{1\leq k_{1}\leq Q \\ 1\leq k_{2}\leq Q \\... \\...\\1\leq k_{d}\leq Q}}e^{-(k_{1}+...+k_{d})} $$ I could…
neticin
  • 101
  • 1
  • 3
9
votes
1 answer

Accept Infinity as an Integer argument

I have the following function, albeit contrived: Foo[x_Integer] := Module[{i}, i = 1; While[i <= x && i <= 10, i++]; i - 1 ]; I am looking for the following Foo[1] = 1 . . . Foo[10] = 10 Foo[11] = 10 Foo[Infinity] = 10 However…
mmorris
  • 1,172
  • 7
  • 18
9
votes
4 answers

Error when using rule as a list index - { i, x[[i]] } /. i -> 5

I can't seem to use a rule to index a vector. x = Range[10]; { i, x[[i]] } /. i -> 5 I get the following error when evaluating the above code, even if the next cell shows the correct result: Part::pspec: Part specification i is neither an integer…
Meh
  • 1,637
  • 2
  • 13
  • 17
7
votes
1 answer

How can I specify a numerical order for variables?

I need to specify that a variable is less than another, and greater than yet another, in a Mathematica program, because I will later apply a test to them that will determine what functional form to use. I also need Sign[] to give the correct answer.…
Tom Dickens
  • 453
  • 2
  • 9
7
votes
0 answers

Do any mainstream text editors support Wolfram Language syntax for highlighting?

Syntax Highlighting for Mathematica on a Blog There is the above, but I'm not terribly excited to install rogue packages. For example on github, I share lots of Mathematica code. I see no way to highlight syntax. This may keep Wolfram down in…
Altoidnerd
  • 73
  • 4
6
votes
2 answers

What does (0 &) mean in an evaluation?

My Mathematica code is this: Simplify[D[Sqrt[1 + (u')^2 + (-60 x - 20 u u')^2], u]] It returns this: (1200 u x (0&) + (1200 x + (0&) + 400 u^2 (0&)) u^′+ 400 u (u')^2) / Sqrt[1 + (u^′)^2 + 400 (3 x + u u^′)^2] What does the (0&) term mean?
oldlab
  • 191
  • 1
  • 4
6
votes
2 answers

How to Write Partition with Infix?

The documentation says that using Infix ~, the following input f[e1,e2,e3,...] can be rewritten as e1~f~e2~f~e3~... So, for the sake of example, consider the following list defined below. samplelist = {1,2,3,4,5,6,7,8,9} If I wanted to Partition…
user155812
  • 505
  • 3
  • 8
6
votes
1 answer

What is the role of _ in this expression?

I'm fairly familiar with basic Mathematica, but some of its more advanced syntax (especially certain special characters) eludes me. In the Scope section in the documentation of Collect, there's this curious bit at the end: D[f[Sqrt[x^2 + 1]], {x,…
jvriesem
  • 417
  • 3
  • 12
6
votes
3 answers

Syntax for prefix mode with multiple arguments using @ shorthand

Is it possible to use the @ symbol with multiple arguments? The Prefix command suggested not. If so, why?
Emre
  • 1,720
  • 2
  • 13
  • 21
6
votes
1 answer

Why can Format be used on the left side?

I am learning Mathematica in random order by reading its documentation. This approach is what I like most when learning new things. Consider the following 2 cases. Syntax A: Format[Foo[x_,y_]]:=MatrixForm[{{x},{y}}] Foo[1,2] Syntax…
kiss my armpit
  • 757
  • 4
  • 15
5
votes
2 answers

f /@ # & /@ # & /@ # & /@ # & /@ # & /@ # & /@ # & /@ matrix

How can one write f /@ # & /@ # & /@ # & /@ # & /@ # & /@ # & /@ # & /@ matrix in one line with arbitrary level and without using Map functions level argument or assigning to any variable names?
user
  • 1,877
  • 10
  • 19
1
2 3 4 5 6 7 8