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.

78 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
8
votes
0answers
102 views

What is the philosophy behind \[Rule] (a.k.a. `->`) for assigning options?

Today I was banging my head against my desk when I realized that the problem I was experiencing was due to having typed ImageSize[Large] instead of ...
8
votes
0answers
232 views

What is a good way to code long, complex, compilable algorithms?

The functional paradigm of the Wolfram Language used in Mathematica is all around wonderful. For intense numerics, Mathematica comes with the ability to Compile ...
8
votes
0answers
128 views

Syntax error in debug mode

Bug introduced in 8.0 and persisting through 10.3.0 It appears that in debug mode, the \[Piecewise] symbol and its associated grid give a syntax error. For a ...
7
votes
0answers
130 views

Design considerations behind `O` (a.k.a. BigOh, a.k.a. Landau Order)

This works without any warnings: O[Log[x]]. This raises a warning: O[x^2]. I have a few questions around this: Why is it a ...
6
votes
0answers
86 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
0answers
355 views

Syntax error for optional pattern, but only in debugger

This expression (explained here by Leonid) evaluates fine unless Evaluation->Debugger is enabled: h[x : (_Integer) : 1] := x Syntax::sntxf: "x:" cannot be ...
4
votes
0answers
164 views

Crossing a symbol like p, similar to HBAR

Is it possible in Mathematica to cross a symbol like p, similar to h-bar, used to denote the Planck constant? Picture in case of font problems: In case of h, we have HBAR, inputted as ESC-hb-ESC ...
4
votes
0answers
107 views

Why does FromDigits transpose its argument (sometimes)?

a = {{1, 2}, {3, 4}, {5, 6}} ; FromDigits /@ Transpose@ a == FromDigits @ a (* True *) The only "strange" syntax I've found in the docs is But it doesn't ...
4
votes
0answers
167 views

“\:”; flagged as syntax error

While answering question 94032, I noticed that Mathematica 10.2 flagged "\:" <> IntegerString[62378, 16, 4] with a red bracket, apparently indicating a ...
4
votes
0answers
213 views

Multiple Constrained Sum

I need to perform a multiple summation, that obeys some conditions. This arises in the study of a statistical physics model. q=Exp[-β]. I would like to ask if ...
4
votes
0answers
153 views

Is there a way to check whether two notebooks share the same variables?

When I code in Mathematica, I often re-use code from old notebooks which fulfilled a specific purpose; for example, one testing for soft matches in strings, or one that identifies outliers on a graph ...
4
votes
0answers
134 views

Proper treatment of roots and powers in Series?

I have the following problem in Mathematica 9 on Linux. I let Mathematica compute the Series expansion: ...
4
votes
0answers
234 views

Syntax colouring when using Symbolize

I need to use symbols with suffixes in order to make my code readable in relation to the Eurocodes. To do this I use Symbolize from the ...
3
votes
0answers
107 views

Different execution behaviour between Wolframcloud and Wolfram Mathematica

When I execute in Wolfram Mathematica: s=0.3; m=5; x=6; it works. But when I execute the same on wolframcloud.com it returns ...
3
votes
0answers
80 views

Use of ContainsAny in EntityClass

The documentation page for EntityClass states that Property values in implicitly defined entity classes may make use of Quantity (and intervals of Quantity) for ...
3
votes
0answers
78 views

Pre-define list of variables to set them in bulk

I understand this is likely tremendously simple, but I cannot work out how to do the following: vars = {b,c} *define variables* vars = {1,2} *set them* Then I ...
3
votes
0answers
125 views

Check an Option without Evaluation

Consider the following: ...
3
votes
0answers
74 views

Java anonymous functions from JLink?

JLink is really great to act on Java objects and access Java static methods. I'm asking myself if there would be a way to have access to a more recent Java syntax that allows anonymous functions, ...
3
votes
0answers
71 views

Why is `Cell` > `Convert To` > `InputForm` not invertible?

I sometimes post code to PhysicsSE, and I usually convert it to InputForm first before posting, in order to avoid pages and pages of ...
3
votes
0answers
129 views

Assign variables from list inside With or Module

I have found that it is possible to assign variables from lists, as follows. r = {1, 2, 3}; {a, b, c} = r; b 2 However, if ...
3
votes
0answers
822 views

NonLinearModelFit with Two Dimensional List of Weights

I'm currently trying to fit Planck's law (B[λ, T]) to measurements, thereby determining Planck's constant. I have a list of triplets containing wavelength, ...
2
votes
0answers
41 views

Why do comments sometimes become Null instead of being removed completely?

Consider the following definition: Piecewise[{{(*comment*)-1, x > 0}, {0, True}}] This is interpreted as intended, with the comment being simply removed, ...
2
votes
0answers
136 views

Model 1D Vlasov Equation

