> Code for coefficient looks OK.  Comments about polynomial are somewhat
> out of place and I am not sure what you want to do with leadingCoefficient
> and friends.

Finally, here is the patch that implements 

coefficient: (%, List Var, List NNI) -> %
coefficient: (%, Var, NNI) -> %
coefficient: (%, IndexedExponents Var) -> Coef

along with some documentation and some tests.  If there is no protest, I'll
commit tonight.

Martin
Index: algebra/Makefile.in
===================================================================
--- algebra/Makefile.in (revision 440)
+++ algebra/Makefile.in (working copy)
@@ -86,7 +86,8 @@
 
 
 TESTS=${INPUT}/INTHEORY.input ${INPUT}/VIEW2D.input ${INPUT}/TESTFR.input \
-      ${INPUT}/TEST-MATCAT.input ${INPUT}/TEST-TABLE.input
+      ${INPUT}/TEST-MATCAT.input ${INPUT}/TEST-TABLE.input \
+      ${INPUT}/TEST-MTS.input
 
 
 subdir = src/algebra/
@@ -530,6 +531,8 @@
 ${INPUT}/TEST-TABLE.input: $(srcdir)/table.spad.pamphlet
        $(axiom_build_document) --tangle='TEST TABLE' --output=$@ $<
 
+${INPUT}/TEST-MTS.input: $(srcdir)/mts.spad.pamphlet
+       $(axiom_build_document) --tangle='TEST MTS' --output=$@ $<
 
 
 mostlyclean-local: 
Index: algebra/mts.spad.pamphlet
===================================================================
--- algebra/mts.spad.pamphlet   (revision 440)
+++ algebra/mts.spad.pamphlet   (working copy)
@@ -10,6 +10,11 @@
 \tableofcontents
 \eject
 \section{domain SMTS SparseMultivariateTaylorSeries}
+<<TEST MTS>>=
+)set break resume
+)expose UnittestCount UnittestAux Unittest
+testsuite "MTS"
+@
 <<domain SMTS SparseMultivariateTaylorSeries>>=
 )abbrev domain SMTS SparseMultivariateTaylorSeries
 ++ This domain provides multivariate Taylor series
@@ -71,7 +76,15 @@
 
   Implementation ==> PS add
 
-    Rep := StS -- Below we use the fact that Rep of PS is Stream SMP.
+@
+\subsection{Rep}
+
+Below we will use the fact that the \verb|Rep| of \verb|PS| is
+\verb|Stream SMP|.  The total degree of the $n$\textsuperscript{th} element of
+the stream should always be $n-1$.
+<<domain SMTS SparseMultivariateTaylorSeries>>=
+    Rep := StS
+
     extend(x,n) == extend(x,n + 1)$Rep
     complete x == complete(x)$Rep
 
@@ -84,8 +97,71 @@
       ints := integers(0)$STT pretend ST NNI
       map(monomial(#2 :: SMP,v,#1)$SMP,ints,s pretend ST
       Coef)$ST3(NNI,Coef,SMP)
 
-    coefficient(s,n) == elt(s,n + 1)$Rep  -- 1-based indexing for streams
+@
 
+\subsection{coefficient}
+
+The function \spadfun{coefficient} carries three different semantics.  We can
extract
+\begin{enumerate}
+\item a polynomial giving the terms of given total degree: 
+<<domain SMTS SparseMultivariateTaylorSeries>>=
+    coefficient(s, n) == elt(s,n + 1)$Rep  -- 1-based indexing for streams
+@
+\item a Taylor series with all coefficients of a monomial:
+  here we have to take into account that we reduce the degree of each term of
+  the stream by a constant.
+<<domain SMTS SparseMultivariateTaylorSeries>>=
+    coefficient(s: %, lv: List Var, ln: List NNI): % == 
+        map(coefficient(#1, lv, ln), rest(s, reduce(_+, ln)))
+@
+\item the coefficient of a particular monomial:
+<<domain SMTS SparseMultivariateTaylorSeries>>=
+    coefficient(s: %, m: IndexedExponents Var): Coef ==
+        n := leadingCoefficient(mon := m)
+        while not zero?(mon := reductum mon) repeat
+            n := n + leadingCoefficient mon      
+
+        coefficient(coefficient(s, n), m)
+@
+\end{enumerate}
+
+<<TEST MTS>>=
+testcase "coefficient"
+)se str cal 2
+X := x::TS FRAC INT;
+Y := y::TS FRAC INT;
+Z := z::TS FRAC INT;
+s := sin(X+Y);
+testEquals("coefficient(s, 3)", "-1/6*(x+y)^3")
+
+IS ==> IndexedExponents Symbol
+testEquals("coefficient(s, monomial(3,x)$IS)", "-1/6")
+
+s := (1/(1-X-Y-Z))::TS FRAC INT;
+t := coefficient(s, [x,z], [3,2]);
+testEquals("degree(polynomial(t, 5), y)", "5")
+
+s := (1/(1-X-Y))::TS FRAC INT;
+t := coefficient(s, x, 1)
+testEquals("polynomial(t, 5)", "1+x+x^2+x^3+x^4+x^5")
+
+@
+
+<<domain SMTS SparseMultivariateTaylorSeries>>=
+
+    leadingCoefficient s ==
+        leadingCoefficient(coefficient(s, order(s pretend PS)$PS))
+
+    leadingMonomial s ==
+        leadingMonomial(coefficient(s, order(s pretend PS)$PS))::%
+
+    reductum s == s - leadingMonomial s
+
+    degree s == degree coefficient(s, order(s pretend PS)$PS)
+
+
+    map(f: Coef -> Coef, x: %): % == map(map(f, #1), x)$Rep
+
 --% creation of series
 
     coerce(r:Coef) == monom(r::SMP,0)$STT
@@ -108,6 +184,8 @@
     monomial(r:%,v:Var,n:NNI) ==
       r * monom(monomial(1,v,n)$SMP,n)$STT
 
+    monomial(c, m): % == monomial(c, m)$SMP::%
+
 --% evaluation
 
     substvar: (SMP,L Var,L %) -> %
@@ -320,6 +398,9 @@
       sum
 
 @
+<<TEST MTS>>=
+statistics()
+@
 \section{License}
 <<license>>=
 --Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd.
Index: algebra/pscat.spad.pamphlet
===================================================================
--- algebra/pscat.spad.pamphlet (revision 440)
+++ algebra/pscat.spad.pamphlet (working copy)
@@ -599,6 +599,11 @@
         --++ We provide transcendental functions when we can divide
         --++ coefficients by integers.
 
+   add
+  
+    coefficient(s: %, v: Var, n: NNI): % == coefficient(s, [v], [n])
+
+
 @
 
 \section{License}
Index: input/Makefile.in
===================================================================
--- input/Makefile.in   (revision 440)
+++ input/Makefile.in   (working copy)
@@ -740,7 +741,8 @@
       zimmer.output 
 
 # new algebra tests based on documentation
-ALGEBRA=INTHEORY.output VIEW2D.output TESTFR.output TEST-MATCAT.output
TEST-TABLE.output
+ALGEBRA=INTHEORY.output VIEW2D.output TESTFR.output TEST-MATCAT.output \
+        TEST-MTS.output TEST-TABLE.output 
 
 .PHONY: regression-tests
 regression-tests: ${OUTS} ${ALGEBRA}


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/fricas-devel?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to