**2. Motivating examples**

2 Will-be-set-by-IN-TECH

failure of a goal is often caused by non-failing subgoals that do not compute all the expected

In contrast to recent approaches to error diagnosis using *abstract interpretation* (e.g., (Alpuente et al., 2003; Comini et al., 1999; Hermenegildo, 2002), and some of the approaches described in (Deransart et al., 2000)), declarative diagnosis often involves complex queries to the user. This problem has been tackled by means of various techniques, such as user-given partial specifications of the program's semantics (Boye et al., 1997), safe inference of information from answers previously given by the user (Caballero & Rodríguez, 2004), or *CT*s tailored to the needs of a particular debugging problem over a particular computation domain (Ferrand et al., 2003). Another practical problem with declarative diagnosis is that the size of *CT*s can cause excessive overhead in the case of computations that demand a big amount of computer storage. As a remedy, techniques for piecemeal construction of *CT*s have been considered; see (Pope, 2006) for a recent proposal in the *FP* field. However, current research in declarative diagnosis has still to face many challenges regarding both the foundations and

In spite of the above mentioned difficulties, we are confident that declarative diagnosis methods can be useful for detecting programming bugs by observing computations whose demand of computer storage is modest. The aim of this chapter is to present a logical and semantic framework for diagnosing wrong and missing computed answers in *CFLP*(D) (López et al., 2006), a newly proposed generic programming scheme for lazy *Constraint Functional-Logic Programming* which can be instantiated by any constraint domain D given as parameter, and supports a powerful combination of functional and constraint logic programming over D. Sound and complete goal solving procedures for the *CFLP*(D) scheme have been obtained (López et al., 2004). Moreover, useful instances of this scheme have been implemented in the T OY system (López & Sánchez, 1999) and tested in practical applications (Fernández et al., 2007). Borrowing ideas from *CFLP*(D) declarative semantics we obtain a suitable notion of *intended interpretation*, as well as a kind of abridged *proof trees* with a sound logical meaning to play the role of *CT*s. Our aim is to achieve a natural combination of previous approaches that were independently developed for the *CLP*(D) scheme (Tessier & Ferrand, 2000) and for lazy functional-logic languages (Caballero & Rodríguez, 2004). We give theoretical results showing that the proposed debugging method is logically correct for any sound *CFLP*(D)-system whose computed answers are logical consequences of the program in the sense of *CFLP*(D) semantics. We also present a practical debugger called DDT , developed as an extension of previously existing but less powerful tools (Caballero, 2005; Caballero & Rodríguez, 2004). DDT implements the proposed diagnosis method for *CFLP*(R)-programming in the T OY system (López & Sánchez, 1999) using the domain R of

The rest of the chapter is organized as follows: Section 2 motivates our approach by presenting debugging examples which are used as illustration of the main features of our diagnosis method. Section 3 recalls the *CFLP*(D) scheme from (López et al., 2006) to the extent needed for understanding the theoretical results in this chapter. Section 4 presents a correct method for the declarative diagnosis of wrong computed answers in any soundly implemented *CFLP*(D)-system. Section 5 describes the debugging tool DDT for wrong answers. Section 6 presents the abbreviated proof trees used as *CT*s in our method for debugging missing

answers.

the development of practical tools.

arithmetic constraints over the real numbers.

As a motivation for our declarative debugging method of wrong answers in the *CFLP*(D) scheme, we consider the following program fragment written in T OY (López & Sánchez, 1999), a programming system which supports several instances of the *CFLP*(D) scheme:
