CoCoALib 0.99850 Examples

The programs in this directory form part of the documentation of CoCoALib. They are self-explanatory and illustrative; they should be read (rather than merely compiled and run). Each one concentrates on certain features of CoCoALib.

Where to start

If you are completely new to the CoCoA Library then you should start by looking at these examples which are the simplest and give an idea of the "philosophy" behind the CoCoA Library:
  ex-ring1.C
  ex-RingQQ1.C
  ex-RingElem1.C
To compile all the example programs, just issue the command
  make
from inside this directory; or the command make examples from the COCOA_ROOT directory.

You can compile just one example (say ex-ring1) by executing:

  make ex-ring1

Writing Your Own Programs

An easy way to create your own program using CoCoALib is the following

Short Descriptions of the Example Programs

ex-00-intro.C This example shows some very basic features of CoCoALib. See also the examples ex-c++-XXX for some basic C++ guidelines.
This example shows some very basic features of CoCoALib.           
We show types for representing "big" integers and rationals.     
We also show how to do some compututations with polynomials.       


ex-AlexanderDual.C Program showing `AlexanderDual' and `PrimaryDecomposition' on monomial ideals. If Frobby is available, it is used too.
This example shows how to compute the `AlexanderDual' and the       
`PrimaryDecomposition' of monomial ideals.  These operations are    
offered by both CoCoALib and the external library Frobby.  This     
program shows how to check whether Frobby is available, and if so,  
how to call its functions with CoCoALib data.                       


ex-ApproxPts1.C A short example showing how to use the approximate point preprocessing algorithms. See the file ex-ApproxPt1.in for a sample input.
A short example which reads a set of approximate points (with common epsilon)
and then applies the various preprocessing algorithms to them.  It prints out
the resulting preprocessed set with the corresponding weights, and the time taken.

ex-BenchmarkToolkit.C
ex-BigInt1.C Program showing basic use of BigInt values: creation, printing, and some simple arithmetic.
This program illustrates basic operations on BigInt values, showing that   
they can be used much like normal C++ ints except that there is a almost   
no limit on the magnitude of the values.                                   
NB If you need extreme efficiency then use the GMP library directly.       
Contrast this example with ex-RingZZ1.                                     


ex-BigInt2.C Program to calculate the modular inverse of a number. You must give as input the modulus and the residue; the residue need not be reduced.
This program illustrates that BigInt values can be used much like normal C++ 
ints except that there is a almost no limit on the magnitude of the values.  
NB If you need extreme efficiency then use the GMP library directly.         
Contrast this example with ex-RingZZ1.                                       


ex-BigInt3.C Program to find a (probable) prime with a specified number of bits.
This program shows that BigInts can be used much like normal C++ ints
with the advantage that there is almost no limit on the magnitude of 
the values.  Here we generate random BigInts and test them for being 
probable primes -- stopping as soon as we find a likely prime.       
NB If you need extreme efficiency then use the GMP library directly. 


ex-BigRat1.C Program illustrating basic use of BigRat values (i.e. rational numbers) showing that they can be used with a natural syntax.
Program giving example of basic arithmetic with exact rational numbers 
represented as values of type BigRat.  The syntax recalls that used for    
the built-in C++ numerical types.  Emphasis is on convenience rather   
utmost execution speed.  To understand better the difference between   
a BigRat value and an element of the ring RingQ, contrast this example     
with ex-RingQ1.C.                                                      


ex-BigRatInterval1.C This example shows how to create objects of type BigRatInterval, and how to do basic arithmetic with them.
This example shows how to create objects of type BigRatInterval,  
and how to do basic arithmetic with them.    


ex-BuildInfo.C This is a very short example showing what you can do with BuildInfo.
BuildInfo::PrintAll gives important information in the (enormously 
unlikely :-) event that you need to report a bug in CoCoALib. 


ex-CoprimeFactorBasis1.C This example shows how to compute a factor base using an object of type GCDFreeBasis_RingElem.
This example shows how to compute a factor base using an object of
type GCDFreeBasis_RingElem.  The gennerators of the factor base   
may be supplied individually, or all together in a vector.        


ex-CpuTimeLimit1.C This example shows how to use a CpuTimeLimit object to limit the CPU time used in a function. Compare this example with that in ex-CpuTimeLimit2.C.
This example shows how to use a CpuTimeLimit object to limit the    
CPU time used in a function containing a loop: just call the memfn  
operator(), which will throw TimeoutException if timeout occurs.    
Note that timeout may occur a bit later than requested.             


ex-CpuTimeLimit2.C This example shows how to use a CpuTimeLimit object to limit the CPU time used in a section of code, and what myPrepareForNewLoop does. Compare this example with ex-CpuTimeLimit1.C.
This example shows how to use a CpuTimeLimit object to limit the   
CPU time used in a section of code.  In particular, it shows use of
myPrepareForNewLoop between two loops (with differing costs for a  
single iteration).  Compare this example with ex-CpuTimeLimit1.C.

ex-DenseUPolyRing1.C DenseUPolyRing functions on RingElem: functions: +, -f, f-g, *, StdDeg, gcd, TidyGens.
This still has to be improved to become an interesting example (copied from test)Environments: DenseUPolyClean (Fp, Z)  


ex-DivMask1.C This example program shows the use of DivMasks. See also the example program ex-PPWithMask1.C
We show how to use DivMasks directly -- it is a bit tedious!             
See also the example ex-PPWithMask1.C, which has a friendlier interface. 
We show how the various different DivMaskRules can be selected.          


