Preface

Welcome to B-Prolog, a versatile and efficient constraint logic programming (CLP) system. B-Prolog is being brought to you by Afany Software.

The birth of CLP is a milestone in the history of programming languages. CLP combines two declarative programming paradigms: logic programming and constraint solving. The declarative nature has proven appealing in numerous applications, including computer-aided design and verification, databases, software engineering, optimization, configuration, graphical user interfaces, and language processing. It greatly enhances the productivity of software development and software maintainability. In addition, because of the availability of efficient constraint-solving, memory management, and compilation techniques, CLP programs can be more efficient than their counterparts that are written in procedural languages.

B-Prolog is a Prolog system with extensions for programming concurrency, constraints, and interactive graphics. The system is based on a significantly refined WAM [1], called TOAM Jr. [19] (a successor of TOAM [16]), which facilitates software emulation. In addition to a TOAM emulator with a garbage collector that is written in C, the system consists of a compiler and an interpreter that are written in Prolog, and a library of built-in predicates that are written in C and in Prolog. B-Prolog does not only accept standard-form Prolog programs, but also accepts matching clauses, in which the determinacy and input/output unifications are explicitly denoted. Matching clauses are compiled into more compact and faster code than standard-form clauses. The compiler and most of the libraries are written in matching clauses. The reader is referred to [19] for a detailed survey of the language features and implementation techniques of B-Prolog.

B-Prolog follows the standard of Prolog, and also enjoys several features that are not available in traditional Prolog systems. B-Prolog provides an interactive environment through which users can consult, list, compile, load, debug, and run programs. The command editor in the environment facilitates recalling and editing old commands. B-Prolog provides a bi-directional interface with C and Java. This interface makes it possible to integrate Prolog with C, C++, and Java. B-Prolog offers a language, called AR (action rules), which is useful for programming concurrency, implementing constraint propagators, and developing interactive user interfaces. AR has been successfully used to implement constraint solvers over trees, Boolean domains, finite-domains, and sets. B-Prolog provides a state-of-the-art implementation of tabling, which is useful for developing dynamic programming solutions for certain applications, such as parsing, combinatorial search and optimization, theorem proving, model checking, deductive databases, and data mining. B-Prolog also provides a high-level and constraint-based graphics library, called CGLIB.0.1 The library includes primitives for creating and manipulating graphical objects. CGLIB also includes a set of constraints that facilitates the specification of objects' layouts. AR is used to program interactions. B-Prolog has been enhanced with the array subscript notation for accessing compound terms and declarative loop constructs for describing repetitions. Recently, a common interface to SAT and mathematical programming (MP) solvers has been added into B-Prolog. With this interface and the existing language constructs, B-Prolog can serve as a powerful modeling language for SAT and MP solvers.

This document explains how to use the B-Prolog system. It consists of two parts.



Part-I: Prolog Programming
This part covers the B-Prolog programming environment and all of the built-ins that are available in B-Prolog. Considerable efforts have been made in order to make B-Prolog compliant with the standard. All of the possible discrepancies are explicitly described in this manual. In addition to the built-ins in the standard, B-Prolog also supports the built-ins in Dec-10 Prolog. Furthermore, B-Prolog supports some new built-ins, including built-ins for arrays and hashtables.

The part about the standard Prolog is kept as compact as possible. The reader is referred to The Prolog Standard for the details about the built-ins in the standard, and is referred to textbooks [2,3,8,10] and online materials for the basics of Prolog.



Part-II: Agent and Constraint Programming
Prolog adopts a static computation rule that selects subgoals strictly from left to right. Subgoals cannot be delayed, and subgoals cannot be responsive to events. Prolog-II provides a predicate called freeze [4]. The subgoal freeze(X,p(X)) is logically equivalent to p(X), but the execution of p(X) is delayed until X is instantiated. B-Prolog provides a more powerful language, called AR, for programming agents. An agent is a subgoal that can be delayed, and that can later be activated by events. Each time that an agent is activated, some actions may be executed. Agents are a more general notion than freeze in Prolog-II and processes in concurrent logic programming, in the sense that agents can be responsive to various kinds of events, including user-defined events.

A constraint is a relation among variables over some domains. B-Prolog supports constraints over trees, finite-domains, Boolean domains, and finite sets. In B-Prolog, constraint propagation is used to solve constraints. Each constraint is compiled into one or more agents, called constraint propagators, that are responsible for maintaining the consistency of the constraint. A constraint propagator is activated when the domain of any variable in the constraint is updated.

AR is a powerful and efficient language for programming constraint propagators, concurrent agents, event handlers, and interactive user interfaces. AR is unique to B-Prolog, and is thus described in detail in the manual.

A separate chapter is devoted to the common interface to SAT and MP solvers. The interface comprises primitives for creating decision variables, specifying constraints, and invoking a solver, possibly with an objective function to be optimized. This chapter includes several examples that illustrate the modeling power of B-Prolog for SAT and MP solvers.

Neng-Fa Zhou 2013-01-25