Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

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

Search the Archive

Re: Pattern Matching

  • To: mathgroup at smc.vnet.net
  • Subject: [mg49027] Re: [mg49003] Pattern Matching
  • From: DrBob <drbob at bigfoot.com>
  • Date: Tue, 29 Jun 2004 04:49:59 -0400 (EDT)
  • References: <200406280813.EAA04275@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

I think the second method is simpler, but this also works, in this case:

Default[Times]
Default[Power,2]
Block[{result},
   Unprotect[Power,Times];
   Default[Power,2]=7;
   Default[Times]=5;
   result=Cases[4x+x^2,c_.*x^n_.\[Rule]{c,n}];
   Default[Power, 2] = Default[Times] = 1;
   Protect[Power,Times];
   result
   ]

1

1

{{4,7},{5,2}}

Bobby

On Mon, 28 Jun 2004 04:13:47 -0400 (EDT), Bruce W. Colletti <bcolletti at compuserve.com> wrote:

> This command (built from recent traffic) extracts the quadratic's
> coefficients and exponents:
>
>     Cases[4x + x^2, c_.*x^n_. -> {c,n}]
>
>     {{4,1}, {1,2}}
>
> As I understand it, the symbol "_." uses the global default value for
> the given variable, a value that can be set using Default.
>
> Question:  For the specific (illustrative) problem above, how would I
> set (using Default[ ]) different default values for c and n?  Or must I
> do something like:
>
>     Cases[4x + x^2, (c_:5)*x^(n_:7) -> {c,n}]
>
> Thanks.
>
> Bruce
>
>



-- 
DrBob at bigfoot.com
www.eclecticdreams.net


  • References:
  • Prev by Date: Re: matrix times a vector
  • Next by Date: Re: matrix times a vector
  • Previous by thread: Pattern Matching
  • Next by thread: Re: Pattern Matching