# How to use Bags in FunctionCompile?

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]

• What is your question here? Jan 11 '20 at 16:51
• How to FunctionCompile the given Function.
– M.R.
Jan 13 '20 at 16:53
• @MarcoB and in doing so give an example of how to handle the things involved: Nothing, lists that grow to unknown lengths, bags, ...
– M.R.
Jan 13 '20 at 17:21
• I think this will be difficult to do with FunctionCompile in a way that gives you speedup benefits. The expression 80892036 + 17994 x (1 + x) (-5995 + 5998 x) grows quickly so the result can not be stored in machine integers. Which means that even the function compiles and works fast for small inputs, it will be slower when it needs bignum integers. Jan 19 at 15:38
• I've asked the compiler developers and in the next version of WL there will likely be 128-bit integer support. They also gave me sample code which runs the first input in less than a second (versus ~2 hours in a normal WL evaluation). If you @M.R. are interested in seeing this work, please consider signing up for the prerelease program. Jan 19 at 19:52