Questions tagged [core-language]
Questions on the basic structure of the Mathematica language (Wolfram language) including atomic data types, syntax etc
626 questions
4
votes
1
answer
226
views
What is the meaning/utility of __[] AKA BlankSequence[][]?
I understand BlankSequence in other contexts, but not this one __h means a pattern of one or more things each of which have head ...
2
votes
1
answer
145
views
Receiving messages quietly
I recently learned about the possibilities of EvaluationData, and would like to analyse for example
the behavior of NIntegrate.
...
1
vote
0
answers
78
views
Are all Atoms created equal? Are there natural categories for atomic elements? [duplicate]
Certain Atoms (by which i mean things for which AtomQ gives True), like Complex, and even ...
3
votes
3
answers
243
views
Versatile way to show points array
I often work with point processes and need simple graphical representation of points.
Processes are investigated in all three dimensions, so arrays of points look like that:
...
8
votes
1
answer
472
views
What's happening when we execute a_b=1?
OK, of course I know that, as mentioned in e.g. here, symbol names in Mathematica cannot contain underscore _ because it's a reserved character, but, what's ...
3
votes
2
answers
281
views
Using List as independent variable of function leads to mysterious output
I was running into a strange error that boils down to this
Myfunction[List_]:= Transpose[{List}]
Test = {1, 2};
Myfunction[Test]
The output is
...
9
votes
2
answers
978
views
Why f[x___] := {x==="To be", x=!="not to be"} is both True for f[]?
The behavior of pattern matching in functions surprised me at the
unexpected behavior of this example
...
4
votes
1
answer
195
views
Head of functions and symbol confusion
I am having trouble understanding how functions work in mathematica. Consider the following.
...
9
votes
2
answers
469
views
How do I display any given expression in postfix notation rather than the standard notation?
My example is
f[f[f[startValue, 1], 2], 3]
which I would like to display as
f[startValue, 1] // f[#, 2]& // f[#, 3]&
...
2
votes
3
answers
468
views
Circular values with Mathematica
In the process of modelling the interaction of charged particles on circle I encountered s.c. circular values calculations.
Consider unit circle and set some point $O$ as starting.
The position of any ...
2
votes
2
answers
150
views
Securing the function definition containing CircleTimes
I'm trying to create a function that handles operators. The only thing left to do is implement the commutator. The minimal working example of func is
...
3
votes
1
answer
172
views
Nearest without element itself
Is there a smart way to get nearest (given number num to given element elem) elements of list,
except element itself?
This works ...
3
votes
3
answers
506
views
Using Out (%) with control flow
I make heavy use of Out in Mathematica's notebook environment. When I get a computation to work, it will often be spread across multiple cells and lines with ...
3
votes
1
answer
97
views
BinCounts: force/block SparseArray output
BinCounts sometimes outputs data as SparseArray, and sometimes Normal.
This does not depend ...
4
votes
0
answers
107
views
Why doesn't NMaximize handle this improper function definition?
First, consider this toy example:
expr = (1 - x)/(x^2 + y^2);
Clear[f];
f[x_?NumericQ, y_?NumericQ] := expr
"Wait, this function definition is wrong! "...
6
votes
2
answers
315
views
How to combine two tabulars into one?
Is there a built-in way to combine two Tabular objects?
i.e. combining them without converting one of the tabular objects into a 'normal' form?
I am currently doing:
...
14
votes
1
answer
346
views
Incompatible change in numerics in V14.2 in Table[], Range[]
There's a change in the outputs of Table[] and Range[] in V14.2 (compared to V14.1) on MacOS ARM when iterating through machine ...
0
votes
2
answers
298
views
Manipulating mathematica expressions without triggering evaluation
I'm curious whether the Mathematica language has some simple way to manipulate expressions without triggering evaluation, at least not without lots of thought and careful debugging.
One method is to ...
0
votes
1
answer
201
views
Modified version of `Table[]` command to make a 1-Dimensional list with several local iteration variables [closed]
Suppose several lists X, Y, Z, ... all have the same length, and f is a function. The command
Table[f[X[[i]], Y[[i]], Z[[i]]], {i, 1, Length[X]}]
is inelegant, but ...
5
votes
5
answers
315
views
Bringing the triangle to a "standard" form
For the study of geometric iterations I needed an algorithm
convert a triangle to some standard form.
It can be described as follows:
Determines the longest side (or any of them)
One of its vertices ...
0
votes
1
answer
154
views
Problems with iterative process
The origin of this question is described here, but there are many details,
distracting from the main topic.
I did not remove the old question so that the interested ones could see the geometrical ...
0
votes
1
answer
131
views
Exploring iterative process with Mathematica
Playing with Geogebra, I became interested in the iterative process of constructing orthic triangles.
For a right-angled triangle, the orthic triangle is degenerate, it’s a segment.
For any other ...
3
votes
0
answers
97
views
$Pre disables downvalue involving Condition?
I notice this when exploring this question, I think it's better to start a new question for it. Consider this toy example:
...
5
votes
1
answer
205
views
Returning a sequence from a function
Let's say I want to take this plot:
r = 3;
DensityPlot[x^2 + y^2, {x, -r, r}, {y, -r, r}]
and make the x and y limits be returned from some function (maybe because ...
6
votes
7
answers
557
views
Loop over array cyclically
Is there any way to make cyclic loop over array without PadLeft,PadRight, ArrayPad?
So ...
2
votes
1
answer
161
views
Central element of matrix
Let we have $(2\cdot r+1) \times (2\cdot r+1)$ matrix mat.
Is there a better way to extract it's central element,
rather than ...
0
votes
0
answers
123
views
Is it safe to modify system functions and distribute?
I am trying to add my definitions to FormulaData and looking through the source files It is clear that one can do that systematically by adding some DownValues to system functions and elements to ...
4
votes
3
answers
277
views
Special case of CellularAutomaton
I’m interested in multi-state CA in a closed 2D space and try to implement them using CellularAutomaton but do not understand how to do it.
The first question is, ...
0
votes
0
answers
133
views
Proving Exact Answers to Logistics Map for 3-Cycles
Seems that I may have found a pair of exact solutions to the logistics map with cycles of period three. However, I’ve run into a bit of a snag in proving it because of some “ambiguities” in the ...
10
votes
1
answer
215
views
List[...] + Association[...], or Association[...] + List[...], when does the order matter?
Values of a list can be added to an association's values like so,
...
3
votes
7
answers
534
views
Extract result of Reap in a natural way no matter if it's empty
This feature has long troubled me, I would like to share it.
If Reap has non-empty set of sown, result looks like:
...
1
vote
0
answers
95
views
Random replacement in array [closed]
In the spirit of this interesting article of Stephen Wolfram I also decided to study some issues related to mutations.
I’m working with simple {0,1} arrays and I’ve ...
0
votes
1
answer
95
views
Specific array filtering - code optimization
I have a nested list where all sublists have a length 2, eg:
{{1,2}, {1,1}, {3,4}, {3,5}, ...}
I need to filter it for two requirements:
Delete all sub-lists ...
11
votes
3
answers
1k
views
Why doesn't b = a; f[a_] := b; f[2] return 2?
As the title asks, why does
b = a;
f[a_] := b;
f[2]
evaluate to a rather than 2?
2
votes
2
answers
194
views
Catch error propagation
I'd like my function to work only for arrays with all positive members, eg:
myf[arr_] := Reverse@arr /; AllTrue[arr, Positive];
So
...
4
votes
5
answers
212
views
How to implement this zip function? zip[g,{f[{a,b}],f[{c,d}]}] to f[{g[{a,c}],g[{b,d}]}]
I have a function that returns an expression in the form f[{a,b}], and I use this function twice and assemble the expression ...
2
votes
3
answers
231
views
Clearing a list of variables: Problems trying to control the order-of-evaluation [duplicate]
I am having trouble controlling the order of evaluation of mathematica expressions.
What I would really like is a general solution, in the form of a pair of functions ...
2
votes
2
answers
101
views
FindClusters with custom DistanceFunction
Let we have an array of integers e.g. Range@365.
Each index has a specific value by which clusterization of integers should be done.
But these values cannot be ...
4
votes
1
answer
132
views
PatternTest in Function
This is probably trivial and already asked but I did not find it.
How to use PatternTest inside Function (...
2
votes
1
answer
125
views
Problem with RecurrenceTable of two variables
Let we have simple recursive function:
...
5
votes
3
answers
239
views
Evaluation control of nested With, If and Integrate
Can you explain the behaviour of the following?
The first With outputs unevaluated If.
So in the second ...
0
votes
3
answers
233
views
Parametric Minimize strongly revisited
Let we try to run this simple code:
Minimize[{Cos[x + a/2], {0 <= x <= \[Pi], 0 < a < 1}}, x]
It doesn't work. But
...
3
votes
2
answers
82
views
Strange behavior of MinimalBy [duplicate]
data = {{1, 2}, {2, 2}, {3, 3}};
MinimalBy[data, Norm@# &]
Output: {{2, 2}}
When applying numerically :
...
7
votes
1
answer
153
views
DuplicateFreeQ VS UnsameQ
What is the exact difference between
DuplicateFreeQ @ arr and UnsameQ @@ arr ?
I checked on many examples and found no ...
5
votes
3
answers
350
views
Converting to a scalar pure function without getting the warning messages
I am using this from the function repository for which I need to convert one of my functions into a unique form. A simple example is like this:
Suppose I have,
...
11
votes
2
answers
571
views
What's the difference between With and ReplaceAll?
A wolfram Tutorial mentions that ReplaceAll and With are similar:
The way ...
7
votes
1
answer
543
views
How does this code work?
I saw this thread and upvoted many answers there.
Below is the answer by kglr (not my most favorite answer there, but it looks fun).
I wonder if anyone could help ...
3
votes
1
answer
135
views
BlankNullSequence (___) when input variable is Null
f[x___] := Plus[x, -x]
f[Null] gives output as 0
f[] ...
4
votes
5
answers
588
views
How to check if multiplication requires carries?
For some purposes I need to know if there are there any carries in the multiplication of two numbers, especially in base-2.
How can we do this in Mathematica?
Thanks
to all, very interesting answers!
...
2
votes
1
answer
131
views
Problem with permutations
For a given binary array like {0, 1, 1, 0,..}, I need to find the shortest permutation, sorting it in standard order ...