NP-SPEC: an executable specification language for solving all problems in NP

https://doi.org/10.1016/S0096-0551(01)00010-8Get rights and content

Abstract

In this paper a logic-based specification language, called NP-SPEC, is presented. The language is obtained by extending DATALOG through allowing a limited use of some second-order predicates of predefined form. NP-SPEC programs specify solutions to problems in a very abstract and concise way, and are executable. In the present prototype they are compiled to PROLOG code, which is run to construct outputs. Second-order predicates of suitable form allow to limit the size of search spaces in order to obtain reasonably efficient construction of problem solutions. NP-SPEC expressive power is precisely characterized as to express exactly the problems in the class NP. The specification of several combinatorial problems in NP-SPEC is shown, and the efficiency of the generated programs is evaluated.

Introduction

The definition and the implementation of logic-based languages allowing for specifying complex problems have recently received much attention in the research community (cf., e.g., [3], [4], [5], [6], [7]). The main features of such languages are:

  • they are highly declarative, and, as such, they are easier to use and simplify the error-prone process of writing algorithms;

  • they are executable, so that the defined specification can be actually run and thus constitutes a rapid prototype.

.

General logic-based languages that, being Turing-complete, allow for an unrestricted specification capability are proposed in, e.g., [5], [6]. Clearly, such languages are fairly complex, and this may be an obstacle for their use (cf., e.g., [8], where the difficulties arising with handling formal specifications is pointed out as a main factor in the limited use of formal methods in software development).

In this paper we follow a different direction, and propose a language with limited expressiveness. In particular, we define NP-SPEC, which is a highly declarative executable language, which allows the user to specify exactly all problems which belong to the complexity class NP in a simple way. This restriction has two advantages:

  • the language is simpler, and easier to learn;

  • a more focused strategy in the search for a solution is possible, thus leading to more efficient programs.

.

Like in [3], [4], we opt for a DATALOG-like, i.e., PROLOG with no function symbols, syntax. Basically, logical formulae are rules, hence they are more restricted than in general predicate logic. The main difference between NP-SPEC and the other languages relies in its semantics, which is based on the notion of model minimality. The different semantics makes negation in the body of rules not necessary—though permitted—thus allowing for simpler specifications.

We show an example of an NP-SPEC specification, which helps us to highlight the main aspects of the language. The example concerns the famous “3-coloring” problem, which is well known to be NP-complete (cf. e.g., [9, problem GT4, p. 191]), and is formally defined as follows:

In NP-SPEC, the user can make the following declarations, which specify both an instance (in the DATABASE section) and the question (in the SPECIFICATION section). In this case, the instance is a graph with six nodes and seven edges, which is 3-colorable.

In the current implementation of NP-SPEC, processing the above specification gives as output an ECLiPSe, i.e., PROLOG, program. Running the ECLiPSe program produces the following output, which represents the colors to be assigned to the nodes so that the input graph is 3-colored.

NP-SPEC is a DATALOG-like language. In particular:

  • the clauses in the DATABASE section specify a set of facts, i.e., function-free ground atomic first-order formulas, that define the instance;

  • rules in the SPECIFICATION section are universally quantified function-free definite clauses, that specify the solution of the problem.

.

The main difference between NP-SPEC and DATALOG is the possibility of using second-order logic in a restricted way. Referring to the above example, the clause Partition(node,coloring,3) has the following meaning:

  • The predicate coloring, which does not occur in the database section, is implicitly declared to have arity 2, i.e., the arity of domain node plus 1.

  • The extension of coloring can be any set of the following kind:

{〈n,c〉|nisintheextensionofnode,c∈{1,2,3}}.

The intuitive meaning of the SPECIFICATION section is: the instance has no solution if for all possible extensions of coloring, there are nodes X and Y such that:

  • X and Y are connected by an edge (cf. atom edge(X,Y)), and

  • X and Y are colored with the same color C (cf. atoms coloring(X,C), coloring(Y,C)).

.

In other words, an extension of coloring which makes fail true does not correspond to a solution.

The execution of the specification is such that as soon as the program finds an extension of coloring that does not make fail true, it outputs such an extension, or, at the request of the user, all extensions of this kind.

