Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Paradigms of Artificial Intelligence Programming (1992) (github.com/norvig)
267 points by _19qg on Feb 26, 2018 | hide | past | favorite | 33 comments


This book is timeless classic that is not getting old.

It's basically two things:

* Learn to program book written in very basic old school Common Lisp. Or, learn to program after you already know how to program. If you never really dwell deeply into code that others write to improve your own skills this is good book so start. It's programming as art or literature.

* Overview of some old AI techniques, interpreters and parsers. Old AI techniques are today's good to know heuristic algorithms.


Peter Norvig is probably my favorite online teacher, from the AI class in 2011 to his Design of Computer Programs on Udacity. His attitude is inviting, and his exposition clear.

The kerning in the PDF looks weird on my Mac, but it's really cool that this is available.


Please check again, now there are better PDFs in the repository.


Wow, it's great this book is now available online for free!

It's definitely one of my all-time-favorite programming books - my own copy is well worn by use. It's not exactly cutting edge AI in 2018, but the general programming advice is timeless and the AI samples can be seen as a fun domain to play in.


Based on the repository description I thought it was just the code examples, but wow yeah it's the whole thing.


This book is excellent. The AI stuff might be a little dated, but if you've read some intro to Common Lisp books and want to learn more about how to use the language, this is a great place to dive in.

As someone mentioned, this particular scan/OCR has some wonky kerning. If you happen to be an ACM member with access to their library there's a much nicer PDF available there.


This is heartening news - I bought the e-book of PAIP a while ago, and the OCR in it is horrible, with many errors (although perhaps they were deliberate, to keep readers on their toes?).


Please check again, looks like there is a new version.


My favorite programming book.

The chapters on performance tuning are timeless. Following Norvig’s thought process on how to develop computer programs is like pair programming with one of the best programmers of all time.


Only second to the SICP book, but yeah, I agree. Fantastic read and timeless advices.


Was slowly re-reading the paper version looking for the particular phrase :) . Search in electronic version got it quickly... but it's still cool to read the book, even though author recommend to go to "AI: modern approach".

The quote I was looking for (found when reading the book earlier, then forgot the exact place):

"To put things in perspective, consider that Lisp is at once one of the highest-level languages available and a universal assembly language. It is a high-level language because it can easily capture data, functional, and control abstractions. It is a good assembly language because it is possible to write Lisp in a style that directly reflects the operations available on modern computers."


Is there any example of this assembly style of programming in Lisp?


