Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to map `and` to a list of boolean?

0 views
Skip to first unread message

steve_H

unread,
Dec 22, 2003, 6:12:44 PM12/22/03
to
hi;

I want to find the result of something like

A and B and C and D

I have a list of the boolean expressions (in this example,
A,B,C,D,etc...). This list can be arbitrarily long.

I thought I can use the command 'map' to apply 'and' to the list,
but can't figure how to do it.

Let m be the list.

> m:=[true,true,true,false];


> map(`and`,m);

Error, wrong number (or type) of parameters in function and

it works in this example:

> map(`and`,true,true);

but not in this example (more than 2 arguments to and):

> map(`and`,true,true,true);

Error, wrong number (or type) of parameters in function and

Any way, as you see I am having trouble with this.

Is there a way to map 'and' to a list of boolean, such that if
only ONE boolean is false, then the return is false?

fyi, in Mathematica, I can do it like this:

In[29]:=m = {True, True, True}
Out[29]={True, True, True}
In[30]:=And @@ m
Out[30]=True


In[31]:= m = {True, True, False}
Out[31]= {True, True, False}
In[32]:= And @@ m
Out[32]= False

Alec Mihailovs

unread,
Dec 23, 2003, 12:02:01 AM12/23/03
to
"steve_H" <nma...@hotmail.com> wrote in message
news:8db3d6c8.03122...@posting.google.com...

>
> I want to find the result of something like
>
> A and B and C and D
>
> I have a list of the boolean expressions (in this example,
> A,B,C,D,etc...). This list can be arbitrarily long.

One can use something like that,

And:=proc(L::list(boolean))
if member(false,L) then false
elif member(FAIL,L) then FAIL
else true fi end:

Alec


Carl Devore

unread,
Dec 23, 2003, 12:42:29 AM12/23/03
to
nma...@hotmail.com (steve_H) wrote:
> I want to find the result of something like
> A and B and C and D
> I have a list of the boolean expressions (in this example,
> A,B,C,D,etc...). This list can be arbitrarily long.
>
> I thought I can use the command 'map' to apply 'and' to the list,
> but can't figure how to do it.
> Let m be the list.
> > m:=[true,true,true,false];

andmap(eval ,m);

Edwin Clark

unread,
Dec 23, 2003, 12:52:09 AM12/23/03
to

"steve_H" <nma...@hotmail.com> wrote in message
news:8db3d6c8.03122...@posting.google.com...
> hi;
>
> I want to find the result of something like
>
> A and B and C and D
>
> I have a list of the boolean expressions (in this example,
> A,B,C,D,etc...). This list can be arbitrarily long.
>

Here's one way to do it:

> X:=[true,true,false,true]:
> not has(X,false);

false

And if the values in the list are boolean expression other than true and
false:

> Y:=[1<2,1=1,2<1]:
> not has(map(evalb,Y),false);

false

Edwin Clark


Edwin Clark

unread,
Dec 23, 2003, 9:47:04 AM12/23/03
to

"Carl Devore" <dev...@math.udel.edu> wrote in message
news:3a64b911.03122...@posting.google.com...

Or, in case m is a list of boolean expressions other than true or false:

>andmap(evalb,[1 =1, 1<2,2<1,x=x]);


0 new messages