Logic Programming and Symbolic Logic

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Listen to an AI-generated conversation about this lesson
Download our mobile app to listen on the go
Get App

Questions and Answers

Which of the following best describes the approach of logic programming languages?

  • Stating the desired result without specifying how to obtain it. (correct)
  • Employing algorithms optimized for speed and memory usage.
  • Using mathematical equations to define program logic.
  • Specifying detailed procedures to achieve a result.

What constitutes a proposition in the context of logic programming?

  • A logical statement that can be either true or false. (correct)
  • A function call that returns a boolean value.
  • A comment within the code explaining a function.
  • A data structure used to store variables.

In symbolic logic, what is the purpose of 'predicate calculus'?

  • To optimize the performance of logical operations.
  • To translate logical statements into machine code.
  • To define the syntax of a programming language.
  • To provide a particular form of symbolic logic used for logic programming. (correct)

How do variables in logic programming differ from those in imperative languages?

<p>Logic programming variables can represent different objects at different times, unlike imperative variables. (A)</p>
Signup and view all the answers

What are the two main components of a compound term in logic programming?

<p>Functor and parameters. (A)</p>
Signup and view all the answers

In predicate calculus, what distinguishes a 'fact' from a 'query'?

<p>A fact is a proposition assumed to be true, while a query seeks to determine the truth of a proposition. (C)</p>
Signup and view all the answers

Which logical operator represents 'a implies b'?

<p>$\supset$ (A)</p>
Signup and view all the answers

What does the universal quantifier ($\forall$) signify in predicate calculus?

<p>The proposition is true for all possible values. (C)</p>
Signup and view all the answers

Why is the concept of 'clausal form' important in logic programming?

<p>It provides a standard form for propositions, simplifying automated reasoning. (B)</p>
Signup and view all the answers

What is the primary role of 'resolution' in predicate calculus?

<p>To allow inferred propositions to be computed from given propositions. (C)</p>
Signup and view all the answers

In the context of resolution, what is 'unification'?

<p>Finding values for variables that allow propositions to match and the process to succeed. (C)</p>
Signup and view all the answers

What is the purpose of 'proof by contradiction' in theorem proving?

<p>To prove a theorem by finding an inconsistency when its negation is assumed. (B)</p>
Signup and view all the answers

What are the two forms of a 'Horn clause'?

<p>Headed and headless. (D)</p>
Signup and view all the answers

What does 'declarative semantics' refer to in logic programming?

<p>The meaning of each statement can be determined in a simple way. (A)</p>
Signup and view all the answers

Logic programming is considered 'nonprocedural'. What does this entail?

<p>The program defines the form of the result, not the process to compute it. (D)</p>
Signup and view all the answers

Which universities were pivotal in the development of Prolog?

<p>University of Aix-Marseille and University of Edinburgh. (C)</p>
Signup and view all the answers

In Prolog, what are the two possible forms an atom can take?

<p>String of letters, digits, and underscores beginning with a lowercase letter or a string of printable ASCII characters delimited by apostrophes. (C)</p>
Signup and view all the answers

In Prolog, what does the term 'instantiation' refer to?

<p>The binding of a variable to a value. (D)</p>
Signup and view all the answers

What is the purpose of 'fact statements' in Prolog?

<p>To define the hypotheses, assumed to be true. (D)</p>
Signup and view all the answers

What is the function of the 'antecedent' in a rule statement?

<p>It represents the 'if' part of the rule. (B)</p>
Signup and view all the answers

What is the effect of using variables in Prolog rules?

<p>It generalizes the rule's meaning to apply to universal objects. (C)</p>
Signup and view all the answers

What is the purpose of a 'goal statement' in Prolog?

<p>To express a proposition that the system should prove or disprove. (E)</p>
Signup and view all the answers

In Prolog's inferencing process, what is a 'subgoal'?

<p>Each of the facts if a goal is a compound proposition. (D)</p>
Signup and view all the answers

