Re: negative pattern matching anyone?
- To: mathgroup at smc.vnet.net
- Subject: [mg43766] Re: negative pattern matching anyone?
- From: Paolo Bientinesi <pauldj at cs.utexas.edu>
- Date: Fri, 3 Oct 2003 02:28:51 -0400 (EDT)
- Organization: University of Texas at Austin
- References: <email@example.com> <firstname.lastname@example.org>
- Sender: owner-wri-mathgroup at wolfram.com
> > Then, is there a way to match both -3 and -a with the same pattern? > > Yes -- use Sign: > > h[x_] := Abs[-x] /; Sign[x] == -1 > h[x_] := x^2 > > Cheers, > Paul Thanks for all the answers, but all of them solve the problem with two different patterns (basically using ||). About the Sign suggestion, it doesn't seem to work, since Sign[-a] yields -Sign[a]: h[x_ /; Sign[x] == -1]:= Abs[x] h[x_]:= x^2 h[-3] is 3 but h[-a] is a^2 -- Paolo pauldj at cs.utexas.edu paolo.bientinesi at iit.cnr.it