10
$\begingroup$

I was reading this question and it wanted to know how to FunctionCompile this:

Function[x,
 If[IntegerQ @ Sqrt[80892036 + 17994 x (1 + x) (-5995 + 5998 x)], x, 
  Nothing] /@ Range[6694300, 31072325]

I don't know much about FunctionCompile, if it can handle Nothing, if bags work for within them, and if so what Types would they be?

This obviously won’t work, but is a jumping off point:

na = NumericArray[Range[6694300, 31072325], "UnsignedInteger32"];

doit = FunctionCompile[
   Function[{Typed[arg, 
      TypeSpecifier["NumericArray"]["UnsignedInteger32", 1]]},
    Module[{
      f = 
       Typed[Function[Typed[x, "UnsignedInteger32"], 
         Sqrt[80892036 + 17994 x (1 + x) (-5995 + 5998 x)]], 
        "UnsignedInteger32" -> "Real64"];
      iq = 
       Typed[KernelFunction[IntegerQ[f[#]] &], {"Real64"} -> 
         "Boolean"]},
     If[iq@#, #, Nothing] & /@ arg
     ]]];
doit[na]
$\endgroup$
  • $\begingroup$ What is your question here? $\endgroup$ – MarcoB Jan 11 at 16:51
  • 1
    $\begingroup$ How to FunctionCompile the given Function. $\endgroup$ – M.R. Jan 13 at 16:53
  • 1
    $\begingroup$ @MarcoB and in doing so give an example of how to handle the things involved: Nothing, lists that grow to unknown lengths, bags, ... $\endgroup$ – M.R. Jan 13 at 17:21

Your Answer

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

Browse other questions tagged or ask your own question.