Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am very new to Mathematica, and need to know how to plug values into existing functions. For example, Math World supplies the following code for building a truth table of n levels of operator op:

TruthTable[op_, n_] := 
Module[{l = 
 Flatten[Outer[List, Sequence @@ Table[{True, False}, {n}]], 
  n - 1], a = Array[A, n]}, 
GridBox[Prepend[Append[#, op @@ #] & /@ l, Append[a, op @@ a]], 
 RowLines -> True, ColumnLines -> True]]]

How do I set the operator and the value of n?

share|improve this question
You've seen BooleanTable[] already? – J. M. Oct 27 '12 at 7:39
You say "Mathematica supplies the following code for building a truth table of n levels of operator op". It it not known to my copy of Mathematica. I found it on Math World, which is not same as "supplied by Mathematica". – m_goldberg Oct 27 '12 at 7:44
@J.M. I have seen BooleanTable[] and the related functions and did not have problems with those--I'm only unsure about the notation used above. – QuietThud Oct 27 '12 at 7:53
@m_goldberg: I meant "supplied by Wolfram". – QuietThud Oct 27 '12 at 7:55
up vote 4 down vote accepted

Here is some results of my trying out this function on my copy of Mathematica:

notebook selection

share|improve this answer
I see you've used an '@' in your definition of the op--is this a standard way of avoiding nested parentheses? Also, can you tell me about the use of the '&' at the end of the definition? – QuietThud Oct 27 '12 at 8:23
@Quiet, @ is a prefix method of applying a function; that is, f @ x and f[x] are the same thing. There's a postfix version, x // f. &, on the other hand, is shorthand for the Function[] construct, which allows you to use pure functions. Look at the docs for Function[] for more detail on this. – J. M. Oct 27 '12 at 8:28
@J.M: Thanks a lot, that's very helpful.=) – QuietThud Oct 28 '12 at 5:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.