<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta>
      <journal-title-group>
        <journal-title>Timisoara, Romania</journal-title>
      </journal-title-group>
    </journal-meta>
    <article-meta>
      <title-group>
        <article-title>CoCoA and CoCoALib: Fast Prototyping and Flexible C++ Library for Computations in Commutative Algebra</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>John Abbott</string-name>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Anna Maria Bigatti</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Dipartimento di Matematica, Universita` degli Studi di Genova, Italy, http://www.dima.unige.it/ bigatti</institution>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>Institut fu ̈ r Mathematik, Universita ̈t Kassel</institution>
          ,
          <addr-line>Kassel, Germany, http://www.dima.unige.it/ abbott</addr-line>
        </aff>
      </contrib-group>
      <pub-date>
        <year>2016</year>
      </pub-date>
      <volume>0</volume>
      <fpage>2</fpage>
      <lpage>07</lpage>
      <abstract>
        <p>-The CoCoA project began in 1987, and conducts research into Computational Commutative Algebra (from which its name comes) with particular emphasis on Gro¨bner bases of ideals in multivariate polynomial rings, and related areas. A major output of the project is the CoCoA software, including the CoCoA-5 interactive system and the CoCoALib C++ library. The software is open-source (GPL v.3), and under continual, active development. We give a summary of the features of the software likely to be relevant to the SC-Square community.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>I. INTRODUCTION</title>
    </sec>
    <sec id="sec-2">
      <title>CoCoA-5 is a well-established Computer Algebra System</title>
      <p>
        specialized in operations on polynomial ideals, and a number
of allied operations (e.g. factorization, and linear algebra).
It offers a dedicated, mathematician-friendly programming
language, and numerous functions covering many aspects of
Commutative Algebra. There is a strong emphasis on both
rigour and ease of use. For details see [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ].
      </p>
      <p>
        The mathematical core of the software is CoCoALib. It is
an open source C++ software library which has been designed
to be user-friendly, facilitating integration with other software.
The library is fully documented, and also comes with about
100 illustrative example programs (since it is often quicker
to copy and modify existing working code than write it from
scratch). For details see [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ].
      </p>
      <p>There is also a prototype “CoCoA server” giving access
to many functions via a remote-procedure-call connection.
Currently, communications to and from the server use an
OpenMath-like syntax. A more sophisticated “remote session”
communication model is envisaged, which will reduce overall
transmission costs.</p>
      <p>The CoCoA software is interesting to SC-square because
it includes a well-documented, open source C++ library
offering a good implementation of Gro¨ bner bases, polynomial
factorization, etc. The interactive system is well-suited to rapid
prototyping, while the server offers possibilities for looser
integration.</p>
    </sec>
    <sec id="sec-3">
      <title>II. THE SOFTWARE LIBRARY COCOALIB</title>
      <p>A crucial aspect of the CoCoA software is that it was
designed from the outset to be an open-source software library
(with two closely related applications being the interactive
system and the compute server). This initial decision, together
with the desire to help the software prosper, has many
implications: e.g. designing a particularly clean interface for all
functions with comprehensive documentation. This cleanliness
makes it easy to integrate CoCoALib into other software in a
trouble-free manner.</p>
      <p>Many computer algebra systems have a two-tier structure:
a compiled kernel with interpreter, and an external library
of interpretable code for more advanced functions. Our aim
with CoCoALib is different: we plan to have all functions
implemented directly in the C++ library so that all features
are available to programs which link to CoCoALib.</p>
      <p>CoCoALib reports errors using C++ exceptions, while the
library itself is exception-safe and (largely) thread-safe. The
current source code follows the C++03 standard; a passage to
the C++11 standard is planned for the near future (and this
should enable the code to become fully thread-safe).</p>
      <sec id="sec-3-1">
        <title>A. Library Design</title>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>We want CoCoALib to be a desirable software library, so it</title>
      <p>must be easy to use, reliable, robust and fast. Unfortunately,
achieving all these features together is not always possible,
so there are occasional compromises. One guiding principle is
that we want no nasty surprises.</p>
      <p>Here are the main features of the design of CoCoALib:
it is well-documented, free and open source C++ code
(under the GPL v.3 licence);
the design is inspired by, and respects, the underlying
mathematical structures;
the source code is clean and portable;
the user function interface is natural for mathematicians,
and easy to memorize;
execution speed is good with robust error detection.</p>
    </sec>
    <sec id="sec-5">
      <title>Our design of CoCoALib aims to make it easy to write correct programs, and difficult to write incorrect ones or ones which produce “nasty surprises”. While trying to follow this guideline we encountered some delicate aspects of the design:</title>
      <p>
        precise definition of a function’s domain (e.g. what result Mayer-Vietoris trees associated to monomial ideals. A
sigshould IsPrime(-2) give? And IsPrime(0)?) nificant aspect of this contribution is that the author worked
a choice between absolute mathematical correctness or completely independently relying entirely on the
documentadecent computational speed (and a remote chance of a tion of CoCoALib — thus confirming the quality of the
docuwrong answer) mentation. His work has encouraged us to develop specialized,
In general, CoCoALib handles limit cases properly. The efficient handling for monomial ideals (see [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ]).
domain of each CoCoALib function is described in the docu- A more recent contribution comes from M. Albert, who
mentation; for instance IsPrime throws an exception if the implemented an algorithm for computing Janet Bases of ideals
argument is not strictly positive — our reasoning is that it in polynomial rings. Once a Janet Basis has been obtained,
is unusual to want to test the primality of zero or a negative many ideal invariants can readily be determined ([
        <xref ref-type="bibr" rid="ref4">4</xref>
        ], [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ]).
number, so it is likely that the routine which called IsPrime Work is still under way to further expand this contribution.
has already made a mistake, so it is better to report it “as soon
as possible”. CoCoALib offers the programmer the choice C. Combining with External Libraries
between absolute correctness or probable correctness and good We have combined some of the features of various external
speed, e.g. IsPrime and IsProbPrime. libraries into CoCoALib. An important step in each case is
      </p>
      <p>An example of design: Finding a library interface which is the “translation” of a mathematical value from its CoCoALib
easy to learn and use, mathematically correct, but also efficient representation to that of the foreign library, and vice versa.
at run-time often requires a delicate balance of compromise. To make it easier to do this CoCoALib offers operations for
We cite here one example from CoCoALib where the solution destructuring the various data-structures it operates upon.
is untraditional but successful. One aspect of combining libraries which requires careful</p>
      <p>CoCoALib uses continued fractions internally in various attention is any global initialization the libraries perform, for
algorithms. A continued fraction is an expression of the form: instance specifying the memory manager for the common
un1 derlying library GMP. CoCoALib addresses this by requiring
a0 + 1 explicit initialization of its globals; there are various options,
a1 + a2+ a3 +1 including one for specifying a memory manager for GMP.
where a0 is an integer, and a1; a2; : : : are positive integers.</p>
      <p>Every rational number has a finite continued fraction which,
for compactness, is often represented as a list of integers
[a0; a1; a2; : : : ; as].</p>
      <p>The most natural implementation in CoCoALib would
simply compute this list. But in many applications only the first
few ak are needed, and computing the entire list is needlessly
costly. So the CoCoALib implementation produces an iterator
(a basic concept well-known in object-oriented programming)
which produces the values of the ak one at a time.</p>
      <sec id="sec-5-1">
        <title>B. Extending CoCoALib</title>
      </sec>
    </sec>
    <sec id="sec-6">
      <title>Naturally most of the source code in CoCoALib was written</title>
      <p>by us, but the design of the library (and its openness) was
chosen to facilitate and encourage “outsiders” to contribute.
We distinguish two categories of contribution: code
written specifically to become part of CoCoALib, and
standalone code written without considering its integration into
CoCoALib.</p>
      <p>Specific Direct Contributions to CoCoALib: The first
outside contribution came from M. Caboara, who wrote the
code for computing Gro¨bner bases and related operations
while CoCoALib was still quite young. At that stage the
detailed implementation of CoCoALib was still quite fluid,
and a number of pretty radical changes in the underlying
data-structures were still to occur; yet despite these upheavals
Caboara’s implementation of Buchberger’s algorithm required
virtually no changes, thus confirming the good modularity and
stability of the CoCoALib interface design.</p>
      <p>Another significant outside contribution came from
E. Saenz-de-Cabezon, who wrote the code for computing</p>
    </sec>
    <sec id="sec-7">
      <title>The first library we combined with CoCoALib is Frobby (see [8]) which is specialized for operations on monomial ideals. The experience also helped us improve the interfacibility of CoCoALib.</title>
      <p>
        The most advanced integration we have achieved so far is
with the Normaliz library (see [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ]) for computing with affine
monoids or rational cones. This is part of a closer collaboration
which is described in more detail in [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ]. In this particular case,
a new data-structure (called cone) was added to CoCoALib
to contain the type of value which Normaliz computes with.
      </p>
      <p>
        The most recent integration was with GFanLib (see [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ])
which is a C++ software library for computing Gro¨bner fans
and tropical varieties. The experience gained from the earlier
integrations made this a swift and painless operation.
      </p>
    </sec>
    <sec id="sec-8">
      <title>There is also an experimental connection to some of the</title>
      <p>
        functions of GSL (GNU Scientific Library [
        <xref ref-type="bibr" rid="ref10">10</xref>
        ]). This is an
interesting challenge because the interface has to handle two
contrasting viewpoints: the exact world of CoCoALib, and the
approximate (i.e. floating-point) world of GSL.
      </p>
    </sec>
    <sec id="sec-9">
      <title>III. THE INTERACTIVE SYSTEM COCOA-5</title>
    </sec>
    <sec id="sec-10">
      <title>The CoCoA-5 system replaces the old CoCoA-4 system</title>
      <p>whose heritage can be traced back at least to 1989. For
several reasons CoCoA-5 is a completely new implementation,
whose design was developed under the precept that it be
“as backward-compatible as (reasonably) possible” while also
eliminating the limitations inherent in the older system.</p>
      <p>All incarnations of the CoCoA system have been noted
for their approachability especially for “computer-phobic”
mathematicians, and CoCoA-5 is no exception. Indeed, the
aim was to make CoCoA-5 even friendlier than its forebears:
a notable example is the importance given to generating
genuinely helpful error messages.</p>
      <p>Here is a typical error message from CoCoA-5; note that the
error was actually signalled by CoCoALib as a C++ exception,
which the interpreter caught, and then “translated” into
humanreadable form:
# X := 99 + FloorSqrt(-99);
--&gt; ERROR: Value must be non-negative
--&gt; X := 99 + FloorSqrt(-99);
--&gt; ˆˆˆˆˆˆˆˆˆˆˆˆˆˆ
Note how the subexpression which actually triggered the error
is indicated by “up-arrows”, a most helpful feature in more
complicated expressions.</p>
      <p>Compared to earlier versions CoCoA-5 has a number of
significant new abilities, notably including algebraic extensions
and ring homomorphisms. The latter can be used to “move
rigorously” values from one ring to another.</p>
      <sec id="sec-10-1">
        <title>A. The Language in CoCoALib and in CoCoA-5</title>
      </sec>
    </sec>
    <sec id="sec-11">
      <title>When designing CoCoALib and CoCoA-5 we envisaged</title>
      <p>researchers and advanced users wishing to tackle hard
computations initially developing a prototype implementation in the
convenient interpreted environment of CoCoA-5, and when the
code is working properly, they translate it into C++ (using
CoCoALib functions) for better performance. Consequently, one
of the joint design goals of CoCoALib and the new CoCoA-5
language was to make it easy to convert CoCoA-5 code into
C++ code built upon CoCoALib. That said, CoCoALib offers
a richer programming environment, but also demands greater
discipline from the programmer. For instance, CoCoA-5 does
not have a special type for a “power-product” (it is just a
polynomial with 1 term and coefficient 1), whereas CoCoALib
has a special class, PPMonoidElem, which represents
powerproducts. Thus a good translation into C++ of a
CoCoA5 program manipulating power-products will require some
effort, but the reward should be a decisive gain in speed.</p>
      <p>To facilitate the conversion into C++ we have, whenever
possible, used the same function names in both CoCoA-5
and CoCoALib. We have also preferred traditional
“functional” syntax in CoCoALib over object oriented “method
dispatch” syntax, e.g. in CoCoALib we define deg(f) rather
than f.deg().</p>
      <sec id="sec-11-1">
        <title>B. Extending CoCoA-5</title>
        <p>
          package. The package indicates which of those functions
it will export; the rest are internal auxiliary functions.
The last way is to write the new functions in C++, add
them to CoCoALib, and then make them “visible” to
CoCoA-5. This last operation is normally quite
straightforward thanks to an ingenious combination of C++
inheritance and C macros (see [
          <xref ref-type="bibr" rid="ref3">3</xref>
          ]). Indeed we use exactly
this mechanism for making standard CoCoALib functions
accessible from an interactive CoCoA-5 session.
        </p>
        <p>While many CoCoA-5 functions just call CoCoALib
directly, there are still a few packages containing functions
which have yet to be migrated into CoCoALib.</p>
      </sec>
    </sec>
    <sec id="sec-12">
      <title>IV. THE COCOASERVER</title>
    </sec>
    <sec id="sec-13">
      <title>Included in the CoCoA software distribution is the Co</title>
      <p>CoAServer, currently still a prototype which provides a
client/server mechanism for accessing the capabilities of
CoCoALib. It uses an OpenMath-like language to accept
computation requests, and then send the result back. An early
use of the protype was to grant access to CoCoALib features
from CoCoA-4.7 while the new CoCoA-5 system was under
development.</p>
      <p>The advantages of computing via a “server” are that it
can be called by any other “client” software (which has an
OpenMath interface), and it avoids the delicate intricacies of
close integration occuring in monolithic compilation.</p>
      <p>Currently the server remains in prototype form as resources
are directed, for the time being, at CoCoALib and CoCoA-5.</p>
    </sec>
    <sec id="sec-14">
      <title>V. CONCLUSION</title>
    </sec>
    <sec id="sec-15">
      <title>The CoCoA software offers access to advanced capabilities</title>
      <p>in computational commutative algebra via three interfaces: an
interactive system, a C++ library, and a prototype server. This
variety allows users to choose whichever approach suits them
best.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>J.</given-names>
            <surname>Abbott</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.M.</given-names>
            <surname>Bigatti</surname>
          </string-name>
          , G. Lagorio, CoCoA-5
          <article-title>: a system for doing Computations in Commutative Algebra</article-title>
          . Available from website http://cocoa.dima.unige.it/cocoalib
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>J.</given-names>
            <surname>Abbott</surname>
          </string-name>
          and
          <string-name>
            <given-names>A.M.</given-names>
            <surname>Bigatti</surname>
          </string-name>
          , CoCoALib: a C+
          <article-title>+ library for doing Computations in Commutative Algebra</article-title>
          . Available from website http://cocoa.dima.unige.it/cocoalib
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>J.</given-names>
            <surname>Abbott</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.M.</given-names>
            <surname>Bigatti</surname>
          </string-name>
          ,
          <string-name>
            <surname>C.</surname>
          </string-name>
          <article-title>So¨ger, Integration of libnormaliz in CoCoALib and CoCoA 5 Proc</article-title>
          .
          <source>ICMS</source>
          <year>2014</year>
          , Springer LNCS 8592, pp.
          <fpage>647</fpage>
          -
          <lpage>653</lpage>
          ,
          <year>2014</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>M.</given-names>
            <surname>Albert</surname>
          </string-name>
          ,
          <article-title>Janet Bases in CoCoA; bachelor thesis</article-title>
          , Institut fu¨r Mathematik,
          <source>Universita¨t Kassel</source>
          ,
          <year>2011</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>M.</given-names>
            <surname>Albert</surname>
          </string-name>
          ,
          <article-title>Computing Minimal Free Resolutions of Polynomial Ideals with Pommaret Bases master thesis</article-title>
          , Institut fu¨r Mathematik,
          <source>Universita¨t Kassel</source>
          ,
          <year>2013</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <given-names>W.</given-names>
            <surname>Bruns</surname>
          </string-name>
          ,
          <string-name>
            <given-names>B.</given-names>
            <surname>Ichim</surname>
          </string-name>
          , T. Ro¨mer, C. So¨ger Normaliz. Available from http://www.mathematik.uni-osnabrueck.de/normaliz
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <given-names>O.</given-names>
            <surname>Ferna</surname>
          </string-name>
          <article-title>`ndez-</article-title>
          <string-name>
            <surname>Ramos</surname>
            ,
            <given-names>E.</given-names>
          </string-name>
          <article-title>Garc´ıa-</article-title>
          <string-name>
            <surname>Llorente</surname>
          </string-name>
          , E. Sa´enz-de-Cabezo´
          <article-title>n A monomial week (Spanish) Gac</article-title>
          .
          <source>R. Soc. Mat. Esp</source>
          .
          <volume>13</volume>
          , No.
          <volume>3</volume>
          ,
          <fpage>515</fpage>
          -
          <lpage>524</lpage>
          ,
          <year>2010</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <given-names>B.H.</given-names>
            <surname>Roune</surname>
          </string-name>
          , Frobby. Available from website http://www.broune.com/frobby
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          [9]
          <string-name>
            <given-names>A.N.</given-names>
            <surname>Jensen</surname>
          </string-name>
          , GFan. Available from website http://home.math.au.dk/jensen/software/gfan/gfan
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          [10]
          <string-name>
            <given-names>M.</given-names>
            <surname>Galassi</surname>
          </string-name>
          et al.,
          <source>GNU Scientific Library Reference Manual (3rd Ed.), ISBN 0954612078</source>
          .
          <article-title>GSL complete package available from website http://www</article-title>
          .gnu.org/software/gsl
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>