Projecting from a ProductSet

23 views
Skip to first unread message

Dan Synek

unread,
Feb 15, 2025, 2:55:30 AM2/15/25
to sympy
Here is a maximally simplified example of what I have been fighting with for days.
I would be grateful for any hints and since I am a relative beginner, sorry if I overlooked something obvious!

from sympy import *
x,y = symbols(" x y")
c = ProductSet(S.Naturals,S.Naturals)
i = ImageSet(Lambda((x,y),x**2), c)

It returns the error:
  raise ValueError('Incompatible signature')

Having reached desperation, I looked in the source code of fancysets.py
Its says:
 The transformation
    must be given as a Lambda function which has as many arguments
    as the elements of the set upon which it operates, e.g. 1 argument
    when acting on the set of integers or 2 arguments when acting on
    a complex region.

To me, if it should work for complex it should also work for a ProductSet. Am I doing something wrong? Is there another way that I can the the first projection from an element of a ProductSet? My first attempt was x[0], but since python has eager evaluation, it tries to take the first element of a symbol. Or is it not yet implemented, or is it a bug? I did check the development version, but it doesn't work there either.
Thanks for any help. Projecting out of a ProductSet seems like a common issue, so I am surprised that it doesn't work.

Aaron Meurer

unread,
Feb 15, 2025, 3:08:01 AM2/15/25
to sy...@googlegroups.com
I believe ImageSet(Lambda(((x,y),),x**2), c) should work

SymPy is very particular about tuple nesting with product sets. The
elements of ProductSet(x, y) are 2-tuples, so the image set needs to
accept a single argument that unpacks a 2-tuple.

Possibly ImageSet should be more lenient about this in cases where
it's unambiguous. It should definitely at least be better documented
and give a better error message.

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/sympy/c370c9f3-1a53-4743-ae5c-3f091e94abdfn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages