On 5/17/07, Ryan Krauss <ryanlists at gmail.com> wrote:
>
> I created a divsimp2 that eliminates the part(ex,0)="+" test and it
> seems to work ,but I don't understand the ramifications of what I did.
> Obviously you put that test there for a reason, but I don't fully
> understand the reason. So, I need to know when I will get into
> trouble with my modified function:
The idea was to preserve any existing factorization and division into
numerator and denominator. In your case in particular, preserving num/den
seemed important. Of course, you don't have to do this.
Compare
divsimp((s*y+s*x+x)/(s*y-s*x+x),s) => (s*(y+x)+x)/(s*(y-x)+x)
divsimp2((s*y+s*x+x)/(s*y-s*x+x),s) => s*(y+x)/(s*y-s*x+x) + x/(s*y-s*x+x)
Depending which result you prefer, you'll use one or the other.
Here are various variants you might want to try, including the original one
and yours. I haven't tested these very much....
divsimp(ex,div):=
if atom(ex)
then ex
elseif part(ex,0) = "+"
then block([quorem:divide(ex,div)],
factorsum(quorem[1]) *
factorsum(div) +
factorsum(quorem[2]))
else map(lambda([q],divsimp(q,div)),ex)$
divsimp1(ex,div):=
if atom(ex)
then ex
elseif part(ex,0) = "+"
then block([quorem:divide(ex,div)],
factor(quorem[1]) *
factor(div) +
factor(quorem[2]))
else map(lambda([q],divsimp(q,div)),ex)$
divsimp2(ex,div):=
if atom(ex)
then ex
else
block([quorem:divide(ex,div)],
factorsum(quorem[1]) *
factorsum(div) +
factorsum(quorem[2]))$
divsimp3(ex,div):=
if atom(ex)
then ex
else
block([quorem:divide(ex,div)],
factor(quorem[1]) *
factor(div) +
factor(quorem[2]))$
divsimp4(ex,div):=
if atom(ex)
then ex
elseif part(ex:factor(ex),0) = "+"
then block([quorem:divide(ex,div)],
if quorem[1]=0 or quorem[2]=0 /* break inf recursion */
then factorsum(quorem[1]) *
factorsum(div) +
factorsum(quorem[2])
else
divsimp4(factor(quorem[1]),div) *
divsimp4(factor(div),div) +
divsimp4(factor(quorem[2]),div))
else map(lambda([q],divsimp4(q,div)),ex)$