MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Help with concatenating a list with &&


On Aug 1, 2:02 am, Tomas Garza <tgarz... at msn.com> wrote:
> Hello, Jane:
>
> Not being an expert, I find it very useful to peruse the on-line documentation center - when in doubt.
>
> I found that BooleanConvert may be used to answer your query
>
> In[1]:=  ls={ex1,ex2,ex3,ex4}
> Out[1]=  {ex1,ex2,ex3,ex4}
>
> In[2]:=  BooleanConvert[Equivalent[Sequence@@ls]]
> Out[2]=  (ex1&&ex2&&ex3&&ex4)||(!ex1&&!ex2&&!ex3&&!ex4)
>
>  Taking the first part of the output will give what you are after:
>
> In[3]:= %[[1]]
> Out[3]= ex1&&ex2&&ex3&&ex4
>
> Cheers,
>
> Tomas
>
> > Date: Fri, 31 Jul 2009 05:52:48 -0400
> > From: janemk... at gmail.com
> > Subject:  Help with concatenating a list with &&
> > To: mathgr... at smc.vnet.net
>
> > Can anyone help me make better use of mathematica's built in commands?
>
> > My problem is to take the list of expressions ls:
>
> > ls={ex1, ex2, ex3, ex4}
>
> > and connect them to obtain
>
> > ex1 && ex2 && ex3 && ex4
>
> > I thought I should be able to use
>
> > && @@ ls
>
> > or equivalently Apply[&&, ls]
>
> > However this fails. I ended up using the very awkward
>
> > conditions = ls[[1]] && ls[[2]]
> > Do[conds = conds && ls[[i]], {i, 3, Length[ls]}]
>
> > which works but feels like just bludgeoning the problem
>
> > Does anyone know of a more elegant way to work this?
>
> > Thanks,
> > Jane.

Apparently I just needed And in place of &&

Your reply is interesting - I had no idea about BooleanConvert, so
thanks for the tip.


  • Prev by Date: Making a LOOP (DO)
  • Next by Date: Batteries {Was: Re: Hacking Wolfram|Alpha)
  • Previous by thread: Re: Help with concatenating a list with &&
  • Next by thread: Re: Help with concatenating a list with &&