100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Summary Logic programming summaries ALL weeks 1-6 $8.03
Add to cart

Summary

Summary Logic programming summaries ALL weeks 1-6

 10 views  0 purchase
  • Course
  • Institution

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.

Preview 3 out of 19  pages

  • May 23, 2023
  • 19
  • 2022/2023
  • Summary
avatar-seller
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)

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller enk. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $8.03. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

53068 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$8.03
  • (0)
Add to cart
Added