Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*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 2005

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

Search the Archive

Re: EUREKA Re: Types in Mathematica, a practical example

  • To: mathgroup at smc.vnet.net
  • Subject: [mg63198] Re: EUREKA Re: [mg62800] Types in Mathematica, a practical example
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Sun, 18 Dec 2005 07:34:35 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

I forgot one thing: how to deal with your original problem.

In[1]:=
a=Array[Unique[a]&,{2,2}]

Out[1]=
{{a$17,a$18},{a$19,a$20}}

In[2]:=
a-x/.Flatten[Thread/@Thread[a->x]]

Out[2]=
{{0,0},{0,0}}


Seems to me a little simpler than with the HoldForm approach.

Andrzej


On 17 Dec 2005, at 13:48, Andrzej Kozlowski wrote:

> If you feel really want do it in this sor of  way, I  suggest the  
> following approach:
>
>
> x=Array[Unique[x]&,{2,2}]
>
>
> {{x$23,x$24},{x$25,x$26}}
>
> etc.
>
> I think in this way you get all the benefits of your approach  
> without all the problems that will result from using HoldForm.  
> (Somebody might have suggested this already; I have not followed  
> all the suggestions carefully since I do not myself feel any need  
> for a solution to this problem.)
>
> Andrzej Kozlowski
>
>
>
> On 17 Dec 2005, at 08:16, Andrzej Kozlowski wrote:
>
>>
>> On 17 Dec 2005, at 02:26, Ingolf Dahl wrote:
>>
>>>
>>>
>>> My suggestion to define a 2x2 list of undefined elements is the  
>>> following:
>>>
>>> x = {{HoldForm[x[[1,1]]], HoldForm[x[[1,2]]]}, {HoldForm[x[[2,1]]],
>>> HoldForm[x[[2,2]]]}};
>>
>> You really do love this typing business ;-) Why not:
>>
>>
>> In[1]:=
>> x = Array[HoldForm[x[[##1]]] & ,
>>    {2, 2}]
>>
>> Out[1]=
>> {{HoldForm[x[[1,1]]],
>>    HoldForm[x[[1,2]]]},
>>   {HoldForm[x[[2,1]]],
>>    HoldForm[x[[2,2]]]}}
>>
>>>
>>> Occasionally, when you have defined some of the undefined  
>>> elements, you may
>>> convert to Input Form or have to apply ReleaseHold or
>>> ReplaceAll[#,HoldForm[Part[a__]]:>Part[a]]& @ to get rid of the  
>>> invisible
>>> HoldForm surrounding the indexed elements. For Set and SetDelayed  
>>> you can
>>> get this automatically by the command
>>
>> Hm... have you really tried it:
>>
>>
>>
>> ReplaceAll[#,HoldForm[Part[a__]]:>Part[a]]& @x
>>
>>
>> {{HoldForm[x[[1,1]]],
>>    HoldForm[x[[1,2]]]},
>>   {3, HoldForm[x[[2,2]]]}}
>>
>>
>>>
>>> Unprotect[HoldForm]; HoldForm /: Set[ HoldForm[ Part[a__]],b_]:=  
>>> Set[
>>> Part[a],b]; HoldForm /: SetDelayed[ HoldForm[ Part[a__]],b_]:=  
>>> SetDelayed[
>>> Part[a],b];
>>>  Protect[HoldForm];
>>
>> Since I consider redefining basic built in functions as  
>> "unnecessary evil" I will stop at this. Personally I just can't  
>> see any point in all of this  but of course this is just a  
>> personal opinion. Those who like or imagine it could be useful it  
>> can pursue this further.  However, there is just one more thing to  
>> deal with:
>>
>>
>>
>>> ___________________________________________________________
>>> When I played with this, I came across the following:
>>>
>>> Assume, that the value of axxx is not defined. Then
>>>
>>> Hold[Part[axxx, 57, 62]] /. {axxx -> b}
>>>
>>> returns
>>>
>>> Hold[b[[57,62]]]
>>>
>>> but if we first assign any value to axxx, e.g. Indeterminate, we  
>>> instead
>>> obtain
>>>
>>> Hold[axxx[[57,62]]]
>>>
>>> Can someone explain?
>>
>> This is pretty obvious and I am sure you can explain it yourself.  
>> However, since you asked ..
>>
>> If aaax has the value Intermediate then in
>>
>> ReplaceAll[Hold[Part[axxx, 57, 62]], {Rule[axxx, b]}]
>>
>> the second argument evaluates to Intermediate->b, so all you are  
>> doing is evaluating:
>>
>> Hold[Part[axxx, 57, 62]] /. {Intermediate -> b}
>>
>> Use instead
>>
>>
>> Hold[axxx[[57,62]]] /.
>>   {HoldPattern[axxx] -> b}
>>
>>
>> Hold[b[[57,62]]]
>>
>>
>>
>>
>>>
>>> And I wish everybody A Merry Christmas and A Happy New Year!
>>>
>>
>> I fully agree with this!
>>
>> Andrzej Kozlowski
>


  • Prev by Date: Re: Re: New MathGL3d Add-On for Mathematica Available
  • Next by Date: Re: How to cope with tiny numbers in FindRoot
  • Previous by thread: EUREKA Re: Types in Mathematica, a practical example
  • Next by thread: Uninstall Mathematica v4