On orthogonal specialization in C + + Dealing with efficiency and algebraic abstraction in Vaucanson

The Vaucanson library works on weighted finite state machines in an algebraic framework. As computing tools, FSMs must provide efficient services. Yet, abstraction is needed to obtain genericity but also to define properly what objects we are working on. Even if parameterized classes are a known solution to this problem, the different kinds of algorithm specializations are limited when using usual template techniques. This paper describes a new design pattern called ELEMENTwhich enables the orthogonal specialization of generic algorithmsw.r. t. the algebraic concept and w.r. t. the implementation. The idea is to make concept and implementation explicitly usable as object instances. First, we show how it solves the specialization problem. Then, we detail its implementation and how we deal with some technical pitfalls. Vaucanson is a C++ generic library for weighted finite state machine manipulation. For the sake of generality, in Vaucanson FSMs are defined using algebraic structures such as alphabet (for the letters), free monoid (for the words), semiring (for the weights) and series (mapping fromwords to weights) [5]. As usual, the challenge is tomaintain efficiencywhile providing a high-level layer for the writing of generic algorithms. One of the particularities of FSMmanipulation is the need for a fine grained specialization power on an object which is both an algebraic concept and an intensive computing machine. Vaucanson is the core of a project initiated in 2001 by Jacques Sakarovitch of the École Nationale Supérieure des Télécommunications (ENST, Paris). The project is now a collaborative work between the ENST and the École Pour l’Informatique et les Techniques Avancées (EPITA, Paris). 1 Algorithms for weighted finite state machines 1.1 Two points of view On the one hand, the mathematical aspect of automata requires the definition of a precise context. Indeed, an algorithm must specify on what kind of semiring or alphabet it works. A hierarchy of algebraic concepts is necessary to make their context explicit. Such a hierarchy can be found in any book about algebraic structures. On the other hand, weighted finite state machines are used to process large amount of data. In addition, algorithms on automata can have exponential complexity, so primitive operations should be as fast as possible. Efficiency cannot be sacrificed to gain the convenience of abstraction. Choosing the most relevant data structure is essential. However, many data structures exist to represent letters, alphabets, words, weights, series and automata. Furthermore, they are highly correlated since an automaton is built with series, a series is defined by words and weights, and a word by letters. Then each implementation is parameterized by some other implementations leading to something like a nest of dolls. Such implementations cannot be easily mixed in a monolithic hierarchy. Also, we want to reuse data structures from external libraries. Thus, the design problem is to unify these two points of view into the same object to enable both implementation-driven and algebraic-driven writing of algorithms. 1.2 Generic algorithms and specialization power Abstraction has lead tomany algorithmswith a general formulation. Generic programming is relevant, because general algorithms should be written once. More precisely, an algorithm can be generic w.r. t the mathematical concept and w.r. t the underlying data structure used as implementation of that concept. However, some theoretical results are restricted to a precise algebraic context. Thus, we must be able to bound the algorithm input to a particular family of concepts. Likewise, algorithms can bewritten using the properties of a particular implementation, so restriction facilities over implementation parameters must be available. The figure 1 sums up some desirable specializations.ion has lead tomany algorithmswith a general formulation. Generic programming is relevant, because general algorithms should be written once. More precisely, an algorithm can be generic w.r. t the mathematical concept and w.r. t the underlying data structure used as implementation of that concept. However, some theoretical results are restricted to a precise algebraic context. Thus, we must be able to bound the algorithm input to a particular family of concepts. Likewise, algorithms can bewritten using the properties of a particular implementation, so restriction facilities over implementation parameters must be available. The figure 1 sums up some desirable specializations.