Menu

#35 powerseries((x+1)/(1-2*x^2), x, 0);

closed
nobody
None
5
2007-07-18
2007-05-20
Dan Gildea
No

If powerseries is called with a monomial as the numerator, it factors it
out before expansion:

(%i9) powerseries((x)/(1-2*x), x, 0);
inf
====
\ i5 i5 + 1 i5
(%o9) - x > (- 2) (- 1) x
/
====
i5 = 0

If the numerator is a polynomial, powerseries tries to do a partial fraction
expansion before powerseries expansion:

(%i8) powerseries((x+1)/(1-2*x), x, 0);
inf
====
\ i4 i4 + 1 i4
3 > (- 2) (- 1) x
/
====
i4 = 0 1
(%o8) - -------------------------------- - -
2 2

If partial fraction expansion fails, the power series fails:

(%i1) powerseries((1+x)/(1-2*x^2), x, 0);
(%o1) Unable to expand

This patch keeps going if partial fraction expansion fails, factoring out
the numerator and doing power series expansion of the denominator only:

(%i7) powerseries((x+1)/(1-2*x^2), x, 0);
inf
====
\ i3 i3 + 1 2 i3
(%o7) (- x - 1) > (- 2) (- 1) x
/
====
i3 = 0

*** ./series.lisp 2007/05/20 11:34:20 1.1
--- ./series.lisp 2007/05/20 13:01:55
***************
*** 174,194 ****

(defun ratexand1 (n d)
(and $verbose
! (prog2 (mtell "Trying partial fraction expansion of ")
(show-exp (list '(mquotient) n d))
(terpri)))
(funcall #'(lambda (*ratexp)
! (m+l (mapcar #'ratexp
! (funcall #'(lambda (l)
! (cond ((eq (caar l) 'mplus)
! (and $verbose
! (mtell "which is ")
! (show-exp l))
! (cdr l))
! (t (throw 'psex
! '(err (mtext)
! "Partial fraction expansion failed")))))
! ($partfrac (div* n d) var)))))
t))
^L
(defun sratsubst (gcd num den)
--- 174,197 ----

(defun ratexand1 (n d)
(and $verbose
! (prog2 (mtell "Trying partial fraction expansion of ~%")
(show-exp (list '(mquotient) n d))
(terpri)))
(funcall #'(lambda (*ratexp)
! (let ((l ($partfrac (div* n d) var)))
! (cond ((eq (caar l) 'mplus)
! (and $verbose
! (mtell "which is ~%")
! (show-exp l))
! (m+l (mapcar #'ratexp
! (cdr l))))
! ((poly? n var)
! (and $verbose
! (mtell "Partial fraction expansion failed, expanding denominator only~%"))
! (m* n (ratexp (m// 1 d))))
! (t (throw 'psex
! '(err (mtext)
! "Partial fraction expansion failed"))))))
t))
^L
(defun sratsubst (gcd num den)

Discussion

  • Dan Gildea

    Dan Gildea - 2007-05-20

    Logged In: YES
    user_id=1797506
    Originator: YES

    File Added: series.lisp.diff

     
  • Dan Gildea

    Dan Gildea - 2007-05-28

    Logged In: YES
    user_id=1797506
    Originator: YES

    Here is a verison of series.lisp with an implementation of the
    rational expansion theorem for distinct roots. Some test cases:

    /* two simple roots */
    powerseries((1)/((1-2*x)*(1-3*x)), x, 0);

    /* fibonacci */
    powerseries((1)/(1-x-x^2), x, 0);

    /* 1 1 2 2 4 4 8 8 */
    powerseries((1+x)/(1-2*x^2), x, 0);

    /* multiple root */
    powerseries((1+x)/(1-x)^2, x, 0);

    /* numerator higher order poly than denom */
    powerseries((1+x^3)/(1-x-x^2), x, 0);

    /* zero root in denom */
    powerseries((1)/((1-2*x)*(x)), x, 0);

    /* one simple and one repeated root in denom */
    powerseries((1+x+x^2)/((1-2*x)*(1+x)^2), x, 0);

    /* gcd of exps is two */
    powerseries((1-x^2)/(1-4*x^2+x^4), x, 0);

    File Added: series.lisp

     
  • Dan Gildea

    Dan Gildea - 2007-05-28
     
  • Dan Gildea

    Dan Gildea - 2007-07-18
    • status: open --> closed
     

Log in to post a comment.