Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Pb with headers in table()

I have a problem with the following function :

# Borda(cand=["A","B","C","D"],ne=[18,16,14,12,11,20,19,14,16,12,2,1,0,0,20,16,13,15,11,10,9,8,7,5],cond=0)
# cond = 0 redonne la répartition des préférences
# cond = 1 donne le classement des candidats sur chaque type de préférences
# cond = 2 donne les scores sur chaque candidat
# cond = 2 donne l'accumulation des scores sur chaque candidat
# cond = 3 déclare le vainqueur au sens de Borda.
def Borda(cand=["A","B","C","D"],ne=[18,16,14,12,11,20,19,14,16,12,2,1,0,0,20,16,13,15,11,10,9,8,7,5],cond=0) :
    Ap=All_pref(cand,2) 
    cond1=['$\\tiny${}{}{}{}$'.format(*w) for w in Ap]
    cond2 =[""]+ [r'${}$'.format(*w) for w in cand]
    cond3 =[r'${}$'.format(*w) for w in cand]
    t1=table([ne])#,header_row=cond1)
    rank=[[x.find(l) for x in Ap] for l in cand] 
    score_de_Borda=[[abs(x.find(l)-len(cand)) for x in Ap] for l in cand]
    t2=table(rank)#,header_row=cond1,header_column=cond2)
    total_score_de_Borda=[add([score_de_Borda[j][i]*ne[i] for i in range(24)]) for j in range(len(cand))]
    t3=table(score_de_Borda)#,header_column=cond3)
    max_total_score_de_Borda=max(total_score_de_Borda)
    ind_max_total_score_de_Borda=total_score_de_Borda.index(max_total_score_de_Borda)
    vainqueur_de_Borda=cand[ind_max_total_score_de_Borda] 
    if cond==0 :
        return t1
    if cond==1 :
        return t2
    if cond==2 :
        return t3
    if cond==3 :
        return total_score_de_Borda
    if cond==4 :
        return vainqueur_de_Borda

and here is a call to the different variations.

show(LatexExpr(r"\text{Le tableau des rangs est :}"))
show(Borda(["A","B","C","D"],[18,16,14,12,11,20,19,14,16,12,2,1,0,0,20,16,13,15,11,10,9,8,7,5],1))
show(LatexExpr(r"\text{Le tableau des scores est :}"))
show(Borda(["A","B","C","D"],[18,16,14,12,11,20,19,14,16,12,2,1,0,0,20,16,13,15,11,10,9,8,7,5],2))
show(LatexExpr(r"\text{Les scores totaux de chaque candidat sont :}"))
Borda(["A","B","C","D"],[18,16,14,12,11,20,19,14,16,12,2,1,0,0,20,16,13,15,11,10,9,8,7,5],3)
show(LatexExpr(r"\text{Le vainqueur d'un décompte à la Borda est : }"),
Borda(["A","B","C","D"],[18,16,14,12,11,20,19,14,16,12,2,1,0,0,20,16,13,15,11,10,9,8,7,5],4),LatexExpr(r"."))

All is fine but if inside the function i remove the# and allow the header(s), I have an error which I do not understand since some time it works and some time not. (I am working with sagemath 9.2 under windows).

Pb with headers in table()

Here is the forgotten function which list all the preferences on a list of candidates

def All_pref(cand=["A","B","C","D"],code=1) :
    ncand=len(cand)
    Scand=sorted(Set(cand))
    all_pref=Arrangements(Scand,ncand).list()
    all_pref1=[str(Word(x)) for x in all_pref]
    if code==1 :
        return ncand
    if code==2 :
        return all_pref1

I have a problem with the following function :

# Borda(cand=["A","B","C","D"],ne=[18,16,14,12,11,20,19,14,16,12,2,1,0,0,20,16,13,15,11,10,9,8,7,5],cond=0) # cond = 0 redonne la répartition des préférences # cond = 1 donne le classement des candidats sur chaque type de préférences # cond = 2 donne les scores sur chaque candidat # cond = 2 donne l'accumulation des scores sur chaque candidat # cond = 3 déclare le vainqueur au sens de Borda. def Borda(cand=["A","B","C","D"],ne=[18,16,14,12,11,20,19,14,16,12,2,1,0,0,20,16,13,15,11,10,9,8,7,5],cond=0) : Ap=All_pref(cand,2) cond1=['$\\tiny${}{}{}{}$'.format(*w) cond1=['$\tiny${}{}{}{}$'.format(w) for w in Ap] cond2 =[""]+ [r'${}$'.format(*w) [r'${}$'.format(w) for w in cand] cond3 =[r'${}$'.format(*w) =[r'${}$'.format(w) for w in cand] t1=table([ne])#,header_row=cond1) rank=[[x.find(l) for x in Ap] for l in cand] score_de_Borda=[[abs(x.find(l)-len(cand)) for x in Ap] for l in cand] t2=table(rank)#,header_row=cond1,header_column=cond2) total_score_de_Borda=[add([score_de_Borda[j][i]*ne[i] total_score_de_Borda=[add([score_de_Borda[j][i]ne[i] for i in range(24)]) for j in range(len(cand))] t3=table(score_de_Borda)#,header_column=cond3) max_total_score_de_Borda=max(total_score_de_Borda) ind_max_total_score_de_Borda=total_score_de_Borda.index(max_total_score_de_Borda) vainqueur_de_Borda=cand[ind_max_total_score_de_Borda] if cond==0 : return t1 if cond==1 : return t2 if cond==2 : return t3 if cond==3 : return total_score_de_Borda if cond==4 : return vainqueur_de_Borda

