Professional Documents
Culture Documents
Matthieu Moisse 2
Matthieu Moisse 2
Matthieu Moisse
AAU
5 November 2009
Jess
5 November 2009
1 / 29
1 2
History Introduction Expert System Rule-Based System Syntax Functions Templates Facts Rules Example Use My Opinion Questions References
Matthieu Moisse (AAU) Jess 5 November 2009 2 / 29
4 5 6 7 8
History
Dr. Ernest J. Friedman-Hill Sandia National Laboratories (late 1995) inspired by CLIPS
C Language Integrated Production System 1985 at NASA-Johnson Space Center
Syntax of LISP
Jess
5 November 2009
3 / 29
Expert System
Jess
5 November 2009
4 / 29
Procedural Programming
functions logic control sequential deterministic
Declarative Programming
rules & facts no logic control
Jess
5 November 2009
5 / 29
Rule-Based System
Working Memory (Facts) Rule Base (If Then Else) Inference Engine (Reasoning)
Jess
5 November 2009
6 / 29
Inference Engine
Pattern Matching (Rete) Activate Rule Conict Resolution Fire Rule
Jess
5 November 2009
7 / 29
Basics
Commands
(reset) (run)
Jess
5 November 2009
8 / 29
Basics
Symbols
letters digits $ = +/ <> ?#
Symbols
foo rst-value contestant#1 abc
Jess
5 November 2009
9 / 29
Basics
Numbers
int long double
Numbers
3 4. 5.643 5654L 6.0E4 1D
Jess
5 November 2009
10 / 29
Basics
Strings
no escape sequences
Strings
foo Hello, World \Nonsense,\ he said rmly. Hello, There
Jess
5 November 2009
11 / 29
Basics
Lists
everything is a list
Lists
(+ 3 2) (a b c) (Hello, World) () (deftemplate foo (slot bar))
Jess
5 November 2009
12 / 29
Function
Functions
(deunction <function-name> [<doc-comment>] (<parameter>*) <exp>* [<return-specier>])
Function
(deunction max Calculates the max of 2 variables (?a ?b) (if (> ?a ?b) then (return ?a) else (return ?b) ))
Jess
5 November 2009
13 / 29
Facts
Facts
Templates Unordered Facts Ordered Facts Shadow Facts
Jess
5 November 2009
14 / 29
Templates
Templates
(deftemplate <template-name> [extends <extended-template-name>] [<doc-comment>] (slot multislot <slot-name> [some options])*)
Template
(deftemplate automobile A specic car.) (slot make) (slot model) (slot year (type INTEGER)) (slot color (default white)) )
Jess
5 November 2009
15 / 29
Unordered Facts
Template
(deftemplate automobile A specic car.) (slot make) (slot model) (slot year (type INTEGER)) (slot color (default white)) )
Unordered facts
(<template-name> (<slot-name> <value>)*)
Unordered fact
(automobile (make ford) (year 1999) (model Explorere))
Matthieu Moisse (AAU) Jess 5 November 2009 16 / 29
Ordered Facts
Ordered facts
(<template-name> <value>*)
Ordered fact
Domain in AI Simulates human brain (shopping-list eggs milk bread)
Template
(deftemplate shopping-list A list of stu we need to buy (declare (ordered TRUE)) )
Jess
5 November 2009
17 / 29
Shadow Fact
Link to Java-Objects
Shadow Fact
(bind ?a (new Account)) (add ?a) (printout t (?a getBalance) crlf) (modify 0 (balance 1))
Jess
5 November 2009
18 / 29
Rules
Rules
(defrule <rule-name> [<doc-comment>] <LHS> => <RHS> ) LHS
IF Pattern Matching
RHS
THEN ...
Jess
5 November 2009
19 / 29
Rules
Rule
(defrule all-fords nd all ford models ?car < (automobile {make == ford}) => (printout t A ?car.model is a model of ford! crlf) )
Rule
(defrule match-list-with-bacon Find grocery-lists that contains bacon (grocery-list $? bacon $?) => (printout t Yes, bacon is on the list crlf) )
Matthieu Moisse (AAU) Jess 5 November 2009 20 / 29
Example
Example
(deftemplate pants-color (slot of) (slot is)) (deftemplate position (slot of) (slot is))
Jess
5 November 2009
21 / 29
Example
Example
(defrule generate-possibilities => (foreach ?name (create$ Fred Joe Bob Tom) (foreach ?color (create$ red blue plaid orange) (assert (pants-color (of ?name) (is ?color)))) (foreach ?position (create$ 1 2 3 4) (assert (position (of ?name) (is ?position))))))
Jess
5 November 2009
22 / 29
Example
Example
(defrule nd-solution ;; There is a golfer named Fred, whose position is ?p1 ;; and pants color is ?c1 (position (of Fred) (is ?p1)) (pants-color (of Fred) (is ?c1)) ;; The golfer to Freds immediate right ;; is wearing blue pants. (position (of ?n& Fred) (is ?p&:(eq ?p (+ ?p1 1)))) (pants-color (of ?n& Fred) (is blue& ?c1)) ;; Joe is in position #2 (position (of Joe) (is ?p2&2& ?p1)) (pants-color (of Joe) (is ?c2& ?c1))
Jess
5 November 2009
23 / 29
. . . Example. . .
. . . Example. . .
;; Bob is wearing the plaid pants (position (of Bob) (is ?p3& ?p1& ?p& ?p2)) (pants-color (of Bob& ?n) (is plaid&?c3& ?c1& ?c2)) ;; Tom isnt in position 1 or 4 ;; and isnt wearing orange (position (of Tom& ?n) (is ?p4& 1& 4& ?p1& ?p2& ?p3)) (pants-color (of Tom) (is ?c4& orange& blue& ?c1& ?c2& ?c3))
Jess
5 November 2009
24 / 29
. . . Example
. . . Example
=> (printout (printout (printout (printout t t t t Fred ?p1 ?c1 crlf) Joe ?p2 ?c2 crlf) Bob ?p3 ?c3 crlf) Tom ?p4 ?c4 crlf crlf))
Jess
5 November 2009
25 / 29
Use
puzzles business environments J2EE enterprise applications Windows CE handhelds DDG 1000 destroyer ship
Jess
5 November 2009
26 / 29
My Opinion
...
Jess
5 November 2009
27 / 29
Questions
Jess
5 November 2009
28 / 29
Use
Jess
5 November 2009
29 / 29