Linked Questions

8
votes
0answers
153 views

Performance of pure function - Best way to define a function?

In general, to define a function, we often use f[x_]. Another way is to use pure function (full form and shorthand). I want to test the performance of these ...
5
votes
1answer
129 views

Compiling a function depending on an external function

Consider the simple case: g[x] := x^3; f[x] := x^2 + g[x]; cf = Compile[{{x, _Real}}, x^2 + g[x]] Evaluating the two functions, Mathematica complains that the ...
14
votes
2answers
526 views

Map vs. Table for index-specific operations on 2D arrays

Many experienced users on this site tend to use Map (and its variants, MapAt, MapIndexed, etc.) rather than Table. When applying the same operation to every element of an array, Map does seem more ...
1
vote
1answer
152 views

Pure functions vs normal functions [duplicate]

I am trying to understand the true difference/usage of a pure function vs a "normal" function. Besides the argument that a pure function is particularly handy when it comes to a single usage, are ...
1
vote
0answers
42 views

Pure OwnValue Functions vs Patterned DownValue Functions [duplicate]

Is it better to use pure Function assigned to symbols as their OwnValues vs function defined by patterns as symbol's ...
12
votes
1answer
543 views

Why use pure functions?

I've now read the official documentation of wolfram on (anonymous) pure functions, and the part about (anonymous) pure functions in the book "mathematica programming intro". I believe I understand ...
10
votes
2answers
489 views

Performance of Nest vs. Do

When I am iterating the logistic function using a pure function, comparing Do and Nest: ...
18
votes
1answer
273 views

Why Function is not identical to `&` in autocompilation?

Here is the example, copied from here square = Function[x, x^2]; square1 = #^2 &; the timing and unpacking status shows ...
2
votes
1answer
400 views

What's the difference between functions and replacement?

I used to thought that calling a function is equal to applying a rule, i.e. applying a rule of f[x_]->sth. is equal to calling a function f with definition f[x_]:=sth. However, given ...
1
vote
1answer
171 views

Change input parameter order in a function

I'm a beginner in Mathematica programming and I'm trying to understand how input parameters work in Mathematica's function. I encountered a problem with the sequence/order of the input parameters of ...
14
votes
2answers
469 views

Bad performance of LengthWhile?

The performance of LengthWhile has been improved in v11.1, now the lengthwhile below is no longer faster. A friend of mine ...
2
votes
1answer
206 views

How to make the code inside Compile conciser without hurting performance?

Consider the following sample: ...
51
votes
2answers
6k views

Scan vs. Map vs. Apply

I cannot understand the difference between Apply, Scan, and Map. I have tried to play with ...
11
votes
4answers
538 views

When should I use Apply (or Function) and when @@ (or &)?

This is a rather general question, which I fail to answer myself. I guess it is mainly due to my insufficient knowledge of the precise terms. If I understand correctly, the following are equivalent: ...
41
votes
4answers
3k views

Compiling more functions that don't call MainEvaluate

I would like to use Compile with functions defined outside Compile. For example if I have the two basic functions ...

15 30 50 per page