YMBOIKO polynomial Expression Variable polynomial X X polynomial
ΣYMBOΛIKOΣ ΥΠΟΛΟΓΙΣΜΟΣ Παράδειγμα • • • %polynomial (Expression, Variable) polynomial (X, X). polynomial (Term, X) : number (Term). polynomial (X^N, X) : number (N). polynomial (Term 1 + Term 2, X) : polynomial (Term 1, X), polynomial (Term 2, X). • polynomial (Term 1 Term 2, X) : polynomial (Term 1, X), polynomial (Term 2, X). • ? polynomial (x^4 + x^2 x + 6, x). • ? polynomial (5, x). • ? polynomial ( 5, x). (number => integer)
derivative(Expression, Variable, Differentiated. Expression) • • • derivative (X, X, 1). derivative (X^N, X, N*X^M): M is N 1. derivative (sin(X), X, cos(X)). derivative (cos(X), X, sin(X)). derivative (e^X, X, e^X). derivative (F+ G, X, DF + DG) : derivative (F, X, DF), derivative (G, X, DG). derivative (F G, X, DF DG) : derivative (F, X, DF), derivative (G, X, DG). derivative (F*G, X, F*DG +G*DF) : derivative (F, X, DF), derivative (G, X, DG). derivative (F/G, X, (G*DF F*DG)/(G*G)) : derivative (F, X, DF), derivative (G, X, DG). derivative (F^N, X, N*F^M*DF): M is N 1, derivative (F, X, DF).
Κέλυφος αλληλεπίδρασης • start_homework: write(“Welcome, …”), continue(yes). • continue(yes): write(“Please enter your (next) expression”), read(Expr), find_variable(Expr, X), derivative(Expr, X, DExpr), write(“The derivative of” Expr “is: ”), nl, write(DExpr), nl, write(“Do you want to continue: yes/no”), read(Ans), continue (Ans). continue(no): write(“Thanks, …”). • find_variable(Expr, X): polynomial(Expr, X).
ΕΛΙΖΑ • Κλασσικό πρόγραμμα Τεχνητής Νοημοσύνης • Προσομοίωση διαλόγου • Παράδειγμα διαλόγου – – – – – User: Eliza: User: Eliza: I am unhappy. How long have you been unhappy. Six months. Can you help me. What makes you think that I can help you. You remind me about my brother. Can you tell me more about your brother. I like teasing my brother. Does anyone else like teasing your brother. No, only me. Please go on.
ΕΛΙΖΑ – Αλγόριθμος • Ο αλγόριθμος της Ελίζας βασίζεται σε ζεύγη «ερέθισμα ανταπόκριση» (stimulus response) – Αυτά είναι προεπιλεγμένα σχήματα διαλόγου π. χ. : Stimulus: I am (statement) Response: How long have you been (statement) • Read input While input is not “bye” – – – Choose a stimulus/response pair Match the input to the stimulus Generate the reply from this match and the response Output the response Read the next input
ΕΛΙΖΑ – Πρόγραμμα eliza: read_word_list(Input), eliza(Input). eliza([bye]): writeln([‘Goodbye. I hope I’ve helped you’]). eliza(Input): pattern(Stimulus, Response), match(Stimulus, Input), match(Response, Output), reply(Output), read_word_list(Input 1), eliza(Input 1).
ΕΛΙΖΑ – Πρόγραμμα %pattern(Stimulus, Response) pattern([i, am | Rest], [how, long, have, you, been | Rest]). pattern([can, you, X, me], [what, makes, you, think, that, i, can, X, you]). pattern([i, like | Rest], [does anyone else in your family like | Rest]). pattern([i, feel | Rest], [do you often feel that way]). pattern(Input, [can you tell me more about X]): member(X, Input), important(X). % important(brother). . pattern(Input, [please, go, on]).
Λογική στο Λογικό Προγραμματισμό! – % sat (Formula, Accumulator, Valuation) – sat (Χ, A, V) : atomic(X), not member(false(X), A), genuine_nsert( true(X), A, V). – sat (and(X, Y), A, V) : sat(X, A, V 1), sat(Y, V 1, V). – – sat (or (X, Y), A, V) : sat (X, A, V). sat (or (X, Y), A, V) : sat (Y, A, V). – – sat (if (X, Y), A, V) : sat (X, A, V 1), sat (Y, V 1, V). sat (if (X, Y), A, V) : invalid(X, A, V). – sat (no (X), A, V) : invalid(X, A, V).
Λογική στο Λογικό Προγραμματισμό! – % invalid (Formula, Accumulator, Valuation) – invalid (X, A, V) – : atomic(X), not member (true(X), A), genuine_nsert( false(X), A), insert (false (X), A, V). – – invalid (and (X, Y), A, V) – invalid (or(X, Y), A, V) : invalid (X, A, V 1), invalid (Y, V 1, V). – invalid(if(X, Y), A, V) : sat (X, A, V 1), invalid (Y, V 1, V). – invalid (no(X), A, V) : sat (X, A, V). : invalid (X, A, V). : invalid (Y, A, V).
Λογική στο Λογικό Προγραμματισμό! – genuine_insert (X, A, A) : member (X, A). – – genuine_insert (X, A, V) : not member (X, A), insert(X, A, V). insert (X, A, [X|A]). – atomic (X) : not (composite (X)). – – composite (and (X, Y)). composite (or (X, Y)). composite (if (X, Y)). composite (no (X)).
- Slides: 12