ex-DivMask2.C This example program performs some divisibility tests on PPs using DivMasks; it measures the effectiveness of the various DivMaskRules. See ex-PPWithMask2 for some similar timing tests.
This example program illustrates the effectiveness of the various    
DivMaskRules when using DivMasks as a quick non-divisibility check.  
Using DivMasks to check divisibility we can obtain two answers:      
'Surely not' or 'Maybe'.  The intention here is to see how often     
'Maybe' really means 'Yes, divisible'.  We see that the effectiveness
depends also on the presence of unused indeterminate in the PPMonoid.


ex-DynamicBitset1.C This example program shows the use of DynamicBitsets.
We show how to convert to and from PPMonoidElem.             
We list the available operations which are a lot faster than 
the corresponding ones on PPMonoidElems.                     
By default DynamicBitsets are printed as STL bitsets, i.e.   
0th bit in the rightmost position.  We show other options.   

Note that the ordering is xel, i.e. like lex but starting    
the comparison from the position with highest index (as they 
are printed by default)

ex-DynamicBitset2.C This example program shows the use of DynamicBitsets.
We show how to convert to and from RingElem.             
We create an ideal I and convert its generator into DynamicBitsets.


ex-ExternalLibs1.C This is an example program showing how to see which external libraries have been compiled into CoCoALib.
This is an example program showing how to see which external  
libraries have been compiled into CoCoALib.                   


ex-FloatApprox1.C This program makes simple use of the "floating point" approximation functions: MantissaAndExponent10 and MantissaAndExponent2, FloatApprox.
Example of use of MantissaAndExponent10 and related MantExp10 structure. 
Example of use of MantissaAndExponent2 and related MantExp2 structure.   
Example of use of FloatApprox (similatr to MantissaAndExponent2).        


ex-GFan1.C This program shows what can be computed in CoCoALib using GFan: a library for computations in ..., ....
This program shows what can be computed in CoCoALib using GFan:  
a library for computations in ..., 
....

ex-GMPAllocator1.C Program to find lengths of 3n+1 sequences -- using CoCoA::GMPAllocator
This example shows how to specify that a CoCoALib custom allocator be used
for managing the memory for small GMP values.  If you do computations    
involving many small big-integers (e.g. up to about 40 decimal digits) then
the custom allocator may give slightly better run-time performance (with 
debugging turned off!)  The argument to the constructor for GlobalManager
indicates that the CoCoALib allocator is to be used for GMP values.      


ex-GMPAllocator2.C Program comparing memory allocators for GMP values; compares speed.
This example shows the various ways of specifying the memory manager to  
be used by the GMP library.  The choice of memory manager is indicated as
an argument to the GlobalManager constructor.  Here we illustrate four   
choices: the CoCoALib default, the system allocator, the specialized     
GMPAllocator (with and without explicit indication of the slice size).   
The program measures the speed of computation with these various choices.


ex-Graeffe.C This example program shows how to apply Graeffe's method.
This example program shows how to apply Graeffe's method.           
When applying Graeffe's method to a polynomial in ZZ[x], the roots  
of a polynomial get raised to some power. The graeffe function is   
for squaring the roots, the graeffe3 function cubes them and the    
GraeffeN function raises them to a custom power. The GraeffeSeq     
class provides a way to iterate over all the powers up to a certain 
degree. In this example, the various functions are being applied    
to a polynomial with roots that are easy to calculate.              


ex-HomomorphismFns1.C This is a template file for example programs. The program itself does nothing whatsoever.
Make a copy of this file (called "foo.C", say) and put your code 
inside the procedure "program".                                  
To compile your file in the examples directory just do this:       
  make foo                                                         


ex-IdealOfPoints1.C This example show how to call IdealOfPoints.
This short example show how to call IdealOfPoints.                
The points are specified as rows of a matrix (over some field k). 
You need a polynomial ring for the answer: its coeff ring must be 
the same field k as used in the matrix.                           


ex-IntegrationUIBCToSparsePolyRing.C This is a template file for example programs. The program itself does nothing whatsoever.
Make a copy of this file (called "foo.C", say) and put your code 
inside the procedure "program".                                  
To compile your file in the examples directory just do this:       
  make foo                                                         


ex-Janet1.C In this file we explain how to compute the Janet Basis in CoCoA.
 We explain the function JanetBasis and show whicht options we can choose. 


ex-Janet2.C In this file we explain how to using some functions which are using the Janet Basis.
 PrintNonMultVar, PrintMultVar, IsPommaretBasis, StandardRepresentation(f) 


ex-LRSDegeneracy.C This example program shows how to check a LRS for degeneracy.
This example program shows how to check a LRS for degeneracy.       
In order to achieve this, the characteristic polynomial can be used 
used to determine whether it has two distinct roots whose quotient  
is a root of unity. As a simple example, two LRS-degenerate         
polynomials and one not-degenerate are examined.                    


ex-LogStream1.C This is a short example showing how to use LogStream, and how to make it refer to a different output stream.
This is a short example showing how to use LogStream, and how to  
make it refer to a different output stream.                       


ex-MVT-Simplicial.C This program contains the code described in ISSAC 2019 paper: Bigatti, Heras, Saenz-De-Cabezon "Monomial resolutions for efficient computation of simplicial homology" https://doi.org/10.1145/3326229.3326266
The paper examples are available at:
  http://www.dima.unige.it/~bigatti/cocoa/ex-MVT-Simplicial-tests.zip
This program reads from stdin.  For your convenience run it as:
  ./ex-MVT-Simplicial < ex-MVT-Simplicial-tests/<...>


ex-MVT-SqFr.C MVT for square free monomial ideals
MVT for square free monomial ideals  


ex-MVT-edge.C MVT for square free monomial ideals
MVT for square free monomial ideals  


