0% found this document useful (0 votes)
5 views30 pages

LOG_PROG_G5

The document discusses the cut operator in Prolog, detailing its types: green cuts for efficiency, red cuts that change program output, and harmful cuts that affect correctness. It also covers control flow statements, Prolog's role in natural language processing, and the implementation of expert systems using Prolog. Additionally, it introduces constraint logic programming and its various forms, including tree terms, reals, and finite domains.

Uploaded by

Mary ann Mora
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views30 pages

LOG_PROG_G5

The document discusses the cut operator in Prolog, detailing its types: green cuts for efficiency, red cuts that change program output, and harmful cuts that affect correctness. It also covers control flow statements, Prolog's role in natural language processing, and the implementation of expert systems using Prolog. Additionally, it introduces constraint logic programming and its various forms, including tree terms, reals, and finite domains.

Uploaded by

Mary ann Mora
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 30

GROUP 5

PRESENTATION
CUT OPERATOR
AND COUNTER
FLOW
Cut Operator
The cut, in Prolog, is a goal, written as !, which
always succeeds but cannot be backtracked.
Cuts can prevent unwanted backtracking, which
could add unwanted solutions and/or
space/time overhead to a query.
TYPES OF CUT
OPERATOR

Green cut
The use of a cut that only improves
efficiency is referred to as a green cut. Green
cuts are used to make programs more efficient
without changing program output.

Example:
gamble(X) :- gotmoney(X),!.
gamble(X) :- gotcredit(X), \+
gotmoney(X).
Red cut
A cut that is not a green cut is
referred to as a red cut, for
example:

Example:

gamble(X) :- gotmoney(X),!.
gamble(X) :- gotcredit(X).
Harmful cut
A cut which affects the
correctness of the program is a
harmful cut.

Example:
min(X,Y,X) :- !, X =< Y. % the ! Is
harmful because if Y<X
min(X,Y,Y) :- Y < X. % it will not let to
continue to the second rule and will
fail
Control Flow
Control flow statements manage the execution
order of program instructions.
Control flow statements are fundamental components
of programming languages that allow developers to
control the order in which instructions are executed in
a program. They enable execution of a block of code
multiple times, execute a block of code based on
conditions, terminate or skip the execution of certain
lines of code, etc.
Types of Control Flow

• Sequential - execute statements one after


another.
• Conditional - `if`, `else`, `switch` (execute
based on conditions).
• Loops - `for`, `while`, `do-while` (repeat
statements).
• Jump - `break`, `continue`, `return`
(transfer control).
Prolog for
Natural
Language
Processing
Prolog
- is that it is an abbreviation that stands for logic
programming. Logic programming is a computer
programming paradigm within which the
programme statements convey the facts and
regulations pertaining to various issues within a
formal logic system. For Prolog to automatically
solve a problem, the user is required to define the
problem, they may not specify how to address it.
The user provides clues as part of the Prolog
solution process.
Components Of Prolog

Prolog is especially ideal for


applications that use non-numeric
or symbolic computing. This is the
primary reason for Prolog's usage
as a programming language,
where manipulating symbols and
inferences are important
operations.
Facts
- A fact is an explicit
Examples:
link between two or more
objects and any potential • Leo is a cat.
attributes those items • Kumar likes to go
may have. Facts are, out.
therefore, inherently • I am tall.
deemed true. A period • Ram is happy.
denotes the conclusion of
a fact.
Rules Examples:
A rule is an implied
connection between • The baby is happy if
two items. It is the someone properly
process of isolation of tends to her.
factual statements
with conditional • Gloria is happy if she
clauses. So, the truth sings.
of facts is conditional.
• Loki is thirsty if he is
looking for water.
Queries
Questions concernExamples:
the relationships
between items and • Is Ram happy?
their attributes. • Does Kumar like
to go out?
• Is Leo a cat?
Natural Language Processing

enables more effective interaction between


