Maple m-files For Scientific WorkPlace

Introduction

Scientific WorkPlace provides menu-driven access to the most commonly used Maple functions. Many Maple functions that are less frequently needed, but which are nevertheless useful can be accessed from the Maple kernel within Scientific WorkPlace. Using these functions requires the same knowledge that is necessary for their use in Maple itself, namely, the Maple function name and the exact calling sequence. These functions will not be discussed here.

Maple is perhaps most often used in interactive command line fashion. The extent of its built-in functions permits such usage. However, Maple can also be used as a programming language to create user-defined functions that meet specialized needs. Such functions can be saved in "m-files" for later use.

Scientific WorkPlace can also be used to read m-files that have been compiled with a compatible release of Maple. For example, the set up of Scientific WorkPlace installs the m-files tcifcns.m and gradeprocs.m in the Scientific WorkPlace directory. The m-files that are available on this site can be used to extend the mathematical capabilities of Scientific WorkPlace 3.5. Download any one of these files in the usual way. Using Netscape, for instance, right click on the link to the file and choose the "Save as ..." option. (If you display the file in a browser window, then you will see plain text that is not intended for human comprehension.) Save the file with its *.m extension in your Scientific WorkPlace directory.

The m-files that you find here were compiled with Maple V R5.1. They are intended to be used with Scientific WorkPlace 3.5, only. Versions that work with earlier releases of Scientific WorkPlace will not be provided.

There is no support for any of these m-files beyond what you see on this web page. They were not written by MacKichan Software and are not being distributed by MacKichan Software; please do not ask them for support. Please report any errors that you find to brian@math.wustl.edu.

The m-Files

Using m-Files

Step 1: Select Define Maple Name from the Define submenu of the Compute menu.

This will bring up a dialogue box titled "Define Maple Name." Step 2 will describe how to fill in its fields.

Step 2: In the first field (namely, Maple Name) of the "Define Maple Name" dialogue box enter the name of the desired function as it appears in the calling sequence for that function. (The calling sequences are listed below.) The Maple name is followed by a left parenthesis which is in turn followed by a comma-separated list of arguments. Enter one (admissable) character for each argument that is given in the calling sequence. The second field (namely the Scientific WorkPlace Name) should be entered exactly as the first field with one exception: the Maple name must be replaced with one character. Choose the "In internal Maple format file" option. Make sure to supply a correct path to the necessary m-file.

As an example, consider the function twinprimes in the file numbertheory.m. Its calling sequence in Maple is twinprimes(a..b). It takes one argument - that single argument is a Maple range and is therefore of the form a..b. The following figure shows the proper way to fill in the Scientific WorkPlace dialogue box. (Another letter could have been used as the Scientific WorkPlace name instead of "t".) Notice that the argument of twinprimes is entered with a single character representing the range a..b.

Step 3: Call the function in the way that is indicated in the calling sequence, substituting the Scientific WorkPlace name for the Maple name. For example, the number of twin prime pairs (p,p+2) with p in the interval [1,100000] is obtained by typing t(1..100000) in math mode and then selecting Evaluate from the Compute menu.

Approximations

Description of the Functions in approximate.m

BernsteinApprox - Returns a Bernstein Uniform Approximating Polynomial
Calling Sequence:
     BernsteinApprox(f,N,a..b,x)
Parameters:
     f    - a name (of the function to be approximated)
     N    - a positive integer (the degree of the approximating polynomial)
     a..b - a range
     x    - an expression (eg. the variable of the approximating polynomial)
Description:
     Suppose that  f  is the name of a function that has been defined.
     The call BernsteinApprox(f,N,a..b,x) returns a degree N polynomial
     in the variable x that approximates  f  on the real interval [a,b].


fourier_series - Returns a Fourier Polynomial
Calling Sequence:
     fourier_series(f,N,a..b,x)
     fourier_series(f,N,x)
Parameters:
     f    - a name (of the function to be approximated)
     N    - a nonnegative integer
     a..b - a range
     x    - an expression (eg. the variable of the approximating trigonometric 
             polynomial)
Description:
     Suppose that  f  is the name of a function that has been defined.
     The call fourier_series(f,N,a..b,x) returns the Fourier polynomial
     a[0]/2+sum(a[k]*cos(2*Pi/L*k*x)+b[k]*sin(2*Pi/L*k*x),k=1..N) where
     a[k]=2/L*int(f(t)*cos(2*Pi/L*k*t),t=a..b), 
     b[k]=2/L*int(f(t)*sin(2*Pi/L*k*t),t=a..b),
     and L = b-a. 
     The three argument call fourier_series(f,N,x)  is equivalent to 
     fourier_series(f,N,-Pi..Pi,x).
     The extent to which the expressions in the return are computed is
     commensurate with the specificity of the parameters that are passed
     to fourier_series.


