Re: FW: How to use Rules on Sequences?

• To: mathgroup at smc.vnet.net
• Subject: [mg29565] Re: FW: How to use Rules on Sequences?
• From: Detlef Mueller <dmueller at mathematik.uni-kassel.de>
• Date: Mon, 25 Jun 2001 20:42:19 -0400 (EDT)
• Organization: University of Kassel - Germany
• References: <9h1afp\$r7j\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```"Wolf, Hartmut" wrote:
>
...
> >
> > given a List of Pairs of the Form
> >
> > L = {{a1,m1},{a2,m2}, ... ,{ai,mi}}
>

Perhaps it may be helping (and exploit some
awkward constructions of mine :) ), to say
for what pupose this is:

I want to represent an Algebra A[D1,...Dr]
(where the Xi do not commute with Elements
of A, but the Di commute with each other.
).
After the trial to leave all calculations
to Mathematica's kernel (in defining rules
Di*a -> f(a)*Di+g(a), associativity etc.)
led to a mess (for when the package grew
bigger, debugging was nearly impossible,
and for more sophisticated Operations one
likes to have a more firm control of what
is actually happening in which order).

So now I changed the Design:
An Polynomial of A[D1,...Dr] is represented
as OP[___OS], And each Summand is of the
Form OS[Coeff_, OM[___List]].
For Example (if the Ring A is Q[X,Y])

X^2 D1^3 D2 + Y D2 + Z + 3 wold be
OP[OS[X^2, OM[{1,3},{2,1}]], OS[Y, OM[{2,1}], OS[Z+3,OM[]]]].

Now what I requested refered to the Multiplication
of The Monomials OM[...](which represent Multiindicees, I
decided not to use a simple List with zero-Entries
for non existent Operators, because it should be
possible to introduce new operators at any time).

...

> suggestions:
>
> If you want to keep your {key, count} pairs in sorted order, you may contain
> them in a container with Attribute Orderless instead of in a List:
>
> In[1]:= keys = {de, frosh, quakt, quark, quarrk}
>
> In[2]:= Attributes[Olaf] = Orderless
>
"Orderless"!
Seems that's what my "OM[..]"'s need,
provided the whole Idea (of numerating
the Di's and storing their Names
and the according non-commutation-functions
(the f, g above) in separat Variables) is
not a too inefficient way in general.
...

>
> However I wouldn't follow that approach. It will become overly slow if you
> keep many counters. Instead use Mathematica symbol store (hash table). Our
> "container" is now a symbol, say 'Ede'.
>
> In[16]:= Ede[a_] := Ede[a] = 0
>
> This general rule automatically creates a counter (with key a), if needed.
>
> In[17]:= inc[a_] := Ede[a] += 1
> In[18]:=
> dec[a_] := If[(Ede[a] -= 1) <= 0, Unset[Ede[a]]; 0, Ede[a]]
>
After some experimenting, i got the idea ...

> In[23]:= inc /@ Table[frosh, {3}]
> Out[23]= {1, 2, 3}
>
> In[24]:= dec /@ Table[frosh, {4}]
> Out[24]= {2, 1, 0, 0}
>
> In[25]:= clr := (ClearAll[Ede]; Ede[a_] := Ede[a] = 0)
>
> To clear all counters.
>
> In[26]:= clr
>
> In[27]:=
> MapThread [inc /@ Table[#1, {#2}] &, {keys, Range[-1, 3]^2}]
>
... think ... think ... type ... think ...
finally I saw what happens here :)

> This just sets up the same content as in Out[3] above
>
> In[28]:= DownValues[Ede] // TableForm
> Out[28]//TableForm=
>    HoldPattern[Ede[de]] :> 1
>    HoldPattern[Ede[quakt]] :> 1
>    HoldPattern[Ede[quark]] :> 4
>    HoldPattern[Ede[quarrk]] :> 9
>    HoldPattern[Ede[a_]] :> (Ede[a] = 0)
>

> No frosh present, however if you ask for it, it shows up
>
> In[29]:= Ede[frosh]
> Out[29]= 0
>

Thank you very much!

greetings
Detlef

```

• Prev by Date: List problems
• Next by Date: Re: How do I really get rid of previous results?
• Previous by thread: Re: Re: How to use Rules on Sequences?
• Next by thread: Computational Finance Position