Re: Re: Selecting left hand sides from assignments

*To*: mathgroup at smc.vnet.net*Subject*: [mg97970] Re: [mg97803] Re: [mg97614] Selecting left hand sides from assignments*From*: "E. Martin-Serrano" <eMartinSerrano at telefonica.net>*Date*: Thu, 26 Mar 2009 05:44:22 -0500 (EST)*References*: <200903221047.FAA08220@smc.vnet.net>

Hi again, The following works as I wanted: it takes apart *lhs* and *rhs* of *Set* expressions while keeping the relation between the *lhs* to the *rhs* for further use. But, to get it to work one has to start working with a fresh kernel as to ensure the *lhs*(s) have not been assigned any value before the sequence of assignments *assign* is sent to the function *SplitSetSides*. However, since I am to use it as a meta-programming tool (not to be include in end user programs) this is not a big drawback, tough a bit artificial. The first sublist in *Out[4]* contains the *lhs*(s) while the second contains the *rhs*(s). In[1]:= Clear@frhs frhs[rhs_][symbols_] := Module[{step}, step = Fold[Flatten[#1, Infinity, #2] &, rhs, symbols]; step = Union@Flatten@FixedPoint[Apply[List, #, Infinity] &, step]; step = List @@ step; SymbolName[#] & /@ Select[Flatten[step], Head[#] === Symbol &] ] In[2]:= Clear@SplitSetSides SplitSetSides[holdassignments_] := Quiet@Module[{symbols = Symbol[#] & /@ Names["System`*"]}, {SymbolName[#] & /@ (List @@ Map[First, Map[Unevaluated, holdassignments]]), frhs[#][symbols] & /@ Apply[List, Map[Hold, holdassignments, {1}]]}] In[3]:= assign = Hold[a1 = Log[b1*c1^12], a2 = Sqrt[b2*c2], a3 = Log[b1*c1^12]*Sqrt[a2*c2]^b3*c3 ]; In[4]:= SplitSetSides[assign] Out[4]= {{"a1", "a2", "a3"}, {{"a1", "b1", "c1"}, {"a2", "b2", "c2"}, {"a3", "c3", "b1", "c1", "a2", "c2", "b3"}}} For now, this solution seems to be good enough for my needs. For instance, it will help me in building the data dependency graph for a large notebook meant to make dense computations involving many dynamic interrelated objects. The simplification of the data dependency graph helps in to improving efficiency by eliminating superfluous or redundant computation paths which would slow down significantly the performance. Also would help in pointing out circularities. And, although it needs some additional testing it seems to be working ok under my conditions. One thing which is still left (among many others) is to take out the names in *symbols* which do not correspond to true symbols (operators) in the list generated by the expression *symbols = Symbol[#] & /@ Names["System`*"]*} in the module of the function *SplitSetSides*. Any feed back will be appreciated. I hope it will be of any use to someone else. Cheers and many thanks for your help. E. Martin-Serrano ------------------------------------------------------------ >I need help on the following. >From the list of assignments: >assignmentslist = {LHS1 = RHS1, LHS2 = RHS2, LHS3 = RHS3, ..., LHSi = RHSi, ..., LHSn = RSHn} >I need to extract all the left hand sides (symbols) within a list like: >lhslist = {LHS, LHS2, LHS3, ..., LHSi, ..., LHSn} >Where the left hand sides are all symbols and the right hand sides are any expression. >E. Martin-Serrano -------------------------------------------

**References**:**Re: Selecting left hand sides from assignments***From:*"E. Martin-Serrano" <eMartinSerrano@telefonica.net>