RE: Re: Operate on Heads

*To*: mathgroup at smc.vnet.net*Subject*: [mg87086] RE: [mg86661] Re: Operate on Heads*From*: "Dr Andy D Kucar P2EE4 www.radio4u.com" <andy at radio4u.com>*Date*: Mon, 31 Mar 2008 02:05:39 -0500 (EST)*Reply-to*: <andy at radio4u.com>

I would like to thank to all respondents to my posted questions on this, as well as on previous topics. I would try to explain some of my desires? on a rather simple example related to some natural events I have a number of Modules (subroutines, functions, or whatever one prefer to call it) With (subject, object(s), event(s), action(s)) structure. For example, a subject is an Earth based location triad, Objects are Sun and Moon, Events are Rise and Set, ... Based on interrelations of all of above, Some unique action, based on the state of the system, should be described/specified, and executed One way to solve this problem is to have all logic in the main program and have a possibly large number of small modules, Each describing a unique but simple action. The logic could, in principle, be implemented via combination of If,Then,Else,Switch; And,Or,... ; (pattern construction) Alternatives; or something better ? In this simple example we have (hidden/protected possibly someone else or even Mathematica own) commands such as Set (possibly the same name for two completely different commands), Rise, Sun, Moon, but also commands (modules, or whatever) SunRise, SunSet, MoonRise, MoonSet, which name (Head) is a composite word. I have dealt with such situations along the lines described by Januk, tnx, and via fun[A,B,C][a,b,c][t] Polygon @@ Line Type of structures. The last line Apply approach actually just replaces the Head name. In principal no problem when I have my own relatively simple structures, however, ... Some of my Modules are to often inside some loops (Table, Plot). In complex interrelations between a larger number of objects and events, logic is becoming cumbersome and all things are getting to slow. Thus my imperative in those situations is getting under the hood, if I can and if I have enough time, And speed things up. Now comes Mathematica's sentence Operate is essentially a generalization of Apply, which allows you to apply an operator to the head of an expression, rather than simply to replace the head What this really means? This is what stimulated me, since I smell (possibilities toward) a number of better, more elegant, more efficient, solutions to my problems ... Of course there might be some Pandora Boxes in between ... (non)technical issues, etc. C pointers and list of all lists, the machine code list, and its 1:1 twin called assembler are coming to mind ... Thanks, andy -----Original Message----- From: Januk [mailto:ggroup at sarj.ca] Sent: Monday, March 17, 2008 00 21 To: mathgroup at smc.vnet.net Subject: [mg87086] [mg86661] Re: Operate on Heads Hi Andy, A basic approach would be to convert everything to strings, use Mathematica's string manipulation commands to create the expression you'd like evaluated, then convert back to an expression. See below for a simple example. f[something_, x__] := Module[{strArgs, strHeads}, strHeads = ToString[something]; strArgs = Riffle[ToString /@ {x}, ","]; (* Manipulate your heads here *) strHeads = StringReplace[strHeads, "p" -> "P"]; StringJoin[strHeads, "[", strArgs, "]" ] // ToExpression ] f[plus, 2, 3] Hope that helps, Januk On Mar 16, 6:49 am, "Dr Andy D Kucar P2EE4 www.radio4u.com" <a... at radio4u.com> wrote: > Hi, > > Hi, > > I would like to be able to pass a composite name Head, e.g., > FirstSecondThird to a Module, > and then, inside the module, use > > FirstSecondThird, First, Second, Third > > Heads, and/or make other Operate ions on Heads > > How could this be accomplished? > Thank you > > Sincerely Andy