sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.43k stars 479 forks source link

One-fold tensor products: fix repr and document the behavior #18349

Open 3f8450e1-87bf-41c6-ab53-29a0552debb3 opened 9 years ago

3f8450e1-87bf-41c6-ab53-29a0552debb3 commented 9 years ago

Hello every one,

sage: h = SymmetricFunctions(QQ).h()
sage: tensor([h]) # I assume that return h?
Symmetric Functions over Rational Field in the homogeneous basis
sage: h == tensor([h])
False

It must be a little mistake but I don't find the good category code where change that issue.

CC: @nthiery @tscrim @fchapoton

Component: categories

Keywords: tensor

Author: Jean-Baptiste Priez

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

3f8450e1-87bf-41c6-ab53-29a0552debb3 commented 9 years ago
comment:1

I suppose the bug is in sage.categories.covariant_functorial_construction.CovariantFunctorialConstruction.call but I don't understand what the code means.

nthiery commented 9 years ago
comment:2

Salut Jean-Baptiste,

h and tensor([h]) are indeed distinct, the latter being a (one-fold) tensor product:

    sage: h = SymmetricFunctions(QQ).h()
    sage: h1 = tensor([h])
    sage: type(h1)
    <class 'sage.combinat.free_module.CombinatorialFreeModule_Tensor_with_category'>

In particular, the basis is indexed by (singleton) tuples of partitions, instead of partitions:

    sage: h1.basis().keys().an_element()
    ([],)
    sage: h.basis().keys().an_element()
    []

Given that a one-fold tensor product of a single space V as above is trivially isomorphic to V, the above behavior may look disappointing at first. Yet making the distinction explicit is on purpose. The rationale is that this enables writing generic code in a uniform way when constructing the tensor product of a list of spaces; otherwise one would need to always special case the singleton list (btw: ideally, we would want to support the empty list as well).

Note that we have the same behavior for e.g. one-fold cartesian products:

    sage: p2 = cartesian_product([Partitions()])
    sage: p2
    The cartesian product of (Partitions,)
    sage: type(p2)
    <class 'sage.sets.cartesian_product.CartesianProduct_with_category'>
    sage: p2.an_element()
    ([],)

This being said, and unlike for cartesian products, the repr of one-fold tensor products, as currently returned by CombinatorialFreeModule_Tensor_with_category._repr_, is indeed very misleading. So I am requalifying this ticket to fix this. Thanks for reporting!

Would you have a suggestion for a good repr in this case?

We also probably want to highlight the above behavior in the documentation of tensor?.

Cheers, Nicolas

3f8450e1-87bf-41c6-ab53-29a0552debb3 commented 9 years ago
comment:4

Thanks, it seems clear to me now.

Replying to @nthiery:

Would you have a suggestion for a good repr in this case?

I don't have any opinion, may be:

sage: h = Sym(QQ).h()
sage: tensor([h])
Tensor:[Symmetric Functions over Rational Field in the homogeneous basis]

?

Replying to @nthiery:

We also probably want to highlight the above behavior in the documentation of tensor?.

May be...

In this way, I have an other stupid question, when we have a tensor product:

sage: S = NCSF(QQ).S()
sage: t = tensor([h, S])

There is a friendly way to recover h and S from t?

nthiery commented 9 years ago
comment:5

At the price of breaking encapsulation, you can do t._sets. There should be a method t.tensor_factors(). It's probably been implemented by Mark, typically in #15832.

mkoeppe commented 3 years ago
comment:7

Setting new milestone based on a cursory review of ticket status, priority, and last modification date.