MathGroup Archive 2004

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

Search the Archive

Pattern Matching

  • To: mathgroup at smc.vnet.net
  • Subject: [mg49003] Pattern Matching
  • From: "Bruce W. Colletti" <bcolletti at compuserve.com>
  • Date: Mon, 28 Jun 2004 04:13:47 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

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


  • Prev by Date: Re: Clarification [Overlay graphs ]
  • Next by Date: matrix times a vector
  • Previous by thread: CellMargins
  • Next by thread: Re: Pattern Matching