MathGroup Archive 2003

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

Search the Archive

Re: Re: New version, new bugs

  • To: mathgroup at smc.vnet.net
  • Subject: [mg42947] Re: [mg42930] Re: New version, new bugs
  • From: Andrzej Kozlowski <andrzej at platon.c.u-tokyo.ac.jp>
  • Date: Tue, 5 Aug 2003 02:04:59 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Having (very reluctantly) considered this matter more closely I feel 
compelled to admit I was wrong. The pattern Hold[Plus] used by Maxim is 
not nonsensical (I apologize) and HoldPattern[Plus][a]] is not parsed 
to a as I had assumed without doing any tests, in fact:


MatchQ[Unevaluated[Plus[a]],HoldPattern[Plus][a]]


True

So, while I hate to admit it, at the moment I can't understand why 
Maxim example:

> f[a] + f[b] + 1 /. HoldPattern[Plus][f[_] ..] :> 0 /; True

does not work (I think I understand the others). But I stand by my 
original claim is that all that is of little value since I can imagine 
no practical situation in which anyone might want to use any of these 
weird constructions. I agree that most users, even pretty sophisticated 
ones, do not fully understand the pattern matcher, but then I can't see 
any compelling reason why they should.

Andrzej Kozlowski
Yokohama, Japan
http://www.mimuw.edu.pl/~akoz/
http://platon.c.u-tokyo.ac.jp/andrzej/



On Monday, August 4, 2003, at 09:12 PM, Andrzej Kozlowski wrote:

> The reason why you usage of HoldPattern[Plus] is nonsensical (as I 
> wrote in my original posting) is that  Plus[a] evaluates to just a and 
> Plus[a,b] to Plus[a,b]. So if you evaluate
>
>>> f[a] + f[b] + 1 /. HoldPattern[Plus][f[_] ..] :> 0 /; True
>
> HoldPattern[Plus][f[_] ..] evaluates to f[_] .. and you do not get a 
> match.  In you other cases you use HoldPattern[Plus] with more than 
> one argument, so things work differently. There is no mystery.
>
> Your tone in this discussion has began to reasmble that of of someone 
> who tried and  failed to get a job with Wolfram Reasearch or has some 
> other personal grudge so I propose to stop it all here.
>
> Andrzej
>
>
> On Monday, August 4, 2003, at 06:45 AM, Maxim wrote:
>
>>
>>
>> Andrzej Kozlowski wrote:
>>
>>> Maxim has pointed out that RuleCondition has the attribute 
>>> HoldFirst. I
>>> was too careless giving my explanation: what I meant to refer to was
>>> the following difference between Condition and RuleCondition (which I
>>> learned form Allan Hayes)
>>>
>>> Hold[a] /. a :> Condition[1 + 1,True]
>>>
>>>          Hold[1+1]
>>>
>>> Hold[a] /. a :> RuleCondition[1 + 1, True]
>>>
>>>          Hold[2]
>>>
>>>
>>
>> I have no idea what RuleCondition is for and how you can rewrite, say,
>>
>> 2/.x_:>x^2/;x>0
>>
>> using RuleCondition, but it's totally irrelevant; you say that 
>> something
>> somewhere doesn't get evaluated -- then put Evaluate in the right 
>> place and
>> demonstrate the difference. I have a feeling you won't succeed. And 
>> before
>> you give yet another "conclusive demonstration", try also explaing 
>> how these
>> four examples work:
>>
>> f[a] + f[b] + 1 /. HoldPattern[Plus][_, _] /; True :> 1
>> f[a] + f[b] + 1 /. HoldPattern[Plus[_, _]] /; True :> 1
>> f[a] + f[b] + 1 /. HoldPattern[Plus][_, _] :> 1 /; True
>> f[a] + f[b] + 1 /. HoldPattern[Plus[_, _]] :> 1 /; True
>>
>> I'll try giving a suggestion why the four examples in my original 
>> posting
>> (with f[_]..) work that way; it is probably related to the following:
>>
>> In[1]:=
>> FreeQ[x+y+z,x+y]
>> Cases[x+y+z,x+y,{0,-1}]
>>
>> Out[1]=
>> False
>>
>> Out[2]=
>> {}
>>
>> Even though Cases does pattern matching (the second argument can be a
>> pattern), in this case it doesn't break the expression into 
>> Plus[Plus[x,y],z]
>> (yes, I know that it is a documented feature). So my guess is that 
>> somewhere
>> in the dark recesses of Mathematica pattern matcher this confusion 
>> between
>> two approaches arises.
>>
>> Of course, maybe Jens-Peer Kuska will explain to me again how I don't 
>> know
>> what I'm doing, but he did seem to be rather quiet lately...
>>
>> The real problem is that there isn't any complete specifications 
>> describing
>> the behaviour of pattern matching. So it's not even possible to say 
>> if an
>> example is correct/incorrect, one has to resort to simply pointing out
>> inconsistencies...only it seems that developers sometimes have to 
>> resort to
>> the same means.
>>
>> Exactly the same goes for the example with Module and variables 
>> renaming.
>>
>> Maxim Rytin
>> m.r at prontomail.com
>>
>>
>>
>>
> Andrzej Kozlowski
> Yokohama, Japan
> http://www.mimuw.edu.pl/~akoz/
> http://platon.c.u-tokyo.ac.jp/andrzej/
>
>


  • Prev by Date: Re: Re: New version, new bugs
  • Next by Date: Roots selection
  • Previous by thread: Re: Re: New version, new bugs
  • Next by thread: Re: Re: New version, new bugs