Вы находитесь на странице: 1из 3

Keehang Kwon, Int. J. Comp. Tech. Appl.

, Vol 2 (1), 121-123 ISSN : 2229-6093

Adding a Loop Construct to Prolog

Keehang Kwon
Dept. of Computer Engineering, DongA University
Busan 604-714, Korea
khkwon@dau.ac.kr

Abstract: Prolog have traditionally lacked de- the programmer to express these looping tasks.
vices for the looping tasks. This limitation can To be specific, a sequential-conjunctive-
T
be addressed by using a fragment of Japaridze’s recurrence goal is of the form G where G is
computability logic. We propose SeqProlog, an a goal. Executing this goal has the following in-
extension to Prolog with sequential recurrence tended semantics: execute G repeatedly. All ex-
T
goal formulas. SeqProlog extends Prolog by al- ecutions must succeed for executing G to suc-
T
lowing goals of the form G where G is a goal. ceed.
These goals allow us to specify the looping tasks. On the other hand, a sequential-conjunctive
keywords: Prolog, loop, computability logic goal, introduced in [3], is of the form G1 ∩ G2
where G1 , G2 are goals. Executing this goal has
the following intended semantics: execute both
1 Introduction G1 and G2 in sequence. Both executions must
succeed for executing G1 ∩ G2 to succeed.
The while-loop constructs have been popular in In this paper we present the syntax and se-
imperative languages. Despite its wide use, the mantics of this extended language, show some
while-loop constructs cannot be specified in logic examples of its use.
programming based on classical logic or linear The remainder of this paper is structured as
logic. For example, it is very awkward to specify follows. We describe SeqProlog based on a first-
the following task in Prolog: repeatedly read a order sequential Horn clauses in the next sec-
number N , output the factorial of N until some tion. In Section 3, we present some examples of
negative number is read. SeqProlog. Section 4 concludes the paper.
Dealing with the looping tasks in Prolog is
typically done via the use of recursion in the in-
struction set. One major drawback with these 2 The Language
attempts is that the semantics of the instruction
The language we use is an expanded version
set becomes awkward and complicated. This
of Horn clauses with sequential-conjunctive-
limitation can be overcome only by a new seman-
recurrence goals. It is described by G- and D-
tics for logical formulas, i.e., using Japaridze’s
formulas given by the syntax rules below:
Computability Logic(CL)[2]. CL is a beauti-
ful semantic platform for reinterpreting logic as G ::= A | G ∧ G | G ∨ G | ∃x G | G ∩ G |
a theory of tasks. Formulas in CL stand for T
G
instructions that can carry out some computa-
tional tasks. D ::= A | G ⊃ A | ∀x D | D ∧ D
This paper proposes SeqProlog, an extension
of Prolog with sequential recurrence operators
in goal formulas. Traditionally, Prolog has the In the rules above, A represents an atomic
problem of expressing the while-loop tasks. The formula. A D-formula is called a sequential Horn
class of sequential recurrence operators enables clause.

121
Keehang Kwon, Int. J. Comp. Tech. Appl., Vol 2 (1), 121-123 ISSN : 2229-6093

In the transition system to be considered, G- (6) If G is G1 ∩ G2 , then execute both hP, G1 i


formulas will function as queries and a set of D- and hP, G2 i in sequence. Both executions
formulas will constitute a set of available instruc- must succeed for the current execution to
tions. For this reason, we refer to a G-formula as succeed.
a query, to a set of D-formula as an instruction
G, then execute both hP, Gi
T
set. (7) If G is
and hP, Gi in sequence. Both executions
T
We will present an operational semantics for
this language. These rules in fact depend on the must succeed for the current execution to
top-level constructor in the expression, a prop- succeed.
erty known as uniform provability[5]. It is worth T
noting that this property is preserved by disal- In the above rules, the symbols provides loop-
lowing the disjunctive formulas, existential for- ing executions of instructions: they allow for the
mulas in the instruction set. We disallow the repeated sequential conjunctive execution of the
sequential conjunctive formulas as well in the in- instructions. We conjecture the completeness of
struction set for simplicity. the above procedure with respect to the CL se-
It appears that uniform provability is re- mantics at this stage.
quired only for noninteractive algorithms.
Definition 2.1. Let G be a goal and let P be a 3 Examples
finite set of available instructions. Then the no-
An example of the use of this construct is pro-
tion of executing hP, Gi – executing G relative
vided by the following “factorial” program which
to P – is defined as follows:
contains some basic factorial-handling instruc-
(1) If G is an atom and is identical to an in- tions written in conventional Prolog. Here + is
stance of a program clause in P, then the used for the arithmetic addition and nat(X) is
current execution terminates with a suc- true if X is a natural number.
cess. f act(0, 1). % base case
(2) If G is an atom and an instance of a pro- f act(X + 1, XY + Y ) : − f act(X, Y ) ∧ nat(X).
gram clause in P is of the form G1 ⊃ G,
execute hP, G1 i. This execution must suc-
Our language in Section 2 permits sequential-
ceed for the current execution to succeed.
conjunctive-recurrence operators in goals. This
(3) If G is G1 ∧ G2 , then execute both hP, G1 i allows for repeated sequential interactions be-
and hP, G2 i in parallel. Both executions tween the user and the system. An example
must succeed for the current execution to of the use of this construct is provided by the
succeed. program which repeatedly does the following se-
quential tasks: read a number from the user, and
(4) If G is G1 ∨ G2 , then execute both hP, G1 i then output its factorial number:
and hP, G2 i in parallel. At least one of
these two executions must succeed for the query :.
T
current execution to succeed. % while-loop begin
(read(N )∩
(5) If G is ∃xG1 , then execute hP, [t/x]G1 i f act(N, O)∩
where t is a term. This execution must write(0 f act :0 )∩
succeed for the current execution to suc- write(O)) % while-loop end
ceed.

122
Keehang Kwon, Int. J. Comp. Tech. Appl., Vol 2 (1), 121-123 ISSN : 2229-6093

For example, consider a goal query. Solving this References


goal has the effect of executing query with re-
spect to the instructions in the factorial program. [1] S. Abramsky, “Sequentiality vs concurrency
in Games and Logic”, Mathematical Struc-
tures in Computer Science, vol.13, pp.531–
565, 2003.
4 Conclusion
[2] G. Japaridze, “Introduction to computabil-
In this paper, we have considered an extension ity logic”, Annals of Pure and Applied Logic,
to Prolog with sequential Horn clauses. This ex- vol.123, pp.1–99, 2003.
T
tension allows goals of the form G where G is
a goal. These goals are particularly useful for [3] K. Kwon and S. Hur, “Adding sequential
the looping executions of instructions. Our fu- conjunctions to Prolog”, IJCTA, vol.1, No.1,
ture interest is in a language which extends se- pp.1-3, 2010.
quential hereditary Harrop formulas with these
[4] D. Miller, “A logical analysis of modules in
features[1].
logic programming”, Journal of Logic Pro-
gramming, vol.6, pp.79–108, 1989.

5 Acknowledgements [5] D. Miller, G. Nadathur, F. Pfenning, and


A. Scedrov, “Uniform proofs as a foundation
This work was supported by Dong-A University for logic programming”, Annals of Pure and
Research Fund. Applied Logic, vol.51, pp.125–157, 1991.

123

Вам также может понравиться