people and computers. NLP can help computers
understand and interpret human language while
listening to it in real-time. Voice activated
commands on a mobile phone is an example of this
technology in application. NLP extends beyond
spoken languages. It also helps in reading and
comprehending documentation in word processing
systems without physical prints.
Expert
Systems
An expert system
emulates the
decision-making ability of
a human expert.
Example: Animal
Examples:
identification
• If it has a fur and
Our aim is to write an
says woof, then the
expert system that helps
animal is a dog.
us identify animals.
Suppose we have
• If it has a fur and
already obtained the
says meow, then the
following knowledge
animal is a cat.
about animals, which are
rules of inference:
• If it has feathers and
says quack, then the
animal is a duck.
3 Different Ways
to Implement
Expert systems
in Prolog
Direct Prolog implementation
This is straight-forward, using is_true/1 to
emit a question and only proceeding with the
current clause if the user input is the atom
yes:
animal(dog) :- is_true("has fur"), is_true("says woof").
animal(cat) :- is_true("has fur"), is_true("says meow").
animal(duck) :- is_true("has feathers"), is_true("says
quack").
is_true(Q) :-
format("~s?\n", [Q]),
read(yes).
Using a domain-specific language
To solve the shortcoming explained
above, we will now change the
representation of our rules from Prolog
clauses to a custom language that we write
and interpret a bit differently than plain
Prolog. A language that is tailored for a
specific application domain is aptly called a
domain-specific language (DSL).
We shall use the following representation to
represent the knowledge:
We shall use the following
representation to represent the
knowledge:

animals([animal(dog, [is_true("has fur"),


is_true("says woof")]),
animal(cat, [is_true("has fur"), is_true("says
meow")]),
animal(duck, [is_true("has feathers"),
is_true("says quack")])]).
Using a different DSL
Consider now yet another way to solve the
exact same problem. Let us view the animal
identification task as interpreting the following
decision diagram, where dotted lines indicate no,
and plain lines indicate yes:

In this case, the


diagram is in fact a full
binary tree which can
be represented
naturally using Prolog
terms.
For example, let us represent the decision tree as
follows, using a term of the form if_then_else/3 for each
inner node, and animal/1 and false/0 for leaves:

tree(if_then_else("has fur",
if_then_else("says woof",
animal(dog),
if_then_else("says meow",
animal(cat),
false)),
if_then_else("has feathers",
if_then_else("says quack",
animal(duck),
false),
false))).
Constraint
Logical
Programming
Constraint logic programming - is a form of
constraint programming, in which logic programming is
extended to include concepts from constraint satisfaction.
A constraint logic program is a logic program that contains
constraints in the body of clauses. An example of a clause
including a constraint is A(X,Y) :- X+Y>0, B(X), C(Y). In this
clause, X+Y>0 is a constraint; A(X,Y), B(X), and C(Y) are
literals as in regular logic programming. This clause states
one condition under which the statement A(X,Y) holds:
X+Y is greater than zero and both B(X) and C(Y) are true.
Terms and Conditions
Different definitions of terms are used,
generating different kinds of constraint logic
programming: over trees, reals, or finite
domains. A kind of constraint that is always
present is the equality of terms. Such
constraints are necessary because the
interpreter adds t1=t2 to the goal whenever a
literal P(...t1...) is replaced with the body of a
clause fresh variant whose head is P(...t2...).
Tree terms
Constraint logic programming with tree
terms emulates regular logic programming by
storing substitutions as constraints in the
constraint store. Terms are variables, constants,
and function symbols applied to other terms.
The only constraints considered are equalities
and disequalities between terms. Equality is
particularly important, as constraints like t1=t2
are often generated by the interpreter.
Reals
Constraint logic programming with real numbers
uses real expressions as terms. When no function symbols
are used, terms are expressions over reals, possibly
including variables. In this case, each variable can only
take a real number as a value.

Finite domains
Constraint satisfaction problem
The third class of constraints used in constraint logic
programming is that of finite domains. Values of
variables are in this case taken from a finite domain,
often that of integer numbers.
THANK YOU
FOR LISTENING 🥰

You might also like