ex-MVT.C Example of use of the Mayer-Vietoris trees.
Example of use of the Mayer-Vietoris trees.  


ex-MathSat1.C This program shows a prototype for MathSAT communication.
This program shows the first prototype for MathSAT communication.
The CoCoA class to use is MathSAT::env.                          
Only linear constraints, defined by matrices or polynomials.     
The matrices have n+1 columns: last col is for constants.        
The linear polynomials are compared with 0 (eq0, neq0, leq0, lt0).


ex-MathSat2.C This program shows a prototype for MathSAT communication.
This program shows another example for MathSAT communication.    
Similar to ex-MathSAT1, also shows the use of verbosity.         


ex-MorseGraph.C In this file we explain how to compute a free Resolution via Pommaret Basis in CoCoA.
 JBResolution, JBBettiDiagramm, JBMinimalResolution. 


ex-NF.C Example program illustrating an implementation of Normal Remainder wrt a list of polynomials. If the list is a Groebner Basis, NR returns the Normal Form.
This is just an example!  If you want to compute Normal Forms 
you should use the library function "NF".                   


ex-Normaliz1.C This program shows what can be computed in CoCoALib using Normaliz: a library for computations in affine monoids, vector configurations, lattice polytopes, and rational cones.
This program shows what can be computed in CoCoALib using Normaliz:  
a library for computations in affine monoids, vector configurations, 
lattice polytopes, and rational cones.

ex-Normaliz2.C This example shows how to set some libnormaliz flags.
This example reads a normaliz input file and computes the support hyperplanes.
It also shows how to set some libnormaliz flags.

ex-NumTheory-crypto1.C Interactive program for investigating cryptosystems. Implementation using BigInt.
 DiffieHellman   
 ElGamal         
 RSA             
 Rabin           
 ====                                                      


ex-NumTheory1.C This program illustrates the use of some basic number theoretic functions.
This programs show how to use some of the basic number theoretic functions.
Many of the examples use machine integers for convenience, but all the     
functions also work with BigInt values (except NextPrime and PrevPrime).   


ex-NumTheory2.C This program illustrates use of CRTMill to build a large integer from its residues modulo various different primes.
This program illustrates use of CRTMill to build a large integer 
from its residues modulo various different primes.               


ex-NumTheory3.C This example uses eratosthenes to build a sieve for testing quickly whether a number is prime. We compute many Goldbach representations.
This program tests how hard it is to find a "Goldbach" represetation 
of an integer; i.e. a sum of two primes.  It has to do many primality  
tests, so it is faster to use a table than call IsPrime repeatedly.    


ex-NumTheory4.C This program shows how to reconstruct a rational from several residue-modulus pairs (allowing for some of them to be wrong).
This program shows how to reconstruct a rational from several        
residue-modulus pairs (allowing for some of them to be wrong).       
CoCoALib offers two methods: one using continued fractions, the other
using lattice reduction.  The actual reconstruction is performed     
inside ContFracTrial or LatticeTrial.                                


ex-OrderingGrading1.C Predefined and user-defined orderings and gradings on PPMonoid and PolyRing.
Each ordering is degree-compatible with grading over Z^GradingDim 
i.e. the grading is given by the first GradingDim rows            
of the ordering matrix.                                           


ex-OrthogPolys1.C This program illustrates calling the functions for making orthogonal polynomials (Chebyshev, Hermite, Laguerre).
This program illustrates calling the functions for making  
orthogonal polynomials (Chebyshev, Hermite, Laguerre).     


ex-PPMonoidElem1.C Example of use of power products and PPMonoids. Program exhibiting most functions on power products.
ex-PPMonoidElem2.C Example of use of power products in different PPMonoids. Program exhibiting timings of the different implementations.
The implementations of PPMonoids are optimized for different uses:  
PPMonoidEv:   stores the Exponent vector                            
              good for accessing the exponents, slow for ordering   
PPMonoidOv:   stores the Order vector                               
              good for ordering, slow for accessing the exponents   
PPMonoidEvOv: stores the Exponent vector and the Order vector       
              good for accessing the exponents and for ordering     
              uses more memory and takes more time to assign        
PPMonoidBigEv: stores the Exponent vector as BigInt's               
              necessary if you use big exponents (>2^10)            
              obviously slow   


ex-PPMonoidHom1.C This program shows how to create and use a PPMonoidHom.
This program shows how to create and use a PPMonoidHom.  


ex-PPVector1.C This example program shows the use of PPVector. PPVector is still work in progress, so syntax might change
PPVector is a vector of PPWithMask.                       
It's been designed to represent the list of generators of 
monomial ideals (e.g. to facilitate interreduction).      
USE WITH CARE!  The interface may still change slightly.

ex-PPWithMask1.C This example program shows the use of PPWithMasks for testing divisibility between PPs. Compare with ex-DivMask1.C.
We show how to use PPWithMasks for testing divisibility.      
This program is very similar to ex-DivMask1.C.  The main      
differences are that this program is shorter and clearer, and 
it does a proper job of testing divisibility (even when the   
 useless null rule is used).                                  


ex-PPWithMask2.C This example program performs some divisibility speed tests using PPWithMasks; it shows the difference in speed which can be achieved using various DivMaskRules.
This example program test the speed of the divisibility test  
on values of type PPwithMask.  The main aim is to show that   
different DivMaskRules can produces differing behaviour, and  
which rule is best depends on the problem (e.g. few indets    
and high degrees, or many indets and low degrees).  Here we   
see also that unused indets can affect the speed.             
In case you're interested, the program ex-DivMask2 measures   
the effectiveness of the various DivMaskRules.                


