Ask Your Question
1

An algorithm on root systems' vectors "ValueError: too many values to unpack "

asked 2020-08-19 14:51:42 +0100

SarahDi gravatar image

updated 2020-09-24 23:10:51 +0100

slelievre gravatar image

While finishing a math project, I need to run the following code, and get an error message which seems related to Sage calculation capacity, could anyone help me through this? (I am quite new to Sage.) If there is no way to handle that in Sage, could anyone recommend me another software with similar language where this code could be run properly?

e = RootSystem(['E', 6]).ambient_space()
Roots = e.roots()
a1 = vector((1/2, -1/2, -1/2, -1/2, -1/2, -1/2, -1/2, 1/2))
a2 = vector((1, 1, 0, 0, 0, 0, 0, 0))
a3 = vector((-1, 1, 0, 0, 0, 0, 0, 0))  
a4 = vector((0, -1, 1, 0, 0, 0, 0, 0))
a5 = vector((0, 0, -1, 1, 0, 0, 0, 0)) 
a6 = vector((0, 0, 0, -1, 1, 0, 0, 0))
Lini = [a1, a2, a3, a4, a5]

def proj(t, ai):
    myLone = vector(ai)
    result= t - myLone.dot_product(t) / (ai.dot_product(ai))*myLone
    return result

myP = [proj(x, a6) for x in Lini]
[proja1, proja2, proja3, proja4, proja5] = myP
myR = [vector(v) for v in Roots]
myL = [proj(x, a6) for x in myR]

len(myL)

myPlist1= Combinations(myP, 3).list()
myLlist1= Combinations(myL, 2).list()

# alternatively: produce all combinaisons in myL of five vectors
# (all to be used in a function where these combinaisons are variables:
# this does not work either

# myLlist = Combinations(myL, 5).list()

def letsapply(listg, alist):
    for listel in listg:
        myPset1= set(tuple(v) for v in listel)
        print(myPset1)
    for listel2 in alist:
        myLset1 = set(tuple(v) for v in listel2)
        print(myLset1)
        myLset1 = myLset1.union(myPset1)

        if len(myLset1) >= 5:
            print(myLset1, "myLset1")

        if len(myLset1) >= 5:
            for myLel in myLset1:
                [proja1, proja2, proja3, proja4, proja5] = myLel
                print(myLel)

print(letsapply(myPlist1, myLlist1))
edit retag flag offensive close merge delete

Comments

1

Beware about the indentation. If you need nested loops, you should indent the inner loop more than the outer loop.

FrédéricC gravatar imageFrédéricC ( 2020-08-19 18:13:05 +0100 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2020-08-19 16:00:54 +0100

tmonteil gravatar image

As i can see, the elements of myLset1 are vectors of length 8, so when you loop for myLel in myLset1:, each myLel is a vector of length 8, so you can not write [proja1, proja2, proja3, proja4, proja5] = myLel.

If you want to pick the 5 first coordinates of myLel, you can use a slice: [proja1, proja2, proja3, proja4, proja5] = myLel[:5]

That said, note that proja1, proja2, ... are not used elsewhere in the function.

edit flag offensive delete link more

Comments

1

Yes, my bad, I wanted :

if len(myLset1) >= 5: [proja1, proja2, proja3, proja4, proja5] = myLset1 Thanks!

SarahDi gravatar imageSarahDi ( 2020-08-19 20:31:16 +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

Stats

Asked: 2020-08-19 14:51:42 +0100

Seen: 339 times

Last updated: Sep 24 '20