G’day all. For reasons that rhyme with “busy beaver”, I have been using SWI-Prolog for evaluating expressions that can involve integers which are tens of thousands of digits long. So far, with the largest expression evaluating to something a number with 40,000 digits, so good. The infinite precision integer arithmetic in SWI-Prolog works very well for this.
However, recently I have had cause to (attempt to) evaluate the expression 2 to the power of 2X-1 where X is a 33-digit number (plus some significantly smaller expressions). Doing the obvious (but naive) thing of using ‘is’ causes a stack overflow, as it takes more than 1Gb to write this out!
Roughly speaking, it seems integers up to about 2 to the power of 10 million are evaluable, but beyond that memory capacity limits explicit calculation. So it seems the only solution is to use some kind of “lazier” evaluation, in which the exponentials are left unevaluated, but the unproblematic parts (eg 4x3x3+1363+1156) are made explicit.
Does anyone have any pointers on such lazy (semi-symbolic) evaluation? Any tips or pointers would be greatly appreciated.
Echoing some of Jan’s comments on Claude code, I suspect will have to get into agentic code generation by necessity, and probably end up using some symbolic algebra libraries (like Maple or Mathematica). Doing the coding to generate the expression mentioned above was hairy enough!