[genius] Mon Jul 27 15:22:57 2009 Jiri (George) Lebl <jirka 5z com>



commit ff6b61e3dcba35558558693f4ef83c5ed296bfa2
Author: Jiri (George) Lebl <jirka 5z com>
Date:   Mon Jul 27 15:23:30 2009 -0500

    Mon Jul 27 15:22:57 2009  Jiri (George) Lebl <jirka 5z com>
    
    	* help/C/genius.xml, help/C/gel-function-list.xml: Update
    	  documentation for all the new features and improve existing
    	  parts a bit especially by adding a bunch of links for some
    	  functions.
    
    	* NEWS: update

 ChangeLog                    |   11 +-
 NEWS                         |   36 ++++-
 help/C/gel-function-list.xml |  317 ++++++++++++++++++++++++++++-
 help/C/genius.txt            |  461 ++++++++++++++++++++++++++++++++++++------
 help/C/genius.xml            |  272 +++++++++++++++++++++----
 5 files changed, 985 insertions(+), 112 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 461c219..c3978ec 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Mon Jul 27 15:22:57 2009  Jiri (George) Lebl <jirka 5z com>
+
+	* help/C/genius.xml, help/C/gel-function-list.xml: Update
+	  documentation for all the new features and improve existing
+	  parts a bit especially by adding a bunch of links for some
+	  functions.
+
+	* NEWS: update
+
 Fri Jul 24 17:23:04 2009  Jiri (George) Lebl <jirka 5z com>
 
 	* lib/calculus/fourier.gel: fix cosine series and fix argument
@@ -13,7 +22,7 @@ Fri Jul 24 17:23:04 2009  Jiri (George) Lebl <jirka 5z com>
 Fri Jul 24 16:32:32 2009  Jiri (George) Lebl <jirka 5z com>
 
 	* lib/calculus/fourier.gel: add NumericalFourierCosineSeriesFunction
-	  and NumericalFourierSineSeriesFunction and fixup some doc stringss
+	  and NumericalFourierSineSeriesFunction and fixup some doc strings
 
 	* src/eval.c, src/dict.c: build the subst_dict on first function
 	  evaluate.  This avoids subst lists for simple functions, plus
diff --git a/NEWS b/NEWS
index 1c3f825..647ca51 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,40 @@
 Changes to 1.0.7
 
-FIXME
+* SYNTAX: Added a possibility to exactly specify which variables are copied
+  into a function's extra dictionary when it is being returned.
+    E.g. "`(x) [x0] = (x-x0)" will copy x0 from the current context.  This
+  is a lot more efficient than the current behaviour which tries to copy
+  everything referenced.
+* SYNTAX: Add "local" variables by specifying "local x,y,z" or "local *" as
+  the first statement in a function.  Local variables are not visible from
+  higher contexts (functions called within)
+* CHANGE: all system parameters are now protected and cannot be redefined
+  using the "parameter" keyword
+* Add UserVariables, UndefineAll, ProtectAll, and add Undefine as an alias to
+  undefine.
+* Add trigonometric Fourier series related functions:
+  NumericalFourierSeriesFunction, NumericalFourierSineSeriesFunction,
+  NumericalFourierCosineSeriesFunction, FourierSeriesFunction,
+  NumericalFourierSeriesCoefficients, NumericalFourierSineSeriesCoefficients,
+  NumericalFourierCosineSeriesCoefficients, PeriodicExtension,
+  EvenPeriodicExtension, OddPeriodicExtension
+* Fix changing floating point precision!
+* Fix uninitialied variable in graphing (Matthias Drochner)
+* Improve variable substitution for returned functions to be more efficient.
+  Slightly changes behaviour with respect to global functions and variables
+  used.
+* Plot windows now not treated annoingly as dialogs
+* Fix compilation/decompilation of all function attributes.
+* Parse/Evaluate with a syntax error at end of string no longer terminate
+  genius
+* Updated Mersenne stuff for the newest data from mersenne.org and
+  fix MersennePrimeExponents
+* Fix opening new files from the command line.
+* Update the gel library to use the new language features.
+* Various other minor fixes
+* Translation updates (Philip Withnall, Jen Ockwell)
+* For some of the changes the author (Jiri) was partially supported by
+  NSF grant DMS 0900885 and the University of Illinois at Urbana-Champaign
 
 Changes to 1.0.6
 
diff --git a/help/C/gel-function-list.xml b/help/C/gel-function-list.xml
index dc642c9..dae8e29 100644
--- a/help/C/gel-function-list.xml
+++ b/help/C/gel-function-list.xml
@@ -335,6 +335,17 @@ avoid them being accidentally overridden.</para>
          </listitem>
         </varlistentry>
 
+        <varlistentry id="gel-function-ProtectAll">
+         <term>ProtectAll</term>
+         <listitem>
+          <synopsis>ProtectAll ()</synopsis>
+          <para>Protect all currently defined variables, parameters and
+functions from being modified.  This is used on the internal GEL functions to
+avoid them being accidentally overridden.  Normally &app; considers
+unprotected variables as user defined.</para>
+         </listitem>
+        </varlistentry>
+
         <varlistentry id="gel-function-set">
          <term>set</term>
          <listitem>
@@ -370,9 +381,26 @@ avoid them being accidentally overridden.</para>
          <term>undefine</term>
          <listitem>
           <synopsis>undefine (id)</synopsis>
+          <para>Alias: <function>Undefine</function></para>
           <para>Undefine a variable.  This includes locals and globals,
 	    every value on all context levels is wiped.  This function
-	    should really not be used on local variables.</para>
+	    should really not be used on local variables.  A vector of
+	    identifiers can also be passed to undefine several variables.
+          </para>
+         </listitem>
+        </varlistentry>
+
+        <varlistentry id="gel-function-UndefineAll">
+         <term>UndefineAll</term>
+         <listitem>
+          <synopsis>UndefineAll ()</synopsis>
+	  <para>Undefine all unprotected global variables
+	    (including functions and parameters).  Normally &app;
+	    considers protected variables as system defined functions
+	    and variables.  Note that <function>UndefineAll</function>
+	    only removes the global definition of symbols not local ones,
+	    so that it may be run from inside other functions safely.
+	  </para>
          </listitem>
         </varlistentry>
 
@@ -384,6 +412,15 @@ avoid them being accidentally overridden.</para>
          </listitem>
         </varlistentry>
 
+        <varlistentry id="gel-function-UserVariables">
+         <term>UserVariables</term>
+         <listitem>
+          <synopsis>UserVariables ()</synopsis>
+          <para>Return a vector of identifiers of
+	    user defined (unprotected) global variables.</para>
+         </listitem>
+        </varlistentry>
+
         <varlistentry id="gel-function-wait">
          <term>wait</term>
          <listitem>
@@ -722,6 +759,7 @@ greater than or equal to
 	  </para>
           <para>
 	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Euler-Mascheroni_constant";>Wikipedia</ulink> or
 	    <ulink url="http://planetmath.org/encyclopedia/MascheroniConstant.html";>Planetmath</ulink> or
 	    <ulink url="http://mathworld.wolfram.com/Euler-MascheroniConstant.html";>Mathworld</ulink> for more information.
 	  </para>
@@ -735,6 +773,7 @@ greater than or equal to
           <para>The Golden Ratio.</para>
           <para>
 	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Golden_ratio";>Wikipedia</ulink> or
 	    <ulink url="http://planetmath.org/encyclopedia/GoldenRatio.html";>Planetmath</ulink> or
 	    <ulink url="http://mathworld.wolfram.com/GoldenRatio.html";>Mathworld</ulink> for more information.
 	  </para>
@@ -745,7 +784,11 @@ greater than or equal to
          <term>Gravity</term>
          <listitem>
           <synopsis>Gravity</synopsis>
-          <para>Free fall acceleration.</para>
+          <para>Free fall acceleration at sea level.</para>
+          <para>
+	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Standard_gravity";>Wikipedia</ulink> for more information.
+	  </para>
          </listitem>
         </varlistentry>
 
@@ -761,6 +804,7 @@ greater than or equal to
 	  </para>
           <para>
 	    See
+	    <ulink url="http://en.wikipedia.org/wiki/E_(mathematical_constant)">Wikipedia</ulink> or
 	    <ulink url="http://planetmath.org/encyclopedia/E.html";>Planetmath</ulink> or
 	    <ulink url="http://mathworld.wolfram.com/e.html";>Mathworld</ulink> for more information.
 	  </para>
@@ -777,6 +821,7 @@ greater than or equal to
 	  </para>
           <para>
 	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Pi";>Wikipedia</ulink> or
 	    <ulink url="http://planetmath.org/encyclopedia/Pi.html";>Planetmath</ulink> or
 	    <ulink url="http://mathworld.wolfram.com/Pi.html";>Mathworld</ulink> for more information.
 	  </para>
