/**  Partial Fractions  **/
/*A: G I Watson */
/*S: University of Western Australia */
/*D: June 1987 */
/*K: Partial Fraction, Pf, Rational */

/*: Pfrac[$expr,$form]
	generates a partial fraction form of $expr with respect to the
	"base" $form, usually much simpler than the expression returned
	by Pf. */

Pfrac_: Tier
Pfrac[$n/$d,$var_=Symbp[$var]] :: (S[$d,$1+$$2-->Fac[Ex[$1+$$2]]]; \
	SubPfrac[$n/%%,$var]; Col[%%])

SubPfrac_: Tier
SubPfrac[$n/$d,$var] :: (Lcl[%facs,%part,%con]; \
	%facs : Factors[$d,$var]; \
	If[Len[%facs]<2,Ret[$n/$d]]; \
	%part : %facs[1] %facs[2]; \
	%con : %part/$d; \
	Pf[$n/%part,$var]; \
	Map[SubPfrac[$1 %con,$var],%%])

Factors_: Tier
Factors[$x,$var] :: If[In[$var,$x],{$x},{}]
Factors[$x $y,$var] :: Cat[Factors[$x,$var],Factors[$y,$var]]
Factors[$x^$i,$var] :: Factors[$x,$var]

/*E:
SMP 1.5.0   (May 14 1986)
Thu Jun 11 22:29:05 1987


#I[1]::  <XPfrac

#I[2]::  t:4x^2/((m+x)^3(n+x)^2)

		  2
	       4 x
#O[2]:   -----------------
		3        2
	 (m + x)  (n + x)

#I[3]::  Pf[t,x]

#O[3]:   4(-3(m/((-(((2n + -((-(n^2*(3m + -2n)) + m^3)/(-2(n*(3m + -2n)) + 3(m\
		    ^2) + -n^2)))*(-(n^2*(3m + -2n)) + m^3))/(-2(n*(3m + -2n))\
		     + 3(m^2) + -n^2)) + n^2)*(-2(n*(3m + -2n)) + 3(m\
		  ^2) + -n^2))) + 2(n/((-(((2n + -((-(n^2*(3m + -2n)) + m\
		    ^3)/(-2(n*(3m + -2n)) + 3(m^2) + -n^2)))*(-(n^2*(3m + -2n)\
		    ) + m^3))/(-2(n*(3m + -2n)) + 3(m^2) + -n^2))\
		 + n^2)*(-2(n*(3m + -2n)) + 3(m^2) + -n^2))) + (m\
		^2*(1/(-(((2n + -((-(n^2*(3m + -2n)) + m^3)/(-2(n*(3m + -2n))\
		     + 3(m^2) + -n^2)))*(-(n^2*(3m + -2n)) + m^3))/(-2(n*(3m\
		     + -2n)) + 3(m^2) + -n^2)) + n^2) + ((3m + -2n)*(2n + -((-\
		    (n^2*(3m + -2n)) + m^3)/(-2(n*(3m + -2n)) + 3(m^2) + -n\
		    ^2))))/((-(((2n + -((-(n^2*(3m + -2n)) + m^3)/(-2(n*(3m\
		     + -2n)) + 3(m^2) + -n^2)))*(-(n^2*(3m + -2n)) + m^3))\
		    /(-2(n*(3m + -2n)) + 3(m^2) + -n^2)) + n^2)*(-2(n*(3m\
		     + -2n)) + 3(m^2) + -n^2)) + -(m*(-(m/((-(((2n + -((-(n\
		    ^2*(3m + -2n)) + m^3)/(-2(n*(3m + -2n)) + 3(m^2) + -n\
		    ^2)))*(-(n^2*(3m + -2n)) + m^3))/(-2(n*(3m + -2n)) + 3(m\
		    ^2) + -n^2)) + n^2)*(-2(n*(3m + -2n)) + 3(m^2) + -n^2)))\
		     + (3m + -2n)/((-(((2n + -((-(n^2*(3m + -2n)) + m^3)/(-2(n\
		    *(3m + -2n)) + 3(m^2) + -n^2)))*(-(n^2*(3m + -2n)) + m\
		    ^3))/(-2(n*(3m + -2n)) + 3(m^2) + -n^2)) + n^2)*(-2(n\
<quit>
		    ) + )/))/))))/ +  +  +  +  + )

#I[4]::  Pfrac[t,x]

		  1     	   -m + n              -m + n
#O[4]:   4(---------------- + ----------------- + ----------------
		  2     	     2        2 	 3
	   (m - n)  (n + x)   (m - n)  (m + x)    (m - n)  (m + x)

			2      2	    2    2            2      2
		     - m  - 2 n 	   m  + n            m  + 2 n
		 + ---------------- + ----------------- + ----------------
			  4     	     3        2 	 4
		   (m - n)  (n + x)   (m - n)  (m + x)    (m - n)  (m + x)

			   2    	       2
			  m     	      n
		 + ----------------- + -----------------)
			  2        3          3        2
		   (m - n)  (m + x)    (m - n)  (n + x)
*/

