MathGroup Archive 2010

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

Search the Archive

Programmatically creating functions of many variables


Suppose I have a graph, and I'd like to create a function which checks
whether given assignment of nodes is a proper labeling -- ie, no two
adjacent nodes get the same number. One could do something like the
following, but that gives Part warnings. Is there a preferred
approach?

graph = GraphData[{"Grid", {2, 2}}, "AdjacencyMatrix"] // Normal;
f = Function @@ {{x}, And @@ (x[[First[#]]] != x[[Last[#]]] & /@
Position[graph, 1])}

This is actually a problem that I periodically come across. Part
approach causes warnings meanwhile something like Function @@
{Subscript[x,#]&/@Range[n], ...} doesn't work. What are typical ways
of generating multivariate functions automatically?

----
Yaroslav
http://stackoverflow.com/users/419116/yaroslav-bulatov


  • Prev by Date: Re: Balance point of a solid
  • Next by Date: FFT in mathematica
  • Previous by thread: help: how to fit a list of data in two dimensions with an equation in
  • Next by thread: Re: Programmatically creating functions of many variables