Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow copying algebraic closure of finite field #38994

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

user202729
Copy link
Contributor

@user202729 user202729 commented Nov 18, 2024

Fixes #38988

I choose to make the copy return itself, because that's what GF(p) does at the moment anyway, and the field is immutable.

Not sure how much of a hack for me to implement __copy__ and __deepcopy__ instead of __reduce__, but pickling and unpickling at the moment works well anyway (although it returns a different instance)

📝 Checklist

  • The title is concise and informative.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation and checked the documentation preview.

⌛ Dependencies

Copy link

Documentation preview for this PR (built with commit f7e4548; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

@JohnCremona
Copy link
Member

@nbruin ? I don't know about copying

@nbruin
Copy link
Contributor

nbruin commented Nov 24, 2024

I'm not sure what the copying behaviour should be for this structure. Reading the intro of the file, there is a very particular reason why the algebraic closure is not UniqueRepresentation. It is EqualityById, which looks like it's not a problem.
This explains why unpickling produces a new instance ... although

k=GF(5)
kbar=k.algebraic_closure()
GF(5).algebraic_closure() == kbar ##True

suggests that indirectly there IS a preferred copy: the one cached on the corresponding prime field.

The fact that multiple copies can exist would suggest that at least deep_copy should be able to produce a separate copy. Perhaps check with Peter Bruin @pjbruin ?

At the moment, only prime finite fields have algebraic closures. As far as I can see, prime finite fields are not formally UniqueRepresentation, but producing a finite field from GF(p) twice does produce identical results. So similarly, perhaps its algebraic closure is effectively also UniqueRepresentation, in which case we might want to fix pickle and then it wouldn't be controversial for copy to just return self.

More particularly:

sage: k=GF(5)
sage: loads(dumps(k)) is k
True
sage: loads(dumps(kbar)) is kbar ## this is more unequal ...
False
sage: loads(dumps(k)).algebraic_closure() is kbar ## than this
True

and I think the following is actually problematic

sage: kbar.prime_subfield().algebraic_closure() is kbar ##one would expect this
True
sage: kcopy = loads(dumps(kbar))
sage: kcopy.prime_subfield().algebraic_closure() is kcopy ## but that's broken on the copy
False

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

Successfully merging this pull request may close these issues.

algebraic_closure of finite field cannot be copied
3 participants