@@ -801,6 +846,7 @@ greater than or equal to
 	  </para>
           <para>
 	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Absolute_value";>Wikipedia</ulink>,
 	    <ulink url="http://planetmath.org/encyclopedia/AbsoluteValue.html";>Planetmath (absolute value)</ulink>,
 	    <ulink url="http://planetmath.org/encyclopedia/ModulusOfComplexNumber.html";>Planetmath (modulus)</ulink>,
 	    <ulink url="http://mathworld.wolfram.com/AbsoluteValue.html";>Mathworld (absolute value)</ulink> or
@@ -821,9 +867,14 @@ for more information.
         <varlistentry id="gel-function-ComplexConjugate">
          <term>ComplexConjugate</term>
          <listitem>
-          <synopsis>ComplexConjugate (M)</synopsis>
+          <synopsis>ComplexConjugate (z)</synopsis>
           <para>Aliases: <function>conj</function> <function>Conj</function></para>
-          <para>Calculates the conjugate.</para>
+          <para>Calculates the complex conjugate of the complex number <varname>z</varname>.  If <varname>z</varname> is a vector or matrix,
+all its elements are conjugated.</para>
+          <para>
+	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Complex_conjugate";>Wikipedia</ulink> for more information.
+          </para>
          </listitem>
         </varlistentry>
 
@@ -832,6 +883,10 @@ for more information.
          <listitem>
           <synopsis>Denominator (x)</synopsis>
           <para>Get the denominator of a rational number.</para>
+          <para>
+	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Denominator";>Wikipedia</ulink> for more information.
+          </para>
          </listitem>
         </varlistentry>
 
@@ -840,6 +895,10 @@ for more information.
          <listitem>
           <synopsis>FractionalPart (x)</synopsis>
           <para>Return the fractional part of a number.</para>
+          <para>
+	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Fractional_part";>Wikipedia</ulink> for more information.
+          </para>
          </listitem>
         </varlistentry>
 
@@ -849,6 +908,10 @@ for more information.
           <synopsis>Im (z)</synopsis>
           <para>Aliases: <function>ImaginaryPart</function></para>
           <para>Get the imaginary part of a complex number.</para>
+          <para>
+	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Imaginary_part";>Wikipedia</ulink> for more information.
+          </para>
          </listitem>
         </varlistentry>
 
@@ -940,6 +1003,10 @@ we accept the convention that 0 is not a natural number.</para>
          <listitem>
           <synopsis>Numerator (x)</synopsis>
           <para>Get the numerator of a rational number.</para>
+          <para>
+	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Numerator";>Wikipedia</ulink> for more information.
+          </para>
          </listitem>
         </varlistentry>
 
@@ -949,6 +1016,10 @@ we accept the convention that 0 is not a natural number.</para>
           <synopsis>Re (z)</synopsis>
           <para>Aliases: <function>RealPart</function></para>
           <para>Get the real part of a complex number.</para>
+          <para>
+	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Real_part";>Wikipedia</ulink> for more information.
+          </para>
          </listitem>
         </varlistentry>
 
@@ -987,6 +1058,7 @@ value then <function>Sign</function> returns the direction or 0.
 	  </para>
           <para>
 	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Exponential_function";>Wikipedia</ulink> or
 	    <ulink url="http://planetmath.org/encyclopedia/LogarithmFunction.html";>Planetmath</ulink> or
 	    <ulink url="http://mathworld.wolfram.com/ExponentialFunction.html";>Mathworld</ulink> for more information.
 	  </para>
@@ -1240,6 +1312,7 @@ number is specified) of the given size returned.  For example
           <para>Calculates the arctan (inverse tan) function.</para>
           <para>
 	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Arctangent";>Wikipedia</ulink> or
 	    <ulink url="http://mathworld.wolfram.com/InverseTangent.html";>Mathworld</ulink> for more information.
 	  </para>
          </listitem>
@@ -1269,6 +1342,7 @@ number is specified) of the given size returned.  For example
 	  </para>
           <para>
 	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Atan2";>Wikipedia</ulink> or
 	    <ulink url="http://mathworld.wolfram.com/InverseTangent.html";>Mathworld</ulink> for more information.
 	  </para>
          </listitem>
@@ -1445,6 +1519,11 @@ number is specified) of the given size returned.  For example
          <listitem>
           <synopsis>BernoulliNumber (n)</synopsis>
           <para>Return the <varname>n</varname>th Bernoulli number.</para>
+          <para>
+	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Bernoulli_number";>Wikipedia</ulink> or
+	    <ulink url="http://mathworld.wolfram.com/BernoulliNumber.html";>Mathworld</ulink> for more information.
+	  </para>
          </listitem>
         </varlistentry>
 
@@ -1459,6 +1538,7 @@ number is specified) of the given size returned.  For example
 	  </para>
           <para>
 	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Chinese_remainder_theorem";>Wikipedia</ulink> or
 	    <ulink url="http://planetmath.org/encyclopedia/ChineseRemainderTheorem.html";>Planetmath</ulink> or
 	    <ulink url="http://mathworld.wolfram.com/ChineseRemainderTheorem.html";>Mathworld</ulink> for more information.
 	  </para>
@@ -1500,6 +1580,7 @@ number is specified) of the given size returned.  For example
 	    is a prime, using the Silver-Pohlig-Hellman algoritm.</para>
           <para>
 	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Discrete_logarithm";>Wikipedia</ulink> or
 	    <ulink url="http://planetmath.org/encyclopedia/DiscreteLogarithm.html";>Planetmath</ulink> or
 	    <ulink url="http://mathworld.wolfram.com/DiscreteLogarithm.html";>Mathworld</ulink> for more information.
 	  </para>
@@ -1525,6 +1606,7 @@ number is specified) of the given size returned.  For example
 	  </para>
           <para>
 	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Euler_phi";>Wikipedia</ulink> or
 	    <ulink url="http://planetmath.org/encyclopedia/EulerPhifunction.html";>Planetmath</ulink> or
 	    <ulink url="http://mathworld.wolfram.com/TotientFunction.html";>Mathworld</ulink> for more information.
 	  </para>
@@ -1559,6 +1641,10 @@ number is specified) of the given size returned.  For example
 [1      11      13
  1      2       1]</screen>
 	  </para>
+          <para>
+	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Factorization";>Wikipedia</ulink> for more information.
+	  </para>
          </listitem>
         </varlistentry>
 
@@ -1596,6 +1682,10 @@ number is specified) of the given size returned.  For example
 	    This is a fairly good factorization if your number is the product
 	    of two factors that are very close to each other.
 	  </para>
+          <para>
+	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Fermat_factorization";>Wikipedia</ulink> for more information.
+	  </para>
          </listitem>
         </varlistentry>
 
@@ -1667,6 +1757,7 @@ precalculated and returned in the second column.</para>
 	  </para>
           <para>
 	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Mersenne_prime";>Wikipedia</ulink>,
 	    <ulink url="http://planetmath.org/encyclopedia/MersenneNumbers.html";>Planetmath</ulink>,
 	    <ulink url="http://mathworld.wolfram.com/MersennePrime.html";>Mathworld</ulink> or 
 	    <ulink url="http://www.mersenne.org/";>GIMPS</ulink>
@@ -1837,6 +1928,7 @@ that is if <userinput>b^(n-1) == 1 mod n</userinput>.  This calles the <function
           </para>
           <para>
 	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Lucas%E2%80%93Lehmer_primality_test";>Wikipedia</ulink> or
 	    <ulink url="http://planetmath.org/encyclopedia/LucasLhemer.html";>Planetmath</ulink> or
 	    <ulink url="http://mathworld.wolfram.com/Lucas-LehmerTest.html";>Mathworld</ulink> for more information.
 	  </para>
@@ -1850,6 +1942,7 @@ that is if <userinput>b^(n-1) == 1 mod n</userinput>.  This calles the <function
           <para>Returns the <varname>n</varname>th Lucas number.</para>
           <para>
 	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Lucas_number";>Wikipedia</ulink> or
 	    <ulink url="http://planetmath.org/encyclopedia/LucasNumbers.html";>Planetmath</ulink> or
 	    <ulink url="http://mathworld.wolfram.com/LucasNumber.html";>Mathworld</ulink> for more information.
 	  </para>
@@ -1880,6 +1973,7 @@ that is if <userinput>b^(n-1) == 1 mod n</userinput>.  This calles the <function
 	  </para>
           <para>
 	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Mersenne_prime";>Wikipedia</ulink>,
 	    <ulink url="http://planetmath.org/encyclopedia/MersenneNumbers.html";>Planetmath</ulink>,
 	    <ulink url="http://mathworld.wolfram.com/MersennePrime.html";>Mathworld</ulink> or 
 	    <ulink url="http://www.mersenne.org/";>GIMPS</ulink>
@@ -1903,6 +1997,7 @@ that is if <userinput>b^(n-1) == 1 mod n</userinput>.  This calles the <function
 	  </para>
           <para>
 	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test";>Wikipedia</ulink> or
 	    <ulink url="http://planetmath.org/encyclopedia/MillerRabinPrimeTest.html";>Planetmath</ulink> or
 	    <ulink url="http://mathworld.wolfram.com/Rabin-MillerStrongPseudoprimeTest.html";>Mathworld</ulink> for more information.
 	  </para>
