Richard Kreckel
25 years ago
17 changed files with 0 additions and 15865 deletions
-
BINdoc/cln.dvi
-
4898doc/cln.html
-
5902doc/cln.ps
-
175doc/cln_1.html
-
163doc/cln_10.html
-
476doc/cln_11.html
-
108doc/cln_12.html
-
22doc/cln_13.html
-
279doc/cln_2.html
-
401doc/cln_3.html
-
2018doc/cln_4.html
-
424doc/cln_5.html
-
125doc/cln_6.html
-
251doc/cln_7.html
-
139doc/cln_8.html
-
359doc/cln_9.html
-
125doc/cln_toc.html
4898
doc/cln.html
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
5902
doc/cln.ps
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -1,175 +0,0 @@ |
|||
<HTML> |
|||
<HEAD> |
|||
<!-- Created by texi2html 1.56k from cln.texi on 28 August 2000 --> |
|||
|
|||
<TITLE>CLN, a Class Library for Numbers - 1. Introduction</TITLE> |
|||
</HEAD> |
|||
<BODY> |
|||
Go to the first, previous, <A HREF="cln_2.html">next</A>, <A HREF="cln_13.html">last</A> section, <A HREF="cln_toc.html">table of contents</A>. |
|||
<P><HR><P> |
|||
|
|||
|
|||
<H1><A NAME="SEC1" HREF="cln_toc.html#TOC1">1. Introduction</A></H1> |
|||
|
|||
<P> |
|||
CLN is a library for computations with all kinds of numbers. |
|||
It has a rich set of number classes: |
|||
|
|||
|
|||
|
|||
<UL> |
|||
<LI> |
|||
|
|||
Integers (with unlimited precision), |
|||
|
|||
<LI> |
|||
|
|||
Rational numbers, |
|||
|
|||
<LI> |
|||
|
|||
Floating-point numbers: |
|||
|
|||
|
|||
<UL> |
|||
<LI> |
|||
|
|||
Short float, |
|||
<LI> |
|||
|
|||
Single float, |
|||
<LI> |
|||
|
|||
Double float, |
|||
<LI> |
|||
|
|||
Long float (with unlimited precision), |
|||
</UL> |
|||
|
|||
<LI> |
|||
|
|||
Complex numbers, |
|||
|
|||
<LI> |
|||
|
|||
Modular integers (integers modulo a fixed integer), |
|||
|
|||
<LI> |
|||
|
|||
Univariate polynomials. |
|||
</UL> |
|||
|
|||
<P> |
|||
The subtypes of the complex numbers among these are exactly the |
|||
types of numbers known to the Common Lisp language. Therefore |
|||
<CODE>CLN</CODE> can be used for Common Lisp implementations, giving |
|||
<SAMP>`CLN'</SAMP> another meaning: it becomes an abbreviation of |
|||
"Common Lisp Numbers". |
|||
|
|||
|
|||
<P> |
|||
The CLN package implements |
|||
|
|||
|
|||
|
|||
<UL> |
|||
<LI> |
|||
|
|||
Elementary functions (<CODE>+</CODE>, <CODE>-</CODE>, <CODE>*</CODE>, <CODE>/</CODE>, <CODE>sqrt</CODE>, |
|||
comparisons, ...), |
|||
|
|||
<LI> |
|||
|
|||
Logical functions (logical <CODE>and</CODE>, <CODE>or</CODE>, <CODE>not</CODE>, ...), |
|||
|
|||
<LI> |
|||
|
|||
Transcendental functions (exponential, logarithmic, trigonometric, hyperbolic |
|||
functions and their inverse functions). |
|||
</UL> |
|||
|
|||
<P> |
|||
CLN is a C++ library. Using C++ as an implementation language provides |
|||
|
|||
|
|||
|
|||
<UL> |
|||
<LI> |
|||
|
|||
efficiency: it compiles to machine code, |
|||
<LI> |
|||
|
|||
type safety: the C++ compiler knows about the number types and complains |
|||
if, for example, you try to assign a float to an integer variable. |
|||
<LI> |
|||
|
|||
algebraic syntax: You can use the <CODE>+</CODE>, <CODE>-</CODE>, <CODE>*</CODE>, <CODE>=</CODE>, |
|||
<CODE>==</CODE>, ... operators as in C or C++. |
|||
</UL> |
|||
|
|||
<P> |
|||
CLN is memory efficient: |
|||
|
|||
|
|||
|
|||
<UL> |
|||
<LI> |
|||
|
|||
Small integers and short floats are immediate, not heap allocated. |
|||
<LI> |
|||
|
|||
Heap-allocated memory is reclaimed through an automatic, non-interruptive |
|||
garbage collection. |
|||
</UL> |
|||
|
|||
<P> |
|||
CLN is speed efficient: |
|||
|
|||
|
|||
|
|||
<UL> |
|||
<LI> |
|||
|
|||
The kernel of CLN has been written in assembly language for some CPUs |
|||
(<CODE>i386</CODE>, <CODE>m68k</CODE>, <CODE>sparc</CODE>, <CODE>mips</CODE>, <CODE>arm</CODE>). |
|||
<LI> |
|||
|
|||
<A NAME="IDX1"></A> |
|||
On all CPUs, CLN may be configured to use the superefficient low-level |
|||
routines from GNU GMP version 3. |
|||
<LI> |
|||
|
|||
It uses Karatsuba multiplication, which is significantly faster |
|||
for large numbers than the standard multiplication algorithm. |
|||
<LI> |
|||
|
|||
For very large numbers (more than 12000 decimal digits), it uses |
|||
Schönhage-Strassen |
|||
<A NAME="IDX2"></A> |
|||
multiplication, which is an asymptotically optimal multiplication |
|||
algorithm, for multiplication, division and radix conversion. |
|||
</UL> |
|||
|
|||
<P> |
|||
CLN aims at being easily integrated into larger software packages: |
|||
|
|||
|
|||
|
|||
<UL> |
|||
<LI> |
|||
|
|||
The garbage collection imposes no burden on the main application. |
|||
<LI> |
|||
|
|||
The library provides hooks for memory allocation and exceptions. |
|||
<LI> |
|||
|
|||
<A NAME="IDX3"></A> |
|||
All non-macro identifiers are hidden in namespace <CODE>cln</CODE> in |
|||
order to avoid name clashes. |
|||
</UL> |
|||
|
|||
<P><HR><P> |
|||
Go to the first, previous, <A HREF="cln_2.html">next</A>, <A HREF="cln_13.html">last</A> section, <A HREF="cln_toc.html">table of contents</A>. |
|||
</BODY> |
|||
</HTML> |
@ -1,163 +0,0 @@ |
|||
<HTML> |
|||
<HEAD> |
|||
<!-- Created by texi2html 1.56k from cln.texi on 28 August 2000 --> |
|||
|
|||
<TITLE>CLN, a Class Library for Numbers - 10. Internals</TITLE> |
|||
</HEAD> |
|||
<BODY> |
|||
Go to the <A HREF="cln_1.html">first</A>, <A HREF="cln_9.html">previous</A>, <A HREF="cln_11.html">next</A>, <A HREF="cln_13.html">last</A> section, <A HREF="cln_toc.html">table of contents</A>. |
|||
<P><HR><P> |
|||
|
|||
|
|||
<H1><A NAME="SEC59" HREF="cln_toc.html#TOC59">10. Internals</A></H1> |
|||
|
|||
|
|||
|
|||
<H2><A NAME="SEC60" HREF="cln_toc.html#TOC60">10.1 Why C++ ?</A></H2> |
|||
<P> |
|||
<A NAME="IDX327"></A> |
|||
|
|||
|
|||
<P> |
|||
Using C++ as an implementation language provides |
|||
|
|||
|
|||
|
|||
<UL> |
|||
<LI> |
|||
|
|||
Efficiency: It compiles to machine code. |
|||
|
|||
<LI> |
|||
|
|||
<A NAME="IDX328"></A> |
|||
Portability: It runs on all platforms supporting a C++ compiler. Because |
|||
of the availability of GNU C++, this includes all currently used 32-bit and |
|||
64-bit platforms, independently of the quality of the vendor's C++ compiler. |
|||
|
|||
<LI> |
|||
|
|||
Type safety: The C++ compilers knows about the number types and complains if, |
|||
for example, you try to assign a float to an integer variable. However, |
|||
a drawback is that C++ doesn't know about generic types, hence a restriction |
|||
like that <CODE>operator+ (const cl_MI&, const cl_MI&)</CODE> requires that both |
|||
arguments belong to the same modular ring cannot be expressed as a compile-time |
|||
information. |
|||
|
|||
<LI> |
|||
|
|||
Algebraic syntax: The elementary operations <CODE>+</CODE>, <CODE>-</CODE>, <CODE>*</CODE>, |
|||
<CODE>=</CODE>, <CODE>==</CODE>, ... can be used in infix notation, which is more |
|||
convenient than Lisp notation <SAMP>`(+ x y)'</SAMP> or C notation <SAMP>`add(x,y,&z)'</SAMP>. |
|||
</UL> |
|||
|
|||
<P> |
|||
With these language features, there is no need for two separate languages, |
|||
one for the implementation of the library and one in which the library's users |
|||
can program. This means that a prototype implementation of an algorithm |
|||
can be integrated into the library immediately after it has been tested and |
|||
debugged. No need to rewrite it in a low-level language after having prototyped |
|||
in a high-level language. |
|||
|
|||
|
|||
|
|||
|
|||
<H2><A NAME="SEC61" HREF="cln_toc.html#TOC61">10.2 Memory efficiency</A></H2> |
|||
|
|||
<P> |
|||
In order to save memory allocations, CLN implements: |
|||
|
|||
|
|||
|
|||
<UL> |
|||
<LI> |
|||
|
|||
Object sharing: An operation like <CODE>x+0</CODE> returns <CODE>x</CODE> without copying |
|||
it. |
|||
<LI> |
|||
|
|||
<A NAME="IDX329"></A> |
|||
<A NAME="IDX330"></A> |
|||
Garbage collection: A reference counting mechanism makes sure that any |
|||
number object's storage is freed immediately when the last reference to the |
|||
object is gone. |
|||
<LI> |
|||
|
|||
Small integers are represented as immediate values instead of pointers |
|||
to heap allocated storage. This means that integers <CODE>> -2^29</CODE>, |
|||
<CODE>< 2^29</CODE> don't consume heap memory, unless they were explicitly allocated |
|||
on the heap. |
|||
</UL> |
|||
|
|||
|
|||
|
|||
<H2><A NAME="SEC62" HREF="cln_toc.html#TOC62">10.3 Speed efficiency</A></H2> |
|||
|
|||
<P> |
|||
Speed efficiency is obtained by the combination of the following tricks |
|||
and algorithms: |
|||
|
|||
|
|||
|
|||
<UL> |
|||
<LI> |
|||
|
|||
Small integers, being represented as immediate values, don't require |
|||
memory access, just a couple of instructions for each elementary operation. |
|||
<LI> |
|||
|
|||
The kernel of CLN has been written in assembly language for some CPUs |
|||
(<CODE>i386</CODE>, <CODE>m68k</CODE>, <CODE>sparc</CODE>, <CODE>mips</CODE>, <CODE>arm</CODE>). |
|||
<LI> |
|||
|
|||
On all CPUs, CLN may be configured to use the superefficient low-level |
|||
routines from GNU GMP version 3. |
|||
<LI> |
|||
|
|||
For large numbers, CLN uses, instead of the standard <CODE>O(N^2)</CODE> |
|||
algorithm, the Karatsuba multiplication, which is an |
|||
<CODE>O(N^1.6)</CODE> |
|||
algorithm. |
|||
<LI> |
|||
|
|||
For very large numbers (more than 12000 decimal digits), CLN uses |
|||
Schönhage-Strassen |
|||
<A NAME="IDX331"></A> |
|||
multiplication, which is an asymptotically optimal multiplication |
|||
algorithm. |
|||
<LI> |
|||
|
|||
These fast multiplication algorithms also give improvements in the speed |
|||
of division and radix conversion. |
|||
</UL> |
|||
|
|||
|
|||
|
|||
<H2><A NAME="SEC63" HREF="cln_toc.html#TOC63">10.4 Garbage collection</A></H2> |
|||
<P> |
|||
<A NAME="IDX332"></A> |
|||
|
|||
|
|||
<P> |
|||
All the number classes are reference count classes: They only contain a pointer |
|||
to an object in the heap. Upon construction, assignment and destruction of |
|||
number objects, only the objects' reference count are manipulated. |
|||
|
|||
|
|||
<P> |
|||
Memory occupied by number objects are automatically reclaimed as soon as |
|||
their reference count drops to zero. |
|||
|
|||
|
|||
<P> |
|||
For number rings, another strategy is implemented: There is a cache of, |
|||
for example, the modular integer rings. A modular integer ring is destroyed |
|||
only if its reference count dropped to zero and the cache is about to be |
|||
resized. The effect of this strategy is that recently used rings remain |
|||
cached, whereas undue memory consumption through cached rings is avoided. |
|||
|
|||
|
|||
<P><HR><P> |
|||
Go to the <A HREF="cln_1.html">first</A>, <A HREF="cln_9.html">previous</A>, <A HREF="cln_11.html">next</A>, <A HREF="cln_13.html">last</A> section, <A HREF="cln_toc.html">table of contents</A>. |
|||
</BODY> |
|||
</HTML> |
@ -1,476 +0,0 @@ |
|||
<HTML> |
|||
<HEAD> |
|||
<!-- Created by texi2html 1.56k from cln.texi on 28 August 2000 --> |
|||
|
|||
<TITLE>CLN, a Class Library for Numbers - 11. Using the library</TITLE> |
|||
</HEAD> |
|||
<BODY> |
|||
Go to the <A HREF="cln_1.html">first</A>, <A HREF="cln_10.html">previous</A>, <A HREF="cln_12.html">next</A>, <A HREF="cln_13.html">last</A> section, <A HREF="cln_toc.html">table of contents</A>. |
|||
<P><HR><P> |
|||
|
|||
|
|||
<H1><A NAME="SEC64" HREF="cln_toc.html#TOC64">11. Using the library</A></H1> |
|||
|
|||
<P> |
|||
For the following discussion, we will assume that you have installed |
|||
the CLN source in <CODE>$CLN_DIR</CODE> and built it in <CODE>$CLN_TARGETDIR</CODE>. |
|||
For example, for me it's <CODE>CLN_DIR="$HOME/cln"</CODE> and |
|||
<CODE>CLN_TARGETDIR="$HOME/cln/linuxelf"</CODE>. You might define these as |
|||
environment variables, or directly substitute the appropriate values. |
|||
|
|||
|
|||
|
|||
|
|||
<H2><A NAME="SEC65" HREF="cln_toc.html#TOC65">11.1 Compiler options</A></H2> |
|||
<P> |
|||
<A NAME="IDX333"></A> |
|||
|
|||
|
|||
<P> |
|||
Until you have installed CLN in a public place, the following options are |
|||
needed: |
|||
|
|||
|
|||
<P> |
|||
When you compile CLN application code, add the flags |
|||
|
|||
<PRE> |
|||
-I$CLN_DIR/include -I$CLN_TARGETDIR/include |
|||
</PRE> |
|||
|
|||
<P> |
|||
to the C++ compiler's command line (<CODE>make</CODE> variable CFLAGS or CXXFLAGS). |
|||
When you link CLN application code to form an executable, add the flags |
|||
|
|||
<PRE> |
|||
$CLN_TARGETDIR/src/libcln.a |
|||
</PRE> |
|||
|
|||
<P> |
|||
to the C/C++ compiler's command line (<CODE>make</CODE> variable LIBS). |
|||
|
|||
|
|||
<P> |
|||
If you did a <CODE>make install</CODE>, the include files are installed in a |
|||
public directory (normally <CODE>/usr/local/include</CODE>), hence you don't |
|||
need special flags for compiling. The library has been installed to a |
|||
public directory as well (normally <CODE>/usr/local/lib</CODE>), hence when |
|||
linking a CLN application it is sufficient to give the flag <CODE>-lcln</CODE>. |
|||
|
|||
|
|||
|
|||
|
|||
<H2><A NAME="SEC66" HREF="cln_toc.html#TOC66">11.2 Compatibility to old CLN versions</A></H2> |
|||
<P> |
|||
<A NAME="IDX334"></A> |
|||
<A NAME="IDX335"></A> |
|||
|
|||
|
|||
<P> |
|||
As of CLN version 1.1 all non-macro identifiers were hidden in namespace |
|||
<CODE>cln</CODE> in order to avoid potential name clashes with other C++ |
|||
libraries. If you have an old application, you will have to manually |
|||
port it to the new scheme. The following principles will help during |
|||
the transition: |
|||
|
|||
<UL> |
|||
<LI> |
|||
|
|||
All headers are now in a separate subdirectory. Instead of including |
|||
<CODE>cl_</CODE><VAR>something</VAR><CODE>.h</CODE>, include |
|||
<CODE>cln/</CODE><VAR>something</VAR><CODE>.h</CODE> now. |
|||
<LI> |
|||
|
|||
All public identifiers (typenames and functions) have lost their |
|||
<CODE>cl_</CODE> prefix. Exceptions are all the typenames of number types, |
|||
(cl_N, cl_I, cl_MI, ...), rings, symbolic types (cl_string, |
|||
cl_symbol) and polynomials (cl_UP_<VAR>type</VAR>). (This is because their |
|||
names would not be mnemonic enough once the namespace <CODE>cln</CODE> is |
|||
imported. Even in a namespace we favor <CODE>cl_N</CODE> over <CODE>N</CODE>.) |
|||
<LI> |
|||
|
|||
All public <EM>functions</EM> that had by a <CODE>cl_</CODE> in their name still |
|||
carry that <CODE>cl_</CODE> if it is intrinsic part of a typename (as in |
|||
<CODE>cl_I_to_int ()</CODE>). |
|||
</UL> |
|||
|
|||
<P> |
|||
When developing other libraries, please keep in mind not to import the |
|||
namespace <CODE>cln</CODE> in one of your public header files by saying |
|||
<CODE>using namespace cln;</CODE>. This would propagate to other applications |
|||
and can cause name clashes there. |
|||
|
|||
|
|||
|
|||
|
|||
<H2><A NAME="SEC67" HREF="cln_toc.html#TOC67">11.3 Include files</A></H2> |
|||
<P> |
|||
<A NAME="IDX336"></A> |
|||
<A NAME="IDX337"></A> |
|||
|
|||
|
|||
<P> |
|||
Here is a summary of the include files and their contents. |
|||
|
|||
|
|||
<DL COMPACT> |
|||
|
|||
<DT><CODE><cln/object.h></CODE> |
|||
<DD> |
|||
General definitions, reference counting, garbage collection. |
|||
<DT><CODE><cln/number.h></CODE> |
|||
<DD> |
|||
The class cl_number. |
|||
<DT><CODE><cln/complex.h></CODE> |
|||
<DD> |
|||
Functions for class cl_N, the complex numbers. |
|||
<DT><CODE><cln/real.h></CODE> |
|||
<DD> |
|||
Functions for class cl_R, the real numbers. |
|||
<DT><CODE><cln/float.h></CODE> |
|||
<DD> |
|||
Functions for class cl_F, the floats. |
|||
<DT><CODE><cln/sfloat.h></CODE> |
|||
<DD> |
|||
Functions for class cl_SF, the short-floats. |
|||
<DT><CODE><cln/ffloat.h></CODE> |
|||
<DD> |
|||
Functions for class cl_FF, the single-floats. |
|||
<DT><CODE><cln/dfloat.h></CODE> |
|||
<DD> |
|||
Functions for class cl_DF, the double-floats. |
|||
<DT><CODE><cln/lfloat.h></CODE> |
|||
<DD> |
|||
Functions for class cl_LF, the long-floats. |
|||
<DT><CODE><cln/rational.h></CODE> |
|||
<DD> |
|||
Functions for class cl_RA, the rational numbers. |
|||
<DT><CODE><cln/integer.h></CODE> |
|||
<DD> |
|||
Functions for class cl_I, the integers. |
|||
<DT><CODE><cln/io.h></CODE> |
|||
<DD> |
|||
Input/Output. |
|||
<DT><CODE><cln/complex_io.h></CODE> |
|||
<DD> |
|||
Input/Output for class cl_N, the complex numbers. |
|||
<DT><CODE><cln/real_io.h></CODE> |
|||
<DD> |
|||
Input/Output for class cl_R, the real numbers. |
|||
<DT><CODE><cln/float_io.h></CODE> |
|||
<DD> |
|||
Input/Output for class cl_F, the floats. |
|||
<DT><CODE><cln/sfloat_io.h></CODE> |
|||
<DD> |
|||
Input/Output for class cl_SF, the short-floats. |
|||
<DT><CODE><cln/ffloat_io.h></CODE> |
|||
<DD> |
|||
Input/Output for class cl_FF, the single-floats. |
|||
<DT><CODE><cln/dfloat_io.h></CODE> |
|||
<DD> |
|||
Input/Output for class cl_DF, the double-floats. |
|||
<DT><CODE><cln/lfloat_io.h></CODE> |
|||
<DD> |
|||
Input/Output for class cl_LF, the long-floats. |
|||
<DT><CODE><cln/rational_io.h></CODE> |
|||
<DD> |
|||
Input/Output for class cl_RA, the rational numbers. |
|||
<DT><CODE><cln/integer_io.h></CODE> |
|||
<DD> |
|||
Input/Output for class cl_I, the integers. |
|||
<DT><CODE><cln/input.h></CODE> |
|||
<DD> |
|||
Flags for customizing input operations. |
|||
<DT><CODE><cln/output.h></CODE> |
|||
<DD> |
|||
Flags for customizing output operations. |
|||
<DT><CODE><cln/malloc.h></CODE> |
|||
<DD> |
|||
<CODE>malloc_hook</CODE>, <CODE>free_hook</CODE>. |
|||
<DT><CODE><cln/abort.h></CODE> |
|||
<DD> |
|||
<CODE>cl_abort</CODE>. |
|||
<DT><CODE><cln/condition.h></CODE> |
|||
<DD> |
|||
Conditions/exceptions. |
|||
<DT><CODE><cln/string.h></CODE> |
|||
<DD> |
|||
Strings. |
|||
<DT><CODE><cln/symbol.h></CODE> |
|||
<DD> |
|||
Symbols. |
|||
<DT><CODE><cln/proplist.h></CODE> |
|||
<DD> |
|||
Property lists. |
|||
<DT><CODE><cln/ring.h></CODE> |
|||
<DD> |
|||
General rings. |
|||
<DT><CODE><cln/null_ring.h></CODE> |
|||
<DD> |
|||
The null ring. |
|||
<DT><CODE><cln/complex_ring.h></CODE> |
|||
<DD> |
|||
The ring of complex numbers. |
|||
<DT><CODE><cln/real_ring.h></CODE> |
|||
<DD> |
|||
The ring of real numbers. |
|||
<DT><CODE><cln/rational_ring.h></CODE> |
|||
<DD> |
|||
The ring of rational numbers. |
|||
<DT><CODE><cln/integer_ring.h></CODE> |
|||
<DD> |
|||
The ring of integers. |
|||
<DT><CODE><cln/numtheory.h></CODE> |
|||
<DD> |
|||
Number threory functions. |
|||
<DT><CODE><cln/modinteger.h></CODE> |
|||
<DD> |
|||
Modular integers. |
|||
<DT><CODE><cln/V.h></CODE> |
|||
<DD> |
|||
Vectors. |
|||
<DT><CODE><cln/GV.h></CODE> |
|||
<DD> |
|||
General vectors. |
|||
<DT><CODE><cln/GV_number.h></CODE> |
|||
<DD> |
|||
General vectors over cl_number. |
|||
<DT><CODE><cln/GV_complex.h></CODE> |
|||
<DD> |
|||
General vectors over cl_N. |
|||
<DT><CODE><cln/GV_real.h></CODE> |
|||
<DD> |
|||
General vectors over cl_R. |
|||
<DT><CODE><cln/GV_rational.h></CODE> |
|||
<DD> |
|||
General vectors over cl_RA. |
|||
<DT><CODE><cln/GV_integer.h></CODE> |
|||
<DD> |
|||
General vectors over cl_I. |
|||
<DT><CODE><cln/GV_modinteger.h></CODE> |
|||
<DD> |
|||
General vectors of modular integers. |
|||
<DT><CODE><cln/SV.h></CODE> |
|||
<DD> |
|||
Simple vectors. |
|||
<DT><CODE><cln/SV_number.h></CODE> |
|||
<DD> |
|||
Simple vectors over cl_number. |
|||
<DT><CODE><cln/SV_complex.h></CODE> |
|||
<DD> |
|||
Simple vectors over cl_N. |
|||
<DT><CODE><cln/SV_real.h></CODE> |
|||
<DD> |
|||
Simple vectors over cl_R. |
|||
<DT><CODE><cln/SV_rational.h></CODE> |
|||
<DD> |
|||
Simple vectors over cl_RA. |
|||
<DT><CODE><cln/SV_integer.h></CODE> |
|||
<DD> |
|||
Simple vectors over cl_I. |
|||
<DT><CODE><cln/SV_ringelt.h></CODE> |
|||
<DD> |
|||
Simple vectors of general ring elements. |
|||
<DT><CODE><cln/univpoly.h></CODE> |
|||
<DD> |
|||
Univariate polynomials. |
|||
<DT><CODE><cln/univpoly_integer.h></CODE> |
|||
<DD> |
|||
Univariate polynomials over the integers. |
|||
<DT><CODE><cln/univpoly_rational.h></CODE> |
|||
<DD> |
|||
Univariate polynomials over the rational numbers. |
|||
<DT><CODE><cln/univpoly_real.h></CODE> |
|||
<DD> |
|||
Univariate polynomials over the real numbers. |
|||
<DT><CODE><cln/univpoly_complex.h></CODE> |
|||
<DD> |
|||
Univariate polynomials over the complex numbers. |
|||
<DT><CODE><cln/univpoly_modint.h></CODE> |
|||
<DD> |
|||
Univariate polynomials over modular integer rings. |
|||
<DT><CODE><cln/timing.h></CODE> |
|||
<DD> |
|||
Timing facilities. |
|||
<DT><CODE><cln/cln.h></CODE> |
|||
<DD> |
|||
Includes all of the above. |
|||
</DL> |
|||
|
|||
|
|||
|
|||
<H2><A NAME="SEC68" HREF="cln_toc.html#TOC68">11.4 An Example</A></H2> |
|||
|
|||
<P> |
|||
A function which computes the nth Fibonacci number can be written as follows. |
|||
<A NAME="IDX338"></A> |
|||
|
|||
|
|||
|
|||
<PRE> |
|||
#include <cln/integer.h> |
|||
#include <cln/real.h> |
|||
using namespace cln; |
|||
|
|||
// Returns F_n, computed as the nearest integer to |
|||
// ((1+sqrt(5))/2)^n/sqrt(5). Assume n>=0. |
|||
const cl_I fibonacci (int n) |
|||
{ |
|||
// Need a precision of ((1+sqrt(5))/2)^-n. |
|||
cl_float_format_t prec = cl_float_format((int)(0.208987641*n+5)); |
|||
cl_R sqrt5 = sqrt(cl_float(5,prec)); |
|||
cl_R phi = (1+sqrt5)/2; |
|||
return round1( expt(phi,n)/sqrt5 ); |
|||
} |
|||
</PRE> |
|||
|
|||
<P> |
|||
Let's explain what is going on in detail. |
|||
|
|||
|
|||
<P> |
|||
The include file <CODE><cln/integer.h></CODE> is necessary because the type |
|||
<CODE>cl_I</CODE> is used in the function, and the include file <CODE><cln/real.h></CODE> |
|||
is needed for the type <CODE>cl_R</CODE> and the floating point number functions. |
|||
The order of the include files does not matter. In order not to write out |
|||
<CODE>cln::</CODE><VAR>foo</VAR> we can safely import the whole namespace <CODE>cln</CODE>. |
|||
|
|||
|
|||
<P> |
|||
Then comes the function declaration. The argument is an <CODE>int</CODE>, the |
|||
result an integer. The return type is defined as <SAMP>`const cl_I'</SAMP>, not |
|||
simply <SAMP>`cl_I'</SAMP>, because that allows the compiler to detect typos like |
|||
<SAMP>`fibonacci(n) = 100'</SAMP>. It would be possible to declare the return |
|||
type as <CODE>const cl_R</CODE> (real number) or even <CODE>const cl_N</CODE> (complex |
|||
number). We use the most specialized possible return type because functions |
|||
which call <SAMP>`fibonacci'</SAMP> will be able to profit from the compiler's type |
|||
analysis: Adding two integers is slightly more efficient than adding the |
|||
same objects declared as complex numbers, because it needs less type |
|||
dispatch. Also, when linking to CLN as a non-shared library, this minimizes |
|||
the size of the resulting executable program. |
|||
|
|||
|
|||
<P> |
|||
The result will be computed as expt(phi,n)/sqrt(5), rounded to the nearest |
|||
integer. In order to get a correct result, the absolute error should be less |
|||
than 1/2, i.e. the relative error should be less than sqrt(5)/(2*expt(phi,n)). |
|||
To this end, the first line computes a floating point precision for sqrt(5) |
|||
and phi. |
|||
|
|||
|
|||
<P> |
|||
Then sqrt(5) is computed by first converting the integer 5 to a floating point |
|||
number and than taking the square root. The converse, first taking the square |
|||
root of 5, and then converting to the desired precision, would not work in |
|||
CLN: The square root would be computed to a default precision (normally |
|||
single-float precision), and the following conversion could not help about |
|||
the lacking accuracy. This is because CLN is not a symbolic computer algebra |
|||
system and does not represent sqrt(5) in a non-numeric way. |
|||
|
|||
|
|||
<P> |
|||
The type <CODE>cl_R</CODE> for sqrt5 and, in the following line, phi is the only |
|||
possible choice. You cannot write <CODE>cl_F</CODE> because the C++ compiler can |
|||
only infer that <CODE>cl_float(5,prec)</CODE> is a real number. You cannot write |
|||
<CODE>cl_N</CODE> because a <SAMP>`round1'</SAMP> does not exist for general complex |
|||
numbers. |
|||
|
|||
|
|||
<P> |
|||
When the function returns, all the local variables in the function are |
|||
automatically reclaimed (garbage collected). Only the result survives and |
|||
gets passed to the caller. |
|||
|
|||
|
|||
<P> |
|||
The file <CODE>fibonacci.cc</CODE> in the subdirectory <CODE>examples</CODE> |
|||
contains this implementation together with an even faster algorithm. |
|||
|
|||
|
|||
|
|||
|
|||
<H2><A NAME="SEC69" HREF="cln_toc.html#TOC69">11.5 Debugging support</A></H2> |
|||
<P> |
|||
<A NAME="IDX339"></A> |
|||
|
|||
|
|||
<P> |
|||
When debugging a CLN application with GNU <CODE>gdb</CODE>, two facilities are |
|||
available from the library: |
|||
|
|||
|
|||
|
|||
<UL> |
|||
<LI>The library does type checks, range checks, consistency checks at |
|||
|
|||
many places. When one of these fails, the function <CODE>cl_abort()</CODE> is |
|||
called. Its default implementation is to perform an <CODE>exit(1)</CODE>, so |
|||
you won't have a core dump. But for debugging, it is best to set a |
|||
breakpoint at this function: |
|||
|
|||
<PRE> |
|||
(gdb) break cl_abort |
|||
</PRE> |
|||
|
|||
When this breakpoint is hit, look at the stack's backtrace: |
|||
|
|||
<PRE> |
|||
(gdb) where |
|||
</PRE> |
|||
|
|||
<LI>The debugger's normal <CODE>print</CODE> command doesn't know about |
|||
|
|||
CLN's types and therefore prints mostly useless hexadecimal addresses. |
|||
CLN offers a function <CODE>cl_print</CODE>, callable from the debugger, |
|||
for printing number objects. In order to get this function, you have |
|||
to define the macro <SAMP>`CL_DEBUG'</SAMP> and then include all the header files |
|||
for which you want <CODE>cl_print</CODE> debugging support. For example: |
|||
<A NAME="IDX340"></A> |
|||
|
|||
<PRE> |
|||
#define CL_DEBUG |
|||
#include <cln/string.h> |
|||
</PRE> |
|||
|
|||
Now, if you have in your program a variable <CODE>cl_string s</CODE>, and |
|||
inspect it under <CODE>gdb</CODE>, the output may look like this: |
|||
|
|||
<PRE> |
|||
(gdb) print s |
|||
$7 = {<cl_gcpointer> = { = {pointer = 0x8055b60, heappointer = 0x8055b60, |
|||
word = 134568800}}, } |
|||
(gdb) call cl_print(s) |
|||
(cl_string) "" |
|||
$8 = 134568800 |
|||
</PRE> |
|||
|
|||
Note that the output of <CODE>cl_print</CODE> goes to the program's error output, |
|||
not to gdb's standard output. |
|||
|
|||
Note, however, that the above facility does not work with all CLN types, |
|||
only with number objects and similar. Therefore CLN offers a member function |
|||
<CODE>debug_print()</CODE> on all CLN types. The same macro <SAMP>`CL_DEBUG'</SAMP> |
|||
is needed for this member function to be implemented. Under <CODE>gdb</CODE>, |
|||
you call it like this: |
|||
<A NAME="IDX341"></A> |
|||
|
|||
<PRE> |
|||
(gdb) print s |
|||
$7 = {<cl_gcpointer> = { = {pointer = 0x8055b60, heappointer = 0x8055b60, |
|||
word = 134568800}}, } |
|||
(gdb) call s.debug_print() |
|||
(cl_string) "" |
|||
(gdb) define cprint |
|||
>call ($1).debug_print() |
|||
>end |
|||
(gdb) cprint s |
|||
(cl_string) "" |
|||
</PRE> |
|||
|
|||
Unfortunately, this feature does not seem to work under all circumstances. |
|||
</UL> |
|||
|
|||
<P><HR><P> |
|||
Go to the <A HREF="cln_1.html">first</A>, <A HREF="cln_10.html">previous</A>, <A HREF="cln_12.html">next</A>, <A HREF="cln_13.html">last</A> section, <A HREF="cln_toc.html">table of contents</A>. |
|||
</BODY> |
|||
</HTML> |
@ -1,108 +0,0 @@ |
|||
<HTML> |
|||
<HEAD> |
|||
<!-- Created by texi2html 1.56k from cln.texi on 28 August 2000 --> |
|||
|
|||
<TITLE>CLN, a Class Library for Numbers - 12. Customizing</TITLE> |
|||
</HEAD> |
|||
<BODY> |
|||
Go to the <A HREF="cln_1.html">first</A>, <A HREF="cln_11.html">previous</A>, <A HREF="cln_13.html">next</A>, <A HREF="cln_13.html">last</A> section, <A HREF="cln_toc.html">table of contents</A>. |
|||
<P><HR><P> |
|||
|
|||
|
|||
<H1><A NAME="SEC70" HREF="cln_toc.html#TOC70">12. Customizing</A></H1> |
|||
<P> |
|||
<A NAME="IDX342"></A> |
|||
|
|||
|
|||
|
|||
|
|||
<H2><A NAME="SEC71" HREF="cln_toc.html#TOC71">12.1 Error handling</A></H2> |
|||
|
|||
<P> |
|||
When a fatal error occurs, an error message is output to the standard error |
|||
output stream, and the function <CODE>cl_abort</CODE> is called. The default |
|||
version of this function (provided in the library) terminates the application. |
|||
To catch such a fatal error, you need to define the function <CODE>cl_abort</CODE> |
|||
yourself, with the prototype |
|||
|
|||
<PRE> |
|||
#include <cln/abort.h> |
|||
void cl_abort (void); |
|||
</PRE> |
|||
|
|||
<P> |
|||
<A NAME="IDX343"></A> |
|||
This function must not return control to its caller. |
|||
|
|||
|
|||
|
|||
|
|||
<H2><A NAME="SEC72" HREF="cln_toc.html#TOC72">12.2 Floating-point underflow</A></H2> |
|||
<P> |
|||
<A NAME="IDX344"></A> |
|||
|
|||
|
|||
<P> |
|||
Floating point underflow denotes the situation when a floating-point number |
|||
is to be created which is so close to <CODE>0</CODE> that its exponent is too |
|||
low to be represented internally. By default, this causes a fatal error. |
|||
If you set the global variable |
|||
|
|||
<PRE> |
|||
cl_boolean cl_inhibit_floating_point_underflow |
|||
</PRE> |
|||
|
|||
<P> |
|||
to <CODE>cl_true</CODE>, the error will be inhibited, and a floating-point zero |
|||
will be generated instead. The default value of |
|||
<CODE>cl_inhibit_floating_point_underflow</CODE> is <CODE>cl_false</CODE>. |
|||
|
|||
|
|||
|
|||
|
|||
<H2><A NAME="SEC73" HREF="cln_toc.html#TOC73">12.3 Customizing I/O</A></H2> |
|||
|
|||
<P> |
|||
The output of the function <CODE>fprint</CODE> may be customized by changing the |
|||
value of the global variable <CODE>default_print_flags</CODE>. |
|||
<A NAME="IDX345"></A> |
|||
|
|||
|
|||
|
|||
|
|||
<H2><A NAME="SEC74" HREF="cln_toc.html#TOC74">12.4 Customizing the memory allocator</A></H2> |
|||
|
|||
<P> |
|||
Every memory allocation of CLN is done through the function pointer |
|||
<CODE>malloc_hook</CODE>. Freeing of this memory is done through the function |
|||
pointer <CODE>free_hook</CODE>. The default versions of these functions, |
|||
provided in the library, call <CODE>malloc</CODE> and <CODE>free</CODE> and check |
|||
the <CODE>malloc</CODE> result against <CODE>NULL</CODE>. |
|||
If you want to provide another memory allocator, you need to define |
|||
the variables <CODE>malloc_hook</CODE> and <CODE>free_hook</CODE> yourself, |
|||
like this: |
|||
|
|||
<PRE> |
|||
#include <cln/malloc.h> |
|||
namespace cln { |
|||
void* (*malloc_hook) (size_t size) = ...; |
|||
void (*free_hook) (void* ptr) = ...; |
|||
} |
|||
</PRE> |
|||
|
|||
<P> |
|||
<A NAME="IDX346"></A> |
|||
<A NAME="IDX347"></A> |
|||
The <CODE>cl_malloc_hook</CODE> function must not return a <CODE>NULL</CODE> pointer. |
|||
|
|||
|
|||
<P> |
|||
It is not possible to change the memory allocator at runtime, because |
|||
it is already called at program startup by the constructors of some |
|||
global variables. |
|||
|
|||
|
|||
<P><HR><P> |
|||
Go to the <A HREF="cln_1.html">first</A>, <A HREF="cln_11.html">previous</A>, <A HREF="cln_13.html">next</A>, <A HREF="cln_13.html">last</A> section, <A HREF="cln_toc.html">table of contents</A>. |
|||
</BODY> |
|||
</HTML> |
@ -1,22 +0,0 @@ |
|||
<HTML> |
|||
<HEAD> |
|||
<!-- Created by texi2html 1.56k from cln.texi on 28 August 2000 --> |
|||
|
|||
<TITLE>CLN, a Class Library for Numbers - Index</TITLE> |
|||
</HEAD> |
|||
<BODY> |
|||
Go to the <A HREF="cln_1.html">first</A>, <A HREF="cln_12.html">previous</A>, next, last section, <A HREF="cln_toc.html">table of contents</A>. |
|||
<P><HR><P> |
|||
|
|||
|
|||
<H1><A NAME="SEC75" HREF="cln_toc.html#TOC75">Index</A></H1> |
|||
|
|||
<P> |
|||
Jump to: |
|||
<P> |
|||
|
|||
|
|||
<P><HR><P> |
|||
Go to the <A HREF="cln_1.html">first</A>, <A HREF="cln_12.html">previous</A>, next, last section, <A HREF="cln_toc.html">table of contents</A>. |
|||
</BODY> |
|||
</HTML> |
@ -1,279 +0,0 @@ |
|||
<HTML> |
|||
<HEAD> |
|||
<!-- Created by texi2html 1.56k from cln.texi on 28 August 2000 --> |
|||
|
|||
<TITLE>CLN, a Class Library for Numbers - 2. Installation</TITLE> |
|||
</HEAD> |
|||
<BODY> |
|||
Go to the <A HREF="cln_1.html">first</A>, <A HREF="cln_1.html">previous</A>, <A HREF="cln_3.html">next</A>, <A HREF="cln_13.html">last</A> section, <A HREF="cln_toc.html">table of contents</A>. |
|||
<P><HR><P> |
|||
|
|||
|
|||
<H1><A NAME="SEC2" HREF="cln_toc.html#TOC2">2. Installation</A></H1> |
|||
|
|||
<P> |
|||
This section describes how to install the CLN package on your system. |
|||
|
|||
|
|||
|
|||
|
|||
<H2><A NAME="SEC3" HREF="cln_toc.html#TOC3">2.1 Prerequisites</A></H2> |
|||
|
|||
|
|||
|
|||
<H3><A NAME="SEC4" HREF="cln_toc.html#TOC4">2.1.1 C++ compiler</A></H3> |
|||
|
|||
<P> |
|||
To build CLN, you need a C++ compiler. |
|||
Actually, you need GNU <CODE>g++ 2.90</CODE> or newer, the EGCS compilers will |
|||
do. |
|||
I recommend GNU <CODE>g++ 2.95</CODE> or newer. |
|||
|
|||
|
|||
<P> |
|||
The following C++ features are used: |
|||
classes, member functions, overloading of functions and operators, |
|||
constructors and destructors, inline, const, multiple inheritance, |
|||
templates and namespaces. |
|||
|
|||
|
|||
<P> |
|||
The following C++ features are not used: |
|||
<CODE>new</CODE>, <CODE>delete</CODE>, virtual inheritance, exceptions. |
|||
|
|||
|
|||
<P> |
|||
CLN relies on semi-automatic ordering of initializations |
|||
of static and global variables, a feature which I could |
|||
implement for GNU g++ only. |
|||
|
|||
|
|||
|
|||
|
|||
<H3><A NAME="SEC5" HREF="cln_toc.html#TOC5">2.1.2 Make utility</A></H3> |
|||
<P> |
|||
<A NAME="IDX4"></A> |
|||
|
|||
|
|||
<P> |
|||
To build CLN, you also need to have GNU <CODE>make</CODE> installed. |
|||
|
|||
|
|||
|
|||
|
|||
<H3><A NAME="SEC6" HREF="cln_toc.html#TOC6">2.1.3 Sed utility</A></H3> |
|||
<P> |
|||
<A NAME="IDX5"></A> |
|||
|
|||
|
|||
<P> |
|||
To build CLN on HP-UX, you also need to have GNU <CODE>sed</CODE> installed. |
|||
This is because the libtool script, which creates the CLN library, relies |
|||
on <CODE>sed</CODE>, and the vendor's <CODE>sed</CODE> utility on these systems is too |
|||
limited. |
|||
|
|||
|
|||
|
|||
|
|||
<H2><A NAME="SEC7" HREF="cln_toc.html#TOC7">2.2 Building the library</A></H2> |
|||
|
|||
<P> |
|||
As with any autoconfiguring GNU software, installation is as easy as this: |
|||
|
|||
|
|||
|
|||
<PRE> |
|||
$ ./configure |
|||
$ make |
|||
$ make check |
|||
</PRE> |
|||
|
|||
<P> |
|||
If on your system, <SAMP>`make'</SAMP> is not GNU <CODE>make</CODE>, you have to use |
|||
<SAMP>`gmake'</SAMP> instead of <SAMP>`make'</SAMP> above. |
|||
|
|||
|
|||
<P> |
|||
The <CODE>configure</CODE> command checks out some features of your system and |
|||
C++ compiler and builds the <CODE>Makefile</CODE>s. The <CODE>make</CODE> command |
|||
builds the library. This step may take 4 hours on an average workstation. |
|||
The <CODE>make check</CODE> runs some test to check that no important subroutine |
|||
has been miscompiled. |
|||
|
|||
|
|||
<P> |
|||
The <CODE>configure</CODE> command accepts options. To get a summary of them, try |
|||
|
|||
|
|||
|
|||
<PRE> |
|||
$ ./configure --help |
|||
</PRE> |
|||
|
|||
<P> |
|||
Some of the options are explained in detail in the <SAMP>`INSTALL.generic'</SAMP> file. |
|||
|
|||
|
|||
<P> |
|||
You can specify the C compiler, the C++ compiler and their options through |
|||
the following environment variables when running <CODE>configure</CODE>: |
|||
|
|||
|
|||
<DL COMPACT> |
|||
|
|||
<DT><CODE>CC</CODE> |
|||
<DD> |
|||
Specifies the C compiler. |
|||
|
|||
<DT><CODE>CFLAGS</CODE> |
|||
<DD> |
|||
Flags to be given to the C compiler when compiling programs (not when linking). |
|||
|
|||
<DT><CODE>CXX</CODE> |
|||
<DD> |
|||
Specifies the C++ compiler. |
|||
|
|||
<DT><CODE>CXXFLAGS</CODE> |
|||
<DD> |
|||
Flags to be given to the C++ compiler when compiling programs (not when linking). |
|||
</DL> |
|||
|
|||
<P> |
|||
Examples: |
|||
|
|||
|
|||
|
|||
<PRE> |
|||
$ CC="gcc" CFLAGS="-O" CXX="g++" CXXFLAGS="-O" ./configure |
|||
$ CC="gcc -V egcs-2.91.60" CFLAGS="-O -g" \ |
|||
CXX="g++ -V egcs-2.91.60" CXXFLAGS="-O -g" ./configure |
|||
$ CC="gcc -V 2.95.2" CFLAGS="-O2 -fno-exceptions" \ |
|||
CXX="g++ -V 2.95.2" CFLAGS="-O2 -fno-exceptions" ./configure |
|||
</PRE> |
|||
|
|||
<P> |
|||
Note that for these environment variables to take effect, you have to set |
|||
them (assuming a Bourne-compatible shell) on the same line as the |
|||
<CODE>configure</CODE> command. If you made the settings in earlier shell |
|||
commands, you have to <CODE>export</CODE> the environment variables before |
|||
calling <CODE>configure</CODE>. In a <CODE>csh</CODE> shell, you have to use the |
|||
<SAMP>`setenv'</SAMP> command for setting each of the environment variables. |
|||
|
|||
|
|||
<P> |
|||
Currently CLN works only with the GNU <CODE>g++</CODE> compiler, and only in |
|||
optimizing mode. So you should specify at least <CODE>-O</CODE> in the CXXFLAGS, |
|||
or no CXXFLAGS at all. (If CXXFLAGS is not set, CLN will use <CODE>-O</CODE>.) |
|||
|
|||
|
|||
<P> |
|||
If you use <CODE>g++</CODE> version 2.8.x or egcs-2.91.x (a.k.a. egcs-1.1) or |
|||
gcc-2.95.x, I recommend adding <SAMP>`-fno-exceptions'</SAMP> to the CXXFLAGS. |
|||
This will likely generate better code. |
|||
|
|||
|
|||
<P> |
|||
If you use <CODE>g++</CODE> version egcs-2.91.x (egcs-1.1) or gcc-2.95.x on Sparc, |
|||
add either <SAMP>`-O'</SAMP>, <SAMP>`-O1'</SAMP> or <SAMP>`-O2 -fno-schedule-insns'</SAMP> to the |
|||
CXXFLAGS. With full <SAMP>`-O2'</SAMP>, <CODE>g++</CODE> miscompiles the division routines. |
|||
Also, if you have <CODE>g++</CODE> version egcs-1.1.1 or older on Sparc, you must |
|||
specify <SAMP>`--disable-shared'</SAMP> because <CODE>g++</CODE> would miscompile parts of |
|||
the library. |
|||
|
|||
|
|||
<P> |
|||
By default, both a shared and a static library are built. You can build |
|||
CLN as a static (or shared) library only, by calling <CODE>configure</CODE> with |
|||
the option <SAMP>`--disable-shared'</SAMP> (or <SAMP>`--disable-static'</SAMP>). While |
|||
shared libraries are usually more convenient to use, they may not work |
|||
on all architectures. Try disabling them if you run into linker |
|||
problems. Also, they are generally somewhat slower than static |
|||
libraries so runtime-critical applications should be linked statically. |
|||
|
|||
|
|||
|
|||
|
|||
<H3><A NAME="SEC8" HREF="cln_toc.html#TOC8">2.2.1 Using the GNU MP Library</A></H3> |
|||
<P> |
|||
<A NAME="IDX6"></A> |
|||
|
|||
|
|||
<P> |
|||
Starting with version 1.1, CLN may be configured to make use of a |
|||
preinstalled <CODE>gmp</CODE> library. Please make sure that you have at |
|||
least <CODE>gmp</CODE> version 3.0 installed since earlier versions are |
|||
unsupported and likely not to work. Enabling this feature by calling |
|||
<CODE>configure</CODE> with the option <SAMP>`--with-gmp'</SAMP> is known to be quite |
|||
a boost for CLN's performance. |
|||
|
|||
|
|||
<P> |
|||
If you have installed the <CODE>gmp</CODE> library and its header file in |
|||
some place where your compiler cannot find it by default, you must help |
|||
<CODE>configure</CODE> by setting <CODE>CPPFLAGS</CODE> and <CODE>LDFLAGS</CODE>. Here is |
|||
an example: |
|||
|
|||
|
|||
|
|||
<PRE> |
|||
$ CC="gcc" CFLAGS="-O2" CXX="g++" CXXFLAGS="-O2 -fno-exceptions" \ |
|||
CPPFLAGS="-I/opt/gmp/include" LDFLAGS="-L/opt/gmp/lib" ./configure --with-gmp |
|||
</PRE> |
|||
|
|||
|
|||
|
|||
<H2><A NAME="SEC9" HREF="cln_toc.html#TOC9">2.3 Installing the library</A></H2> |
|||
<P> |
|||
<A NAME="IDX7"></A> |
|||
|
|||
|
|||
<P> |
|||
As with any autoconfiguring GNU software, installation is as easy as this: |
|||
|
|||
|
|||
|
|||
<PRE> |
|||
$ make install |
|||
</PRE> |
|||
|
|||
<P> |
|||
The <SAMP>`make install'</SAMP> command installs the library and the include files |
|||
into public places (<TT>`/usr/local/lib/'</TT> and <TT>`/usr/local/include/'</TT>, |
|||
if you haven't specified a <CODE>--prefix</CODE> option to <CODE>configure</CODE>). |
|||
This step may require superuser privileges. |
|||
|
|||
|
|||
<P> |
|||
If you have already built the library and wish to install it, but didn't |
|||
specify <CODE>--prefix=...</CODE> at configure time, just re-run |
|||
<CODE>configure</CODE>, giving it the same options as the first time, plus |
|||
the <CODE>--prefix=...</CODE> option. |
|||
|
|||
|
|||
|
|||
|
|||
<H2><A NAME="SEC10" HREF="cln_toc.html#TOC10">2.4 Cleaning up</A></H2> |
|||
|
|||
<P> |
|||
You can remove system-dependent files generated by <CODE>make</CODE> through |
|||
|
|||
|
|||
|
|||
<PRE> |
|||
$ make clean |
|||
</PRE> |
|||
|
|||
<P> |
|||
You can remove all files generated by <CODE>make</CODE>, thus reverting to a |
|||
virgin distribution of CLN, through |
|||
|
|||
|
|||
|
|||
<PRE> |
|||
$ make distclean |
|||
</PRE> |
|||
|
|||
<P><HR><P> |
|||
Go to the <A HREF="cln_1.html">first</A>, <A HREF="cln_1.html">previous</A>, <A HREF="cln_3.html">next</A>, <A HREF="cln_13.html">last</A> section, <A HREF="cln_toc.html">table of contents</A>. |
|||
</BODY> |
|||
</HTML> |
@ -1,401 +0,0 @@ |
|||
<HTML> |
|||
<HEAD> |
|||
<!-- Created by texi2html 1.56k from cln.texi on 28 August 2000 --> |
|||
|
|||
<TITLE>CLN, a Class Library for Numbers - 3. Ordinary number types</TITLE> |
|||
</HEAD> |
|||
<BODY> |
|||
Go to the <A HREF="cln_1.html">first</A>, <A HREF="cln_2.html">previous</A>, <A HREF="cln_4.html">next</A>, <A HREF="cln_13.html">last</A> section, <A HREF="cln_toc.html">table of contents</A>. |
|||
<P><HR><P> |
|||
|
|||
|
|||
<H1><A NAME="SEC11" HREF="cln_toc.html#TOC11">3. Ordinary number types</A></H1> |
|||
|
|||
<P> |
|||
CLN implements the following class hierarchy: |
|||
|
|||
|
|||
|
|||
<PRE> |
|||
Number |
|||
cl_number |
|||
<cln/number.h> |
|||
| |
|||
| |
|||
Real or complex number |
|||
cl_N |
|||
<cln/complex.h> |
|||
| |
|||
| |
|||
Real number |
|||
cl_R |
|||
<cln/real.h> |
|||
| |
|||
+-------------------+-------------------+ |
|||
| | |
|||
Rational number Floating-point number |
|||
cl_RA cl_F |
|||
<cln/rational.h> <cln/float.h> |
|||
| | |
|||
| +--------------+--------------+--------------+ |
|||
Integer | | | | |
|||
cl_I Short-Float Single-Float Double-Float Long-Float |
|||
<cln/integer.h> cl_SF cl_FF cl_DF cl_LF |
|||
<cln/sfloat.h> <cln/ffloat.h> <cln/dfloat.h> <cln/lfloat.h> |
|||
</PRE> |
|||
|
|||
<P> |
|||
<A NAME="IDX8"></A> |
|||
<A NAME="IDX9"></A> |
|||
The base class <CODE>cl_number</CODE> is an abstract base class. |
|||
It is not useful to declare a variable of this type except if you want |
|||
to completely disable compile-time type checking and use run-time type |
|||
checking instead. |
|||
|
|||
|
|||
<P> |
|||
<A NAME="IDX10"></A> |
|||
<A NAME="IDX11"></A> |
|||
<A NAME="IDX12"></A> |
|||
The class <CODE>cl_N</CODE> comprises real and complex numbers. There is |
|||
no special class for complex numbers since complex numbers with imaginary |
|||
part <CODE>0</CODE> are automatically converted to real numbers. |
|||
|
|||
|
|||
<P> |
|||
<A NAME="IDX13"></A> |
|||
The class <CODE>cl_R</CODE> comprises real numbers of different kinds. It is an |
|||
abstract class. |
|||
|
|||
|
|||
<P> |
|||
<A NAME="IDX14"></A> |
|||
<A NAME="IDX15"></A> |
|||
<A NAME="IDX16"></A> |
|||
The class <CODE>cl_RA</CODE> comprises exact real numbers: rational numbers, including |
|||
integers. There is no special class for non-integral rational numbers |
|||
since rational numbers with denominator <CODE>1</CODE> are automatically converted |
|||
to integers. |
|||
|
|||
|
|||
<P> |
|||
<A NAME="IDX17"></A> |
|||
The class <CODE>cl_F</CODE> implements floating-point approximations to real numbers. |
|||
It is an abstract class. |
|||
|
|||
|
|||
|
|||
|
|||
<H2><A NAME="SEC12" HREF="cln_toc.html#TOC12">3.1 Exact numbers</A></H2> |
|||
<P> |
|||
<A NAME="IDX18"></A> |
|||
|
|||
|
|||
<P> |
|||
Some numbers are represented as exact numbers: there is no loss of information |
|||
when such a number is converted from its mathematical value to its internal |
|||
representation. On exact numbers, the elementary operations (<CODE>+</CODE>, |
|||
<CODE>-</CODE>, <CODE>*</CODE>, <CODE>/</CODE>, comparisons, ...) compute the completely |
|||
correct result. |
|||
|
|||
|
|||
<P> |
|||
In CLN, the exact numbers are: |
|||
|
|||
|
|||
|
|||
<UL> |
|||
<LI> |
|||
|
|||
rational numbers (including integers), |
|||
<LI> |
|||
|
|||
complex numbers whose real and imaginary parts are both rational numbers. |
|||
</UL> |
|||
|
|||
<P> |
|||
Rational numbers are always normalized to the form |
|||
<CODE><VAR>numerator</VAR>/<VAR>denominator</VAR></CODE> where the numerator and denominator |
|||
are coprime integers and the denominator is positive. If the resulting |
|||
denominator is <CODE>1</CODE>, the rational number is converted to an integer. |
|||
|
|||
|
|||
<P> |
|||
Small integers (typically in the range <CODE>-2^30</CODE>...<CODE>2^30-1</CODE>, |
|||
for 32-bit machines) are especially efficient, because they consume no heap |
|||
allocation. Otherwise the distinction between these immediate integers |
|||
(called "fixnums") and heap allocated integers (called "bignums") |
|||
is completely transparent. |
|||
|
|||
|
|||
|
|||
|
|||
<H2><A NAME="SEC13" HREF="cln_toc.html#TOC13">3.2 Floating-point numbers</A></H2> |
|||
<P> |
|||
<A NAME="IDX19"></A> |
|||
|
|||
|
|||
<P> |
|||
Not all real numbers can be represented exactly. (There is an easy mathematical |
|||
proof for this: Only a countable set of numbers can be stored exactly in |
|||
a computer, even if one assumes that it has unlimited storage. But there |
|||
are uncountably many real numbers.) So some approximation is needed. |
|||
CLN implements ordinary floating-point numbers, with mantissa and exponent. |
|||
|
|||
|
|||
<P> |
|||
<A NAME="IDX20"></A> |
|||
The elementary operations (<CODE>+</CODE>, <CODE>-</CODE>, <CODE>*</CODE>, <CODE>/</CODE>, ...) |
|||
only return approximate results. For example, the value of the expression |
|||
<CODE>(cl_F) 0.3 + (cl_F) 0.4</CODE> prints as <SAMP>`0.70000005'</SAMP>, not as |
|||
<SAMP>`0.7'</SAMP>. Rounding errors like this one are inevitable when computing |
|||
with floating-point numbers. |
|||
|
|||
|
|||
<P> |
|||
Nevertheless, CLN rounds the floating-point results of the operations <CODE>+</CODE>, |
|||
<CODE>-</CODE>, <CODE>*</CODE>, <CODE>/</CODE>, <CODE>sqrt</CODE> according to the "round-to-even" |
|||
rule: It first computes the exact mathematical result and then returns the |
|||
floating-point number which is nearest to this. If two floating-point numbers |
|||
are equally distant from the ideal result, the one with a <CODE>0</CODE> in its least |
|||
significant mantissa bit is chosen. |
|||
|
|||
|
|||
<P> |
|||
Similarly, testing floating point numbers for equality <SAMP>`x == y'</SAMP> |
|||
is gambling with random errors. Better check for <SAMP>`abs(x - y) < epsilon'</SAMP> |
|||
for some well-chosen <CODE>epsilon</CODE>. |
|||
|
|||
|
|||
<P> |
|||
Floating point numbers come in four flavors: |
|||
|
|||
|
|||
|
|||
<UL> |
|||
<LI> |
|||
|
|||
<A NAME="IDX21"></A> |
|||
Short floats, type <CODE>cl_SF</CODE>. |
|||
They have 1 sign bit, 8 exponent bits (including the exponent's sign), |
|||
and 17 mantissa bits (including the "hidden" bit). |
|||
They don't consume heap allocation. |
|||
|
|||
<LI> |
|||
|
|||
<A NAME="IDX22"></A> |
|||
Single floats, type <CODE>cl_FF</CODE>. |
|||
They have 1 sign bit, 8 exponent bits (including the exponent's sign), |
|||
and 24 mantissa bits (including the "hidden" bit). |
|||
In CLN, they are represented as IEEE single-precision floating point numbers. |
|||
This corresponds closely to the C/C++ type <SAMP>`float'</SAMP>. |
|||
|
|||
<LI> |
|||
|
|||
<A NAME="IDX23"></A> |
|||
Double floats, type <CODE>cl_DF</CODE>. |
|||
They have 1 sign bit, 11 exponent bits (including the exponent's sign), |
|||
and 53 mantissa bits (including the "hidden" bit). |
|||
In CLN, they are represented as IEEE double-precision floating point numbers. |
|||
This corresponds closely to the C/C++ type <SAMP>`double'</SAMP>. |
|||
|
|||
<LI> |
|||
|
|||
<A NAME="IDX24"></A> |
|||
Long floats, type <CODE>cl_LF</CODE>. |
|||
They have 1 sign bit, 32 exponent bits (including the exponent's sign), |
|||
and n mantissa bits (including the "hidden" bit), where n >= 64. |
|||
The precision of a long float is unlimited, but once created, a long float |
|||
has a fixed precision. (No "lazy recomputation".) |
|||
</UL> |
|||
|
|||
<P> |
|||
Of course, computations with long floats are more expensive than those |
|||
with smaller floating-point formats. |
|||
|
|||
|
|||
<P> |
|||
CLN does not implement features like NaNs, denormalized numbers and |
|||
gradual underflow. If the exponent range of some floating-point type |
|||
is too limited for your application, choose another floating-point type |
|||
with larger exponent range. |
|||
|
|||
|
|||
<P> |
|||
<A NAME="IDX25"></A> |
|||
As a user of CLN, you can forget about the differences between the |
|||
four floating-point types and just declare all your floating-point |
|||
variables as being of type <CODE>cl_F</CODE>. This has the advantage that |
|||
when you change the precision of some computation (say, from <CODE>cl_DF</CODE> |
|||
to <CODE>cl_LF</CODE>), you don't have to change the code, only the precision |
|||
of the initial values. Also, many transcendental functions have been |
|||
declared as returning a <CODE>cl_F</CODE> when the argument is a <CODE>cl_F</CODE>, |
|||
but such declarations are missing for the types <CODE>cl_SF</CODE>, <CODE>cl_FF</CODE>, |
|||
<CODE>cl_DF</CODE>, <CODE>cl_LF</CODE>. (Such declarations would be wrong if |
|||
the floating point contagion rule happened to change in the future.) |
|||
|
|||
|
|||
|
|||
|
|||
<H2><A NAME="SEC14" HREF="cln_toc.html#TOC14">3.3 Complex numbers</A></H2> |
|||
<P> |
|||
<A NAME="IDX26"></A> |
|||
|
|||
|
|||
<P> |
|||
Complex numbers, as implemented by the class <CODE>cl_N</CODE>, have a real |
|||
part and an imaginary part, both real numbers. A complex number whose |
|||
imaginary part is the exact number <CODE>0</CODE> is automatically converted |
|||
to a real number. |
|||
|
|||
|
|||
<P> |
|||
Complex numbers can arise from real numbers alone, for example |
|||
through application of <CODE>sqrt</CODE> or transcendental functions. |
|||
|
|||
|
|||
|
|||
|
|||
<H2><A NAME="SEC15" HREF="cln_toc.html#TOC15">3.4 Conversions</A></H2> |
|||
<P> |
|||
<A NAME="IDX27"></A> |
|||
|
|||
|
|||
<P> |
|||
Conversions from any class to any its superclasses ("base classes" in |
|||
C++ terminology) is done automatically. |
|||
|
|||
|
|||
<P> |
|||
Conversions from the C built-in types <SAMP>`long'</SAMP> and <SAMP>`unsigned long'</SAMP> |
|||
are provided for the classes <CODE>cl_I</CODE>, <CODE>cl_RA</CODE>, <CODE>cl_R</CODE>, |
|||
<CODE>cl_N</CODE> and <CODE>cl_number</CODE>. |
|||
|
|||
|
|||
<P> |
|||
Conversions from the C built-in types <SAMP>`int'</SAMP> and <SAMP>`unsigned int'</SAMP> |
|||
are provided for the classes <CODE>cl_I</CODE>, <CODE>cl_RA</CODE>, <CODE>cl_R</CODE>, |
|||
<CODE>cl_N</CODE> and <CODE>cl_number</CODE>. However, these conversions emphasize |
|||
efficiency. Their range is therefore limited: |
|||
|
|||
|
|||
|
|||
<UL> |
|||
<LI> |
|||
|
|||
The conversion from <SAMP>`int'</SAMP> works only if the argument is < 2^29 and > -2^29. |
|||
<LI> |
|||
|
|||
The conversion from <SAMP>`unsigned int'</SAMP> works only if the argument is < 2^29. |
|||
</UL> |
|||
|
|||
<P> |
|||
In a declaration like <SAMP>`cl_I x = 10;'</SAMP> the C++ compiler is able to |
|||
do the conversion of <CODE>10</CODE> from <SAMP>`int'</SAMP> to <SAMP>`cl_I'</SAMP> at compile time |
|||
already. On the other hand, code like <SAMP>`cl_I x = 1000000000;'</SAMP> is |
|||
in error. |
|||
So, if you want to be sure that an <SAMP>`int'</SAMP> whose magnitude is not guaranteed |
|||
to be < 2^29 is correctly converted to a <SAMP>`cl_I'</SAMP>, first convert it to a |
|||
<SAMP>`long'</SAMP>. Similarly, if a large <SAMP>`unsigned int'</SAMP> is to be converted to a |
|||
<SAMP>`cl_I'</SAMP>, first convert it to an <SAMP>`unsigned long'</SAMP>. |
|||
|
|||
|
|||
<P> |
|||
Conversions from the C built-in type <SAMP>`float'</SAMP> are provided for the classes |
|||
<CODE>cl_FF</CODE>, <CODE>cl_F</CODE>, <CODE>cl_R</CODE>, <CODE>cl_N</CODE> and <CODE>cl_number</CODE>. |
|||
|
|||
|
|||
<P> |
|||
Conversions from the C built-in type <SAMP>`double'</SAMP> are provided for the classes |
|||
<CODE>cl_DF</CODE>, <CODE>cl_F</CODE>, <CODE>cl_R</CODE>, <CODE>cl_N</CODE> and <CODE>cl_number</CODE>. |
|||
|
|||
|
|||
<P> |
|||
Conversions from <SAMP>`const char *'</SAMP> are provided for the classes |
|||
<CODE>cl_I</CODE>, <CODE>cl_RA</CODE>, |
|||
<CODE>cl_SF</CODE>, <CODE>cl_FF</CODE>, <CODE>cl_DF</CODE>, <CODE>cl_LF</CODE>, <CODE>cl_F</CODE>, |
|||
<CODE>cl_R</CODE>, <CODE>cl_N</CODE>. |
|||
The easiest way to specify a value which is outside of the range of the |
|||
C++ built-in types is therefore to specify it as a string, like this: |
|||
<A NAME="IDX28"></A> |
|||
|
|||
<PRE> |
|||
cl_I order_of_rubiks_cube_group = "43252003274489856000"; |
|||
</PRE> |
|||
|
|||
<P> |
|||
Note that this conversion is done at runtime, not at compile-time. |
|||
|
|||
|
|||
<P> |
|||
Conversions from <CODE>cl_I</CODE> to the C built-in types <SAMP>`int'</SAMP>, |
|||
<SAMP>`unsigned int'</SAMP>, <SAMP>`long'</SAMP>, <SAMP>`unsigned long'</SAMP> are provided through |
|||
the functions |
|||
|
|||
|
|||
<DL COMPACT> |
|||
|
|||
<DT><CODE>int cl_I_to_int (const cl_I& x)</CODE> |
|||
<DD> |
|||
<A NAME="IDX29"></A> |
|||
<DT><CODE>unsigned int cl_I_to_uint (const cl_I& x)</CODE> |
|||
<DD> |
|||
<A NAME="IDX30"></A> |
|||
<DT><CODE>long cl_I_to_long (const cl_I& x)</CODE> |
|||
<DD> |
|||
<A NAME="IDX31"></A> |
|||
<DT><CODE>unsigned long cl_I_to_ulong (const cl_I& x)</CODE> |
|||
<DD> |
|||
<A NAME="IDX32"></A> |
|||
Returns <CODE>x</CODE> as element of the C type <VAR>ctype</VAR>. If <CODE>x</CODE> is not |
|||
representable in the range of <VAR>ctype</VAR>, a runtime error occurs. |
|||
</DL> |
|||
|
|||
<P> |
|||
Conversions from the classes <CODE>cl_I</CODE>, <CODE>cl_RA</CODE>, |
|||
<CODE>cl_SF</CODE>, <CODE>cl_FF</CODE>, <CODE>cl_DF</CODE>, <CODE>cl_LF</CODE>, <CODE>cl_F</CODE> and |
|||
<CODE>cl_R</CODE> |
|||
to the C built-in types <SAMP>`float'</SAMP> and <SAMP>`double'</SAMP> are provided through |
|||
the functions |
|||
|
|||
|
|||
<DL COMPACT> |
|||
|
|||
<DT><CODE>float float_approx (const <VAR>type</VAR>& x)</CODE> |
|||
<DD> |
|||
<A NAME="IDX33"></A> |
|||
<DT><CODE>double double_approx (const <VAR>type</VAR>& x)</CODE> |
|||
<DD> |
|||
<A NAME="IDX34"></A> |
|||
Returns an approximation of <CODE>x</CODE> of C type <VAR>ctype</VAR>. |
|||
If <CODE>abs(x)</CODE> is too close to 0 (underflow), 0 is returned. |
|||
If <CODE>abs(x)</CODE> is too large (overflow), an IEEE infinity is returned. |
|||
</DL> |
|||
|
|||
<P> |
|||
Conversions from any class to any of its subclasses ("derived classes" in |
|||
C++ terminology) are not provided. Instead, you can assert and check |
|||
that a value belongs to a certain subclass, and return it as element of that |
|||
class, using the <SAMP>`As'</SAMP> and <SAMP>`The'</SAMP> macros. |
|||
<A NAME="IDX35"></A> |
|||
<CODE>As(<VAR>type</VAR>)(<VAR>value</VAR>)</CODE> checks that <VAR>value</VAR> belongs to |
|||
<VAR>type</VAR> and returns it as such. |
|||
<A NAME="IDX36"></A> |
|||
<CODE>The(<VAR>type</VAR>)(<VAR>value</VAR>)</CODE> assumes that <VAR>value</VAR> belongs to |
|||
<VAR>type</VAR> and returns it as such. It is your responsibility to ensure |
|||
that this assumption is valid. |
|||
Example: |
|||
|
|||
|
|||
|
|||
<PRE> |
|||
cl_I x = ...; |
|||
if (!(x >= 0)) abort(); |
|||
cl_I ten_x = The(cl_I)(expt(10,x)); // If x >= 0, 10^x is an integer. |
|||
// In general, it would be a rational number. |
|||
</PRE> |
|||
|
|||
<P><HR><P> |
|||
Go to the <A HREF="cln_1.html">first</A>, <A HREF="cln_2.html">previous</A>, <A HREF="cln_4.html">next</A>, <A HREF="cln_13.html">last</A> section, <A HREF="cln_toc.html">table of contents</A>. |
|||
</BODY> |
|||
</HTML> |
2018
doc/cln_4.html
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -1,424 +0,0 @@ |
|||
<HTML> |
|||
<HEAD> |
|||
<!-- Created by texi2html 1.56k from cln.texi on 28 August 2000 --> |
|||
|
|||
<TITLE>CLN, a Class Library for Numbers - 5. Input/Output</TITLE> |
|||
</HEAD> |
|||
<BODY> |
|||
Go to the <A HREF="cln_1.html">first</A>, <A HREF="cln_4.html">previous</A>, <A HREF="cln_6.html">next</A>, <A HREF="cln_13.html">last</A> section, <A HREF="cln_toc.html">table of contents</A>. |
|||
<P><HR><P> |
|||
|
|||
|
|||
<H1><A NAME="SEC44" HREF="cln_toc.html#TOC44">5. Input/Output</A></H1> |
|||
<P> |
|||
<A NAME="IDX237"></A> |
|||
|
|||
|
|||
|
|||
|
|||
<H2><A NAME="SEC45" HREF="cln_toc.html#TOC45">5.1 Internal and printed representation</A></H2> |
|||
<P> |
|||
<A NAME="IDX238"></A> |
|||
|
|||
|
|||
<P> |
|||
All computations deal with the internal representations of the numbers. |
|||
|
|||
|
|||
<P> |
|||
Every number has an external representation as a sequence of ASCII characters. |
|||
Several external representations may denote the same number, for example, |
|||
"20.0" and "20.000". |
|||
|
|||
|
|||
<P> |
|||
Converting an internal to an external representation is called "printing", |
|||
<A NAME="IDX239"></A> |
|||
converting an external to an internal representation is called "reading". |
|||
<A NAME="IDX240"></A> |
|||
In CLN, it is always true that conversion of an internal to an external |
|||
representation and then back to an internal representation will yield the |
|||
same internal representation. Symbolically: <CODE>read(print(x)) == x</CODE>. |
|||
This is called "print-read consistency". |
|||
|
|||
|
|||
<P> |
|||
Different types of numbers have different external representations (case |
|||
is insignificant): |
|||
|
|||
|
|||
<DL COMPACT> |
|||
|
|||
<DT>Integers |
|||
<DD> |
|||
External representation: <VAR>sign</VAR>{<VAR>digit</VAR>}+. The reader also accepts the |
|||
Common Lisp syntaxes <VAR>sign</VAR>{<VAR>digit</VAR>}+<CODE>.</CODE> with a trailing dot |
|||
for decimal integers |
|||
and the <CODE>#<VAR>n</VAR>R</CODE>, <CODE>#b</CODE>, <CODE>#o</CODE>, <CODE>#x</CODE> prefixes. |
|||
|
|||
<DT>Rational numbers |
|||
<DD> |
|||
External representation: <VAR>sign</VAR>{<VAR>digit</VAR>}+<CODE>/</CODE>{<VAR>digit</VAR>}+. |
|||
The <CODE>#<VAR>n</VAR>R</CODE>, <CODE>#b</CODE>, <CODE>#o</CODE>, <CODE>#x</CODE> prefixes are allowed |
|||
here as well. |
|||
|
|||
<DT>Floating-point numbers |
|||
<DD> |
|||
External representation: <VAR>sign</VAR>{<VAR>digit</VAR>}*<VAR>exponent</VAR> or |
|||
<VAR>sign</VAR>{<VAR>digit</VAR>}*<CODE>.</CODE>{<VAR>digit</VAR>}*<VAR>exponent</VAR> or |
|||
<VAR>sign</VAR>{<VAR>digit</VAR>}*<CODE>.</CODE>{<VAR>digit</VAR>}+. A precision specifier |
|||
of the form _<VAR>prec</VAR> may be appended. There must be at least |
|||
one digit in the non-exponent part. The exponent has the syntax |
|||
<VAR>expmarker</VAR> <VAR>expsign</VAR> {<VAR>digit</VAR>}+. |
|||
The exponent marker is |
|||
|
|||
|
|||
<UL> |
|||
<LI> |
|||
|
|||
<SAMP>`s'</SAMP> for short-floats, |
|||
<LI> |
|||
|
|||
<SAMP>`f'</SAMP> for single-floats, |
|||
<LI> |
|||
|
|||
<SAMP>`d'</SAMP> for double-floats, |
|||
<LI> |
|||
|
|||
<SAMP>`L'</SAMP> for long-floats, |
|||
</UL> |
|||
|
|||
or <SAMP>`e'</SAMP>, which denotes a default float format. The precision specifying |
|||
suffix has the syntax _<VAR>prec</VAR> where <VAR>prec</VAR> denotes the number of |
|||
valid mantissa digits (in decimal, excluding leading zeroes), cf. also |
|||
function <SAMP>`cl_float_format'</SAMP>. |
|||
|
|||
<DT>Complex numbers |
|||
<DD> |
|||
External representation: |
|||
|
|||
<UL> |
|||
<LI> |
|||
|
|||
In algebraic notation: <CODE><VAR>realpart</VAR>+<VAR>imagpart</VAR>i</CODE>. Of course, |
|||
if <VAR>imagpart</VAR> is negative, its printed representation begins with |
|||
a <SAMP>`-'</SAMP>, and the <SAMP>`+'</SAMP> between <VAR>realpart</VAR> and <VAR>imagpart</VAR> |
|||
may be omitted. Note that this notation cannot be used when the <VAR>imagpart</VAR> |
|||
is rational and the rational number's base is >18, because the <SAMP>`i'</SAMP> |
|||
is then read as a digit. |
|||
<LI> |
|||
|
|||
In Common Lisp notation: <CODE>#C(<VAR>realpart</VAR> <VAR>imagpart</VAR>)</CODE>. |
|||
</UL> |
|||
|
|||
</DL> |
|||
|
|||
|
|||
|
|||
<H2><A NAME="SEC46" HREF="cln_toc.html#TOC46">5.2 Input functions</A></H2> |
|||
|
|||
<P> |
|||
Including <CODE><cln/io.h></CODE> defines a type <CODE>cl_istream</CODE>, which is |
|||
the type of the first argument to all input functions. <CODE>cl_istream</CODE> |
|||
is the same as <CODE>std::istream&</CODE>. |
|||
|
|||
|
|||
<P> |
|||
The variable |
|||
|
|||
<UL> |
|||
<LI> |
|||
|
|||
<CODE>cl_istream stdin</CODE> |
|||
</UL> |
|||
|
|||
<P> |
|||
contains the standard input stream. |
|||
|
|||
|
|||
<P> |
|||
These are the simple input functions: |
|||
|
|||
|
|||
<DL COMPACT> |
|||
|
|||
<DT><CODE>int freadchar (cl_istream stream)</CODE> |
|||
<DD> |
|||
Reads a character from <CODE>stream</CODE>. Returns <CODE>cl_EOF</CODE> (not a <SAMP>`char'</SAMP>!) |
|||
if the end of stream was encountered or an error occurred. |
|||
|
|||
<DT><CODE>int funreadchar (cl_istream stream, int c)</CODE> |
|||
<DD> |
|||
Puts back <CODE>c</CODE> onto <CODE>stream</CODE>. <CODE>c</CODE> must be the result of the |
|||
last <CODE>freadchar</CODE> operation on <CODE>stream</CODE>. |
|||
</DL> |
|||
|
|||
<P> |
|||
Each of the classes <CODE>cl_N</CODE>, <CODE>cl_R</CODE>, <CODE>cl_RA</CODE>, <CODE>cl_I</CODE>, |
|||
<CODE>cl_F</CODE>, <CODE>cl_SF</CODE>, <CODE>cl_FF</CODE>, <CODE>cl_DF</CODE>, <CODE>cl_LF</CODE> |
|||
defines, in <CODE><cln/<VAR>type</VAR>_io.h></CODE>, the following input function: |
|||
|
|||
|
|||
<DL COMPACT> |
|||
|
|||
<DT><CODE>cl_istream operator>> (cl_istream stream, <VAR>type</VAR>& result)</CODE> |
|||
<DD> |
|||
Reads a number from <CODE>stream</CODE> and stores it in the <CODE>result</CODE>. |
|||
</DL> |
|||
|
|||
<P> |
|||
The most flexible input functions, defined in <CODE><cln/<VAR>type</VAR>_io.h></CODE>, |
|||
are the following: |
|||
|
|||
|
|||
<DL COMPACT> |
|||
|
|||
<DT><CODE>cl_N read_complex (cl_istream stream, const cl_read_flags& flags)</CODE> |
|||
<DD> |
|||
<DT><CODE>cl_R read_real (cl_istream stream, const cl_read_flags& flags)</CODE> |
|||
<DD> |
|||
<DT><CODE>cl_F read_float (cl_istream stream, const cl_read_flags& flags)</CODE> |
|||
<DD> |
|||
<DT><CODE>cl_RA read_rational (cl_istream stream, const cl_read_flags& flags)</CODE> |
|||
<DD> |
|||
<DT><CODE>cl_I read_integer (cl_istream stream, const cl_read_flags& flags)</CODE> |
|||
<DD> |
|||
Reads a number from <CODE>stream</CODE>. The <CODE>flags</CODE> are parameters which |
|||
affect the input syntax. Whitespace before the number is silently skipped. |
|||
|
|||
<DT><CODE>cl_N read_complex (const cl_read_flags& flags, const char * string, const char * string_limit, const char * * end_of_parse)</CODE> |
|||
<DD> |
|||
<DT><CODE>cl_R read_real (const cl_read_flags& flags, const char * string, const char * string_limit, const char * * end_of_parse)</CODE> |
|||
<DD> |
|||
<DT><CODE>cl_F read_float (const cl_read_flags& flags, const char * string, const char * string_limit, const char * * end_of_parse)</CODE> |
|||
<DD> |
|||
<DT><CODE>cl_RA read_rational (const cl_read_flags& flags, const char * string, const char * string_limit, const char * * end_of_parse)</CODE> |
|||
<DD> |
|||
<DT><CODE>cl_I read_integer (const cl_read_flags& flags, const char * string, const char * string_limit, const char * * end_of_parse)</CODE> |
|||
<DD> |
|||
Reads a number from a string in memory. The <CODE>flags</CODE> are parameters which |
|||
affect the input syntax. The string starts at <CODE>string</CODE> and ends at |
|||
<CODE>string_limit</CODE> (exclusive limit). <CODE>string_limit</CODE> may also be |
|||
<CODE>NULL</CODE>, denoting the entire string, i.e. equivalent to |
|||
<CODE>string_limit = string + strlen(string)</CODE>. If <CODE>end_of_parse</CODE> is |
|||
<CODE>NULL</CODE>, the string in memory must contain exactly one number and nothing |
|||
more, else a fatal error will be signalled. If <CODE>end_of_parse</CODE> |
|||
is not <CODE>NULL</CODE>, <CODE>*end_of_parse</CODE> will be assigned a pointer past |
|||
the last parsed character (i.e. <CODE>string_limit</CODE> if nothing came after |
|||
the number). Whitespace is not allowed. |
|||
</DL> |
|||
|
|||
<P> |
|||
The structure <CODE>cl_read_flags</CODE> contains the following fields: |
|||
|
|||
|
|||
<DL COMPACT> |
|||
|
|||
<DT><CODE>cl_read_syntax_t syntax</CODE> |
|||
<DD> |
|||
The possible results of the read operation. Possible values are |
|||
<CODE>syntax_number</CODE>, <CODE>syntax_real</CODE>, <CODE>syntax_rational</CODE>, |
|||
<CODE>syntax_integer</CODE>, <CODE>syntax_float</CODE>, <CODE>syntax_sfloat</CODE>, |
|||
<CODE>syntax_ffloat</CODE>, <CODE>syntax_dfloat</CODE>, <CODE>syntax_lfloat</CODE>. |
|||
|
|||
<DT><CODE>cl_read_lsyntax_t lsyntax</CODE> |
|||
<DD> |
|||
Specifies the language-dependent syntax variant for the read operation. |
|||
Possible values are |
|||
|
|||
<DL COMPACT> |
|||
|
|||
<DT><CODE>lsyntax_standard</CODE> |
|||
<DD> |
|||
accept standard algebraic notation only, no complex numbers, |
|||
<DT><CODE>lsyntax_algebraic</CODE> |
|||
<DD> |
|||
accept the algebraic notation <CODE><VAR>x</VAR>+<VAR>y</VAR>i</CODE> for complex numbers, |
|||
<DT><CODE>lsyntax_commonlisp</CODE> |
|||
<DD> |
|||
accept the <CODE>#b</CODE>, <CODE>#o</CODE>, <CODE>#x</CODE> syntaxes for binary, octal, |
|||
hexadecimal numbers, |
|||
<CODE>#<VAR>base</VAR>R</CODE> for rational numbers in a given base, |
|||
<CODE>#c(<VAR>realpart</VAR> <VAR>imagpart</VAR>)</CODE> for complex numbers, |
|||
<DT><CODE>lsyntax_all</CODE> |
|||
<DD> |
|||
accept all of these extensions. |
|||
</DL> |
|||
|
|||
<DT><CODE>unsigned int rational_base</CODE> |
|||
<DD> |
|||
The base in which rational numbers are read. |
|||
|
|||
<DT><CODE>cl_float_format_t float_flags.default_float_format</CODE> |
|||
<DD> |
|||
The float format used when reading floats with exponent marker <SAMP>`e'</SAMP>. |
|||
|
|||
<DT><CODE>cl_float_format_t float_flags.default_lfloat_format</CODE> |
|||
<DD> |
|||
The float format used when reading floats with exponent marker <SAMP>`l'</SAMP>. |
|||
|
|||
<DT><CODE>cl_boolean float_flags.mantissa_dependent_float_format</CODE> |
|||
<DD> |
|||
When this flag is true, floats specified with more digits than corresponding |
|||
to the exponent marker they contain, but without <VAR>_nnn</VAR> suffix, will get a |
|||
precision corresponding to their number of significant digits. |
|||
</DL> |
|||
|
|||
|
|||
|
|||
<H2><A NAME="SEC47" HREF="cln_toc.html#TOC47">5.3 Output functions</A></H2> |
|||
|
|||
<P> |
|||
Including <CODE><cln/io.h></CODE> defines a type <CODE>cl_ostream</CODE>, which is |
|||
the type of the first argument to all output functions. <CODE>cl_ostream</CODE> |
|||
is the same as <CODE>std::ostream&</CODE>. |
|||
|
|||
|
|||
<P> |
|||
The variable |
|||
|
|||
<UL> |
|||
<LI> |
|||
|
|||
<CODE>cl_ostream stdout</CODE> |
|||
</UL> |
|||
|
|||
<P> |
|||
contains the standard output stream. |
|||
|
|||
|
|||
<P> |
|||
The variable |
|||
|
|||
<UL> |
|||
<LI> |
|||
|
|||
<CODE>cl_ostream stderr</CODE> |
|||
</UL> |
|||
|
|||
<P> |
|||
contains the standard error output stream. |
|||
|
|||
|
|||
<P> |
|||
These are the simple output functions: |
|||
|
|||
|
|||
<DL COMPACT> |
|||
|
|||
<DT><CODE>void fprintchar (cl_ostream stream, char c)</CODE> |
|||
<DD> |
|||
Prints the character <CODE>x</CODE> literally on the <CODE>stream</CODE>. |
|||
|
|||
<DT><CODE>void fprint (cl_ostream stream, const char * string)</CODE> |
|||
<DD> |
|||
Prints the <CODE>string</CODE> literally on the <CODE>stream</CODE>. |
|||
|
|||
<DT><CODE>void fprintdecimal (cl_ostream stream, int x)</CODE> |
|||
<DD> |
|||
<DT><CODE>void fprintdecimal (cl_ostream stream, const cl_I& x)</CODE> |
|||
<DD> |
|||
Prints the integer <CODE>x</CODE> in decimal on the <CODE>stream</CODE>. |
|||
|
|||
<DT><CODE>void fprintbinary (cl_ostream stream, const cl_I& x)</CODE> |
|||
<DD> |
|||
Prints the integer <CODE>x</CODE> in binary (base 2, without prefix) |
|||
on the <CODE>stream</CODE>. |
|||
|
|||
<DT><CODE>void fprintoctal (cl_ostream stream, const cl_I& x)</CODE> |
|||
<DD> |
|||
Prints the integer <CODE>x</CODE> in octal (base 8, without prefix) |
|||
on the <CODE>stream</CODE>. |
|||
|
|||
<DT><CODE>void fprinthexadecimal (cl_ostream stream, const cl_I& x)</CODE> |
|||
<DD> |
|||
Prints the integer <CODE>x</CODE> in hexadecimal (base 16, without prefix) |
|||
on the <CODE>stream</CODE>. |
|||
</DL> |
|||
|
|||
<P> |
|||
Each of the classes <CODE>cl_N</CODE>, <CODE>cl_R</CODE>, <CODE>cl_RA</CODE>, <CODE>cl_I</CODE>, |
|||
<CODE>cl_F</CODE>, <CODE>cl_SF</CODE>, <CODE>cl_FF</CODE>, <CODE>cl_DF</CODE>, <CODE>cl_LF</CODE> |
|||
defines, in <CODE><cln/<VAR>type</VAR>_io.h></CODE>, the following output functions: |
|||
|
|||
|
|||
<DL COMPACT> |
|||
|
|||
<DT><CODE>void fprint (cl_ostream stream, const <VAR>type</VAR>& x)</CODE> |
|||
<DD> |
|||
<DT><CODE>cl_ostream operator<< (cl_ostream stream, const <VAR>type</VAR>& x)</CODE> |
|||
<DD> |
|||
Prints the number <CODE>x</CODE> on the <CODE>stream</CODE>. The output may depend |
|||
on the global printer settings in the variable <CODE>default_print_flags</CODE>. |
|||
The <CODE>ostream</CODE> flags and settings (flags, width and locale) are |
|||
ignored. |
|||
</DL> |
|||
|
|||
<P> |
|||
The most flexible output function, defined in <CODE><cln/<VAR>type</VAR>_io.h></CODE>, |
|||
are the following: |
|||
|
|||
<PRE> |
|||
void print_complex (cl_ostream stream, const cl_print_flags& flags, |
|||
const cl_N& z); |
|||
void print_real (cl_ostream stream, const cl_print_flags& flags, |
|||
const cl_R& z); |
|||
void print_float (cl_ostream stream, const cl_print_flags& flags, |
|||
const cl_F& z); |
|||
void print_rational (cl_ostream stream, const cl_print_flags& flags, |
|||
const cl_RA& z); |
|||
void print_integer (cl_ostream stream, const cl_print_flags& flags, |
|||
const cl_I& z); |
|||
</PRE> |
|||
|
|||
<P> |
|||
Prints the number <CODE>x</CODE> on the <CODE>stream</CODE>. The <CODE>flags</CODE> are |
|||
parameters which affect the output. |
|||
|
|||
|
|||
<P> |
|||
The structure type <CODE>cl_print_flags</CODE> contains the following fields: |
|||
|
|||
|
|||
<DL COMPACT> |
|||
|
|||
<DT><CODE>unsigned int rational_base</CODE> |
|||
<DD> |
|||
The base in which rational numbers are printed. Default is <CODE>10</CODE>. |
|||
|
|||
<DT><CODE>cl_boolean rational_readably</CODE> |
|||
<DD> |
|||
If this flag is true, rational numbers are printed with radix specifiers in |
|||
Common Lisp syntax (<CODE>#<VAR>n</VAR>R</CODE> or <CODE>#b</CODE> or <CODE>#o</CODE> or <CODE>#x</CODE> |
|||
prefixes, trailing dot). Default is false. |
|||
|
|||
<DT><CODE>cl_boolean float_readably</CODE> |
|||
<DD> |
|||
If this flag is true, type specific exponent markers have precedence over 'E'. |
|||
Default is false. |
|||
|
|||
<DT><CODE>cl_float_format_t default_float_format</CODE> |
|||
<DD> |
|||
Floating point numbers of this format will be printed using the 'E' exponent |
|||
marker. Default is <CODE>cl_float_format_ffloat</CODE>. |
|||
|
|||
<DT><CODE>cl_boolean complex_readably</CODE> |
|||
<DD> |
|||
If this flag is true, complex numbers will be printed using the Common Lisp |
|||
syntax <CODE>#C(<VAR>realpart</VAR> <VAR>imagpart</VAR>)</CODE>. Default is false. |
|||
|
|||
<DT><CODE>cl_string univpoly_varname</CODE> |
|||
<DD> |
|||
Univariate polynomials with no explicit indeterminate name will be printed |
|||
using this variable name. Default is <CODE>"x"</CODE>. |
|||
</DL> |
|||
|
|||
<P> |
|||
The global variable <CODE>default_print_flags</CODE> contains the default values, |
|||
used by the function <CODE>fprint</CODE>. |
|||
|
|||
|
|||
<P><HR><P> |
|||
Go to the <A HREF="cln_1.html">first</A>, <A HREF="cln_4.html">previous</A>, <A HREF="cln_6.html">next</A>, <A HREF="cln_13.html">last</A> section, <A HREF="cln_toc.html">table of contents</A>. |
|||
</BODY> |
|||
</HTML> |
@ -1,125 +0,0 @@ |
|||
<HTML> |
|||
<HEAD> |
|||
<!-- Created by texi2html 1.56k from cln.texi on 28 August 2000 --> |
|||
|
|||
<TITLE>CLN, a Class Library for Numbers - 6. Rings</TITLE> |
|||
</HEAD> |
|||
<BODY> |
|||
Go to the <A HREF="cln_1.html">first</A>, <A HREF="cln_5.html">previous</A>, <A HREF="cln_7.html">next</A>, <A HREF="cln_13.html">last</A> section, <A HREF="cln_toc.html">table of contents</A>. |
|||
<P><HR><P> |
|||
|
|||
|
|||
<H1><A NAME="SEC48" HREF="cln_toc.html#TOC48">6. Rings</A></H1> |
|||
|
|||
<P> |
|||
CLN has a class of abstract rings. |
|||
|
|||
|
|||
|
|||
<PRE> |
|||
Ring |
|||
cl_ring |
|||
<cln/ring.h> |
|||
</PRE> |
|||
|
|||
<P> |
|||
Rings can be compared for equality: |
|||
|
|||
|
|||
<DL COMPACT> |
|||
|
|||
<DT><CODE>bool operator== (const cl_ring&, const cl_ring&)</CODE> |
|||
<DD> |
|||
<DT><CODE>bool operator!= (const cl_ring&, const cl_ring&)</CODE> |
|||
<DD> |
|||
These compare two rings for equality. |
|||
</DL> |
|||
|
|||
<P> |
|||
Given a ring <CODE>R</CODE>, the following members can be used. |
|||
|
|||
|
|||
<DL COMPACT> |
|||
|
|||
<DT><CODE>void R->fprint (cl_ostream stream, const cl_ring_element& x)</CODE> |
|||
<DD> |
|||
<A NAME="IDX241"></A> |
|||
<DT><CODE>cl_boolean R->equal (const cl_ring_element& x, const cl_ring_element& y)</CODE> |
|||
<DD> |
|||
<A NAME="IDX242"></A> |
|||
<DT><CODE>cl_ring_element R->zero ()</CODE> |
|||
<DD> |
|||
<A NAME="IDX243"></A> |
|||
<DT><CODE>cl_boolean R->zerop (const cl_ring_element& x)</CODE> |
|||
<DD> |
|||
<A NAME="IDX244"></A> |
|||
<DT><CODE>cl_ring_element R->plus (const cl_ring_element& x, const cl_ring_element& y)</CODE> |
|||
<DD> |
|||
<A NAME="IDX245"></A> |
|||
<DT><CODE>cl_ring_element R->minus (const cl_ring_element& x, const cl_ring_element& y)</CODE> |
|||
<DD> |
|||
<A NAME="IDX246"></A> |
|||
<DT><CODE>cl_ring_element R->uminus (const cl_ring_element& x)</CODE> |
|||
<DD> |
|||
<A NAME="IDX247"></A> |
|||
<DT><CODE>cl_ring_element R->one ()</CODE> |
|||
<DD> |
|||
<A NAME="IDX248"></A> |
|||
<DT><CODE>cl_ring_element R->canonhom (const cl_I& x)</CODE> |
|||
<DD> |
|||
<A NAME="IDX249"></A> |
|||
<DT><CODE>cl_ring_element R->mul (const cl_ring_element& x, const cl_ring_element& y)</CODE> |
|||
<DD> |
|||
<A NAME="IDX250"></A> |
|||
<DT><CODE>cl_ring_element R->square (const cl_ring_element& x)</CODE> |
|||
<DD> |
|||
<A NAME="IDX251"></A> |
|||
<DT><CODE>cl_ring_element R->expt_pos (const cl_ring_element& x, const cl_I& y)</CODE> |
|||
<DD> |
|||
<A NAME="IDX252"></A> |
|||
</DL> |
|||
|
|||
<P> |
|||
The following rings are built-in. |
|||
|
|||
|
|||
<DL COMPACT> |
|||
|
|||
<DT><CODE>cl_null_ring cl_0_ring</CODE> |
|||
<DD> |
|||
The null ring, containing only zero. |
|||
|
|||
<DT><CODE>cl_complex_ring cl_C_ring</CODE> |
|||
<DD> |
|||
The ring of complex numbers. This corresponds to the type <CODE>cl_N</CODE>. |
|||
|
|||
<DT><CODE>cl_real_ring cl_R_ring</CODE> |
|||
<DD> |
|||
The ring of real numbers. This corresponds to the type <CODE>cl_R</CODE>. |
|||
|
|||
<DT><CODE>cl_rational_ring cl_RA_ring</CODE> |
|||
<DD> |
|||
The ring of rational numbers. This corresponds to the type <CODE>cl_RA</CODE>. |
|||
|
|||
<DT><CODE>cl_integer_ring cl_I_ring</CODE> |
|||
<DD> |
|||
The ring of integers. This corresponds to the type <CODE>cl_I</CODE>. |
|||
</DL> |
|||
|
|||
<P> |
|||
Type tests can be performed for any of <CODE>cl_C_ring</CODE>, <CODE>cl_R_ring</CODE>, |
|||
<CODE>cl_RA_ring</CODE>, <CODE>cl_I_ring</CODE>: |
|||
|
|||
|
|||
<DL COMPACT> |
|||
|
|||
<DT><CODE>cl_boolean instanceof (const cl_number& x, const cl_number_ring& R)</CODE> |
|||
<DD> |
|||
<A NAME="IDX253"></A> |
|||
Tests whether the given number is an element of the number ring R. |
|||
</DL> |
|||
|
|||
<P><HR><P> |
|||
Go to the <A HREF="cln_1.html">first</A>, <A HREF="cln_5.html">previous</A>, <A HREF="cln_7.html">next</A>, <A HREF="cln_13.html">last</A> section, <A HREF="cln_toc.html">table of contents</A>. |
|||
</BODY> |
|||
</HTML> |
@ -1,251 +0,0 @@ |
|||
<HTML> |
|||
<HEAD> |
|||
<!-- Created by texi2html 1.56k from cln.texi on 28 August 2000 --> |
|||
|
|||
<TITLE>CLN, a Class Library for Numbers - 7. Modular integers</TITLE> |
|||
</HEAD> |
|||
<BODY> |
|||
Go to the <A HREF="cln_1.html">first</A>, <A HREF="cln_6.html">previous</A>, <A HREF="cln_8.html">next</A>, <A HREF="cln_13.html">last</A> section, <A HREF="cln_toc.html">table of contents</A>. |
|||
<P><HR><P> |
|||
|
|||
|
|||
<H1><A NAME="SEC49" HREF="cln_toc.html#TOC49">7. Modular integers</A></H1> |
|||
<P> |
|||
<A NAME="IDX254"></A> |
|||
|
|||
|
|||
|
|||
|
|||
<H2><A NAME="SEC50" HREF="cln_toc.html#TOC50">7.1 Modular integer rings</A></H2> |
|||
<P> |
|||
<A NAME="IDX255"></A> |
|||
|
|||
|
|||
<P> |
|||
CLN implements modular integers, i.e. integers modulo a fixed integer N. |
|||
The modulus is explicitly part of every modular integer. CLN doesn't |
|||
allow you to (accidentally) mix elements of different modular rings, |
|||
e.g. <CODE>(3 mod 4) + (2 mod 5)</CODE> will result in a runtime error. |
|||
(Ideally one would imagine a generic data type <CODE>cl_MI(N)</CODE>, but C++ |
|||
doesn't have generic types. So one has to live with runtime checks.) |
|||
|
|||
|
|||
<P> |
|||
The class of modular integer rings is |
|||
|
|||
|
|||
|
|||
<PRE> |
|||
Ring |
|||
cl_ring |
|||
<cln/ring.h> |
|||
| |
|||
| |
|||
Modular integer ring |
|||
cl_modint_ring |
|||
<cln/modinteger.h> |
|||
</PRE> |
|||
|
|||
<P> |
|||
<A NAME="IDX256"></A> |
|||
|
|||
|
|||
<P> |
|||
and the class of all modular integers (elements of modular integer rings) is |
|||
|
|||
|
|||
|
|||
<PRE> |
|||
Modular integer |
|||
cl_MI |
|||
<cln/modinteger.h> |
|||
</PRE> |
|||
|
|||
<P> |
|||
Modular integer rings are constructed using the function |
|||
|
|||
|
|||
<DL COMPACT> |
|||
|
|||
<DT><CODE>cl_modint_ring find_modint_ring (const cl_I& N)</CODE> |
|||
<DD> |
|||
<A NAME="IDX257"></A> |
|||
This function returns the modular ring <SAMP>`Z/NZ'</SAMP>. It takes care |
|||
of finding out about special cases of <CODE>N</CODE>, like powers of two |
|||
and odd numbers for which Montgomery multiplication will be a win, |
|||
<A NAME="IDX258"></A> |
|||
and precomputes any necessary auxiliary data for computing modulo <CODE>N</CODE>. |
|||
There is a cache table of rings, indexed by <CODE>N</CODE> (or, more precisely, |
|||
by <CODE>abs(N)</CODE>). This ensures that the precomputation costs are reduced |
|||
to a minimum. |
|||
</DL> |
|||
|
|||
<P> |
|||
Modular integer rings can be compared for equality: |
|||
|
|||
|
|||
<DL COMPACT> |
|||
|
|||
<DT><CODE>bool operator== (const cl_modint_ring&, const cl_modint_ring&)</CODE> |
|||
<DD> |
|||
<A NAME="IDX259"></A> |
|||
<DT><CODE>bool operator!= (const cl_modint_ring&, const cl_modint_ring&)</CODE> |
|||
<DD> |
|||
<A NAME="IDX260"></A> |
|||
These compare two modular integer rings for equality. Two different calls |
|||
to <CODE>find_modint_ring</CODE> with the same argument necessarily return the |
|||
same ring because it is memoized in the cache table. |
|||
</DL> |
|||
|
|||
|
|||
|
|||
<H2><A NAME="SEC51" HREF="cln_toc.html#TOC51">7.2 Functions on modular integers</A></H2> |
|||
|
|||
<P> |
|||
Given a modular integer ring <CODE>R</CODE>, the following members can be used. |
|||
|
|||
|
|||
<DL COMPACT> |
|||
|
|||
<DT><CODE>cl_I R->modulus</CODE> |
|||
<DD> |
|||
<A NAME="IDX261"></A> |
|||
This is the ring's modulus, normalized to be nonnegative: <CODE>abs(N)</CODE>. |
|||
|
|||
<DT><CODE>cl_MI R->zero()</CODE> |
|||
<DD> |
|||
<A NAME="IDX262"></A> |
|||
This returns <CODE>0 mod N</CODE>. |
|||
|
|||
<DT><CODE>cl_MI R->one()</CODE> |
|||
<DD> |
|||
<A NAME="IDX263"></A> |
|||
This returns <CODE>1 mod N</CODE>. |
|||
|
|||
<DT><CODE>cl_MI R->canonhom (const cl_I& x)</CODE> |
|||
<DD> |
|||
<A NAME="IDX264"></A> |
|||
This returns <CODE>x mod N</CODE>. |
|||
|
|||
<DT><CODE>cl_I R->retract (const cl_MI& x)</CODE> |
|||
<DD> |
|||
<A NAME="IDX265"></A> |
|||
This is a partial inverse function to <CODE>R->canonhom</CODE>. It returns the |
|||
standard representative (<CODE>>=0</CODE>, <CODE><N</CODE>) of <CODE>x</CODE>. |
|||
|
|||
<DT><CODE>cl_MI R->random(random_state& randomstate)</CODE> |
|||
<DD> |
|||
<DT><CODE>cl_MI R->random()</CODE> |
|||
<DD> |
|||
<A NAME="IDX266"></A> |
|||
This returns a random integer modulo <CODE>N</CODE>. |
|||
</DL> |
|||
|
|||
<P> |
|||
The following operations are defined on modular integers. |
|||
|
|||
|
|||
<DL COMPACT> |
|||
|
|||
<DT><CODE>cl_modint_ring x.ring ()</CODE> |
|||
<DD> |
|||
<A NAME="IDX267"></A> |
|||
Returns the ring to which the modular integer <CODE>x</CODE> belongs. |
|||
|
|||
<DT><CODE>cl_MI operator+ (const cl_MI&, const cl_MI&)</CODE> |
|||
<DD> |
|||
<A NAME="IDX268"></A> |
|||
Returns the sum of two modular integers. One of the arguments may also |
|||
be a plain integer. |
|||
|
|||
<DT><CODE>cl_MI operator- (const cl_MI&, const cl_MI&)</CODE> |
|||
<DD> |
|||
<A NAME="IDX269"></A> |
|||
Returns the difference of two modular integers. One of the arguments may also |
|||
be a plain integer. |
|||
|
|||
<DT><CODE>cl_MI operator- (const cl_MI&)</CODE> |
|||
<DD> |
|||
Returns the negative of a modular integer. |
|||
|
|||
<DT><CODE>cl_MI operator* (const cl_MI&, const cl_MI&)</CODE> |
|||
<DD> |
|||
<A NAME="IDX270"></A> |
|||
Returns the product of two modular integers. One of the arguments may also |
|||
be a plain integer. |
|||
|
|||
<DT><CODE>cl_MI square (const cl_MI&)</CODE> |
|||
<DD> |
|||
<A NAME="IDX271"></A> |
|||
Returns the square of a modular integer. |
|||
|
|||
<DT><CODE>cl_MI recip (const cl_MI& x)</CODE> |
|||
<DD> |
|||
<A NAME="IDX272"></A> |
|||
Returns the reciprocal <CODE>x^-1</CODE> of a modular integer <CODE>x</CODE>. <CODE>x</CODE> |
|||
must be coprime to the modulus, otherwise an error message is issued. |
|||
|
|||
<DT><CODE>cl_MI div (const cl_MI& x, const cl_MI& y)</CODE> |
|||
<DD> |
|||
<A NAME="IDX273"></A> |
|||
Returns the quotient <CODE>x*y^-1</CODE> of two modular integers <CODE>x</CODE>, <CODE>y</CODE>. |
|||
<CODE>y</CODE> must be coprime to the modulus, otherwise an error message is issued. |
|||
|
|||
<DT><CODE>cl_MI expt_pos (const cl_MI& x, const cl_I& y)</CODE> |
|||
<DD> |
|||
<A NAME="IDX274"></A> |
|||
<CODE>y</CODE> must be > 0. Returns <CODE>x^y</CODE>. |
|||
|
|||
<DT><CODE>cl_MI expt (const cl_MI& x, const cl_I& y)</CODE> |
|||
<DD> |
|||
<A NAME="IDX275"></A> |
|||
Returns <CODE>x^y</CODE>. If <CODE>y</CODE> is negative, <CODE>x</CODE> must be coprime to the |
|||
modulus, else an error message is issued. |
|||
|
|||
<DT><CODE>cl_MI operator<< (const cl_MI& x, const cl_I& y)</CODE> |
|||
<DD> |
|||
<A NAME="IDX276"></A> |
|||
Returns <CODE>x*2^y</CODE>. |
|||
|
|||
<DT><CODE>cl_MI operator>> (const cl_MI& x, const cl_I& y)</CODE> |
|||
<DD> |
|||
<A NAME="IDX277"></A> |
|||
Returns <CODE>x*2^-y</CODE>. When <CODE>y</CODE> is positive, the modulus must be odd, |
|||
or an error message is issued. |
|||
|
|||
<DT><CODE>bool operator== (const cl_MI&, const cl_MI&)</CODE> |
|||
<DD> |
|||
<A NAME="IDX278"></A> |
|||
<DT><CODE>bool operator!= (const cl_MI&, const cl_MI&)</CODE> |
|||
<DD> |
|||
<A NAME="IDX279"></A> |
|||
Compares two modular integers, belonging to the same modular integer ring, |
|||
for equality. |
|||
|
|||
<DT><CODE>cl_boolean zerop (const cl_MI& x)</CODE> |
|||
<DD> |
|||
<A NAME="IDX280"></A> |
|||
Returns true if <CODE>x</CODE> is <CODE>0 mod N</CODE>. |
|||
</DL> |
|||
|
|||
<P> |
|||
The following output functions are defined (see also the chapter on |
|||
input/output). |
|||
|
|||
|
|||
<DL COMPACT> |
|||
|
|||
<DT><CODE>void fprint (cl_ostream stream, const cl_MI& x)</CODE> |
|||
<DD> |
|||
<A NAME="IDX281"></A> |
|||
<DT><CODE>cl_ostream operator<< (cl_ostream stream, const cl_MI& x)</CODE> |
|||
<DD> |
|||
<A NAME="IDX282"></A> |
|||
Prints the modular integer <CODE>x</CODE> on the <CODE>stream</CODE>. The output may depend |
|||
on the global printer settings in the variable <CODE>default_print_flags</CODE>. |
|||
</DL> |
|||
|
|||
<P><HR><P> |
|||
Go to the <A HREF="cln_1.html">first</A>, <A HREF="cln_6.html">previous</A>, <A HREF="cln_8.html">next</A>, <A HREF="cln_13.html">last</A> section, <A HREF="cln_toc.html">table of contents</A>. |
|||
</BODY> |
|||
</HTML> |
@ -1,139 +0,0 @@ |
|||
<HTML> |
|||
<HEAD> |
|||
<!-- Created by texi2html 1.56k from cln.texi on 28 August 2000 --> |
|||
|
|||
<TITLE>CLN, a Class Library for Numbers - 8. Symbolic data types</TITLE> |
|||
</HEAD> |
|||
<BODY> |
|||
Go to the <A HREF="cln_1.html">first</A>, <A HREF="cln_7.html">previous</A>, <A HREF="cln_9.html">next</A>, <A HREF="cln_13.html">last</A> section, <A HREF="cln_toc.html">table of contents</A>. |
|||
<P><HR><P> |
|||
|
|||
|
|||
<H1><A NAME="SEC52" HREF="cln_toc.html#TOC52">8. Symbolic data types</A></H1> |
|||
<P> |
|||
<A NAME="IDX283"></A> |
|||
|
|||
|
|||
<P> |
|||
CLN implements two symbolic (non-numeric) data types: strings and symbols. |
|||
|
|||
|
|||
|
|||
|
|||
<H2><A NAME="SEC53" HREF="cln_toc.html#TOC53">8.1 Strings</A></H2> |
|||
<P> |
|||
<A NAME="IDX284"></A> |
|||
<A NAME="IDX285"></A> |
|||
|
|||
|
|||
<P> |
|||
The class |
|||
|
|||
|
|||
|
|||
<PRE> |
|||
String |
|||
cl_string |
|||
<cln/string.h> |
|||
</PRE> |
|||
|
|||
<P> |
|||
implements immutable strings. |
|||
|
|||
|
|||
<P> |
|||
Strings are constructed through the following constructors: |
|||
|
|||
|
|||
<DL COMPACT> |
|||
|
|||
<DT><CODE>cl_string (const char * s)</CODE> |
|||
<DD> |
|||
Returns an immutable copy of the (zero-terminated) C string <CODE>s</CODE>. |
|||
|
|||
<DT><CODE>cl_string (const char * ptr, unsigned long len)</CODE> |
|||
<DD> |
|||
Returns an immutable copy of the <CODE>len</CODE> characters at |
|||
<CODE>ptr[0]</CODE>, ..., <CODE>ptr[len-1]</CODE>. NUL characters are allowed. |
|||
</DL> |
|||
|
|||
<P> |
|||
The following functions are available on strings: |
|||
|
|||
|
|||
<DL COMPACT> |
|||
|
|||
<DT><CODE>operator =</CODE> |
|||
<DD> |
|||
Assignment from <CODE>cl_string</CODE> and <CODE>const char *</CODE>. |
|||
|
|||
<DT><CODE>s.length()</CODE> |
|||
<DD> |
|||
<A NAME="IDX286"></A> |
|||
<DT><CODE>strlen(s)</CODE> |
|||
<DD> |
|||
<A NAME="IDX287"></A> |
|||
Returns the length of the string <CODE>s</CODE>. |
|||
|
|||
<DT><CODE>s[i]</CODE> |
|||
<DD> |
|||
<A NAME="IDX288"></A> |
|||
Returns the <CODE>i</CODE>th character of the string <CODE>s</CODE>. |
|||
<CODE>i</CODE> must be in the range <CODE>0 <= i < s.length()</CODE>. |
|||
|
|||
<DT><CODE>bool equal (const cl_string& s1, const cl_string& s2)</CODE> |
|||
<DD> |
|||
<A NAME="IDX289"></A> |
|||
Compares two strings for equality. One of the arguments may also be a |
|||
plain <CODE>const char *</CODE>. |
|||
</DL> |
|||
|
|||
|
|||
|
|||
<H2><A NAME="SEC54" HREF="cln_toc.html#TOC54">8.2 Symbols</A></H2> |
|||
<P> |
|||
<A NAME="IDX290"></A> |
|||
<A NAME="IDX291"></A> |
|||
|
|||
|
|||
<P> |
|||
Symbols are uniquified strings: all symbols with the same name are shared. |
|||
This means that comparison of two symbols is fast (effectively just a pointer |
|||
comparison), whereas comparison of two strings must in the worst case walk |
|||
both strings until their end. |
|||
Symbols are used, for example, as tags for properties, as names of variables |
|||
in polynomial rings, etc. |
|||
|
|||
|
|||
<P> |
|||
Symbols are constructed through the following constructor: |
|||
|
|||
|
|||
<DL COMPACT> |
|||
|
|||
<DT><CODE>cl_symbol (const cl_string& s)</CODE> |
|||
<DD> |
|||
Looks up or creates a new symbol with a given name. |
|||
</DL> |
|||
|
|||
<P> |
|||
The following operations are available on symbols: |
|||
|
|||
|
|||
<DL COMPACT> |
|||
|
|||
<DT><CODE>cl_string (const cl_symbol& sym)</CODE> |
|||
<DD> |
|||
Conversion to <CODE>cl_string</CODE>: Returns the string which names the symbol |
|||
<CODE>sym</CODE>. |
|||
|
|||
<DT><CODE>bool equal (const cl_symbol& sym1, const cl_symbol& sym2)</CODE> |
|||
<DD> |
|||
<A NAME="IDX292"></A> |
|||
Compares two symbols for equality. This is very fast. |
|||
</DL> |
|||
|
|||
<P><HR><P> |
|||
Go to the <A HREF="cln_1.html">first</A>, <A HREF="cln_7.html">previous</A>, <A HREF="cln_9.html">next</A>, <A HREF="cln_13.html">last</A> section, <A HREF="cln_toc.html">table of contents</A>. |
|||
</BODY> |
|||
</HTML> |
@ -1,359 +0,0 @@ |
|||
<HTML> |
|||
<HEAD> |
|||
<!-- Created by texi2html 1.56k from cln.texi on 28 August 2000 --> |
|||
|
|||
<TITLE>CLN, a Class Library for Numbers - 9. Univariate polynomials</TITLE> |
|||
</HEAD> |
|||
<BODY> |
|||
Go to the <A HREF="cln_1.html">first</A>, <A HREF="cln_8.html">previous</A>, <A HREF="cln_10.html">next</A>, <A HREF="cln_13.html">last</A> section, <A HREF="cln_toc.html">table of contents</A>. |
|||
<P><HR><P> |
|||
|
|||
|
|||
<H1><A NAME="SEC55" HREF="cln_toc.html#TOC55">9. Univariate polynomials</A></H1> |
|||
<P> |
|||
<A NAME="IDX293"></A> |
|||
<A NAME="IDX294"></A> |
|||
|
|||
|
|||
|
|||
|
|||
<H2><A NAME="SEC56" HREF="cln_toc.html#TOC56">9.1 Univariate polynomial rings</A></H2> |
|||
|
|||
<P> |
|||
CLN implements univariate polynomials (polynomials in one variable) over an |
|||
arbitrary ring. The indeterminate variable may be either unnamed (and will be |
|||
printed according to <CODE>default_print_flags.univpoly_varname</CODE>, which |
|||
defaults to <SAMP>`x'</SAMP>) or carry a given name. The base ring and the |
|||
indeterminate are explicitly part of every polynomial. CLN doesn't allow you to |
|||
(accidentally) mix elements of different polynomial rings, e.g. |
|||
<CODE>(a^2+1) * (b^3-1)</CODE> will result in a runtime error. (Ideally this should |
|||
return a multivariate polynomial, but they are not yet implemented in CLN.) |
|||
|
|||
|
|||
<P> |
|||
The classes of univariate polynomial rings are |
|||
|
|||
|
|||
|
|||
<PRE> |
|||
Ring |
|||
cl_ring |
|||
<cln/ring.h> |
|||
| |
|||
| |
|||
Univariate polynomial ring |
|||
cl_univpoly_ring |
|||
<cln/univpoly.h> |
|||
| |
|||
+----------------+-------------------+ |
|||
| | | |
|||
Complex polynomial ring | Modular integer polynomial ring |
|||
cl_univpoly_complex_ring | cl_univpoly_modint_ring |
|||
<cln/univpoly_complex.h> | <cln/univpoly_modint.h> |
|||
| |
|||
+----------------+ |
|||
| | |
|||
Real polynomial ring | |
|||
cl_univpoly_real_ring | |
|||
<cln/univpoly_real.h> | |
|||
| |
|||
+----------------+ |
|||
| | |
|||
Rational polynomial ring | |
|||
cl_univpoly_rational_ring | |
|||
<cln/univpoly_rational.h> | |
|||
| |
|||
+----------------+ |
|||
| |
|||
Integer polynomial ring |
|||
cl_univpoly_integer_ring |
|||
<cln/univpoly_integer.h> |
|||
</PRE> |
|||
|
|||
<P> |
|||
and the corresponding classes of univariate polynomials are |
|||
|
|||
|
|||
|
|||
<PRE> |
|||
Univariate polynomial |
|||
cl_UP |
|||
<cln/univpoly.h> |
|||
| |
|||
+----------------+-------------------+ |
|||
| | | |
|||
Complex polynomial | Modular integer polynomial |
|||
cl_UP_N | cl_UP_MI |
|||
<cln/univpoly_complex.h> | <cln/univpoly_modint.h> |
|||
| |
|||
+----------------+ |
|||
| | |
|||
Real polynomial | |
|||
cl_UP_R | |
|||
<cln/univpoly_real.h> | |
|||
| |
|||
+----------------+ |
|||
| | |
|||
Rational polynomial | |
|||
cl_UP_RA | |
|||
<cln/univpoly_rational.h> | |
|||
| |
|||
+----------------+ |
|||
| |
|||
Integer polynomial |
|||
cl_UP_I |
|||
<cln/univpoly_integer.h> |
|||
</PRE> |
|||
|
|||
<P> |
|||
Univariate polynomial rings are constructed using the functions |
|||
|
|||
|
|||
<DL COMPACT> |
|||
|
|||
<DT><CODE>cl_univpoly_ring find_univpoly_ring (const cl_ring& R)</CODE> |
|||
<DD> |
|||
<DT><CODE>cl_univpoly_ring find_univpoly_ring (const cl_ring& R, const cl_symbol& varname)</CODE> |
|||
<DD> |
|||
This function returns the polynomial ring <SAMP>`R[X]'</SAMP>, unnamed or named. |
|||
<CODE>R</CODE> may be an arbitrary ring. This function takes care of finding out |
|||
about special cases of <CODE>R</CODE>, such as the rings of complex numbers, |
|||
real numbers, rational numbers, integers, or modular integer rings. |
|||
There is a cache table of rings, indexed by <CODE>R</CODE> and <CODE>varname</CODE>. |
|||
This ensures that two calls of this function with the same arguments will |
|||
return the same polynomial ring. |
|||
|
|||
<DT><CODE>cl_univpoly_complex_ring find_univpoly_ring (const cl_complex_ring& R)</CODE> |
|||
<DD> |
|||
<A NAME="IDX295"></A> |
|||
<DT><CODE>cl_univpoly_complex_ring find_univpoly_ring (const cl_complex_ring& R, const cl_symbol& varname)</CODE> |
|||
<DD> |
|||
<DT><CODE>cl_univpoly_real_ring find_univpoly_ring (const cl_real_ring& R)</CODE> |
|||
<DD> |
|||
<DT><CODE>cl_univpoly_real_ring find_univpoly_ring (const cl_real_ring& R, const cl_symbol& varname)</CODE> |
|||
<DD> |
|||
<DT><CODE>cl_univpoly_rational_ring find_univpoly_ring (const cl_rational_ring& R)</CODE> |
|||
<DD> |
|||
<DT><CODE>cl_univpoly_rational_ring find_univpoly_ring (const cl_rational_ring& R, const cl_symbol& varname)</CODE> |
|||
<DD> |
|||
<DT><CODE>cl_univpoly_integer_ring find_univpoly_ring (const cl_integer_ring& R)</CODE> |
|||
<DD> |
|||
<DT><CODE>cl_univpoly_integer_ring find_univpoly_ring (const cl_integer_ring& R, const cl_symbol& varname)</CODE> |
|||
<DD> |
|||
<DT><CODE>cl_univpoly_modint_ring find_univpoly_ring (const cl_modint_ring& R)</CODE> |
|||
<DD> |
|||
<DT><CODE>cl_univpoly_modint_ring find_univpoly_ring (const cl_modint_ring& R, const cl_symbol& varname)</CODE> |
|||
<DD> |
|||
These functions are equivalent to the general <CODE>find_univpoly_ring</CODE>, |
|||
only the return type is more specific, according to the base ring's type. |
|||
</DL> |
|||
|
|||
|
|||
|
|||
<H2><A NAME="SEC57" HREF="cln_toc.html#TOC57">9.2 Functions on univariate polynomials</A></H2> |
|||
|
|||
<P> |
|||
Given a univariate polynomial ring <CODE>R</CODE>, the following members can be used. |
|||
|
|||
|
|||
<DL COMPACT> |
|||
|
|||
<DT><CODE>cl_ring R->basering()</CODE> |
|||
<DD> |
|||
<A NAME="IDX296"></A> |
|||
This returns the base ring, as passed to <SAMP>`find_univpoly_ring'</SAMP>. |
|||
|
|||
<DT><CODE>cl_UP R->zero()</CODE> |
|||
<DD> |
|||
<A NAME="IDX297"></A> |
|||
This returns <CODE>0 in R</CODE>, a polynomial of degree -1. |
|||
|
|||
<DT><CODE>cl_UP R->one()</CODE> |
|||
<DD> |
|||
<A NAME="IDX298"></A> |
|||
This returns <CODE>1 in R</CODE>, a polynomial of degree <= 0. |
|||
|
|||
<DT><CODE>cl_UP R->canonhom (const cl_I& x)</CODE> |
|||
<DD> |
|||
<A NAME="IDX299"></A> |
|||
This returns <CODE>x in R</CODE>, a polynomial of degree <= 0. |
|||
|
|||
<DT><CODE>cl_UP R->monomial (const cl_ring_element& x, uintL e)</CODE> |
|||
<DD> |
|||
<A NAME="IDX300"></A> |
|||
This returns a sparse polynomial: <CODE>x * X^e</CODE>, where <CODE>X</CODE> is the |
|||
indeterminate. |
|||
|
|||
<DT><CODE>cl_UP R->create (sintL degree)</CODE> |
|||
<DD> |
|||
<A NAME="IDX301"></A> |
|||
Creates a new polynomial with a given degree. The zero polynomial has degree |
|||
<CODE>-1</CODE>. After creating the polynomial, you should put in the coefficients, |
|||
using the <CODE>set_coeff</CODE> member function, and then call the <CODE>finalize</CODE> |
|||
member function. |
|||
</DL> |
|||
|
|||
<P> |
|||
The following are the only destructive operations on univariate polynomials. |
|||
|
|||
|
|||
<DL COMPACT> |
|||
|
|||
<DT><CODE>void set_coeff (cl_UP& x, uintL index, const cl_ring_element& y)</CODE> |
|||
<DD> |
|||
<A NAME="IDX302"></A> |
|||
This changes the coefficient of <CODE>X^index</CODE> in <CODE>x</CODE> to be <CODE>y</CODE>. |
|||
After changing a polynomial and before applying any "normal" operation on it, |
|||
you should call its <CODE>finalize</CODE> member function. |
|||
|
|||
<DT><CODE>void finalize (cl_UP& x)</CODE> |
|||
<DD> |
|||
<A NAME="IDX303"></A> |
|||
This function marks the endpoint of destructive modifications of a polynomial. |
|||
It normalizes the internal representation so that subsequent computations have |
|||
less overhead. Doing normal computations on unnormalized polynomials may |
|||
produce wrong results or crash the program. |
|||
</DL> |
|||
|
|||
<P> |
|||
The following operations are defined on univariate polynomials. |
|||
|
|||
|
|||
<DL COMPACT> |
|||
|
|||
<DT><CODE>cl_univpoly_ring x.ring ()</CODE> |
|||
<DD> |
|||
<A NAME="IDX304"></A> |
|||
Returns the ring to which the univariate polynomial <CODE>x</CODE> belongs. |
|||
|
|||
<DT><CODE>cl_UP operator+ (const cl_UP&, const cl_UP&)</CODE> |
|||
<DD> |
|||
<A NAME="IDX305"></A> |
|||
Returns the sum of two univariate polynomials. |
|||
|
|||
<DT><CODE>cl_UP operator- (const cl_UP&, const cl_UP&)</CODE> |
|||
<DD> |
|||
<A NAME="IDX306"></A> |
|||
Returns the difference of two univariate polynomials. |
|||
|
|||
<DT><CODE>cl_UP operator- (const cl_UP&)</CODE> |
|||
<DD> |
|||
Returns the negative of a univariate polynomial. |
|||
|
|||
<DT><CODE>cl_UP operator* (const cl_UP&, const cl_UP&)</CODE> |
|||
<DD> |
|||
<A NAME="IDX307"></A> |
|||
Returns the product of two univariate polynomials. One of the arguments may |
|||
also be a plain integer or an element of the base ring. |
|||
|
|||
<DT><CODE>cl_UP square (const cl_UP&)</CODE> |
|||
<DD> |
|||
<A NAME="IDX308"></A> |
|||
Returns the square of a univariate polynomial. |
|||
|
|||
<DT><CODE>cl_UP expt_pos (const cl_UP& x, const cl_I& y)</CODE> |
|||
<DD> |
|||
<A NAME="IDX309"></A> |
|||
<CODE>y</CODE> must be > 0. Returns <CODE>x^y</CODE>. |
|||
|
|||
<DT><CODE>bool operator== (const cl_UP&, const cl_UP&)</CODE> |
|||
<DD> |
|||
<A NAME="IDX310"></A> |
|||
<DT><CODE>bool operator!= (const cl_UP&, const cl_UP&)</CODE> |
|||
<DD> |
|||
<A NAME="IDX311"></A> |
|||
Compares two univariate polynomials, belonging to the same univariate |
|||
polynomial ring, for equality. |
|||
|
|||
<DT><CODE>cl_boolean zerop (const cl_UP& x)</CODE> |
|||
<DD> |
|||
<A NAME="IDX312"></A> |
|||
Returns true if <CODE>x</CODE> is <CODE>0 in R</CODE>. |
|||
|
|||
<DT><CODE>sintL degree (const cl_UP& x)</CODE> |
|||
<DD> |
|||
<A NAME="IDX313"></A> |
|||
Returns the degree of the polynomial. The zero polynomial has degree <CODE>-1</CODE>. |
|||
|
|||
<DT><CODE>cl_ring_element coeff (const cl_UP& x, uintL index)</CODE> |
|||
<DD> |
|||
<A NAME="IDX314"></A> |
|||
Returns the coefficient of <CODE>X^index</CODE> in the polynomial <CODE>x</CODE>. |
|||
|
|||
<DT><CODE>cl_ring_element x (const cl_ring_element& y)</CODE> |
|||
<DD> |
|||
<A NAME="IDX315"></A> |
|||
Evaluation: If <CODE>x</CODE> is a polynomial and <CODE>y</CODE> belongs to the base ring, |
|||
then <SAMP>`x(y)'</SAMP> returns the value of the substitution of <CODE>y</CODE> into |
|||
<CODE>x</CODE>. |
|||
|
|||
<DT><CODE>cl_UP deriv (const cl_UP& x)</CODE> |
|||
<DD> |
|||
<A NAME="IDX316"></A> |
|||
Returns the derivative of the polynomial <CODE>x</CODE> with respect to the |
|||
indeterminate <CODE>X</CODE>. |
|||
</DL> |
|||
|
|||
<P> |
|||
The following output functions are defined (see also the chapter on |
|||
input/output). |
|||
|
|||
|
|||
<DL COMPACT> |
|||
|
|||
<DT><CODE>void fprint (cl_ostream stream, const cl_UP& x)</CODE> |
|||
<DD> |
|||
<A NAME="IDX317"></A> |
|||
<DT><CODE>cl_ostream operator<< (cl_ostream stream, const cl_UP& x)</CODE> |
|||
<DD> |
|||
<A NAME="IDX318"></A> |
|||
Prints the univariate polynomial <CODE>x</CODE> on the <CODE>stream</CODE>. The output may |
|||
depend on the global printer settings in the variable |
|||
<CODE>default_print_flags</CODE>. |
|||
</DL> |
|||
|
|||
|
|||
|
|||
<H2><A NAME="SEC58" HREF="cln_toc.html#TOC58">9.3 Special polynomials</A></H2> |
|||
|
|||
<P> |
|||
The following functions return special polynomials. |
|||
|
|||
|
|||
<DL COMPACT> |
|||
|
|||
<DT><CODE>cl_UP_I tschebychev (sintL n)</CODE> |
|||
<DD> |
|||
<A NAME="IDX319"></A> |
|||
<A NAME="IDX320"></A> |
|||
Returns the n-th Chebyshev polynomial (n >= 0). |
|||
|
|||
<DT><CODE>cl_UP_I hermite (sintL n)</CODE> |
|||
<DD> |
|||
<A NAME="IDX321"></A> |
|||
<A NAME="IDX322"></A> |
|||
Returns the n-th Hermite polynomial (n >= 0). |
|||
|
|||
<DT><CODE>cl_UP_RA legendre (sintL n)</CODE> |
|||
<DD> |
|||
<A NAME="IDX323"></A> |
|||
<A NAME="IDX324"></A> |
|||
Returns the n-th Legendre polynomial (n >= 0). |
|||
|
|||
<DT><CODE>cl_UP_I laguerre (sintL n)</CODE> |
|||
<DD> |
|||
<A NAME="IDX325"></A> |
|||
<A NAME="IDX326"></A> |
|||
Returns the n-th Laguerre polynomial (n >= 0). |
|||
</DL> |
|||
|
|||
<P> |
|||
Information how to derive the differential equation satisfied by each |
|||
of these polynomials from their definition can be found in the |
|||
<CODE>doc/polynomial/</CODE> directory. |
|||
|
|||
|
|||
<P><HR><P> |
|||
Go to the <A HREF="cln_1.html">first</A>, <A HREF="cln_8.html">previous</A>, <A HREF="cln_10.html">next</A>, <A HREF="cln_13.html">last</A> section, <A HREF="cln_toc.html">table of contents</A>. |
|||
</BODY> |
|||
</HTML> |
@ -1,125 +0,0 @@ |
|||
<HTML> |
|||
<HEAD> |
|||
<!-- Created by texi2html 1.56k from cln.texi on 28 August 2000 --> |
|||
|
|||
<TITLE>CLN, a Class Library for Numbers - Table of Contents</TITLE> |
|||
</HEAD> |
|||
<BODY> |
|||
<H1>CLN, a Class Library for Numbers</H1> |
|||
<ADDRESS>by Bruno Haible</ADDRESS> |
|||
<P> |
|||
<P><HR><P> |
|||
<UL> |
|||
<LI><A NAME="TOC1" HREF="cln_1.html#SEC1">1. Introduction</A> |
|||
<LI><A NAME="TOC2" HREF="cln_2.html#SEC2">2. Installation</A> |
|||
<UL> |
|||
<LI><A NAME="TOC3" HREF="cln_2.html#SEC3">2.1 Prerequisites</A> |
|||
<UL> |
|||
<LI><A NAME="TOC4" HREF="cln_2.html#SEC4">2.1.1 C++ compiler</A> |
|||
<LI><A NAME="TOC5" HREF="cln_2.html#SEC5">2.1.2 Make utility</A> |
|||
<LI><A NAME="TOC6" HREF="cln_2.html#SEC6">2.1.3 Sed utility</A> |
|||
</UL> |
|||
<LI><A NAME="TOC7" HREF="cln_2.html#SEC7">2.2 Building the library</A> |
|||
<UL> |
|||
<LI><A NAME="TOC8" HREF="cln_2.html#SEC8">2.2.1 Using the GNU MP Library</A> |
|||
</UL> |
|||
<LI><A NAME="TOC9" HREF="cln_2.html#SEC9">2.3 Installing the library</A> |
|||
<LI><A NAME="TOC10" HREF="cln_2.html#SEC10">2.4 Cleaning up</A> |
|||
</UL> |
|||
<LI><A NAME="TOC11" HREF="cln_3.html#SEC11">3. Ordinary number types</A> |
|||
<UL> |
|||
<LI><A NAME="TOC12" HREF="cln_3.html#SEC12">3.1 Exact numbers</A> |
|||
<LI><A NAME="TOC13" HREF="cln_3.html#SEC13">3.2 Floating-point numbers</A> |
|||
<LI><A NAME="TOC14" HREF="cln_3.html#SEC14">3.3 Complex numbers</A> |
|||
<LI><A NAME="TOC15" HREF="cln_3.html#SEC15">3.4 Conversions</A> |
|||
</UL> |
|||
<LI><A NAME="TOC16" HREF="cln_4.html#SEC16">4. Functions on numbers</A> |
|||
<UL> |
|||
<LI><A NAME="TOC17" HREF="cln_4.html#SEC17">4.1 Constructing numbers</A> |
|||
<UL> |
|||
<LI><A NAME="TOC18" HREF="cln_4.html#SEC18">4.1.1 Constructing integers</A> |
|||
<LI><A NAME="TOC19" HREF="cln_4.html#SEC19">4.1.2 Constructing rational numbers</A> |
|||
<LI><A NAME="TOC20" HREF="cln_4.html#SEC20">4.1.3 Constructing floating-point numbers</A> |
|||
<LI><A NAME="TOC21" HREF="cln_4.html#SEC21">4.1.4 Constructing complex numbers</A> |
|||
</UL> |
|||
<LI><A NAME="TOC22" HREF="cln_4.html#SEC22">4.2 Elementary functions</A> |
|||
<LI><A NAME="TOC23" HREF="cln_4.html#SEC23">4.3 Elementary rational functions</A> |
|||
<LI><A NAME="TOC24" HREF="cln_4.html#SEC24">4.4 Elementary complex functions</A> |
|||
<LI><A NAME="TOC25" HREF="cln_4.html#SEC25">4.5 Comparisons</A> |
|||
<LI><A NAME="TOC26" HREF="cln_4.html#SEC26">4.6 Rounding functions</A> |
|||
<LI><A NAME="TOC27" HREF="cln_4.html#SEC27">4.7 Roots</A> |
|||
<LI><A NAME="TOC28" HREF="cln_4.html#SEC28">4.8 Transcendental functions</A> |
|||
<UL> |
|||
<LI><A NAME="TOC29" HREF="cln_4.html#SEC29">4.8.1 Exponential and logarithmic functions</A> |
|||
<LI><A NAME="TOC30" HREF="cln_4.html#SEC30">4.8.2 Trigonometric functions</A> |
|||
<LI><A NAME="TOC31" HREF="cln_4.html#SEC31">4.8.3 Hyperbolic functions</A> |
|||
<LI><A NAME="TOC32" HREF="cln_4.html#SEC32">4.8.4 Euler gamma</A> |
|||
<LI><A NAME="TOC33" HREF="cln_4.html#SEC33">4.8.5 Riemann zeta</A> |
|||
</UL> |
|||
<LI><A NAME="TOC34" HREF="cln_4.html#SEC34">4.9 Functions on integers</A> |
|||
<UL> |
|||
<LI><A NAME="TOC35" HREF="cln_4.html#SEC35">4.9.1 Logical functions</A> |
|||
<LI><A NAME="TOC36" HREF="cln_4.html#SEC36">4.9.2 Number theoretic functions</A> |
|||
<LI><A NAME="TOC37" HREF="cln_4.html#SEC37">4.9.3 Combinatorial functions</A> |
|||
</UL> |
|||
<LI><A NAME="TOC38" HREF="cln_4.html#SEC38">4.10 Functions on floating-point numbers</A> |
|||
<LI><A NAME="TOC39" HREF="cln_4.html#SEC39">4.11 Conversion functions</A> |
|||
<UL> |
|||
<LI><A NAME="TOC40" HREF="cln_4.html#SEC40">4.11.1 Conversion to floating-point numbers</A> |
|||
<LI><A NAME="TOC41" HREF="cln_4.html#SEC41">4.11.2 Conversion to rational numbers</A> |
|||
</UL> |
|||
<LI><A NAME="TOC42" HREF="cln_4.html#SEC42">4.12 Random number generators</A> |
|||
<LI><A NAME="TOC43" HREF="cln_4.html#SEC43">4.13 Obfuscating operators</A> |
|||
</UL> |
|||
<LI><A NAME="TOC44" HREF="cln_5.html#SEC44">5. Input/Output</A> |
|||
<UL> |
|||
<LI><A NAME="TOC45" HREF="cln_5.html#SEC45">5.1 Internal and printed representation</A> |
|||
<LI><A NAME="TOC46" HREF="cln_5.html#SEC46">5.2 Input functions</A> |
|||
<LI><A NAME="TOC47" HREF="cln_5.html#SEC47">5.3 Output functions</A> |
|||
</UL> |
|||
<LI><A NAME="TOC48" HREF="cln_6.html#SEC48">6. Rings</A> |
|||
<LI><A NAME="TOC49" HREF="cln_7.html#SEC49">7. Modular integers</A> |
|||
<UL> |
|||
<LI><A NAME="TOC50" HREF="cln_7.html#SEC50">7.1 Modular integer rings</A> |
|||
<LI><A NAME="TOC51" HREF="cln_7.html#SEC51">7.2 Functions on modular integers</A> |
|||
</UL> |
|||
<LI><A NAME="TOC52" HREF="cln_8.html#SEC52">8. Symbolic data types</A> |
|||
<UL> |
|||
<LI><A NAME="TOC53" HREF="cln_8.html#SEC53">8.1 Strings</A> |
|||
<LI><A NAME="TOC54" HREF="cln_8.html#SEC54">8.2 Symbols</A> |
|||
</UL> |
|||
<LI><A NAME="TOC55" HREF="cln_9.html#SEC55">9. Univariate polynomials</A> |
|||
<UL> |
|||
<LI><A NAME="TOC56" HREF="cln_9.html#SEC56">9.1 Univariate polynomial rings</A> |
|||
<LI><A NAME="TOC57" HREF="cln_9.html#SEC57">9.2 Functions on univariate polynomials</A> |
|||
<LI><A NAME="TOC58" HREF="cln_9.html#SEC58">9.3 Special polynomials</A> |
|||
</UL> |
|||
<LI><A NAME="TOC59" HREF="cln_10.html#SEC59">10. Internals</A> |
|||
<UL> |
|||
<LI><A NAME="TOC60" HREF="cln_10.html#SEC60">10.1 Why C++ ?</A> |
|||
<LI><A NAME="TOC61" HREF="cln_10.html#SEC61">10.2 Memory efficiency</A> |
|||
<LI><A NAME="TOC62" HREF="cln_10.html#SEC62">10.3 Speed efficiency</A> |
|||
<LI><A NAME="TOC63" HREF="cln_10.html#SEC63">10.4 Garbage collection</A> |
|||
</UL> |
|||
<LI><A NAME="TOC64" HREF="cln_11.html#SEC64">11. Using the library</A> |
|||
<UL> |
|||
<LI><A NAME="TOC65" HREF="cln_11.html#SEC65">11.1 Compiler options</A> |
|||
<LI><A NAME="TOC66" HREF="cln_11.html#SEC66">11.2 Compatibility to old CLN versions</A> |
|||
<LI><A NAME="TOC67" HREF="cln_11.html#SEC67">11.3 Include files</A> |
|||
<LI><A NAME="TOC68" HREF="cln_11.html#SEC68">11.4 An Example</A> |
|||
<LI><A NAME="TOC69" HREF="cln_11.html#SEC69">11.5 Debugging support</A> |
|||
</UL> |
|||
<LI><A NAME="TOC70" HREF="cln_12.html#SEC70">12. Customizing</A> |
|||
<UL> |
|||
<LI><A NAME="TOC71" HREF="cln_12.html#SEC71">12.1 Error handling</A> |
|||
<LI><A NAME="TOC72" HREF="cln_12.html#SEC72">12.2 Floating-point underflow</A> |
|||
<LI><A NAME="TOC73" HREF="cln_12.html#SEC73">12.3 Customizing I/O</A> |
|||
<LI><A NAME="TOC74" HREF="cln_12.html#SEC74">12.4 Customizing the memory allocator</A> |
|||
</UL> |
|||
<LI><A NAME="TOC75" HREF="cln_13.html#SEC75">Index</A> |
|||
</UL> |
|||
<P><HR><P> |
|||
This document was generated on 28 August 2000 using |
|||
<A HREF="http://wwwinfo.cern.ch/dis/texi2html/">texi2html</A> 1.56k. |
|||
</BODY> |
|||
</HTML> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue