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, database, software engineering, optimization, configuration, graphical user interface, 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 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. [18] (a successor of TOAM [15]), which facilitates software emulation. In addition to a TOAM emulator with a garbage collector written in C, the system consists of a compiler and an interpreter written in Prolog, and a library of built-in predicates written in C and Prolog. B-Prolog accepts not only standard form Prolog programs but also matching clauses in which the determinacy and input/output unifications are denoted explicitly. 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 [18] for a detailed survey of the language features and implementation techniques of B-Prolog.

B-Prolog follows the standard of Prolog but 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 you 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, finite-domains, and sets. B-Prolog provides a state-of-the-art implementation of tabling, which is useful 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 and a set of constraints that facilitates the specification of layouts of objects. 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 LP/MIP solvers.

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



Part-I: Prolog Programming
This part covers the B-Prolog programming environment and all the built-ins available in B-Prolog. Considerable efforts have been made to make B-Prolog compliant with the standard. All 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 and some new ones such as those on arrays and hashtables.

This part on 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 to textbooks [2,3,8,9] 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. No subgoals can be delayed and no subgoals can 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 can be later activated by events. Each time 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 ones.

A constraint is a relation among variables over some domains. B-Prolog supports constraints over trees, finite-domains, Boolean, 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 a powerful and efficient language for programming constraint propagators, concurrent agents, event handlers, and interactive user interfaces. AR is unique to B-Prolog and are thus described in detail in the manual.

A separate chapter is devoted to the common interface to SAT and LP/MIP 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 LP/MIP solvers.

Neng-Fa Zhou 2012-11-23