ex-PolyInput1.C This program shows a very crude way to read a polynomial from the input; this could be useful for importing some kind of raw data. See ex-PolyInput2.C for much better, human usable, functions.
ex-PolyInput2.C This program shows how read a polynomial from a string or a file.
This program shows the easiest way to read a RingElem (not just polys) 
from an expression written in a string or in a file.                   
It is much more refined than what was available/shown in ex-PolyInput1.
NB As always, reading from string is convenient but NOT efficient.     


ex-PolyIterator1.C Program showing how to iterate through "sparse" polynomials.
Unlike in CoCoA-5, there no functions in CoCoALib to extract the      
support, the coeff list or the monomials from a polynomial.  Instead  
CoCoALib offers an "iterator" over the terms in a sparse polynomial:
you can access the coeff and PP directly from the iterator.           


ex-PolyIterator2.C Program showing how to homogenize a sparse polynomial using iterators.
This is just an example!  If you want to homogenize polynomials  
you should use the library function "homog".                   


ex-PolyRing1.C Example showing how to create some simple polynomial rings. It also shows some of the operations specific to elements of PolyRings. See also ex-ring2.C
This example program exhibits two things: various ways of creating 
polynomial rings, and several operations specific to elements of a 
polynomial ring.                                                   
In the procedure "program" there are examples of creating        
polynomial rings.                                                  
In the procedure "SomeComputations" there are brief examples of  
the operations specific to elements of PolyRings (e.g. deg).       
See also ex-ring2.C.                                               


ex-PolyRing2.C Example showing how to write polynomials using "monomial" See also ex-PolyRing1.C
Because of C/C++ precedence on operator "^" we cannot overload
it to define powers, as a consequence writing power-products can
be quite tedious or difficult to read.                          
Here we show how to write a simple function to create exponent  
vectors to be passed to "monomial".                           
I wish there were a better way to initialise a C++ vector...    


ex-PolyRing3.C This example program shows how to extract the "coefficients" of a polynomial, and also how to compute some other operations on the coefficients
This example program shows how to extract the "coefficients" 
of a polynomial, and also how to compute some other operations 
on the coefficients (e.g. content).  CoCoALib offers two notions
of coefficient: one is the natural one dictated by the ring,   
and the other comes from identifying e.g. k[x,y,z] and k[x,z][y]


ex-PolyRing4.C Example showing how to create more polynomial rings. (follows ex-PolyRing1.C)
More specialized and optimized polynomial rings                   


ex-Pommaret1.C In this file we explain how to compute several stability positions.
In this file we explain how to compute several stability positions.  


ex-Pommaret2.C In this file we explain how to using some methods which are using the Pommaret Basis.
In this file we explain how to using some methods which are using the Pommaret Basis.  


ex-ProgressReporter1.C This is a simple example showing how to use a ProgressReporter.
An example of how to use a ProgressReporter to print occasional 
updates during a long iterative computation.                    


ex-QuotientBasis.C Program showing how to compute a quotient basis of a 0-dimensional ideal.
The function "QuotientBasis" is now included in CoCoALib,          
so this example is a lot shorter than it was before version 0.9943.  
It returns a vector of PPMonoidElem.


ex-RandomBigInt1.C This program illustrates use of the pseudo-random number generator of CoCoALib. The numbers are independent and uniformly distributed in the given range; both ends of the range are reachable. See RandomSeqBool if you want random bools, & RandomSeqLong if you want random machine integers. See also RandomSource for a general random generator.
CoCoALib offers a way to make uniform pseudo-random number generators.      
When creating the generator you must specify the (inclusive) upper and lower
bounds for the random numbers which will be generated.  When creating a     
generator you may specify a `seed'; this allows different pseudo-random     
sequences to be produced, though the sequence is completely determined by   
its initial seed value.                                                     


ex-RandomBool1.C This program illustrates use of the pseudo-random bit generator of CoCoALib. The bits are independent, identically distributed; each with equal probability of being true or false. It is also possible to generate biased bits. See RandomSeqLong & RandomSeqBigInt if you want random integers. See also RandomSource for a general random generator.
CoCoALib offers a pseudorandom bit generator.  The generator can be   
seeded when it is created; this allows different pseudo-random        
sequences to be produced, though the sequence is completely determined
by the initial seed value.  The `NextBiasedBool' function filters a   
random bit sequence to produce `true' with a specified probability.   


ex-RandomLong1.C This program illustrates the pseudo-random number generator of CoCoALib: RandomSeqLong. The numbers are independent and uniformly distributed in the given range; both ends of the range are reachable. See RandomSeqBool if you want random bools, and RandomSeqBigInt if you want random large integers. See also RandomSource for a general random generator.
CoCoALib offers a way to make uniform pseudo-random number generators.   
When creating the generator you must specify the (inclusive)             
upper and lower bounds for the random numbers which will be generated.   
When creating a generator you may specify a `seed';                      
this allows different pseudo-random sequences to be produced,            
though the sequence is completely determined by its initial seed value.  


ex-RandomSource1.C This program shows the easiest way to produce random booleans, machine integers, and big integers.
This program uses GlobalRandomSource() to generate uniformly   
distributed random bits/booleans, machine integers in a given  
range, and big integers in a given range.  For the booleans and
machine integers it produces a histogram.                      
Use of globals could be dangerous in multi-threaded programs.  


ex-RandomSource2.C This program shows basic use of a RandomSource object to produce random booleans, machine integers, and big integers. Also shows how to seed and reseed a RandomSource. This program uses explicitly a RandomSource object to generate distributed random bits/booleans, machine integers in a given range, and big integers in a given range.
This program uses explicitly a RandomSource object to generate 
distributed random bits/booleans, machine integers in a given  
range, and big integers in a given range.                      


