Suppose I borrow a book from a library and then use the theory described in this book to write a commercial computer program. In this situation, am I infringing any copyright laws?
In the US, Copyright does not extend to theories:
Section 102 of the Copyright Act (title 17 of the U.S. Code) clearly expresses this principle: “In no case does copyright protection for an original work of authorship extend to any idea, procedure, process, system, method of operation, concept, principle, or discovery, regardless of the form in which it is described, explained, illustrated, or embodied in such work.” Copyright of Ideas, Methods, or Systems - govcirc31.pdf
Copyright does protects the expression of a theory. In your case,
A computer program is a set of statements or instructions to be used directly or indirectly in a computer to bring about a certain result. Copyright protection for a computer program extends to all of the copyrightable expression embodied in the program. The copyright law does not protect the functional aspects of a computer program, such as the program’s algorithms, formatting, functions, logic, or system design. Copyright Registration of Computer Programs - circ61.pdf
So you can develop a commercial computer program that does what the theory postulates, and that program itself will be under your copyright.
The idea that you borrow the book from the library isn't relevant; nor would be reading the book in a bookstore.