/**  Rational Function Simplification and Factoring  **/
/*A: G I Watson */
/*S: University of Western Australia */
/*D: June 1987 */
/*K: Cancel, Rational, Polynomial, Division, Quotient, Factorise, Fac */

/*: Can[$expr,($form)]
	attempts to simplify the rational function $expr by cancelling
	factors in the denominator with the numerator. Additional
	trial factors may be specified in $form.
	Can[$expr,$form] may also be used to separate factors in $form
	out of a polynomial $expr. */

Can_: Tier
Can[$n/$d,$form] :: (Lcl[%fr]; \
	%fr : Can[$n/$d]; \
	Can[Num[%fr]/$form]/Can[Den[%fr]/$form])
Can[$n/$d] :: (Lcl[%fac,%pqr]; \
	%num : Ex[$n]; %fac : Extr[$d]; \
	Pqr[%num,Ex[%fac],Rel[Cont[%fac]][1]]; \
	%pqr : Ex[%%]; \
	If[Match[%pqr[2],0],Can[%pqr[1] %fac/$d],Can[%num %fac/$d]/%fac])
Can[$expr,$form] :: $form Can[$expr/$form]
Can[$expr] :: $expr

Extr[$x $y] :: Extr[$x]
Extr[$x^$y] :: $x
Extr[$x] :: $x

/*E:
SMP 1.5.0   (May 14 1986)
Wed Jun 10 15:09:29 1987


#I[1]::  <XCan

#I[2]::  (a^2 b c^4+16b^5 c^2-10a b^3 c^3)/(a c^3 (a c-8b^2)^2 (a c-2b^2))

	     5  2        3  3    2    4
	 16 b  c  - 10a b  c  + a  b c
#O[2]:   -------------------------------
	    3   	2 2           2
	 a c  (a c - 8 b )  (a c - 2 b )

#I[3]::  Can[%]

		b
#O[3]:   ----------------
		       2
	 a c (a c - 8 b )

#I[4]::  y^5+7y^4+14y^3+7y^2+5y+6

		     2       3      4    5
#O[4]:   6 + 5y + 7 y  + 14 y  + 7 y  + y

#I[5]::  Can[%,(y+1)(y+2)(y+3)]

				     2    3
#O[5]:   (1 + y) (3 + y) (2 - y + 3 y  + y )

#I[6]::  (t^3+2x t^3)/(t^3+t^2)

	    3      3
	 2 t  x + t
#O[6]:   -----------
	    2    3
	   t  + t

#I[7]::  Can[%,t^3]

	 t (1 + 2x)
#O[7]:   ----------
	   1 + t

#I[8]::  <end>
*/