ex-RingElem1.C First introduction to polynomial rings and polynomials (RingElem)
Create your first polynomial ring and polynomial.           
Basic operations an printing. 


ex-RingElem2.C Example showing operations on RingElem for a ring or a PolyRing.
This is a long list of function calls from different rings.  


ex-RingFp1.C Inefficient program to compute sqrt(2) modulo a given number. Simple example using finite fields or integers modulo N.
The program asks the user for the value of N, it creates the     
ring of integers mod N, and finally uses "brute force" to find 
all square-roots of 2 modulo N.                                  


ex-RingFp2.C When computing over a finite field normally it is best to use the function NewZZmod to create the field. However, for the curious it is possible to create small prime finite fields stating the particular implemention method (there are 3 possibilities).
This program compares the speeds of computing sums and products in   
the three different implementations of small prime finite fields.    
It performs the timing tests for different sizes of prime, and       
illustrates that different implementations have different upper      
limits for the characteristic -- these limits depend on the platform.
It also gives the performance of the finite field created by NewZZmod


ex-RingFq1.C This example illustrates how to create an algebraic extension of a finite field, and how to obtain its generator.
This example illustrates how to create an algebraic extension of a finite 
field, and how to obtain its generator.  We use the (group) generator to  
run through all the elements of the finite field.                         


ex-RingHom1.C The example in this file shows how to create and use some homomorphisms between rings.
CanonicalHom is an easy way to make these homomorphisms:  
R --> R/I,    R --> R[x],   R --> FractionField(R),       
R --> R,      QQ --> R,     ZZ --> R,                     
PolyAlgebraHom makes the R-algebra homomorphisms:         
R[x] --> R,   R[x] --> R[y]                               


ex-RingHom2.C Operations between elements of different rings are not allowed but we can use homomorphisms to map the elements into the same ring.
The example in this file shows how to create and use some      
homomorphisms between rings.  In particular, it gives a simple 
example of mixed ring arithmetic: the user must map all values 
into a single ring before combining them arithmetically.       


ex-RingHom3.C This program shows how we define a ring homomorphism to perform a change of coordinates in a polynomial ring.
ex-RingHom4.C This program shows how we define a ring homomorphism to evaluate polynomials.
ex-RingHom5.C The example in this file shows how to create and use some homomorphisms between rings.
We compute these polynomials (with parameters) in some rings: 
f = (2*a/3-1)*x[0] + 1/a;  g = x[0]-a;                        


