MathGroup Archive 2003

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

Search the Archive

Re: negative pattern matching anyone?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg43741] Re: negative pattern matching anyone?
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Thu, 2 Oct 2003 02:52:22 -0400 (EDT)
  • Organization: Universitaet Leipzig
  • References: <blcqqj$p8h$1@smc.vnet.net>
  • Reply-to: kuska at informatik.uni-leipzig.de
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

k[n_?NumericQ] /; n < 0 := Abs[n]
k[a_.*b_Symbol] /; NumericQ[a] && a < 0 := Abs[a]*b

Regards
  Jens

Paolo Bientinesi wrote:
> 
> Hello,
> could anyone explain me why -3 is different from -a in the
> following situation, please?
> 
> h[-x_] := Abs[x]
> h[x_]  := x^2
> 
> now,
> 
> k[-3] = 9
> k[-a] = Abs[a]
> 
> I guess the answer con be found in the FullForm:
> 
> FullForm[-a] = Times[-1,a]
> FullForm[-x_] = Times[-1,Pattern[x,Blank[]]]
> 
> while FullForm[-3] = -3
> 
> Then, is there a way to match both -3 and -a with the same pattern?
> Thanks.
> --
> Paolo
> 
> pauldj at cs.utexas.edu                    paolo.bientinesi at iit.cnr.it


  • Prev by Date: Re: FileBrowse command
  • Next by Date: Non-string output in for loop
  • Previous by thread: Re: negative pattern matching anyone?
  • Next by thread: Re: negative pattern matching anyone?