/* Filename improved.mac

   ***************************************************************
   *							         *
   *                     <package name>                          *
   *                <functionality description>                  *
   *                                                             *
   *          from: Computer Algebra in Applied Math.            *
   *                   by Rand (Pitman,1984)                     *
   *                Programmed by Richard Rand                   *
   *      These files are released to the public domain          *
   *            						 *
   * Reverse engineered from file newimprv.bk1                   *
   * David Billinghurst - Feb 2004                               *
   *                                                             *
   ***************************************************************
*/ /*   This program uses recursive functions to find 
the transition curves in Mathieu's equation.  To call it,
type:
                        TC()
*/

tc():=(input(),sign:1,find(),if n > 0 then (sign:-1,find()))$
input():=(n:read("enter transition curve number n"),
      m:read("enter degree of truncation"))$
find():=(remarray(b,e),delta:n^2/4,for i thru m do delta:delta+d(i)*e^i,
     print("delta=",delta),print(" "))$
a(j,k):=
  if j < 0 or k < 0 then 
    0
  else if j = 0 and k = n then 
    1
  else if j = 0 then 
    0
  else if k = n then 
    0
  else if numberp(b[j,k]) then
    b[j,k]
  else if k = 0 then 
    b[j,k]:(-a(j-1,2)/2-sum(d(i)*a(j-i,0),i,1,j))/(n^2/4)
  else 
    b[j,k]:(-(a(j-1,k-2)+a(j-1,k+2)+sign*a(j-1,2-k))/2
      -sum(d(i)*a(j-i,k),i,1,j))/((n^2-k^2)/4)
$

d(j):=
  if numberp(e[j]) then
    e[j]
  else if n = 0 then 
    e[j]:-a(j-1,2)/2
  else 
    e[j]:-(a(j-1,n-2)+a(j-1,n+2)+sign*a(j-1,2-n))/2
$