ex-RingHom6.C The example in this file shows how to create a RingHom from one quotient ring to another.
The example in this file shows how to create a RingHom from 
one quotient ring to another.  First we make a RingHom from 
a polynomial ring to the codomain (a quotient ring), then we
use the function `InducedHom' to extend it to the full domain.


ex-RingQQ1.C Some simple computations with rational numbers. This example illustrates how to create the field of rational numbers. It shows that we can compute 7/3 in QQ but not in ZZ. It shows how to map an integer into a rational number.
Familiarize yourself with the example ex-RingZZ1.C before proceeding. 
As C++ does not natively have any rings, we must construct them from  
scratch.                                                              


ex-RingTwinFloat1.C Example showing some features of RingTwinFloat. Program to explore the precision offered by RingTwinFloat
ex-RingTwinFloat2.C Program exhibiting a way of using ever higher precisions... This example shows how failure can be a success: this pathological computation produces the **same wrong result** when using normal floating point arithmetic at any given finite precision! However, since twin floats are self-checking, we detect that there is a problem.
Example showing iterative increase of precision using RingTwinFloat    
until the answer is found (or some maximum precision is reached).      
This program will always fail to find the limit: J-M Muller's sequence 
actually converges to 6 (rather slowly), however it is pathological    
because it converges to 100 using any finite precision arithmetic.     
RingTwinFloat detects the onset of pathological convergence to 100, and
throws an InsufficientPrecision exception.                             


ex-RingTwinFloat3.C Program showing how some RingTwinFloat values can have more precision than that requested.
Example showing that certain RingTwinFloat values may have a precision  
higher than that requested.  In this case we request 64 bits (i.e.      
about 19 decimal digits), but in fact we can remove the nineteen most   
significant digits and still have a result with the requested precision.
So the original value of the variable third did in fact have at         
least 127 bits correct (i.e. about 38 decimal digits).                   


ex-RingTwinFloat6.C (Advanced) example illustrating the `soft transitions' from false to uncertain and from uncertain to true in the equality test between twin floats (as eps to zero when comparing 1+eps to 1).
Example illustrating the `soft transitions' from false to uncertain      
and from uncertain to true in the equality test between twin floats.     
For many small values of eps this example computes 1+eps and compares    
the to 1 (either by direct comparison, or by subtacting and seeing if    
the difference is positive or zero.  Direct comparison is better than    
computing the difference (which throws InsufficientPrecision more often).


ex-RingWeyl1.C An example about RingWeyl, the interface is not quite settled yet.
All these examples about RingWeyl will probably be merged into one.


ex-RingWeyl2.C An example about RingWeyl, the interface is not quite settled yet.
This shows a computation of a Groebner Basis.
All these examples about RingWeyl will probably be merged into one.


ex-RingWeyl3.C An example about RingWeyl, the interface is not quite settled yet.
This shows a computation of a Groebner Basis.
All these examples about RingWeyl will probably be merged into one.


ex-RingWeyl4.C An example about RingWeyl, the interface is not quite settled yet.
This shows a computation of a Groebner Basis.
All these examples about RingWeyl will probably be merged into one.


ex-RingWeyl5.C An example about RingWeyl, the interface is not quite settled yet.
This shows a computation of a Groebner Basis.
All these examples about RingWeyl will probably be merged into one.


ex-RingZZ1.C This is a basic example about the creation and use of the ring of integers. It illustrates the CoCoALib "philosophy" of first creating a ring, and then computing with values in that ring. The C++ commands for performing arithmetic on RingElems have a natural syntax (except we cannot use ^ for powers). It warns about "mixed ring arithmetic", which is forbidden in CoCoALib.
To calculate with elements of a ring we must first create the   
ring, then we can create C++ objects of type RingElem which     
belong to the ring -- a RingElem can change its value but not   
the ring to which it belongs.                                   


ex-RootBound1.C This program illustrates use of the RootBound function for obtaining an upper bound on the abs value of the complex roots.
This program illustrates use of the RootBound function for      
obtaining an upper bound on the abs value of the complex roots. 
The function has an optional second arg.  The second arg says   
how many Graeffe iterations to perform; these lead to a better  
bound, but can be slow for large polynomials (as the example    
makes clear).                                                   


ex-SmallFp1.C This example illustrates basic use of SmallFpImpl for arithmetic in a small prime finite field. ex-SmallFp3 shows how to compute more efficiently, but it is not for the faint-hearted!
This example illustrates basic use of SmallFpImpl for arithmetic in a
small prime finite field.  ex-SmallFp3 shows how to compute more     
efficiently, but it is not for the faint-hearted!                    
Here we see how to create a SmallFpImpl object, and its use for basic
arithmetic (add, sub, mul, div, power) on finite field elements.     


ex-SmallFp2.C This simple example shows how to use the SmallFp export conventions "SymmResidues" and "NonNegResidues", and the effect they have.
This simple example shows how to use the SmallFp export conventions
"SymmResidues" and "NonNegResidues", and the effect they have. 


ex-SmallFp3.C **ADVANCED** This example program is for advanced CoCoALib users. It shows how to use SmallFpImpl for efficient arithmetic in a small prime finite field. Not for the faint-hearted!
**ADVANCED**  This example program is for advanced CoCoALib users.    
SmallFpImpl enables you to perform arithmetic efficiently in a small  
prime finite field.  The catch is that efficient use is not as simple 
as using RingElems directly.  We take as a specific illustrative      
example the computation of an inner product.  Be prepared to spend    
some time reading and comprehending the code!                         


ex-SparsePolyOps-eval.C This example illustrates evaluating a univariate polynomial with integer coefficients at an integer or rational point.
This example illustrates evaluating a univariate polynomial  
with integer coefficients at an integer or rational point.   


ex-SparsePolyOps1.C This is a template file for example programs. The program itself does nothing whatsoever.
Make a copy of this file (called "foo.C", say) and put your code 
inside the procedure "program".                                  
To compile your file in the examples directory just do this:       
  make foo                                                         


ex-SparsePolyOps2.C This example shows simple use of RealRadical and HasRealRoot3.
This example shows simple use of RealRadical and HasRealRoot3.  


ex-SparsePolyOps3.C This shows how to use the functions SturmSeq and NumRealRoots.
This shows how to use the functions SturmSeq and NumRealRoots.  


ex-SumBigRat.C Example of using a SumBigRat object to sum many rationals; and an example of using a SumBigInt object to sum many integers.
Example of using a SumBigRat object to sum many rationals.     
SumBigRat can be rather faster than directly summing.          
Similarly SumBigInt is suitable for summing many big integers. 


ex-ToString1.C This program illustrates use of the decimal string conversion functions.
Example of use FloatStr, ScientificStr and DecimalStr for printing 
rationals in a comprehensible/decimal format.                      


ex-ToString2.C This program illustrates use of the decimal string conversion functions.
Example of use FloatStr, ScientificStr and DecimalStr for printing 
rationals in a comprehensible/decimal format.                      


ex-UtilsTemplate1.C This program shows how to use some of the "template utilities" in CoCoALib: e.g. sum, product, LexCmp3.
This program illustrates use of product, sum, and LexCmp3.      
The functions are fairly general, but we present just a simple  
case.  They can also be used with lists instead of vectors      


ex-VectorOperations1.C Program to demonstrate printing of vectors (and lists).
This example shows how to print out a C++ vector of values.          
It also shows that you can just as easily print a vector of vectors. 


ex-VerificationLevel1.C This is a program showing how to use VerificationLevel.
This is a program showing how to use VerificationLevel.  
We construct a polynomial which confuses MinPolyQuot, then
show that MinPolyQuot gives the wrong answer if verification
is 0; but it get the right answer if verification is 2.
The guaranteed correct answer can be obtained by passing "guaranteed()"

ex-bool3.C This program shows a simple use of three-state booleans.
This program shows a simple use of three-state booleans.        
We define a quick primality test which is guaranteed to be fast 
but which sometimes has to return a verdict of "Don't know" so
it can keep its guarantee of speed.  We then see how often the  
quick test gives a definite answer, and how often it has to say 
"Don't know".                                                 


ex-c++-arith.C This is an example showing some basic arithmetic ops in C++.
This is an example showing some basic arithmetic ops in C++. 
With a strong caution about division and computing powers.   


ex-c++-basic.C This is an example showing some very basic C++: comments, variable declaration (and init) for basic types and how to print.
This is an example showing some very basic C++:  comments, 
variable declaration (and init) for basic types and        
how to print.  See also ex-c++-bool.C                      


ex-c++-bool.C This is an example showing basic use of booleans in C++. See also ex-c++-basic.C.
This is an example showing basic use of booleans in C++.  
Note especially the `smart' operators for `and' and `or'. 
See also ex-c++-basic.C.                                  


ex-c++-class.C This is a (harder) example showing the implemention of a simple C++ class. It shows class definition, and use of an object of that class. The class contains a general factorization of an integer.
This is a (harder) example showing the implemention of a simple C++ class.
It shows class definition, and use of an object of that class.            
The class contains a general factorization of an integer.  The class data 
members are `private' so their values can be seen or changed only by      
`member functions' or `friend functions'.                                 


