Message Boards Message Boards

A better way to supply the elements of a list as arguments to a function ..

The built-in function BooleanFunction creates a function that accepts a specified number of arguments. There's some way(?), that is escaping me, to convert the elements of a list into a sequence of arguments.

Here's an example (and attached), using #[[1]] and #[[2]] to extract the elements of a list of length 2 ...

Create boolean function #1, of two variables ...

f = BooleanFunction[1, 2]

Display the function ...

BooleanConvert[f[x, y], "DNF"]

! x && ! y

Confirm on one pair of values ...

f[False, False]

True

Generate all boolean pairs ...

Tuples[{False, True}, 2]

{{False, False}, {False, True}, {True, False}, {True, True}}

Apply function to each pair using ugly method ...

f[#[[1]], #[[2]]] & /@ %

{True, False, False, False}

Attachments:
POSTED BY: Mark Tuttle
2 Replies

Yes, thank you!

Sequence @@

Is what I was trying to remember; I forgot it was a two-step thing - replace the head of the list with Sequence and then execute Sequence.

Couldn't get there using Help.

-- Mark

POSTED BY: Mark Tuttle

Could define a transition function that explicitly makes the list into a sequence.

f = BooleanFunction[1, 2];
tt = Tuples[{False, True}, 2];
f[#[[1]], #[[2]]] & /@ tt
g[ll_List] := f[Sequence @@ ll]
g /@ tt

{True, False, False, False}

{True, False, False, False}

{True, False, False, False}
POSTED BY: Daniel Lichtblau
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract