I need to speed up a function that uses Binomial
and QuotientRemainder
. I used Compile
, but unfortunately MA resorts to uncompiled evaluation
inxC = Compile[{{n, _Integer}, {k, _Integer}},
Module[{q, ix, ic, iv},
q = k;
ix = 0;
While[q > 0, q = q - Binomial[n, ix]^2; ix++];
ix = ix - 1;
q = q + Binomial[n, ix]^2;
{iv, ic} = QuotientRemainder[q - 1, Binomial[n, ix]];
{ix, iv + 1, ic + 1}
]]
inxC[6, 887]
(*{4, 15, 15}*)
How such a function can be compiled? It seems the optimizer does not know Binomial
and QuotientRemainder
.