Skip to content

Improve hashing of function and pseudocode objects#4254

Open
d-torrance wants to merge 4 commits intoMacaulay2:developmentfrom
d-torrance:hash-function
Open

Improve hashing of function and pseudocode objects#4254
d-torrance wants to merge 4 commits intoMacaulay2:developmentfrom
d-torrance:hash-function

Conversation

@d-torrance
Copy link
Copy Markdown
Member

We add hash codes to all members of the Code union in the interpreter, which we then use to compute proper hashes of function and pseudocode objects.

Before

i1 : hash (() -> print "Hello, world!")

o1 = 6474929089309016109

i2 : hash (() -> print "Hello, world!")

o2 = 14328623249302651656

After

i1 : hash(() -> print "Hello, world!")

o1 = 9105046539553097294

i2 : hash(() -> print "Hello, world!")

o2 = 9105046539553097294

Closes: #667

AI Disclosure

This was almost entirely vibe-coded by Claude Code, but with serious hand-holding.

@pzinn
Copy link
Copy Markdown
Contributor

pzinn commented May 4, 2026

Are you saying Claude Code can program in "d", despite the lack of any meaningful documentation?

@d-torrance
Copy link
Copy Markdown
Member Author

d-torrance commented May 4, 2026

Yup! It was basically just copying and modifying the hashing function for the Expr union, but it did a decent job!

@pzinn
Copy link
Copy Markdown
Contributor

pzinn commented May 4, 2026

Interesting. I for one would be happy to never have to write another line of "d".
BTW:
Maybe that's something you guys can talk about at the upcoming M2 meeting: how to get Claude Code to entirely rewrite the whole d code into a more modern language...

Comment thread M2/Macaulay2/d/basic.d
is x:CCcell do hash(x.v)
is x:Sequence do (
-- the numbers here are the same as in binary lookup() in objects.d!!
-- these constants must match the manual hash computations in hashtables.dd
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be feasible to have a single source of truth for all magic numbers?

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.

3 participants