MathGroup Archive 2009

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

Search the Archive

Re: Help with concatenating a list with &&

  • To: mathgroup at smc.vnet.net
  • Subject: [mg102197] Re: [mg102153] Help with concatenating a list with &&
  • From: "David Park" <djmpark at comcast.net>
  • Date: Sat, 1 Aug 2009 03:58:55 -0400 (EDT)
  • References: <22188493.1249035660220.JavaMail.root@n11>

The documentation does seem to be confusing about that. "&&" apparently can
only be used as an infix operator. But in your case you can just use plain
"And".

ls = {ex1, ex2, ex3, ex4};

And @@ ls
ex1 && ex2 && ex3 && ex4

Apply[And, ls]
ex1 && ex2 && ex3 && ex4


David Park
djmpark at comcast.net
http://home.comcast.net/~djmpark/  


From: janey [mailto:janemkiwi at gmail.com] 

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.




  • Prev by Date: Re: Help with concatenating a list with &&
  • Next by Date: Re: Help with concatenating a list with &&
  • Previous by thread: Re: Help with concatenating a list with &&
  • Next by thread: Re: Help with concatenating a list with &&