Vlasov Equation The non-relativistic form of the Vlasov equation is given by: $$ \partial_{t} f\left( \mathbf{x}, \mathbf{v}, t \right) + \mathbf{v} \cdot \nabla f\left( \mathbf{x}, \mathbf{v}, t \...
2
votes
0answers
76 views

How do decrease uncertainty of Monte-Carlo integration?

I have some function of many arguments and need to integrate it over the region given by the products of Heaviside theta functions. Namely, I write, say, ...
2
votes
0answers
82 views

Run function as loop over two matrices

I'm still wrapping my head around Mathematica syntax. I have a matrix clustersAll that looks like ...
2
votes
0answers
51 views

How to add sugar for NetEncoder?

I'm tired of the extra level of list in NetEncoder and would like to get rid of it. The obvious thing fails: ...
2
votes
0answers
73 views

What do these parentheses inserted after “Pretty Print” with StandardForm?

Background: I have a list containing individual elements and sublists. tab = {1, 2, 3, a, {4, 1}, {5, 2}} The individual elements are also to be converted into ...
2
votes
0answers
93 views

Piecewise function Syntax error only in debug mode

If I enter the following through mathematica (11.0) through UI $$\begin{cases} 1 &x \geq 0 \\ 0 &True \end{cases}$$ No error is reported. $$\begin{cases} 1 &x \geq 0 \\ 0 &True \end{...
2
votes
0answers
608 views

Conditional statements in intial conditions?

This is potentially a daft question, but I thought I'd ask it; I have some material free to diffuse in a boundary between rn and ro; I've been able to get it working nicely for neumann type boundary ...
1
vote
0answers
47 views

How to figure out syntax for symbols?

I'm new to Mathematica and am having a hard time figuring out how to type certain symbols when I read the documentation. For example, in https://reference.wolfram.com/language/ref/...
1
vote
2answers
29 views

How to get the symbol name of a list element?

Let's say we have a list g with variable d as its element: Clear[g, d] g = {1,2,3,d} Now <...
1
vote
0answers
40 views

Create a set of prime factor numbers given a set of tuples

Given a set $\Omega$ of tuples, for example, Tuples[{Range[0, 4], Range[0, 3], Range[0, 2]}] how can I create all numbers on the form $p_1^{t_1}p_2^{t_2}p_3^{t_3}$ ...
1
vote
0answers
22 views

Manipulating a system of equalities into particular form

newbie here just trying to learn the Mathematica syntax. I have a list of equations, some of them definitions, others relationships, as follows: ...
1
vote
0answers
43 views

Loop over variable sized arrays

I would like to build an Encoder/Decoder to export my Data from Mathematica to Julia. From Mathematica I get arrays of variable dimensions, these arrays contain variables that don't have a fixed value ...
1
vote
0answers
80 views

Difficulty with ExternalEvaluate

I am trying to import a Python function or execute a Python script from inside Mathematica, but the ExternalEvaluate command drives me nuts. I proceed cautiously ...
1
vote
0answers
38 views

Trouble Plotting the maximum values of a function

First off, I apologize if this question is either incredibly obvious, or has been clearly asked and answered before. I've been searching the forum for a while, and the questions and answers thusfar ...
1
vote
0answers
56 views

How to write down existence and uniqueness?

Mathematica has strong commands ForAlland Exists. However, I face difficulties, trying to express "existence and uniqueness" in ...
1
vote
0answers
90 views

NIntegrate and definite Integrate give different results

Suppose the function f[x_,q_]=(15876 Exp[-0.527076 q^2] (x^2-2 x+2) SphericalBesselJ[1,5 q]^2 (q^2-8100 x^2))/(3425*Pi*q^5*x); I need to perform the integration ...
1
vote
0answers
56 views

Strange behavior of NIntegrate

I have some function f[x,y,a], where a is some parameter, defined as piecewise f[x,y,a] = Piecewise[{{g[x,y,a], a<m[x]}, {0, True}}] Here $m$ is some function....
1
vote
0answers
77 views

How to check the positivity of a function depending on many variables?

Suppose we have some complicated function $f(x,y,z,v,u,w)$ with $\{x,y,z,v,u,w\} \in G$; precisely, each variable excepting one is defined in the sub-domain depending on other variables: $w \in G_{1}(...
1
vote
0answers
86 views

Mathematica can't evaluate the function at the point where it is smooth

Suppose the function ...
1
vote
0answers
141 views

Proper syntax for DeleteCases with conditions

List is an array of dimensions {61777, 3}. dist1 & dist2 are RegionDistanceFunctions. Using: ...
1
vote
0answers
41 views

Notation doesn't work if toolbar is used

I am trying the examples on Notation Tutorial In:= a + b\[LongLeftRightArrow]c // FullForm Out:= Plus[a,LongLeftRightArrow[b,c]] Then I try to change ...
1
vote
0answers
64 views

Assigning variables from rules from fit

It became quite clear after running this a few times that my syntax is wrong, but I can't parse out why. Anybody know of a better way to write this? ...
1
vote
0answers
112 views

Decimal alignment in a grid

I tried to find an answer and found quite a few posts on similar topics, but none of them really helped me. Here is a typical example: ...
1
vote
0answers
249 views

How to get user input using FormPage

I am designing a user interface for a word-ladder game using CloudDeploy, CloudExpression and FormPage and I am having trouble with receiving the user input from the form. What I basically need is a ...
1
vote
0answers
94 views

Using Nearest on a 2D List (seeing extra parentheses)

I am working a problem involving colliding particles. I define a list of particle diameters (effectively a bin distribution). I need to know if two particles collide, in what bin diameter should I ...
1
vote
0answers
97 views

Decapitating “explicit” and “implicit” heads

This is a follow up to this question. So far, I named "explicit" heads to those that appear explicitly in the expression. For example, f[x] has an explicit head. I ...
1
vote
0answers
60 views

Matching Root[…] objects with patterns, unexpected hidden argument

I needed to write patterns that could distinguish between arbitrary-function and polynomial forms of Root objects, for example, ...
1
vote
0answers
224 views

Defining an operator

Let s be a positive integer and let DifferenceDelta be this function with step = 1. Define <...