What is 'matching' in the context of Prolog's inferencing process?

<p>Proving the truth of a subgoal. (C)</p>
Signup and view all the answers

What distinguishes 'bottom-up resolution' from 'top-down resolution' in logic programming?

<p>Bottom-up resolution begins with known facts, while top-down begins with the goal. (D)</p>
Signup and view all the answers

What type of search strategy does Prolog primarly use?

<p>Depth-first search. (B)</p>
Signup and view all the answers

In Prolog, what is 'backtracking'?

<p>Reconsidering previous subgoals to find alternative solutions when a subgoal fails. (A)</p>
Signup and view all the answers

How is the is operator used in Prolog arithmetic?

<p>To assign the value of an arithmetic expression to a variable. (A)</p>
Signup and view all the answers

What is the purpose of the 'trace' feature in Prolog?

<p>To display instantiations at each step of the execution. (C)</p>
Signup and view all the answers

What does the notation [Head | Tail] represent in Prolog?

<p>A list structure with a head and a tail. (D)</p>
Signup and view all the answers

What does the underscore character _ signify when used within a Prolog rule or fact?

<p>An anonymous variable. (A)</p>
Signup and view all the answers

What is the 'closed-world assumption' in Prolog?

<p>The only knowledge available is what is explicitly stated in the database. (A)</p>
Signup and view all the answers

Which of the following are example application areas of logic programming?

<p>Relational database management systems, expert systems, and natural language processing. (C)</p>
Signup and view all the answers

Which statements accurately reflect the summary of Logic Programming?

<p>Symbolic Logic provides the basis, logic programs are nonprocedural, Prolog statements are facts/rules/goals, resolution is the primary activity. (B)</p>
Signup and view all the answers

What is a key deficiency of Prolog related to control?

<p>Resolution Order Control (D)</p>
Signup and view all the answers

What are the four tracing models?

<p>Call, Exit, Redo, Fail (A)</p>
Signup and view all the answers

Flashcards

Logic Language Programs

Programs in logic languages are expressed in symbolic logic.

Logical Inferencing

Using a logical inferencing process to produce results.

Declarative Programming

Only specification of results are stated, the procedures are not.

Proposition

A logical statement that may or may not be true.

Signup and view all the flashcards

Symbolic Logic

Logic used for the basic needs of formal logic, expressing propositions and relationships.

Signup and view all the flashcards

Predicate Calculus

A particular form of symbolic logic used for logic programming.

Signup and view all the flashcards

Object Representation

Represent objects in propositions.

Signup and view all the flashcards

Constant

A symbol that represents an object.

Signup and view all the flashcards

Variable

A symbol that can represent different objects at different times.

Signup and view all the flashcards

Compound Term

One element of a mathematical relation, written like a mathematical function.

Signup and view all the flashcards

Functor

The function symbol that names the relationship in a compound term.

Signup and view all the flashcards

Fact Propositions

Propositions that are assumed to be true.

Signup and view all the flashcards

Query Propositions

Propositions where the truth is to be determined.

Signup and view all the flashcards

Compound Propositions

Propositions having two or more atomic propositions.

Signup and view all the flashcards

Negation

¬a

Signup and view all the flashcards

Conjunction

a ∩ b

Signup and view all the flashcards

Disjunction

a ∪ b

Signup and view all the flashcards

Universal Quantifier

∀X.P

Signup and view all the flashcards

Existential Quantifier

∃X.P

Signup and view all the flashcards

Clausal Form

A standard form for propositions, B₁ ∪ B₂ ∪ ... ∪ Bₙ ⊂ A₁ ∩ A₂ ... ∩ Aₘ

Signup and view all the flashcards

Antecedent

The right side of the clause, the 'if' part.

Signup and view all the flashcards

Consequent

The left side of the clause.

Signup and view all the flashcards

Predicate Calculus

