Skip to content

Round trip and pickling for arb and acb - #439

Merged
oscarbenjamin merged 4 commits into
flintlib:mainfrom
oscarbenjamin:pr_arb_roundtrip
Oct 25, 2026
Merged

oscarbenjamin merged 4 commits into
flintlib:mainfrom
oscarbenjamin:pr_arb_roundtrip

Conversation

@oscarbenjamin

Copy link
Copy Markdown
Collaborator

Fixes gh-438

@oscarbenjamin
oscarbenjamin merged commit 3333d2f into flintlib:main Oct 25, 2026
199 of 204 checks passed
@oscarbenjamin
oscarbenjamin deleted the pr_arb_roundtrip branch October 25, 2026 01:33
@deftasparagusanaconda

deftasparagusanaconda commented Nov 1, 2026 •

Copy link
Copy Markdown

is this a bug?

from pickle import loads, dumps
from flint import arb

original = arb(2).sqrt()
roundtrip = loads(dumps(original))

print(original)
print(roundtrip)
print(original == roundtrip) # False
print(original.mid() == roundtrip.mid()) # True
print(original.rad() == roundtrip.rad()) # True

expected behaviour: original == roundtrip returns True


python: 3.15.2t
python-flint: up to date with 3333d2f

@oscarbenjamin

Copy link
Copy Markdown
Collaborator Author

That's expected behaviour for arb:

In [1]: from flint import arb

In [2]: a1 = arb(2).sqrt()

In [3]: a2 = arb(2).sqrt()

In [4]: a1
Out[4]: [1.41421356237309 +/- 5.15e-15]

In [5]: a2
Out[5]: [1.41421356237309 +/- 5.15e-15]

In [6]: a1 == a2
Out[6]: False

Conceptually an arb represents an exact number that is only known approximately. Here a1 and a2 are each known to be in the same interval but we don't know if they represent the same number in that interval. Perhaps == should give None rather than False to make this clearer but it is not supposed to be True.

@deftasparagusanaconda

Copy link
Copy Markdown

i think instead of == returning None (which would violate python interfaces), the class shouldn't have an __eq__ method at all

@oscarbenjamin

Copy link
Copy Markdown
Collaborator Author

It isn't possible to to not have an __eq__ method because if a class does not define __eq__ then it inherits it from object which has its own quirks:

In [14]: class A: pass

In [15]: a1 = A()

In [16]: a2 = A()

In [17]: a1 == a1
Out[17]: True

In [18]: a1 == a2
Out[18]: False

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

arb.repr() fails to roundtrip

2 participants