Redefine[Plus] - problem
- To: mathgroup at smc.vnet.net
- Subject: [mg41126] Redefine[Plus] - problem
- From: Petr Kujan <kujanp at fel.cvut.cz>
- Date: Sun, 4 May 2003 03:56:41 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Hello all,
I would be grateful if someone could explain the difference in
time consummation.
I need redefine standard function Plus[] for function fc[]:
Unprotect[Plus];
Plus[a : fc[x_], b : fc[y_]] := fc[x + y]
Plus[k : _?NumericQ, b : fc[y_]] := fc[k + y]
Protect[Plus];
Now easy computation is very slow (time consummation is exponential!):
dat = Table[s, {20}];
Plus @@ dat // Timing
{20.019 Second, 20 s}
But if the symbol s replace by x only:
dat = Table[x, {20}];
Plus @@ dat // Timing
{0. Second, 20 x}
Thank you,
Petr Kujan
--
kujanp at fel.cvut.cz