Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2013

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

Search the Archive

Re: Define function using lists or tables

  • To: mathgroup at smc.vnet.net
  • Subject: [mg131427] Re: Define function using lists or tables
  • From: "Nasser M. Abbasi" <nma at 12000.org>
  • Date: Wed, 3 Jul 2013 22:04:42 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-outx@smc.vnet.net
  • Delivered-to: mathgroup-newsendx@smc.vnet.net
  • References: <kr0oij$3dv$1@smc.vnet.net>
  • Reply-to: nma at 12000.org

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



  • Prev by Date: Re: Animate Command and Vector Reference
  • Next by Date: Re: Calculating derivate in Mathematica 9 giving wrong result
  • Previous by thread: Re: Define function using lists or tables
  • Next by thread: Re: Define function using lists or tables