well, I did some more hacking and ended up with the following result: I do
not understand varlist and genvar...
It seems that it is perfectly alright for $rat to put anything on the
DISREP property of a genvar symbol, discarding its previous value?
Is this really true?
I let fpolysum print varlist and genvar together with its DISREP
properties just before and just after the $RAT stuff:
(defun fpolysum (e) ;returns *ans*
(bugprint "fpolysum")
(let ((a (fpoly1 (setq e ($expand ($ratdisrep ($rat e *var*))))))
(b) ($prederror))
(bugprint "fpolysum")
I found out that setting taylor_simplifier:false; makes the result of
taylor(blabla) correct. Still, the following is part of the computation
and makes me wonder:
("fpolysum"
($D ((%SUM SIMP)
((MTIMES SIMP) ((%SUM SIMP) ((MEXPT SIMP) $L $K) $L 1 $D)
((MEXPT SIMP) $M $K))
$K 1 $INF)
$M)
((#:D21809 $D) (#:|'SUM(('SUM(L^K,L,1,D))*M^K,K,1,INF)21808| $L)
(#:M21808 $M)))
(1 ENTER $RAT (((MEXPT SIMP) $L 2) $L))
("fpolysum"
($D ((%SUM SIMP)
((MTIMES SIMP) ((%SUM SIMP) ((MEXPT SIMP) $L $K) $L 1 $D)
((MEXPT SIMP) $M $K))
$K 1 $INF)
$M)
((#:D21809 $L) (#:|'SUM(('SUM(L^K,L,1,D))*M^K,K,1,INF)21808| $L)
(#:M21808 $M)))
The only difference diff found between taylor_simplifier being switched
off and being equal to the default SIMPLIFY is that
taylor_simplify_recurse is not executed in the first setting. (rather,
taylor3 returns the result of taylor2 immediately:
(xcons (if (null taylor_simplifier) (taylor2 e)
(setq e (taylor2 e))
(let ((exact-poly () ) (trunc-constants? () ))
(taylor_simplify_recurse e)))
(list 'MRAT 'SIMP varlist genvar tlist 'TRUNC)
when taylor_simplify_recurse is invoked, it eventually rcdisrep's its
argument ps which returns the wrong answer, because the property cell of
the genvar contains the value set long ago by $rat in fpolysum. I inserted
some bugprint's as below and got the following:
(rcdisrep is just a macro that calls cdisrep...)
(1 ENTER TAYLOR_SIMPLIFY_RECURSE
((PS (#:M21808 . 2) ((1 . 1)) ((1 . 1) (#:D21809 2 1 1 1) . 2))))
("recurse"
($D ((%SUM SIMP)
((MTIMES SIMP) ((%SUM SIMP) ((MEXPT SIMP) $L $K) $L 1 $D)
((MEXPT SIMP) $M $K))
$K 1 $INF)
$M)
((#:D21809 $L) (#:|'SUM(('SUM(L^K,L,1,D))*M^K,K,1,INF)21808| $L)
(#:M21808 $M)))
(2 ENTER TAYLOR_SIMPLIFY_RECURSE (((#:D21809 2 1 1 1) . 2)))
("recurse"
($D ((%SUM SIMP)
((MTIMES SIMP) ((%SUM SIMP) ((MEXPT SIMP) $L $K) $L 1 $D)
((MEXPT SIMP) $M $K))
$K 1 $INF)
$M)
((#:D21809 $L) (#:|'SUM(('SUM(L^K,L,1,D))*M^K,K,1,INF)21808| $L)
(#:M21808 $M)))
(1 ENTER CDISREP (((#:D21809 2 1 1 1) . 2)))
(1 EXIT CDISREP
((MTIMES RATSIMP) ((RAT) 1 2)
((MPLUS RATSIMP) ((MEXPT RATSIMP) $L 2) $L)))
...
Martin
(defun taylor_simplify_recurse (ps)
(bugprint "recurse")
(if (pscoefp ps) (taylor2 (funcall taylor_simplifier (rcdisrep ps))))
(let ((datum (ps-data ps)) (var () ))
;; We must treat multivars like 1, since they'll reappear again
;; when we call taylor2 on their disrep'd coeff's.
(if (switch 'MULTIVAR datum) (setq datum () )
(setq var (getdisrep (gvar-o ps)))
;; Don't push pw's < 0, else constants will be truncated
(push-pw datum (emax (trunc-lvl ps) (rczero))))
(do ((terms (terms ps) (n-term terms))
(ans (rczero) (psplus (if (null datum)
(taylor_simplify_recurse (lc
terms))
(pstimes (taylor_simplify_recurse
(lc terms))
;; Don't do
;; (taylor2 (funcall taylor_simplifier
;; (m^ var (edisrep (le terms)))))
;; causes terms to be lost when inverting. E.g.
;; taylor(log(1+exp(-1/x)),x,0,5) calls
psexpt(<exp(1/x)^3>...3,-1)
;; which must return a series good to 3+3(-1-1)=-3 which, when
added
;; to other terms will truncate them to degree -3 also.
(if (ezerop (le terms)) (rcone)
(make-ps ps
(ncons
(term (le terms)
(rcone)))))))
ans)))
((null terms)
(when datum (pop-pw datum))
ans)))))