       Re: Using a list as a variable

• To: mathgroup at smc.vnet.net
• Subject: [mg67096] Re: Using a list as a variable
• From: dh <dh at metrohm.ch>
• Date: Fri, 9 Jun 2006 01:08:00 -0400 (EDT)
• References: <e68qc9\$d2i\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```
Hi Bonny,

The domains that "Element" accepts are well defined (see manual) and do

not include Subsets[S].

You may have to iterate over the subsets e.g. using Scan.

Daniel

Bonny Banerjee wrote:

> I would like to use a list (or set) as a variable. I am working on the

> Subset-Sum problem. Given a set S of integers, the goal is to find a subset

> of S (say Q) whose elements add to a given integer x. This is how I would

> like to define the function:

>

> SubsetSum(S, x) := {Q such that Q is a subset of S and sum of the elements

> of Q is x}

>

> In Mathematica functional programming language, this would look like:

>

> SubsetSum[S_, x_] := Reduce[Q \[Element] Subsets[S] && Sum[Q,

> {i,1,Length[Q]}]==x, Q, Reals]

>

> Now when I try to evaluate SubsetSum[{1, 3, 5, 2, 7, 100, 6}, 101], the

> output is as follows:

>

> Reduce : : naqs :

>         \[Exists]{Q} Q is not a quantified system of equations and

> inequalities. More ...

>

> Out= Reduce[Q, False, Q, Reals]

>

>

> I guess, Mathematica is not being able to understand from my statement that

> the variable Q is not an atom but a list. But it should since I stated that

> Q is an element of the power set of S.

>

> Note that I know how to write a function for Subset-Sum using a Module. But

> I am interested in functional programming, similar to the format shown

> above.

>

> Any help would be appreciated.

>

> Thanks much,

> Bonny.

>

>

```

• Prev by Date: Re: Plot Sequencies of Complex Functions
• Next by Date: Re: Re: Re: Plot Sequencies of Complex Functions
• Previous by thread: Re: Using a list as a variable
• Next by thread: Re: Using a list as a variable