Artificial Intelligence
1. Lisp - "functional programming style"
Rather than a list of commands to execute, a functional program
consists of expressions that represent/return values.
Example: Find if an element, x, is part of a list of elements.
C: declare variables, data structures. Write the commands to
process through the list and check each element.
Lisp: each expression in parenthesis represents something and
"returns" this "something" as a value.
C array version: C pointer version:
int x=9; struct node {
int list[10] int info;
bool found=false; node *next;
int i; };
node *list,*p,*temp;
for(i=0; i<10; i++) int x=9, i=0;
list[i] = i; bool found = false;
while (i<1000 && found==false) p=list;
{ while(i < 10)
if (x==list[i]) {
found=true; new(temp);
else i++; temp->info = i;
} temp->next = list;
list = temp;
i++;
}
x = list;
while (x != NULL &&
found==false)
{
if (p->info == x)
found = true;
else
p = p->next;
}
Lisp
(setf x 9)
(setf list '(a b c hello 4567 -3.141 "apple" 9 10000000)
(defun member (element lst)
(cond ((null lst) nil)
((equal element (first lst)) lst)
(t (member element (rest lst)))
)
)
(member x list) => TRUE
2. Search techniques
Example: you need to find the shortest route from here to Richmond.
First generate a list of possible routes from DC to other places.
Depth first search
Follow each search, one by one, until you either find Richmond
or reach a dead end. You may find a very long route to Richmond.
Breadth first search
Go in steps. Check each 10 mile route, then each 20 mile route,
...each 100 mile route, checking each time for Richmond.
Best First search
Choose your next step to take based on some evaluation/guess of
the "best" next step to take, the one that's closest to the goal-
how far you have to go.
A* search
Choose the best path to take based on looking at how far you've
come and how far you have to go.
We set up graphs/networks to represent the problem states, such as
routes to get from a to b.
3. Pattern matching
Eliza program, the computer psychiatrist
(hello)
(how are you today)
(i feel bad)
(why do you feel bad)
4. Symbolic logic, propositional logic
Programmable logic structures, proofs, simple reasoning.
Linneus program - have the computer prove a simple conjecture
(a bear is a mammal)
(is a bear a mammal)
(yes indeed a bear is a mammal)
(a mammal is an animal)
(why is a bear an animal)
(a bear is an animal because a mammal is an animal and a
bear is a mammal)
Propositional logic and Wangs theorem
Premises:
If Julia missed the 7:01 train, then she arrived late at the lab.
If Julia arrived late, then she skipped her 10:00 coffee.
She did not skip her 10:00 coffee.
Prove that Julia did not miss the train. (the first proposition:
Julia missed the 7:01 train, must be false)
5. Prolog - a Programming Logic language.
grandparent(X, Y) :- parent(X,Z),
parent(Z,X).
parent(bob, ann).
parent(ann, sue).
?-grandparent(bob,sue). =>YES
5. Genetic algorithms
Generate a population of random possible solutions.
Pick the best of solution set of this generation, and use this
new population to produce the next generation.
Repeat this process, generation after generation, until solutions
are reached that are good enough.