Re: negative pattern matching anyone?
- To: mathgroup at smc.vnet.net
- Subject: [mg43933] Re: negative pattern matching anyone?
- From: Paolo Bientinesi <pauldj at cs.utexas.edu>
- Date: Mon, 13 Oct 2003 04:04:35 -0400 (EDT)
- Organization: University of Texas at Austin
- References: <firstname.lastname@example.org> <email@example.com> <firstname.lastname@example.org>
- Sender: owner-wri-mathgroup at wolfram.com
Paul Abbott wrote: > > Finally, what is the application? There are possibly other better ways > to approach such problems. > Thanks again for the responses. I have to say that I was searching for a single pattern to match both the cases just for elegance, not for strict need. Anyway the particular problem I'm dealing with is somewhat unnatural: I am working with HoldForms, say: holdTimes[x_,y_]:=HoldForm[x y] so that holdTimes[3,-2] returns 3 (-2) but what I am particularly interested in is that the product x y is not evaluated, while the sign of the operation can be resolved (this to avoid situations like -(-(-(-(.... ). So I would like holdTimes to behave like holdTimes[3,-2] = -(3 2) and holdTimes[-3,-a] = 3 a Unfortunately the definitions holdTimes[-x_,-y_]:=holdTimes[x,y] holdTimes[-x_,y_]:=-holdTimes[x,y] holdTimes[x_,-y_]:=-holdTimes[x,y] holdTimes[x_,y_]:=holdForm[x y] don't work, as holdTimes[3, -4] = 3 (-4) and holdTimes[-3,-4] = -3 (-4) but notice that holdTimes[-a, -b] = a b -- Paolo pauldj at cs.utexas.edu paolo.bientinesi at iit.cnr.it