Questions tagged [syntax]

Questions on correct (or improved) formulation of Mathematica code to achieve particular results. Use this tag (not "symbol") for questions about all those odd @@ /@ # & and ~ characters.

Filter by
Sorted by
Tagged with
6
votes
2answers
237 views

How to Write Partition with Infix?

The documentation says that using Infix ~, the following input f[e1,e2,e3,...] can be rewritten as ...
6
votes
2answers
2k views

What does (0 &) mean in an evaluation? [closed]

My Mathematica code is this: Simplify[D[Sqrt[1 + (u')^2 + (-60 x - 20 u u')^2], u]] It returns this: ...
6
votes
3answers
689 views

Finding the square root of a squared number?

Taking the square root of the square of a number Variable set to a real value I'm wondering why these examples a = -4.3; Sqrt@a² Sqrt@(a^2) Sqrt[a^2] Sqrt[a²] ...
6
votes
1answer
88 views

How to use a function as a value in an association? [closed]

I just started learning Mathematica. I was wondering if it is possible to use a function as an value in an association. Ideally, it would be something like this: ...
6
votes
2answers
105 views

Converting prefix to infix

Is there a way in Mathematica to convert prefix to infix notation (where precedence order is preserved)? For example, how would I convert S[a, S[b, c]] to ...
6
votes
1answer
347 views

FindFaces in Mathematica 11.3

I just upgraded to Mathematica 11.3. but now my FindFaces instructions do not work anymore. I guess they changed the syntax in 11.3. Here is the original code: <...
6
votes
2answers
571 views

Can someone explain this code for joining two lists by the first element of each sublist?

Background (which may be skipped, unless context is needed) I've recently begun learning Mathematica (and only up to chapter 3 of Wellin), but wanted to write some code to get a better feel for ...
6
votes
2answers
122 views

Separation of statements vs “space mul”, formal definition of Mathematica syntax?

In Mathematica, space can often be used to indicate multiply. For example "a b" = "a * b". On the other hand, in a *.m file, we also have multiple statements separated by newlines. How does the ...
6
votes
1answer
346 views

How can I define a ⊕ operator?

