MathGroup Archive 2003

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

Search the Archive

Re: negative pattern matching anyone?


> > 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


  • Prev by Date: Signal Processing Help please..
  • Next by Date: Re: Plotting functions with undefined values
  • Previous by thread: Re: negative pattern matching anyone?
  • Next by thread: Re: negative pattern matching anyone?