namespace stuff applied to Zeilberger package



As an example of the namespace stuff I've been working on,
I've modified my copy of the zeilberger package
(maxima/share/contrib/Zeilberger) to use it.
Perhaps this is more interesting than the contrived examples
I posted a while ago.

(%i2) load_namespace (zeilberger);
(%o2)                   #<PACKAGE MAXIMA>

(A minor wart: load_namespace returns the namespace in which zeilberger
is loaded instead of zeilberger itself.)

Only a few symbols (the user-level functions) are exported from zeilberger.
The intent here is to avoid cluttering the Maxima namespace when
zeilberger is imported.

(%i3) external_symbols (zeilberger);
(%o3) [zeilberger at Gosper, zeilberger at Zeilberger,
zeilberger at parGosper, zeilberger at GosperSum,
zeilberger at AntiDifference]

GosperSum is not in the default namespace unless it is explicitly imported.

(%i4) GosperSum (x^k, k, 1, n);
                                k
(%o4)                GosperSum(x , k, 1, n)
(%i5) zeilberger at GosperSum (x^k, k, 1, n);
                          n + 1
                         x          x
(%o5)                    ------ - -----
                         x - 1    x - 1

This function call yields a symbol which is in the zeilberger namespace.

(%i6) zeilberger at GosperSum (1 / ((a - k)!*k!), k, 1, n);
(%o6)            zeilberger at NON_GOSPER_SUMMABLE

Now import the functions which are declared external in zeilberger.

(%i7) import (zeilberger);
(%o7) [[zeilberger at Gosper, zeilberger at Zeilberger,
zeilberger at parGosper, zeilberger at GosperSum,
zeilberger at AntiDifference]]
(%i8) GosperSum (x^k, k, 1, n);
                          n + 1
                         x          x
(%o8)                    ------ - -----
                         x - 1    x - 1

This flag is not exported (neither are any other variables in zeilberger)
so it still has to be qualified with the namespace name.

(%i9) zeilberger at Gosper_in_Zeilberger;
(%o9)                         true
(%i10) Zeilberger ((-1)^k*k / (4*k^2 - 1), k, k);

Dependent equations eliminated:  (1)
                                1
                            k + -
                                2
(%o10)                  [[- -----, [1]]]
                             2 k
(%i11) zeilberger at Gosper_in_Zeilberger : false;
(%o11)                        false
(%i12) Zeilberger ((-1)^k*k / (4*k^2 - 1), k, k);

Dependent equations eliminated:  (3)
------------------------------------------------------------
WARNING!
Multiple solutions have been found.
A lower order might probably work and yield fewer solutions.
------------------------------------------------------------
             2 k - 1       2       2 k + 1    2
(%o12)     [[-------, [0, 2 ]], [- -------, [2 , 0]]]
                k                     k


This exercise has helped me understand some problems.

(1) I started out trying this with the linearalgebra package,
  but some files there are Lisp and it is harder to make sure
  that all symbols of interest are accessible. Also symbols
  in the CL package are printed in a clumsy way, which I
  don't know how to fix at this point. Zeilberger is
  implemented entirely as Maxima scripts.

(2) Since Maxima strings are Lisp symbols, it's necessary
  at present to qualify operator names --
  e.g. if op(expr) = maxima@"+" then ....

(3) At present the Lisp package :maxima has no external
  symbols. I've put in code to export symbols whose names
  begin with $ or m. Probably we could talk about a less
  hackish policy.

Anyway I hope this sheds some light on namespaces in Maxima.

Robert Dodier

PS. This code implements Maxima namespaces via the Lisp package system:
http://maxima.sourceforge.net/misc/namespaces.lisp
Here is some verbiage about the namespace stuff:
http://maxima.sourceforge.net/wiki/index.php/User-level%20namespaces%20in%20Maxima