What are in your opinion some good propositional and first order logic textbooks (undergraduate level)? I need one that focuses mainly on the aspects of logic related to computer science. thanks in advance.

5$\begingroup$ I guess this should be made "community wiki"? $\endgroup$ – Yemon Choi Sep 18 '10 at 12:23

$\begingroup$ @Ralf To what extent do you need to have examples that are relevant for the applications in CS (e.g. data bases, etc.) as against a purer formulation? Also what level is required? Both questions may influence the reply that you need. $\endgroup$ – Tim Porter Sep 18 '10 at 15:44

$\begingroup$ i'm looking for a textbook that covers both aspects or alternatively two books one for each "topic". $\endgroup$ – Ralf Sep 18 '10 at 16:23

1$\begingroup$ Also, logic shapes CS in two different guises: model theory overlaps with complexity theory, and structural proof theory overlaps with the theory of programming languages. Which do you have a preference for? $\endgroup$ – Neel Krishnaswami Sep 19 '10 at 9:10

$\begingroup$ Once again, i'm interested in both aspects. Thank you all for the answers. $\endgroup$ – Ralf Sep 19 '10 at 15:29
My favourite introductory book on mathematical logic is Robert S. Wolfe's A Tour Through Mathematical Logic. Amazingly well written, it covers an extraordinary amount of material in both logic and set theory, complete with biographical vignettes and historical insights. There a deep discussion of first order logic, and it's place in metamathematical systems. It also has a wonderful introductory chapter on the theory of computation and its origins. This is the book I would recommend to any of my students if they asked me about logic.
After that, there are several more advanced texts that I like, particularly the ones by Shoenfield and the classic by my old teacher, Elliot Mendelson.
You can't go wrong with any of those.
The question as currently stated is a little vague, but I took a course on logic and theorem proving as it relates to computer science as an undergraduate, and the textbook, Huth and Ryan's "Logic in Computer Science" (which I see now has a second edition) was a reasonable textbook.
For a somewhat different value of "aspects of logic related to computer science," Pfenning's notes on from his undergraduate course on Constructive Logic are relatively complete and might be useful.
I'm surprised that no one has yet mentioned Boolos 'Computability and Logic'. The first 100 pages are pretty solid computability theory, and then follows Metalogic, with an especially good précis on firstorder logic that emphasizes the difference between a language, a theory, and logical/nonlogical symbols. Worth a gander, especially if you're interested in CS related logic.
Robert Soare's 'Recursively Enumerable Sets and Degrees' is another good place to start for recursion theory, as well as general logic. His approach is very clear (if a little assuming that you're following everything at once) and the first 120pp are very informative on recursively enumerable sets (now usually called computably enumerable). But for undergraduates, I'd go with the Boolos...
Note of warning  Mendelson's book Introduction to Mathematical Logic I found confusing when starting out  this was confirmed by supervisors/colleagues.
I hope this helps!
A first course in logic by S. Hedman (OUP) is excellent.
For a discussion of logic textbooks, highly recommended:
Teach Yourself Logic 2016:A Study Guide
Peter Smith
Available online at http://www.logicmatters.net/tyl/
It depends on what you mean by "related to computer science". Undergraduate computer science "logic" books tend to focus more on computability, like
Hopcroft and Ullman, Introduction to Automata Theory, Languages, and Computation
Papadimitriou, Computational Complexity
Undergraduate mathematical "logic" books tend to focus on propositional logic and firstorder logic but not things like computational complexity. One wellregarded book of that sort is
 Enderton, A Mathematical Introduction to Logic
That book does prove the unique readability (parsing) algorithm for propositional and firstorder formulas.
As a clear introduction to propositional and first order logic for the mathematically minded, I think Logic and Structure by Van Dalen is in a class of its own. The majority of the book is not particularly CS focused, but the beginnings of recursion theory are covered in the last chapter.
A very clear (and free) introductory textbook is A Problem Course in Mathematical Logic  "a freeware mathematics text by Stefan Bilaniuk" available as pdf, ps and Latex source on http://euclid.trentu.ca/math/sb/pcml/pcml.html:
A Problem Course in Mathematical Logic is intended to serve as the text for an introduction to mathematical logic for undergraduates with some mathematical sophistication. It supplies definitions, statements of results, and problems, along with some explanations, examples, and hints. The idea is for the students, individually or in groups, to learn the material by solving the problems and proving the results for themselves. The book should do as the text for a course taught using the modified Mooremethod.
The material and its presentation are pretty strippeddown and it will probably be desirable for the instructor to supply further hints from time to time or to let the students consult other sources. Various concepts and and topics that are often covered in introductory mathematical logic or computability courses are given very short shrift or omitted entirely, among them normal forms, definability, and model theory.
Parts I and II, Propositional Logic and FirstOrder Logic respectively, cover the basics of these topics through the Soundness, Completeness, and Compactness Theorems, plus a little on applications of the Compactness Theorem. They could be used for a oneterm course on these subjects. Part III, Computability, covers the basics of computability using Turing machines and recursive functions; it could be used as the basis of a oneterm course. Part IV, Incompleteness, is concerned with proving the Gödel Incompleteness Theorems.
The Logic Book by Merrie Bergmann, et al, used to be used to teach propositional logic and firstorder predicate logic to philosophy undergraduates at University College London (UCL) and at the University of Oxford. It has a gentle learning curve, with lots of exercises, and a companion volume of selected answers.
Mathematical Logic, Part I by Cori and Lascar used to be used to teach mathematics undergraduates at some of the University of London colleges, IIRC, though I forget which ones. It has a steeper learning curve, but again has plenty of exercises. With this book, the exercises are at the back, not in a separate volume.
Not quite a textbook, but a collection of historical projects about elementary logic and related issues in discrete mathematics and computer science can be found at www.cs.nmsu.edu/historicalprojects Click on the project "Deduction Through the Ages ..."
Though a little advanced, Logic for Applications by Nerode and Shore fits the bill. (Google books) The book has an extensive treatment of propositional and firstorder logic, with an emphasis on resolution as a proof method. Hilbert style systems are also discussed to some length, but natural deduction is lacking. I found that the Prolog related parts can be successfully skipped if necessary.
I don't understand what people usually mean when they say "aspects of some mathematical field related to computer science" (how they know what is really related to CS?), but if you really want to study or teach first order logic, then, in my opinion, there is old but still the best book for that  Joseph Shoenfield's Mathematical logic.

3$\begingroup$ I agree that Shoenfield's book is great, but I wouldn't dare teach an undergraduate course from it. $\endgroup$ – Andreas Blass Sep 21 '10 at 13:53

$\begingroup$ I completely agree with Andreas. Using Shoenfield as an introduction to logic is like using Lang as an introduction to abstract algebra. $\endgroup$ – Brendan Cordy Jun 13 '11 at 17:53

$\begingroup$ Of course I mean Lang's Algebra, not Undergraduate Algebra. $\endgroup$ – Brendan Cordy Jun 13 '11 at 18:04