Help needed with UniqueRepresentation (of SymmetricFunctions)

90 views
Skip to first unread message

Martin R

unread,
Feb 5, 2024, 8:57:40 AM2/5/24
to sage-devel
At https://github.com/sagemath/sage/pull/37220 I am trying to provide a construction functor for symmetric functions. I am hitting the following bug, which I hope is easy to fix if one knows the right magic:

sage: P.<t> = QQ[]
sage: S = SymmetricFunctions(P)
sage: S.jack().P() == S.jack(t=t).P()
False

Can someone help me out?

Martin

Gareth Ma

unread,
Feb 5, 2024, 10:16:34 AM2/5/24
to sage-...@googlegroups.com
The following should show the problem:

sage: from sage.structure.unique_representation import UniqueRepresentation
....:
....: class A(UniqueRepresentation):
....:     def __init__(self, v=1):
....:         self.v = str(v)
....:
....: A() == A()
....: A() is A()
....: A() == A(1)
True
True
False


My understanding is that UniqueRepresentation wraps around the class constructor, such that it returns a unique object if the arguments are exactly the same. You see that in the second check, A() is A(). However, A() and A(1) have different arguments (one is empty, one is [1]), so they return distinct objects.

To fix this, I believe you just have to implement _eq_ or __eq__. For my example, add def __eq__(self, other): return self.v == other.v. (If I am incorrect, others please correct me!)

Gareth
--
You received this message because you are subscribed to the Google Groups "sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/5e221666-215b-4210-8bc4-15a3744ccb26n%40googlegroups.com.

Nils Bruin

unread,
Feb 5, 2024, 1:17:20 PM2/5/24
to sage-devel
I second that response. More specifically, what you're running into is:

sage: S.jack(t=t) == S.jack(t='t')
False

which is indeed within UniqueRepresentation design parameters: returned values are cached on construction parameters 't' and '"t"' hash to different values. If you need better processing, you'd need to normalize the input parameters further before calling the UniqueRepresentation constructor. In your case, I think jack.Jack (which is what ends up being called) actually does expect a string. Perhaps this keyword should be renamed to "names" to comply with uses elsewhere? e.g., would R.<t>=S.jack() make sense? If so, then the following should probably be made to work:

sage: preparse("R.<t>=S.jack()")
"R = S.jack(names=('t',)); (t,) = R._first_ngens(1)"

Martin R

unread,
Feb 6, 2024, 2:16:21 AM2/6/24
to sage-devel
Thank you for the explanation.

I would be very surprised about `R.<t>=S.jack()`, because the *coefficients* are (usually regarded as) rational functions in `t`, and the *monomials* are Jack symmetric functions.


class Jack(UniqueRepresentation):
    @staticmethod
    def __classcall__(cls, Sym, t='t'):
        return super().__classcall__(cls, Sym, Sym.base_ring()(t))
   
    def __init__(self, Sym, t):

I think I like it better.  Is there anything wrong with it?

Travis Scrimshaw

unread,
Feb 8, 2024, 8:29:49 PM2/8/24
to sage-devel
Martin's solution is the correct one as it should be preparsing the input before it gets to the __init__(), which is then used as the key. This also is needed for HallLittlewood and Macdonald.

Best,
Travis

PS - Sorry for not responding sooner about this.
Reply all
Reply to author
Forward
0 new messages