ex-c++-fn-defn.C This is an example showing some basic function definitions in C++. The command `return' ends computation in the function/procedure; in a function it also says which value to return to the caller.
This is an example showing some basic function definitions in C++. 
The command `return' ends computation in the function/procedure;   
in a function it also says which value to return to the caller.    
C++ barely distinguishes between "functions" (which return a     
value) and "procedures" (which return no value).                 


ex-c++-integers.C This is an example showing the C++ integer type "long", which we recommend just for indexing; otherwise use "BigInt". We also give an ugly example about how to detect integer overflow.
This is an example showing the C++ integer type "long".  There  
are other types with different bit-widths; all can be "signed"  
or "unsigned" (just for non-negative values).  Computations     
are fast, but may cause overflow -- something you should avoid! 
We give an example showing how awkward it can be to avoid or    
anticipate overflow.  There are no such problems with BigInt!   


ex-c++-loop-for1.C This is an example showing some basic "for" loops in C++. It also shows "continue" and "break" inside a loop.
This is an example showing some basic "for" loops in C++.    
It also shows "continue" and "break" inside a loop.        
We restrict to simple integer "for" loops.  See also examples
for vectors and iterators.                                     


ex-c++-loop-for2.C This is an example showing the new style "for" loop in C++. See ex-c++-loop-for1.C for "continue" and "break" commands.
This is an example showing the new style "for" loop in C++.   
See ex-c++-loop-for1.C for "continue" and "break" commands. 
We show how to state whether the elements are copied.           


ex-c++-loop-while.C This is an example showing some basic "for" loops in C++. It also shows "continue" and "break" inside a loop.
This is an example showing some basic "for" loops in C++.    
It also shows "continue" and "break" inside a loop.        
We restrict to simple integer "for" loops.  See also examples
for vectors and iterators.                                     


ex-c++-vector1.C This is an example showing some basic use of C++ vectors (which are a bit like lists in CoCoA-5). See also ex-c++-loop-for2.C for iterating over the elements.
This is an example showing some basic use of C++ vectors.    
C++ has few built-in types, but the STL (Standard Template   
Library) contains many useful extensions.  std::vector is    
is one of these extensions.  It is a homogeneous array: a    
collection of many objects of the same type, and each one    
may be accessed directly by an integer index (from 0 to n-1) 
See also ex-c++-loop-for2.C for iterating over the elements. 


ex-c++-vector2.C This is an example showing how to translate CoCoA-5 list functions APPEND, FIRST & LAST into C++.
This is an example showing how to translate CoCoA-5 list  
functions APPEND, FIRST & LAST into C++.  APPEND translates
nicely into push_back. Also first(L) and last(L) have nice
translations; BUT first(L,k) and last(L,k) do not have    
efficient translations -- there are usually better, but   
different techniques in C++.                              


ex-combinatorics1.C This example illustrates use of the iterators for subsets and for tuples.
This example illustrates use of the iterators for subsets and for tuples.  
The iterators actually work on "indexes" in the range 0 to n-1.          


ex-convert1.C This program illustrates use of some of the "conversion" functions.
This program illustrates use of some of the "conversion" functions.  
These functions convert integer/rational values from one type into     
another preserving the value -- if the conversion cannot be safely made
then this is indicated (via a boolean or an error).                    


ex-cyclotomic.C This example program shows how to check for cyclotomicity.
This example program shows how to check for cyclotomicity.          
The input is always expected to be a univariate polynomial over ZZ. 
Here, two cyclotomic and one non-cyclotomic polynomial are being    
examined.

ex-empty.C This is a template file for example programs. The program itself does nothing whatsoever.
Make a copy of this file (called "foo.C", say) and put your code 
inside the procedure "program".                                  
To compile your file in the examples directory just do this:       
  make foo                                                         


ex-error1.C This example shows how to throw, catch and create your own errors.
CoCoALib uses C++ exceptions to inform the user that a problem has occurred.    
This simple example illustrates the CoCoALib convention for reporting an error: 
call the macro CoCoA_THROW_ERROR which both constructs the "ErrorInfo" value  
and throws it.  It also shows how to catch these CoCoALib exceptions, which are 
always objects of type "ErrorInfo".  The most useful part of a CoCoALib       
exception is its error code: after catching a CoCoALib exception we can check   
whether its code is one we expected (and can deal with).  The full list of      
possible error codes can be found in the header file CoCoA/error.H.             


ex-factor1.C This example shows how to interpret the result of a factorization.
This example shows how to interpret the result of a factorization. 
It creates a ring element (belonging to a polynomial ring), and    
factorizes it.  The result is a "factorization object".  We show 
how to access/use the various fields in this object.               


ex-frobby1.C This program shows what can be computed in CoCoALib using the C++ library Frobby
  "Frobby - Computations With Monomial Ideals"  
Web page: http://www.broune.com/frobby/

ex-geobucket1.C This program shows how to use geobuckets for long sums. It compares timings between normal sum "+=" and geobucket sum.
We simulate a long sum:
we add the summands of a long polynomial f (and f*x) one at a time,   
and do it twice to consider also the arithmetics on the coefficients. 
The advantage for geobuckets comes when f is quite long.              
Geobuckets are to be used as a temporary value;                       
the final result is then copied into a RingElem.

