Tagged Questions
13
votes
2answers
302 views
Fastest way to measure Hamming distance of integers
I am looking for a fast and robust way to calculate the Hamming distance of integers. The Hamming distance of two integers is the number of matching bits in their binary representations. I expect that ...
12
votes
3answers
475 views
Fastest way to calculate matrix of pairwise distances
It is a very common problem that given a distance function $d(p_1,p_2)$ and a set of points pts, we need to construct a matrix ...
6
votes
2answers
202 views
CorrelationFunction for vectors
Mathematica 9 has a new CorrelationFunction. Sadly the joy does not last long, as I can't get it to work with vectors. I would like to make a velocity correlation ...
8
votes
4answers
290 views
Passing large list by reference
I have the following problem: I would like to control evaluation of a variable that points to a list. For example, frequently in the code I have functions of the form that are supposed to work on ...
6
votes
2answers
360 views
Easier program for period of Fibonacci sequence modulo p
For a little project I need to calculate the period of a Fibonacci sequence modulo p, for which p is a prime number. For example, the Fibonacci sequence modulo 19 would be:
$$0, 1, 1, 2, 3, 5, 8, 13, ...
18
votes
4answers
494 views
Efficient circular buffer?
I wish to create an efficient circular buffer. That is, I wish to keep a fixed length list while appending a new value and dropping the oldest, repeatedly.
As we know lists in Mathematica are ...
10
votes
4answers
489 views
How to write this without For loop
Suppose I have a few lists of numbers and want to exponentiate element-wise, then sum up everything into a polynomial.
For example, if I have
...
0
votes
1answer
189 views
How can I improve my code with efficient mathematica built-in functions?
I have written a module for my assignment like below.
V[n + 1] = rk[x[n], y[n] ,z[n], V[n]];
vs = V[n].V[n+1];
V[n + 1] =
I want to modify it with efficient ...
4
votes
2answers
223 views
How can I find the lines that go through?
I have a 80 x 80 x 50 dataset. From this dataset, I get some curves. These curves are randomly seeded, by which I mean that their starting points have been chosen randomly.
Below, you can find an ...
11
votes
4answers
410 views
Can you recommend an efficient method for finding the least integer satisfying my inequality?
I tried find the minimum make
$\frac{1}{2}+\frac{1}{2+\sqrt{2}}+\frac{1}{3
+\sqrt{3}}+...+\frac{1}{n+\sqrt{n}}>15$
Following code is so slow when I use condition
...
2
votes
1answer
113 views
Computing closest set of points to each point in large set — running out of memory (arrays unpacking)
I have a large set of points in 3D and I'm trying to identify all the points that lie within a certain distance of each point. Then using this data store the vector between the pairs of points.
I ...
4
votes
1answer
192 views
speed up iteration with conditionals plus optimize memory usage
Given list1 and list2 whose elements are vectors of a certain (fixed) dimension, I am interested in the behaviour of a scalar ...
16
votes
3answers
607 views
Reading periodic elements from a large file
I have a large binary data file (big endian) with 100+ million "rows" of 11 elements, combination of floats and integers.
This is the format:
...
6
votes
2answers
306 views
Web scraping and multi-threading in Mathematica
I'm working in some web scraping using Mathematica, and today, to speed-up the process, I used bash commands (xargs with parallel options with curl and wget) using ...
33
votes
2answers
843 views
Performance tuning for game solving (peg solitaire | senku)
There's a game I saw at a friend's yesterday, that I often see at people's homes, but never for enough time to think on it too hard. It's called peg solitaire (thanks @R.M).
So I came home and I ...
9
votes
3answers
365 views
Improve speed for calculating a recursive sequence
I want to calculate following recursive sequence:
$\alpha_{0}=0,\\
\cos(\alpha_{i})=\cos(\alpha_{i-1})\cdot\cos(\beta_{i})+\sin(\alpha_{i-1})\cdot\sin(\beta_{i})\cdot\cos(\gamma_{i}).$
In ...
7
votes
2answers
156 views
Speed up Fourier for Booleans
I'm calculating a bit of the power spectrum of a two color cellular automaton using:
...
8
votes
1answer
375 views
GeoDirection and GeoDistance Memory Leaks: How to Recover the Memory?
The functions GeoDirection and GeoDistance have memory leaks. To see this, run the example functions below and watch as the Physical Memory Available in the Windows Task Manager, Performance tab, ...
29
votes
2answers
859 views
What is a Mathematica packed array?
A simple sounding question with a few sub questions:
What is the difference between unpacked vs packed array?
Are packed arrays more space efficent, how much so?
Are packed arrays more time ...
6
votes
2answers
332 views
Very long Refine/Solve batch run - is my code broken, or just complicated?
So I'm trying to run some Mathematica code in batch mode from my university cluster. Specifically, I'm trying to find the equilibria of a system of ordinary differential equations. Inspired by the ...
9
votes
3answers
381 views
How can I speed up SQL queries in Mathematica?
I have an application that queries a MySQL database many times for data. At the moment, Mathematica and MySQL are running on the same box and yet it takes over 1.6 seconds for the query to run and ...
15
votes
4answers
269 views
Function that caches when it returns unevaluated
How would you go about implementing a function that caches not the result but the fact that it didn't match a pattern? So that it doesn't waste time recomputing a complex time-consuming pattern ...

