On 5/15/07, Ryan Krauss <ryanlists at gmail.com> wrote:
>
> Thanks Stavros, that is powerful and flexible and I have learned a lot
> from your example. I think I now mostly understand substpart and it
> will definitely help with fine tuning.
>
> Is there a way to do this sort of thing less interactively? It seems
> like I need to first use part to find out which terms I want to work
> with and then use substpart on those terms.
Well, it depends exactly what you want to do. As my example showed, these
partial factorizations are not unique, and factorsum doesn't handle the
numerator case -- which is why I used substpart.
To take a simpler example showing non-uniqueness:
ex:a*b+b*c+c*a => b c + a c + a b
substpart(factor(piece),ex,[1,2]) => (b + a) c + a b
substpart(factor(piece),ex,[1,3]) => b (c + a) + a c
substpart(factor(piece),ex,[2,3]) => a (c + b) + b c
rat(ex,a,b,c) => (b + a) c + a b
rat(ex,a,c,b) => (c + a) b + a c
rat(ex,b,a,c) => (a + b) c + b a
rat(ex,b,c,a) => (c + b) a + b c
rat(ex,c,a,b) => (a + c) b + c a
rat(ex,c,b,a) => (b + c) a + c b
These forms are all equivalent, and all equally short. Depending on the
structure of the problem, any one of them may be ideal. In fact, the
original, unfactored form may be ideal if the real structure is sum(
a[mod(i,n)]*a[mod(i+1,n)],i,0,n-1 ).
The "obvious" factorization of the 4-term version
a*b+b*c+c*d+d*a = (a+c)*(b+d)
may be a fluke if you also care about the 3- and 5-term versions....
You can perform an exhaustive search (looking at all partitions) for a
factorsum -- in fact I posted some code for this on the list a while ago --
but that may or may not do what you want and it gets slow on large
expressions.
As a first step in this direction, I tried to just call
> factorsum on the numerator and denominator from num and denom (my
> expressions will always be fractions of transcendental expressions).
> But the weird thing is that factorsum doesn't seem to work on the
> numerator:
Yes, factorsum only works under fairly narrow conditions:
factorsum(a*b+a*c+b*c) => a*b+a*c+b*c
factorsum(a*b+a*c+c*d+e*d) => a*b+a*c+c*d+e*d NOT d*(e+c)+a*(c+b)
>
> If I could make factorsum always work on the numerator and denominator
> separately, I think I could make this work algorithmically (i.e.
> non-interactively).
>
Yes, that is the challenge. If you know the structure of your expressions a
priori, you can do a lot more. For example,
divsimp(ex,div):=
if atom(ex) then ex
elseif part(ex,0)="+"
then block([quorem: divide(ex,div)], quorem[1]*div + quorem[2])
else map(lambda([q],divsimp(q,div)),ex)$
divsimp(N,c*s+k) =>
L^3*((cos(beta)*sinh(beta)-cosh(beta)*sin(beta))*(c*s+k)*L-2*beta*sin(beta)*sinh(beta)*EI)
Hope this helps,
-s