Copyright is about exclusive right to copy a work of art from some creative effort. Copyright is implicit upon creation of a work of art.

Patent is about means and ends. Process applied to achieve outcome. Patents must be approved by some authority.

Trademark is "recognizable sign, design, or expression which identifies products or services of a particular source from those of others" (from wikipedia [0]). A trademark may optionally be registered, but need not be (the difference between (tm) and (r)). Registered trademarks are governed by some authority in a given jurisdiction.

Copyrights and patents can expire. The property right need not be exercised to be maintained.

Trademarks can be maintained in perpetuity, but must be exercised, or else they may be lost.

Facts cannot have any copyright. Nor ideas. Only the creative expression of these can have copyright.

Ideas + specific process and application may receive a patent.

A clean room design for a map would include only geographic facts, but no creative representation of these. Similarly a clean room design of a piece of software would include only requirements, but no implementation details. A clean room design is not necessary to prove lack of copyright infringement. It is a strong defense against an accusation.

Derivative works are typically protected under copyright law. For a derivative work to not be an infringement of copyright, it must be itself a substantial creative effort. You'll notice that creativity is a significant part of copyright.

The application of creativity to create a new work means that there is a new creator with a new copyright. Definitionally, a derivative work is not copyright infringement. Failing to prove (in the face of an infringement claim) that something is a new, derivative work means that copyright infringement has occurred.

Characters may be subject to both copyright and trademark protections. For example, Mickey Mouse is trademarked by Disney.

There are several legal tests applied to characters when it comes to copyright. Simply, the character themselves must be important in the copyrighted work and be a creative element themselves. "Extras" cannot be protected by copyright - i.e. a villager with a pitchfork is not protected by copyright. A character who happens to be a villager, with distinctive characteristics that delineate them from other individuals and make them recognizable, and around whom the story revolves (and perhaps in the story, this person carries a pitchfork) may be protected by copyright.

I cannot put Harry Potter or his significant likeness into a new work. I cannot publish a 7-part series following the exploits of "chosen one" Gary Rotter in the school of Pigpimples School of Magic and Sorcery as he fights against the rise of "He Whose Name Cannot Be Spoken", and so on.

The name "Harry Potter" is likely trademarked. Assuming it is not, I certainly can tell a story about an old man named Harry Potter if my story is significantly different than J.K. Rowling's series.

This sort of thing is why satirical works are typically not copyright infringement.

Decompiling a program would be a copyright infringement, because there is no creativity there. It is a rote reproduction, specifically the thing that copyright says you cannot do.

[0] https://en.wikipedia.org/wiki/Trademark