currently seriesSolve uses a power series Ansatz of the form

f(x) = f_0 + f_1 x + ... + f_k x^k + \sum_{n>k} a x^n

(assuming that f_0, f_1, ..., f_k are already known) and solves for a.
This works surprisingly well, but of course not always.

The patch attached fixes this, please give OK to commit.

--

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 fricas-de...@googlegroups.com.
To unsubscribe from this group, send email to 
fricas-devel+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/fricas-devel?hl=en.


Martin
Index: Makefile.in
===================================================================
--- Makefile.in	(revision 756)
+++ Makefile.in	(working copy)
@@ -349,7 +349,7 @@
 RPOLCAT RURPK SHP SOLVETRA SUPFRACF SYMFUNC TBCMPPK TEMUTL URAGG \
 UTS WEIER WP ZDSOLVE ZMOD
 
-GUESSLIST= SUPEXPR FAMR2 NEWTON UFPS GOPT GUESSF1 GUESSP1\
+GUESSLIST= SMPEXPR FAMR2 NEWTON UFPS GOPT GUESSF1 GUESSP1\
            UTSSOL FFFG UFPS1 GOPT0 EXPRSOL FFFGF \
            RECOP STNSR GUESS GUESSINT GUESSF GUESSP GUESSPI GUESSAN
 
Index: Makenotes.tex
===================================================================
--- Makenotes.tex	(revision 756)
+++ Makenotes.tex	(working copy)
@@ -490,7 +490,7 @@
 we add it here.
 <<USERLAYER>>=
 
-GUESSLIST= SUPEXPR FAMR2 NEWTON UFPS GOPT GUESSF1 \
+GUESSLIST= SMPEXPR FAMR2 NEWTON UFPS GOPT GUESSF1 \
            UTSSOL FFFG UFPS1 GOPT0 EXPRSOL FFFGF \
            RECOP GUESS GUESSINT GUESSP GUESSF GUESSAN
 
Index: rec.spad.pamphlet
===================================================================
--- rec.spad.pamphlet	(revision 756)
+++ rec.spad.pamphlet	(working copy)
@@ -424,7 +424,7 @@
                                $ExpressionSolve(R, F,
                                             UnivariateFormalPowerSeries F,
                                             UnivariateFormalPowerSeries
-                                       SparseUnivariatePolynomialExpressions F)
+                                       SparseMultivariatePolynomialExpressions F)
 
         setINFOSER(info, [eq, argsym, op, v, params, values, _
                           "failed", fn, explicit?]$INFOSER)
Index: ssolve.spad.pamphlet
===================================================================
--- ssolve.spad.pamphlet	(revision 756)
+++ ssolve.spad.pamphlet	(working copy)
@@ -9,7 +9,7 @@
 \begin{abstract}
 \end{abstract}
 \tableofcontents
-\section{domain SUPEXPR SparseUnivariatePolynomialExpressions}
+\section{domain SMPEXPR SparseMultivariatePolynomialExpressions}
 
 This domain is a hack, in some sense. What I'd really like to do -
 automatically - is to provide all operations supported by the coefficient
@@ -17,16 +17,16 @@
 long as they are just constants. I don't see another way to do this,
 unfortunately.
 
-<<domain SUPEXPR SparseUnivariatePolynomialExpressions>>=
-)abb domain SUPEXPR SparseUnivariatePolynomialExpressions
-SparseUnivariatePolynomialExpressions(R: Ring): Exports == Implementation where
+<<domain SMPEXPR SparseMultivariatePolynomialExpressions>>=
+)abb domain SMPEXPR SparseMultivariatePolynomialExpressions
+SparseMultivariatePolynomialExpressions(R: Ring): Exports == Implementation where
 
-    Exports == UnivariatePolynomialCategory R with
+    Exports ==> PolynomialCategory(R, IndexedExponents NonNegativeInteger, NonNegativeInteger) with
 
         if R has TranscendentalFunctionCategory
         then TranscendentalFunctionCategory
 
-    Implementation == SparseUnivariatePolynomial R add
+    Implementation ==> SparseMultivariatePolynomial(R, NonNegativeInteger) add
 
         if R has TranscendentalFunctionCategory then
             log(p: %): % ==
@@ -88,45 +88,25 @@
 
 <<package UTSSOL TaylorSolve>>=
 )abb package UTSSOL TaylorSolve