More precisely, in general, a specification in NP-SPEC has the following structure:

The main distinctive features of NP-SPEC are the following:

  • It has a completely defined semantics, which is based on an extension of DATALOG known as DATALOGCIRC, defined in [10].

  • It has a precise connotation in terms of expressive power and computational complexity. In particular, it can specify exactly all problems in the complexity class NP.

  • It offers a set of metapredicates, called tailoring predicates, which guide the system in the synthesis of algorithms that operate on search spaces of limited size so as to be reasonably efficient.

.

The language NP-SPEC is meant to be simple to use and to propose intuitive and concise specifications. Our approach is meant to lift the abstraction level at which the problem must be specified for the system to be able to generate automatically the code. The user is allowed to take the decisions at such an abstract level, and her/his decisions have an impact in the generated program in a transparent way.

In the rest of the paper, we outline the main technical aspects of NP-SPEC: syntax, semantics, and computational properties. We also briefly address the current prototype and its performances, report more specification examples, and discuss related work.

Section snippets

Preliminaries

In this section we recall some notions about complexity and expressiveness that will be useful in the following. The interested reader is referred to [11], [12]. Also, we recall the definition of DATALOGCIRC [10], the language upon which the semantics of NP-SPEC relies.

Basic NP-SPEC

In this section we introduce the basic language fragment of NP-SPEC, define its semantics in terms of a translation into a DATALOGCIRC specification, and prove that it has the same expressive power of the latter language. NP-SPEC extensions are discussed in the next section.

Full NP-SPEC

This section is devoted to show some more advanced features of NP-SPEC. Such features, which are a suitable set of built-in metapredicates called tailoring predicates and a set of arithmetical and aggregation operators, have been designed with the following three goals in mind:

  • 1.

    allowing the user to specify a problem in a more natural way;

  • 2.

    allowing the user to specify the search space in a way so as to help the interpreter generate an efficient code;

  • 3.

    not exceeding NP as the data complexity.

As for

Specification examples

In this section we illustrate the specification in NP-SPEC of three classical NP-complete problems, namely Integer knapsack, Subset sum, and Hamiltonian circuit [9]. These examples show the use of various features of NP-SPEC and highlight the simplicity and compactness of specifications in NP-SPEC. We conclude the section showing a more complex example of a practical problem of university course timetabling [19].

Apart from those presented here, we have been able to specify in NP-SPEC a number

The NP-SPEC compiler

NP-SPEC has been implemented in a system prototype, whose structure is shown in Fig. 3. The prototype system is written in Gnu C. The NP-SPEC compiler was developed using FLex and Bison. In the present prototype release, both the specification and the database section of NP-SPEC specifications are written in text files.

The compiler takes two files, one containing the specification section, and another containing the database section of a NP-SPEC program and merges them with a

Considerations on performance

The current version of the system is meant only for developing executable specifications, and not for effective program synthesis. Therefore, in this work we mostly focus on the language design and semantics rather than on the efficiency of the generated programs. Recently, some of the authors designed a new strategy, based on translating a specification into a SAT instance [22].

Nevertheless, we believe that an evaluation of the efficiency of the system is still useful, and it prepares the

Related work

The language NP-SPEC is similar in spirit to the system KIDS [6], which produces the concrete implementation starting from the specification written in a logic language based on set theory. The main characteristic of KIDS is the use of a “domain theory” (written in terms of a set of axioms), which guides the system in the application of a predefined set of transformation rules that lead to the synthesis of a program compliant to the specified strategy.

Similar to our proposal, KIDS makes use of

Conclusions and future work

We have presented NP-SPEC, an executable specification language for search problems, and we have shown how some classical problems can be expressed in NP-SPEC in a natural and concise way.

Differently from most specification languages in the literature, NP-SPEC has a precise characterization of its expressive power, namely the class NP. On the one hand, such expressiveness guarantees the decidability of the execution and, to a limited extent, its efficiency. On the other hand, it allows the

Acknowledgements

The first author has been in part supported by a scholarship from the Italian National Research Council (CNR) under the “Short-term mobility” program. The work has also been supported by ASI (Italian Space Agency) and MURST (Italian Ministry for University and Scientific and Technological Research) under the 40% “Interdata” project.

