Dear Andrzej,

First of all I feel really sorry that some simple examples from your book are not supported anymore. To prevent such annoying thing in the future, you could write all the doctests in a file and include them in the dedicated repository "/tests/" of the Sage source code. Any changes in Sage that break some of your doctest will immediately alert the responsible programmer.

For concreteness, there was some recent changes in cartesian product. Mainly

http://trac.sagemath.org/ticket/18411

It cleans up a lot of things but at the same time is not fully compatible anymore with old style parents (such as Combinations). In order to solve it, the simplest would be to make Combinations a new style parent and I created the following ticket for that purpose

http://trac.sagemath.org/ticket/19986

Best,
Vincent


On 30/01/16 09:07, Andrzej Giniewicz wrote:
Hello,

in earlier versions of sage this worked:

Omega = Combinations([1, 2, 3, 4, 5, 6], 4)

A1 = Combinations([1], 1)
A2 = Combinations([2, 3, 4, 5, 6], 3)

A = CartesianProduct(A1, A2)

A.cardinality() / Omega.cardinality()

which we used in book for high school students to illustrate basic
probability examples. Now this fails with assertion error (and no
explanation attached). Digging deeper gives:

   File 
"/usr/local/sage/sage-7.0/local/lib/python2.7/site-packages/sage/combinat/cartesian_product.py",
line 102, in CartesianProduct
     return cartesian_product(iters)
   File 
"/usr/local/sage/sage-7.0/local/lib/python2.7/site-packages/sage/categories/cartesian_product.py",
line 174, in __call__
     return super(CartesianProductFunctor, self).__call__(args, **kwds)
   File 
"/usr/local/sage/sage-7.0/local/lib/python2.7/site-packages/sage/categories/covariant_functorial_construction.py",
line 221, in __call__
     assert(all( hasattr(arg, self._functor_name) for arg in args))
AssertionError

Simply making A1 and A2 list fails as well, because Combinations
iterates over lists, so list(A1) is list of lists.

TypeError: unhashable type: 'list'

Easiest way I found around this is:

A = cartesian_product([[tuple(a1) for a1 in A1], [tuple(a2) for a2 in A2]])

there is a LOT of syntax noise compared to simply:

A = CartesianProduct(A1, A2)

And the meaning is slightly different (in A there are tuples, in Omega
there are lists, so we are not comparing same objects).

Is there any simpler way to product output of Combinations? Limiting
syntax noise is very important for making mathematical packages
approachable to young students, and this change is definiately not
along the lines. Also, it is important that most use cases are with
same syntax, so if we have

A1 = [1,2,3]
A2 = [4,5,6]
A = cartesian_product([A1, A2])

it would be good if the syntax was same for Combinations and other objects.

Is the current behaviour designed or bug?

Regards,
Andrzej.


--
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

Reply via email to