Re: Pattern matching "on the fly"
- To: mathgroup at smc.vnet.net
- Subject: [mg30122] Re: [mg30100] Pattern matching "on the fly"
- From: Andrzej Kozlowski <andrzej at bekkoame.ne.jp>
- Date: Sun, 29 Jul 2001 21:26:15 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Note, however, that myexpand method gives a "general" answer to Tony
MacKenzie's problem, which the series method does not. For example,
suppose we wish to work in a in a quotient of the polynomial ring on x
and y, where the following condition holds:
In[1]:=
Unprotect[Times];
In[2]:=
((x^k_)*(y^l_)=0)/;k+l>6;
In[3]:=
Protect[Times];
Suppose we now want to compute (x+y)^1000000. The series method is not
applicable (I think) but:
myexpand[f_, n_] :=
Fold[Expand[#1^2*If[#2 == 1, f, 1]] &, f, Rest[IntegerDigits[n, 2]]]
In[8]:=
myexpand[x+y,1000000]//Timing
Out[8]=
1000000
999999 999999 1000000
{0.02 Second, x + 1000000 x y + 1000000 x y +
y }
In principle one could do this with PolynomialReduce but I think it
would take quite a while...
Andrzej Kozlowski
Toyama International University
JAPAN
http://platon.c.u-tokyo.ac.jp/andrzej/
On Sunday, July 29, 2001, at 03:07 PM, Allan Hayes wrote:
> From the results below it looks as if for getting the first three tems
> of
> (1+x)^(10^6) (the original example). Andrzej's method is quicker as a
> one-off calcuation. But the Series method that Bob and I suggested does
> some
> cacheing and is quicker for repeats.
>
>
>
>