Rule Based Programming: 3rd Year, 2nd Semester
Rule Based Programming: 3rd Year, 2nd Semester
Declarative Programming
Expert Systems
CLIPS
Course information
Course timetable: https://profs.info.uaic.ro/~orar/discipline/orar_pbr.html
Evaluation:
● Written exam at the end of the semester (E - maximum 40). The written exam is mandatory.
● Lab exercises (L - 7 * 4 + 6 * 2, maximum 40).
● Project work (PP - weeks 8-13, maximum 40).
● Grades are set using the formula ROUND (L + PP + E)/10. To pass you need L + PP + E at least 50.
Programming paradigms: imperative
● You tell the computer exactly what to do.
● Easy to debug.
● Easy to implement - it needs the bare
minimum of data.
● Fast execution (program as good as the
programmer).
● Hard to adapt to changing goals.
Go to C309.
Expert systems
Human experts
● Expensive
● Hard to access
● Adaptable
Expert systems
● Much cheaper
● Very easy access
● Little adaptability
● Still require human experts to be
built
What is knowledge?
Intelligence applied to
information produces knowledge.
Knowledge supplements
intelligence.
Inference
Knowledge Base Inference Rules
Engine
5 + 2 + 6 * (7 - 2) is written as (+ 5 2 (* 6 (- 7 2)))
Easier to parse: each parenthesis is a call to a function identified by the first field.
CLIPS: Knowledge Base (I)
Contains facts. A fact can be anything (as long as it doesn’t contain & or | or ~ and the first
field starts with a char - not a number).
Creating a fact:
(assert (minge))
(assert (lista 1 2 3 4 5))
(facts)
f-0 (initial-fact)
f-1 (minge rosie)
f-2 (minge mare)
For a total of 3 facts.
Each fact is assigned (by CLIPS) an unique identifier. All future references to that fact can
only be done by referencing that identifier.
CLIPS: Knowledge Base (III)
Deleting a fact:
(retract 1)
(facts)
f-0 (initial-fact)
f-2 (minge mare)
For a total of 2 facts.
(facts)
f-0 (initial-fact)
f-2 (minge mare)
f-3 (minge rosie)
For a total of 3 facts.
For CLIPS, a fact is a pair (id, content). Once retracted, no other fact with the same id can
ever exist. This is the first important CLIPS tip. Use it in many situations to control the
order of rules, for example by using a fact as a flag/switch.
CLIPS: Inference Rules (I)
Name of the rule. Has to be unique and provided
(defrule name by the user!
(minge rosie)
(minge mare) } Left side: conditions (patterns) to be matched
on the KB
=>
(assert (minge frumoasa)) Right side: actions to be taken affecting the KB
)
CLIPS: Inference Rules (II)
(rules)
name
For a total of 1 defrule.
(facts)
f-0 (initial-fact)
f-1 (minge rosie)
f-2 (minge mare)
f-3 (minge frumoasa)
For a total of 4 facts.
CLIPS: Interacting with the user (I)
(printout t "message" crlf))
t = terminal crlf = carriage return line feed
(defrule read_fact
(minge mare)
=>
(assert (minge (read))
)
CLIPS: Interacting with the user (II)
● (read)gets the first field entered at the terminal
(assert (lista (read))
one two three CR will get (lista one)
● To read all fields, use (readline) - will merge all fields before enter into a single
field! (lista “one two three”)