Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2003
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2003

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

Search the Archive

Re: Re: negative pattern matching anyone?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg43941] Re: [mg43933] Re: negative pattern matching anyone?
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Tue, 14 Oct 2003 01:07:37 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

On Tuesday, October 14, 2003, at 03:36 AM, Paolo Bientinesi wrote:

> Andrzej Kozlowski wrote:
>>
>> How about this:
>>
>> holdTimes[x_, y_] := If[x y != 0, With[{u = Abs[x], v = Abs[y]},
>>        x y HoldForm[u v]/Abs[x y]], 0]
>>
>> Everything you demand seems to work:
>
> Andrzej,
>
> this definition doesn't work for symbolic arguments:
>
> try:
>
> holdTimes[-a, 3]
>
> --
> Paolo
>
> pauldj at cs.utexas.edu		        paolo.bientinesi at iit.cnr.it
>
>

I forgot that you wanted it to "work" for symbolic arguments. You can 
modify it either like this:


holdTimes[x_, y_] := FullSimplify[If[x*y =!= 0,
     With[{u = Abs[x], v = Abs[y]}, (x*y*HoldForm[u*v])/
       Abs[x*y]], 0]]

which gives the mathematically more sensible result:



holdTimes[-a, b]


(-HoldForm[Abs[a]*Abs[b]])*Sign[a*b]

or, to


holdTimes[x_, y_] :=
   FullSimplify[If[x*y =!= 0,
      With[{u = Abs[x], v = Abs[y]}, (x*y*HoldForm[u*v])/
        Abs[x*y]], 0]] /. {Abs[p_] -> p, Sign[p_] -> 1}

which gives


holdTimes[-a, b]

-HoldForm[a*b]

which I guess is what you wanted (?)

Note however that the presence of FullSimplify makes this relatively 
slow so that an approach based on using string matching (which I 
suggested in an earlier posting) might perhaps be preferable.

Andrzej



  • Prev by Date: Re: What Happens to Garbage in Mathematica?
  • Next by Date: Re: Re: negative pattern matching anyone?
  • Previous by thread: Re: negative pattern matching anyone?
  • Next by thread: Re: Re: negative pattern matching anyone?