How do I get Mathematica to thread a 2-variable function over two lists, using functional programmin

Posted by Leah Wrenn Berman on Stack Overflow See other posts from Stack Overflow or by Leah Wrenn Berman
Published on 2010-04-01T23:21:09Z Indexed on 2010/04/01 23:23 UTC
Read the original article Hit count: 278

Filed under:
|

Lets say I have a function f[x_, y_], and two lists l1, l2. I'd like to evaluate f[x,y] where x runs over the list l1 and y runs over the list l2, and I'd like to do it without having to make all pairs of the form {l1[[i]],l2[[j]]}.

(Motivation: I'm trying to implement some basic Haskell programs in Mathematica. In particular, I'd like to be able to code the Haskell program

isMatroid::[[Int]]->Bool
isMatroid b =and[or[sort(union(xs\\[x])[y]'elem'b|y<-ys]|xs<-b,ys<-b, xs<-x]

I think I can do the rest of it, if I can figure out the original question, but I'd like the code to be Haskell-like. Any suggestions for implementing Haskell-like code in Mathematica would be appreciated.)

© Stack Overflow or respective owner

Related posts about mathematica

Related posts about haskell