-TaylorSolve(F, UTSF, UTSSUPF): Exports == Implementation where
+TaylorSolve(F, UTSF, UTSSMPF): Exports == Implementation where
     F: Field
-    SUP  ==> SparseUnivariatePolynomialExpressions
+    SMPF  ==> SparseMultivariatePolynomialExpressions F
     UTSF: UnivariateTaylorSeriesCategory F
-    UTSSUPF: UnivariateTaylorSeriesCategory SUP F
+    UTSSMPF: UnivariateTaylorSeriesCategory SMPF
     NNI  ==> NonNegativeInteger
 
     Exports == with
-        seriesSolve: (UTSSUPF -> UTSSUPF, List F) -> UTSF
+        seriesSolve: (UTSSMPF -> UTSSMPF, List F) -> UTSF
 
     Implementation == add
 <<implementation: UTSSOL TaylorSolve>>
 @
 
-<<implementation: UTSSOL TaylorSolve>>=
-        seriesSolve(f, l) ==
-            c1 := map((x : F) : SUP F +-> x::(SUP F),
-                      l)$ListFunctions2(F, SUP F)::(Stream SUP F)
-            coeffs: Stream SUP F := concat(c1, generate(monomial(1$F,1$NNI)))
---            coeffs: Stream SUP F := concat(c1, monomial(1$F,1$NNI))
-@
-
 [[coeffs]] is the stream of the already computed coefficients of the solution,
 plus one which is so far undetermined. We store in [[st.2]] the complete stream
 and in [[st.1]] the stream starting with the first coefficient that has
 possibly not yet been computed.
 
-\begin{ToDo}
-  The mathematics is not quite worked out. If [[coeffs]] is initialized as
-  stream with all coefficients set to the \emph{same} transcendental value,
-  and not enough initial values are given, then the missing ones are
-  implicitely assumed to be all identical. It may well happen that a solution
-  is produced, although it is not uniquely determined\dots
-\end{ToDo}
-
-<<implementation: UTSSOL TaylorSolve>>=
-            st: List Stream SUP F := [coeffs, coeffs]
-@
-
 Consider an arbitrary equation $f\big(x, y(x)\big)=0$. When setting $x=0$, we
 obtain $f\big(0, y(0)\big)=0$. It is not necessarily the case that this
 determines $y(0)$ uniquely, so we need one initial value that satisfies this
@@ -161,43 +141,50 @@
 \end{ToDo}
 
 <<implementation: UTSSOL TaylorSolve>>=
+        seriesSolve(f, l) ==
+            l1 := [e::SMPF for e in l]::Stream SMPF
+            s1: Stream Integer := generate(inc, 0)$Stream(Integer)
+            l2 := map(i +-> monomial(1, monomial(1, i::NNI)
+                                                $IndexedExponents(NNI))
+                            $SMPF, s1)$StreamFunctions2(Integer, SMPF)
+
+            coeffs: Stream SMPF := concat(l1, l2)
+            st: List Stream SMPF := [coeffs, coeffs]
+
             next: () -> F :=
                 nr := st.1
                 res: F
 
-                if ground?(coeff: SUP F := nr.1)$(SUP F)
-@
-%$
+                if ground?(coeff: SMPF := nr.1)$SMPF then
+-- If the next element was already calculated, we can simply return it:
 
-If the next element was already calculated, we can simply return it:
-
-<<implementation: UTSSOL TaylorSolve>>=
-                then
                     res := ground coeff
                     st.1 := rest nr
                 else
-@
 
-Otherwise, we have to find the first non-satisfied relation and solve it. It
-should be linear, or a single non-constant monomial. That is, the solution
-should be unique.
+-- Otherwise, we have to find the first non-satisfied relation and solve it. It
+-- should be linear, or a single non-constant monomial. That is, the solution
+-- should be unique.
 
-<<implementation: UTSSOL TaylorSolve>>=
                     ns := st.2
-                    eqs: Stream SUP F := coefficients f series ns
+                    eqs: Stream SMPF := coefficients f series ns
                     while zero? first eqs repeat eqs := rest eqs