Discovering new theorems inferred from known axioms and theorems.

Signup and view all the flashcards

Resolution

An inference principle that allows inferred propositions to be computed from given propositions.

Signup and view all the flashcards

Unification

Finding values for variables in propositions that allows matching process to succeed.

Signup and view all the flashcards

Instantiation

Assigning temporary values to variables to allow unification to succeed.

Signup and view all the flashcards

Hypotheses

A set of pertinent propositions in proof by contradiction.

Signup and view all the flashcards

Goal

Negation of theorem stated as a proposition in proof by contradiction.

Signup and view all the flashcards

Theorem Proving

Basis for logic programming, restricted form.

Signup and view all the flashcards

Horn Clause

Can have only two forms, headed and headless.

Signup and view all the flashcards

Headed Horn Clause

Single atomic proposition on the left side.

Signup and view all the flashcards

Headless Horn Clause

Empty left side (used to state facts).

Signup and view all the flashcards

Declarative Semantics

There is a simple way to determine the meaning of each statement.

Signup and view all the flashcards

Nonprocedural Programming

Programs do not state how a result is computed, but rather the form of the result.

Signup and view all the flashcards

Origins of Prolog

University of Aix-Marseille (Calmerauer & Roussel) for natural language processing.

Signup and view all the flashcards

Term

A constant, variable, or a structure.

Signup and view all the flashcards

Constant

An atom or an integer.

Signup and view all the flashcards

Atom

Symbolic value of Prolog.

Signup and view all the flashcards

Variable

Any string of letters, digits, and underscores beginning with an uppercase letter.

Signup and view all the flashcards

Instantiation

Binding of a variable to a value.

Signup and view all the flashcards

Study Notes

Introduction

  • Logic languages are expressed in a form of symbolic logic.
  • Logical referencing is used to produce results.
  • Logic languages are declarative, meaning only results are specified, not the procedures.

Proposition

  • A proposition is a logical statement that may or may not be true.
  • Propositions consist of objects and relationships between objects.

Symbolic Logic

  • Symbolic logic expresses propositions.
  • Symbolic logic expresses relationships between propositions.
  • Symbolic logic describes how propositions can be inferred from other propositions.
  • Predicate calculus is a form of symbolic logic used for logic programming.

Object Representation

  • Objects in propositions are represented by simple terms consisting of constants and variables.
  • A constant is a symbol that represents an object.
  • A variable is a symbol that can represent different objects at different times.
  • Object representation in logic programming is different from variables in imperative languages.

Compound Terms

  • Atomic propositions consist of compound terms.
  • A compound term is one element of a mathematical relation, written like a mathematical function.
  • Mathematical functions are a mapping that can be written as a table.

Parts of a Compound Term

  • Compound terms are composed of a functor and an ordered list of parameters (tuple).
  • The functor is a function symbol that names the relationship.
  • Examples include student(jon), like(seth, OSX), like(nick, windows), like(jim, linux).

Forms of a Proposition

  • Propositions can be stated as facts or queries.
  • A fact is a proposition assumed to be true.
  • A query is a proposition whose truth is to be determined.
  • Compound propositions have two or more atomic propositions.
  • Propositions are connected by operators.

Logical Operators

  • Negation: ¬a (not a)
  • Conjunction: a ∩ b (a and b)
  • Disjunction: a ∪ b (a or b)
  • Equivalence: a = b (a is equivalent to b)
  • Implication: a ⊃ b (a implies b), a ⊂ b (b implies a)

Quantifiers

  • Universal: ∀X.P (For all X, P is true)
  • Existential: ∃X.P (There exists a value of X such that P is true)

Clausal Form

  • Clausal form is a standard form for propositions.
  • B₁ ∪ B₂ ∪ ... ∪ Bₙ ⊂ A₁ ∩ A₂ ∩ ... ∩ Aₘ means if all the As are true, then at least one B is true
  • Antecedent is the right side of the expression.
  • Consequent is the left side of the expression.

