egglog-python icon indicating copy to clipboard operation
egglog-python copied to clipboard

Better error message when storing too large integer

Open bakerk98 opened this issue 5 months ago • 5 comments

I'm trying to store a big integer in the e-graph, and I've found that BigInt can't store it.

Running on egglog-11.0.0,

When running the code:

with EGraph() as egraph:
    bigint = BigInt(0xfffffffffffffff8)
    egraph.register(bigint)

I get the error: OverflowError: Python int too large to convert to C long

I tried to store the larger int as a PyObject created from the int, and that works.

with EGraph() as egraph:
    pyobj = PyObject(0xfffffffffffffff8)
    egraph.register(pyobj)

I'm not sure if this is user error and maybe I should use a different primitive or if PyObject is the best way to store the number instead, but any help is appreciated. I'd like to be able to use native egglog types if possible.

bakerk98 avatar Aug 13 '25 18:08 bakerk98

Could you try BigInt.from_string? You should be able to store it as a bigint but maybe just not from that constructor

https://github.com/egraphs-good/egglog-python/blob/239a9f566480ca5ff4926a582e24c55f1d6c30a0/python/egglog/builtins.py#L689

saulshanabrook avatar Aug 13 '25 19:08 saulshanabrook

Could you try BigInt.from_string? You should be able to store it as a bigint but maybe just not from that constructor

egglog-python/python/egglog/builtins.py

Line 689 in 239a9f5 def from_string(cls, s: StringLike) -> BigInt: ...

I tried the following on the Python command line and it does run successfully with the egraph being able to register the BigInt:

from egglog import *
with EGraph() as egraph:
     bigint = BigInt.from_string(str(0xfffffffffffffff8))
     egraph.register(bigint)

bakerk98 avatar Aug 29 '25 17:08 bakerk98

This seems to work for me:

(egglog) uv run python
Python 3.13.3 (main, Apr  8 2025, 13:54:08) [Clang 16.0.0 (clang-1600.0.26.6)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Cmd click to launch VS Code Native REPL
>>> from egglog import *
>>> with EGraph() as egraph:
...      bigint = BigInt.from_string(str(0xfffffffffffffff8))
...      egraph.register(bigint)
... 
>>> egraph.extract(bigint)
BigInt.from_string("18446744073709551608")
>>> egraph.extract(bigint + 1)
BigInt.from_string("18446744073709551609")
>>> 

What version of egglog are you running?

saulshanabrook avatar Sep 02 '25 07:09 saulshanabrook

I'm on 11.1.0. I was successfully able to get it to work w/ your from_string suggestion, I appreciate the help! I'm new to GitHub issues and etiquette and I'm not sure if I should close the issue or not, because of the BigInt() constructor not being as robust as the from_string constructor. Maybe a check for an int bigger than what BigInt() can handle could warn the user to use BigInt.from_string()? In any case, thank you for the help, I have been able to get my script working now

bakerk98 avatar Sep 04 '25 19:09 bakerk98

Hey yeah, that's a good idea to give a more helpful error message if you try to create too big of an int. So it sounds good to leave this open.

saulshanabrook avatar Sep 04 '25 20:09 saulshanabrook