100% tevredenheidsgarantie Direct beschikbaar na betaling Zowel online als in PDF Je zit nergens aan vast
logo-home
Summary Logic programming summaries ALL weeks 1-6 €7,49   In winkelwagen

Samenvatting

Summary Logic programming summaries ALL weeks 1-6

 8 keer bekeken  0 keer verkocht

This file contains all important information from the course Logic programming. The file is divided into weeks from 1-6 and the summaries include information from the lecture slides and the book. Very useful for exam preparation.

Voorbeeld 3 van de 19  pagina's

  • 23 mei 2023
  • 19
  • 2022/2023
  • Samenvatting
Alle documenten voor dit vak (1)
avatar-seller
enk
Logic Programming Week 1 Summary

Chapter 1

 A collection of facts and rules is called a knowledge base (or a database)
 Posing queries - asking questions about the information stored in the knowledge
base
 Facts are unconditionally true
 ?- prompt symbol

listensToMusic(mia). FACT
happy(yolanda). FACT
playsAirGuitar(mia) :- listensToMusic(mia). RULE
playsAirGuitar(yolanda) :- listensToMusic(yolanda). RULE

 Rules state information that is conditionally true
 :- should be read as “if” or “is implied by”
 Left side is called head of the rule, right side is called body of the rule
 If the body of the rule is true, then the head of the rule is also true
 Modus ponens - if a knowledge base contains a rule head :- body, and Prolog
knows that body follows from the information in the knowledge base, then Prolog
can infer head
 Prolog is able to retrieve information that logically follows from the rules and facts
recorded in the knowledge base
 Clauses - the facts and rules contained in a knowledge base (all the dots)
 Predicates - the concepts we find important (listensToMusic, happy,
playsAirGuitar)
 We can view a fact as a rule with an empty body

playsAirGuitar(vincent):-
listensToMusic(vincent),happy(vincent).


 The comma means and (Vincent plays air guitar if he listens to music and he is
happy), both need to be fulfilled to get a “yes”

, Logical disjunction (or) can be written separately or together with a semicolon ;
but it is not recommended because the code becomes hard to read

playsAirGuitar(butch):- happy(butch); listensToMusic(butch).

 Any word beginning with an upper-case letter is a Prolog variable (X, Y, Z)
 Prolog answers a query by working its way from top to bottom

loves(marcellus,X),woman(X). (Is there any individual X such that
Marcellus loves X and X is a woman?)

jealous(X,Y) :- loves(X,Z),loves(Y,Z). (Conditional
statement, an individual X will be jealous of an individual Y if there is some
individual Z that X loves, and Y loves that same individual Z too)

 There are four kinds of terms in Prolog: atoms, numbers, variables, and complex
terms (or structures)
 Atoms and numbers are lumped together under the heading constants, and
constants and variables together make up the simple terms of Prolog
 An atom is either:
- A string of characters made up of upper-case letters, lower-case letters,
digits, and the underscore character, that begins with a lower-case letter
(butch, big_kahuna_burger, and m_monroe2)
- An arbitrary sequence of characters enclosed in single quotes (’Vincent’,
’The Gimp’, ’Five_Dollar_Shake’, ’&^%&#@$ &*’, and ’ ’), the character
between the single quotes is called the atom name
- A string of special characters (@= and ====> and ; and :-)
 Numbers (integers, floats)
 A variable is a string of upper-case letters, lower-case letters, digits and
underscore characters that starts either with an upper-case letter or with underscore
(X, Y, Variable, _tag, X_526, List, List24, _head, Tail, _input, Output)
 Complex terms are built out of a functor followed by a sequence of arguments.
The arguments are put in ordinary brackets, separated by commas, and placed after
the functor. The functor must be an atom. That is, variables cannot be used as
functors. On the other hand, arguments can be any kind of term
 playsAirGuitar(jody) is a complex term, “playsAirGuitar” is a functor, “jody” is an
argument

,  In Prolog we can nest complex terms: hide(X,father(father(father(butch))))
 Arity is the number of arguments that a complex term has
 woman(mia) is a complex term with arity 1, while loves(vincent,mia) is a complex
term with arity 2
 Woman /1 loves/2 (how you write the predicates), loves/2 and loves/3 are
considered different by Prolog
 ?- listing. (display the contents of the current knowledge base)
 ?- [kb2]. (load the contents of file “kb2.pl”)
 ?- listing(playsAirGuitar). (lists information about a specific predicate)




Chapter 2

 Matching/Unification - Prolog matches woman(X) with woman(mia), thereby
instantiating the variable X to mia
 Three types of terms:
- Constants (atoms or numbers)
- Variables
- Complex terms
 Two terms match, if they are equal or if they contain variables that can be
instantiated in such a way that the resulting terms are equal (mia - mia, 42 - 42, X -
X match as they are all the same) (X - mia would match)

=(mia,mia). Testing if they match, YES
=(mia,vincent). Testing if they match, NO
mia = mia. Nicer way to write this testing
’mia’ = mia. YES
’2’ = 2. NO (2 is a number, ‘2’ is an atom!)
X = Y. YES (variables unify with anything, so with each other too)
kill(shoot(gun),Y) = kill(X,stab(knife)). YES (they use the same atom as the
functor name and have the same number of arguments)

 Prolog is optimistic and assumes that you are not going to give it anything
dangerous, so it does not make an occurs check and as soon as you give it two
terms, it charges full steam ahead and tries to match them (that makes it work
faster as a programming language)

Voordelen van het kopen van samenvattingen bij Stuvia op een rij:

Verzekerd van kwaliteit door reviews

Verzekerd van kwaliteit door reviews

Stuvia-klanten hebben meer dan 700.000 samenvattingen beoordeeld. Zo weet je zeker dat je de beste documenten koopt!

Snel en makkelijk kopen

Snel en makkelijk kopen

Je betaalt supersnel en eenmalig met iDeal, creditcard of Stuvia-tegoed voor de samenvatting. Zonder lidmaatschap.

Focus op de essentie

Focus op de essentie

Samenvattingen worden geschreven voor en door anderen. Daarom zijn de samenvattingen altijd betrouwbaar en actueel. Zo kom je snel tot de kern!

Veelgestelde vragen

Wat krijg ik als ik dit document koop?

Je krijgt een PDF, die direct beschikbaar is na je aankoop. Het gekochte document is altijd, overal en oneindig toegankelijk via je profiel.

Tevredenheidsgarantie: hoe werkt dat?

Onze tevredenheidsgarantie zorgt ervoor dat je altijd een studiedocument vindt dat goed bij je past. Je vult een formulier in en onze klantenservice regelt de rest.

Van wie koop ik deze samenvatting?

Stuvia is een marktplaats, je koop dit document dus niet van ons, maar van verkoper enk. Stuvia faciliteert de betaling aan de verkoper.

Zit ik meteen vast aan een abonnement?

Nee, je koopt alleen deze samenvatting voor €7,49. Je zit daarna nergens aan vast.

Is Stuvia te vertrouwen?

4,6 sterren op Google & Trustpilot (+1000 reviews)

Afgelopen 30 dagen zijn er 82871 samenvattingen verkocht

Opgericht in 2010, al 14 jaar dé plek om samenvattingen te kopen

Start met verkopen
€7,49
  • (0)
  Kopen