Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 697481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:10:21+00:00 2026-05-14T03:10:21+00:00

Lets say I have a function f[x_, y_] , and two lists l1 ,

  • 0

Lets say I have a function f[x_, y_], and two lists l1, l2. I’d like to evaluate f[x,y] for each pair x,y with x in l1 and y in l2, and I’d like to do it without having to make all pairs of the form {l1[[i]],l2[[j]]}.

Essentially, what I want is something like Map[Map[f[#1, #2]&, l1],l2] where #1 takes values from l1 and #2 takes values from l2, but this doesn’t work.

(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.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T03:10:22+00:00Added an answer on May 14, 2026 at 3:10 am

    To evaluate a function f over all pairs from two lists l1 and l2, use Outer:

    In[1]:=  Outer[f, {a,b}, {x,y,z}]
    Out[1]:= {{f[a,x],f[a,y],f[a,z]}, {f[b,x],f[b,y],f[b,z]}}
    

    Outer by default works at the lowest level of the provided lists; you can also specify a level with an additional argument:

    In[2]:=  Outer[f, {{1, 2}, {3, 4}}, {{a, b}, {c, d}}, 1]
    Out[2]:= {{f[{1,2},{a,b}], f[{1,2},{c,d}]}, {f[{3,4},{a,b}], f[{3,4},{c,d}]}}
    

    Note that this produces a nested list; you can Flatten it if you like.

    My original answer pointed to Thread and MapThread, which are two ways to apply a function to corresponding pairs from lists, e.g. MapThread[f,{a,b},{1,2}] == {f[a,1], f[b,2]}.

    P.S. I think as you’re learning these things, you’ll find the documentation very helpful. There are a lot of general topic pages, for example, applying functions to lists and list manipulation. These are generally linked to in the “more about” section at the bottom of specific documentation. This makes it a lot easier to find things when you don’t know what they’ll be called.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say we have a method signature like public static function explodeDn($dn, array &$keys
Lets say I have several web sites on my web server, all as applications
Lets say I have two types of documents stored in my CouchDB database. First
So let's say I have two different functions. One is a part of the
Let's say you have a function that returns a date: Date myFunc(paramA, paramB){ //conditionally
Let's say we have a simple function defined in a pseudo language. List<Numbers> SortNumbers(List<Numbers>
Let's say I have the following function: sumAll :: [(Int,Int)] -> Int sumAll xs
Let's say we have the following method declaration: Public Function MyMethod(ByVal param1 As Integer,
Lets say I have a Dictionary object: Dictionary myDictionary<int, SomeObject> = new Dictionary<string, SomeObject>();
Lets say I have the following code: abstract class Animal case class Dog(name:String) extends

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.