       Ugly expressions. Was: Toghether, Apart ?

• To: mathgroup at smc.vnet.net
• Subject: [mg17036] Ugly expressions. Was: Toghether, Apart ?
• From: tobiasoed at my-dejanews.com
• Date: Wed, 14 Apr 1999 02:11:52 -0400
• Organization: Deja News - The Leader in Internet Discussion
• Sender: owner-wri-mathgroup at wolfram.com

```Hi all.
There was a post about handling long expressions (leafcount > 10^7). I am
manipulating the same kind of nasty things and am interested in any little
function that deals with them (without running out of memory) - like the
following FactorCommon. that pulls out common factors of sums.

FactorCommon[expr_Plus]:=Block[{com,dummy1,dummy2},
com=Apply[Intersection,dummy1 dummy2 Apply[List,expr]]
/.                            {dummy1->1,dummy2->1};
com Map[#/com &,expr]
]

FactorCommon[expr_]:=expr

an example use:

In:= FactorCommon[expr_Plus]:=Block[{com,dummy1,dummy2},
com=Apply[Intersection,dummy1 dummy2 Apply[List,expr]] /.
{dummy1->1,dummy2->1};
com Map[#/com &,expr]
]

In:= FactorCommon[expr_]:=expr

In:= ex = Expand[a b
Apply[Plus,Apply[Times,Table[e[i+j*10],{j,0,8},{i,0,9}],{1}]]]

Out= a b e e e e e e e e e e +

>    a b e e e e e e e e e e +

>    a b e e e e e e e e e e +

>    a b e e e e e e e e e e +

>    a b e e e e e e e e e e +

>    a b e e e e e e e e e e +

>    a b e e e e e e e e e e +

>    a b e e e e e e e e e e +

>    a b e e e e e e e e e e

In:= Timing[FactorCommon[ex]][]

Out= 0.04 Second

In:= Timing[Factor[ex]][]

Out= 0.73 Second

Sure, FactorCommon is not as powerfull as Factor, but sometimes it's the only
way I found to reduce some of my exprssions.
Hope this can help some others too, Tobias.

-----------== Posted via Deja News, The Discussion Network ==----------