# How to create and implement a small database on Mathematica?

I have a function

f[x_,y_,z_]:= a^x b^y c^z


and I want to evaluate it for various values of x,y,z always coming in triples. This means I have a database with columns x,y,z and rows vectors say A,B,C. (Sorry I could not write a Latex table here for some reason!)

How does one create such a table on Mathematica and then asks the function to directly compute 1) f[vector A] instead f[x,y,z] and 2) say the sum or product of vectors A,B, and C?

• E.g. f @@ {X, Y, Z} - see Apply – corey979 Jan 18 '18 at 17:01
• I believe you would be best served either with Dataset, which has a convenient (and I think optimized) Query syntax, or with Association, from which you can Lookup. That said, there are probably a dozen different ways to get this done. – b3m2a1 Jan 18 '18 at 17:06
• You can use \begin{bmatrix} ... \end{bmatrix} if you want to draw a table with mathjax. – anderstood Jan 18 '18 at 18:48
• The title mentions a database, and the answer below describes how to make a Dataset, but the question seems to be only about how to apply a function to a list of vectors. For this all you need is f @@@ {A,B,C}. Don't make a Dataset if you don't plan to use the querying functionality. – Jason B. Jan 19 '18 at 19:34

I recommend looking into Dataset.

Here is a test dataset:

data = Dataset@
Table[<|"x" -> RandomReal[], "y" -> RandomReal[],
"z" -> RandomReal[]|>, {i, 9}]


Then you can apply your function like this:

f[data[1, "x"], data[1, "y"], data[1, "z"]]


or shorter:

f @@ data[1]


Which applies your function to the first row (or row vector A in your question).

With a dataset you can use Total like this to get a sum per row:

data[1, Total]