Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Can I show ordered sets in order?

I'm using SageTex to generate random algebra tests, with an answer key at the end. To have my students show they understand roster notation for sets, I'm having them write the set of all two-digit multiples of n for some number n in {2, 3, 4, ... 9}. Asking the question isn't hard. But in generating the answer key, the set shows up in random order. I know it's still the same set, of course, but it's less intuitive to interpret. It seems like Sage is going out of it's way to randomize the set. Here's some minimal working code:

n = Set(range(2, 10)).random_element()
X = Set()
for i in range(10, 100):
    if i % n == 0:
        X = X.union(Set([i]))
show(n)
show(X)

This shows, for example:

8

{32, 64, 48, 40, 80, 96, 16, 24, 56, 72, 88}

Is there some way to have Sage show the elements of the set in order?