Re: Combining several pure functions into a single pure function

*To*: mathgroup at smc.vnet.net*Subject*: [mg7287] Re: [mg7262] Combining several pure functions into a single pure function*From*: penny at suu.edu (Des Penny)*Date*: Thu, 22 May 1997 09:19:38 -0400 (EDT)*Sender*: owner-wri-mathgroup at wolfram.com

>I am working with a little program that generates several pure >functions which are "Boolean" in nature -- i.e., each of them, when >applied to an argument, evaluates to True or False. These functions, >when they are initially produced, are connected with logical operators >-- for example: > > (Function[x,Plus[x]>9] && Function[x,Length[x]==4]) || > (Function[x,Plus[x]<3] && Function[x,Length[x]==6]) > >In this form, however, they are useless since, as a group, they do not >constitute a pure function and cannot be applied to an argument. >Thus, I need to convert the foregoing into a single pure Boolean >function, which would (using the above example) look like this: > > Function[x,(Plus[x]>9 && Length[x]==4) || > (Plus[x]<3 && Length[x]==6)] Hi Robert: Is this what you need? ================================================= test= (((Plus @@ # >9) && (Length[#]==4)) || ((Plus @@ # >3)&&(Length[#]==6)))&; test[{1,-2,3,1,1,1}] Out: True ================================================= I was initially confused about x in your code. I finally decided that it had to be a list. However Plus[{1,2}], returns {1,2}. I believe what you need is the Apply function: Apply[Plus,{1,2}] Which returns 3. This can also be written: Plus @@ {1,2}. This is the form I've used above. Hope this helps. Cheers, Des Penny ------------------------------- Des Penny Physical Science Dept. Southern Utah University Cedar City, UT 84720 VOICE: (Office): (801) 586-7708 (Home) : (801) 586-2286 FAX: (801) 865-8051 e-mail: penny at suu.edu -------------------------------