universidad complutense de madrid programación declarativa

Loading...

UNIVERSIDAD COMPLUTENSE DE MADRID FACULTAD DE INFORMÁTICA Departamento de Sistemas Informáticos y Computación

PROGRAMACIÓN DECLARATIVA CUALIFICADA CON RESTRICCIONES. MEMORIA PARA OPTAR AL GRADO DE DOCTOR PRESENTADA POR

Carlos Alberto Romero Díaz Bajo la dirección de los doctores Rafael Caballero Mario Rodríguez Artalejo Madrid, 2011 ISBN: 978-84-694-5111-3

© Carlos Alberto Romero Díaz, 2011

PROGRAMACIÓN DECLARATIVA CUALIFICADA CON RESTRICCIONES

Teſis doctoral preſentada por el doctorando

Carlos • Alberto • Romero • Díaz

para la obtención del título de doctor en Ingeniería Informática en el departamento de Siſtemas Informáticos y Computación de la Universidad Complutense de Madrid

Dirigida por los profeſores R. Caballero & M. Rodríguez Artalejo. Terminada en Madrid el día viernes 14enerommxi

Programación declarativa cualificada con restricciones Carlos Alberto Romero Díaz DSIC ♣ UCM

Tesis doctoral en formato publicaciones presentada por el doctorando Carlos A. Romero Díaz en el Departamento de Sistemas Informáticos y Computación de la Universidad Complutense de Madrid para la obtención del título de doctor en ingeniería informática. Terminada en Madrid el 14 de enero de 2011.

Título: Programación declarativa cualificada con restricciones Doctorando: Carlos A. Romero Díaz ([email protected]) Departamento de Sistemas Informáticos y Computación, Universidad Complutense Facultad de Informática, 28040 Madrid, España

Directores: Rafael Caballero ([email protected]) Mario Rodríguez Artalejo ([email protected]) Esta tesis doctoral ha sido realizada dentro del grupo de investigación sobre Programación Declarativa (grupo 910502 del catálogo de grupos reconocidos por la UCM) como parte de las actividades del proyecto de investigación Foundations and Applications of Declarative Software Technologies – Software Tools and Multiparadigm Programming (FAST-STAMP, referencia TIN2008-06622-C03-01).

Agradecimientos La realización de esta tesis no hubiera sido posible sin la ayuda y colaboración de muchas personas e instituciones que han contribuido, de un modo u otro, a fomentar, facilitar y permitir mi trabajo de investigación. No quisiera por ello perder esta oportunidad para mostrar mi agradecimiento a Mario y Rafa, mis directores, por su inestimable ayuda, por su colaboración en el trabajo y por la confianza depositada en mi; a Paco por haberlo hecho posible; al GPD y al DSIC por haberme permitido desarrollar mi labor; a mis compañeros del 220 por el inmejorable ambiente de trabajo; a mis amigos, especialmente a Laura, por haber estado ahí cuando hacían falta y cuando no; a mis padres y mi familia, por haber sido los principales artífices de la persona que soy y sin los cuales no hubiera podido llegar hasta aquí; y, finalmente, a Xavi.

Índice Resumen

6

1. Introducción 1.1. Programación declarativa . . . . . . . . . . . . . . . . . . 1.2. Programación declarativa con incertidumbre . . . . . . . . 1.2.1. Programación lógica cuantitativa . . . . . . . . . 1.2.2. Programación lógica anotada . . . . . . . . . . . 1.2.3. Programación lógica multi-valuada . . . . . . . . . 1.2.4. Programación lógica con similaridad . . . . . . . . 1.2.5. Otros marcos de programación con incertidumbre . 1.3. Objetivos . . . . . . . . . . . . . . . . . . . . . . . . . . 1.4. Contribuciones principales . . . . . . . . . . . . . . . . . . 1.5. Organización de la tesis . . . . . . . . . . . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

7 7 9 10 11 11 13 14 14 15 17

2. Programación lógica con cualificación 2.1. Dominios de cualificación . . . . . . . . . . . . 2.2. Sintaxis . . . . . . . . . . . . . . . . . . . . . 2.3. Semántica declarativa . . . . . . . . . . . . . . 2.3.1. Interpretaciones y modelos . . . . . . . 2.3.2. Semántica de punto fijo . . . . . . . . 2.3.3. Semántica basada en un cálculo lógico 2.3.4. Objetivos y soluciones . . . . . . . . . 2.4. Resolución de objetivos . . . . . . . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

18 19 22 25 25 27 28 29 30

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

3. Programación lógica con cualificación y similaridad 3.1. Relaciones de similaridad . . . . . . . . . . . . . . . . . 3.2. Sintaxis . . . . . . . . . . . . . . . . . . . . . . . . . . 3.3. Semántica declarativa . . . . . . . . . . . . . . . . . . . 3.3.1. Interpretaciones y modelos . . . . . . . . . . . . 3.3.2. Semántica basada en un cálculo lógico . . . . . 3.3.3. Objetivos y soluciones . . . . . . . . . . . . . . 3.4. Transformación de SQLP-programas en QLP-programas

. . . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

33 34 36 37 38 40 41 42

4. Programación lógico-funcional con restricciones y cualificación 4.1. Dominios de restricciones . . . . . . . . . . . . . . . . . . . 4.2. Sintaxis . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.3. Semántica declarativa . . . . . . . . . . . . . . . . . . . . . 4.3.1. Semántica basada en una lógica de reescritura . . . 4.3.2. Objetivos y soluciones . . . . . . . . . . . . . . . . 4.4. Transformación de QCFLP-programas en CFLP-programas . 4.4.1. Transformación de expresiones . . . . . . . . . . . . 4.4.2. Transformación de qc-declaraciones . . . . . . . . . 4.4.3. Transformación de reglas de programa . . . . . . . . 4.4.4. Transformación de objetivos . . . . . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

47 48 50 51 52 54 55 57 58 59 60

4

. . . . . . .

5. Programación lógica con restricciones, cualificación y 5.1. Base computacional . . . . . . . . . . . . . . . . . 5.2. Sintaxis . . . . . . . . . . . . . . . . . . . . . . . 5.3. Semántica declarativa . . . . . . . . . . . . . . . . 5.3.1. Interpretaciones y modelos . . . . . . . . . 5.3.2. Semántica de punto fijo . . . . . . . . . . 5.3.3. Semántica basada en un cálculo lógico . . 5.3.4. Objetivos y soluciones . . . . . . . . . . . 5.4. Casos particulares . . . . . . . . . . . . . . . . . . 6. Implementación práctica 6.1. El sistema (S)QCLP . . . . . . . 6.1.1. Ejecución 1: Números de 6.1.2. Ejecución 2: Obras . . . 6.2. Otros prototipos . . . . . . . . .

. . . . Peano . . . . . . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

proximidad . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . . . . . .

. . . .

. . . . . . . .

. . . .

. . . . . . . .

. . . .

. . . . . . . .

. . . .

. . . . . . . .

. . . .

. . . . . . . .

61 61 63 64 65 67 67 69 70

. . . .

70 71 74 75 76

7. Conclusiones y trabajo futuro

77

Referencias

80

A. Publicaciones A.1. Quantitative logic programming revisited . . . . . . . . . . . . A.2. Qualified logic programming with bivalued predicates . . . . . A.3. Similarity-based reasoning in qualified logic programming . . . A.4. Qualified computations in functional logic programming . . . . A.5. Declarative semantics for CLP with qualification and proximity B. Recursos adicionales B.1. A generic scheme for QLP (TR) . . . . . . . . . . . . . . B.2. Similarity-based reasoning in QLP (RE) . . . . . . . . . . B.3. A generic scheme for QCFLP (TR) . . . . . . . . . . . . B.4. Fixpont & proof-theoretic semantics for SQCLP (TR) . . B.5. A transformation-based implementation for SQCLP (TR) (TR) (RE)

Informe técnico Edición revisada

5

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

85 86 103 119 129 144

. . . . .

160 161 184 194 230 277

Resumen La incorporación del razonamiento con incertidumbre a la programación declarativa y, en especial, a la programación lógica ha sido objeto de investigación en las últimas décadas. En este periodo, se han aportado diversas propuestas con este propósito así como diferentes aplicaciones prácticas de estas propuestas. Al mismo tiempo, los esquemas CLP y CFLP de la programación lógica con restricciones y la programación lógico-funcional con restricciones, respectivamente, se han convertido en potentes marcos de programación con soporte para computaciones eficientes sobre dominios de restricciones especializados, el primero, y también con funciones perezosas al estilo de las de la programación funcional, el segundo. Sin embargo, han sido escasas las extensiones con incertidumbre que han tomado como punto de partida alguno de los esquemas CLP o CFLP, a pesar de que la potencia de cómputo de los dominios de restricciones sí ha facilitado su implementación práctica. Es por ello objeto de esta tesis la investigación de extensiones con incertidumbre de los esquemas anteriormente mencionados, y por tanto se desarrollan aquí principalmente dos esquemas paramétricos de programación declarativa con incertidumbre: una extensión con cualificación y proximidad del marco CLP; y una extensión con cualificación de programas CFLP de primer orden. Para los esquemas de programación aquí desarrollados se aportan dos caracterizaciones equivalentes de la semántica declarativa — una de punto fijo a partir de un transformador de interpretaciones y otra basada en un cálculo lógico o una lógica de reescritura, según sea el esquema de partida. Se aportan también una noción declarativa de objetivo y solución, y diferentes métodos de resolución de objetivos basados en técnicas de transformación de programas, que conducen a la obtención de programas y objetivos equivalentes para los que pueden computarse respuestas adecuadas. Estas técnicas de transformación permiten además implementar de manera sencilla y natural distintas instancias útiles de los esquemas propuestos en un prototipo que está públicamente disponible y que, sobre sistemas CLP actuales, hace posible la ejecución de ejemplos y programas propuestos a lo largo de la tesis y la resolución de objetivos arbitrarios para dichos programas. Palabras clave: dominios de cualificación, incertidumbre, programación cualificada, programación lógica, programación lógica con restricciones, programación lógico-funcional con restricciones, relaciones de similaridad, relaciones de proximidad, transformación de programas.

6

1.

Introducción

En la lógica clásica se ha utilizado de manera general dos valores veritativos para indicar cuando una determinada fórmula lógica es consecuencia o deducible a partir de un conjunto de fórmulas lógicas. En este sentido, cuando en una interpretación una fórmula ϕ toma el valor cierto indica que, en efecto, la fórmula es deducible en la interpretación del conjunto de fórmulas iniciales dado, y toma el valor falso en otro caso, i.e. cuando no es deducible. Esta visión de la lógica tiene el inconveniente de que no permite tratar adecuadamente aquellos casos en los que existe una ausencia de información total, o cuando la información disponible no resulta del todo certera. Por ello, han surgido a lo largo de los últimos 30 años una serie de aproximaciones en distintas áreas de la lógica que intentan aportar herramientas adecuadas que permitan tratar con situaciones en las que o bien no se tenga toda la información posible para poder asegurar la veracidad de las informaciones en juego, o bien se acepte que la veracidad de las informaciones puede no ser completa. Así, surgen en general, lógicas específicas y enfoques de programación en los que resulta posible representar distintos grados o niveles de certidumbre para las fórmulas o la información, de manera que permiten trabajar sobre unos niveles de información a partir de los cuales pueden extraerse conclusiones que, de otro modo, no serían posibles.

1.1.

Programación declarativa

La programación declarativa es un paradigma de programación caracterizado por la independencia del orden de evaluación y la eliminación de la asignación y otras estructuras de control características de los lenguajes imperativos. Es común en los lenguajes declarativos evitar en los programas toda indicación a cómo debe procederse para alcanzar los objetivos deseados, limitándose a especificar, en una cierta lógica, qué objetivos han de perseguirse. Por lo tanto, mientras que en el caso de los lenguajes imperativos resulta estrictamente necesario aportar un algoritmo que indique cómo debe ejecutarse cada programa, para los lenguajes declarativos esto no es necesario puesto que el modo de proceder vendrá determinado a partir de las posibilidades de la lógica empleada para describir el programa. A pesar de emplear de manera general el nombre de programación declarativa (DP) para toda una serie de lenguajes de programación no imperativos, resulta más conveniente, y apropiado, distinguir estos lenguajes según sus características en una serie de paradigmas de programación todos ellos declarativos. Entre los paradigmas más comunes encontramos la programación funcional (FP), con raíces en el cálculo lambda [8] y que incluye lenguajes como Haskell [36, 30]; la programación lógica (LP), basada en la lógica matemática aplicada a la computación y que incluye lenguajes como Prolog, para el que existen múltiples implementaciones y sistemas como pueden ser SICStus Prolog [67] o SWI-Prolog [70]; la programación con restricciones (CP), que surgió dentro de la programación lógica aunque ahora puede asociarse a la programación funcional o, incluso, a la programación imperativa, y que podemos encontrar tanto en SICStus Prolog como SWI-Prolog bajo diferentes librerías según sea el dominio de restricciones empleado; y toda una serie de lenguajes que combinan dos o más paradigmas como es el caso de la programación lógica con restricciones (CLP) o la programación lógico-funcional (FLP) y su versión con restricciones (CFLP). Son representantes de este último caso los lenguajes Toy [6] y Curry [29].

7

A modo de ilustración, considérese los dos siguientes ejemplos en los que se define la función matemática factorial en Prolog y Haskell, respectivamente. Ejemplo 1.1 (Factorial; I). Predicado que calcula el factorial de un número natural n en Prolog. 1 2

factorial(0, 1). factorial(N, F ) :− N>0, N1 is N−1, factorial(N1 , F1 ), F is N∗F1 .

Ejemplo 1.2 (Factorial; II). Función que calcula el factorial de un número natural n en Haskell. 1 2

factorial 0 = 1 factorial n = n ∗ factorial (n−1)

Como ya se indicó, en el caso de los lenguajes declarativos no se hace explícito junto a los programa el cómo proceder en cada caso, sino el qué debe hacerse. Esto puede verse en los dos ejemplos anteriores por los motivos siguientes: En el caso de Prolog, y de la programación lógica, se dice que un átomo es derivable de un programa cuando es posible probarlo a partir del conjunto de hechos y cláusulas del programa. En el ejemplo anterior, factorial(0, 1) es un hecho y nos dice que efectivamente el factorial de 0 es 1. La otra cláusula del programa, la cláusula 2, nos permite probar que el factorial de un número, representado por la variable N, es otro, representado por la variable F, siempre que ambas variables tomen valores que hagan posible probar todos los átomos de su cuerpo (sin un orden determinado ya que el cuerpo representa una conjunción lógica) para algún valor válido de las variables libres que en él aparezcan (en nuestro caso son libres las variables N1 y F1 ). Así, si tenemos que N es mayor que 0, que N1 = N − 1, que el factorial de N1 es F1 y que F = N ∗ F1 , entonces podremos efectivamente decir que F es el factorial de N. En el caso de Haskell, y de la programación funcional, es aún más claro puesto que lo escrito en el programa se limita a describir el comportamiento matemático de la función factorial asumiendo que el lenguaje será capaz de interpretar adecuadamente dicha definición y computar efectivamente el factorial de un número n. Sin embargo, en la práctica ocurre que en ambos lenguajes aparecen elementos no declarativos puesto que, por ejemplo, el orden de evaluación de los átomos del cuerpo de las cláusulas Prolog es siempre de izquierda a derecha, y la comprobación de que la expresión a evaluar encaja con uno de los lados izquierdos de las reglas Haskell se realiza según el orden en el que se escriben dichas reglas, eligiendo siempre la primera que encaje y descartando el resto. El trabajo de esta tesis se enmarca dentro de la programación declarativa y, más concretamente, dentro de los paradigmas de la programación lógica (véase [44, 2]), la programación lógica con restricciones (véase [33, 34]) y la programación lógico-funcional (véase [47, 1]). Por último, a pesar que se trabaja con el objetivo de aportar cuanta información 8

sea necesaria para el correcto entendimiento de la tesis, se espera que el lector esté especialmente familiarizado con los conceptos y la semántica de la programación lógica y la programación lógica con restricciones.

1.2.

Programación declarativa con incertidumbre

La investigación sobre la incertidumbre en el marco de la programación declarativa se ha producido durante los últimos 25 años, y muy especialmente dentro del campo de la programación lógica. En este campo se han tratado diversas aproximaciones a la semántica declarativa y operacional, así como a la aplicación práctica de estos enfoques de la programación lógica con soporte para la incertidumbre y el razonamiento incierto. Desde que L. A. Zadeh [76] definiera, en el año 1965, los conjuntos borrosos como una extensión de la teoría matemática de conjuntos, en la que la función de pertenencia de un conjunto indicaba el grado de pertenencia de un elemento al conjunto mediante la asignación de un número real, comprendido en el intervalo [0, 1], la utilización de la incertidumbre en el ámbito de la lógica matemática y la programación ha visto numerosas aproximaciones desde diferentes enfoques que podemos englobar, de manera muy general, en cuatro grandes líneas de trabajo: Enfoques anotados como [71, 68, 69, 41], para los que los grados de certidumbre representan el nivel de confiabilidad sobre la certeza de las pruebas, y se aporta un procedimiento de cómputo para grados de certidumbre por medio de una interpretación para la implicación y otra para la conjunción. Opcionalmente, además, puede darse interpretación a la disyunción y/u otras conectivas lógicas. Enfoques multi-valuados o borrosos como [28, 75, 48], para los que los dos valores veritativos clásicos de falso y cierto se reemplazan por toda una serie de valores veritativos, y para los que se proponen multitud de conectivas y agregadores lógicos que permiten interpretar de manera diferente las cláusulas de un programa. Enfoques posibilistas como [78, 19], para los que el cómputo de los grados de certidumbre se realiza atendiendo a la teoría de la posibilidad [18], un sistema deductivo que, siguiendo ideas de Rescher [54], se basa en la idea de que la fuerza de una conclusión coincide con la fuerza de su argumento más débil. Estos guardan bastante relación con los enfoques anotados con los que comparten origen, y con los enfoques multi-valuados en que existen propuestas posibilistas que amplían el número de valores veritativos. Enfoques probabilísticos como [51, 56], para los que el cómputo de los grados de certidumbre se realiza atendiendo a las condiciones de la teoría matemática de la probabilidad. Además, como ocurre de forma normal en la investigación, el enriquecimiento mutuo de estas líneas de trabajo hace que algunas propuestas encajen en más de una línea de trabajo según cómo se interpreten o qué elementos se consideren. Así tenemos propuestas basadas en relaciones de similaridad como [77, 4, 64, 45], o en relaciones de proximidad como [77, 17, 66, 38], que pueden ser anotadas o multi-valuadas según la interpretación de los grados de certidumbre y el número de conectivas y agregadores lógicos empleados. 9

En lo que respecta a esta tesis, puede decirse que el trabajo realizado se enmarca principalmente dentro de los enfoques anotados, no teniendo relación alguna con los enfoques probabilísticos dado que la teoría de la probabilidad no jugará papel alguno en las interpretaciones de implicaciones y conjunciones, y poca relación con los multi-valuados en el sentido de que la elección de la interpretación de las conectivas lógicas de implicación y conjunción está determinada y es única para un programa. En relación con los enfoques posibilistas, aún pudiendo decirse que resultan bastante cercanos a las propuestas de esta tesis, resultan bastante más restrictivos en el sentido de que exigen una serie de condiciones que no se cumplen, en general, en nuestras propuestas, e.g. que el retículo que contiene los valores de certidumbre sea completo y su orden total. 1.2.1.

Programación lógica cuantitativa

La programación lógica cuantitativa comienza fundamentalmente con un trabajo de Shapiro [65] de 1983, en el que se proponía el uso del intervalo [0, 1] de forma similar a como lo había usado Zadeh con anterioridad pero, esta vez, como valores de certidumbre que indicaban cuál era el grado con el que se podía confiar en la veracidad de la información proporcionada por las cláusulas de un programa lógico. Además, permitía utilizar diferentes funciones de certidumbre para propagar los factores de certidumbre que podían obtenerse para los cuerpos de las cláusulas a las cabezas. En 1986, M. H. van Emden [71] consideró los programas lógicos cuantitativos (QLP por quantitative logic program) como conjuntos de cláusulas anotadas de la forma f A ← − B1 , . . . , Bm

con un factor de atenuación f en su implicación, que tenían la característica fundamental de que empleaban una única función de certidumbre ×, ahora denominada función de atenuación, que debía emplearse para la propagación de los valores de certidumbre en todas las cláusulas del programa. Así, podía decirse que si b era el grado de certidumbre con el que podía probarse el cuerpo de una cláusula, calculado este a su vez como el mínimo de los grados de certidumbre con el que se probaban todos los átomos del cuerpo, f × b sería el grado de certidumbre para el que podía probarse la cabeza de dicha cláusula. Aunque el enfoque de van Emden resultaba menos general que el Shapiro, debido a la elección fija de una función de certidumbre particular, permitía al mismo tiempo probar resultados bastante más generales para la teoría de modelos y la semántica de punto fijo, similares incluso a aquellos obtenidos en [72, 3] para la programación lógica clásica. Además, van Emden aportaba, en el mismo trabajo, un procedimiento para el cómputo de los valores de certidumbre de los átomos en el menor modelo de Herbrand para un programa dado, mediante la aplicación de una heurística alfa-beta a los átomos de un árbol de búsqueda and/or. Sin embargo, este procedimiento únicamente funcionaba para átomos cerrados y para los que existiese un árbol de búsqueda finito. Dos trabajos posteriores de V. S. Subrahmanian [68, 69] introdujeron un retículo especial SL en sustitución del retículo de los números reales en el intervalo [0, 1] con el orden natural que había sido utilizado hasta el momento. SL incluía dos copias isomorfas de [0, 1] cuyos elementos eran incomparables bajo el orden de SL, y que podían utilizarse separadamente para representar el grado de verdad y de falsedad, respectivamente, permitiendo

10

así el uso de un sencillo tipo de negación en el cuerpo de las cláusulas. Otras contribuciones relevantes de [68, 69] fueron: a) la introducción de cláusulas de programa anotadas —generalizadas posteriormente en [41] a un marco mucho más expresivo y del que hablaremos a continuación— que relajaban la restricción impuesta por van Emden de emplear una única función de certidumbre; y b) la introducción de un procedimiento de resolución de objetivos mucho más conveniente y potente que el dado en [71]. 1.2.2.

Programación lógica anotada

La programación lógica anotada tiene su máximo exponente en la teoría de programas lógicos anotados generalizados (GAPs por generalized annotated programs) [41], una propuesta de Kifer y Subrahmanian del año 1992. En esencia, dado un semirretículo superior de valores de verdad, no necesariamente el formado por el intervalo [0, 1] con el orden natural, se dice que un programa GAP es un conjunto de cláusulas anotadas de la forma A : ρ ← B1 : µ1 & . . . & Bm : µm en la que A : ρ es un átomo anotado, cada Bi : µi es un átomo c-anotado o v-anotado, según sea µi una constante o una variable, respectivamente, y en donde & representa la conjunción lógica. Dado que la anotación ρ de la cabeza de las cláusulas puede ser una constante, i.e. un valor del semirretículo, una variable o un término de anotación complejo (que puede contener funciones definidas con los elementos del semirretículo), es fácil ver que las cláusulas de los programas QLP de van Emden pueden representarse en GAP con cláusulas anotadas de la siguiente forma A : f ×min{µ1 , . . . , µm } ← B1 : µ1 , & . . . & Bm : µm y por lo tanto GAP es, intuitivamente, más general que QLP. En relación a su semántica declarativa, se presentaron para GAP resultados más generales que los aportados por van Emden para QLP, y el procedimiento de resolución propuesto para GAP mejoraba de forma significativa aquel existente para QLP. En todo caso, las interpretaciones en GAP se definen sobre el conjunto de átomos cerrados (la base de Herbrand), y el hecho de utilizar como anotación para un átomo cerrado del modelo mínimo de un programa el supremo (lub) de todas las anotaciones con la que es posible probarlo, obliga a introducir una compleja, y costosa en lo que a implementación se refiere, noción de reductante para permitir computar con una “unión” de cuerpos de cláusulas cuyas cabezas son todas unificables con el átomo en cuestión. Estos elementos limitan, en cierto modo, los resultados de la semántica declarativa y operacional de GAP ya que, por otro lado, su muy general sintaxis permitía, en efecto, englobar muchos de los enfoques conocidos, hasta el momento, sobre el razonamiento incierto o con incertidumbre. 1.2.3.

Programación lógica multi-valuada

Una propuesta alternativa para tratar la incertidumbre a la programación cuantificada o anotada que se ha comentado hasta ahora, consiste en la utilización de lógicas multivaluadas, como es el caso de los birretículos de Fitting [20], que son, intuitivamente, estructuras ordenadas mediante dos órdenes diferentes, uno de conocimiento ≤k , al estilo 11

del utilizado en las propuestas anteriores, y otro de verdad ≤t , en el que un elemento se dice menor o igual que otro cuando se prueba más falso o igual de falso que otro. Los birretículos son una generalización de la lógica multi-valuada FOUR de Belnap > [9, 74] que, como puede verse en la figura 1, permite utilizar cuatro valores lógicos: 0 6 @ @ para la falsedad; 1 para la verdad; ⊥ para @ la ausencia de información, i.e. ni falsedad @ ni verdad; y > para la contradicción, i.e. @ @ 1 falsedad y verdad al mismo tiempo. 0 @ Los dos órdenes que pueden definirse en @ @ el birretículo inducido por la lógica FOUR @ serían concretamente: @ ≤k @ El orden de conocimiento (≤k ), que ⊥ nos indica la cantidad de información ≤t que disponemos para un átomo, y ordena los valores de la lógica según la cantidad de información de la siguienFigura 1: Birretículo de cuatro valores te manera: ⊥, el mínimo en este orden, representa la ausencia de información, 0 y 1 representan la misma cantidad de información pero el primero hacia la falsedad, y el segundo hacia la verdad; por último, >, el máximo en este orden, representa que el átomo es falso y cierto a la vez o, lo que es lo mismo, que tenemos el máximo de información posible sobre un átomo. El orden de verdad (≤t ), que nos indica cuánto de verdadero es un átomo determinado, y ordena los valores de la lógica según pueda deducirse la veracidad del átomo en cuestión. Así, 0, que representa el mínimo en este orden, indica falsedad; ⊥ y > representan el mismo nivel de falsedad que de verdad; y 1, que representa el máximo de este orden, indica verdad. A partir de otras lógicas multi-valuadas surgen enfoques basados en lógica borrosa como [75, 73, 27, 48, 49] y sistemas que implementan el principio de resolución de [42], presentado por Lee en 1972, como Prolog-Elf [32], Fril-Prolog [7] y F-Prolog [43]; cuya característica fundamental es la utilización de una serie de conectivas y agregadores lógicos multi-valuados que permiten variar la forma en que cada cláusula del programa debe interpretarse. Así tenemos, más recientemente, lenguajes como [75, 73, 27] que hacen uso de conectivas como las mostradas en la figura 2 y de los cuales la propuesta de [27] ha sido implementada sobre CLP(R). Por otro lado, basándose en la definición dada por Pavelka [52] de par adjunto (←, &) con respecto a un retículo dado, el marco de programación lógica multi-adjunta [48] (MALP por multi-adjoint logic programming) define programas lógicos con capacidad para utilizar diferentes pares adjuntos en un mismo programa, permitiendo interpretar cláusulas diferentes de un mismo programa de maneras muy diversas. La semántica procedural de MALP fue presentada en [49] y una transformación de programas MALP a programas Prolog equivalentes fue descrita posteriormente en [37].

12

Łukasiewicz &Ł (x, y ) = max(0, x+y −1) →Ł (x, y ) = min(1, 1−x+y ) ∨Ł (x, y ) = min(1, x+y ) Gödel &G (x, y ) = min(x, y ) →G (x, y ) = y if x>y else 1 ∨G (x, y ) = max(x, y ) Product &P (x, y ) = x·y →P (x, y ) = min(1, y /x) ∨P (x, y ) = x+y −x·y

Además, en la tesis doctoral de J. Penabad [53], presentada muy recientemente, se describen un conjunto de técnicas de transformación de programas borrosos, basadas en desplegado, para la optimización, especialmente, de programas multi-adjuntos. Se espera que estas técnicas contribuyan a la mejora y el desarrollo del sistema FLOPER [21], también implementado sobre CLP(R), y que permite ejecutar un subconjunto de programas multi-adjuntos. 1.2.4.

Programación lógica con similaridad

Un enfoque más reciente que los anteriores es el de la programación lógica con incertidumbre basada en relaciones de similaridad (SLP por similarity-based logic programming) presentado por M. I. Sessa en Figura 2: Conectivas lógicas [64] y otros trabajos anteriores como [26, 22, 63]. Este enfoque utiliza también el retículo [0, 1] para tratar la incertidumbre al estilo de la programación lógica anotada o de la programación lógica multi-valuada. A diferencia de como ocurre en la programación lógica anotada o en la borrosa, los programas SLP son, sencillamente, un conjunto de cláusulas de Horn como aquellas de la programación lógica clásica. La diferencia con un programa lógico clásico radica, entonces, en la presencia de una relación de similaridad, i.e. el análogo borroso de una relación de equivalencia, que permite establecer similitudes, bien entre símbolos de función, bien entre símbolos de predicado, y que se proporciona junto al programa para permitir unificar términos que, de otro modo, no serían unificables en el sentido clásico. Esta unificación puede verse como si fuera estratificada, i.e. como si fuera de manera que a cada grado de certidumbre que descendemos desde el 1, se permitiera una mayor cantidad de unificaciones entre elementos no unificables en niveles superiores de certidumbre. El nivel con el que dos elementos son unificables se denomina, en este caso, grado de similaridad. Para la semántica operacional de los enfoques basados en similaridad existen diferentes propuestas: Una posibilidad es transformar el programa original con similaridad en un programa equivalente sin similaridad y aplicar la resolución SLD clásica, como se propone en [26, 63, 64]. Alternativamente, puede también desarrollarse una resolución SLD basada en relaciones de similaridad y aplicarla al programa original con similaridad, como se propone también en [64]. Las proposiciones [64](Prop. 7.1) y [64](Prop. 7.2) demuestran la equivalencia de las respuestas calculadas en ambos modos de proceder, y los sistemas Likelog [4, 5] y SiLog [45] se desarrollaron como implementaciones del esquema SLP sobre sistemas Prolog para dar soporte a aplicaciones en el ámbito de la búsqueda flexible de información. Algunos trabajos posteriores han generalizado el enfoque SLP utilizando relaciones de proximidad en lugar de relaciones de similaridad porque, como ya dijeran Shenoi y Melton

13

[66], la transitividad requerida por las relaciones de similaridad puede resultar conflictiva con las intenciones de los usuarios en múltiples ocasiones. Así, intuitivamente, una relación de proximidad, originalmente propuesta por Dubois y Prade en [17], es el análogo borroso de una relación binaria reflexiva y simétrica, pero no necesariamente transitiva como en el caso de las relaciones de similaridad. El lenguaje Bousi∼Prolog [39] supone una extensión de la programación lógica con relaciones de proximidad, y existen dos implementaciones del mismo: una implementación de bajo nivel [40] basada en la adaptación de la WAM clásica, denominada Similarity WAM e implementada en JAVA y capaz de ejecutar programas Prolog en el contexto de una relación de proximidad definida sobre el alfabeto de primer orden inducido por el programa; y una implementación de alto nivel [38] realizada sobre el sistema SWI-Prolog por medio de transformaciones de programas Bousi∼Prolog a programas BPL Traducidos (así denominados) que pueden ser ejecutados en un metaintérprete de acuerdo con una resolución SLD basada en proximidad al estilo de la desarrollada en [64] para SLP, pero generalizada para el caso de las relaciones de proximidad. 1.2.5.

Otros marcos de programación con incertidumbre

Como se ha podido ver, muchas de las extensiones de la programación lógica clásica con incertidumbre que han llegado a implementarse, han utilizado la programación con restricciones como método de implementación por las facilidades que aporta a la hora de calcular con los grados de certidumbre. De cualquier modo, son pocas las aproximaciones a la incertidumbre que toman como base el esquema clásico de CLP de Jaffar y Lassez [33]. En particular, podemos encontrar trabajos como [55, 56], que extienden la formulación de CLP de Höhfeld y Smolka [31] con programación lógica cuantitativa en el sentido de [71], y que están motivados por problemas en el ámbito del procesamiento del lenguaje natural. Por otro lado, [10] propuso la utilización de una aproximación a CLP, basada en semianillos en lugar de retículos, en el que las restricciones se resuelven de manera difusa por medio de unos niveles de consistencia, representados por valores del semianillo. Esta aproximación, motivada por problemas de satisfacción de restricciones (CSPs por constraint satisfaction problems), fue implementada con clp(FD,S) en [25] para una clase particular de semianillos que permitían utilizar algoritmos de consistencia local. En el campo más específico de la programación lógico-funcional, son muy pocas las aproximaciones con incertidumbre, y básicamente se concentran dentro del marco multi-adjunto de la programación lógica multi-valuada, para el que se ha investigado una unificación basada en similaridad para extender el procedimiento de estrechamiento necesario, que es el principal procedimiento de resolución de objetivos para lenguajes FLP [50]. Al igual que en [64], las relaciones de similaridad de [50] toman valores en el intervalo real [0, 1].

1.3.

Objetivos

El objetivo fundamental de esta tesis es tanto el estudio, investigación y desarrollo de marcos de programación declarativa de semántica rigurosa y con expresividad suficiente para el correcto tratamiento de la incertidumbre y del razonamiento incierto, como el desarrollo de la implementación práctica de dichos esquemas y la resolución de los problemas técnicos asociados a toda implementación práctica de un marco teórico de programación.

14

Más concretamente, se propone contribuir en dos áreas fundamentales: por un lado, en el área de la programación declarativa, aportando un marco teórico tanto para programación lógica como para programación lógico-funcional que incorpore incertidumbre, y que permita construir programas declarativos en los que la incertidumbre juegue un papel relevante; y por otro lado, en la implementación de un lenguaje con incertidumbre, mediante técnicas que aprovechen la programación con restricciones disponible en CLP o en CFLP para representar efectivamente programas con incertidumbre como programas CLP o CFLP equivalentes, y que permita, a su vez, la construcción de aplicaciones prácticas en el área de la incertidumbre, mejorando lenguajes existentes de enfoques relacionados al permitir la utilización de restricciones de un dominio de restricciones y funciones perezosas indeterministas. De manera más esquemática, podemos englobar los objetivos de esta tesis en los siguientes puntos: 1. Generalizar el concepto de incertidumbre para permitir utilizar otros elementos distintos de los contenidos en el retículo [0, 1], permitiendo representar otras características de los programas además del grado sobre la certidumbre de las cláusulas de los programas. En particular, se propone contribuir construyendo una nueva noción de cualificación, más general que las empleadas por enfoques relacionados, que satisfaga ciertos axiomas que garantizan la compatibilidad con la noción clásica de incertidumbre, y que permita razonar en los programas sobre otros elementos distintos de la incertidumbre como puede ser la complejidad de la demostración. 2. Presentar un marco teórico de semántica natural y rigurosa para la programación lógica con cualificación que sirva de base para la investigación posterior. En concreto, se pretende conseguir una semántica declarativa clara que permita, además de admitir caracterizaciones prácticas de interpretaciones y modelos, razonar adecuadamente sobre la corrección de los métodos de resolución de objetivos y de las técnicas de implementación. 3. Estudiar las posibles extensiones de la semántica y la expresividad del marco desarrollado en el punto anterior, así como proponer esquemas más generales que engloben o incorporen otras propuestas en el área, como por ejemplo la programación lógica basada en similaridad al estilo de [64] o la programación lógico-funcional con restricciones de [47]. 4. Implementar instancias útiles de los esquemas de programación investigados para facilitar el desarrollo posterior de aplicaciones prácticas aportando herramientas útiles y sencillas de utilizar para los usuarios finales de estos marcos de programación. Más concretamente, estudiando la posibilidad de extender sistemas de programación existentes como el CFLP Toy [6] o los CLP SICStus Prolog [67] y SWI-Prolog [70].

1.4.

Contribuciones principales

Las contribuciones principales de esta tesis se concretan en los resultados principales del conjunto de publicaciones que constituyen el contenido fundamental de esta tesis en formato de tesis por publicaciones, y pueden brevemente resumirse en los siguientes puntos:

15

1. La noción de dominio de cualificación, tal y como se presenta en la sección 2.1 y se define, principalmente, en las publicaciones [59](A.1, §2) y [61](A.5, §2.2), supone una generalización de la noción usual en enfoques relacionados, y permite razonar sobre diferentes maneras de asociar a cada respuesta calculada un valor de interés para el usuario que, como se verá más adelante, permite razonar tanto sobre la incertidumbre como sobre otros elementos. 2. El esquema QLP para la programación lógica con cualificación, presentado por primera vez en la publicación [59](A.1), y que sirve como base para el conjunto de marcos de programación desarrollados en el resto de publicaciones de la tesis. Este esquema de programación es una generalización de la programación lógica cuantitativa de van Emden [71], y para él se desarrollan dos caracterizaciones equivalentes de la semántica declarativa; una noción declarativa de objetivo y solución; y un procedimiento de resolución de objetivos, denominado resolución SLD cualificada, que se demuestra correcto y completo con respecto a la semántica declarativa. El esquema QLP presenta instancias interesantes que pueden ser fácilmente implementadas utilizando tecnología CLP, de manera que los QLP-programas pueden ser transformados a CLPprogramas equivalentes que hacen uso de restricciones para computar con los valores de cualificación. 3. Un conjunto de esquemas de programación declarativa con cualificación que engloban a QLP y extienden su semántica y su expresividad. Estos esquemas desarrollados son: BQLP. Presentado en la sección 2 y en la publicación [60](A.2), es una pequeña extensión de QLP introduciendo predicados bivaluados —en el sentido de que es posible deducir átomos a partir de un programa que prueban veracidad o falsedad— y restricciones umbrales en los átomos del cuerpo de las cláusulas que limitan inferiormente la cantidad de información a partir de la cual es posible deducir otros elementos. Para este esquema, se extienden ambas caracterizaciones de la semántica de QLP y se adapta el procedimiento de resolución de objetivos. SQLP. Presentado en la sección 3 y en la publicación [11](A.3), es una extensión de QLP con una generalización de las relaciones de similaridad de [64], de forma que estas den valores sobre el conjunto soporte de un dominio de cualificación adecuado, en lugar del más estricto retículo de los números reales en el intervalo [0, 1] con el orden estándar (≤). Para este esquema se desarrolla una caracterización de la semántica declarativa y una técnica de transformación de SQLP-programas a QLPprogramas equivalentes para los que puede utilizarse el procedimiento de resolución de objetivos existente. Además, se demuestra que los SLP-programas en el sentido de [64] son, en efecto, un caso particular de SQLP-programas que no hacen uso de factores de atenuación en sus cláusulas. QCFLP. Presentado en la sección 4 y en la publicación [13](A.4), es una extensión de la semántica y la expresividad de QLP con soporte para computaciones con funciones perezosas indeterministas y restricciones de un dominio de restricciones. En concreto, se considera un fragmento de primer orden de CFLP —un esquema general para la programación lógico-funcional con restricciones sobre un dominio de restricciones dado como parámetro presentado en [47]—, y se desarrolla una extensión del

16

mismo con un dominio de cualificación adecuado. Para este esquema se desarrollan dos caracterizaciones de la semántica declarativa y una técnica de transformación de QCFLP-programas en CFLP-programas equivalentes —al estilo de la desarrollada para SQLP pero con soporte para la pereza— que permite ejecutar los programas transformados sobre un sistema CFLP como Toy [6] o Curry [29]. SQCLP. Presentado en la sección 5 y en las publicaciones [61](A.5) y [15](B.5), es una extensión de SQLP que generaliza las relaciones de similaridad a relaciones de proximidad y que incorpora computaciones con restricciones de un dominio de restricciones. En concreto, se desarrollan dos caracterizaciones equivalentes de la semántica declarativa, inspiradas en la semántica para CLP basada en observables de [23], y una técnica de transformación de programas que se demuestra correcta y completa con respecto a la semántica declarativa. Esta técnica permite transformar SQCLP-programas en CLP-programas equivalentes en dos pasos: 1) eliminando la relación de proximidad — al estilo de la transformación presentada para SQLP; y 2) eliminando el dominio de cualificación — al estilo de la transformación presentada para QCFLP. 4. El sistema (S)QCLP, presentado en la sección 6, es un prototipo de implementación, basado en la técnica desarrollada en el informe técnico [15](B.5), de varias instancias útiles del esquema SQCLP — que engloba restricciones, cualificación y proximidad. Este sistema permite la ejecución de todos los ejemplos y programas de esta tesis a excepción de aquellos que hacen uso de funciones perezosas, i.e. los ejemplos específicos del esquema QCFLP. (S)QCLP está públicamente disponible en http://gpd.sip.ucm.es/cromdia/qclp y funciona indistintamente sobre los sistemas CLP SICStus Prolog y SWI-Prolog.

1.5.

Organización de la tesis

Esta tesis sigue el formato de tesis por publicaciones de acuerdo con la normativa vigente de la Universidad Complutense de Madrid y se compone, por lo tanto, de una introducción — que incluye motivación, objetivo, resumen de contribuciones y conclusión— y de un apéndice con el conjunto de publicaciones asociadas a la tesis —que avalan la calidad de los resultados de la misma— en su formato y longitud original. Las secciones 1 a 7 constituyen el resumen de las publicaciones asociadas a la tesis, e incluyen la motivación, los objetivos, las contribuciones principales de la tesis y sus conclusiones. Las publicaciones principales, y que avalan formalmente los resultados de la tesis, se presentan en el Apéndice A; el resto de publicaciones asociadas, correspondiente al conjunto de informes técnicos con versiones extendidas y con demostraciones completas, se presentan en el Apéndice B. Las citas a referencias bibliográficas se realizan indicando únicamente con un número entre corchetes la publicación a la que hacen referencia, con el añadido de incluir opcionalmente y entre paréntesis la sección o enunciado específico que resulta de interés en dicha cita bibliográfica. Por ejemplo: [n] — Cita a la publicación n. [n](§X) — Cita a la sección X de n. 17

[n](Def. X) — Cita a la definición X de n. En el caso de las citas a las publicaciones asociadas de esta tesis, se incluye además dentro de los paréntesis opcionales el número del apéndice que contiene dicha publicación. Así: [n](A.m) — Cita a la publicación principal asociada n en el apéndice A.m. [n](B.m) — Cita a la publicación asociada n en el apéndice B.m. [n](B.m, §X) — Cita a la sección X de n en el apéndice B.m. [n](B.m, Def. X) — Cita a la definición X de n en el apéndice B.m. De manera más específica, y excluyendo la introducción que finaliza con esta subsección, la tesis se organiza de la siguiente manera: La sección 2 desarrolla los esquemas QLP y BQLP que extienden la programación lógica clásica con un dominio de cualificación y otras mejoras de su expresividad mediante ampliación de la sintaxis de los programas. Los dominios de cualificación se presentan en la subsección 2.1. La sección 3 desarrolla el esquema SQLP de la programación lógica con cualificación y similaridad. Las relaciones de similaridad se presentan en la subsección 3.1. La sección 4 desarrolla el esquema QCFLP de la programación lógico-funcional de primer orden con restricciones y cualificación. Los dominios de restricciones se presentan en la subsección 4.1. La sección 5 desarrolla el esquema SQCLP de la programación lógica con restricciones, cualificación y proximidad. Las relaciones de proximidad se presentan, como generalización de las relaciones de similaridad, al principio de la subsección 5.1. La sección 6 presenta el sistema (S)QCLP como prototipo de implementación de varias instancias útiles del esquema SQCLP sobre los sistemas SICStus Prolog [67] y SWI-Prolog [70]. Finalmente, la sección 7 concluye la introducción que conforma la primera parte de las tesis con formato por artículos, incidiendo en los principales resultados de la tesis y en las líneas de investigación futura.

2.

Programación lógica con cualificación

La programación lógica con cualificación surge como una extensión de la programación lógica clásica que amplía la expresividad de los programas lógicos clásicos en el sentido de proporcionar una sintaxis y una semántica clara para permitir el modelado y uso de la incertidumbre y el razonamiento incierto, así como de otras maneras de asociar a cada respuesta calculada un valor de interés para el usuario, llamado valor de cualificación, en los programas lógicos. De esta manera, será posible probar no sólo que un átomo A es cierto, sino que dicho átomo A se prueba con (o para) al menos un determinado valor de cualificación d. 18

A nivel sintáctico, un programa lógico con cualificación es un conjunto de cláusulas o reglas de programa cualificadas. Una cláusula o regla de programa cualificada es una cláusula lógica clásica con un factor de atenuación en su implicación. Un factor de atenuación es el valor de cualificación asociado a la cláusula que, en el caso más conocido de la incertidumbre, representaría el grado de confianza en la información proporcionada por la cláusula. Al igual que ocurre en la programación lógica clásica, podemos distinguir entre hechos y cláusulas cualificadas. Así, asumiendo que A, B1 , . . . , Bm son átomos y α es un valor de cualificación, tenemos que α A← − es un hecho cualificado, y α

A← − B1 , . . . , Bm es una cláusula cualificada, en la que el átomo A es su cabeza y la conjunción de átomos B1 , . . . , Bm es su cuerpo. Nota 1. En las publicaciones iniciales, el factor de atenuación α se representaba en las impliα caciones de las cláusulas como “←α−” en lugar de “ ← −”.

A partir de una signatura universal —que proporciona símbolos de predicado y de función— y un conjunto de variables, se construyen términos y átomos de la manera usual. Así, un término es o bien una variable, o bien una constante (símbolo de función de aridad 0) o un símbolo de función de aridad n seguido, entre paréntesis, de n términos. Y un átomo es un símbolo de proposición (símbolo de predicado de aridad 0) o un símbolo de predicado de aridad n seguido, entre paréntesis, de n términos. Si la intuición que hay detrás de una cláusula lógica como A ← B1 , . . . , Bm es que la cabeza de la cláusula debe ser cierta siempre que lo sea su cuerpo, i.e. algo equivalente a la fórmula lógica B1 ∧ . . . ∧ Bm ⇒ A, en el caso de la programación lógica con cualificación, α la cabeza de una cláusula como A ← − B1 , . . . , Bm será cierta para (o hasta) un determinado valor de cualificación d, siempre que el cuerpo sea cierto para (o hasta) un valor de cualificación e y que el valor de cualificación resultante de la atenuación de e con el factor de atenuación α de la cláusula sea igual o mejor que d. Por lo tanto, en un marco de programación lógica con cualificación, no nos bastará con decir que un átomo A es cierto, sino que es cierto para al menos un determinado valor de cualificación d (en símbolos, A]d) cuando sea posible probar el átomo A con un valor de cualificación igual o mejor que d, i.e. algo parecido a la fórmula B1 ]e ∧ . . . ∧ Bm ]e ⇒ A]d con d acotado superiormente por la atenuación de e con α. En estas circunstancias, estaremos interesados en probar la deducibilidad de átomos cualificados A]d con respecto a un programa lógico con cualificación dado. El significado exacto de las expresiones “A es cierto para (hasta) un valor de cualificación d”, “el cuerpo es cierto para (hasta) un valor de cualificación e”, “atenuación de e con el factor de atenuación α” y “un valor de cualificación es igual o mejor que otro” quedará claro en la siguiente subsección.

2.1.

Dominios de cualificación

Como es de esperar, el significado de un programa lógico con cualificación dependerá de la interpretación que se haga de los valores de cualificación y de la función de atenuación que 19

se utilicen en el programa. La interpretación de estos dos elementos es, precisamente, lo que proporcionan los dominios de cualificación. Los dominios de cualificación se introdujeron por primera vez en la publicación [59](A.1) como generalización de los valores de certidumbre empleados por van Emden en [71]. El objetivo de esta generalización es no sólo permitir la utilización de la incertidumbre y el razonamiento incierto en los programas lógicos como parte de la inferencia lógica, como es el caso de los QLPs1 de van Emden, sino también permitir utilizar otros elementos de interés para el usuario como puede ser el coste de la demostración de una respuesta calculada. En esencia, un dominio de cualificación proporciona un conjunto de valores posibles de cualificación equipado con estructura de retículo, y una función de atenuación que se usa para calcular la propagación de valores de cualificación a través de las implicaciones lógicas de las cláusulas de los programas. La finalidad de un dominio de cualificación es aportar las herramientas necesarias para representar y razonar sobre una cualidad medible en los programas lógicos. Por lo tanto, los valores de cualificación de un dominio representan una medida específica de la cualidad sobre la que se pretende razonar. Un ejemplo de esto serían los grados de confianza o de certeza sobre la verosimilitud de la información proporcionada por un átomo, o también el coste —medido en base a la profundidad de la prueba— de obtener dicha información. Por otro lado, la finalidad de la función de atenuación es la de obtener un valor de cualificación a partir de la atenuación, o degradación, de otro valor de cualificación cuando es utilizado en un proceso de inferencia lógica con factor de atenuación. Así, la función de atenuación será la encargada de calcular el valor de cualificación con el que es posible probar la cabeza de una cláusula a partir del factor de atenuación de la cláusula y el valor de cualificación con el que se prueba su cuerpo. Por último, una conjunción de átomos podrá probarse con un valor de cualificación determinado siempre que sea posible probar cada átomo de la conjunción con dicho valor de cualificación. Esto implica, en la práctica, que el valor de cualificación con el que se prueba el cuerpo de una cláusula está acotado superiormente por el ínfimo en el dominio de cualificación de los valores de cualificación con los que se prueban los átomos del cuerpo. Más concretamente, un dominio de cualificación D proporciona: un retículo hD, P, b, ti de valores de cualificación con extremos, i.e. con un elemento mínimo b y otro máximo t con respecto al orden parcial P; y una función de atenuación ◦ : D × D → D asociativa, conmutativa, monótona con respecto al orden del retículo (P) y distributiva con respecto al ínfimo del retículo (u), que cumple además: ∀d ∈ D : d ◦ t = d y d ◦ b = b. ∀d, e ∈ D : d ◦ e P e.

Nota 2. En las publicaciones iniciales, los extremos del retículo se representaban por ⊥ y > en lugar de b y t, respectivamente; y el orden parcial se representaba por v en lugar de P.

Los axiomas anteriores surgen de manera natural a partir de las características del producto (×) en el retículo formado por el intervalo de los números reales entre el 0 y el 1 con el orden estándar (≤). 1 Aquí,

quantitative logic program o programa lógico cuantitativo.

20

En este punto es conveniente realizar las siguientes observaciones sobre los axiomas mencionados. Como ya se ha dicho con anterioridad, un valor de cualificación aporta una medida sobre alguna característica cualitativa del programa sobre la que se desea poder razonar. En este sentido, un valor de cualificación aporta una cierta cantidad de información que puede considerarse mejor o peor según sea su posición en el orden del retículo, de manera que b es la peor información posible y t la mejor. Entonces: 1. ∀d ∈ D : d ◦ t = d, quiere decir que el resultado de atenuar un valor de cualificacion d con el máximo t del dominio es el propio d, o lo que es lo mismo, que atenuar con el máximo del dominio no empeora la cualificación conocida. 2. ∀d ∈ D : d ◦ b = b, quiere decir que el resultado de atenuar un valor de cualificación d con el mínimo del dominio es el mínimo del dominio, o lo que es lo mismo, que no es posible extraer información mejor de una cláusula con factor de atenuación b, que la de átomos cualificados con b y, en consecuencia, triviales. 3. ∀d, e ∈ D : d ◦ e P e, quiere decir que no es posible mejorar la información con respecto a la proporcionada por los valores de cualificación d y e; es decir, al atenuar podremos, en el mejor de los casos, mantener la información dada por los valores de cualificación considerados pero en ningún caso mejorarla. Nota 3. Este axioma ha sido relajado con respecto a como aparece originalmente en [59](A.1) para permitir que puedan ser iguales a e y no estrictamente peores que e. El requerir que fuera estrictamente peor que e coincide con el comportamiento de los valores de certidumbre, pero no resulta necesario para la semántica. Además, esta variación del axioma permite definir dominios de restricciones adicionales.

Los axiomas anteriores se plantearon partiendo de la base de que el mínimo del dominio representa la ausencia de información, por lo que probar un átomo con b resulta trivial, y por tanto la cualificación explícita de cláusulas con b no resulta útil. En esta misma línea y cómo veremos próximamente, el elemento mínimo de los dominios no es siempre fácilmente representable, por lo que evitar su uso explícito facilita la representación práctica de los dominios de cualificación. Son ejemplos de dominios de cualificación los siguientes: El dominio B de los valores booleanos. En este dominio existen únicamente dos valores de cualificación, falso y cierto; el orden se define como falso P cierto, por lo que los extremos del dominio son b = falso y t = cierto; y tanto la función de atenuación, como el ínfimo del retículo, coinciden con la conjunción lógica (∧). Dado que el único valor de cualificación posible para un átomo que pueda probarse a partir de una cláusula es el de cierto, los programas lógicos cualificados con valores de este dominio de cualificación coinciden con los programas lógicos clásicos. El dominio U de los valores de certidumbre. En este dominio los valores de cualificación hacen referencia al grado de certidumbre o de confianza en la verosimilitud de la información contenida en un átomo. Los valores de cualificación posibles son los contenidos en el intervalo real [0, 1]; el orden parcial es el estándar (≤), por lo que los extremos del dominio son b = 0 y t = 1; la función de atenuación es el 21

producto (×); y el ínfimo del dominio coincide con la función m´ın. Por lo tanto, A]1 significa que A se demuestra con certidumbre, o confianza, máxima, y A]0.5 significa que A es cierto para un grado de certidumbre de al menos 0.5. Nótese que A]0.5 no significa que A tenga un 50 % de probabilidades de ser cierto —y por consiguiente, también un 50 % de probabilidades de ser falso— sino que A ha podido demostrarse para (o hasta) un grado de confianza de 0.5 según criterios heurísticos representados por las reglas del programa lógico cualificado que se haya utilizado. En general, dichas heurísticas pueden ser subjetivas y no está garantizado que obedezcan las leyes de la teoría matemática de la probabilidad. El dominio W de la profundidad ponderada de la prueba. En este dominio los valores de cualificación se refieren al coste de probar un átomo de acuerdo con la ponderación de cada nivel de profundidad de su demostración. Los valores de cualificación posibles son los números reales positivos y +∞; el orden parcial es el inverso del estándar (≥), por lo que b = +∞ y t = 0; la función de atenuación es la suma (+); y el ínfimo del dominio coincide con la función m´ ax. Por lo tanto, A]0 significa que podemos probar el átomo A sin coste alguno por su prueba (nótese que esto no tiene influencia sobre la forma de la demostración de A); A]5 significa que para probar A deberemos pagar un coste de orden al menos 5; y A](+∞) significa que puede probarse A siempre que paguemos un coste de orden infinito, lo que convierte al átomo A en un átomo trivial. Los dominios producto cartesiano estrictos. Una forma adicional de construir dominios de cualificación es mediante el producto cartesiano estricto de otros dos dominios de cualificación dados. El producto cartesiano estricto de dos dominios de cualificación se define de la manera natural por componentes. Sus valores de cualificación son parejas (d1 , d2 ) en las que la primera componente d1 es un valor de cualificación de D1 y la segunda componente d2 es un valor de cualificación de D2 . Estos dominios producto son la consecuencia de un refinamiento desarrollado en [61](A.5) del dominio producto tal y como fue definido en [59](A.1). La finalidad de dicho refinamiento fue la de evitar los pares problemáticos que contenían el mínimo de uno de los dominios de cualificación como una de sus componentes. Así, los elementos del dominio producto cartesiano estricto son, en la práctica, la pareja (b1 , b2 ) junto con todas las parejas (d1 , d2 ) tales que d1 6= b1 y d2 6= b2 .

2.2.

Sintaxis

Para la formalización de la sintaxis completa nos referiremos a la programación lógica con cualificación como un esquema de programación paramétrico con un único parámetro: el dominio de cualificación. Así, llamaremos QLP(D) a la instancia específica del esquema QLP para el dominio de cualificación D, y será QLP(U) la instancia correspondiente a programación lógica con incertidumbre; QLP(W) la instancia correspondiente a programación lógica con profundidades ponderadas de la prueba; y así sucesivamente. Como ya se dijo anteriormente, un QLP(D)-programa P es un conjunto de cláusulas cualificadas de la forma α A← − B1 , . . . , Bm

22

donde α ∈ D \ {b} es un factor de atenuación —distinto del mínimo del dominio de cualificación— y A, B1 , . . . , Bm son átomos. Y nuestro interés radicará en la prueba de átomos cualificados A]d, o átomos que pueden probarse para un valor de cualificación de al menos d, a partir de un QLP(D)-programa P. Considérese el siguiente QLP(W)-programa como ilustración. Ejemplo 2.1 (QLP: Números de Peano). Las dos cláusulas siguientes son una posible representación de los conocidos números de Peano en la instancia QLP(W): 0

C1

num(c) ← −

C2

− num(X) num(s(X)) ←

1

Y el predicado suma, tal y como se muestra a continuación, permite sumar números de Peano: 0

C3

suma(c, X, X) ← −

C4

suma(s(X), Y, s(Z)) ← − suma(X, Y, Z)

1

Como puede verse, el efecto de los factores de atenuación en este programa indica que las cláusulas C1 y C3 no requieren pagar coste alguno para su utilización, y las cláusulas C2 y C4 requieren que se pague al menos 1 por cada nivel de profundidad en el que se utilicen en una demostración. Por lo tanto, podemos ver de manera intuitiva que num(c)]0 debe tenerse debido a C1 y que num(s(X))](1 + d) debe tenerse siempre que tengamos num(X)]d para alguna instanciación válida de la variable X. De manera similar ocurre para las cláusulas C3 y C4 . En la publicación posterior [60](A.2), se extendió la sintaxis de los QLP-programas dando lugar al esquema paramétrico BQLP de instancias BQLP(D). Esta extensión consistió: 1. Por un lado, en la definición de restricciones umbral en los cuerpo de las cláusulas para permitir imponer cotas inferiores a los valores de cualificación calculados para cada uno de los átomos del cuerpo. De esta forma se consigue evitar inferencias con premisas insuficientemente cualificadas. 2. Y por otro lado, en la incorporación de un sencillo tipo de negación mediante el uso de átomos marcados A]tt y A]ff, donde tt y ff representan los dos valores veritativos clásicos de cierto y falso, respectivamente. Estos átomos marcados pueden verse como aserciones lógicas de predicados bivaluados que pueden cualificarse mediante valores de cualificación de un dominio D. Cabe aquí hacer mención a que no hay relación entre átomos ciertos y falsos en un programa más allá de la interpretación subjetiva dada por el usuario a los predicados del programa, así puede ocurrir en un programa que un mismo átomo aparezca marcado con tt y con ff y que ambos sean deducibles al mismo tiempo. El resultado de esta extensión de la sintaxis de los programas QLP queda reflejada en las cláusulas cualificadas al pasar a ser de la forma α

A]v ← − B1 ](v1 , w1 ), . . . , Bm ](vm , wm ) 23

donde A, B1 , . . . , Bm son átomos, v , v1 , . . . , vm ∈ {tt, ff} indican si el átomo prueba verdad o falsedad y w1 , . . . , wm ∈ (D \ {b}) ] {?} establecen cotas inferiores para los valores de cualificación con los que se debe probar cada átomo del cuerpo. La notación “?” indica que no se establece cota inferior y que, por lo tanto, cualquier valor de cualificación es aceptable. Como convenio, se asume que un átomo B]tt o B]ff, en el cuerpo de una cláusula, abrevia B](tt, ?) o B](ff, ?), respectivamente. Finalmente, diremos ahora que probamos átomos cualificados de la forma A](v , d) con v ∈ {tt, ff} y d ∈ D \ {b}, que deben entenderse como que A se prueba cierto o falso (según sea v ) para un valor de cualificación de al menos d. Nótese que (v , d) no es un valor de cualificación en sí, sino una anotación compuesta por una marca y un valor de cualificación. Así, si d fuera un valor de un dominio producto cartesiano estricto, entonces sería de la forma (d1 , d2 ) y, por lo tanto, (v , d) = (v , (d1 , d2 )). Como ilustración de la sintaxis BQLP, considérense los dos siguientes ejemplos en los que se muestra la versión BQLP(W) del ejemplo 2.1, y un programa más completo para la instancia BQLP(U⊗W) del esquema. Ejemplo 2.2 (BQLP: Números de Peano). Las cuatro cláusulas siguientes son la representación directa y natural de los números de Peano y de su predicado suma, tal y como fueron presentados en el ejemplo 2.1: 0

C1

− num(c)]tt ←

C2

− num(X)](tt, ?) num(s(X))]tt ←

C3

− suma(c, X, X)]tt ←

C4

suma(s(X), Y, s(Z))]tt ← − suma(X, Y, Z)](tt, ?)

1

0

1

Nótese que en este ejemplo no se hace uso de restricciones umbral en los cuerpos de las cláusulas para imponer condiciones adicionales (podíamos también haber omitido la “?”) y que las marcas empleadas corresponden todas a probar la veracidad (i.e. tt) del átomo en cuestión. Ejemplo 2.3 (BQLP: Alimentación). Sea D = U⊗W el dominio de cualificación producto cartesiano estricto entre U y W. Entonces el siguiente programa Pr es un BQLP(U⊗W)-programa válido. (1,0)

1

persona(juan)]tt ←−−

2

persona(ana)]tt ←−−

3

persona(h(X))]tt ←−− persona(X)](tt, ?)

4

come(juan, insectos)]ff ←−−−

5

come(juan, arroz)]tt ←−−−−

6

come(ana, carne)]ff ←−−−

(1,0)

(1,1)

(0.9,0)

(0.85,0)

(0.6,0)

(0.9,0)

7

come(ana, pollo)]tt ←−−−

8

come(h(X), Y )]ff ←−−− persona(X)](tt, ?), come(X, Y )](ff, ?)

9

come(h(X), Y )]tt ←−−− persona(X)](tt, ?), come(X, Y )](tt, ?)

(0.8,1)

(0.9,1)

En este programa las cualificaciones (d, e) indican, respectivamente, la certidumbre con

24

la que se confía en la veracidad de los predicados y el coste computacional de obtenerlos (o de demostrarlos). Como puede observarse, las cláusulas 1, 2 y 3 definen un conjunto de personas, en particular, juan, ana y todas aquellas personas que son descendientes de alguno de ellos. Las cláusulas 4, 5, 6 y 7 informan sobre los gustos alimenticios tanto de juan como de ana, indicando qué alimentos comen y cuáles no. Por último las cláusulas 8 y 9 permiten deducir los gustos alimenticios de sus descendientes a partir de los gustos alimenticios de los progenitores, partiendo de la base de que los descendientes se alimentarán de la misma forma que sus progenitores, aunque atenuando la certidumbre y aumentando el coste conforme aumenta el número de generaciones intermedias. La exposición que resta de esta sección se centra en el esquema BQLP, dado que los resultados equivalentes para QLP pueden obtenerse muy fácilmente por simplificación.

2.3.

Semántica declarativa

La semántica declarativa de los esquemas QLP y BQLP se desarrolló en [59](A.1) y en [60](A.2), respectivamente. Una versión extendida con las demostraciones de los principales resultados de [59](A.1) puede encontrarse en [58](B.1). A continuación se hace una exposición resumida de la semántica declarativa del esquema BQLP. Como es costumbre en programación lógica, la semántica declarativa puede presentarse de varias maneras diferentes. En nuestro caso, presentamos dos caracterizaciones alternativas de la semántica declarativa: una semántica de punto fijo y una semántica basada en un cálculo lógico. En ambos casos coinciden las nociones de interpretación, consecuencia inmediata y modelo de un programa lógico con cualificación. 2.3.1.

Interpretaciones y modelos

A diferencia de como resulta más común en las presentaciones de la semántica declarativa de los esquemas basados en programación lógica, se define una interpretación como un conjunto de átomos cualificados que satisfacen la condición de ser cerrados respecto a una relación denominada hDi-implicación. Las hDi-implicaciones de un átomo cualificado son, intuitivamente, aquellos átomos cualificados cuya información es más particular que la información dada por el primero. O, de otro modo, aquellos átomos cualificados que han de ser necesariamente ciertos cuando lo sea el primero. Formalmente, se dice que A](v , d) hDi-implica A0 ](v 0 , d 0 ), en símbolos A](v , d)
25

Entonces: 1. La base de Herbrand         AtΣ =       

abierta es el conjunto: p(X)](tt, 1), p(X)](ff, 1), p(a)](tt, 1), p(a)](ff, 1), p(b)](tt, 1), p(b)](ff, 1),

..., ..., ..., ..., ..., ...,

p(X)](tt, 0.9), p(X)](ff, 0.9), p(a)](tt, 0.9), p(a)](ff, 0.9), p(b)](tt, 0.9), p(b)](ff, 0.9),

..., ..., ..., ..., ..., ...

              

2. Son interpretaciones: ∅, AtΣ y {p(a)](tt, d) | 0 < d ≤ 1}, entre otras. Nótese que resulta muy sencillo comprobar que los tres conjuntos mencionados satisfacen que son cerrados con respecto a la relación de hDi-implicación, por lo que son, en efecto, interpretaciones. Una noción auxiliar, pero que resulta interesante por facilitar la comprensión del resto de la semántica, es la de consecuencia inmediata de una interpretación dada con respecto a una cláusula también dada. Intuitivamente, son consecuencias inmediatas de una interpretación dada, con respecto a una cláusula lógica cualificada también dada, aquellos átomos cualificados que coinciden con la cabeza de la cláusula instanciada —para alguna sustitución—, y cuyos átomos del cuerpo pertenecen a la interpretación dada. Es decir, aquellos átomos cualificados que pueden probarse (en un único paso de inferencia lógica) a partir de los átomos contenidos en la interpretación y de acuerdo con la cláusula proporcionada. Formalmente, dadas una interpretación I y una cláusula C de la forma α

H]v ← − B1 ](v1 , w1 ), . . . , Bm ](vm , wm ) se dice que un átomo cualificado A](v , d) es consecuencia inmediata de I con respecto a C, sii existe una sustitución θ tal que A = Hθ, y una serie de valores de cualificación d1 , . . . , dm ∈ D \ {b} que cumplen (1) y (2) como siguen: 1. Bi θ](vi , di ) ∈ I con di Q? wi para i = 1 . . . m. d 2. d P α ◦ {d1 , . . . , dm }.

La notación “d Q?w ” es trivialmente cierta si w = ?; y codifica “d Q w ” en otro caso. A continuación, resulta sencillo definir las nociones de modelo de una cláusula y modelo de un programa: una interpretación I es modelo de una cláusula C de P, sii todo átomo cualificado, que es consecuencia inmediata de I con respecto a C, pertenece a I; y una interpretación I es modelo de un programa P, sii I es modelo de cada cláusula C de P.

26

2.3.2.

Semántica de punto fijo

Como es de sobra conocido, una manera de caracterizar los modelos y modelos mínimos de un programa lógico es mediante el uso de operadores de consecuencia inmediata que actúan como transformadores de interpretaciones. Para comenzar, es sencillo comprobar que el conjunto de todas las interpretaciones forma un retículo completo con respecto al orden de inclusión (⊆), donde el elemento mínimo coincide con la interpretación vacía (o conjunto vacío, ∅) y el elemento máximo con el conjunto de todos lo átomos cualificados (o base de Herbrand F abierta, AtΣ ). Además, para cualquier conjunto deSinterpretaciones I, su supremo (lub) I es la unión de las interpretaciones del conjuntoTI ( I∈I I); y su ínfimo d (glb) I es la intersección de las interpretaciones del conjunto I ( I∈I I). A continuación, el transformador de interpretaciones TP se define con la intención de obtener todas las posibles consecuencias inmediatas de una interpretación I, con respecto a las cláusulas de un programa P. Su definición formal es la que sigue: TP (I) =def {A](v ,d) | A](v ,d) es consecuencia inmediata de I vía alguna C ∈ P} donde la noción de consecuencia inmediata es tal y como se definió en la subsección anterior. El siguiente ejemplo ilustra el funcionamiento del transformador de interpretaciones TP . Ejemplo 2.5 (Transformador de interpretaciones). Considérese D = U y los mismos p, a y b del ejemplo 2.4. Dado entonces el programa compuesto por las dos siguientes cláusulas: 0.75

1

p(X)]tt ←−− 0.95

2

p(b)]ff ←−− p(a)](tt, ?)

Se tiene:   p(X)](tt, 0.75), p(a)](tt, 0.75), TP ↑1 (∅) = TP (∅) =  p(b)](tt, 0.75),

. . . , p(X)](tt, 0.7), . . . , p(a)](tt, 0.7), . . . , p(b)](tt, 0.7),

a partir de ∅ con la cláusula 1 (que es la única con cuerpo vacío); y

 ...,  ...,  ...

TP ↑2 (∅) = TP (TP (∅)) = TP (∅) ∪ { p(b)](ff, d) | 0 < d ≤ 0.7125 } cuando se tiene que puede probarse también el cuerpo de la cláusula 2 a partir de los átomos cualificados contenidos en la interpretación TP (∅). Finalmente, como TP ↑3 (∅) = TP (TP ↑2 (∅)) = TP ↑2 (∅), se tiene que TP ↑2 (∅) es el menor punto fijo. Como cabría esperar, son propiedades del transformador de interpretaciones TP las de ser una función bien definida —i.e. de interpretaciones en interpretaciones—, monótona y continua. Además, sus puntos prefijos coinciden con los modelos de P — i.e. para toda interpretación I, I es modelo de P sii se tiene que TP (I) ⊆ I. Por último, la caracterización del modelo mínimo MP de P coincide con el menor punto fijo (lfp) del operador TP , y entonces: [ MP = lfp(TP ) = TP ↑k (∅) k∈N

27

Ejemplo 2.6 (Modelo mínimo). Considérese el programa del ejemplo 2.2. Por la definición del transformador de interpretaciones TP sabemos que: TP ↑1 (∅) = { num(c)](tt, 0), . . . , num(c)](tt, 1), . . . } TP ↑2 (∅) = TP ↑1 (∅) ∪ { num(s(c))](tt, 1), . . . , num(s(c))](tt, 2), . . . } TP ↑3 (∅) = TP ↑2 (∅) ∪ { num(s(s(c)))](tt, 2), . . . , num(s(s(c)))](tt, 3), . . . } Y por la caracterización del modelo mínimo MP dada anteriormente, se  num(c)](tt, 0), . . . , num(c)](tt, 1),     num(s(c))](tt, 1), . . . , num(s(c))](tt, 2),    num(s(s(c)))](tt, 2), . . . , num(s(s(c)))](tt, 3), MP = ...      num(s k (c))](tt, k), . . . , num(s k (c))](tt, k+1),   ...

que coincide con el modelo mínimo esperado para el programa.

2.3.3.

tiene:  ...,    ...,     ...,     ...,   

Semántica basada en un cálculo lógico

La semántica basada en un cálculo lógico es otra manera de caracterizar los modelos y modelos mínimos de un programa lógico. En este caso, la caracterización viene dada a partir de un sistema de deducción lógica, que denominaremos lógica de Horn cualificada y bivaluada sobre D, i.e. BQHL(D), que contiene una única regla de inferencia denominada Modus ponens cualificado y bivaluado, i.e. BQMP. En la figura 3 puede verse el cálculo lógico BQHL(D).

BQMP

B1 θ](v1 , d1 )

· · · Bm θ](vm , dm ) Aθ](v , d)

α

si (A]v ← − B1 ](v1 , w1 ), . . . , Bm ](vdm , wm )) ∈ P, θ sust., di Q? wi (1 ≤ i ≤ m) y d P α ◦ {d1 , . . . , dm }. Figura 3: Cálculo lógico BQHL(D)

Nota 4. Téngase en cuenta que el nombre del cálculo lógico presentado en la publicación [60](A.2) es también QHL, y no BQHL como se le ha denominado aquí. Con este cambio de denominación se tiene que QHL denomina, en exclusiva, el cálculo lógico que puede obtenerse eliminando la parte correspondiente a las marcas de los átomos y las restricciones umbral, y que da lugar a la semántica basada en un cálculo lógico del esquema QLP presentado en la publicación [59](A.1).

28

La notación P `D A](v , d) indica que el átomo cualificado A](v , d) puede inferirse a partir de las cláusulas del programa P en un número finito de pasos de inferencia BQMP. Para hacer explícito el número exacto n de inferencias BQMP utilizadas en la demostración, empleamos la notación P `nD A](v , d). Nótese que es usual representar pruebas en BQHL(D) como árboles invertidos en el que la raíz contiene el átomo cualificado objetivo de la demostración, y cada nodo contiene un átomo cualificado que se corresponde con una inferencia que utiliza como premisas los hijos del nodo en cuestión. Como ilustración, considérese el siguiente ejemplo: Ejemplo 2.7 (Derivación en BQHL). Considérese el programa Pr del ejemplo 2.3. La siguiente demostración prueba que el átomo cualificado come(h(ana), carne)](ff, (0.45, 3)) es derivable a partir de las cláusulas de Pr : (2)

persona(ana)](tt, (1, 0)) come(ana, carne)](ff, (0.6, 0)) come(h(ana), carne)](ff, (0.45, 3))

(3) (1)

donde cada paso de inferencia es como sigue: (1) Inferencia con cláusula 8 y donde (0.45, 3) P (0.8, 1) ◦ (2) Inferencia con cláusula 2 y donde (1, 0) P (1, 0) ◦ t.

d {(1, 0), (0.6, 0)}.

(3) Inferencia con cláusula 6 y donde (0.6, 0) P (0.6, 0) ◦ t.

Finalmente, la caracterización del modelo mínimo MP de un programa P dado, a partir del cálculo lógico BQHL(D), es MP = {A](v , d) | P `D A](v , d)} i.e. el conjunto de todos los átomos A](v , d) que se deducen de las cláusulas del programa P en el cálculo BQHL(D). 2.3.4.

Objetivos y soluciones

En el caso de la programación lógica clásica, un objetivo se presenta como la conjunción de una serie de átomos que se espera puedan ser probados a partir del programa. Sin embargo, en el caso que nos ocupa, y dado que los átomos deben probarse para un determinado valor de cualificación, se consideran átomos anotados abiertos A](v , W ) donde v ∈ {tt, ff} y W es una variable de cualificación, perteneciente a un conjunto de variables War, disjunto de la signatura y del conjunto de variables Var. Además, los objetivos podrán incluir una serie de restricciones umbral con la finalidad de limitar, por medio de cotas inferiores, los posibles valores de cualificación con los que se desea probar cada átomo. Estas restricciones umbral son de la forma W Q? β donde W ∈ War y β es: a) un valor de cualificación, i.e. β = d ∈ D \ {b}, y entonces la restricción debe entenderse como W Q β; o bien b) β = ?, 29

y entonces la restricción es trivialmente cierta, y equivale a no establecer una restricción umbral para el átomo anotado con la variable W . Formalmente, un objetivo BQLP tiene la forma A1 ](v1 ,W1 ), . . . , Am ](vm ,Wm ) 8 W1 Q? β1 , . . . , Wm Q? βm

que puede abreviarse como ( Ai ](vi ,Wi ), Wi Q? βi )i=1...m . Y una solución para dicho objetivo, será una pareja hθ, ρi donde θ es una substitución de variables a términos y ρ es una sustitución de variables de cualificación a valores de cualificación, y tal que P `D Ai θ](vi ,Wi ρ) con Wi ρ Q? βi para i = 1 . . . m. Es decir, que pueden probarse, a partir del programa P, todos los átomos del objetivo una vez instanciados por θ y ρ, y ρ asigna valores de cualificación aceptables a las variables de cualificación del objetivo — entendiendo por aceptables aquellos valores que satisfagan la restricción umbral impuesta en el objetivo y que permitan probar el átomo cualificado a partir del programa. Nota 5. La noción de solución de un objetivo BQLP aquí presentada difiere de la realizada en [60](A.2, Def. 4.2) — y en [59](A.1, Def. 2) para objetivos QLP. El motivo es que la noción que se presenta aquí resulta independiente del procedimiento de resolución de objetivos escogido, y se acerca más a la noción declarativa de solución dada en los trabajos posteriores. En cualquier caso, es fácil ver que la noción de solución tal y como aquí se presenta resulta equivalente a la dada en aquella definición, si se asume que el objetivo BQLP es inicial, en el sentido de [60](A.2, Def. 4.1).

El siguiente ejemplo ilustra la noción de objetivo y solución. Ejemplo 2.8 (Objetivo y solución). Siguiendo con el programa Pr del ejemplo 2.3, un posible objetivo Gr para preguntar qué alimentos no comería un hijo de ana con al menos una cualificación de (0.45, 3), es: come(h(ana), A)](ff,W ) 8 W Q? (0.45, 3)

y una posible solución válida para Gr con respecto a Pr es:

h{A 7→ carne}, {W 7→ (0.48, 1)}i que satisface ambas condiciones para ser solución porque (0.48, 1) Q? (0.45, 3) y Pr `U ⊗W come(h(ana), carne)](ff, (0.48, 1)).

2.4.

Resolución de objetivos

Para resolver BQLP-objetivos se presenta, a continuación, un procedimiento paramétrico de resolución de objetivos inspirado en la resolución SLD clásica que llamaremos BQSLD(D). Nota 6. Este procedimiento de resolución se presentó originalmente en [59](A.1, §4) como “SLD(D)” para programas y objetivos QLP; y en [60](A.2, §4) como “QSLD(D)” para programas y objetivos BQLP. Este último es el que se presenta en esta sección con el nombre de “BQSLD(D)” por considerarlo más acertado.

30

La resolución BQSLD(D) parte de un BQLP-objetivo, al que nos referiremos como objetivo inicial, y procede a través de una serie de objetivos intermedios mediante pasos de resolución hasta alcanzar un objetivo final del que se podrá extraer una solución asociada. Por tanto, resulta conveniente extender ligeramente la sintaxis dada para un objetivo con la finalidad de poder representar el estado intermedio de una computación de resolución. Así, diremos ahora que un BQLP-objetivo es de la forma: A8σ8∆

donde A es una conjunción de átomos anotados abiertos, σ es una sustitución de variables a términos y ∆ una conjunción de restricciones de cualificación. Adicionalmente, ∆ deberá cumplir una serie de condiciones de admisibilidad, detalladas en [60](A.2, Def. 4.1), para garantizar la integridad del procedimiento de resolución. Las restricciones de cualificación que pueden aparecer en ∆, son de dos tipos: o bien son de la forma “W Q? β”, y entonces decimos quedse trata de una restricción umbral para la variable W ; o bien son de la forma “W = α ◦ {W1 , . . . , Wm }”, y entonces decimos que se trata de una restricción definitoria para la variable W. Las restricciones umbral tienen la finalidad de acotar inferiormente los valores de cualificación con los que podrán probarse los átomos del objetivo, y vendrán determinadas por el usuario en el objetivo inicial según sean sus expectativas o intereses, y por el programa según sean los cuerpos de las cláusulas empleadas en la resolución. Por otro lado, las restricciones definitorias tienen la finalidad de determinar cómo debe calcularse el valor de una variable de cualificación en particular —la que define— y esta restricción dependerá de la cláusula que haya sido empleada en el paso específico de resolución en el que se introdujo, ya que esta determinará el factor de atenuación α a aplicar y el número de variables de cualificación nuevas de las que dependerá. Concretando un poco más la forma de los objetivos: Un objetivo inicial será de la forma A 8 ε 8 ∆ (o sencillamente A 8 ∆), donde ε es la sustitución vacía y ∆ contiene únicamente restricciones umbral para las variables de cualificación que aparecen en A. Un objetivo intermedio será de la forma A 8 σ1 σ2 · · · σl 8 ∆, donde σ1 σ2 · · · σl corresponde a las sustituciones aplicadas a A y calculadas en cada uno de los l pasos de resolución dados hasta el momento; y ∆ contiene tanto restricciones umbral como restricciones definitorias. Un objetivo final será de la forma 8σ1 σ2 · · · σl 8 ∆ (o sencillamente σ1 σ2 · · · σl 8 ∆), donde la conjunción de átomos es vacía y ∆ sólo contiene restricciones definitorias. Cabe aquí destacar que todo objetivo final σ 8 ∆ tiene una solución asociada hθ, ρi en la que θ = σ y ρ asigna valores de cualificación a variables de cualificación según indica el conjunto de restricciones definitorias ∆. La construcción de ρ está garantizada por las condiciones adicionales de admisibilidad expuestas en [60](A.2, Def. 4.1) y que no se detallan en esta exposición. De la forma de los objetivos se extrae que los pasos de resolución deberán encargarse de dos elementos principales: a) obtener las sustituciones σi que unifican cada átomo de la conjunción A seleccionado en el paso de resolución con la cabeza de una cláusula del programa; 31

y b) actualizar las restricciones umbral para cada una de las variables de cualificación que aparecen en la conjunción A por su correspondiente restricción definitoria determinada por la cláusula empleada en el paso de resolución. La idea general consiste, por tanto, en que dados un programa P y un objetivo G, un paso de resolución haga lo siguiente: 1. Seleccionar un átomo anotado abierto del objetivo para el paso de resolución — sin presuponer ninguna función de selección determinada. 2. Obtener un u.m.g. σ entre el átomo seleccionado y la cabeza de una cláusula C del programa P. Esta cláusula será la seleccionada para dar el paso de resolución. 3. Añadir al objetivo los átomos del cuerpo de la cláusula C, anotándolos con variables de cualificación nuevas. 4. Aplicar σ al objetivo resultante, tanto a la conjunción de átomos como a la sustitución del objetivo. 5. Variar el conjunto de restricciones de cualificación de forma que se añadan restricciones umbral para cada una de las variables de cualificación nuevas introducidas en el objetivo, y se sustituya la restricción umbral de la variable de cualificación del átomo seleccionado por la correspondiente restricción definitoria, utilizando para ello el factor de atenuación α de C, y las variables de cualificación nuevas introducidas para cada uno de los átomos del cuerpo de C. Procediendo de forma reiterada, y suponiendo que el cómputo termine, se llega hasta que: o bien no puede darse ningún paso de resolución adicional y falla el cómputo con respecto al programa; o bien no queden átomos en el objetivo y haya podido probarse con respecto al programa para una solución hθ, ρi que se obtiene como solución asociada al objetivo final de la computación. De manera más formal se escribirá G0 C1 ,σ1 G1 C2 ,σ2 · · · Cn ,σn Gn para indicar una computación en n pasos de resolución desde el objetivo inicial G0 hasta el objetivo final Gn , y donde casa paso de resolución tiene la forma G C 0 ,σ0 G 0 con

cuando

G : L, A](v , W ), R 8 σ 8 W Q? β, ∆ dm G 0 : (L, (Bi ](vi , Wi ))i=1...m , R)σ 0 8 σσ 0 8 ( Wi Q? βi )i=1...m , W = α ◦ i=1 Wi , ∆

A](v , W ) es el átomo seleccionado; α

C 0 : H]v ← − B1 ](v1 , w1 ), . . . , Bm ](vm , wm ) es una variante de una cláusula del programa P con variables nuevas y tal que α Q? β; σ 0 es un u.m.g. entre A y H;

W1 , . . . , Wm son variables de cualificación nuevas;

32

y los umbrales βi para las variables de cualificación Wi se calculan en función del umbral β para W, del factor de atenuación α de C 0 y del umbral wi del átomo correspondiente del cuerpo de C 0. Nota 7. En este momento es donde se hace patente la diferencia en la definición presentada de los dominios de cualificación en [59](A.1, §2) y en [60](A.2, §2). La presentación de los dominios de cualificación en este último incluye una función que se define como la inversa de ◦ (o de ⊗ como se denomina por coherencia con en en dicho trabajo), y que es la que nos permite calcular el valor final de los umbrales βi mediante la función newThreshold(β, α, wi ) que aparece en [60](A.2, Def. 4.4) y que aquí se ha omitido por ser la definición de la función un detalle técnico que no ha tenido continuidad en la presentación axiomática de los dominios de cualificación utilizada en posteriores publicaciones.

El siguiente ejemplo muestra una posible computación por resolución del BQLP-objetivo come(h(ana), A)](ff, W ) 8 W Q? (0.4, 3) para el programa Pr del ejemplo 2.3. Ejemplo 2.9 (Resolución de objetivos). Sea Pr el programa del ejemplo 2.3 y Gr el objetivo del ejemplo 2.8. Entonces: G0 G1

G2

G3

come(h(ana), A)](ff, W ) 8 W Q? (0.4, 3)

persona(ana)](tt, W1 ), come(ana, Y )](ff, W2 ) 8 { X 7→ ana, A 7→ Y } d 8 W1 Q? (0.5, 2), W2 Q? (0.5, 2), W = (0.8, 1) ◦ {W1 , W2 }

come(ana, Y )](ff, W2 ) 8 {X 7→ ana, A 7→ Y } ε d 8 W1 = (1, 0) ◦ t, W2 Q? (0.5, 2), W = (0.8, 1) ◦ {W1 , W2 }

8, { X 7→ ana,

A 7→ Y }

2, ε

6, { Y 7→ carne }

{ X 7→ ana, A 7→ Y } ε { Y 7→ carne } 8 W1 = (1, 0), W2 = (0.6, 0), W = (0.48, 1)

y h{A 7→ carne}, {W 7→ (0.48, 1)}i es la restricción a las variables de Gr de la solución asociada al objetivo final G3 de la resolución.

Nota 8. Nótese que las restricciones umbral W1 Q? (0.5, 2) y W2 Q? (0.5, 2) del objetivo intermedio G1 surgen de la utilización de la función newThreshold según se define en [60](A.2, Def. 4.4) mediante el cálculo: newThreshold((0.4, 3), (0.8, 1), ?) = (0.4, 3) (0.8, 1) = (0.5, 2)

3.

Programación lógica con cualificación y similaridad

Como se ha visto hasta ahora, la cualificación supone una generalización de la noción de incertidumbre empleada en la programación lógica cuantitativa o anotada, permitiendo, de hecho, modelar programas lógicos que hagan uso de la incertidumbre en sus razonamientos.

33

La programación lógica con similaridad (SLP) surge con la misma finalidad que la programación lógica cuantitativa y, evidentemente, también que la programación lógica cualificada: permitir la utilización de la incertidumbre en los programas lógicos. Sin embargo, su aproximación difiere en la forma en la que se emplea esta incertidumbre como parte del razonamiento lógico. Si bien en la programación lógica cualificada la incertidumbre (o la cualificación) interviene directamente en el grado con el que confiamos en la veracidad de la implicación de las cláusulas lógicas; en la programación lógica con similaridad, la incertidumbre es la que permite que algunos símbolos del programa jueguen el papel de otros símbolos similares según la relación de similaridad empleada en el programa. Por lo tanto, en los esquemas de programación lógica basada en similaridad, la incertidumbre juega el papel de permitir probar átomos similares, según la relación de similaridad considerada, a aquellos que resultan consecuencia lógica, en el sentido clásico, de un programa lógico cualquiera. En esta sección, se extiende con relaciones de similaridad al estilo de [64] el esquema QLP objeto de la sección anterior —i.e. BQLP sin predicados bivaluados ni restricciones umbrales en los cuerpos de las cláusulas—, obteniendo como resultado el esquema general SQLP de la programación lógica con cualificación y similaridad con la expresividad necesaria para escribir programas lógicos que hagan uso de la cualificación y la similaridad al mismo tiempo. Asimismo, y en lugar de proponer una semántica operacional para programas SQLP, se propone un mecanismo de transformación de programas SQLP a programas QLP equivalentes que puedan hacer uso del procedimiento de resolución de objetivos descrito en la subsección 2.4 de la sección anterior. En particular, estos resultados demuestran que los SLP-programas pueden ser, en efecto, reducidos a QLP-programas equivalentes.

3.1.

Relaciones de similaridad

Las relaciones de similaridad sobre un conjunto de elementos S fueron definidas en [64] y otros trabajos relacionados como funciones S : S × S → [0, 1] que satisfacen tres axiomas análogos a los requeridos en las relaciones de equivalencia clásicas — i.e. reflexividad, simetría y transitividad. Cada valor S(x, y ) computado por la relación de similaridad S se denomina grado de similaridad entre x e y . En nuestro caso, se utiliza una extensión natural de la definición dada en [64] para permitir que elementos arbitrarios de un dominio de cualificación D sirvan como grados de similaridad. Así, se tiene que una relación de similaridad puede establecer el grado de certidumbre sobre el parecido de dos símbolos (si esta diera valores en el dominio de cualificación U), el precio a pagar para que un símbolo juegue el papel de otro en una demostración (si esta diera valores en el dominio de cualificación W), etc. De la misma manera que en [64], se estará interesado en relaciones de similaridad sobre un conjunto S cuyos elementos sean variables y símbolos de la signatura de un programa dado. Nota 9. En la publicación [11](A.3) las relaciones de similaridad se representaban con la notación R y no con S. Aquí se ha optado por utilizar S —al igual que se hace en las publicaciones posteriores— para reservar la notación R para el dominio de restricciones reales que se empleará en las próximas secciones.

Formalmente, dados un dominio de cualificación D con conjunto soporte D y un conjunto S, se define una relación de similaridad D-valuada sobre el conjunto S como cualquier 34

función S : S × S → D tal que los tres axiomas siguientes se satisfacen para todo x, y , z del conjunto S: Reflexividad. S(x, x) = t. Simetría. S(x, y ) = S(y , x). Transitividad. S(x, z) Q S(x, y ) u S(y , z).

Como consecuencia de esta definición puede trivialmente definirse una relación de similaridad Sid especial, la identidad, que cumple: (1) ∀x ∈ S, Sid (x, x) = t; y (2) ∀x, y ∈ S tal que x 6= y , Sid (x, y ) = b. A modo de ilustración, considérese la siguiente relación de similaridad: Ejemplo 3.1 (Relación de similaridad). Sean roble, haya, castaño, mármol y granito cinco constantes de la signatura que representan diferentes materiales. Entonces, la relación de similaridad S definida por las siguientes ecuaciones: S(roble, roble) = 1 S(haya, haya) = 1 S(castaño, castaño) = 1 S(mármol, mármol) = 1 S(granito, granito) = 1

S(roble, haya) = 0.85 = S(haya, roble) S(roble, castaño) = 0.75 = S(castaño, roble) S(haya, castaño) = 0.75 = S(castaño, haya) S(mármol, granito) = 0.85 = S(granito, mármol)

es una relación de similaridad U-valuada que satisface los tres axiomas de reflexividad, simetría y transitividad. Nótese que entre las parejas de símbolos no especificadas se tiene un grado de similaridad de 0; i.e. S(roble, granito) = 0, etc. En adelante, las relaciones de similaridad se especificarán mediante un conjunto de ecuaciones sin ecuaciones reflexivas y no necesariamente cerrado bajo simetría ni transitividad, por lo que la relación de similaridad definida será en realidad la que resultase del cierre reflexivo, simétrico y transitivo del conjunto de ecuaciones dadas. Hasta al momento, una relación de similaridad ha sido definida como una función tal que dados dos elementos de un conjunto S, correspondiente al conjunto de variables y símbolos de un programa, les asigna un valor de cualificación de un dominio D determinado, y por el que se dice que la relación de similaridad es D-valuada. Sin embargo, cumpliendo lo anterior es posible definir relaciones de similaridad cuya utilidad en un marco de programación lógica fuera bastante discutible, es decir, ¿qué cabría esperar de una relación de similaridad de la que pudiera concluirse que un determinado símbolo, e.g. una constante, fuera parecido a otro de distinta naturaleza, e.g. un símbolo de predicado? Por esta razón, se hace necesario establecer unas condiciones adicionales de admisibilidad para que una relación de similaridad pueda formar parte de una instancia del esquema SQLP. En esencia, diremos que una relación S de similaridad D-valuada es admisible sii el conjunto S es la unión del conjunto de variables y los conjuntos de símbolos de constructora y de predicado, y además: 1. La restricción de S al conjunto de las variables se comporta como la identidad — i.e. S(X, X) = t para toda variable X, y S(X, Y ) = b cuando X 6= Y . 35

2. S(x, y ) 6= b se cumple únicamente si x e y son: a) la misma variable; b) símbolos de constructora de igual aridad; o c) símbolos de predicado de igual aridad. Por último, se asume de ahora en adelante que es posible extender cualquier relación admisible de similaridad S para actuar sobre términos y átomos. La extensión, que se denominará también S, puede definirse de manera recursiva como en [64], y tal y como se hace para el caso de los términos en [11](A.3, Def. 3). Básicamente, esta extensión calcula el ínfimo de los grados de similaridad de cada símbolo de un término con respecto al símbolo del otro término que ocupa la misma posición. El siguiente ejemplo ilustra esta extensión: Ejemplo 3.2 (Extensión de una relación de similaridad). Dada una constructora unaria m, y la relación de similaridad U-valuada del ejemplo 3.1, se tiene: S(m(roble), m(haya)) = S(m, m) u S(roble, haya) = 1 u 0.85 = 0.85 Por lo que m(roble) y m(haya) son términos similares con grado 0.85. Para el caso de los átomos, así como de cualquier otro elemento estructurado, se procedería de manera análoga.

3.2.

Sintaxis

El esquema SQLP se define también como un esquema paramétrico de programación lógica con dos parámetros: un dominio de cualificación D arbitrario y una relación S de similaridad D-valuada admisible. La instancia del esquema SQLP para la pareja hS, Di será SQLP(S, D), y por tanto SQLP(S, U) es la instancia para valores de incertidumbre (con S relación de similaridad U-valuada), que puede verse también como SLP con cualificación; SQLP(S, W) es la instancia para costes valorados de la profundidad de la prueba (con S relación de similaridad W-valuada); y así sucesivamente para otros dominios de cualificación cualesquiera. Nótese que el esquema SQLP subsume QLP cuando se toma S = Sid , la identidad; y también subsume la programación lógica basada en similaridad al comportarse como las aproximaciones descritas en [64], y otros trabajos relacionados, cuando se toma D = U y se usan exclusivamente cláusulas con factor de atenuación 1. A nivel sintáctico, SQLP presenta muy pocas novedades con respecto a QLP. Las diferencias se harán patentes en la definición de la semántica declarativa que se verá en la siguiente subsección, ya que esta deberá ser extendida de manera adecuada para que se tenga en cuenta la relación de similaridad dada. En definitiva, la sintaxis de un SQLPprogramas es bastante sencilla: se trata de QLP-programas ampliados con una relación de similaridad que permitirá a unos símbolos jugar el papel de otros pagando un coste, e.g. disminuyendo la certidumbre del átomo probado o aumentando el coste mínimo de la prueba. Un programa para la instancia SQLP(S, U) es el que muestra el siguiente ejemplo.

36

Ejemplo 3.3 (SQLP: Piezas de roble). Supóngase que disponemos de una serie de piezas de diferentes materiales identificadas por un número. Una representación válida de esta serie de piezas es la colección de hechos que sigue: 1

C1

pieza(1, granito) ← − 1

C2

pieza(2, roble) ← −

C3

pieza(3, haya) ← −

C4

pieza(4, castaño) ← −

1

1

1

C5

pieza(5, mármol) ← −

Construimos ahora un predicado capaz de seleccionar las piezas de roble y dar, uno a uno, sus identificadores: 1

C6

sel_roble(X) ← − pieza(X, roble)

Asumiendo además la relación de similaridad S del ejemplo 3.1, un usuario esperaría obtener, para el objetivo sel_roble(Pieza)]W 8 W ≥? 0.8

las piezas 2 y 3. El caso de la pieza 2 es claro por ser una pieza de roble. El de la pieza 3, es debido a que el límite de certidumbre establecido por el objetivo es inferior al grado de similaridad entre los materiales roble y haya, por lo que a un nivel de certidumbre suficiente (en este caso mayor o igual que 0.8), es posible utilizar el material haya en lugar del material roble. Por este motivo, la pieza 3 debe ser también una solución válida al objetivo planteado. Nótese que la pieza 4, aún siendo de un material similar al roble, no lo es a un grado suficiente (al menos 0.8) como para poder jugar el papel del roble en este caso. La diferencia entre la solución 2 y la solución 3 vendrá dada por el valor máximo de la variable de cualificación W en cada caso: mientras que para la pieza 2 tendríamos que W 7→ 1; para la pieza 3, W 7→ 0.85. Como es fácil observar, el ejemplo anterior no saca partido de la cualificación, ya que los factores de atenuación de las seis cláusulas del programa coinciden con el máximo en el dominio de cualificación U. Así que, el ejemplo anterior podría considerarse como un SLP-programa si se sustituyen las implicaciones por “←”, al estilo de los programas de [64].

3.3.

Semántica declarativa

La semántica declarativa del esquema SQLP se basa en una extensión de la semántica de QLP para el tratamiento adecuado de las relaciones de similaridad. Nótese que en esta sección partiremos de la semántica del esquema QLP, y no de la del esquema BQLP, que fue la realmente desarrollada en la sección 2, por lo que las nociones de interpretación, consecuencia inmediata y modelo, y la caracterización del modelo mínimo, se harán a partir de la simplificación de las presentadas en dicha sección una vez eliminada la parte correspondiente a la bivaluación de los predicados y las restricciones umbrales de los cuerpos de las cláusulas. 37

3.3.1.

Interpretaciones y modelos

Antes de comenzar con la definición de las interpretaciones y modelos en el esquema SQLP, resulta conveniente exponer un problema que surge precisamente por la utilización de relaciones de similaridad. Para situarnos, considérese la relación de similaridad S del ejemplo 3.1 y el átomo d(X, X) donde d es una predicado binario de la signatura. Una instanciación cualquiera de dicho átomo, daría lugar a átomos que son: o bien de la forma d(Y, Y ) donde Y es una variable del conjunto de variables; o más en general de la forma d(t, t) donde t es un término construido de acuerdo con la signatura. Sin embargo, y dado que ahora nos encontramos bajo el influjo una relación de similaridad, será interesante poder instanciar el átomo d(X, X) de manera que los dos argumentos de d fueran no necesariamente iguales, sino similares de acuerdo con la relación de similaridad S empleada. Para ello, esperaríamos que tanto d(roble, roble) como d(roble, haya) fueran “instancias similares” del átomo d(X, X) —y este último porque S(roble, haya) 6= b—, y por lo tanto instancias aceptables para el átomo d(X, X). Para conseguir esto, tenemos dos alternativas: 1. variar la noción clásica de sustitución de variables por términos, de modo que se permitiera instanciar una misma variable con términos construidos de una clase de equivalencia inducida por la relación de similaridad; o bien 2. linealizar el átomo estableciendo restricciones adicionales sobre la manera en que el átomo lineal resultante debiera ser instanciado. Mientras que la primera opción parece mejor desde el punto de vista de la definición formal de un esquema de programación basado en similaridad, resulta más compleja de implementar. El motivo es que los sistemas Prolog disponibles implementan, obviamente, la noción estándar de sustitución y para conseguir el efecto deseado, se necesitaría implementar un sistema completo desde el principio, cosa que no resulta trivial si se espera conseguir un rendimiento comparable al de los sistemas Prolog existentes. Por este motivo, se desarrollará la segunda opción, de manera que se conseguirá obtener átomos equivalentes al original pero que permitan, realizando una instanciación clásica condicionada —dado que deberá cumplir condiciones adicionales—, obtener todos los átomos que son “instancias similares” del original. Así, dado un átomo A, diremos que lin(A) = (A` , S` ) es su versión lineal, en la que: A` es un átomo lineal; y S` es un conjunto de ecuaciones de la forma X ∼ Xi que indican que el término que resulte de la instanciación de la variable X debe ser similar, según la relación de similaridad S, al término que resulte de la instanciación de la variable Xi . La manera de construir la versión lineal de un átomo A cualquiera es la siguiente: A` se construye sustituyendo las n apariciones adicionales de una variable X cualquiera por variables nuevas Xi (con 1 ≤ i ≤ n); y S` es el conjunto de ecuaciones de similaridad X ∼ Xi (con 1 ≤ i ≤ n) condicionando las variables de A` a que tomen valores similares en los casos en que correspondieran a la misma variable X del átomo A. Un ejemplo de 38

este procedimiento es el siguiente. Nótese, en particular, qué ocurre cuando se tiene que el átomo original es lineal. Ejemplo 3.4 (Linealización). Sean H1 = p(c(X), Y ) y H2 = p(c(X), X, Y ) dos átomos. Entonces: lin(H1 ) = ( p(c(X), Y ), {} ). lin(H2 ) = ( p(c(X), X1 , Y ), {X ∼ X1 } ). A partir de la linealización lin(A) = (A` , S` ) de un átomo A cualquiera, resulta sencillo definir cuáles son las “instancias similares” a nivel δ de A. Se dirá que A0 es una instancia similar a nivel δ de A, o más formalmente que A0 es una S-instancia a nivel δ de A, en símbolos (A0 , δ) ∈ [A]S , cuando A0 sea una instancia de un átomo similar —con grado de similaridad δ diferente de b— a A` con una sustitución que satisfaga el conjunto de ecuaciones de similaridad S` a nivel δ. Para la definición formal de S-instancia de un átomo, véase [11](A.3, Def. 4). Nota 10. En la publicación [11](A.3) se denominaba R-instancia de un átomo a las Sinstancias de un átomo.

Una vez explicada la razón de por qué es necesario linealizar, y definida la noción de S-instancia de un átomo, puede continuarse con la definición de interpretación en el esquema SQLP. Las interpretaciones en SQLP se definen también como conjuntos de átomos cualificados cerrados, esta vez, bajo una relación denominada hS, Di-implicación, cuya finalidad es la de asegurar que si una interpretación I incluye un átomo cualificado A]d, entonces incluya también todos aquellos átomos cualificados que sean S-instancias de A]d. Formalmente, se dice que un átomo cualificado A]d hS, Di-implica de otro átomo cualificado A0 ]d 0 , en símbolos A]d
Finalmente, dado un SQLP-programa P, se dice que una interpretación I es modelo de α 0 una cláusula C de P, sii para toda S-instancia C 0 : A0 ← − B10 , . . . , Bm a nivel δ de C y 39

para cualesquiera valores de cualificación d1 , . . . , dm tales que Bi0 ]di ∈ I con 1 ≤ i ≤ m, d 0 entonces A ]d ∈ I donde d P α ◦ {δ, d1 , . . . , dm }. Y se dice que I es modelo de P sii I es modelo de toda cláusula C de P. 3.3.2.

Semántica basada en un cálculo lógico

Como ya se ha visto para el caso de la semántica declarativa del esquema QLP, existen dos posibles alternativas para caracterizar el modelo mínimo de un programa SQLP, bien mediante un transformador de interpretaciones, bien mediante un cálculo de inferencia lógica. Para este caso, y siguiendo la propuesta de la publicación [11](A.3), se propone únicamente una semántica basada en un cálculo de inferencia lógica, dado que ambas aproximaciones producen caracterizaciones equivalentes, y la extensión del transformador de interpretaciones presentado en la subección 2.3.2 resulta claramente sencilla. Se define, por tanto, un cálculo lógico denominado lógica de Horn cualificada basada en similaridad sobre hS, Di —i.e. SQHL(S, D)— compuesto también en este caso por una única regla de inferencia denominada Modus Ponens cualificado basado en similaridad —i.e. SQMP— tal y como puede verse en la figura 4.

SQMP

B10 ]d1

0 ]dm · · · Bm 0 A ]d

α

0 0 si (A0 ← − Bd 1 , . . . , Bm , δ) ∈ [C]S para alguna cláusula C ∈ P y d P α ◦ {δ, d1 , . . . , dm }.

Figura 4: Cálculo lógico SQHL(S, D)

De manera similar a como se hizo para el esquema QLP, la notación P `S,D A]d indica que el átomo cualificado A]d puede inferirse a partir de las cláusulas de P en un número finito de pasos de inferencia. En el caso de querer hacer explícito el número n de pasos de inferencia, se escribirá P `nS,D A]d. Nótese la diferencia en la notación `S,D con respecto a la notación `D correspondiente a la inferencia QHL (y también BQHL) del esquema QLP (o BQLP). Como ilustración del proceso de inferencia lógica en el cálculo SQHL(S, D) considérese el siguiente ejemplo. Ejemplo 3.5 (Derivación en SQHL). Sea S la relación de similaridad del ejemplo 3.1, y sea D el dominio de cualificación U de los valores de incertidumbre. Entonces el átomo sel_roble(3)]0.8 se deduce en SQHL a partir del programa del ejemplo 3.3 con el siguiente árbol de prueba: pieza(3, roble)]0.85 sel_roble(3)]0.8 donde:

40

(2) (1)

1

(1) Inferencia con cláusula (sel_roble(3) ← − pieza(3, roble), 1) ∈ [C6 ]S y sustitución {X 7→ 3} donde 0.8 ≤ 1 × min{1, 0.85}. 1

(2) Inferencia con cláusula (pieza(3, roble) ← −, 0.85) ∈ [C3 ]S y sustitución ε donde 0.85 ≤ 1 × min{0.85}.

Finalmente, la caracterización del modelo mínimo MP de un programa P dado, a partir del cálculo lógico SQHL(S, D), es MP = {A]d | P `S,D A]d} i.e. el conjunto de todos los átomos A]d que se deducen de las cláusulas del programa P en el cálculo SQHL(S, D). 3.3.3.

Objetivos y soluciones

Tanto los objetivos como las soluciones en SQLP presentan una forma idéntica a la de ambas nociones en el esquema QLP, dado que la relación de similaridad no influye en la definición declarativa de ambas nociones. Por lo tanto, únicamente se recordará la forma de un SQLP-objetivo y la definición de solución. Un SQLP-objetivo es una conjunción de átomos anotados abiertos A]W y un conjunto de restricciones umbral W Q β, con β ∈ D \ {b}, para las variables de cualificación que aparecen en la conjunción de átomos. Nota 12. En la publicación [11](A.3) no se consideraba la posibilidad de que β tomara el valor “?” al estar basada, la noción de objetivo y solución, en aquella desarrollada en la publicación [59](A.1) para el esquema QLP, que aún no tenía en cuenta dicha posibilidad.

Más concretamente, un objetivo es de la forma: A1 ]W1 , . . . , Am ]Wm 8 W1 Q β1 , . . . , Wm Q βm

o también, de manera más corta, ( Ai ]Wi , Wi Q βi )i=1...m . Por último, se dice que la pareja hθ, ρi, donde σ es una sustitución de variables por términos y µ es una sustitución de variables de cualificación por valores de cualificación, es una solución a un objetivo ( Ai ]Wi , Wi Q βi )i=1...m para un SQLP-programa P sii se tiene P `S,D Ai θ]Wi ρ con Wi ρ Q βi para i = 1 . . . m. El siguiente ejemplo ilustra esta noción de objetivo y solución utilizando para ello el SQLP-programa del ejemplo 3.3: Ejemplo 3.6 (SQLP: Objetivo y solución). Sea S la relación de similaridad del ejemplo 3.1 y P el SQLP(S, U)-programa del ejemplo 3.3. Entonces: G : sel_roble(P )]W 8 W ≥ 0.8

es un objetivo para P, y h{P 7→ 3}, {W 7→ 0.85}i una solución para G.

41

3.4.

Transformación de SQLP-programas en QLP-programas

Dado un SQLP(S, D)-programa P, existen dos alternativas a la hora de resolver objetivos G para el programa P: 1. adaptar el procedimiento de resolución SLD para SQLP-programas; 2. transformar los programas y objetivos SQLP en otros programas y objetivos equivalentes para los que exista un procedimiento de resolución de objetivos, y resolver sobre dichos programas y objetivos equivalentes. En esta sección, y partiendo de la existencia del procedimiento de resolución QSLD(D) para QLP(D) —que resulta de la simplificación de la resolución BQSLD(D) presentada en la subsección 2.4, y que fue presentado en [59](A.1, §4.2)—, se desarrolla un método de transformación de programas y objetivos SQLP en programas y objetivos QLP equivalentes. En cualquier caso, en [64] se desarrolla una adaptación de la resolución SLD estándar para programas lógicos con similaridad, y también hubiera sido posible desarrollar una adaptación de dicha resolución SLD con similaridad para SQLP-programas. La finalidad será, por tanto, la siguiente: dado un SQLP(S, D)-programa P, y un objetivo G para P, se obtendrá un QLP(D)-programa SS (P), semánticamente equivalente a P, sobre el que ejecutar el objetivo G. Nótese que el objetivo G no requiere de transformación alguna dado que es, sin cambios, tanto un SQLP(S, D)-objetivo para P, como un QLP(D)-objetivo para SS (P). La intuición que guiará la transformación de SQLP-programas en QLP-programas equivalentes es la de extender el conjunto de cláusulas que componen el SQLP-programa para que incluya toda la información contenida en la relación de similaridad S. De esta manera, puede eliminarse la relación de similaridad manteniéndose el sentido del programa original. Un pequeño ejemplo de esta idea es el siguiente: Ejemplo 3.7 (Intuición sobre la transformación; I). Sea D el dominio de cualificación U de los valores de certidumbre, y sea S la relación de similaridad del ejemplo 3.1. Entonces, el siguiente conjunto de cláusulas conforma un SQLP(S, U)-programa. 1

C1

pieza(1, granito) ← − 1

C2

pieza(2, roble) ← −

C6

sel_roble(X) ← − pieza(X, roble)

1

Nótese que es un subconjunto de las cláusulas del programa del ejemplo 3.3. Intuitivamente, es fácil ver que tanto pieza(1, granito)]1 como pieza(2, roble)]1 pertenecen al modelo mínimo, y por lo tanto también sel_roble(2)]1 pertenece al modelo mínimo (inferencia SQHL con la cláusula C6 y la sustitución {X 7→ 2}). Sin embargo, debido a la relación de similaridad S, también es cierto que pieza(1, mármol)]0.85, pieza(2, haya)]0.85 y pieza(2, castaño)]0.75 pertenecen al modelo mínimo (♠), y por lo tanto tenemos también que sel_roble(2)]0.85 y sel_roble(2)]0.75 pertenecen al modelo mínimo (♣). Los pasos (♠) y (♣) se explican a continuación.

42

(♠) Por un lado sabemos que el átomo pieza(1, mármol) es una S-instancia a nivel δ = 0.85 de pieza(1, granito). Por lo tanto, pieza(1, granito)]1
(2) (1)

(1) Cláusula C6 , que es S-instancia de sí misma con δ = 1, con sustitución {X 7→ 2} y donde 0.85 ≤ 1 × min{1, 0.85}. 1

(2) Cláusula C20 : (pieza(2, haya) ← −), que es S-instancia de C2 con δ = 1, con sustitución ε y donde 0.85 ≤ 1 × {0.85}. y sel_roble(2)]0.75 puede probarse también variando el paso (2) de la derivación anterior para utilizar la S-instancia de C2 que incluye castaño. De modo que, si quisiéramos ampliar el conjunto de cláusulas del programa con la información contenida en la relación de similaridad S, necesitaríamos transformar el programa al siguiente QLP(U)-programa equivalente: 1

C1

pieza(1, granito) ← −

C10

pieza(1, mármol) ← − pay 0.85

1

1

C2

pieza(2, roble) ← −

C20

pieza(2, haya) ← − pay 0.85

C200

pieza(2, castaño) ← − pay 0.75

1

1

1

C6

sel_roble(X) ← − pieza(X, roble)

C7

pay 0.85 ←−−

C8

pay 0.75 ←−−

0.85 0.75

Donde los átomos pay introducidos se encargan de calcular los δ que resultarían de la relación de similaridad en el cálculo de los valores de cualificación finales para las cabezas de las cláusulas, de este modo serían posibles también en QHL las inferencias equivalentes a las mostradas en (♠) y (♣)(2), aunque en QHL requerirían de una inferencia más con la cláusula C7 .

43

A partir del ejemplo anterior, puede verse que los QLP-programas transformados estarán compuestos por dos conjuntos de cláusulas: a) aquellas que vienen del conjunto de cláusulas original, ya fueran ellas mismas como en el caso de las cláusulas C1 , C2 y C6 , ya las que resultan de ser cláusulas con una cabeza similar —según S— a alguna cláusula original, como es el caso de C10 , C20 y C200 ; y b) aquellas que se encargan de computar el grado de similaridad entre la cabeza de una cláusula del primer conjunto y la cabeza de la cláusula SQLP original de la que proviene dicha cláusula, y que en la transformación se codifican en átomos pay, como las cláusulas C7 y C8 , con la que se resolverán los átomos pay introducidos en los cuerpos de las cláusulas del primer conjunto. En este punto, es importante hacer notar que en el ejemplo anterior las cabezas de las cláusulas eran lineales, i.e. se dice que el programa es lineal por la izquierda, y por lo tanto las ecuaciones de similaridad que aparecen al linealizar un átomo no lineal no han jugado papel alguno. Para poder ver qué ocurre en el caso de tener un programa que no sea lineal por la izquierda, considérese el siguiente ejemplo: Ejemplo 3.8 (Intuición sobre la transformación; y II). Sea D el dominio de cualificación U de los valores de certidumbre, y sea S la relación de similaridad del ejemplo 3.1. Entonces, la siguiente cláusula conforma un SQLP(S, U)-programa no lineal por la izquierda. 1

D1

− p(X, X) ←

Sin ánimo de ser exhaustivos aquí, nos centraremos en la prueba de dos posibles átomos cualificados que pueden deducirse de la cláusula D1 en el cálculo SQHL y que resultarán ilustrativos acerca de la problemática de la linealidad en las cabezas. El primero de ellos será p(roble, roble)]1 (♥), y el segundo p(granito, mármol)]0.85 (♦). En primer lugar, nótese que lin(p(X, X)) = (p(X, X1 ), {X ∼ X1 }). Y por lo tanto tenemos que: 1 D10 : p(roble, roble) ← − 1

D100 : p(granito, mármol) ← − son S-instancias de la cláusula D1 con δ = 1 y sustitución {X 7→ roble, X1 7→ roble} para D10 , y δ = 0.85 y sustitución {X 7→ granito, X1 7→ mármol} para D100 . Nótese además que, en efecto, (♥) se deduce del programa en SQHL con la cláusula D10 y con 1 ≤ 1 × min{1} = 1; y que (♦) se deduce del programa en SQHL con la cláusula D200 y con 0.85 ≤ 1 × min{0.85} = 0.85. Para conseguir hacer dos inferencias en QHL equivalentes a estas, parece claro que es necesario que el programa transformado tenga una versión lineal de la cláusula D1 en lugar de la propia D1 , de este modo será posible realizar instanciaciones como la requerida en el caso de (♦). Sin embargo, escribiendo una cláusula como 1

p(X, X1 ) ← − no obligará en la lógica QHL a que la sustitución θ escogida para el paso de inferencia con dicha cláusula cumpla que S(Xθ, X1 θ) 6= b. Por lo tanto, será necesario introducir un predicado especial adicional “∼” que se encargue de obligar a que las sustituciones

44

cumplan ciertas condiciones de similaridad que, en particular, serán aquellas que resulten de la linealización de la cabeza de la cláusula. En el caso que nos ocupa, tendríamos sólo una condición de similaridad, i.e. X ∼ X1 , por lo que deberemos añadirla a la versión linealizada de la cláusula, de manera que esta quedaría como sigue 000 D1

1

p(X, X1 ) ← − X ∼ X1

Finalmente, añadiendo también las cláusulas apropiadas para el predicado “∼” obtendríamos el comportamiento deseado en las inferencias QHL que utilizaran esta cláusula. En nuestro caso, para poder probar tanto (♥) como (♦), las cláusulas para “∼” necesarias serían: 1

D2

− X∼X←

D3

− pay 0.85 granito ∼ mármol ←

1

Y el programa QLP equivalente transformado sería: 000 D1

1

p(X, X1 ) ← − X ∼ X1 1

D2

− X∼X←

D3

granito ∼ mármol ← − pay 0.85

1

0.85

D4

pay 0.85 ←−−

permitiendo, en efecto: (♥) probar p(roble, roble)]1 en QHL con la siguiente demostración: Xθ1 ∼ X1 θ1 ]1 p(roble, roble)]1

(2) (1)

donde (1) Cláusula D1000 con θ1 = {X 7→ roble, X1 7→ roble} y donde 1 ≤ 1×min{1, 1}. (2) Cláusula D2 con θ2 = ε y donde 1 ≤ 1 × min{}. (♦) probar p(granito, mármol)]0.85 en QHL con la siguiente demostración: (3)

pay 0.85 θ3 ]0.85 Xθ1 ∼ X1 θ1 ]0.85 p(granito, mármol)]0.85

(2) (1)

donde (1) Cláusula D1000 con θ1 = {X 7→ granito, X1 7→ mármol} y donde 0.85 ≤ 1 × min{1, 0.85}. (2) Cláusula D3 con θ2 = ε y donde 0.85 ≤ 1 × min{0.85}. (3) Cláusula D4 con θ3 = ε y donde 0.85 ≤ 0.85 × min{}.

45

Tras este ejemplo, pueden verse dos cosas: 1. Las cláusulas que se utilizan para obtener el primer conjunto de cláusulas de la transformación, i.e. aquellas que vienen de las cláusulas originales, deberán ser las versiones lineales de las cláusulas originales, y no las originales. En cualquier caso, nótese que estas coinciden cuando el programa es lineal por la izquierda como ocurría en el caso del ejemplo 3.7. 2. Deberá añadirse un conjunto adicional de cláusulas que implementen el predicado “∼”, de manera que puedan resolverse los átomos correspondientes a dicho predicado y que obligarán a instanciar adecuadamente las cláusulas. Este conjunto de cláusulas para el predicado “∼” trasladarán a QLP la información contenida para las constructoras en la relación de similaridad S. Nótese que la información referida a los símbolos de predicado se utilizará en la generación de las cláusulas adicionales del primer conjunto. Así se tendrá, formalmente, que dado un SQLP(S, D)-programa P, el QLP(D)-programa transformado SS (P) equivalente será SS (P) = PS ] P∼ ] Ppay donde PS es el conjunto de cláusulas con cabezas parecidas a alguna cláusula linealizada del programa original P que contienen además un átomo pay con el grado de similaridad entre la cabeza de dicha cláusula y la cláusula linealizada original de la que proviene; P∼ es el conjunto de cláusulas que implementan el predicado ∼ con la información contenida en la relación de similaridad S para las constructoras de la signatura; y Ppay es el conjunto de cláusulas que permiten deducir los átomos pay necesarios que hayan sido introducidos en los cuerpos de las cláusulas presentes en cualquier de los dos conjuntos anteriores. Para una definición formal y exhaustiva de la transformación, véase [11](A.3, Def. 6). Por último, y como resultado principal de la trasformación de programas propuesta, se demuestra que dado un SQLP-programa P cualquiera, y su equivalente QLP-programa transformado SS (P), se tiene: P `S,D A]d ⇐⇒ SS (P) `D A]d para todo átomo cualificado A]d cuyo símbolo de predicado sea S-similar a un símbolo de predicado que aparezca en alguna cláusula de P. Este resultado prueba que todo átomo cualificado A]d de la signatura de P que es deducible en SQHL a partir del programa P, puede también deducirse en QHL a partir del programa SS (P). Y también, que todo átomo cualificado A]d de la signatura de P que es deducible en QHL a partir del programa SS (P), puede también deducirse en SQHL a partir del programa P. Esto prueba, de hecho, la equivalencia semántica de ambos programas en sus respectivos esquemas. Este resultado está demostrado en [11](A.3, T.1). Antes de terminar esta sección, resulta conveniente hacer dos comentarios que serán de relevancia en las secciones que siguen a continuación: 46

La ausencia de igualdad con similaridad en el esquema hace necesario aplicar una técnica como la de la linealización de los lados izquierdos de las cláusulas, y al desarrollo de las nociones de S-instancia que se han presentado. Aunque resulta posible variar las técnicas y nociones empleadas, es evidente que sin igualdad, se hace necesario algún mecanismo que permita obtener instancias “no tradicionales” de términos, átomos y cláusulas debidas a la relación de similaridad. El procedimiento de transformación seguido presenta la ventaja de evitar el uso del predicado “∼” cuando el programa SQLP es un programa lineal por la izquierda. Esto es así, porque los parecidos entre símbolos de predicado, o constructora, que aparezcan en los lados izquierdos de las cláusulas se resuelven, durante el proceso de transformación, añadiendo cláusulas adicionales con su respectivo átomo pay que asegura que se tenga en cuenta el grado de similaridad de ambas cabezas. Sin embargo, en esquemas de programación que permitan el uso de la igualdad es posible simplificar tanto la noción de instancia utilizada en la semántica de programas con similaridad como la técnica de transformación de programas con similaridad en programas sin similaridad semánticamente equivalentes. Así se hará en los esquemas de programación declarativa cualificada presentados en el resto de la tesis.

4.

Programación lógico-funcional con restricciones y cualificación

Las extensiones de la programación lógica que se han desarrollado hasta ahora incluyen la utilización de los valores de cualificación de un dominio de cualificación dado como generalización de los valores de incertidumbre utilizados por van Emden [71], y la utilización de las relaciones de similaridad al estilo de [64] como una forma de modelar la incertidumbre más cercana a la intuición. En esta sección, se extiende el esquema QLP de la programación lógica cualificada con dos elementos que no habían aparecido hasta ahora: por un lado, se incorpora un dominio de restricciones como los empleados en la programación lógica con restricciones (CLP); y por otro lado, se incorpora también la posibilidad de utilizar funciones perezosas de primer orden al estilo de la programación funcional (FP), dando lugar a un esquema paramétrico que se denomina QCFLP para la programación lógico-funcional con restricciones y cualificación. A pesar de que podría también hacerse uso de las relaciones de similaridad que se presentaron en la sección anterior, se optará ahora por dejarlas fuera del esquema para evitar las dificultades técnicas propias de la similaridad y, así, centrarse en el desarrollo de un marco de programación lógico-funcional básico con cualificación. Más concretamente, se parte de un fragmento de primer orden del esquema CFLP(C) para la programación lógico-funcional con restricciones sobre un dominio paramétrico C de restricciones presentado en [47]. Se extenderá dicho fragmento a un esquema QCFLP(D, C) en el que el parámetro adicional D representa un dominio de cualificación. Un QCFLP(D, C)programa P será, entonces, un conjunto de reglas condicionales de reescritura de la forma α

f (t n ) − →r ⇐∆ donde la condición ∆ es una conjunción de C-restricciones que pueden involucrar funciones definidas por el usuario, y α es el factor de atenuación de la regla. Como ocurría en los 47

esquemas de programación lógica con cualificación, el factor α representa la confianza del usuario en la inferencia indicada por la regla en cuestión: cualquier aplicación satisfactoria de la regla aplica al valor devuelto una cualificación que no puede exceder de la computada por medio del cálculo α◦d, donde d es el mínimo de los valores de cualificación computados para la expresión r y las C-restricciones pertenecientes a la conjunción ∆. Es sencillo observar que cualquier cláusula de un QLP(D)-programa puede ser formulada como caso particular de regla de un QCFLP(D, C)-programa. Dos sistemas para la programación lógico-funcional con restricciones que pueden servir de ilustración sobre la expresividad del marco utilizado como base para la extensión que se propone en esta sección son los sistemas Toy [6] y Curry [29]. Por último, el informe técnico [12](B.3) es una versión ampliada con demostraciones completas de los resultados de la publicación [13](A.4) en la que se basa esta sección de la tesis.

4.1.

Dominios de restricciones

Los dominios de restricciones se emplean en CLP y sus extensiones como un mecanismo para proporcionar valores de datos, funciones primitivas y restricciones específicas para aplicaciones orientadas a un área también específica. Existen varias formalizaciones de esta noción dadas por diferentes autores. Aquí emplearemos dominios de restricciones relacionados con signaturas Σ que incluyen un conjunto universal de símbolos de constructora de datos, un conjunto universal de símbolos de función definida y un conjunto de símbolos de función primitiva determinado por el dominio de restricciones considerado. Además, dada una signatura, un símbolo ⊥ para representar el valor indefinido, un conjunto B de valores básicos y un conjunto de variables Var , definimos las siguientes nociones donde o n abrevia o1 , . . . , on . Expresiones e. Son: o bien el valor indefinido ⊥; o bien una variable X ∈ Var ; o bien un valor básico u ∈ B; o bien de la forma h(e n ) donde h es un símbolo de constructora, de función definida o de función primitiva. Cuando n = 0, h(e 0 ) se escribe simplemente como h. Términos construidos t. Son: o bien el valor indefinido ⊥; o bien una variable X ∈ Var ; o bien un valor básico u ∈ B; o bien de la forma c(e n ) donde c es un símbolo de constructora. Cuando n = 0, c(t 0 ) se escribe simplemente c, y en adelante, se denominarán sencillamente términos. Expresiones o términos totales. Una expresión o un término se dice que es total cuando no es, ni contiene, el valor indefinido ⊥. Expresiones o términos cerrados. Una expresión o un término (totales o no) es cerrado si no es una variable, ni contiene variables X ∈ Var . Orden de información v. Se define como el menor orden parcial sobre las expresiones compatible con contextos y que verifica que ⊥ v e para toda expresión e. Sustitución. Se definen como funciones de variables a términos (no necesariamente totales), y se representan, tal y como hemos hecho hasta ahora, como conjuntos de vínculos X 7→ t extendidos para actuar sobre otros objetos sintácticos o.

48

Adaptando ahora la definición [47](§2.2, Def. 1) a primer orden, se formaliza un dominio de restricciones de signatura Σ como una estructura algebraica de la forma C = hC, {p C | p es símbolo de función primitiva}i tal que: 1. El conjunto soporte C es el conjunto de los términos cerrados sobre la signatura Σ y el conjunto de valores básicos B. 2. p C es la interpretación de la primitiva p en el dominio de restricciones C. Para una formalización más rigurosa, véase [12](B.3, Def. 2). Se asumirá, de ahora en adelante, la existencia de dos constructoras true y false para los valores booleanos, y un símbolo de función primitiva binaria == (que se usará en notación infija) para la igualdad estricta; véase [47] para más detalles. Para los ejemplos de esta sección, y la siguiente, y como ejemplo representativo de los dominios de restricciones, se considera el dominio de restricciones R de las restricciones reales cuyo conjunto de elementos básicos es el conjunto R de los números reales y cuyas funciones primitivas se corresponden con las operaciones aritméticas +, ×, . . . y las operaciones de comparación ≤, <, . . . usuales sobre R. Otros ejemplos de dominios de restricciones pueden encontrarse en [47]. Finalmente, se definen las tres nociones siguientes: C-restricción atómica. Son de la forma p(e n ) == v donde p es un símbolo de función primitiva y v es o bien una variable; o bien una constante (constructora de aridad 0); o bien un valor básico. Las C-restricciones atómicas de la forma p(e n ) == true se abrevian como p(e n ); en particular, (e1 == e2 ) == true se abrevia como e1 == e2 . Y las C-restricciones atómicas de la forma (e1 == e2 ) == false se abrevian como e1 /= e2 . C-restricción compuesta. Se construyen a partir de C-restricciones atómicas empleando conjunciones lógicas, cuantificaciones existenciales y, a veces, otras operaciones lógicas. Las C-restricciones sin apariciones de símbolos f de función definida se denominan primitivas. A lo largo de esta sección, denotaremos δ a las C-restricciones atómicas, ∆ a los conjuntos de C-restricciones atómicas, π a las C-restricciones atómicas primitivas y Π a los conjuntos de C-restricciones atómicas primitivas. Cuando se interpreten conjuntos de C-restricciones, se tratarán como la conjunción de sus C-restricciones atómicas miembro. Valoración de variables sobre C. Son sustituciones de variables por términos cerrados, i.e. tales que a cada variable de su dominio le asignan un término cerrado, o lo que es lo mismo, que no contiene variables. Por último, para las posibles instancias del esquema QCFLP objeto de esta sección, interesará que sus dos parámetros estén relacionados de una manera similar a como lo estaba la relación de similaridad S con respecto al dominio de cualificación D en las instancias del esquema SQLP(S, D). En este caso, se dice que una pareja hD, Ci es admisible cuando el dominio de cualificación D es expresable en el dominio de restricciones C. Y se dice que D es expresable en C cuando el conjunto soporte de C incluye todos los elementos del conjunto D (excepto quizás b) y además es posible construir dos C-restricciones primitivas especiales que sirven para calcular con valores de cualificación. 49

Nota 13. En posteriores publicaciones sobre el esquema SQCLP, la condición de que el conjunto soporte de C incluya a D \ {b} se ha relajado a la condición más general de que C incluya una copia isomorfa de D \ {b}.

Estas dos C-restricciones primitivas son: 1. qVal(X). Que se verifica cuando la variable X toma un valor de cualificación válido, i.e. distinto de b. 2. qBound(X, Y, Z). Que se verifica cuando las tres variables toman valores de cualificación válidos (distintos de b) y tales que X P Y ◦ Z se verifica también, cuando P y ◦ se sustituyen por las operaciones necesarias dependiendo del dominio de cualificación D que se desee expresar en C (y asumiendo que estas fueran expresables en C). Un ejemplo de la construcción de estas dos C-restricciones es el siguiente. Ejemplo 4.1 (Expresando W en R). Tomando el dominio de cualificación W de las profundidades ponderadas de la prueba, y el dominio R de las restricciones reales, se construyen las R-restricciones primitivas qVal(X) y qBound(X, Y, Z) de la siguiente manera: qVal(X) = X > 0. qBound(X, Y, Z) = qVal(X) ∧ qVal(Y ) ∧ qVal(Z) ∧ (X ≤ Y + Z).

4.2.

Sintaxis

Para la presentación de la sintaxis del esquema QCFLP, interesan instancias QCFLP(D, C) tales que la pareja hD, Ci sea admisible en el sentido de que D sea expresable en C, tal y como se ha visto al final de la subsección anterior. Son ejemplos de parejas admisibles las parejas hB, Ri, hU, Ri, hW, Ri y cualquier otra compuesta por un producto estricto de B, U y/o W y el dominio de restricciones R. Nota 14. Esto último sólo funciona si se permite que el conjunto soporte de R incluya una copia isomorfa de D \ {b} porque los elementos (d1 , d2 ) de un dominio producto no son, en general, elementos del conjunto soporte de R.

En la introducción de esta sección ya se indicó que un QCFLP(D, C)-programa P es un conjunto de reglas de programa condicionales de la forma α

f (t n ) − →r ⇐∆ En este punto se dirá, además, que f es un símbolo de función definida, t n es una secuencia lineal de términos, i.e. en la que cada variable aparece una única vez, α es un factor de atenuación del dominio D de cualificación distinto de b, r es una expresión y ∆ una secuencia de C-restricciones atómicas δ1 , . . . , δm interpretada como su conjunción. Por último, debe 50

tenerse en cuenta que el símbolo indefinido (⊥), que podía formar parte de términos y expresiones, no puede aparecer en una regla de programa por lo que todos los términos ti , la expresión r y las posibles C-restricciones δi que conforman una regla de programa deberán ser totales. A modo de ejemplo, considérese la versión lógico-funcional del ejemplo 2.1: Ejemplo 4.2 (QCFLP: Números de Peano). Sea D = W y C = R. Entonces, el siguiente conjunto de reglas de programa es un QCFLP(W, R)-programa para representar los números naturales según la representación de Peano y sumar con ellos: 0

1

num − →c

2

→ s(num) num −

3

suma(c, X) − →X

4

→ s(suma(X, Y )) suma(s(X), Y ) −

1

0

1

Nótese que tanto c como s son símbolos de constructora de datos, y que tanto num como suma son símbolos de función definida. Otro posible ejemplo es el siguiente, en el que define una función para estimar el nivel adecuado de lectura de un libro para estudiantes de lengua, a partir del nivel de su vocabulario, género y número de páginas. Ejemplo 4.3 (Nivel de lectura). Sea D = U y C = R. Entonces el siguiente conjunto de reglas de programa es un QCFLP(U, R)-programa capaz de estimar el nivel de dificultad de un libro dado, teniendo en cuenta su vocabulario, su género y su número de páginas: 1

1

estima_nivel(fácil, G, Págs) − → básico ⇐ Págs < 50 0.8

2

estima_nivel(fácil, G, Págs) −→ intermedio ⇐ Págs ≥ 50

3

estima_nivel(V , infantil, Págs) −→ básico

4

estima_nivel(difícil, G, Págs) −→ proficiencia ⇐ Págs ≥ 200

0.9

0.9

0.8

5

estima_nivel(difícil, G, Págs) −→ alto ⇐ Págs < 200

6

estima_nivel(medio, G, Págs) −→ intermedio

0.8

0.7

7

estima_nivel(medio, G, Págs) −→ alto

Nótese que este ejemplo está basado en el subconjunto de las reglas de programa para la función definida guessReaderLevel del ejemplo presentado en [11](A.3, Fig. 1).

4.3.

Semántica declarativa

Fijándonos en los ejemplos 4.2 y 4.3 que acaban de verse, resulta evidente que, aún sin tener en cuenta los factores de atenuación, se trata claramente de sistemas de reescritura de términos condicionales no confluentes, i.e. viendo únicamente las reglas de programa 1 y 2 del primero de los ejemplos está claro que pueden obtenerse resultados diferentes para una misma llamada a la función num. Las funciones diseñadas para comportarse de esa manera 51

se dice que son funciones no deterministas, y tal y como se argumenta en [57], la semántica para funciones no deterministas no puede describirse adecuadamente mediante la reescritura clásica. Por ello, y para la definición de la semántica declarativa del esquema QCFLP, se opta aquí por diseñar un sistema formal de inferencia denominado lógica de reescritura con restricciones condicional o, más brevemente, QCRWL(D, C). Nótese que también es posible caracterizar la semántica declarativa de QCFLP-programas como semántica de punto fijo, a pesar de que se opte únicamente aquí por una caracterización de la semántica basada en una lógica de reescritura. Una caracterización de este tipo, mediante un transformador de interpretaciones, se desarrolla con todo detalle en la primera parte de [12](B.3, §3.2). 4.3.1.

Semántica basada en una lógica de reescritura

El primer paso es el de definir el tipo de enunciados declarativos que podrán inferirse en la lógica QCRWL(D, C). De manera resumida, podrán inferirse qc-declaraciones ϕ de las dos formas siguientes: ϕ : (e → t)]d ⇐ Π, i.e. ϕ es una qc-producción, donde e es una expresión, t un término parcial, d un valor de cualificación distinto de b y Π un conjunto de Crestricciones primitivas atómicas. Intuitivamente, significa que t es uno de los valores posibles que se pueden obtener evaluando e con respecto a las reglas del programa, bajo el supuesto de que Π se satisface. Si t es un término parcial con apariciones de ⊥, se deberá entender como una aproximación de un valor total de e. Además, debido al indeterminismo, (e → t)]d ⇐ Π se podrá cumplir para varias elecciones diferentes de t. Las qc-producciones de la forma (f (t n ) → t)]d ⇐ Π donde f es un símbolo de función definida de aridad n se llaman qc-hechos. ϕ : δ]d ⇐ Π, i.e. ϕ es un qc-átomo, donde δ es una C-restricción atómica (no necesariamente primitiva), d un valor de cualificación distinto de b y Π un conjunto de C-restricciones primitivas atómicas. Intuitivamente, significa que el átomo δ se deduce de las reglas de programa con valor de cualificación asociado d, bajo la condición de que Π se satisface. Además, una qc-declaración ϕ se dice que es trivial cuando Π es insatisfactible, o también cuando ϕ es una qc-producción de la forma (e → ⊥)]d ⇐ Π. A continuación, se define QCRWL(D, C) como el sistema formal de inferencia que puede verse en [13](A.4, Fig. 2), y cuyas reglas de inferencia permiten, a partir de un QCFLP(D, C)-programa P, un conjunto Π de C-restricciones primitivas atómicas y un valor de cualificación d distinto de b, deducir lo siguiente: (QTI) toda qc-declaración trivial; (QRR) toda qc-producción de la forma (v → v )]d ⇐ Π donde v es una variable o un valor básico; (QDC) toda qc-producción de la forma c(e n ) → c(t n )]d ⇐ Π donde c es un símbolo de constructora de aridad n y d es tal que d P di con i = 1 . . . n, siempre que • (ei → ti )]di ⇐ Π para i = 1 . . . n

se deduzca de P; 52

α

(QDFP ) toda qc-producción de la forma (f (e n ) → t)]d ⇐ Π con la instancia f (t n ) − → r ⇐ δ1 , . . . , δm de una regla de programa de P, donde f es un símbolo de función definida de aridad n y d es tal que d P di con i = 1 . . . n y d P α ◦ dj0 con j = 0 . . . m, siempre que • (ei → ti )]di ⇐ Π para i = 1 . . . n,

• (r → t)]d00 ⇐ Π, y • δj ]dj0 ⇐ Π para j = 1 . . . m se deduzcan de P; (QPF) toda qc-producción de la forma (p(e n ) → v )]d ⇐ Π siendo p(t n ) → v una consecuencia de Π, y donde p es un símbolo de función primitiva de aridad n, v es variable, constante o valor básico, d es tal que d P di con i = 1 . . . n, siempre que • (ei → ti )]di ⇐ Π para i = 1 . . . n

se deduzca de P; y (QAC) toda qc-producción de la forma (p(e n ) == v )]d ⇐ Π siendo p(t n ) == v una consecuencia de Π, y donde p es un símbolo de función primitiva de aridad n, v es variable, constante o valor básico, d es tal que d P di con i = 1 . . . n, siempre que • (ei → ti )]di ⇐ Π para i = 1 . . . n

se deduzca de P. En particular, la regla QDFP formaliza la aplicación de la instancia de una regla de programa de P para inferir que f (e n ) devuelve como resultado t con cualificación d. Nótese que d estará limitado por las cualificaciones di correspondientes a la evaluación de los argumentos ei , y también por los α ◦ dj0 correspondientes a la atenuación con α de las evaluaciones del lado derecho y de las condiciones de la regla. De manera similar a como se ha hecho con el resto de cálculos de inferencia lógica, se escribirá P `D,C ϕ para indicar que ϕ se infiere en QCRWL a partir del QCFLP-programa P en un número finito de pasos de inferencia con las reglas de inferencia. Como ilustración del proceso de inferencia, véase el siguiente ejemplo. Ejemplo 4.4 (Derivación en QCRWL(D, C)). Considérese el programa del ejemplo 4.3. Entonces, puede inferirse la qc-producción (estima_nivel(difícil, ensayo, 59) → alto)]0.9 ⇐ ∅ a partir de las reglas de programa mediante el siguiente árbol de inferencia: (♠)

(♣)

(♥) (♦) (2) (alto → alto)]1 ⇐ ∅ (59 < 200)]1 ⇐ ∅ (estima_nivel(difícil, ensayo, 59) → alto)]0.9 ⇐ ∅ (♥)

53

(3) (1)

con: (♠) (♣) (♥) (♦)

(2)

(difícil → difícil)]1 ⇐ ∅ (ensayo → ensayo)]1 ⇐ ∅ (59 → 59 )]1 ⇐ ∅ (200 → 200 )]1 ⇐ ∅

(2)

(4) (4)

y donde cada paso de inferencia es posible porque: (1) Inferencia QDFP con instancia de la regla de programa 5 con sustitución {G 7→ ensayo, Págs 7→ 59}. Nótese que 0.9 ≤ 1 (para las tres primeras premisas) y que 0.9 ≤ 0.9 × 1 (para las dos últimas premisas). (2) Inferencia QDC dado que alto, difícil y ensayo son constantes. (3) Inferencia QAC con ∅ |=R (59 < 200) == true. Nótese que en realidad el qcátomo es (<(59, 200) == true)]1 ⇐ ∅ con < símbolo de función primitiva, y que este puede simplificarse en <(59, 200)]1 ⇐ ∅ o también (59 < 200)]1 ⇐ ∅ como aparece en la derivación. (4) Inferencia QRR dado que 59 y 200 son valores básicos. Extendiendo las ideas de [47], es posible definir las qc-interpretaciones [12](B.3, Def. 6) como conjuntos de qc-hechos que verifican ciertas condiciones de clausura como [12](B.3, Def. 5) y, además, los modelos [12](B.3, Def. 7) de un QCFLP-programa P pueden definirse como esas qc-interpretaciones que satisfacen el conjunto de reglas del programa P de un modo adecuado. Finalmente, es posible demostrar que el menor modelo de un QCFLPprograma P es SP = {ϕ | ϕ es un qc-hecho y P `D,C ϕ} tal y como se prueba en [13](A.4, T.1), es decir, que coincide con el conjunto de qc-hechos que son derivables en QCRWL a partir de las reglas de programa de P. Nótese que esto incluye, en particular, todos los qc-hechos triviales. 4.3.2.

Objetivos y soluciones

Las nociones de objetivo y solución que se presentan aquí continúan en la misma dirección que las nociones análogas para los esquemas vistos con anterioridad. En este caso, un objetivo G para un QCFLP-programa P tendrá la forma δ1 ]W1 , . . . , δm ]Wm 8 W1 Q β1 , . . . , Wm Q βm

abreviado como ( δi ]Wi , Wi Q βi )i=1...m , donde δi ]Wi son C-restricciones atómicas (no necesariamente primitivas) anotadas con variables de cualificación Wi donde recoger el valor de cualificación final con el que se prueba δi , y Wi Q βi son las condiciones umbral que limitan los valores de cualificación aceptables con los que se espera puedan probarse los átomos δi del objetivo. 54

De manera similar a como se presentaron los objetivos en los esquemas anteriores, las βi de las condiciones umbral podrían perfectamente aceptar un valor “?” que permitiese convertir en trivial la condición umbral, pero esto no se desarrolló en la publicación [13](A.4). La noción de solución será en este caso una terna hσ, µ, Πi donde σ es una sustitución de variables por términos, µ una sustitución de variables de cualificación por valores de cualificación y Π un conjunto de C-restricciones primitivas atómicas tales que: 1. Wi µ = di Q βi para i = 1 . . . m, y

2. P `D,C δi σ]Wi µ ⇐ Π para i = 1 . . . m. Es decir, si puede probarse en QCRWL a partir de P toda C-restricción atómica δi ]Wi del objetivo, implicada por Π, una vez instanciado δi por σ y Wi por µ. Y donde, además, µ asigna valores aceptables a las variables de cualificación — en el sentido de que se satisfagan todas las condiciones umbrales impuestas en el objetivo. Ejemplo 4.5 (Objetivo y solución). Sea P el QCFLP(U, R)-programa del ejemplo 4.3. Entonces: G : (estima_nivel(difícil, ensayo, 59) == alto)]W 8 W ≥ 0.9

es un objetivo para P y hε, {W 7→ 0.9}i una solución para G.

4.4.

Transformación de QCFLP-programas en CFLP-programas

La resolución de objetivos para las instancias CFLP(C) de [47] ha sido formalizada por medio de técnicas de estrechamiento con restricciones como puede verse en [46, 16], y está soportado en sistemas como Curry [29] y Toy [6]. En esta subsección estaremos interesados en proporcionar herramientas adecuadas tanto para la resolución de objetivos de instancias QCFLP(D, C) como para la implementación práctica de dichas instancias y, al igual que ocurría para el esquema SQLP presentado en la sección 3, se puede pensar en dos posibles alternativas: a) extender con cualificación un procedimiento de resolución de CFLP-objetivos existente; o b) transformar los QCFLP-programas en CFLP-programas equivalentes para los que se conozcan procedimientos de resolución de objetivos. Con vistas a una futura implementación de instancias del esquema QCFLP, la segunda opción resulta más conveniente y permite que el trabajo de implementación se centre en la implementación de la transformación de los QCFLP-programas a CFLP-programas equivalentes, pues los sistemas Curry [29] y Toy [6] ya pueden ejecutar CFLP-programas adecuadamente, y no tanto en la implementación completa del método de resolución —con todo el trabajo que ello conlleva— cuando la mayor parte de los problemas técnicos a los que nos enfrentaríamos han sido ya resueltos en los dos sistemas que hemos comentado. Por lo tanto, al igual que ya ocurriese en la sección 3, optaremos aquí por presentar una transformación de QCFLP(D, C)-programas en CFLP(C)-programas equivalentes o, más concretamente, en programas de un fragmento de primer orden de CFLP(C), al que por abuso de notación nos referiremos también como CFLP(C).

55

En [47] se ha mostrado que la semántica declarativa de CFLP(C) puede caracterizarse mediante una lógica de reescritura con restricciones CRWL(C) en la que pueden inferirse cdeclaraciones a partir de un programa dado. Una c-declaración será o bien una c-producción de la forma e → t ⇐ Π, o bien un c-átomo de la forma δ ⇐ Π. Si nos restringimos al fragmento de primer orden del esquema CFLP presentado en [47], la lógica de reescritura CRWL(C) puede formalizarse mediante seis reglas de inferencia que se obtienen sencillamente por eliminación de todo lo relativo a la cualificación del conjunto de reglas de reescritura presentadas en la subsección 4.3.1 para QCRWL(D, C) y, aunque en [13](A.4, §4) se da también la idea general de esta simplificación, al principio de [12](B.3, §4) se presenta la lógica de reescritura CRWL(C) completa. Análogamente, la notación P `C ϕ indica que ϕ puede inferirse a partir de P en CRWL(C) y, también en analogía con la caracterización del modelo mínimo de un QCFLP(D, C)-programa, es posible probar que SP = {ϕ | ϕ es un c-hecho y P `C ϕ} es el menor modelo de un CFLP(C)-programa P. Por lo que, para el resto de esta subsección, bastarán inferencias formales en las lógicas de reescritura QCWRL(D, C) y CRWL(C) para demostrar la corrección y completitud de la transformación propuesta. De manera análoga a la definición presentada en la subsección 4.3.2 para objetivos y soluciones en el esquema QCFLP, los objetivos G para un CFLP(C)-programa P tienen la forma δ1 , . . . , δm donde cada δi es una C-restricción atómica; y las soluciones son pares hσ, Πi tales que σ es una sustitución de variables por términos, Π es un conjunto de Crestricciones primitivas atómicas y se tiene que pueden probarse en CRWL, a partir de P, todas las C-restricciones atómicas δi del objetivo una vez instanciadas por σ e implicadas por Π. La transformación que se presenta a continuación presenta dos diferencias fundamentales con la presentada para SQLP-programas en la subsección 3.4: 1. Dado que el esquema CFLP no tiene cualificación, en esta transformación sí deberá indicarse cómo se debe operar con los valores de cualificación y, por lo tanto, aparecerán explícitamente las dos restricciones de cualificación mencionadas al final de la subsección 4.1, y que son dependientes de los dominios D y C elegidos como parámetros de la instancia QCFLP(D, C) que se está implementando. 2. Dado que los símbolos de función definida —que son a un QCFLP-programa lo que los símbolos de predicado a un SQLP-programa— aumentarán en uno su número de argumentos —el que corresponderá a la variable de cualificación—, y dado que estos pueden aparecer tanto en los argumentos de la cabeza de una regla de programa, como en la expresión del lado derecho y en las condiciones de la regla, la transformación de expresiones deja de ser trivial, como era el caso de los átomos en las cláusulas SQLP. Además, la transformación de programas y objetivos de QCFLP(D, C) a CFLP(C) debe tener en cuenta el hecho de que las dos lógicas de reescritura QCRWL(D, C) y CRWL(C) especifican que los símbolos de función definida se interpretan como funciones perezosas. Por otro lado, al no haber relaciones de similaridad en QCFLP, el número final de reglas de programa transformadas será, en esencia, el mismo que el de reglas de programa original, i.e. cada regla se transformará en una única regla transformada. En resumen, dado un

56

QCFLP(D, C)-programa P = {R1 , . . . , Rn }, obtendremos un CFLP(C)-programa P T = {R1T , . . . , RnT } ] {RqVal , RqBound } donde RiT es la transformación de cada regla de programa Ri de P, y RqVal y RqBound serán, respectivamente, las reglas de programa que implementen en CFLP(C) dos funciones correspondientes a las C-restricciones qVal y qBound encargadas de representar a D en C. Nota 15. En la presentación realizada en [13](A.4) no se precisó de manera suficientemente explícita la construcción de funciones definibles en CFLP(C) que correspondan a las restricciones qVal y qBound al realizar la transformación de programas. En la sección 6 se verá un tratamiento detallado de este asunto para el esquema SQCLP, el cual se puede adaptar muy fácilmente a QCFLP.

Formalmente, la transformación consta de 4 grupos de reglas de transformación que pueden verse en [13](A.4, Fig. 3). Estos grupos son: 1) reglas de transformación de expresiones; 2) reglas de transformación de qc-declaraciones; 3) reglas de transformación de reglas de programa; y 4) reglas de transformación de objetivos. En esta presentación nos centraremos en la explicación intuitiva de los cuatro grupos de reglas, relegando los detalles técnicos y formales de la transformación a la publicación [13](A.4) y el informe técnico [12](B.3) que la extiende. Los resultados relativos a la transformación de programas y objetivos QCFLP a programas y objetivos equivalentes CFLP son los teoremas de corrección y completitud para la transformación de programas [13](A.4, T. 2) y objetivos [13](A.4, T. 3) que prueban la equivalencia semántica de ambos programas y objetivos (el original y su transformado) a partir de la derivabilidad en QCRWL(D, C) y CRWL(C). 4.4.1.

Transformación de expresiones

La transformación de una expresión e nos dará, en concreto, una terna e T = (e 0 , Ω, W) donde e 0 es también una expresión, Ω es un conjunto de restricciones de cualificación y W es el conjunto de variables de cualificación que aparecen en e 0 en la posición más exterior. Aunque normalmente W contendrá una única variable de cualificación, en general no podrá asegurarse. La razón del conjunto Ω es la de asegurar que las variables de cualificación que aparecen en e 0 se instancien de manera satisfactoria, i.e. cumpliendo lo que dicta la lógica de la cualificación en cada caso. Y la del conjunto W es la de permitir el “enganche” de la expresión e 0 en una expresión o regla de programa mayor que contenga, a su vez, otras variables de cualificación que deban instanciarse de manera que sus valores de cualificación no excedan a aquellos valores de cualificación que instancien las variables de cualificación de e 0 . Por construcción de ambos conjuntos, bastará con que la expresión o regla de programa contenedora de e 0 establezca restricciones de cualificación adicionales entre las variables de cualificación que no aparecen en e 0 (que deberán instanciarse con valores de cualificación acotados superiormente en función de los valores de las variables de cualificación de e) y 57

las variables de cualificación más exteriores de e 0 (que aparecerán en el conjunto W), dado que será el conjunto de restricciones de cualificación Ω de la expresión e 0 el que se encargue de asegurar eso mismo para las variables de cualificación exteriores de e 0 con respecto a las posibles variables de cualificación interiores de e 0 . Veamos un ejemplo: Ejemplo 4.6 (Transformación de expresiones). Sea e la siguiente expresión: e = suma( suma(s(c), c), suma(s(s(c)), s(c)) ) Al ser suma un símbolo de función definida, el transformado de nombre suma’ tendrá un argumento más, el correspondiente a la variable de cualificación. El resto de símbolos, permanecen sin cambios, así: e 0 = suma0 ( suma0 (s(c), c, W1 ), suma0 (s(s(c)), s(c), W2 ), W3 ) porque tanto s como c son símbolos de constructora de datos. Dado que las subexpresiones suma0 (s(c), c, W1 ) y suma0 (s(s(c)), s(c), W2 ) son interiores a e 0 , no tendría sentido que una sustitución ρ de variables de cualificación por valores de cualificación hiciera W3 ρ Q W1 ρ ni tampoco W3 ρ Q W2 ρ, porque estaría diciendo que es posible probar e 0 con un valor de cualificación mejor que con los que es posible probar sus subexpresiones. Por lo tanto, el conjunto de restricciones Ω deberá evitar este tipo de instanciaciones incluyendo dos restricciones de cualificación W3 P W1 y W3 P W2 . Entonces: Ω = {qVal(W1 ), qVal(W2 ), qVal(W3 ), qBound(W3 , t, W1 ), qBound(W3 , t, W2 )}

Nótese que las dos restricciones de cualificación qBound utilizan t como factor de atenuación porque en este caso no hay factor de atenuación que aplicar. Por último, la variable que será necesaria “enganchar” cuando queramos utilizar e 0 en otra expresión mayor o en una regla de programa será W3 , por lo que W = {W3 } y entonces: e T = (e 0 , Ω, W).

4.4.2.

Transformación de qc-declaraciones

Las qc-producciones y los qc-átomos incondicionales se transforman mediante reglas basadas, de la manera obvia, en la transformación de expresiones. Así: (e → t)T = (e 0 → t, Ω, W) siempre que e T = (e 0 , Ω, W). S S (p(e n ) == v )T = (p(e 0 n ) == v , ni=1 Ωi , ni=1 Wi ) donde p es símbolo de función primitiva y v es variable, constante o valor básico, y siempre que eiT = (ei0 , Ωi , Wi ) para i = 1 . . . n. Las qc-declaraciones ϕ]d ⇐ Π se transforman en c-declaraciones ϕ0 ⇐ Π0 donde la parte condicional Π0 incluye, además de Π, las restricciones de cualificiación Ω provenientes de ϕ0 y otras restricciones de cualificación que aseguren que d esté acotado superiormente por los valores de cualificación con los que se prueben las variables de cualificación en ϕ0 .

58

4.4.3.

Transformación de reglas de programa

Las reglas de programa se transforman basándose en la transformación de la expresión del lado derecho y la transformación de las C-restricciones del conjunto de condiciones de la regla. Así, una QCFLP-regla como α

f (t n ) − → r ⇐ δ1 , . . . , δm se transforma en una CFLP-regla de la forma f 0 (t n , W ) → r 0 ⇐ qVal(W ), Ωr , ( qBound(W, α, W 0 ) )W 0 ∈Wr , ( Ωi , ( qBound(W, α, W 0 ) )W 0 ∈Wi , δi0 )i=1...n donde W es una variable de cualificación nueva, siempre que: r T = (r 0 , Ωr , Wr ), y δiT = (δi0 , Ωi , Wi ) para i = 1 . . . m. En particular, el conjunto de condiciones finales de la CFLP-regla resultante es tal que: 1. obliga a que la nueva variable de cualificación W , que será la que devuelva el valor de cualificación final con el que se puede probar, en efecto, que f (t n ) → r , sea un valor aceptable de cualificación; 2. incluye las restricciones de cualificación que sean necesarias debido a la transformación del lado derecho r ; 3. incluye las restricciones de cualificación adicionales necesarias que dicen que W no puede ser mejor que la atenuación con α de las variables de cualificación exteriores de r 0 ; y por último 4. incluye, para cada condición δ del conjunto de condiciones original, las restricciones de cualificación que sean necesarias debido a la transformación de la condición δ de la regla orginal, incluye las restricciones de cualificación adicionales necesarias para indicar que el valor de W ha de estar acotado superiormente por los resultados de atenuar con α los valores de las variables de cualificación exteriores de la condición δ 0 e incluye la propia δ 0 que resulta de la transformación de la original δ. Un caso particular es cuando el conjunto de condiciones en la regla original es vacío, en este caso, una QCFLP-regla como α f (t n ) − →r se transforma en una CFLP-regla de la forma f 0 (t n , W ) → r 0 ⇐ qVal(W ), Ωr , ( qBound(W, α, W 0 ) )W 0 ∈Wr , qBound(W, α, t) donde W es una variable de cualificación nueva, siempre que: r T = (r 0 , Ωr , Wr ).

59

Lo que tiene el efecto de asegurar que W no pueda ser mejor que el factor de atenuación de la QCFLP-regla en cuestión. Además, cuando ocurre que Wr = ∅, se tendrá también que Ωr = ∅ y por lo tanto las condiciones de la CFLP-regla transformada relativas al lado derecho se eliminan. Como ilustración, considérese el siguiente ejemplo. Ejemplo 4.7 (Transformación de programas). Considérese el QCFLP(W, R)-programa del ejemplo 4.2. Su CFLP(R)-programa equivalente es el siguiente: 1

num(W ) → c ⇐ qVal(W ), qBound(W, 0, 0)

2

num(W ) → s(num(W1 )) ⇐ qVal(W ), qVal(W1 ), qBound(W, 1, W1 )

3

suma(c, X, W ) → X ⇐ qVal(W ), qBound(W, 0, 0)

5

suma(s(X), Y, W ) → s(suma(X,Y,W1 )) ⇐ qVal(W ), qVal(W1 ), qBound(W, 1, W1 ) qVal(X) → true ⇐ X ≥ 0

6

qBound(X, Y, Z) → true ⇐ X ≤ Y + Z

4

Nótese que el programa traducido incluye dos reglas encargadas de definir las funciones qVal y qBound, que implementan las dos C-restricciones de nombre idéntico que se corresponden con la representación del dominio de cualificación D dentro del dominio de restricciones C, y que no hacían falta en el programa original.

4.4.4.

Transformación de objetivos

La transformación de objetivos QCFLP en objetivos CFLP equivalentes se realiza transformando un objetivo ( δi ]Wi , Wi Q βi )i=1...m por medio de transformaciones individuales para cada C-restricción atómica δi de forma que, si: δiT = (δi0 , Ωi , Wi )

entonces: ( δi ]Wi , Wi Q βi )T = Ωi , qVal(Wi ), (qBound(Wi , t, W ))W ∈Wi , qBound(βi , t, Wi ), δi0

para asegurar que cada variable de cualificación Wi se interpreta como un valor de cualificación acotado superiormente por la mayor cualificación calculada para δi y satisfaciendo también la condición umbral Wi Q βi impuesta en el objetivo. Como ilustración, considérese el siguiente ejemplo. Ejemplo 4.8 (Transformación de objetivos). Sea G el QCFLP-objetivo suma(s(c), X, s(s(c)))]W1 8 W1 ≤ 5

para el QCFLP-programa P del ejemplo 4.2. Entonces el transformado G T de G es qVal(W ), qVal(W1 ), qBound(W1 , 0, W ), qBound(5, 0, W1 ), suma(s(c), X, s(s(c)), W )

dado que (suma(s(c), X, s(s(c))))T = (suma(s(c), X, s(s(c)), W ), {qVal(W )}, {W }).

60

5.

Programación lógica con restricciones, cualificación y proximidad

En esta sección se define un esquema genérico SQCLP cuyas instancias SQCLP(S, D, C) están parametrizadas por una relación de proximidad S, un dominio de cualificación D y un dominio de restricciones C; y se muestra cómo muchos de los esquemas anteriores propuestos pueden verse como casos particulares de SQCLP obtenidos mediante instanciación parciales de sus parámetros. Además, se presenta una semántica declarativa para SQCLP inspirada en la semántica de observables para CLP de [24, 23] que proporciona caracterizaciones de punto fijo y basadas en un cálculo lógico de los modelos mínimos, así como una noción de solución a objetivos que resulta independiente de implementación y que puede utilizarse para especificar el comportamiento esperado, en la práctica, de un sistema de resolución de objetivos. Concretamente, el esquema SQCLP proporcionará: 1. programación con restricciones al estilo de CLP(C) de [35] para un dominio de restricciones C (véase 4.1); 2. programación cualificada con elementos de un dominio de cualificación D (véase 2.1) con atenuaciones α en las cláusulas de los programas y restricciones umbrales en los cuerpos de las mismas al estilo de las presentadas en la sección 2.2; y 3. relaciones de proximidad S como generalización de las relaciones de similaridad (véase 3.1) al relajar el axioma de transitividad. Nota 16. Aquí se mantiene la notación S para las relaciones de proximidad y la letra S en el nombre del esquema a pesar de tratarse en este momento de una generalización de las relaciones de similaridad.

La publicación [61](A.5) detalla las principales características de la semántica declarativa de SQCLP, y el informe técnico [62](B.4) es una extensión detallada de aquella con explicaciones y resultados auxiliares y demostraciones completas todos sus resultados. Finalmente, mientras que el objeto de esta sección será la definición de la semántica declarativa del esquema SQCLP, la próxima sección se centrará en la implementación de SQCLP, mediante técnicas de transformación de programas al estilo de las vistas en las secciones 3.4 y 4.4, sobre los sistemas CLP(C) SICStus Prolog y SWI-Prolog.

5.1.

Base computacional

El esquema SQCLP hace uso de los dominios de cualificación que se vieron en la sección 2.1; las relaciones de proximidad (como generalización de las relaciones de similaridad) vistas en la sección 3.1; y los dominios de restricciones vistos en la sección 4.1, una vez adaptados al marco de la programación lógica sin funciones. En esencia, los dominios de cualificación no presentan diferencias con respecto a las vistas con anterioridad. Las relaciones de proximidad se definen como relaciones de similaridad que pueden no cumplir el axioma de transitividad. Así, dado un dominio de cualificación D con conjunto 61

soporte D y un conjunto S, se define formalmente una relación de proximidad D-valuada sobre el conjunto S como cualquier función S : S×S → D tal que los dos axiomas siguientes se satisfacen para todo x, y , z del conjunto S de la relación de proximidad: Reflexividad. S(x, x) = t. Simetría. S(x, y ) = S(y , x). Nótese que la identidad Sid tal y como fue definida en la sección 3.1 es también una relación de proximidad, y que las extensiones de una relación de proximidad a elementos construidos como términos y átomos se realizan también como en el caso de las relaciones de similaridad. Y, por último, los dominios de restricciones se definen análogamente a como se ha visto en la sección 4.1, aunque adaptándolos a su uso en el contexto de un esquema de programación lógica puramente relacional. Así: Términos construidos t. Son: o bien una variable X ∈ Var ; o bien un valor básico u ∈ B; o bien de la forma c(t n ) donde c es un símbolo de constructora de aridad n. Cuando n = 0, c(t n ) se escribe simplemente c. Nota 17. Ahora no pueden ser el valor indefinido (⊥).

Átomos A. Pueden ser: átomos definidos r (t n ), donde r es un símbolo de predicado definido; átomos primitivos κ : p(t n ), donde p es un símbolo de predicado primitivo; o ecuaciones t1 == t2 , donde == es el símbolo de igualdad, que no pertenece a la signatura. La definición del dominio R de restricciones reales varía en el sentido de que su conjunto de operaciones primitivas +, −, . . . y de comparaciones primitivas >, ≥, . . . pasan a ser conjuntos de predicados de operación primitivos op+ , op− , . . . y predicados de comparación primitivos cp> , cp≥ , . . . de aridad 3 y 2, respectivamente. A diferencia del esquema QCFLP, en SQCLP las primitivas de cualquier dominio de restricciones se representan por medio de predicados, por lo que no pueden anidarse. Por ejemplo, una restricción que podría escribirse en QCFLP como: Y > 2 ∗ (X + 1) debe escribirse en SQCLP del siguiente modo: ∃Z1 ∃Z2 (op+ (X, 1, Z1 ) ∧ op∗ (2, Z1 , Z2 ) ∧ cp> (Y, Z2 )) en la que el tercer argumento de las operaciones op+ y op∗ es donde devuelven el resultado. Para una definición más formal, véase [62](B.4, Def. 2.6). Para terminar con la base computacional del esquema SQCLP, se introducen tres nociones auxiliares que resultan de interés al permitir comparar, a distintos niveles, la igualdad entre elementos de la signatura. Dado un dominio de restricciones C y una relación de proximidad S, se dice: que t y s son Π-equivalentes, y se escribe t ≈Π s, cuando se cumpla Π |=C t == s, véase [62](B.4, Lem. 2.2) para propiedades de ≈Π ;

62

que t y s son próximos a nivel λ, y se escribe t ≈λ s, cuando se cumpla S(t, s) Q λ, véase [62](B.4, Lem. 2.5) para propiedades de ≈λ ; y

que t y s son Π-próximos a nivel λ, y se escribe t ≈λ,Π s, cuando se cumpla que existen tˆ y sˆ tales que t ≈Π tˆ, s ≈Π sˆ y tˆ ≈λ sˆ, véase [62](B.4, Lem. 2.7) para propiedades de ≈λ,Π .

5.2.

Sintaxis

En el esquema SQCLP interesarán instancias SQCLP(S, D, C) que cumplan ciertas condiciones de admisibilidad para la terna hS, D, Ci que, en esencia, no son más que la unión de las condiciones de admisibilidad que se vieron para los esquemas SQLP y QCFLP, es decir: 1. que la relación S sea una relación de proximidad D-valuada; y 2. que el dominio de cualificación D sea representable en el dominio de restricciones C. Por lo tanto, se dirá que hS, D, Ci es una terna admisible cuando cumpla las condiciones (1) y (2). Nota 18. La noción de representabilidad de un dominio de cualificación en un dominio de restricciones ha sido refinada, con respecto a como se presentaba en publicaciones anteriores, por medio de una función inyectiva ı que asigna, a cada valor de cualificación (tal vez excepto b) un elemento del conjunto soporte del dominio de restricciones. En el informe técnico [62](B.4, §2.2.5) puede verse este refinamiento con más detalle.

Al igual que en secciones anteriores, un SQCLP(S, D, C)-programa P será un conjunto de cláusulas cualificadas de la forma α

H← − B1 ]w1 , . . . , Bm ]wm en la que H, B1 , . . . , Bm son átomos, α es un factor de atenuación de D distinto de b y los w1 , . . . , wm son o bien elementos de D distintos de b, o bien “?”, y representan la restricción umbral con la que cada átomo del cuerpo debe poder probarse. La intuición que hay detrás de una SQCLP-cláusula cualificada es la siguiente: si para todo 1 ≤ j ≤ m se tiene que puede probarse Bj ]ej para un valor de cualificación ej satisfactorio, i.e. ej Q? wj , entonces podrá inferirse A]d, para cualquier átomo A que sea Π-próximo a nivel δ de la cabeza H de la cláusula, siempre que el valor de cualificación d esté acotado superiormente por el nivel δ de Π-proximidad y por el ínfimo de las atenuaciones con α de los valores de cualificación ej con los que se probaron los Bj . Un ejemplo motivador utilizado en las publicaciones es el siguiente: Ejemplo 5.1 (SQCLP: Obras). Sea S como aparece más adelante, D = U⊗W y C = R. Entonces: (0.75,3)

1

buena_obra(X) ←−−−− famoso(Y )](0.5, 100), escribió(Y, X)]?

2

famoso(shakespeare) ←−−−

3

escribió(shakespeare, king_lear ) ←−−

(0.9,1)

(1,1)

S(king_lear , king_liar ) = (0.8, 2)

63

es un SQCLP(S, U⊗W, R)-programa P en el que las cualificaciones (d, e) son tales que d representa el grado de certidumbre con el que confiamos en la veracidad de la información y e el coste de obtener (o demostrar) dicha información. Así, la restricción umbral (0.5, 100) que aparece en el cuerpo de la cláusula 1 nos sirve para indicar que estamos interesados sólo en utilizar dicha cláusula cuando Y tome el valor de una persona famosa con certidumbre de al menos 0.5 y que no cueste obtenerla más de 100 unidades.

5.3.

Semántica declarativa

Al igual que se hizo en la sección 2.3, y con el objetivo de ser más completos y formales, se desarrollan a continuación las dos caracterizaciones alternativas de la semántica declarativa más conocidas: una semántica de punto fijo, y otra basada en un cálculo lógico, ambas inspiradas por [24, 23]. Estas dos publicaciones proponían tres semánticas para programas S1 , S2 y S3 diferentes que caracterizaban soluciones válidas cerradas para objetivos, soluciones válidas abiertas para objetivos y respuestas calculadas para objetivos en CLP, respectivamente. En la publicación a la que se corresponde esta sección, se desarrolla una semántica al estilo de la S2 que permite caracterizar soluciones válidas abiertas para SQCLP-objetivos y que se expone a continuación. Como base de la semántica, se trabajará con qc-átomos de la forma A]d ⇐ Π en los que se pretende asertar que el átomo A es consecuencia del conjunto de C-restricciones Π con valor de cualificación d. Además, se utilizará también una noción especial de implicación con la intención de capturar algunas implicaciones entre qc-átomos cuya validez no depende de la relación de proximidad S ni de la semántica de los predicados definidos. Estas nociones son: Un qc-átomo A]d ⇐ Π se dice que es definido, primitivo o ecuacional según sea la forma del átomo A. Un qc-átomo A]d ⇐ Π se dice que es observable cuando d es distinto de b y Π es satisfactible. Dados dos qc-átomos ϕ : A]d ⇐ Π y ϕ0 : A0 ]d 0 ⇐ Π, se dice que ϕ hD, Ci-implica ϕ0 , y se escribe ϕ
En lo que sigue, se centra la atención en qc-átomos observables porque podrán ser interpretados como observaciones de soluciones abiertas válidas para objetivos atómicos en SQCLP(S, D, C) como se verá en la subsección 5.3.4. Como ya ocurriera en la sección 2, las nociones de interpretación, consecuencia inmediata y modelo son coincidentes para ambas caracterizaciones de la semántica declarativa, y son el objeto de la siguiente subsección.

64

5.3.1.

Interpretaciones y modelos

Las qc-interpretaciones (o interpretaciones) I en SQCLP son conjuntos de qc-átomos definidos observables cerrados bajo hD, Ci-implicación. A diferencia de la noción de implicación empleada en la semántica del esquema SQLP, en esta la relación de proximidad no juega ningún papel. El motivo es que el cierre de un conjunto de átomos con una relación de implicación es transitivo por naturaleza, y dado que la relación de proximidad no tiene porqué ser transitiva obligaría a probar más átomos de los que pueden probarse directamente con la relación de proximidad. Es decir, considérese la instancia SQCLP(S, U, R) donde la relación de proximidad S es tal que S(a, b) = 0.8, S(b, c) = 0.8. Y sea S(a, c) = 02 y el qc-átomo a]1 ⇐ ∅ un qc-átomo perteneciente a una interpretación I del esquema SQCLP. Debido a la noción de hD, Ci-implicación, y dado que I que contiene a a]1 ⇐ ∅, deberá contener también a cualquier qc-átomo más particular que él mismo o con peor cualificación, así que tendremos también que cualquier qc-átomo de la forma a]λ ⇐ ∅ con 0 < λ ≤ 1 pertenece también a I por ser más particular y con peor cualificación que a]1 ⇐ ∅. Ahora bien, si la relación de hD, Ci-implicación tuviera en cuenta la proximidad, se tendría que si a]1 ⇐ ∅, entonces también b]0.8 ⇐ ∅ porque se consideraría más particular que a]1 ⇐ ∅, y si se quisiera hacer el cierre de esa implicación, deberían introducirse también las implicaciones de este nuevo qc-átomo, haciendo que, de hecho, c]0.8 ⇐ ∅ pertenezca a I, por ser a su vez más particular que b]0.8 ⇐ ∅, y este más particular que a]1 ⇐ ∅, a pesar de que la relación de proximidad dice expresamente que S(a, c) = 0. En consecuencia, no resulta aceptable decir que un átomo próximo a otro es “más particular” que el primero, y por lo tanto, no debe deducirse directamente de que un átomo pertenezca a una interpretación que sus átomos próximos también pertenezcan a ella. La noción de implicación utilizada en la sección 3 y sus publicaciones asociadas [11](A.3) y [14](B.2) sí dependía de S, y ello no causaba problemas técnicos debido a que S se suponía transitiva. No obstante, también hubiese sido factible definir una semántica de SQLP basada en una implicación entre átomos independiente de S. Como se habrá observado, se ha dicho que existen qc-átomos definidos, primitivos y ecuacionales y, sin embargo, las interpretaciones se han definido como conjuntos de qcátomos observables definidos. Esto se ha hecho así porque la validez de los átomos primitivos depende únicamente del conjunto de C-restricciones, y la validez de las ecuaciones depende únicamente de la relación de proximidad S y del conjunto de restricciones C. Formalmente, se dice que un qc-átomo observable ϕ es válido en una interpretación I, y se escribe como I ``S,D,C ϕ, sii se da alguno de los tres casos siguientes: ϕ es definido y pertenece a I; ϕ es de la forma κ]d ⇐ Π primitivo, y es consecuencia de Π, i.e. Π |=C κ; ϕ es de la forma (t == s)]d ⇐ Π ecuacional, y t y s son Π-próximos a nivel d, i.e. t ≈d,Π s. La noción de consecuencia inmediata simplifica la posterior definición de la noción de modelo y de las caracterizaciones de la semántica declarativa. Intuitivamente, son consecuencias inmediatas de una interpretación dada, con respecto a la instancia de una cláusula 2 Nótese

que S no es transitiva porque no se tiene S(a, c) Q S(a, b) u S(b, c) = 0.8.

65

lógica cualificada también dada, aquellos qc-átomos A]d ⇐ Π que son próximos a nivel d0 a la cabeza de la cláusula instanciada, entendiendo que un qc-átomo es próximo a nivel λ a la cabeza de una cláusula cuando el símbolo de predicado de ambos elementos es próximo a dicho nivel, y puede probarse que los argumentos del qc-átomo son Π-próximos a nivel λ a los argumentos de la cabeza de la cláusula, y además: el cuerpo de la cláusula instanciada es válido en la interpretación para valores de cualificación adecuados, i.e. mejores que sus restricciones umbrales respectivas; y el valor de cualificación d del qc-átomos es peor o igual que el ínfimo entre λ y de la atenuación de los valores de cualificación empleados para probar los átomos del cuerpo. Nota 19. Otra diferencia con respecto al esquema SQLP es que los valores de cualificación que son debidos a la relación de proximidad no se atenúan con el factor de atenuación de la cláusula aplicada, dado que la información que proporcionan no es debida a la implicación de la cláusula sino al parecido de un elemento que ya ha sido probado fehacientemente para un determinado grado de cualificación.

Es decir, son consecuencias inmediatas de una interpretación dada via una cláusula de programa también dada, aquellos qc-átomos que son próximos a la cabeza de la cláusula instanciada cuyo cuerpo es válido en la interpretación para un valor de cualificación mejor que con el que se prueba la cabeza. Formalmente, dadas una interpretación I y una cláusula: α

C : p(t n ) ← − B1 ]w1 , . . . , Bm ]wm se dice que un qc-átomo observable p 0 (t 0 n )]d ⇐ Π es consecuencia inmediata de I con respecto a C, sii existe una sustitución θ y una serie de valores de cualificación d0 , d1 , . . . , dn , e1 , . . . , em —distintos de b— que cumplen (1), (2), (3) y (4) como siguen: (1) S(p 0 , p) = d0 . (2) I ``S,D,C (ti0 == ti θ)]di ⇐ Π para i = 1 . . . n. (3) I ``S,D,C Bj θ]ej ⇐ Π con ej Q? wj para j = 1 . . . m. (4) d P di (0 ≤ i ≤ n) y d P α ◦ ej (1 ≤ j ≤ m).

Nótese que el nivel λ empleado en la intuición de la noción de consecuencia inmediata vendría determinado por las condiciones (1) y (2) y sería equivalente a d0 u d1 u · · · u dn , y que en la condición (4) se pide, en su primera parte, precisamente que d P λ. Finalmente: una interpretación I es modelo de una cláusula C, sii todo qc-átomo definido observable ϕ que es consecuencia inmediata de I via C verifica que ϕ ∈ I; y una interpretación I es modelo de un programa P sii es modelo de toda cláusula C del programa P.

66

5.3.2.

Semántica de punto fijo

En primer lugar, es posible demostrar que el conjunto de interpretaciones forma un retículo completo con respecto al orden de inclusión como se prueba en [62](B.4, Prop. 3.2). A continuación se define el transformador de interpretaciones TP con la intención de obtener todas las posibles consecuencias inmediatas de una interpretación I, con respecto a las cláusulas C de un programa P. Así: TP (I) =def {ϕ | ϕ es consecuencia inmediata de I vía alguna C ∈ P} donde la noción de consecuencia inmediata es como se definió en la subsección anterior. Además, en este caso también, son propiedades del transformador de interpretaciones es ser una función bien definida, mónotona, continua y cuyos puntos prefijos son los modelos P, i.e. para toda interpretación I, se tiene que I es modelo de P sii TP (I) ⊆ I. Finalmente, la caracterización del modelo mínimo MP de P coincide, como cabría esperar, con el menor punto fijo (lfp) del operador TP , i.e.: [ MP = lfp(TP ) = TP ↑k (∅) . k∈N

5.3.3.

Semántica basada en un cálculo lógico

Esta semántica es también una extensión de las presentadas anteriormente para los casos de los esquemas BQLP y SQLP. Sin embargo, dado que ahora nos podemos encontrar con qc-átomos primitivos y ecuacionales, tendremos dos reglas adicionales de inferencia en el cálculo para tratar estos casos de manera adecuada. El cálculo de la lógica de Horn con restricciones, cualificación y proximidad, i.e. SQCHL(S, D, C), puede verse completo en la figura 5.

SQDA

ti0 == ti θ]di ⇐ Π



i=1...n p 0 (t 0 n )]d

(Bj θ]ej ⇐ Π)j=1...m ⇐Π

α

SQEA SQPA

si (p(t n ) ← − B1 ]w1 , . . . , Bm ]wd S(p 0 , p) = d0 6= b, m ) ∈ P, θ sust., d n m ej Q? wj (1 ≤ j ≤ m) y d P i=0 di u α ◦ j=1 ej . (t == s)]d ⇐ Π κ]d ⇐ Π

si t ≈d,Π s.

si Π |=C κ.

Figura 5: Cálculo lógico SQCHL(S, D, C) En el cálculo SQCHL, la regla SQDA resulta de la extensión de la regla modus ponens de los cálculos de inferencia lógica que hems visto con anterioridad. En ella, se hace necesaria utilizar una cláusula del programa y encontrar una sustitución θ y una serie de valores de cualificación di (para las igualdades de los argumentos de la cabeza) y ej (para el cuerpo de 67

la cláusula). Nótese que en este caso, el primer grupo de premisas se encargan de probar que los argumentos de la cabeza de la cláusula instanciada por θ son, en efecto, Π-próximos a los argumentos del qc-átomo que se está probando, cosa que, junto a la petición de que los símbolos principales de predicado de ambos elementos sean próximos, prueban que el propio qc-átomo es próximo a una instanciación válida de la cabeza de la cláusula con sustitución θ a un nivel que resulta, como ya se ha comentado, de calcular el ínfimo d0 u d1 u · · · u dn . El otro grupo de premisas, es el usual para probar el cuerpo de la cláusula una vez instanciado por la sustitución θ. Las otras dos reglas del cálculo se utilizan para permitir probar qc-átomos ecuacionales (caso de la regla SQEA) y qc-átomos primitivos (regla SQPA). Estas dos reglas resultan bastante sencillas de entender si se tiene en cuenta que son, respectivamente, equivalentes a la noción de Π-proximidad a nivel d y deducibilidad a partir de Π. De forma análoga a como se ha hecho para los cálculos de inferencia anteriores, la notación P `S,D,C ϕ indica que el qc-átomo ϕ puede inferirse a partir de las cláusulas de P en la lógica SQCHL en un número finito de pasos de inferencia. Si fuera necesario hacer explícito el número n de pasos de inferencia, utilizaríamos la notación P `nS,D,C ϕ. Nótese también en este caso la diferencia entre `S,D,C y las inferencias `S,D y `D correspondientes a los cálculos de inferencia lógica para los esquemas SQLP y QLP (o BQLP), respectivamente. Los árboles de inferencia SQCHL presentan una forma algo más complicada que en los casos anteriores por el motivo de presentar reglas adicionales de inferencia lógica y por hacer explícito las igualdades entre los argumentos de los qc-átomos que se prueban y las cláusulas empleadas. Sin embargo, no debe resultar excesivamente complejo desarrollar una demostración en SQCHL partiendo de la base de que las ideas fundamentales coinciden con la de los cálculos de inferencia lógica anteriormente presentados. Como ilustración, considérese el siguiente ejemplo. Ejemplo 5.2 (Inferencia en SQCHL). Sean S y P como en el ejemplo 5.1. Entonces, el siguiente árbol de inferencia prueba que el qc-átomo buena_obra(kli )](0.64, 5) ⇐ ∅ es, en efecto, derivable de P en la lógica SQCHL, cuando las constantes shakespeare, king_lear y king_liar han sido reemplazadas, respectivamente, por sha, kle y kli. (5)

(sha == sha)](1, 0) ⇐ ∅ (kli == kle)](0.8, 2) ⇐ ∅ famoso(sha)](0.9, 1) ⇐ ∅ buena_obra(kli )](0.64, 5) ⇐ ∅ (4)

(2)

(♠) (1)

con: (5)

(♠)

(sha == sha)](1, 0) ⇐ ∅ (kle == kle)](1, 0) ⇐ ∅ escribió(sha, kle)](1, 1) ⇐ ∅

(6) (3)

y donde casa paso de inferencia es como sigue: (1) Inferencia SQDA con cláusula 1, sustitución {X 7→ kle, Y 7→ sha} y donde

68

d d (0.6,5) P {(0.8, 2)} u (0.75, 3) ◦ {(0.9, 1), (1, 1)} = (0.8, 2) u (0.675, 4) = (0.675, 4) . (2) Inferencia SQDA con cláusula 2, sustitución ε y donde d (0.9,1) P {(1, 0)} u (0.9, 1) ◦ t = (1, 0) u (0.9, 1) = (0.9, 1) . (3) Inferencia SQDA con cláusula 3, sustitución ε y donde (1,1)

d P {(1, 0), (1, 0)} u (1, 1) ◦ t = (1, 0) u (1, 1) = (1, 1) .

(4) Inferencia SQEA con kli ≈(0.8,2),∅ kle. (5) Inferencia SQEA con sha ≈(1,0),∅ sha. (6) Inferencia SQEA con kle ≈(1,0),∅ kle. Finalmente, dado un SQCLP(S, D, C)-programa P es posible demostrar, véase [62](B.4, T. 3.2), que su modelo mínimo MP es MP = {ϕ | ϕ es definido observable y P `S,D,C ϕ} es decir, es el conjunto de qc-átomos definidos observables que pueden probarse en SQCHL a partir de las cláusulas del programa P. 5.3.4.

Objetivos y soluciones

Un SQCLP-objetivo tendrá la forma G : A1 ]W1 , . . . , Am ]Wm 8 W1 Q? β1 , . . . , Wm Q? βm  o de manera más abreviada Ai ]Wi , Wi Q? βi i=1...m . Y, dado un SQCLP-programa P, y un objetivo G para P, se dice que hσ, µ, Πi es una solución para G cuando σ es una sustitución de variables por términos, µ es una sustitución de variables de cualificación a términos que representan elementos del dominio de cualificación (recuérdese que en este esquema se hacía uso de una función inyectiva ı de valores de cualificación en términos) y Π es un conjunto de C-restricciones y se cumplen, para 1 ≤ i ≤ m, las condiciones (1) y (2) como siguen: (1) Wi µ = di Q? βi .

(2) P `S,D,C Ai σ]Wi µ ⇐ Π.

69

Ejemplo 5.3 (Objetivo y solución). Sean S y P como en el ejemplo 5.1. Entonces, G : buena_obra(X)]W 8 W Q? (0.6, 5)

es un objetivo para P y h{X 7→ king_liar }, {W 7→ (0.675, 4)}i una solución para G.

5.4.

Casos particulares

A continuación se detalla una serie de esquemas de programación que pueden obtenerse mediante instanciación parcial de los parámetros del esquema SQCLP y también de la no utilización de alguno de los elementos disponibles en el esquema. Un listado de estas características con mayor detalle y profundidad aparece en [61](A.5, §4). Haciendo uso de la relación de proximidad/similaridad Sid de identidad, del dominio de cualificación B de los valores booleanos y del dominio de restricciones R de las restricciones reales pueden obtenerse los siguientes esquemas de programación: 1. El esquema de la programación lógica con restricciones y cualificación, QCLP; con instancias QCLP(D, C) = SQCLP(Sid , D, C). 2. El esquema de la programación lógica con cualificación y proximidad (o similaridad), SQLP; con instancias SQLP(S, D) = SQCLP(S, D, R). El esquema del mismo nombre que se vio en la sección 3 puede verse, en realidad, como una forma restringida de esta, en la que las cláusulas no contienen en sus cuerpos restricciones de R, ni restricciones umbrales distintas de “?”. 3. El esquema de la programación lógica con cualificación, QLP; con instancias QLP(D) = SQCLP(Sid , D, R) siempre que no se haga uso de restricciones de R en los cuerpos de las cláusulas. 4. El esquema de la programación lógica con restricciones, CLP; con instancias CLP(C) = SQCLP(Sid , B, C). 5. La programación lógica clásica, LP; que puede verse, cuando H es el dominio de restricciones de Herbrand, como la instancia SQCLP(Sid , B, H) del esquema SQCLP. Además, el esquema de la programación lógica basada en similaridad, SLP; con instancias SLP(S) = SQCLP(S, U, R). Las formulaciones SLP de otros autores como en [64, 39] puede verse como una formulación restringida de la presente de modo que en estos programas no aparezcan factores de atenuación diferentes de 1, restricciones umbrales diferentes de “?” y restricciones de R.

6.

Implementación práctica

Las secciones precedentes y las publicaciones que las acompañan no han abordado la presentación de implementaciones efectivas de los diversos esquemas de programación declarativa cualificada que se han investigado. Pese a ello, todas las investigaciones y publicaciones de 70

esta tesis han ido siempre acompañadas de un esfuerzo importante por proporcionar, como mínimo, facilidades para probar la ejecución de ejemplos representativos; y en el caso del esquema SQCLP un prototipo de implementación cuidadosamente desarrollado que soporta varias instancias significativas para SQCLP y otros esquemas que resultan de instanciaciones parciales de SQCLP admitidas en el prototipo. La implementabilidad de los esquemas investigados ha sido siempre un factor determinante que ha influido en la presentación de las publicaciones y en la formulación de la semántica declarativa, en particular, en la definición de las interpretaciones como conjunto de observaciones (en la práctica, cada una será el resultado de una posible computación), la definición de las restricciones de cualificación (en la práctica, definidas desde un primer momento como restricciones de R), etc. Es por ello objeto de esta sección mostrar, de un modo general pero claro, el trabajo y esfuerzo realizado en el aspecto más práctico del desarrollo de todos estos esquemas de programación y que, generalmente, ha quedado relegado a posiciones menos relevantes en las publicaciones formales.

6.1.

El sistema (S)QCLP

Para SQCLP se ha propuesto, en [15](B.5), un método de implementación basado en una técnica de transformación de programas que ha dado lugar a una implementación práctica que se concreta en el sistema (S)QCLP. El desarrollo realizado ha aprovechado las experiencias adquiridas en los trabajos previos de implementación de QLP, SQLP y QCFLP, así como las técnicas de transformación de programas semánticamente correctas obtenidas en las publicaciones ya descritas en la sección 5. Teniendo en cuenta la expresividad del esquema SQCLP y algunas elecciones significativas de dominios con los que instanciar sus parámetros, se decidió desarrollar un prototipo que diese soporte a lo siguiente: programación lógica cualificada para dominios de cualificación construidos mediante producto estricto de los dominios de cualificación b, u, w como versión implementada de los dominios B, U y W, respectivamente; programación lógica basada en proximidad (o similaridad cuando la relación de proximidad satisface el axioma de transitividad) implementando incluso el predicado == como versión implementada de la noción de Π-proximidad; programación lógica con restricciones al estilo CLP aunque con sintaxis reducida — mediante predicados primitivos como se ha explicado en el final de la subsección 5.1 dedicada a la base computacional del esquema SQCLP—; restricciones umbrales en los cuerpos de las cláusulas; y restricciones umbrales opcionales en los objetivos (es decir, con la posibilidad de utilizar el símbolo “?” también en los objetivos). De todo ello, resultaba que el sistema (S)QCLP sería capaz de transformar y ejecutar programas para los esquemas SQCLP, QCLP, SQLP, QLP y SLP, que como se ha visto pueden todos verse como casos particulares de SQCLP, y resolver objetivos para cada uno de ellos.

71

Además, un paso posterior incorporó algunos elementos para mejorar la eficiencia final del sistema, dando lugar a: 1. Capacidad para ejecutar programas QCLP mediante una transformación optimizada, es decir, sin necesidad de asumir que existía la relación de proximidad identidad y reduciendo, por tanto, el número de cláusulas finales. Es por esta característica por la que el sistema recibe el nombre de (S)QCLP porque en el caso de no establecer una relación de proximidad en un determinado programa, hace que se considere al programa como perteneciente al esquema QCLP en lugar de al esquema SQCLP, afectando esto únicamente a la eficiencia en la ejecución. 2. Capacidad para mostrar las soluciones estableciendo el vínculo entre las variables de cualificación y su valor máximo posible de acuerdo con el conjunto de restricciones de la solución, o no. Nota 20. En su versión actual, el flag que determina este comportamiento no está disponible para el usuario final dado que debe modificarse en el código fuente del sistema y, por tanto, el comportamiento por defecto es el de establecer el vínculo y no mostrar el conjunto de restricciones finales. El motivo para actuar de esta forma es que SWI-Prolog no muestra soluciones al objetivo clpr X > 0, X ≤ 0.8, Y > 0, Y ≤ 1, X ≤ 0.9 × Y como demuestra lo siguiente: ?- {X>0, X=<0.8, Y>0, Y=<1, X=<0.9*Y}. ^CAction (h for help) ? abort % Execution Aborted ?- {X>0, X=<0.8, Y>0, Y=<1, X=<0.9*Y},fail. false.

3. Traducción optimizada para cláusulas con factor de atenuación t y cláusulas sin restricciones umbrales en sus cuerpos, para las que es posible reducir el número de restricciones finales a establecer. 4. Posibilidad de indicar al sistema que el programa sea tratado como programa SLP en el sentido de [64]. En este caso el sistema resuelve ecuaciones basándose en las transformaciones de unificación módulo similaridad presentadas en [64], evitando ciertas alternativas de búsqueda que son necesarias para no perder soluciones en el caso de programas y objetivos SQCLP generales. Una discusión más detallada de esta cuestión se puede encontrar al final de [15](B.5, §2). Las mejoras en la eficiencia según el tipo de programa pueden verse en el cuadro 1. En él, y a modo de comparación con Prolog, se proponen una serie de programas extraídos del SICStus Prolog Benchmark3 que han podido ser adecuadamente adaptados para ejecutarse tanto en Prolog como en (S)QCLP (dado que no es posible ejecutar cualquier programa Prolog en (S)QCLP) y se muestra el factor de sobrecarga introducido por la transformación 3 Véase

http://www.sics.se/isl/sicstuswww/site/perfomance.html.

72

Programa naivrev deriv qsort query a Versión b Versión c Versión d Versión e Versión f Versión

Q(b)a 1.80 1.94 1.05 1.02

Q(u)b 10.71 10.60 1.11 1.12

PQ(b)c 4289.79 331.45 135.59 7.17

PQ(u)d 4415.11 469.67 136.98 7.13

SQ(b)e 56.22 29.63 2.51 3.80

SQ(u)f 65.75 39.32 2.83 3.88

QCLP(B, R) (i.e. el programa no tiene la directiva #prox). QCLP(U , R) (i.e.el programa no tiene la directiva #prox). SQCLP(Sid , B, R). SQCLP(Sid , U , R). SQCLP(Sid , B, R) con directiva #optimized_unif. SQCLP(Sid , U , R) con directiva #optimized_unif.

Cuadro 1: Sobrecarga con respecto a Prolog en la ejecución en (S)QCLP. Como puede verse, en algunos casos la sobrecarga es considerable, mientras que en otros es mucho más aceptable. Para más detalles sobre la eficiencia del sistema, véase [15](B.5, §5.3). Por último, se optó por hacer una implementación sobre los sistemas CLP SICStus Prolog y SWI-Prolog, de manera que pudiera optarse, a discreción del usuario, por uno u otro sistema sin consecuencia alguna en el funcionamiento y utilización del sistema. El sistema (S)QCLP está públicamente disponible en http://gpd.sip.ucm.es/cromdia/qclp y, tanto en la misma página como en [15](B.5, §5.2), se da la información necesaria para su instalación, ejecución y utilización. Sobre los detalles de la técnica de implementación utilizada, se definen en [15](B.5) dos transformaciones de programas, denominadas elimS y elimD que eliminan, respectivamente, la relación de proximidad y el dominio de cualificación, y que en conjunto permiten transformar un SQCLP-programa en un CLP-programa equivalente. Estas dos transformaciones se formalizan, respectivamente, en [15](B.5, §4.1) y en [15](B.5, §4.2), donde se prueban, además, resultados de corrección y completitud con respecto a la semántica declarativa de los esquemas SQCLP, QCLP y CLP considerados por las transformaciones. El sistema (S)QCLP implementa, de hecho, ambas transformaciones por separado y tras efectuarlas a partir de un programa de una instancia del esquema SQCLP aceptada, obtiene un programa CLP(R) equivalente que puede cargarse en cualquiera de los sistemas Prolog soportados y sobre el que pueden resolverse objetivos propuestos por el usuario. A modo de ejemplo, se muestran a continuación dos ejecuciones para los programas de los ejemplos4 2.1 y 5.1 en el sistema (S)QCLP que se esperan resulten ilustrativas sobre el funcionamiento general del sistema. Para más detalles sobre el mismo, véase [15](B.5, §5) o http://gpd.sip.ucm.es/cromdia/qclp. 4 En las ejecuciones siguientes se ha mantenido la versión original en inglés de los ejemplos que es como se distribuyen con el sistema (S)QCLP.

73

6.1.1.

Ejecución 1: Números de Peano

Considérese el programa Peano.qclp como sigue: Archivo: qclp/samples/Peano.qclp 1

# qdom w

2

% num( ?Num ) num(z) <-num(s(X)) <-1- num(X)

3 4

5 6 7

% add( ?A, ?B, ?Sum ) add(c, X, X) <-add(s(X), Y, s(Z)) <-1- add(X, Y, Z)

En donde la directiva #qdom de la línea 1 selecciona el dominio de cualificación W, que se representa como w en la práctica. Otros dominios posibles serían b (para B), u (para U) y cualquier producto (d1 ,d2 ) construido a partir de los dominios de cualificación b, u y w. Desde la carpeta qclp/ podemos, entonces, hacer lo siguiente5 : $ sicstus SICStus 4.0.4 (x86_64-darwin-8.11.1): Mon Jun 16 23:58:36 CEST 2008 Licensed to SP4fdi.ucm | ?- [qclp]. WELCOME TO (S)QCLP 0.6.2 (S)QCLP is free software and comes with absolutely no warranty. Support & Updates: http://gpd.sip.ucm.es/cromdia/qclp. Type ’:help.’ for help. yes | ?- :cd(samples). qclp/samples/ yes | ?- :run(’Peano’). Compiling... QDom: ’w’. Translating to QCLP... Translating to CLP... Generating code... Done. Loaded. yes | ?- num(X)#W. W = 0.0, X = z ? ; W = 1.0, X = s(z) ? yes | ?- num(X)#W::W>=0. 5 Los comentarios de SICStus Prolog se han omitido y los vínculos de cada solución se muestran en una única línea.

74

W = 0.0, X = z ? ; no | ?- add(s(s(X)),s(X),Z)#W::W>=1. no | ?- add(s(s(X)),s(X),Z)#W::W>=2. W = 2.0, X = c, Z = s(s(s(c))) ? ; no | ?-

6.1.2.

Ejecución 2: Obras

Considérese la relación de proximidad Work.prox como sigue: File: qclp/samples/Work.prox 1 2

3 4 5

% PREDICATES PROXIMITY... % pprox( Symbol1, Symbol2, Arity, Value ) % CONSTRUCTORS PROXIMITY... % cprox( Symbol1, Symbol2, Arity, Value ) cprox(king_lear, king_liar, 0, (0.8,2.0)).

Nótese que en la línea 5 se muestra la codificación de la ecuación S(king_lear, king_liar) = (0.8, 2.0) que define propiamente la relación de proximidad. Y considérese también el programa Work.qclp como sigue: Archivo: qclp/samples/Work.qclp 1 2

3 4

5 6

8 9

# qdom (u,w) # prox ’Work’ % famous( ?Author ) famous(shakespeare) <-(0.9,1)% wrote( ?Author, ?Book ) wrote(shakespeare, king_lear) <-(1,1)% good_work( ?Work ) good_work(X) <-(0.75,3)- famous(Y)#(0.5,100), wrote(Y,X)

En donde las directivas #qdom y #prox permiten especificar, respectivamente, el dominio de cualificación del programa, en este caso el producto cartesiano estricto U⊗W, y la relación de proximidad a utilizar. Entonces, desde la carpeta qclp/ podemos hacer: $ sicstus SICStus 4.0.4 (x86_64-darwin-8.11.1): Mon Jun 16 23:58:36 CEST 2008 Licensed to SP4fdi.ucm | ?- [qclp].

75

WELCOME TO (S)QCLP 0.6.2 (S)QCLP is free software and comes with absolutely no warranty. Support & Updates: http://gpd.sip.ucm.es/cromdia/qclp. Type ’:help.’ for help. yes | ?- :cd(samples). qclp/samples/ yes | ?- :run(’Work’). Compiling... QDom: ’u,w’. Prox: ’Work’. Translating to QCLP... Translating to CLP... Generating code... Done. Loaded. yes | ?- king_lear==X#W. W = (1.0,0.0), X = king_lear ? ; W = (0.8,2.0), X = king_liar ? ; no | ?- good_work(king_lear)#W::W>=(0.65,5). W = (0.675,4.0) ? ; no | ?- good_work(king_liar)#W::W>=(0.65,5). W = (0.675,4.0) ? ; no | ?-

6.2.

Otros prototipos

Antes del desarrollo final de (S)QCLP, se procedió a construir otro prototipo preliminar destinado a implementar las instancias QLP(U), QLP(W) y QLP(U×W) sobre el sistema CFLP Toy [6] como una opción activable por el usuario que hacía un preprocesado de los programas QLP para que pudieran ser ejecutados desde el sistema Toy. El proceso de transformación de programas implementado seguía las ideas de la resolución QSLD(D) de la sección 2.4, que a pesar de haber sido pensadas para implementar una variante de la resolución SLD estándar capaz de resolver objetivos para programas lógicos con cualificación, requeriría de mayores esfuerzos de implementación que la implementación de una transformación de programas, como ya se ha razonado con anterioridad. En este momento se optó por la utilización del sistema Toy como parte de la implementación y no por un sistema Prolog, pensando en sentar las bases para integrar en Toy la implementación de futuras extensiones de QLP que soportasen características de programación lógico-funcional perezosas, tal como el esquema QCFLP desarrollado posteriormente. El prototipo permitía transformar programas QLP básicos, es decir que no incluyeran

76

ninguna de las extensiones propuestas en el marco BQLP como era las marcas tt y ff, y las restricciones umbrales en los cuerpos de las cláusulas cualificadas. Asimismo, el cálculo de los valores de cualificación finales se hacía mediante dos tipos de restricciones de cualificación, implementadas como restricciones de R, que venían a ser las precursoras de las dos restricciones qVal y qBound que se definirían más tarde para los esquemas con restricciones, i.e. QCFLP y SQCLP. La principal diferencia entre las restricciones empleadas por el prototipo y las definidas qVal y qBound, era que d la restricción qBound se definió mediante una igualdad, i.e. se hacía algo como W = α ◦ {W1 , . . . , Wm }, en lugar de la d posteriormente utilizada W P α ◦ {W1 , . . . , Wm }, lo que tenía la ventaja de no dejar sin instanciar ninguna variable de cualificación del objetivo a costa de convertir en impaciente, y por tanto exigir la evaluación de las variables Wi del programa. La versión actual de este prototipo no está públicamente accesible, aunque sigue formando parte de los planes de desarrollo del sistema Toy y aparecerá como parte integrante de una futura versión pública de dicho sistema. Para el esquema SQLP no llegó a desarrollarse un prototipo funcional completo antes del propio (S)QCLP, y los ejemplos se ejecutaron en el prototipo desarrollado para QLP tras una transformación manual de los mismos siguiendo la técnica aportada en [11](A.3).

7.

Conclusiones y trabajo futuro

A lo largo del trabajo de esta tesis se han aportado una serie de esquemas de programación declarativa para programas lógicos y lógico-funcionales desarrollando, para cada uno de ellos, una semántica declarativa clara y rigurosa, y una técnica de resolución de objetivos basada ya en una semántica operacional, ya en una técnica de transformación de programas que se prueba correcta y completa con respecto a la semántica declarativa de ambos esquemas de programación involucrados en la transformación. Así, podemos efectivamente decir que los objetivos de la tesis han quedado cubiertos de manera satisfactoria, tanto por los esquemas de programación desarrollados como por el sistema (S)QCLP, implementado siguiendo las ideas de la técnica de transformación de programas propuesta para el esquema SQCLP. Más concretamente, se han desarrollado esquemas de programación declarativa que pueden clasificarse de dos maneras diferentes: a) atendiendo al paradigma de programación que toman como base y extienden; y b) atendiendo al elemento o elementos que incorporan. Por lo tanto, tenemos: esquemas que extienden la programación lógica, como el esquema QLP (sección 2) con instancias QLP(D), el esquema BQLP (sección 2) con instancias BQLP(D), y el esquema SQLP (sección 3) con instancias SQLP(S, D); esquemas que extienden la programación lógica con restricciones, como el esquema SQCLP (sección 5) con instancias SQCLP(S, D, C); y esquemas que extienden la programación lógico-funcional, como el esquema QCFLP (sección 4) con instancias QCFLP(D, C). Y también: esquemas que incorporan cualificación, como los esquemas QLP (sección 2), BQLP (sección 2), SQLP (sección 3), QCFLP (sección 4) y SQCLP (sección 5); 77

esquemas que incorporan similaridad o proximidad, como el esquema SQLP (sección 3) para el primer caso, y el esquema SQCLP (sección 5) para el segundo; esquemas que incorporan restricciones, como los esquemas QCFLP (sección 4) y SQCLP (sección 5); esquemas que incorporan funciones, como el esquema QCFLP (sección 4). Por otro lado, y dado que es posible ver los esquemas QLP, BQLP y SQLP como instanciaciones parciales del esquema SQCLP tal y como se cuenta en las conclusiones de [61](A.5, §4), puede decirse que el trabajo desarrollado ha seguido dos direcciones principales: a) extender la programación lógica primero con cualificación, después con similaridad (o proximidad) y por último con restricciones al estilo de la semántica S2 para CLP de [23]; y b) extender la programación lógico-funcional de primer orden, entendida como un subconjunto de la lógica de reescritura propuesta en [47], con cualificación. Por lo tanto, se han desarrollado efectivamente dos esquemas de programación: uno para programación lógica (o programación lógica con restricciones), i.e. SQCLP(S, D, C); y otro para programación lógico-funcional de primer orden, i.e. QCFLP(D, C). Y también un sistema (S)QCLP (Sección 6) que implementa varias instancias interesantes del esquema SQCLP sobre los sistemas SICStus Prolog y SWI-Prolog, y que permite escribir, ejecutar y resolver objetivos para programas escritos en los esquemas QLP, SQLP y SQCLP, así como en cualquier otro esquema resulte de una instanciación parcial de cualquiera de las instancias de SQCLP efectivamente implementadas en (S)QCLP, sobre cualquiera de los dos sistemas Prolog anteriormente mencionados. En comparación con otros enfoques relacionados, y a modo de resumen de las conclusiones de las publicaciones asociadas a esta tesis, la programación cualificada presenta interesantes contribuciones. Con respecto a los programas cuantitativos (QLP) de van Emden [71], la programación lógica basada en similaridad (SLP) [64] y el lenguaje Bousi∼Prolog [39], los esquemas QLP, SQLP y SQCLP engloban, respectivamente, a cada uno de ellos y, por consiguiente, el esquema SQCLP a los tres. Con respecto a los programas anotados generalizados (GAP) de Kifer y Subrahmanian [41], a pesar de que la sintaxis de los programas QLP(D), tal vez también los BQLP(D), y el procedimiento de resolución QSLD(D), pueden encajar perfectamente dentro del esquema GAP, la visión de la semántica aquí presentada permite probar resultados más fuertes que aquellos para GAP, y los esquemas sucesivos basados en QLP introducen elementos imposibles de representar, de manera natural, en el esquema GAP como las relaciones de similaridad o proximidad y la programación con restricciones. Además, el método de resolución QSLD(D) puede implementarse de manera más eficiente que la resolución SLD restringida de GAP al evitar el uso de los costosos reductantes. Los predicados bivaluados introducidos en el esquema BQLP aportan una sencilla forma de permitir devolver un valor diferente de cierto a la hora de interpretar un predicado en un programa lógico. De la misma manera, permiten introducir una muy sencilla negación en los programas al permitir interpretar predicados que demuestran veracidad y predicados que demuestran falsedad. La extensión de los sucesivos SQLP y SQCLP con predicados bivaluados resulta sencilla, a pesar de haberse omitido para permitir centrarse en las novedades que cada esquema presenta y sus respectivos problemas técnicos. En el esquema QCFLP, la valoración de un predicado vendría a ser la expresión que constituye el lado derecho de

78

una regla de programa y, por este motivo, no tiene sentido pensar en posibles valoraciones para las funciones definidas en el paradigma de la programación lógico-funcional. Las relaciones de similaridad empleadas en SQLP, y posteriormente las relaciones de proximidad empleadas en SQCLP, son bastante generales al permitir tomar valores en un determinado dominio de cualificación y no necesariamente en el intervalo real [0, 1] como en [64]. En relación al enfoque multi-adjunto de MALP [48], los esquemas SQLP y SQCLP tienen una finalidad y motivación diferente, como prueban las diferencias entre las álgebras multi-adjuntas y los dominios de cualificación como estructuras. En lo que a programación lógico-funcional se refiere, el esquema QCFLP, a pesar de basarse únicamente en un fragmento de primer orden de la lógica de reescritura CRWL, resulta más expresivo que el resto de enfoques relacionados de los que se tiene constancia. Además, la técnica de transformación de programas QCFLP(D, C) a programas CFLP(C) equivalentes permitiría efectivamente implementar un sistema para resolver QCFLP-objetivos para QCFLP-programas sobre un sistema CFLP actual como Toy [6] o Curry [29]. Por último, junto al esquema SQCLP se proporciona una noción de Π-proximidad ≈λ,Π , presentada por primera vez en [61](A.5, Def. 2.3), que permite especificar el papel semántico de una relación de proximidad en un enfoque basado en restricciones con menos dificultades técnicas que en enfoques relacionados previos. Asimismo, la semántica declarativa inspirada en la CLP semántica de observables de [24, 23] proporciona una caracterización del modelo mínimo de un programa y una noción declarativa de objetivo y solución adecuadas para su implementación en un sistema como (S)QCLP, que sobre un sistema CLP(R), es capaz de resolver objetivos para programas de algunas instancias interesante del esquema SQCLP. Las líneas de investigación que quedan abiertas para el trabajo futuro se centran por un lado en la extensión del esquema QCFLP a orden superior, incorporando tal vez relaciones de proximidad como en SQCLP y permitiendo por lo tanto servir como extensión con incertidumbre de la base computacional de un sistema CFLP como Toy [6], y el desarrollo de una resolución SLD basada en proximidad para SQCLP al estilo de la proporcionada en [64] para programas SLP. Por otro lado, queda pendiente la tarea de encontrar aplicaciones reales interesantes de estos esquemas de programación declarativa, en especial, en lo que a representación de consultas sobre dominios específicos se refiere (como por ejemplo dentro del campo de la medicina) o en aplicaciones de búsqueda flexible de información en la web. Otras líneas de menor relevancia, o a más largo plazo, en las que cabría trabajar son: buscar otros posibles dominios de cualificación que aporten expresividad a la programación declarativa con cualificación; estudiar otras posibles estructuras para representar la incertidumbre y ver cómo podrían encajar con los dominios de cualificación, como pueden ser los birretículos o los semianillos; y una vez desarrollada la extensión de QCFLP a orden superior, implementar una extensión de Toy con cualificación.

79

Referencias [1] Sergio Antoy and Michael Hanus. Functional logic programming. Communications of the ACM, 53(4):74–85, April 2010. [2] Krzysztof R. Apt. Logic programming. In J. van Leeuwen, editor, Handbook of Theoretical Computer Science, volume B: Formal Models and Semantics, pages 493–574. Elsevier and The MIT Press, 1990. [3] Krzysztof R. Apt and M. H. van Emden. Contributions to the theory of logic programming. Journal of the Association for Computing Machinery (JACM), 29(3):841–862, 1982. [4] F. Arcelli and F. Formato. Likelog: a logic programming language for flexible data retrieval. In Proceedings of the 1999 ACM Symposium on Applied computing (SAC’99), pages 260–267, New York, NY, USA, 1999. ACM Press. [5] Francesca Arcelli Fontana. Likelog for flexible query answering. Soft Computing, 7:107–114, 2002. [6] P. Arenas, A. J. Fernández, A. Gil, F. J. López-Fraguas, M. Rodríguez-Artalejo, and F. SáenzPérez. T OY, a multiparadigm declarative language (version 2.3.1). In R. Caballero and J. Sánchez, editors, User Manual, available at http://toy.sourceforge.net, July 2007. [7] J. F. Baldwin, T.P. Martin, and B.W. Pilsworth. Fril-Fuzzy and Evidential Reasoning in Artificial Intelligence. John Wiley & Sons, 1995. [8] H. P. Barendregt. Functional programming and lambda calculus. In J. van Leeuwen, editor, Handbook of Theoretical Computer Science, volume B, chapter 7, pages 321–363. Elsevier and The MIT Press, 1990. [9] Nuel D. Belnap, Jr. A useful four-valued logic. In J. Michael Dunn and G. Epstein, editors, Modern Uses of Multiple-Valued Logic, pages 8–37. D. Reidel Pub. Co., 1977. [10] Stefano Bistarelli, Ugo Montanari, and Francesca Rossi. Semiring-based constraint logic programming: Syntax and semantics. ACM Transactions on Programming Languages and Systems, 3(1):1–29, January 2001. [11] Rafael Caballero, Mario Rodríguez-Artalejo, and Carlos A. Romero-Díaz. Similarity-based reasoning in qualified logic programming. In PPDP ’08: Proceedings of the 10th international ACM SIGPLAN conference on Principles and Practice of Declarative Programming, pages 185–194, Valencia, Spain, July 15–17 2008. ACM. [12] Rafael Caballero, Mario Rodríguez-Artalejo, and Carlos A. Romero-Díaz. A generic scheme for qualified constraint functional logic programming. Technical Report SIC-1-09 (CoRR abs/1101.2146), Universidad Complutense, Departamento de Sistemas Informáticos y Computación, Madrid, Spain, 2009. [13] Rafael Caballero, Mario Rodríguez-Artalejo, and Carlos A. Romero-Díaz. Qualified computations in functional logic programming. In P.M. Hill and D.S. Warren, editors, Logic Programming (ICLP’09), volume 5649 of LNCS, pages 449–463, Pasadena, CA, USA, July 14-17 2009. Springer-Verlag Berlin Heidelberg. [14] Rafael Caballero, Mario Rodríguez-Artalejo, and Carlos A. Romero-Díaz. Similarity-based reasoning in qualified logic programming. CoRR abs/1008.3867, 2010. [15] Rafael Caballero, Mario Rodríguez-Artalejo, and Carlos A. Romero-Díaz. A transformationbased implementation for CLP with qualification and proximity. Technical Report SIC-4-10 (CoRR abs/1009.1976), Universidad Complutense, Departamento de Sistemas Informáticos y Computación, Madrid, Spain, 2010.

80

[16] R. del Vado-Vírseda. Declarative constraint programming with definitional trees. In Bernhard Gramlich, editor, Proceedings of the 5th International Conference on Frontiers of Combining Systems (FroCoS’05), volume 3717 of LNCS, pages 184–199. Springer-Verlag, 2005. [17] D. Dubois and H. Prade. Fuzzy Sets and Systems: Theory and Applications. Academic Press, New York, NY, USA, 1980. [18] D. Dubois and H. Prade. Possibility Theory. New York: Plenum, 1988. [19] D. Dubois and H. Prade. Possibilistic logic: a retrospective and prospective view. Fuzzy Sets and Systems, 144:3–23, 2004. [20] Melvin Fitting. Bilattices and the semantics of logic programming. Journal of Logic Programming, 11:91–116, 1991. [21] FLOPER: A Fuzzy LOgic Programming Environment for Research. Available at http://www. dsi.uclm.es/investigacion/dect/FLOPERpage.htm, 2010. [22] F. Formato, G. Gerla, and M. I. Sessa. Similarity-based unification. Fundamenta Informaticae, 40:1–22, 2000. [23] Maurizio Gabbrielli, Giovanna M. Dore, and Giorgio Levi. Observable semantics for constraint logic programs. Journal of Logic and Computation, 5(2):133–171, 1995. [24] Maurizio Gabbrielli and Giorgio Levi. Modeling answer constraints in constraint logic programs. In Proceedings of the 8th International Conference on Logic Programming (ICLP’91), pages 238–252. The MIT Press, 1991. [25] Yan Georget and Philippe Codognet. Compiling semiring-based constraints with CLP(FD,S). In Proceedings of the 4th International Conference on Principles and Practice of Constraint Programming, volume 1520 of LNCS, pages 205–219. Springer-Verlag, 1998. [26] G. Gerla and M.I. Sessa. Similarity in logic programming. In G. Chen, M. Ying, and K.Y. Cai, editors, Fuzzy Logic and Soft Computing, pages 19–31. Kluwer Accademic Publishers, 1999. [27] S. Guadarrama, S. Muñoz, and C. Vaucheret. Fuzzy prolog: A new approach using soft constraint propagation. Fuzzy Sets and Systems, 144(1):127–150, 2004. [28] Petr Hájek. Metamathematics of Fuzzy Logic. Dordrecht: Kluwer, 1998. [29] M. Hanus, Ed. Curry: An integrated functional logic language (vers. 0.8.2, 2006); http: //www.curry-language.org. [30] Haskell 98. Available at http://www.haskell.org/, 2010. [31] M. Höhfeld and G. Smolka. Definite relations over constraint languages. Technical Report LILOG Report 53, IBM Deutschland, 1988. [32] M. Ishizuka and N. Kanai. Prolog-ELF incorporating fuzzy logic. In Aravind K. Joshi, editor, Proceedings of the 9th International Joint Conference on Artificial Intelligence (IJCAI’85), pages 701–703, Los Angeles, CA, USA, August 1985. Morgan Kaufmann. [33] J. Jaffar and J. L. Lassez. Constraint logic programming. In Proceedings of the 14th ACM SIGACT-SIGPLAN symposium on Principles of Programming Languages (POPL’87), pages 111–119, Munich, West Germany, 1987. ACM New York, NY, USA. [34] J. Jaffar, M. Maher, K. Marriott, and P. J. Stuckey. Semantics of constraints logic programs. Journal of Logic Programming, 37(1-3):1–46, 1998. [35] J. Jaffar, S. Michaylov, P. J. Stuckey, and R. H. C. Yap. The CLP(R) language and system. ACM Transactions on Programming Languages and Systems, 14(3):339–395, 1992. [36] Simon Peyton Jones. The haskell 98 language. Journal of Functional Programming, 13(1):7– 255, January 2003.

81

[37] R. Julián, G. Moreno, and J. Penabad. An improved reductant calculus using fuzzy partial evaluation techniques. Fuzzy Sets and Systems, 160(2):162–181, 2009. [38] P. Julián-Iranzo, C. Rubio, and J. Gallardo. Bousi∼Prolog: a prolog extension language for flexible query answering. In J. M. Almendros-Jiménez, editor, Proceedings of the Eighth Spanish Conference on Programming and Computer Languages (PROLE 2008), volume 248 of ENTCS, pages 131–147, Gijón, Spain, October 7–10 2009. Elsevier. [39] Pascual Julián-Iranzo and Clemente Rubio-Manzano. A declarative semantics for Bousi∼Prolog. In PPDP’09: Proceedings of the 11th ACM SIGPLAN conference on Principles and practice of declarative programming, pages 149–160, Coimbra, Portugal, September 7–9 2009. ACM. [40] Pascual Julián-Iranzo and Clemente Rubio-Manzano. A similarity-based WAM for Bousi∼Prolog. In Bio-Inspired Systems: Computational and Ambient Intelligence (IWANN 2009), volume 5517 of LNCS, pages 245–252, Salamanca, Spain, 10-12 June 2009. Springer Berlin / Heidelberg. [41] M. Kifer and V. S. Subrahmanian. Theory of generalized annotated logic programs and their applications. Journal of Logic Programming, 12(3&4):335–367, 1992. [42] R. C. T. Lee. Fuzzy logic and the resolution principle. Journal of the Association for Computing Machinery (ACM), 19(1):109–119, January 1972. [43] Dayi Li and Dongbo Liu. A Fuzzy Prolog Database System. John Wiley & Sons, 1990. [44] John W. Lloyd. Foundations of Logic Programming, Second Edition. Springer, 1987. [45] V. Loia, S. Senatore, and M. I. Sessa. Similarity-based SLD resolution and its role for web knowledge discovery. Fuzzy Sets and Systems, 144(1):151–171, 2004. [46] F. J. López-Fraguas, M. Rodríguez-Artalejo, and R. del Vado-Virseda. A lazy narrowing calculus for declarative constraint programming. In Proceedings of the 6th International ACM SIGPLAN Conference on Principles and Practice of Declarative Programming (PPDP’04), pages 43–54. ACM Press, 2004. [47] F. J. López-Fraguas, M. Rodríguez-Artalejo, and R. del Vado-Vírseda. A new generic scheme for functional logic programming with constraints. Journal of Higher-Order and Symbolic Computation, 20(1&2):73–122, 2007. [48] J. Medina, M. Ojeda-Aciego, and P. Vojtáš. Multi-adjoint logic programming with continuous semantics. In T. Eiter, W. Faber, and M. Truszczyinski, editors, Logic Programming and NonMonotonic Reasoning (LPNMR’01), volume 2173 of LNAI, pages 351–364. Springer-Verlag, 2001. [49] J. Medina, M. Ojeda-Aciego, and P. Vojtáš. A procedural semantics for multi-adjoint logic programming. In P. Brazdil and A. Jorge, editors, Progress in Artificial Intelligence (EPIA’01), volume 2258 of LNAI, pages 290–297. Springer-Verlag, 2001. [50] Ginés Moreno and Vicente Pascual. Formal properties of needed narrowing with similarity relations. Electronic Notes in Theoretical Computer Science, 188:21–35, 2007. [51] Raymond T. Ng and V. S. Subrahmanian. Probabilistic logic programming. Information and Computation, 101(2):150–201, 1992. [52] J. Pavelka. On fuzzy logic I, II, III. Zeitschrift fur Math. Logik und Grundlagen der Math, 25:45–52, 119–134, 447–464, 1979. [53] Jaime Penabad Vázquez. Desplegado de Programas Lógicos Difusos. PhD thesis, Departamento de Sistemas Informáticos, Universidad de Castilla-La Mancha, 2010. [54] N. Rescher. Plausible Reasoning. Van Gorcum, Amsterdam, 1976.

82

[55] S. Riezler. Quantitative constraint logic programming for weighted grammar applications. In C. Retoré, editor, Proceedings of the Logical Aspects of Computational Linguistics (LACL’96), volume 1328 of LNCS, pages 346–365. Springer-Verlag, 1996. [56] S. Riezler. Probabilistic Constraint Logic Programming. PhD thesis, Neuphilologischen Fakultät del Universität Tübingen, 1998. [57] M. Rodríguez-Artalejo. Functional and constraint logic programming. In C. Marché H. Comon and R. Treinen, editors, Constraints in Computational Logics, Theory and Applications, volume 2002 of Lecture Notes in Computer Science, pages 202–270. Springer-Verlag, 2001. [58] Mario Rodríguez-Artalejo and Carlos A. Romero-Díaz. A generic scheme for qualified logic programming. Technical Report SIC-1-08 (CoRR abs/1008.3863), Universidad Complutense, Departamento de Sistemas Informáticos y Computación, Madrid, Spain, 2008. [59] Mario Rodríguez-Artalejo and Carlos A. Romero-Díaz. Quantitative logic programming revisited. In J. Garrigue and M. Hermenegildo, editors, Functional and Logic Programming (FLOPS’08), volume 4989 of LNCS, pages 272–288, Ise, Japan, April 14–16 2008. SpringerVerlag. [60] Mario Rodríguez-Artalejo and Carlos A. Romero-Díaz. Qualified logic programming with bivalued predicates. In J. M. Almendros-Jiménez, editor, Proceedings of the Eighth Spanish Conference on Programming and Computer Languages (PROLE 2008), volume 248 of ENTCS, pages 67–82, Gijón, Spain, October 7–10 2009. Elsevier. [61] Mario Rodríguez-Artalejo and Carlos A. Romero-Díaz. A declarative semantics for CLP with qualification and proximity. Theory and Practice of Logic Programming, 26th Int’l. Conference on Logic Programming (ICLP’10) Special Issue, 10(4–6):627–642, 2010. [62] Mario Rodríguez-Artalejo and Carlos A. Romero-Díaz. Fixpoint & Proof-theoretic Semantics for CLP with Qualification and Proximity. Technical Report SIC-1-10 (CoRR abs/1009.1977), Universidad Complutense, Departamento de Sistemas Informáticos y Computación, Madrid, Spain, 2010. [63] M. I. Sessa. Translations and similarity-based logic programming. Soft Computing, 5(2), 2001. [64] M. I. Sessa. Approximate reasoning by similarity-based SLD resolution. Theoretical Computer Science, 275(1-2):389–426, 2002. [65] Ehud Y. Shapiro. Logic programs with uncertainties: A tool for implementing rule-based systems. In Alan Bundy, editor, Proceedings of the 8th International Joint Conference on Artificial Intelligence (IJCAI’83), pages 529–532, Karlsruhe, Germany, 1983. [66] S. Shenoi and A. Melton. Proximity relations in the fuzzy relational database model. Fuzzy Sets and Systems, 100(supl.):51–62, 1999. [67] SICS AB. SICStus Prolog. Available at http://www.sics.se/sicstus, 2010. [68] V. S. Subrahmanian. On the semantics of quantitative logic programs. In Proceedings of the 4th IEEE Symposium on Logic Programming, pages 173–182, San Francisco, 1987. [69] V. S. Subrahmanian. Query processing in quantitative logic programming. In Proceedings of the 9th International Conference on Automated Deduction, volume 310 of LNCS, pages 81–100, London, UK, 1988. Springer-Verlag. [70] SWI-Prolog. Available at http://www.swi-prolog.org, 2010. [71] M. H. van Emden. Quantitative deduction and its fixpoint theory. Journal of Logic Programming, 3(1):37–53, 1986. [72] M. H. van Emden and R. A. Kowalski. The semantics of predicate logic as a programming language. Journal of the Association for Computing Machinery (JACM), 23(4):733–742, 1976.

83

[73] C. Vaucheret, S. Guadarrama, and S. Muñoz. Fuzzy prolog: A simple general implementation using CLP(R). In M. Baaz and A. Voronkov, editors, Logic for Programming, Artificial Intelligence, and Reasoning (LPAR’02), volume 2514 of LNCS, pages 450–463, Tbilisi, Georgia, October 14–18 2002. Springer Berlin / Heidelberg. [74] A. Visser. Four valued semantics and the liar. Journal of Philosophical Logic, 13:181–212, 1984. [75] P. Vojtáš. Fuzzy logic programming. Fuzzy Sets and Systems, 124:361–370, 2001. [76] L. A. Zadeh. Fuzzy sets. Information and Control, 8(3):338–353, 1965. [77] L. A. Zadeh. Similarity relations and fuzzy orderings. Information Sciences, 3(2):177–200, 1971. [78] L. A. Zadeh. Fuzzy sets as a basis for a theory of possibility. Fuzzy Sets and Systems, 1:3–28, 1978.

84

A.

Publicaciones

(A.1) Quantitative logic programming revisited M. Rodríguez-Artalejo and C. A. Romero-Díaz In J. Garrigue and M. Hermenegildo, editors, Functional and Logic Programming (FLOPS 2008), volume 4989 of LNCS, pages 272–288, Ise, Japan, April 14–16 2008. Springer-Verlag. → Página 86

(A.2) Qualified logic programming with bivalued predicates M. Rodríguez-Artalejo and C. A. Romero-Díaz In J. M. Almendros-Jiménez, editor, Proceedings of the Eighth Spanish Conference on Programming and Computer Languages (PROLE 2008), volume 248 of ENTCS, pages 67–82, Gijón, Spain, October 7–10 2009. Elsevier. → Página 103

(A.3) Similarity-based reasoning in qualified logic programming R. Caballero, M. Rodríguez-Artalejo, and C. A. Romero-Díaz In PPDP’08: Proceedings of the 10th international ACM SIGPLAN conference on Principles and Practice of Declarative Programming, pages 185–194, Valencia, Spain, July 15–17. → Página 119

(A.4) Qualified computations in functional logic programming R. Caballero, M. Rodríguez-Artalejo, and C. A. Romero-Díaz In P.M. Hill and D.S. Warren, editors, Logic Programming (ICLP 2009), volume 5649 of LNCS, pages 449–463, Pasadena, CA, USA, July 14–17 2009. Springer-Verlag Berlin Heidelberg. → Página 129

(A.5) A declarative semantics for CLP with qualification and proximity M. Rodríguez-Artalejo and C. A. Romero-Díaz Theory and Practice of Logic Programming, 26th Int’l. Conference on Logic Programming (ICLP 2010) Special Issue, 10(4–6):627–642, 2010. → Página 144

85

B.

Recursos adicionales

(B.1) A generic scheme for qualified logic programming M. Rodríguez-Artalejo and C. A. Romero-Díaz Technical Report SIC-1-08 (CoRR abs/1008.3863), Universidad Complutense, Departamento de Sistemas Informáticos y Computación, Madrid, Spain, 2008 → Página 161

(B.2) Similarity-based reasoning in qualified logic programming (revised edition) R. Caballero, M. Rodríguez-Artalejo and C. A. Romero-Díaz CoRR abs/1008.3867, 2010 → Página 184

(B.3) A generic scheme for qualified constraint functional logic programming R. Caballero, M. Rodríguez-Artalejo and C. A. Romero-Díaz Technical Report SIC-1-09 (CoRR abs/1101.2146), Universidad Complutense, Departamento de Sistemas Informáticos y Computación, Madrid, Spain, 2009 → Página 194

(B.4) Fixpoint & proof-theoretic semantics for CLP with qualification and proximity M. Rodríguez-Artalejo and C. A. Romero-Díaz Technical Report SIC-1-10 (CoRR abs/1009.1977), Universidad Complutense, Departamento de Sistemas Informáticos y Computación, Madrid, Spain, 2010 → Página 230

(B.5) A transformation-based implementation for CLP with qualification and proximity (preliminary version) R. Caballero, M. Rodríguez-Artalejo and C. A. Romero-Díaz Technical Report SIC-4-10 (CoRR abs/1009.1976), Universidad Complutense, Departamento de Sistemas Informáticos y Computación, Madrid, Spain, 2010 → Página 277

160

A Generic Scheme for Qualified Logic Programming? Technical Report SIC-1-08 Mario Rodr´ıguez-Artalejo and Carlos A. Romero-D´ıaz Departamento de Sistemas Inform´ aticos y Computaci´ on Universidad Complutense de Madrid, Spain [email protected] and [email protected]

Abstract. Uncertainty in Logic Programming has been investigated since about 25 years, publishing papers dealing with various approaches to semantics and different applications. This report is intended as a first step towards the investigation of qualified computations in Constraint Functional Logic Programming, including uncertain computations as a particular case. We revise an early proposal, namely van Emden’s Quantitative Logic Programming [24], and we improve it in two ways. Firstly, we generalize van Emden’s QLP to a generic scheme QLP (D) parameterized by any given Qualification Domain D, which must be a lattice satisfying certain natural axioms. We present several interesting instances for D, one of which corresponds to van Emden’s QLP . Secondly, we generalize van Emden’s results by providing stronger ones, concerning both semantics and goal solving. We present Qualified SLD Resolution over D, a sound and strongly complete goal solving procedure for QLP (D), which is applicable to open goals and can be efficiently implemented using CLP technology over any constraint domain CD able to deal with qualification constraints over D. We have developed a prototype implementation of some instances of the QLP (D) scheme (including van Emden’s QLP ) on top of the CF LP system T OY. Keywords: Quantitative Logic Programming, Qualification Domains, Qualification Constraints.

1

Introduction

The investigation of uncertainty in logic programming has proceeded along various lines during the last 25 years. A recent recollection by V. S. Subrahmanian [23] highlights some phases in the evolution of the topic from the viewpoint of a committed researcher. Research on the field has dealt with various approaches to semantics, as well as different applications. One of the earliest approaches was Quantitative Logic Programming, QLP for short. This can be traced back to a paper by Shapiro ?

Research partially supported by projects MERIT-FORMS (TIN2005-09027-C03-03) and PROMESAS-CAM(S-0505/TIC/0407)

161

2

M. Rodr´ıguez-Artalejo and C.A. Romero-D´ıaz

[19], who proposed to use real numbers in the interval (0, 1] as certainty factors, as well as certainty functions for propagating certainty factors from the bodies to the heads of program clauses. Subsequently, van Emden [24] considered QLP with an attenuation factor f ∈ (0, 1] attached to the implication of each program clause and restricted his attention to the certainty function which propagates to a clause head the certainty factor f ×b, where f is the clause’s attenuation factor and b is the minimum of the certainty factors known for the body atoms. Van Emden’s approach was less general than Shapiro’s because of the fixed choice of a particular certainty function, but it allowed to prove more general results on model theoretic and fixpoint semantics, similar to those previously obtained in [25,1] for classical Logic Programming. Moreover, [24] gave a procedure for computing the certainty of atoms in the least Herbrand model of a given program, by applying an alpha-beta heuristic to the atoms’ and/or search trees. This procedure worked only for ground atoms having a finite search tree. Following these beginnings, logic programming with uncertainty developed in various directions. Subrahmanian [21] proposed an alternative to [24], using a different lattice of numeric values (aiming at a separate representation of certainty degrees for truth an falsity) as well as clauses whose atoms were annotated with values from this lattice. Neither certainty functions nor attenuation factors were used in this approach, which was extended in [22] to provide goal solving procedures enjoying stronger soundness and completeness results. As a brief summary of some significant later contributions let us mention: generalized annotated logic programs [11], a quite general framework which will be discussed in more detail in Section 6; semantics based on bilattices of generalized truth values with both a ‘knowledge’ order and a ‘truth’ order [8]; logic programming with probabilistic semantics and applications to deductive databases [14,15]; quantitative and probabilistic constraint logic programming and applications to natural language processing [16]; hybrid probabilistic programs [5]; probabilistic agent programs [7] and their extension to deal with both time and uncertainty [6]; logic programs with similarity based unification and applications to flexible data retrieval [2,18,9,12]; and functional logic programming with similarity based unification [13]. We are interested in a long-term research project aiming at a generalization of existing work on logic programming with uncertainty. The generalization we plan to develop will operate in two directions: a) extending logic programming languages to more expressive multi-paradigm declarative languages supporting functions and constraints; and b) generalizing uncertain truth values to so-called qualification values, attached to computed answers and intended to measure the degree in which such computed answers satisfy various user’s expectations. In this setting, (constraint) logic programming with uncertainty becomes the particular case in which no functional programming features are used and qualification values are just uncertain truth values. As a first step, we present in this report a generalization of the early QLP proposal by van Emden [24], which is still appealing because of its neat semantics. Syntactically, our proposal is very close to van Emden’s QLP : we use qualified definite Horn clauses A ← d − B with

162

A Generic Scheme for Qualified Logic Programming

3

an attenuation value d attached to the implication and no annotations attached to the atoms. However, we improve [24] in the two ways summarized in the abstract: firstly, we replace numeric certainty values (in particular, those playing the role of attenuation factors in program clauses) by qualification values belonging to a parametrically given Qualification Domain D with a lattice structure, which provides abstract operations generalizing the use of min (minimum) and × (product) in [24]. In this way we get a generic scheme QLP (D). Secondly, we present stronger semantic results and a sound and strongly complete goal solving procedure called Qualified SLD Resolution over D(in symbols, SLD(D)), which extends SLD resolution using annotated atoms and qualification constraints over D. The QLP (D) scheme enjoys nice semantic properties and has interesting instances that can be efficiently implemented using CLP technology: QLP (D) programs and goals can be easily translated into CLP (CD ) for any choice of a constraint domain CD able to compute with qualification constraints over D. We have developed a prototype implementation of some instances of the QLP (D) scheme (including van Emden’s QLP ) on top of the CF LP system T OY. After this introduction, the rest of the report is structured as follows: Section 2 presents the axioms for qualification domains D, showing some basic instances and proving that the class of such domains is closed under cartesian product. Section 3 presents the syntax and declarative semantics of the QLP (D) scheme. Section 4 presents qualified SLD resolution over D with its soundness and strong completeness properties. Section 5 presents the general implementation technique for QLP (D) that we have used to implement some instances of the scheme (including van Emden’s QLP ) on top of the CF LP system T OY. Finally, Section 6 presents our conclusions and plans for future work. Appendix A includes detailed proofs for the main results. Other proofs that have been ommitted or sketched can be found in [17] (in Spanish).

2

Qualification Domains

By definition, a Qualification Domain is any structure D = hD, v, ⊥, >, ◦i such that: 1. hD, v, ⊥, >i is a lattice with extreme points ⊥ and > w.r.t. the partial ordering v. For given elements d, e ∈ D, we write d u e for the greatest lower bound (glb) of d and e and d t e for the least upper bound (lub) of d and e. We also write d @ e as abbreviation for d v e ∧ d 6= e. 2. ◦ : D × D → D, called attenuation operation, verifies the following axioms: (a) ◦ is associative, commutative and monotonic w.r.t. v. (b) ∀d ∈ D : d ◦ > = d. (c) ∀d ∈ D : d ◦ ⊥ = ⊥. (d) ∀d, e ∈ D \ {⊥, >} : d ◦ e @ e. (e) ∀d, e1 , e2 ∈ D : d ◦ (e1 u e2 ) = d ◦ e1 u d ◦ e2 .

163

4

M. Rodr´ıguez-Artalejo and C.A. Romero-D´ıaz

In the rest of the report, D will generally denote an arbitrary qualification d domain. For any finite S = {e1 , e2 , . . . , en } ⊆ D, the glb of S (noted as S) exists and can be computed as e1 u e2 u · · · u en (which reduces to > in the d case n d = 0). As an easy consequence of the axioms, one gets the identity d ◦ S = {d ◦ e | e ∈ S}. We generalize van Emden’s QLP to a generic scheme QLP (D) which uses qualification values d ∈ D \ {⊥} in place of certainty values d ∈ (0, 1], d the glb operator in place of the minimum operator min, and the attenuation operator ◦ in place of the multiplication operator ×. Three interesting instances of qualification domains are shown below. The Domain of Classical Boolean Values: B = ({0, 1}, ≤, 0, 1, ∧), where 0 and 1 stand for the two classical truth values false and true, ≤ is the usual numerical ordering over {0, 1}, and ∧ stands for the classical conjunction operation over {0, 1}. The instance QLP (B) of our QLP (D) scheme behaves as classical Logic Programming. The Domain of van Emden’s Uncertainty Values: U = (U, ≤, 0, 1, ×), where U = [0, 1] = {d ∈ IR | 0 ≤ d ≤ 1}, ≤ is the usual numerical ordering, and × is the multiplication operation. In this domain, the top element > is 1 and d the greatest lower bound S of a finite S ⊆ U is the minimum value min(S), which is 1 if S = ∅. For this reason, the instance QLP (U) of our QLP (D) scheme behaves as van Emden’s QLP . The Domain of Weight Values: W = (P, ≥, ∞, 0, +), where P = [0, ∞] = {d ∈ IR ∪ {∞} | d ≥ 0}, ≥ is the reverse of the usual numerical ordering (with ∞ ≥ d for any d ∈ P), and + is the addition operation (with ∞+d = d+∞ = ∞ for anydd ∈ P). In this domain, the top element > is 0 and the greatest lower bound S of a finite S ⊆ P is the maximum value max(S), which is 0 if S = ∅. When working in the instance QLP (W) of our QLP (D) scheme one propagates to a clause head the qualification value f + b, where f is the clause’s ’attenuation factor’ and b is the maximum of the qualification values known for the body atoms. Therefore, qualification values in the instance QLP (W) of our QLP (D) scheme behave as a weighted measure of the depth of proof trees. It is easily checked that the axioms of qualification domains are satisfied by B, U and W. In fact, the axioms have been chosen as a natural generalization of some basic properties satisfied by the ordering ≤ and the operation × in U. In general, the values belonging to a qualification domain are intended to qualify logical assertions by measuring the degree in which they satisfy some kind of user’s expectations. In this way, one can think of U values as measuring the degree of truth, W values as measuring proofs sizes, etc. Given two qualification domains Di = hDi , vi , ⊥i , >i , ◦i i (i ∈ {1, 2}), their cartesian product D1 × D2 is defined as D =def hD, v, ⊥, >, ◦i, where D =def D1 × D2 , the partial ordering v is defined as (d1 , d2 ) v (e1 , e2 ) ⇐⇒def d1 v1 e1 and d2 v2 e2 , ⊥ =def (⊥1 , ⊥2 ), > =def (>1 , >2 ), and the attenuation operator ◦ is defined as (d1 , d2 )◦(e1 , e2 ) =def (d1 ◦1 e1 , d2 ◦2 e2 ). The class of the qualification domains is closed under cartesian products, as stated in the following result. Proposition 1. The cartesian product D = D1 × D2 of two given qualification domains is always another qualification domain.

164

A Generic Scheme for Qualified Logic Programming

5

Proof. According to the axiomatic definition of qualification domains, one must prove two items: 1. D is a lattice with extreme points ⊥ and > w.r.t. the partial ordering v. This is easily checked using the definition of v in the product domain. In particular, one gets the equalities (d1 , d2 ) u (e1 , e2 ) = (d1 u1 e1 , d2 u2 e2 ) and (d1 , d2 ) t (e1 , e2 ) = (d1 t1 e1 , d2 t2 e2 ). 2. ◦ satisfies the five axioms required for attenuation operators, i.e.: (a) ◦ is associative, commutative and monotonic w.r.t. v. (b) ∀(d1 , d2 ) ∈ D1 × D2 : (d1 , d2 ) ◦ > = (d1 , d2 ). (c) ∀(d1 , d2 ) ∈ D1 × D2 : (d1 , d2 ) ◦ ⊥ = ⊥. (d) ∀(d1 , d2 ), (e1 , e2 ) ∈ D1 × D2 \ {⊥, >} : (d1 , d2 ) ◦ (e1 , e2 ) @ (e1 , e2 ). (e) ∀(d1 , d2 ), (e1 , e2 ), (e01 , e02 ) ∈ D1 × D2 : (d1 , d2 ) ◦ ((e1 , e2 ) u (e01 , e02 )) = ((d1 , d2 ) ◦ (e1 , e2 )) u ((d1 , d2 ) ◦ (e01 , e02 )). All these conditions are easily proved, using the hypothesis that both D1 and D2 are qualification domains as well as the construction of D as cartesian product of D1 and D2 . t u Intuitively, each value (d1 , d2 ) belonging to a product domain D1 ×D2 imposes the qualification d1 and also the qualification d2 . In particular, values (c, d) belonging to the product domain U × W impose two qualifications, namely: a certainty value greater or equal than c and a proof tree with depth less or equal than d. These intuitions indeed correspond to the declarative and operational semantics formally defined in Sections 3 and 4.

3 3.1

Syntax and Semantics of QLP(D) Programs, Interpretations and Models

We assume a signature Σ providing free function symbols (a.k.a. constructors) and predicate symbols. Terms are built from constructors and variables from a countably infinite set Var, disjoint from Σ. Atoms are of the form p(t1 , . . . , tn ) (abbreviated as p(tn )) where p is a n-ary predicate symbol and ti are terms. We write AtΣ for the set of all the atoms, called the open Herbrand base. A QLP (D) program P is a set of qualified definite Horn clauses of the form A ← d−B where A is an atom, B a finite conjunction of atoms and d ∈ D \ {⊥} is the attenuation value attached to the clause’s implication. In QLP (B) programs, the only choice for d is 1, standing for true, and therefore QLP (B) behaves as classical LP . The following example presents two simple programs over the domains U and W. It is not meant as a realistic application, but just as an illustration. Example 1. 1. The QLP (U) program PU displayed below can be understood as a knowledge base given by the facts for the predicates animal, plant, human and eats, along with knowledge inference rules corresponding to the clauses with nonempty body. The clauses for the predicate human specify the human beings as

165

6

M. Rodr´ıguez-Artalejo and C.A. Romero-D´ıaz

the ancestors of adam and eve, with the certainty of being an actual human decreasing as one moves back along the ancestors’ chain. Therefore, the certainty of being a cruel human also decreases when moving from descendants to ancestors. cruel(X) <-0.90- human(X), eats(X,Y), animal(Y) cruel(X) <-0.40- human(X), eats(X,Y), plant(Y) animal(bird) <-1.0animal(cat) <-1.0plant(oak) <-1.0plant(apple) <-1.0-

human(adam) <-1.0human(eve) <-1.0human(father(X)) <-0.90- human(X) human(mother(X)) <-0.90- human(X)

eats(adam, X) <-0.80eats(eve,X) <-0.30- animal(X) eats(eve,X) <-0.60- plant(X) eats(father(X),Y) <-0.80- eats(X,Y) eats(mother(X),Y) <-0.70- eats(X,Y) 2. The QLP (W) program PW is very similar to PU , except that the attenuation value 1 is attached to all the clauses. Therefore, each clause is intended to convey the information that the depth of a proof tree for the head is 1 plus the maximum depth of proof trees for the atoms in the body. As we will see, qualification constraints over W can be used to impose upper bounds to the depths of proof trees when solving goals w.r.t. PW . Note that the two programs in this example are different qualified versions of the classical LP program P obtained by dropping all the annotations. Due to the left recursion in the clauses for the predicates human and eats, some goals for P have an infinite search space where SLD resolution with a leftmost selection strategy would fail to compute some expected answers. For instance, the answer {X 7→ mother(eve), Y 7→ apple} would not be computed for the goal eats(X,Y). However, when solving goals for the qualified programs PU and PW using the resolution method presented in Section 4, qualification constraints can be used for imposing bounds to the search space, so that even the leftmost selection strategy leads to successful computations. t u As shown in the example, clauses contain classic atoms in both their head and their body. But for our semantics, we will be interested in not only proving that we can infer an atom for a given program, but proving that we can infer it with qualification greater or equal than some given value. For this reason, we introduce D-annotated atoms A ] d, consisting of an atom A with an attached ‘annotation’ d ∈ D \ {⊥}. For use in goals to be solved, we consider also open annotated atoms of the form A ] W , where W is a qualification variable intended to take values over D \ {⊥}. We postulate a countably infinite set War of qualification variables, disjoint from Var and Σ.

166

A Generic Scheme for Qualified Logic Programming

7

The annotated Herbrand base over D is defined as the set AtΣ (D) of all D-annotated atoms. The D-entailment relation over AtΣ (D) is defined as follows: A ] d
Let C be any clause A ← d − B1 , . . . , Bk in the program P, and I ∈ IntΣ (D) any interpretation over D. We say that I is a model of C if and only if for any substitution θ and any qualification valuesdd1 , . . . , dk ∈ D \ {⊥} such that Bi θ ] di ∈ I for all 1 ≤ i ≤ k, one has Aθ ] (d ◦ {d1 , . . . , dk }) ∈ I. And we say that I is a model of the QLP (D) program P (in symbols, I |= P) if and only if I is a model of each clause in P. 3.2

Declarative Semantics

As in any logic language, we need some technique to infer formulas (in our case, D-annotated atoms) from a given QLP (D) program P. Following traditional ideas, we consider two alternative ways of formalizing an inference step which goes from the body of a clause to its head: an operator TP and a qualified variant of Horn Logic, noted as QHL(D) and called Qualified Horn Logic. The operator TP : IntΣ (D) → IntΣ (D) is defined as: TP (I) =def {A0 ] d0 | (A ← d − B1 , . . . , Bk ) ∈ P, 0 θ subst., Bi θ ] di ∈ I for d all 1 ≤ i ≤ k, A = Aθ, d0 ∈ D \ {⊥}, d0 v d ◦ {d1 , . . . , dk }}

Intuitively, we can see that for a given interpretation I, TP (I) is the set of those D-annotated atoms obtained by considering D-annotated bodies of clause instances that are included in I and propagating an annotation to the head via the clause’s qualification value. The logic QHL(D) is defined as a deductive system consisting just of one inference rule QMP(D), called Qualitative Modus Ponens over D. If there are some (A ← d − B1 , . . . , Bk ) ∈ P, some substitution θ such that A0 = Aθ and

167

8

M. Rodr´ıguez-Artalejo and C.A. Romero-D´ıaz

Bi0 = Bi θ for all 1 ≤ i ≤ k and d0 v d ◦ step is allowed: B10 ] d1

d

{d1 , . . . , dk }, the following inference

· · · Bk0 ] dk A0 ] d0

QMP(D)

We will use the notations P `QHL(D) A ] d (resp. P `nQHL(D) A ] d) to indicate that A ] d can be inferred from the clauses in program P in finitely many steps (resp. n steps). Note that QHL(D) proofs can be naturally represented as upwards growing proof trees with D-annotated atoms at their nodes, each node corresponding to one inference step having the children nodes as premises. The following proposition collects the main results concerning the declarative semantics of the QLP (D) scheme. We just sketch some key proof ideas. The full proofs are given in [17]. As in [24], they can be developed in analogy to the classical papers [25,1], except that our Herbrand interpretations are open, as first suggested by Clark in [4]. Our use of the QHL(D) calculus is obviously related to the classical TP operator, although it has no direct counterpart in the historical papers we are aware of. Proposition 3. The following assertions hold for any QLP (D) program P: 1. 2. 3. 4.

I |= P ⇐⇒ TP (I) ⊆ I . TP is monotonic and continuous. The least S fixpoint µ(TP ) is the least Herbrand model of P, noted as MP . MP = n∈IN TP ↑n (∅) = {A ] d | P `QHL(D) A ] d}.

Proof (Sketch). Item (1) is easy to prove from the definition of TP . In item (2), monotonicity (I ⊆ J =⇒ S TP (I) ⊆ TP (J S )) follows easily from the definition of TP and continuity (TP ( n∈IN In ) = n∈IN TP (In ) for any chain {In | n ∈ IN} ⊆ IntΣ (D) with In ⊆ In+1 for all n ∈ IN) follows from monotonicity and properties of chains and sets of interpretations. Item (3) follows from (1), (2), Proposition 2 and some known properties about lattices. Finally, item (4) follows from proving the two implications P `nQHL(D) A ] d =⇒ ∃m (A ] d ∈ TP ↑m (∅)) and A ] d ∈ TP ↑n (∅) =⇒ ∃m (P `m t u QHL(D) A ] d) by induction on n. The next example presents proofs deriving annotated atoms that belong to the least models of the programs PU and PW from Example 1. Example 2. 1. The proof tree displayed below shows that the U-annotated atom at its root can be deduced from PU in QHL(U). Therefore, the atom belongs to MPU . human(eve)#1.0 human(mother(eve))#0.90

animal(bird)#1.0 eats(eve,bird)#0.30 eats(mother(eve),bird)#0.21 cruel(mother(eve))#0.15

animal(bird)#1.0

It is easy to see which clause was used in each inference step. Note that the atom at the root could have been proved even with the greater certainty value 0.189. However, since 0.15 ≤ 0.189, the displayed inference it is also correct (albeit less informative).

168

A Generic Scheme for Qualified Logic Programming

9

2. A proof tree quite similar to the previous one, but with different annotations, can be easily built to show that cruel(mother(eve))#4 can be deduced from PW in QHL(W). Therefore, this annotated atom belongs to MPW . It conveys the information that cruel(mother(eve)) has a proof tree of depth 4 w.r.t. to the classical LP program P obtained by dropping PW ’s annotations. t u

4 4.1

Goal Solving by SLD(D) Resolution Goals and Solutions

In classical logic programming a goal is presented as a conjunction of atoms. In our setting, proving atoms with arbitrary qualifications may be unsatisfactory, since qualification values too close to ⊥ may not ensure sufficient information. For this reason, we present goals as conjunctions of open D-annotated atoms and we indicate the minimum qualification value required each of them. Hence initial goals look like: A1 ] W1 , . . . , An ] Wn 8 W1 w β1 , . . . , Wn w βn , where Wi ∈ War and βi ∈ D \ {⊥}. Observe that we have annotated all atoms in the goal with qualification variables Wi instead of plain values because we are interested in any solution that satisfies the qualification constraints Wi w βi , used to impose lower bounds to the atoms’ qualifications. As explained in the next Subsection, goal resolution proceeds from an initial goal through intermediate goals until reaching a final solved goal. The intermediate goals have a more general form, consisting of a composition of three items: a conjunction of D-annotated atoms A waiting to be solved, a substitution σ computed in previous steps, and a set of qualification constraints ∆. We consider two kinds of qualification constraints: 1. α ◦ W w β, where W ∈ War is qualification variable and α, β ∈ D \ {⊥} are such that αdw β. This is called a threshold constraint for W . 2. W = d ◦ {W1 , . . . , Wk }, where W, W1 , . . . , Wk ∈ War are qualification variables and d ∈ D \ {⊥}. This is called a defining constraint for W . In order to understand why these two kinds of constraints are needed, think of an annotated atom A ] W within an initial goal which includes also an initial threshold constraint > ◦ W w β (i.e. W w β) for W . Applying a resolution step with a program clause whose head unifies with A and whose attenuation value is dd∈ D \ {⊥} will lead to a new goal including a defining constraint W = d ◦ {W1 , . . . , Wk } for W and a threshold constraint d ◦ > ◦ Wi w β for each 1 ≤ i ≤ k, where the new qualification variables Wi correspond to the atoms in the clause’s body. This explains the need to introduce defining constraints as well as more general threshold constraints α ◦ W w β. Intuitively, the values α and β within such constraints play the role of an upper and a lower bound, respectively. As we will see, our goal solving procedure takes advantage of these bounds for pruning useless parts of the computation search space.

169

10

M. Rodr´ıguez-Artalejo and C.A. Romero-D´ıaz

Let us now present some notations needed for a formal definition of goals. Given a conjunction of D-annotated atoms A and a set of qualification constraints ∆, we define the following sets of variables: S – var(A) =def S{var(A) | A ] W ∈ A} . – war(A) =def {W | A ] W ∈ A} . – war(∆) as the set of qualification variables that appears in any qualification constraint in ∆. – dom(∆) as the set of qualification variables that appear in the left hand side of any qualification constraint in ∆. We also say that ∆ is satisfiable iff there is some ω ∈ SubstΣ (D) –the set of all the substitutions of values in D\{⊥} for variables in War– such that ω ∈ Sol(∆), what means that ω satisfies every qualification constraint in ∆, i.e. ω is a solution of ∆. Moreover, we say that ∆ is admissible iff it satisfies the following three conditions: 1. ∆ is satisfiable, 2. for every W ∈ war(∆) there exists one and only one constraint for W in ∆ (this implies dom(∆) = war(∆)), and 3. the relation d >∆ defined by W >∆ Wi iff there is some defining constraint W = α ◦ {W1 , . . . , Wi , . . . , Wk } in ∆, satisfies that >∗∆ is irreflexive.

Finally, we say that ∆ is solved iff ∆ is admissible and only contains defining constraints. Now we are in a position to define goals and their solutions:

Definition 1 (Goals and its Variables). Given a conjunction of D-annotated atoms A, a substitution σ ∈ SubstΣ –the set of all substitutions of terms for variables in Var– and a set of qualification constraints ∆, we say that G ≡ A 8 σ 8 ∆ is a goal iff

i. σ ∈ SubstΣ is idempotent and such that dom(σ) ∩ var(A) = ∅. ii. ∆ is admisible. iii. For every qualification variable in war(A) there is one and only one threshold constraint for W in ∆. And there are no more threshold constraints in ∆. Furthermore, if σ =  (the identity substitution) then G is called initial, and if A is empty and ∆ is solved, then G is called solved. For any goal G, we define the set of variables of G as var(G) =def var(A) ∪ dom(σ) and the set of qualification variables of G as war(G) =def war(A) ∪ dom(∆). t u Definition 2 (Goal Solutions). A pair of substitutions (θ, ρ) such that θ ∈ SubstΣ and ρ ∈ SubstΣ (D) is called a solution of a goal G ≡ A 8 σ 8 ∆ iff: 1. θ = σθ . 2. ρ ∈ Sol(∆) . 3. P `QHL(D) Aθ ] W ρ for all A ] W ∈ A .

170

A Generic Scheme for Qualified Logic Programming

11

In addition, a solution (σ, µ) for a goal G is said to be more general than another solution (θ, ρ) for the same goal G (one also says in this case that (θ, ρ) is subsumed by (σ, µ)) iff σ 4 θ [var(G)] and µ w ρ [war(G)], where σ 4 θ [var(G)] means that there is some substitution η such that the composition ση behaves the same as θ over any variable in the set var(G) and µ w ρ [war(G)] means that µ(W ) w ρ(W ) holds for any W ∈ war(G). t u Any solved goal G0 ≡ σ 8 ∆ has the associated solution (σ, µ), where µ = ω∆ is the qualification substitution given by ∆, such that ω∆ (W ) is the qualification value determined by the defining constraints in ∆ for all W ∈ dom(∆), and ω∆ (W ) = ⊥ for any W ∈ War \ dom(∆). Notedthat for any W ∈ dom(∆) there exists one unique defining constraint W = d ◦ {W d 1 , . . . , Wk } for W in ∆, and then ω∆ (W ) can be recursively computed as d ◦ {ω∆ (W1 ), . . . , ω∆ (Wk )}. The solutions associated to solved goals are called computed answers. Example 3. 1. A possible goal for program PU in Example 1 is eats(father(X),Y)#W1, human(father(X))#W2 | W1>=0.4, W2>=0.6; and a valid solution for it is {X 7→ adam, Y 7→ apple} | {W1 7→ 0.50, W2 7→ 0.75}. 2. A goal for program PW in Example 1 may be eats(X,Y)#W | W<=5.0; and a valid solution is {X 7→ father(adam), Y 7→ apple} | {W 7→ 4.0}. t u Note that the goal for PU in the previous example imposes lower bounds to the certainties to be computed, while the goal for PW imposes an upper bound to the proof depth. In general, goal solving in QLP (W) corresponds to depth-bound goal-golving in classical Logic Programming. 4.2

SLD(D) Resolution

We propose a sound and strongly complete goal solving procedure called Qualified SLD Resolution parameterized over a given qualification domain D, written as SLD(D), which makes use of annotated atoms and qualification constraints over D. The implementation of this goal solving procedure using CLP technology will be discussed in the next section. Resolution computations are written G0 C1 ,σ1 G1 C2 ,σ2 · · · Cn ,σn Gn , abbreviated as G0 ∗σ Gn with σ = σ1 σ2 · · · σn . They are finite sequences of resolution steps Gi−1 Ci ,σi Gi , starting with an initial goal G0 and ending up with a solved goal Gn . One single resolution step is formally defined as follows: Definition 3 (Resolution step). A resolution step has the form L, A ] W, R 8 σ 8 α ◦ W w β, ∆ C1 ,σ1 (L, B1 ] W1 , . . . Bk ] Wk , R)σ1 8 σσ1 8 ∆1 where d A ] W is the selected atom, ∆1 = d ◦ α ◦ W1 w β, . . . , d ◦ α ◦ Wk w β, W = d◦ {W1 , . . . , Wk }, ∆, C1 ≡ (H ← d−B1 , . . . , Bk ) ∈var P is chosen as a variant of a clause in P with fresh variables and such that d ◦ α w β, σ1 is the m.g.u. between A and H, and W1 , . . . , Wk ∈ War are fresh qualification variables. t u

171

12

M. Rodr´ıguez-Artalejo and C.A. Romero-D´ıaz

The notation α ◦ W w β, ∆ represents a set of qualification constraints including the threshold constraint α ◦ W w β plus those in ∆, with no particular ordering assumed. Notice that the condition d ◦ α w β is required for the resolution step to be enabled. In this way, threshold constraints α ◦ W w β are actively used for pruning parts of the computation search space where no solutions can be found. In the instance of QLP (B) it is easily checked that all the qualification values and constraints become trivial, so that SLD(B) boils down to classical SLD resolution. In the rest of this section we present the main properties of SLD(D) resolution in the general case. Proposition 4. If G is a goal and G0 C1 ,σ1 G1 , then G1 is also a goal. Proof (Sketch). Assume a goal G0 and a SLD(D) resolution step G0 C1 ,σ1 G1 , as in Definition 3. Then G0 satisfies the conditions required for goals in Definition 1, and we must show that G1 also satisfies such conditions. This is not difficult to check, using the fact that C1 has been chosen without variables in common with G0 . In particular, note that the threshold constraint for W in G0 is absent in G1 , which includes a defining constraint for W and threshold constraints for the new qualification variables Wi . t u The next two theorems are the main theoretical results in this report. The Soundness Theorem 1 guarantees that every computed answer is correct in the sense that it is a solution of the given goal. The Strong Completeness Theorem 2 ensures that, for any solution of a given goal and any fixed selection strategy, SLD(D) resolution is able to compute an equal, if not better, solution. The proofs, given in Appendix A, use inductive techniques similar to those presented in [20] for classical SLD resolution. Example 4 below illustrates the Completeness Theorem. Theorem 1 (Soundness). Assume G0 ∗ G and G = σ 8 ∆ solved. Let (σ, µ) be the solution associated to G. Then (σ, µ) –called the computed answer– is a solution of G0 . t u Theorem 2 (Strong Completeness). Assume a given solution (θ, ρ) for G0 and any fixed strategy for choosing the selected atom at each resolution step. Then there is some computed answer (σ, µ) for G0 which subsumes (θ, ρ). t u Example 4. 1. The following SLD(U) computation solves the goal for program PU presented in Example 3:

172

A Generic Scheme for Qualified Logic Programming

13

eats(father(X),Y)#W1, human(father(X))#W2 | W1 >= 0.4, W2 >= 0.6

eats.4,{X7→adam} eats(adam,Y)#W3, human(father(adam))#W2 | {X 7→ adam} | W1 = 0.8 * min{W3}, W2 >= 0.6, 0.8 * W3 >= 0.4

eats.1, human(father(adam))#W2 | {X 7→ adam} | W1 = 0.8 * min{W3}, W2 >= 0.6, W3 = 0.8

human.3, human(adam)#W4 | {X 7→ adam} | W1 = 0.8 * min{W3}, W2 = 0.9 * min{W4}, W3 = 0.8, 0.90 * W4 >= 0.6

human.1, | {X 7→ adam} | W1 = 0.8 * min{W3}, W2 = 0.9 * min{W4}, W3 = 0.8, W4 = 1.0 Note that the computed answer {X 7→ adam} | {W1 7→ 0.64, W2 7→ 0.90} subsumes the solution for the same goal given in Example 3. 2. Similarly, SLD(W) resolution can solve the goal eats(X,Y)#W | W <= 5.0 for PW , obtaining a computed answer {X 7→ father(adam)} | {W 7→ 3.0} which subsumes the solution for the same goal given in Example 3. t u

5

Towards an Implementation

In this section we assume a qualification domain D and a constraint domain CD such that the qualification constraints used in SLD(D) resolution can be expressed as CD constraints, and we describe a translation of QLP (D) programs P and goals G into CLP (CD ) programs P t and goals Gt , such that solving G with SLD(D) resolution using P corresponds to solving Gt with constrained SLD resolution using P t and a solver for CD . The translation can be used to develop an implementation of SLD(D) resolution for the QLP (D) language on top of any CLP or CF LP system that supports CD constraints. In particular, if D is any of the two qualification domains U or W, the constraint domain CD can be chosen as R, which supports arithmetic constraints over the real numbers [10]. We have developed prototype implementations for QLP (U), QLP (W) and QLP (U × W) on top of the CF LP system T OY [3], that supports R constraints. Note that although the use of a CLP (R) system could lead to a more efficient implementation, we have chosen a CF LP (R) system instead of a CLP (R) one due to our interest in a future extension of the QLP (D) scheme to support qualified CF LP programming. Our translation of a QLP (D) program works by adding three extra arguments to all predicates and translating each clause independently. Given the

173

14

M. Rodr´ıguez-Artalejo and C.A. Romero-D´ıaz

QLP (D) clause C ≡ p(t) ← d − q1 (s1 ), . . . , qk (sk ) its head is translated as p(t, Alpha, W, Beta), where the new variables Alpha, W and Beta correspond, respectively, to α, W and β in the threshold constraint α ◦ W w β related to a D-annotated atom A ] W which could be selected for a SLD(D) resolution step using the clause C. The clause’s body is translated with the aim of emulating such a resolution step, and the translated clause becomes: C t ≡ p(t, Alpha, W, Beta) ← d ◦ Alpha w Beta, W1 A ⊥, W1 v >, q1 (s1 , d ◦ Alpha, W1 , Beta), .. .

Wk A ⊥, d Wk v >, qk (sk , d ◦ Alpha, Wk , Beta), W = d ◦ {W1 , . . . , Wk }

The conditions in the body of C t do indeed correspond to the performance of a SLD(D) resolution step with clause C. In fact, d ◦ Alpha w Beta checks that C is eligible for such a step; the conditions in the next k lines using new variables Wi correspond to placing the annotated atoms from C’s body into the new goal; and the last condition introduces the proper defining constraint for W . The idea for translating goals is similar. Given an initial goal QLP (D) goal G like q1 (t1 ) ] W1 , . . . , qm (tm ) ] Wm 8 W1 w β1 , . . . , Wm w βm where β1 , . . . , βm ∈ D \ {⊥}, the translated goal Gt is

q1 (t1 , >, W1 , β1 ), . . . , qm (tm , >, Wm , βm ) where the three additional arguments at each atom are used to encode the initial threshold constraints Wi w βi , that are equivalent to > ◦ Wi w βi . Example 5. As an example of the translation process we present the translation of the program PU from Example 1 into a T OY program which uses R constraints. min1 min1 min2 data

[] = 1 [X|Xs] = min2 X (min1 Xs) W1 W2 = if W1 <= W2 then W1 else W2 being = adam | eve | bird | cat | oak | apple | father being | mother being cruel(X,F,W,M) :- F*0.9>=M, W1>0, W1<=1.0, human(X,F*0.9,W1,M), W2>0, W2<=1.0, eats(X,Y,F*0.9,W2,M), W3>0, W3<=1.0, animal(Y,F*0.9,W3,M), W == 0.9 * min1 [W1,W2,W3] cruel(X,F,W,M) :- F*0.4>=M, W1>0, W1<=1.0, human(X,F*0.4,W1,M), W2>0, W2<=1.0, eats(X,Y,F*0.4,W2,M), W3>0, W3<=1.0, plant(Y,F*0.4,W3,M), W == 0.4 * min1 [W1,W2,W3]

174

A Generic Scheme for Qualified Logic Programming

15

animal(bird,F,W,M) :- F*1.0>=M, W == 1.0 * min1 [] animal(cat,F,W,M) :- F*1.0>=M, W == 1.0 * min1 [] plant(oak,F,W,M) :- F*1.0>=M, W == 1.0 * min1 [] plant(apple,F,W,M) :- F*1.0>=M, W == 1.0 * min1 [] human(adam,F,W,M) :- F*1.0>=M, W == 1.0 * min1 [] human(eve,F,W,M) :- F*1.0>=M, W == 1.0 * min1 [] human(father(X),F,W,M) :- F*0.9>=M, W1>0, W1<=1.0, human(X,F*0.9, W1, M), W == 0.9 * min1 [W1] human(mother(X),F,W,M) :- F*0.8>=M, W1>0, W1<=1.0, human(X,F*0.8, W1, M), W == 0.8 * min1 [W1] eats(adam,X,F,W,M) :- F*0.8>=M, W == 0.8 * min1 [] eats(eve,X,F,W,M) :- F*0.3>=M, W1>0, W1<=1.0, animal(X,F*0.3,W1,M), W == 0.3 * min1 [W1] eats(eve,X,F,W,M) :- F*0.6>=M, W1>0, W1<=1.0, plant(X,F*0.6,W1,M), W == 0.6 * min1 [W1] eats(father(X),Y,F,W,M) :- F*0.8>=M, W1>0, W1<=1.0, eats(X,Y,F*0.8,W1,M), W == 0.8 * min1 [W1] eats(mother(X),Y,F,W,M) :- F*0.7>=M, W1>0, W1<=1.0, eats(X,Y,F*0.7,W1,M), W == 0.7 * min1 [W1] To understand this example it is important to notice the following: 1. Since glbs in U are computed as minimums, translated programs must include functions for this task. Here, min1 resp. min2 compute the minimum of a list of numbers resp. two numbers. 2. As T OY need types for every constructor, we must include suitable datatype declarations in translated programs. 3. The resulting code could be simplified and optimized, but our aim here is to illustrate the literal application of the general translation rules. For this reason, no optimizations have been performed. t u

6

Conclusions and Future Work

We have generalized the early QLP proposal by van Emden [24] to a generic scheme QLP (D) parameterized by a qualification domain D, which must be a lattice with extreme points and equipped with an attenuation operator. The values belonging to a qualification domain are intended to qualify logical assertions, ensuring that they satisfy certain user’s expectations. Qualification domains include B (classical truth values of two-valued logic), U (van Emden’s certainty values) and W (numeric values representing proof weights), as well as arbitrary cartesian products of given qualification domains. As shown by instances such as QLP (W) and QLP (U × W), the QLP (D) scheme can express uncertainty in Logic Programming and more, since the user’s expectations qualified by W do not correspond to uncertain truth values. The semantic results obtained for QLP (D) are stronger than those in [24]. Each program P has a least open Herbrand model MP with two equivalent

175

16

M. Rodr´ıguez-Artalejo and C.A. Romero-D´ıaz

characterizations: as the least fixpoint of the operator TP , and as the set of qualified atoms deducible from P in the logic calculus QHL(D). Moreover, the goal solving calculus SLD(D), based on an extension of SLD resolution with qualification constraints, is sound and strongly complete for arbitrary open goals. SLD(B) boils down to classical SLD resolution. As implementation technique, we have proposed a translation of QLP (D) programs and goals into CLP (CD ), choosing a constraint domain CD able to compute with qualification constraints over D. If D is U, B, or U × B, the constraint domain CD can be chosen as R, and QLP (D) can be implemented on top of any CLP or CF LP system which supports constraint solving over R. We have implemented prototypes of QLP (U), QLP (W) and QLP (U × W) on top of the CF LP system T OY.

In comparison to the theory of generalized annotated logic programs (GAP for short) presented in [11], our results in this report also include some interesting contributions. With respect to the syntax and goal solving procedure, the QLP (D) scheme can be made to fit into the GAP framework by viewing our attenuation operators as annotation functions. However, our resolution procedure SLD(D) can be implemented more efficiently than the constrained SLD resolution used in GAP , due to an optimized treatment of qualification constraints and, more importantly, because the costly computation of so-called reductants between variants of program clauses is needed in GAP resolution but not in SLD(D). The purpose of reductants in GAP is to explicitly compute the lubs of several lattice values (qualification values in the case of QLP (D)) which would result from finitely many different computations if no reductants were used. In GAP ’s declarative semantics, interpretations are required to be closed w.r.t. finite lubs of lattice values assigned to the same atom, and for this reason reductants are needed for the completeness of goal resolution. In QLP (D) interpretations as defined in Section 3 no closure condition w.r.t. lubs is required, and therefore the completeness result stated in Theorem 2 can be proved without reductants. Of course, the QLP (D) approach to semantics means that a user has to observe several computed answers for one and the same goal and think of the lub of the various D elements provided by the different computations by himself instead of getting the lub computed by one single SLD(D) derivation. In our opinion, this is a reasonable scenario because even in GAP the T value provided by any single computed answer always corresponds to some lub of finitely many T values, and it may be not the highest possible T value w.r.t. to the program’s declarative semantics. Moreover, our Theorem 2 is much stronger than the one given in [11], which only ensures the possibility of computing some solution for any goal whose solvability holds in the least program model. We strongly conjecture that a stronger completeness theorem could be proved also for GAP by using a proof technique more similar to our’s. As possible lines of future work we consider: to improve the current prototype implementations of the instances QLP (U), QLP (W) and QLP (U × W); to extend the QLP (D) scheme and its implementation to a more expressive scheme which can support qualitative programming with features such as disjunctive

176

A Generic Scheme for Qualified Logic Programming

17

goals, negation, lazy functions and parametrically given constraint domains; to explore alternative semantic approaches, considering annotations, bilattices, probabilistic semantics and similarity based unification; and to investigate applications to the computation of qualified answers for web search queries.

Acknowledgements The authors are thankful to their colleagues Paco L´ opez and Rafa Caballero for their valuable hints concerning bibliography and implementation techniques. They also appreciate the constructive comments of the anonymous reviewers, that were helpful for improving the presentation.

References 1. K. R. Apt and M. H. van Emden. Contributions to the theory of logic programming. Journal of the Association for Computing Machinery (JACM), 29(3):841– 862, 1982. 2. F. Arcelli and F. Formato. Likelog: a logic programming language for flexible data retrieval. In Proceedings of the 1999 ACM Symposium on Applied computing (SAC’99), pages 260–267, New York, NY, USA, 1999. ACM Press. 3. P. Arenas, A. J. Fern´ andez, A. Gil, F. J. L´ opez-Fraguas, M. Rodr´ıguezArtalejo, and F. S´ aenz-P´erez. T OY, a multiparadigm declarative language. version 2.3.1, 2007. R. Caballero and J. S´ anchez (Eds.), Available at http://toy.sourceforge.net. 4. K. L. Clark. Predicate logic as a computational formalism (res. report doc 79/59). Technical report, Imperial College, Dept. of Computing, London, 1979. 5. A. Dekhtyar and V. S. Subrahmanian. Hybrid probabilistic programs. Journal of Logic Programming, 43(3):187–250, 2000. 6. J. Dix, S. Kraus, and V. S. Subrahmanian. Heterogeneous temporal probabilistic agents. ACM Transactions on Computational Logic, 7(1):151–198, 2006. 7. J. Dix, M. Nanni, and V. S. Subrahmanian. Probabilistic agent programs. ACM Transactions on Computational Logic, 1(2):208–246, 2000. 8. M. Fitting. Bilattices and the semantics of logic programming. Journal of Logic Programming, 11:91–116, 1991. 9. S. Guadarrama, S. Mu˜ noz, and C. Vaucheret. Fuzzy prolog: A new approach using soft constraint propagation. Fuzzy Sets and Systems, 144(1):127–150, 2004. 10. J. Jaffar, S. Michaylov, P. J. Stuckey, and R. H. C. Yap. The CLP(R) language and system. ACM Transactions on Programming Languages and Systems, 14(3):339– 395, 1992. 11. M. Kifer and V. S. Subrahmanian. Theory of generalized annotated logic programs and their applications. Journal of Logic Programming, 12(3&4):335–367, 1992. 12. V. Loia, S. Senatore, and M. I. Sessa. Similarity-based SLD resolution and its role for web knowledge discovery. Fuzzy Sets and Systems, 144(1):151–171, 2004. 13. G. Moreno and V. Pascual. Programming with fuzzy logic and mathematical functions. In A. P. I. Bloch and A. Tettamanzi, editors, Proceedings of the 6th International Workshop on Fuzzy Logic and Applications (WILF’05), volume 3849 of LNAI, pages 89–98. Springer Verlag, 2006.

177

18

M. Rodr´ıguez-Artalejo and C.A. Romero-D´ıaz

14. R. T. Ng and V. S. Subrahmanian. Probabilistic logic programming. Information and Computation, 101(2):150–201, 1992. 15. R. T. Ng and V. S. Subrahmanian. A semantical framework for supporting subjective and conditional probability in deductive databases. Journal of Automated Reasoning, 10(2):191–235, 1993. 16. S. Riezler. Probabilistic Constraint Logic Programming. PhD thesis, Neuphilologischen Fakult¨ at del Universit¨ at T¨ ubingen, 1998. 17. C. A. Romero-D´ıaz. Programaci´ on l´ ogica cuantitativa y su implementaci´ on en T OY. Proyecto de Fin de M´ aster, DSIC, Universidad Complutense de Madrid. 18. M. I. Sessa. Approximate reasoning by similarity-based SLD resolution. Theoretical Computer Science, 275(1-2):389–426, 2002. 19. E. Y. Shapiro. Logic programs with uncertainties: A tool for implementing rulebased systems. In A. Bundy, editor, Proceedings of the 8th International Joint Conference on Artificial Intelligence (IJCAI’83), pages 529–532, Karlsruhe, Germany, 1983. 20. R. F. St¨ ark. A direct proof for the completeness of SLD-resolution. In E. B¨ orger, H. K. B¨ uning, and M. M. Richter, editors, Proceedings of the 3rd Workshop on Computer Science Logic (CSL’89), volume 440 of LNCS, pages 382–383. Springer Verlag, 1990. 21. V. S. Subrahmanian. On the semantics of quantitative logic programs. In Proceedings of the 4th IEEE Symposium on Logic Programming, pages 173–182, San Francisco, 1987. 22. V. S. Subrahmanian. Query processing in quantitative logic programming. In Proceedings of the 9th International Conference on Automated Deduction, volume 310 of LNCS, pages 81–100, London, UK, 1988. Springer-Verlag. 23. V. S. Subrahmanian. Uncertainty in logic programming: Some recollections. Association for Logic Programming Newsletter, 20(2), 2007. 24. M. H. van Emden. Quantitative deduction and its fixpoint theory. Journal of Logic Programming, 3(1):37–53, 1986. 25. M. H. van Emden and R. A. Kowalski. The semantics of predicate logic as a programming language. Journal of the Association for Computing Machinery (JACM), 23(4):733–742, 1976.

178

A Generic Scheme for Qualified Logic Programming

A

19

Appendix: Additional Proofs

This appendix contains the proofs of the Soundness Theorem 1 and the Completeness Theorem 2. In order to prove them, we will previously prove an auxiliary lemma for each of the two cases. In the rest of the Appendix, we assume a given program P over a qualification domain D. A.1

Proof of the Soundness Theorem

Lemma 1 (Soundness). Assume two goals G0 and G1 and a pair of substitutions (θ, ρ) such that G0 C1 ,σ1 G1 and (θ, ρ) ∈ QSolP (G1 ) (the set of all solutions of G1 ). Then we have that (θ, ρ) ∈ QSolP (G0 ). Proof. Assume G0 ≡ L, A ] W, R 8 σ0 8 α ◦ W w β, ∆; C1 ≡ (H ← d − B1 , . . . , Bk ) ∈var P a variant of a program clause without variables in common with G0 ; and σ1 the m.g.u. between A and H. Then G1 ≡ (L, B1 ] W1 , . . . , Bk ] Wk R)σ1 8 σ0 σ1 8 ∆1 d where ∆1 ≡ W = d ◦ {W1 , . . . , Wk }, d ◦ α ◦ W1 w β, . . . , d ◦ α ◦ Wk w β, ∆. As (θ, ρ) ∈ QSolP (G1 ) we know (1) σ0 σ1 θ = θ , (2) ρ ∈ Sol(∆1 ) , and (3) P `QHL(D) (L, B1 ] W1 , . . . , Bk ] Wk , R)σ1ˆ(θ, ρ)1 . And for (θ, ρ) to be a solution of G0 we need the following: (4) σ0 θ = θ , (5) ρ ∈ Sol(α ◦ W w β, ∆) , and (6) P `QHL(D) (L, A ] W, R)ˆ(θ, ρ) . Therefore we have to prove (4), (5) and (6). Proof of (4). First, we can see that for every variable y ∈ Var, if y ∈ vran(σ0 ), then y ∈ / dom(σ0 ) because σ0 is idempotent. Hence, y ∈ vran(σ0 ) =⇒ yσ1 θ = yσ0 σ1 θ =(1) yθ, and it is true that (7) σ1 θ = θ [vran(σ0 )]. Now, for any variable x we can prove xσ0 θ = xθ by distinguishing two cases: a) if x ∈ / dom(σ0 ) then xσ0 θ = xθ; and b) if x ∈ dom(σ0 ) then var(xσ0 ) ⊆ vran(σ0 ) =⇒ xσ0 θ =(7) xσ0 σ1 θ =(1) xθ. Proof of d (5). We have to prove d that α ◦ W ρ w β and ρ ∈ Sol(∆). α ◦ W ρ =(2) α ◦ d ◦ {W1 ρ, . . . , Wk ρ} = {α ◦ d ◦ W1 ρ, . . . , α ◦ d ◦ Wk ρ}. It is enough proving α ◦ d ◦ Wi ρ w β for 1 ≤ i ≤ k. But {α ◦ d ◦ Wi w β | 1 ≤ i ≤ k} ⊆ ∆1 and ρ ∈ Sol(∆1 ). ρ ∈ Sol(∆) is trivial because ∆ ⊆ ∆1 . 1

P `QHL(D) (A ] W )ˆ(θ, ρ) ⇐⇒def P `QHL(D) Aθ ] W ρ .

179

20

M. Rodr´ıguez-Artalejo and C.A. Romero-D´ıaz

Proof of (6). We can split (6) in the following three cases: (6a) P `QHL(D) Lˆ(θ, ρ). We prove that Lˆ(θ, ρ) = Lσ1ˆ(θ, ρ) which, because of (3), can be inferred in QHL(D) from P. We know that dom(σ0 ) ∩ var(G0 ) = ∅, therefore, Lσ1ˆ(θ, ρ) = Lσ0 σ1ˆ(θ, ρ) = Lˆ(σd0 σ1 θ, ρ) =(1) Lˆ(θ, ρ). (6b) P `QHL(D) A ] Wˆ(θ, ρ). Using W ρ = d ◦ {W1 ρ, . . . , Wk ρ} which holds because of (2), (3) and one inference step with clause C1 and substitution σ1 θ, we obtain P `QHL(D) Hσ1 θ ] W ρ. Now, because σ1 is the m.g.u. between A and H, we have Hσ1 θ = Aσ1 θ. Therefore, we have P `QHL(D) Aσ1 θ ] W ρ. Finally, we note that Aσ1 θ = Aσ0 σ1 θ =(1) Aθ because dom(σ0 )∩var(A) = ∅. t u (6c) P `QHL(D) Rˆ(θ, ρ). As in (6a). Proof (of Soundness Theorem). Assume G0 nσ0 G where G ≡ σ 8 ∆ is solved. Let (σ, µ) be the solution associated to G. We prove (σ, µ) ∈ QSolP (G0 ) by induction on n. Base. In this case, n = 0 and G0 = G is solved and P `QHL(D) Aˆ(σ, µ) is trivial because the sequence of atoms A of G is empty. Moreover, µ ∈ Sol(∆) because µ = ω∆ . Induction. In this case we have n > 0 and G0 G1 n−1 G. Then we obtain (σ, µ) ∈ QSolP (G1 ) by induction hypothesis, and therefore (σ, µ) ∈ QSolP (G0 ) because of Lemma 1. t u A.2

Proof of the Completeness Theorem

Before going into the proof, just a note on notation: as said, (θ, ρ) ∈ QSolP (G) means that the pair of substitutions (θ, ρ) is a solution of the goal G ≡ A 8 σ 8 ∆. n (G) we are expressing that the exact number of Now, writing (θ, ρ) ∈ QSolP inference steps in P `QHL(D) Aˆ(θ, ρ) is n, written as P `nQHL(D) Aˆ(θ, ρ). Lemma 2 (Completeness). Let G0 ≡ A0 8 σ0 8 ∆0 be a goal not solved, n and (θ0 , ρ0 ) ∈ QSolP (G0 ). Let also V0 be any finite set of variables such that var(G0 ) ∪ dom(θ0 ) ⊆ V0 . For any arbitrary selection of an atom A ] W of A0 , there exists some resolution step G0 σ1 G1 selecting the chosen atom and, in addition, some (θ1 , ρ1 ) satisfying the following properties: a. b. c. d. e. f.

θ1 = θ0 [V0 ] σ1 θ 1 = θ 1 σ0 σ1 θ 1 = θ 1 ρ1 w ρ0 [war(G0 )] ρ1 ∈ Sol(∆1 ) n−1 P `QHL(D) A1ˆ(θ1 , ρ1 )

n−1 In particular, (c), (e) and (f ) mean that (θ1 , ρ1 ) ∈ QSolP (G1 ).

Proof. Assume A ] W to be the selected atom in G0 . Then, G0 ≡ L0 , A ] W, R0 8 σ0 8 α ◦ W w β, ∆. Because of the lemma’s hypothesis we can also assume the following:

180

A Generic Scheme for Qualified Logic Programming

(0) (1) (2) (3)

21

σ0 θ 0 = θ 0 , ρ0 ∈ Sol(∆0 ) , 1 P `m QHL(D) L0ˆ(θ0 , ρ0 ) , m2 P `QHL(D) A ] Wˆ(θ0 , ρ0 ) , and

3 (4) P `m QHL(D) R0ˆ(θ0 , ρ0 )

with m1 + m2 + m3 = n > 0. Because of (3) there must exist some clause C1 ≡ (H ← d − B1 , . . . , Bk ) ∈var P and some substitution η0 such that 2 −1 (5) Aθ0 = Hη0 and P `m B1 η0 ] d1 , . . . , Bk η0 ] dk with d1 , . . . , dk ∈ D\{⊥} QHL(D) d such that W ρ0 v d ◦ {d1 , . . . , dk }.

It is possible to choose C1 and η0 so that var(C1 )∩V0 = ∅ and dom(η0 ) ⊆ var(C1 ). Therefore, it is guaranteed that dom(η0 ) ∩ dom(θ0 ) = ∅ and then:

(6) θ1 =def θ0 ] η0 is a well-founded substitution that satisfies: dom(θ1 ) = dom(θ0 ) ] dom(η0 ); θ1 = θ0 [V0 ]; θ1 = η0 [\V0 ] =⇒ (a) of lemma. From (5) and (6) we know that θ1 is an unifier of A and H. Choosing σ1 as the m.g.u. (in the Robinson’s sense) between A and H we will have: (7) Aσ1 = Hσ1 and σ1 θ1 = θ1 =⇒ (b) of lemma. Then, taking ρ1 such that  if W 0 = Wi for some 1 ≤ i ≤ k  di d (8) W 0 ρ1 =def d ◦ {d1 , . . . , dk } if W 0 = W  0 W ρ0 otherwise

we will have, by (8) and (5), ρ1 w ρ0 [war(G0 )] =⇒ (d) of lemma. Now, doing a resolution step with σ1 and C1 we get G0 σ1 ,C1 G1 ≡ A1 8 σ0 σ1 8 ∆1 where A1 = (L0 , B1 ] Wd1 , . . . , Bk ] Wk , R0 )σ1 and ∆1 ≡ d ◦ α ◦ W1 w β, . . . , d ◦ α ◦ Wk w β, W = d ◦ {W1 , . . . , Wk }, ∆. Note that we can deduce d ◦ α w β from (5), (1) and the axioms required for the attenuation operd ation (◦) in any qualification domain, because we have W ρ = d ◦ {d , . . . , dk } 0 1 d and α ◦ W ρ0 w β =⇒ α ◦ d ◦ {d1 , . . . , dk } w β =⇒ α ◦ d w β. Remember from Definition 3 that the condition α ◦ d w β is required for the resolution step to be enabled. To finish the proof we only need to prove (c), (e) and (f ). Proof of (c). σ0 σ1 θ1 =(b) σ0 θ1 =(6) σ0 (θ0 ] η0 ) =(∗) σ0 θ0 ] η0 =(0) θ0 ] η0 = θ1 . (∗) Because vran(σ0 ) ⊆ V0 and dom(η0 ) ∩ V0 = ∅. Proof of (e). We have to see that ρ1 satisfies every constraint in ∆1 : d 1. W = d ◦ {W1 , . . . , Wk }. This is satisfied by definition of ρ1 .

181

22

M. Rodr´ıguez-Artalejo and C.A. Romero-D´ıaz

2. d ◦ α ◦ Wi w β for 1 ≤ i ≤ k. We know from (1) that α ◦ W ρ0 w β, and from (d) follows W ρ1dw W ρ0 . Therefore, α ◦ W ρ1 w β. Because d of (8) we also know W ρ1 = d ◦ {W1 ρ1 , . . . , Wk ρ1 } that implies α ◦ W ρ1 = {d ◦ α ◦ W1 ρ1 , . . . , d ◦ α ◦ Wk ρ1 } Hence α ◦ W ρ1 w β implies that d ◦ α ◦ Wi ρ1 w β is satisfied for every 1 ≤ i ≤ k. 3. ∆. From (7) follows that ρ1 = ρ0 [war(∆)], and because of (1) ρ0 ∈ Sol(∆) =⇒ ρ1 ∈ Sol(∆). Proof of (f ). First we can deduce: 1 (9) P `m QHL(D) L0ˆ(θ1 , ρ1 ) by (2), (6) and (8).

2 −1 (10) P `m QHL(D) (B1 ] W1 , . . . , Bk ] Wk )ˆ(θ1 , ρ1 ) by (5), (6) and (8). 3 (11) P `m QHL(D) R0ˆ(θ1 , ρ1 ) by (4), (6) and (8).

Considering that m1 + (m2 − 1) + m3 = n − 1, (9), (10) and (11) imply that P `n−1 u QHL(D) (L0 , B1 ] W1 , . . . , Bk ] Wk , R0 )ˆ(θ1 , ρ1 ); and this is (f ) due to (b). t Proof (of Completeness Theorem). As G0 is a goal, we know that σ0 is idempotent and that A0 σ0 = A0 . Now, as (θ0 , ρ0 ) ∈ QSolP (G0 ), we can choose n (G0 ) and therefore we have (1) a number n ∈ IN such that (θ0 , ρ0 ) ∈ QSolP σ0 θ0 = θ0 , (2) ρ0 ∈ Sol(∆0 ) and (3) P `nQHL(D) A0ˆ(θ0 , ρ0 ). We can also choose a finite set of variables V0 satisfying (4) var(G0 ) ∪ dom(θ0 ) ⊆ V0 . Given the conditions (1) to (4), we will prove the following: (†) There exist some resolution computation G0 ∗σ σ0 σ 8 ∆ (that we can build making use of any selection strategy) ending in a solved goal, and some substitution θ satisfying (5) θ = θ0 [V0 ], (6) σθ = θ and (7) σ0 σθ = θ. From (†) follows the theorem’s thesis (except (8) µ w ρ0 [war(G0 )]) because: – (6) =⇒(5) σθ = θ0 [V0 ] =⇒ σ 4 θ0 [var(G0 )] – (7) =⇒(5) σ0 σθ = θ0 [V0 ] =⇒ σ0 σ 4 θ0 [var(G0 )] We simultaneously prove (†) and (8) by induction on n: Base. If n = 0, (2) implies that A0 is empty. Then, taking σ =  and θ = θ0 we have that G0 0 σ0 8 ∆0 with is a trivial resolution of 0 steps; and in addition: – (5) reduces to θ0 = θ0 [V0 ], which is trivial. – (6) reduces to θ0 = θ0 , which also is trivial. – (7) reduces to σ0 θ0 = θ0 which is true given (1). – (8) is satisfied because µ = ρ0 [war(G0 )] is true, given that war(G0 ) = war(∆0 ). Now, as ∆0 is solved, it only contains defining constraints and therefore (2) implies that for any W ∈ war(∆0 ) it is true that W ρ0 = ω∆0 (W ) = W µ.

182

A Generic Scheme for Qualified Logic Programming

23

Induction. If n > 0, (2) implies that A0 is not empty. Hence, selecting an atom A ] W in A0 with any selection strategy and using the Completeness Lemma 2, we can perform a resolution step (9) G0 ≡ A0 8 σ0 8 ∆0 σ1 A1 8 σ0 σ1 8 ∆1 ≡ G1

n−1 having that there exists some solution (θ1 , ρ1 ) ∈ QSolP (G1 ) satisfying all 6 conditions guaranteed by the lemma: (10) θ1 = θ0 [V0 ], (11) σ1 θ1 = θ1 , (1’) σ0 σ1 θ1 = θ1 , (12) ρ1 w ρ0 [war(G0 )], (2’) ρ1 ∈ Sol(∆1 ), and (3’) P `n−1 QHL(D) A1ˆ(θ1 , ρ1 ). Let V1 be any finite set of variables such that

(40 ) V0 ∪ var(G1 ) ∪ dom(θ1 ) ⊆ V1 . Conditions (1’), (2’), (3’) and (4’) are similar, respectively, to (1), (2), (3) n−1 and (4), but now for (θ1 , ρ1 ) ∈ QSolP (G1 ). By induction hypothesis we can obtain a resolution computation (13) G1 ∗σ0 σ0 σ1 σ 0 8 ∆0

and a substitution θ such that (5’) θ = θ1 [V1 ] (6’) σ 0 θ = θ (7’) σ0 σ1 σ 0 θ = θ (8’) µ0 w ρ1 [war(G1 )] with (σ0 σ1 σ 0 , µ0 ) the associated solution to σ0 σ1 σ 0 8 ∆0 . From (9) and (13) results G0 ≡ A0 8 σ0 8 ∆0 σ1 G1 ≡ A1 8 σ0 σ1 8 ∆1 ∗σ0 σ0 σ1 σ 0 8 ∆0 .

Now there is only left to check that (5), (6) and (7) are satisfied given the same θ that satisfies (5’), (6’) and (7’) and σ = σ1 σ 0 ; and that (8) is also satisfied when µ = µ0 . In fact: – (5) trivially follows from (5’), (4’) and (10). – (6) comes from the following: by (4’) we can assume θ = θ1 ] η 0 , with η 0 such that dom(η 0 ) ∩ (V1 ) = ∅. Then: σθ = σ1 σ 0 θ =(60 ) σ1 θ = σ1 (θ1 ] η 0 ) =(∗) σ1 θ1 ] η 0 =(11) θ1 ] η 0 = θ. The step (∗) is correct because vran(σ1 ) ⊆ V1 and dom(η 0 ) ∩ V1 = ∅. – (7) trivially follows from (7’), given that σ = σ1 σ 0 . – (8) is consequence of (8’) and (12), because war(G0 ) ⊆ war(G1 ). t u

183

Similarity-based Reasoning in Qualified Logic Programming Revised Edition Rafael Caballero

Mario Rodr´ıguez-Artalejo

Carlos A. Romero-D´ıaz

Departamento de Sistemas Inform´aticos y Computaci´on Universidad Complutense de Madrid, Spain {rafa,mario}@sip.ucm.es, [email protected]

Abstract

the certainty factor d × b, where b is the minimum of the certainty factors di ∈ (0, 1] previously computed for the various atoms occurring in the body. The papers [17, 18] proposed to use a special lattice T in place of the lattice of the real numbers in the interval [0, 1] under their natural ordering. T includes two isomorphic copies of [0, 1] whose elements are incomparable under T ’s ordering and can be used separately to represent degrees of truth and falsity, respectively, thus enabling a simple treatment of negation. Other main contributions of [17, 18] were the introduction of annotated program clauses and goals (later generalized to a much more expressive framework in [7]), as well as goal solving procedures more convenient and powerful than those given in [20]. A more recent line of research is Similarity-based Logic Programming (briefly, SLP ) as presented in [16] and previous related works such as [3, 6, 5, 15]. This approach also uses the lattice [0, 1] to deal with uncertainty in the spirit of fuzzy logic. In contrast to approaches based on annotated clauses, programs in SLP are just sets of definite Horn clauses as in classical LP . However, a similarity relation R (roughly, the fuzzy analog of an equivalence relation) between predicate and function symbols is used to enable the unification terms that would be not unifiable in the classical sense, measured by some degree λ ∈ (0, 1]. There are different proposals for the operational semantics of SLP programs. One possibility is to apply classical SLD resolution w.r.t. a transformation of the original program [6, 15, 16]. Alternatively, a R-based SLD-resolution procedure relying on R-unification can be applied w.r.t. to the original program, as proposed in [16]. Propositions 7.1 and 7.2 in [16] state a correspondence between the answers computed by R-based SLD resolution w.r.t. a given logic program P and the answers computed by classical SLD resolution w.r.t. the two transformed programs Hλ (P) (built by adding to P new clauses R-similar to those in P up to the degree λ ∈ (0, 1]) and Pλ (built by replacing all the function and predicate symbols in P by new symbols that represent equivalence classes modulo R-similarity up to λ). The SiLog system [8] has been developed to implement SLP and to support applications related to flexible information retrieval from the web. The aim of the present paper is to show that similarity-based reasoning can be expressed in QLP (D), a programming scheme for Qualified LP over a parametrically given Qualification Domain D recently presented in [14] as a generalization and improvement of the classical approach by van Emden [20] to Quantitative LP . Qualification domains are lattices satisfying certain natural axioms. They include the lattice [0, 1] used both in [20] and in [16], as well as other lattices whose elements can be used to qualify logical assertions by measuring their closeness to different kinds of users’ expectations. Programs in QLP (D) use D-attenuated clauses of the form A ← d − B where A is an atom, B a finite conjunction of atoms and d ∈ D \ {⊥} is the attenuation value

Similarity-based Logic Programming (briefly, SLP ) has been proposed to enhance the LP paradigm with a kind of approximate reasoning which supports flexible information retrieval applications. This approach uses a fuzzy similarity relation R between symbols in the program’s signature, while keeping the syntax for program clauses as in classical LP . Another recent proposal is the QLP (D) scheme for Qualified Logic Programming, an extension of the LP paradigm which supports approximate reasoning and more. This approach uses annotated program clauses and a parametrically given domain D whose elements qualify logical assertions by measuring their closeness to various users’ expectations. In this paper we propose a more expressive scheme SQLP (R, D) which subsumes both SLP and QLP (D) as particular cases. We also show that SQLP (R, D) programs can be transformed into semantically equivalent QLP (D) programs. As a consequence, existing QLP (D) implementations can be used to give efficient support for similarity-based reasoning. Categories and Subject Descriptors D.1.6 [Programming Techniques]: Logic Programming; D.3.2 [Programming Languages]: Language Classifications—Constraint and logic languages; F.3.2 [Theory of Computation]: Logics and Meanings of Programs— Algebraic approaches to semantics General Terms Keywords

Algorithms, Languages, Theory

Qualification Domains, Similarity Relations

1. Introduction The historical evolution of the research on uncertainty in Logic Programming (LP ) has been described in a recent recollection by V. S. Subrahmanian [19]. Early approaches include the quantitative treatment of uncertainty in the spirit of fuzzy logic, as in van Emden’s classical paper [20] and two subsequent papers by Subrahmanian [17, 18]. The main contribution of [20] was a rigorous declarative semantics for a LP language with program clauses of the form A ← d − B, where the head A is an atom, the body B is a conjunction of atoms, and the so-called attenuation factor d ∈ (0, 1] attached to the clause’s implication is used to propagate to the head

Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. To copy otherwise, to republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. PPDP’08, July 15–17, 2008, Valencia, Spain. c 2008 ACM 978-1-60558-117-0/08/07. . . $5.00 Copyright

184

In Section 3 we recall the scheme QLP (D) and we introduce its extension SQLP (R, D) with its declarative semantics, given by a logical calculus which characterizes the least Herbrand model MP of each SQLP (R, D) program P. In Section 4 we define the transformation SR (P) of any given SQLP (R, D) program P into a QLP (D) program SR (P) such that MSR (P) = MP , we give some comparisons to previously known program transformations, and we illustrate the application of SR (P) to similarity-based computation by means of a simple example. Finally, in Section 5 we summarize conclusions and comparisons to related work and we point to planned lines of future work.

attached to the clause’s implication, used to propagate to the head the qualification value d ◦ b, where b is the infimum in D of the qualification values di ∈ D \ {⊥} previously computed for the various atoms occurring in the body, and ◦ is an attenuation operator coming with D. As reported in [14, 13], the classical results in LP concerning the existence of least Herbrand models of programs and the soundness and completeness of the SLD resolution procedure (see e.g.[21, 2, 1]) have been extended to the QLP (D) scheme, and potentially useful instances of the scheme have been implemented on top of the Constraint Functional Logic Programming (CF LP ) system T OY [4]. The results presented in this paper can be summarized as follows: we consider generalized similarity relations over a set S as mappings R : S × S → D taking values in the carrier set D of an arbitrarily given qualification domain D, and we extend QLP (D) to a more expressive scheme SQLP (R, D) with two parameters for programming modulo R-similarity with D-attenuated Horn clauses. We present a declarative semantics for SQLP (R, D) and a program transformation mapping each SQLP (R, D) program P into a QLP (D) program SR (P) whose least Herbrand model corresponds to that of P. Roughly, SR (P) is built adding to P new clauses obtained from the original clauses in P by computing various new heads R-similar to a linearized version of the original head, adding also R-similarity conditions Xi ∼ Xj to the body and suitable clauses for the new predicate ∼ to emulate R-based unification. Thanks to the SR (P) transformation, the sound and complete procedure for solving goals in QLP (D) by D-qualified SLD resolution and its implementation in the T OY system [14] can be used to implement SQLP (R, D) computations, including as a particular case SLP computations in the sense of [16]. Another recent proposal for reducing the SLP approach in [16] to a fuzzy LP paradigm can be found in [11], a paper which relies on the multi-adjoint framework for Logic Programming (MALP for short) previously proposed in [9, 10]. MALP is a quite general framework supporting LP with weighted program rules over different multi-adjoint lattices, each of which provides a particular choice of operators for implication, conjunction and aggregation of atoms in rule bodies. In comparison to the QLP (D) scheme, the multi-adjoint framework differs in motivation and scope. Multi-adjoint lattices and qualification domains are two different classes of algebraic structures. Concerning declarative and operational semantics, there are also some significant differences between QLP (D) and MALP. In particular, MALP ’s goal solving procedure relies on a costly computation of reductant clauses, a technique borrowed from [7] which can be avoided in QLP (D), as discussed in the concluding section of [14]. In spite of these differences, the results in [11] concerning the emulation of similarity-based can be compared to those in the present paper. Theorem 24 in [11] shows that every classical logic program P can be transformed into a MALP program PE,R which can be executed using only syntactical unification and emulates the successful computations of P using the SLD resolution with Rbased unification introduced in [16]. PE,R works over a particular multi-adjoint lattice G with carrier set [0, 1] and implication and conjunction operators chosen according to the so-called G¨odel’s semantics [22]. PE,R also introduces clauses for a binary predicate ∼ which emulates R-based unification, as in our transformation SR (P). Nevertheless, SR (P) is defined for a more general class of programs and uses the R-similarity predicate ∼ only if the source program P has some clause whose head is non-linear. More detailed comparisons between the program transformations SR (P), Hλ (P), Pλ and PE,R will be given in Subsection 4.2. The rest of the paper is structured as follows: In Section 2 we recall the qualification domains D first introduced in [14] and we define similarity relations R over an arbitrary qualification domain.

2.

Qualification Domains and Similarity Relations

2.1

Qualification Domains

Qualification Domains were introduced in [14] with the aim of using their elements to qualify logical assertions in different ways. In this subsection we recall their axiomatic definition and some significant examples. Definition 1. A Qualification Domain is any structure D = hD, v, ⊥, >, ◦i verifying the following requirements:

1. hD, v, ⊥, >i is a lattice with extreme points ⊥ and > w.r.t. the partial ordering v. For given elements d, e ∈ D, we write d u e for the greatest lower bound (glb) of d and e and d t e for the least upper bound (lub) of d and e. We also write d @ e as abbreviation for d v e ∧ d 6= e. 2. ◦ : D × D → D, called attenuation operation, verifies the following axioms: (a) ◦ is associative, commutative and monotonic w.r.t. v. (b) ∀d ∈ D : d ◦ > = d. (c) ∀d ∈ D : d ◦ ⊥ = ⊥. (d) ∀d, e ∈ D \ {⊥, >} : d ◦ e @ e. (e) ∀d, e1 , e2 ∈ D : d ◦ (e1 u e2 ) = d ◦ e1 u d ◦ e2 .

In the rest of the paper, D will generally denote an arbitrary qualification domain. For any d finite S = {e1 , e2 , . . . , en } ⊆ D, the glb of S (noted as S) exists and can be computed as e1 u e2 u · · · u en (which reduces to > in the case n = d 0). As an d easy consequence of the axioms, one gets the identity d ◦ S = {d◦e | e ∈ S}. The QLP (D) scheme presented in [14] supports LP over a parametrically given qualification domain D. Example 1. Some examples of qualification domains are presented below. Their intended use for qualifying logical assertions will become more clear in Subsection 3.1.

1. B = ({0, 1}, ≤, 0, 1, ∧), where 0 and 1 stand for the two classical truth values false and true, ≤ is the usual numerical ordering over {0, 1}, and ∧ stands for the classical conjunction operation over {0, 1}. Attaching 1 to an atomic formula A is intended to qualify A as ‘true’ in the sense of classical LP . 2. U = (U, ≤, 0, 1, ×), where U = [0, 1] = {d ∈ R | 0 ≤ d ≤ 1}, ≤ is the usual numerical ordering, and × is the multiplication operation. In this d domain, the top element > is 1 and the greatest lower bound S of a finite S ⊆ U is the minimum value min(S), which is 1 if S = ∅. Attaching an element c ∈ U \ {0} to an atomic formula A is intended to qualify A as ‘true with certainty degree c’ in the spirit of fuzzy logic, as done in the classical paper [20] by van Emden. The computation of qualifications c as certainty degrees in U is due to the interpretation of u as min and ◦ as ×. 3. W = (P, ≥, ∞, 0, +), where P = [0, ∞] = {d ∈ R ∪ {∞} | d ≥ 0}, ≥ is the reverse of the usual numerical ordering (with ∞ ≥ d for any d ∈ P), and + is the addition operation (with

185

∞ + d = d + ∞ = ∞ for any d ∈ P). In this d domain, the top element > is 0 and the greatest lower bound S of a finite S ⊆ P is the maximum value max(S), which is 0 if S = ∅. Attaching an element d ∈ P \ {∞} to an atomic formula A is intended to qualify A as ‘true with weighted proof depth d’. The computation of qualifications d as weighted proof depths in W is due to the interpretation of u as max and ◦ as +. 4. Given 2 qualification domains Di = hDi , vi , ⊥i , >i , ◦i i (i ∈ {1, 2}), their cartesian product D1 × D2 is D =def hD, v , ⊥, >, ◦i, where D =def D1 × D2 , the partial ordering v is defined as (d1 , d2 ) v (e1 , e2 ) ⇐⇒def d1 v1 e1 and d2 v2 e2 , ⊥ =def (⊥1 , ⊥2 ), > =def (>1 , >2 ), and the attenuation operator ◦ is defined as (d1 , d2 ) ◦ (e1 , e2 ) =def (d1 ◦1 e1 , d2 ◦2 e2 ). The product of two given qualification domains is always another qualification domain, as proved in [14]. Intuitively, each value (d1 , d2 ) belonging to D1 × D2 imposes the qualification d1 and also the qualification d2 . For instance, values (c, d) belonging to U × W impose two qualifications, namely: a certainty degree greater or equal than c and a weighted proof depth less or equal than d.

the same arity; or else x, y ∈ P S are predicate symbols with the same arity. The similarity degrees computed by a D-valued similarity relation must be interpreted w.r.t. the intended role of D-elements as qualification values. For example, let R be an admissible similarity relation, and let c, d ∈ CS be two nullary constructor symbols (i.e., constants). If R is U-valued, then R(c, d) can be interpreted as a certainty degree for the assertion that c and d are similar. On the other hand, if R is W-valued, then R(c, d) can be interpreted as a cost to be paid for c to play the role of d. These two views are coherent with the different interpretations of the operators u and ◦ in U and W, respectively. In the rest of the paper we assume that any admissible similarity relation R can be extended to act over terms, atoms and clauses. The extension, also called R, can be recursively defined as in [16]. The following definition specifies the extension of R acting over terms. The case of atoms and clauses is analogous. Definition 3. (R acting over terms). 1. For X ∈ Var and for any term t different from X: R(X, X) = > and R(X, t) = R(t, X) = ⊥. 2. For c, c0 ∈ CS with different arities n, m: R(c(t1 , . . . , tn ), c0 (t01 , . . . , t0m )) = ⊥. 3. For c, c0 ∈ CS with the same arity n: R(c(t1 , . . . , tn ), c0 (t01 , . . . , t0n )) = R(c, c0 )uR(t1 , t01 )u. . .u R(tn , t0n ).

For technical reasons that will become apparent in Section 4, we consider the two structures U 0 resp. W 0 defined analogously to U resp. W, except that ◦ behaves as min in U 0 and as max in W 0 . Note that almost all the axioms for qualification domains enumerated in Definition 1 hold in U 0 and W 0 , except that axiom 2.(d) holds only in the relaxed form ∀d, e ∈ D : d ◦ e v e. Therefore, we will refer to U 0 and W 0 as quasi qualification domains. 2.2

3.

Similarity-based Qualified Logic Programming

In this section we extend our previous scheme QLP (D) to a more expressive scheme called Similarity-based Qualified Logic Programming over (R, D) –abbreviated as SQLP (R, D)– which supports both qualification over D in the sense of [14] and R-based similarity in the sense of [16] and related research. Subsection 3.1 presents a quick review of the main results concerning syntax and declarative semantics of QLP (D) already presented in [14], while the extensions needed to conform the new SQLP (R, D) scheme are presented in subsection 3.2.

Similarity relations

Similarity relations over a given set S have been defined in [16] and related literature as mappings R : S × S → [0, 1] that satisfy three axioms analogous to those required for classical equivalence relations. Each value R(x, y) computed by a similarity relation R is called the similarity degree between x and y. In this paper we use a natural extension of the definition given in [16], allowing elements of an arbitrary qualification domain D to serve as similarity degrees. As in [16], we are especially interested in similarity relations over sets S whose elements are variables and symbols of a given signature.

3.1

Qualified Logic Programming

QLP (D) was proposed in our previous work [14] as a generic scheme for qualified logic programming over a given qualification domain D. In that scheme, a signature Σ providing constructor and predicate symbols with given arities is assumed. Terms are built from constructors and variables from a countably infinite set Var (disjoint from Σ) and Atoms are of the form p(t1 , . . . , tn ) (shortened as p(tn ) or simply p(t)) where p is a n-ary predicate symbol and ti are terms. We write AtΣ , called the open Herbrand base, for the set of all atoms. A QLP (D) program P is a finite set of D-qualified definite Horn clauses of the form A ← d− B where A is an atom, B a finite conjunction of atoms and d ∈ D \ {⊥} is the attenuation value attached to the clause’s implication. As explained in [14], in our aim to work with qualifications we are not only interested in just proving an atom, but in proving it along with a qualification value. For this reason, D-qualified atoms (A ] d where A is an atom and d ∈ D \ {⊥}) are introduced to represent the statement that the atom A holds for at least the qualification value d. For use in goals to be solved, open D-annotated atoms (A ] W where A is an atom and W a qualification variable intended to take values over D) are also introduced, and a countably infinite set War of qualification variables (disjoint from Var and Σ) is postulated. The annotated Herbrand base over D is defined as the set AtΣ (D) of all D-qualified atoms. A D-entailment relation over AtΣ (D), defined as A ] d
Definition 2. Let a qualification domain D with carrier set D and a set S be given. 1. A D-valued similarity relation over S is any mapping R : S × S → D such that the three following axioms hold for all x, y, z ∈ S: (a) Reflexivity: R(x, x) = >. (b) Symmetry: R(x, y) = R(y, x). (c) Transitivity: R(x, z) w R(x, y) u R(y, z). 2. The mapping R : S × S → D defined as R(x, x) = > for all x ∈ D and R(x, y) = ⊥ for all x, y ∈ D, x 6= y is trivially a D-valued similarity relation called the identity. 3. A D-valued similarity relation R over S is called admissible iff S = Var ∪ CS ∪ P S (where the three mutually disjoint sets Var, CS and P S stand for a countably infinite collection of variables, a set of constructor symbols and a set of predicate symbols, respectively) and the two following requirements are satisfied: (a) R restricted to Var behaves as the identity, i.e. R(X, X) = > for all X ∈ Var and R(X, Y ) = ⊥ for all X, Y ∈ Var, X 6= Y . (b) R(x, y) 6= ⊥ holds only if some of the following three cases holds x, y: either x, y ∈ Var are both the same variable; or else x, y ∈ CS are constructor symbols with

186

mally define an open Herbrand interpretation over D –from now on just an interpretation– as any subset I ⊆ AtΣ (D) which is closed under D-entailment. We write IntΣ (D) for the family of all interpretations. The notion of model is such that given any clause C ≡ A ← d−B1 , . . . , Bk in the QLP (D) program P, an interpretation I is said to be a model of C iff for any substitution θ and any qualification values d1 , . . . , dk ∈ D \ {⊥} d such that Bi θ ] di ∈ I for all 1 ≤ i ≤ k, one has Aθ ] (d ◦ {d1 , . . . , dk }) ∈ I. The interpretation I is also said to be a model of the QLP (D) program P (written as I |= P) iff it happen to be a model of every clause in P. As technique to infer formulas (or in our case D-qualified atoms) from a given QLP (D) program P, and following traditional ideas, we consider two alternative ways of formalizing an inference step which goes from the body of a clause to its head: both an interpretation transformer TP : IntΣ (D) → IntΣ (D), and a qualified variant of Horn Logic, noted as QHL(D), called Qualified Horn Logic over D. As both methods are equivalent and correctly characterize the least Herbrand model of a given program P, we will only be recalling the logic QHL(D), although we encourage the reader to see Section 3.2 in [14], where the fix-point semantics is explained. The logic QHL(D) is defined as a deductive system consisting just of one inference rule: QMP(D), called Qualified Modus Ponens over D. Such rule allows us to give the following inference step given that there were some (A ← d− B1 , . . . , Bk ) ∈ P, some substitution θ such that A0 = Aθ and Bi0 = d Bi θ for all 1 ≤ i ≤ k and some d0 ∈ D \ {⊥} such that d0 v d ◦ {d1 , . . . , dk }: B10 ] d1

· · · Bk0 ] dk A0 ] d0

wild(lynx) <-0.9wild(boar) <-0.9wild(snake) <-1.0-

4 5

farm(cow) <-1.0farm(pig) <-1.0-

6 7

domestic(cat) <-0.8domestic(snake) <-0.4-

8 9

intelligent(A) <-0.9- domestic(A) intelligent(lynx) <-0.7-

10 11

pacific(A) <-0.9- domestic(A) pacific(A) <-0.7- farm(A)

12

pet(A) <-1.0- pacific(A), intelligent(A) R(farm,domestic) = 0.3 R(pig,boar) = 0.7 R(lynx,cat) = 0.8 Figure 1. SQLP (R, U) program.

relation R given in the same figure and the qualification domain U for certainty values. This program will be used just for illustrative purposes in the rest of the paper. The reader is referred to Section 2 for other examples of qualification domains, and to the references [8, 11] for suggestions concerning practical applications of similarity-based LP . D-qualified atoms (A ] d with A an atom and d ∈ D \ {⊥}) and open D-annotated atoms (A ] W with A and atom and W ∈ W ar a qualification variable intended to take values in D \{⊥}) will still be used here. Similarly, the annotated open Herbrand base over D is again defined as the set AtΣ (D) of all D-qualified atoms. At this point, and before extending the notions of D-entailment relation and interpretation to the SQLP (R, D) scheme, we need to define what an R-instance of an atom is. Intuitively, when building Rinstances of an atom A, signature symbols occurring in A can be replaced by similar ones, and different occurrences of the same variable in A may be replaced by different terms, whose degree of similarity must be taken into account. Technically, R-instances of an atom A ∈ AtΣ are built from a linearized version of A which has the form lin(A) = (A` , S` ) and is constructed as follows: A` is a linear atom built from A by replacing each n additional occurrences of a variable X by new fresh variables Xi (1 ≤ i ≤ n); and S` is a set of similarity conditions X ∼ Xi (with 1 ≤ i ≤ n) asserting the similarity of all variables in A` that correspond to the same variable X in A. As a concrete illustration, let us show the linearization of two atoms. Note what happens when the atom A is already linear as in the first case: A` is just the same as A and S` is empty.

QMP(D)

Roughly, each QMP(D) inference step using an instance of a program clause A ← d−B has the effect of propagating to the head the qualification value d ◦ b, where b is the infimum in D of the qualification values di ∈ D \ {⊥} previously computed for the various atoms occurring in the body. This helps to understand the claims made in Example 1 above about the intended use of elements of the domains U and W for qualifying logical assertions. We use the notations P `QHL(D) A ] d (resp. P `n QHL(D) A ] d) to indicate that A ] d can be inferred from the clauses in program P in finitely many steps (resp. n steps). The least Herbrand model of P happens to be MP = {A ] d | P `QHL(D) A ] d}, as proved in [14]. 3.2

1 2 3

Similarity-based Qualified Logic Programming

The scheme SQLP (R, D) presented in this subsection has two parameters R and D, where D can be any qualification domain and R can be any admissible D-valued similarity relation, in the sense of Definition 2. The new scheme subsumes the approach in [14] by behaving as QLP (D) in the case that R is chosen as the identity, and it also subsumes similarity-based LP by behaving as the approach in [16] and related papers in the case that D is chosen as U. Syntactically, SQLP (R, D) presents almost no changes w.r.t. QLP (D), but the declarative semantics must be extended to account for the behavior of the parametrically given similarity relation R. As in the previous subsection, we assume a signature Σ providing again constructor and predicate symbols. Terms and Atoms are built the same way they were in QLP (D), and AtΣ will stand again for the set of all atoms, called the open Herbrand base. An atom A is called linear if there is no variable with multiple occurrences in A; otherwise A is called non-linear. A SQLP (R, D) program P is a finite set of D-qualified definite Horn clauses with the same syntax as in QLP (D), along with a D-valued admissible similarity relation R in the sense of Definition 2, item 2. Figure 1 shows a simple SQLP (R, U) program built from the similarity

• H1 = p(c(X), Y )

lin(H1 ) = (p(c(X), Y ), {})

• H2 = p(c(X), X, Y )

lin(H2 ) = (p(c(X), X1 , Y ), {X ∼ X1 })

Now we are set to formally define the R-instances of an atom.

Definition 4. (R-instance of an atom). Assume an atom A ∈ AtΣ and its linearized version lin(A) = (A` , S` ). Then, an atom A0 is

187

0 0 0 such that B di ] di ∈ I for all 1 ≤ i ≤ k, one has H ] d ∈ I where d0 = d ◦ {e, d1 , . . . , dk }. And we say that I is a model of the SQLP (R, D) program P (also written I |= P) iff I is a model of each clause in P. We will provide now a way to perform an inference step from the body of a clause to its head. As in the case of QLP (D), this can be formalized in two alternative ways, namely an interpretation transformer and a variant of Horn Logic. Both approaches lead to equivalent characterizations of least program models. Here we focus on the second approach, defining what we will call Similarity-based Qualified Horn Logic over (R, D) – abbreviated as SQHL(R, D)–, another variant of Horn Logic and an extension of the previous QHL(D). The logic SQHL(R, D) is also defined as a deductive system consisting just of one inference rule SQM P (R, D), called Similarity-based Qualified Modus Ponens over (R, D): If ((A0 ← d − B10 , . . . , Bk0 ), δ) ∈ [C]R for some clause C ∈ P with attenuation value d, then the followingdinference step is allowed for any d0 ∈ D \{⊥} such that d0 v d◦ {δ, d1 , . . . , dk }:

said to be an R-instance of A with similarity degree δ, noted as (A0 , δ) ∈ [A]R , iff there are some atom AS anddsome substitution θ such that A0 = AS θ and δ = R(A` , AS ) u {R(Xi θ, Xj θ) | (Xi ∼ Xj ) ∈ S` } 6= ⊥.

Next, the (R, D)-entailment relation over AtΣ (D) is defined as follows: A ] d <(R,D) A0 ] d0 iff there is some similarity degree δ such that (A0 , δ) ∈ [A]R and d0 v d ◦ δ. Finally, an open Herbrand interpretation –just interpretation from now on– over (R, D) is defined as any subset I ∈ AtΣ (D) which is closed under (R, D)-entailment. That is, an interpretation I including a given D-qualified atom A ] d is required to include all the ‘similar instances’ A0 ] d0 such that A ] d <(R,D) A0 ] d0 , because we intend to formalize a semantics in which all such similar instances are valid whenever A ] d is valid. This complements the intuition given for the D-entailment relation in QLP (D) to include the similar instances (obtainable due to R) of each atom, and not only those which are true because we can prove them for a better (i.e. higher in D) qualification. Note that (R, D)-entailment is a refinement of Dentailment, since: A ] d ) ∈ [A]R and d0 v d◦> =⇒ A ] d <(R,D) A0 ] d0 . As an example of the closure of interpretations w.r.t. (R, D)entailment, consider the U-qualified atom domestic(cat)#0.8. As a trivial consequence of Proposition 2 below, this atom belongs to the least Herbrand model of the program in Figure 1. On the other hand, we also know that lynx is similar to cat with a similarity degree of 0.8 w.r.t. the similarity relation R in Figure 1. Therefore, domestic(lynx) is a R-instance of domestic(cat) to the degree 0.8. Then, by definition of (R, U)-entailment, it turns out that domestic(cat)#0.8 <(R,U ) domestic(lynx)#0.64, and the U-qualified atom domestic(lynx)#0.64 does also belong to the least model of the example program. Intuitively, 0.64 = 0.8 × 0.8 is the best U-qualification which can be inferred from the U-qualification 0.8 for domestic(cat) and the R-similarity 0.8 between domestic(cat) and domestic(lynx). We will write IntΣ (R, D) for the family of all interpretations over (R, D), a family for which the following proposition can be easily proved from the definition of an interpretation and the definitions of the union and intersection of a family of sets.

B10 ] d1

Proposition 2. Given any SQLP (R, D) program P. The least Herbrand model (MP ) of P is {A ] d | P `SQHL(R,D) A ] d} .

The following example serves as an illustration of how the logic SQHL(R, D) works over (R, U) using the example program displayed in Figure 1. Example 2. The following proof tree proves that the atom pet(lynx) can be inferred for at least a qualification value of 0.50 in the SQLP (R, U) program P of Figure 1. Let’s see it: (4)

Similarly as we did for the R-instances of an atom, we will define what the R-instances of a clause are. The following definition tells us so.

Note that as an immediate consequence from Definitions 4 and 5 it is true that given two clauses C and C 0 such that (C 0 , δ) ∈ [C]R , and assuming A to be head atom of C and A0 to be the head atom of C 0 , then we have that (A0 , δ) ∈ [A]R . Let C be any clause A ← d−B1 , . . . , Bk in the program P, and I ∈ IntΣ (R, D) any interpretation over (R, D). We say that I is a model of C iff for any clause C 0 ≡ H 0 ← d−B10 , . . . , Bk0 such that (C 0 , δ) ∈ [C]R and any qualification values d1 , . . . , dk ∈ D \{⊥}

SQMP(R, D) .

We will use the notations P `SQHL(R,D) A ] d (respectively P `n SQHL(R,D) A ] d) to indicate that A ] d can be inferred from the clauses in program P in finitely many steps (respectively n steps). Note that SQHL(R, D) proofs can be naturally represented as upwards growing proof trees with D-qualified atoms at their nodes, each node corresponding to one inference step having the children nodes as premises. The following proposition contains the main result concerning the declarative semantics of the SQLP (R, D) scheme. A full proof can be developed in analogy to the QLP (D) case presented in [14, 13].

Proposition 1. The family IntΣ (R, D) of all interpretations over (R, D) is a complete lattice under the inclusion ordering ⊆, whose extreme points are IntΣ (R, D) as maximum and ∅ as minimum. Moreover, given anydfamily S of interpretations I ⊆ IntΣ (R, D), its and glb are I = {I ∈ IntΣ (R, D) | I ∈ I} and F lub T I = {I ∈ IntΣ (R, D) | I ∈ I}, respectively. Definition 5. (R-instance of a clause). Assume a clause C ≡ A ← d − B1 , . . . , Bk and the linearized version of its head atom lin(A) = (A` , S` ). Then, a clause C 0 is said to be an Rinstance of C with similarity degree δ, noted as (C 0 , δ) ∈ [C]R , S iff there are some atom d A and some substitution θ such that δ = R(A` , AS ) u {R(Xi θ, Xj θ) | (Xi ∼ Xj ) ∈ S` } 6= ⊥ and C 0 ≡ AS θ ← d− B1 θ, . . . , Bk θ.

· · · Bk0 ] dk A0 ] d0

domestic(lynx)#0.64 (2) (3) pacific(lynx)#0.57 intelligent(lynx)#0.70 (1) pet(lynx)#0.50

where the clauses and qualification values used for each inference step are: (1) pet(lynx) <-1.0- pacific(lynx),intelligent(lynx) is an instance of clause 12 in P and 0.50 ≤ 1.0 × min{1.0, 0.57, 0.70}. Note that the first 1.0 in the minimum is the one which comes from the similarity relation as for this step we are just using a plain instance of clause 12 in P. (2) pacific(lynx) <-0.9- domestic(lynx) is a plain instance of clause 10 in P and 0.57 ≤ 0.9 × min{1.0, 0.64}. (3) intelligent(lynx) <-0.7- is clause 9 in P and 0.70 ≤ 0.70 × min{1.0}. (4) The clause domestic(lynx) <-0.8- is an R-instance of clause 6 with a similarity degree of 0.8 and we have 0.64 ≤ 0.8 × min{0.8}.

188

4.

Reducing Similarities to Qualifications

4.1

A Program Transformation

the inference step at the root of T uses some clause (c(X n ) ∼ 0 c0 (X n ) ← >− payR(c,c0 ) , X1 ∼ X10 , . . . , Xn ∼ Xn0 ) ∈ P∼ , and must be of the form: payw ] v (t1 ∼ s1 ) ] e1 . . . (tn ∼ sn ) ] en c(tn ) ∼ c0 (sn ) ] d

In this section we prove that any SQLP (R, D) program P can be transformed into an equivalent QLP (D) program which will be denoted by SR (P). The program transformation is defined as follows:

where w = R(c, c0 ), v ∈ D, v v dw, t = c(tn ), s = c0 (snd ), and e1 , . . . , en s.t. d v > ◦ {v, e1 , . . . , ek }, i.e., d v {v, e1 , . . . , ek }. By induction hypothesis ei v R(ti , si ) d for i = 1 . . . n. Then d v {v, e1 , . . . , en } implies d v d {w, R(t1 , s1 ), . . . , R(tn , sn )} and hence d v R(t, s) (Def. 3, item 3). 2. If R(t, s) = d, d 6= ⊥, we prove that SR (P) `QHL(D) (t ∼ s) ] d by induction on the syntactic structure of t. The basis corresponds to the case t = c for some constant c, or t = Y for some variable Y . If t = c then s = c0 for some other constant c0 . By Definition 6 there is a clause in P∼ of the form (c ∼ c0 ← >− payd ). Using this clause and the identity substitution we can write the root inference step of a proof for SR (P) `QHL(D) (c ∼ c0 ) ] d as follows:

Definition 6. Let P be a SQLP (R, D) program. We define the transformed program SR (P) as: SR (P) = PS ∪ P∼ ∪ Ppay

where the auxiliary sets of clauses PS , P∼ , Ppay are defined as:

• For each clause (H ← d− B) ∈ P and for each H 0 such that

R(H` , H 0 ) 6= ⊥

(H 0 ← d− payR(H` ,H 0 ) , S` , B) ∈ PS

where (H` , S` ) = lin(H). • P∼ = {X ∼ X ← >−} ∪ {(c(X n ) ∼ c0 (Y n ) ← > − payR(c,c0 ) , X1 ∼ Y1 , . . . , Xn ∼ Yn ) | c, c0 ∈ CS of arity n, R(c, c0 ) 6= ⊥} • Ppay = {(payw ← w−) | for each atom payw occurring in P∼ ∪ P S }

payd ] d c ∼ c0 ] d

The condition required by rule QMP(D) is in this d the inferenced particular case d v > ◦ {d}, and > ◦ {d} = d. Proving the only premise payd ] d in QHL(D) is direct from its definition. If t = Y , with Y a variable, then s = Y and d = > (otherwise R(t, s) = ⊥). Then SR (P) `QHL(D) (Y ∼ Y ) ] > can be proved by using the clause (X ∼ X ←>−) ∈ P∼ with substitution θ = {X 7→ Y }. In the inductive step, t must be of the form c(tn ), with n ≥ 1, and then s must be of the form c0 (sn ) (otherwise R(t, s) = ⊥). From d = R(t, s) 6= ⊥ (hypotheses of the lemma) and Definition 3 we have that R(c, c0 ) 6= ⊥. Then, by Definition 6, there is a clause in P∼ of the form:

Note that the linearization of clause heads in this transformation is motivated by the role of linearized atoms in the SQHL(R, D) logic defined in Subsection 3.2 to specify the declarative semantics of SQLP (R, D) programs. For instance, assume a SQLP (R, U) program P including the clause p(X, X) ← 1.0− and two nullary constructors c, d such that R(c, d) = 0.8. Then, SQHL(R, U) supports the derivation P `SQHL(R,U ) p(c, d) ] 0.8, and the transformed program SR (P) will include the clauses p(X, X1 ) X∼X c∼d pay1.0 pay0.8

← 1.0− pay1.0 , X ∼ X1 , ← 1.0−, ← 1.0− pay0.8 , ← 1.0−, ← 0.8−

c(X n ) ∼ c0 (Y n ) ← >− payR(c,c0 ) , X1 ∼ Y1 , . . . , Xn ∼ Yn

By using the substitution θ = {X1 7→ t1 , . . . , Xn 7→ tn , Y1 7→ s1 , . . . , Yn 7→ sn } we can write the root inference step in QHL(D) as:

thus enabling the corresponding derivation SR (P) `QHL(U ) p(c, d) ] 0.8 in QHL(U). In general, P and SR (P) are semantically equivalent in the sense that P `SQHL(R,D) A ] d ⇐⇒ SR (P) `QHL(D) A ] d holds for any D-qualified atom A ] d, as stated in Theorem 1 below. The next technical lemma will be useful for the proof of this theorem.

payR(c,c0 ) ] R(c, c0 ) (ti ∼ si ] R(ti , si ))i=1...n c(tn ) ∼ c0 (sn ) ] d

The inference can be applied because the condition l d v > ◦ {R(c, c0 ), R(t1 , s1 ), . . . , R(tn , sn )}

Lemma 1. Let P be a SQLP (R, D) program and SR (P) its transformed program according to Definition 6. Let t, s be two terms in P’s signature and d ∈ D \ {⊥}. Then:

reduces to

dv

1. SR (P) `QHL(D) (t ∼ s) ] d =⇒ d v R(t, s) 2. R(t, s) = d =⇒ SR (P) `QHL(D) (t ∼ s) ] d

l {R(c, c0 ), R(t1 , s1 ), . . . , R(tn , sn )}

which holds by Definition 3, item 3. Moreover, the premises ti ∼ si ] R(ti , si ), i = 1 . . . n, hold in QHL(D) due to the inductive hypotheses, and proving

Proof. We prove the two items separately.

payR(c,c0 ) ] R(c, c0 )

1. Let T be a QHL(D) proof tree witnessing

is straightforward from its definition.

SR (P) `QHL(D) (t ∼ s) ] d

We prove by induction on number of nodes of T that d v R(t, s). The basis case, with T consisting of just one node, must correspond to some inference without premises, i.e., a clause with empty body for ∼. Checking P∼ we observe that X ∼ X ← >− is the only possibility. In this case t and s must be the same term and by the reflexivity of R (Def. 2), R(t, s) = >, which means d v R(t, s) for every d. In the inductive step, we consider T with more than one node. Then

Now we can prove the equivalence between semantic inferences in QHL(D) w.r.t. P and semantic inferences in SQHL(R, D) w.r.t. SR (P). Theorem 1. Let P be a SQLP (R, D) program, A an atom in P’s signature and d ∈ D \ {⊥}. Then: P `SQHL(R,D) A ] d ⇐⇒ SR (P) `QHL(D) A ] d .

189

Proof. Let T be a SQHL(R, D) proof tree for some annotated atom A ] d in P’s signature witnessing P `SQHL(R,D) A ] d. We prove that SR (P) `QHL(D) A ] d by induction on the number of nodes of T . The inference step at the root of T must be of the form B10 ] d1

· · · Bk0 ] dk A]d

(2) we have QHL(D) proofs of ui θ ∼ vi θ ] ei for i = 1 . . . m. Therefore ei v e0i , by Lemma 1, item 1. Then d d v e ◦ d{w, e1 . . . , em , d1 , . . . , dk } (by(2)) v e ◦ d{w, e01 . . . , e0m , d1 , . . . , dk } (ei v e0i ) = e ◦ {δ, d1 , . . . , dk }

We must still prove that δ 6= ⊥. Observe that by the distributivity of ◦ w.r.t. u (Def. 1, axiom 2.(e)): l l e ◦ {δ, d1 , . . . , dk } = (e ◦ δ) u (e ◦ {d1 , . . . , dk }) .

(1)

B10 , . . . , Bk0 ), δ)

with ((A ← e − ∈ [C]R for some clause C ≡ (H ← e − B1 , . . . , Bk ) ∈ P (observe that the case k = 0 corresponds to the induction basis). By Definition 5, A = H 0 θ, Bi0 = Bi θ for d some substitution θ and atom H 0 such that δ = R(H` , H 0 ) u {R(Xi θ, Xj θ) | (Xi ∼ Xj ) ∈ S` } 6= ⊥, with lin(H) = (H` , S` ). This means in particular that w = R(H` , H 0 ) 6= ⊥, which by Definition 6 implies that there is a clause C 0 in SR (P) of the form C 0 ≡ (H 0 ← e − payw , S` , B1 , . . . Bk ). Then the root inference step of the deduction proving P `QHL(D) A ] d will use the inference rule QMP(D) with C 0 and substitution θ (such that H 0 θ = A) as follows: payw θ ] w ((ui ∼ vi )θ ] ei )1≤i≤m B10 ] d1 · · · Bk0 ] dk (2) A]d

Therefore

d v (e ◦ δ) u (e ◦

l {d1 , . . . , dk })

and from d 6= ⊥ we obtain (e ◦ δ) 6= ⊥ which implies δ 6= ⊥ due to axiom 2.(c) in Definition 1. This completes the proof. 4.2

where S` = {u1 ∼ v1 , . . . , um ∼ vm }, and ei = R(ui θ, vi θ) for i = 1 . . . m. Next we check that the premises can be proved from SR (P) in QHL(D): • payw θ = payw , since payw is a nullary predicate for every w.

Therefore SR (P) `QHL(D) payw ] w is immediate from the definition of payw in Definition 6.

• For each 1 ≤ i ≤ m, we observe that R(ui θ, vi θ) 6= ⊥

because δ 6= ⊥ has been computed above as the infimum of a set including R(ui θ, vi θ) among its members. Then SR (P) `QHL(D) (ui ∼ vi )θ holds by Lemma 1, item 2. • For each 1 ≤ i ≤ k, (1) shows that P `SQHL(R,D) Bi0 ] di with a proof tree having less nodes that T . Therefore, SR (P) `QHL(D) Bi0 ] di by induction hypothesis.

In order to perform the inference d step (2), the QMP(D) inference rule also requires that d v e ◦ {w, e1 . . . , em , d1 , . . . , dk }. This follows from the associativity of u since: d • As defined above, δ = R(H` , H 0 ) u {R(Xi θ, Xj θ) | d (Xi ∼ Xj ) ∈ S` }, i.e. δ = w u {e1 . . . em }. • By the SQMP(R, D) inference (1) we know that d v e ◦ d {δ, d1 , . . . , dk }.

Comparison to Related Approaches

Other program transformations have been proposed in the literature with the aim of supporting R-based reasoning while avoiding explicit R-based unification. Here we draw some comparisons between the program transformation SR (P) presented in the previous subsection, the program transformations Hλ (P) and Pλ proposed in [16], and the program transformation PE,R proposed in [11]. These three transformations are applied to a classical logic program P w.r.t. a fuzzy similarity relation R over symbols in the program’s signature. Both Hλ (P) and Pλ are classical logic programs to be executed by SLD resolution, and their construction depends on a fixed similarity degree λ ∈ (0, 1]. On the other hand, PE,R is a multi-adjoint logic program over a particular multi-adjoint lattice G, providing the uncertain truth values in the interval [0, 1] and two operators for conjunction and disjunction in the sense of G¨odel’s fuzzy logic (see [22] for technical details). As in the case of our own transformation SR (P), the construction of PE,R does not depend on any fixed similarity degree. The transformation SR (P) proposed in this paper is more general in that it can be applied to an arbitrary SQLP (R, D) program P, yielding a QLP (D) program SR (P) whose least Herbrand model is the same as that of P. We will restrict our comparisons to the case that P is chosen as a similarity-based logic program in the sense of [16]. As an illustrative example, consider the simple logic program P consisting of the following four clauses: • Cr : r(X, Y ) ← p(X), q(Y ), s(X, Y )

• Cp : p(c(U )) ←

• Cq : q(d(V )) ← • Cs : s(Z, Z) ←

Let T be a QHL(D) proof tree witnessing SR (P) `QHL(D) A ] d for some atom A in P’s signature. We prove by induction on the number of nodes of T that P `SQHL(R,D) A ] d. Since A is in P’s signature, the clause employed at the inference step at the root of T must be in the set PS of Definition 6, and the inference step at the root of T have of the form of the inference (2) above. Hence this clause must have been constructed from a clause C ≡ (H ← e − B1 , . . . , Bk ) ∈ P and some atom H 0 such that A = H 0 θ and R(H` , H 0 ) 6= ⊥, where lin(H) = (H` , S` ). Then we can use C and θ to prove P `SQHL(R,D) A ] d by a SQMP(R, D) inference like (1) using the R-instance C 0 ≡ A ← e−B10 , . . . , Bk0 of C. The premises can be proved in SQHL(R, D) by induction hypotheses, since all of them are also premises in (2). Finally, we must check that the conditions required by (1) hold: (C 0 , δ) ∈ [C]R for some δ ∈ D,dδ 6= ⊥ s.t. d v e ◦ d {δ, d1 , . . . , dk }. This is true for δ = {w, e01 , . . . , e0n }, with e0i = R(ui θ, vi θ) for i = 1 . . . m. Observe that in the premises of

Assume an admissible similarity relation defined by R(c, d) = 0.9 and consider the goal G : ← r(X, Y ) for P. Then, R-based SLD-resolution as defined in [16] computes the answer substitution σ = {X 7→ c(U ), Y 7→ d(U )} with similarity degree 0.9. This computation succeeds because R-based unification can compute the m.g.u. {Z 7→ c(U ), V 7→ U } with similarity degree 0.9 to unify the two atoms s(c(U ), d(V )) and s(Z, Z). Let us now examine the behavior of the the transformed programs H0.9 (P), P0.9 , SR (P) and PE,R and when working to emulate this computation without explicit use of a R-based unification procedure. 1. H0.9 (P) is defined in [16] as the set of all clauses C 0 such that R(C, C 0 ) ≥ 0.9 for some clause C ∈ P. In this case H0.9 (P) includes the four clauses of P and the two additional clauses p(d(U )) ← and q(c(V )) ←, derived by similarity from Cp and Cq , respectively. Solving G w.r.t. H0.9 (P) by means of

190

tween terms. In our example, PE,R will include (among others) the following clause for ∼:

classical SLD resolution produces two possible answer substitutions, namely σ1 = {X 7→ c(U ), Y 7→ c(U )} and σ2 = {X 7→ d(U ), Y 7→ d(U )}. They are both similar to σ to a degree greater or equal than 0.9, but none of them is σ itself, contrary to the claim in Proposition 7.1 (i) from [16]. Therefore, this Proposition seems to hold only in a somewhat weaker sense than the statement in [16]. This problem is due to the possible non-linearity of a clause’s head, which is properly taken into account by our transformation SR (P).

• S 0 : c(X1 ) ∼ d(Y1 ) ← 0.9− X1 ∼ Y1

In comparison to the clause S in SR (P), clause S 0 needs no call to a pay0.9 predicate at its body, because the similarity degree 0.9 = R(c, d) can be attached directly to the clause’s implication. This difference corresponds to the different interpretations of ◦, which behaves as × in U and as min in U 0 . Moreover, PE,R is defined to include a clause of the following form for each pair of n-ary predicate symbols pd and pd0 such that R(pd, pd0 ) 6= 0:

2. According to [16], P0.9 is computed from P by replacing all the constructor and predicate symbols by new symbols that represent the equivalence classes of the original ones modulo R-similarity to a degree greater or equal than 0.9. In our example these classes are {r}, {p}, {q}, {s} and {c, d}, that can be represented by the symbols r, p, q, s an e, respectively. Then, P0.9 replaces the two clauses Cp and Cq by p(e(U )) ← and q(e(V )) ←, respectively, leaving the other two clauses unchanged. Solving G w.r.t. P0.9 by means of classical SLD resolution produces the answer substitution σ 0 = {X 7→ e(U ), Y 7→ e(U )}, which corresponds to σ modulo the replacement of the symbols in the original program by their equivalence classes. This is consistent with the claims in Proposition 7.2 from [16].

• Cpd,pd0 : pd(Y1 , . . . , Yn ) ← R(pd, pd0 )−

pd0 (X1 , . . . , Xn ), X1 ∼ Y1 , . . . , Xn ∼ Yn

In our simple example, all the clauses of this form correspond to the trivial case where pd and pd0 are the same predicate symbol and R(pd, pd0 ) = 1.0. Solving goal G w.r.t.SR (P) by means of the procedural semantics described in Section 4 of [11] can compute the answer substitution σ to the similarity degree 0.9. More generally, Theorem 24 in [11] claims that for any choice of P, PE,R can emulate any successful computation performed by P using R-based SLD resolution.

3. Note that P can be trivially converted into a semantically equivalent a SQLP (R, U) program, just by replacing each occurrence of the implication sign ← in P’s clauses by ← 1.0−. Then SR (P) can be built as a QLP (U) program by the method explained in Subsection 4.1. It includes three clauses corresponding to Cr , Cp and Cq of P plus the following three new clauses:

In conclusion, the main difference between SR (P) and PE,R pertains to the techniques used by both program transformations in order to emulate the effect of replacing the head of a clause in the original program by a similar one. PE,R always relies on the clauses of the form Cpd,pd0 and the clauses for ∼, while SR (P) can avoid to use the clauses for ∼ as long as all the clauses involved in the computation have linear heads. In comparison to the two transformations Hλ (P) and Pλ , our transformation SR (P) does not depend on a fixed similarity degree λ and does not replace the atoms in clause bodies by similar ones.

• Cp0 : p(d(U )) ← 1.0− pay0.9 • Cq0 : q(c(V )) ← 1.0− pay0.9

• Cs0 : s(Z1 , Z2 ) ← 1.0− Z1 ∼ Z2

where Cp0 resp. Cq0 come from replacing the linear heads of Cp resp. Cq by similar heads, and Cs comes from linearizing the head of Cs , which allows no replacements by similarity. SR (P) includes also the proper clauses for P∼ and Ppay , in particular the following three ones:

4.3

A Goal Solving Example

In order to illustrate the use of the transformed program SR (P) for golving goals w.r.t. the original program P, we consider the case where P is the SQLP (R, U) program displayed in Figure 1. The transformed program SR (P) obtained by applying Definition 6 is shown in Figure 2. The following observations are useful to understand how the transformation has worked in this simple case:

• I : X ∼ X ← 1.0−

• S : c(X1 ) ∼ d(Y1 ) ← 1.0− pay0.9 , X1 ∼ Y1 • P : pay0.9 ← 0.9−

Solving goal G w.r.t. SR (P) by means of the U-qualified SLD resolution procedure described in [14] can compute the answer substitution σ with qualification degree 0.9. More precisely, the initial goal can be stated as r(X, Y )#W 8 W ≥ 0.9, and the computed answer is (σ, {W 7→ 0.9}). The computation emulates R-based unification of s(c(U ), c(V )) and s(Z, Z) to the similarity degree 0.9 by solving s(c(U ), c(V )) with the clauses Cs0 , I, S and P .

• The value > in the domain U corresponds to the real number

1 and hence by reflexivity R(A, A) = 1 for any atom in the signature of the program. Therefore, and as a consequence of Definition 6, every clause in the original program gives rise to a clause in the transformed program with the same head and with the same body except for a new, first atom pay1.0 . For instance, clauses 1, 2 and 3 in Figure 2 correspond to the same clause numbers in Figure 1.

4. The semantics of the MALP framework depending on the chosen multi-adjoint lattice is presented in [11]. A comparison with the semantics of the QLP (D) scheme (see [14] and Subsection 3.1 above) shows that MALP programs over the multiadjoint lattice G behave as QLP (U 0 ) programs, where U 0 is the quasi qualification domain analogous to U introduced at the end of Subsection 2.1 above. For this reason, we can think of the transformed program PE,R as presented with he syntax of a QLP (U 0 ) program. The original program P can also be written as a QLP (U 0 ) program just by replacing each the implication sign ← occurring in P by ← 1.0−. As explained in [11], PE,R is built by extending P with clauses for a new binary predicate ∼ intended to emulate the behaviour of R-based unification be-

• Apart of the clauses corresponding directly to the original

clauses, the program of Figure 2 contains new clauses obtained by similarity with some clause heads in the original program. For instance, lines 4 and 5 are obtained by similarity with clauses at lines 1 and 2 in the original program, respectively. The subindexes at literal pay correspond to R(lynx, cat) = 0.8, R(boar, pig) = 0.7, respectively.

• Analogously, for instance the clause at line 10 (with head

farm(lynx)) is obtained by head-similarity with the clause of line 6 in the SQLP (R, U) program (head domestic(cat)),

191

from a given SQLP (R, D) program P to its transformed program SR (P), because it was developed mainly for [14]. Therefore, the transformed program shown in Figure 2 has been computed manually. We will start running T OY and loading the QLP (U) instance with the command /qlp(u):

1 2 3 4 5

wild(lynx) <-0.9- pay1.0 wild(boar) <-0.9- pay1.0 wild(snake) <-1.0- pay1.0 wild(cat) <-0.9- pay0.8 wild(pig) <-0.9- pay0.7

6 7 8 9 10 11

farm(cow) <-1.0- pay1.0 farm(pig) <-1.0- pay1.0 farm(boar) <-1.0- pay0.7 farm(cat) <-0.8- pay0.3 farm(lynx) <-0.8- pay0.3 farm(snake) <-0.4- pay0.3

12 13 14 15 16 17

domestic(cat) <-0.8- pay1.0 domestic(snake) <-0.4- pay1.0 domestic(lynx) <-0.8- pay0.8 domestic(cow) <-1.0- pay0.3 domestic(pig) <-1.0- pay0.3 domestic(boar) <-1.0- pay0.3

18 19 20

intelligent(A) <-0.9- pay1.0 ,domestic(A) intelligent(lynx) <-0.7- pay1.0 intelligent(cat) <-0.7- pay0.8

21 22

pacific(A) <-0.9- pay1.0 ,domestic(A) pacific(A) <-0.7- pay1.0 ,farm(A)

And finally we are set to launch our goal with the command /qlpgoal. The solutions found for this program and goal are:

23

pet(A) <-1.0- pay1.0 ,pacific(A),intelligent(A)

24 25 26 27

pay1.0 pay0.8 pay0.7 pay0.3

QLP(U)> /qlpgoal(pet(A)#W | W>=0.50) { A -> cat, W -> 0.5599999999999999 }

Toy> /qlp(u) this will have the effect of loading the Real Domain Constraints library and the QLP (U) library into the system, the prompt QLP(U)> will appear. Now we have to compile our example program (assume we have it in a text file called animals.qlp in C:/examples/) with the command /qlptotoy (this command will behave differently based on the actual instance loaded). QLP(U)> /qlptotoy(c:/examples/animals) Note that we didn’t write the extension of the file because it must be .qlp. This will create the file animals.toy in the same directory as our former file. And this one will be an actual T OY program. We run the program with /run(c:/examples/animals) (again without the extension –although this time we are assuming .toy as extension–) and we should get the following message: PROCESS COMPLETE

<-1.0<-0.8<-0.7<-0.3-

sol.1, more solutions (y/n/d/a) [y]? { A -> cat, W -> 0.7200000000000001 } sol.2, more solutions (y/n/d/a) [y]? { A -> lynx, W -> 0.5760000000000002 }

Figure 2. Example of transformed program. (Note: no clauses for ∼ are needed because the original program was left-linear).

sol.3, more solutions (y/n/d/a) [y]? { A -> lynx, W -> 0.5760000000000002 }

and the subindex at pay is obtained from R(domestic(cat), farm(lynx)) R(domestic, farm) u R(cat, lynx) 0.3 u 0.8 0.3

= = =

sol.4, more solutions (y/n/d/a) [y]? no

• There is no clause for predicate ∼ since all the heads in the

At this point and if you remember the inference we did in Example 2 for pet(lynx)#0.50, we have found a better solution (as you can see there are two solutions for lynx, and this is due to the two different ways of proving intelligent(lynx): intelligent(lynx)#0.7 using clause 19, and intelligent (lynx)#0.576 using clauses 18 and 14.

original program were already linear and therefore P∼ can be left empty in practice.

• The clauses for pay correspond to the fragment Ppay in Defini-

tion 6.

In the rest of this subsection, we will show an execution for the goal pet(A)#W | W >= 0.50 over the program SR (P) (see Figure 2) with the aim of obtaining all those animals that could be considered a pet for at least a qualification value of 0.50. We are trying this execution in the prototype developed along with [14] for the instances QLP (U) and QLP (W). Although this prototype hasn’t been released as an integrated part of T OY, you can download1 the prototype to try this execution. Please notice that the prototype does not automatically do the translation process

5.

Conclusions

Similarity-based LP has been proposed in [16] and related works to enhance the LP paradigm with a kind of approximate reasoning which supports flexible information retrieval applications, as argued in [8, 11]. This approach keeps the syntax for program clauses as in classical LP , and supports uncertain reasoning by using a fuzzy similarity relation R between symbols in the program’s signature. We have shown that similarity-based LP as presented in [16] can be reduced to Qualified LP in the QLP (D) scheme introduced in [14], which supports logic programming with attenuated program clauses over a parametrically given domain D whose

1 Available

at: http://gpd.sip.ucm.es/cromdia/qlpd. There you will also find specific instructions on how to install and run it as well as text files with the program examples tried in here.

192

elements qualify logical assertions by measuring their closeness to various users’ expectations. Using generalized similarity relations taking values in the carrier set of an arbitrarily given qualification domain D, we have extended QLP (D) to a more expressive scheme SQLP (R, D) with two parameters, for programming modulo R-similarity with D-attenuated Horn clauses. We have presented a declarative semantics for SQLP (R, D) programs and a semantics-preserving program transformation which embeds SQLP (R, D) into QLP (D). As a consequence, the sound and complete procedure for solving goals in QLP (D) by D-qualified SLD resolution and its implementation in the T OY system [14] can be used to implement SQLP (R, D) computations via the transformation. Our framework is quite general due to the availability of different qualification domains, while the similarity relations proposed in [16] take fuzzy values in the interval [0, 1]. In comparison to the multi-adjoint framework proposed in [11], the QLP (D) and SQLP (R, D) schemes have a different motivation and scope, due to the differences between multi-adjoint algebras and qualification domains as algebraic structures. In contrast to the goal solving procedure used in the multi-adjoint framework, D-qualified SLD resolution does not rely on costly computations of reductant clauses and has been efficiently implemented. As future work, we plan to investigate an extension of the R-based SLD resolution procedure proposed in [16] to be used within the SQLP (R, D) scheme, and to develop an extension of this scheme which supports lazy functional programming and constraint programming facilities. The idea of similarity-based unification has been already applied in [12] to obtain an extension of needed narrowing, the main goal solving procedure of functional logic languages. As in the case of [16], the similarity relations considered in [12] take fuzzy values in the real interval [0, 1].

[6] G. Gerla and M.I. Sessa. Similarity in logic programming. In G. Chen, M. Ying and K. Cai, editors, Fuzzy Logic and Soft Computing, pages 19-31. Kluwer Academic Publishers, 1999. [7] M. Kifer and V.S. Subrahmanian. Theory of generalized annotated logic programs and their applications. Journal of Logic Programming, 12(3&4):335-367, 1992. [8] V. Loia, S. Senatore and M.I. Sessa. Similarity-based SLD resolution and its role for web knowledge discovery. Fuzzy Sets and Systems, 144(1):151-171, 2004. [9] J. Medina, M. Ojeda-Aciego and P. Vojt´asˇ. Multi-adjoint logic programming with continuous semantics. In T. Eiter, W. Faber and M. Truszczyinski, editors, Logic Programming and Non-Monotonic Reasoning (LPNMR’01), volume 2173 of LNAI, pages 351-364. Springer-Verlag, 2001. [10] J. Medina, M. Ojeda-Aciego and P. Vojt´asˇ. A procedural semantics for multi-adjoint logic programming. In P. Brazdil and A. Jorge, editors, Progress in Artificial Intelligence (EPIA’01), volume 2258 of LNAI, pages 290-297. Springer-Verlag, 2001. [11] J. Medina, M. Ojeda-Aciego and P. Vojt´asˇ. Similarity-based unification: A multi-adjoint approach. Fuzzy Sets and Systems, 146:43-62, 2004. [12] G. Moreno and V. Pascual. Programming with fuzzy logic and mathematical functions. In A.P.I. Bloch and A. Tettamanzi, editors, Proceedings of the 6th International Workshop on Fuzzy Logic and Applications (WILF’05), volume 3849 of LNAI, pages 89-98. Springer-Verlag, 2006. [13] M. Rodr´ıguez-Artalejo and C.A. Romero-D´ıaz. A generic scheme for qualified logic programming (Technical Report SIC-1-08). Technical Report, Universidad Complutense, Departamento de Sistemas Inform´aticos y Computaci´on, Madrid, Spain, 2008. [14] M. Rodr´ıguez-Artalejo and C.A. Romero-D´ıaz. Quantitative logic programming revisited. In J. Garrigue and M. Hermenegildo, editors, Functional and Logic Programming (FLOPS’08), volume 4989 of LNCS, pages 272-288. Springer-Verlag, 2008.

Acknowledgments

[15] M.I. Sessa. Translations and similarity-based logic programming. Soft Computing, 5(2), 2001.

The authors have been partially supported by the Spanish National Projects MERIT-FORMS (TIN2005-09027-C03-03) and PROMESAS–CAM (S-0505/TIC/0407).

[16] M.I. Sessa. Approximate reasoning by similarity-based SLD resolution. Theoretical Computer Science, 275(1&2):389-426, 2002. [17] V.S. Subrahmanian. On the semantics of quantitative logic programs. In Proceedings of the 4th IEEE Symposium on Logic Programming, pages 173-182, San Francisco, 1987.

References [1] K.R. Apt. Logic programming. In J. van Leeuwen, editor, Handbook of Theoretical Computer Science, volume B: Formal Models and Semantics, pages 493-574. Elsevier and The MIT Press, 1990.

[18] V.S. Subrahmanian. Query processing in quantitative logic programming. In Proceedings of the 9th International Conference on Automated Deduction, volume 310 of LNCS, pages 81-100, London, UK, 1988. Springer-Verlag.

[2] K.R. Apt and M.H. van Emden. Contributions to the theory of logic programming. Journal of the Association for Computing Machinery (JACM), 29(3):841-862, 1982.

[19] V.S. Subrahmanian. Uncertainty in logic programming: Some recollections. Association for Logic Programming Newsletter, 20(2), 2007.

[3] F. Arcelli and F. Formato. Likelog: A logic programming language for flexible data retrieval. In Proceedings of the 1999 ACM Symposium on Applied Computing (SAC’99), pages 260-267, New York, NY, USA, 1999. ACM Press.

[20] M.H. van Emden. Quantitative deduction and its fixpoint theory. Journal of Logic Programming, 3(1):37-53, 1986.

[4] P. Arenas, A.J. Fern´andez, A. Gil, F.J. L´opez-Fraguas, M. Rodr´ıguezArtalejo and F. S´aenz-P´erez. T OY, a multiparadigm declarative language. Version 2.3.1, 2007. R. Caballero and J. S´anchez (Eds.), available at http://toy.sourceforge.net.

[21] M.H. van Emden and R.A. Kowalski. The semantics of predicate logic as a programming language. Journal of the Association for Computing Machinery (JACM), 23(4):733-742, 1976. [22] P. Vojt´asˇ. Fuzzy logic programming. Fuzzy Sets and Systems, 124:361:370, 2001.

[5] F. Formato, G. Gerla and M.I. Sessa. Similarity-based unification. Fundamenta Informaticae, 41(4):393-414, 2000.

193

A Generic Scheme for Qualified Constraint Functional Logic Programming? Technical Report SIC-1-09 Rafael Caballero, Mario Rodr´ıguez-Artalejo and Carlos A. Romero-D´ıaz Departamento de Sistemas Inform´ aticos y Computaci´ on, Universidad Complutense, Facultad de Inform´ atica, 28040 Madrid, Spain {rafa,mario}@sip.ucm.es and [email protected]

Abstract. Qualification has been recently introduced as a generalization of uncertainty in the field of Logic Programming. In this report we investigate a more expressive language for First-Order Functional Logic Programming with Constraints and Qualification. We present a Rewriting Logic which characterizes the intended semantics of programs, and a prototype implementation based on a semantically correct program transformation. Potential applications of the resulting language include flexible information retrieval. As a concrete illustration, we show how to write program rules to compute qualified answers for user queries concerning the books available in a given library. Keywords: Constraints, Functional Logic Programming, Program Transformation, Qualification, Rewriting Logic.

1

Introduction

Various extensions of Logic Programming with uncertain reasoning capabilities have been widely investigated during the last 25 years. The recent recollection [21] reviews the evolution of the subject from the viewpoint of a committed researcher. All the proposals in the field replace classical two-valued logic by some kind of many-valued logic with more than two truth values, which are attached to computed answers and interpreted as truth degrees. In a recent work [19,18] we have presented a Qualified Logic Programming scheme QLP(D) parameterized by a qualification domain D, a lattice of so-called qualification values that are attached to computed answers and interpreted as a measure of the satisfaction of certain user expectations. QLP(D)-programs are α sets of clauses of the form A ← − B, where the head A is an atom, the body B is a conjunction of atoms, and α ∈ D is called attenuation factor. Intuitively, α measures the maximum confidence placed on an inference performed by the clause. More precisely, any successful application of the clause attaches to the ?

Research partially supported by projects MERIT–FORMS (TIN2005-09027-C0303), PROMESAS–CAM(S-0505/TIC/0407) and STAMP (TIN2008-06622-C03-01).

194

2

R. Caballero, M. Rodr´ıguez-Artalejo and C.A. Romero-D´ıaz

head a qualification value which cannot exceed the infimum of α ◦ βi ∈ D, where βi are the qualification values computed for the body atoms and ◦ is a so-called attenuation operator, provided by D.

Uncertain Logic Programming can be expressed by particular instances of QLP(D), where the user expectation is understood as a lower bound for the truth degree of the computed answer and D is chosen to formalize a lattice of non-classical truth values. Other choices of D can be designed to model other kinds of user expectations, as e.g. an upper bound for the size of the logical proof underlying the computed answer. As shown in [4], the QLP(D) scheme is also well suited to deal with Uncertain Logic Programming based on similarity relations in the line of [20]. Therefore, Qualified Logic Programming has a potential for flexible information retrieval applications, where the answers computed for user queries may match the user expectations only to some degree. As shown in [19], several useful instances of QLP(D) can be conveniently implemented by using constraint solving techniques. In this report we investigate an extension of QLP(D) to a more expressive scheme, supporting computation with first-order lazy functions and constraints. More precisely, we consider the first-order fragment of CFLP(C), a generic scheme for functional logic programming with constraints over a parametrically given domain C presented in [13]. We propose an extended scheme QCFLP(D, C) where the additional parameter D stands for a qualification domain. QCFLP(D, C)-programs are sets of conditional rewrite rules of the form α → r ⇐ ∆, where the condition ∆ is a conjunction of C-constraints that f (tn ) − may involve user defined functions, and α ∈ D is an attenuation factor. As in the logic programming case, α measures the maximum confidence placed on an inference performed by the rule: any successful application of the rule attaches to the computed result a qualification value which cannot exceed the infimum of α ◦ βi ∈ D, where βi are the qualification values computed for r and ∆, and ◦ is D’s attenuation operator. QLP(D) program clauses can be easily formulated as a particular case of QCFLP(D, C) program rules.

As far as we know, no related work covers the expressivity of our approach. Guadarrama et al. [8] have proposed to use real arithmetic constraints as an implementation tool for a Fuzzy Prolog, but their language does not support constraint programming as such. Starting from the field of natural language processing, Riezler [15,16] has developed quantitative and probabilistic extensions of the classical CLP(C) scheme with the aim of computing good parse trees for constraint logic grammars, but his work bears no relation to functional programming. Moreno and Pascual [14] have investigated similarity-based unification in the context of needed narrowing [1], a narrowing strategy using so-called definitional trees that underlies the operational semantics of functional logic languages such as Curry [9] and T OY [3], but they use neither constraints nor attenuation factors and they provide no declarative semantics. The approach of the present report is quite different. We work with a class of programs more general and expressive than the inductively sequential term rewrite systems used in [14], and our results focus on a rewriting logic used to characterize declarative semantics

195

A Generic Scheme for QCFLP

3

and to prove the correctness of an implementation technique based on a program transformation. Similarity relations could be easily incorporated to our scheme by using the techniques presented in [4] for the Logic Programming case. Moreover, the good properties of needed narrowing as a computation model are not spoiled by our implementation technique, because our program transformation preserves the structure of the definitional trees derived from the user-given program rules. %% Data types: type pages, id = int type title, author, language, genre = [char] data vocabularyLevel = easy | medium | difficult data readerLevel = basic | intermediate | upper | proficiency data book = book(id, title, author, language, genre, vocabularyLevel, pages) %% Simple library, represented as list of books: library :: [book] library --> [ book(1, "Tintin", "Herge", "French", "Comic", easy, 65), book(2, "Dune", "F. P. Herbert", "English", "SciFi", medium, 345), book(3, "Kritik der reinen Vernunft", "Immanuel Kant", "German", "Philosophy", difficult, 1011), book(4, "Beim Hauten der Zwiebel", "Gunter Grass", "German", "Biography", medium, 432) ] %% Auxiliary function for computing list membership: member(B,[]) --> false member(B,H:_T) --> true <== B == H member(B,H:T) --> member(B,T) <== B /= H %% Functions for getting the explicit attributes of a given book: getId(book(Id,_Title,_Author,_Lang,_Genre,_VocLvl,_Pages)) --> Id getTitle(book(_Id,Title,_Author,_Lang,_Genre,_VocLvl,_Pages)) --> Title getAuthor(book(_Id,_Title,Author,_Lang,_Genre,_VocLvl,_Pages)) --> Author getLanguage(book(_Id,_Title,_Author,Lang,_Genre,_VocLvl,_Pages)) --> Lang getGenre(book(_Id,_Title,_Author,_Lang,Genre,_VocLvl,_Pages)) --> Genre getVocabularyLevel(book(_Id,_Title,_Author,_Lang,_Genre,VocLvl,_Pages)) --> VocLvl getPages(book(_Id,_Title,_Author,_Lang,_Genre,_VocLvl,Pages)) --> Pages %% Function for guessing the genre of a given book: guessGenre(B) --> getGenre(B) guessGenre(B) -0.9-> "Fantasy" <== guessGenre(B) == "SciFi" guessGenre(B) -0.8-> "Essay" <== guessGenre(B) == "Philosophy" guessGenre(B) -0.7-> "Essay" <== guessGenre(B) == "Biography" guessGenre(B) -0.7-> "Adventure" <== guessGenre(B) == "Fantasy" %% Function for guessing the reader level of a given book: guessReaderLevel(B) --> basic <== getVocabularyLevel(B) == easy, getPages(B) < 50 guessReaderLevel(B) -0.8-> intermediate <== getVocabularyLevel(B) == easy, getPages(B) >= 50 guessReaderLevel(B) -0.9-> basic <== guessGenre(B) == "Children" guessReaderLevel(B) -0.9-> proficiency <== getVocabularyLevel(B) == difficult, getPages(B) >= 200 guessReaderLevel(B) -0.8-> upper <== getVocabularyLevel(B) == difficult, getPages(B) < 200 guessReaderLevel(B) -0.8-> intermediate <== getVocabularyLevel(B) == medium guessReaderLevel(B) -0.7-> upper <== getVocabularyLevel(B) == medium %% Function for answering a particular kind of user queries: search(Language,Genre,Level) --> getId(B) <== member(B,library), getLanguage(B) == Language, guessReaderLevel(B) == Level, guessGenre(B) == Genre

Fig. 1. Library with books in different languages

196

4

R. Caballero, M. Rodr´ıguez-Artalejo and C.A. Romero-D´ıaz

Figure 1 shows a small set of QCFLP(U, R) program rules, called the library program in the rest of the report. The concrete syntax is inspired by the functional logic language T OY, but the ideas and results of this report could be also applied to Curry and other similar languages. In this example, U stands for a particular qualification domain which supports uncertain truth values in the real interval [0, 1], while R stands for a particular constraint domain which supports arithmetic constraints over the real numbers; see Section 2 for more details. The program rules are intended to encode expert knowledge for computing qualified answers to user queries concerning the books available in a simplified library, represented as a list of objects of type book. The various get functions extract the explicit values of book attributes. Functions guessGenre and guessReaderLevel infer information by performing qualified inferences, relying on analogies between different genres and heuristic rules to estimate reader levels on the basis of other features of a given book, respectively. Some program rules, as e.g. those of the auxiliary function member, have attached no explicit attenuation factor. By convention, this is understood as the implicit attachment of the attenuation factor 1.0, the top value of U. For any instance of the QCFLP(D, C) scheme, a similar convention allows to view CFLP(C)-program rules as QCFLP(D, C)-program rules whose attached qualification is optimal. The last rule for function search encodes a method for computing qualified answers to a particular kind of user queries. Therefore, the queries can be formulated as goals to be solved by the program fragment. For instance, answering the query of a user who wants to find a book of genre "Essay", language "German" and user level intermediate with a certainty degree of at least 0.65 can be formulated as the goal: (search("German","Essay",intermediate) == R) # W | W >= 0.65 The techniques presented in Section 4 can be used to translate the QCFLP(U, R) program rules and goal into the CFLP(R) language, which is implemented in the T OY system. Solving the translated goal in T OY computes the answer {R 7→ 4}{0.65 ≤ W, W ≤ 0.7}, ensuring that the library book with id 4 satisfies the query’s requirements with any certainty degree in the interval [0.65,0.7], in particular 0.7. The computation uses the 4th program rule of guessGenre to obtain "Essay" as the book’s genre with qualification 0.7, and the 6th program rule of guessReaderLevel to obtain intermediate as the reader level with qualification 0.8. The rest of the report is organized as follows. In Section 2 we recall known proposals concerning qualification and constraint domains, and we introduce a technical notion needed to relate both kinds of domains for the purposes of this report. In Section 3 we present the generic scheme QCFLP(D, C) announced in this introduction, and we formalize a special Rewriting Logic which characterizes the declarative semantics of QCFLP(D, C)-programs. In Section 4 we present a semantically correct program transformation converting QCFLP(D, C) programs and goals into the qualification-free CFLP(C) programming scheme, which is supported by existing systems such as T OY. Section 5 concludes and points to some lines of planned future work.

197

A Generic Scheme for QCFLP

2

5

Qualification and Constraint Domains

Qualification Domains were introduced in [19]. Their intended use has been already explained in the Introduction. In this section we recall and slightly improve their axiomatic definition. Definition 1 (Qualification Domains). A Qualification Domain is any structure D = hD, P, b, t, ◦i verifying the following requirements: 1. D, noted as DD when convenient, is a set of elements called qualification values. 2. hD, P, b, ti is a lattice with extreme points b and t w.r.t. the partial ordering P. For given elements d, e ∈ D, we write d u e for the greatest lower bound (glb) of d and e, and d t e for the least upper bound (lub) of d and e. We also write d C e as abbreviation for d P e ∧ d 6= e. 3. ◦ : D × D −→ D, called attenuation operation, verifies the following axioms: (a) ◦ is associative, commutative and monotonic w.r.t. P. (b) ∀d ∈ D : d ◦ t = d. (c) ∀d, e ∈ D \ {b, t} : d ◦ e C e. (d) ∀d, e1 , e2 ∈ D : d ◦ (e1 u e2 ) = d ◦ e1 u d ◦ e2 . t u

As an easy consequence of the previous definition one can prove the following proposition. 1 Proposition 1 (Additional properties of qualification domains). Any qualification domain D satisfies the following properties: 1. ∀d, e ∈ D : d ◦ e P e. 2. ∀d ∈ D : d ◦ b = b.

Proof. Since t is the top element of the lattice, we know d P t for any d ∈ D. As ◦ is monotonic w.r.t. P, d ◦ e P t ◦ e also holds for any e ∈ D which, due to commutativity and axiom (b) of ◦, yields d ◦ e P e. Therefore 1 . holds. Now, taking e = b, one has d ◦ b P b which implies d ◦ b = b as b is the bottom element of the lattice. Hence 2 . also holds. t u

The examples in this report will use a particular qualification domain U whose values represent certainty degrees in the sense of fuzzy logic. Formally, U = hU, ≤, 0, 1, ×i, where U = [0, 1] = {d ∈ R | 0 ≤ d ≤ 1}, ≤ is the usual numerical ordering, and × is the multiplication operation. In this domain, the bottom and top elements are b = 0 and t = 1, and the infimum of a finite S ⊆ U is the minimum value min(S), understood as 1 if S = ∅. The class of qualification domains is closed under cartesian products. For a proof of this fact and other examples of qualification domains, the reader is referred to [19,18]. Constraint domains are used in Constraint Logic Programming and its extensions as a tool to provide data values, primitive operations and constraints 1

The authors are thankful to G. Gerla for pointing out this fact.

198

6

R. Caballero, M. Rodr´ıguez-Artalejo and C.A. Romero-D´ıaz

tailored to domain-oriented applications. Various formalizations of this notion are known. In this report, constraint domains of the S are related to signatures S form ΣS = hDC, P F, DF i where DC = n∈N DC n , P F = n∈N P F n and DF = n∈N DF n are mutually disjoint sets of data constructor symbols, primitive function symbols and defined function symbols, respectively, ranked by arities. Given a signature Σ, a symbol ⊥ to note the undefined value, a set B of basic values u and a countably infinite set Var of variables X, we define the notions listed below, where on abbreviates the n-tuple of syntactic objects o1 , . . . , on . – Expressions e ∈ Exp⊥ (Σ, B, Var) have the syntax e ::= ⊥|X|u|h(en ), where h ∈ DC n ∪ P F n ∪ DF n . In the case n = 0, h(en ) is written simply as h. – Constructor Terms t ∈ Term⊥ (Σ, B, Var) have the syntax e ::= ⊥|X|u|c(tn ), where c ∈ DC n . They will be called just terms in the sequel. – Total Expressions e ∈ Exp(Σ, B, Var) and Total Terms t ∈ Term(Σ, B, Var) have a similar syntax, with the ⊥ case omitted. – An expression or term (total or not) is called ground iff it includes no occurrences of variables. Exp⊥ (Σ, B) stands for the set of all ground expressions. The notations Term⊥ (Σ, B), Exp(Σ, B) and Term(Σ, B) have a similar meaning. – We note as v the information ordering, defined as the least partial ordering over Exp⊥ (Σ, B, Var) compatible with contexts and verifying ⊥ v e for all e ∈ Exp⊥ (Σ, B, Var). – Substitutions are defined as mappings σ : Var → Term⊥ (Σ, B, Var) assigning not necessarily total terms to variables. They can be represented as sets of bindings X 7→ t and extended to act over other syntactic objects o. The domain vdom(σ) and variable range vran(σ) are defined in the usual way. We will write oσ for the result of applying σ to o. The composition σσ 0 of two substitutions is such that o(σσ 0 ) equals (oσ)σ 0 . By adapting the definition found in Section 2.2 of [13] to a first-order setting, we obtain: 2 Definition 2 (Constraint Domains). A Constraint Domain of signature Σ is any algebraic structure of the form C = hC, {pC | p ∈ P F }i such that:

1. The carrier set C is Term⊥ (Σ, B) for a certain set B of basic values. When convenient, we note B and C as BC and CC , respectively. 2. pC ⊆ C n × C, written simply as pC ⊆ C in the case n = 0, is called the interpretation of p in C. We will write pC (tn ) → t (or simply pC → t if n = 0) to indicate that (tn , t) ∈ pC . 3. Each primitive interpretation pC has monotonic and radical behavior w.r.t. the information ordering v. More precisely: (a) Monotonicity: For all p ∈ P F n , pC (tn ) → t behaves monotonically w.r.t. the arguments tn and antimonotonically w.r.t. the result t. Formally: For all tn , t0 n , t, t0 ∈ C such that pC (tn ) → t, tn v t0 n and t w t0 , pC (t0 n ) → t0 also holds.

2

We slightly modify the statement of the radicality property, rendering it simpler than in [13] but sufficient for practical purposes.

199

A Generic Scheme for QCFLP

7

(b) Radicality: For all p ∈ P F n , as soon as the arguments given to pC have enough information to return a result other than ⊥, the same arguments suffice already for returning a simple total result. Formally: For all tn , t ∈ C, if pC (tn ) → t then t = ⊥ or else t ∈ B ∪ DC 0 . Note that symbols h ∈ DC ∪ DF are given no interpretation in C. As we will see in Section 3, symbols in c ∈ DC are interpreted as free constructors, and the interpretation of symbols f ∈ DF is program-dependent. We assume that any signature Σ includes two nullary constructors true and f alse for the boolean values, and a binary symbol == ∈ P F 2 used in infix notation and interpreted as strict equality; see [13] for details. For the examples in this report we will use a constraint domain R whose set of basic elements is CR = R and whose primitives functions correspond to the usual arithmetic operations +, ×, . . . and the usual boolean-valued comparison operations ≤, <, . . . over R. Other useful instances of constraint domains can be found in [13]. Atomic constraints over C have the form p(en ) == v 3 with p ∈ P F n , ei ∈ Exp⊥ (Σ, B, Var) and v ∈ Var ∪ DC 0 ∪ BC . Atomic constraints of the form p(en ) == true are abbreviated as p(en ). In particular, (e1 == e2 ) == true is abbreviated as e1 == e2 . Atomic constraints of the form (e1 == e2 ) == f alse are abbreviated as e1 /= e2 . Compound constraints are built from atomic constraints using logical conjunction, existential quantification, and sometimes other logical operations. Constraints without occurrences of symbols f ∈ DF are called primitive. We will note atomic constraints as δ, sets of atomic constraints as ∆, atomic primitive constraints as π, and sets of atomic primitive constraints as Π. When interpreting set of constraints, we will treat them as the conjunction of their members. Ground substitutions η such that Xη ∈ Term⊥ (Σ, B) for all X ∈ vdom(η) are called variable valuations over C. The set of all possible variable valuations is noted ValC . The solution set SolC (Π) ⊆ ValC includes as members those valuations η such that πσ is true in C for all π ∈ Π; see [13] for a formal definition. In case that SolC (Π) = ∅ we say that Π is unsatisfiable and we write UnsatC (Π). In case that SolC (Π) ⊆ SolC (π) we say that π is entailed by Π in C and we write Π |=C π. Note that the notions defined in this paragraph only make sense for primitive constraints. In this report we are interested in pairs consisting of a qualification domain and a constraint domain that are related in the following technical sense: Definition 3 (Expressing D in C). A qualification domain D with carrier set DD is expressible in a constraint domain C with carrier set CC if DD \ {b} ⊆ CC and the two following requirements are satisfied: 1. There is a primitive C-constraint qVal(X) depending on the variable X, such that SolC (qVal(X)) = {η ∈ ValC | η(X) ∈ DD \ {b}}. 2. There is a primitive C-constraint qBound(X, Y, Z) depending on the variables X, Y , Z, such that any η ∈ ValC such that η(X), η(Y ), η(Z) ∈ DD \ {b} verifies η ∈ SolC (qBound(X, Y, Z)) ⇐⇒ η(X) P η(Y ) ◦ η(Z). t u

3

Written as p(en ) →! v in [13].

200

8

R. Caballero, M. Rodr´ıguez-Artalejo and C.A. Romero-D´ıaz

Intuitively, qBound(X, Y, Z) encodes the D-statement X P Y ◦ Z as a Cconstraint. As convenient notations, we will write pX P Y ◦ Zq, pX P Y q and pX Q Y q in place of qBound(X, Y, Z), qBound(X, t, Y ) and qBound(Y, t, X), respectively. In the sequel, C-constraints of the form pκq are called qualification constraints, and Ω is used as notation for sets of qualification constraints. We also write ValD for the set of all µ ∈ ValC such that Xµ ∈ DD \ {b} for all X ∈ vdom(µ), called D-valuations. Note that U can be expressed in R, because DU \ {0} = (0, 1] ⊆ R ⊆ CR , qVal(X) can be built as the R-constraint 0 < X ∧ X ≤ 1 and pX P Y ◦ Zq can be built as the R-constraint X ≤ Y × Z. Other instances of qualification domains presented in [19] are also expressible in R.

3

A Qualified Declarative Programming Scheme

In this section we present the scheme QCFLP(D, C) announced in the Introduction, and we develop alternative characterizations of its declarative semantics using an interpretation transformer and a rewriting logic. The parameters D and C respectively stand for a qualification domain and a constraint domain with certain signature Σ. By convention, we only allow those instances of the scheme verifying that D is expressible in C in the sense of Definition 3. For example, QCFLP(U, R) is an allowed instance. Technically, the results presented here extend similar ones known for the CFLP(C) sheme [13], omitting higher-order functions and adding a suitable treatment of qualifications. In particular, the qc-interpretations for QCFLP(D, C)programs are a natural extension of the c-interpretations for CFLP(C)-programs introduced in [13]. In turn, these were inspired by the π-interpretations for the CLP(C) scheme proposed by Dore, Gabbrielli and Levi [7,6]. 3.1

Programs, Interpretations and Models

A QCFLP(D, C)-program is a set P of program rules. A program rule has the α → r ⇐ ∆ where f ∈ DF n , tn is a lineal sequence of Σ-terms, form f (tn ) − α ∈ DD \ {b} is an attenuation factor, r is a Σ-expression and ∆ is a sequence of atomic C-constraints δj (1 ≤ j ≤ m), interpreted as conjunction. The undefined symbol ⊥ is not allowed to occur in program rules. The library program shown in Figure 1 is an example of QCFLP(U, R)program. Leaving aside the attenuation factors, this is clearly not a confluent conditional term rewriting system. Certain program rules, as e.g. those for guessGenre, are intended to specify the behavior of non-deterministic functions. As argued elsewhere [17], the semantics of non-deterministic functions for the purposes of Functional Logic Programming is not suitably described by ordinary rewriting. Inspired by the approach in [13], we will overcome this difficulty by designing special inference mechanisms to derive semantically meaningful statements from programs. The kind of statements that we will consider are defined below:

201

A Generic Scheme for QCFLP

9

Definition 4 (qc-Statements). Assume partial Σ-expression e, partial Σterms t, t0 , tn , a qualification value d ∈ DD \ {b}, an atomic C-constraint δ and a finite set of atomic primitive C-constraints Π. A qualified constrained statement (briefly, qc-statement) ϕ must have one of the following two forms: 1. qc-production (e → t)]d ⇐ Π. Such a qc-statement is called trivial iff either t is ⊥ or else UnsatC (Π). Its intuitive meaning is that a rewrite sequence e →∗ t0 using program rules and with attached qualification value d is allowed in our intended semantics for some t0 w t, under the assumption that Π holds. By convention, qc-productions of the form (f (tn ) → t)]d ⇐ Π with f ∈ DF n are called qc-facts. 2. qc-atom δ]d ⇐ Π. Such a qc-statement is called trivial iff UnsatC (Π). Its intuitive meaning is that δ is entailed by the program rules with attached qualification value d, under the assumption that Π holds. t u Our semantics will use program interpretations defined as sets of qc-facts with certain closure properties. As an auxiliary tool we need the following technical notion: Definition 5 ((D, C)-Entailment). Given two qc-statements ϕ and ϕ0 , we say that ϕ (D, C)-entails ϕ0 (in symbols, ϕ
The intended meaning of ϕ
202

10

R. Caballero, M. Rodr´ıguez-Artalejo and C.A. Romero-D´ıaz

Definition 6 (qc-Interpretations). A qualified constrained interpretation (or qc-interpretation) over D and C is a set I of qc-facts including all trivial and entailed qc-facts. In other words, a set I of qc-facts such that clD,C (I) ⊆ I, where the closure over D and C of I is defined as: clD,C (I) =def {ϕ | ϕ trivial} ∪ {ϕ0 | ϕ
QTI QRR

QDC

QDFI

ϕ

if ϕ is a trivial qc-statement.

(v → v)]d ⇐ Π

if v ∈ Var ∪ BC and d ∈ DD \ {b}.

( (ei → ti )]di ⇐ Π )i=1...n (c(en ) → c(tn ))]d ⇐ Π ( (ei → ti )]di ⇐ Π )i=1...n (f (en ) → t)]d ⇐ Π

if c ∈ DC n and d ∈ DD \ {b} verifies d P di (1 ≤ i ≤ n).

if f ∈ DF n , non-trivial ((f (tn ) → t)]d0 ⇐ Π) ∈ I and d ∈ DD \ {b} verifies d P di (0 ≤ i ≤ n). QPF

( (ei → ti )]di ⇐ Π )i=1...n (p(en ) → v)]d ⇐ Π

if p ∈ P F n , v ∈ Var ∪ DC 0 ∪ BC ,

Π |=C p(tn ) → v and d ∈ DD \ {b} verifies d P di (1 ≤ i ≤ n). QAC

( (ei → ti )]di ⇐ Π )i=1...n (p(en ) == v)]d ⇐ Π

if p ∈ P F n , v ∈ Var ∪ DC 0 ∪ BC ,

Π |=C p(tn ) == v and d ∈ DD \ {b} verifies d P di (1 ≤ i ≤ n).

Fig. 2. Qualified Constrained Rewriting Logic for Interpretations

Given a qc-interpretation I, the inference rules displayed in Fig. 2 are used to derive qc-statements from the qc-facts belonging to I. The inference system consisting of these rules is called Qualified Constrained Rewriting Logic for Interpretations and noted as I-QCRWL(D, C). The notation I ``D,C ϕ is used to indicate that ϕ can be derived from I in I-QCRWL(D, C). By convention, we agree that no other inference rule is used whenever QTI is applicable. Therefore, trivial qc-statements can only be inferred by rule QTI. As usual in formal inference systems, I-QCRWL(D, C) proofs can be represented as trees whose nodes correspond to inference steps.

203

A Generic Scheme for QCFLP

11

In the sequel, the inference rules QDFI , QPF and QAC will be called crucial. The notation |T | will denote the number of inference steps within the proof tree T that are not crucial. Proof trees with no crucial inferences (i.e. such that |T | = 0) will be called easy. The following lemma states some technical properties of I-QCRWL(D, C). Lemma 1 (Some properties of I-QCRWL(D, C)). 1. Approximation property: For any non-trivial ϕ of the form (t → t0 )]d ⇐ Π where t, t0 ∈ Term⊥ (Σ, B, Var), the three following affirmations are equivalent: (a) t w t0 ; (b) I ``D,C ϕ with an easy proof tree; and (c) I ``D,C ϕ. 2. Primitive c-atoms: For any primitive c-atom p(tn ) == v, one has I ``D,C (p(tn ) == v)]d ⇐ Π ⇐⇒ Π |=C p(tn ) == v. 3. Entailment property: I ``D,C ϕ with a proof tree T and ϕ
204

12

R. Caballero, M. Rodr´ıguez-Artalejo and C.A. Romero-D´ıaz

[3 .] (Entailment property). Assume I ``D,C ϕ with a I-QCRWL(D, C)-proof tree T . We must prove that I ``D,C ϕ0 with some proof tree T 0 such that |T 0 | ≤ |T |. If ϕ0 results trivial, then it is proved with just one QTI inference step, and therefore |T 0 | = 0 ≤ |T |. In the sequel, we assume ϕ0 non-trivial and we reason by induction on the number of inference steps within T . We distinguish cases according to the inference step at the root of T : – QTI: From Definition 5 it is easy to check that ϕ0 must be trivial whenever ϕ
205

A Generic Scheme for QCFLP

13

tree T 0 i such that |T 0 i | ≤ |Ti |. Consider now ψ 0 = ((f (tn )σ → t0 )]d0 ⇐ Π 0 ). Clearly, ψ
206

14

R. Caballero, M. Rodr´ıguez-Artalejo and C.A. Romero-D´ıaz

– (⇒) Assume I ``D,C ϕ. As ϕ is not trivial, there is a I-QCRWL(D, C)-proof tree of the form: ( (ti → t0i )]di ⇐ Π )i=1...n QDFI using ϕ0 = (f (t0 n ) → t)]d0 ⇐ Π) ∈ I (f (tn ) → t)]d ⇐ Π where d P d0 , di and I ``D,C (ti → t0i )]di ⇐ Π (1 ≤ i ≤ n). For each 1 ≤ i ≤ n, we claim that t0i v ti . If t0i = ⊥ the claim is trivial. If t0i 6= ⊥, then (ti → t0i )]di ⇐ Π is a non-trivial qc-production and the claim follows from I ``D,C (ti → t0i )]di ⇐ Π and the approximation property. Now, the claim together with Π |=C Π, d0 Q d and t w t yields ϕ0
Next, we can define program models and semantic consequence, adapting ideas from the so-called strong semantics of [13]. 4 Definition 7 (Models and semantic consequence). Let a QCFLP(D, C)program P be given. α

1. A qc-interpretation I is a model of Rl : (f (tn ) − → r ⇐ δ m ) ∈ P (in symbols, I |=D,C Rl ) iff for every substitution θ, for every set of atomic primitive C-constraints Π, for every c-term t ∈ Term⊥ (Σ, B, Var) and for all d, d0 , . . . , dm ∈ DD \ {b} such that I ``D,C δi θ]d0i ⇐ Π (1 ≤ i ≤ m), I ``D,C (rθ → t)]d00 ⇐ Π and d P α ◦ di (0 ≤ i ≤ m), one has ((f (tn )θ → t)]d ⇐ Π) ∈ I. 2. A qc-interpretation I is a model of P (in symbols, I |=D,C P) iff I is a model of every program rule belonging to P. 3. A qc-statement ϕ is a semantic consequence of P (in symbols, P |=D,C ϕ) iff I ``D,C ϕ holds for every qc-interpretation I such that I |=D,C P. t u 3.2

Least Models

We will now present two different characterizations for the least model of a given program P: in the first place as a least fixpoint of an interpretation transformer and in the second place as the set of qc-facts derivable from P in a special rewriting logic. A fixpoint characterization of least models. A well-known way of characterizing least program models is to exploit the lattice structure of the family of all program interpretations and to obtain the least model of a give program P as the least fixpoint of an interpretation transformer related to P. Such characterizations are know for logic programming [11,2], constraint logic programming [7,6,10], constraint functional logic programming [13] 4

Weak models and weak semantic consequence could be also defined similarly as in [13], but strong semantics suffices for the purposes of this report.

207

A Generic Scheme for QCFLP

15

and qualified logic programming [19]. Our approach here extends that in [13] by adding qualification values. The next result, whose easy proof is omitted, provides a lattice structure of program interpretations: Proposition 2 (Interpretations Lattice). IntD,C defined as the set of all qcinterpretations over the qualification domain D and the constraint domain C is a complete lattice w.r.t. the set inclusion ordering (⊆). Moreover, the bottom element ⊥⊥ and the top element >> of this lattice are characterized as ⊥⊥ = clD,C ({ϕ | ϕ is a trivial qc-fact}) and >> = {ϕ | ϕ is any qc-fact}. Now we define an interpretations transformer STP intended to formalize the computation of immediate consequences from the qc-facts belonging to a given qc-interpretation. Definition 8 (Interpretations transformers). Assuming a QCFLP(D, C)program P and a qc-interpretation I, STP : IntD,C → IntD,C is defined as STP (I) =def clD,C (preSTP (I)) where the closure operator clD,C () is defined as in Def. 6 and the auxiliary interpretation pre-transformer preSTP acts as follows: preSTP (I) =def {(f (tn )θ → t)]d ⇐ Π | there are α some (f (tn ) − → r ⇐ δ m ) ∈ P, some substitution θ, some set Π of primitive atomic C-constraints , some c-term t ∈ Term⊥ (Σ, B, Var), and some qualification values d0 , d1 , . . . , dm ∈ DD \ {b} such that – I ``D,C δi θ]di ⇐ Π (1 ≤ i ≤ m), – I ``D,C (rθ → t)]d0 ⇐ Π, and – d P α ◦ di (0 ≤ i ≤ m) }.

Proposition 3 below shows that preSTP (I) is closed under (D, C)-entailment. Its proof relies on the next technical, but easy result: Lemma 2 (Auxiliary Result). Given terms t, t0 ∈ Term⊥ (Σ, B, Var) and a substitution η such that t is linear and tη v t0 , there is some substitution η 0 such that: 1. tη 0 = t0 , 2. η v η 0 (i.e. Xη v Xη 0 for all X ∈ Var) , and 3. η = η 0 [\var(t)] . Proof. Since t is linear, for each variable X occurring in t there is one single position p such that X occurs in t at position p. Let pX be this position. Since tθ v t0 , there must be a subterm t0X occurring in t0 at position pX such that Xη v t0X . Let η 0 be a substitution such that Xη 0 = t0X for each variable X occurring in t, and Y η 0 = Y θ for each variable Y not occurring in t. It is easy to check that η 0 has all the desired properties. t u

208

16

R. Caballero, M. Rodr´ıguez-Artalejo and C.A. Romero-D´ıaz

Proposition 3 (preSTP (I) is closed under (D, C)-entailment). Assume two qc-facts ϕ and ϕ0 . If ϕ ∈ preSTP (I) and ϕ
Proof. Since ϕ ∈ preSTP (I), there are some Rl : (f (tn ) − → r ⇐ δ m ) ∈ P and some substitution θ such that ϕ : (f (tn )θ → t)]d ⇐ Π and – (1) I ``D,C δi θ]di ⇐ Π (1 ≤ i ≤ m) , – (2) I ``D,C (rθ → t)]d0 ⇐ Π , and – (3) d P α ◦ di (0 ≤ i ≤ m) .

Since ϕ
Let us see that (1’), (2’) and (3’) hold when choosing d0i = di (0 ≤ i ≤ m): [1’] For any 1 ≤ i ≤ m we have δi θ]di ⇐ Π
As a consequence of the previous proposition, we can establish a stronger relation between STP (I) and preSTP (I) for non-trivial qc-facts, as given in the following lemma. Lemma 3 (STP (I) versus preSTP (I)). For any non-trivial qc-fact ϕ one has: ϕ ∈ STP (I) =⇒ ϕ ∈ preSTP (I).

Proof. From ϕ ∈ STP (I) it follows by definition of STP that ϕ ∈ clD,C (preSTP (I)). As we are assuming that ϕ is not trivial, there must be some ψ ∈ preSTP (I) such that ψ
209

A Generic Scheme for QCFLP

17

2. For any I ∈ IntD,C : I |=D,C P ⇐⇒ STP (I) ⊆ I . Proof. Monotonicity and continuity are well-known results for similar semantics; see e.g. Prop. 3 in [13]. Item 2 can be proved as follows: as an easy consequence of Def. 7, I |=D,C P ⇐⇒ preSTP (I) ⊆ I. Moreover, preSTP (I) ⊆ I ⇐⇒ clD,C (preSTP (I)) ⊆ clD,C (I) ⇐⇒ STP (I) ⊆ I, where the first equivalence is obvious and the second equivalence is due to the equalities clD,C (preSTP (I)) = STP (I) and clD,C (I) = I. Therefore, I |=D,C P ⇐⇒ STP (I) ⊆ I, as desired. t u Finally, we can conclude that the least fixpoint of STP characterizes the least model of any given QCFLP(D, C)-program P, as stated in the following theorem. Theorem 1. ForSevery QCFLP(D, C)-program P there exists the least model SP = lfp(STP ) = k∈N STP ↑k (⊥⊥).

Proof. Due to a well-known theorem by Knaster and Tarski [22], a monotonic mapping from a complete lattice into itself always has a least fixpoint which is also its least pre-fixpoint. In the case that the mapping is continuous, its least fixpoint can be characterized as the lub of the sequence of lattice elements obtained by reiterated application of the mapping to the bottom element. Combining these results with Prop. 4 trivially proves the theorem. t u

A qualified constraint rewriting logic. In order to obtain a logical view of program semantics and an alternative characterization of least program models, we define the Qualified Constrained Rewriting Logic for Programs QCRWL(D, C) as the formal system consisting of the six inference rules displayed in Fig. 3. Note that QCRWL(D, C) is very similar Qualified Constrained Rewriting Logic for Interpretations I-QCRWL(D, C) (see Fig. 2), except that the inference rule QDFI from I-QCRWL(D, C) is replaced by the inference rule QDFP in QCRWL(D, C). The inference rules in QCRWL(D, C) formalize provability of qc-statements from a given program P according to their intuitive meanings. In particular, QDFP formalizes the behavior of program rules and attenuation factors that was informally explained in the Introduction, using the set [P]⊥ of program rule instances. In the sequel we use the notation P `D,C ϕ to indicate that ϕ can be inferred from P in QCRWL(D, C). By convention, we agree that no other inference rule is used whenever QTI is applicable. Therefore, trivial qc-statements can only be inferred by rule QTI. As usual in formal inference systems, QCRWL(D, C) proofs can be represented as trees whose nodes correspond to inference steps. For example, if P is the library program, Π is empty, and ψ is (guessGenre(book(4,"Beim Hauten der Zwiebel","Gunter Grass", "German","Biography", medium, 432)) --> "Essay")#0.7

210

18

R. Caballero, M. Rodr´ıguez-Artalejo and C.A. Romero-D´ıaz

QTI

ϕ

QRR

if ϕ is a trivial qc-statement.

(v → v)]d ⇐ Π

if v ∈ Var ∪ BC and d ∈ DD \ {b}.

( (ei → ti )]di ⇐ Π )i=1...n (c(en ) → c(tn ))]d ⇐ Π

QDC

QDFP

if c ∈ DC n and d ∈ DD \ {b} verifies d P di (1 ≤ i ≤ n).

( (ei → ti )]di ⇐ Π )i=1...n (r → t)]d00 ⇐ Π (f (en ) → t)]d ⇐ Π

(δj ]d0j ⇐ Π)j=1...m

α

if f ∈ DF n and (f (tn ) − → r ⇐ δ1 , . . . , δm ) ∈ [P]⊥ where [P]⊥ = {Rl θ | Rl is a rule in P and θ is a substitution}, and d ∈ DD \ {b} verifies d P di (1 ≤ i ≤ n), d P α ◦ d0j (0 ≤ j ≤ m). QPF

( (ei → ti )]di ⇐ Π )i=1...n (p(en ) → v)]d ⇐ Π

if p ∈ P F n , v ∈ Var ∪ DC 0 ∪ BC ,

Π |=C p(tn ) → v and d ∈ DD \ {b} verifies d P di (1 ≤ i ≤ n). QAC

( (ei → ti )]di ⇐ Π )i=1...n (p(en ) == v)]d ⇐ Π

if p ∈ P F n , v ∈ Var ∪ DC 0 ∪ BC ,

Π |=C p(tn ) == v and d ∈ DD \ {b} verifies d P di (1 ≤ i ≤ n).

Fig. 3. Qualified Constrained Rewriting Logic for Programs

then P `U ,R ψ ⇐ Π with a proof tree whose root inference may be chosen as QDFP using a suitable instance of the fourth program rule for guessGenre. The following lemma states the main properties of QCRWL(D, C). The proof is similar to that of Lemma 1 and omitted here. The interested reader is also referred to the proof of Lemma 2 in [13]. Lemma 4 (Some properties of QCRWL(D, C)). The three first items of Lemma 1 also hold for QCRWL(D, C), with the natural reformulation of their statements. More precisely: 1. Approximation property: For any non-trivial ϕ of the form (t → t0 )]d ⇐ Π where t, t0 ∈ Term⊥ (Σ, B, Var), the three following affirmations are equivalent: (a) t w t0 ; (b) P `D,C ϕ with an easy proof tree; and (c) P `D,C ϕ. 2. Primitive c-atoms: For any primitive c-atom p(tn ) == v, one has P `D,C (p(tn ) == v)]d ⇐ Π ⇐⇒ Π |=C p(tn ) == v. 3. Entailment property: P `D,C ϕ with a proof tree T and ϕ
211

A Generic Scheme for QCFLP

19

of Definition 7 (soundness and completeness properties), as well as a characterization of least program models in terms of QCRWL(D, C)-derivability (canonicity property). Theorem 2 (QCRWL(D, C) characterizes program semantics). For any QCFLP(D, C)-program P and any qc-statement ϕ, the following three conditions are equivalent: (a)

P `D,C ϕ

(b)

P |=D,C ϕ

(c)

SP ``D,C ϕ

Moreover, we also have: 1. Soundness: for any qc-statement ϕ, P `D,C ϕ =⇒ P |=D,C ϕ. 2. Completeness: for any qc-statement ϕ, P |=D,C ϕ =⇒ P `D,C ϕ. 3. Canonicity: SP = {ϕ | ϕ is a qc-fact and P `D,C ϕ}. Proof. Assuming the equivalence between (a), (b) and (c), soundness and completeness are a trivial consequence of the equivalence between (a) and (b), and canonicity holds because of the equivalences ϕ ∈ SP ⇐⇒ SP ``D,C ϕ ⇐⇒ P `D,C ϕ, which follow from the conservation property from Lemma 1 and the equivalence between (c) and (a). The rest of the proof consists of separate proofs for the three implications (a) ⇒ (b), (b) ⇒ (c) and (c) ⇒ (a). [(a) ⇒ (b)] We assume (a), i.e., P `D,C ϕ with a QCRWL(D, C)-proof tree TP including k ≥ 1 QCRWL(D, C)-inference steps. In order to prove (b) we also assume a qc-interpretation I such that I |=D,C P. We must prove I ``D,C ϕ with some QCRWL(D, C)-proof tree TI . This follows easily by induction on k, using the fact that each QCRWL(D, C)-inference rule QRL is sound in the following sense: each inference step ϕ1 · · · ϕn QRL ϕ verifying I ``D,C ϕi (1 ≤ i ≤ n) (i.e., the premises are valid in I) also verifies I ``D,C ϕ (i.e., the conclusion is valid in I). For QRL other than QDFP , soundness of QRL does not depend on the assumption I |=D,C P; it can be easily proved by using the homonomous I-QCRWL(D, C)-inference rule QRL. In the case of QDFP , ϕ has the form f (en ) → t)]d ⇐ Π and the validity of the premises in I means the following: – (1) I ``D,C (ei → ti )]di ⇐ Π (1 ≤ i ≤ n) , – (2) I ``D,C (r → t)]d00 ⇐ Π , and – (3) I ``D,C δj ]d0j ⇐ Π (1 ≤ j ≤ m) α

with f ∈ DF n , (f (tn ) − → r ⇐ δ1 , · · · , δm ) ∈ [P]⊥ , d P di (1 ≤ i ≤ n) and d P α ◦ d0j (0 ≤ j ≤ m). Then, from the assumption I |=D,C P and Def. 7 we obtain – (4) ((f (tn ) → t)]d ⇐ Π) ∈ I.

212

20

R. Caballero, M. Rodr´ıguez-Artalejo and C.A. Romero-D´ıaz

Finally, from (1), (4) we conclude that (f (en ) → t)]d ⇐ Π can de derived by means of a QDFI -inference step from premises (ei → ti )]di ⇐ Π (1 ≤ i ≤ n). Therefore, I ``D,C (f (en ) → t)]d ⇐ Π, as desired. [(b) ⇒ (c)] Straightforward, given that SP |=D,C P, as proved in Th. 1. [(c) ⇒ (a)] Let ϕ be any c-statement and assume SP ``D,C ϕ with proof tree T . Note that T includes a finite number of QDFI -inference steps S with I = SP , relying on finitely many qc-facts ψi ∈ SP (1 ≤ i ≤ p). As SP = k∈N STP ↑k (⊥⊥) because of Th. 1, there must exist some k ∈ N such that all the ψi (1 ≤ i ≤ p) belong to STP ↑k (⊥⊥) and thus STP ↑k (⊥⊥) ``D,C ϕ. Therefore, it is enough to prove by induction on k that STP ↑k (⊥⊥) ``D,C ϕ =⇒ P `D,C ϕ Basis (k=0). Assume STP ↑0 (⊥⊥) ``D,C ϕ with I-QCRWL(D, C)-proof tree T . As STP ↑0 (⊥⊥) = ⊥⊥, which only includes trivial qc-facts and QDFI always uses non-trivial qc-facts, T cannot include QDFI -inference steps. Hence, T also serves as a QCRWL(D, C)-proof tree which includes no QDFP -inference steps and proves STP ↑0 (⊥⊥) `D,C ϕ. Inductive step (k>0). Assume STP ↑k+1 (⊥⊥) ``D,C ϕ with I-QCRWL(D, C)proof tree T . Then P `D,C ϕ can be proved by an auxiliary induction on the size of T , measured as its number of nodes. The reasoning must distinguish six cases, according to the I-QCRWL(D, C)-inference rule QRL used to infer ϕ at the root of T . Here we present only the most interesting case, when QRL is QDFI . In this case, ϕ is a non-trivial qc-statement of the form (f (en ) → t)]d ⇐ Π, and T has the form ( (ei → ti )]di ⇐ Π )i=1...n QDFI ϕ : (f (en ) → t)]d ⇐ Π with non-trivial ψ : ((f (tn ) → t)]d0 ⇐ Π) ∈ STP ↑k+1 (⊥⊥), d P di (0 ≤ i ≤ n), and STP ↑k+1 (⊥⊥) ``D,C (ei → ti )]di ⇐ Π proved by I-QCRWL(D, C)-proof trees Ti wit sizes smaller than the size of T (1 ≤ i ≤ n). Therefore, the inductive hypothesis of the nested induction guarantees – (1) P `D,C (ei → ti )]di ⇐ Π with QCRWL(D, C)-proof trees Tˆi (1 ≤ i ≤ n) On the other hand, Lemma 3 ensures ψ ∈ preSTP (STP ↑k (⊥ ⊥)). Therefore, α recalling Def. 8, there must exist f (sn ) − → r ⇐ δ m ∈ P, a substitution θ and qualification values d00 , d01 , . . . , d0m satisfying si θ = ti (1 ≤ i ≤ n) and – (2) STP ↑k (⊥⊥) ``D,C δj θ]d0j ⇐ Π (1 ≤ j ≤ m) – (3) STP ↑k (⊥⊥) ``D,C (rθ → t)]d00 ⇐ Π – (4) d0 P α ◦ d0j (0 ≤ j ≤ m)

By the inductive hypothesis of the main induction, applied to (2) and (3), we get: – (5) P `D,C δj θ]d0j ⇐ Π with QCRWL(D, C)-proof trees Tˆ0 j (1 ≤ j ≤ m)

213

A Generic Scheme for QCFLP

21

– (6) P `D,C (rθ → t)]d00 ⇐ Π with QCRWL(D, C)-proof tree Tˆ0 From d P di (0 ≤ i ≤ n) and (4) we also obtain:

– (7) d P di (0 ≤ i ≤ n), d P α ◦ d0j (0 ≤ j ≤ m)

Finally, we can prove P `D,C ϕ with a QCRWL(D, C)-proof tree Tˆ of the form: ((ei → si θ)]di ⇐ Π)i=1...n (rθ → t)]d00 ⇐ Π (δj θ]d0j ⇐ Π)j=1...m QDFP ϕ : (f (en ) → t)]d ⇐ Π α

using the program rule instance (f (sn ) − → r ⇐ δ m )θ ∈ [P]⊥ , where (5) and (6) provide proof trees for deriving the premises and (7) ensures the additional conditions required by the QDFP inference at the root of Tˆ . t u 3.3

Goals and their Solutions

In all declarative programming paradigms, programs are generally used by placing goals and computing answers for them. In this brief subsection we define the syntax of QCFLP(D, C)-goals and we give a declarative characterization of goal solutions, based on the QCRWL(D, C) logic. This will allow formal proofs of correctness for the goal solving methods presented in Section 4. Definition 9 (QCFLP(D, C)-Goals and their Solutions). Assume a a countable set War of so-called qualification variables W , disjoint from Var and C’s signature Σ, and a QCFLP(D, C)-program P. Then: 1. A goal G for P has the form δ1 ]W1 , . . . , δm ]Wm 8 W1 Q β1 , . . . , Wm Q βm , abbreviated as ( δi ]Wi , Wi Q βi )i=1...m , where δj ]Wj (1 ≤ j ≤ m) are atomic C-constraints annotated with different qualification variables Wi , and Wi Q βi are so-called threshold conditions, with βi ∈ DD \ {b} (1 ≤ i ≤ m). 2. A solution for G is any triple hσ, µ, Πi such that σ is a substitution, µ is a D-valuation, Π is a finite set of atomic primitive C-constraints, and the following two conditions hold for all 1 ≤ i ≤ m: Wi µ = di Q βi , and P `D,C (δi σ)]di ⇐ Π. The set of all solutions for G is noted SolP (G). t u

Thanks to the Canonicity property of Theorem 2, solutions of P are valid in the least model SP and hence in all models of P. A goal for the library program and one solution for it have been presented in the Introduction. In this particular example, Π = ∅ and the QCRWL(U, R) proof needed to check the solution according to Definition 9 can be formalized by following the intuitive ideas sketched in the Introduction.

4

Implementation by Program Transformation

Goal solving in instances of the CFLP(C) scheme from [13] has been formalized by means of constrained narrowing procedures as e.g. [12,5], and is supported

214

22

R. Caballero, M. Rodr´ıguez-Artalejo and C.A. Romero-D´ıaz

by systems such as Curry [9] and T OY [3]. In this section we present a semantically correct transformation from QCFLP(D, C) into the first-order fragment of CFLP(C) which can be used for implementing goal solving in QCFLP(D, C). By abuse of notation, the first-order fragment of the CFLP(C) scheme will be noted simply as CFLP(C) in the sequel. A formal description of CFLP(C) can be found in [13]; it is easily derived from the previous Section 3 by simply omitting everything related to qualification domains and values. Programs P are sets of program rules of the form f (tn ) → r ⇐ ∆, with no attenuation factors attached. Program semantics relies on inference mechanisms for deriving c-staments from programs. In analogy to Def. 4, a c-statement ϕ may be a c-production e → t ⇐ Π or a c-atom δ ⇐ Π. In analogy to Def. 6, c-interpretations are defined as sets of c-statements closed under a C-entailment relation. Program models and semantic consequence are defined similarly as in Def. 7. Results similar to Th. 1 and Th. 2 can be obtained to characterize program semantics in terms of an interpretation transformer and a rewriting logic CRWL(C), respectively. For the purposes of this section it is enough to focus on CRWL(C), which is a formal system consisting of the six inference rules displayed in Fig. 4. They are quite similar to the QCRWL(D, C)-inference rules from Fig. 3, except that attenuation factors and qualification values are absent.

TI RR DC

DFP

ϕ

if ϕ is a trivial c-statement.

v→v⇐Π

if v ∈ Var ∪ BC .

( ei → ti ⇐ Π )i=1...n c(en ) → c(tn ) ⇐ Π

if c ∈ DC n .

( ei → ti ⇐ Π )i=1...n r → t ⇐ Π f (en ) → t ⇐ Π

( δj ⇐ Π )j=1...m

α

if f ∈ DF n and (f (tn ) − → r ⇐ δ1 , . . . , δm ) ∈ [P]⊥ where [P]⊥ = {Rl θ | Rl is a rule in P and θ is a substitution}. PF

( ei → ti ⇐ Π )i=1...n p(en ) → v ⇐ Π

if p ∈ P F n , v ∈ Var ∪ DC 0 ∪ BC and Π |=C p(tn ) → v.

AC

( ei → ti ⇐ Π )i=1...n p(en ) == v ⇐ Π

if p ∈ P F n , v ∈ Var ∪ DC 0 ∪ BC and Π |=C p(tn ) == v.

Fig. 4. First Order Constrained Rewriting Logic

The notation P `C ϕ indicates that ϕ can be inferred from P in CRWL(C). In analogy to the Canonicity Property from Th. 2, it is possible to prove that

215

A Generic Scheme for QCFLP

23

the least model of P w.r.t. set inclusion can be characterized as SP = {ϕ | ϕ is a c-fact and P `C ϕ}. Therefore, working with formal inference in the rewrite logics QCRWL(D, C) and CRWL(C) is sufficient for proving the semantic correctness of the transformations presented in the rest of this section. The following definition is similar to Def. 9. It will be useful for proving the correctness of the goal solving procedure for QCFLP(D, C)-goals discussed in the final part of this section. Definition 10 (CFLP(C)-Goals and their Solutions). Assume a CFLP(C)program P. Then: 1. A goal G for P has the form δ1 , . . . , δm where δj are atomic C-constraints. 2. A solution for G is any pair hσ, Πi such that σ is a substitution, Π is a finite set of atomic primitive C-constraints, and P `C δj σ ⇐ Π holds for 1 ≤ j ≤ m. The set of all solutions for G is noted SolP (G). t u Now we are ready to describe a semantically correct transformation from QCFLP(D, C) into CFLP(C). The transformation goes from a source signature Σ into a target signature Σ 0 such that each f ∈ DF n in Σ becomes f 0 ∈ DF n+1 in Σ 0 , and all the other symbols in Σ remain the same in Σ 0 . There are four group of transformation rules displayed in Figure 5 and designed to transform expressions, qc-statements, program rules and goals, respectively. The transformation works by introducing fresh qualification variables W to represent the qualification values attached to the results of calls to defined functions, as well as qualification constraints to be imposed on the values of qualification variables. Let us comment the four groups of rules in order. Transforming any expression e yields a triple eT = (e0 , Ω, W), where Ω is a set of qualification constraints and W is the set of qualification variables occurring in e0 at outermost positions. This set is relevant because the qualification value attached to e cannot exceed the infimum in D of the values of the variables W ∈ W, and eT is computed by recursion on e’s syntactic structure as specified by the transformation rules TAE, TCE1 and TCE2 . Note that TCE2 introduces a new qualification variable W for each call to a defined function f ∈ DF n and builds a set Ω 0 of qualification constraints ensuring that W must be interpreted as a qualification value not greater than the qualification values attached to f ’s arguments. TCE1 deals with calls to constructors and primitive functions just by collecting information from the arguments, and TAE is self-explanatory. Unconditional productions and atomic constraints are transformed by means of TP and TA, respectively, relying on the transformation of expressions in the obvious way. Relying on TP and TA, TCS transforms any qc-statement of the form ψ]d ⇐ Π into a c-statement whose conditional part includes, in addition to Π, the qualification constraints Ω coming from ψ T and extra qualification constraints ensuring that d is not greater than allowed by ψ’s qualification. Program rules are transformed by TPR. Transforming the left-hand side f (tn ) introduces a fresh symbol f 0 ∈ DF n+1 and a fresh qualification variable W . The transformed right-hand side r0 comes from rT , and the transformed conditions are obtained from the constraints coming from rT and δi T (1 ≤ i ≤ m)

216

24

R. Caballero, M. Rodr´ıguez-Artalejo and C.A. Romero-D´ıaz

Transforming Expressions TAE

v T = (v, ∅, ∅)

if v ∈ Var ∪ BC .

TCE1

( ei T = (e0i , Ωi , Wi ) )i=1...n Sn S h(en )T = (h(e0 n ), n i=1 Wi ) i=1 Ωi ,

TCE2

( ei T = (e0i , Ωi , Wi ) )i=1...n f (en )T = (f 0 (e0 n , W ), Ω 0 , {W })

if h ∈ DC n ∪ P F n .

if f ∈ DF n and Sn S W is a fresh variable, 0 0 where Ω 0 = ( n i=1 Wi }. i=1 Ωi ) ∪ {qVal(W )} ∪ {pW P W q | W ∈ Transforming qc-Statements TP

eT = (e0 , Ω, W) (e → t)T = (e0 → t, Ω, W)

TA

( ei T = (e0i , Ωi , Wi ) )i=1...n S Sn (p(en ) == v)T = ( p(e0 n ) == v, n i=1 Ωi , i=1 Wi )

if p ∈ P F n , v ∈ Var ∪ DC 0 ∪ BC . TCS

ψ T = (ψ 0 , Ω, W) (ψ]d ⇐ Π) = (ψ 0 ⇐ Π, Ω ∪ {pd P W q | W ∈ W})) T

if ψ is of the form e → t or p(en ) == v and d ∈ DD . Transforming Program Rules TPR

rT = (r0 , Ωr , Wr )

α

T

( δi T = (δi0 , Ωi , Wi ) )i=1...m

→ r ⇐ δ1 , . . . , δ m ) = (f (tn ) − f 0 (tn , W ) → r0 ⇐ qVal(W ), Ωr , (pW P α ◦ W 0 q)W 0 ∈Wr , ( Ωi , (pW P α ◦ W 0 q)W 0 ∈Wi , δi0 )i=1...m where W is a fresh variable. Transforming Goals TG

( δi T = (δi0 , Ωi0 , Wi0 ) )i=1...m (( δi ]Wi , Wi Q βi )i=1...m )T = ( Ωi0 , qVal(Wi ), (pWi P W 0 q)W 0 ∈Wi0 , pWi Q βi q, δi0 )i=1...m

Fig. 5. Transformation rules

217

A Generic Scheme for QCFLP

25

by adding extra qualification constraints to be imposed on W , namely qVal(W ) and (pW P α ◦ W 0 q)W 0 ∈W 0 , for W 0 = Wr and W 0 = Wi (1 ≤ i ≤ m). By convention, (pW P α ◦ W 0 q)W 0 ∈W 0 is understood as pW P αq in case that W 0 = ∅. The idea is that W ’s value cannot exceed the infimum in D of all the values α ◦ β, for the different β coming from the qualifications of r and δi (1 ≤ i ≤ m). Finally, TG transforms a goal ( δi ]Wi , Wi Q βi )i=1...m by transforming each atomic constraint δi and adding qVal(Wi ), (pWi P W 0 q)W 0 ∈Wi0 and pWi Q βi q (1 ≤ i ≤ m) to ensure that each Wi is interpreted as a qualification value not bigger than the qualification computed for δi and satisfying the threshold condition Wi Q βi . In case that Wi0 = ∅, (pWi P W 0 q)W 0 ∈Wi0 is understood as pWi P tq. The result of applying TPR to all the program rules of a program P will be noted as P T . The following theorem proves that QCRWL(D, C)-derivability from P corresponds to CRWL(C)-derivability from P T . Since program semantics in QCFLP(D, C) and in CFLP(C) is characterized by, respectively, derivability in QCRWL(D, C) and in CRWL(C), the program transformation is semantically correct. The theorem uses an auxiliary lemma we are proving first which indicates that the constraints obtained when transforming a qc-statement always admit a solution. Lemma 5. Let ϕ = ψ]d ⇐ Π be a qc-statement such that ϕT = (ψ 0 ⇐ Π, Ω 0 ). Then exists ρ : var(Ω 0 ) → DD \ {b} solution of Ω 0 .

Proof. ϕT is obtained by the transformation rule TCS of Figure 5. This rule needs to obtain ψ T which can be done using either the transformation rule TP or TA of the same figure. In the case of using TP, ψ must be of the form (e → t) and Ω 0 will be of the form Ω ∪ {pd P W q | W ∈ W}, with Ω, W such that eT = (e0 , Ω, W). Checking the transformation rules for expressions (again Figure 5) we see that Ω is a set of constraints where each element is either of the form pW P W 0 q or qVal(W ), with W, W 0 ∈ War. Then ρ can be defined assigning t to every variable W occurring in either Ω 0 or W. The case corresponding to the transformation rule TA is analogous. t u Theorem 3. Let P be a QCFLP(D, C)-program and ψ]d ⇐ Π a qc-statement T such that (ψ]d ⇐ Π) = (ψ 0 ⇐ Π, Ω 0 ). Then the two following statements are equivalent: 1. P `D,C ψ]d ⇐ Π. 2. P T `C ψ 0ρ ⇐ Π for some ρ ∈ SolC (Ω 0 ) such that vdom(ρ) = var(Ω 0 ). Proof. We prove the equivalence separately proving each implication. [1 . ⇒ 2 .] (Transformation completeness). Assume P `D,C ψ]d ⇐ Π by means of a QCRWL(D, C) proof tree T with k nodes. By induction on k we show the existence of a CRWL(C) proof tree T 0 witnessing P T `C ψ 0ρ ⇐ Π for some ρ ∈ SolC (Ω 0 ) such that vdom(ρ) = var(Ω 0 ). Basis (k=1). If T contains only one node the QCRWL(D, C) inference step applied at the root must be one of the following:

218

26

R. Caballero, M. Rodr´ıguez-Artalejo and C.A. Romero-D´ıaz

– QTI. In this case ψ]d ⇐ Π is a trivial qc-statement, and we take ρ as the substitution defined in Lemma 5. By Def. 4, ψ]d ⇐ Π trivial implies either ψ = e → ⊥ or UnsatC (Π). In the first case ψ 0 = e0 → ⊥ and therefore ψ 0ρ ⇐ Π is trivial. Analogously, if UnsatC (Π) then ψ 0ρ ⇐ Π is trivial as well. Hence T 0 consists of a single node ψ 0ρ ⇐ Π with a TI inference step at its root. T – QRR. In this case ψ = t → t for some t ∈ Var ∪ BC , and (ψ]d ⇐ Π) = (t → t ⇐ Π, ∅) (applying the transformation rules TCS, TP and TAE to obtain tT = (t, ∅, ∅)). Therefore ρ can be defined as the identity substitution and prove P T `C ψ 0ρ ⇐ Π by using a single RR inference step. T – QDC. In this case ψ = c → c and (ψ]d ⇐ Π) = (c → c ⇐ Π, ∅) (applying the transformation rules TCS, TP and TCE1 for cT = (c, ∅, ∅)). Therefore ρ can be defined as the identity substitution and prove P T `C ψ 0ρ ⇐ Π by using a single DC inference step. Inductive step (k>1). The QCRWL(D, C) inference step applied at the root must be one of the following: – QDC. In this case ψ = c(en ) → c(tn ) and the first inference step is of the form ( (ei → ti )]di ⇐ Π )i=1...n (c(en ) → c(tn ))]d ⇐ Π with d P di (1 ≤ i ≤ n). In order to obtain ψ]d ⇐ Π T we apply the transformation rules as follows: • By the transformation rule TCE1 , T

c(en ) = (c(e0 n ),

n [

i=1

Ωi ,

n [

i=1

Wi )

with ei T = (e0i , Ωi , Wi ) for i = 1 . . . n. • By TP and with the result of the previous step, T

ψ T = (c(en ) → c(tn )) = (c(e0 n ) → c(tn ),

n [

Ωi ,

i=1

n [

i=1

Wi ) .

• And finally from ψ T and by TCS, T

(ψ]d ⇐ Π) = (c(e0 n ) → c(tn ) ⇐ Π, Ω 0 ) , with Ω0 =

n [

i=1

Ωi ∪ {pd P W q | W ∈

n [

i=1

Wi } .

From the premises ( (ei → ti )]di ⇐ Π )i=1...n of the QDC step and by the induction hypothesis we have that P T `C (e0i → ti )ρi ⇐ Π, i = 1 . . . n for some substitutions ρi : var(Ωi0 ) → DD \ {b} solution of Ωi0 = Ωi ∪ {pdi P W q | W ∈ Wi }

219

A Generic Scheme for QCFLP

27

for i = 1 . . . n. Since var(Ωi0 ) ∩ var(Ωj0 ) = ∅ for every 1 ≤ i, j ≤ n, i 6= j, Sn 0 0 and var(Ω 0 ) = i=1 Unvar(Ωi ), we can define a new substitution ρ : var(Ω ) → DD \ {b} as ρ = i=1 ρi . It is easy to check that ρ is solution of Ω 0 :

• It is solution of S every Ωi0 for i = 1 . . . n, since ρvar(Ωi0 ) = ρi . Therefore n it is solution of i=1 Ωi . Sn • It is a solution of {pd P W q | W ∈ i=1 Wi } because as solution of 0 Ωi for i = 1 . . . n, ρ is solution of {pdi P W q | W ∈ Wi }, and by the hypothesis of QDC d P di .

Therefore we prove P T `C (c(e0 n )ρ → c(tn ))ρ ⇐ Π with a proof tree T 0 which starts with a DC inference rule of the form (( e0i → ti )ρ ⇐ Π )i=1...n . (c(e0 n ) → c(tn ))ρ ⇐ Π

In order to justify that P T `C (e0i → ti )ρ ⇐ Π for each i = 1 . . . n, we observe that the only variables of e0i → ti that can be affected by ρ are those introduced in e0i by the transformation, and that therefore (e0i → ti )ρ = (e0i → ti )ρi for i = 1 . . . n, and these premises correspond to the inductive hypotheses of this case. – QDFP . In this case ψ = f (en ) → t and the inference step applied at the root is of the form ( (ei → ti θ)]di ⇐ Π )i=1...n (rθ → t)]d00 ⇐ Π (f (en ) → t)]d ⇐ Π

( δj θ]d0j ⇐ Π )j=1...m

α

for some program rule Rl = (f (tn ) − → r ⇐ δ m ) ∈ P and substitution θ such that Rl θ ∈ [P]⊥ , and with d P di (1 ≤ i ≤ n) and d P α ◦ d0j (0 ≤ j ≤ m). The inductive hypotheses in this case are:

1. P T `C (e0i → ti θ)ρi ⇐ Π for i = 1 . . . n, with ei T = (e0i , Ωi , Wi ) and ρi solution of Ωi0 = Ωi ∪ {pdi P W 0 q | W 0 ∈ Wi }, for i = 1 . . . n. 2. P T `C (r0 θ → t)ρ00 ⇐ Π, with rT = (r0 , Ωr , W00 ) (it is easy to check that T if rT = (r0 , Ωr , W00 ) then (rθ) = (r0 θ, Ωr , W00 ) for every substitution θ), and ρ00 solution of Ωr0 = Ωr ∪ {pd00 P W 0 q | W 0 ∈ W00 }. 3. P T `C (δj0 θ)ρ0j ⇐ Π with δj T = (δj0 , Ωδj , Wj0 ) for j = 1 . . . k (it is easy T to check that if δj T = (δj0 , Ωδj , Wj0 ) then (δj θ) = (δj0 θ, Ωδj , Wj0 ) for every substitution θ and j = 1 . . . k). The substitution ρ0j is solution of Ωδ0 j = Ωδj ∪ {pd0j P W 0 q | W 0 ∈ Wj0 } for j = 1 . . . m. T

In this case, (ψ]d ⇐ Π) is obtained by means of the transformation rule TCS. This rule asks first for the transformation of the qualified statement (f (en ) → t)]d, which can be obtained by rule TP, and this one requires the transformation of f (en ), provided by rule rule TCE2 . Let’s see it:

220

28

R. Caballero, M. Rodr´ıguez-Artalejo and C.A. Romero-D´ıaz

( ei T = (e0i , Ωi , Wi ) )i=1...n TCE2 T

f (en )S = ( f (e0 n , W ), n ( i=1 Ωi ) ∪ {qVal(WS)} ∪ n {pW P W 0 q | W 0 ∈ i=1 Wi }, {W } )

TP

T

(f (en )S→ t) = ( f (e0 n , W ) → t, n ( i=1 Ωi ) ∪ {qVal(WS)} ∪ n {pW P W 0 q | W 0 ∈ i=1 Wi }, {W } )

TCS

T

((f (enS) → t)]d ⇐ Π) = ( f (e0 n , W ) → t ⇐ Π, n ( i=1 Ωi ) ∪ {qVal(WS)} ∪ n {pW P W 0 q | W 0 ∈ i=1 Wi } ∪ {pd P W q} )

Therefore Ω0 = (

n [

i=1

Ωi ) ∪ {qVal(W )} ∪ {pW P W 0 q | W 0 ∈

We define a new substitution ρ=

n ]

i=1

ρi ] ρ00 ]

m ]

j=1

n [

i=1

Wi } ∪ {pd P W q} .

ρ0j ] {W 7→ d} .

It is straightforward to check that ρ is a solution for Ω 0 because ρ is solution of: • Each Ωi (1 ≤ i ≤ n), because ρi is solution of Ωi0 which contains Ωi (see inductive hypothesis 1) and ρ is an extension of ρi . • {qVal(W )} because qVal(W )ρ = qVal(d) which holds by definition. Sn • {pW P W 0 q | W 0 ∈ i=1 Wi } because Wρ = d, ρ is solution of {pdi P W 0 q | W 0 ∈ Wi } for each i = 1 . . . n (see inductive hypothesis 1), and d P di (1 ≤ i ≤ n) by the hypotheses of the inference rule QDPP . • {pd P W q} since Wρ = d and trivially d P d. α → r ⇐ δ m ) ∈ P will be a The transformed of the program rule Rl = (f (tn ) − program rule in P T of the form: T

(Rl ) = (f (tn , W ) → r0 ⇐ qVal(W ), Ωr , (pW P α ◦ W 0 q)W 0 ∈W00 , Ωδ1 , (pW P α ◦ W10 q)W10 ∈W10 , δ10 .. . 0 0 0 ∈W 0 , δ Ωδm , (pW P α ◦ Wm q)Wm m m

221

A Generic Scheme for QCFLP

29

with rT = (r0 , Ωr , W00 ) and ( δj T = (δj0 , Ωδj , Wj0 ) )j=1...m . Then we prove (f (e0 n , W ) → t)ρ ⇐ Π in CFLP(C) with a DFP root inT ference step using the program rule (Rl ) and the substitution θ0 = θ ] ρ to instantiate the program rule. We next check that every premise of this inference can be proven in CRWL(C): • P T `C (e0i ρ → ti (θ ] ρ)) ⇐ Π for i = 1 . . . n. We observe that the only variables of e0i that can be affected by ρ are those in ρi . Moreover, ρ cannot affect ti because the program transformation does not introduce new variables in terms. Therefore (e0i ρ → ti (θ ] ρ)) = (e0i → ti θ)ρi and P T `C (e0i → ti θ)ρi ⇐ Π for i = 1 . . . n follows from inductive hypothesis number 1. • P T `C (W ρ → W (θ]ρ)) ⇐ Π. By construction of ρ, (Wρ → W (θ]ρ)) = d → d and one RR inference step proves this statement. • P T `C (r0 (θ ] ρ) → tρ) ⇐ Π. In this case tρ = t because t it contains no variables introduced during the transformation, and r0 (θ ] ρ) = r0 (θρ00 ) since ρ00 is the only part of ρ that can affect r0 and the range of θ does not include any of the new variables in the domain of ρ00 . Now, P T `C (r0 θ → t)ρ00 ⇐ Π follows from inductive hypothesis number 2. • P T `C qVal(W )(θ ] ρ) ⇐ Π. W is a fresh variable and, by construction of ρ, qVal(W )(θ ] ρ) = qVal(d). P T `C qVal(d) ⇐ Π trivially holds. • P T `C Ωr (θ ] ρ) ⇐ Π. Ωr (θ ] ρ) = Ωr ρ = Ωr ρ00 and, by construction, ρ00 is solution of Ωr . • P T `C (pW P α ◦ W 0 q)(θ ] ρ) ⇐ Π for each W 0 ∈ W00 . We have (pW P α◦W 0 q)(θ]ρ) = (pW P α◦W 0 q)ρ = pW ρ P α◦W 0ρ00 q = pd P α◦W 0 ρ00 q. And pd P α ◦ W 0ρ00 q holds because d P α ◦ d00 by the hypotheses of the inference rule QDPP , and pd00 P W 0 q by inductive hypothesis number 2. • P T `C Ωδj (θ ] ρ) ⇐ Π for j = 1 . . . m. As in the previous premises Ωδj (θ ] ρ) = Ωδj ρ = Ωδj ρ0j and ρ0j is solution of Ωδj as a consequence of the inductive hypothesis number 3. • P T `C (pW P α ◦ Wj0 q)(θ ] ρ) ⇐ Π for every Wj0 ∈ Wj0 and j = 1 . . . m. We have (pW P α◦Wj0 q)(θ]ρ) = (pW P α◦Wj0 q)ρ = pW ρ P α◦Wj0 ρq = pd P α ◦ Wj0 ρ0j q. Now, from the hypotheses of the inference rule QDPP follows d P α ◦ d0j for j = 1 . . . m, and from inductive hypothesis number 3, ρ0j is solution of pd0j P Wj0 q. Hence P T `C pd P α ◦ Wj0 ρ0j q ⇐ Π for j = 1 . . . k. • P T `C δj0 (θ ]ρ) ⇐ Π for j = 1 . . . m. In this case δj0 can contain variables from both θ and ρ0j . Hence δj0 (θ ] ρ) = (δj0 θ)ρ0j . And P T `C (δj0 θ)ρ0j ⇐ Π follows from the inductive hypothesis number 3. – QPF. In this case ψ = p(en ) → v and the inference step applied at the root is of the form ( (ei → ti )]di ⇐ Π )i=1...n (p(en ) → v)]d ⇐ Π with v ∈ Var ∪ DC 0 ∪ BC , Π |=C p(tn ) → v and d P di (1 ≤ i ≤ n). In order T to obtain (ψ]d ⇐ Π) one has to:

222

30

R. Caballero, M. Rodr´ıguez-Artalejo and C.A. Romero-D´ıaz

• First, apply the transformation rule TCE1 , T

p(en ) = (p(e0 n ),

n [

Ωi ,

i=1

n [

i=1

Wi )

where ei T = (e0i , Ωi , Wi ) for i = 1 . . . n. • Second, apply the transformation rule TP, T

(p(en ) → v) = (p(e0 n ) → v,

n [

Ωi ,

i=1

n [

i=1

Wi ) .

• And finally, apply the transformation rule TCS, T

(ψ]d ⇐ Π) = (p(e0 n ) → v ⇐ Π, Therefore Ω0 =

n [

i=1

n [

i=1

Ωi ∪ {pd P W q | W ∈

Ωi ∪ {pd P W q | W ∈

n [

i=1

n [

i=1

Wi }) .

Wi } .

From the premises ( (ei → ti )]di ⇐ Π )i=1...n of the inference rule QPF, and by the inductive hypothesis we have P T `C (e0i → ti )ρi ⇐ Π (1 ≤ i ≤ n) for some substitutions ρi : var(Ωi0 ) → DD \ {b} solution of Ωi0 = Ωi ∪ {pdi P W q | W ∈ Wi }

for iU= 1 . . . n. We define a new substitution ρ : var(Ω 0 ) → DD \ {b} as n ρ = i=1 ρi . It is easy to check that ρ is solution of Ω 0 : • It is solution of S every Ωi0 for i = 1 . . . n, since ρvar(Ωi0 ) = ρi . Therefore n it is solution of i=1 Ωi . Sn • It is a solution of {pd P W q | W ∈ i=1 Wi } because as solution of 0 Ωi for i = 1 . . . n, ρ is solution of {pdi P W q | W ∈ Wi }, and by the hypothesis of the inference rule QPF, d P di (1 ≤ i ≤ n). We now prove P T `C (p(e0 n ) → v)ρ ⇐ Π with a proof tree T 0 with a PF root inference of the form: ( (e0i → ti )ρ ⇐ Π )i=1...n (p(e0 n )ρ → v) ⇐ Π The rule can be applied because the requirements v ∈ Var ∪ DC 0 ∪ BC and Π |=C p(tn ) → v are ensured by the hypothesis of the inference rule QPF. In order to justify that P T `C (e0i → ti )ρ ⇐ Π for each i = 1 . . . n, we observe that the only variables of (e0i → ti ) that can be affected by ρ are those introduced in e0i by the transformation, and that therefore (e0i → ti )ρ = (e0i → ti )ρi for i = 1 . . . n, and it is easy to check that these premises correspond to the inductive hypotheses of this case. – QAC. This case is analogous to the previous proof, with the only differences being:

223

A Generic Scheme for QCFLP

31

• The inference rule applied at the root of the proof tree is a QAC inference rule instead of a QPF inference rule. T • In order to obtain the (ψ]d ⇐ Π) , the transformation rules applied are TA and TCS instead of TCE1 , TP and TCS. • The proof tree T 0 will have an AC inference step at its root instead of a PF inference step. [2 . ⇒ 1 .] (Transformation soundness). Assume ρ ∈ SolC (Ω 0 ) such that vdom(ρ) = var(Ω 0 ) and P T `C ψ 0 ρ ⇐ Π by means of a CRWL(C) proof tree T with k nodes. Reasoning by induction on k we show the existence of a QCRWL(D, C) proof tree T 0 witnessing P `D,C ψ]d ⇐ Π. Basis (k=1). If T contains only one node the QCRWL(D, C) inference step applied at the root must be any of the following: – TI. In this case ψ 0ρ ⇐ Π is a trivial c-statement. Then ψ 0ρ is either of the form e0 → ⊥ or UnsatC (Π). In the first case, since the transformation introduces no new variables at the right-hand side of a production, ψ 0 is of the form e00 → ⊥ with e0 = e00 ρ, and ψ is of the form e → ⊥, hence ψ]d ⇐ Π is trivial. Analogously, if UnsatC (Π) then ψ]d ⇐ Π is trivial as well. Therefore T 0 consists of a single node ψ]d ⇐ Π with d any value in DD \ {b}, with a QTI inference step at its root. – RR. In this case ψ 0ρ = v → v with v ∈ Var ∪ BC . Then ψ 0 = v1 → v2 for some v1 , v2 ∈ Var ∪ BC such that ψ 0ρ = v → v. Since ψ 0 cannot contain new variables introduced by the transformation (by the transformation rules), this means ψ 0ρ = ψ 0 , and then ψ 0 = v → v. Therefore ψ = v → v, and T 0 consists of a single node containing (v → v)]d ⇐ Π for any d ∈ DD \ {b} as the conclusion of a QRR inference step. – DC. Then ψ 0ρ = c → c, which means that ψ 0 can be either of the form c → c, X → c, or X → Y with X, Y variables. In every case ψ 0 does not include new variables introduced by the transformation, and therefore ψ 0 ρ = ψ 0 , which means that ψ 0 = c → c is the only possibility. Therefore ψ = c → c, and T 0 consists of a single node containing (c → c)]d ⇐ Π for some d ∈ DD \ {b} as the conclusion of a QDC inference step. Inductive step (k>1). The CRWL(C) inference step applied at the root must be any of the following: – DC. Then ψ 0ρ = c(e00 n ) → c(tn ) where c ∈ DC n and n > 0, which implies that ψ = c(en ) → c(tn ) for values ei verifying ei T = (e0i , Ωi , Wi ) for i = 1 . . . n, and e00i = e0i ρ for i = 1 . . . n. Then T

ψ T = (c(en ) → c(tn )) = (c(e0 n ) → c(tn ),

n [

Ωi ,

i=1

n [

i=1

Wi )

and thus ϕ = (c(en ) → c(tn ))]d ⇐ Π for some d ∈ DD \ {b} such that ϕT = (ψ 0 ⇐ Π, Ω 0 ), with Ω0 =

n [

i=1

Ωi ∪ {pd P W q | W ∈

224

n [

i=1

Wi }

32

R. Caballero, M. Rodr´ıguez-Artalejo and C.A. Romero-D´ıaz

The substitution ρ : var(Ω 0 ) → DD \ {b} must be solution of Ω 0 , and the inference step at the root must be of the form: ( e0i ρ → ti ⇐ Π )i=1...n c(e0 n )ρ → c(tn ) ⇐ Π In the premises we have the proofs Ti of P T `C e0i ρ ⇐ Π for i =d 1 . . . n. Now, for each 1 ≤ i ≤ n we obtain a new value di ∈ DD \ {b} as di = {Wρ | W ∈ Wi }. Then we will prove P `D,C ϕ applying the following QDC inference step at the root: ( (ei → ti )]di ⇐ Π )i=1...n (c(en ) → c(tn ))]d ⇐ Π In order to ensure that this step must be applied we must check that d P di (1 ≤ i ≤ n). This holds because ρ is solution of Ω 0 , in particular of {pd P W q | W ∈ Wi } for i = 1 . . . n. Therefore for d each i = 1 . . . n and W ∈ Wi , d P Wρ, which means that d P di = {W ρ | W ∈ Wi }. To complete the proof we must check that there are proof trees for the premises, i.e. that P `D,C ϕi with ϕi = (ei → ti )]di ⇐ Π, i = 1 . . . n. This is a consequence of the inductive hypotheses since for each i = 1 . . . n: • ϕi T = (e0i → ti ⇐ Π, Ωi0 ), with Ωi0 = Ωi ∪ {pdi P W q | W ∈ Wi }. • ρ is solution of Ωi0 , since it is solution of Ωi and by the definition of di , di P Wρ for every W ∈ Wi . • We have that P T `C e0i ρ ⇐ Π for i = 1 . . . n (the premises of the DC step). – DFP . The inference step at the root of T will use an instance (Rl T )θ ∈ [P T ]⊥ of a program rule Rl T of P T . Rl T will be the transformed of a program rule α Rl = (f (tn ) − → r ⇐ δ m ) ∈ P, and therefore will have the form: Rl T = (f (tn , W ) → r0 ⇐ qVal(W ), Ωr , (pW P α ◦ W 0 q)W 0 ∈W00 , Ωδ1 , (pW P α ◦ W10 q)W10 ∈W10 , δ10 .. . 0 0 0 ∈W 0 , δ q)Wm Ωδm , (pW P α ◦ Wm m m

with rT = (r0 , Ωr , W00 ) and (δj T = (δj0 , Ωj0 , Wj0 ))j=1...m . In this case, ψ 0ρ must be of the form (f (e0 n+1 ) → t)ρ. By the theorem T premises, there exists a qc-statement ψ]d ⇐ Π such that (ψ]d ⇐ Π) = (ψ 0 ⇐ Π, Ω 0 ) for some Ω 0 . Examining the transformation program rules we observe that the only possibility for ψ is to be of the form f (en ) → t and that the TCS transformation rules should have been applied followed by TP and TCE2 . This means in particular that d 6= b and that ei T = (e0i , Ωi , Wi ) for i = 1 . . . n and that e0n+1 = V with V fresh variable. Hence ψ T = (f (e0 n , V ) → t, (

Sn

)}∪ i=1 Ωi ) ∪ {qVal(V S n {pV P W 0 q | W 0 ∈ i=1 Wi }, {V })

225

A Generic Scheme for QCFLP

33

and ϕ = (f (en ) → t)]d ⇐ Π for some d ∈ DD \ {b}. By hypotheses, ρ is solution of Ω0 = (

n [

i=1

Ωi ) ∪ {qVal(V )} ∪ {pV P W 0 q | W 0 ∈

n [

i=1

Wi } ∪ {pd P V q}

which means, in particular, that Vρ ∈ DD \ {b}, since it must hold both qVal(V ) and pd P V q. Therefore the root of T will be f (e0 n , V )ρ → t ⇐ Π, with premises proof trees proving: 1. P T `C ( e0i ρ → ti θ ⇐ Π )i=1...n . 2. P T `C ( Vρ → W θ ⇐ Π ). Since Vρ ∈ DD \ {b} then either W θ = Vρ or W θ = b. By premise 4 below, W θ 6= b, therefore W θ = Vρ. 3. P T `C r0 θ → t ⇐ Π. 4. P T `C qVal(W θ) ⇐ Π. 5. P T `C Ωr θ ⇐ Π. 6. P T `C (pW P α ◦ W 0 q)W 0 ∈W00 θ ⇐ Π. 7. P T `C Ωδj θ ⇐ Π for j = 1 . . . m. 8. P T `C (pW P α ◦ Wj0 q)Wj0 ∈Wj0 θ ⇐ Π for j = 1 . . . m. 9. P T `C δj0 θ ⇐ Π for j = 1 . . . m. Then we can prove P `D,C ϕ by applying a QDFP inference step of the form: ( (ei → ti θ)]di ⇐ Π )i=1...n (rθ → t)]d00 ⇐ Π (f (en ) → t)]d ⇐ Π

( δj θ]d0j ⇐ Π )j=1...m

where d • di = d{Wρ | W ∈ Wi } for i = 1 . . . n. 0 • d0 = d{W θ | W ∈ W00 }. • d0j = {W θ | W ∈ Wj0 } for j = 1 . . . m. For proving P `D,C ϕ we need to check that • d P di (1 ≤ i ≤ n). Since ρ is solution of Ω 0 , d P Wρ, d and Wρ P W 0ρ for every W 0 ∈ Wi and every 1 ≤ i ≤ n. Therefore d P {ρ(W ) | W ∈ Wi } = di for i = 1 . . . n. • d P α ◦ d00 . Since ρ is solution of Ω 0 , d P Vρ = W dθ. From premise 6, W θ P α ◦ W 0 θ for every W 0 ∈ W00 . Therefore d P {W θ | W ∈ W00 } = d00 . • d P α ◦ d0j (1 ≤ j ≤ m). Analogous to the previous point but using premise 8. Finally, in order to justify the premises of the QDFP we must prove: • P `D,C (ei → ti θ)]di ⇐ Π, which is a consequence of applying the inductive hypotheses to the premises 1, ( e0i ρ → ti θ ⇐ Π )i=1...n , following the same reasoning we applied for the premises of the DC inference. • P `D,C (rθ → t)]d00 ⇐ Π. Analogously, is a consequence of the inductive hypothesis and of premise 3.

226

34

R. Caballero, M. Rodr´ıguez-Artalejo and C.A. Romero-D´ıaz

• P `D,C ( δj θ]d0j ⇐ Π )j=1...m . Again a consequence of the inductive hypothesis, this time applied to the premise 9. – PF. Analogous to the proof for the DC inference step. – AC. analogous to the proof for the DC inference step. t u Using Theorem 3 we can prove that the transformation of goals specified in Fig. 5 preserves solutions in the sense of the following result. Theorem 4. Let G be a goal for a given QCFLP(D, C)-program P. Then, the two following statements are equivalent: 1. hσ, µ, Πi ∈ SolP (G). 2. hσ ] µ ] ρ, Πi ∈ SolP T (GT ) for some ρ ∈ ValD such that vdom(ρ) is the set of new variables W introduced by the transformation of G. Proof. Let G = ( δi ]Wi , Wi Q βi )i=1...m , σ and µ be given. For i = 1 . . . m, consider δi T = (δi0 , Ωi , Wi ) and Ωi0 = Ωi ∪ {pWi P W q | W ∈ Wi }. According to Fig. 5, GT = (Ωi0 , qVal(Wi ), pWi Q βi q, δi0 )i=1...m . Then, because of Def. 9(2) and the analogous notion of solution for CFLP(C) goals explained in Sect. 3, the two statements of the theorem can be reformulated as follows: (a) Wi µ Q βi and P `D,C δi σ]Wi µ ⇐ Π hold Sm for i = 1 . . . m. (b) There exists ρ ∈ ValD with vdom(ρ) = i=1 var(Ωi ) such that ρ ∈ SolC (Ωi0 µ), Wi µ Q βi and P T `C (δi0 σ)ρ ⇐ Π hold for i = 1 . . . m. [(a) ⇒ (b)] Assume (a). Note that δi σ]Wi µ ⇐ Π T is δi0 σ ⇐ Π, Ωi0 µ. Applying Theorem 3 (with ψ = δi σ, d = Wi µ and Π) we obtain P T `C (δi0 σ)ρi ⇐ Π for someUρi ∈ SolC (Ωi0 µ) with vdom(ρi ) = var(Ωi0 µ) = var(Ωi ). Then (b) holds for m ρ = i=1 ρi .

[(b) ⇒ (a)] Assume (b). Let ρi = ρvar(Ωi ), i = 1 . . . m. Note that (b) ensures P T `C (δi0 σ)ρi ⇐ Π and ρ ∈ SolC (Ωi0 µ). Then Theorem 3 can be applied (again with ψ = δi σ, d = Wi µ and Π) to obtain P `D,C δi σ]Wi µ ⇐ Π. Therefore, (a) holds. t u As an example of goal solving via the transformation, we consider again the library program P and the goal G discussed in the Introduction. Both belong to the instance QCFLP(U, R) of our scheme. Their translation into CFLP(R) can be executed in the T OY system [3] after loading the Real Domain Constraints library (cflpr). The source and translated code are publicly available at gpd.sip.ucm.es/cromdia/qlp. Solving the transformed goal in T OY computes the answer announced in the Introduction as follows: Toy(R)> qVal([W]), W>=0.65, search("German","Essay",intermediate,W) == R { R -> 4 } { W=<0.7, W>=0.65 } sol.1, more solutions (y/n/d/a) [y]? no

The best qualification value for W provided by the answer constraints is 0.7.

227

A Generic Scheme for QCFLP

5

35

Conclusions

The work in this report is based on the scheme CFLP(C) for functional logic programming with constraints presented in [13]. Our main results are: a new programming scheme QCFLP(D, C) extending the first-order fragment of CFLP(C) with qualified computation capabilities; a rewriting logic QCRWL(D, C) characterizing QCFLP(D, C)-program semantics; and a transformation of QCFLP(D, C) into CFLP(C) preserving program semantics and goal solutions, that can be used as a correct implementation technique. Existing CFLP(C) systems such as T OY [3] and Curry [9] that use definitional trees as an efficient implementation tool can easily adopt the implementation, since the structure of definitional trees is quite obviously preserved by the transformation. As argued in the Introduction, our scheme is more expressive than the main related approaches we are aware of. By means of an example dealing with a simplified library, we have shown that instances of QCFLP(D, C) can serve as a declarative language for flexible information retrieval problems, where qualified (rather than exact) answers to user’s queries can be helpful. As future work we plan to extend QCFLP(D, C) and the program transformation in order to provide explicit support for similarity-based reasoning, as well as the higher-order programming features available in CFLP(C). We also plan to automate the program transformation, which should be embedded as part of an enhanced version of the T OY system. Finally, we plan further research on flexible information retrieval applications, using different instances of our scheme.

References 1. S. Antoy, R. Echahed, and M. Hanus. A needed narrowing strategy. Journal of the ACM, 47(4):776–822, 2000. 2. K. R. Apt. Logic programming. In J. van Leeuwen, editor, Handbook of Theoretical Computer Science, volume B: Formal Models and Semantics, pages 493–574. Elsevier and The MIT Press, 1990. 3. P. Arenas, A. J. Fern´ andez, A. Gil, F. J. L´ opez-Fraguas, M. Rodr´ıguez-Artalejo, and F. S´ aenz-P´erez. T OY, a multiparadigm declarative language. version 2.3.1, 2007. R. Caballero and J. S´ anchez (Eds.), Available at http://toy.sourceforge. net. 4. R. Caballero, M. Rodr´ıguez-Artalejo, and C. A. Romero-D´ıaz. Similarity-based reasoning in qualified logic programming. In PPDP ’08: Proceedings of the 10th international ACM SIGPLAN conference on Principles and Practice of Declarative Programming, pages 185–194, New York, NY, USA, 2008. ACM. 5. R. del Vado-V´ırseda. Declarative constraint programming with definitional trees. In B. Gramlich, editor, Proceedings of the 5th International Conference on Frontiers of Combining Systems (FroCoS’05), volume 3717 of LNCS, pages 184–199. Springer Verlag, 2005. 6. M. Gabbrielli, G. M. Dore, and G. Levi. Observable semantics for constraint logic programs. Journal of Logic and Computation, 5(2):133–171, 1995.

228

36

R. Caballero, M. Rodr´ıguez-Artalejo and C.A. Romero-D´ıaz

7. M. Gabbrielli and G. Levi. Modeling answer constraints in constraint logic programs. In Proceedings of the 8th International Conference on Logic Programming (ICLP’91), pages 238–252. The MIT Press, 1991. 8. S. Guadarrama, S. Mu˜ noz, and C. Vaucheret. Fuzzy prolog: A new approach using soft constraint propagation. Fuzzy Sets and Systems, 144(1):127–150, 2004. 9. M. Hanus. Curry: an integrated functional logic language, version 0.8.2, 2006. M. Hanus (Ed.), Available at http://www.informatik.uni-kiel.de/~curry/report. html. 10. J. Jaffar, M. Maher, K. Marriott, and P. J. Stuckey. Semantics of constraints logic programs. Journal of Logic Programming, 37(1-3):1–46, 1998. 11. J. W. Lloyd. Foundations of Logic Programming, Second Edition. Springer, 1987. 12. F. J. L´ opez-Fraguas, M. Rodr´ıguez-Artalejo, and R. del Vado-Virseda. A lazy narrowing calculus for declarative constraint programming. In Proceedings of the 6th International ACM SIGPLAN Conference on Principles and Practice of Declarative Programming (PPDP’04), pages 43–54. ACM Press, 2004. 13. F. J. L´ opez-Fraguas, M. Rodr´ıguez-Artalejo, and R. del Vado-V´ırseda. A new generic scheme for functional logic programming with constraints. Journal of Higher-Order and Symbolic Computation, 20(1&2):73–122, 2007. 14. G. Moreno and V. Pascual. Formal properties of needed narrowing with similarity relations. Electronic Notes in Theoretical Computer Science, 188:21–35, 2007. 15. S. Riezler. Quantitative constraint logic programming for weighted grammar applications. In C. Retor´e, editor, Proceedings of the Logical Aspects of Computational Linguistics (LACL’96), volume 1328 of LNCS, pages 346–365. Springer Verlag, 1996. 16. S. Riezler. Probabilistic Constraint Logic Programming. PhD thesis, Neuphilologischen Fakult¨ at del Universit¨ at T¨ ubingen, 1998. 17. M. Rodr´ıguez-Artalejo. Functional and constraint logic programming. In C. M. H. Comon and R. Treinen, editors, Constraints in Computational Logics, Theory and Applications, volume 2002 of Lecture Notes in Computer Science, pages 202– 270. Springer Verlag, 2001. 18. M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz. A generic scheme for qualified logic programming. Technical Report SIC-1-08, Universidad Complutense, Departamento de Sistemas Inform´ aticos y Computaci´ on, Madrid, Spain, 2008. 19. M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz. Quantitative logic programming revisited. In J. Garrigue and M. Hermenegildo, editors, Functional and Logic Programming (FLOPS’08), volume 4989 of LNCS, pages 272–288. Springer Verlag, 2008. 20. M. I. Sessa. Approximate reasoning by similarity-based SLD resolution. Theoretical Computer Science, 275(1-2):389–426, 2002. 21. V. S. Subrahmanian. Uncertainty in logic programming: Some recollections. Association for Logic Programming Newsletter, 20(2), 2007. 22. A. Tarski. A lattice-theoretical fixpoint theorem and its applications. Pacific Journal of Mathematics, 5(2):285–309, 1955.

229

Fixpoint & Proof-theoretic Semantics for CLP with Qualification and Proximity ∗ Technical Report SIC-1-10

MARIO RODR´IGUEZ-ARTALEJO and CARLOS A. ROMERO-D´IAZ Departamento de Sistemas Inform´ aticos y Computaci´ on, Universidad Complutense Facultad de Inform´ atica, 28040 Madrid, Spain (e-mail: mario@sip.ucm.es, cromdia@fdi.ucm.es)

Abstract Uncertainty in Logic Programming has been investigated during the last decades, dealing with various extensions of the classical LP paradigm and different applications. Existing proposals rely on different approaches, such as clause annotations based on uncertain truth values, qualification values as a generalization of uncertain truth values, and unification based on proximity relations. On the other hand, the CLP scheme has established itself as a powerful extension of LP that supports efficient computation over specialized domains while keeping a clean declarative semantics. In this report we propose a new scheme SQCLP designed as an extension of CLP that supports qualification values and proximity relations. We show that several previous proposals can be viewed as particular cases of the new scheme, obtained by partial instantiation. We present a declarative semantics for SQCLP that is based on observables, providing fixpoint and proof-theoretical characterizations of least program models as well as an implementation-independent notion of goal solutions. KEYWORDS: Constraint Logic Programming, Qualification Domains and Values, Proximity Relations.

1 Introduction Many extensions of logic programming (shortly LP) to deal with uncertainty have been proposed in the last decades. A line of research not related to this report is based on probabilistic extensions of LP such as (Ng and Subrahmanian 1992). Other proposals in the field replace classical two-valued logic by some kind of many-valued logic whose truth values can be attached to computed answers and are usually interpreted as certainty degrees. The next paragraphs summarize some relevant approaches of this kind. There are extensions of LP using annotations in program clauses to compute a certainty degree for the head atom from the certainty degrees previously computed ∗ This work has been partially supported by the Spanish projects STAMP (TIN2008-06622-C0301), PROMETIDOS–CM (S2009TIC-1465) and GPD–UCM (UCM–BSCH–GR58/08-910502).

230

2

M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz

for the body atoms. This line of research includes the seminal proposal of Quantitative Logic Programming by (van Emden 1986) and inspired later works such as the Generalized Annotated logic Programs (shortly GAP) by (Kifer and Subrahmanian 1992) and the QLP scheme for Qualified LP (Rodr´ıguez-Artalejo and Romero-D´ıaz 2008b). While (van Emden 1986) and other early approaches used real numbers of the interval [0, 1] as certainty degrees, QLP and GAP take elements from a parametrically given lattice to be used in annotations and attached to computed answers. In the case of QLP, the lattice is called a qualification domain and its elements (called qualification values) are not always understood as certainty degrees. As argued in (Rodr´ıguez-Artalejo and Romero-D´ıaz 2008b), GAP is a more general framework, but QLP’s semantics have some advantages for its intended scope. There are also extended LP languages based on fuzzy logic (Zadeh 1965; H´ ajek 1998), which can be classified into two major lines. The first line includes Fuzzy LP languages such as (Vojt´aˇs 2001; Vaucheret et al. 2002; Guadarrama et al. 2004) and the Multi-Adjoint LP (shortly MALP) framework by (Medina et al. 2001a; Medina et al. 2001b). All these approaches extend classical LP by using clause annotations and a fuzzy interpretation of the connectives and aggregation operators occurring in program clauses and goals. There is a relationship between Fuzzy LP and GAP that has been investigated in (Krajˇci et al. 2004). Intended applications of Fuzzy LP languages include expert knowledge representation. The second line includes Similarity-based LP (shortly SLP) in the sense of (Arcelli and Formato 1999; Sessa 2002; Loia et al. 2004) and related proposals, which keep the classical syntax of LP clauses but use a similarity relation over a set of symbols S to allow “flexible” unification of syntactically different symbols with a certain approximation degree. Similarity relations over a given set S have been defined in (Zadeh 1971; Sessa 2002) and related literature as fuzzy relations represented by mappings S : S × S → [0, 1] which satisfy reflexivity, symmetry and transitivity axioms analogous to those required for classical equivalence relations. A more general notion called proximity relation was introduced in (Dubois and Prade 1980) by omitting the transitivity axiom. As noted by (Shenoi and Melton 1999) and other authors, the transitivity property required for similarity relations may conflict with user’s intentions in some cases. The Bousi∼Prolog language (Juli´ an-Iranzo et al. 2009; Juli´ an-Iranzo and Rubio-Manzano 2009b; Juli´ an-Iranzo and Rubio-Manzano 2009a) has been designed with the aim of generalizing SLP to work with proximity relations. A different generalization of SLP is the SQLP scheme (Caballero et al. 2008), designed as an extension of the QLP scheme. In addition to clause annotations in QLP style, SQLP uses a given similarity relation S : S × S → D (where D is the carrier set of a parametrically given qualification domain) in order to support flexible unification. In the sequel we use the acronym SLP as including proximity-based LP languages also. Intended applications of SLP include flexible query answering. An analogy of proximity relations in a different context (namely partial constraint satisfaction) can be found in (Freuder and Wallace 1992), where several metrics are proposed to measure the proximity between the solution sets of two different constraint satisfaction problems. Several of the above mentioned LP extensions (including GAP, QLP, the Fuzzy

231

Fixpoint & Proof-theoretic Semantics for SQCLP

3

LP language in (Guadarrama et al. 2004) and SQLP) have used constraint solving as an implementation technique. However, we only know two approaches which have been conceived as extensions of the classical CLP scheme (Jaffar and Lassez 1987). Firstly, (Riezler 1996; Riezler 1998) extended the formulation of CLP by (H¨ohfeld and Smolka 1988) with quantitative LP in the sense of (van Emden 1986); this work was motivated by problems from the field of natural language processing. Secondly, (Bistarelli et al. 2001) proposed a semiring-based approach to CLP, where constraints are solved in a soft way with levels of consistency represented by values of a semiring. This approach was motivated by constraint satisfaction problems and implemented with clp(FD,S) in (Georget and Codognet 1998) for a particular class of semirings which enable to use local consistency algorithms. The relationship between (Riezler 1996; Riezler 1998; Bistarelli et al. 2001) and the results of this report will be further discussed in Section 4. Finally, there are a few preliminary attempts to combine some of the above mentioned approaches with the Functional Logic Programming (shortly FLP) paradigm found in languages such as Curry (Hanus ) and T OY (Arenas et al. 2007). Similaritybased unification for FLP languages has been investigated by (Moreno and Pascual 2007), while (Caballero et al. 2009) have proposed a generic scheme QCFLP designed as a common extension of the two schemes CLP and QLP with first-order FLP features. In this report we propose a new extension of CLP that supports qualification values and proximity relations. More precisely, we define a generic scheme SQCLP whose instances SQCLP(S, D, C) are parameterized by a proximity relation S, a qualification domain D and a constraint domain C. We will show that several previous proposals can be viewed as particular cases of SQCLP, obtained by partial instantiation. Moreover, we will present a declarative semantics for SQCLP that is inspired in the observable CLP semantics by (Gabbrielli and Levi 1991; Gabbrielli et al. 1995) and provides fixpoint and proof-theoretical characterizations of least program models as well as an implementation-independent notion of goal solution that can be used to specify the expected behavior of goal solving systems. The reader is assumed to be familiar with the semantic foundations of LP (Lloyd 1987; Apt 1990) and CLP (Jaffar and Lassez 1987; Jaffar et al. 1998). The rest of the report is structured as follows: Section 2 introduces constraint domains, qualification domains and proximity relations. Section 3 presents the SQCLP scheme and the main results on its declarative semantics. Finally, Section 4 concludes by giving an overview of related approaches (many of which can be viewed as particular cases of SQCLP) and pointing to some lines open for future work.

2 Constraints, Qualification & Proximity 2.1 Constraint Domains The Constraint Logic Programming paradigm (CLP) was introduced in (Jaffar and Lassez 1987) with the aim of generalizing the Herbrand Universe which underlies classical Logic Programming (LP) to other domains tailored to specific applica-

232

4

M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz

tion areas. In this seminal paper, CLP was introduced as a generic scheme with instances CLP(C) parameterized by constraint domains C, each of which supplies several items: a constraint language providing a class of domain specific formulae, called constraints and serving as logical conditions in CLP(C) programs and computations; a constraint structure serving as interpretation of the constraint language; a constraint theory serving as a basis for proof-theoretical deduction with constraints; and a constraint solver for checking constraint satisfiability. Certain assumptions were made to ensure the proper relationship between the constraint language, structure, theory and solver, so that the classical results on the operational and declarative semantics of LP (Lloyd 1987; Apt 1990) could be extended to all the CLP(C) languages. A revised and updated presentation of the main results from (Jaffar and Lassez 1987) can be found in (Jaffar et al. 1998), while a survey of CLP as a programming paradigm is given in (Jaffar and Maher 1994). The notion of constraint domain is a key ingredient of the CLP scheme. In addition to the classical formulation in (Jaffar and Lassez 1987; Jaffar et al. 1998), other formalizations have been used for different purposes. Some significative examples are: the CLP scheme proposed in (H¨ohfeld and Smolka 1988), motivated by applications to computational linguistics and allowing more than one constraint structure to come along with a given constraint language; the proof-theoretical notion of constraint system given in (Saraswat 1992), intended for application to concurrent constraint languages; and the constraint systems proposed in (Lucio et al. 2008) as the basis of a functorial semantics for CLP with negation, where a single constraint structure is replaced by a class of elementary equivalent structures. In this paper we will use a simple notion of constraint domain, motivated by three main considerations: firstly, to focus on declarative semantics, rather than prooftheoretic or operational issues; secondly, to provide a purely relational framework; and thirdly, to clarify the interplay between domain-specific programming resources such as basic values and primitive predicates, and general-purpose programming resources such as data constructors and defined predicates. 2.1.1 Preliminary notions Before presenting constraint domains in a formal way, let us introduce some mainly syntactic notions that will be used all along the paper. Definition 2.1 (Signatures) We assume a universal programming signature Γ = hDC, DP i where DC = S S n and DP = n∈N DP n are infinite and mutually disjoint sets of free n∈N DC function symbols (called data constructors in the sequel) and defined predicate symbols, respectively, ranked by arities. We will use domain specific signatures S Σ = hDC, DP, P P i extending Γ with a disjoint set P P = n∈N P P n of primitive predicate symbols, also ranked by arities. The idea is that primitive predicates come along with constraint domains, while defined predicates are specified in user programs. Each P P n maybe any countable set of n-ary predicate symbols. In practice, P P is expected to be a finite set.

233

Fixpoint & Proof-theoretic Semantics for SQCLP

5

In the sequel, we assume that any signature Σ includes two nullary constructors true, false ∈ DC 0 to represent the boolean values, a binary constructor pair ∈ DC 2 to represent ordered pairs, as well as constructors to represent lists and other common data structures. Given a signature Σ, a set B of basic values u and a countably infinite set Var of variables X, terms and atoms are built as defined below, where on abbreviates the n-tuple of syntactic objects o1 , . . . , on and var(o) denotes the set of all variables occurring in the syntactic object o. Definition 2.2 (Terms and atoms) • Constructor Terms t ∈ Term(Σ, B, Var) have the syntax t ::= X|u|c(tn ), where c ∈ DC n . They will be called just terms in the sequel. In concrete examples, we will use Prolog syntax for terms built with list constructors, and we will write (t1 , t2 ) rather than pair(t1 , t2 ) for terms representing ordered pairs. • The set of all the variables occurring in t is noted as var(t). A term t is called ground iff var(t) = ∅. Term(Σ, B) stands for the set of all ground terms. • Atoms A ∈ At(Σ, B, Var) can be defined atoms r(tn ), where r ∈ DP n and ti ∈ Term(Σ, B, Var) (1 ≤ i ≤ n); primitive atoms p(tn ), where p ∈ P P n and ti ∈ Term(Σ, B, Var) (1 ≤ i ≤ n); and equations t1 == t2 , where t1 , t2 ∈ Term(Σ, B, Var) and ‘==’ is the equality symbol, which does not belong to the signature Σ. Primitive atoms are noted as κ and the set of all primitive atoms is noted PAt(Σ, B, Var). Equations and primitive atoms are collectivelly called C-based atoms. • The set of all the variables occurring in A is noted as var(A). An atom A is called ground iff var(A) = ∅. The set of all ground atoms (resp. ground primitive atoms) is noted as GAt(Σ, B) (resp. GPAt(Σ, B)). Note that the equality symbol ‘==’ used as part of the syntax of equational atoms is not the same as the symbol ‘=’ generally used for mathematical equality. In particular, metalevel equations o = o0 can be used to assert the identity of two syntactical objects o and o0 . Following well-known ideas, the syntactical structure of terms and atoms can be represented by means of trees with nodes labeled by signature symbols, basic values and variables. In the sequel we will use the notation ktk to denote the syntactical size of t measured as the number of nodes in the tree representation of t. The positions of nodes in this tree can be noted as finite sequences p of natural numbers. In particular, the empty sequence ε represents the root position. The next definition presents essential notions concerning positions in terms. Positions in atoms can be treated similarly. Definition 2.3 (Positions) 1. The set pos(t) of positions of the term t is defined by recursion on the structure of t: • pos(X) = {ε} for each variable X ∈ Var. • pos(u) = {ε} for each basic value u ∈ B. Sn • pos(c(tn )) = {ε} ∪ i=1 {iq | q ∈ pos(ti )} for each c ∈ DC n .

234

6

M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz 2. Given p ∈ pos(t), the symbol t ◦ p of t at position p is defined recursively: • • • •

X ◦ ε = X for each variable X ∈ Var. u ◦ ε = u for each basic value u ∈ B. c(t1 , . . . , tn ) ◦ ε = c if c ∈ DC n . c(t1 , . . . , tn ) ◦ iq = ti ◦ q if c ∈ DC n , 1 ≤ i ≤ n and q ∈ vpos(ti ).

3. Given p ∈ pos(t), the subterm t|p of t at position p is defined as follows: • t|ε = t for any t. • c(t1 , . . . , tn )|iq = ti |q if c ∈ DC n , 1 ≤ i ≤ n and q ∈ pos(ti ). 4. p ∈ pos(t) is called a variable position of t iff t|p is a variable, and a rigid position of t otherwise. We define vpos(t) = {p ∈ pos(t) | p is a variable position} and rpos(t) = {p ∈ pos(t) | p is a rigid position}. 5. Given p ∈ vpos(t) and another term s, the result of replacing s for the subterm of t at position p is noted as t[s]p . See e.g. (Baader and Nipkow 1998) for a recursive definition. As usual, substitutions are defined as mappings σ : Var → Term(Σ, B, Var) assigning terms to variables. The set of all substitutions is noted as Subst(Σ, B, Var). Substitutions are extended to act over terms and other syntactic objects o in the natural way. By convention, the result of replacing each variable X occurring in o by σ(X) is noted as oσ. Other common notions concerning substitutions are defined as follows: Definition 2.4 (Notions concerning Substitutions) • The composition σσ 0 of two substitutions is such that o(σσ 0 ) equals (oσ)σ 0 . • For a given σ ∈ Subst(Σ, B, Var), the domain dom(σ) is defined as {X ∈ Var | S Xσ 6= X}, and the variable range vran(σ) is defined as X∈dom(σ) var(Xσ). • A substitution σ is called ground iff Xσ is a ground term for all X ∈ dom(σ). The set of all ground substitutions is noted GSubst(Σ, B). • A substitution σ is called finite iff dom(σ) is a finite set, say {X1 , . . . , Xk }. In this case, σ can be represented as the set of bindings {X1 7→ t1 , . . . , Xk 7→ tk }, where ti = Xi σ for all 1 ≤ i ≤ k. • Assume two substitutions σ, σ 0 , a set of variables X and a variable Y . The notation σ =X σ 0 means that Xσ = Xσ 0 holds for all variables X ∈ X . We also write σ =\X σ 0 and σ =\Y σ 0 to abbreviate σ =Var\X σ 0 and σ =Var\{Y } σ 0 , respectively. 2.1.2 Constraint domains, constraints and their solutions We are now prepared to present constraint domains as mathematical structures providing a set of basic values along with an terms and an interpretation of primitive predicates1 . The formal definition is as follows: 1

As we will see in Section 3, the interpretation of defined predicate symbols is program dependent.

235

Fixpoint & Proof-theoretic Semantics for SQCLP

7

Definition 2.5 (Constraint Domains) A Constraint Domain of signature Σ is any relational structure of the form C = hC, {pC | p ∈ P P }i such that: 1. The carrier set C is Term(Σ, B) for a certain set B of basic values. When convenient, we note B and C as BC and CC , respectively. 2. pC : C n → {0, 1}, written simply as pC ∈ {0, 1} in the case n = 0, is called the interpretation of p in C. A ground primitive atom p(tn ) is true in C iff pC (tn ) = 1; otherwise p(tn ) is false in C. For the examples in this paper we will use a constraint domain R which allows to work with arithmetic constraints over the real numbers, as formalized in Definition 2.6 below. Definition 2.6 (The Real Constraint Domain R) The constraint domain R is defined to include: • The set of basic values BR = R. Note that CR includes ground terms built from real values and data constructors, in addition to real numbers. • Primitive predicates for encoding the usual arithmetic operations over R. For instance, the addition operation + over R is encoded by a ternary primitive predicate op+ such that, for any t1 , t2 ∈ CR , op+ (t1 , t2 , t) is true in R iff t1 , t2 , t ∈ R and t1 + t2 = t. In particular, op+ (t1 , t2 , t) is false in R if either t1 or t2 includes data constructors. The primitive predicates encoding other arithmetic operations such as × and − are defined analogously. • Primitive predicates for encoding the usual inequality relations over R. For instance, the ordering ≤ over R is encoded by a binary primitive predicate cp≤ such that, for any t1 , t2 ∈ CR , cp≤ (t1 , t2 ) is true in R iff t1 , t2 , t ∈ R and t1 ≤ t2 . In particular, cp≤ (t1 , t2 ) is false in R if either t1 or t2 includes data constructors. The primitive predicates encoding the other inequality relations, namely >, ≥ and >, are defined analogously. The domain R is well known as the basis of the CLP(R) language and system (Jaffar et al. 1992). Some presentations of R known in the literature represent the arithmetical operations by using primitive functions instead of primitive predicates. In this paper we have chosen to work in a purely relational framework in order to simplify some technicalities without loss of real expressivity. Other useful instances of constraint domains are known in the Constraint Programming literature; see e.g. (Jaffar and Maher 1994; L´ opez-Fraguas et al. 2007). In particular, the Herbrand domain H is intended to work just with equality constraints, while FD allows to work with constraints involving finite domain variables. The set of basic values of FD is Z. There are also known techniques for combining several given constraint domains into a more expressive one; see e.g. the coordination domains defined in (Est´evez-Mart´ın et al. 2009). The following definition introduces constraints over a given domain:

236

8

M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz

Definition 2.7 (Constraints and Their Solutions) Given a constraint domain C of signature Σ: 1. Atomic constraints over C are of two kinds: primitive atoms p(tn ) and equations t1 == t2 . 2. Compound constraints are built from atomic constraints using logical conjunction ∧, existential quantification ∃, and sometimes other logical operations. Constraints of the form ∃X1 . . . ∃Xn (B1 ∧ . . . ∧ Bm ) –where Bj (1 ≤ j ≤ m) are atomic– are called existential. The set of all constraints over C is noted ConC . 3. Substitutions σ : Var → Term(Σ, B, Var) where Term(Σ, B, Var) is built using the set BC of basic values are called C-substitutions. Ground substitutions η ∈ GSubst(Σ, B) are called variable valuations. The set of all possible variable valuations is noted ValC . 4. The solution set SolC (π) of a constraint π ∈ ConC is defined by recursion on π’s syntactic structure as follows: • If π is a primitive atom p(tn ), then SolC (π) is the set of all η ∈ ValC such that p(tn )η is ground and true in C. • If π is an equation t1 == t2 , then SolC (π) is the set of all η ∈ ValC such that t1 η and t2 η are ground and syntactically identical terms. • If π is π1 ∧ π2 then SolC (π) = SolC (π1 ) ∩ SolC (π2 ). • If π is ∃Xπ 0 then SolC (π) is the set of all η ∈ ValC such that η 0 ∈ SolC (π 0 ) holds for some η 0 ∈ ValC verifying η =\X η 0 . π is called satisfiable over C iff SolC (π) 6= ∅, and π is called unsatisfiable over C iff SolC (π) = ∅. T 5. The solution set SolC (Π) of a set Π of constraints is defined as π∈Π SolC (π). In this way, finite sets of constraints are interpreted as the conjunction of their members. Π is called satisfiable over C iff SolC (Π) 6= ∅, and Π is called unsatisfiable over C iff SolC (Π) = ∅. 6. A constraint π is entailed by a set of constraints Π (in symbols, Π |=C π) iff SolC (Π) ⊆ SolC (π). The following example illustrates the previous definition: Example 2.1 (Constraint solutions and constraint entailment over R) Consider the set of constraints Π = {cp≥ (A, 3.0), op+ (A, A, X), op× (2.0, A, Y )} ⊆ ConR . Then: 1. For any valuation η ∈ ValR : η ∈ SolR (Π) holds iff η(A), η(X) and η(Y ) are real numbers a, x, y ∈ R such that a ≥ 3.0, a + a = x and 2.0 × a = y. 2. Due to the previous item, the following R-entailments are valid: (a) Π |=R cp> (X, 5.5), because SolR (Π) ⊆ SolR (cp> (X, 5.5)). (b) Π |=R X == Y , because SolR (Π) ⊆ SolR (X == Y). (c) Π |=R c(X) == c(Y ), because SolR (Π) ⊆ SolR (c(X) == c(Y)). Here we assume c ∈ DC 1 .

237

Fixpoint & Proof-theoretic Semantics for SQCLP

9

(d) Π |=R [X, Y ] == [Y, X], because SolR (Π) ⊆ SolR ([X,Y] == [Y,X]). Here, the terms [X, Y ] and [Y, X] are built from variables and list constructors. The next technical result will be useful later on: Lemma 2.1 (Substitution Lemma) Assume a set of constraints Π ⊆ ConC and a C-substitution σ. Then: 1. For any valuation η ∈ ValC : η ∈ SolC (Πσ) ⇐⇒ ση ∈ SolC (Π). 2. For any constraint π ∈ ConC : Π |=C π =⇒ Πσ |=C πσ. Proof Let us give a separate reasoning for each item. 1. The following statement holds for any constraint π ∈ ConC : (?) η ∈ SolC (πσ) ⇐⇒ ση ∈ SolC (π) In fact, (?) can can be easily proved reasoning by induction on the syntactic structure of π. Now, using (?) we can reason as follows: η ∈ SolC (Πσ) ⇐⇒ η ∈ SolC (πσ) for all π ∈ Π ⇐⇒(?) ση ∈ SolC (π) for all π ∈ Π ⇐⇒ ση ∈ SolC (Π) 2. Assume Π |=C π. For the sake of proving Πσ |=C πσ, also assume an arbitrary η ∈ SolC (Πσ). Then we get ση ∈ SolC (Π) because of item 1 and ση ∈ SolC (π) due to the assumption Π |=C π, which implies η ∈ SolC (πσ) again because of item 1. Since η is arbitrary, we have proved SolC (Πσ) ⊆ SolC (πσ), i.e. Πσ |=C πσ. 2.1.3 Term equivalence w.r.t. a given constraint set Given two terms t, s we will use the notation t ≈Π s (read as t and s are Πequivalent) as an abbreviation of Π |=C t == s, assuming that the constraint domain C and the constraint set Π ⊆ ConC are known. For the sake of simplicity, C is not made explicit in the ≈Π notation. In this subsection we present some properties related to ≈Π which will be needed later. First, we prove that ≈Π is an equivalence relation with a natural characterization. Lemma 2.2 (Π-Equivalence Lemma) 1. ≈Π is an equivalence relation over Term(Σ, B, Var). 2. For any given terms t and s the following two statements are equivalent: (a) t ≈Π s. (b) For any common position p ∈ pos(t) ∩ pos(s) some of the cases below holds: i t ◦ p or s ◦ p is a variable, and moreover t|p ≈Π s|p . ii t ◦ p = s ◦ p = u for some u ∈ BC . iii t ◦ p = s ◦ p = c for some n ∈ N and some c ∈ DC n . 3. ≈Π boils down to the syntactic equality relation = when Π is the empty set.

238

10

M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz

Proof We give a separate reasoning for each item. 1. Checking that ≈Π satisfies the axioms of an equivalence relation (i.e. reflexivity, symmetry and transitivity) is quite obvious. 2. Due to Definition 2.7, t ≈Π s holds iff tη and sη are identical ground terms for each η ∈ SolC (Π). This statement can be proved equivalent to condition 2.(b) reasoning by induction on ktk + ksk. 3. Note that t ≈∅ s holds iff tη and sη are identical ground terms for each η ∈ SolC (∅) = ValC . This can happen iff t and s are syntactically identical. Since the set Var of all variables is countably infinite, we can assume an arbitrarily fixed bijective mapping ord : Var → N. By convention, ord(X) is called the ordinal number of X. The notions defined below rely on this convention. Definition 2.8 (Π-Canonical Variables and Terms) 1. A variable X is called Π-canonical iff there is no other variable X 0 such that X ≈Π X 0 and ord(X 0 ) < ord(X). 2. For each variable X its Π-canonical form cfΠ (X) is defined as the member of the set {X 0 ∈ Var | X ≈Π X 0 } with the least ordinal number. 3. A term t is called Π-canonical iff all the variables occurring in t are Πcanonical. 4. For each term t its Π-canonical form cfΠ (t) is defined as the result of replacing cfΠ (X) for each variable X occurring in t. The following lemma states some obvious properties of terms in canonical form: Lemma 2.3 (Π-Canonicity Lemma) For each term t, cfΠ (t) is Π-canonical and such that t ≈ Π cfΠ (t). Moreover, t and cfΠ (t) have the same positions and structure, except that each variable X occurring at some position p ∈ vpos(t) is replaced by an occurrence of cfΠ (X) at the same position p in cfΠ (t). Proof Straightforward consequence of the construction of cfΠ (t) from t and the Π-Equivalence Lemma 2.2. Given two terms t and s, the term built from t by replacing within t each variable X occurring at some position p ∈ vpos(t) ∩ pos(s) by the subterm s|p is called the extension of t w.r.t. to s and noted as t  s (or equivalently, s  t). A more precise definition of this notion and some related properties are given below. Definition 2.9 (Term extension) Given any two terms t and s, the extension of t w.r.t. s is defined by recursion on the syntactical structure of t: • X  s = s for each variable X ∈ Var. • u  s = u for each basic value u ∈ B.

239

Fixpoint & Proof-theoretic Semantics for SQCLP

11

• c(t1 , . . . , tn )  s = c(t1  s1 , . . . , tn  sn ) if c ∈ DC n and there is some c0 ∈ DC n such that s = c0 (s1 , . . . , sn ). • c(t1 , . . . , tn )  s = c(t1 , . . . , tn ) if c ∈ DC n and there is no c0 ∈ DC n such that s = c0 (s1 , . . . , sn ). Lemma 2.4 (Extension Lemma) The term extension operation  enjoys the two following properties: 1. Symmetrical Extension Property: Let t0 , t00 be Π-canonical terms such that t0 ≈Π t00 . Under this assumption (t0  t00 ) = (t00  t0 ). 2. Π-Equivalence Extension Property: Let the terms t, s be such that for any p ∈ pos(t) with t|p = X ∈ Var one has p ∈ pos(s) and X ≈Π s|p . Under this assumption t ≈Π (t  s). Proof of Symmetrical Extension Property Recall that the hypothesis t0 ≈Π t00 means that Π |=C t0 == t00 . We reason by complete induction on kt0 k + kt00 k. There are five possible cases: 1. t0 == t00 is c0 (t0 n ) == c00 (t00 n ) for some n ∈ N, c0 , c00 ∈ DC n . In this case, the Π-Equivalence Lemma 2.2 ensures that c0 = c00 = c ∈ DC n and t0i ≈Π t00i holds for all 1 ≤ i ≤ n. Clearly, the terms t0i , t00i are Π-canonical. Therefore, by induction hypothesis we can assume (t0i  t00i ) = (t00i  t0i ) for all 1 ≤ i ≤ n. Then, by definition of  we get t0  t00 = c(t01  t001 , . . . , t0n  t00n ) = c(t001  t01 , . . . , t00n  t0n ) = t00  t0 . 2. t0 == t00 is u0 == u00 for some u0 , u00 ∈ B. In this case, u0 ≈Π u00 implies that u0 = u00 = u ∈ B, and by definition of  we get t0  t00 = t00  t0 = u  u = u. 3. t0 == t00 is X == Y for some X, Y ∈ Var. In this case, X ≈Π Y and X, Y Πcanonical implies that X, Y must be identical variables. By definition of  we get t0  t00 = t00  t0 = X  X = X. 4. t0 == t00 is X == t00 with X ∈ Var, t00 ∈ / Var. In this case, by definition of  we get t0  t00 = X  t00 = t00 and t00  t0 = t00  X = t00 . 5. t0 == t00 is t0 == Y with Y ∈ Var, t0 ∈ / Var. In this case, by definition of  we get t0  t00 = t0  Y = t0 = t00 and t00  t0 = Y  t0 = t0 . Proof of Π-Equivalence Extension Property Recall that the thesis t ≈Π (t  s) means that Π |=C t == (t  s). We reason by complete induction on ktk. There are four possible cases: 1. t is a variable X ∈ Var. In this case, X  s = s by definition of , and X ≈Π s holds by hypothesis. 2. t is a basic value u ∈ B. In this case, u  s = u by definition of , and u ≈Π u holds trivially. 3. t is c(tn ) for some c ∈ DC n and there is no c0 ∈ DC n such that s has the form c0 (sn ). In this case, c(tn )  s = c(tn ) by definition of , and c(tn ) ≈Π c(tn ) holds trivially.

240

12

M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz

4. t is c(tn ) for some c ∈ DC n and s is c0 (sn ) for some c0 ∈ DC n . In this case c(tn )  c0 (sn ) = c(t1  s1 , . . . , tn  sn ) by definition of . Moreover, the assumptions of the Π-Equivalent Extension Property hold for the smaller terms ti , si (1 ≤ i ≤ n). By induction hypothesis we can assume ti ≈Π (ti  si ) for all 1 ≤ i ≤ n. Therefore, c(tn ) ≈Π c(t1  s1 , . . . , tn  sn ) due to the Π-Equivalence Lemma 2.2. 2.2 Qualification Domains The intended role of Qualification Domains in an extended logic programming scheme SQCLP have been already explained in the Introduction. They were originally introduced in (Rodr´ıguez-Artalejo and Romero-D´ıaz 2008b) and their axiomatic definition was extended with axioms for an additional operation in (Rodr´ıguez-Artalejo and Romero-D´ıaz 2009) in order to enable a particular implementation technique for program clauses with threshold conditions in their bodies. The definition given below is again closer to the original one: is omitted and the axioms of the operator ◦ are slightly refined. Definition 2.10 (Qualification Domains) A Qualification Domain is any structure D = hD, P, b, t, ◦i verifying the following requirements: 1. D, noted as DD when convenient, is a set of elements called qualification values. 2. hD, P, b, ti is a lattice with extreme points b (called infimum or bottom element) and t (called maximum or top element) w.r.t. the partial ordering P, called qualification ordering. For given elements d, e ∈ D, we write d u e for the greatest lower bound (glb) of d and e, and d t e for the least upper bound (lub) of d and e. We also write d C e as abbreviation for d P e ∧ d 6= e. 3. ◦ : D × D → D, called attenuation operation, verifies the following axioms: (a) (b) (c) (d) (e)

◦ is associative, commutative and monotonic w.r.t. P. ∀d ∈ D : d ◦ t = d. ∀d ∈ D : d ◦ b = b. ∀d, e ∈ D : d ◦ e P e. ∀d, e1 , e2 ∈ D : d ◦ (e1 u e2 ) = (d ◦ e1 ) u (d ◦ e2 ).

Actually, some of the properties of ◦ postulated as axioms in the previous definition are redundant.2 More precisely: Proposition 2.1 (Redundant postulates of Qualification Domains) The properties (3)(c) and (3)(d) are redundant and can be derived from the other axioms in Definition 2.10.

2

The authors are thankful to G. Gerla for pointing out this fact.

241

Fixpoint & Proof-theoretic Semantics for SQCLP

13

Proof Note that ◦ is commutative and monotonic w.r.t. P because of axiom (3)(a). Since t is the top element of the lattice, d P t holds for any d ∈ D. By monotonicity of ◦, d ◦ e P t ◦ e also holds for any e ∈ D. By commutativity of ◦ and axiom (3)(b), d ◦ e P t ◦ e is the same as d ◦ e P e. Therefore (3)(d) is a consequence of the other axioms postulated for ◦. In particular, taking e = b we get d ◦ b P b, which implies d ◦ b = b because b is the bottom element of the lattice. Hence, (3)(c) also follows form the other axioms. In the rest of the report, D will generally denote an arbitrary qualification domain. For any finite S = {e1 , e2 , . . . , en } ⊆ D, the greatest lower bound (also called d infimum of S and noted as S) exists and can be computed as e1 u e2 u · · · u en (which reduces to > in the case n = 0). The dual claim concerning least upper bounds is also true. As an easy consequence of the axioms, one gets the identity d d d ◦ S = {d ◦ e | e ∈ S}. Many useful qualification domains are such that ∀d, e ∈ D \ {b} : d ◦ e 6= b. In the sequel, any qualification domain D that verifies this property will be called stable. Below we present some basic qualification domains which are clearly stable, along with brief explanations of their role for building extended CLP languages as instances of the SQCLP scheme proposed in this report. Checking that these domains satisfy the axioms given in Def. 2.10 is left as an easy exercise. In fact, the axioms have been chosen as a natural generalization of some basic properties satisfied by the ordering ≤ and the operation × over the real interval [0, 1]. 2.2.1 The Domain B of Classical Boolean Values This domain is B =def h{0, 1}, ≤, 0, 1, ∧i, where 0 and 1 stand for the two classical truth values false and true, ≤ is the usual numerical ordering over {0, 1}, and ∧ stands for the classical conjunction operation over {0, 1}. 2.2.2 The Domain U of Uncertainty Values and its variant U 0 This domain is U =def hU, ≤, 0, 1, ×i, where U = [0, 1] = {d ∈ R | 0 ≤ d ≤ 1}, ≤ is the usual numerical ordering, and × is the multiplication operation. The top d element t is 1 and the greatest lower bound S of a finite S ⊆ U is the minimum value min(S), which is 1 if S = ∅. Elements of U are intended to represent certainty degrees as used in (van Emden 1986). A slightly different domain U 0 can be defined as hU, ≤, 0, 1, mini where the only difference with respect to U is that in the case of U 0 , ◦ = min. 2.2.3 The Domain W of Weight Values and related variants This domain is W =def hP, ≥, ∞, 0, +i, where P = [0, ∞] = {d ∈ R ∪ {∞} | d ≥ 0}, ≥ is the reverse of the usual numerical ordering (with ∞ ≥ d for any d ∈ P), and + is the addition operation (with ∞ + d = d + ∞ = ∞ for any d ∈ P). The top

242

14

M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz

d element t is 0 and the greatest lower bound S of a finite S ⊆ P is the maximum value max(S), which is 0 if S = ∅. Elements of W are intended to represent proof costs, measured as the weighted depth of proof trees. In analogy to the definition of U 0 as a variant of U, we can define a qualification domain W 0 as hP, ≥, ∞, 0, maxi with ◦ = max. Also, as a discrete variant of W, we define the qualification domain Wd =def hP, ≥, ∞, 0, +i with the only difference w.r.t. W being that P = N ∪ {∞}. Elements of Wd are also intended to represent proof costs (represented by natural numbers in this case). Finally, a variant Wd0 of Wd can be defined by replacing the attenuation operation in Wd by max. 2.2.4 Two product constructions To close this section, we present two product constructions that can be used to build compound qualification domains. The mathematical definition is as follows: Definition 2.11 (Products of Qualification Domains) Let two qualification domains Di = hDi , Pi , bi , ti , ◦i i (i ∈ {1, 2}) be given.

1. The cartesian product D1 × D2 is defined as D =def hD, P, b, t, ◦i where D =def D1×D2 , the partial ordering P is defined as (d1 , d2 ) P (e1 , e2 ) ⇐⇒def d1 P1 e1 and d2 P2 e2 , b =def (b1 , b2 ), t =def (t1 , t2 ) and the attenuation operator ◦ is defined as (d1 , d2 ) ◦ (e1 , e2 ) =def (d1 ◦1 e1 , d2 ◦2 e2 ). 2. Given two elements d1 ∈ D1 and d2 ∈ D2 , the strict pair L d1 , d2 M is defined by case distinction as follows: if d1 6= b1 and d2 6= b2 , then L d1 , d2 M = (d1 , d2 ); if d1 = b1 or d2 = b2 , then L d1 , d2 M = (b1 , b2 ). In both cases, L d1 , d2 M ∈ D1 × D2 . 3. The strict cartesian product D1 ⊗ D2 is defined as D =def hD, P, b, t, ◦i where D = D1 ⊗ D2 =def {L d1 , d2 M | d1 ∈ D1 , d2 ∈ D2 } (or equivalently, D = ((D1 \ {b1 }) × (D2 \ {b2 })) ∪ {(b1 , b2 )}), the partial ordering P is defined as (d1 , d2 ) P (e1 , e2 ) ⇐⇒def d1 P1 e1 and d2 P2 e2 , b =def L b1 , b2 M = (b1 , b2 ), t =def L t1 , t2 M, and the attenuation operator ◦ is defined as (d1 , d2 )◦ (e1 , e2 ) =def (d1 ◦1 e1 , d2 ◦2 e2 ). Note the special case when D1 or D2 is a singleton set. Then, D is the singleton set {(b1 , b2 )}, L t1 , t2 M = (b1 , b2 ), and (t1 , t2 ) ∈ D happens to be false if one of the two sets D1 , D2 is not a singleton.

Intuitively, each value (d1 , d2 ) belonging to a product domain D1× D2 or D1 ⊗ D2 imposes the qualification d1 and also the qualification d2 . In particular, values (c, d) belonging to the product domains U × W and U ⊗ W impose two qualifications, namely: a certainty value greater or equal than c and a proof tree with weighted depth less or equal than d. This intuition indeed corresponds to the declarative semantics formally defined in Section 3. The next theorem shows that the class of the qualification domains is closed under ordinary cartesian products, while the subclass of stable qualification domains is closed under strict cartesian products. We are particularly interested in stable

243

Fixpoint & Proof-theoretic Semantics for SQCLP

15

qualification domains built from basic domains by reiterated strict products, because they can be encoded into into constraint domains in the sense explained in Subsection 2.2.5 below. Theorem 2.1 Assume two given qualification domains D1 and D2 . Then the ordinary cartesian product D1×D2 is always a qualification domain. Moreover, if D1 and D2 are stable, then the strict cartesian product D1 ⊗ D2 is a stable qualification domain. Proof Here we reason only for the case of the strict cartesian product since the reasonings needed for the ordinary cartesian product are very similar and even simpler. Assume that D1 and D2 are stable qualification domains, and let D = D1 ⊗D2 be constructed as in Definition 2.11. In order to show that D is a stable qualification domain, we prove the four items below. The assumption that D1 and D2 satisfy all the axioms from Definition 2.10 is used in all the reasonings, often implicitly. 1. The attenuation operator ◦ of D is well defined. Assume (d1 , d2 ), (e1 , e2 ) ∈ D. According to Definition 2.11, (d1 , d2 ) ◦ (e1 , e2 ) is defined as (d1 ◦1 e1 , d2 ◦2 e2 ). Since D = D1 ⊗D2 is a strict subset of D1 ×D2 , we must prove that (d1 ◦1 e1 , d2 ◦2 e2 ) ∈ D. We reason by distinction of cases: 1.1. (d1 , d2 ) = (b1 , b2 ) or (e1 , e2 ) = (b1 , b2 ). In this case, (d1 ◦1 e1 , d2 ◦2 e2 ) = (b1 , b2 ) ∈ D. 1.2. (d1 , d2 ) 6= (b1 , b2 ) and (e1 , e2 ) 6= (b1 , b2 ). In this case, d1 , e1 ∈ D1 \ {b1 } and d2 , e2 ∈ D2 \ {b2 }. The assumption that D1 and D2 are stable ensures d1 ◦1 e1 6= b1 and d2 ◦2 e2 6= b2 , and therefore (d1 ◦1 e1 , d2 ◦2 e2 ) ∈ D. 2. hD, P, b, ti is a lattice with extreme points b = L b1 , b2 M = (b1 , b2 ) and t =def L t1 , t2 M w.r.t. the partial ordering P. By definition, (d1 , d2 ) P (e1 , e2 ) ⇐⇒ d1 P1 e1 ∧d2 P2 e2 . The fact that P is a partial ordering with minimum (bottom) element b is an obvious connsequence. To prove that t is the maximum (top) element, we reason by case distinction. If D1 is a singleton set, then D1 = {b1 }, t1 = b1 , D = {(b1 , b2 )}, and L t1 , t2 M = (b1 , b2 ) is obviously the top element. The case that D2 is a singleton set is argued similarly. Finally, if neither D1 nor D2 are singleton, we have t1 6= b1 , t2 6= b2 , and t = L t1 , t2 M = (t1 , t2 ) is clearly the top element. To show that hD, P, b, ti is a lattice, we assume two arbitrary elements (d1 , d2 ), (e1 , e2 ) ∈ D, and we prove: 2.1. There is a lub (d1 , d2 ) t (e1 , e2 ) ∈ D. The lubs d1 t1 e1 ∈ D1 and d2 t2 e2 ∈ D2 are known to exist. We claim that (d1 , d2 )t(e1 , e2 ) = (d1 t1 e1 , d2 t2 e2 ). Due to the component-wise definition of P, it suffices to show that (d1 t1 e1 , d2 t2 e2 ) ∈ D. We prove this by case distinction:

2.1.1. If (d1 , d2 ) = (b1 , b2 ) then (d1 t1 e1 , d2 t2 e2 ) = (e1 , e2 ) ∈ D. 2.1.2. If (e1 , e2 ) = (b1 , b2 ) then (d1 t1 e1 , d2 t2 e2 ) = (d1 , d2 ) ∈ D. 2.1.3. If (d1 , d2 ) 6= (b1 , b2 ) and (e1 , e2 ) 6= (b1 , b2 ) then the construction of D ensures that d1 , e1 ∈ D1 \ {b1 } and d2 , e2 ∈ D2 \ {b2 }. This implies d1 t1 e1 6= b1 and d2 t2 e2 6= b2 , which guarantees (d1 t1 e1 , d2 t2 e2 ) ∈ D.

244

16

M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz

2.2. There is a glb (d1 , d2 ) u (e1 , e2 ) ∈ D. The glbs d1 u1 e1 ∈ D1 and d2 u2 e2 ∈ D2 are known to exist. We claim that (d1 , d2 ) u (e1 , e2 ) = L d1 u1 e1 , d2 u2 e2 M. We prove the claim by case distinction:

2.2.1. If d1 u1 e1 6= b1 and d2 u2 e2 6= b2 , then L d1 u1 e1 , d2 u2 e2 M is the same as (d1 u1 e1 , d2 u e2 ) ∈ D, and this pair is the glb of (d1 , d2 ) and (e1 , e2 ) due to the component-wise definition of P. 2.2.2. If d1 u1 e1 = b1 or d2 u2 e2 = b2 , then L d1 u1 e1 , d2 u2 e2 M = (b1 , b2 ) is obviously a common lower bound of (d1 , d2 ) and (e1 , e2 ). In order to conclude that (b1 , b2 ) is the glb of (d1 , d2 ) and (e1 , e2 ), we show that (b1 , b2 ) is the only common lower bound of (d1 , d2 ) and (e1 , e2 ) by the following reasoning: assume an arbitrary (x, y) ∈ D such that (x, y) P (d1 , d2 ) and (x, y) P (e1 , e2 ). Then x P d1 u1 e1 and y P d2 u2 e2 . Since d1 u1 e1 = b1 or d2 u2 e2 = b2 , it follows that x = b1 or y = b2 . By construction of D, it must be the case that x = b1 and y = b2 , because otherwise (x, y) would not belong to D. Therefore (x, y) = (b1 , b2 ), as desired.

3. ◦ satisfies axioms required for attenuation operators in Definition 2.10. By definition of ◦ we know (?) (d1 , d2 ) ◦ (e1 , e2 ) = (d1 ◦1 e1 , d2 ◦2 e2 ) which always belongs to D as already proved in item (1) above. All the axioms listed under item (3) of Definition 2.10 except (3)(e) follow easily from the equation (?) and the corresponding axioms for ◦1 and ◦2 . In order to verify axiom (3)(e) for ◦, we assume three pairs (d1 , d2 ), (e1 , e2 ), (e01 , e02 ) ∈ D. We must prove the equation (†) (d1 , d2 ) ◦ ((e1 , e2 ) u (e01 , e02 )) = (d1 , d2 ) ◦ (e1 , e2 ) u (d1 , d2 ) ◦ (e01 , e02 ) . We reason by case distinction: 3.1. If d1 = b1 and d2 = b2 then both sides of (†) are equal to (b1 , b2 ), as shown by the following calculations: (d1 , d2 ) ◦ ((e1 , e2 ) u (e01 , e02 )) = (b1 , b2 ) ◦ ((e1 , e2 ) u (e01 , e02 )) = (b1 , b2 )

(d1 , d2 ) ◦ (e1 , e2 ) u (d1 , d2 ) ◦ (e01 , e02 ) = (b1 , b2 ) ◦ (e1 , e2 ) u (b1 , b2 ) ◦ (e01 , e02 ) = (b1 , b2 ) u (b1 , b2 ) = (b1 , b2 ) 3.2. If the previous case does not apply, the construction of D ensures that d1 6= b1 and d2 6= b2 . We distiguish two subcases: 3.2.1. If e1 u1 e01 = b1 or e2 u2 e02 = b2 we get also d1 ◦1 (e1 u1 e01 ) = b1 or d2 ◦2 (e2 u2 e02 ) = b2 , and we can assume the following: (♣) L e1 u1 e01 , e2 u2 e02 M = (b1 , b2 ) (♠) L d1 ◦1 (e1 u1 e01 ), d2 ◦2 (e2 u2 e02 ) M = (b1 , b2 )

245

Fixpoint & Proof-theoretic Semantics for SQCLP

17

We can now prove that both sides of (†) are equal to (b1 , b2 ) as follows: (d1 , d2 ) ◦ ((e1 , e2 ) u (e01 , e02 )) = (d1 , d2 ) ◦ L e1 u1 e01 , e2 u2 e02 M =♣ (d1 , d2 ) ◦ (b1 , b2 ) = (b1 , b2 ) (d1 , d2 ) ◦ (e1 , e2 ) u (d1 , d2 ) ◦ (e01 , e02 ) = (d1 ◦1 e1 , d2 ◦2 e2 ) u (d1 ◦1 e01 , d2 ◦2 e02 ) = L d1 ◦1 e1 u1 d1 ◦1 e01 , d2 ◦2 e2 u2 d2 ◦2 e02 M = L d1 ◦1 (e1 u1 e01 ), d2 ◦2 (e2 u2 e02 ) M =♠ (b1 , b2 )

3.2.2. If e1 u1 e01 6= b1 and e2 u2 e02 6= b2 then the stability assumption made for D1 and D2 ensures d1 ◦1 (e1 u1 e01 ) 6= b1 and d2 ◦2 (e2 u2 e02 ) 6= b2 , and we can assume the following: (♦) L e1 u1 e01 , e2 u2 e02 M = (e1 u1 e01 , e2 u2 e02 ) (♥) L d1 ◦1 (e1 u1 e01 ), d2 ◦2 (e2 u2 e02 ) M = (d1 ◦1 (e1 u1 e01 ), d2 ◦2 (e2 u2 e02 ))

Then, (†) is proved by the following calculations:

(d1 , d2 ) ◦ ((e1 , e2 ) u (e01 , e02 )) = (d1 , d2 ) ◦ L e1 u1 e01 , e2 u2 e02 M =♦ (d1 , d2 ) ◦ (e1 u1 e01 , e2 u2 e02 ) = (d1 ◦1 (e1 u1 e01 ), d2 ◦2 (e2 u2 e02 )) (d1 , d2 ) ◦ (e1 , e2 ) u (d1 , d2 ) ◦ (e01 , e02 ) = (d1 ◦1 e1 , d2 ◦2 e2 ) u (d1 ◦1 e01 , d2 ◦2 e02 ) = L d1 ◦1 e1 u1 d1 ◦1 e01 , d2 ◦2 e2 u2 d2 ◦2 e02 M = L d1 ◦1 (e1 u1 e01 ), d2 ◦2 (e2 u2 e02 ) M =♥ (d1 ◦1 (e1 u1 e01 ), d2 ◦2 (e2 u2 e02 ))

4. D1⊗D2 is stable. To prove this let us assume (d1 , d2 ), (e1 , e2 ) ∈ D1 ⊗D2 \{(b1 , b2 )}. Then d1 , e1 ∈ D1 \ {b1 } and d2 , e2 ∈ D2 \ {b2 }. Since D1 and D2 are stable qualification domains, we can infer that d1 ◦1 e1 6= b1 and d2 ◦2 e2 6= b2 , which implies (d1 , d2 ) ◦ (e1 , e2 ) = (d1 ◦1 e1 , d2 ◦2 e2 ) 6= (b1 , b2 ). 2.2.5 Encoding Qualification Domains into Constraint Domains In this subsection we investigate a technical relationship between qualification domains and constraint domains which will play a key role in the rest of the report. Definition 2.12 (Expressing D in C) A qualification domain D with carrier set DD is expressible in a constraint domain C with carrier set CC if there is an injective mapping ı : DD \ {b} → CC embedding DD \ {b} into CC , and the two following requirements are satisfied: 1. There is a C-constraint qVal(X) such that SolC (qVal(X)) is the set of all η ∈ ValC such that η(X) belongs to the range of ı. 2. There is a C-constraint qBound(X, Y, Z) encoding “x P y ◦ z” in the following sense: any η ∈ ValC satisfying η(X) = ı(x), η(Y ) = ı(y) and η(Z) = ı(z) for some x, y, z ∈ D \ {b} verifies η ∈ SolC (qBound(X, Y, Z)) ⇐⇒ x P y ◦ z.

Moreover, if qVal(X) and qBound(X, Y, Z) can be chosen as existential constraints, we say that D is existentially expressable in C.

246

18

M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz

In the sequel, C-constraints built as instances of qVal(X) and qBound(X, Y, Z) are called qualification constraints, and Ω is used as notation for sets of qualification constraints. The following result ensures that several qualification domains built with the techniques presented in Subsection 2.2 are existentially expressible in H, R or FD, according to the case. Proposition 2.2 (Expressing Qualification Domains in Constraint Domains) 1. The domain B is existentially expressible in any given constraint domain C. 2. The domains U, U 0, W and W 0 are existentially expressible in R (or any other constraint domain that supports the expressivity of R). 3. The domains Wd and Wd0 are existentially expressible in FD (or any other constraint domain that supports the expressivity of FD). 4. Assume that the two qualification domains D1 and D2 are stable and (existentially) expressible in a constraint domain C. Then, D1 ⊗ D2 is also (existentially) expressible in C. Proof 1. Straightforward, due to the fact that DB \ {b} is the singleton set {t} = {true}. 2. We prove that U can be existentially expressed in R as follows: DU \ {b} = DU \ {0} = (0, 1] ⊆ R ⊆ CR ; therefore ı can be taken as the identity embedding mapping from (0, 1] into R. Moreover, qVal(X) can be built as the existential R-constraint cp< (0, X) ∧ cp≤ (X, 1) and qBound(X, Y, Z) can be built as the existential R-constraint ∃X1 (op× (Y, Z, X1 ) ∧ cp≤ (X, X1 )). By very similar reasonings it is easy to check that U 0 , W and W 0 can also be existentially expressed in R. Note that in the cases of W and W 0 there is no reasonable way to define ı(∞). This is the reason why the domain of ı is required to be D \ {b} in Definition 2.12. 3. Note that DWd \ {b} = DWd \ {∞} = N. Moreover, P is ≥ and ◦ is + in Wd . Therefore, Wd can be expressed in FD by taking ı as the identity embedding mapping, building qVal(X) as an existential FD constraint that requires the value of X to be an integer x ≥ 0, and building qBound(X, Y, Z) as an existential FD constraint that requires the values of X, Y and Z to be integers x, y and z such that x ≥ y + z. A similar reasoning proves that Wd0 is existentially expressible in FD also. 4. For j = 1, 2 assume the existence of injective embedding mappings ıj and Cconstraints qValj (X), qBoundj (X, Y, Z) that can be used to (existentially) express Dj in C. Due to Theorem 2.1 we know that D1 ⊗ D2 is a stable qualification domain. Moreover, because of the construction of D = D1 ⊗ D2 given in Definition 2.11, we know that D \ {b} = (D1 \ {b1 }) × (D2 \ {b2 }). We also know that P is defined component-wise from P1 , and P2 , and analogously for ◦. Therefore, D can be (existentially) expressed in C by taking: • ı defined by ı(d1 , d2 ) =def (ı1 (d1 ), ı2 (d2 )). • qVal(X) built as the prenex form of the constraint

∃X1 ∃X2 (X == (X1 , X2 ) ∧ qVal1 (X1 ) ∧ qVal2 (X2 )) which is existential if qVal1 (X1 ) and qVal2 (X2 ) are both existential.

247

Fixpoint & Proof-theoretic Semantics for SQCLP

19

• qBound(X, Y, Z) built as the prenex form of the constraint ∃X1 ∃X2 ∃Y1 ∃Y2 ∃Z1 ∃Z2 (X == (X1 , X2 ) ∧ Y == (Y1 , Y2 ) ∧ Z == (Z1 , Z2 )∧ qBound1 (X1 , Y1 , Z1 ) ∧ qBound2 (X2 , Y2 , Z2 )) which is existential if qBound1 (X1 , Y1 , Z1 ) and qBound2 (X2 , Y2 , Z2 ) are both existential. Note that this reasoning does not work for the non-strict cartesian product D = D1 × D2 , because in this case D \ {b} = (D1 × D2 ) \ {(b1 , b2 )} includes some pairs (d1 , d2 ) such that either d1 = b1 or d2 = b2 (but not both), and the given mappings ı1 , ı2 cannot be used to embed such pairs into CC . 2.3 Similarity and Proximity Relations Similarity relations over a given set S have been defined in (Zadeh 1971; Sessa 2002) and related literature as mappings S : S × S → [0, 1] that satisfy reflexivity, symmetry and transitivity axioms analogous to those required for classical equivalence relations. A more general notion called proximity relation has been defined in (Dubois and Prade 1980) by omitting the transitivity axiom. Each value S(x, y) computed by a similarity (resp. proximity) relation S is called the similarity degree (resp. proximity degree) between x and y. In our previous paper (Caballero et al. 2008), we proposed to generalize similarity relations by allowing elements of an arbitrary qualification domain D to serve as proximity degrees. The definition below further generalizes this approach by considering proximity relations. Definition 2.13 (Proximity and similarity relations) Let a qualification domain D with carrier set D and a set S be given. 1. A D-valued relation over S is any mapping S : S × S → D. 2. A D-valued relation S over S is called (a) Reflexive iff ∀x ∈ S : S(x, x) = t. (b) Symmetrical iff ∀x, y ∈ S : S(x, y) = S(y, x). (c) Transitive iff ∀x, y, z ∈ S : S(x, z) Q S(x, y) u S(y, z).

3. S is called a D-valued proximity relation iff S is reflexive and symmetrical. 4. If S is also transitive, then it is called a D-valued similarity relation. 5. S is called finitary iff there are only finitely many choices of elements x, y ∈ S such that x 6= y and S(x, y) 6= b. From a practical viewpoint, this is a very natural requirement. Obviously, D-valued similarity relations are a particular case of D-valued proximity relations. Moreover, when D is chosen as the qualification domain U, the previous definition provides proximity and similarity relations in the sense of (Zadeh 1971; Dubois and Prade 1980). In this case, a proximity degree S(x, y) = d ∈ [0, 1] can be naturally interpreted as a certainty degree for the assertion that x and y are interchangeable. On the other hand, if S is W-valued, then S(x, y) = d ∈ [0, ∞] can be interpreted as a cost to be paid for y to play the role of x. More generally, the

248

20

M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz

proximity degrees computed by a D-valued proximity relation may have different interpretations according to the intended role of D-elements as qualification values. In contrast to previous works such as (Sessa 2002; Caballero et al. 2008), in the rest of this report we will work with D-valued proximity rather than similarity relations. Formally, this leads to more general results. Moreover, as already noted by (Shenoi and Melton 1999) and other authors, the transitivity property required for similarity relations may be counterintuitive in some cases. For instance, assume nullary constructors colt, cold and gold intended to represent words composed of four letters. Then, measuring the proximity between such words might reasonably lead to a U-valued proximity relation S such that S(colt, cold) = 0.9, S(cold, gold) = 0.9 and S(colt, gold) = 0.4. On the other hand, insisting on S to be transitive would enforce the unreasonable condition S(colt, gold) ≥ 0.9. Therefore, a similarity relation would be not appropriate in this case. The special mapping Sid : S × S → D defined as Sid (x, x) = t for all x ∈ S and Sid (x, y) = b for all x, y ∈ S, x 6= y is trivially a D-valued similarity (and therefore, also proximity) relation called the identity. 2.3.1 Admissible triples and proximity relations From now on, we will focus on proximity relations that are related to constraint domains in the following sense: Definition 2.14 (Admissible triples) hS, D, Ci is called an admissible triple iff the following requirements are fulfilled: 1. C is a constraint domain with signature Σ = hDC, DP, P P i and set of basic values BC , and D is a qualification domain expressible in C in the sense of Definition 2.12. 2. S is a D-valued proximity relation over S = Var ] BC ] DC ] DP ] P P . 3. S restricted to Var behaves as the identity, i.e. S(X, X) = t for all X ∈ Var and S(X, Y ) = b for all X, Y ∈ Var such that X 6= Y . 4. For any x, y ∈ S, S(x, y) 6= b can happen only if some of the following cases holds: (a) (b) (c) (d)

x = y are identical. x, y ∈ BC are basic values. x, y ∈ DC are data constructor symbols with the same arity. x, y ∈ DP are defined predicate symbols with the same arity.

In particular, S(p, p0 ) 6= b cannot happen if p, p0 ∈ P P are syntactically different primitive predicate symbols. In the rest of the report, our notions and results are valid for any choice of an admissible triple hS, D, Ci. Proposition 2.2 provides useful information for building admissible triples. For any given admissible triple, S can be naturally extended to act over terms and atoms over C. The extension, also noted S, works as specified in the recursive definition below. An analogous definition for the case of U-valued similarity relations can be found in (Sessa 2002).

249

Fixpoint & Proof-theoretic Semantics for SQCLP

21

Definition 2.15 (S acting over terms and atoms) For any given admissible triple, S is extended to work over C-terms and C-atoms as follows: 1. For any t ∈ Term(Σ, B, Var): S(t, t) = t. 2. For X ∈ Var and for any term t different from X: S(X, t) = S(t, X) = b. 3. For c, c0 ∈ DC with different arities n, m: S(c(tn ), c0 (t0 m )) = b. 4. For c, c0 ∈ DC with the same arity n: S(c(tn ), c0 (t0 n )) = S(c, c0 ) u S(t1 , t01 ) u . . . u S(tn , t0n ). 5. For r, r0 ∈ DP ∪ P P with different arities n, m: S(r(tn ), r0 (t0 m )) = b. 6. For r, r0 ∈ DP ∪ P P with the same arity n: S(r(tn ), r0 (t0 n ) = S(r, r0 ) u S(t1 , t01 ) u . . . u S(tn , t0n ). Given two terms t, t0 and some fixed qualification value λ ∈ D \ {b} we will use the notation t ≈λ t0 (read as t and t0 are S-close at level λ) as an abbreviation of λ P S(t, t0 ). For the sake of simplicity, S is not made explicit in the ≈λ notation. The following lemma provides a natural characterization of ≈λ . A similar result was given in (Sessa 2002) for the case of case of U-valued similarity relations. Lemma 2.5 (Proximity Lemma) 1. ≈λ is a reflexive and symmetric equivalence relation over terms, which is also transitive (and hence an equivalence relation) in the case that S is a similarity relation. 2. For any given terms t and t0 the following two statements are equivalent: (a) t ≈λ t0 . (b) pos(t) = pos(t0 ), and for each p ∈ pos(t) ∩ pos(t0 ) some of the cases below holds: i t ◦ p = t0 ◦ p = X for some X ∈ Var. ii t ◦ p = s ◦ p = u for some u ∈ BC . iii t ◦ p = c and t0 ◦ p = c0 for some n ∈ N and some c, c0 ∈ DC n such that λ P S(c, c0 ).

3. Any given terms t and t0 such that t ≈λ t0 are quasi-identical in the following sense: pos(t) = pos(t0 ), and for each p ∈ pos(t) = pos(t0 ) either t ◦ p = t0 ◦ p or else t ◦ p and t0 ◦ p are two data constructors of the same arity. 4. ≈λ boils down to the syntactic equality relation ‘=’ when S is the identity proximity relation Sid . Proof We give a separate reasoning for each item.

250

22

M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz

1. Note that the reflexivity and symmetry of ≈λ are a trivial consequence of the reflexivity and symmetry of S, as formulated in Definition 2.13. In the case that S is a similarity relation, transitivity of ≈λ follows from transitivity of S and the obvious fact that λ u λ = λ. 2. The claimed equivalence between conditions 2(a) and 2(b) can be proved reasoning by induction on ktk + kt0 k. 3. This item is an obvious consequence of the previous one. 4. Assume S = Sid . Then, as a trivial consequence of Definition 2.15, the value of S(t, t0 ) is t if t = t0 and b otherwise. Since λ 6= b, it follows that t ≈λ t0 iff t = t0 , as desired. The following result shows that ≈λ is compatible with the term extension operation in a natural way: Lemma 2.6 (Proximity Preservation Lemma) Assume terms t, t0 and λ ∈ D \ {b} such that t ≈λ t0 . Then (t  s) ≈λ (t0  s) holds also for any term s. Proof Due to the assumption, t ≈λ t0 are quasi-identical and satisfy condition 2(b) as stated in the Proximity Lemma 2.5. From this fact and Definition 2.9 it is quite clear that the same condition 2(b) holds also for t  s, t0  s and λ. Therefore, the Proximity Lemma allows to conclude t ≈λ t0 as desired. 2.3.2 Term proximity w.r.t. a given constraint set Reasoning with equations between C-terms will require to infer information both from S and for some fixed constraint set Π ⊆ ConC . This leads to a generalization of ≈λ formally defined as follows: Definition 2.16 (Term proximity w.r.t. a given constraint set) Let hS, D, Ci be any admissible triple. Assume λ ∈ D \ {b} and Π ⊆ ConC . We will say that t and s are S-close at level λ w.r.t. Π (in symbols, t ≈λ,Π s) iff there are two terms tˆ, sˆ such that t ≈Π tˆ, s ≈Π sˆ and tˆ ≈λ sˆ. For the sake of simplicity neither S nor C are made explicit in the notation. As illustration, let us present an example using the constraint domain R and the qualification domain U: Example 2.2 (Term proximity w.r.t. R constraints) Consider Π = {op+ (A, A, X), op× (2.0, A, Y ), Z == c(X, Y )} ⊆ ConR . Note that this choice of Π ensures X ≈Π Y . Assume c, c0 , c00 ∈ DC 2 and an U-valued proximity relation S such that S(c0 , c) = S(c, c00 ) = 0.8 and S(c0 , c00 ) = 0.6. Then: 1. c(Y, X) ≈Π Z holds, but c0 (Y, X) ≈Π Z is false. 2. c0 (Y, X) ≈0.7,Π Z holds, because c0 (Y, X) ≈Π c0 (X, X), Z ≈Π c(X, X) and c0 (X, X) ≈0.7 c(X, X). 3. Z ≈0.7,Π c00 (X, Y ) is also true, for similar reasons.

251

Fixpoint & Proof-theoretic Semantics for SQCLP

23

4. c0 (Y, X) ≈0.7,Π c00 (X, Y ) is false, because there is no possible choice of terms tˆ and sˆ such that c0 (Y, X) ≈Π tˆ, c00 (X, Y ) ≈Π sˆ and tˆ ≈0.7 sˆ. The next result states some basic properties of relations ≈λ,Π . Lemma 2.7 (Π-Proximity Lemma) 1. ≈λ,Π is invariant w.r.t. ≈Π in the following sense: t ≈λ,Π s implies t0 ≈λ,Π s0 for all terms t0, s0 such that t0 ≈Π t and s0 ≈Π s. 2. ≈λ,Π is a reflexive and symmetric relation over terms, which is also transitive (and hence an equivalence relation) in the case that S is a similarity relation. 3. For any given terms t and t0 the following two statements are equivalent: (a) t ≈λ,Π t0 . (b) For any common position p ∈ pos(t) ∩ pos(t0 ) some of the cases below holds: i t ◦ p or t0 ◦ p is a variable, and moreover t|p ≈λ,Π t0 |p . ii t ◦ p = s ◦ p = u for some u ∈ BC . iii t ◦ p = c and t0 ◦ p = c0 for some n ∈ N and some c, c0 ∈ DC n such that λ P S(c, c0 ).

4. ≈λ,Π boils down to ≈λ when Π is the empty set, and ≈λ,Π boils down to ≈Π when S is the identity proximity relation Sid .

Proof We give a separate reasoning for each item. Definition 2.16 and Lemmata 2.2 and 2.5 are implicitely used at some points. 1. By definition, t ≈λ,Π s means the existence of terms tˆ, sˆ such that t ≈Π tˆ, s ≈Π sˆ and tˆ ≈λ sˆ. In case that t0 ≈Π t and s0 ≈Π s, the same terms tˆ, sˆ verify t0 ≈Π tˆ, s0 ≈Π sˆ (since ≈Π is an equivalence relation) and tˆ ≈λ sˆ. Therefore t0 ≈λ,Π s0 . 2. Let us consider the three properties in turn: Reflexivity: t ≈λ,Π t holds because tˆ = t trivially verifies t ≈Π tˆ and tˆ ≈λ tˆ. Symmetry: Assume t ≈λ,Π s. Then there are terms tˆ, sˆ such that t ≈Π tˆ, s ≈Π sˆ and tˆ ≈λ sˆ. Due to the symmetry of ≈λ we get sˆ ≈λ tˆ and hence s ≈λ,Π t. Transitivity: Example 2.2 above shows that ≈λ,Π is not transitive in general. Here we prove transitivity of ≈λ,Π under the assumption that S is a similarity relation fulfilling the transitive property stated in Definition 2.13. Assume terms t1 , t2 and t3 such that t1 ≈λ,Π t2 and t2 ≈λ,Π t3 . Then there are terms t01 , t02 , t002 and t003 such that (a) t1 ≈Π t01 , t2 ≈Π t02 , t01 ≈λ t02

(b) t2 ≈Π t002 , t3 ≈Π t003 , t002 ≈λ t003 .

and

Without loss of generality, t01 , t02 , t002 and t003 can be assumed to be Π-canonical terms. If they were not, it would suffice to to replace each of them by its Π-canonical form, built as explained in Definition 2.8. This replacement would preserve properties (a) and (b) thanks to the Canonicity Lemma 2.3. We claim that there are three terms tˆ1 , tˆ2 , and tˆ3 such that (c) t1 ≈Π tˆ1 , t2 ≈Π tˆ2 , t3 ≈Π tˆ3

and

252

(d) tˆ1 ≈λ tˆ2 , tˆ2 ≈λ tˆ3 .

24

M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz

Conditions (c) and (d) imply t1 ≈λ,Π t3 due to Definition 2.16 and the transivity property of ≈λ , which is ensured by the transitivity of S and the Proximity Lemma 2.5. In the rest of this item we prove the claim by assuming (a) and (b) and showing how to build tˆ1 , tˆ2 , and tˆ3 fulfilling (c) and (d). Note that the assumption t01 ≈λ t02 implies that t01 and t02 are quasi-identical terms, due Proximity Lemma 2.5(3). Analogously, terms t002 and t003 must be also quasiidentical due to the assumption t002 ≈λ t003 , and the target condition (d) requires that tˆ1 , tˆ2 , tˆ3 are constructed as quasi-identical terms. Since our assumptions do not guarantee quasi-identity of terms t02 and t002 , we resort to the term extension construction from Definition 2.9 for building the terms tˆi . More precisely, we build: tˆ1 =def (t01  t002 );

tˆ2 =def (t02  t002 ) = (t002  t02 );

and tˆ3 =def (t003  t02 )

where the identity (t02  t002 ) = (t002  t02 ) is a consequence of the Symmetrical Extension Property from Lemma 2.4, which can be applied because t02 and t002 are Π-canonical and assumptions (a), (b) imply t02 ∼Π t002 . We argue that conditions (c) and (d) are satisfied as follows: — Condition (c), t1 ≈Π tˆ1 : By assumptions (a), (b) we know t1 ≈Π t01 and t02 ≈Π t002 . It suffices to prove t01 ≈Π tˆ1 . For each p ∈ pos(t01 ) with t01 |p = X ∈ Var we have t02 |p = X because t01 and t02 are quasi-identical. Moreover, t02 ≈Π t002 implies that p ∈ pos(t002 ) and X ∼Π t002 |p , due to the Π-Equivalence Lemma 2.2. In these conditions, t01 ≈Π tˆ1 follows from tˆ1 = (t01  t002 ) and the Equivalent Extension Property from Lemma 2.4. — Condition (c), t3 ≈Π tˆ3 : The proof for this is analogous to the previous one. Since t3 ≈Π t003 and tˆ3 = (t003  t02 ) it suffices to prove t003 ≈Π (t003  t02 ), which can be done with the help of the Equivalent Extension Property. — Condition (c), t2 ≈Π tˆ2 : By assumptions (a), (b) we know t2 ≈Π t02 and t02 ≈Π t002 . It suffices to prove t02 ≈Π tˆ2 . For each p ∈ pos(t02 ) with t02 |p = X ∈ Var we have p ∈ pos(t002 ) and X ∼Π t002 |p , due to t02 ≈Π t002 and the Π-Equivalence Lemma 2.2. In these conditions, t02 ≈Π tˆ2 follows from tˆ2 = (t02  t002 ) and the Equivalent Extension Property. — Condition (d), tˆ1 ≈λ tˆ2 : By assumption (a) we have t01 ≈λ t02 . By the Proximity Preservation Lemma 2.6 this implies (t01  t002 ) ≈λ (t02  t002 ). By construction of the terms tˆi , this is the same as tˆ1 ≈λ tˆ2 . — Condition (d), tˆ2 ≈λ tˆ3 : The proof for this is analogous to the previous one. Assumption (b) provides t002 ≈λ t003 . Then, the Proximity Preservation Lemma guarantees (t002  t02 ) ≈λ (t003  t02 ), which is the same as tˆ2 ≈λ tˆ3 by construction of the terms tˆi (this time viewing tˆ2 as (t002  t02 ) rather than (t02  t002 ) as in the previous argumentation). 3. The claimed equivalence between conditions 3(a) and 3(b) can proved reasoning by induction on ktk + kt0 k. 4. According to Definition 2.16, t ≈λ,Π s is true iff (?) holds, where: (?) there are terms tˆ, sˆ such that t ≈Π tˆ, s ≈Π sˆ and tˆ ≈λ sˆ.

Let us argue for the two cases Π = ∅ and S = Sid separately:

• Assume that Π = ∅. Then, due to Π-Equivalence Lemma 2.2(3), (?) can be

253

Fixpoint & Proof-theoretic Semantics for SQCLP

25

rewritten as there are terms tˆ, sˆ such that t = tˆ, s = sˆ and tˆ ≈λ sˆ which is equivalent to t ≈λ s. • Assume now that S = Sid . Then, due to Proximity Lemma 2.5(4), (?) can be rewritten as there are terms tˆ, sˆ such that t ≈Π tˆ, s ≈Π sˆ and tˆ = sˆ which is equivalent to t ≈Π s. The following technical lemma will be needed later on. Although it is closely related to Lemma 2.1(2), it needs a separate proof because statements of the form t ≈λ,Π s are not C-constraints. Lemma 2.8 (Substitution Lemma for ≈λ,Π ) Let hS, D, Ci be any admissible triple. Assume λ ∈ D \ {b}, Π ⊆ ConC , and two terms t, s such that t ≈λ,Π s. Then tσ ≈λ,Πσ sσ holds for every C-substitution σ. Proof Because of the assumptions and Definition 2.16, there are terms tˆ, sˆ such that t ≈Π tˆ (i.e. Π |=C t == tˆ), s ≈Π sˆ (i.e. Π |=C s == sˆ) and tˆ ≈λ sˆ. Consider now any substitution σ. Due to Lemma 2.1(2), we get Πσ |=C tσ == tˆσ (i.e. tσ ≈Πσ tˆσ) and Πσ |=C sσ == sˆσ (i.e. sσ ≈Πσ sˆσ). Moreover, tˆσ ≈λ sˆσ is an easy consequence of tˆ ≈λ sˆ and Proximity Lemma 2.5(2). Then, Definition 2.16 allows to conclude ˆ and sˆσ as sσ. tσ ≈λ,Πσ sσ simply by taking tˆσ as tσ ˆ 3 The SQCLP Programming Scheme In this section we develop the SQCLP scheme with instances SQCLP(S, D, C) announced in the introduction. The parameters S, D and C stand for an admissible proximity relation, a qualification domain and a constraint domain with a certain signature Σ, respectively. By convention, we consider only those instances of the scheme whose parameters are chosen to constitute an admissible triple in the sense of Definition 2.14. We focus on declarative semantics, using an interpretation transformer and a logical inference system to provide alternative characterizations of least program models. We also discuss declarative semantics of goals and related approaches. A brief remark regarding notation is in place here. For the sake of notational consistency with previous works (either by us or other authors) where similarity rather than proximity relations were used, we keep the symbol S for proximity relations and the uppercase letter S in the names of programming schemes. Our results, however, do not rely on the transitivity property from Definition 2.13. 3.1 Programs and their Declarative Semantics A SQCLP(S, D, C)-program is a set P of qualified program rules (also called qualified α clauses) of the form C : A ← − B1 ]w1 , . . . , Bm ]wm , where A is a defined atom, α ∈

254

26

M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz

DD \ {b} is called the attenuation factor of the clause and each Bj ]wj (1 ≤ j ≤ m) is an atom Bj annotated with a so-called threshold value wj ∈ (DD \{b})]{?}. The intended meaning of C is as follows: if for all 1 ≤ j ≤ m one has Bj ]ej (meaning that Bj holds with qualification value ej ) for some ej Q? wj , then A]d (meaning that A holds with qualification value d) can be inferred for any d ∈ D \ {b} such dm that d P α ◦ j=1 ej . By convention, ej Q? wj means ej Q wj if wj 6= ? and is identically true otherwise. In practice threshold values equal to ‘?’ and attenuation values equal to t can be omitted. As motivating example, consider a SQCLP(S, U⊗W, R)-program P including the clauses and equations for S displayed in Figure 1. From Subsection 2.2 recall that qualification values in U ⊗ W are pairs (d, e) (where d represents a certainty degree and e represents a proof cost), as well as the behavior of P and ◦ in U ⊗ W. Consider the problem of proving goodWork(king liar)](d, e) from P. This can be achieved for d = 0.75 × min{d1 , d2 }, e = 3 + max{e1 , e2 } by using R1 instantiated by {X 7→ king liar, Y 7→ shakespeare}, and going on to prove famousAuthor(shakespeare)](d1 , e1 ) for some d1 ≥ 0.5, e1 ≤ 100 and wrote(shakespeare,king liar)](d2 , e2 ) for some d2 , e2 . Thanks to R2 , R3 and S, these proofs succeed with (d1 , e1 ) = (0.9, 1) and (d2 , e2 ) = (0.8, 2). Therefore, the desired proof succeeds with certainty degree d = 0.75 × min{0.9, 0.8} = 0.6, and proof cost e = 3 + max{1, 2} = 5.

R1 : goodWork(X) <-(0.75,3)- famousAuthor(Y)#(0.5,100), wrote(Y,X)#? R2 : famousAuthor(shakespeare) <-(0.9,1)R3 : wrote(shakespeare,king_lear) <-(1,1)S(king_lear,king_liar) = (0.8,2)

Fig. 1. SQCLP(S, U ⊗W, R) Program Fragment It is useful to define some special types of program clauses and programs, as follows: • A clause is called attenuation-free iff α = t. The name is justified because t is an identity element for the attenuation operator ◦, as explained in Subsection 2.2. By convention, attenuation-free clauses may be written with the simplified syntax A ← B1 ]w1 , . . . , Bm ]wm . • A clause is called threshold-free iff wj = ? for all j = 1 . . . m. The name is justified because the threshold value wj = ? occurring as annotation of a body atom Bj does not impose any particular requirement to the qualification value of Bj . Threshold-free clauses may be written with the simplified syntax α A← − B1 , . . . , B m . • A clause is called qualification-free iff it is both attenuation-free and thresholdfree. These clauses may be written with the simplified syntax A ← B1 , . . . , Bm . They behave just like those used in the classical CLP scheme. • A clause is called constraint-free iff all its body atoms are defined.

255

Fixpoint & Proof-theoretic Semantics for SQCLP

27

• A program is called attenuation-free iff all its clauses are of this type. Threshold-free, qualification-free and constraint-free programs are defined similarly. The more technical SQCLP(S, U, R)-program P presented below will serve as a running example to illustrate various points in the rest of the report. Example 3.1 (Running example) Assume unary constructors c, c0 ∈ DC 1 , binary predicate symbols p, p0 , q ∈ DP 2 and a ternary predicate symbol r ∈ DP 3 . Consider the admissible triple hS, U, Ri, where S is an U-valued proximity relation such that S(c, c0 ) = 0.9 and S(p, p0 ) = 0.8. Let P be the SQCLP(S, U, R)-program consisting of the qualified clauses R1 , R2 and R3 listed below: 1.0

R1 : q(X, c(X)) ←−− 0.9

R2 : p(c(X), Y ) ←−− q(X, Y )]0.8 0.9

R3 : r(c(X), Y, Z) ←−− q(X, Y )]0.8, cp≥ (X, 0.0)]?

As we will see in the Conclusions, the classical CLP scheme for Constraint Logic Programming originally introduced in (Jaffar and Lassez 1987) can be seen as a particular case of the SQCLP scheme. In the rest of this subsection we present a declarative semantics for SQCLP(S, D, C)-programs inspired by (Gabbrielli and Levi 1991; Gabbrielli et al. 1995). These papers provided three different program semantics Si (i = 1, 2, 3) characterizing valid ground solutions for goals, valid open solutions for goals and computed answers for goals in CLP, respectively. In fact, the Si semantics in (Gabbrielli and Levi 1991; Gabbrielli et al. 1995) were conceived as the CLP counterpart of previously known semantics for logic programming, namely the least ground Herbrand model semantics (Apt 1990; Lloyd 1987), the open Herbrand model semantics, also known as C-semantics (Clark 1979; Falaschi et al. 1993), and the S-semantics (Falaschi et al. 1989; Bossi et al. 1994); see (Apt and Gabbrielli 1994) for a very concise and readable overview. In this report we restrict ourselves to develop a S2 -like semantics which can be used to characterize valid open solutions for SQCLP goals as we will see in Subsection 3.2. As a basis for our semantics we use so-called qc-atoms of the form A]d ⇐ Π, intended to assert that the atom A is entailed by the constraint set Π with qualification degree d. We also use a special entailment relation
256

28

M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz 4. Given two qc-atoms ϕ : A]d ⇐ Π and ϕ0 : A0 ]d0 ⇐ Π0 , we say that ϕ (D, C)entails ϕ0 (in symbols, ϕ
We will focus our attention on observable qc-atoms because they can be interpreted as observations of valid open solutions for atomic goals in SQCLP(S, D, C) as we will see in Subsection 3.2. The example below illustrates the main technical ideas from Definition 3.1. Example 3.2 (Observable qc-atoms and (D, C)-entailment) Consider the admissible triple underlying Example 3.1 and the sets of R-constraints: Π = {cp> (X, 1.0), op+ (A, A, X), op× (2.0, A, Y )} Π0 = {cp≥ (A, 3.0), op× (2.0, A, X), op+ (A, A, Y )} Then, the following are observable qc-atoms: ϕ1 = q(X, c0 (Y ))]0.9 ⇐ Π ϕ2 = p0 (c0 (Y ), c(X))]0.8 ⇐ Π

ϕ3 = r(c0 (Y ), c(X), Z)]0.8 ⇐ Π ϕ03 = r(c0 (Y ), c(X), c(Z 0 ))]0.7 ⇐ Π0

and the (U, R)-entailment ϕ3
The intended meaning of
257

Fixpoint & Proof-theoretic Semantics for SQCLP

29

for A. Our view of interpretations is closer to the expected operational behavior of goal solving systems and can be used to characterize the validity of solutions computed by such systems, as we will see in Subsection 3.2. Note also that the notation I ``S,D,C ϕ is defined only for the case that ϕ is observable. In the sequel, we will implicitly assume that ϕ is observable in any context where the notation I ``S,D,C ϕ is used. The next technical result shows that validity in any given interpretation is closed under entailment. Proposition 3.1 (Entailment Property for Interpretations) Assume that I ``S,D,C ϕ and ϕ
1. ϕ is defined. In this case, ϕ0 is also defined. Moreover, I ``S,D,C ϕ is equivalent to ϕ ∈ I because of Definition 3.2, which implies ϕ0 ∈ I because qc-interpretations are closed under
S(p0 , p) = d0 I ``S,D,C (t0i == ti θ)]di ⇐ Π (i.e. t0i ≈di ,Π ti θ) for i = 1 . . . n I ``S,D,C Bj θ]ej ⇐ Π with ej Q? wj for j = 1 . . . m dn dm d P i=0 di u α ◦ j=1 ej [i.e., d P di (0 ≤ i ≤ n) and d P α ◦ ej (1 ≤ j ≤ m)]

Note that the qualification value d attached to ϕ is limited by two kinds of upper bounds: di (0 ≤ i ≤ n), i.e. the S-proximity between p0 (t0 n ) and the head of Rl θ; and α ◦ ej (1 ≤ j ≤ m), i.e. the qualification values of the atoms in the body of Rl θ attenuated w.r.t. Rl ’s attenuation factor α. Moreover, the inequalities

258

30

M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz

ej Q? wj (1 ≤ j ≤ m) are required in order to impose the threshold conditions within Rl ’s body. As already explained at the beginning of this subsection, ej Q?wj means that either wj = ? or else wj ∈ D \ {b} and ej Q wj . Now we can define: 1. I is a model of a program rule Rl ∈ P (in symbols, I |=S,D,C Rl ) iff every defined observable qc-atom ϕ which is an immediate consequence of I via Rl verifies ϕ ∈ I; and I is a model of P (in symbols, I |=S,D,C P) iff I is a model of every program rule Rl ∈ P. 2. ϕ is a semantic consequence of P (in symbols, P |=S,D,C ϕ) iff I ``S,D,C ϕ for every qc-interpretation I such that I |=S,D,C P.

The next example may serve as a concrete illustration: Example 3.3 (Models and semantic consequence) Recall the SQCLP(S, U, R)-program P from Example 3.1. Let us show that the three qc-atoms ϕ1 , ϕ2 and ϕ3 from Example 3.2 are semantic consequences of P: 1. Assume an arbitrary model I |=S,U ,R P. Note that the atom underlying ϕ1 and the head atom of R1 are q(X, c0 (Y )) and q(X, c(X)), respectively. Since S(c, c0 ) = 0.9 and Π |=C X == Y , ϕ1 can be obtained as an immediate consequence of I via R1 using θ = ε. Therefore ϕ1 ∈ I and we can conclude that P |=S,U ,R ϕ1 . 2. Assume an arbitrary model I |=S,U ,R P. Consider the substitution θ = {Y 7→ c0 (Y )}. Note that the atom underlying ϕ2 and the head atom of R2 θ are p0 (c0 (Y ), c(X)) and p(c(X), c0 (Y )), respectively. Moreover, ϕ1 ∈ I (due to the previous item) and the atom q(X, c0 (Y )) underlying ϕ1 is the same as the atom in the body of R2 θ. These facts together with S(p, p0 ) = 0.8, S(c, c0 ) = 0.9 and Π |=C X == Y allow to obtain ϕ2 as an immediate consequence of I via R2 . Therefore ϕ2 ∈ I and we can conclude that P |=S,U ,R ϕ2 . 3. Assume an arbitrary model I |=S,U ,R P. Consider again the substitution θ = {Y 7→ c0 (Y )}. Note that the atom underlying ϕ3 and the head atom of R3 θ are r(c0 (Y ), c(X), Z) and r(c(X), c0 (Y ), Z), respectively. Moreover, the two annotated atoms Bj θ]wj (1 ≤ j ≤ 2) occurring in the body of R3 θ are such that I ``S,D,C Bj θ]ej ⇐ Π for suitable values ej ≥? wj , namely e1 = 0.9 and e2 = 1.0. Note that e1 = 0.9 works because B1 θ is the atom q(X, c0 (Y )) underlying ϕ1 and ϕ1 ∈ I, as proved in the first item of this example. On the other hand, e2 = 1.0 works because B2 θ is the primitive atom cp≥ (X, 0.0) which is trivially entailed by Π. All these facts, together with S(c, c0 ) = 0.9, 0.8 ≤ 0.9 × 0.9 and Π |=C X == Y allow to obtain ϕ3 as an immediate consequence of I via R3 . Therefore ϕ3 ∈ I and we can conclude that P |=S,U ,R ϕ3 . Now we are ready to obtain results on the declarative semantics of programs in the SQCLP scheme. We will characterize the observable consequences of a given program P in two different, but equivalent, ways: either using the interpretation transformer presented in Subsection 3.1.1, or using the extension of Horn Logic presented in Subsection 3.1.2. In both approaches, we will prove the existence of a least model MP for each given program P.

259

Fixpoint & Proof-theoretic Semantics for SQCLP

31

3.1.1 A Fixpoint Semantics A well-known way of characterizing models and least models of programs in declarative languages proceeds by considering a lattice structure for the family of all program interpretations, and using an interpretation transformer to compute the immediate consequences obtained from program rules. This kind of approach is well known for logic programming (van Emden and Kowalski 1976; Apt and van Emden 1982; Lloyd 1987; Apt 1990) and constraint logic programming (Gabbrielli and Levi 1991; Gabbrielli et al. 1995; Jaffar et al. 1998). It has been used also in various extensions of logic programming designed to support uncertain reasoning, such as quantitative logic programming (van Emden 1986), its extension to qualified logic programming (Rodr´ıguez-Artalejo and Romero-D´ıaz 2008b) quantitative constraint logic programming (Riezler 1996; Riezler 1998), similarity-based logic programming (Sessa 2002) and proximity-based logic programming in the sense of Bousi∼Prolog (Juli´an-Iranzo and Rubio-Manzano 2009a). The SQCLP scheme is intended to unify all these logic programming extensions in a common framework. This subsection is based on the declarative semantics given in (Rodr´ıguez-Artalejo and Romero-D´ıaz 2008b; Rodr´ıguez-Artalejo and RomeroD´ıaz 2008a), extended to deal with constraints and proximity relations. Our first result provides a lattice of program interpretations. Proposition 3.2 (Lattice of Interpretations) IntD,C , defined as the set of all qc-interpretations over the qualification domain D and the constraint domain C, is a complete lattice w.r.t. the set inclusion ordering ⊆. Moreover, the bottom element ⊥⊥ and the top element >> of this lattice are characterized as ⊥ ⊥ = ∅ and > > = {ϕ | ϕ is a defined observable qc-atom} and for any subset I ⊆ IntD,C its greatest lower bound (glb) and least upper bound (lub) are characterized as follows: d T 1. The glb of I (written as I) is I∈I I, understood as >> if I = ∅; and F S 2. The lub of I (written as I) is I∈I I, understood as ⊥⊥ if I = ∅. Proof Both ⊥⊥ and > > are qc-interpretations because they are sets of defined observable qc-atoms and they are closed under (D, C)-entailment for trivial reasons, namely: ⊥⊥ is empty and > > includes all the defined observables. Moreover, they are the minimum and the maximum of IntD,C w.r.t. ⊆ because ⊥⊥ ⊆ I ⊆ >> is trivially true for each I ∈ IntD,C . Thus, we have only left to prove 1. and 2.: T 1. I∈I I is obviously a set of defined observable qc-atoms because this is the case T for each I ∈ I. Given any ϕ ∈ I∈I and any observable defined qc-atom ϕ0 such T 0 0 that ϕ
260

32

M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz

S 2. Using the properties of the union of a family of sets it is easy to prove that I∈I I ∈ S IntD,C and also that I∈I I is the lub of I w.r.t. ⊆. A more detailed reasoning would S F be similar to the previous item. Therefore, I∈I I = I.

Next we define an interpretation transformer TP , intended to compute the immediate consequences obtained from a given qc-interpretation via the program rules belonging to P.

Definition 3.4 (Interpretations Transformer ) Let P be a fixed SQCLP(S, D, C)-program. The interpretations transformer TP : IntD,C → IntD,C is defined by the condition: TP (I) =def {ϕ | ϕ is an immediate consequence of I via some Rl ∈ P} . The computation of immediate consequences of a given qc-interpretation I via a given program rule Rl has been already explained in Definition 3.3. The following example illustrates the workings of TP . Example 3.4 (Interpretation transformer in action) Recall again the SQCLP(S, U, R)-program P from Example 3.1 and the observable defined qc-atoms ϕ1 , ϕ2 and ϕ3 from Example 3.2. Then: 1. The arguments given in Example 3.3(1) can be easily reused to show that ϕ1 is an immediate consequence of the empty interpretation ⊥⊥ via the program rule R1 . Therefore, ϕ1 ∈ TP (⊥⊥). 2. The arguments given in Example 3.3(2) can be easily reused to show that ϕ1 is an immediate consequence of I via the program rule R2 , provided that ϕ1 ∈ I. Therefore, ϕ2 ∈ TP (TP (⊥⊥)). 3. The arguments given in Example 3.3(3) can be easily reused to show that ϕ3 is an immediate consequence of I via the program rule R3 , provided that ϕ1 ∈ I. Therefore, ϕ3 ∈ TP (TP (⊥⊥)). The next proposition states the main properties of interpretation transformers. Proposition 3.3 (Properties of interpretation transformers) Let P be any fixed SQCLP(S, D, C)-program. Then: 1. TP is a well defined mapping, i.e. for all I ∈ IntD,C one has TP (I) ∈ IntD,C . 2. TP is monotonic and continuous. 3. For all I ∈ IntD,C one has: I |=S,D,C P ⇐⇒ TP (I) ⊆ I, That is, the models of P are precisely the pre-fixpoints of TP . Proof 1. By definition, TP (I) is a set of observable defined qc-atoms. It is sufficient to prove that it is closed under (D, C)-entailment. Let us assume two observable defined qcatoms ϕ and ϕ0 such that ϕ ∈ TP (I) and ϕ
261

Fixpoint & Proof-theoretic Semantics for SQCLP (a) (b) (c) (d)

33

S(p, q) = d0 , I ``S,D,C (ti == si σ)]di ⇐ Π for i = 1 . . . n, I ``S,D,C Bj σ]ej ⇐ Π with ej Q? wj for j = 1 . . . m, dn dm d P i=0 di u α ◦ j=1 ej [i.e., d P di (0 ≤ i ≤ n) and d P α ◦ ej (1 ≤ j ≤ m)].

In order to show that ϕ0 ∈ TP (I), we claim that ϕ0 can be computed as an immediate consequence of I via the same program rule Rl , using the substitution σθ and the qualification values d0 , d1 , . . . , dn , e1 , . . . , em ∈ D \ {b}. To justify this claim it is enough to check the following items: (a’) (b’) (c’) (d’)

S(p, q) = d0 , I ``S,D,C (t0i == si σθ)]di ⇐ Π0 for i = 1 . . . n, I ``S,D,C Bj σθ]ej ⇐ Π0 with ej Q? wj for j = 1 . . . m, dn dm d P i=0 di u α ◦ j=1 ej [i.e., d P di (0 ≤ i ≤ n) and d P α ◦ ej (1 ≤ j ≤ m)].

These four items closely correspond to items (a)-(d) above. More specifically: — Items (a’) and (d’) are identical to items (a) and (d), respectively. — Regarding item (b’): For i = 1 . . . n, I ``S,D,C (t0i == si σθ)]di ⇐ Π is the same as ti θ ≈di ,Π0 si σθ. Because of Lemma 2.8, this is a consequence of Π0 |=C Πθ and ti ≈di ,Π si σ, which is ensured by item (b). — Regarding item (c’): For j = 1 . . . m, ej Q? wj is ensured by item (c), and I ``S,D,C Bj σθ]ej ⇐ Π0 follows from I ``S,D,C Bj σ]ej ⇐ Π –also ensured by item (c)– and the entailment property for interpretations (Proposition 3.1), which can be applied because Bj σ]ej ⇐ Π
262

34

M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz

3. According to Definition 3.3, I |=S,D,C P holds iff every observable defined qc-atom ϕ which is an immediate consequence of I via the program rules Rl ∈ P verifies ϕ ∈ I. According to Definition 3.4, TP (I) is just the set of all the defined observable qc-atoms ϕ that can be obtained as immediate consequences of I via the program rules Rl ∈ P. Consequently, I |=S,D,C P holds iff TP (I) ⊆ I. The theorem below is the main result in this subsection. Theorem 3.1 (Fixpoint characterization of least program models) Every SQCLP(S, D, C)-program P has a least model MP , smaller than any other model of P w.r.t. the set inclusion ordering of the interpretation lattice IntD,C . Moreover, MP can be characterized as the least fixpoint of TP as follows: [ MP = lfp(TP ) = TP ↑k (⊥⊥) . k∈N

Proof As usual, a given I ∈ IntD,C is called a fixpoint of TP iff TP (I) = I, and I is called a pre-fixpoint of TP iff TP (I) ⊆ I. Due to a well-known theorem by Knaster and Tarski, see (Tarski 1955), a monotonic mapping from a complete lattice into itself always has a least fixpoint which is also its least pre-fixpoint. In the case that the mapping is continuous, its least fixpoint can be characterized as the lub of the sequence of lattice elements obtained by reiterated application of the mapping to the bottom element. Combining these results with Proposition 3.3 trivially proves the theorem. 3.1.2 An equivalent Proof-theoretic Semantics In order to give a logical view of program semantics and an alternative characterization of least program models, we define the Proximity-based Qualified Constrained Horn Logic SQCHL(S, D, C) as a formal inference system consisting of the three inference rules displayed in Figure 2.

SQDA

( (t0i == ti θ)]di ⇐ Π )i=1...n ( Bj θ]ej ⇐ Π )j=1...m p0 (t0 n )]d ⇐ Π α

SQEA SQPA

if (p(tn ) ← − B1 ]w1 , . . . , Bm ]wm ) ∈ P, θ subst., S(p0 , p) = d0 6= b, d dm ej Q? wj (1 ≤ j ≤ m) and d P n i=0 di u α ◦ j=1 ej . (t == s)]d ⇐ Π κ]d ⇐ Π

if t ≈d,Π s.

if Π |=C κ.

Fig. 2. Proximity-based Qualified Constrained Horn Logic

263

Fixpoint & Proof-theoretic Semantics for SQCLP

35

The three inference rules are intended to work with observable qc-atoms. Rule SQDA is used to infer defined qc-atoms. It formalizes an extension of the classical Modus Ponens inference, allowing to infer a defined qc-atom p0 (t0 n )]d ⇐ Π by means of an instance of a program clause with head p(tn )θ and body atoms Bj θ]wj . The n premises (t0i == ti θ)]di ⇐ Π combined with the side condition S(p0 , p) = d0 6= b ensure the “equality” between p0 (t0 n ) and p(tn )θ modulo S; the m premises Bj θ]ej ⇐ Π require to prove the body atoms; and the side conditions ej Q? wj dn dm and d P i=0 di u α ◦ j=1 ej check the threshold conditions of the body atoms and impose the proper relationships between the qualification value attached to the conclusion and the qualification values attached to the premises. In particular, the dm inequality d P α◦ j=1 ej is imposed, meaning that the qualification value attached to a clause’s head cannot exceed the glb of the qualification values attached to the body atoms attenuated by the clause’s attenuation factor. Rules SQEA and SQPA are used to infer equational and primitive qc-atoms, respectively. Rule SQEA is designed to work with term proximity w.r.t. Π in the sense of Definition 2.16, inferring (t == s)]d ⇐ Π just in the case that t ≈d,Π s holds. Rule SQPA infers κ]d ⇐ Π for an arbitrary d ∈ D \ {b}, provided that Π |=C κ holds. This makes sense because the requirements for admissible triples in Definition 2.14 include the assumption that S(p, p0 ) 6= b cannot happen if p, p0 ∈ P P are syntactically different primitive predicate symbols. As usual in formal inference systems, SQCHL(S, D, C) proofs can be represented as proof trees T whose nodes correspond to qc-atoms, each node being inferred from its children by means of some SQCHL(S, D, C) inference step. In the rest of the report we will use the following notations: • kT k will denote the size of the proof tree T , measured as its number of nodes, which equals the number of inference steps in the SQCHL(S, D, C) proof represented by T . • kT kd will denote the number of nodes of the proof tree T that represent conclusions of SQDA inference steps. Obviously, kT kd ≤ kT k. • P `S,D,C ϕ will indicate that ϕ can be inferred from P in SQCHL(S, D, C). • P `kS,D,C ϕ will indicate that ϕ can be inferred from P in SQCHL(S, D, C) using some proof tree T such that kT kd = k.

The next example shows a SQCHL(S, U, R) proof tree. Example 3.5 (SQCHL(S, D, C) proof tree) Recall the proximity relation S and the program P from our running Example 3.1, as well as the observable qc-statement ϕ2 = p0 (c0 (Y ), c(X))]0.8 ⇐ Π already known from Example 3.2. A SQCHL(S, U, R) proof tree witnessing P `S,U ,R ϕ2 can be displayed as follows:

♠=

(5) (6) (Y == Y )]1.0 ⇐ Π (c(X) == c(Y ))]1.0 ⇐ Π (4) q(Y, c(X))]1.0 ⇐ Π

264

36

M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz

(2) (3) (c0 (Y ) == c(Y ))]0.8 ⇐ Π (c(X) == c(X))]1.0 ⇐ Π 0 0 p (c (Y ), c(X))]0.8 ⇐ Π

♠ (4)

(1)

The inference steps in this proof are commented below. For the sake of clarity, we have used a different variant of the corresponding program clause for each each application of the inference rule SQDA. 0.9

(1) SQDA step with clause R1 = ( p(c(X1 ), Y1 ) ←−− q(X1 , Y1 ) ) instantiated by substitution θ1 = {X1 7→ Y, Y1 7→ c(X)}. Note that 0.8 satisfies 0.8 ≤ S(p, p0 ) = 0.8, 0.8 ≤ 0.8, 0.8 ≤ 1.0, 0.8 ≤ 0.9 × 1.0. (2) SQEA step. c0 (Y ) ≈0.8,Π c(Y ) holds due to c0 (Y ) ≈Π c0 (Y ), c(Y ) ≈Π c(Y ) and c0 (Y ) ≈0.8 c(Y ). (3) SQEA step. c(X) ≈1.0,Π c(X) holds for trivial reasons. 1.0

(4) SQDA step with clause R2 = ( q(X2 , c(X2 )) ←−− ) instantiated by substitution θ2 = {X2 7→ Y }. Note that 1.0 satisfies 1.0 ≤ S(q, q) = 1.0 and 1.0 ≤ 1.0. (5) SQEA step. Y ≈1.0,Π Y holds for trivial reasons. (6) SQEA step. c(X) ≈1.0,Π c(Y ) holds due to c(X) ≈Π c(Y ) (which follows from Π |=R X == Y ) and c(X) ≈1.0 c(X).

The next technical lemma establishes two basic properties of formal inference in the SQCHL(S, D, C) logic. Lemma 3.1 (Properties of SQCHL(S, D, C) derivability) Let P be any SQCLP(S, D, C)-program. Then: 1. P-independent Inferences: Given any C-based qc-atom ϕ and any qc-interpretation I, one has: P `0S,D,C ϕ ⇐⇒ P `S,D,C ϕ ⇐⇒ I ``S,D,C ϕ . 2. Entailment Property for Programs: Given any pair of qc-atoms ϕ and ϕ0 such that P `S,D,C ϕ with inference proof tree T and ϕ
265

Fixpoint & Proof-theoretic Semantics for SQCLP

37

2. ϕ is primitive. Then A is a primitive atom κ. Considering the SQCHL(S, D, C)inference rule SQPA and the second item of Definition 3.2, we get P `S,D,C ϕ ⇐⇒ Π |=C κ ⇐⇒ I ``S,D,C ϕ . Proof of Entailment Property for Programs Due to the hypothesis ϕ
• The SQDA root inference uses some Rl : (q(sn ) ← − B1 ]w1 , . . . , Bm ]wm ) ∈ P, some substitution σ and some qualification values d0 , d1 , . . . , dn , e1 , . . . em ∈ D \ {b} such that S(p, q) = d0 6= b, d P di (0 ≤ i ≤ n) and d P α ◦ ej (1 ≤ j ≤ m). • For i = 1 . . . n, (ti == si σ)]di ⇐ Π has a proof tree Tih with kTih k < kT k. • For j = 1 . . . m, Bj σ]ej ⇐ Π has a proof tree Tjb with kTjb k < kT k. Then, T 0 can be built as a proof tree of the form:    T0 :

(t0i

== si σθ)]di ⇐ Π0

i=1...n

··· Bj σθ]ej ⇐ Π0

p(t0 n )]d0 ⇐ Π0



j=1...m

SQDA

where: • The SQDA root inference uses the same program clause Rl ∈ P, the substitution σθ and the same qualification values di (0 ≤ i ≤ n) and ej (1 ≤ j ≤ m), satisfying S(p, q) = d0 6= b, d0 P d P di (0 ≤ i ≤ n) and d0 P d P α ◦ ej (1 ≤ j ≤ m). 0 • For i = 1 . . . n, (t0i == si σθ)]di ⇐ Π0 has a proof tree Ti h of the same size 0 and structure as Tih . In fact, Ti h can be obtained by induction hypothesis applied to Tih , which is allowed because kTih k < kT k and (ti == si σ)]di ⇐ Π
266

38

M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz

By construction, T 0 has the same size and structure as T , as desired. 2. A is an equation: In this case, A : t == s and A0 : t0 == s0 with t0 = tθ, s0 = sθ. Moreover, T must consist of one single node (t == s)]d ⇐ Π inferred by means of SQEA. Therefore, t ≈d,Π s holds. This implies tθ ≈d,Πθ sθ (i.e. t0 ≈d,Πθ s0 ) due to the Substitution Lemma 2.8. From this we conclude t0 ≈Π0 s0 due to d0 P d and Π0 |=C Πθ. Therefore, T 0 can be built as a proof tree consisting of one single node (t0 == s0 )]d0 ⇐ Π0 inferred by means of SQEA. 3. A is a primitive atom: In this case, A : κ and A0 : κ0 = κθ. Moreover, T must consist of one single node κ]d ⇐ Π inferred by means of SQPA. Therefore, Π |=C κ holds. This implies Πθ |=C κθ due to the Substitution Lemma 2.1. From this we conclude Π0 |=C κ0 due to κ0 = κθ and Π0 |=C Πθ. Therefore, T 0 can be built as a proof tree consisting of one single node κ0 ]d0 ⇐ Π0 inferred by means of SQPA. The following theorem is the main result in this subsection. It characterizes the least model of a SQCLP(S, D, C)-program P w.r.t. the logic SQCHL(S, D, C): Theorem 3.2 (Logical characterization of least program models) For any SQCLP(S, D, C)-program P, its least model can be characterized as: MP = {ϕ | ϕ is a defined observable qc-atom and P `S,D,C ϕ} . Proof S By Theorem 3.1, we already know that MP = k∈N TP ↑k (⊥⊥). Therefore, it is sufficient to prove that the two implications 0

⊥) 1. P `kS,D,C ϕ =⇒ ∃k 0 : ϕ ∈ TP ↑k (⊥ 0

2. ϕ ∈ TP ↑k (⊥⊥) =⇒ ∃k 0 : P `kS,D,C ϕ

hold for any defined observable qc-atom ϕ = p(tn )]d ⇐ Π and for any integer value k ≥ 1. We prove both implications within one single inductive reasoning on k. Basis (k = 1). — Implication 1. Assume P `1S,D,C ϕ. Then, due to the single SQDA inference, α there must exist some Rl = (q(sn ) ← −) ∈ P with empty body, some substitution θ and some d0 , d1 , . . . , dn ∈ D \ {b} such that P `0S,D,C (ti == si θ)]di ⇐ Π for i = 1 . . . n, S(p, q) = d0 6= b, d P di (0 ≤ i ≤ n) and d P α. Then ⊥⊥ `0S,D,C (ti == si θ)]di ⇐ Π holds for i = 1 . . . n, because of Lemma 3.1(1). Therefore ϕ is an immediate consequence of ⊥⊥ via Rl , which guarantees ϕ ∈ TP ↑1 (⊥⊥). — Implication 2. Assume now ϕ ∈ TP ↑1 (⊥ ⊥). Then ϕ must be an immediate α consequence of ⊥ ⊥ via some Rl = (q(sn ) ← −) ∈ P with empty body. Then there are some substitution θ and some d0 , d1 , . . . , dn ∈ D \{b} such that ⊥⊥ ``S,D,C (ti == si θ)]di ⇐ Π for i = 1 . . . n, S(p, q) = d0 6= b, d P di (0 ≤ i ≤ n) and d P α. Again because of Lemma 3.1(1), we get P `0S,D,C (ti == si θ)]di ⇐ Π for i = 1 . . . n, which guarantees P `1S,D,C ϕ with one single SQDA inference using Rl instantiated by θ.

267

Fixpoint & Proof-theoretic Semantics for SQCLP

39

Inductive step (k > 1). — Implication 1. Assume P `kS,D,C ϕ. Since the root inference must be SQDA, α there must exist some program rule (Rl : q(sn ) ← − B1 ]w1 , . . . , Bm ]wm ) ∈ P, some substitution θ and some qualification values d0 , d1 , . . . , dn , e1 , . . . , em ∈ D \ {b} such that • P `0S,D,C φi = ((ti == si θ)]di ⇐ Π) for i = 1 . . . n, k

j ψj = (Bj θ]ej ⇐ Π) with ej Q? wj for j = 1 . . . m, and • P `S,D,C • S(p, q) = d0 6= b, d P di (0 ≤ i ≤ n) and d P α ◦ ej (1 ≤ j ≤ m)

where Σm j=1 kj = k − 1. For each j = 1 . . . m, either ψj is defined, and then in0

duction hypothesis yields some kj0 such that ψj ∈ TP ↑kj (⊥⊥) and therefore also kj0

0

TP ↑ (⊥ ⊥) ``S,D,C ψj ; or else ψj is not defined and then TP ↑kj (⊥⊥) ``S,D,C ψj for any arbitrarily chosen kj0 , by Lemma 3.1(1). Then l = max{kj0 | 1 ≤ j ≤ m} verifies that ϕ is an immediate consequence of TP ↑l (⊥⊥) via Rl , which implies 0 ϕ ∈ TP ↑k (⊥ ⊥) for k 0 = l + 1. — Implication 2. Assume ϕ ∈ TP ↑k (⊥⊥) = TP (TP ↑k−1 (⊥⊥)). Then ϕ is an imα mediate consequence of T p↑k−1 (⊥⊥) via some clause (Rl : q(sn ) ← − B1 ]w1 , . . . , Bm ]wm ) ∈ P. Therefore, there exist some substitution θ and some qualification values d0 , d1 , . . . , dn , e1 , . . . , em ∈ D \ {b} such that: • TP ↑k−1 (⊥ ⊥) ``S,D,C φi = ((ti == si θ)]di ⇐ Π) for i = 1 . . . n,

• TP ↑k−1 (⊥⊥) ``S,D,C ψj = (Bj θ]ej ⇐ Π) with ej Q? wj for j = 1 . . . m, and • S(p, q) = d0 6= b, d P di (0 ≤ i ≤ n) and d P α ◦ ej (1 ≤ j ≤ m).

For each i = 1 . . . n, Lemma 3.1(1) yields P `0S,D,C φi . For each j = 1 . . . m, either ψj is defined, in which case ψj ∈ TP ↑k−1 (⊥⊥), k − 1 ≥ 1, and induction k0

j hypothesis yields some kj0 such that P `S,D,C ψj ; or else ψj is not defined, in which

k0

0

j case P `S,D,C ψj for kj0 = 0, by Lemma 3.1(1). In these conditions, P `kS,D,C ϕ 0 holds for k 0 = 1 + Σm j=1 kj , with a proof tree using a SQDA root inference based on Rl instantiated by θ.

As an easy consequence of the previous theorem we get: Corollary 3.1 (SQCHL(S, D, C) is sound and complete) For any SQCLP(S, D, C)-program P and any observable qc-atom ϕ, the following three statements are equivalent: (a) P `S,D,C ϕ

(b) P |=S,D,C ϕ

Moreover, we also have: 1. Soundness: P `S,D,C ϕ =⇒ P |=S,D,C ϕ. 2. Completeness: P |=S,D,C ϕ =⇒ P `S,D,C ϕ.

268

(c) MP ``S,D,C ϕ

40

M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz

Proof Soundness and completeness are just a trivial consequence of (a) ⇔ (b). To finish the proof it suffices to prove the two equivalences (a) ⇔ (c) and (b) ⇔ (c). This is done as follows: [(a) ⇔ (c)] In the case that ϕ is a defined qc-atom, MP ``S,D,C ϕ reduces to ϕ ∈ MP which is equivalent to P `S,D,C ϕ by Theorem 3.2. Otherwise, P `S,D,C ϕ ⇐⇒ MP ``S,D,C ϕ holds because of Lemma 3.1(1).

[(b) ⇒ (c)] Assume P |=S,D,C ϕ and recall Definition 3.3. Then I ``S,D,C ϕ for every qc-interpretation I such that I |=S,D,C P. In particular, MP ``S,D,C ϕ, since MP |=S,D,C P was proved in Theorem 3.1. [(c) ⇒ (b)] Assume MP ``S,D,C ϕ. In order to obtain P |=S,D,C ϕ we must prove: (?) I ``S,D,C ϕ holds for any qc-interpretation I such that I |=S,D,C P . In the case that ϕ is a defined qc-atom, MP ``S,D,C ϕ reduces to ϕ ∈ MP , which implies (?) because MP is the least model of P, as proved in Theorem 3.1. In the case that ϕ is not defined but C-based, (?) follows form the fact that I ``S,D,C ϕ holds for any arbitrary qc-interpretation I, as proved in Lemma 3.1(1).

We close this subsection with a brief discussion on the relationship between the entailment relation
R1 : p1 ←−−

and assume that S verifies S(p1 , p2 ) = 0.9, S(p2 , p3 ) = 0.9 and S(p1 , p3 ) = 0.4 where p1 , p2 , p3 ∈ DP 0 . Then, P `S,U ,R p2 ]0.9 ⇐ ∅ can be easily proved with the SQCHL rule SQDA and p2 ]0.9 ⇐ ∅
269

Fixpoint & Proof-theoretic Semantics for SQCLP

41

which are expected to be fulfilled by goal solving devices. These notions are intended as a useful tool to reason about the correctness of SQCLP implementations to be developed in the future. In order to build goals for SQCLP(S, D, C)-programs, we assume a countably infinite set War of so-called qualification variables W , disjoint from Var and C’s signature Σ. Goals for a given program P have the form G : A1 ]W1 , . . . , Am ]Wm 8 W1 Q? β1 , . . . , Wm Q? βm

abbreviated as (Ai ]Wi , Wi Q? βi )i=1...m , where Ai ]Wi (1 ≤ i ≤ m) are atoms annotated with different qualification variables Wi ; and Wi Q? βi are so-called threshold conditions with βi ∈ (D \ {b}) ] {?} (1 ≤ i ≤ m). The notations ? and Q? have been already explained in Section 3.1. In the sequel, the notation war(o) will denote the set of all qualification variables occurring in the syntactic object o. In particular, for a goal G as displayed above, war(G) denotes the set {Wi | 1 ≤ i ≤ m}. In the case m = 1 the goal is called atomic. The declarative semantics of goals is provided by their solutions, that are defined as follows: Definition 3.5 (Goal Solutions) Assume a given SQCLP(S, D, C)-program P and a goal G for the program P with the syntax displayed above. Then: 1. A solution for G is any triple hσ, µ, Πi such that σ is a C-substitution, µ : war(G) → D \ {b}, Π is a satisfiable and finite set of atomic C-constraints and the following two conditions hold for all i = 1 . . . m: (a) Wi µ = di Q? βi and (b) P `S,D,C Ai σ]Wi µ ⇐ Π.

The set of all solutions for G is noted SolP (G). Note that solutions are open in the sense that the substitution σ is not required to be ground. 2. A solution hη, ρ, Πi for G is called ground iff Π = ∅ and η ∈ ValC is a variable valuation such that Ai η is a ground atom for all i = 1 . . . m. The set of all ground solutions for G is noted GSolP (G). Obviously, GSolP (G) ⊆ SolP (G). 3. A ground solution hη, ρ, ∅i ∈ GSolP (G) is subsumed by hσ, µ, Πi iff there is some ν ∈ SolC (Π) s.t. η =var(G) σν and Wi ρ P Wi µ for i = 1 . . . m.

Implicitly, the first item in the previous definition requires Ai σ]Wi µ ⇐ Π to be observable qc-atoms in the sense of Definition 3.1, which is trivially true because Wi µ = di ∈ D \ {b} and Π is satisfiable. In fact, Definition 3.1 was designed with the aim of using observable qc-atoms as observations of valid open solutions for atomic goals. The next example illustrates the definition: Example 3.6 (Solutions for an atomic goals) 1. G : goodWork(X)]W 8 W Q (0.55,30) is a goal for the program fragment P shown in Figure 1, and the arguments given near the beginning of Subsection 3.1 can be formalized to prove that h{X 7→ king liar}, {W 7→ (0.6,5)}, ∅i ∈ SolP (G).

270

42

M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz 2. As an additional example involving constraints, recall the SQCLP(S, U, R)program P presented in Example 3.1. An atomic goal G for this program is p0 (c0 (Y ), Z)]W 8 W ≥? 0.75. Consider σ = {Z 7→ c(X)}, µ = {W 7→ 0.8} and Π = {cp> (X, 1.0), op+ (A, A, X), op× (2.0, A, Y )}. Note that 0.8 ≥ 0.75 and P `S,U ,R p0 (c0 (Y ), Z)σ]W µ ⇐ Π, as we have seen in Example 3.5. Therefore, the requirements of Definition 3.5 are fulfilled, and hσ, µ, Πi ∈ SolP (G).

In practice, users of SQCLP languages will rely on some available goal solving system for computing goal solutions. The following definition specifies two important properties of goal solving systems: Definition 3.6 (Correct Goal Solving Systems) At a high abstraction level, a goal solving system for SQCLP(S, D, C) can be thought as a device that takes a program P and a goal G as input and yields various triples hσ, µ, Πi, called computed answers, as outputs. Such a goal solving system is called: 1. Sound iff every computed answer is a solution hσ, µ, Πi ∈ SolP (G). 2. Weakly complete iff every ground solution hη, ρ, ∅i ∈ GSolP (G) is subssumed by some computed answer. 3. Correct iff it is both sound and weakly complete. Every goal solving system for a SQCLP instance should be sound and ideally also weakly complete. Implementing such systems is one of the major lines of future research mentioned in the Conclusions of this report. 4 Conclusions We have extended the classical CLP scheme to a new scheme SQCLP whose instances SQCLP(S, D, C) are parameterized by a proximity relation S, a qualification domain D and a constraint domain C. In addition to the known features of CLP programming, the new scheme offers extra facilities for dealing with expert knowledge representation and flexible query answering. Inspired by the observable CLP semantics in (Gabbrielli and Levi 1991; Gabbrielli et al. 1995), we have presented a declarative semantics for SQCLP that provides fixpoint and proof-theoretical characterizations of least program models as well as an implementation-independent notion of goal solutions. SQCLP is a quite general scheme. Different partial instantiations of its three parameters lead to more particular schemes, most of which can be placed in close correspondence to previous proposals. The items below present seven particularizations, along with some comments which make use of the notions threshold-free, attenuation-free and constraint-free which have been explained at the beginning of Section 3.1. 1. By definition, QCLP has instances QCLP(D, C) =def SQCLP(Sid , D, C), where Sid is the identity proximity relation. The quantitative CLP scheme proposed in (Riezler 1998) can be understood as a further particularization of QCLP that works with threshold-free QCLP(U, C) programs, where U is the qualification domain of uncertainty values (see Subsection 2.2.2).

271

Fixpoint & Proof-theoretic Semantics for SQCLP

43

2. By definition, SQLP has instances SQLP(S, D) =def SQCLP(S, D, R), where R is the real constraint domain (see Subsection 2.1.2). The scheme with the same name originally proposed in (Caballero et al. 2008) can be understood as a restricted form of the present formulation; it worked with threshold-free and constraint-free SQLP(S, D) programs and it restricted the choice of the S parameter to transitive proximity (i.e. similarity) relations. 3. By definition, SCLP3 has instances SCLP(S, C) =def SQCLP(S, B, C), where B is the qualification domain of classical boolean values (see Subsection 2.2.1). Due to the fixed parameter choice D = B, both attenuation values and threshold values become useless, and each choice of S must necessarily represent a crisp reflexive and symmetric relation. Therefore, this new scheme is not so interesting from the viewpoint of uncertain and qualified reasoning. 4. By definition, QLP has instances QLP(D) =def SQCLP(Sid , D, R). The scheme with the same name originally proposed in (Rodr´ıguez-Artalejo and RomeroD´ıaz 2008b) can be understood as a restricted form of the present formulation; it worked with threshold-free and constraint-free QLP(D) programs. 5. By definition, SLP has instances SLP(S) =def SQCLP(S, U, R). The pure fragment of Bousi~Prolog (Juli´an-Iranzo and Rubio-Manzano 2009a) can be understood as a restricted form of SLP in the present formulation; it works with threshold-free, attenuation-free and constraint-free SLP(S) programs. Moreover, restricting the choice of S to similarity relations leads to SLP in the sense of (Sessa 2002) and related papers. 6. The CLP scheme can be defined by instances CLP(C) =def SQCLP(Sid , B, C). Both attenuation values and threshold values are useless in CLP programs, due to the fixed parameter choice D = B. 7. Finally, the pure LP paradigm can be defined as LP =def SQCLP(Sid , B, H), where H is the Herbrand constraint domain. Again, attenuation values and threshold values are useless in LP due to the fixed parameter choice D = B. In all the previous items, the schemes obtained by partial instantiation inherit the declarative semantics from SQCLP, using sets of observables of the form A]d ⇐ Π as interpretations. A similar semantic approach were used in our previous papers (Rodr´ıguez-Artalejo and Romero-D´ıaz 2008b; Caballero et al. 2008), except that Π and equations were absent due to the lack of CLP features. The other related works discussed in the Introduction view program interpretations as mappings I from the ground Herbrand base into some set of lattice elements (the real interval [0, 1] in many cases), as already discussed in the explanations following Definition 3.2. As seen in Subsection 3.2, SQCLP’s semantics enables a declarative characterization of valid goal solutions. This fact is relevant for modeling the expected behavior of goal solving devices and reasoning about their correctness. Moreover, the relations ≈λ,Π introduced for the first time in the present paper (see Definition 2.16) allow to specify the semantic role of S in a constraint-based framework, with less technical overhead than in previous related approaches. 3

Not to be confused with SCLP in the sense of (Bistarelli et al. 2001), discussed below.

272

44

M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz

A related work not mentioned in items 1–7 above is the semiring-based CLP of (Bistarelli et al. 2001), a scheme with instances SCLP(S) parameterized by a semiring S = hA, +, ×, 0, 1i whose elements are used to represent consistency levels in soft constraint solving. The semirings used in this approach can be equipped with a lattice structure whose lub operation is always +, but whose glb operation may be different from ×. On the other hand, our qualification domains are defined as lattices with an additional attenuation operation ◦. It turns out that the kind of semirings used in SCLP(S) correspond to qualification domains only in some cases. Moreover, × is used in SCLP(S) to interpret logical conjunction in clause bodies and goals, while the glb operation is used in SQCLP(S, D, C) for the same purpose. For this reason, even if D is “equivalent” to S, SQCLP(S, D, C) cannot be naturally used to express SCLP(S) in the case that × is not the glb. Assuming that D is “equivalent” to S and that × behaves as the glb in S, program clauses in SCLP(S) can be viewed as a particular case of program clauses in SQCLP(S, D, C) which use an attenuation factor different from t only for facts. Other relevant differences between SQCLP(S, D, C) and SCLP(S) can be explained by comparing the parameters. As said before D may be “equivalent” to S in some cases, but S is absent and C is not made explicit in SCLP(S). Seemingly, the intended use of SCLP(S) is related to finite domain constraints and no parametrically given constraint domain is provided. In the future we plan to implement some SQCLP instances by extending the semantically correct program transformation techniques from (Caballero et al. 2008), and to investigate applications which can profit from flexible query answering. Other interesting lines of future work include: a) extension of the qualified SLD resolution presented in (Rodr´ıguez-Artalejo and Romero-D´ıaz 2008b) to a SQCLP goal solving procedure able to work with constraints and a proximity relation; and b) extension of the QCFLP scheme in (Caballero et al. 2009) to work with a proximity relation and higher-order functions. Acknowledgements This report is a widely extended version of (Rodr´ıguez-Artalejo and Romero-D´ıaz 2010). The authors are thankful to the anonymous referees of (Rodr´ıguez-Artalejo and Romero-D´ıaz 2010) for constructive remarks and suggestions which helped to improve the presentation. They are also thankful to Rafael Caballero for useful discussions on the report’s topics and to Jes´ us Almendros for pointing to bibliographic references in the area of flexible query answering. References Apt, K. R. 1990. Logic programming. In Handbook of Theoretical Computer Science, J. van Leeuwen, Ed. Vol. B: Formal Models and Semantics. Elsevier and The MIT Press, 493–574. Apt, K. R. and Gabbrielli, M. 1994. Declarative interpretations reconsidered. In Proceedings of the 11th International Conference on Logic Programming (ICLP’94), P. van Hentenryck, Ed. The MIT Press, 74–89.

273

Fixpoint & Proof-theoretic Semantics for SQCLP

45

Apt, K. R. and van Emden, M. H. 1982. Contributions to the theory of logic programming. Journal of the Association for Computing Machinery (JACM) 29, 3, 841–862. Arcelli, F. and Formato, F. 1999. Likelog: a logic programming language for flexible data retrieval. In Proceedings of the 1999 ACM Symposium on Applied computing (SAC’99). ACM Press, New York, NY, USA, 260–267. ´ ndez, A. J., Gil, A., Lo ´ pez-Fraguas, F. J., Rodr´ıguez-Artalejo, Arenas, P., Ferna ´ enz-Pe ´rez, F. 2007. T OY, a multiparadigm declarative language (version M., and Sa 2.3.1). In R. Caballero and J. S´ anchez, editors, User Manual, available at http://toy. sourceforge.net. Baader, F. and Nipkow, T. 1998. Term Rewriting and All That. Cambridge University Press. Bistarelli, S., Montanari, U., and Rossi, F. 2001. Semiring-based constraint logic programming: Syntax and semantics. ACM Transactions on Programming Languages and Systems 3, 1 (January), 1–29. Bossi, A., Gabbrielli, M., Levi, G., and Martelli, M. 1994. The s-semantics approach: Theory and applications. Journal of Logic Programming 19/20, 149–197. Caballero, R., Rodr´ıguez-Artalejo, M., and Romero-D´ıaz, C. A. 2008. Similaritybased reasoning in qualified logic programming. In PPDP ’08: Proceedings of the 10th international ACM SIGPLAN conference on Principles and Practice of Declarative Programming. ACM, Valencia, Spain, 185–194. Caballero, R., Rodr´ıguez-Artalejo, M., and Romero-D´ıaz, C. A. 2009. Qualified computations in functional logic programming. In Logic Programming (ICLP’09), P. Hill and D. Warren, Eds. LNCS, vol. 5649. Springer-Verlag Berlin Heidelberg, Pasadena, CA, USA, 449–463. Clark, K. L. 1979. Predicate logic as a computational formalism (res. report doc 79/59). Tech. rep., Imperial College, Dept. of Computing, London. Dubois, D. and Prade, H. 1980. Fuzzy Sets and Systems: Theory and Applications. Academic Press, New York, NY, USA. ´vez-Mart´ın, S., Hortala ´ -Gonza ´ lez, T., Rodr´ıguez-Artalejo, M., del Este ´ enz-Pe ´rez, F., and Ferna ´ ndez, A. J. 2009. On the coopVado V´ırseda, R., Sa eration of the constraint domains H, R and FD in cf lp. Theory and Practice of Logic Programming 9, 4, 415–527. Falaschi, M., Levi, G., Martelli, M., and Palamidessi, C. 1993. A model-theoretic reconstruction of the operational semantics of logic programs. Information and Computation 102, 1, 86–113. Falaschi, M., Levi, G., Palamidessi, C., and Martelli, M. 1989. Declarative modeling of the operational behavior of logic languages. Theoretical Computer Science 69, 3 (December), 289–318. Freuder, E. C. and Wallace, R. J. 1992. Partial constraint satisfaction. Artificial Intelligence 58, 1–3, 21–70. Gabbrielli, M., Dore, G. M., and Levi, G. 1995. Observable semantics for constraint logic programs. Journal of Logic and Computation 5, 2, 133–171. Gabbrielli, M. and Levi, G. 1991. Modeling answer constraints in constraint logic programs. In Proceedings of the 8th International Conference on Logic Programming (ICLP’91). The MIT Press, 238–252. Georget, Y. and Codognet, P. 1998. Compiling semiring-based constraints with CLP(FD,S). In Proceedings of the 4th International Conference on Principles and Practice of Constraint Programming. LNCS, vol. 1520. Springer-Verlag, 205–219. ˜ oz, S., and Vaucheret, C. 2004. Fuzzy prolog: A new approach Guadarrama, S., Mun using soft constraint propagation. Fuzzy Sets and Systems 144, 1, 127–150.

274

46

M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz

´ jek, P. 1998. Metamathematics of Fuzzy Logic. Dordrecht: Kluwer. Ha Hanus, Ed., M. Curry: An integrated functional logic language (vers. 0.8.2, 2006); http: //www.curry-language.org. ¨ hfeld, M. and Smolka, G. 1988. Definite relations over constraint languages. Tech. Ho Rep. LILOG Report 53, IBM Deutschland. Jaffar, J. and Lassez, J. L. 1987. Constraint logic programming. In Proceedings of the 14th ACM SIGACT-SIGPLAN symposium on Principles of Programming Languages (POPL’87). ACM New York, NY, USA, Munich, West Germany, 111–119. Jaffar, J. and Maher, M. 1994. Constraint logic programming: a survey. Journal of Logic Programming 19&20, 503–581. Jaffar, J., Maher, M., Marriott, K., and Stuckey, P. J. 1998. Semantics of constraints logic programs. Journal of Logic Programming 37, 1-3, 1–46. Jaffar, J., Michaylov, S., Stuckey, P. J., and Yap, R. H. C. 1992. The CLP(R) language and system. ACM Transactions on Programming Languages and Systems 14(3), 339–395. ´ n-Iranzo, P., Rubio, C., and Gallardo, J. 2009. Bousi∼Prolog: a prolog extenJulia sion language for flexible query answering. In Proceedings of the Eighth Spanish Conference on Programming and Computer Languages (PROLE 2008), J. M. AlmendrosJim´enez, Ed. ENTCS, vol. 248. Elsevier, Gij´ on, Spain, 131–147. ´ n-Iranzo, P. and Rubio-Manzano, C. 2009a. A declarative semantics for Julia Bousi∼Prolog. In PPDP’09: Proceedings of the 11th ACM SIGPLAN conference on Principles and practice of declarative programming. ACM, Coimbra, Portugal, 149–160. ´ n-Iranzo, P. and Rubio-Manzano, C. 2009b. A similarity-based WAM for Julia Bousi∼Prolog. In Bio-Inspired Systems: Computational and Ambient Intelligence (IWANN 2009). LNCS, vol. 5517. Springer Berlin / Heidelberg, Salamanca, Spain, 245– 252. Kifer, M. and Subrahmanian, V. S. 1992. Theory of generalized annotated logic programs and their applications. Journal of Logic Programming 12, 3&4, 335–367. ˇi, S., Lencses, R., and Vojta ´ˇ Krajc s, P. 2004. A comparison of fuzzy and annotated logic programming. Fuzzy Sets and Systems 144, 173–192. Lloyd, J. W. 1987. Foundations of Logic Programming, Second Edition. Springer. Loia, V., Senatore, S., and Sessa, M. I. 2004. Similarity-based SLD resolution and its role for web knowledge discovery. Fuzzy Sets and Systems 144, 1, 151–171. ´ pez-Fraguas, F. J., Rodr´ıguez-Artalejo, M., and del Vado-V´ırseda, R. 2007. Lo A new generic scheme for functional logic programming with constraints. Journal of Higher-Order and Symbolic Computation 20, 1&2, 73–122. Lucio, P., Orejas, F., Pasarella, E., and Pino, E. 2008. A functorial framework for constraint normal logic programming. Applied Categoriacal Structures 16, 3, 421–450. ´ˇ Medina, J., Ojeda-Aciego, M., and Vojta s, P. 2001a. Multi-adjoint logic programming with continuous semantics. In Logic Programming and Non-Monotonic Reasoning (LPNMR’01), T. Eiter, W. Faber, and M. Truszczyinski, Eds. LNAI, vol. 2173. SpringerVerlag, 351–364. ´ˇ Medina, J., Ojeda-Aciego, M., and Vojta s, P. 2001b. A procedural semantics for multi-adjoint logic programming. In Progress in Artificial Intelligence (EPIA’01), P. Brazdil and A. Jorge, Eds. LNAI, vol. 2258. Springer-Verlag, 290–297. Moreno, G. and Pascual, V. 2007. Formal properties of needed narrowing with similarity relations. Electronic Notes in Theoretical Computer Science 188, 21–35. Ng, R. T. and Subrahmanian, V. S. 1992. Probabilistic logic programming. Information and Computation 101, 2, 150–201.

275

Fixpoint & Proof-theoretic Semantics for SQCLP

47

Riezler, S. 1996. Quantitative constraint logic programming for weighted grammar applications. In Proceedings of the Logical Aspects of Computational Linguistics (LACL’96), C. Retor´e, Ed. LNCS, vol. 1328. Springer-Verlag, 346–365. Riezler, S. 1998. Probabilistic constraint logic programming. Ph.D. thesis, Neuphilologischen Fakult¨ at del Universit¨ at T¨ ubingen. Rodr´ıguez-Artalejo, M. and Romero-D´ıaz, C. A. 2008a. A generic scheme for qualified logic programming. Tech. Rep. SIC-1-08 (CoRR abs/1008.3863), Universidad Complutense, Departamento de Sistemas Inform´ aticos y Computaci´ on, Madrid, Spain. Rodr´ıguez-Artalejo, M. and Romero-D´ıaz, C. A. 2008b. Quantitative logic programming revisited. In Functional and Logic Programming (FLOPS’08), J. Garrigue and M. Hermenegildo, Eds. LNCS, vol. 4989. Springer-Verlag, Ise, Japan, 272–288. Rodr´ıguez-Artalejo, M. and Romero-D´ıaz, C. A. 2009. Qualified logic programming with bivalued predicates. In Proceedings of the Eighth Spanish Conference on Programming and Computer Languages (PROLE 2008), J. M. Almendros-Jim´enez, Ed. ENTCS, vol. 248. Elsevier, Gij´ on, Spain, 67–82. Rodr´ıguez-Artalejo, M. and Romero-D´ıaz, C. A. 2010. A declarative semantics for CLP with qualification and proximity. Theory and Practice of Logic Programming, 26th Int’l. Conference on Logic Programming (ICLP’10) Special Issue 10, 4–6, 627–642. Saraswat, V. A. 1992. The category of constraint systems is cartesian-closed. In Proceedings of the Seventh Annual IEEE Symposium on Logic in Computer Science (LICS ’92). 341–345. Sessa, M. I. 2002. Approximate reasoning by similarity-based SLD resolution. Theoretical Computer Science 275, 1-2, 389–426. Shenoi, S. and Melton, A. 1999. Proximity relations in the fuzzy relational database model. Fuzzy Sets and Systems 100, supl., 51–62. Tarski, A. 1955. A lattice-theoretical fixpoint theorem and its applications. Pacific Journal of Mathematics 5, 2, 285–309. van Emden, M. H. 1986. Quantitative deduction and its fixpoint theory. Journal of Logic Programming 3, 1, 37–53. van Emden, M. H. and Kowalski, R. A. 1976. The semantics of predicate logic as a programming language. Journal of the Association for Computing Machinery (JACM) 23, 4, 733–742. ˜ oz, S. 2002. Fuzzy prolog: A simple general Vaucheret, C., Guadarrama, S., and Mun implementation using CLP(R). In Logic for Programming, Artificial Intelligence, and Reasoning (LPAR’02), M. Baaz and A. Voronkov, Eds. LNCS, vol. 2514. Springer Berlin / Heidelberg, Tbilisi, Georgia, 450–463. ´ˇ Vojta s, P. 2001. Fuzzy logic programming. Fuzzy Sets and Systems 124, 361–370. Zadeh, L. A. 1965. Fuzzy sets. Information and Control 8, 3, 338–353. Zadeh, L. A. 1971. Similarity relations and fuzzy orderings. Information Sciences 3, 2, 177–200.

276

A Transformation-based Implementation for CLP with Qualification and Proximity ∗ Preliminary Version (Technical Report SIC-4-10)

R. CABALLERO, M. RODR´IGUEZ-ARTALEJO and C. A. ROMERO-D´IAZ Departamento de Sistemas Inform´ aticos y Computaci´ on, Universidad Complutense Facultad de Inform´ atica, 28040 Madrid, Spain (e-mail: {rafa,mario}@sip.ucm.es, cromdia@fdi.ucm.es)

Abstract Uncertainty in logic programming has been widely investigated in the last decades, leading to multiple extensions of the classical LP paradigm. However, few of these are designed as extensions of the well-established and powerful CLP scheme for Constraint Logic Programming. In a previous work we have proposed the SQCLP (proximity-based qualified constraint logic programming) scheme as a quite expressive extension of CLP with support for qualification values and proximity relations as generalizations of uncertainty values and similarity relations, respectively. In this paper we provide a transformation technique for transforming SQCLP programs and goals into semantically equivalent CLP programs and goals, and a practical Prolog-based implementation of some particularly useful instances of the SQCLP scheme. We also illustrate, by showing some simple—and working—examples, how the prototype can be effectively used as a tool for solving problems where qualification values and proximity relations play a key role. Intended use of SQCLP includes flexible information retrieval applications. KEYWORDS: Constraint Logic Programming, Program Transformation, Qualification Domains and Values, Similarity and Proximity Relations, Flexible Information Retrieval.

1 Introduction Many extensions of LP (logic programming) to deal with uncertain knowledge and uncertainty have been proposed in the last decades. These extensions have been proposed from different and somewhat unrelated perspectives, leading to multiple approaches in the way of using uncertain knowledge and understanding uncertainty. A recent work by us (Rodr´ıguez-Artalejo and Romero-D´ıaz 2010a) focuses on the declarative semantics of a new proposal for an extension of the CLP scheme supporting qualification values and proximity relations. More specifically, this work defines a new generic scheme SQCLP (proximity-based qualified constraint logic programming) whose instances SQCLP(S, D, C) are parameterized by a proximity ∗ This work has been partially supported by the Spanish projects STAMP (TIN2008-06622-C0301), PROMETIDOS–CM (S2009TIC-1465) and GPD–UCM (UCM–BSCH–GR58/08-910502).

277

2

R. Caballero, M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz

relation S, a qualification domain D and a constraint domain C. The current paper is intended as a continuation of (Rodr´ıguez-Artalejo and Romero-D´ıaz 2010a) with the aim of providing a semantically correct program transformation technique that allows us to implement a sound and complete implementation of some useful instances of SQCLP on top of existing CLP systems like SICStus Prolog or SWI-Prolog. In the introductory section of (Rodr´ıguez-Artalejo and Romero-D´ıaz 2010a) we have already summarized some related approaches of SQCLP with a special emphasis on their declarative semantics and their main semantic differences with SQCLP. In the next paragraphs we present a similar overview but, this time, putting the emphasis on the goal resolution procedures and system implementation techniques, when available. Within the extensions of LP using annotations in program clauses we can find the seminal proposal of quantitative logic programming by (van Emden 1986) that inspired later works such as the GAP (generalized annotated programs) framework by (Kifer and Subrahmanian 1992) and the QLP (qualified logic programming) scheme by us (Rodr´ıguez-Artalejo and Romero-D´ıaz 2008). In the proposal of van Emden, one can find a primitive goal solving procedure based in and/or trees (these are similar to the alpha-beta trees used in game theory), used to prune the search space when proving some specific ground atom for some certainty value in the real interval [0, 1]. In the case of GAP, the goal solving procedure uses constrained SLD resolution in conjunction with a—costly—computation of so-called reductants between variants of program clauses. In contrast, QLP goal solving uses a more efficient resolution procedure called SLD(D) resolution, implemented by means of real domain constraints, used to compute the qualification value of the head atom based on the attenuation factor of the program clause and the previously computed qualification values of the body atoms. Admittedly, the gain in efficiency of SLD(D) w.r.t. GAP’s goal solving procedure is possible because QLP focuses on a more specialized class of annotated programs. While in all these three approaches there are some results of soundness and completeness, the results for the QLP scheme are the stronger ones (again, thanks to its also more focused scope w.r.t. GAP). From a different viewpoint, extensions of LP supporting uncertainty can be roughly classified into two major lines: approaches based in fuzzy logic (Zadeh 1965; H´ajek 1998) and approaches based in similarity relations. Historically, Fuzzy LP languages were motivated by expert knowledge representation applications. Early Fuzzy LP languages implementing the resolution principle introduced in (Lee 1972) include Prolog-Elf (Ishizuka and Kanai 1985), Fril Prolog (Baldwin et al. 1995) and F-Prolog (Li and Liu 1990). More recent approaches such as the Fuzzy LP languages in (Vojt´aˇs 2001; Guadarrama et al. 2004) and Multi-Adjoint LP (MALP for short) in the sense of (Medina et al. 2001a) use clause annotations and a fuzzy interpretation of the connectives and aggregation operators occurring in program clauses and goals. The Fuzzy Prolog system proposed in (Guadarrama et al. 2004) is implemented by means of real constrains on top of a CLP(R) system, using a syntactic expansion of the source code during the Prolog compilation. A complete procedural semantics for MALP using reductants has been presented in (Medina

278

A Transformation-based Implementation for SQCLP (Preliminary Version) 3 et al. 2001b). A method for translating a MALP like program into standard Prolog has been described in (Juli´an et al. 2009). The second line of research mentioned in the previous paragraph was motivated by applications in the field of flexible query answering. Classical LP is extended to Similarity-based LP (SLP for short), leading to languages which keep the classical syntax of LP clauses but use a similarity relation over a set of symbols S to allow “flexible” unification of syntactically different symbols with a certain approximation degree. Similarity relations over a given set S have been defined in (Zadeh 1971; Sessa 2002) and related literature as fuzzy relations represented by mappings S : S× S → [0, 1] which satisfy reflexivity, symmetry and transitivity axioms analogous to those required for classical equivalence relations. Resolution with flexible unification can be used as a sound and complete goal solving procedure for SLP languages as shown e.g. in (Sessa 2002). SLP languages include Likelog (Arcelli and Formato 1999; Arcelli Fontana 2002) and more recently SiLog (Loia et al. 2004), which has been implemented by means of an extended Prolog interpreter and proposed as a useful tool for web knowledge discovery. In the last years, the SLP approach has been extended in various ways. The SQLP (similarity-based qualified logic programming) scheme proposed in (Caballero et al. 2008) extended SLP by allowing program clause annotations in QLP style and generalizing similarity relations to mappings S : S × S → D taking values in a qualification domain not necessarily identical to the real interval [0, 1]. As implementation technique for SQLP, (Caballero et al. 2008) proposed a semantically correct program transformation into QLP, whose goal solving procedure has been described above. Other related works on transformation-based implementations of SLP languages include (Sessa 2001; Medina et al. 2004). More recently, the SLP approach has been generalized to work with proximity relations in the sense of (Dubois and Prade 1980) represented by mappings S : S × S → [0, 1] which satisfy reflexivity and symmetry axioms but do not always satisfy transitivity. SLP like languages using proximity relations include Bousi∼Prolog (Juli´ an-Iranzo and RubioManzano 2009a) and the SQCLP scheme (Rodr´ıguez-Artalejo and Romero-D´ıaz 2010a). Two prototype implementations of Bousi∼Prolog are available: a low-level implementation (Juli´an-Iranzo and Rubio-Manzano 2009b) based on an adaptation of the classical WAM (called Similarity WAM) implemented in Java and able to execute a Prolog program in the context of a similarity relation defined on the first order alphabet induced by that program; and a high-level implementation (Juli´ anIranzo et al. 2009) done on top of SWI-Prolog by means of a program transformation from Bousi∼Prolog programs into a so-called Translated BPL code than can be executed according to the weak SLD resolution principle by a meta-interpreter. Let us now refer to approaches related to constraint solving and CLP. An analogy of proximity relations in the context of partial constraint satisfaction can be found in (Freuder and Wallace 1992), where several metrics are proposed to measure the proximity between the solution sets of two different constraint satisfaction problems. Moreover, some extensions of LP supporting uncertain reasoning use constraint solving as implementation technique, as discussed in the previous paragraphs. However, we are only aware of three approaches which have been conceived

279

4

R. Caballero, M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz

as extensions of the classical CLP scheme proposed for the first time in (Jaffar and Lassez 1987). These three approaches are: (Riezler 1998) that extends the formulation of CLP by (H¨ohfeld and Smolka 1988) with quantitative LP in the sense of (van Emden 1986) and adapts van Emden’s idea of and/or trees to obtain a goal resolution procedure; (Bistarelli et al. 2001) that proposes a semiring-based approach to CLP, where constraints are solved in a soft way with levels of consistency represented by values of the semiring, and is implemented with clp(FD,S) for a particular class of semirings which enable to use local consistency algorithms, as described in (Georget and Codognet 1998); and the SQCLP scheme proposed in our previous work (Rodr´ıguez-Artalejo and Romero-D´ıaz 2010a), which was designed as a common extension of SQLP and CLP. As we have already said at the beginning of this introduction, this paper deals with transformation-based implementations of the SQCLP scheme. Our main results include: a) a transformation technique for transforming SQCLP programs into semantically equivalent CLP programs via two specific program transformations named elimS and elimD ; and b) and a practical Prolog-based implementation which relies on the aforementioned program transformations and supports several useful SQCLP instances. As far as we know, no previous work has dealt with the implementation of extended LP languages for uncertain reasoning which are able to support clause annotations, proximity relations and CLP style programming. In particular, our previous paper (Caballero et al. 2008) only presented a transformation analogous to elimS for a programming scheme less expressive than SQCLP, which supported neither non-transitive proximity relations nor CLP programming. Moreover, the transformation-based implementation reported in (Caballero et al. 2008) was not implemented in a system. The reader is assumed to be familiar with the semantic foundations of LP (Lloyd 1987; Apt 1990) and CLP (Jaffar and Lassez 1987; Jaffar et al. 1998). The rest of the paper is structured as follows: Section 2 presents a brief overview of the semantics of the SQCLP scheme, focusing on the essential notions needed to understand the following sections and concluding with an abstract discussion of goal solving procedures for SQCLP. Section 3 briefly discusses two specializations of SQCLP, namely QCLP and CLP, which are used as the targets of the program transformations elimS and elimD , respectively. Section 4 presents these two program transformations along with mathematical results which prove their semantic correctness, relying on the declarative semantics of the SQCLP, QCLP and CLP schemes. Section 5 presents a Prolog-based prototype system which relies on the transformations proposed in the previous section and implements several useful SQCLP instances. Finally, Section 6 summarizes conclusions and points to some lines of planned future research. 2 The Scheme SQCLP and its Declarative Semantics We present in this section a short overview of the declarative semantics of the SQCLP scheme originally presented in (Rodr´ıguez-Artalejo and Romero-D´ıaz 2010a), focusing on the essential notions needed to understand the following sections. In-

280

A Transformation-based Implementation for SQCLP (Preliminary Version) 5 terested readers are referred to (Rodr´ıguez-Artalejo and Romero-D´ıaz 2010a) and its extended version (Rodr´ıguez-Artalejo and Romero-D´ıaz 2010b) for a full-fledged exposition of SQCLP semantics and a discussion of various extended LP languages for uncertain reasoning which can be obtained as specializations and instances of SQCLP. Some technical notions and results from (Rodr´ıguez-Artalejo and RomeroD´ıaz 2010b) will be cited along this paper when needed to support mathematical proofs. Constraint domains C, sets of constraints Π and their solutions, as well as terms, atoms and substitutions over a given C are well known notions underlying the CLP scheme. The reader is referred (Rodr´ıguez-Artalejo and Romero-D´ıaz 2010b) for a relational formalization of constraint domains and some examples, including the real constraint domain R. We assume the following classification of atomic C-constraints: defined atomic constraints p(tn ), where p is a program-defined predicate symbol; primitive constraints r(tn ) where r is a C-specific primitive predicate symbol; and equations t == s. We use ConC as a notation for the set of all C-constraints and κ as a notation for an atomic primitive constraint. Constraints are interpreted by means of C-valuations η ∈ ValC , which are ground substitutions. The set SolC (Π) of solutions of Π ⊆ ConC includes all the valuations η such that Πη is true when interpreted in C. Π ⊆ ConC is called satisfiable if SolC (Π) 6= ∅ and unsatisfiable otherwise. π ∈ ConC is entailed by Π ⊆ ConC (noted Π |=C π) iff SolC (Π) ⊆ SolC (π). Qualification domains were first introduced in (Rodr´ıguez-Artalejo and RomeroD´ıaz 2008) with the aim of providing elements, called qualification values, which can be attached to computed answers. They are defined as structures D = hD, P, b, t, ◦i verifying the following requirements: 1. hD, P, b, ti is a lattice with extreme points b (called infimum or bottom element) and t (called maximum or top element) w.r.t. the partial ordering P (called qualification ordering). For given elements d, e ∈ D, we write d u e for the greatest lower bound (glb) of d and e, and d t e for the least upper bound (lub) of d and e. We also write d C e as abbreviation for d P e ∧ d 6= e. 2. ◦ : D × D → D, called attenuation operation, verifies the following axioms: (a) (b) (c) (d)

◦ is associative, commutative and monotonic w.r.t. P. ∀d ∈ D : d ◦ t = d and d ◦ b = b. ∀d, e ∈ D : d ◦ e P e and even b 6= d ◦ e P e if d, e ∈ D \ {b}. ∀d, e1 , e2 ∈ D : d ◦ (e1 u e2 ) = (d ◦ e1 ) u (d ◦ e2 ).

For any S = {e1 , e2 , . . . , en } ⊆ D, the glb (also called infimum of S) exists and can d be computed as S = e1 u e2 u · · · u en (which reduces to t in the case n = 0). The dual claim concerning lubs is also true. As an easy consequence of the axioms, one d d gets the identity d ◦ S = {d ◦ e | e ∈ S}. Technical details, explanations and examples can be found in (Rodr´ıguez-Artalejo and Romero-D´ıaz 2010b), including: the qualification domain B of classical boolean values, the qualification domain U of uncertainty values, the qualification domain W of weight values, and other qualification domains built from these by means of

281

6

R. Caballero, M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz

the strict cartesian product operation ⊗. The following definition is borrowed from (Rodr´ıguez-Artalejo and Romero-D´ıaz 2010a): Definition 2.1 (Expressing D in C) A qualification domain D is expressible in a constraint domain C if there is an injective embedding mapping ı : D \ {b} → C and moreover: 1. There is a C-constraint qVal(X) such that SolC (qVal(X)) is the set of all η ∈ ValC verifying η(X) ∈ ran(ı). 2. There is a C-constraint qBound(X, Y, Z) encoding “x P y ◦ z” in the following sense: any η ∈ ValC such that η(X) = ι(x), η(Y ) = ι(y) and η(Z) = ι(z) verifies η ∈ SolC (qBound(X, Y, Z)) iff x P y ◦ z.

In addition, if qVal(X) and qBound(X, Y, Z) can be chosen as existential constraints of the form ∃X1 . . . ∃Xn (B1 ∧ . . . ∧ Bm )—where Bj (1 ≤ j ≤ m) are atomic—we say that D is existentially expressible in C. It can be proved that B, U, W and and any qualification domain built from these with the help of ⊗ are existentially expressible in any constraint domain C that includes the basic values and computational features of R. Admissible triples hS, D, Ci consist of a constraint domain C, a qualification domain D and a proximity relation S : S × S → D—where D is the carrier set of D and S is the set of all variables, basic values and signature symbols available in C—satisfying the following properties: • ∀x ∈ S : S(x, x) = t (reflexivity). • ∀x, y ∈ S : S(x, y) = S(y, x) (symmetry). • Some additional technical conditions explained in (Rodr´ıguez-Artalejo and Romero-D´ıaz 2010b). A proximity relation S is called similarity iff it satisfies the additional property ∀x, y, z ∈ S : S(x, z) Q S(x, y) u S(y, z) (transitivity). The scheme SQCLP has instances SQCLP(S, D, C) where hS, D, Ci is an admissible triple. A SQCLP(S, D, C)-program is a set P of qualified program rules (also called α qualified clauses) C : A ← − B1 ]w1 , . . . , Bm ]wm , where A is a defined atom, α ∈ D \ {b} is called the attenuation factor of the clause and each Bj ]wj (1 ≤ j ≤ m) is an atom Bj annotated with a so-called threshold value wj ∈ (D \ {b}) ] {?}. The intended meaning of C is as follows: if for all 1 ≤ j ≤ m one has Bj ]ej (meaning that Bj holds with qualification value ej ) for some ej Q? wj , then A]d (meaning that A holds with qualification value d) can be inferred for any d ∈ D \ {b} such dm that d P α ◦ j=1 ej . By convention, ej Q? wj means ej Q wj if wj 6= ? and is identically true otherwise. In practice threshold values equal to ‘?’ and attenuation values equal to t can be omitted. Figure 1 shows a simple SQCLP(Ss , U, R)-program Ps which illustrates the expressivity of the SQCLP scheme to deal with problems involving flexible information retrieval. Predicate search can be used to answer queries asking for books in the library matching some desired language, genre and reader level. Predicate guessRdrLvl takes advantage of attenuation factors to encode heuristic rules to

282

A Transformation-based Implementation for SQCLP (Preliminary Version) 7 % Book representation: book( ID, Title, Author, Lang, Genre, VocLvl, Pages ). 1

library([ book(1, ‘Tintin’, ‘Herg´ e’, french, comic, easy, 65),

2

book(2, ‘Dune’, ‘F.P. Herbert’, english, sciFi, medium, 345),

3

book(3, ‘Kritik der reinen Vernunft’, ‘I. Kant’, german, philosophy, difficult, 1011),

4

book(4, ‘Beim Hauten der Zwiebel’, ‘G. Grass’, german, biography, medium, 432) ]) % Auxiliary predicate for computing list membership:

5

member(B, [B| ])

6

member(B, [ |T]) ← member(B, T) % Predicates for getting the explicit attributes of a given book:

7

getId(book(ID, Title, Author, Lang, Genre, VocLvl, Pages), ID)

8

getTitle(book( ID, Title, Author, Lang, Genre, VocLvl, Pages), Title)

9

getAuthor(book( ID, Title, Author, Lang, Genre, VocLvl, Pages), Author)

10

getLanguage(book( ID, Title, Author, Lang, Genre, VocLvl, Pages), Lang)

11

getGenre(book( ID, Title, Author, Lang, Genre, VocLvl, Pages), Genre)

12

getVocLvl(book( ID, Title, Author, Lang, Genre, VocLvl, Pages), VocLvl)

13

getPages(book( ID, Title, Author, Lang, Genre, VocLvl, Pages), Pages) % Function for guessing the reader level of a given book:

14 15 16 17 18 19 20

guessRdrLvl(B, basic) ← getVocLvl(B, easy), getPages(B, N), N < 50 0.8

guessRdrLvl(B, intermediate) ←−− getVocLvl(B, easy), getPages(B, N), N ≥ 50 0.9

guessRdrLvl(B, basic) ←−− getGenre(B, children) 0.9

guessRdrLvl(B, proficiency) ←−− getVocbLvl(B, difficult), getPages(B, N), N ≥ 200 0.8

guessRdrLvl(B, upper) ←−− getVocLvl(B, difficult), getPages(B, N), N < 200 0.8

guessRdrLvl(B, intermediate) ←−− getVocLvl(B, medium) 0.7

guessRdrLvl(B, upper) ←−− getVocLvl(B, medium)

% Function for answering a particular kind of user queries: 21

search(Lang, Genre, Level, Id) ← library(L)#1.0, member(B, L)#1.0,

22

getLanguage(B, Lang), getGenre(B, Genre),

23

guessRdrLvl(B, Level), getId(B, Id)#1.0 % Proximity relation Ss :

24 25 26 27

Ss (sciFi, fantasy) = Ss (fantasy, sciFi) = 0.9

Ss (adventure, fantasy) = Ss (fantasy, adventure) = 0.7

Ss (essay, philosophy) = Ss (philosophy, essay) = 0.8

Ss (essay, biography) = Ss (biography, essay) = 0.7

Fig. 1. SQCLP(Ss , U, R)-program Ps (Library with books in different languages) compute reader levels on the basis of vocabulary level and other book features. The other predicates compute book features in the natural way, and the proximity relation Ss allows flexibility in any unification (i.e. solving of equality constraints) arising during the invocation of the program predicates. The declarative semantics of a given SQCLP(S, D, C)-program P relies on qualified constrained atoms (briefly qc-atoms) of the form A]d ⇐ Π, intended to assert

283

8

R. Caballero, M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz

that the validity of atom A with qualification degree d ∈ D is entailed by the constraint set Π. A qc-atom is called defined, primitive or equational according to the syntactic form of A; and it is called observable iff d ∈ D \ {b} and Π is satisfiable. Program interpretations are defined as sets of observable qc-atoms which obey a natural closure condition. The results proved in (Rodr´ıguez-Artalejo and RomeroD´ıaz 2010a) show two equivalent ways to characterize declarative semantics, using a fix-point approach and a proof-theoretical approach, respectively. For the purposes of the present paper it suffices to consider the proof theoretical approach, that relies on a formal inference system called Proximity-based Qualified Constrained Horn Logic—in symbols, SQCHL(S, D, C)—intended to infer observable qc-atoms from P and consisting of the three inference rules displayed in Figure 2. Rule SQEA depends on a relation ≈d,Π between terms that is defined in the following way: t ≈d,Π s iff there exist two terms tˆ and sˆ such that Π |=C t == tˆ, Π |=C s == sˆ and b 6= d P S(tˆ, sˆ). This allows to deduce equations from Π in a flexible way, taking the proximity relation S into account. The reader is referred to (Rodr´ıguez-Artalejo and Romero-D´ıaz 2010b) for more motivating comments on SQCHL(S, D, C) and some technical properties of the ≈d,Π relation.

SQDA

( (t0i == ti θ)]di ⇐ Π )i=1...n ( Bj θ]ej ⇐ Π )j=1...m p0 (t0 n )]d ⇐ Π α

SQEA

− B1 ]w1 , . . . , Bm ]wm ) ∈ P, θ subst., S(p0 , p) = d0 6= b, if (p(tn ) ← d dm ej Q? wj (1 ≤ j ≤ m) and d P n i=0 di u α ◦ j=1 ej . (t == s)]d ⇐ Π

if t ≈d,Π s.

SQPA

κ]d ⇐ Π

if Π |=C κ.

Fig. 2. Proximity-based Qualified Constrained Horn Logic

We will write P `S,D,C ϕ to indicate that ϕ can be deduced from P in SQCHL(S, D, C), and P `kS,D,C ϕ in the case that the deduction can be performed with exactly k SQDA inference steps. As usual in formal inference systems, SQCHL(S, D, C) proofs can be represented as proof trees whose nodes correspond to qc-atoms, each node being inferred from its children by means of some SQCHL(S, D, C) inference step. The following theorem, proved in (Rodr´ıguez-Artalejo and Romero-D´ıaz 2010b), characterizes least program models in the scheme SQCLP. This result allows to use SQCHL(S, D, C)-derivability as a logical criterion for proving the semantic correctness of program transformations, as we will do in Section 4. Theorem 2.1 (Logical characterization of least program models in SQCHL) For any SQCLP(S, D, C)-program P, its least model can be characterized as: MP = {ϕ | ϕ is an observable defined qc-atom and P `S,D,C ϕ}. Let us now discuss goals and their solutions. Goals for a given SQCLP(S, D, C)-

284

A Transformation-based Implementation for SQCLP (Preliminary Version) 9 program P have the form G : A1 ]W1 , . . . , Am ]Wm 8 W1 Q? β1 , . . . , Wm Q? βm

abbreviated as (Ai ]Wi , Wi Q? βi )i=1...m . The Ai ]Wi are called annotated atoms. The pairwise different variables Wi ∈ War are called qualification variables; they are taken from a set War assumed to be disjoint from the set Var of data variables used in terms. The conditions Wi Q? βi (with βi ∈ (D \ {b}) ] {?}) are called threshold conditions and their intended meaning (relying on the notations ‘?’ and ‘Q? ’) is as already explained when introducing program clauses above. In the sequel, war(o) will denote the set of all qualification variables occurring in the syntactic object o. In particular, for a goal G as displayed above, war(G) denotes the set {Wi | 1 ≤ i ≤ m}. In the case m = 1 the goal is called atomic. The following definition relies on SQCHL(S, D, C)-derivability to provide a natural declarative notion of goal solution: Definition 2.2 (Goal Solutions) Assume a given SQCLP(S, D, C)-program P and a goal G for P with the syntax displayed above. Then: 1. A solution for G is any triple hσ, µ, Πi such that σ is a C-substitution, Wµ ∈ D \ {b} for all W ∈ dom(µ), Π is a satisfiable and finite set of atomic Cconstraints and the following two conditions hold for all i = 1 . . . m: Wi µ = di Q? βi and P `S,D,C Ai σ]Wi µ ⇐ Π. The set of all solutions for G w.r.t. P is noted SolP (G). 2. A solution hη, ρ, Πi for G is called ground iff Π = ∅ and η ∈ ValC is a variable valuation such that Ai η is a ground atom for all i = 1 . . . m. The set of all ground solutions for G w.r.t. P is noted GSolP (G) ⊆ SolP (G). 3. A ground solution hη, ρ, ∅i ∈ GSolP (G) is subsumed by hσ, µ, Πi iff there is some ν ∈ SolC (Π) s.t. η =var(G) σν and Wi ρ P Wi µ for i = 1 . . . m.

A possible goal Gs for the library program displayed in Figure 1 is

Gs : search(german, essay, intermediate, ID)#W 8 W ≥ 0.65

and one solution for Gs is h{ID 7→ 4}, {W 7→ 0.7}, ∅i. In this simple case, the constraint set Π within the solution is empty. Other examples of goal solutions can be found in (Rodr´ıguez-Artalejo and Romero-D´ıaz 2010b) and Sections 4 and 5 below. In practice, users of SQCLP languages will rely on some available goal solving system for computing goal solutions. The following definition specifies two important abstract properties of goal solving systems which will be taken as a reference for the implementation presented in this paper. Definition 2.3 (Correct Abstract Goal Solving Systems) An abstract goal solving system for SQCLP(S, D, C) is any device that takes a program P and a goal G as input and yields various triples hσ, µ, Πi, called computed answers, as outputs. Such a goal solving system is called: 1. Sound iff every computed answer is a solution hσ, µ, Πi ∈ SolP (G).

285

10

R. Caballero, M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz 2. Weakly complete iff every ground solution hη, ρ, ∅i ∈ GSolP (G) is subsumed by some computed answer. 3. Correct iff it is both sound and weakly complete.

Every goal solving system for a SQCLP instance should be sound and ideally also weakly complete. In principle, goal solving systems with these properties for extensions of the classical LP paradigm can be formalized as extensions of the well-known SLD-resolution method (Lloyd 1987; Apt 1990). A sound and complete extensions of SLD-resolution for the CLP scheme can be found e.g. in (Jaffar et al. 1998), and several extensions of SLD resolution for LP languages aiming at uncertain reasoning SQCLP scheme have been mentioned in Section 1. Our aim in this paper is to present an implementation based on a semantically correct program transformation from SQCLP into CLP, rather than developing a sound and complete extension of SLD resolution. Nevertheless, both our implementation and SLD-based approaches for SLP languages in the line of (Sessa 2002) must share the ability to solve unification problems w.r.t. to a proximity relation S : S × S → [0, 1] over signature symbols, which is assumed to be transitive in (Sessa 2002) but not in our setting. The lack of transitivity makes a crucial difference w.r.t. the behavior of unification algorithms. In the rest of this section we briefly discuss the problem by means of a simple example. (Sessa 2002) presents a flexible unification algorithm for solving unification problems represented as systems of the form S 8 α, where S is a set of equations between terms and α is a certainty degree. A solution of such a system is any substitution θ which verifies S(sθ, tθ) ≥ α for all equations s == t belonging to S. This notion of solution is consistent with the declarative semantics of the SQCLP scheme (more specifically, with Definition 2.2), even in the case that S is a non-transitive proximity relation. Following a traditional approach, Sessa presents the flexible unification algorithm as set of transformation rules which convert systems S 8 α into solved form systems which represent unifiers. The transformations are similar to those presented in e.g. Section 4.6 of (Baader and Nipkow 1998) for the case of classical syntactic unification, extended with suitable computations to update α during the process, taking the given similarity relation S into account. One of the transformations allows to transform a system of the form X == t, S 8 α into S{X 7→ t} 8 α (provided that X is not identical to t and does not occur in t, the so-called occurs check). Unfortunately, this transformation can lose solutions in case that S is not transitive. Consider for instance the following example: Example 2.1 Assume constants a, b, c and a non-transitive proximity relation S such that S(a, b) = S(b, a) = 0.7; S(a, c) = S(c, a) = 0.8; S(b, c) = S(c, b) = 0. Then, the substitution θ = {X 7→ a} is obviously a solution of the unification problem X == b, X == c 8 0.7. Nevertheless, the unification algorithm presented in (Sessa 2002) and related papers fails without computing any solution: X == b, X == c 8 0.7 =⇒ X == c {X 7→ b} 8 0.7 =⇒ fail

The second transformation step leads to fail because X == c {X 7→ b} 8 0.7 is

286

A Transformation-based Implementation for SQCLP (Preliminary Version) 11 the same as b == c 8 0.7 and S(b, c) = 0 < 0.7. Should S satisfy transitivity, then S(b, c) = S(c, b) ≥ 0.7, and Sessa’s unification algorithm would compute the unifier σ = {X 7→ b} as follows: X == b, X == c 8 0.7 =⇒ X == c {X 7→ b} 8 0.7 =⇒ {X 7→ b} 8 0.7

Note that σ is more general than θ in the sense that S(θ, σθ) = S(θ, σ) ≥ 0.7. Therefore this example does not contradict the completeness of Sessa’s unification algorithm for the case of (transitive) similarity relations. Even in the case that S is transitive, we have found examples showing that a goal solving system based on Sessa’s unification algorithm can fail to compute some valid solutions for SQCLP(S, D, C)-programs whose clauses use attenuation factors other than t. The unification algorithm underlaying the implementations presented in Section 5—based on the program transformations from Section 4—avoids the problematic transformation step X == t, S 8 α =⇒ S{X 7→ t} 8 α, that might cause incompleteness; instead, Prolog’s backtracking is used to implement the effect of a non-deterministic choice between several transformation steps X == c(tn ), S 8 α =⇒ X1 == t1 , . . . , Xn == tn , Sµ 8 α, where X1 , . . . , Xn are fresh variables and µ = {X 7→ c0 (X n )} for some possible choice of c0 such that S(c, c0 ) ≥ α. As an optimization, our prototype system allows the user to use a directive whose effect is that the system avoids the backtracking search just discussed and implements just the effect of the transformation X == t, S 8 α =⇒ S{X 7→ t} 8 α. When including this directive, the user runs the risk of losing some valid solutions. We conjecture that no incompleteness occurs in the case of SQCLP(S, D, C)-programs based on a transitive S and whose clauses do not use attenuation factors other than t; i.e. SLP programs enriched with constraint solving. 3 The Schemes QCLP & CLP as Specializations of SQCLP As discussed in the concluding section of (Rodr´ıguez-Artalejo and Romero-D´ıaz 2010a), several specializations of the SQCLP scheme can be obtained by partial instantiation of its parameters. In particular, QCLP and CLP can be defined as schemes with instances: QCLP(D, C) =def SQCLP(Sid , D, C) CLP(C) =def SQCLP(Sid , B, C) = QCLP(B, C)

where Sid is the identity proximity relation and B is the qualification domain including just the two classical boolean values. As explained in the introduction, QCLP and CLP are the targets of the two program transformations to be developed in Section 4. In this brief section we provide an explicit description of the syntax and semantics of these two schemes, derived from their behavior as specializations of SQCLP. 3.1 Presentation of the QCLP Scheme As already explained, the instances of QCLP can be defined by the equation QCLP(D,C) = SQCLP(Sid ,D,C). Due to the admissibility of the parameter triple

287

12

R. Caballero, M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz

hSid , D, Ci, the qualification domain D must be (existentially) expressible in the constraint domain C. Technically, the QCLP scheme can be seen as a common extension of the classical CLP scheme for Constraint Logic Programming (Jaffar and Lassez 1987; Jaffar et al. 1998) and the QLP scheme for Qualified Logic Programming originally introduced in (Rodr´ıguez-Artalejo and Romero-D´ıaz 2008). Intuitively, QCLP programming behaves like SQCLP programming, except that proximity information other than the identity is not available for proving equalities. Program clauses and observable qc-atoms in QCLP are defined in the same way as in SQCLP. The library program Ps in Figure 1 becomes a QCLP( U, R)-program Ps0 just by replacing Sid for S. Of course, Ps0 does not support flexible unification as it was the case with Ps . As explained in Section 2, the proof system consisting of the three displayed in Figure 2 characterizes the declarative semantics of a given SQCLP(S, D, C)-program P. In the particular case S = Sid , the inference rules specialize to those displayed in Figure 3, yielding a formal proof system called Qualified Constrained Horn Logic – in symbols, QCHL(D, C) – which characterizes the declarative semantics of a given QCLP(D, C)-program P. Note that rule SQEA depends on a relation ≈Π between terms that is defined to behave the same as the specialization of ≈d,Π to the case S = Sid . It is easily checked that t ≈Π s does not depend on d and holds iff Π |=C t == s. Both ≈d,Π and ≈Π allow to use the constraints within Π when deducing equations. However, c(tn ) ≈Π c0 (sn ) never holds in the case that c and c0 are not syntactically identical.

QDA

( (t0i == ti θ)]di ⇐ Π )i=1...n ( Bj θ]ej ⇐ Π )j=1...m p(t0 n )]d ⇐ Π α

QEA

if (p(tn ) ← − B1 ]w1 , . . . , Bm ]wm ) ∈ P, θ subst., d dm ej Q? wj (1 ≤ j ≤ m) and d P n i=1 di u α ◦ j=1 ej . (t == s)]d ⇐ Π

if t ≈Π s.

QPA

κ]d ⇐ Π

if Π |=C κ.

Fig. 3. Qualified Constrained Horn Logic

SQCHL(S, D, C) proof trees and the notations related to them can be naturally specialized to QCHL(D, C). In particular, we will use the notation P `D,C ϕ (resp. P `kD,C ϕ) to indicate that the qc-atom ϕ can be inferred in QCHL(D, C) from the program P (resp. it can be inferred by using exactly k QDA inference steps). Theorem 2.1 also specializes to QCHL, yielding the following result: Theorem 3.1 (Logical characterization of least program models in QCHL) For any QCLP(D, C)-program P, its least model can be characterized as: MP = {ϕ | ϕ is an observable defined qc-atom and P `D,C ϕ}.

288

A Transformation-based Implementation for SQCLP (Preliminary Version) 13 Concerning goals and their solutions, their specialization to the particular case S = Sid leaves the syntax of goals G unaffected and leads to the following definition, almost identical to Definition 2.2: Definition 3.1 (Goal Solutions in QCLP ) Assume a given QCLP(S, D)C-program P and a goal G : ( Ai ]Wi , Wi Q? βi )i=1...m . Then:

1. A solution for G is any triple hσ, µ, Πi such that σ is a C-substitution, W µ ∈ D \ {b} for all W ∈ dom(µ), Π is a satisfiable and finite set of atomic Cconstraints, and the following two conditions hold for all i = 1 . . . m: Wi µ = di Q? βi and P `D,C Ai σ]Wi µ ⇐ Π. The set of all solutions for G is noted SolP (G). 2. A solution hη, ρ, Πi for G is called ground iff Π = ∅ and η ∈ ValC is a variable valuation such that Ai η is a ground atom for all i = 1 . . . m. The set of all ground solutions for G is noted GSolP (G) ⊆ SolP (G). 3. A ground solution hη, ρ, ∅i ∈ GSolP (G) is subsumed by hσ, µ, Πi iff there is some ν ∈ SolC (Π) s.t. η =var(G) σν and Wi ρ P Wi µ for i = 1 . . . m.

Finally, the notion of correct abstract goal solving system for SQCLP given in Definition 2.3 specializes to QCLP without any formal change. Therefore, we state no new definition at this point.

3.2 Presentation of the CLP Scheme As already explained, the instances of CLP can be defined by the equation CLP(C) = SQCLP(Sid , B, C), or equivalently, CLP(C) = QCLP(B, C). Due to the fixed choice D = B, the only qualification value d ∈ D\{b} available for use as attenuation factor or threshold value is d = t. Therefore, CLP can only include threshold values equal to ‘?’ and attenuation values equal to the top element t = true of B. As explained in Section 2, such trivial threshold and attenuation values can be omitted, and CLP clauses can be written with the simplified syntax A ← B1 , . . . , Bm . Since t = true is the only non-trivial qualification value available in CLP, qcatoms A]d ⇐ Π are always of the form A]true ⇐ Π and can be written as A ⇐ Π. Moreover, all the side conditions for the inference rule QDA in Figure 3 become trivial when specialized to the case D = B. Therefore, the specialization of QCHL(D, C) to the case D = B leads to the formal proof system called Constrained Horn Logic – in symbols, CHL(C) – consisting of the three inference rules displayed in Figure 4, which characterizes the declarative semantics of a given CLP(C)-program P. QCHL(D, C) proof trees and the notations related to them can be naturally specialized to CHL(C). In particular, we will use the notation P `ϕ (resp. P `k ϕ) to indicate that the qc-atom ϕ can be inferred in CHL(C) from the program P (resp. it can be inferred by using exactly k DA inference steps). Theorem 3.1 also specializes to CHL, yielding the following result:

289

14

R. Caballero, M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz

DA

( (t0i == ti θ) ⇐ Π )i=1...n ( Bj θ ⇐ Π )j=1...m p(t0 n ) ⇐ Π if (p(tn ) ← B1 , . . . , Bm ) ∈ P and θ subst.

EA

(t == s) ⇐ Π

if t ≈Π s.

PA

κ⇐Π

if Π |=C κ.

Fig. 4. Constrained Horn Logic

Theorem 3.2 (Logical characterization of least program models in CHL) For any CLP(C)-program P, its least model can be characterized as: MP = {ϕ | ϕ is an observable defined qc-atom and P `ϕ }. Concerning goals and their solutions, their specialization to the scheme CLP leads to the following definition: Definition 3.2 (Goals and their Solutions in CLP) Assume a given CLP(C)-program P. Then: 1. Goals for P have the form G : A1 , . . . , Am , abbreviated as ( Ai )i=1...m , where Ai (1 ≤ i ≤ m) are atoms. 2. A solution for a goal G is any pair hσ, Πi such that σ is a C-substitution, Π is a satisfiable and finite set of atomic C-constraints, and P `C Ai σ ⇐ Π holds for all i = 1 . . . m. The set of all solutions for G is noted SolP (G). 3. A solution hη, Πi for G is called ground iff Π = ∅ and η ∈ ValC is a variable valuation such that Ai η is a ground atom for all i = 1 . . . m. The set of all ground solutions for G is noted GSolP (G). Obviously, GSolP (G) ⊆ SolP (G). 4. A ground solution hη, ∅i ∈ GSolP (G) is subsumed by hσ, Πi iff there is some ν ∈ SolC (Π) s.t. η =var(G) σν. The notion of correct abstract goal solving system for SQCFLP given in Definition 2.3 specializes to CLP with only minor formal changes, as follows: Definition 3.3 (Correct Abstract Goal Solving Systems for CLP) A goal solving system for CLP(C) is any effective procedure which takes a program P and a goal G as input and yields various pairs hσ, Πi, called computed answers, as outputs. Such a goal solving system is called: 1. Sound iff every computed answer is a solution hσ, Πi ∈ SolP (G). 2. Weakly complete iff every ground solution hη, ∅i ∈ GSolP (G) is subsumed by some computed answer. 3. Correct iff it is both sound and weakly complete. We close this Subsection with a technical lemma that will be useful for proving some results in Subsection 4.2:

290

A Transformation-based Implementation for SQCLP (Preliminary Version) 15 Lemma 3.1 Assume an existential C-constraint π(X n ) = ∃Y1 . . . ∃Yk (B1 ∧ . . . ∧ Bm ) with free variables X n and a given CLP(C)-program P including the clause C : p(X n ) ← B1 , . . . , Bm , where p ∈ DP n does not occur at the head of any other clause of P. Then, for any n-tuple tn of C-terms and any finite and satisfiable Π ⊆ ConC , one has: 1. P `C (p(tn ) ⇐ Π) =⇒ Π |=C π(tn ), where π(tn ) stands for the result of applying the substitution {X n 7→ tn } to π(X n ). 2. The opposite implication Π |=C π(tn ) =⇒ P `C (p(tn ) ⇐ Π) holds if tn is a ground term tuple. Note that for ground tn the constraint entailment Π |=C π(tn ) simply means that π(tn ) is true in C. 3. Π |=C π(tn ) =⇒ P `C (p(tn ) ⇐ Π) may fail if tn is not a ground term tuple. Proof We prove each item separately: 1. Assume P `C (p(tn ) ⇐ Π). Note that C is the only clause for p in P and that each atom Bj in C’s body is an atomic constraint. Therefore, the CHL(C) proof must use a DA step based on an instance Cθ of clause C such that Π |=C ti == Xi θ holds for all 1 ≤ i ≤ n and Π |= Bj θ holds for all 1 ≤ j ≤ m. These conditions and the syntactic form of π(X n ) obviously imply Π |=C π(tn ). 2. Assume now Π |=C π(tn ) and tn ground. Then π(tn ) is true in C, and due to the syntactic form of π(X n ), there must be some substitution θ such that Xi θ = ti (syntactic identity) for all 1 ≤ i ≤ n and Bj θ is ground and true in C for all 1 ≤ j ≤ m. Trivially, Π |=C ti == Xi θ holds for all 1 ≤ i ≤ n and Π |=C Bj θ also holds for all 1 ≤ j ≤ m. Then, it is obvious that P `C (p(tn ) ⇐ Π) can be proved by using a DA step based on the instance Cθ of clause C. 3. We prove that Π |=C π(tn ) =⇒ P `C (p(tn ) ⇐ Π) can fail if tn is not ground by presenting a counterexample based on the constraint domain R, using the syntax for R-constraints explained in (Rodr´ıguez-Artalejo and Romero-D´ıaz 2010b). Consider the existential R-constraint π(X) = ∃Y (op+ (Y, Y, X)), and a CLP(R)program P including the clause C : p(X) ← op+ (Y, Y, X) and no other occurrence of the defined predicate symbol p. Consider also Π = {cp≥ (X, 0.0)} and t = X. Then Π |=R π(X) is obviously true, because any real number x ≥ 0.0 satisfies ∃Y (op+ (Y, Y, x)) in R. However, there is no R-term s such that Π |=R op+ (s, s, X), and therefore there is no instance Cθ of clause C that can be used to prove P `C (p(X) ⇐ Π) by applying a DA step. 4 Implementation by Program Transformation The purpose of this section is to introduce a program transformation that transforms SQCLP(S, D, C) programs and goals into semantically equivalent CLP(C) programs and goals. This transformation is performed as the composition of the two following specific transformations:

291

16

R. Caballero, M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz 1. elimS — Eliminates the proximity relation S of arbitrary SQCLP(S, D, C) programs and goals, producing equivalent QCLP(D, C) programs and goals. 2. elimD — Eliminates the qualification domain D of arbitrary QCLP(D, C) programs and goals, producing equivalent CLP(C) programs and goals.

Thus, given a SQCLP(S, D, C)-program P—resp. SQCLP(S, D, C)-goal G—, the composition of the two transformations will produce an equivalent CLP(C)-program elimD (elimS (P))—resp. CLP(C)-goal elimD (elimS (G))—. Example 4.1 (Running example: SQCLP(Sr , U⊗W, R)-program Pr ) As a running example for this section, consider the SQCLP(Sr , U⊗W, R)-program Pr as follows: (0.9,1)

R1

famous(sha) ←−−−−

R2

wrote(sha, kle) ←−−−

R3

wrote(sha, hamlet) ←−−−

(1,1)

(1,1)

(0.75,3)

R4

S1 S2

good work(G) ←−−−−− famous(A)#(0.5,100), authored(A, G) Sr (wrote, authored) = Sr (authored, wrote) = (0.9,0)

Sr (kle, kli) = Sr (kli, kle) = (0.8,2)

where the constants shakespeare, king lear and king liar have been respectively replaced, for clarity purposes in the subsequent examples, by sha, kle and kli. In addition, consider the SQCLP(Sr , U⊗W, R)-goal Gr as follows: good work(X)#W 8 W Q? (0.5,10)

We will illustrate the two transformation by showing, in subsequent examples, the program clauses of elimS (Pr ) and elimD (elimS (Pr )) and the goals elimS (Gr ) and elimD (elimS (Gr )). The next two subsections explain each transformation in detail.

4.1 Transforming SQCLP into QCLP In this subsection we assume that the triple hS, D, Ci is admissible. In the sequel we say that a defined predicate symbol p ∈ DP n is affected by a SQCLP(S, D, C)program P iff S(p, p0 ) 6= b for some p0 occurring in P. We also say that an atom A is relevant for P iff some of the three following cases hold: a) A is an equation t == s; b) A is a primitive atom κ; or c) A is a defined atom p(tn ) such that p is affected by P. As a first step towards the definition of the first program transformation elimS , we define a set EQS of QCLP(D, C) program clauses that emulates the behavior of equations in SQCLP(S, D, C). The following definition assumes that the binary predicate symbol ∼ ∈ DP 2 (used in infix notation) and the nullary predicate symbols payλ ∈ DP 0 are not affected by P.

292

A Transformation-based Implementation for SQCLP (Preliminary Version) 17 Definition 4.1 We define EQS as the following QCLP(D, C)-program: t

EQS =def { X ∼ Y ← − (X == Y )]? } S t { u ∼ u0 ← − payλ ]? | u, u0 ∈ BC and S(u, u0 ) = λ 6= b } S t { c(X n ) ∼ c0 (Y n ) ← − payλ ]?, ( (Xi ∼ Yi )]? )i=1...n | c, c0 ∈ DC n 0 and S(c, c ) = λ 6= b } S λ { payλ ← − | for each λ ∈ D \ {b} }.

The following lemma shows the relation between the semantics of equations in SQCHL(S, D, C) and the behavior of the binary predicate symbol ‘∼’ defined by EQS in QCHL(D, C). Lemma 4.1 Consider any two arbitrary terms t and s; EQS defined as in Definition 4.1; and a satisfiable finite set Π of C-constraints. Then, for every d ∈ D \ {b}: t ≈d,Π s ⇐⇒ EQS `D,C (t ∼ s)]d ⇐ Π . Proof We separately prove each implication. [=⇒] Assume t ≈d,Π s. Then, there are two terms tˆ, sˆ such that: (1) t ≈Π tˆ

(2) s ≈Π sˆ

(3) tˆ ≈d sˆ

We use structural induction on the form of the term tˆ. • tˆ = Z, Z ∈ Var. From (3) we have sˆ = Z. Then (1) and (2) become t ≈Π Z and s ≈Π Z, therefore t ≈Π s. Now EQS `D,C (t ∼ s)]d ⇐ Π can be proved with a proof tree rooted by a QDA step of the form: (t == Xθ)]t ⇐ Π

(s == Y θ)]t ⇐ Π (t ∼ s)]d ⇐ Π

(X == Y )θ]t ⇐ Π

t

using the clause X ∼ Y ← − (X == Y )]? ∈ EQS instantiated by the substitution θ = {X 7→ t, Y 7→ s}. Therefore the three premises can be derived from EQS with QEA steps since t ≈Π t, s ≈Π s and t ≈Π s, respectively. Checking the side conditions of all inference steps is straightforward. • tˆ = u, u ∈ BC . From (3) we have sˆ = u0 for some u0 ∈ BC such that d P λ = S(u, u0 ). Then (1) and (2) become t ≈Π u and s ≈Π u0 , which allow to build a proof of EQS `D,C (t ∼ s)]d ⇐ Π by means of a QDA step using the clause t

u ∼ u0 ← − payλ ]?. • tˆ = c, c ∈ DC 0. From (3) we have sˆ = c0 for some c0 ∈ DC 0 such that d P λ = S(c, c0 ). Then (1) and (2) become t ≈Π c and s ≈Π c0, which allow us to build a proof of EQS `D,C (t ∼ s)]d ⇐ Π by means of a QDA step using the clause t

c ∼ c0 ← − payλ ]?. • tˆ = c(tn ), c ∈ DC n with n > 0. In this case, and because of (3), we can assume sˆ = c0 (sn ) for some c0 ∈ DC n satisfying d P d0 =def S(c, c0 ) and d P di =def S(ti , si )

293

18

R. Caballero, M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz

for i = 1 . . . n. Then EQS `D,C (t ∼ s)]d ⇐ Π with a proof tree rooted by a QDA step of the form: (t == c(tn ))]t ⇐ Π payd0 ]d0 ⇐ Π (s == c0 (sn ))]t ⇐ Π ( (ti ∼ si )]di ⇐ Π )i=1...n (t ∼ s)]d ⇐ Π t

using the EQS clause C : c(X n ) ∼ c0 (Y n ) ← − payd0 ]?, ((Xi ∼ Yi )]?)i=1...n instantiated by the substitution θ = {X1 7→ t1 , Y1 7→ s1 , . . . , Xn 7→ tn , Yn 7→ sn }. Note that C has attenuation factor t and threshold values ? at the body. Therefore, the side conditions of the QDA step boil down to d P di (1 ≤ i ≤ n) which are true by assumption. It remains to prove that each premise of the QDA step can be derived from EQS in QCHL(D, C): — EQS `D,C (t == c(tn ))]t ⇐ Π and EQS `D,C (s == c0 (sn ))]t ⇐ Π are trivial consequences of t ≈Π c(tn ) and s ≈Π c0 (sn ), respectively. In both cases, the QCHL(D,C) proofs consist of one single QEA step. d

0 — EQS `D,C payd0 ]d0 ⇐ Π can be proved using the clause payd0 ←− ∈ EQS in one single QDA step. — EQS `D,C (ti ∼ si )]di ⇐ Π for i = 1 . . . n. For each i, we observe that ti ≈di ,Π si holds because of tˆi = ti , sˆi = si which satisfy ti ≈Π tˆi , si ≈Π sˆi and tˆi ≈di sˆi . Since tˆi = ti is a subterm of tˆ = c(tn ), the inductive hypothesis can be applied.

[⇐=] Let T be a QCHL(D, C)-proof tree witnessing EQS `D,C (t ∼ s)]d ⇐ Π. We prove t ≈d,Π s reasoning by induction on the number n = kT k of nodes in T that represent conclusions of QDA inference steps. Note that all the program clauses belonging to EQS define either the binary predicate symbol ‘∼’ or the nullary predicates payλ . Basis (n = 1). In this case we have for the QDA inference step that there can be used three possible EQS clauses: t

1. The program clause is X ∼ Y ← − (X == Y )]?. Then the QDA inference step must be of the form: (t == t0 )]d1 ⇐ Π

(s == s0 )]d2 ⇐ Π (t ∼ s)]d ⇐ Π

(t0 == s0 )]e1 ⇐ Π

with d P d1 u d2 u e1 . The proof of the three premises must use the QEA inference rule. Because of the conditions of this inference rule we have t ≈Π t0 , s ≈Π s0 and t0 ≈Π s0 . Therefore t ≈Π s is clear. Then t ≈d,Π s holds by taking tˆ = sˆ = t because, trivially, t ≈Π tˆ, s ≈Π sˆ and tˆ ≈d sˆ. t 2. The program clause is u ∼ u0 ← − payλ ]? with u, u0 ∈ BC such that S(u, u0 ) = λ 6= b. The QDA inference step must be of the form: (t == u)]d1 ⇐ Π

(s == u0 )]d2 ⇐ Π (t ∼ s)]d ⇐ Π

294

payλ ]e1 ⇐ Π

A Transformation-based Implementation for SQCLP (Preliminary Version) 19 with d P d1 u d2 u e1 . Due to the forms of the QEA inference rule and λ the EQS clause payλ ← −, we can assume without loss of generality that d1 = d2 = t and e1 = λ. Therefore d P λ. Moreover, the QCHL(D,C) proofs of the first two premises must use QEA inferences. Consequently we have t ≈Π u and s ≈Π u0 . These facts and u ≈d u0 imply t ≈d,Π s. t

3. The program clause is c ∼ c0 ← − payλ ]? with c, c0 ∈ DC 0 such that S(c, c0 ) = λ 6= b. The QDA inference step must be of the form: (t == c)]d1 ⇐ Π

(s == c0 )]d2 ⇐ Π (t ∼ s)]d ⇐ Π

payλ ]e1 ⇐ Π

with d P d1 u d2 u e1 . Due to the forms of the QEA inference rule and λ the EQS clause payλ ← −, we can assume without loss of generality that d1 = d2 = t and e1 = λ. Therefore d P λ. Moreover, the QCHL(D,C) proofs of the first two premises must use QEA inferences. Consequently we have t ≈Π c and s ≈Π c0 . These facts and c ≈d c0 imply t ≈d,Π s. Inductive step (n > 1). In this case t and s must be of the form t = c(tn ) and s = c0 (sn ). The EQS clause used in the QDA inference step at the root must be of the form: t

c(X n ) ∼ c0 (Y n ) ← − payd0 ]?, ((Xi ∼ Yi )]?)i=1...n with S(c, c0 ) = d0 6= b. The inference step at the root will be: (t == c(tn ))]d1 ⇐ Π payd0 ]e0 ⇐ Π ( (ti ∼ si )]ei ⇐ Π )i=1...n (s == c0 (sn ))]d2 ⇐ Π (t ∼ s)]d ⇐ Π dn d0 with d P d1 u d2 u i=0 ei . Due to the forms of the EQS clause payd0 ←− and the QEA inference rule there is no loss of generality in assuming d1 = d2 = t dn and e0 = d0 , therefore we have d P d0 u i=1 ei . By the inductive hypothesis ti ≈ei ,Π si (1 ≤ i ≤ n), i.e. there are constructor terms tˆi , sˆi such that ti ≈Π tˆi , si ≈Π sˆi and tˆi ≈ei sˆi for i = 1 . . . n. Thus, we can build tˆ = c(tˆ1 , . . . , tˆn ) and sˆ = c0 (ˆ s1 , . . . , sˆn ) having t ≈d,Π s because: • • •

t ≈Π tˆ, i.e. c(tn ) ≈Π c(tˆn ), by decomposition since ti ≈Π tˆi . s ), again by decomposition since si ≈Π sˆi . s ≈Π sˆ, i.e. c0 (sn ) ≈Π c0 (ˆ dn dn n tˆ ≈d sˆ, since d P d0 u i=1 ei P S(c, c0 ) u i=1 S(tˆi , sˆi ) = S(tˆ, sˆ) .

We are now ready to define elimS acting over programs and goals.

Definition 4.2 Assume a SQCLP(S, D, C)-program P and a SQCLP(S, D, C)-goal G for P whose atoms are all relevant for P. Then we define: 1. For each atom A, let A∼ be t ∼ s if A : t == s; otherwise let A∼ be A. α 2. For each clause C : (p(tn ) ← − B) ∈ P let CˆS be the set of QCLP(D, C) clauses consisting of:

295

20

R. Caballero, M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz α — The clause Cˆ : (b pC (tn ) ← − B ∼ ), where pbC ∈ DP n is not affected by P (chosen in a different way for each C) and B ∼ is obtained from B by replacing each atom A occurring in B by A∼ . t — A clause p0 (X n ) ← − payλ ]?, ((Xi ∼ ti )]?)i=1...n , pbC (tn )]? for each p0 ∈ n DP such that S(p, p0 ) = λ 6= b. Here, X n must be chosen as n pairwise different variables not occurring in the clause C. S 3. elimS (P) is the QCLP(D, C)-program EQS ∪ PˆS where PˆS =def C∈P CˆS . 4. elimS (G) is the QCLP(D, C)-goal G∼ obtained from G by replacing each atom A occurring in G by A∼ .

The following example illustrates the transformation elimS . Example 4.2 (Running example: QCLP(U ⊗W, R)-program elimS (Pr )) Consider the SQCLP(Sr , U⊗W, R)-program Pr and the goal Gr for Pr as presented in Example 4.1. The transformed QCLP(U⊗W, R)-program elimS (Pr ) is as follows: ˆ R 1 R1.1 ˆ R 2 R2.1 R2.2 ˆ R 3 R3.1 R3.2 ˆ R 4 R4.1

(0.9,1) ˆ famousR1 (sha) ←−−−−

famous(X) ← payt , X∼sha, ˆ famousR1 (sha) (1,1)

w ˆ roteR2 (sha, kle) ←−−− wrote(X, Y) ← payt , X∼sha, Y∼kle, w ˆ roteR2 (sha, kle) authored(X, Y) ← pay(0.9,0) , X∼sha, Y∼kle, w ˆ roteR2 (sha, kle) (1,1)

w ˆ roteR3 (sha, hamlet) ←−−− wrote(X, Y) ← payt , X∼sha, Y∼hamlet, w ˆ roteR3 (sha, hamlet) authored(X, Y) ← pay(0.9,0) , X∼sha, Y∼hamlet, w ˆ roteR3 (sha, hamlet) (0.75,3)

ˆ good workR4 (G) ←−−−−− famous(A)#(0.5,100), authored(A, G) good work(X) ← payt , X∼G, ˆ good workR4 (G) % Program clauses for ∼:

% Program clauses for pay:

X ∼Y ← X==Y

payt ←

kle ∼ kli ← pay(0.8,2)

pay(0.9,0) ←−−−−

[. . .]

pay(0.8,2) ←−−−−

(0.9,0) (0.8,2)

Finally, the goal elimS (Gr ) for elimS (Pr ) is as follows: good work(X)#W 8 W Q? (0.5,10)

The next theorem proves the semantic correctness of the program transformation. Theorem 4.1 Consider a SQCLP(S, D, C)-program P, an atom A relevant for P, a qualification value d ∈ D \ {b} and a satisfiable finite set of C-constraints Π. Then, the following two statements are equivalent: 1. P `S,D,C A]d ⇐ Π 2. elimS (P) `D,C A∼ ]d ⇐ Π where A∼ is understood as in Definition 4.2(1).

296

A Transformation-based Implementation for SQCLP (Preliminary Version) 21 Proof We separately prove each implication. [1. ⇒ 2.] (the transformation is complete). Assume that T is a SQCHL(S, D, C) proof tree witnessing P `S,D,C A]d ⇐ Π. We want to show the existence of a QCHL(D, C) proof tree T 0 witnessing elimS (P) `D,C A∼ ]d ⇐ Π. We reason by complete induction on kT k. There are three possible cases according to the syntactic form of the atom A. In each case we argue how to build the desired proof tree T 0 . — A is a primitive atom κ. In this case A∼ is also κ and T contains only one SQPA inference node. Because of the inference rules SQPA and QPA, both P `S,D,C κ]d ⇐ Π and elimS (P) `D,C κ]d ⇐ Π are equivalent to Π |=C κ, therefore T 0 trivially contains just one QPA inference node. — A is an equation t == s. In this case A∼ is t ∼ s and T contains just one SQEA inference node. We know P `S,D,C (t == s)]d ⇐ Π is equivalent to t ≈d,Π s because of the inference rule SQEA. From this equivalence follows EQS `D,C (t ∼ s)]d ⇐ Π due to Lemma 4.1 and hence elimS (P) `D,C (t ∼ s)]d ⇐ Π by construction of elimS (P). In this case, T 0 will be a proof tree rooted by a QDA inference step. — A is a defined atom p0 (t0 n ) with p0 ∈ DP n. In this case A∼ is p0 (t0 n ) and the root inference of T must be a SQDA inference step of the form: ( (t0i == ti θ)]di ⇐ Π )i=1...n ( Bj θ]ej ⇐ Π )j=1...m (♣) p0 (t0 n )]d ⇐ Π α

with C : (p(tn ) ← − B1 ]w1 , . . . , Bm ]wm ) ∈ P, θ substitution, S(p0 , p) = d0 6= b, ? ej Q wj (1 ≤ j ≤ m), d P di (0 ≤ i ≤ n) and d P α ◦ ej (1 ≤ j ≤ m)—which means d P α in the case m = 0. We can assume that the first n premises at (♣) are proved in SQCLP(S, D, C) w.r.t. P by proof trees T1i (1 ≤ i ≤ n) satisfying kT1i k < kT k (1 ≤ i ≤ n), and the last m premises at (♣) are proved in SQCLP(S, D, C) w.r.t. P by proof trees T2j (1 ≤ j ≤ m) satisfying kT2j k < kT k (1 ≤ j ≤ m). By Definition 4.2, we know that the transformed program elimS (P) contains two clauses of the following form: α 1 m Cˆ : pˆC (tn ) ← − B∼ ]w1 , . . . , B∼ ]wm t 0 ˆ Cp0 : p (X n ) ← − payd0 ]?, ( (Xi ∼ ti )]? )i=1...n , pˆC (tn )]? j where Xi (1 ≤ i ≤ n) are fresh variables not occurring in C and B∼ (1 ≤ j ≤ m) is the result of replacing ‘∼’ for ‘==’ if Bj is equation; and Bj itself otherwise. Given that the n variables Xi do not occur in C, we can assume that σ =def θ0 ] θ with θ0 =def {X1 7→ t01 , . . . , Xn 7→ t0n } is a well-defined substitution. We claim that elimS (P) `D,C A∼ ]d ⇐ Π can be proved with a proof tree T 0 rooted by the QDA inference step (♠.1), which uses the clause Cˆp0 instantiated by σ and having dn+1 = d.

( (t0i == Xi σ)]t ⇐ Π )i=1...n payd0 σ]d0 ⇐ Π ( (Xi ∼ ti )σ]di ⇐ Π )i=1...n pˆC (tn )σ]dn+1 ⇐ Π p0 (t0 n )]d ⇐ Π

(♠.1)

297

( (t0i == Xi θ0 )]t ⇐ Π )i=1...n payd0 ]d0 ⇐ Π ( (Xi θ0 ∼ ti θ)]di ⇐ Π )i=1...n pˆC (tn θ)]dn+1 ⇐ Π p0 (t0 n )]d ⇐ Π

(♠.2)

22

R. Caballero, M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz

By construction of σ, (♠.1) can be rewritten as (♠.2), and in order to build the rest of T 0, we show that each premise of (♠.2) admits a proof in QCHL(D, C) w.r.t. the transformed program elimS (P): • elimS (P) `D,C (t0i == Xi θ0 )]t ⇐ Π for i = 1 . . . n. Straightforward using a single QEA inference step since Xi θ0 = t0i and t0i ≈Π t0i is trivially true. d

0 ∈ elimS (P) • elimS (P) `D,C payd0 ]d0 ⇐ Π. Immediate using the clause (payd0 ←−) with a single QDA inference step. • elimS (P) `D,C (Xi θ0 ∼ ti θ)]di ⇐ Π for i = 1 . . . n. From the first n premises of (♣) we know P `S,D,C (t0i == ti θ)]di ⇐ Π with a proof tree T1i satisfying kT1i k < kT k for i = 1 . . . n. Therefore, for i = 1 . . . n, elimS (P) `D,C (t0i ∼ ti θ)]di ⇐ Π with some 0 QCHL(D,C) proof tree T1i by inductive hypothesis. Since (Xi θ0 ∼ ti θ) = (t0i ∼ ti θ) for i = 1 . . . n, we are done. • elimS (P) `D,C pˆC (tn θ)]d ⇐ Π. This is proved by a QCHL(D, C) proof tree with a QDA inference step node at its root of the following form:

j θ]ej ⇐ Π )j=1...m ( (ti θ == ti θ)]di ⇐ Π )i=1...n ( B∼ (♥) pˆC (tn θ)]d ⇐ Π

which uses the program clause Cˆ instantiated by the substitution θ. Once more, we have to check that the premises can be derived in QCHL(D, C) from the transformed program elimS (P) and that the side conditions of (♥) are satisfied: — The first n premises can be trivially proved using QEA inference steps. — The last m premises can be proved w.r.t. elimS (P) with some QCHL(D, C) 0 proof trees T2j (1 ≤ j ≤ m) by the inductive hypothesis, since we have premises ( Bj θ]ej ⇐ Π )j=1...m at (♣) that can be proved in SQCLP(S, D, C) w.r.t. P with proof trees T2j of size kT2j k < kT k (1 ≤ j ≤ m). — The side conditions—namely: ej Q? wj (1 ≤ j ≤ m), d P di (1 ≤ i ≤ n) and d P α ◦ ej (1 ≤ j ≤ m)—trivially hold because they are also satisfied by (♣).

Finally, we complete the construction of T 0 by checking that (♠.2) satisfies the side conditions of the inference rule QDA:

• All threshold values at the body of Cˆp0 are ‘?’, therefore the first group of side conditions becomes di Q? ? (0 ≤ i ≤ n + 1), which are trivially true. • The second side condition reduces to d P t, which is also trivially true. • The third, and last, side condition is d P t ◦ di (0 ≤ i ≤ n + 1), or equivalently d P di (0 ≤ i ≤ n + 1). In fact, d P di (0 ≤ i ≤ n) holds due to the side conditions in (♣), and d P dn+1 holds because dn+1 = d by construction of (♠.1) and (♠.2). [2. ⇒ 1.] (the transformation is sound). Assume that T 0 is a QCHL(D, C) proof tree witnessing elimS (P) `D,C A∼ ]d ⇐ Π. We want to show the existence of a SQCHL(S, D, C) proof tree T witnessing P `S,D,C A]d ⇐ Π. We reason by complete induction of kT 0 k. There are three possible cases according to the syntactic form of the atom A∼ . In each case we argue how to build the desired proof tree T . — A∼ is a primitive atom κ. In this case A is also κ and T 0 contains only one QPA inference node. Both elimS (P) `D,C κ]d ⇐ Π and P `S,D,C κ]d ⇐ Π are equivalent

298

A Transformation-based Implementation for SQCLP (Preliminary Version) 23 to Π |=C κ because of the inference rules QPA and SQPA, therefore T trivially contains just one SQPA inference node. — A∼ is of the form t ∼ s. In this case A is t == s and T 0 is rooted by a QDA inference step. From elimS (P) `D,C (t ∼ s)]d ⇐ Π and by construction of elimS (P) we have EQS `D,C (t ∼ s)]d ⇐ Π. By Lemma 4.1 we get t ≈d,Π s and, by the definition of the SQEA inference step, we can build T as a proof tree with only one SQEA inference node proving P `S,D,C (t == s)]d ⇐ Π. — A∼ is a defined atom p0 (tn ) with p0 ∈ DP n and p0 6= ∼. In this case A = A∼ and the step at the root of T 0 must be a QDA inference step using a clause C 0 ∈ elimS (P) with head predicate p0 and a substitution θ. Because of Definition 4.2 and α − B) ∈ P the fact that p0 is relevant for P, there must be some clause C : (p(tn ) ← 0 0 such that S(p, p ) = d0 6= b, and C must be of the form: t

− payd0 ]?, ((Xi ∼ ti )]?)i=1...n , pˆC (tn )]? C 0 : p0 (X n ) ← where the variables X n do not occur in C. Thus the QDA inference step at the root of T 0 must be of the form: ( (t0i == Xi θ)]d1i ⇐ Π )i=1...n payd0 θ]e10 ⇐ Π ( (Xi ∼ ti )θ]e1i ⇐ Π )i=1...n pˆC (tn )θ]e1(n+1) ⇐ Π p0 (t0 n )]d ⇐ Π

(♠)

and the proof of the last premise must use the only clause for pˆC introduced in elimS (P) according to Definition 4.2, i.e.: α 1 m Cˆ : pˆC (tn ) ← − B∼ ]w1 , . . . , B∼ ]wm .

Therefore, the proof of this premise must be of the form: j 0 θ ]e2j ⇐ Π )j=1...m ( (ti θ == ti θ0 )]d2i ⇐ Π )i=1...n ( B∼ (♥) pˆC (tn )θ]e1(n+1) ⇐ Π

for some substitution θ0 not affecting X n . We can assume that the last m premises in (♥) are proved in QCHL(D, C) w.r.t. elimS (P) by proof trees Tj0 satisfying kTj0 k < kT 0 k (1 ≤ j ≤ m). Then we use the substitution θ0 and clause C to build a SQCHL(S, D, C) proof tree T with a SQDA inference step at the root of the form: ( (t0i == ti θ0 )]e1i ⇐ Π )i=1...n ( Bj θ0 ]e2j ⇐ Π )j=1...m (♣) p0 (t0 n )]d ⇐ Π

Next we check that the premises of this inference step admit proofs in SQCHL(S, D, C) and that (♣) satisfies the side conditions of a valid SQDA inference step. • P `S,D,C (t0i == ti θ0 )]e1i ⇐ Π for i = 1 . . . n. — From the premises ((Xi ∼ ti )θ]e1i ⇐ Π)i=1...n of (♠) and by construction of elimS (P) we know EQS `D,C (Xi ∼ ti )θ]e1i ⇐ Π (1 ≤ i ≤ n). Therefore by Lemma 4.1 we have Xi θ ≈e1i ,Π ti θ for i = 1 . . . n. — Consider now the premises ((t0i == Xi θ)]d1i ⇐ Π)i=1...n of (♠). Their proofs

299

24

R. Caballero, M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz

must rely on QEA inference steps, and therefore t0i ≈Π Xi θ holds for i = 1 . . . n. — Analogously, from the proofs of the premises ((ti θ == ti θ0 )]d2i ⇐ Π)i=1...n we have ti θ ≈Π ti θ0 (or equivalently ti θ0 ≈Π ti θ) for i = 1 . . . n.



• • • •

From the previous points we have Xi θ ≈e1i ,Π ti θ, t0i ≈Π Xi θ and ti θ0 ≈Π ti θ, which by Lemma 2.7(1) of (Rodr´ıguez-Artalejo and Romero-D´ıaz 2010b) imply t0i ≈e1i ,Π ti θ0 (1 ≤ i ≤ n). Therefore the premises ((t0i == ti θ0 )]e1i ⇐ Π)i=1...n can be proven in SQCHL(S, D, C) using a SQEA inference step. j 0 P `S,D,C Bj θ0 ]e2j ⇐ Π for j = 1 . . . m. We know elimS (P) `D,C B∼ θ ]e2j ⇐ Π with 0 0 0 a proof tree Tj satisfying kTj k < kT k (1 ≤ j ≤ m) because of (♥). Therefore we have, by inductive hypothesis, P `S,D,C Bj θ0 ]e2j ⇐ Π for some SQCHL(S, D, C) proof tree Tj (1 ≤ j ≤ m). S(p, p0 ) = d0 6= b. As seen above. e2j Q? wj for j = 1 . . . m. This is a side condition of the QDA step in (♥). d P e1i for i = 1 . . . n. Straightforward from the side conditions of (♠), which include d P t ◦ e1i for (0 ≤ i ≤ n + 1). d P α◦e2j for j = 1 . . . m. This follows from the side conditions of (♠) and (♥), since we have d P t◦e1i for i = 0 . . . n+1 (in particular d P e1(n+1) ) and e1(n+1) P α◦e2j for j = 1 . . . m. Finally, the next theorem extends the previous result to goals.

Theorem 4.2 Let G be a goal for a SQCLP(S, D, C)-program P whose atoms are all relevant for P. Assume P 0 = elimS (P) and G0 = elimS (G). Then, SolP (G) = SolP 0 (G0 ). Proof According to the definition of goals in Section 2, and Definition 4.2, G and G0 must be of the form (Ai ]Wi , Wi Q? βi )i=1...m and (Ai∼ ]Wi , Wi Q? βi )i=1...m , respectively. By Definitions 2.2 and 3.1, both SolP (G) and SolP 0 (G0 ) are sets of triples hσ, µ, Πi where σ is a C-substitution, µ : war(G) → DD \ {b} (note that war(G) = war(G0 )) and Π is a satisfiable finite set of C-constraints. Moreover: 1. hσ, µ, Πi ∈ SolP (G) iff Wi µ = di Q? βi and P `S,D,C Ai σ]Wi µ ⇐ Π (1 ≤ i ≤ m). 2. hσ, µ, Πi ∈ SolP 0 (G0 ) iff Wi µ = di Q? βi and P 0 `D,C Ai∼ σ]Wi µ ⇐ Π (1 ≤ i ≤ m). Because of Theorem 4.1, conditions (1) and (2) are equivalent. 4.2 Transforming QCLP into CLP The results presented in this subsection are dependant on the assumption that the qualification domain D is existentially expressible in the constraint domain C via an injective mapping ı : DD \ {b} → CC and two existential C-constraints of the following form: qVal(X) = ∃U1 . . . ∃Uk (B1 ∧ . . . ∧ Bm ) qBound(X, Y, Z) = ∃V1 . . . ∃Vl (C1 ∧ . . . ∧ Cq )

300

A Transformation-based Implementation for SQCLP (Preliminary Version) 25 Our aim is to present semantically correct transformations from QCLP(D, C) into CLP(C), working both for programs and goals. In order to compute with the encodings of D values in C, we will use the CLP(C)-program ED consisting of the following two clauses: qVal(X) ← B1 , . . . , Bm qBound(X, Y, Z) ← C1 , . . . , Cq where qVal ∈ DP 1 and qBound ∈ DP 3 do not occur in the QCLP(D, C) programs and goals to be transformed. The lemma stated below is an immediate consequence of Lemma 3.1 and Definition 2.1. Lemma 4.2 For any satisfiable finite set Π of C-constraints one has: 1. For any ground term t ∈ CC : t ∈ ran(ı) ⇐⇒ qVal(t) true in C ⇐⇒ ED `C qVal(t) ⇐ Π 2. For any ground terms r = ı(x), s = ı(y), t = ı(z) with x, y, z ∈ DD \ {b}: x P y ◦ z ⇐⇒ qBound(r, s, t) true in C ⇐⇒ ED `C qBound(r, s, t) ⇐ Π

The two items above are also valid if ED is replaced by any CLP(C)-program including the two clauses in ED and having no additional occurrences of qVal and qBound at the head of clauses. Now we are ready to define the transformations from QCLP(D, C) into CLP(C). Definition 4.3 Assume that D is existentially expressible in C, and let qVal(X), qBound(X, Y, Z) and ED be as explained above. Assume also a QCLP(D, C)-program P and a QCLP(D, C)-goal G for P without occurrences of the defined predicate symbols qVal and qBound. Then: 1. P is transformed into the CLP(C)-program elimD (P) consisting of the two clauses in ED and the transformed C T of each clause C ∈ P, built as specified in Figure 5. The transformation rules of this figure assume a different choice of p0 ∈ DP n+1 for each p ∈ DP n. 2. G is transformed into the CLP(C)-goal elimD (G) built as specified in Figure 5. Note that the qualification variables Wn occurring in G become normal CLP variables in the transformed goal. The following example illustrates the transformation elimD . Example 4.3 (Running example: CLP(R)-program elimD (elimS (Pr ))) Consider the QCLP(U⊗W, R)-program elimS (Pr ) and the goal elimS (Gr ) for the same program as presented in Example 4.2. The transformed CLP(R)-program elimD (elimS (Pr )) is as follows:

301

26

R. Caballero, M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz

Transforming Atoms TEA

(t == s)T = (t == s, ı(t)).

TPA

(κ)T = (κ, ı(t)) with κ primitive atom.

TDA

(p(tn ))T = (p0 (tn , W ), W ) with p ∈ DP n and W a fresh CLP variable.

Transforming qc-Atoms TQCA

AT = (A0 , w) (A]d ⇐ Π)T = (A0 ⇐ Π, {qVal(w), qBound(ı(d), ı(t), w)})

Transforming Program Clauses TPC CT

( BjT = (Bj0 , wj0 ) )j=1...m   qVal(wj0 ), pwj0 Q? ı(wj )q, = p0 (tn , W ) ← qVal(W ), 0 0 qBound(W, ı(α), wj ), Bj j=1...m α

− B1 ]w1 , . . . , Bm ]wm , W is a fresh CLP variable and where C : p(tn ) ← pwj0 Q? ı(wj )q is omitted if wj = ?, i.o.c. abbreviates qBound(ı(wj ), ı(t), wj0 ).

Transforming Goals TG

elimD (G) =



( BjT = (Bj0 , wj0 ) )j=1...m  qVal(Wj ), pWj Q? ı(βj )q, 0 0 0 qVal(wj ), qBound(Wj , ı(t), wj ), Bj j=1...m

where G : (Bj ]Wj , Wj Q? βj )j=1...m and pWj Q? ı(βi )q as in TPC above.

Fig. 5. Transformation rules

ˆ R 1 R1.1

ˆ famousR1 (sha, W) ← qVal(W), qBound(W, t, (0.9,1))

famous(X, W) ← qVal(W), qVal(W1 ), qBound(W, t, W1 ), payt (W1 ), qVal(W2 ), qBound(W, t, W2 ), ∼(X, sha, W2 ), qVal(W3 ), qBound(W, t, W3 ), ˆ famousR (sha, W3 ) 1

ˆ R 2 R2.1

w ˆ roteR2 (sha, kle, W) ← qVal(W), qBound(W, t, (1,1))

wrote(X, Y, W) ← qVal(W), qVal(W1 ), qBound(W, t, W1 ), payt (W1 ), qVal(W2 ), qBound(W, t, W2 ), ∼(X, sha, W2 ), qVal(W3 ), qBound(W, t, W3 ), ∼(Y, kle, W3 ),

qVal(W4 ), qBound(W, t, W4 ), w ˆ roteR2 (sha, kle, W4 ) R2.2

authored(X, Y, W) ← qVal(W), qVal(W1 ), qBound(W, t, W1 ), pay(0.9,0) (W1 ), qVal(W2 ), qBound(W, t, W2 ), ∼(X, sha, W2 ), qVal(W3 ), qBound(W, t, W3 ), ∼(Y, kle, W3 ),

qVal(W4 ), qBound(W, t, W4 ), w ˆ roteR2 (sha, kle, W4 )

ˆ R 3 R3.1

w ˆ roteR3 (sha, hamlet, W) ← qVal(W), qBound(W, t, (1,1))

wrote(X, Y, W) ← qVal(W), qVal(W1 ), qBound(W, t, W1 ), payt (W1 ), qVal(W2 ), qBound(W, t, W2 ), ∼(X, sha, W2 ),

qVal(W3 ), qBound(W, t, W3 ), ∼(Y, hamlet, W3 ),

qVal(W4 ), qBound(W, t, W4 ), w ˆ roteR3 (sha, hamlet, W4 )

302

A Transformation-based Implementation for SQCLP (Preliminary Version) 27 R3.2

authored(X, Y, W) ← qVal(W), qVal(W1 ), qBound(W, t, W1 ), pay(0.9,0) (W1 ), qVal(W2 ), qBound(W, t, W2 ), ∼(X, sha, W2 ),

qVal(W3 ), qBound(W, t, W3 ), ∼(Y, hamlet, W3 ),

qVal(W4 ), qBound(W, t, W4 ), w ˆ roteR3 (sha, hamlet, W4 )

ˆ R 4

ˆ good workR4 (X, W) ← qVal(W),

qVal(W1 ), qBound((0.5,100), t, W1 ), qBound(W, (0.75,3), W1 ), famous(Y, W1 ), qVal(W2 ), qBound(W, (0.75,3), W2 ), authored(Y, X, W2 )

R4.1

good work(G, W) ← qVal(W), qVal(W1 ), qBound(W, t, W1 ), payt (W1 ), qVal(W2 ), qBound(W, t, W2 ), ∼(G, X, W2 ),

qVal(W3 ), qBound(W, t, W3 ), ˆ good workR4 (X, W3 ) % Program clauses for ∼:

∼(X, Y, W) ← qVal(W), qVal(t), qBound(W, t, t), X==Y

∼(kle, kli, W) ← qVal(W), qVal(W1 ), qBound(W, t, W1 ), pay(0.8,2) (W1 ) [. . .]

% Program clauses for pay: payt (W) ← qVal(W), qBound(W, t, t)

pay(0.9,0) (W) ← qVal(W), qBound(W, t, (0.9,0))

pay(0.8,2) (W) ← qVal(W), qBound(W, t, (0.8,2)) % Program clauses for qVal & qBound: qVal((X1 ,X2 )) ← X1 > 0, X1 ≤ 1, X2 ≥ 0

qBound((W1 ,W2 ), (Y1 ,Y2 ), (Z1 ,Z2 )) ← W1 ≤ Y1 × Z1 , W2 ≥ Y2 + Z2

Finally, the goal elimD (elimS (Gr )) for elimD (elimS (Pr )) is as follows: qVal(W), qBound((0.5,10), t, W), qVal(W’), qBound(W, t, W’), good work(X, W’)

Note that, in order to improve the clarity of the program clauses of this example, the qualification value (1,0)—top value in U⊗W—has been replaced by t. The next theorem proves the semantic correctness of the program transformation. Theorem 4.3 Let A be an atom such that qVal and qBound do not occur in A. Assume d ∈ D\{b} such that (A]d ⇐ Π)T = (A0 ⇐ Π, Ω). Then, the two following statements are equivalent: 1. P `D,C A]d ⇐ Π 2. elimD (P) `C A0ρ ⇐ Π for some ρ ∈ SolC (Ω) such that dom(ρ) = var(Ω). Proof We separately prove each implication. [1. ⇒ 2.] (the transformation is complete). We assume that T is a QCHL(D, C) proof tree witnessing P `D,C A]d ⇐ Π. We want to show the existence of a CLP(C) proof tree T 0 witnessing elimD (P) `C A0ρ ⇐ Π for some ρ ∈ SolC (Ω) such that dom(ρ) = var(Ω). We reason by complete induction on kT k. There are three possible

303

28

R. Caballero, M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz

cases, according to the the syntactic form of the atom A. In each case we argue how to build the desired proof tree T 0. — A is a primitive atom κ. In this case TQCA and TPA compute A0 = κ and Ω = {qVal(ı(t)), qBound(ı(d), ı(t), ı(t))}. Now, from P `D,C κ]d ⇐ Π follows Π |=C κ due to the QPA inference, and therefore taking ρ = ε we can prove elimD (P) `C κε ⇐ Π with a proof tree T 0 containing only one PA node. Moreover, ε ∈ SolC (Ω) is trivially true because the two constraints belonging to Ω are obviously true in C. — A is an equation t == s. In this case TQCA and TEA compute A0 = (t == s) and Ω = {qVal(ı(t)), qBound(ı(d), ı(t), ı(t))}. Now, from P `D,C (t == s)]d ⇐ Π follows t ≈Π s due to the QEA inference, and therefore taking ρ = ε we can prove elimD (P) `C (t == s)ε ⇐ Π with a proof tree T 0 containing only one EA node. Moreover, ε ∈ SolC (Ω) is trivially true because the two constraints belonging to Ω are obviously true in C. — A is a defined atom p(t0 n ) with p ∈ DP n . In this case TQCA and TDA compute A0 = p0 (t0 n , W ) and Ω = {qVal(W ), qBound(ı(d), ı(t), W )} where W is a fresh CLP variable. On the other hand, T must be rooted by a QDA step of the form: ( (t0i == ti θ)]di ⇐ Π )i=1...n ( Bj θ]ej ⇐ Π )j=1...m p(t0 n )]d ⇐ Π

(♣)

α

using a clause C : (p(tn ) ← − B1 ]w1 , . . . , Bm ]wm ) ∈ P instantiated by a substitution θ and such that the side conditions ej Q? wj (1 ≤ j ≤ m), d P di (1 ≤ i ≤ n) and d P α ◦ ej (1 ≤ j ≤ m) are fulfilled. For j = 1 . . . m we can assume BjT = (Bj0 , wj0 ) and thus (Bj θ]ej ⇐ Π)T = (Bj0 θ ⇐ Π, Ωj ) where Ωj = {qVal(wj0 ), qBound(ı(ej ), ı(t), wj0 )}. The proof trees Tj of the last m premises of (♣) will have less than kT k nodes, and hence the induction hypothesis can be applied to each (Bj θ]ej ⇐ Π) with 1 ≤ j ≤ m, obtaining CHL(C) proof trees Tj0 proving elimD (P) `C Bj0 θρj ⇐ Π for some ρj ∈ SolC (Ωj ) with dom(ρj ) = var(Ωj ). Consider ρ = {W 7→ ı(d)} and C T ∈ elimD (P) of the form:   qVal(wj0 ), pwj0 Q? ı(wj )q, C T : p0 (tn , W 0 ) ← qVal(W 0 ), qBound(W 0 , ı(α), wj0 ), Bj0 j=1...m. Obviously, ρ ∈ SolC (Ω) and dom(ρ) = var(Ω). To finish the proof we must prove elimD (P) `C A0ρ ⇐ Π. We claim that this can be done with a CHL(C) proof tree T 0 whose root inference is a DA step of the form:

   

( (t0i ρ == ti θ0 ) ⇐ Π )i=1...n (W ρ == W 0 θ0 ) ⇐ Π qVal(W 0 )θ0 ⇐ Π qVal(wj0 )θ0 ⇐ Π pwj0 Q? ı(wj )qθ0 ⇐ Π qBound(W 0 , ı(α), wj0 )θ0 ⇐ Π Bj0 θ0 ⇐ Π p0 (t0 n , W )ρ ⇐ Π

304

   

j=1...m

(♠)

A Transformation-based Implementation for SQCLP (Preliminary Version) 29 using C T instantiated by the substitution θ0 = θ ] ρ1 ] · · · ] ρm ] {W 0 7→ ı(d)}. We check that the premises of (♠) can be derived from elimD (P) in CHL(C): • elimD (P) `C (t0i ρ == ti θ0 ) ⇐ Π for i = 1 . . . n. By construction of ρ and θ0, these are equivalent to prove elimD (P) `C (t0i == ti θ) ⇐ Π for i = 1 . . . n and these hold with CHL(C) proof trees of only one EA node because of t0i ≈Π ti θ, which is a consequence of the first n premises of (♣). • elimD (P) `C (W ρ == W 0 θ0 ) ⇐ Π. By construction of ρ and θ0, this is equivalent to prove elimD (P) `C (ı(d) == ı(d)) ⇐ Π which results trivial. • elimD (P) `C qVal(W 0 )θ0 ⇐ Π. By construction of θ0 , this is equivalent to prove elimD (P) `C qVal(ı(d)) ⇐ Π. We trivially have that ı(d) ∈ ran(ı). Then, by Lemma 4.2, this premise holds. • elimD (P) `C qVal(wj0 )θ0 ⇐ Π for j = 1 . . . m. By construction of θ0 and Lemma 4.2 we must prove, for any fixed j, that qVal(wj0 ρj ) is true in C. As ρj ∈ SolC (Ωj ) we know ρj ∈ SolC (qVal(wj0 )), therefore qVal(wj0 ρj ) is trivially true in C. • elimD (P) `C pwj0 Q? ı(wj )qθ0 ⇐ Π for j = 1 . . . m. We reason for any fixed j. If wj = ? this results trivial. Otherwise, it amounts to qBound(ı(wj ), ı(t), wj0 ρj ) being true in C, by construction of θ0 and Lemma 4.2. As seen before, qVal(wj0 ρj ) is true in C, therefore wj0 ρj = ı(e0j ) for some e0j ∈ D \ {b}. From the side conditions of (♣) we have wj P ej . On the other hand, ρj ∈ SolC (Ωj ) and, in particular, ρj ∈ SolC (qBound(ı(ej ), ı(t), wj0 )). This, together with wj0 ρj = ı(e0j ), means ej P e0j , which with wj P ej implies wj P e0j , i.e. qBound(ı(wj ), ı(t), wj0 ρj ) is true in C. • elimD (P) `C qBound(W 0 , ı(α), wj0 )θ0 ⇐ Π for j = 1 . . . m. We reason for any fixed j. By construction of θ0 and Lemma 4.2, we must prove that qBound(ı(d), ı(α), wj0 ρj ) is true in C. As seen before, qVal(wj0 ρj ) is true in C, therefore wj0 ρj = ı(e0j ) for some e0j ∈ D \{b}. From the side conditions of (♣) we have d P α◦ej . On the other hand, ρj ∈ SolC (Ωj ) and, in particular, ρj ∈ SolC (qBound(ı(ej ), ı(t), wj0 )). This, together with wj0 ρj = ı(e0j ), means ej P e0j . Now, d P α ◦ ej and ej P e0j implies d P α ◦ e0j , i.e. qBound(ı(d), ı(α), wj0 ρj ) is true in C. • elimD (P) `C Bj0 θ0 ⇐ Π for j = 1 . . . m. In this case, it is easy to see that Bj0 θ0 = Bj0 θρj by construction of θ0 and because of the program transformation rules. On the other hand, proof trees Tj0 proving elimD (P) `C Bj0 θρj ⇐ Π can be obtained by inductive hypothesis as seen before. [2. ⇒ 1.] (the transformation is sound). We assume that T 0 is a a CHL(C) proof tree witnessing elimD (P) `C A0 ρ ⇐ Π for some ρ ∈ SolC (Ω) such that dom(ρ) = var(Ω). We want to to show the existence of a QCHL(D, C) proof tree T witnessing P `D,C A]d ⇐ Π. We reason by complete induction on kT 0 k. There are three possible cases according to the the syntactic form of the atom A0. In each case we argue how to build the desired proof tree T . — A0 is a primitive atom κ. In this case due to TQCA and TPA we can assume A = κ and Ω = {qVal(ı(t)), qBound(ı(d), ı(t), ı(t))}. Note that dom(ρ) = var(Ω) = ∅ implies ρ = ε. Now, from elimD (P) `C κε ⇐ Π follows Π |=C κ due to the PA inference, and therefore we can prove P `D,C κ]d ⇐ Π with a proof tree T containing only one QPA node. — A0 is an equation t == s. In this case due to TQCA and TEA we can assume

305

30

R. Caballero, M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz

A = (t == s) and Ω = {qVal(ı(t)), qBound(ı(d), ı(t), ı(t))}. Note that dom(ρ) = var(Ω) = ∅ implies ρ = ε. Now, from elimD (P) `C (t == s)ε ⇐ Π follows t ≈Π s due to the EA inference, and therefore we can prove P `D,C (t == s)]d ⇐ Π with a proof tree T containing only one QEA node. — A0 is a defined atom p0 (t0 n , W ) with p0 ∈ DP n+1 . In this case due to TQCA and TDA we can assume A = p(t0 n ) and Ω = {qVal(W ), qBound(ı(d), ı(t), W )}. On the other hand, T 0 must be rooted by a DA step (♠) using a clause C T ∈ elimD (P) instantiated by a substitution θ0 . We can assume that (♠), C T and the corresponding clause C ∈ P have the form already displayed in [1. ⇒ 2.]. By construction of C T , we can assume BjT = (Bj0 , wj0 ). Let θ = θ0 var(C) and ρj = θ0 var(wj0 ) (1 ≥ j ≥ m). Then, due to the premises qVal(wj0 )θ0 ⇐ Π of (♠) and Lemma 4.2 we can assume e0j ∈ D \ {b} (1 ≤ j ≤ m) such that wj0 ρj = ı(e0j ). To finish the proof, we must prove P `D,C A]d ⇐ Π. We claim that this can be done with a QCHL(D, C) proof tree T whose root inference is a QDA step of the form of (♣), as displayed in [1. ⇒ 2.], using clause C instantiated by θ. In the premises of this inference we choose di = t (1 ≤ i ≤ n) and ej = e0j (1 ≤ j ≤ m). Next we check that these premises can be derived from P in QCHL(D, C) and that the side conditions are fulfilled: • P `D,C (t0i == ti θ)]di ⇐ Π for i = 1 . . . n. This amounts to t0i ≈Π ti θ which follows from the first n premises of (♠) given that t0i ρ = t0i and ti θ0 = ti θ. • P `D,C Bj θ]ej ⇐ Π for j = 1 . . . m. From BjT = (Bj0 , wj0 ) and due to rule TQCA, we have ((Bj θ)]ej ⇐ Π)T = (Bj θ ⇐ Π, Ωj ) where Ωj = {qVal(wj0 ), qBound(ı(ej ), ı(t), wj0 )}. From the premises of (♠) and the fact that Bj0 θ0 = Bj0 θρj we know that elimD (P) `C Bj0 θρj ⇐ Π with a CHL(C) proof tree Tj0 such that kTj0 k < kT 0 k. Therefore P `D,C Bj θ]ej ⇐ Π follows by inductive hypothesis provided that ρj ∈ SolC (Ωj ). In fact, due to the form of Ωj , ρj ∈ SolC (Ωj ) holds iff wj0 ρj = ı(e0j ) for some e0j such that ej P e0j , which is the case because of the choice of ej . • ej Q? wj for j = 1 . . . m. Trivial in the case that wj = ?. Otherwise they are equivalent to wj P e0j which follow from premises pwj0 Q? ı(wj )qθ0 ⇐ Π (i.e. pwj0 ρj Q? ı(wj )q ⇐ Π) of (♠) and Lemma 4.2. • d P di for i = 1 . . . n. Trivially hold due to the choice of di = t. • d P α◦ej for j = 1 . . . m. Note that ρ ∈ SolC (Ω) implies the existence of d0 ∈ D \{b} such that ı(d0 ) = W ρ and d P d0 . On the other hand, ej = e0j by choice. It suffices to prove d0 P α ◦ e0j for j = 1 . . . m. Premises of (♠) and Lemma 4.2 imply that qBound(W 0 θ0 , ı(α), wj0 θ0 ) is true in C. Moreover, W 0 θ0 = W ρ = ı(d0 ) because of another premise of (♠) and wj0 θ0 = ı(e0j ) as explained above. Therefore qBound(W 0 θ0 , ı(α), wj0 θ0 ) amounts to qBound(ı(d0 ), ı(α), ı(e0j )) which guarantees d0 P α ◦ e0j (1 ≤ j ≤ m).

The goal transformation correctness is established by the next theorem, which will rely on the previous result:

Theorem 4.4 Let G be a goal for a QCLP(D, C)-program P such that qVal and qBound do not occur in G. Let P 0 = elimD (P) and G0 = elimD (G). Assume a C-subtitution σ,

306

A Transformation-based Implementation for SQCLP (Preliminary Version) 31 a mapping µ : war(G) → DD \ {b} and a satisfiable finite set of C-constraints Π. Then, the following two statements are equivalent: 1. hσ, µ, Πi ∈ SolP (G). 2. hθ, Πi ∈ SolP 0 (G0 ) for some θ that verifies the following requirements: (a) θ =var(G) σ, (b) θ =war(G) µı and (c) W θ ∈ ran(ı) for each W ∈ var(G0 ) \ (var(G) ∪ war(G)). Proof As explained in Subsection 3.1 the syntax of goals in QCLP(D, C)-programs is the same as that of goals for SQCLP(S, D, C)-programs, which is described in Section 2. Therefore G, and G0 due to rule TG, must have the following form: G : ( Bj ]Wj , Wj Q? βj )j=1...m G0 : ( qVal(Wj ), pWj Q? ı(βj )q, qVal(wj0 ), qBound(Wj , ı(t), wj0 ), Bj0 )j=1...m

with BjT = (Bj0 , wj0 ) (1 ≤ j ≤ m). Note that, because of rule TQCA, we have (Bj σ]Wj µ ⇐ Π)T = (Bj0 σ ⇐ Π, Ωj ) with Ωj = {qVal(wj0 ), qBound(ı(Wj µ), ı(t), wj0 )} for j = 1 . . . m. We now prove each implication. [1. ⇒ 2.] Let hσ, µ, Πi ∈ SolP (G). This means, by Definition 3.1, Wj µ Q? βj and P `D,C Bj σ]Wj µ ⇐ Π for j = 1 . . . m. In these conditions, Theorem 4.3 guarantees P 0 `C Bj0 σρj ⇐ Π (1 ≤ j ≤ m) for some ρj ∈ SolC (Ωj ) such that dom(ρj ) = var(Ωj ). It is easy to see that var(G0 )\(var(G)∪war(G)) = var(Ω1 )]· · ·]var(Ωm ). Therefore it is possible to define a substitution θ verifying θ =var(G) σ, θ =war(G) µı and θ =dom(ρj ) ρj (1 ≤ j ≤ m). Trivially, θ satisfies conditions 2.(a) and 2.(b). It also satisfies condition 2.(c) because for any j and any variable X such that X ∈ var(Ωj ), we have a constraint qVal(X) ∈ Ωj implying, due to Lemma 4.2, Xρj ∈ ran(ı) (because ρj ∈ SolC (Ωj )). In order to prove hθ, Πi ∈ SolP 0 (G0 ) in the sense of Definition 3.2 we check the following items: • By construction, θ is a C-substitution. • By the theorem’s assumptions, Π is a satisfiable and finite set of C-constraints. • P 0 `C Aθ ⇐ Π for every atom A in G0 . Because of the form of G0 we have to prove the following for any fixed j: — P 0 `C qVal(Wj )θ ⇐ Π. By construction of θ and Lemma 4.2, this amounts to qVal(ı(Wj µ)) being true in C, which is trivial consequence of Wj µ ∈ D \ {b}. — P 0 `C pWj Q? ı(βj )qθ ⇐ Π. If βj = ? this becomes trivial. Otherwise, Wj θ = ı(Wj µ) by construction of θ, and by Lemma 4.2 it suffices to prove qBound(ı(βj ), ı(t), ı(Wj µ)) is true in C. This follows from Wj µ Q? βj , that is ensured by hσ, µ, Πi ∈ SolP (G). — P 0 `C qVal(wj0 )θ ⇐ Π. By construction of θ and Lemma 4.2, this amounts to qVal(wj0 ρj ) being true in C, that is guaranteed by ρj ∈ SolC (Ωj ). — P 0 `C qBound(Wj , ı(t), wj0 )θ ⇐ Π. By construction of θ and Lemma 4.2, this amounts to qBound(ı(Wj µ), ı(t), wj0 ρj ) being true in C, that is also guaranteed by ρj ∈ SolC (Ωj ).

307

32

R. Caballero, M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz

— P 0 `C Bj0 θ ⇐ Π. Note that, by construction of θ, Bj0 θ = Bj0 σρj . On the other hand, ρj has been chosen above to verify P 0 `C Bj0 σρj ⇐ Π. [2. ⇒ 1.] Let hθ, Πi ∈ SolP 0 (G0 ) and assume that θ verifies 2.(a), 2.(b) and 2.(c). In order to prove hσ, µ, Πi ∈ SolP (G) in the sense of Definition 3.1 we must prove the following items: • By the theorem’s assumptions, σ is a C-substitution, µ : war(G) → DD \ {b} and Π is a satisfiable finite set of C-constraints. • Wj µ Q? βj . We reason for any fixed j. If βj = ? this results trivial. Otherwise, we have P 0 `C pWj Q? ı(βj )qθ ⇐ Π which, by condition 2.(b) and Lemma 4.2 amounts to qBound(ı(βj ), ı(t), ı(Wj µ)) is true C, i.e. Wj µ Q βj . • P `D,C Bj σ]Wj µ ⇐ Π for j = 1 . . . m. We reason for any fixed j. Let ρj be the restriction of θ to var(Ωj ). Then, P 0 `C Bj0 σρj ⇐ Π follows from hθ, Πi ∈ SolP 0 (G0 ) and Bj0 θ = Bj0 σρj . Therefore, P `D,C Bj σ]Wj µ ⇐ Π follows from Theorem 5.3 provided that ρj ∈ SolC (Ωj ). By Lemma 4.2 and the form of Ωj , ρj ∈ SolC (Ωj ) holds iff P 0 `C qVal(wj0 ρj ) ⇐ Π and P 0 `C qBound(ı(Wj µ), ı(t), wj0 ρj ) ⇐ Π, which is true because hθ, Πi ∈ SolP 0 (G0 ) and construction of ρj . 4.3 Solving SQCLP Goals In this subsection we show that the transformations from the two previous subsections can be used to define abstract goal solving systems for SQCLP and arguing about their correctness. In the sequel we consider a given SQCLP(S, D, C)program P and a goal G for P whose atoms are all relevant for P. We also consider P 0 = elimS (P), G0 = elimS (G), P 00 = elimD (P 0 ) and G00 = elimD (G0 ). Due to the definition of both elimS and elimD , we can assume: G : ( Ai ]Wi , Wi Q? βi )i=1...m G0 : ( Ai∼ ]Wi , Wi Q? βi )i=1...m G00 : ( qVal(Wi ), pWi Q? ı(βi )q, qVal(wi0 ), qBound(Wi , ı(t), wi0 ), A0i )i=1...m where ATi = (A0i , wi0 ).

We start by presenting an auxiliary result.

Lemma 4.3 Assume P, G, P 0, G0, P 00 and G00 as above. Let hσ 0 , Πi ∈ SolP 00 (G00 ), ν ∈ SolC (Π) and θ = σ 0 ν. Then hθ, Πi ∈ SolP 00 (G00 ). Moreover, W θ ∈ ran(ı) for every W ∈ var(G00 ) \ var(G).1 Proof Consider an arbitrary atom A00 occurring in G00. Because of hσ 0 , Πi ∈ SolP 00 (G00 ) we have P `C A00 σ 0 ⇐ Π. On the other hand, because of ν ∈ SolC (Π) we have ∅ |=C Πν and therefore also Π |=C Πν. This and Definition 3.1(4) of (Rodr´ıguez-Artalejo and Romero-D´ıaz 2010b) ensure A00 σ 0 ⇐ Π
Note that war(G) ⊆ var(G00 ) \ var(G).

308

A Transformation-based Implementation for SQCLP (Preliminary Version) 33 This fact, P 00 `C A00 σ 0 ⇐ Π and the Entailment Property for Programs in CLP(C) imply P 00 `C A00 θ ⇐ Π. Therefore, hθ, Πi ∈ SolP 00 (G00 ). Consider now any W ∈ var(G00 ) \ var(G). By construction of G00, one of the atoms occurring in G00 is qVal(W ). Then, due to hσ 0 Πi ∈ SolP 00 (G00 ) we have P 00 `C qVal(W σ 0 ) ⇐ Π. Because of Lemma 3.1(1) this implies Π |=C qVal(W σ 0 ), i.e. SolC (Π) ⊆ SolC (qVal(W σ 0 )). Since ν ∈ SolC (Π) we get ν ∈ SolC (qVal(W σ 0 )), i.e. W σ 0 ν ∈ ran(ı). Since W σ 0 ν = W θ, we are done. Next, we explain how to define an abstract goal solving system for SQCLP from a given abstract goal solving system for CLP. Definition 4.4 Let CLP-AGSS be an abstract goal solving system for CLP(C) (in the sense of Definition 3.3). Then we define SQCLP-AGSS as an abstract goal solving system for SQCLP(S, D, C) that works as follows: 1. Given a goal G for the SQCLP(S, D, C)-program P, consider P 0, G0, P 00 and G00 as explained at the beginning of the subsection. 2. For each solution hσ 0 , Πi computed by CLP-AGSS for G00, P 00 and for any ν ∈ SolC (Π), SQCLP-AGSS computes hσ, µ, Πi where θ = σ 0 ν, σ = θvar(G) and µ = θı−1 war(G). Note that µ is well-defined thanks to Lemma 4.3. The next theorem ensures that SQCLP-AGSS is correct provided that CLPAGSS is also correct. The proof relies on the semantic results of the two previous subsections. Theorem 4.5 Assume that CLP-AGSS is correct (in the sense of Definition 3.3). Let SQCLPAGSS be as in the previous definition. Then SQCLP-AGSS is correct in the sense of Definition 2.3. Proof We separately prove that SQCLP-AGSS is sound and weakly complete. — SQCLP-AGSS is sound. Let hσ, µ, Πi be an answer computed by SQCLP-AGSS for G, P. We must prove that hσ, µ, Πi ∈ SolP (G). By Definition 4.4 we can assume hσ 0 , Πi ∈ SolP 00 (G00 ) and ν ∈ SolC (Π) such that σ = θvar(G) and µ = θı−1 war(G) with θ = σ 0 ν. Because of Lemma 4.3 we have hθ, Πi ∈ SolP 00 (G00 ) and W θ ∈ ran(ı) for every W ∈ var(G00 ) \ var(G). Note that: • θ =var(G0 ) σ. This follows from var(G0 ) = var(G) and the construction of σ. • θ =war(G0 ) µı. This follows from war(G0 ) = war(G) and θ =war(G) µı, that is obvious from the construction of µ. • W θ ∈ ran(ı) for each W ∈ var(G00 ) \ (var(G0 ) ∪ war(G0 )). This is a consequence of Lemma 4.3 since var(G00 ) \ (var(G0 ) ∪ war(G0 )) ⊆ var(G00 ) \ var(G0 ) and var(G0 ) = var(G). From the previous items and Theorem 4.4 we get hσ, µ, Πi ∈ SolP 0 (G0 ), which trivially implies hσ, µ, Πi ∈ SolP (G) because of Theorem 4.2.

309

34

R. Caballero, M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz

— SQCLP-AGSS is weakly complete. Let hη, ρ, ∅i ∈ GSolP (G) be a ground solution for G w.r.t. P. We must prove that it is subsumed—in the sense of Definition 2.2(3)—by some answer hσ, µ, Πi computed by SQCLP-AGSS for G, P. By Theorem 4.2 we have that hη, ρ, ∅i is also a ground solution for G0 w.r.t. P 0 . In addition, by Theorem 4.4 hη 0 , ∅i ∈ SolP 00 (G00 ) for some η 0 such that • (1) η 0 =var(G0 ) η, • (2) η 0 =war(G0 ) ρı and hence η 0 (ı−1 ) =war(G0 ) ρ, and • W η 0 ∈ ran(ı) for each W ∈ var(G00 ) \ (var(G0 ) ∪ war(G0 )) (i.e. wi0 η 0 ∈ ran(ı) for each i = 1 . . . m such that wi0 is a variable). By construction of η 0 , it is clear that hη 0 , ∅i is ground. Now, by the weak completeness of CLP-AGSS, there is some computed answer hσ 0 , Πi subsuming hη 0 , ∅i, therefore satisfying • (3) there is some ν ∈ SolC (Π), and • (4) η 0 =var(G00 ) σ 0 ν. Because of Definition 4.4 one can build a SQCLP-AGSS computed answer hσ, µ, Πi as follows: • (5) σ = σ 0 νvar(G) • (6) µ = σ 0 νı−1 war(G) We now check that hσ, µ, Πi subsumes hη, ρ, ∅i: • Wi ρ P Wi µ and even Wi ρ = Wi µ because:

Wi ρ =(2) Wi η 0 (ı−1 ) =(4) Wi σ 0 ν(ı−1 ) =(6) Wi µ .

• ν ∈ SolC (Π) by (3) and, moreover, for any X ∈ var(G): Xη =(1) Xη 0 =(4) Xσ 0 ν =(†) Xσ 0 νν =(5) Xσν therefore η =var(G) σν. The step (†) is justified because ν ∈ ValC implies ν = νν. 5 A Practical Implementation This section is devoted to the more practical aspects of the SQCLP programming scheme and it is developed in three subsections: Subsection 5.1 explains what steps must be given when implementing a programming scheme like this and why the theoretic results presented in the previous sections—with special emphasis in those in Subsection 4.3—become useful for implementation. Subsection 5.2 introduces a prototype implementation and explains how to write programs and how to solve goals. Finally, in Subsection 5.3 we study the unavoidable overload introduced in the system by qualifications and proximity relations when comparing the execution of programs without any explicit use of such resources.

310

A Transformation-based Implementation for SQCLP (Preliminary Version) 35 5.1 SQCLP over a CLP Prolog System Assume an available CLP Prolog System, a SQCLP(S, D, C)-program P and a goal G for P. Our purpose is to implement a goal solving system for SQCLP following Definition 4.4. We will examine each step in this schema, discussing the necessary implementation details for putting theory into practice. The first step is to obtain the transformed programs P 0 = elimS (P) and P 00 = elimD (P 0 ); and the transformed goals G0 = elimS (G) and G00 = elimD (G0 ). According to Definition 4.2(3), P 0 = elimS (P) is of the form EQS ∪ PˆS , where EQS is obtained following Definition 4.1 and PˆS is obtained following Definition 4.2(3,2). When implementing EQS a first difficulty arises, namely the implementation of ∼ ∈ DP 2, which apparently requires one clause of the form: t

u ∼ u0 ← − payλ ]? for each pair u, u0 ∈ BC such that S(u, u0 ) = λ 6= b, and one clause of the form: t

c(X n ) ∼ c0 (Y n ) ← − payλ ]?, ((Xi ∼ Yi )]?)i=1...n for each pair c, c0 ∈ DC n such that S(c, c0 ) = λ 6= b. While this should obviously require an infinite number of clauses (because DC n is infinite and S(c, c) = t 6= b for all c ∈ DC n ; and also BC is infinite—in general—and S(u, u) = t 6= b for every u ∈ BC ), in practice, it is enough to limit the number of clauses to the finite number of different basic values u ∈ BC and constructors c ∈ DC n that can be found either in P, G or S. A similar difficulty arises when codifying the clauses for predicates payλ ∈ DP 0, which according to Definition 4.1 there should be a clause of the form: λ

payλ ← − in EQS for each λ ∈ DD \ {b}. In this case, the solution is also similar because it suffices to generate enough payλ clauses for the finite λ ∈ DD \ {b} that can be found occurring either in the clauses of PˆS or in the clauses implementing the predicate ∼ ∈ DP 2. The construction of PˆS , following Definition 4.2, presents no particular difficulα − B) ∈ P we will generate a finite set CˆS of clauses, ties. For each clause C : (p(tn ) ←

because the number of symbols p0 such that S(p, p0 ) = λ 6= b will be also finite in practice. Finally, the construction of G0 is merely the straightforward replacement of all the occurrences of ‘==’ in G by ‘∼’. The transformation elimD from QCLP(D, C) into CLP(C), is defined in Definition 4.3. P 00 = elimD (P 0 ) is obtained by incorporating the two clauses of the program ED to the result of applying the transformation rules in Figure 5 to the QCLP(D, C)-program P 0. Applying the transformation rules is straightforward, but the codification of constraints qVal(X) and qBound(X, Y, Z) in ED requires some clarification. In our implementation we have considered the constraint domain R, as well as any qualification domain that can be built from B, U and W by means of the strict cartesian product operation ⊗ including, in particular, U⊗W. These qualification domains are existentially expressible in R, therefore the constraints

311

36

R. Caballero, M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz

can be implemented by defined predicates as explained in Section 4.2. In particular in our prototype implementation these predicates are: % qval( +QDom, ?W ): qval(b, 1). qval(u, W) :- {W > 0, W =< 1}. qval(w, W) :- {W >= 0}. qval((D1,D2), (W1,W2)) :- qval(D1, W1), qval(D2, W2). % qbound( +QDom, ?X, ?Y, ?Z ): qbound(b, 1, 1, 1). qbound(u, X, Y, Z) :- {X =< Y * Z}. qbound(w, X, Y, Z) :- {X >= Y + Z}. qbound((D1,D2), (X1,X2), (Y1,Y2), (Z1,Z2)) :- qbound(D1, X1, Y1, Z1), qbound(D2, X2, Y2, Z2). Instead of using different qVal and qBound predicates for each allowable D, our prototype implementation just uses two predicates qVal and qBound with an extra first argument, used to encode an identifier of some specific allowable D. This parameter can take either the value b (for B), u (for U), w (for W) or a pair (D1 ,D2 ) (for D1 ⊗ D2 ), where each Di can be either b, u, w or another pair representing a product. For instance ((u,w),w) represents the qualification domain (U⊗W)⊗W. The compiler ensures that this argument takes the correct value for each transformed program and goal depending on the specific instance of the SQCLP scheme the program is written for. After obtaining P 00 and G00, the CLP Prolog System is used to solve G00 w.r.t. P 00. This yields computed answers of the form hσ 0 , Πi. Now, instead of obtaining particular substitutions θ = σ 0 ν, σ = θvar(G) and µ = θı−1 war(G) for any ν ∈ SolC (Π) as explained in Definition 4.4(2), our prototype implementation limits itself to display hσ 0 , Πi as the computed answer in SQCLP. The reason behind this behavior is that, in general (and particularly in R), it is impossible to enumerate the possible solutions ν ∈ SolC (Π). Thus, it results impossible to implement a technique for obtaining all the possible triples hσ, µ, Πi. Note, however, that for a user it will not be difficult to distinguish, in the shown computed answers, what variable bindings correspond to the substitution σ of the triple and what to the substitution µ, even when the qualification variables are not bound but constrained, which is a common behavior in the context of CLP programming. However, for the SQCLP-AGSS of Definition 4.4, it results mandatory to define the computed answers in terms of ν ∈ SolC (Π), because our SQCLP-semantics relies on proving instances of G for some specific ground values of the variables in war(G). 5.2 (S)QCLP: A Prototype System for SQCLP Programming The prototype implementation object of this subsection is publicly available, and can be found at: http://gpd.sip.ucm.es/cromdia/qclp

312

A Transformation-based Implementation for SQCLP (Preliminary Version) 37 The system currently requires the user to have installed either SICStus Prolog or SWI-Prolog, and it has been tested to work under Windows, Linux and MacOSX platforms. The latest version available at the time of writing this paper is 0.6. If a latter version is available some things might have changed but in any case the main aspects of the system should remain the same. Please consult the changelog provided within the system itself for specific changes between versions. SQCLP is a very general programming scheme and, as such, it supports different proximity relations, different qualification domains and different constraint domains when building specific instances of the scheme for any specific purpose. As it would result impossible to provide an implementation for every admissible triple (or instance of the scheme), it becomes mandatory to decide in advance what specific instances will be available for writing programs in (S)QCLP. In essence: 1. In its current state, the only available constraint domain is R. Thus, under both SICStus Prolog and SWI-Prolog the library clpr will provide all the available primitives in (S)QCLP programs. 2. The available qualification domains are: ‘b’ for the domain B; ‘u’ for the domain U; ‘w’ for the domain W; and any strict cartesian product of those, as e.g. ‘(u,w)’ for the product domain U⊗W. 3. With respect to proximity relations, the user will have to provide, in addition to the two symbols and their proximity value, their kind (either predicate or constructor) and their arity. Both kind and arity must be the same for each pair of symbols having a proximity value different of b. Note, however, that when no specific proximity relation S is provided for a given program, Sid is then assumed. Under this circumstances, an obvious technical optimization consists on transforming the original program only with elimD , thus reducing the overload introduced in this case by elimS . The reason behind this optimization is that for any given SQCLP(Sid , D, C)-program P, it is also true that P is a QCLP(D, C)-program, therefore elimD (elimS (P)) must semantically be equivalent to elimD (P). Nevertheless, elimD (P) behaves more efficiently than elimD (elimS (P)) due to the reduced number of resulting clauses. Thus, in order to improve the efficiency, the system will avoid the use of elimS when no proximity relation is provided by the user. The final available instances in the (S)QCLP system are: SQCLP(S, b, clpr), SQCLP(S, u, clpr), SQCLP(S, w, clpr), SQCLP(S, (u, w), clpr), . . . and their counterparts in the QCLP scheme when S = Sid . 5.2.1 Programming in (S)QCLP Programming in (S)QCLP is straightforward if the user is accustomed to the Prolog programming style. However, there are three syntactic differences with pure Prolog: 1. Clauses implications are replaced by “<-d-” where d ∈ D \ {b}. If d = t, then the implication can become just “<--”. E.g. “<-0.9-” is a valid implication in the domains U and W; and “<-(0.9,2)-” is a valid implication in the domain U⊗W.

313

38

R. Caballero, M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz 2. Clauses in (S)QCLP are not finished with a dot (.). They are separated by layout, therefore all clauses in a (S)QCLP program must start in the same column. Otherwise, the user will have to explicitly separate them by means of semicolons (;). 3. After every body atom (even constraints) the user can provide a threshold condition using ‘#’. The notation ‘?’ can also be used instead of some particular qualification value, but in this case the threshold condition ‘#?’ can be omitted.

Comments are as in Prolog: % This is a line comment. /* This is a multi-line comment, /* and they nest! */. */ and the basic structure of a (S)QCLP program is the following (line numbers are for reference): File: Peano.qclp 1 2 3 4 5 6

% Directives... # qdom w % Program clauses... % num( ?Num ) num(z) <-num(s(X)) <-1- num(X)

In the previous small program, lines 1, 3 and 4 are line comments, line 2 is a program directive telling the compiler the specific qualification domain the program is written for, and lines 5 and 6 are program clauses defining the well-known Peano numbers. As usual, comments can be written anywhere in the program as they will be completely ignored (remember that a line comment must necessarily end in a new line character, therefore the very last line of a file cannot contain a line comment), and directives must be declared before any program clause. There are three program directives in (S)QCLP: 1. The first one is “#qdom qdom” where qdom is any system available qualification domain, i.e. b, u, w, (u,w). . . See line 2 in the previous program sample as an example. This directive is mandatory because the user must tell the compiler for which particular qualification domain the program is written. 2. The second one is “#prox file” where file is the name of a file (with extension .prox containing a proximity relation. If the name of the file starts with a capital letter, or it contains spaces or any special character, file will have to be quoted with single quotes. For example, assume that with our program file we have another file called Proximity.prox. Then, we would have to write “#prox ‘Proximity’” to link the program with such proximity relation. This directive is optional, and if omitted, the system assumes that the program is of an instance of the QCLP scheme. 3. The third one is “#optimized unif”. This directive tells the compiler that the program is intended to be used with the optimized version of the unification algorithm, what improves the general efficiency of the goal solving

314

A Transformation-based Implementation for SQCLP (Preliminary Version) 39 process. However, as noted at the end of Section 2, this could have the effect of losing valid answers, although we conjecture that if the proximity relation is transitive and if the program clauses do not make use of attenuation factors other that t, this will not happen. Proximity relations are defined in files of extension .prox with the following form: File: Work.prox 1 2 3 4

% Predicates: pprox( S1, S2, Arity, Value ). pprox(wrote, authored, 2, (0.9,0)). % Constructors: cprox( S1, S2, Arity, Value ). cprox(king_lear, king_liar, 0, (0.8,2)).

where the file can contain pprox/4 Prolog facts, for defining proximity between predicate symbols of any arity; or cprox/4 Prolog facts, for defining proximity between constructor symbols of any arity. The arguments of both pprox/4 and cprox/4 are: the two symbols, their arity and its proximity value. Note that, although it is not made explicit the qualification domain this proximity relation is written for, all values in it must be of the same specific qualification domain, and this qualification domain must be the same declared in every program using the proximity relation. Otherwise, the solving of equations may produce unexpected results or even fail. Reflexive and symmetric closure is inferred by the system, therefore, there is no need for writing reflexive proximity facts, nor the symmetric variants of proximity facts already provided. You can notice this in the previous sample file in which neither reflexive proximity facts, nor the symmetric proximity facts to those at lines 2 and 4 are provided. In the case of being explicitly provided, additional (repeated) solutions might be computed for the same given goal, although soundness and weak completeness of the system should still be preserved. Transitivity is neither checked nor inferred so the user will be responsible for ensuring it if desired. As the reader would have already guessed, the file Work.prox implements the proximity relation Sr of Example 4.1 in (S)QCLP. Finally, the program Pr of Example 4.1 can be represented in (S)QCLP as follows: File: Work.qclp 1 2 3 4 5 6 7 8 9

# qdom (u,w) # prox ’Work’ % famous( ?Author ) famous(shakespeare) <-(0.9,1)% wrote( ?Author, ?Book ) wrote(shakespeare, king_lear) <-(1,1)wrote(shakespeare, hamlet) <-(1,1)% good_work( ?Work ) good_work(X) <-(0.75,3)- famous(Y)#(0.5,100), authored(Y,X)

Note that, at line 1 the qualification domain U⊗W is declared, and at line 2 the proximity relation at Work.prox is linked to the program. In addition, observe

315

40

R. Caballero, M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz

that one threshold constraint is imposed for a body atom in the program clause at line 9, effectively requiring to prove famous(Y) for a qualification value of at least (0.5,100) to be able to use this program clause. Finally, we explain how constraints are written in (S)QCLP. As it has already been said, only R is available, thus both in SICStus Prolog and SWI-Prolog the library clpr is the responsible for providing the available primitive predicates. Given that constraints are primitive atoms of the form r(tn ) where r ∈ P P n and ti are terms; primitive atoms share syntax with usual Prolog atoms. At this point, and having that many of the primitive predicates are syntactically operators (hence not valid identifiers), the syntax for predicate symbols has been extended to include operators, therefore predicate symbols like op+ ∈ P P 3 , which codifies the operation + in a 3-ary predicate, will let us to build constraints of the form +(A,B,C), that must be understood as in A + B = C or C = A + B. Similarly, predicate symbols like cp> ∈ P P 2 , which codifies the comparison operator > in a binary predicate, will let us to build constraints of the form >(A,B), that must be understood as in A > B. Any other primitive predicate such as maximize ∈ P P 1 , will let us to build constraints like maximize(X). Valid primitive predicate symbols include +, -, *, /, >, >=, =<, <, maximize, minimize, etc. Threshold constraints can also be provided for primitive atoms in the body of clauses with the usual notation. Note, however, that due the semantics of SQCLP, all primitive atoms can be trivially proved with t if they ever succeeds—so threshold constraints become, in this case, of no use. The syntax for constraints explained above follows the standard syntax for atoms. Nonetheless, the system also allows to write these constraints in a more natural infix notation. More precisely, +(A,B,C) can be also written in the infix form A+B=C or C=A+B, and >(X,Y) in the infix form X>Y; and similarly for other op and cp constraints. When using infix notation, threshold conditions can be set by (optionally) enclosing the primitive atom between parentheses, therefore becoming (A+B=C)#t, (C=A+B)#t or (X>Y)#t (or any other valid qualification value or ‘?’). Using parentheses is recommended to avoid understanding that the threshold condition is set only for the last term in the constraint, which would not be the case. Note that even in infix notation, operators cannot be nested, that is, terms A, B, C, X and Y cannot have operators as main symbols (neither in prefix nor in infix notation), so the infix notation is just a syntactic sugar of its corresponding prefix notation. As a final example for constraints, one could write the predicate double/2 in (S)QCLP, for computing the double of any given number, with just the clause double(N,D) <-- *(N,2,D), or double(N,D) <-- N*2=D for a clause with a more natural syntax. 5.2.2 The interpreter for (S)QCLP The interpreter for (S)QCLP has been implemented on top of both SICStus Prolog and SWI-Prolog. To load it, one must first load her desired (and supported) Prolog system and then load the main file of the interpreter—i.e. qclp.pl—, that will be located in the main (S)QCLP folder among other folders. Once loaded, one will

316

A Transformation-based Implementation for SQCLP (Preliminary Version) 41 see the welcome message and will be ready to compile and load programs, and to execute goals. WELCOME TO (S)QCLP 0.6 (S)QCLP is free software and comes with absolutely no warranty. Support & Updates: http://gpd.sip.ucm.es/cromdia/qclp. Type ’:help.’ for help. yes | ?From the interpreter for (S)QCLP one can, in addition to making use of any standard Prolog goals, use the specific (S)QCLP commands required for both interacting with the (S)QCLP system, and for compiling/loading SQCLP programs. All these commands take the form: :command. if they do not require arguments, or: :command(Arg1 , ..., Argn ). if they do; where each argument Argi must be a prolog atom unless stated otherwise. The most useful commands are: • :cd(Folder). Changes the working directory to Folder. Folder can be an absolute or relative path. • :compile(Program). Compiles the (S)QCLP program ‘Program.qclp’ producing the equivalent Prolog program in the file ‘Program.pl’. • :load(Program). Loads the already compiled (S)QCLP program ‘Program.qclp’ (note that the file ‘Program.pl’ must exist for the program to correctly load). • :run(Program). Compiles the (S)QCLP program ‘Program.qclp’ and loads it afterwards. This command is equivalent to executing: :compile(Program), :load(Program). For illustration purposes, we will assume that you have the files Work.prox and Work.qclp (both as seen before) in the folder ∼/examples. Under these circumstances, after loading your preferred Prolog system and the interpreter for (S)QCLP, one would only have to change the working directory to that where the files are located: | ?- :cd(’∼/examples’). and run the program: | ?- :run(’Work’). If no errors are encountered, one should see the output:

317

42

R. Caballero, M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz

| ?- :run(’Work’). Compiling... QDom: ’u,w’. Prox: ’Work’. Translating to QCLP... Translating to CLP... Generating code... Done. Loaded. yes and now everything is ready to execute goals for the program loaded. 5.2.3 Executing SQCLP-Goals Recall that goals have the form A1 ]W1 , . . . , Am ]Wm 8 W1 Q? β1 , . . . , Wm Q? βm which in actual (S)QCLP syntax becomes: | ?- A1#W1, ..., Am#Wm :: W1 >= B1, ..., Wm >= Bm. Note the following: 1. Goals must end in a dot (.). 2. The symbol ‘8’ is replaced by ‘::’. 3. The symbol ‘Q? ’ is replaced by ‘>=’ (and this is independent of the qualification domain in use, so that it may mean ≤ in W). 4. Conditions of the form W Q? ? must be omitted, therefore A1 ]W1 , A2 ]W2 8 W1 Q? ?, W2 Q? β2 becomes “A1#W1, A2#W2 :: W2 >= B2.”, and A]W 8 W Q? ? becomes just “A#W.”.

Assuming now that we have loaded the program Work.qclp as explained before, we can execute the goal good work(king liar)]W 8 W Q? (0.5, 100): | ?- good_work(king_liar)#W::W>=(0.5,10). W = (0.6,5.0) ? yes 5.2.4 Examples

To finish this subsection, we are now showing some additional goal executions using the interpreter for (S)QCLP and the programs displayed along the paper. Peano. Consider the program Peano.qclp as displayed at the beginning of Subsection 5.2.1. Qualifications in this program are intended as a cost measure for obtaining a given number in the Peano representation, assuming that each use of the clause at line 6 requires to pay at least 1. In essence, threshold conditions will impose an upper bound over the maximum number obtainable in goals containing the atom num(X). Therefore if we ask for numbers up to a cost of 3 we get the following answers:

318

A Transformation-based Implementation for SQCLP (Preliminary Version) 43 Goal Sol1 Sol2 Sol3 Sol4

?- num(X)#W::W>=3. W = W = W = W = no

0.0, 1.0, 2.0, 3.0,

X X X X

= = = =

z ? ; s(z) ? ; s(s(z)) ? ; s(s(s(z))) ? ;

Work. Consider now the program Work.qclp and the proximity relation Work.prox, both as displayed in Subsection 5.2.1 above. In this program, qualifications behave as the conjunction of the certainty degree of the user confidence about some particular atom, and a measure of the minimum cost to pay for proving such atom. In these circumstances, we could ask—just for illustration purposes—for famous authors with a minimum certainty degree—for them being actually famous—of 0.5, and with a proof cost of no more than 30 (think of an upper bound for possible searches in different databases). Such a goal would have, in this very limited example, only the following solution: Goal Sol1

?- famous(X)#W::W>=(0.5,30). W = (0.9,1.0), X = shakespeare ? ; no

meaning that we can have a confidence of shakespeare being famous of 0.9, and that we can prove it with a cost of 1. Now, in a similar fashion we could try to obtain different works that can be considered as good works by using the last clause in the example. Limiting the search to those works that can be considered good with a qualification value better or equal to (0.5,100) produce the following result: Goal Sol1 Sol2

?- good_work(X)#W::W>=(0.5,100). W = (0.675,4.0), X = king_lear ? ; W = (0.6,5.0), X = king_liar ? ; no

It is important to remark here that the qualification value obtained for a particular computed answer is not guaranteed to be the best possible one; rather, different computed answers may compute different qualification values which can be observed by the user. This is easy to see if we try to solve a more particular goal: Goal Sol1

?- good_work(king_liar)#W::W>=(0.675,4.0). W = (0.675,4.0) ? ; no

That is, not only good work(king liar) can be proved for for W = (0.6,5.0) as shown in Sol2 above, but also with W = (0.675,4.0), which results a better qualification value (i.e. greater certainty degree and lower proof cost). Library. Finally, consider the program Ps and the proximity relation Ss , both as displayed in Figure 1 of Section 2. As it has been said when this example was introduced, the predicate guessRdrLvl takes advantage of attenuation factors to

319

44

R. Caballero, M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz

encode heuristic rules to compute reader levels on the basis of vocabulary level and other book features. As an illustration of use, consider the following goal: Goal

Sol1

Sol6

?- guessRdrLvl(book(2, ’Dune’, ’F. P. Herbert’, english, sciFi, medium, 345), Level)#W. W = 0.8, Level = intermediate ? ; ··· W = 0.7, Level = upper ? yes

Here we ask for possible ways of classifying the second book in the library according to reader levels. We obtain as valid solutions, among others, intermediate with a certainty factor of 0.8; and upper with a certainty factor of 0.7. These valid solutions show that the predicate guessRdrLvl tries with different levels for any certain book based on the heuristic implemented by the qualified clauses. To conclude, consider now the goal proposed in Section 2 for this program. For such goal we obtain: Goal Sol1

?- search(german, essay, intermediate, ID)#W::W>=0.65. W = 0.8, ID = 4 ? yes

What tells us that the forth book in the library is written in German, it can be considered to be an essay, and it is targeted for an intermediate reader level. All this with a certainty degree of at least 0.8. 5.3 Efficiency The minimum—and unavoidable—overload introduced by qualifications and proximity relations in the transformed programs manifests itself in the case of (S)QCLP programs which use the identity proximity relation and have t as the attenuation factor of all their clauses. In order to measure this overload we have made some experiments using some program samples, taken from the SICStus Prolog Benchmark that can be found in: http://www.sics.se/isl/sicstuswww/site/performance.html and we have compared the time it took to repeatedly execute a significant number of times each program in both (S)QCLP and SICStus Prolog making use of a slightly modified (to ensure a correct behavior in both systems) version of the harness also provided in the same site. From all the programs available in the aforementioned site, we selected the following four: • naivrev: naive implementation of the predicate that reverses the contents of a list. • deriv: program for symbolic derivation. • qsort: implementation of the well-known sorting algorithm Quicksort. • query: obtaining the population density of different countries.

320

A Transformation-based Implementation for SQCLP (Preliminary Version) 45 No other program could be used because they included impure features such as cuts which are not currently supported by our system. In order to adapt these Prolog programs to our setting the following modifications were required: 1. All the program clause are assumed to have t as attenuation factor. After including these attenuation factors, we obtain as results QCLP programs. More specifically we obtain two QCLP programs for each initial Prolog program, one using the qualification domain B (because this domain uses trivial constraints), and another using the qualification domain U (which uses Rconstraints). 2. We define an empty proximity relation, allowing us to obtain two additional SQCLP-programs. 3. By means of the program directive “#optimized unif” defined in Subsection 5.2.1, each SQCLP program can be also executed in this optimized mode. Therefore each original Prolog Program produces six (S)QCLP programs, denoted as Q(b), Q(u), PQ(b), PQ(u), SQ(b) and SQ(u) in Table 1. Additionally some minor modifications to the program samples have been introduced for compatibility reasons, i.e. additions using the predicate is/2 were replaced, both in the Prolog version of the benchmark and in the multiple (S)QCLP versions, by clpr constraints. In any case, all the program samples used for this benchmarks in this subsection can be found in the folder benchmarks/ of the (S)QCLP distribution. Finally, we proceeded to solve the same goals for every version of the benchmark programs, both in SICStus Prolog and in (S)QCLP. The benchmark results can be found in Table 1. All the experiments were performed in a computer with a Intel(R) Core(TM)2 Duo CPU at 2.19GHz and with 3.5 GB RAM. Table 1. Time overload factor with respect to Prolog Program naivrev deriv qsort query a b c d e f

Q(b)a

Q(u)b

PQ(b)c

PQ(u)d

SQ(b)e

SQ(u)f

1.80 1.94 1.05 1.02

10.71 10.60 1.11 1.12

4289.79 331.45 135.59 7.17

4415.11 469.67 136.98 7.13

56.22 29.63 2.51 3.80

65.75 39.32 2.83 3.88

QCLP(B, R) version (i.e. the program does not have QCLP(U , R) version (i.e. the program does not have SQCLP(Sid , B, R) version. SQCLP(Sid , U , R) version. SQCLP(Sid , B, R) version with directive #optimized SQCLP(Sid , U , R) version with directive #optimized

the #prox directive). the #prox directive). unif. unif.

The results in the table indicate the slowdown factor obtained for each version of each program. For instance, the first column indicates that the time required for evaluating the goal corresponding to the sample program naivrev in QCLP(B, R) is about 1.80 times the required time for the evaluation of the same goal in Prolog. Next we discuss the results:

321

46

R. Caballero, M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz • Influence of the qualification domain. In general the difference between the slowdown factors obtained for the two considered qualification domains is not large. However, in the case of QCLP-programs naivrev and deriv the difference increases notably. This is due to the different ratios of the B-constraints w.r.t. the program and U-constraints w.r.t. the program. It must be noticed that the transformed programs are the same in both cases, but for the implementation of qval and qbound constraints, which is more complex for U as one can see in Section 5.1. In the case of naivrev and deriv this makes a big difference because the number of computation steps directly required by the programs is much smaller than in the other cases. Thus the slowdown factor becomes noticeable for the qualification domain U in computations that requires a large number of steps. • Influence of the proximity relation. The introduction of a proximity relation, even of empty, is very significative. This is due to the introduction of the predicate ∼, which replaces Prolog unification. The situation even worsens when the computation introduces large constructor terms, as in the case of naivrev which deals with Prolog lists. The efficient Prolog unification is replaced by an explicit term decomposition. • Influence of the optimized unification. As explained at the end of Section 2 this optimization can lead to the loss of solutions in general. However, this is not the case for the chosen examples. As seen in the table, the use of the program directive #optimized unif causes a clear increase in the efficiency of goal solving for these examples. 6 Conclusions

In our recent work (Rodr´ıguez-Artalejo and Romero-D´ıaz 2010a) we extended the classical CLP scheme to a new programming scheme SQCLP whose instances SQCLP(S, D, C) were parameterized by a proximity relation S, a qualification domain D and a constraint domain C. This new scheme offered extra facilities for dealing with expert knowledge representation and flexible query answering. In this paper we have contributed to the aforementioned scheme providing, in a more practical sense, both a semantically correct transformation technique, in two steps, for transforming SQCLP programs and goals intro equivalent CLP programs and goals; and a prototype implementation on top CLP(R) systems like SICStus Prolog and SWI-Prolog of some particularly interesting instances of the scheme. The two-step transformation technique presented in Section 4 has provided us with the needed theoretical results for effectively showing how proximity relations can be reduced to qualifications and clause annotations by means of the transformation elimS ; and how qualifications and clause annotations can be reduced to classical CLP programming by means of the transformation elimD . These two transformations altogether, ultimately enables the use of the classical mechanism of SLD resolution to obtain computed answers for SQCLP goals w.r.t SQCLP programs, via their equivalent CLP programs and goals and the computed answers obtained from them by any capable CLP goal solving procedure.

322

A Transformation-based Implementation for SQCLP (Preliminary Version) 47 The prototype implementation presented in Section 5 has finally allowed us to execute all the examples showed in this paper—and in previous ones—, and a series of benchmarks for measuring the overload actually introduced by proximity relations—or by similarity relations—and by clause annotations and qualifications. While we are aware that the prototype implementation presented in this paper has to be considered a research application (and as such, we have to admit that it cannot be used for industrial applications), we think that it can contribute to the field as a quite complete implementation of an extension of the CLP(R) scheme with proximity relations and qualifications. Some related implementation techniques and systems have been cited in the introduction. However, as far as we know, no other implementation in this field has ever provided support for proximity (and similarity) relations, qualifications via clause annotations and CLP(R) style programming. Moreover, our results in Section 4 on the semantic correctness of our implementation technique are in our opinion another contribution of this paper which has no counterpart in related approaches. In the future, and taking advantage of the prototype system we have already developed, we plan to investigate possible applications which can profit from proximity relations and qualifications, such as in the area of flexible query answering. In particular, we plan to investigate application related to flexible answering of queries to XML documents, in the line of (Campi et al. 2009) and other related papers. As support for practical applications, we also plan to increase the repertoire of constraint and qualification domains which can be used in the (S)QCLP prototype, adding the constraint domain FD and the qualification domain Wd defined in Section 2.2.3 of (Rodr´ıguez-Artalejo and Romero-D´ıaz 2010b). On a more theoretical line, other possible lines of future work include: a) extension of the SLD(D) resolution procedure presented in (Rodr´ıguez-Artalejo and Romero-D´ıaz 2008) to a SQCLP goal solving procedure able to work with constraints and a proximity relation; b) investigation of the conjecture stated at the end of Section 2; and c) extension of the QCFLP (qualified constraint functional logic programming) scheme in (Caballero et al. 2009) to work with a proximity relation and higher-order functions, as well as the implementation of the resulting scheme in the CFLP(C)-system Toy (Arenas et al. 2007). References Apt, K. R. 1990. Logic programming. In Handbook of Theoretical Computer Science, J. van Leeuwen, Ed. Vol. B: Formal Models and Semantics. Elsevier and The MIT Press, 493–574. Arcelli, F. and Formato, F. 1999. Likelog: a logic programming language for flexible data retrieval. In Proceedings of the 1999 ACM Symposium on Applied computing (SAC’99). ACM Press, New York, NY, USA, 260–267. Arcelli Fontana, F. 2002. Likelog for flexible query answering. Soft Computing 7, 107–114. ´ ndez, A. J., Gil, A., Lo ´ pez-Fraguas, F. J., Rodr´ıguez-Artalejo, Arenas, P., Ferna ´ enz-Pe ´rez, F. 2007. T OY, a multiparadigm declarative language. version M., and Sa 2.3.1. R. Caballero and J. S´ anchez (Eds.), Available at http://toy.sourceforge.net.

323

48

R. Caballero, M. Rodr´ıguez-Artalejo and C. A. Romero-D´ıaz

Baader, F. and Nipkow, T. 1998. Term Rewriting and All That. Cambridge University Press. Baldwin, J. F., Martin, T., and Pilsworth, B. 1995. Fril-Fuzzy and Evidential Reasoning in Artificial Intelligence. John Wiley & Sons. Bistarelli, S., Montanari, U., and Rossi, F. 2001. Semiring-based constraint logic programming: Syntax and semantics. ACM Transactions on Programming Languages and Systems 3, 1 (January), 1–29. Caballero, R., Rodr´ıguez-Artalejo, M., and Romero-D´ıaz, C. A. 2008. Similaritybased reasoning in qualified logic programming. In PPDP ’08: Proceedings of the 10th international ACM SIGPLAN conference on Principles and Practice of Declarative Programming. ACM, Valencia, Spain, 185–194. Caballero, R., Rodr´ıguez-Artalejo, M., and Romero-D´ıaz, C. A. 2009. Qualified computations in functional logic programming. In Logic Programming (ICLP’09), P. Hill and D. Warren, Eds. LNCS, vol. 5649. Springer-Verlag Berlin Heidelberg, Pasadena, CA, USA, 449–463. Campi, A., Damiani, E., Guinea, S., Marrara, S., Pasi, G., and Spoletini, P. 2009. A fuzzy extension of the XPath query language. Journal of Intelligent Information Systems 33, 3 (December), 285–305. Dubois, D. and Prade, H. 1980. Fuzzy Sets and Systems: Theory and Applications. Academic Press, New York, NY, USA. Freuder, E. C. and Wallace, R. J. 1992. Partial constraint satisfaction. Artificial Intelligence 58, 1–3, 21–70. Georget, Y. and Codognet, P. 1998. Compiling semiring-based constraints with CLP(FD,S). In Proceedings of the 4th International Conference on Principles and Practice of Constraint Programming. LNCS, vol. 1520. Springer-Verlag, 205–219. ˜ oz, S., and Vaucheret, C. 2004. Fuzzy prolog: A new approach Guadarrama, S., Mun using soft constraint propagation. Fuzzy Sets and Systems 144, 1, 127–150. ´ jek, P. 1998. Metamathematics of Fuzzy Logic. Dordrecht: Kluwer. Ha ¨ hfeld, M. and Smolka, G. 1988. Definite relations over constraint languages. Tech. Ho Rep. LILOG Report 53, IBM Deutschland. Ishizuka, M. and Kanai, N. 1985. Prolog-ELF incorporating fuzzy logic. In Proceedings of the 9th International Joint Conference on Artificial Intelligence (IJCAI’85), A. K. Joshi, Ed. Morgan Kaufmann, Los Angeles, CA, USA, 701–703. Jaffar, J. and Lassez, J. L. 1987. Constraint logic programming. In Proceedings of the 14th ACM SIGACT-SIGPLAN symposium on Principles of Programming Languages (POPL’87). ACM New York, NY, USA, Munich, West Germany, 111–119. Jaffar, J., Maher, M., Marriott, K., and Stuckey, P. J. 1998. Semantics of constraints logic programs. Journal of Logic Programming 37, 1-3, 1–46. ´ n, R., Moreno, G., and Penabad, J. 2009. An improved reductant calculus using Julia fuzzy partial evaluation techniques. Fuzzy Sets and Systems 160, 2, 162–181. ´ n-Iranzo, P., Rubio, C., and Gallardo, J. 2009. Bousi∼Prolog: a prolog extenJulia sion language for flexible query answering. In Proceedings of the Eighth Spanish Conference on Programming and Computer Languages (PROLE 2008), J. M. AlmendrosJim´enez, Ed. ENTCS, vol. 248. Elsevier, Gij´ on, Spain, 131–147. ´ n-Iranzo, P. and Rubio-Manzano, C. 2009a. A declarative semantics for Julia Bousi∼Prolog. In PPDP’09: Proceedings of the 11th ACM SIGPLAN conference on Principles and practice of declarative programming. ACM, Coimbra, Portugal, 149–160. ´ n-Iranzo, P. and Rubio-Manzano, C. 2009b. A similarity-based WAM for Julia Bousi∼Prolog. In Bio-Inspired Systems: Computational and Ambient Intelligence (IWANN 2009). LNCS, vol. 5517. Springer Berlin / Heidelberg, Salamanca, Spain, 245– 252.

324

A Transformation-based Implementation for SQCLP (Preliminary Version) 49 Kifer, M. and Subrahmanian, V. S. 1992. Theory of generalized annotated logic programs and their applications. Journal of Logic Programming 12, 3&4, 335–367. Lee, R. C. T. 1972. Fuzzy logic and the resolution principle. Journal of the Association for Computing Machinery (ACM) 19, 1 (January), 109–119. Li, D. and Liu, D. 1990. A Fuzzy Prolog Database System. John Wiley & Sons. Lloyd, J. W. 1987. Foundations of Logic Programming, Second Edition. Springer. Loia, V., Senatore, S., and Sessa, M. I. 2004. Similarity-based SLD resolution and its role for web knowledge discovery. Fuzzy Sets and Systems 144, 1, 151–171. ´ˇ Medina, J., Ojeda-Aciego, M., and Vojta s, P. 2001a. Multi-adjoint logic programming with continuous semantics. In Logic Programming and Non-Monotonic Reasoning (LPNMR’01), T. Eiter, W. Faber, and M. Truszczyinski, Eds. LNAI, vol. 2173. SpringerVerlag, 351–364. ´ˇ Medina, J., Ojeda-Aciego, M., and Vojta s, P. 2001b. A procedural semantics for multi-adjoint logic programming. In Progress in Artificial Intelligence (EPIA’01), P. Brazdil and A. Jorge, Eds. LNAI, vol. 2258. Springer-Verlag, 290–297. ´ˇ Medina, J., Ojeda-Aciego, M., and Vojta s, P. 2004. Similarity-based unification: a multi-adjoint approach. Fuzzy Sets and Systems 146, 43–62. Riezler, S. 1998. Probabilistic constraint logic programming. Ph.D. thesis, Neuphilologischen Fakult¨ at del Universit¨ at T¨ ubingen. Rodr´ıguez-Artalejo, M. and Romero-D´ıaz, C. A. 2008. Quantitative logic programming revisited. In Functional and Logic Programming (FLOPS’08), J. Garrigue and M. Hermenegildo, Eds. LNCS, vol. 4989. Springer-Verlag, Ise, Japan, 272–288. Rodr´ıguez-Artalejo, M. and Romero-D´ıaz, C. A. 2010a. A declarative semantics for CLP with qualification and proximity. Theory and Practice of Logic Programming, 26th Int’l. Conference on Logic Programming (ICLP’10) Special Issue 10, 4–6, 627–642. Rodr´ıguez-Artalejo, M. and Romero-D´ıaz, C. A. 2010b. Fixpoint & Proof-theoretic Semantics for CLP with Qualification and Proximity. Tech. Rep. SIC-1-10, Universidad Complutense, Departamento de Sistemas Inform´ aticos y Computaci´ on, Madrid, Spain. Sessa, M. I. 2001. Translations and similarity-based logic programming. Soft Computing 5, 2. Sessa, M. I. 2002. Approximate reasoning by similarity-based SLD resolution. Theoretical Computer Science 275, 1-2, 389–426. van Emden, M. H. 1986. Quantitative deduction and its fixpoint theory. Journal of Logic Programming 3, 1, 37–53. ´ˇ Vojta s, P. 2001. Fuzzy logic programming. Fuzzy Sets and Systems 124, 361–370. Zadeh, L. A. 1965. Fuzzy sets. Information and Control 8, 3, 338–353. Zadeh, L. A. 1971. Similarity relations and fuzzy orderings. Information Sciences 3, 2, 177–200.

325

Loading...

universidad complutense de madrid programación declarativa

UNIVERSIDAD COMPLUTENSE DE MADRID FACULTAD DE INFORMÁTICA Departamento de Sistemas Informáticos y Computación PROGRAMACIÓN DECLARATIVA CUALIFICADA CO...

4MB Sizes 1 Downloads 0 Views

Recommend Documents

UNIVERSIDAD COMPLUTENSE DE MADRID - E-Prints Complutense
84; Manuel Fernández del Riesgo, La ambigüedad social de la religión, Editorial Verbo. Divino, Estrella (Navarra), 19

UNIVERSIDAD COMPLUTENSE DE MADRID - E-Prints Complutense
“Cuando emprendas el viaje hacia Ítaca, ruega que tu camino sea largo y rico en ... interminables de día y de noche,

universidad complutense de madrid - Core
25. PRESENTACIÓN DE LA MEMORIA. La presente memoria titulada “TITULO” se enmarca dentro de las líneas de investiga

universidad complutense de madrid - Core
El concepto de tiempo se estructura, por tanto, como un objeto en movimiento hacia nosotros (“el tiempo ...... En lugar

Teotihuacan - Universidad Complutense de Madrid
un ambicioso plan de estudio de toda la ciudad con base a un exhaustivo registro de la superficie del .... construyó en

universidad complutense de madrid - Core
Resistencia anaeróbica. Resistencia aeróbica,. Resistencia muscular. UTILIZACIÓN. Actividades intensas y breves. Activid

universidad complutense de madrid - CSIC
Ángeles, con la que llevo desde el principio y a la que he visto doctorarse, casarse y ahora ser mamá,... cómo pasa e

UNIVERSIDAD COMPLUTENSE DE MADRID - E-Prints Complutense
pudiera aclarar en el caso de la hemoncosis el papel de los eosinófilos y su relación con la infestación y la resiste

UNIVERSIDAD COMPLUTENSE DE MADRID - E-Prints Complutense
Dª María Isabel García Real, Profesor Contratado Doctor del Departamento de. Medicina y Cirugía Animal de la Univers

UNIVERSIDAD COMPLUTENSE DE MADRID - E-Prints Complutense
sexo, de 3.4 veces en hombres y 4.6 veces en mujeres (Sarasa-Renedo, 2014). 1.1.Definición. Para la CIE-10 (WHO, 1992),