-                    eq: SUP F := first eqs
-                    if degree eq > 1 then
+                    eq: SMPF := first eqs
+                    var := variables eq
+                    if not one?(# var) or degree(eq, first var) > 1 then
                         if monomial? eq then res := 0
                         else
                             output(hconcat("The equation is: ", eq::OutputForm))
                                   $OutputPackage
                             error "seriesSolve: equation for coefficient not linear"
-                    else res := (-coefficient(eq, 0$NNI)$(SUP F)
-                                 /coefficient(eq, 1$NNI)$(SUP F))
+                    else
+--                        output(hconcat("The equation is: ", eq::OutputForm))
+--                              $OutputPackage
+ 
+                        res := (-coefficient(eq, monomial(0$NNI, first var)$IndexedExponents(NNI))$(SMPF)
+                                 /coefficient(eq, monomial(1$NNI, first var)$IndexedExponents(NNI))$(SMPF))
 
-                    nr.1 := res::SUP F
---                    concat!(st.2, monomial(1$F,1$NNI))
+                    nr.1 := res::SMPF
                     st.1 := rest nr
 
                 res
@@ -219,16 +206,16 @@
 
 <<package EXPRSOL ExpressionSolve>>=
 )abb package EXPRSOL ExpressionSolve
-ExpressionSolve(R, F, UTSF, UTSSUPF): Exports == Implementation where
+ExpressionSolve(R, F, UTSF, UTSSMPF): Exports == Implementation where
     R: Join(Comparable, IntegralDomain, ConvertibleTo InputForm)
     F: FunctionSpace R
     UTSF: UnivariateTaylorSeriesCategory F
-    SUP  ==> SparseUnivariatePolynomialExpressions
-    UTSSUPF: UnivariateTaylorSeriesCategory SUP F
+    SMPF ==> SparseMultivariatePolynomialExpressions F
+    UTSSMPF: UnivariateTaylorSeriesCategory SMPF
     OP   ==> BasicOperator
     SY   ==> Symbol
     NNI  ==> NonNegativeInteger
-    MKF ==> MakeBinaryCompiledFunction(F, UTSSUPF, UTSSUPF, UTSSUPF)
+    MKF ==> MakeBinaryCompiledFunction(F, UTSSMPF, UTSSMPF, UTSSMPF)
 
     Exports == with
 
@@ -291,15 +278,15 @@
         seriesSolve(expr, op, sy, l) ==
             ex := replaceDiffs(expr, op, sy)
             f := compiledFunction(ex, name op, sy)$MKF
-            seriesSolve(x +-> f(x, monomial(1,1)$UTSSUPF),
-                        l)$TaylorSolve(F, UTSF, UTSSUPF)
+            seriesSolve(x +-> f(x, monomial(1,1)$UTSSMPF),
+                        l)$TaylorSolve(F, UTSF, UTSSMPF)
 @
 %$
 
 \section{Bugs}
 
 <<inp: seriesSolve>>=
-seriesSolve(sin f x / cos x, f, x, [1])$EXPRSOL(INT, EXPR INT, UFPS EXPR INT, UFPS SUPEXPR EXPR INT)
+seriesSolve(sin f x / cos x, f, x, [1])$EXPRSOL(INT, EXPR INT, UFPS EXPR INT, UFPS SMPEXPR EXPR INT)
 @
 returns
 \begin{verbatim}
@@ -308,8 +295,8 @@
 
 but
 <<inp: seriesSolve>>=
-U ==> UFPS SUPEXPR EXPR INT
-seriesSolve(s +-> sin s *((cos monomial(1,1)$U)^-1)$U, f, x, [0])$EXPRSOL(INT, EXPR INT, UFPS EXPR INT, UFPS SUPEXPR EXPR INT)
+U ==> UFPS SMPEXPR EXPR INT
+seriesSolve(s +-> sin s *((cos monomial(1,1)$U)^-1)$U, f, x, [0])$EXPRSOL(INT, EXPR INT, UFPS EXPR INT, UFPS SMPEXPR EXPR INT)
 @
 
 works. This is probably due to missing [[/]] in [[UFPS]].
@@ -347,7 +334,7 @@
 <<*>>=
 <<license>>
 
-<<domain SUPEXPR SparseUnivariatePolynomialExpressions>>
+<<domain SMPEXPR SparseMultivariatePolynomialExpressions>>
 
 <<package UTSSOL TaylorSolve>>
 

Reply via email to