code

All code examples in Prolog and C/C++ are provided for personal and educational use only. You may modify or distribute the code in source or compiled form for similar purposes so long as the original source is clearly identified.

These code examples were written for the First Edition of the AI Book, and have been modified minimally since then to cope with changes to run with Tau-Prolog, so that you can try them out within the browser.

If you wish to use any of the code examples, in part or whole, for commercial purposes please contact Alan Dix.

Most are written principally with ease of comprehension in mind and are not necessarily the most efficient coding of the algorithm. In particular, Prolog code, especially the early examples, try to avoid ‘clever’ Prolog tricks. However, the nature of the examples, means that sequential code achieved using cuts and mutable store achieved using assert/retract is often necessary.

Code examples are being added incrementally. If you have any problems with the existing code, or if critical examples are too slow appearing, please contact Alan Dix who will try to correct/add to the code as appropriate in a reasonable time!

Some of the prolog examples use predicates defined in utility files.

tbirds.pchapter 1page 16: representing logic
prod.pchapter 1pages 19–20: production rules
network.pchapter 1page 22: semantic networks and inheritance
frames.pchapter 1pages 23–24: frames and slots
forback.pchapter 2pages 33–34: forwards and backwards reasoning
tms.pchapter 2page 35: non-monotonic reasoning
TMS – truth maintenace system
bayes.pchapter 2page 36: Baysian inference
bayes2.pchapter 2page 36: Baysian inference
certf.pchapter 2pages 37–38: certainty factors
fuzzy.pchapter 2pages 39–40: fuzzy set theory
gentest.pchapter 3pages 49–50: generate and test
prune.pchapter 3pages 50–51:search tree pruning
hanext.pchapter 3pages 52–53: hanoi search graph 1
hanint.pchapter 3pages 52–53: hanoi search graph 2
proof.pchapter 3pages 53–54: addition proof graph
pages 62–63: closed lists
eximages.pchapter 8image processing utilities
images from examples in book
filter.pchapter 8pages 169–172: digital filters
pages 174–175: gradient filters
gimage.pchapter 8image processing utilities
the ‘gimage’ representation of a pixel image
image.pchapter 8image processing utilities
simple representation of a pixel image
threshold.pchapter 8pages 166–167: thresholding
meansend.pchapter 9pages 205–207: means-end analysis
blackboard.pchapter 10pages 236–238: blackboard architecture
life.pchapter 10pages 240–241: Conway’s game of Life