Concepts+Techniques+and+Models+of+Computer+Programming_Part24

# Concepts+Techniques+and+Models+of+Computer+Programming_Part24

This preview shows pages 1–3. Sign up to view the full content.

648 Relational Programming correct deductions from the axioms. That is, the results of all predicates are valid tuples in the predicates’ relations. We call this deterministic logic programming . Table 9.2 deﬁnes a translation scheme T which translates any statement ± s ² in the relational kernel language into a logical formula T ( ± s ² ). Procedure deﬁnitions are translated into predicate deﬁnitions. Note that exceptions are not translated. Raising an exception signals that the normal, logical execution is no longer valid. The logical sentence therefore does not hold in that case. Proving the correctness of this table is beyond the scope of this chapter. We leave it as an interesting exercise for mathematically-minded readers. A given logical semantics can correspond to many operational semantics. For example, the following three statements: 1. X=Y ± s ² 2. ± s ² X=Y 3. if X==Y then ± s ² else fail end all have the exactly same logical semantics, namely: x = y T ( ± s ² ) But their operational semantics are very diﬀerent! The ﬁrst statement binds X and Y andthenexecutes ± s ² . The second statement executes ± s ² and then binds X and Y . The third statement waits until it can determine whether or not X and Y are equal. It then executes ± s ² , if it determines that they are equal. Writing a logic program consists of two parts: writing the logical semantics and then choosing an operational semantics for it. The art of logic program- ming consists in balancing two conﬂicting tensions: the logical semantics should be simple and the operational semantics should be eﬃcient. All the declarative programs of Chapters 3 and 4 can be seen in this light. They are all logic pro- grams. In the Prolog language, this has given rise to a beautiful programming style [182, 21, 139]. Deterministic append Let us write a simple logic program to append two lists. We have already seen the Append function: fun {Append A B} case A of nil then B [] X|As then X|{Append As B} end end Let us expand it into a procedure: Copyright c ³ 2001-3 by P. Van Roy and S. Haridi. All rights reserved.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
9.3 Relation to logic programming 649 Relational statement Logical formula skip true fail false ± s ² 1 ± s ² 2 T ( ± s ² 1 ) T ( ± s ² 2 ) local X in ± s ² end x.T ( ± s ² ) X=Y x = y X=f(l1:X1 . .. ln:Xn) x = f ( l 1 : x 1 , ..., l n : x n ) if X then ± s ² 1 else ± s ² 2 end ( x = true T ( ± s ² 1 )) ( x = false T ( ± s ² 2 )) case X of f(l1:X1 . .. ln:Xn) ( x 1 , ..., x n .x = f ( l 1 : x 1 , ..., l n : x n ) T ( ± s ² 1 )) then ± s ² 1 else ± s ² 2 end ( ¬∃ x 1 , ..., x n .x = f ( l 1 : x 1 , ..., l n : x n ) T ( ± s ² 2 )) proc {P X1 . .. Xn} ± s ² end x 1 , ..., x n .p ( x 1 , ..., x n ) T ( ± s ² ) {P Y1 . .. Yn} p ( y 1 , ..., y n ) choice ± s ² 1 [] . .. [] ± s ² n end T ( ± s ² 1 ) ... T ( ± s ² n ) Table 9.2: Translating a relational program to logic proc {Append A B ?C} case A of nil then C=B [] X|As then Cs in C=X|Cs {Append As B Cs} end end According to Table 9.2, this procedure has the following logical semantics: a, b, c. append ( a, b, c ) ( a = nil c = b ) ( x, a ± ,c ± .a = x | a ± c = x | c ± append ( a ± ,b,c ± ))
This is the end of the preview. Sign up to access the rest of the document.

## This document was uploaded on 08/10/2011.

### Page1 / 30

Concepts+Techniques+and+Models+of+Computer+Programming_Part24

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online