MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Pattern matching "on the fly"

  • To: mathgroup at
  • Subject: [mg30113] Re: [mg30100] Pattern matching "on the fly"
  • From: BobHanlon at
  • Date: Sat, 28 Jul 2001 22:08:50 -0400 (EDT)
  • Sender: owner-wri-mathgroup at

In a message dated 2001/7/28 2:07:38 AM, mackenzi at writes:

>I am trying to use Mathematica's pattern matching abilities to achieve
>something I can do using the computer algebra software REDUCE.  I want
>to do
>this because I need to take advantage of the powerful numerical algorithms
>of Mathematica.
>I want to set all powers of some variable greater than a certain value
>zero, but I want mathematica to apply this pattern matching "on the fly"
>(while an expression is being evaluated, not after the expression has been
>I'll give a quick example. I want to set all powers of x greater than 2
>zero i.e. x^3=>0, x^4=>0 and so on. In REDUCE I can use the following
>let x^3=>0;   (* This replaces x^3 with 0, x^4 with 0 and so on*)
>Then if I evaluate (1+x)^1000000, I quickly (a few seconds) find this
>expression gives 499999500000*x^2  + 1000000*x + 1.  The pattern matching
>done as the expression is being expanded.
>Now in Mathematica I have tried  x^n_ ^:=0 /; n> 2; This works, but it
>appears to be applied after an expression has been expanded.  For example
>I try
>x^n_ ^:=0 /; n> 2;
>in Mathematica, the evaluation is very slow (which I think is because the
>pattern matching is applied after the expansion and not on the fly).
>Any help would be greatly appreciated as I am very new to Mathematica.

Series[(1+x)^1000000, {x, 0, 2}]//Normal

499999500000*x^2 + 1000000*x + 1

Bob Hanlon
Chantilly, VA  USA

  • Prev by Date: Re: subscripted variables in Modules
  • Next by Date: Re: Nested Trigonometry Functions
  • Previous by thread: Re: Pattern matching "on the fly"
  • Next by thread: Re: Pattern matching "on the fly"