This code “works”, in the sense that it compiles and runs. It’s just working very hard!
Compiling with profiling:
ghc Main.hs -prof -fprof-auto
./Main +RTS -p
I get
Wed Mar 15 08:07 2023 Time and Allocation Profiling Report (Final)
Main +RTS -p -RTS
total time = 33.85 secs (33853 ticks @ 1000 us, 1 processor)
total alloc = 66,183,779,816 bytes (excludes profiling overheads)
COST CENTRE MODULE SRC %time %alloc
isInteger Main Main.hs:2:1-44 62.8 54.7
prf.x Main Main.hs:5:37-73 31.8 36.0
prf Main Main.hs:5:1-78 5.4 9.3
individual inherited
COST CENTRE MODULE SRC no. entries %time %alloc %time %alloc
MAIN MAIN <built-in> 128 0 0.0 0.0 100.0 100.0
CAF Main <entire-module> 255 0 0.0 0.0 100.0 100.0
main Main Main.hs:(7,1)-(9,19) 256 1 0.0 0.0 100.0 100.0
prf Main Main.hs:5:1-78 258 1 5.4 9.3 100.0 100.0
prf.x Main Main.hs:5:37-73 259 85145795 31.8 36.0 94.6 90.7
isInteger Main Main.hs:2:1-44 260 85145795 62.8 54.7 62.8 54.7
CAF GHC.Conc.Signal <entire-module> 250 0 0.0 0.0 0.0 0.0
CAF GHC.IO.Encoding <entire-module> 237 0 0.0 0.0 0.0 0.0
CAF GHC.IO.Encoding.Iconv <entire-module> 235 0 0.0 0.0 0.0 0.0
CAF GHC.IO.Exception <entire-module> 229 0 0.0 0.0 0.0 0.0
CAF GHC.IO.Handle.FD <entire-module> 227 0 0.0 0.0 0.0 0.0
CAF GHC.TopHandler <entire-module> 205 0 0.0 0.0 0.0 0.0
main Main Main.hs:(7,1)-(9,19) 257 0 0.0 0.0 0.0 0.0
Note that it tooks ~30 s for my computer to go through j
= 0, 1, …, 85 145 795. I stopped the program manually after that.
Do you have a sense of what values of j
might satisfy isInteger ((j * j + 1) / (j + 1))
? Could it be that there’s some math trick which would allow you to skip over some values of j
?