@@ -1920,6 +2015,7 @@ that is if <userinput>b^(n-1) == 1 mod n</userinput>.  This calles the <function
 	  </para>
           <para>
 	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test";>Wikipedia</ulink> or
 	    <ulink url="http://planetmath.org/encyclopedia/MillerRabinPrimeTest.html";>Planetmath</ulink> or
 	    <ulink url="http://mathworld.wolfram.com/Rabin-MillerStrongPseudoprimeTest.html";>Mathworld</ulink> for more information.
 	  </para>
@@ -2212,6 +2308,10 @@ that is if <userinput>b^(n-1) == 1 mod n</userinput>.  This calles the <function
          <listitem>
           <synopsis>DiagonalOf (M)</synopsis>
           <para>Gets the diagonal entries of a matrix as a column vector.</para>
+          <para>
+	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Diagonal_of_a_matrix#Matrices";>Wikipedia</ulink> for more information.
+          </para>
          </listitem>
         </varlistentry>
 
@@ -2284,6 +2384,7 @@ same size.  No conjugates are taken so this is a bilinear form even if working o
           <para>Is a matrix diagonal.</para>
           <para>
 	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Diagonal_matrix";>Wikipedia</ulink> or
 	    <ulink url="http://planetmath.org/encyclopedia/DiagonalMatrix.html";>Planetmath</ulink> for more information.
 	  </para>
          </listitem>
@@ -2430,6 +2531,7 @@ functions make this check.  Values can be any number including complex numbers.<
           <para>Make diagonal matrix from a vector.</para>
           <para>
 	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Diagonal_matrix";>Wikipedia</ulink> or
 	    <ulink url="http://planetmath.org/encyclopedia/DiagonalMatrix.html";>Planetmath</ulink> for more information.
           </para>
          </listitem>
@@ -3457,6 +3559,7 @@ function of two arguments or it can be a matrix giving a sesquilinear form.
           <para>Get the determinant of a matrix.</para>
           <para>
 	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Determinant";>Wikipedia</ulink> or
 	    <ulink url="http://planetmath.org/encyclopedia/Determinant2.html";>Planetmath</ulink> for more information.
           </para>
          </listitem>
@@ -3472,6 +3575,7 @@ elimination but not backaddition to <varname>M</varname>.  The pivot rows are
 divided to make all pivots 1.</para>
           <para>
 	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Row_echelon_form";>Wikipedia</ulink> or
 	    <ulink url="http://planetmath.org/encyclopedia/RowEchelonForm.html";>Planetmath</ulink> for more information.
           </para>
          </listitem>
@@ -3485,6 +3589,7 @@ divided to make all pivots 1.</para>
           <para>Get the reduced row echelon form of a matrix.  That is, apply gaussian elimination together with backaddition to <varname>M</varname>.</para>
           <para>
 	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Reduced_row_echelon_form";>Wikipedia</ulink> or
 	    <ulink url="http://planetmath.org/encyclopedia/ReducedRowEchelonForm.html";>Planetmath</ulink> for more information.
           </para>
          </listitem>
@@ -3568,6 +3673,7 @@ divided to make all pivots 1.</para>
 	  </para>
           <para>
 	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Fibonacci_number";>Wikipedia</ulink> or
 	    <ulink url="http://planetmath.org/encyclopedia/FibonacciSequence.html";>Planetmath</ulink> or
 	    <ulink url="http://mathworld.wolfram.com/FibonacciNumber.html";>Mathworld</ulink> for more information.
 	  </para>