return vainqueur_de_Borda

and here is a call to the different variations.

show(LatexExpr(r"\text{Le tableau des rangs est :}"))
show(Borda(["A","B","C","D"],[18,16,14,12,11,20,19,14,16,12,2,1,0,0,20,16,13,15,11,10,9,8,7,5],1))
show(LatexExpr(r"\text{Le tableau des scores est :}"))
show(Borda(["A","B","C","D"],[18,16,14,12,11,20,19,14,16,12,2,1,0,0,20,16,13,15,11,10,9,8,7,5],2))
show(LatexExpr(r"\text{Les scores totaux de chaque candidat sont :}"))
Borda(["A","B","C","D"],[18,16,14,12,11,20,19,14,16,12,2,1,0,0,20,16,13,15,11,10,9,8,7,5],3)
show(LatexExpr(r"\text{Le vainqueur d'un décompte à la Borda est : }"),
Borda(["A","B","C","D"],[18,16,14,12,11,20,19,14,16,12,2,1,0,0,20,16,13,15,11,10,9,8,7,5],4),LatexExpr(r"."))

All is fine but if inside the function i remove the# and allow the header(s), I have an error which I do not understand since some time it works and some time not. (I am working with sagemath 9.2 under windows).

Pb with headers in table()

Here is the forgotten function which list all the preferences on a list of candidates

def All_pref(cand=["A","B","C","D"],code=1) :
    ncand=len(cand)
    Scand=sorted(Set(cand))
    all_pref=Arrangements(Scand,ncand).list()
    all_pref1=[str(Word(x)) for x in all_pref]
    if code==1 :
        return ncand
    if code==2 :
        return all_pref1

I have a problem with the following function :

# Borda(cand=["A","B","C","D"],ne=[18,16,14,12,11,20,19,14,16,12,2,1,0,0,20,16,13,15,11,10,9,8,7,5],cond=0) # cond = 0 redonne la répartition des préférences # cond = 1 donne le classement des candidats sur chaque type de préférences # cond = 2 donne les scores sur chaque candidat # cond = 2 donne l'accumulation des scores sur chaque candidat # cond = 3 déclare le vainqueur au sens de Borda. def Borda(cand=["A","B","C","D"],ne=[18,16,14,12,11,20,19,14,16,12,2,1,0,0,20,16,13,15,11,10,9,8,7,5],cond=0) : Ap=All_pref(cand,2) cond1=['$\tiny${}{}{}{}$'.format(w) for w in Ap] cond2 =[""]+ [r'${}$'.format(w) for w in cand] cond3 =[r'${}$'.format(w) for w in cand] t1=table([ne])#,header_row=cond1) rank=[[x.find(l) for x in Ap] for l in cand] score_de_Borda=[[abs(x.find(l)-len(cand)) for x in Ap] for l in cand] t2=table(rank)#,header_row=cond1,header_column=cond2) total_score_de_Borda=[add([score_de_Borda[j][i]ne[i] for i in range(24)]) for j in range(len(cand))] t3=table(score_de_Borda)#,header_column=cond3) max_total_score_de_Borda=max(total_score_de_Borda) ind_max_total_score_de_Borda=total_score_de_Borda.index(max_total_score_de_Borda) vainqueur_de_Borda=cand[ind_max_total_score_de_Borda] if cond==0 : return t1 if cond==1 : return t2 if cond==2 : return t3 if cond==3 : return total_score_de_Borda if cond==4 : return vainqueur_de_Borda

and here is a call to the different variations.

