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: [mg63188] Re: EUREKA Re: [mg62800] Types in Mathematica, a practical example
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Sat, 17 Dec 2005 03:46:20 -0500 (EST)
  • References: <43A1787000069CF6@pne-smtpout2-sn2.hy.skanova.net> (added by postmaster@pne.skanova.net)
  • Sender: owner-wri-mathgroup at wolfram.com

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: EUREKA Re: Types in Mathematica, a practical example
  • Next by Date: Re: Why is y a local variable here?
  • Previous by thread: Re: EUREKA Re: Types in Mathematica, a practical example
  • Next by thread: Re: EUREKA Re: Types in Mathematica, a practical example