Predicate Calculus and Proving Theorems

  • Propositions are used to discover new theorems that can be inferred from known axioms and theorems.
  • Resolution is an inference principle that allows inferred propositions to be computed from given propositions.

Resolution

  • Unification finds values for variables that allows a matching process to succeed.
  • Instantiation assigns temporary values to the variable to allow unification to succeed.
  • Backtracking is sometimes required if the matching fails after instantiating a variable, and a different value needs to be instantiated.

Proof by Contradiction

  • Hypotheses: set of pertinent propositions.
  • Goal: theorem negation stated as a proposition.
  • Theorem proven by finding an inconsistency.

Theorem Proving

  • Theorem proving is the basis for logic programming.
  • When propositions are used for resolution, only a restricted form can be used.
  • Horn clauses have only two forms: headed and headless.
  • Headed: single atomic proposition on left side.
  • Headless: empty left side (used to state facts).
  • Most propositions can be stated as Horn clauses.

Overview of Logic Programming

  • Declarative semantics: a simple way to determine the meaning of each statement that is simpler than the semantics of imperative languages.
  • Programming is nonprocedural: Programs do not state how a result is to be computed, but rather the form of the result.

Example: Sorting a List

  • Describe the characteristics of a sorted list, not the process of rearranging a list i.e. sort(old_list, new_list) ⊂ permute (old_list,new_list) ∩ sorted (new_list)
  • The formula* sorted (list) ⊂ ∀j such that 1≤ j < n, list(j) ≤ list (j+1)* is an example of describing the characteristics of a sorted list.

The Origins of Prolog

  • University of Aix-Marseille (Calmerauer & Roussel): Natural language processing
  • University of Edinburgh (Kowalski): Automated theorem proving

Terms

  • Edinburgh syntax of Prolog is used.
  • A term is a constant, variable, or structure.
  • A constant is an atom or an integer.
  • An atom is a symbolic value of Prolog and consists of a string of letters, digits, and underscores beginning with a lowercase letter or a string of printable ASCII characters delimited by apostrophes.

Terms: Variables and Structures

  • A variable is any string of letters, digits, and underscores beginning with an uppercase letter.
  • Instantiation is the binding of a variable to a value and lasts only as long as it takes to satisfy one complete goal.
  • Structure represents atomic proposition functor (parameter list)

Fact Statements

  • Fact statements are used for the hypotheses.
  • They are headless Horn clauses i.e. female(shelley)., male(bill)., father(bill, jake).

Rule Statements

  • Rule statements are used for the hypotheses.
  • They are headed Horn clauses
  • The right side of a rule statement is the antecedent (if part) which may be single term or conjunction
  • The left side of a rule statement is the consequent (then part) which must be single term
  • Conjunction is multiple terms separated by logical AND operations (implied).

Example Rules

  • Variables can be used to generalize meaning i.e. universally quantified objects.
  • parent(X,Y):- mother(X,Y). is an example of a rule statement.
  • grandparent(X,Z):- parent(X,Y), parent(Y,Z). is an example of a rule statement.

Goal Statements

  • For theorem proving, a theorem is in the form of a proposition that is to be proven or disproven via a goal statement.
  • Goal statements have the same format as headless Horn clauses i.e. man(fred)
  • Conjunctive propositions and propositions with variables are also legal goals i.e. father(X, mike)

Inferencing Process of Prolog

  • Queries are called goals.
  • If a goal is a compound proposition, each of the facts is a subgoal.
  • To prove a goal is true, a chain of inference rules and/or facts.
  • Proving a subgoal is called matching, satisfying, or resolution.

Approaches

  • Matching is the process of proving a proposition.
  • Proving a subgoal is called satisfying the subgoal.
  • Bottom-up resolution is forward chaining which begins with facts and rules of database and finds sequence that leads to goal effectively for large sets of correct answers
  • Top-down resolution, or backward chaining, begins with a goal and attempts to find sequence that leads to set of facts in database, effective for small sets of correct answers
  • Prolog implementations use backward chaining.

