Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

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 want do something for all subsets J of a certain cardinality of {1,2,...,n}, for a (previously declared) number n. It seems magma is not happy with:

for J in PowerSet([1..n]) do

To which MAGMA responds:

for J in PowerSet([1..n]) do; ^ Runtime error in for: Iteration is not possible over this object

Is it really impossible to iterate over power sets? Or do I just need a small change? Any suggestions on how to solve this would be appreciated.

share|cite|improve this question
You want to use Subsets({1..n}) ... – martini Oct 5 '12 at 13:33
up vote 2 down vote accepted

To construct a set of all subsets of $\{1,\ldots,n\}$ of size $k$, use the command Subsets({1..n},k). You can iterate over this.

Example: go to and run for x in Subsets({1..4},2) do Random(x); end for;

share|cite|improve this answer

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.