Edit: Updated “can actually own code” to “can’t actually own code”
Edit: Updated “can actually own code” to “can’t actually own code”
2. Suppose the OP neither took the file nor memorized the code, but had photographic memory and replayed the exact visual scenes during their creation of the utility functions and copied down the code from what they saw in their mind's eye. Would that be theft?
3. Suppose the OP was solving a seemingly novel problem and suddenly remembered how they solved the exact same problem when they were employed by company X. Are they obligated to banish this solution from their mind?
It is copyright infringement, yes. That's why clean room implementations are done by someone who hasn't seen the original source code,
https://en.m.wikipedia.org/wiki/Clean_room_design
For the other examples, it depends but I'm pretty sure a copyright infringement case for either of them wouldn't be immediately thrown out. IANAL but I do know that law is quite fuzzy.
The range of circumstances in which it is morally acceptable are MUCH broader.
All that to say that in some circumstances taking source code is considered theft.
(Also, if it was theft this particular example would be theft in the same way that taking a book from someone's recycling bin would be theft: no one is worse off)