# Tagged Questions

Questions on optimizing Mathematica code for higher performance. This may mean faster execution, lower memory usage or both. Not to be confused with mathematical optimization.

128 views

### Is this a reliable method for getting a list of very large primes?

As noted here, both PrimePi and Prime are documented as having their limits somwhere around $10^{15}.$ ...
413 views

### Looping through 3 million elements of a list to 'Set' values is slow

I am looping through the 3 million elements of a time-series (v1, o1) and corresponding values (v2, o2). v1 contains a uniformly increasing timestamp (e.g. 1 to 3,000,000 in increments of 1) o1 ...
232 views

### Finding planetary conjunctions with Mathematica (project-level) [closed]

Summary: What's an efficient way of finding planetary conjuctions with Mathematica using the SPICE kernels, and without using AstronomicalData (which I believe is less efficient). NASA publishes ...
708 views

### Efficient lazy weak compositions

In Mathematica all weak k-compositions of integer n can be generated using permutations of integer partitions: ...
679 views

### How to delete subsets quickly?

I have some data like this: ...
172 views

### My evaluation is taking a lot of time

I was evaluating the roots of a transcendental equation, when I noticed that Mathematica never finishes but stays in the running state. The following is the code that I was using: ...
96 views

### How to speed up the evaluation of a function with a large LeafCount but many repeated sub-functions for use in NIntegrate

General Context Apparently, the memory leak in NIntegrate is unavoidable pre-MMA-10.2. I have some (two-dimensional) numerical integration to do on a complicated ...
262 views

### Modifying the elements of a list according to a given probability

Let list be a list of lists, the elements of which are random integers in the interval $[1,c]$. Each element $i$ has a probability ...
101 views

### How can I speed up this code with 4 variables sum

I have to make a sum over 4 variables. My code is very very slow. I want to know how to speed up this code. This problem is related to but different from one previous problem. Any help or suggestion ...
189 views

Has anyone benchmarked LibraryLink vs MathLink when passing large arrays? Specifically I would like to know how performance compares when using the following to pass and return a large array: ...
123 views

### Importing large number of frames form Video - improved method?

I am trying to work with large numbers of frames from a video (30000+). I see there are a number of answers out there, but I find none of them satisfying - see below for details. I understand from ...
654 views

### Use Compile to improve performance

I've recently discovered Compile as a way to optimize my code. I wrote a program to learn something new about Compile. I have a ...
473 views

### Improving speed of code computing number of nonrepeating partitions

I need to answer the following for a number of parameters: How many ways can the integer $k$ be written as a sum of $n$ different integers ranging from $1$ to $m$? My initial attempt was the ...
256 views

154 views

### CompilationTarget to C takes long compilation time

Consider I have a function, with one version that compiled to the virtual machine and one that compiled to C: ...
134 views

### How to compile procedural program effectively

Consider these four function in different form: ...
61 views

### Adding another looping element with a list

I have code that is looping on to elements and is working shown below ...
109 views

### Replace For-Loop to speed up code

I need to speed up this code ...
119 views

### Composition vs serial assignment, which performs better?

I have a giant block of code that manipulations an expression in many different ways. Currently it looks like ...
289 views

### Visualization of traces of moving objects

An example movie which is made with the listed mathematica code below shows traces of moving objects: https://youtu.be/8jN2uuSHCEg (Melting ...) http://youtu.be/5ET62846C-I (Crystallisation ...) ...
150 views

### Image smoothing with own smoothing function

I have thousands images similar to the following one: This image was produced with the following color table: ...
452 views

### Faster binary Hamming weight for big integers?

While working on an answer to Count the sequences in an array I found that DigitCount was the bottleneck in my code when used as ...
85 views

### Increasing Plot3D speed when plotted function is Eigenvalue

This is probably a really simple fix, but I'm fairly new to Mathematica and am not sure how to do this properly. I know that trying to plot eigenvalues directly can be computationally expensive, so I'...
88 views

### Improve speed of evaluating a sum over four indices

I am trying to implement the Fox-H function with several variables as sum of residues. I have arrived at the following function; ...
51 views

### Why is the Max function so slow when operating on lists of dates?

Example: dates = DateRange[DateObject[], DatePlus[DateObject[], 15]]; First[AbsoluteTiming[Max[dates]]] (* 21.364247 *) As a workaround, ...
137 views

### How to Optimize Solution? (Project Euler #14) [duplicate]

Link to Question: https://projecteuler.net/problem=14 I began by defining the following functions below. ...
907 views

### Finding number of pixels with certain RGB color in an image

I have the following image: To determine the number of black pixels (nBlackPixels) I use: ...
87 views

### Conditional subset generation

I am trying to accomplish the following task: Given a list of coordinates of n points in the plane, I need to find subsets of all points that share the same x-...
38 views

### Numerical minimization hangs at some steps

Let me briefly explain what I observe and cannot really explain by myself. I occasionally use NMinimize to find optimal parameter sets and sometimes it happens that ...
183 views

### Optimize evaluation time for a Quantum Walk simulation

Here's the problem. I'm trying to simulate a noisy Quantum Walk to obtain results similar to these, experimentally obtained. I wrote my code, and I get results which are in accordance to what I ...
565 views

### Solve a trig equation system

Background of the problem In the same plane, P is a fixed point, A,B,C are moving point, PA=a, PB=b, PC=c, find the maximize perimeter of △ABC. let ∠BPC=A, ∠CPA=B, ∠APB=2*Pi-A-B, then the perimeter ...
118 views

### Mathematica is getting slow when repeatedly calling an external program

I found a strange phenomenon that Mathematica is getting slow when I repeatedly called an external program by using ReadList. For example, the following code will display a significant increase of CPU ...