I have a problem where I am trying to find the relationship between parts and the parts that make them up. Like if a boiler is made with two side plates and one bottom plate, and the side plates have five bolts and the bottom four, than a tractor has $2*5 +1*4 = 14$ bolts. Except think 3.5 million parts and possibly ten levels deep.
Anyways, We want to prevent repeating interactions. If engines a and b require boilers we don't want to print out how many bolts are in the boiler twice.
Background out of the way, this is what I came up with. I generated the square roots of the first fifteen primes. My theory is that a linear combination of integers from one to 3.5 million multiplied by these will form an orthoginal set.
I set up the structure like a tree, repeated parts and all.
Then I go down to the deepest level. Say the connection between part 1 and part 5. My hash fuction between the two is the part number of the lower level times the first prime, so $1*\sqrt2$.
each level I go up I sum the hash functions for the children with the current lowest part number multiplied with the Nth prime, where N is the highest N of all its children plus one.
So $H(3, 7) = 7 * \sqrt5+H(7, 11)+H(7,5)+H(7, 2)$
with $\sqrt5$ being the 3rd prime, and $H(7, 2)$ having a "depth" of 2
The way that you compute the connection between parts not directly connected is the sum of the hashes of the connections that contain that part minus the sum of connections from there.
So $H(3, 11) = H(3, 7) - H(7, 11)$
And $H(12, 7) = H(12, 3) - H(3, 7) + H(12, 13) - H(13, 7)$
$= H(12, 3) - H(3, 7) + H(12, 13) - (H(13, 10) - H(10, 7))$
$= H(12, 3) - H(3, 7) + H(12, 13) - H(13, 10) + H(10, 7)$
I calculated all the first degree connections and some higher degree ones.
The question is, does a hash uniquely determine not only a relationship between the two parts, but also where on the tree they are, so that if the indicies are the same and hashes different the numbers should be summed like the total number of bolts above. And if two hash numbers are identical they must be talking about the same two indicies and suggest that they are repeated?


First, a potential easier solution: you already have unique hashes, in the form of your (pairs of, though I'm not sure why you're using pairs exactly) part IDs: why not just use them? While building your output, just keep track of which part IDs you've already run your recursion on and how many bolts they needed, and if you come across a part ID that you've already calculated, just use that value (and don't print the duplicate).
Now, to answer your actual question: yes, in theory, but with implementation issues. Your hashing should never produce exact duplicates: the linear independence of the $\sqrt{p}$ over $\mathbb{Q}$ combined with the fact that a part's highest-$p$ coefficient is exactly its part ID. However you are not working in an infinite-precision setting, so it's possible that you'll have clashes in cases where the theoretical hashes are not exactly equal, but are closer than the precision that you are operating to.