interpolate - Returns an Interpolating Polynomial
Calling Sequence:
     interpolate(f,abscissae,x)
Parameters:
     f         - a name (of the function that is to be interpolated)
     abscissae - a list of distinct real numbers
     expr      - an algebraic expression
Description:
     Suppose that  f  is the name of a function that has been defined.
     Suppose that abscissae := [xi[1],xi[2],...,xi[N+1]].
     The call interpolate(f,abscissae,x) returns the degree N polynomial
     in the variable x that interpolates the points 
     [xi[1],f([xi[1])], [xi[2],f([xi[2])], ... , [xi[N+1],f([xi[N+1])]


TaylorPoly - Returns a Taylor Polynomial
Calling Sequence:
     TaylorPoly(f,c,N,x)
Parameters:
     f - a name (of a function)
     c - a real number (the center of the Taylor approximation)
     N - a positive integer
     x - an algebraic expression
Description:
     Suppose that  f  is the name of a function that has been defined, that
     c is a real number, and that N is a nonnegative integer.
     Then TaylorPoly(f,c,N,x) returns a Taylor polynomial of the 
     function named  f, centered at the real number  c, of degree N (in
     general). 


TaylorPoly_seq - Returns a Sequence of Taylor Polynomials
Calling Sequence:
     TaylorPoly_seq(f,c,N,x)
Parameters:
     f - a name (of a function)
     c - a real number (the center of the Taylor approximation)
     N - a positive integer, a range of positive integers, or a list of
         positive integers
     x - an algebraic expression
Description:
     Suppose that  f  is the name of a function that has been defined.
     If L := [n[1],n[2],...,n[k]] is a list of positive integers, then
     TaylorPoly_seq(f,c,L,x) returns a sequence of Taylor polynomials of
     the function named  f, centered at the real number  c, of degrees
     n[1], n[2], ... , n[k]. If the third argument is a positive integer N,
     then the call TaylorPoly_seq(f,c,N,x) is equivalent to 
     TaylorPoly_seq(f,c,[1,2,3,...,N],x). If the third argument is a range
     of positive integers a..b, then the call TaylorPoly_seq(f,c,a..b,x) is 
     equivalent to TaylorPoly_seq(f,c,[a,a+1,a+2,...,b],x).

Example - TaylorPoly_seq:
Let g(t) = sin(t) - ln(( 1-t)^2). Over the interval [2,8] we wish to plot the degrees 1, 2 and 4 Taylor polynomials of g centered at t = 5. We define the Maple name TaylorPoly_seq(f,c,N,x) as the Scientific WorkPlace function T(f,c,N,x). We define g(t) as indicated. The following plot results from plotting T(g,5,[1,2,4],x). The plot of g(x) (in red) was then added.



Example - BernsteinApprox:
Let g(t) be as in the preceding example. We define the Maple name BernsteinApprox(f,N,r,x) as the Scientific WorkPlace name B(f,N,r,x). Then B(g,10,2..8,x) is the degree 10 polynomial in x that approximates g(x) over the interval [2,8] as constructed in S. Bernstein's constructive proof of the Uniform Approximation by Polynomials Theorem. The plot of B(g,10,2..8,x) appears in blue. The plot of g(x) was added.



Example - fourier_series:
Let f(t) = sin(t) - ln(( 1-t)^2). Over the interval [2,8] we wish to plot the Fourier polynomial of f of order 5. We define f and then define the Maple name fourier_series(g,N,r,x) with the Scientific WorkPlace name F(g,N,r,x). We then plot F(f,5,2..8,x) as indicated.



Since f does not periodize to a continuous function, poor approximation at the end points is expected.


Calculus Functions

Description of the Functions in calculus.m

RecurseReductionFormula - Recurses an Inactive Reduction Formula
Calling Sequence:
     RecurseReductionFormula(rf,n,k)
Parameters:
    rf    - a reduction formula
     n    - the parameter that is reduced
     k    - a nonnegative integer
Description:
     If rf is an equation of the form Int(f(x,n),x) = ... Int(f(x,n-s),x) ...
     where s is a nonnegative integer, then RecurseReductionFormula(rf,n,k) 
     returns equation eqn. The left side of eqn is Int(f(x,k),x). The right
     side of eqn is obtained by successively applying the left side of rf 
     until int(f(x,r) is attained with 0 <= r < s . This function should
     only be used with integrals Int(f(x,n),x) that Maple cannot evaluate.


recurseReductionFormula - Recurses an Active Reduction Formula
Calling Sequence:
     recurseReductionFormula(rf,n,k)
Parameters:
    rf    - a reduction formula
     n    - the parameter that is reduced
     k    - a nonnegative integer
Description:
     If rf is an equation of the form int(f(x,n),x) = ... int(f(x,n-s),x) ...
     where s is a nonnegative integer, then recurseReductionFormula(rf,n,k) 
     returns equation eqn. The left side of eqn is int(f(x,n),x). The right
     side of eqn is obtained by successively applying the left side of rf 
     k times to evaluate int(f(x,n-j*s) (j=1..k). Thus, 
     recurseReductionFormula(rf,n,0) returns rf and recurseReductionFormula(rf,n,k)
     returns int(f(x,n),x) = ... int(f(x,n-(k+1)*s),x) ...


Example - RecurseReductionFormula:
The following screen capture shows the result of applying this function (with R as its Scientific WorkPlace name). The three functions on the preceding line were generically defined prior to the call to R. (With the mouse insert point in th function F(x,n), select New Definition from the Define submenu of the Compute menu. Repeat with A(x,n) and B(x,n).)




Example - recurseReductionFormula:
The following screen capture shows the result of applying this function (with r as its Scientific WorkPlace name):




Calendar Functions

Description of the Functions in calendar.m

calendar - Returns the Calendar for a Specified Month
Calling Sequence:
     calendar(m,y)
Parameters:
     m    - an integer between 1 and 12 (representing the months, in order,
            with January = 1)
     y    - a positive integer greater than 1592(the year)
Description:
     With m and y as described, calendar(m,y) returns the calendar for the
     specified month. 


whichday - Returns a Week Day Name
Calling Sequence:
     whichday(m,d,y)
Parameters:
     m    - an integer between 1 and 12 (representing the months, in order,
            with January = 1)
     d    - an integer between 1 and 28, or 1 and 29, or 1 and 30, or 1 and 31
     y    - a positive integer greater than 1592(the year)
Description:
     If (m,d,y) represents a valid calendar date, then whichday(m,d,y) returns
     the name of the day on which that date fell (or will fall).


Example - calendar:
With w(m,d,y) defined as the Scientific WorkPlace name for the Maple name whichday(m,d,y) and c(m,y) defined as the Scientific WorkPlace name for the Maple name calendar(m,y), the following applications of Evaluate from the Compute menu illustrate that my father, Louis Blank, was born on a Thursday and that the month in which my son Andrew was born began with a Tuesday and ended with a Thursday.



Loop Constructions

Description of the Functions in loops.m

double_sum - Returns a Double sum
Calling Sequence:
     double_sum(expr,i=a..b,j=c..d)
Parameters:
     expr - an expression
     j    - a name (of the index of the inner sum)
     k    - a name (of the index of the outer sum)
     a..b - a range (of the inner sum)
     c..d - a range (of the outer sum)
Description:
     The call double_sum(f(j,k),j=a..b,k=c..d) returns

                                        d   /  b          \
                                      ----- |-----        |
                                       \    | \           |
                                        )   |  )   f(j, k)|
                                       /    | /           |
                                      ----- |-----        |
                                      k = c \j = a        /

     As a precaution, the limits c and d of the outer sum may
     not depend on the index variable j of the inner sum.

     Note: The letter i stands for the square root of -1 in Scientific
     WorkPlace and cannot be used as an index of summation!


pointplot_seq - Returns a Sequence of Points for Plotting
Calling Sequence:
     pointplot_seq(f,a,b,s)
Parameters:
     f - a name (of a function)
     a - a real number (left or right endpoint)
     b - a real number (right or left endpoint)
     s - a step size (optional)
Description:
     If f is the name of a function that has been defined and if a and b 
     are real numbers, then pointplot_seq(f,a,b,s) returns the sequence
     [a,f(a)],[a+s,f(a+s)],[a+2*s,f(a+2*s)],...,[a+n*s,f(a+n*s)]
     The sequence stops when a+(n+1)*s assumes a value outside the range a..b.
     If the fourth argument s is omitted, then the step size defaults to 1.
     If the fourth argument s is specified but does not have the same sign as
     b-a, then -s is used as the step size.
     Note: When pointplot_seq(f,a,b,s) is defined as a Maple name (as discussed
     in Step 2 of the section titled "Using m-Files"), all four arguments should be 
     included. It is only when pointplot_seq(f,a,b,s) is called from Scientific 
     WorkPlace that the fourth argument is optional. 

split_list - Splits a list of Ordered Pairs into Lists of Abscissae and Ordinates
Calling Sequence:
     split_list(L)
Parameters:
     L - a list of ordered pairs
Description:
     If L = [[x1,y1],[x2,y2],[x3,y3],...,[xN,yN]], then the call
     split_list(L) returns the sequence [x1,x2,x3,...,xN],[y1,y2,y3,...,yN] .

Example - pointplot_seq:
Consider the problem of plotting

as a function of x over the interval [0,2]. Define

Trying to plot f(x) directly will result in an error message asserting that there are too many variables. Instead, define L(f,a,b,s) as the Maple name for pointplot_seq(f,a,b,s) and Evaluate

The return is a sequence of twentyone points on the graph of f. The tail end of the sequence looks like


Position the mouse insert point within this sequence and select Rectangular from the Plot2D submenu of the Compute menu.

For a smoother plot, decrease the step size.

Example - double_sum:
The following screen capture illustrates what can happen when Scientific WorkPlace is called on to evaluate certain double sums.

Instead, define the Maple Name double_sum(a,b,c) as the Scientific WorkPlace name S(a,b,c). An evaluation of S(j, j=k..n, k=1..n) results in



Number Theory

Description of the Functions in numbertheory.m

EulerPartitions - Returns the number of partitions of an integer
Calling Sequence:
     EulerPartitions(n)
Parameters:
     n - an integer
Description:
     If n is an integer then EulerPartitions(n) is the number of ways n can be written
     as a sum of one or more positive integers (without regard to order of summands).
     For example, EulerPartitions(5) = 7 because 5 = 5, 5 = 4+1, 5 = 3+2, 5 = 3+1+1,
     5 = 2+2+1, 5 = 2+1+1+1, 5 = 1+1+1+1+1.


farey - Returns a particular Farey fraction
Calling Sequence:
     farey(k,n)
Parameters:
     n - an integer greater than 1
     k - a positive integer less than or equal to number_farey(n)
Description:
     If n is an integer greater than 1 and if k is a positive integer that is not greater 
     than number_farey(n), then farey(k,n) returns the k'th term of  farey_seq(n).


farey_seq - Returns a Farey sequence
Calling Sequence:
     farey_seq(n)
Parameters:
     n - an integer greater than 1
Description:
     If n is an integer greater than 1, then farey_seq(n) returns the list of Farey numbers
     in increasing order. These are the rational numbers strictly between 0 and 1
     that can be expressed with a positive integer denominator less than or equal to n.


FranelLandauD - Measures the uniformity with which a Farey sequence partitions 
                the unit interval
Calling Sequence:
     FranelLandauD(x)
Parameters:
     x - a real number greater than 2
Description:
     If x is a real number greater than 1, then FranelLandauD(x) returns
     sum(abs(farey(k,n)-k/(N+1)), k = 1..N)
     where n = floor(x) and N = number_farey(n). Notice that the N numbers
     1/(N+1), 2/(N+1), ..., N/(N+1) partition the unit interval (0,1) into
     N+1 equal pieces. The N numbers farey(1,n), farey(2,n), ... , farey(n,n)
     also partitions (0,1) into N subintervals, but the lengths of the subintervals
     in the Farey dissection are generally unequal. FranelLandauD(x) measures the
     deviation of farey_seq(floor(x)) from a uniform partition.


inv_mobius_transform_for_swp - Returns the inverse Mobius transformation of a function
Calling Sequence:
     inv_mobius_transform(F,n)
Parameters:
     F - the name of a function
     n - a positive integer
Description:
     If F is a function name and if n is a positive integer, then inv_mobius_transform(F,n)
     returns the sum of F(d)*mobius(n/d) over the positive integer divisors d of n. 


Liouville - Returns 1 or -1 depending on the number of prime power divisors of an integer
Calling Sequence:
     Liouville(n)
Parameters:
     n - an integer
Description:
     If n is an integer, then Liouville(n) returns -1 if the total number of prime power 
     divisors of n is odd and 1 otherwise. For example, Liouville(72) = -1 since 
     72 = (2^3)*(3^2) has the five prime power divisors 2, 2^2, 2^3, 3, and 3^2. 



Mangoldt - Returns ln(p) or 0 depending on whether its argument is a power of a prime p
               or not.
Calling Sequence:
     Mangoldt(n)
Parameters:
     n - a positive integer
Description:
     If n is a positive integer, then Mangoldt(n) returns ln(p) if n is a power of a prime p and
     0 if n has more than one prime divisor. 


MertensM - Returns the sum of the mobius function
Calling Sequence:
     MertensM(x)
Parameters:
     x - a real number greater than or equal to 1
Description:
     If x is a real number greater than or equal to 1, then MertensM(x) returns
     sum(mobius(k), k=1..floor(x)). Among square-free positive integers between
     1 and floor(x), MertensM(x) tallies the number that are a product of an
     even number of primes, the number that are a product of an
     odd number of primes, and returns the (signed) difference.


number_farey - Returns the number of terms in a Farey sequence
Calling Sequence:
     number_farey(n)
Parameters:
     n - an integer greater than 1
Description:
     If n is an integer greater than 1, then number_farey(n) returns the number of
     terms in th list farey_seq(n) of Farey numbers.


pcf - Returns the number of primes less than or equal to a number
Calling Sequence:
     pcf(x)
Parameters:
     x - a positive  number
Description:
     If x is a positive number, then pcf(x) is the number of prime integers
     that are less than or equal to x. The Prime Number Theorem states
     that the prime counting function pcf(x) is asymptotic to x/ln(x).



prime_info - Returns information pertaining to prime numbers
Calling Sequence:
     prime_info(n1, n2)
Parameters:
     n1 - a positive integer. If n2 = 5, then n1 may also be [m] where m belongs to
            {1,2,3,...,35,36}.
     n2 - 1, 2, 3, 4, or 5 
Description:
     If n2=1, then prime_info(n1, n2) returns true if n1 is a prime and false otherwise.
     If n2=2, then prime_info(n1, n2) returns the n1'th prime.
     If n2=3, then prime_info returns the smallest prime that is greater than n1.
     If n2=4, then prime_info returns the greatest prime that is smaller than n1.
     If n2=5 and n1 is a positive integer, then prime_info(n1,n2) returns 
     2^n1-1 if this number is prime ( a so-called Mersenne prime), false if this number
     is not prime (as always happens for composite n1 as well as for many prime n1), and
     FAIL if  Maple cannot determine whether the number is prime. If n2=5 and n1=[m],
     then prime_info([m],n2) returns the m'th Mersenne prime.

     Notice that prime_info is a wrapper for the five separate Maple routines: isprime,
     ithprime, nextprime, prevprime, and mersenne.


prime_power_divisor_count - Returns the number of prime power divisors of an integer
Calling Sequence:
     prime_power_divisor_count(n)
Parameters:
     n - an integer
Description:
     If n is an integer, then prime_power_divisor_count(n) returns the total number 
     of prime power divisors of n. For example, prime_power_divisor_count(72) = 5 
     since 72 = (2^3)*(3^2) has the five prime power divisors 2, 2^2, 2^3, 3, and 3^2. 


RamanujanTau - The Ramanujan tau function
Calling Sequence:
     RamanujanTau(n)
Parameters:
     n - a positive integer
Description:
     If n is a positive integer, then RamanujanTau(n) is the coefficient of x^n in the
     Maclaurin series of x*product( (1-x^k)^24, k= 1.. n). If n has a prime power factor
     that is greater than 31, then the calculation of RamanujanTau(n) is very 
     time-consuming.


sumoverdivisors - Sums an expression over positive integer divsors 
Calling Sequence:
     sumoverdivisors(expr,x,n)
Parameters:
     expr - an algebraic expression
         x - a name
         n - a positive integer
Description:
     If n is a positive integer, then sumoverdivisors(expr,x,n) calculates each
     positive divisor d of n, evaluates expr for x = d, and then returns the
     sum of these expressions.


twinprimes - Returns the number of twin prime pairs in an interval
Calling Sequence:
     twinprimes(m..n)
Parameters:
     m..n - a range of real numbers with n > m.
Description:
     If m and n are real numbers with n >  m, then twinprimes(m..n) is the 
     number of primes p in the interval [m,n] with p + 2 also prime (whether or
     not p + 2 is in the interval [m,n]).  For example, twinprimes(3..5) returns 2
     because 3 and 5 is a pair of twin primes and 5 and 7 is a pair of twin primes,
     and the first number of each pair is in the interval [3,5].

Brian E. Blank
Department of Mathematics
Washington University in St. Louis
1 Brookings Drive
St. Louis, MO  63130
 
Phone: (314) - 935 - 6763
Fax:   (314) - 935 - 6839 
 
                    e-mail: brian@math.wustl.edu

Last Updated: February 28 2000

Clock Local time of download (Courtesy of the U.S. Naval Observatory)