Marco Cadoli is currently an associate professor of Computer Engineering at the University of “La Sapienza” Rome, Italy. He holds a Laurea in computer engineering and a Ph.D. in Computer science from the University “La Sapienza”. His Ph.D. thesis has been published by Springer-Verlag in the LNAI series. His research focuses on computational aspects (algorithms, complexity, compilation, approximation, implementation, experiments, etc.) of automated deduction and data and knowledge

References (29)

  • Eiter T, Leone N, Mateis C, Pfeifer G, Scarcello F. The KR system dlv: progress report, comparisons and benchmarks....
  • I. Niemelä

    Logic programs with stable model semantics as a constraint programming paradigm

    Annals of Mathematics and Artificial Intelligence

    (1999)
  • S. Minton

    Automatic configuring constraint satisfaction programs: A case study

    Constraints

    (1996)
  • D.R. Smith

    KIDS: a semi-automatic program development system

    IEEE Transactions on Software Engineering

    (1990)
  • Cited by (24)

    • CONJURE: Automatic Generation of Constraint Models from Problem Specifications

      2022, Artificial Intelligence
      Citation Excerpt :

      MiniZinc uses a solver-dependent instance level language called FlatZinc to interact with solvers. The NP-Spec language [119] allows the specification of NP-complete problems in a subset of existential second order logic. It provides a small number of high level domains, sets and partitions of integers, which are automatically refined into decision variables with simpler domains.

    • Compiling problem specifications into SAT

      2005, Artificial Intelligence
    • A hybrid encoding of CSP to SAT integrating order and log encodings

      2016, Proceedings - International Conference on Tools with Artificial Intelligence, ICTAI
    View all citing articles on Scopus

    Marco Cadoli is currently an associate professor of Computer Engineering at the University of “La Sapienza” Rome, Italy. He holds a Laurea in computer engineering and a Ph.D. in Computer science from the University “La Sapienza”. His Ph.D. thesis has been published by Springer-Verlag in the LNAI series. His research focuses on computational aspects (algorithms, complexity, compilation, approximation, implementation, experiments, etc.) of automated deduction and data and knowledge representation, and on software engineering. In 1999 he received the “Artificial Intelligence” award from the Italian AI Association. He has served on the Program Committee of several AI and database conferences, such as AAAI, ECAI, KR, and ICDT. He is coauthor of books on object-oriented analysis and design, and C++ programming.

    Giovambattista Ianni graduated in Computer Science Engineering in 1998. Since 1999 he is a Ph.D. student in Systems and Computer Science Engineering at DEIS, Università della Calabria, Italy. Since 2001 he owns a research scholarship in Computer Science at Mathematics Department, Università della Calabria, Italy. His research interests are on database theory and applications, data and web mining and knowledge representation.

    Luigi Palopoli was a member of the research division at CRAI (Rende, Italy) from 1988 to 1991. From 1991 to 2000 he was assistant and associate professor of Computer Science at DEIS, Università della Calabria, Italy. Currently he is professor of Computer Science at DIMET, Università “Mediterranea” di Reggio Calabria, Italy. His research interests are on database theory and applications, distributed information systems, data warehousing, data mining and knowledge representation. Prof. Palopoli authored more than eighty papers that appeared in international journals and conference proceedings. He serves in the editorial board of AI Communications.

    Andrea Schaerf received his Ph.D. in Computer Science from University of Rome “La Sapienza” (Italy) in 1994. During his studies, he spent one year at Stanford University. After graduating, he was supported for one year by a scholarship from CNR (Italian research council) at the University of Rome “La Sapienza”. Successively, he spent one year at CWI in Amsterdam under the supervision of prof. Krzysztof R. Apt, supported by a fellowship from ERCIM (European Research Consortium for Informatics and Mathematics). From 1996 to 1998 he has been Assistant Professor at the University of Rome “La Sapienza”. Starting November 1998 he is Associate Professor at the University of Udine (Italy). His main research interests are in the solution of scheduling problems using local search and constraint programming, and in the design of constraint programming languages and specification tools for combinatorial problems.

    View full text