Questions tagged [core-language]
Questions on the basic structure of the Mathematica language (Wolfram language) including atomic data types, syntax etc
602
questions
2
votes
1
answer
119
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
59
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 ...
3
votes
3
answers
135
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
86
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 ...
9
votes
1
answer
183
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
435
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
60
views
Random replacement in array
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
54
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 ...
9
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
141
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
140
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
93
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
55
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
83
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
90
views
Problem with RecurrenceTable of two variables
Let we have simple recursive function:
...
5
votes
3
answers
157
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
2
answers
81
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
41
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
125
views
DuplicateFreeQ VS UnsameQ
What is the exact difference between
DuplicateFreeQ @ arr and UnsameQ @@ arr ?
I checked on many examples and found no ...
4
votes
3
answers
241
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,
...
9
votes
2
answers
509
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
501
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
99
views
BlankNullSequence (___) when input variable is Null
f[x___] := Plus[x, -x]
f[Null] gives output as 0
f[] ...
4
votes
5
answers
497
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
81
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 ...
6
votes
1
answer
142
views
Want Map function to apply over sum of terms but not product
For a given function F, if I use Map[F,a+b+c d], Mathematica returns, as desired:
F[a]+F[b]+F[c d] ;
However, for ...
1
vote
0
answers
35
views
Monitor inside core function
I like DistanceMatrix: its performance is surprisingly high, even for a big data.
However, for a huge arrays and custom ...
0
votes
0
answers
55
views
MinimalBy with argument and value
I need to find element of some list arr which is minimal by some function f.
But I need to get result in form ...
0
votes
0
answers
31
views
MapApply not converting numbers as strings to numbers
I have large vectors that were imported and came in as strings. I try to convert these to numbers using MapApply of ToExpression (and the "@@@" form of this). There must be some subtle ...
1
vote
0
answers
33
views
Can symbolic sums of indexed arrays be simplified?
As a simple example, is it possible to simplify say
Sum[Indexed[x, i], {i, 1, n}] == Indexed[x, n] + Sum[Indexed[x, i], {i, 1, n - 1}]
If not, please explain ...
4
votes
1
answer
104
views
Function[0], Function[,0], and Function[{},0]: Is there any inherent distinction in the "academic" sense?
Note that Function[,0] is by default interpreted as Function[Null,0].
The following three calls all give ...
3
votes
2
answers
84
views
Problem with Association in DynamicModule
How can I understand the success of the first append but the failure of the second, here? (Mma 13.3.) Is there a ready work around?
...
-6
votes
1
answer
72
views
How to test if the input is a positive fraction?
I would like to check if a fraction is positive. The difficulty arises when there are symbols. I would like to make the assumption that all symbols, variables, and indeterminates are positive real ...
-2
votes
1
answer
54
views
How can I list the heads of an expression?
How can I check that a fraction contains only multiplication and power? I would like to check if it contains only the heads of Power and Times. I am wondering how to get a list of heads for a fraction....
5
votes
1
answer
129
views
Condition inside pure function
Why condition /; not work inside pure function?
Suppose we have:
...
1
vote
0
answers
53
views
Why do rules not default to local scope? [closed]
Consider the following:
80 //. a_?EvenQ -> a/2
a = 3
80 //. a_?EvenQ -> a/2
which outputs:
5
3
3/2
I think I understand ...
6
votes
0
answers
99
views
Using Cases to select expressions from a list
I am using v12.2.0 on Win7-x64. I want to use Cases to select the Times and Plus cases from ...
2
votes
1
answer
124
views
Why does using a variable name as pattern name determine its context?
Checking the context of a fresh variable inside Begin-End, it gives the enclosing context.
...
11
votes
2
answers
1k
views
What is a function?
Regarding:
Map[#[{2, b}] &, {Reverse}]
The above works, but it makes my head spin. The documentation for Map says that the ...
2
votes
0
answers
79
views
With[{a=1},{b=a},b] in 13.2 does evaluate to 1 [duplicate]
This isn't documented, and the front end highlights the second comma and third argument in red, but it's used in DownValues[Once][[3]] and is very convenient. Anyone know more?
1
vote
1
answer
130
views
How to convert a function with named arguments to a pure function?
A function is defined with named arguments. How can this function be converted to a pure function that uses slots (#). As a simple example, how can the following:
<...
1
vote
1
answer
119
views
Where does the result of thing["Properties"] come from?
Question
I'll focus on the example
stream=AudioStream@First@$AudioInputDevices
I can do stream@"Properties" to get a ...
5
votes
2
answers
241
views
Do not understand evaluation order of ReplaceAll [duplicate]
{x, x^2, Length@x, Subsets[x]} /. x -> {1, 2, 3}
(* {{1, 2, 3}, {1, 4, 9}, 0, {{}, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}}} *)
with error
What ...
6
votes
4
answers
330
views
Delete first case
How to delete just first occurrence of given value from a list?
Without sorting etc.
Something like this:
...
5
votes
1
answer
76
views
Assumptions about indexed variables
I am interested in the most efficient way to impose assumptions on indexed variables. In the following stylized problem, the following code
...
0
votes
1
answer
77
views
Using Unevaluated to get a list of symbol names
The official documentation of Unevaluated contains the following example:
...
5
votes
2
answers
209
views
Slots inside nested pure functions
I'd like /@ instead of Table or Map.
But let we have it inside pure function:
...
1
vote
1
answer
59
views
Get FullForm content
For this challenge I need to get FullForm as array, string or nested function.
Especially for number expressions.
The best I have achieved is:
...
2
votes
2
answers
243
views
How to implement Newton's Identities
I need to produce identities related to Newton's Identities of arbitrary order. More specifically, I need the identities in the following image for an arbitrary n:
What I can't quite wrap my head ...
4
votes
1
answer
194
views
How to enforce/specify the type of a module local variables similar to the module arguments?
In Mathematica, one can specify the type of a module argument by giving the Head name. I am using type loosely here since Mathematica does not have types. But this does basically the same thing. So ...