Skip to main content

Questions tagged [core-language]

Questions on the basic structure of the Mathematica language (Wolfram language) including atomic data types, syntax etc

Filter by
Sorted by
Tagged with
2 votes
2 answers
46 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: ...
lesobrod's user avatar
  • 1,719
1 vote
0 answers
52 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 ...
lesobrod's user avatar
  • 1,719
0 votes
1 answer
50 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 ...
lesobrod's user avatar
  • 1,719
7 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?
xzczd's user avatar
  • 66.8k
2 votes
2 answers
137 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 ...
lesobrod's user avatar
  • 1,719
2 votes
2 answers
63 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 ...
Tapiocaweasel's user avatar
2 votes
3 answers
87 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 ...
J Tyson's user avatar
  • 132
0 votes
0 answers
23 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 ...
lesobrod's user avatar
  • 1,719
4 votes
1 answer
79 views

PatternTest in Function

This is probably trivial and already asked but I did not find it. How to use PatternTest inside Function (...
azerbajdzan's user avatar
  • 18.9k
2 votes
1 answer
78 views

Problem with RecurrenceTable of two variables

Let we have simple recursive function: ...
lesobrod's user avatar
  • 1,719
5 votes
3 answers
155 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 ...
three777's user avatar
  • 188
0 votes
2 answers
64 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 ...
lesobrod's user avatar
  • 1,719
3 votes
2 answers
40 views

Strange behavior of MinimalBy [duplicate]

data = {{1, 2}, {2, 2}, {3, 3}}; MinimalBy[data, Norm@# &] Output: {{2, 2}} When applying numerically : ...
lesobrod's user avatar
  • 1,719
7 votes
1 answer
123 views

DuplicateFreeQ VS UnsameQ

What is the exact difference between DuplicateFreeQ @ arr and UnsameQ @@ arr ? I checked on many examples and found no ...
lesobrod's user avatar
  • 1,719
4 votes
3 answers
237 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, ...
codebpr's user avatar
  • 2,253
9 votes
2 answers
501 views

What's the difference between With and ReplaceAll?

A wolfram Tutorial mentions that ReplaceAll and With are similar: The way ...
ions me's user avatar
  • 991
7 votes
1 answer
499 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 ...
internet's user avatar
  • 793
3 votes
1 answer
93 views

BlankNullSequence (___) when input variable is Null

f[x___] := Plus[x, -x] f[Null] gives output as 0 f[] ...
metroidman's user avatar
4 votes
5 answers
494 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! ...
lesobrod's user avatar
  • 1,719
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 ...
lesobrod's user avatar
  • 1,719
6 votes
1 answer
139 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 ...
user160385's user avatar
1 vote
0 answers
34 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 ...
lesobrod's user avatar
  • 1,719
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 ...
lesobrod's user avatar
  • 1,719
0 votes
0 answers
28 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 ...
Mark R's user avatar
  • 1,589
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 ...
Alan's user avatar
  • 13.7k
4 votes
1 answer
103 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 ...
user688486's user avatar
3 votes
2 answers
83 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? ...
Alan's user avatar
  • 13.7k
-6 votes
1 answer
70 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 ...
Peter Burbery's user avatar
-2 votes
1 answer
53 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....
Peter Burbery's user avatar
5 votes
1 answer
117 views

Condition inside pure function

Why condition /; not work inside pure function? Suppose we have: ...
lesobrod's user avatar
  • 1,719
1 vote
0 answers
50 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 ...
Jonah's user avatar
  • 121
6 votes
0 answers
95 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 ...
Syed's user avatar
  • 55.4k
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. ...
Jineon Baek's user avatar
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 ...
Chris 's user avatar
  • 467
2 votes
0 answers
78 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?
Edward Huff's user avatar
1 vote
1 answer
119 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: <...
feynman's user avatar
  • 229
1 vote
1 answer
110 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 ...
Adam's user avatar
  • 3,956
5 votes
2 answers
236 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 ...
lesobrod's user avatar
  • 1,719
6 votes
4 answers
312 views

Delete first case

How to delete just first occurrence of given value from a list? Without sorting etc. Something like this: ...
lesobrod's user avatar
  • 1,719
5 votes
1 answer
71 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 ...
oyy's user avatar
  • 187
0 votes
1 answer
72 views

Using Unevaluated to get a list of symbol names

The official documentation of Unevaluated contains the following example: ...
Shredderroy's user avatar
  • 5,249
5 votes
2 answers
184 views

Slots inside nested pure functions

I'd like /@ instead of Table or Map. But let we have it inside pure function: ...
lesobrod's user avatar
  • 1,719
1 vote
1 answer
57 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: ...
lesobrod's user avatar
  • 1,719
2 votes
2 answers
237 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 ...
Wynne's user avatar
  • 1,526
4 votes
1 answer
131 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 ...
Nasser's user avatar
  • 145k
1 vote
1 answer
61 views

VEHICLe dataset - aromatic ring counts problem

I was recently exploring the VEHICLe data set and seem to have run into an inconsistency. The dataset is described as, The VEHICLe database, short for Virtual Exploratory heterocyclic library, ...
bhopshang's user avatar
  • 739
3 votes
1 answer
158 views

A workaround needed to overcome the Derivative function anomaly in Mathematica 13

Edits: Additional illustrations are provided for comparison with D[] in Mathematica 12, as clarifying examples, supplemented at the end. An erroneous Derivative ...
ghogoh's user avatar
  • 343
7 votes
2 answers
377 views

Why do some functions require its arguments to be in a list while others accept these as a sequence? [closed]

With Midpoint[{{4, -2}, {2, 5}}], the vectors must be in a list. But with EuclideanDistance[{-2, 2}, {3, -6}], they don't. These ...
cybervigilante's user avatar
1 vote
0 answers
56 views

Clustering related entities using the data from Wikidata

This question starts from Creating a Graph of related entities with the data from Wikidata Compared to the previous question, I have defined a larger starting set, which I am going to enrich with ...
Revious's user avatar
  • 540
5 votes
1 answer
92 views

FindIsomers produces disconnected fragments

I was playing around with FindIsomers and got this strange result, FindIsomers[Molecule["butane"]] output This seems unexpected in the sense that you ...
bhopshang's user avatar
  • 739

1
2 3 4 5
12