Comment #1 on issue 2430 by christian.muise: Expression Countable Set
http://code.google.com/p/sympy/issues/detail?id=2430

Why not use lambda's to make up a set's behaviour? If it's countable, then there should be a mapping from the ints to an element in the set and vice versa. A lambda can be passed in that checks whether or not a number qualifies. Using the set of even numbers as an example:

```python
even_numbers = CountableSet(lambda x: 0 == x % 2)
```

Internally, the check_membership function is set to be the passed in lambda function. Then you could do set intersection (a new lambda that checks both lambdas in the intersection), union (a new lambda that checks at least one lambda in the union), etc.

Additionally, you could accept an optional second argument that is a function to yield elements in the set given an integer:

```python
even_numbers = CountableSet(lambda x: 0 == x % 2, generator_func = lambda x: 2*x)
```

If you are only concerned with sets that contain ints, you can have a default generator_func that just iterates through integers until one passes the test (inefficient, but gets the job done).

--
You received this message because you are subscribed to the Google Groups 
"sympy-issues" group.
To post to this group, send email to sympy-issues@googlegroups.com.
To unsubscribe from this group, send email to 
sympy-issues+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sympy-issues?hl=en.

Reply via email to