Implementing Parameterized Type Algorithm

0 downloads 0 Views 219KB Size Report
The paper also discusses run time efficiency aspects ... successively: Scratchpad [6], Axiom, A# [11], Aldor. Symbolic ... computation, sorting & merging algorithms in various forms ..... within computation systems take into account the impact of ...
Implementing Parameterized Type Algorithm Definitions in Mathematica Alina Andreica ICT Department, “Babeş-Bolyai” University Cluj-Napoca, Romania [email protected]

Abstract The paper focuses on means of defining parameterized type categories and algorithms built on such types in Mathematica. Symbolic algorithms based on category theory have the advantage of systematically dealing with domains, categories, operators over them by creating general contexts of expressing algorithms, which can be applied by parameterizing them with various domains, using the same algorithm definition. While similar approaches have been previously presented by the author, the present paper aims at a stronger focus on algorithm characteristics defined on categorical principles and giving a more general framework for implementing Mathematica algorithms based on generic principles and category theory. The paper also discusses run time efficiency aspects for these generic implementations. Keywords: category theory, parameterized type definitions, generic algorithms in symbolic computation AMS Subject Classification: 68Q40

1. Defining the working framework The category theory in symbolic computation and the tools for implementing it, such as type based symbolic computation systems or functorial facilities, are powerful tools for building systematic solutions in various areas of computer science and software design. This statement is sustained by the fact that category theory in symbolic computation introduces techniques for implementing general working contexts of performing symbolic algorithms. The defined categories can later be particularized for various domains, by elegantly using the same definition. Definitions for categories and domains, from the symbolic point of view, can be found in [1]. Early researches based on applying type category principles in designing symbolic computations systems

and languages appeared in the ’80 [9] and evolved successively: Scratchpad [6], Axiom, A# [11], Aldor. Symbolic implementations of category theory have been developed in two main directions: a constructive manner [7] and in a systematic logical approach [5], which enables the definition of categories, domains, operators and their properties in a way that is suitable for automatic proving. In this respect, in Theorema [10], B. Buchberger uses currying and modules for implementing domains, categories and functors. Functors have supplemental advantages, since their syntax, condensing their essence, is very useful in proving [5]. Another topic in the field that has important practical advantages regards extending classical symbolic computation systems with a type system that would enable working over systematically defined domains and categories (on the above described principles). In [1] we present such an extension of Mathematica with a system of algebraic structures, from which multivariate polynomial domains are derived in a categorical parameterized manner and applied in computing Groebner basis for polynomials over various coefficient domains The present paper is more systematically oriented on applying generic principles in constructing categorical based implementations. In this respect, we shall define a set category and an ordered set category and study the impact that the insertion of such a generic layer has on the implementation presented in [1] As one of the basic algorithms in symbolic computation, sorting & merging algorithms in various forms, including categorical approaches are extensively studied. In [4] they appear as a case study for algorithm synthesis and automatic proving. We consider that generic design of algorithms is very important for systematic algorithmic definition based on category theory principles. The present paper tackles the impact of generic definitions in symbolic computation algorithms.

2. Defining a Hierarchy of Parameterized Categories in Mathematica Aiming at implementing a systematic hierarchy of parameterized categories in Mathematica, in an object oriented style, we start by defining the Set category and the OrderedSet category. The Set and OrderedSet categories are parameterized with the domain of elements and define their specific operators (which can be redefined if necessary in descendant domains). Inheritance is modelled by explicit call of the inherited context / category in the current one; therefore, inherited operators can be used either with their previous definition, or overloaded / redefined in the current context. Algorithm implementations will be parameterized with the definition domain, being therefore applicable in the same generic manner for each parameter domain, while operator overloading can be applied if necessary at any level (operators can be added or overwritten for parameter domains according to their role, in an object oriented style). Algorithms are presented in pseudocode below. We intend to use the sorting and merging algorithms defined within the OrderedSet category for various domains, in a parameterized style, and to compare the efficiency of these definitions as a consequence of introducing more inheritance levels in algorithm definitions. On the other hand, the programming advantage of using the same categorical definition is very obvious in respect with the programming style, code reuse and implementation flexibility: in a straightforward implementation, distinct definitions of algorithms should be implemented for each domain. Contextual_module SetCat[S:Symbol; D:Symbol] //defines the set S over domain D //(with elements in domain D) SD:=SD U {S} //set of symbols for the defined set categories ∀ expr s∈D, Canonic[s:SymbolList]:=disjoint list of symbols in lexicographical ordering; // canonical representation in S ∀ a,b∈S, S["=",a,b]:= Module[ n1,n2,i : Integer; eq:Boolean; eq=True; //verifies set equality a_can=Canonic[a]; b_can=Canonic[b]; n1=Length[a_can; n2=Length[b_can]; If (n1n2) Return False; Else For (i=1; inr) rel=1; If (rel==0 && n2>nr) rel=-1; Return rel ; ] ∀ a,b∈S, S["", a, b] or S["=",a,b]; S["sort", L:list] :=Module[ {i,j,n:Integer; aux:Symbol; li:List}, n=Length[L]; li=L; for (i=0;i=0; S["Max"]:="zzzzzzzzzzz"; ];

The above described categorical definitions are implemented in Mathematica package dom.m

2.2 Defining Polynomial Domains Aiming at comparing design and run-time algorithm characteristics, we define a Polynomial category using the implementation in [1] and a new implementation, which introduces another generic layer, that has been the previously described in OrderedSet category. This implementation uses the generic merging algorithm in computing the polynomial sum and the generic sorting in constructing the polynomial canonical form. The coefficient domain and the exponent vector domain are given as parameters for the polynomial category definition in both implementations, while both implementations represent a polynomial as a pair containing the list of coefficients and the list of exponent vectors (see [1]). The exponent vector domain uses list representation on elements. We compare below the most relevant parts in designing the two Mathematica implementations:

Implementation 1 [1] – vectexp.m, polinom.m packages Definition of Exponent vector domain VectExp[V_,lv_List]:=Module[... V["+",l1_List,l2_List]:=l1+l2; V["-",l1_List,l2_List]:=l1-l2;

...]

Definition of Polynomial domains: Polynom[Pol_,DCoef_,DVect_,basis_List]=Module[ … InelCom[DCoef,"+","*"]; (*abelian ring *) VectExp[DVect,basis]; ... Pol["+",P1_,P2_]:= Module[{n1,n2,i,j,k,v1,v2,Rez}, (* returns polynomial sum of P1, P2 *) n1=Pol["Nr",P1]; n2=Pol["Nr",P2]; Rez=Pol["Init"]; For[i=1;j=1;k=1, k