]> www.ginac.de Git - ginac.git/blobdiff - doc/tutorial/ginac.texi
documentation update
[ginac.git] / doc / tutorial / ginac.texi
index 98033e40767d1914fc7f8fded5e5a99f4a4127a5..80000ff98d670931c189f145c1efab55e89be3b2 100644 (file)
@@ -23,7 +23,7 @@
 This is a tutorial that documents GiNaC @value{VERSION}, an open
 framework for symbolic computation within the C++ programming language.
 
-Copyright (C) 1999-2002 Johannes Gutenberg University Mainz, Germany
+Copyright (C) 1999-2003 Johannes Gutenberg University Mainz, Germany
 
 Permission is granted to make and distribute verbatim copies of
 this manual provided the copyright notice and this permission notice
@@ -52,7 +52,7 @@ notice identical to this one.
 
 @page
 @vskip 0pt plus 1filll
-Copyright @copyright{} 1999-2002 Johannes Gutenberg University Mainz, Germany
+Copyright @copyright{} 1999-2003 Johannes Gutenberg University Mainz, Germany
 @sp 2
 Permission is granted to make and distribute verbatim copies of
 this manual provided the copyright notice and this permission notice
@@ -135,7 +135,7 @@ the near future.
 
 @section License
 The GiNaC framework for symbolic computation within the C++ programming
-language is Copyright @copyright{} 1999-2002 Johannes Gutenberg
+language is Copyright @copyright{} 1999-2003 Johannes Gutenberg
 University Mainz, Germany.
 
 This program is free software; you can redistribute it and/or
@@ -734,7 +734,7 @@ containers of expressions and so on.
 
 @cindex container
 @cindex atom
-To get an idea about what kinds of symbolic composits may be built we
+To get an idea about what kinds of symbolic composites may be built we
 have a look at the most important classes in the class hierarchy and
 some of the relations among the classes:
 
@@ -895,7 +895,7 @@ can use the expression's @code{.subs()} method (@pxref{Substituting Expressions}
 For storing numerical things, GiNaC uses Bruno Haible's library CLN.
 The classes therein serve as foundation classes for GiNaC.  CLN stands
 for Class Library for Numbers or alternatively for Common Lisp Numbers.
-In order to find out more about CLN's internals the reader is refered to
+In order to find out more about CLN's internals, the reader is referred to
 the documentation of that library.  @inforef{Introduction, , cln}, for
 more information. Suffice to say that it is by itself build on top of
 another library, the GNU Multiple Precision library GMP, which is an
@@ -1009,7 +1009,7 @@ naively expect it to be rounded in the decimal system.  But note also,
 that in both cases you got a couple of extra digits.  This is because
 numbers are internally stored by CLN as chunks of binary digits in order
 to match your machine's word size and to not waste precision.  Thus, on
-architectures with differnt word size, the above output might even
+architectures with different word size, the above output might even
 differ with regard to actually computed digits.
 
 It should be clear that objects of class @code{numeric} should be used
@@ -3033,6 +3033,7 @@ Notes:
   are also valid patterns.
 @end itemize
 
+@subsection Matching expressions
 @cindex @code{match()}
 The most basic application of patterns is to check whether an expression
 matches a given pattern. This is done by the function
@@ -3142,6 +3143,7 @@ FAIL
 @{$0==x^2@}
 @end example
 
+@subsection Matching parts of expressions
 @cindex @code{has()}
 A more general way to look for patterns in expressions is provided by the
 member function
@@ -3191,9 +3193,9 @@ bool ex::find(const ex & pattern, lst & found);
 @end example
 
 works a bit like @code{has()} but it doesn't stop upon finding the first
-match. Instead, it appends all found matches to the specified list. If there
-are multiple occurrences of the same expression, it is entered only once to
-the list. @code{find()} returns false if no matches were found (in
+match. Instead, it inserts all found matches into the specified list. If
+there are multiple occurrences of the same expression, it is entered only
+once to the list. @code{find()} returns false if no matches were found (in
 @command{ginsh}, it returns an empty list):
 
 @example
@@ -3210,6 +3212,7 @@ sin(y)*a+sin(x)*b+sin(x)*a+sin(y)*b
 @{sin(y),sin(x)@}
 @end example
 
+@subsection Substituting expressions
 @cindex @code{subs()}
 Probably the most useful application of patterns is to use them for
 substituting expressions with the @code{subs()} method. Wildcards can be
@@ -3405,6 +3408,7 @@ argument. You can not use functions like @samp{diff()}, @samp{op()},
 @subsection Expanding and collecting
 @cindex @code{expand()}
 @cindex @code{collect()}
+@cindex @code{collect_common_factors()}
 
 A polynomial in one or more variables has many equivalent
 representations.  Some useful ones serve a specific purpose.  Consider
@@ -3463,6 +3467,25 @@ d*sin(x)+(d*sin(x)+sin(y)+d*sin(y)+sin(x))*p+(d*sin(x)+sin(y)+d*sin(y)+sin(x))*q
 (1+q+d*(1+q+p)+p)*sin(y)+(1+q+d*(1+q+p)+p)*sin(x)
 @end example
 
+Polynomials can often be brought into a more compact form by collecting
+common factors from the terms of sums. This is accomplished by the function
+
+@example
+ex collect_common_factors(const ex & e);
+@end example
+
+This function doesn't perform a full factorization but only looks for
+factors which are already explicitly present:
+
+@example
+> collect_common_factors(a*x+a*y);
+(x+y)*a
+> collect_common_factors(a*x^2+2*a*x*y+a*y^2);
+a*(2*x*y+y^2+x^2)
+> collect_common_factors(a*(b*(a+c)*x+b*((a+c)*x+(a+c)*y)*y));
+(c+a)*a*(x*y+y^2+x)*b
+@end example
+
 @subsection Degree and coefficients
 @cindex @code{degree()}
 @cindex @code{ldegree()}
@@ -4210,9 +4233,9 @@ numbers are written.
 The above example will produce (note the @code{x^2} being converted to @code{x*x}):
 
 @example
-float f = (3.000000e+00/2.000000e+00)*(x*x)+4.500000e+00;
-double d = (3.000000e+00/2.000000e+00)*(x*x)+4.500000e+00;
-cl_N n = (cln::cl_F("3.0")/cln::cl_F("2.0"))*(x*x)+cln::cl_F("4.5");
+float f = (3.0/2.0)*(x*x)+4.500000e+00;
+double d = (3.0/2.0)*(x*x)+4.5000000000000000e+00;
+cl_N n = cln::cl_RA("3/2")*(x*x)+cln::cl_F("4.5_17");
 @end example
 
 The @code{print_context} type @code{print_tree} provides a dump of the
@@ -5730,7 +5753,7 @@ simple_SOURCES = simple.cpp
 @end example
 
 This @file{Makefile.am}, says that we are building a single executable,
-from a single sourcefile @file{simple.cpp}. Since every program
+from a single source file @file{simple.cpp}. Since every program
 we are building uses GiNaC we simply added the GiNaC options
 to @env{$LIBS} and @env{$CPPFLAGS}, but in other circumstances, we might
 want to specify them on a per-program basis: for instance by