Subgoal Strategies

  • When a goal has more than one subgoal, either depth-first or breadth-first search strategies can be used.
  • Depth-first search finds a complete proof for the first subgoal before working on others.
  • Breadth-first search works on all subgoals in parallel.
  • Prolog uses depth-first search and can be done with fewer computer resources.

Backtracking

  • When one of multiple subgoals cannot be satisfied, the previous subgoal is reconsidered to find an alternate solution.
  • Begin search where previous search left off.
  • Backtracking can take lots of time and space because all possible proofs to every subgoal may need to be found.

Simple Arithmetic

  • Prolog supports integer variables and integer arithmetic.
  • is operator takes an arithmetic expression as right operand and variable as left operand.
  • A is operator is not the same as an assignment statement

Example

speed(ford,100).
speed(chevy,105).
speed(dodge,95)
speed(volvo,80).
time(ford,20)
time(chevy,21).
time(dodge,24).
time(volvo,24).
distance(X,Y) :- speed(X,Speed), time(X,Time), Y is Speed * Time.
  • Distance is computed as Speed * Time
  • A query example is distance(chevy, Chevy_Distance).

Trace

  • A trace is a built-in structure that displays instantiations at each step.
  • The tracing model of execution includes four events: Call, Exit, Redo, Fail.
  • Call is the beginning of attempt to satisfy goal.
  • Exit is when a goal has been satisfied.
  • Redo is when backtrack occurs.
  • Fail is when goal fails.

Example

likes(jake,chocolate).
likes(jake, apricots)
likes(darcie, licorice).
likes(darcie, apricots)
trace.
likes(jake, X), likes(darcie, X).
(1) 1 Call: likes(jake, _0)?
(1) 1 Exit: likes(jake, chocolate)
(2) 1 Call: likes(darcie, chocolate)?
(2) 1 Fail: likes(darcie, chocolate)
(1) 1 Redo: likes(jake, _0)?
(1) 1 Exit: likes(jake, apricots)
(3) 1 Call: likes(darcie, apricots)?
(3) 1 Exit: likes(darcie, apricots)
X = apricots

List Structures

  • List is a basic data structure (besides atomic propositions we have already seen) which is a sequence of elements.
  • Elements can be atoms, atomic propositions, or other terms (including other lists)
  • [apple, prune, grape, kumquat] is a list of atoms
  • [] an empty list
  • [X | Y] is the head X and tail Y

Append Example

append([], List, List).
append([Head | List_1], List_2, [Head | List_3]) :-
append (List 1, List 2, List 3).

More Examples

  • Underscore character means an anonymous variable, meaning instantiation does not matter.
reverse([], []).
reverse([Head | Tail], List) :-
reverse (Tail, Result),
append (Result, [Head], List).

member(Element, [Element | _]).

member(Element, [_ | List]) :-
member(Element, List).

Deficiencies of Prolog

  • Resolution order control

  • Order Matches are non deterministic as all matches would be attempted concurrently in a pure logic programming environment

  • In Closed-world assumption the only knowledge is what in the database.

  • Negation Problem in which Anything not stated in the database is assumed to be false

  • Intrinsic limitations

  • It is easy to state a sort process in logic, but does not know how to sort.

Applications of Logic Programming

  • Relational database management systems
  • Expert systems
  • Natural language processing

Summary

  • Symbolic logic provides the basis for logic programming.
  • Logic programs should be nonprocedural.
  • Prolog statements are facts, rules, or goals.
  • Resolution is the primary activity of a Prolog interpreter.
  • Although there are a number of drawbacks with the current state of logic programming, it has been used in a number of areas.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

More Like This

Use Quizgecko on...
Browser
Browser