factor/simplification problem



Very cool.  Thanks again.  In my tests so far, divsimp2 and 3 give
results in the second form you mentioned:
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)

where divsimp and divsimp1 and 4 give results of the more compact form
divsimp((s*y+s*x+x)/(s*y-s*x+x),s)  => (s*(y+x)+x)/(s*(y-x)+x)

It seems like the
else map(lambda([q],divsimp(q,div)),ex)
line is the key to the now beautiful results (even without seperating
my numerator and denominator explicitly).

Am I rightly understanding this very powerful line: it seems like map
is essentially recursively walking the branches of part.  If I turn on
trace I get

(%i91) divsimp(N,c*s+k);
 1 Enter divsimp
[L^3*(cos(beta)*sinh(beta)*c*s*L-cosh(beta)*sin(beta)*c*s*L+cos(beta)*
sinh(beta)*k*L-cosh(beta)*sin(beta)*k*L-2*beta*sin(beta)*sinh(beta)*EI),c*s+k]
 .2 Enter divsimp [L^3,c*s+k]
 ..3 Enter divsimp [L,c*s+k]
 ..3 Exit  divsimp L
 ..3 Enter divsimp [3,c*s+k]
 ..3 Exit  divsimp 3
 .2 Exit  divsimp L^3
 .2 Enter divsimp
[cos(beta)*sinh(beta)*c*s*L-cosh(beta)*sin(beta)*c*s*L+cos(beta)*
sinh(beta)*k*L-cosh(beta)*sin(beta)*k*L-2*beta*sin(beta)*sinh(beta)*EI,c*s+k]
 .2 Exit  divsimp
(cos(beta)*sinh(beta)-cosh(beta)*sin(beta))*(c*s+k)*L-2*beta*sin(beta)*
sinh(beta)*EI
 1 Exit  divsimp L^3*
((cos(beta)*sinh(beta)-cosh(beta)*sin(beta))*(c*s+k)*L-2*beta*sin(beta)*sinh(beta)*EI)
(%o91) L^3*((cos(beta)*sinh(beta)-cosh(beta)*sin(beta))*(c*s+k)*L-2*beta*sin(beta)*sinh(beta)*EI)


It seems like these lines
.2 Enter divsimp [L^3,c*s+k]
 ..3 Enter divsimp [L,c*s+k]
 ..3 Exit  divsimp L
 ..3 Enter divsimp [3,c*s+k]
 ..3 Exit  divsimp 3
 .2 Exit  divsimp L^3
correspond to part(ex,1)

and
 .2 Enter divsimp
[cos(beta)*sinh(beta)*c*s*L-cosh(beta)*sin(beta)*c*s*L+cos(beta)*
sinh(beta)*k*L-cosh(beta)*sin(beta)*k*L-2*beta*sin(beta)*sinh(beta)*EI,c*s+k]
corresponds to part(ex,2)

and so on.  Is that what  the documentation for map is saying?

Thanks again, this is very helpful and very instructive.  I appreciate
your patience.

Ryan

On 5/17/07, Stavros Macrakis <macrakis at alum.mit.edu> wrote:
> 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)$
>
>
>