# Tag Info

Accepted

### Fast Hankel Function in Mathematica

This is LibraryLink code with compiler and linker options specifically for macos on Apple Silicon. These are the prerequisites to compile and run this successfully: XCode installed along with the ...

### Gravitation simulation and interaction of N (1000) massive objects

And I was somewhat lying in wait for this kind of question... In I have been working on Barnes-Hut-like code for the so-called tangent-point energies in the last couple of years. This is a family of ...

### Speeding up Gaussian sampling

Watching Activity Monitor, I don't think RandomVariate is multithreaded. Luckily random samples from a normal distribution can be compiled. We can exploit ...
• 35.8k
Accepted

### How to speed up Outer[Subtract, vect1,vect2]?

x = RandomReal[1., 10000]; y = RandomReal[1., 10000]; a = Outer[Subtract, x, y]; // RepeatedTiming b = Outer[Plus, x, -y]; // RepeatedTiming a == b {13.667, Null}...
• 901
Accepted

### Speeding up Gaussian sampling

We can achieve noticeable speedup with Intel's MKL random number generator, which leverages hardware accelerated code. m = 1000000; d = 100; Default behavior: <...
• 35.8k

### How can I get samples of f(x) that are roughly evenly spaced?

f[x_] := 1 - 8 x^2 + 8 x^4; You can use the option MeshFunctions -> {ArcLength} and ... 1. Specify the number of equal-arc-...
• 392k

### How can I get samples of f(x) that are roughly evenly spaced?

If we want to the ArcLength approximately equal to the dist = 0.15;, we can define an arclength function ...
• 69.4k

### Speeding up Gaussian sampling

This is my LibraryLink take on this. I use one of the random number generators of the standard library in conjunction with OpenMP. This will only work on Apple Silicon with OpenMP installed via ...
Accepted

### How can I make the following table quickly?

Tabb has the structure: {{a[1, 1], a[1, 2]}, {a[2, 1], a[2, 2]}, {a[3, 1], a[3, 2]}} Now you want to introduce 1 in sublist 1. This can be done with "Riffle&...
• 50k

### How to quickly make a rectangular array of continous 1 and 0 given the start position of 1

Obligatory bare-metal C answer for ultimate speed: ...
• 46.9k
Accepted

### Why does Mathematica take so long to produce this sound?

Creating the audio signal as a vector first allows us to use more efficient ways to sample the function: ...

### How to quickly make a rectangular array of continous 1 and 0 given the start position of 1

This is pretty fast: ...
• 24.7k

### How to quickly make a rectangular array of continous 1 and 0 given the start position of 1

Instead of constructing every column separately, note that each column is contained in a vector of n 0's and n 1's, we only need to pick the corresponding part. For ease, we create the matrix row wise ...
• 50k

### Efficient eigendecomposition of DPR1 matrices

The most important facts about DPR1 matrices of size $n \times n$ are: Their matrix-vector multiplication can be computed in $O(n)$ time instead of $O(n^2)$ as for ordinary dense matrices. By virtue ...

### Why does Mathematica take so long to produce this sound?

The way you have created the function you are forcing MMA to keep evaluating your expression, which although lightweight on its own, is rather heavy when it needs to be repeated for different values ...
• 1,396

### How can I make the following table quickly?

Tabb = Array[a, {3, 2}]; John Taylor (original) ...
• 155k

...
• 46.9k

### How can I make Manipulate faster?

You can use a single Plot function and add the required annotations using the options MeshFunctions, ...
• 392k
Accepted

### Better code for Ramsey partitions

Update 3: We get further speed-up by (1) working with the left parts of partitions with elements $\geq 2$ and appending the results with appropriate number of 1s in ...
• 392k
Accepted

### Why Does Part Work Much Slower on Modified List?

what is the reason for slowdown for the second example? It got unpacked, that is why tabb=RandomReal[{0.0000001,10^5},{10^6,80}]; Developer`PackedArrayQ[tabb] <...
• 142k
Accepted

### Efficient eigendecomposition of DPR1 matrices

Okay, apparently, the root finding for the characteristic polynomial is quite easy. Since the derivative of the characteristic polynomial is easy to compute, too, I try to use Newton's method where ...

### Values of counting functions

You can use SparseArray and Accumulate to assemble a vector cvec so that ...

### How to produce the following table faster?

tl;dr: As always with my post, find the most recent implementation at the bottom of the post. InterpolationFunctions are indeed much less efficient than they could/...

...
• 48.6k
Accepted

### How to quickly make a rectangular array of continous 1 and 0 given the start position of 1

Plain C-style loop with Compile: ...

...
• 901

### Fast pairwise difference

As Henrik has demonstrated in his excellent answer, the good old C compiler interface is still super fast -- the fastest if considering the compiling time. But the new compiler (...
• 27.5k
Accepted

...
• 19k