LOG_PROG_G5
LOG_PROG_G5
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
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 🥰