Search Results

Results tagged with Search options user 3246
19 results

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.

Here's a version allowing MaxFilter to work with windows of even length k. It runs MaxFilter with window radius k/2-1, then corrects the output. MovingMaxEven is slower than Andrew's MovingMax, for ex …
answered Aug 27 '15 by KennyColnago
Looks like you are describing the classic problem of counting the number of ways to make change, given coins of value 1, 2, 5, and 10. Generating functions can count the ways. GFCoinPartitions[n_, d …
answered May 16 '18 by KennyColnago
Borrowing the notation of @BobHanlon, the analytic solution to the sum is $x*Sum[10^{c*d},\{d,0,n\}]=x*(10^{c*(n+1)}-1)/(10^c-1)$. Mod $m$, the equation may be written as follows Mod[x,m] * (PowerMo …
answered Feb 23 '16 by KennyColnago
I wrote something similar to @Okkes (+1), but with a general maximum m. TeMgame = Compile[{{m, _Integer}}, Block[{r = Range[m]}, Sign[ First[ Pick[r, UnitStep[Accumulate[RandomInteg …
answered Nov 27 '18 by KennyColnago
There is an analytic solution. For the (n,n,n+1) triangle, the area is Sqrt[(n-1)(3n+1)]/2. Area -> FullSimplify[triangleA[n, n, n + 1]] The valid values of n are Sloane's A103974, the smaller sid …
It seems you are calculating legs of Pythagorean triples, $\{a,b\}$, for $b<a/\sqrt{2}$. I used your isSq function, and added a different test for GCD[a,b]==1. RelativePrimesA[n_Integer] := Block[ …
answered Dec 16 '15 by KennyColnago
I'd like to expand on the answer given by @ChipHurst in the comments. My hope was that one of these approximate tests would be much faster than PrimeQ; however, that was not the case. Perhaps someone …
answered Sep 2 '15 by KennyColnago
Here is a summary of comments (before @ciao's best answer above), with a change in notation. These functions calculate the number of partitions of n into exactly k distinct parts of size at most m. N …
answered Aug 14 '15 by KennyColnago
You can useFindInstanceto specify the number of solutions desired as in FindInstance[{p == x^2 + y^2, x>0, y>0, x>y}, {x, y}, Integers, 1] for large random primep. However, the following Cornacchia …
answered Dec 23 '13 by KennyColnago
The expression I get for the angle angle increment $d$ is (d^2 + 2d (Pi + t) + 2(Pi + t)^2 - 2(Pi + t)(d + Pi + t) Cos[d])/(4 Pi^2) = c^2 For your problem, $c=1$ and $t$ is the start angle of Pi/2. …
answered Jan 20 '14 by KennyColnago
Most PE problems are designed such that any computing system will buckle under the teraflops usually required to brute force a solution. Not so many flops required for this problem, but some experimen …
answered Sep 3 '14 by KennyColnago
Here is a totally different approach based on the fact that successive products forming the generating function are due to multiplication by a binomial $1+t*z^j$. Form a matrix $v$ of zeros with $n+1$ …
answered Aug 16 '15 by KennyColnago
The following is about 50 times faster on my machine. Block[{n = 10^9, CbrtNindex}, CbrtNindex = PrimePi[CubeRoot[n]]; Sum[ PrimePi[n/(Prime[i]*Prime[j])] - j, {i, 1, …
answered Jun 9 '17 by KennyColnago
I found testing for an odd number of divisors can be more efficient sometimes. Try Sum[If[OddQ[DivisorSigma[0,DivisorSigma[2, i]]],i,0],{i,10^5-1}] The following is 2.5 times faster than your metho …
answered Feb 15 '13 by KennyColnago
This code is faster than yours, but unable to solve the full problem. StepGen[v_?VectorQ] := With[{a = Last[v]}, Which[ a == 0, {Flatten[{v, 1}]}, a == 9, {Flat …
answered Oct 27 '17 by KennyColnago

15 30 50 per page