Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pushout construction and finding common parents for/including cartesian products #18182

Closed
dkrenn opened this issue Apr 13, 2015 · 42 comments
Closed

Comments

@dkrenn
Copy link
Contributor

dkrenn commented Apr 13, 2015

sage: cartesian_product([ZZ]).construction() is None
True

and the coercion model (in partiuclar, the pushout function) does not take care of cartesian products. The aim of this ticket is to add functionality for doing so.

CC: @roed314 @behackl

Component: coercion

Keywords: sd67

Author: Daniel Krenn, David Roe

Branch/Commit: bc70cb9

Reviewer: Benjamin Hackl, Daniel Krenn

Issue created by migration from https://trac.sagemath.org/ticket/18182

@dkrenn dkrenn added this to the sage-6.6 milestone Apr 13, 2015
@nathanncohen
Copy link
Mannequin

nathanncohen mannequin commented Apr 14, 2015

comment:1

(see also #15425)

@roed314
Copy link
Contributor

roed314 commented Apr 14, 2015

Branch: u/roed/18182

@dkrenn
Copy link
Contributor Author

dkrenn commented Aug 20, 2015

Changed branch from u/roed/18182 to u/dkrenn/18182

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 20, 2015

Commit: 7f56908

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 20, 2015

Branch pushed to git repo; I updated commit sha1. New commits:

fe83e88update authors of pushout
7f56908fix links in docu

@dkrenn
Copy link
Contributor Author

dkrenn commented Aug 20, 2015

Author: Daniel Krenn, David Roe

@dkrenn
Copy link
Contributor Author

dkrenn commented Aug 20, 2015

Reviewer: Daniel Krenn

@dkrenn
Copy link
Contributor Author

dkrenn commented Aug 20, 2015

comment:5

I've reviewed David's part, but I am also an author of this ticket; thus I request an additional reviewer.

Note that there is still one failing doctest, where I don't have any glue why (it is the bug at the very top of the file). Who knows what is going on there?

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 20, 2015

Branch pushed to git repo; I updated commit sha1. New commits:

f55cf6bMerge tag '6.8' into u/dkrenn/18182

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 20, 2015

Changed commit from 7f56908 to f55cf6b

@dkrenn
Copy link
Contributor Author

dkrenn commented Aug 20, 2015

Changed branch from u/dkrenn/18182 to u/dkrenn/18182-on-6.7

@dkrenn
Copy link
Contributor Author

dkrenn commented Aug 20, 2015

Changed commit from f55cf6b to 7f56908

@dkrenn
Copy link
Contributor Author

dkrenn commented Aug 20, 2015

Work Issues: merge 6.8

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 20, 2015

Changed commit from 7f56908 to cbb0d83

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 20, 2015

Branch pushed to git repo; I updated commit sha1. New commits:

cbb0d83Merge tag '6.8' into u/dkrenn/18182

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 20, 2015

Changed commit from cbb0d83 to 7f56908

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 20, 2015

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

@dkrenn
Copy link
Contributor Author

dkrenn commented Aug 20, 2015

New commits:

cbb0d83Merge tag '6.8' into u/dkrenn/18182

@dkrenn
Copy link
Contributor Author

dkrenn commented Aug 20, 2015

Changed branch from u/dkrenn/18182-on-6.7 to u/dkrenn/18182-on-6.8

@dkrenn
Copy link
Contributor Author

dkrenn commented Aug 20, 2015

Changed commit from 7f56908 to cbb0d83

@dkrenn
Copy link
Contributor Author

dkrenn commented Aug 20, 2015

Changed work issues from merge 6.8 to none

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 23, 2015

Branch pushed to git repo; I updated commit sha1. New commits:

3cacc52change recursive pushout to common_parent (to take care of direct coercions)
4662eedbug kind of solved (called now directly by cartesian_product); move doctest
ce20dd9Merge remote-tracking branch 'origin/u/dkrenn/18182-on-6.7' into u/dkrenn/18182-on-6.8
23354dbadd missing test and fix broken tests
2de49baMerge remote-tracking branch 'origin/u/dkrenn/18182-on-6.7' into u/dkrenn/18182-on-6.8

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 23, 2015

Changed commit from cbb0d83 to 2de49ba

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 16, 2015

Branch pushed to git repo; I updated commit sha1. New commits:

c16587cfix bug (tower has only one entry which is None)

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 16, 2015

Changed commit from 60b9375 to c16587c

@dkrenn
Copy link
Contributor Author

dkrenn commented Sep 16, 2015

comment:19

Bug fixed...let's see what the patchbot does...

@behackl
Copy link
Member

behackl commented Oct 4, 2015

comment:20

Hello!

I had a look at the changes on this ticket, made a few reviewer commits, and I have the following comments:

  1. categories.modules.CartesianProducts: I'm not entirely sure about how everything is handled here:

    • ParentMethods.base_ring: It seems as if the base ring of the cartesian product of some modules is considered to be the base ring of the first module in the list. Is this intended?
    • Should different base rings of the modules in a cartesian product be allowed? If so, this has to be fixed:
      sage: E = CombinatorialFreeModule(ZZ, [1,2])
      sage: F = CombinatorialFreeModule(QQ, ['a', 'b'])
      sage: cartesian_product([E, F])
      Traceback (most recent call last):
      ...
      AttributeError: 'CommutativeAdditiveGroups.CartesianProducts_with_c' object has no attribute 'FiniteDimensional'
    
    • Otherwise, if this should not be supported, the error message should be replaced by something more meaningful.

Note that fixing these things would be suitable for a follow-up ticket, as the current behavior is (as far as I can tell) correct: if the base rings of the modules coincide, the cartesian product can be built (at least in the examples I tried). Otherwise, a (unfortunately rather strange) exception is raised. And in the case where all base rings coincide, base_ring can of course return the base ring of any of the passed modules.

  1. categories.pushout.ConstructionFunctor.common_base: I think that Raise a CoercionException does not fit in a OUTPUT-block from a semantic point of view.

  2. categories.pushout.MultivariateConstructionFunctor: Is there a reason for the import of CartesianProduct in the TESTS-block? (I've removed the import in one of my commits.)

  3. MultivariateConstructionFunctor.common_base: Could you explain why you use get_coercion_model().common_parent(...) instead of pushout(...)?

  4. pushout: Is there a reason for using

  sage: from sage.sets.cartesian_product import CartesianProduct
  sage: A = CartesianProduct((ZZ['x'], QQ['y'], QQ['z']), Sets().CartesianProducts())

over

  sage: A = cartesian_product((ZZ['x'], QQ['y'], QQ['z']))

As far as I can tell, the only difference is in the categories -- but they aren't used in these doctests.

  1. pushout: Am I right in the assumption that the reason for the check .. and R_tower[-1][0] is not None is that when considering, for example
  sage: from sage.categories.pushout import pushout
  sage: pushout(ZZ, cartesian_product([ZZ, QQ]))
  Traceback (most recent call last):
  ...
  CoercionException: 'NoneType' object is not iterable

that a CoercionException is thrown (instead of an AttributeError for the failed call to R_tower[-1][0].common_base(...) in the line after the check)? Or is there more to it? Would it make sense to add a doctest for this exact case? (I've included one in my reviewer commits; proceed with it as you like.)

  1. pushout: CartesianProductPolys vs. CartesianProductPoly? (cf. cartesian products with orders #18223 ;-)).

Benjamin


New commits:

5c29fd4fix typos
6233426improve language
d31667efix ReSt-error
c4a5bfdremove superfluous import in doctest, superfluous empty line in docstring, and fix spacing in a line (pep 8)
726b74aCartesianProductPolys: check whether other has a construction
d449fabadd two doctests

@behackl
Copy link
Member

behackl commented Oct 4, 2015

Changed reviewer from Daniel Krenn to Benjamin Hackl, Daniel Krenn

@behackl
Copy link
Member

behackl commented Oct 4, 2015

Changed commit from c16587c to d449fab

@behackl
Copy link
Member

behackl commented Oct 4, 2015

Changed branch from u/dkrenn/18182/pushout to u/behackl/coercion/pushout

@dkrenn
Copy link
Contributor Author

dkrenn commented Oct 8, 2015

comment:21

Replying to @behackl:

  1. categories.modules.CartesianProducts: I'm not entirely sure about how everything is handled here:

    • ParentMethods.base_ring: It seems as if the base ring of the cartesian product of some modules is considered to be the base ring of the first module in the list. Is this intended?
    • Should different base rings of the modules in a cartesian product be allowed? If so, this has to be fixed:
      sage: E = CombinatorialFreeModule(ZZ, [1,2])
      sage: F = CombinatorialFreeModule(QQ, ['a', 'b'])
      sage: cartesian_product([E, F])
      Traceback (most recent call last):
      ...
      AttributeError: 'CommutativeAdditiveGroups.CartesianProducts_with_c' object has no attribute 'FiniteDimensional'
    
    • Otherwise, if this should not be supported, the error message should be replaced by something more meaningful.

Note that fixing these things would be suitable for a follow-up ticket, as the current behavior is (as far as I can tell) correct: if the base rings of the modules coincide, the cartesian product can be built (at least in the examples I tried). Otherwise, a (unfortunately rather strange) exception is raised. And in the case where all base rings coincide, base_ring can of course return the base ring of any of the passed modules.

This is now #19375.

  1. categories.pushout.ConstructionFunctor.common_base: I think that Raise a CoercionException does not fit in a OUTPUT-block from a semantic point of view.

Rewritten (but I am open to suggestions if you want something different)

  1. categories.pushout.MultivariateConstructionFunctor: Is there a reason for the import of CartesianProduct in the TESTS-block? (I've removed the import in one of my commits.)

Thanks.

  1. MultivariateConstructionFunctor.common_base: Could you explain why you use get_coercion_model().common_parent(...) instead of pushout(...)?

We need a common parent, thus common_parent is the correct method to call. A pushout is one possible way to construct a common parent, but there are other ways; e.g. one could coerce into the other, or there is a scalar multiplication or action available.

  1. pushout: Is there a reason for using
  sage: from sage.sets.cartesian_product import CartesianProduct
  sage: A = CartesianProduct((ZZ['x'], QQ['y'], QQ['z']), Sets().CartesianProducts())

over

  sage: A = cartesian_product((ZZ['x'], QQ['y'], QQ['z']))

As far as I can tell, the only difference is in the categories -- but they aren't used in these doctests.

This is to check that it works as well (there was once a bug with this kind of construction, thus a doctest was added).

  1. pushout: Am I right in the assumption that the reason for the check .. and R_tower[-1][0] is not None is that when considering, for example
  sage: from sage.categories.pushout import pushout
  sage: pushout(ZZ, cartesian_product([ZZ, QQ]))
  Traceback (most recent call last):
  ...
  CoercionException: 'NoneType' object is not iterable

that a CoercionException is thrown (instead of an AttributeError for the failed call to R_tower[-1][0].common_base(...) in the line after the check)?

Yes, this is the reason. An AttributeError does not work with some of the calling functions; they need a CoercionException`.

Or is there more to it?

No.

Would it make sense to add a doctest for this exact case? (I've included one in my reviewer commits; proceed with it as you like.)

Thanks.

  1. pushout: CartesianProductPolys vs. CartesianProductPoly? (cf. cartesian products with orders #18223 ;-)).

Done.

Cross-reviewed your changes...seem to be fine.

@dkrenn
Copy link
Contributor Author

dkrenn commented Oct 8, 2015

Changed branch from u/behackl/coercion/pushout to u/dkrenn/coercion/pushout

@dkrenn
Copy link
Contributor Author

dkrenn commented Oct 8, 2015

New commits:

4619fe7Trac #18182, comment 20, 2: rewrite OUTPUT-block
bc70cb9Trac #18182, comment 20, 7: rename CartesianProductPolys --> CartesianProductPoly

@dkrenn
Copy link
Contributor Author

dkrenn commented Oct 8, 2015

Changed commit from d449fab to bc70cb9

@behackl
Copy link
Member

behackl commented Oct 13, 2015

comment:24

Replying to @dkrenn:

  1. categories.modules.CartesianProducts: I'm not entirely sure [...]

This is now #19375.

Perfect.

  1. categories.pushout.ConstructionFunctor.common_base: I think that Raise a CoercionException does not fit in a OUTPUT-block from a semantic point of view.

Rewritten (but I am open to suggestions if you want something different)

No, the way you've rewritten it is fine.

  1. MultivariateConstructionFunctor.common_base: Could you explain why you use get_coercion_model().common_parent(...) instead of pushout(...)?

We need a common parent, thus common_parent is the correct method to call. A pushout is one possible way to construct a common parent, but there are other ways; e.g. one could coerce into the other, or there is a scalar multiplication or action available.

I understand.

  1. pushout: Is there a reason for using
  sage: from sage.sets.cartesian_product import CartesianProduct
  sage: A = CartesianProduct((ZZ['x'], QQ['y'], QQ['z']), Sets().CartesianProducts())

over

  sage: A = cartesian_product((ZZ['x'], QQ['y'], QQ['z']))

As far as I can tell, the only difference is in the categories -- but they aren't used in these doctests.

This is to check that it works as well (there was once a bug with this kind of construction, thus a doctest was added).

Alright.

I cross-checked your changes, everything seems to work now, and I have no more comments.

The documentation builds and make ptestlong passes. --> positive_review.

@vbraun
Copy link
Member

vbraun commented Oct 14, 2015

Changed branch from u/dkrenn/coercion/pushout to bc70cb9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants