1 / 12

Σ YMBO Λ IKO Σ ΥΠΟΛΟΓΙΣΜΟΣ

Σ YMBO Λ IKO Σ ΥΠΟΛΟΓΙΣΜΟΣ. Σ YMBO Λ IKO Σ ΥΠΟΛΟΓΙΣΜΟΣ - Παράδειγμα. %polynomial (Expression, Variable) polynomial (X, X). polynomial (Term, X) :- number (Term). polynomial (X^N, X) :- number (N). polynomial (Term1 + Term2, X) :­ polynomial (Term1,X), polynomial (Term2,X).

girardt
Download Presentation

Σ YMBO Λ IKO Σ ΥΠΟΛΟΓΙΣΜΟΣ

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ΣYMBOΛIKOΣ ΥΠΟΛΟΓΙΣΜΟΣ

  2. ΣYMBOΛIKOΣ ΥΠΟΛΟΓΙΣΜΟΣ - Παράδειγμα • %polynomial (Expression, Variable) • polynomial (X, X). • polynomial (Term, X) :- number (Term). • polynomial (X^N, X) :- number (N). • polynomial (Term1 + Term2, X) :­ polynomial (Term1,X), polynomial (Term2,X). • polynomial (Term1 - Term2, X) :­ polynomial (Term1,X), polynomial (Term2,X). • ?polynomial (x^4 + x^2 - x + 6, x). • ?polynomial (5, x). • ?polynomial (-5, x). (number => integer)

  3. derivative(Expression, Variable, DifferentiatedExpression) • 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).

  4. Κέλυφος αλληλεπίδρασης • 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).

  5. ΕΛΙΖΑ • Κλασσικό πρόγραμμα Τεχνητής Νοημοσύνης • Προσομοίωση διαλόγου • Παράδειγμα διαλόγου • User: I am unhappy. • Eliza: How long have you been unhappy. • User: Six months. Can you help me. • Eliza: What makes you think that I can help you. • User: You remind me about my brother. • Eliza: Can you tell me more about your brother. • User: I like teasing my brother. • Eliza: Does anyone else like teasing your brother. • User: No, only me. • Eliza: Please go on.

  6. ΕΛΙΖΑ – Αλγόριθμος • Ο αλγόριθμος της Ελίζας βασίζεται σε ζεύγη «ερέθισμα - ανταπόκριση» (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

  7. ΕΛΙΖΑ – Πρόγραμμα 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(Input1), eliza(Input1).

  8. ΕΛΙΖΑ – Πρόγραμμα %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]).

  9. Λογική στο Λογικό Προγραμματισμό! • Πώς μπορούμε να γράψουμε ένα λογικό πρόγραμμα που να αποφασίζει αν μια πρόταση του προτασιακού λογισμού είναι αληθής ή ψευδής κάτω από μια εκτίμηση; • Η πρόταση (p \/ q) => rκάτω απότην εκτίμηση, val(p)=true, val(q)=false, val(r)= false, είναι ψευδής ενώ κάτω απότην εκτίμηση, val(p)=true, val(q)=false, val(r)= true, είναι αληθής. • Πώς θα επεκτείνουμε το πρόγραμμα ούτως ώστε για κάθε δεδομένη πρόταση το πρόγραμμα να κατασκευάζει (και να επιστρέφει ως απάντηση) τις εκτιμήσεις κάτω από τις οποίες η πρόταση είναι ψευδής;

  10. Λογική στο Λογικό Προγραμματισμό! • % 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, V1), sat(Y, V1,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, V1), sat (Y, V1, V). • sat (if (X, Y), A, V) :- invalid(X,A, V). • sat (no (X), A, V) :- invalid(X,A, V).

  11. Λογική στο Λογικό Προγραμματισμό! • % 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 (X,A, V). • invalid (and (X, Y), A, V) :- invalid (Y, A, V). • invalid (or(X, Y), A, V) :- invalid (X, A, V1), invalid (Y, V1, V). • invalid(if(X, Y),A,V) :- sat (X, A, V1), invalid (Y, V1, V). • invalid (no(X),A, V) :- sat (X,A, V).

  12. Λογική στο Λογικό Προγραμματισμό! • 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)).

More Related