Sindbad~EG File Manager

Current Path : /usr/home/beeson/MathXpert/series/
Upload File :
Current File : /usr/home/beeson/MathXpert/series/pseries.c

/* manipulation of the SERIES data structure */
/* M. Beeson, for Mathpert */
/* 6.25.98 */
/* 7.22.98 last modified */


#include "globals.h"
#include "pseries.h"

/*_____________________________________________________________*/
PSERIES expandSeries( PSERIES a, unsigned short n)
/* expand series a to order n using the general term to
generate more initial terms. */
{ unsigned short m = ORDER(a);
  PSERIES ans;
  term v;
  int i;
  if(m >= n)
     return a;
  ans = make_term(SERIES,(unsigned short)(n+2));
  for(i=0;i<=n;i++)
     { if(i<=m)
          ARGREP(ans,i,ARG(i,a));
       else
          { subst(make_int(i),var0,GENERALTERM(a),&v);
            polyval(v,ARGPTR(ans)+i);
          }
     }
  ARGREP(ans,n+1,ARG(m+1,a));
  return ans;
}

/*_____________________________________________________________*/
PSERIES addSeries( PSERIES a, PSERIES b)
/* return the sum of two series, computing
   the sum to the minimum of the input orders
*/
{ int n = ORDER(a);
  int m = ORDER(b);
  int k = n < m ? n: m;  /* min of n,m */
  int i;
  term u,v,w;
  term ans = make_term(SERIES,(unsigned short)(k+2));
  for(i=0;i<=k;i++)
     { subst(make_int(i),var0,GENERALTERM(a),&u);
       subst(make_int(i),var0,GENERALTERM(b),&v);
       polyval(sum(u,v),&w);
       ARGREP(ans,i,w);
     }
  polyval(sum(GENERALTERM(a),GENERALTERM(b)),&v);
  ARGREP(ans,k+1,v);
  return ans;
}

/*_____________________________________________________________*/
PSERIES negateSeries(PSERIES a)
/* negate a series term-by-term */
{ PSERIES ans;
  int i;
  unsigned short n = ARITY(a);
  ans = make_term(SERIES,n);
  for(i=0;i<n; i++)
     ARGREP(ans,i,tnegate(ARG(i,a)));
  return ans;
}
/*_______________________________________________________________*/
PSERIES subSeries(PSERIES a, PSERIES b)
/* return a-b */
{ return addSeries(a,negateSeries(b));
}
/*________________________________________________________________*/
PSERIES multiplySeries(PSERIES a, PSERIES b)
/* return ab, to the order min(ORDER(a),ORDER(b)) */
{ PSERIES ans;
  unsigned short n,m,k;
  term x,u,v,w;
  int i,j;
  n = ORDER(a);
  m = ORDER(b);
  k = n < m ? n : m;
  ans = make_term(SERIES,(unsigned short)(k+2));
  u = product(ARG(0,a),ARG(0,b));
  polyval(u,ARGPTR(ans));  /* the constant term */
  for(i=1;i<=k;i++)
     { u = make_term('+',(unsigned short)(i+1));
       for(j=0;j<=i;j++)
          ARGREP(u,j,product(ARG(j,a),ARG(i-j,b)));
       polyval(u,ARGPTR(ans)+i);
       RELEASE(u);
     }
  u = make_term(SUM,4);
  x = getnewvar(product(a,b),"ijklmnpqr");
  subst(x,var0,GENERALTERM(a),&v);
  subst(sum(var0,tnegate(x)),var0,GENERALTERM(b),&w);
  polyval(product(v,w),ARGPTR(u));
  ARGREP(u,1,x);
  ARGREP(u,2,zero);
  ARGREP(u,3,var0);
  ARGREP(ans,k+1,u);
  return ans;
}

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists