If you make an exact (or nearly exact) reproduction of a copyrighted work, that is clearly a copy and you have infringed its copyright unless you have permission (or an exception such as fair use applies). It does not matter if the reproduction is done mechanically or via memory.
If you take a copyrighted work, and make small mechanical changes, leaving the structure intact (say you change all the occurrences of 'John' to 'Fred' in a novel, or you translate the novel faithfully into another language) you have created a derivative work, and this still infringes copyright unless you have permission.
If you take ideas from a copyrighted work, and use them to build a new work, that work does not infringe.
Exactly where the line gets drawn between a paraphrase and a new work is a judgement call. In general if there is a close part-by-part structural similarity between the old and new works, it is probably a paraphrase and thus a derived work.
If the ideas come from multiple different sources, that argues for a new work rather than a derived work. Relying on facts from several different sources, rather than taking everything from a single source, suggests research rather than copying.
When handling software source code, particularly short segments of code implementing a single algorithm, such as might be written for a text on programming, sometimes the ideas more or less dictate the expression. When an expression is obvious and there are few options on how to create it, it may not be protected by copyright. The literary term used for this principle is Scènes à faire ("required scenes"). This is closely related to the "Merger doctrine". When the expression has merged with the idea so that there is only a single way or only a few reasonable ways to express the idea, the expression is considered part of the idea and is not protected by copyright.
Facts are not protected by copyright, although the expression of a fact may be. Lists of facts in a natural or obvious order are not protected either. Lists selected and arranged in a creative order will be protected.
For example, a biography reading something like:
John Jones was born in 1948. He grew up in Anytown. He Graduated from Anytown HS in 1966. John attended BigU university. He graduated with a BS in computer sciennce in 1971. John Moved to New City. He worked as a systems programmer for DynaTech. He invented several new algorithms, including the much used Mastersort algorithm. In 1998 John won the Turing Award. John died in 2012.
This is a very basic biography, in strictly chronological order, listing facts with no creative expression. Copying this paragraph would not infringe copyright. It is not original enough for protection. But if it were expanded to several pages which told the story of John's life in expressive detail, including anecdotes of his time at BigU, what his co-workers at DynaTech thought of him, and how other famous developers regarded him and his work, that would almost surely be an original work that could not be copied without permission.