Tag Info

Hot answers tagged

22

I can't take much credit for this answer--I hadn't even got version 10.2 installed until J. M. commented to me that these functions could be written efficiently in terms of the Hamming weight function. But, it is understandable that he doesn't want to write an answer using a smartphone. The definition of the built-in ThueMorse is: ThueMorse[n_Integer] := ...


7

Not very efficient, but you may find it useful for some experiments. I perused the code from the link you provided (kuba's), although there are better alternatives in the answers. ClearAll[spiral, genTri, mp]; spiral[n_?OddQ] := Nest[ With[{d = Length@#, l = #[[-1, -1]]}, Composition[ Insert[#, l + 3 d + 2 + Range[d + 2], -1] &, ...


7

Here's another perspective for you. cf[x_] := ColorData[{"DeepSeaColors", {2, 0}}][Mod[Sqrt[8 x + 1] + 1, 2]]; Graphics[{PointSize[Small], cf[#], Point[ulamCoords[#]]} & /@ Range[1024], Background -> Black] This color function allows us to (visually) trace "triangularity level curves" of a sort, where the brightest points are triangular ...


4

As this is special-functions question, I feel justified in using a bit of heavy artillery. Here goes nothing... In effect, what the OP seems to want to do is to evaluate $$\sum_{n=1}^\infty \frac{(q^{n+1};q)_\infty}{(q^n;q)_\infty} q^{n-1}$$ where $(a;q)_n$ is the $q$-Pochhammer symbol by approximating it with its partial sums. However, there is a more ...


4

With modest preprocessing we get a factor of 9 or so for large inputs just by chunking into 12 bit pieces and using a compiled lookup function. m = 12; Timing[tmLookup = Table[Mod[Total[IntegerDigits[j, 2]], 2], {j, 0, 2^m - 1}];] (* Out[49]= {0.00157, Null} *) Some of the option settings are probably overkill. tmLookupCSmall = With[{tmtable = ...


3

Just to separate this from a package-based answer. In Mathematica 10.2, you can now do this with the built-in function SmithDecomposition. So using the same matrix from my previous answer: mat = {{1, 2, 3}, {-2, 3, 1}, {3, 2, 1}}; MatrixForm /@ SmithDecomposition[mat] Where the second element is the Smith normal form.


1

A slightly different way: tripixels[n_] := Module[{g, coords, triQ}, g = PathGraph[Range[n^2]]; triQ = Function[x, IntegerQ@Sqrt[8 x + 1]]; coords = VertexCoordinates /. AbsoluteOptions[g, VertexCoordinates]; Partition[ Sort[Thread[coords -> Boole[triQ /@ Range[n^2]]]][[All, 2]], n] // Transpose] ArrayPlot[tripixels[1000], DataReversed ...


1

Frankly, I'd write this function differently, at least if B is small: ClearAll[pollard]; Module[{p}, p[n_, i_] := GCD[PowerMod[2, i!, n] - 1, n]; pollard[n_, B_] := p[n, #] & /@ Select[Range[2, B], 1 < p[n, #] < n &, 1]] I am not entirely sure what your function is intended to return, and how you define "most B iterations" (since your ...



Only top voted, non community-wiki answers of a minimum length are eligible