What is wrong with the following code? CirclePlus := SparseArray[Band[{1, 1}] -> {##}] & a_ ⊕ b_ := CirclePlus[a, b] SetDelayed::write: Tag Function in (...
6
votes
1answer
144 views

Why 2^^1*^k does not work?

Table[2^^1*^k,{k,0,10}] This gives an error, why is that? Also this BaseForm[2 ** 1*^ #, 16] & /@ Range[10] What is ...
6
votes
2answers
425 views

Ignore some values at return

Is there Mathematica analogue of Python _ (underscore) or Matlab ~, a special variable, that can be used when a function returns ...
6
votes
1answer
124 views

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: ...
6
votes
1answer
78 views

Variable dimensional integrals

I need to Integrate a function, but let the number of dimensions vary. Integrate[Product[Exp[-( t[[i]] )^2], {i,1,4}], options] ...
6
votes
1answer
131 views

Is (x|y|…)∈set the same as x∈set&&y∈set&&…?

I've sometimes seen that this operator is used to specify that each of given variables is in some set, e.g. Reals. Like ...
6
votes
4answers
2k views

Defining a function with parameters as variables [duplicate]

I have an expression V = (a[1] + a[2])b[1]. How would I define a function of a[1], a[2] and <...
6
votes
1answer
163 views

Why are SetProperty and PropertyValue not working here?

I have a very simple graph, a loop: ...
6
votes
1answer
647 views

How to convert an image to a compressed string representation equivalent to one copied to clipboard by `CopyToClipboard[image]`?

In my recent question I asked How to embed an image into a string? The suggested solution was ...
6
votes
1answer
78 views

Non-trivial partitions of numbers using Combinatorica

I have made a code which gives back partitions of numbers in two Young diagrams (one Young diagram is trivial). For example, the partitions of 1 are ...
6
votes
1answer
119 views

Where does Documentation Center introduce the basics?

While helping a user who mistakenly thought that log rather than Log was the correct built-in function name, I included a gently-...
6
votes
1answer
199 views

Problem overloading D[] using UpValues

First I define an entry of UpValues overloading D[] for expressions with head ftest: ...
6
votes
1answer
315 views

Best way to write an equation with subscripts and superscripts

This post is not about a specific Mathematica problem but about to develop the best way to enter mathematical equations with subscripts and superscripts. I have a ...
6
votes
1answer
172 views

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 ...
6
votes
0answers
83 views

Infix non-ASCII operator needs a space to be parsed correctly in a script

Bug introduced in 9.0 or earlier and persisting through 11.1 First off: ...
5
votes
4answers
412 views

Multiple colors in Graphics[] environment

There are other questions on the site that are similar to this one, but the answers provided didn't help me. I want to draw disks of different radii. Each radius is the absolute value of a variable, ...
5
votes
3answers
290 views

How to imitate list comprehensions for constant arrays?

In Python, ['a'] * 10 generates ['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a'] and ...
5
votes
5answers
256 views

Nested function with an increasing argument

If, for example, I have a nesting function like Nest[1 + x^n (#) &, 1, 3] it gives the result ...
5
votes
5answers
303 views

Integral of the integral using NIntegrate

Consider the integral NIntegrate[Exp[-NIntegrate[x, {x, 0, y}]], {y, 0, 2.8}] It displays an error ...
5
votes
3answers
858 views

Is it possible to make the Button execute two or more actions?

According to the help: Button[label,action] Is it possible to make the button execute two actions?
5
votes
2answers
325 views

Overlapping pure functions

Let say I need and option for Plot: RegionFunction -> (-6 < #2 < 6 &) But I also want those ...
5
votes
2answers
263 views

Why SetDelayed won't work

I'm trying to do this: Riffle[list = {a, b, c, d, e, f}, tem = RandomInteger[1, Length@list-1]] {a, 0, b, 0, c, 1, d, 0, e, 0, f} But I think this method is ...
5
votes
2answers
497 views

List reversion inspired by Python

In python, if you wish to reverse a list, here is the trick: range(10)[::-1] => [9, 8, 7, 6, 5, 4, 3, 2, 1, 0] Note: ...
5
votes
3answers
274 views

Relational operators on vectors

How do I use relational operators on vectors? {1, 2, 3} > {0, 1, 2} (*outputs {1, 2, 3} > {0, 1, 2}*) More generally, I want ...
5
votes
3answers
479 views

What is the right way to write a function that includes other functions?

I want to include multiple sub functions: $b(x) = 10x$ $w(x) = s + b(x)$ $c(x) = x^2$ into two main functions: $ua(x) = w(x)-c(x)$ $ub(x) = w(x)-c(x)^2$ As a reaction to this answer, I wrote ...
5
votes
2answers
480 views

Game schedule where each player meets only once

I am trying to generate a game schedule where $k$ players at the time, out of $n$ participants, meet in each game, but any player meets another player only once. In each game, with $k$ simultaneous ...
5
votes
2answers
761 views

Integrate using \[Esc] int \[Esc]

I like writing integrals symbolically instead of using Integrate[]. I suddenly seem to not be able to do this and am confused. I type \[Esc] int \[Esc] then ...
5
votes
2answers
307 views

Syntax highlighting conflict

I'm trying to syntax highlight this expression: x=$\sqrt{\pi }$//N and from various sources I've learned that x (the assigned symbol) belongs to context Global while the Pi and N belongs to System. So ...
5
votes
2answers
234 views

Unexpected interpretation of a variable with subscripts

I am new to Mathematica and encounter the following problem. Define two variables g = 1 and Subscript[g, 1]= 1. If we execute $...
5
votes
2answers
504 views

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

How can one write f /@ # & /@ # & /@ # & /@ # & /@ # & /@ # & /@ # & /@ matrix in one line with arbitrary level and without using ...
5
votes
2answers
257 views

Associativity of `/@` [duplicate]

Why are the following not equivalent: Map[Line, Map[(Print[#]; #) &, {{{2, 1}, {1, 1}}, {{-2, 1}, {3, 1}}}]] which produces ...
5
votes
2answers
120 views

Merge numbers to a new number and find digit on position \(n\)

I'm trying to construct a 'Mathematica solution' for the following 'puzzle' The natural numbers are placed in a row; 12345678910111213... What digit is the 10,000th digit? I don't know ...
5
votes
3answers
150 views

Unexpected behavior of MapAt

For the description, I have a simplified problem like the following: MapAt[f[1, #1], {a, b, c, d}, #2] & @@@ {{1, 2}, {3, 4}} will give ...
5
votes
3answers
238 views

FillingStyle->{None,Automatic} gives unexpected results?

Plot[1 - x^2, {x, -1.5, 1.5}, Filling -> Axis, FillingStyle -> {None, Automatic}] produces an outcomes I find unexpected: In contrast, ...
5
votes
2answers
98 views

Grouping/precedence for “/@” operator

This returns errors: {#[[1]],#[[3]]} & /@ {#[[1]],#[[2]],#[[3]]} & /@ {{"A","B","C"},{1,2,3}} Part::partd: Part specification A[[1]] is longer than ...
5
votes
1answer
139 views

Dot when used in a pattern becomes Times… Why?

In[1] := Hold[a.b] // FullForm Out[1] := Hold[Dot[a,b]] So far so good. ...
5
votes
1answer
162 views

Counting a part of the speech in a sentence

I want to count a number of nouns in a sentence. For that, I'm using TextStructere but I don't know how to get tags of each word.
5
votes
2answers
142 views

How to construct infix operator with usual behavior?

I am trying to define my own infix operator and having problems with strung-together evaluation. The code below is a simple example. What I would like is to have the operator treated associatively, ...
5
votes
2answers
431 views

Why this syntax for renaming columns in datasets?

Form the documentation of Dataset: ...
5
votes
2answers
2k views

Scalar product operator of complex vectors

What is the scalar product operator for complex vectors (or matrices) in Mathematica? The usual $Dot[]$ doesn't work. E.g. here is what the Mathematica gives $$\{1,0\}.\{I,0\}=I$$ but the answer ...
5
votes
1answer
289 views

Why does the Front End group backslashes into pairs?

What is \\ for? Help finds nothing on it. An odd number of backslashes greater than one are grouped by two and the last one is displayed with a different color. ...
5
votes
1answer
69 views

How to create a 2D table with varying step?

I would like to produce a table with 2 coordinates, where a step for one coordinate depends on the value of another one. I tried to do this in the following way: ...