show(LatexExpr(r"\text{Le tableau des rangs est :}"))
show(Borda(["A","B","C","D"],[18,16,14,12,11,20,19,14,16,12,2,1,0,0,20,16,13,15,11,10,9,8,7,5],1))
show(LatexExpr(r"\text{Le tableau des scores est :}"))
show(Borda(["A","B","C","D"],[18,16,14,12,11,20,19,14,16,12,2,1,0,0,20,16,13,15,11,10,9,8,7,5],2))
show(LatexExpr(r"\text{Les scores totaux de chaque candidat sont :}"))
Borda(["A","B","C","D"],[18,16,14,12,11,20,19,14,16,12,2,1,0,0,20,16,13,15,11,10,9,8,7,5],3)
show(LatexExpr(r"\text{Le vainqueur d'un décompte à la Borda est : }"),
Borda(["A","B","C","D"],[18,16,14,12,11,20,19,14,16,12,2,1,0,0,20,16,13,15,11,10,9,8,7,5],4),LatexExpr(r"."))

All is fine but if inside the function i remove the# and allow the header(s), I have an error which I do not understand since some time it works and some time not. (I am working with sagemath 9.2 under windows).

Pb with headers in table()

Here is the forgotten function which list all the preferences on a list of candidates

def All_pref(cand=["A","B","C","D"],code=1) :
    ncand=len(cand)
    Scand=sorted(Set(cand))
    all_pref=Arrangements(Scand,ncand).list()
    all_pref1=[str(Word(x)) for x in all_pref]
    if code==1 :
        return ncand
    if code==2 :
        return all_pref1

I have a problem with the following function :

# Borda(cand=["A","B","C","D"],ne=[18,16,14,12,11,20,19,14,16,12,2,1,0,0,20,16,13,15,11,10,9,8,7,5],cond=0)
 # cond = 0 redonne la répartition des préférences
 # cond = 1 donne le classement des candidats sur chaque type de préférences
 # cond = 2 donne les scores sur chaque candidat
 # cond = 2 donne l'accumulation des scores sur chaque candidat
 # cond = 3 déclare le vainqueur au sens de Borda.
 def Borda(cand=["A","B","C","D"],ne=[18,16,14,12,11,20,19,14,16,12,2,1,0,0,20,16,13,15,11,10,9,8,7,5],cond=0) :
     Ap=All_pref(cand,2) 
        cond1=['$\tiny${}{}{}{}$'.format(w) cond1=['$\\tiny${}{}{}{}$'.format(*w) for w in Ap]
     cond2 =[""]+ [r'${}$'.format(w) [r'${}$'.format(*w) for w in cand]
     cond3 =[r'${}$'.format(w) =[r'${}$'.format(*w) for w in cand]
     t1=table([ne])#,header_row=cond1)
     rank=[[x.find(l) for x in Ap] for l in cand] 
     score_de_Borda=[[abs(x.find(l)-len(cand)) for x in Ap] for l in cand]
     t2=table(rank)#,header_row=cond1,header_column=cond2)
        total_score_de_Borda=[add([score_de_Borda[j][i]ne[i] total_score_de_Borda=[add([score_de_Borda[j][i]*ne[i] for i in range(24)]) for j in range(len(cand))]
     t3=table(score_de_Borda)#,header_column=cond3)
     max_total_score_de_Borda=max(total_score_de_Borda)
     ind_max_total_score_de_Borda=total_score_de_Borda.index(max_total_score_de_Borda)
     vainqueur_de_Borda=cand[ind_max_total_score_de_Borda] 
     if cond==0 :
         return t1
     if cond==1 :
         return t2
     if cond==2 :
         return t3
     if cond==3 :
         return total_score_de_Borda
     if cond==4 :
            return vainqueur_de_Borda 

return vainqueur_de_Borda

and here is a call to the different variations.

show(LatexExpr(r"\text{Le tableau des rangs est :}"))
show(Borda(["A","B","C","D"],[18,16,14,12,11,20,19,14,16,12,2,1,0,0,20,16,13,15,11,10,9,8,7,5],1))
show(LatexExpr(r"\text{Le tableau des scores est :}"))
show(Borda(["A","B","C","D"],[18,16,14,12,11,20,19,14,16,12,2,1,0,0,20,16,13,15,11,10,9,8,7,5],2))
show(LatexExpr(r"\text{Les scores totaux de chaque candidat sont :}"))
Borda(["A","B","C","D"],[18,16,14,12,11,20,19,14,16,12,2,1,0,0,20,16,13,15,11,10,9,8,7,5],3)
show(LatexExpr(r"\text{Le vainqueur d'un décompte à la Borda est : }"),
Borda(["A","B","C","D"],[18,16,14,12,11,20,19,14,16,12,2,1,0,0,20,16,13,15,11,10,9,8,7,5],4),LatexExpr(r"."))

All is fine but if inside the function i remove the# and allow the header(s), I have an error which I do not understand since some time it works and some time not. (I am working with sagemath 9.2 under windows).