Any time people claim that Lisp is a functional programming language, I like to drag out this example posted by Joe Marshall to comp.lang.lisp[1]:

    (DEFUN RDSYL (L DF)
      (PROG (LL BRAKP ANS CH)
            (SETQ DF (MERGEF DF '((* *) * *)))
         AA (SETQ LL (SETQ BRAKP () ))
          A (SETQ CH (OR (CAR L) #/_))
            (COND ((OR (= CH #/ ) (= CH #//))     ;"/", " "
                   (POP L)
                   (SETQ CH (CAR L)))
                  ((AND (= CH #/[) (NOT #%(ITSP)))    ;"["
                   (SETQ BRAKP 'T))
                  ((AND (= CH #/]) (NOT #%(ITSP))) (SETQ BRAKP () )) ;"]"
                  ((OR (= CH #/( ) (= CH #/) )) (RETURN () ))  ;Cant have parens here
                  ((= CH #/,)     ;Comma
                   (COND ((NOT BRAKP)
                          (POP L)
                          (GO RET))))
                  ((= CH #/_) (GO RET)))
           (PUSH CH LL)
           (POP L)
           (GO A)
      RET  (SETQ DF (MERGEF (NAMELIST (MAKNAM (NREVERSE LL))) DF))
           (SETQ ANS (NCONC ANS (LIST DF)))
           (AND (= CH #/,) (GO AA))
           (RETURN ANS) ))
There is a lot of this kind of code around in the various Lisp Machine sources (CADR is legally available for poking around in[2]). Occasionally things like this pop up in contemporary Lisp compilers or IO/concurrency libraries. Some algorithms are much easier to express with goto.

[1] https://groups.google.com/forum/#!msg/comp.lang.lisp/4nwskBo...

[2] http://www.unlambda.com/cadr/


If you look at code with really low-level operators like CAR, CDR, CONS, ATOM, NULL, etc then this is the assembly level of Lisp. If you look at some Lisp Machines, which had a processor with a for Lisp optimized instruction set, many of those mapped relatively direct to corresponding machine instructions - using a mostly stack machine.

The CLISP implementation of Common Lisp has a virtual machine implementation.

Let's take some simple demonstration code:

    [1]> (defun foo (a)
            (car (cdr (if (null a)
                          '(1 2)
                          (cons 3 a)))))
    FOO
Now we compile it for the CLISP virtual machine:

    [2]> (compile 'foo)
    FOO ;
    NIL ;
    NIL
If we look at the disassembled virtual machine code, you'll see that the machine code has actually similar primitives for its stack machine:

    [3]> (disassemble 'foo)

    Disassembly of function FOO
    (CONST 0) = (1 2)
    (CONST 1) = 3
    1 required argument
    0 optional arguments
    No rest parameter
    No keyword parameters
    11 byte-code instructions:
    0     (LOAD&JMPIFNOT 1 L10)
    3     (CONST&PUSH 1)                      ; 3
    4     (LOAD 2)
    5     (CONS)
    6     L6
    6     (CDR)
    7     (CAR)
    8     (SKIP&RET 2)
    10    L10
    10    (CONST 0)                           ; (1 2)
    11    (JMP L6)
    NIL

Unrelated to that there is also the idea to program assembler code embedded in Lisp - this is often called LAP code (Lisp Assembler Program). Several implementations are using this.


SBCL is mostly written in Common Lisp. It has a compiler that can compile itself. Part of that compiler are definitions of building blocks (VOPs or virtual operations) that describe snippets of assembly code. So as always, you use the tools provided by Lisp to create a DSL that allows you to write code as is practical for your use case.

For an example look at https://github.com/sbcl/sbcl/blob/master/src/compiler/x86-64...

You can find similar code for other ISAs in neighbouring directories.


One of the best books on programming there is. Every time I get the gumption to work on one of the chapters from this cookbook, I always learn something new.

:+1:


I've lightly skimmed this book in the past and got an impression that it is a collection of intros to bunch of subjects. For those who read it thoroughly - do you think this book is useful for experienced devs who are aware/knowledgeable (from other sources) in most (or all) of the subjects mentioned? Or maybe this book is aimed for more beginners, e.g. as a second book after SICP or similar?


I had the same impression when it first came out and I dipped into it in the bookstore a couple times: it looked like a good treatment of a bunch of topics I'd mostly already been introduced to.

This misses what I found most valuable when I did get around to it. There's another thread up on HN right now, "Nobody's just reading your code". Back then I read a lot of code from books, and read more actively by treating it like a reviewer: how could this code be clearer or otherwise better, how else might you do it? Most of the time, in many other books, you wouldn't get far before seeing some clear improvement. In PAIP this basically never happened. Often enough I would think of something, but if you worked it out in detail there was some less-obvious reason the code was the way it was. At one point I spotted a bug, and he wrote back that it'd been a year since the last bug report, and he'd started to hope there weren't any more.

All the code in the book is pretty short, and it's not really "production code", but it's enough to be an education in craftsmanship at every level. I found that more interesting than the object-level topics, though they're worth learning about too.

Nowadays if you prefer Python you can get a similar experience at https://github.com/norvig/pytudes#pytudes-index-of-jupyter-i... treating different examples.

One more personal reaction I had to this book: feeling like here was someone else with some of the same values. (Only, you know, smarter.) Someone with a similar taste, who couldn't resist coming back to their code repeatedly well after it's "done". The work in the end looks pragmatic, but sort of an idealized pragmatism: you have to really want to produce your best work, to work that hard over it.


pytides looks interesting. I wonder if he ever produced (or worked on) a similar material/project using statically typed traditional languages.


He cowrote a Scheme interpreter in Java -- you can find it on his webpage. There are some projects from others on implementing algorithms from AIMA in other languages, such as this one that just came up in my feed the other day: https://github.com/MrDupin/aima-go


I've read most of it, and I think it's a great book for experienced developers looking to dive deep into a pretty specific range of topics. As a beginner's second book after SICP, I'd still recommend it, because it assumes almost nothing. Having read it, I find it hard to see it as just a collection of intros, because you get a lot of mental algorithmic mileage out of e.g. hand-rolling an implementation of automatic differentiation, which is done in the book. You get a lot of clarity on things that are still quite useful.


> looking to dive deep into a pretty specific range of topics

But does the book dive deep enough? Won't be more useful to go with more specialized books/papers?


Peter goes through various iterations improving the approaches in the book. There is a bunch of stuff - like writing good and efficient Lisp code - which is not covered that well in many other books.


Forgot to mention - for the person who is not (that much) interested in Lisp (anymore).


Wow. Wish I'd found this a month ago. I just bought yet another paper copy (the binding of the paper version is not very durable).


This is awesome! I lost my copy or borrowed it to somebody and do not remember who or when.

Either way, this was one of the most fun programming books I have ever read, Lisp or no Lisp.


I bought this a long time ago and never took the time to go through it. I should correct that, maybe this reminder will get me to finally dig in.


Awesome. I have had this much-recommended book sitting on the shelf for a year now and this is a helpful reminder that I should start on it.


I don't know why the title of the submission has been changed. It's not only the code, a PDF of the book is in the repository, too.


Thanks, we've updated the title so that it's not misleading.


962 pages. It'll be a while I guess.


Yes, it seems big. Tried to download the PDF on my mobile earlier, Android said the file is too big. Same for the text file :) First time I've seen that message. Checking it out on PC now.


I distinctly remember learning memoisation from this book. Great memories!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: