+def _all2list(x):
+ r"""
+ Flatten a vector, matrix, or cartesian product of those things
+ into a long list.
+ """
+ if hasattr(x, 'list'):
+ # Easy case...
+ return x.list()
+ if hasattr(x, 'cartesian_factors'):
+ # If it's a formal cartesian product space element, then
+ # we also know what to do...
+ return sum(( x_i.list() for x_i in x ), [])
+ else:
+ # But what if it's a tuple or something else?
+ return sum( map(_all2list,x), [] )
+