       Re: Indexed Slot in a Rule - How to do it??

• To: mathgroup at smc.vnet.net
• Subject: [mg100326] Re: Indexed Slot in a Rule - How to do it??
• From: Simon <simonjtyler at gmail.com>
• Date: Mon, 1 Jun 2009 07:07:17 -0400 (EDT)
• References: <gvtme0\$gct\$1@smc.vnet.net>

```Hi again,

First, a function to find all symbols of the form symb followed by
something.  This could be streamlined and generalised a bit...

In:= findSymbols[symb_String,expr_]:=findSymbols
[{symb,CharacterRange["0","9"]},expr]
In:= findSymbols[{symb_String,exts:{__String}},expr_]:=Module[{x},
x=Union@Flatten@FixedPoint[Apply[List,#,\[Infinity]]&,expr];
Symbol/@Select[x,StringMatchQ[#,symb~~exts..]&]]

In:= test={x1,x2,x2a+x33,E^x5,Sin[x1 x2+x3 x4]}

In:= findSymbols["x",test]
findSymbols[{"x",{"2","a"}},test]
Out= {x1,x2,x3,x33,x4,x5}
Out= {x2,x2a}

Then a function that takes the expression, extracts the relevant
symbols and turns it into the type of function that you wanted

In:= T[expr_]:=Apply[Function[Evaluate@findSymbols
["x",expr],Evaluate@expr],#]&

In:= T[test]@{a,b,c,d,e,f}
Out= {a,b,d+x2a,E^f,Sin[a b+c e]}

Simon

```

• Prev by Date: Re: treatment on C[i]
• Next by Date: Re: RandomReal gets stuck
• Previous by thread: Re: Indexed Slot in a Rule - How to do it??
• Next by thread: Re: Indexed Slot in a Rule - How to do it??