@@ -3853,6 +3959,44 @@ do (
          </listitem>
         </varlistentry>
 
+        <varlistentry id="gel-function-EvenPeriodicExtension">
+         <term>EvenPeriodicExtension</term>
+         <listitem>
+          <synopsis>EvenPeriodicExtension (f,L)</synopsis>
+	  <para>Return a function which is even periodic extension of
+<function>f</function> with half period <varname>L</varname>.  That
+is a function defined on the interval <userinput>[0,L]</userinput>
+extended to be even on <userinput>[-L,L]</userinput> and then
+extended to be periodic with period <userinput>2*L</userinput>.</para>
+	  <para>
+	    See also
+	    <link linkend='gel-function-OddPeriodicExtension'>OddPeriodicExtension</link>
+	    and
+	    <link linkend='gel-function-PeriodicExtension'>PeriodicExtension</link>.
+	  </para>
+         </listitem>
+        </varlistentry>
+
+        <varlistentry id="gel-function-FourierSeriesFunction">
+         <term>FourierSeriesFunction</term>
+         <listitem>
+          <synopsis>FourierSeriesFunction (a,b,L)</synopsis>
+	  <para>Return a function which is a Fourier series with the
+coefficients given by the vectors <varname>a</varname> (sines) and
+<varname>b</varname> (cosines).  Note that <userinput>a@(1)</userinput> is
+the constant coefficient!  That is, <userinput>a@(n)</userinput> refers to
+the term <userinput>cos(x*(n-1)*pi/L)</userinput>, while
+<userinput>b@(n)</userinput> refers to the term
+<userinput>sin(x*n*pi/L)</userinput>.  Either <varname>a</varname>
+or <varname>b</varname> can be <constant>null</constant>.</para>
+          <para>
+	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Fourier_series";>Wikipedia</ulink> or
+	    <ulink url="http://mathworld.wolfram.com/FourierSeries.html";>Mathworld</ulink> for more information.
+          </para>
+         </listitem>
+        </varlistentry>
+
         <varlistentry id="gel-function-InfiniteProduct">
          <term>InfiniteProduct</term>
          <listitem>
@@ -3934,6 +4078,131 @@ do (
          </listitem>
         </varlistentry>
 
+        <varlistentry id="gel-function-NumericalFourierSeriesCoefficients">
+         <term>NumericalFourierSeriesCoefficients</term>
+         <listitem>
+          <synopsis>NumericalFourierSeriesCoefficients (f,L,N)</synopsis>
+	  <para>Return a vector of vectors <userinput>[a,b]</userinput>
+where <varname>a</varname> are the cosine coefficients and
+<varname>b</varname> are the sine coefficients of
+the Fourier series of
+<function>f</function> with half-period <varname>L</varname> (that is defined
+on <userinput>[-L,L]</userinput> and extended periodically) with coefficients
+up to <varname>N</varname>th harmonic computed numerically.  The coefficients are
+computed by numerical integration using
+<function>NumericalIntegral</function>.</para>
+          <para>
+	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Fourier_series";>Wikipedia</ulink> or
+	    <ulink url="http://mathworld.wolfram.com/FourierSeries.html";>Mathworld</ulink> for more information.
+          </para>
+         </listitem>
+        </varlistentry>
+
+        <varlistentry id="gel-function-NumericalFourierSeriesFunction">
+         <term>NumericalFourierSeriesFunction</term>
+         <listitem>
+          <synopsis>NumericalFourierSeriesFunction (f,L,N)</synopsis>
+	  <para>Return a function which is the Fourier series of
+<function>f</function> with half-period <varname>L</varname> (that is defined
+on <userinput>[-L,L]</userinput> and extended periodically) with coefficients
+up to <varname>N</varname>th harmonic computed numerically.  This is the
+trigonometric real series composed of sines and cosines.  The coefficients are
+computed by numerical integration using
+<function>NumericalIntegral</function>.</para>
+          <para>
+	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Fourier_series";>Wikipedia</ulink> or
+	    <ulink url="http://mathworld.wolfram.com/FourierSeries.html";>Mathworld</ulink> for more information.
+          </para>
+         </listitem>
+        </varlistentry>
+
+        <varlistentry id="gel-function-NumericalFourierCosineSeriesCoefficients">
+         <term>NumericalFourierCosineSeriesCoefficients</term>
+         <listitem>
+          <synopsis>NumericalFourierCosineSeriesCoefficients (f,L,N)</synopsis>
+	  <para>Return a vector of coefficients of the
+the cosine Fourier series of
+<function>f</function> with half-period <varname>L</varname>.  That is,
+we take <function>f</function> defined on <userinput>[0,L]</userinput>
+take the even periodic extension and compute the Fourier series, which
+only has sine terms.  The series is computed up to the 
+<varname>N</varname>th harmonic.  The coefficients are
+computed by numerical integration using
+<function>NumericalIntegral</function>.
+Note that <userinput>a@(1)</userinput> is
+the constant coefficient!  That is, <userinput>a@(n)</userinput> refers to
+the term <userinput>cos(x*(n-1)*pi/L)</userinput>.</para>
+          <para>
+	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Fourier_series";>Wikipedia</ulink> or
+	    <ulink url="http://mathworld.wolfram.com/FourierCosineSeries.html";>Mathworld</ulink> for more information.
+          </para>
+	  </listitem>
+        </varlistentry>
+
+        <varlistentry id="gel-function-NumericalFourierCosineSeriesFunction">
+         <term>NumericalFourierCosineSeriesFunction</term>
+         <listitem>
+          <synopsis>NumericalFourierCosineSeriesFunction (f,L,N)</synopsis>
+	  <para>Return a function which is the cosine Fourier series of
+<function>f</function> with half-period <varname>L</varname>.  That is,
+we take <function>f</function> defined on <userinput>[0,L]</userinput>
+take the even periodic extension and compute the Fourier series, which
+only has cosine terms.  The series is computed up to the 
+<varname>N</varname>th harmonic.  The coefficients are
+computed by numerical integration using
+<function>NumericalIntegral</function>.</para>
+          <para>
+	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Fourier_series";>Wikipedia</ulink> or
+	    <ulink url="http://mathworld.wolfram.com/FourierCosineSeries.html";>Mathworld</ulink> for more information.
+          </para>
+         </listitem>
+        </varlistentry>
+
+        <varlistentry id="gel-function-NumericalFourierSineSeriesCoefficients">
+         <term>NumericalFourierSineSeriesCoefficients</term>
+         <listitem>
+          <synopsis>NumericalFourierSineSeriesCoefficients (f,L,N)</synopsis>
+	  <para>Return a vector of coefficients of the
+the sine Fourier series of
+<function>f</function> with half-period <varname>L</varname>.  That is,
+we take <function>f</function> defined on <userinput>[0,L]</userinput>
+take the odd periodic extension and compute the Fourier series, which
+only has sine terms.  The series is computed up to the 
+<varname>N</varname>th harmonic.  The coefficients are
+computed by numerical integration using
+<function>NumericalIntegral</function>.</para>
+          <para>
+	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Fourier_series";>Wikipedia</ulink> or
+	    <ulink url="http://mathworld.wolfram.com/FourierSineSeries.html";>Mathworld</ulink> for more information.
+          </para>
+         </listitem>
+        </varlistentry>
+
+        <varlistentry id="gel-function-NumericalFourierSineSeriesFunction">
+         <term>NumericalFourierSineSeriesFunction</term>
+         <listitem>
+          <synopsis>NumericalFourierSineSeriesFunction (f,L,N)</synopsis>
+	  <para>Return a function which is the sine Fourier series of
+<function>f</function> with half-period <varname>L</varname>.  That is,
+we take <function>f</function> defined on <userinput>[0,L]</userinput>
+take the odd periodic extension and compute the Fourier series, which
+only has sine terms.  The series is computed up to the 
+<varname>N</varname>th harmonic.  The coefficients are
+computed by numerical integration using
+<function>NumericalIntegral</function>.</para>
+          <para>
+	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Fourier_series";>Wikipedia</ulink> or
+	    <ulink url="http://mathworld.wolfram.com/FourierSineSeries.html";>Mathworld</ulink> for more information.
+          </para>
+         </listitem>
+        </varlistentry>
+
         <varlistentry id="gel-function-NumericalIntegral">
          <term>NumericalIntegral</term>
          <listitem>
@@ -3966,6 +4235,24 @@ do (
          </listitem>
         </varlistentry>
 
+        <varlistentry id="gel-function-OddPeriodicExtension">
+         <term>OddPeriodicExtension</term>
+         <listitem>
+          <synopsis>OddPeriodicExtension (f,L)</synopsis>
+	  <para>Return a function which is odd periodic extension of
+<function>f</function> with half period <varname>L</varname>.  That
+is a function defined on the interval <userinput>[0,L]</userinput>
+extended to be odd on <userinput>[-L,L]</userinput> and then
+extended to be periodic with period <userinput>2*L</userinput>.</para>
+	  <para>
+	    See also
+	    <link linkend='gel-function-EvenPeriodicExtension'>EvenPeriodicExtension</link>
+	    and
+	    <link linkend='gel-function-PeriodicExtension'>PeriodicExtension</link>.
+	  </para>
+         </listitem>
+        </varlistentry>
+
         <varlistentry id="gel-function-OneSidedFivePointFormula">
          <term>OneSidedFivePointFormula</term>
          <listitem>
@@ -3982,6 +4269,22 @@ do (
          </listitem>
         </varlistentry>
 
+        <varlistentry id="gel-function-PeriodicExtension">
+         <term>PeriodicExtension</term>
+         <listitem>
+          <synopsis>PeriodicExtension (f,a,b)</synopsis>
+	  <para>Return a function which is the periodic extension of
+<function>f</function> defined on the interval <userinput>[a,b]</userinput>
+and has period <userinput>b-a</userinput>.</para>
+	  <para>
+	    See also
+	    <link linkend='gel-function-OddPeriodicExtension'>OddPeriodicExtension</link>
+	    and
+	    <link linkend='gel-function-EvenPeriodicExtension'>EvenPeriodicExtension</link>.
+	  </para>
+         </listitem>
+        </varlistentry>
+
         <varlistentry id="gel-function-RightLimit">
          <term>RightLimit</term>
          <listitem>
@@ -4185,7 +4488,11 @@ do (
          <term>UnitStep</term>
          <listitem>
           <synopsis>UnitStep (x)</synopsis>
-          <para>The unit step function is 0 for x&lt;0, 1 otherwise.  This is the integral of the Dirac Delta function.</para>
+          <para>The unit step function is 0 for x&lt;0, 1 otherwise.  This is the integral of the Dirac Delta function.  Also called the Heaviside function.</para>
+          <para>
+	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Unit_step";>Wikipedia</ulink> for more information.
+          </para>
          </listitem>
         </varlistentry>
 
diff --git a/help/C/genius.txt b/help/C/genius.txt
index 00b6a5e..5793ad4 100644
--- a/help/C/genius.txt
+++ b/help/C/genius.txt
@@ -173,9 +173,11 @@
 
                 7.3. Returning Functions
 
-                7.4. GEL Startup Procedure
+                7.4. True Local Variables
 
-                7.5. Loading Programs
+                7.5. GEL Startup Procedure
+
+                7.6. Loading Programs
 
    8. Matrices in GEL
 
@@ -1429,38 +1431,65 @@
 
 6.5. Global Variables and Scope of Variables
 
-   Like most programming languages, GEL has two different types of variables:
-   local and global. A local variable only exists in the context of the
-   function where it is set and all functions called from inside this
-   function. A global variable exists in all contexts. When you set a
-   variable on the toplevel command line, outside of any function, then it
-   will be a global. All functions will see it.
+   Like most programming languages, GEL has different types of variables.
+   Normally when a variable is defined in a function, it is visible from that
+   function and from all functions that are called (all higher contexts). For
+   example, suppose a function f defines a variable a and then calls function
+   g. Then function g can reference a. But once f returns, the variable a
+   goes out of scope. This is where GEL differs from a language such as C.
+   One could describe variables as being semi global in a sense For example,
+   the following code will print out 5. The function g cannot be called on
+   the top level (outside f as a will not be defined).
+
+ function f() = (a:=5; g());
+ function g() = print(a);
+ f();
 
-   When you set a variable inside a function, it will only be seen inside the
-   function, including all function calls that are made inside this function.
-   This is where GEL differs from a language such as C. One could describe
-   local variables as being semi global in this sense. For example the
-   following code will print out 5. but the function g cannot be called on
-   the top level as a will not be defined.
+   If you define a variable inside a function it will override any variables
+   defined in calling functions. For example, we modify the above code and
+   write:
 
  function f() = (a:=5; g());
  function g() = print(a);
+ a:=10;
  f();
 
-   Suppose you assign a value to an identifier inside a function, and this
-   identifier is also used for a global variable, or a variable set in a
-   calling function. Then this has the effect of creating a new local
-   variable inside the function. For example the following code will print
-   out 6 and not 5.
+   This code will still print out 5. But if you call g outside of f then you
+   will get a printout of 10. Note that setting a to 5 inside f does not
+   change the value of a at the top (global) level, so if you now check the
+   value of a it will still be 10.
+
+   Function arguments are exactly like variables defined inside the function,
+   except that they are initialized with the value that was passed to the
+   function. Other than this point, they are treated just like all other
+   variables defined inside the function.
+
+   Functions are treated exactly like variables. Hence you can locally
+   redefine functions. Normally (on the top level) you cannot redefine
+   protected variables and functions. But locally you can do this. Consider
+   the following session:
+
+ genius> function f(x) = sin(x)^2
+ = (`(x)=(sin(x)^2))
+ genius> function f(x) = sin(x)^2
+ = (`(x)=(sin(x)^2))
+ genius> function g(x) = ((function sin(x)=x^10);f(x))
+ = (`(x)=((sin:=(`(x)=(x^10)));f(x)))
+ genius> g(10)
+ = 1e20
+
+   Functions and variables defined at the top level are considered global.
+   They are visible from anywhere. As we said the following function f will
+   not change the value of a to 5.
 
  a=6;
  function f() = (a:=5);
- print(a);
+ f();
 
-   Sometimes however it is neccessary to set a global variable from inside a
-   function. For this, use the set function. Passing a string or a quoted
-   identifier to this function sets the variable globally. For example, to
-   set a to the value 3 you could call:
+   Sometimes, however, it is neccessary to set a global variable from inside
+   a function. When this behaviour is needed, use the set function. Passing a
+   string or a quoted identifier to this function sets the variable globally
+   (on the top level). For example, to set a to the value 3 you could call:
 
  set(`a,3)
 
@@ -1469,8 +1498,22 @@
  set("a",3)
 
    The set function always sets the toplevel global. There is no way to set a
-   local variable in some function from a subroutine. For this you must use
-   passing by reference.
+   local variable in some function from a subroutine. If this is required,
+   must use passing by reference.
+
+   So to recap in a more technical language: Genius operates with different
+   numberred contexts. The top level is the context 0 (zero). Whenever a
+   function is entered, the context is raised, and when the function returns
+   the context is lowered. A function or a variable is always visible from
+   all higher numbered contexts. When a variable was defined in a lower
+   numbered context, then setting this variable has the effect of creating a
+   new local variable in the current context number and this variable will
+   now be visible from all higher numbered contexts.
+
+   There are also true local variables which are not seen from anywhere but
+   the current context. Also when returning functions by value it may
+   reference variables not visible from higher context and this may be a
+   problem. See the sections True Local Variables and Returning Functions.
 
      ----------------------------------------------------------------------
 
@@ -1629,10 +1672,11 @@
    functions which construct special purpose functions according to some
    parameters. The tricky bit is what variables does the function see. The
    way this works in GEL is that when a function returns another function,
-   all identifiers referenced in the function body are prepended a private
-   dictionary of the returned function. So the function will see all
-   variables that were in scope when it was defined. For example we define a
-   function which returns a function which adds 5 to its argument.
+   all identifiers referenced in the function body that went out of scope are
+   prepended a private dictionary of the returned function. So the function
+   will see all variables that were in scope when it was defined. For example
+   we define a function which returns a function which adds 5 to its
+   argument.
 
  function f() = (
    k = 5;
@@ -1647,12 +1691,12 @@
    And g(5) should return 10.
 
    One thing to note is that the value of k that is used is the one that's in
-   effect when the f returns. So for example
+   effect when the f returns. For example:
 
  function f() = (
-   k = 5;
-   r = `(x) = (x+k);
-   k = 10;
+   k := 5;
+   function r(x) = (x+k);
+   k := 10;
    r
  )
 
@@ -1664,11 +1708,111 @@
    variables are added to the extra dictionary that are in the context that
    just ended and no longer exists. Variables used in the function that are
    in still valid contexts will work as usual, using the current value of the
-   variable.
+   variable. The only difference is with global variables and functions. All
+   identifiers that referenced global variables at time of the function
+   definition are not added to the private dictionary. This is to avoid much
+   unnecessary work when returning functions and would rarely be a problem.
+   For example, suppose that you delete the "k=5" from the function f, and at
+   the top level you define k to be say 5. Then when you run f, the function
+   r will not put k into the private dictionary because it was global
+   (toplevel) at the time of definition of r.
+
+   Sometimes it is better to have more control over how variables are copied
+   into the private dictionary. Since version 1.0.7, you can specify which
+   variables are copied into the private dictionary by putting extra square
+   brackets after the arguments with the list of variables to be copied
+   separated by commas. If you do this, then variables are copied into the
+   private dictionary at time of the function definition, and the private
+   dictionary is not touched afterwards. For example
+
+ function f() = (
+   k := 5;
+   function r(x) [k] = (x+k);
+   k := 10;
+   r
+ )
+
+   will return a function that when called will add 5 to its argument. The
+   local copy of k was created when the function was defined.
+
+   When you want the function to not have any private dictionary when put
+   empty square brackets after the argument list. Then no private dictionary
+   will be created at all. Doing this is good to increase efficiency when a
+   private dictionary is not needed or when you want the function to lookup
+   all variables as it sees them when called. For example suppose you want
+   the function returned from f to see the value of k from the toplevel
+   despite there being a local variable of the same name during definition.
+   So the code
+
+ function f() = (
+   k := 5;
+   function r(x) [] = (x+k);
+   r
+ );
+ k := 10;
+ g = f();
+ g(10)
+
+   will return 20 and not 15, which would happen if k with a value of 5 was
+   added to the private dictionary.
+
+     ----------------------------------------------------------------------
+
+7.4. True Local Variables
+
+   When passing functions into other functions, the normal scoping of
+   variables might be undesired. For example:
+
+ k := 10;
+ function r(x) = (x+k);
+ function f(g,x) = (
+   k := 5;
+   g(x)
+ );
+ f(r,1)
+
+   you probably want the function r when passed as g into f to see k as 10
+   rather than 5, so that the code returns 11 and not 6. However, as written,
+   the function when executed will see the k that is equal to 5. There are
+   two ways to solve this. One would be to have r get k in a private
+   dictionary using the square bracket notation section Returning Functions.
+
+   But there is another solution. Since version 1.0.7 there are true local
+   variables. These are variables that are visible only from the current
+   context and not from any called functions. We could define k as a local
+   variable in the function f. To do this add a local statement as the first
+   statement in the function (it must always be the first statement in the
+   function). You can also make any arguments be local variables as well.
+   That is,
+
+ function f(g,x) = (
+   local g,x,k;
+   k := 5;
+   g(x)
+ );
+
+   Then the code will work as expected and prints out 11. Note that the local
+   statement initializes all the refereced variables (except for function
+   arguments) to a null.
+
+   If all variables are to be created as locals you can just pass an asterix
+   instead of a list of variables. In this case the variables will not be
+   initialized until they are actually set of course. So the following
+   definition of f will also work:
+
+ function f(g,x) = (
+   local *;
+   k := 5;
+   g(x)
+ );
+
+   It is good practice that all functions that take other functions as
+   arguments use local variables. This way the passed function does not see
+   implementation details and get confused.
 
      ----------------------------------------------------------------------
 
-7.4. GEL Startup Procedure
+7.5. GEL Startup Procedure
 
    First the program looks for the installed library file (the compiled
    version lib.cgel) in the installed directory, then it looks into the
@@ -1680,7 +1824,7 @@
 
      ----------------------------------------------------------------------
 
-7.5. Loading Programs
+7.6. Loading Programs
 
    Sometimes you have a larger program that you wrote into a file and want to
    read in that file. In these situations, you have two options. You can keep
@@ -2190,6 +2334,15 @@
            internal GEL functions to avoid them being accidentally
            overridden.
 
+   ProtectAll
+
+ ProtectAll ()
+
+           Protect all currently defined variables, parameters and functions
+           from being modified. This is used on the internal GEL functions to
+           avoid them being accidentally overridden. Normally Genius
+           Mathematics Tool considers unprotected variables as user defined.
+
    set
 
  set (id,val)
@@ -2220,9 +2373,23 @@
 
  undefine (id)
 
+           Alias: Undefine
+
            Undefine a variable. This includes locals and globals, every value
            on all context levels is wiped. This function should really not be
-           used on local variables.
+           used on local variables. A vector of identifiers can also be
+           passed to undefine several variables.
+
+   UndefineAll
+
+ UndefineAll ()
+
+           Undefine all unprotected global variables (including functions and
+           parameters). Normally Genius Mathematics Tool considers protected
+           variables as system defined functions and variables. Note that
+           UndefineAll only removes the global definition of symbols not
+           local ones, so that it may be run from inside other functions
+           safely.
 
    unprotect
 
@@ -2230,6 +2397,13 @@
 
            Unprotect a variable from being modified.
 
+   UserVariables
+
+ UserVariables ()
+
+           Return a vector of identifiers of user defined (unprotected)
+           global variables.
+
    wait
 
  wait (secs)
@@ -2483,7 +2657,7 @@
            Euler's Constant gamma. Sometimes called the Euler-Mascheroni
            constant.
 
-           See Planetmath or Mathworld for more information.
+           See Wikipedia or Planetmath or Mathworld for more information.
 
    GoldenRatio
 
@@ -2491,13 +2665,15 @@
 
            The Golden Ratio.
 
-           See Planetmath or Mathworld for more information.
+           See Wikipedia or Planetmath or Mathworld for more information.
 
    Gravity
 
  Gravity
 
-           Free fall acceleration.
+           Free fall acceleration at sea level.
+
+           See Wikipedia for more information.
 
    e
 
@@ -2506,7 +2682,7 @@
            The base of the natural logarithm. e^x is the exponential function
            exp. This is the number approximately 2.71828182846...
 
-           See Planetmath or Mathworld for more information.
+           See Wikipedia or Planetmath or Mathworld for more information.
 
    pi
 
@@ -2515,7 +2691,7 @@
            The number pi, that is the ratio of a circle's circumference to
            its diameter. This is approximately 3.14159265359...
 
-           See Planetmath or Mathworld for more information.
+           See Wikipedia or Planetmath or Mathworld for more information.
 
      ----------------------------------------------------------------------
 
@@ -2530,8 +2706,8 @@
            Absolute value of a number and if x is a complex value the modulus
            of x. I.e. this the distance of x to the origin.
 
-           See Planetmath (absolute value), Planetmath (modulus), Mathworld
-           (absolute value) or Mathworld (complex modulus) for more
+           See Wikipedia, Planetmath (absolute value), Planetmath (modulus),
+           Mathworld (absolute value) or Mathworld (complex modulus) for more
            information.
 
    Chop
@@ -2542,11 +2718,14 @@
 
    ComplexConjugate
 
- ComplexConjugate (M)
+ ComplexConjugate (z)
 
            Aliases: conj Conj
 
-           Calculates the conjugate.
+           Calculates the complex conjugate of the complex number z. If z is
+           a vector or matrix, all its elements are conjugated.
+
+           See Wikipedia for more information.
 
    Denominator
 
@@ -2554,12 +2733,16 @@
 
            Get the denominator of a rational number.
 
+           See Wikipedia for more information.
+
    FractionalPart
 
  FractionalPart (x)
 
            Return the fractional part of a number.
 
+           See Wikipedia for more information.
+
    Im
 
  Im (z)
@@ -2568,6 +2751,8 @@
 
            Get the imaginary part of a complex number.
 
+           See Wikipedia for more information.
+
    IntegerQuotient
 
  IntegerQuotient (m,n)
@@ -2639,6 +2824,8 @@
 
            Get the numerator of a rational number.
 
+           See Wikipedia for more information.
+
    Re
 
  Re (z)
@@ -2647,6 +2834,8 @@
 
            Get the real part of a complex number.
 
+           See Wikipedia for more information.
+
    Sign
 
  Sign (x)
@@ -2672,7 +2861,7 @@
            The exponential function. This is the function e^x where e is the
            base of the natural logarithm.
 
-           See Planetmath or Mathworld for more information.
+           See Wikipedia or Planetmath or Mathworld for more information.
 
    float
 
@@ -2889,7 +3078,7 @@
 
            Calculates the arctan (inverse tan) function.
 
-           See Mathworld for more information.
+           See Wikipedia or Mathworld for more information.
 
    atanh
 
@@ -2909,7 +3098,7 @@
            If x<0 then it returns sign(y) * (pi - atan(|y/x|). When x=0 it
            returns sign(y) * pi/2. atan2(0,0) returns 0 rather then failing.
 
-           See Mathworld for more information.
+           See Wikipedia or Mathworld for more information.
 
    cos
 
@@ -3026,6 +3215,8 @@
 
            Return the nth Bernoulli number.
 
+           See Wikipedia or Mathworld for more information.
+
    ChineseRemainder
 
  ChineseRemainder (a,m)
@@ -3035,7 +3226,7 @@
            Find the x that solves the system given by the vector a and modulo
            the elements of m, using the Chinese Remainder Theorem.
 
-           See Planetmath or Mathworld for more information.
+           See Wikipedia or Planetmath or Mathworld for more information.
 
    CombineFactorizations
 
@@ -3064,7 +3255,7 @@
            Find discrete log of n base b in Fq, the finite field of order q,
            where q is a prime, using the Silver-Pohlig-Hellman algoritm.
 
-           See Planetmath or Mathworld for more information.
+           See Wikipedia or Planetmath or Mathworld for more information.
 
    Divides
 
@@ -3079,7 +3270,7 @@
            Compute the Euler phi function for n, that is the number of
            integers between 1 and n relatively prime to n.
 
-           See Planetmath or Mathworld for more information.
+           See Wikipedia or Planetmath or Mathworld for more information.
 
    ExactDivision
 
@@ -3103,6 +3294,8 @@
  [1      11      13
   1      2       1]
 
+           See Wikipedia for more information.
+
    Factors
 
  Factors (n)
@@ -3129,6 +3322,8 @@
            This is a fairly good factorization if your number is the product
            of two factors that are very close to each other.
 
+           See Wikipedia for more information.
+
    FindPrimitiveElementMod
 
  FindPrimitiveElementMod (q)
@@ -3176,7 +3371,8 @@
            known values which is relatively short. See also
            MersennePrimeExponents and LucasLehmer.
 
-           See Planetmath, Mathworld or GIMPS for more information.
+           See Wikipedia, Planetmath, Mathworld or GIMPS for more
+           information.
 
    IsNthPower
 
@@ -3291,7 +3487,7 @@
            Test if 2p-1 is a Mersenne prime using the Lucas-Lehmer test. See
            also MersennePrimeExponents and IsMersennePrimeExponent.
 
-           See Planetmath or Mathworld for more information.
+           See Wikipedia or Planetmath or Mathworld for more information.
 
    LucasNumber
 
@@ -3299,7 +3495,7 @@
 
            Returns the nth Lucas number.
 
-           See Planetmath or Mathworld for more information.
+           See Wikipedia or Planetmath or Mathworld for more information.
 
    MaximalPrimePowerFactors
 
@@ -3315,7 +3511,8 @@
            positive integers p such that 2p-1 is a prime. See also
            IsMersennePrimeExponent and LucasLehmer.
 
-           See Planetmath, Mathworld or GIMPS for more information.
+           See Wikipedia, Planetmath, Mathworld or GIMPS for more
+           information.
 
    MillerRabinTest
 
@@ -3326,7 +3523,7 @@
            usually better to use   IsPrime since that is faster and better on
            smaller integers.
 
-           See Planetmath or Mathworld for more information.
+           See Wikipedia or Planetmath or Mathworld for more information.
 
    MillerRabinTestSure
 
@@ -3336,7 +3533,7 @@
            assuming the Generalized Reimann Hypothesis the result is
            deterministic.
 
-           See Planetmath or Mathworld for more information.
+           See Wikipedia or Planetmath or Mathworld for more information.
 
    ModInvert
 
@@ -3535,6 +3732,8 @@
 
            Gets the diagonal entries of a matrix as a column vector.
 
+           See Wikipedia for more information.
+
    DotProduct
 
  DotProduct (u,v)
@@ -3591,7 +3790,7 @@
 
            Is a matrix diagonal.
 
-           See Planetmath for more information.
+           See Wikipedia or Planetmath for more information.
 
    IsIdentity
 
@@ -3702,7 +3901,7 @@
 
            Make diagonal matrix from a vector.
 
-           See Planetmath for more information.
+           See Wikipedia or Planetmath for more information.
 
    MakeVector
 
@@ -4471,7 +4670,7 @@
 
            Get the determinant of a matrix.
 
-           See Planetmath for more information.
+           See Wikipedia or Planetmath for more information.
 
    ref
 
@@ -4483,7 +4682,7 @@
            elimination but not backaddition to M. The pivot rows are divided
            to make all pivots 1.
 
-           See Planetmath for more information.
+           See Wikipedia or Planetmath for more information.
 
    rref
 
@@ -4494,7 +4693,7 @@
            Get the reduced row echelon form of a matrix. That is, apply
            gaussian elimination together with backaddition to M.
 
-           See Planetmath for more information.
+           See Wikipedia or Planetmath for more information.
 
      ----------------------------------------------------------------------
 
@@ -4549,7 +4748,7 @@
            recursively by Fibonacci(n) = Fibonacci(n-1) + Fibonacci(n-2) and
            Fibonacci(1) = Fibonacci(2) = 1.
 
-           See Planetmath or Mathworld for more information.
+           See Wikipedia or Planetmath or Mathworld for more information.
 
    FrobeniusNumber
 
@@ -4759,6 +4958,29 @@
            Attempt to calculate derivative by trying first symbolically and
            then numerically.
 
+   EvenPeriodicExtension
+
+ EvenPeriodicExtension (f,L)
+
+           Return a function which is even periodic extension of f with half
+           period L. That is a function defined on the interval [0,L]
+           extended to be even on [-L,L] and then extended to be periodic
+           with period 2*L.
+
+           See also OddPeriodicExtension and PeriodicExtension.
+
+   FourierSeriesFunction
+
+ FourierSeriesFunction (a,b,L)
+
+           Return a function which is a Fourier series with the coefficients
+           given by the vectors a (sines) and b (cosines). Note that a@(1) is
+           the constant coefficient! That is, a@(n) refers to the term
+           cos(x*(n-1)*pi/L), while b@(n) refers to the term sin(x*n*pi/L).
+           Either a or b can be null.
+
+           See Wikipedia or Mathworld for more information.
+
    InfiniteProduct
 
  InfiniteProduct (func,start,inc)
@@ -4827,6 +5049,85 @@
 
            Attempt to calculate numerical derivative.
 
+   NumericalFourierSeriesCoefficients
+
+ NumericalFourierSeriesCoefficients (f,L,N)
+
+           Return a vector of vectors [a,b] where a are the cosine
+           coefficients and b are the sine coefficients of the Fourier series
+           of f with half-period L (that is defined on [-L,L] and extended
+           periodically) with coefficients up to Nth harmonic computed
+           numerically. The coefficients are computed by numerical
+           integration using NumericalIntegral.
+
+           See Wikipedia or Mathworld for more information.
+
+   NumericalFourierSeriesFunction
+
+ NumericalFourierSeriesFunction (f,L,N)
+
+           Return a function which is the Fourier series of f with
+           half-period L (that is defined on [-L,L] and extended
+           periodically) with coefficients up to Nth harmonic computed
+           numerically. This is the trigonometric real series composed of
+           sines and cosines. The coefficients are computed by numerical
+           integration using NumericalIntegral.
+
+           See Wikipedia or Mathworld for more information.
+
+   NumericalFourierCosineSeriesCoefficients
+
+ NumericalFourierCosineSeriesCoefficients (f,L,N)
+
+           Return a vector of coefficients of the the cosine Fourier series
+           of f with half-period L. That is, we take f defined on [0,L] take
+           the even periodic extension and compute the Fourier series, which
+           only has sine terms. The series is computed up to the Nth
+           harmonic. The coefficients are computed by numerical integration
+           using NumericalIntegral. Note that a@(1) is the constant
+           coefficient! That is, a@(n) refers to the term cos(x*(n-1)*pi/L).
+
+           See Wikipedia or Mathworld for more information.
+
+   NumericalFourierCosineSeriesFunction
+
+ NumericalFourierCosineSeriesFunction (f,L,N)
+
+           Return a function which is the cosine Fourier series of f with
+           half-period L. That is, we take f defined on [0,L] take the even
+           periodic extension and compute the Fourier series, which only has
+           cosine terms. The series is computed up to the Nth harmonic. The
+           coefficients are computed by numerical integration using
+           NumericalIntegral.
+
+           See Wikipedia or Mathworld for more information.
+
+   NumericalFourierSineSeriesCoefficients
+
+ NumericalFourierSineSeriesCoefficients (f,L,N)
+
+           Return a vector of coefficients of the the sine Fourier series of
+           f with half-period L. That is, we take f defined on [0,L] take the
+           odd periodic extension and compute the Fourier series, which only
+           has sine terms. The series is computed up to the Nth harmonic. The
+           coefficients are computed by numerical integration using
+           NumericalIntegral.
+
+           See Wikipedia or Mathworld for more information.
+
+   NumericalFourierSineSeriesFunction
+
+ NumericalFourierSineSeriesFunction (f,L,N)
+
+           Return a function which is the sine Fourier series of f with
+           half-period L. That is, we take f defined on [0,L] take the odd
+           periodic extension and compute the Fourier series, which only has
+           sine terms. The series is computed up to the Nth harmonic. The
+           coefficients are computed by numerical integration using
+           NumericalIntegral.
+
+           See Wikipedia or Mathworld for more information.
+
    NumericalIntegral
 
  NumericalIntegral (f,a,b)
@@ -4853,6 +5154,17 @@
 
            Attempt to calculate numerical right derivative.
 
+   OddPeriodicExtension
+
+ OddPeriodicExtension (f,L)
+
+           Return a function which is odd periodic extension of f with half
+           period L. That is a function defined on the interval [0,L]
+           extended to be odd on [-L,L] and then extended to be periodic with
+           period 2*L.
+
+           See also EvenPeriodicExtension and PeriodicExtension.
+
    OneSidedFivePointFormula
 
  OneSidedFivePointFormula (f,x0,h)
@@ -4865,6 +5177,15 @@
 
            Compute one-sided derivative using three-point formula.
 
+   PeriodicExtension
+
+ PeriodicExtension (f,a,b)
+
+           Return a function which is the periodic extension of f defined on
+           the interval [a,b] and has period b-a.
+
+           See also OddPeriodicExtension and EvenPeriodicExtension.
+
    RightLimit
 
  RightLimit (f,x0)
@@ -5020,7 +5341,10 @@
  UnitStep (x)
 
            The unit step function is 0 for x<0, 1 otherwise. This is the
-           integral of the Dirac Delta function.
+           integral of the Dirac Delta function. Also called the Heaviside
+           function.
+
+           See Wikipedia for more information.
 
    cis
 
@@ -5898,3 +6222,8 @@
    the License, or (at your option) any later version. A copy of this license
    can be found at this link, or in the file COPYING included with the source
    code of this program.
+
+   Jiri Lebl was during various parts of the development partially supported
+   for the work by NSF grant DMS 0900885 and the University of Illinois at
+   Urbana-Champaign. The software has been used for both teaching and
+   research.
diff --git a/help/C/genius.xml b/help/C/genius.xml
index dc71809..c821809 100644
--- a/help/C/genius.xml
+++ b/help/C/genius.xml
@@ -3,7 +3,7 @@
 "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd"; [
   <!ENTITY app "<application>Genius Mathematics Tool</application>">
   <!ENTITY appname "Genius">
-  <!ENTITY appversion "1.0.6">
+  <!ENTITY appversion "1.0.7">
   <!ENTITY manrevision "0.2.3">
   <!ENTITY date "March 2009">
 
@@ -1827,43 +1827,82 @@ for conditional evaluation works here as well. For example, <literal>1 or a=1</l
       <sect1 id="genius-gel-variables-global">
         <title>Global Variables and Scope of Variables</title>
 	<para>
-	  Like most programming languages, GEL has two different types
-	  of variables: local and global.  A local variable only exists
-	  in the context of the function where it is set and all functions
-	  called from inside this function.  A global variable
-	  exists in all contexts.  When you set a variable on the toplevel
-	  command line, outside of any function, then it will be a global.
-	  All functions will see it.
+	  Like most programming languages, GEL has different types
+	  of variables.  Normally when a variable is defined in a function,
+	  it is visible from that function and from all functions that are
+	  called (all higher contexts).  For example, suppose a function
+	  <function>f</function> defines a variable <varname>a</varname>
+	  and then calls function <function>g</function>.  Then
+	  function <function>g</function> can reference
+	  <varname>a</varname>.  But once <function>f</function> returns,
+	  the variable <varname>a</varname> goes out of scope.
+	  This is where GEL differs from a language
+	  such as C.  One could describe variables as being semi global
+	  in a sense
+	  For example, the following code will print out 5.
+	  The function <function>g</function> cannot be called on the
+	  top level (outside <function>f</function> as <varname>a</varname>
+	  will not be defined).
+<programlisting>function f() = (a:=5; g());
+function g() = print(a);
+f();
+</programlisting>
         </para>
         <para>
-          When you set a variable inside a function, it will only be seen
-	  inside the function, including all function calls that are made
-	  inside this function.  This is where GEL differs from a language
-	  such as C.  One could describe local variables as being semi global
-	  in this sense.  For example the following code will print out 5.
-	  but the function <function>g</function> cannot be called on the
-	  top level as <varname>a</varname> will not be defined.
+	  If you define a variable inside a function it will override
+	  any variables defined in calling functions.  For example,
+	  we modify the above code and write:
 <programlisting>function f() = (a:=5; g());
 function g() = print(a);
+a:=10;
 f();
 </programlisting>
+	  This code will still print out 5.  But if you call
+	  <function>g</function> outside of <function>f</function> then
+	  you will get a printout of 10.  Note that
+	  setting <varname>a</varname>
+	  to 5 inside <function>f</function> does not change
+	  the value of <varname>a</varname> at the top (global) level,
+	  so if you now check the value of <varname>a</varname> it will
+	  still be 10.
+        </para>
+	<para>
+	  Function arguments are exactly like variables defined inside
+	  the function, except that they are initialized with the value
+	  that was passed to the function.  Other than this point, they are
+	  treated just like all other variables defined inside the
+	  function.
 	</para>
-        <para>
-	  Suppose you assign a value to an identifier inside a function,
-	  and this identifier is also used for a global variable, or a
-	  variable set in a calling function.  Then this has the effect of
-	  creating a new local variable inside the function.  For example
-	  the following code will print out 6 and not 5.
+	<para>
+	  Functions are treated exactly like variables.  Hence you can
+	  locally redefine functions.  Normally (on the top level) you
+	  cannot redefine protected variables and functions.  But locally
+	  you can do this.  Consider the following session:
+<screen><prompt>genius> </prompt><userinput>function f(x) = sin(x)^2</userinput>
+= (`(x)=(sin(x)^2))
+<prompt>genius> </prompt><userinput>function f(x) = sin(x)^2</userinput>
+= (`(x)=(sin(x)^2))
+<prompt>genius> </prompt><userinput>function g(x) = ((function sin(x)=x^10);f(x))</userinput>
+= (`(x)=((sin:=(`(x)=(x^10)));f(x)))
+<prompt>genius> </prompt><userinput>g(10)</userinput>
+= 1e20
+</screen>
+	</para>
+	<para>
+	  Functions and variables defined at the top level are
+	  considered global.  They are visible from anywhere.  As we
+	  said the following function <function>f</function>
+	  will not change the value of <varname>a</varname> to 5.
 <programlisting>a=6;
 function f() = (a:=5);
-print(a);
+f();
 </programlisting>
-	</para>
-        <para>
-	  Sometimes however it is neccessary to set
-a global variable from inside a function. For this, use the
+	  Sometimes, however, it is neccessary to set
+a global variable from inside a function.  When this behaviour is needed,
+use the
 <function>set</function> function. Passing a string or a quoted identifier to
-this function sets the variable globally. For example, to set
+this function sets the variable globally (on the top level).
+For example, to set
 <varname>a</varname> to the value 3 you could call:
 <programlisting>set(`a,3)
 </programlisting>
@@ -1874,8 +1913,30 @@ or:
         <para>
 	  The <function>set</function> function always sets the toplevel
 	  global.  There is no way to set a local variable in some function
-	  from a subroutine.  For this you must use passing by reference.
+	  from a subroutine.  If this is required, must use passing by
+	  reference.
         </para>
+	<para>
+	  So to recap in a more technical language:  Genius operates with
+	  different numberred contexts.  The top level is the context 0
+	  (zero).  Whenever a function is entered, the context is raised,
+	  and when the function returns the context is lowered.  A function
+	  or a variable is always visible from all higher numbered contexts.
+	  When a variable was defined in a lower numbered context, then
+	  setting this variable has the effect of creating a new local
+	  variable in the current context number and this variable
+	  will now be visible from all higher numbered contexts.
+	</para>
+	<para>
+	  There are also true local variables which are not seen from
+	  anywhere but the current context.  Also when returning functions
+	  by value it may reference variables not visible from higher context
+	  and this may be a problem.  See the sections
+	  <link linkend="genius-gel-true-local-variables">True
+	  Local Variables</link> and
+	  <link linkend="genius-gel-returning-functions">Returning
+	  Functions</link>.
+	</para>
       </sect1>
 
     <sect1 id="genius-gel-returning">
@@ -2068,8 +2129,10 @@ else
 	  to some parameters.  The tricky bit is what variables does the
 	  function see.  The way this works in GEL is that when a function
 	  returns another function, all identifiers referenced in the
-	  function body are prepended a private dictionary of the returned
-	  function.  So the function will see all variables that were in scope
+	  function body that went out of scope
+	  are prepended a private dictionary of the returned
+	  function.  So the function will see all variables that were in
+	  scope
 	  when it was defined.  For example we define a function which
 	  returns a function which adds 5 to its argument.
 <programlisting>function f() = (
@@ -2087,16 +2150,17 @@ g(5)
 	<para>
 	  One thing to note is that the value of <varname>k</varname>
 	  that is used is the one that's in effect when the
-	  <function>f</function> returns.  So for example
+	  <function>f</function> returns.  For example:
 <programlisting>function f() = (
-  k = 5;
-  r = `(x) = (x+k);
-  k = 10;
+  k := 5;
+  function r(x) = (x+k);
+  k := 10;
   r
 )
 </programlisting>
-	  will return a function that adds 10 to its argument rather than 5.
-	  This is because the extra dictionary is created only when the context
+	  will return a function that adds 10 to its argument rather than
+	  5.  This is because the extra dictionary is created only when
+	  the context
 	  in which the function was defined ends, which is when the function
 	  <function>f</function> returns.  This is consistent with how you
 	  would expect the function <function>r</function> to work inside
@@ -2106,9 +2170,131 @@ g(5)
 	  no longer exists.  Variables
 	  used in the function that are in still valid contexts will work
 	  as usual, using the current value of the variable.
+	  The only difference is with global variables and functions.
+	  All identifiers that referenced global variables at time of
+	  the function definition are not added to the private dictionary.
+	  This is to avoid much unnecessary work when returning functions
+	  and would rarely be a problem.  For example, suppose that you
+	  delete the "k=5" from the function <function>f</function>,
+	  and at the top level you define <varname>k</varname> to be
+	  say 5.  Then when you run <function>f</function>, the function
+	  <function>r</function> will not put <varname>k</varname> into
+	  the private dictionary because it was global (toplevel)
+	  at the time of definition of <function>r</function>.
+	</para>
+	<para>
+	  Sometimes it is better to have more control over how variables
+	  are copied into the private dictionary.  Since version 1.0.7,
+	  you can specify which
+	  variables are copied into the private dictionary by putting
+	  extra square brackets after the arguments with the list of
+	  variables to be copied separated by commas.
+	  If you do this, then variables are
+	  copied into the private dictionary at time of the function
+	  definition, and the private dictionary is not touched afterwards.
+	  For example
+<programlisting>function f() = (
+  k := 5;
+  function r(x) [k] = (x+k);
+  k := 10;
+  r
+)
+</programlisting>
+	  will return a function that when called will add 5 to its
+	  argument.  The local copy of <varname>k</varname> was created
+	  when the function was defined.
+	</para>
+	<para>
+	  When you want the function to not have any private dictionary
+	  when put empty square brackets after the argument list.  Then
+	  no private dictionary will be created at all.  Doing this is
+	  good to increase efficiency when a private dictionary is not
+	  needed or when you want the function to lookup all variables
+	  as it sees them when called.  For example suppose you want
+	  the function returned from <function>f</function> to see
+	  the value of <varname>k</varname> from the toplevel despite
+	  there being a local variable of the same name during definition.
+	  So the code
+<programlisting>function f() = (
+  k := 5;
+  function r(x) [] = (x+k);
+  r
+);
+k := 10;
+g = f();
+g(10)
+</programlisting>
+	  will return 20 and not 15, which would happen if
+	  <varname>k</varname> with a value of 5 was added to the private
+	  dictionary.
 	</para>
     </sect1>
 
+    <sect1 id="genius-gel-true-local-variables">
+      <title>True Local Variables</title>
+      <para>
+	When passing functions into other functions, the normal scoping of
+	variables might be undesired.  For example:
+<programlisting>k := 10;
+function r(x) = (x+k);
+function f(g,x) = (
+  k := 5;
+  g(x)
+);
+f(r,1)
+</programlisting>
+	you probably want the function <function>r</function>
+	when passed as <function>g</function> into <function>f</function>
+	to see <varname>k</varname> as 10 rather than 5, so that
+	the code returns 11 and not 6.  However, as written, the function
+	when executed will see the <varname>k</varname> that is
+	equal to 5.  There are two ways to solve this.  One would be
+	to have <function>r</function> get <varname>k</varname> in a
+	private dictionary using the square bracket notation section
+	<link linkend="genius-gel-returning-functions">Returning
+	Functions</link>.
+      </para>
+      <para>
+	But there is another solution.  Since version 1.0.7 there are
+	true local variables.  These are variables that are visible only
+	from the current context and not from any called functions.
+	We could define <varname>k</varname> as a local variable in the
+	function <function>f</function>.  To do this add a
+	<command>local</command> statement as the first statement in the
+	function (it must always be the first statement in the function).
+	You can also make any arguments be local variables as well.
+	That is,
+<programlisting>function f(g,x) = (
+  local g,x,k;
+  k := 5;
+  g(x)
+);
+</programlisting>
+	Then the code will work as expected and prints out 11.
+	Note that the <command>local</command> statement initializes
+	all the refereced variables (except for function arguments) to
+	a <constant>null</constant>.
+      </para>
+      <para>
+	If all variables are to be created as locals you can just pass an
+	asterix instead of a list of variables.  In this case the variables
+	will not be initialized until they are actually set of course.
+	So the following definition of <function>f</function>
+	will also work:
+<programlisting>function f(g,x) = (
+  local *;
+  k := 5;
+  g(x)
+);
+</programlisting>
+      </para>
+      <para>
+	It is good practice that all functions that take other functions
+	as arguments use local variables.  This way the passed function 
+	does not see implementation details and get confused.
+      </para>
+    </sect1>
+
     <sect1 id="genius-gel-startup-procedure">
       <title>GEL Startup Procedure</title>
       <para>
@@ -2807,9 +2993,12 @@ typsetting in LaTeX, MathML (XML), or in Troff.</para>
   <chapter id="genius-about"> 
     <title>About &app;</title> 
 
-    <para> &app; was written by Ji&#345;&iacute; (George) Lebl (<email>jirka 5z com</email>).  The history of &app; goes back to late 1997.  It was the first
-calculator program for GNOME, but it then grew beyond being just a desktop calculator.  To find more information about &app;, please visit the <ulink url="http://www.jirka.org/genius.html"; type="http">Genius Web
-	page</ulink>.
+    <para> &app; was written by Ji&#345;&iacute; (George) Lebl
+(<email>jirka 5z com</email>).  The history of &app; goes back to late
+1997.  It was the first calculator program for GNOME, but it then grew
+beyond being just a desktop calculator.  To find more information about
+&app;, please visit the <ulink url="http://www.jirka.org/genius.html";
+type="http">Genius Web page</ulink>.
     </para>
     <para>
       To report a bug or make a suggestion regarding this application or
@@ -2824,6 +3013,11 @@ calculator program for GNOME, but it then grew beyond being just a desktop calcu
       <ulink url="ghelp:gpl" type="help">link</ulink>, or in the file
       COPYING included with the source code of this program. </para>
 
+    <para>Ji&#345;&iacute; Lebl was during various parts of the development
+      partially supported for the work by NSF grant DMS 0900885 and
+      the University of Illinois at Urbana-Champaign.  The software has
+      been used for both teaching and research.</para>
+
   </chapter>
 
 </book>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]