sympy/sympy — pull request #1632 by mrocklin (2012-10-31 18:24:18+00:00)
Title: Branching rules

This is a reinvention of the rules module where the rules are generators. It is intended to handle the case when a rule might produce multiple results. Everything is handled lazily.

```
def split_on_five(x):
if 0 < x < 5:
yield x-1
elif 5 < x < 10:
yield x+1
elif x == 5:
yield x+1
yield x-1
else:
yield x

rl = canon(split_on_five)
expr = Basic(2, Basic(5, 3), 8)

for result in rl(expr):
print result

Basic(0, Basic(0, 0), 10)
Basic(0, Basic(10, 0), 10)
```

I think that many of the functions could be improved a bit. Feedback is welcome.