Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: Define function using lists or tables
Replies: 1   Last Post: Jul 3, 2013 6:06 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Nasser Abbasi

Posts: 5,694
Registered: 2/7/05
Re: Define function using lists or tables
Posted: Jul 3, 2013 6:06 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 7/3/2013 3:49 AM, Joaquim Nogueira wrote:
> Hello. Possibly this is a very simple question.
>
> Is there a way to define a function over a (BIG) list of ordered pairs? I mean,
>suppose that I have a list, created using a Table command or something like that,
>of the form [{a,b},{c,d},etc.] such that, after naming it f, say,
>f = [{a,b},{c,d},etc.], then, afterwards, whenever there is a command such
>that one needs to compute f[a] (or f[c]), the program immediately replaces f[a] by b,and f[c] by d?
>
> Thank you.
>


This looks like a hash table. In Mathematica, it is build in. All what
you have to do is:

--------------
f[a] = b;
f[c] = d;
-------------

Now

---------------------
In[294]:= f[a]
Out[294]= b
--------------------

There are more advanced ways to do this for more complicated setups.

google the subject of hash tables with mathematica for more information.

--Nasser




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.