Maple Libraries
- Page ID
- 5181
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)
( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\id}{\mathrm{id}}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\kernel}{\mathrm{null}\,}\)
\( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\)
\( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\)
\( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)
\( \newcommand{\vectorA}[1]{\vec{#1}} % arrow\)
\( \newcommand{\vectorAt}[1]{\vec{\text{#1}}} % arrow\)
\( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vectorC}[1]{\textbf{#1}} \)
\( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)
\( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)
\( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\(\newcommand{\avec}{\mathbf a}\) \(\newcommand{\bvec}{\mathbf b}\) \(\newcommand{\cvec}{\mathbf c}\) \(\newcommand{\dvec}{\mathbf d}\) \(\newcommand{\dtil}{\widetilde{\mathbf d}}\) \(\newcommand{\evec}{\mathbf e}\) \(\newcommand{\fvec}{\mathbf f}\) \(\newcommand{\nvec}{\mathbf n}\) \(\newcommand{\pvec}{\mathbf p}\) \(\newcommand{\qvec}{\mathbf q}\) \(\newcommand{\svec}{\mathbf s}\) \(\newcommand{\tvec}{\mathbf t}\) \(\newcommand{\uvec}{\mathbf u}\) \(\newcommand{\vvec}{\mathbf v}\) \(\newcommand{\wvec}{\mathbf w}\) \(\newcommand{\xvec}{\mathbf x}\) \(\newcommand{\yvec}{\mathbf y}\) \(\newcommand{\zvec}{\mathbf z}\) \(\newcommand{\rvec}{\mathbf r}\) \(\newcommand{\mvec}{\mathbf m}\) \(\newcommand{\zerovec}{\mathbf 0}\) \(\newcommand{\onevec}{\mathbf 1}\) \(\newcommand{\real}{\mathbb R}\) \(\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}\) \(\newcommand{\laspan}[1]{\text{Span}\{#1\}}\) \(\newcommand{\bcal}{\cal B}\) \(\newcommand{\ccal}{\cal C}\) \(\newcommand{\scal}{\cal S}\) \(\newcommand{\wcal}{\cal W}\) \(\newcommand{\ecal}{\cal E}\) \(\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}\) \(\newcommand{\gray}[1]{\color{gray}{#1}}\) \(\newcommand{\lgray}[1]{\color{lightgray}{#1}}\) \(\newcommand{\rank}{\operatorname{rank}}\) \(\newcommand{\row}{\text{Row}}\) \(\newcommand{\col}{\text{Col}}\) \(\renewcommand{\row}{\text{Row}}\) \(\newcommand{\nul}{\text{Nul}}\) \(\newcommand{\var}{\text{Var}}\) \(\newcommand{\corr}{\text{corr}}\) \(\newcommand{\len}[1]{\left|#1\right|}\) \(\newcommand{\bbar}{\overline{\bvec}}\) \(\newcommand{\bhat}{\widehat{\bvec}}\) \(\newcommand{\bperp}{\bvec^\perp}\) \(\newcommand{\xhat}{\widehat{\xvec}}\) \(\newcommand{\vhat}{\widehat{\vvec}}\) \(\newcommand{\uhat}{\widehat{\uvec}}\) \(\newcommand{\what}{\widehat{\wvec}}\) \(\newcommand{\Sighat}{\widehat{\Sigma}}\) \(\newcommand{\lt}{<}\) \(\newcommand{\gt}{>}\) \(\newcommand{\amp}{&}\) \(\definecolor{fillinmathshade}{gray}{0.9}\)A Sample File
We create a file in the currentdir named source-code . Here are its contents.
|
We read the file into the Maple session.
>
read "source-code";
We can then execute the procedures.
>
MyModule:-proc1();
>
MyModule:-proc2(3,4);
The Standard Library
The standard library for Maple consists of 2 files:
- maple.ind : an index of the contents of the library.
- maple.lib : the actual library
The directory where these files exist depends on the details of the installation. For a default installation the directory is given by the libname command.
>
libname;
We can list the contents of the directory.
FileTools[ListDirectory](libname);
["include","classic","maple.hdb","units.lib","units.ind","scandsea.lib","scandsea.ind",
"maplets.lib","maplets.ind","maple.lib","maple.ind","Student.lib","Student.ind",
"CodeGeneration.lib","CodeGeneration.ind","CodeGeneration.hdb","standard.hdb"]
You can see from the above that there are other libraries and directories, in addition to the standard Maple library.
Depending on the details of your installation, you may be able to add your own modules to the standard library, or create new libraries in the directory specified by libname. Both of these are bad ideas. Adding a broken module to the standard library can make Maple non-functioning. Adding a new library to the system area means that updating your version of Maple can cause you to lose your new library.
Creating a New Library Named maple.lib
As discussed, in general it is a bad idea to install your libraries in the system areas of Maple. We shall create a new library in the empty directory "/home/harrison/tmp/mylibs."
>
new_lib_dir := "/home/harrison/tmp/mylibs":
>
FileTools[ListDirectory](new_lib_dir);
We create an empty library with slots for 10 archive members using the Maple archive program march .
>
march('create', new_lib_dir, 10);
This has created 2 files, maple.ind and maple.lib, in the directory.
>
FileTools[ListDirectory](new_lib_dir);
The library has no contents yet.
>
march('list', "/home/harrison/tmp/mylibs/maple.lib");
Then we modify the libname variable to include the new directory.
>
libname := new_lib_dir, libname;
Maple will search the directories listed in libname in the order in which they are listed. Thus, new_lib_dir will be searched before the system directory.
Recall that in the first section we loaded the procedures in the MyModule module into Maple. We add the module to the library.
>
savelib('MyModule');
Now the module is in the library. In fact, it has been saved to the first library found in the first directory listed in libname .
>
march('list', "/home/harrison/tmp/mylibs/maple.lib");
[["MyModule.m", [2004, 1, 29, 11, 14, 3], 1024, 116],
[":-1.m", [2004, 1, 29, 11, 14, 3], 1140, 105],
[":-2.m", [2004, 1, 29, 11, 14, 3], 1245, 85]]
We can load the library into a fresh session and use its procedures, provided we tell Maple where to find it.
>
restart;
>
new_lib_dir := "/home/harrison/tmp/mylibs":
>
libname := new_lib_dir, libname;
>
with(MyModule);
>
proc1();
>
proc2(3,4);
We can also use the procedures in the new library without using the with command.
>
restart;
>
new_lib_dir := "/home/harrison/tmp/mylibs":
>
libname := new_lib_dir, libname;
>
MyModule:-proc1();
>
MyModule:-proc2(3,4);
Creating a Library With an Arbitrary Name
In the previous section we created a library with the same name as the system library: maple.lib . Here we shall create a library named ThisLibrary.lib in the directory /home/harrison/tmp/otherlibs . Initially this directory is empty. We begin with a fresh Maple session and load the file containing the definition of the module that we want to place in the library. Our current directory contains only that source file.
>
restart;
>
currentdir();
>
FileTools[ListDirectory]( currentdir() );
>
read "source-code";
Now we set libname to include the directory where we wish to create the library and use march to create it.
>
new_lib_dir := "/home/harrison/tmp/otherlibs":
>
libname := new_lib_name, libname;
>
FileTools[ListDirectory]( new_lib_name );
>
march('create', cat( new_lib_name, "/ThisLibrary.lib"), 10);
>
FileTools[ListDirectory]( new_lib_name );
The savelib command by default saves into the first library file that it finds in going through the directories specified in libname. Thus, we can save MyModule directly.
>
savelib('MyModule');
>
march('list', cat( new_lib_name, "/ThisLibrary.lib"));
[["MyModule.m", [2004, 1, 29, 13, 17, 29], 1024, 116],
[":-1.m", [2004, 1, 29, 13, 17, 29], 1140, 105],
[":-2.m", [2004, 1, 29, 13, 17, 29], 1245, 85]]
You may specify a specific library by setting the savelibname variable.
About the save Command
The save command saves names or symbols, by default into a file in Maple's internal format. For example, if our current directory contains only the file source-code , then we can create a file try.m containing a name definition.
>
restart;
>
currentdir();
>
FileTools[ListDirectory]( currentdir() );
>
foo := "hi sailor";
>
save foo, "try.m";
>
FileTools[ListDirectory]( currentdir() );
The definition can then later be read into a new Maple session.
>
restart;
>
foo;
>
read "try.m";
>
foo;
However, if the save command is issued from a directory where there is a library, then the "file name" will be added to the library instead. We will illustrate with the ThisLibrary.lib that we created in the previous section.
>
restart;
>
currentdir("/home/harrison/tmp/otherlibs");
>
FileTools[ListDirectory]( currentdir() );
>
march('list', "ThisLibrary.lib" );
[["MyModule.m", [2004, 1, 29, 13, 17, 29], 1024, 116],
[":-1.m", [2004, 1, 29, 13, 17, 29], 1140, 105],
[":-2.m", [2004, 1, 29, 13, 17, 29], 1245, 85]]
>
foo := "hi sailor";
>
save( foo, "try.m" );
>
FileTools[ListDirectory]( currentdir() );
>
march('list', "ThisLibrary.lib" );
[["MyModule.m", [2004, 1, 29, 13, 17, 29], 1024, 116],
[":-1.m", [2004, 1, 29, 13, 17, 29], 1140, 105],
["try.m", [2004, 1, 29, 13, 38, 32], 1356, 26],
[":-2.m", [ 2004, 1, 29, 13, 17, 29], 1245, 85]]
Then, we can read the definition of foo contained in try.m in a fresh Maple session. This time, the read command has dug the definition out of the library.
>
restart;
>
currentdir("/home/harrison/tmp/otherlibs");
>
foo;
>
read "try.m";
>
foo;
Initialization
When you have libraries in non-system areas, it can be a pain to have to begin every Maple session by manipulating libname.
You can change the value of libname once and for all via an initialization file. The details of the name and location of this file depends on the operating system of the computer and on how Maple was installed by the administrator. Details may be found in the on-line Help Browser in Getting Started ... => Configure Maple ... => initialization files .
Regardless of the name and placement of the initialization file, putting the following line in it will set the value of libname:
libname := "/some/directory", libname: |
Note the trailing colon in the above command. This keeps the new value of libname from being printed to your screen when Maple is invoked.