[Date Index] [Thread Index] [Author Index]
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