Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

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

Search the Archive

Re: Re: RandomReal gets stuck

  • To: mathgroup at smc.vnet.net
  • Subject: [mg100728] Re: [mg100687] Re: RandomReal gets stuck
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Thu, 11 Jun 2009 21:44:45 -0400 (EDT)
  • Organization: Deep Space Corps of Engineers
  • References: <200906061025.GAA04602@smc.vnet.net> <h0fvjl$rb1$1@smc.vnet.net>
  • Reply-to: drmajorbob at bigfoot.com

You're correct that Block and aa=ToString@a are unnecessary; it's a very  
long time since I looked at the code.

But it works just fine, as it is or with those removed; I just neglected  
to tell you how to use it.

For instance,

subFunction[
   a_Symbol] := (MakeExpression[SubscriptBox[ToString@a, i_], f_] :=
    MakeExpression[RowBox[{ToString@a, "[", i, "]"}]];
   MakeBoxes[a[i_], f_] :=
    SubscriptBox[MakeBoxes[a, f], MakeBoxes[i, f]])

Now enter

subFunction[a]

then

Array[a, 10]
Array[Subscript[a, #] &, 10]

and observe. Both outputs are the same.

Or enter

a[j]

whose output is

Subscript[a,j]

(But looking like a subscripted variable, of course.)

It only affects the symbol a, which you've set up using subFunction[a].

Bobby

On Thu, 11 Jun 2009 06:07:36 -0500, Alexey <lehin.p at gmail.com> wrote:

> On 7 =C9=C0=CE, 13:00, DrMajorBob <btre... at austin.rr.com> wrote:
>> If you want to use subscripted variables, it might help to use this  
>> code:
>>
>> subFunction::usage = "subFunction[a] causes inputting a[i] or \
>> \!\(\*SubscriptBox[\"a\", \"i\"]\) to be synonymous, while always \
>> displaying the latter in outputs."
>>
>> "subFunction[a] causes inputting a[i] or \!\(\*SubscriptBox[\"a\", \
>> \"i\"]\) to be synonymous, while always displaying the latter in \
>> outputs."
>>
>> subFunction[a_Symbol]:=Block[{aa=ToString[a]},MakeExpression[Subscrip=
> tBox[ToString@a,i_],f_]:=MakeExpression[RowBox[{ToString@a,"[",i,"]"}]];MakeBoxes[a[i_],f_]:=SubscriptBox[MakeBoxes[a,f],MakeBoxes[i,f]]]
>>
>> The result is that you can refer to a[i] or Subscript[a,i]
>> interchangeably, but it always displays in the subscripted form. I find  
>> it
>> much easier to use a[i] while typing formulas, so I'm getting the best  
>> of
>> both worlds.
>>
>> Not sure if that addresses everything brought up on the thread, of  
>> course.
>>
>> Bobby
>
>
> It is very interesting, thank you. But as I understand the definition
> aa=ToString[a]
> inside Block is not necessary. And Mathematica does not recognizes
> input Subscript[a,i] as equivalent to a[i]. There seems to be some
> errors in the code.
>



-- 
DrMajorBob at bigfoot.com


  • Prev by Date: Re: Re: differentiation operator
  • Next by Date: Re: Getting histogram information
  • Previous by thread: Re: Re: RandomReal gets stuck
  • Next by thread: Re: RandomReal gets stuck