ex-hilbert1.C This example is just for testing the Hilbert code. It might disappear as soon as HilbertSeries is included in CoCoALib.
This code also shows how to create the "chess examples".           


ex-ideal1.C This example shows how to create ideals from ring elements.
This short example shows how to create ideals from one or more 
ring elements.  If there are at most 4 generators this can be  
done directly; otherwise put the generators in a vector, and   
create the ideal from the vector.                              


ex-ideal2.C This example shows some operations on ideals.
This short example shows how to perform various operations  
involving ideals.  Certain operations are valid only for    
ideals in a polynomial ring.                                


ex-interrupt1.C This short example shows an easy way of making CoCoALib programs handle signals (or interrupts), by converting them to exceptions.
This short example shows an easy way of making CoCoALib programs  
handle signals (or interrupts), by converting them to exceptions. 
There are two crucial parts: create a SignalWatcher to say which  
signals to watch for, and call CheckForInterrupt when it is       
convenient to act upon the interrupting signal.                   


ex-interrupt2.C This example shows how to make a CoCoALib programs watch for signals only during a section of code. Look at ex-interrupt1 before looking at this example! Compare what happens when you interrupt the first computation, and when you interrupt the second (identical) computation.
This example shows how to make a CoCoALib programs watch for   
signals only during a section of code.  Look at ex-interrupt1  
before looking at this example!  Compare what happens when you 
interrupt the first computation, and when you interrupt the    
second (identical) computation.                                


ex-interrupt3.C This example shows how to make a CoCoALib program watch for signals, and if one is detected, it prints extra info.
This example shows how to make a CoCoALib program watch for   
signals, and if one is detected, it prints extra info.  Look  
at ex-interrupt1.C and ex-interrupt2.C before looking at this.


ex-limits.C This example shows the numeric limits for CoCoALib.
The numeric limits of CoCoALib depend on many factors: 
some choices from the authors of CoCoALib,                  
the compilation flags of CoCoALib, which in turn depend on  
the architecture of your machine and the compilations flags 
used by the gmp and boost libraries.                        


ex-matrix1.C Example program illustrating the creation of matrices, and some operations on them.
Example program illustrating the creation of matrices, and some 
basic operations on them. 


ex-matrix2.C Example program illustrating the creation of matrix views, and some effects of "aliasing". Examples of matrix views include transposes submatrices, block matrices, and concatenated matrices.
Example program illustrating the creation of matrix views, and some    
effects of "aliasing", i.e. where there is more than one way to refer
to a single entry of the matrix.  We gives examples of creating various
views: ZeroMat, IdentityMat, transpose, submat, BlockMat2x2, ConcatHor 
and ConcatVer.

ex-matrix3.C This program shows how to solve linear systems (matrix equations).
This program shows how to solve linear systems (matrix equations). 
At the moment linear system solving is only partially implemented. 
It will work if the matrix is over a field; otherwise it may fail. 


ex-matrix4.C This example shows how to use MatByRows & MatByCols.
A simple example showing how a C++ vector can be viewed as a matrix.
You can even view the same vector in several different ways.        


ex-module1.C Example program illustrating the creation of free modules, and some operations on them.
Please note that the module code is still rather young. 


ex-module2.C Example program illustrating the creation of polynomial modules with ordering and shifts.
Please note that the module code is still rather young. 


ex-obsolescent.C This example program shows how to call an obsolescent CoCoALib function.
This example program shows how to call an obsolescent CoCoALib function. 
You must do two things: 
(1) include the header file CoCoA/obsolescent.H 
(2) give the option AllowObsolescentFns to GlobalManager

ex-ring1.C This example program shows how to use the rings ZZ and QQ, and how to perform various operations on ring elements (RingElem).
Use of the fundamental rings ZZ and QQ.                              
Creation of ring elements (C++ type RingElem).                       
Operations allowed on elements of the same ring:                     
  zero(R) and one(R)                                                 
  a + b, a - b, a * b                                                
  -a                                                                 
  a = b   (assignment)                                               
  a == b  and  a != b  (comparison)                                  
  IsZero(a), IsOne(a), IsMinusOne(a)                                 
Moreover other operations might be allowed, for example:             
  a > b   if the ring is ordered                                     
  a / b   if exact division is possible (and implemented!)           
See ex-RingHom*.C for how to move elements from one ring to another. 


ex-ring2.C This example program shows how to create various types of ring, and several operations one can perform on rings (e.g. querying their properties).
This example creates several different sorts of ring,            
and then calls PrintRingInfo on each one.                        
PrintRingInfo calls various functions to obtain information      
about each ring passed to it.  Naturally, some query functions   
make sense only for certain types of ring (e.g. NumIndets(R)).   


ex-symbol1.C Creation of symbols, and some simple operations on them.
Symbols are used to give print names to indeterminates.  Their main   
use is as an argument to a pseudo-ctor for a PPMonoid or a polynomial 
ring -- see examples for those types.                                 


ex-symbol2.C This program shows simple use of the functions for creating new anonymous symbols.
Often algorithms need one to work with an addition new indeterminate
which must be different from all indeterminates already being use.  
In CoCoALib we can create new "anonymous" indeterminates guaranteed
to be different from all others.  This examples shows how to create 
them singly, and also several all together.                         


ex-verbose1.C This program illustrates the use of VerboseLog for producing progress reports on the various steps of an algorithm.
This program illustrates the use of VerboseLog for producing progress    
reports on the various steps of an algorithm.  You must set the global   
verbosity level using the fn SetVerbosityLevel (higher values mean more  
messages are printed) immediately before the call you want to investigate
and set it back to 0 afterwards!