Ask Your Question
1

selector behavior difference , Combinations or Arrangements list

asked 2020-06-07 08:39:52 +0100

ortollj gravatar image

updated 2020-06-08 09:18:32 +0100

HI

I opened this question first then I deleted it after a while now I re-open it because finally I do not know if its a pb or not!. sorry for my versatile behavior

Ubuntu 18.04 , SageMath 9.0 notebook

why if I uncoment line 3 of the code below, I get TraitError: Invalid selection: value not found. but code is ok if line 3 commented

anIndexL=[1..5]
anCoupleIndexL=Arrangements(anIndexL,2).list()
#anCoupleIndexL=Combinations(anIndexL,2).list()
show(anCoupleIndexL)

@interact
def _( nbStepMax=slider(1,20,1,default=20),anCouple = selector(anCoupleIndexL,default=anCoupleIndexL[0])):
    show(anCouple)

Arrangements return object parent is ๐™ฐ๐š›๐š›๐šŠ๐š—๐š๐šŽ๐š–๐šŽ๐š—๐š๐šœ ๐š˜๐š ๐š๐š‘๐šŽ ๐šœ๐šŽ๐š[๐Ÿท,๐Ÿธ,๐Ÿน,๐Ÿบ,๐Ÿป] ๐š˜๐š ๐š•๐šŽ๐š—๐š๐š๐š‘ ๐Ÿธ

As Combinations return object is a simple list.

anIndexL=[1..5]
anCoupleIndexL0=Arrangements(anIndexL,2).list()
anCoupleIndexL1=Combinations(anIndexL,2).list()
anCoupleIndexStrL0=[]
print("test parent couple for anCoupleIndexL0")

for an in anCoupleIndexL0 :
    anT=[]
    for e in an :
        show(e.parent())
    show(an.parent())
    anCoupleIndexStrL0.append(anT)

anCoupleIndexStrL1=[]
print("test parent couple for anCoupleIndexL1")
for an in anCoupleIndexL1 :
    anT=[]
    for e in an :
        show(e.parent())
    show(an.parent())
    anCoupleIndexStrL1.append(anT)
edit retag flag offensive close merge delete

Comments

strange if I not put default value, then the displayed choices are integers, not Integers couples. (if uncommented line 3)

ortollj gravatar imageortollj ( 2020-06-07 09:13:15 +0100 )edit

finally I did a wobbly (horrible ! ;-) ) workaround:

anIndexL=[1..5]
anCoupleIndexL0=Arrangements(anIndexL,2).list()
anCoupleIndexL1=Combinations(anIndexL,2).list()

anCoupleIndexL11=[]
print("change couple parent for anCoupleIndexL1")
for an in anCoupleIndexL1 :
        anCoupleIndexL11.append(Arrangements(an,2).list()[0])

show(anCoupleIndexL0)
show(anCoupleIndexL1)
show(anCoupleIndexL11)

@interact
def _( nbStepMax=slider(1,20,1,default=20),anCouple = selector(anCoupleIndexL11,default=anCoupleIndexL11[0])):
    show(anCouple)
ortollj gravatar imageortollj ( 2020-06-08 10:05:28 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-06-08 11:34:21 +0100

rburing gravatar image

From the documentation of selector:

Apart from a simple list, "values" can be given as a list of 2-tuples "(value, label)"

SageMath interprets your input list like this, and as a consequence it can't find the default value.

So for Combinations you have to do the following:

anIndexL=[1..5]
anCoupleIndexL=[(v,str(v)) for v in Combinations(anIndexL,2)]

@interact
def _( nbStepMax=slider(1,20,1,default=20),anCouple = selector(anCoupleIndexL,default=anCoupleIndexL[0][0])):
    show(anCouple)
edit flag offensive delete link more

Comments

Thanks @rburing

ortollj gravatar imageortollj ( 2020-06-08 13:18:19 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2020-06-07 08:39:52 +0100

Seen: 192 times

Last updated: Jun 08 '20