Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Non-sequential composition of pure functions
Replies: 6   Last Post: Aug 23, 2012 8:51 PM

 Search Thread: Advanced Search

 Messages: [ Previous | Next ]
 Ralph Dratman Posts: 62 Registered: 5/13/11
Re: Non-sequential composition of pure functions
Posted: Aug 23, 2012 2:53 AM
 Plain Text Reply

I have developed some relevant techniques for handling this sort of
problem, but in order to suggest what to do, I need to see more
details of what the desired result should look like. Could you please
illustrate that with an example of (manually) combining two or three
pure functions, showing what you would like the resulting function to
look like?

Thank you.

Ralph Dratman

On Wed, Aug 22, 2012 at 5:19 AM, awnl <awnl@gmx-topmail.de> wrote:
> Hi,
>

>> I have a list of pure functions (If[Conditional[#[[1]]],Action]&
>> statements) and I want to compose them into one large pure function
>> If[FirstConditional[#[[1]]]&&SecondConditional[#[[6]]]&&ThirdConditional[#[[foo]]],Action]&.
>> They are to be applied to a list of values, and the conditionals checked
>> for multiple columns for a given element of a list.
>>
>> I'm having problems joining these things together - to the point that I've
>> considered converting them all to strings and doing the tedious
>> (hackie) string manipulations to get the final function in the right form.
>> Any recommendations on how to do this? I found Composition[] but it nests
>> the functions - and I want to combine them.

>
> it is not clear what you mean by "combining" the functions, but whatever
> you want to do, I would never suggest to convert to string and back. It
> is one of the great strengths of Mathematica that you can treat
> Mathematica code just a any other expression, although the evaluation
> scheme makes it somewhat tricky to manipulate code without evaluating
> it. Here is an example which does something along the lines you described:
>
> condlist={If[#[[1]]>0,Print["1"]]&,If[#[[2]]>0,Print["2"]]&}
>
> If@@@(Function@@{Join[
> And@@@Hold@@{Flatten[Hold@@Cases[condlist,Function[If[c_,a_]]:>Hold[c],{1}]]},
> Hold[Print["3"]]
> ]})
>
> There might be somewhat simpler or clearer ways to do such
> manipulations. Which "tricks" you use to avoid the evaluation of the
> code you manipulate are also a matter of taste, it's usually some
> combination of Hold, Unevaluated, With that you'll need. If you want a
> solution for your very problem, you would need to send a full example of
> input and desired output...
>
> hth,
>
> albert
>

Date Subject Author
8/22/12 Earl.J.Mitchell@gmail.com
8/22/12 Ray Koopman
8/22/12 Albert Retey
8/23/12 Ray Koopman
8/23/12 Ray Koopman
8/23/12 Ralph Dratman
8/23/12 Earl.J.Mitchell@gmail.com

© The Math Forum at NCTM 1994-2018. All Rights Reserved.