1
$\begingroup$

Considering mathematica code

range = Range[4 10^6];
Position[Mod[10^5 NestList[Mod[ 10^6 #, 1355297] &, 10^6,Length[#] - 1] - (54 # + 46), 1355297], 0] &[range]
(* {{2331259}, {3776127}} *)

which works as expected I intend (performance issue)to compile the code. All the functions involved are compilable as

Compile`CompilerFunctions[] // Sort

shows but the approach

fu = Compile[{{range, _Integer, 1}},Position[Mod[10^5 NestList[Mod[ 10^6    range, 1355297] &, 10^6,Length[range] - 1] - (54 range + 46), 1355297], 0]]
(*Compile::cset: Variable Compile`Variable$630 of type 
{_Integer,0}    encountered in assignment of type {_Integer,1}. *)

doesn't work. Checking the compiled code

Needs["CompiledFunctionTools`"]
CompilePrint[fu]

I recognize, that NestList doesn't appear!!

My questions: Is NestList compilable ? Is there a workaround to make the compile-code run? Thanks

$\endgroup$
5
$\begingroup$

Don't you want this?:

fu = Compile[{{range, _Integer, 1}}, 
  Position[Mod[
    10^5 NestList[
       Mod[10^6 #, 1355297] &,  (* N.B. range -> # *)
       10^6, 
       Length[range] - 1] - (54 range + 46), 1355297], 0]]
$\endgroup$
  • $\begingroup$ Yes , thank you! Silly mistake... $\endgroup$ – Ulrich Neumann Feb 13 '18 at 14:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.