# tmonteil's profile - activity

2021-01-22 05:30:57 -0600 answered a question when I must declare f= or f(x,y)= ?

If you remove the comment, you have to replace sgn(SGN) with sgn(SGN(x)).

For me, the problem is in:

show(SGN.parent())


That prints (LaTeX) SR, while we have:

SGN.parent()
Callable function ring with argument x

SGN(x).parent()
Symbolic Ring

2021-01-21 05:36:44 -0600 commented question Which hash function can be used to get $w=H(d)\in F^n$ case?

You need to make your question more precise. There is always the trivial hash function that maps very w to the zero vector of F^n. What properties should your hash function satisfy ?

Regarding your first issue, you could try:

sage: solve([circ, line], [x,y])
[[x == -1/2*sqrt(2), y == -1/2*sqrt(2)], [x == 1/2*sqrt(2), y == 1/2*sqrt(2)]]


Regarding your second issue, Sage reports the inequations because it is not able to solve the simple system of inequalities. Indeed, qepcad is able to decide that there is no solution:

sage: qf = qepcad_formula
sage: F = qf.and_([circ, badIneq]) ; F
[x^2 + y^2 = 1 /\ y > 1]
FALSE
FALSE


You should be able to install qepcad with the command (in a terminal)

sage -i qepcad


If this does not work, you should provide some informations on your system.

You could also have a look at sympy, which is installed in Sage: https://docs.sympy.org/latest/modules...

2021-01-21 03:11:41 -0600 answered a question How to import rings in python module

At startup, Sage does not only import things, it also adds a preparser, so that what you typed in Sage is modified on the fly to some valid Python:

sage: type(1/3)
<class 'sage.rings.rational.Rational'>


If we turn the preparser off, we get:

sage: preparser(False)
sage: type(1/3)
<class 'float'>


To see how the preparser modified 1/3, you can do:

sage: preparse('1/3')
'Integer(1)/Integer(3)'


and check:

sage: type(Integer(1)/Integer(3))
<class 'sage.rings.rational.Rational'>


So, to transform some Sage code into a Python module, you have to both add import statements and preparse it.

You could notice that the Sage source code is pure Python, i.e. does not rely on preparser either, maybe looking at it could help to get the idea.

2021-01-20 15:22:40 -0600 commented question Extracting coefficients

Could you please provide a sample of what you want to obtain ? I do not see any matrix, the list e is unidimensional.

2021-01-20 13:52:43 -0600 commented question Solve returns bad results

Could you please tell us which problems you encountered in installing qepcad ?

2021-01-20 05:36:53 -0600 commented question Extracting coefficients

2021-01-19 03:53:05 -0600 answered a question Multiply polynomials from different rings

Ther is not coercion (see the doc) defined between the two polynomial rings, so you have to construct a common parent by yourself and convert the polynomials. Here is a possible way:

First, you can get the names of the variables of both polynomial rings as follows:

sage: R_1.variable_names() + R_2.variable_names()
('z1', 'z2', 'x1', 'x2')


Then you can construct the polynomial ring with this new list of variable names:

sage: R = PolynomialRing(K, R_1.variable_names() + R_2.variable_names())
sage: R
Multivariate Polynomial Ring in z1, z2, x1, x2 over Finite Field in a of size 2^2


Then, you can convert a polynomial from R_1 to R:

sage: pp
(a)*z1^2 + (a)*z2^2 + z1 + z2
sage: pp.parent()
Multivariate Polynomial Ring in z1, z2 over Finite Field in a of size 2^2

sage: R(pp)
(a)*z1^2 + (a)*z2^2 + z1 + z2
sage: R(pp).parent()
Multivariate Polynomial Ring in z1, z2, x1, x2 over Finite Field in a of size 2^2


Now, you can add the converted polynomials within the new larger parent:

sage: R(pp) + R(qq)
(a)*z1^2 + (a)*z2^2 + (a)*x1^2 + x1*x2 + (a + 1)*x2^2 + z1 + z2 + 1
sage: rr = R(pp) + R(qq)
sage: rr
(a)*z1^2 + (a)*z2^2 + (a)*x1^2 + x1*x2 + (a + 1)*x2^2 + z1 + z2 + 1
sage: rr.parent()
Multivariate Polynomial Ring in z1, z2, x1, x2 over Finite Field in a of size 2^2

2021-01-19 02:18:48 -0600 answered a question Random polynomial of degree 1

You can get the documentation of the random_element method by typing:

sage: R1.random_element?


As you can see, you can specify the degree, so the following should work:

sage: R1.random_element(degree=1)

2021-01-18 11:17:58 -0600 answered a question Rounding the values of a mapping

You should not use a symbolic function for such purpose, symbolic functions should be understood as mathematical expressions, they are usefull if you want to view them as a mathematical object, for example if you want to derivate them.

Instead use a Python function, which is an object that returns a value given an entry.

There are two equivalent ways to define a Python function:

sage: def f(x):
....:     return round(1/add([10,20,30]) * x, 2)


Or, the shorter

sage: f = lambda x : round(1/sum([10,20,30]) * x, 2)


In both cases, you can do:

sage: percent_votes_cand=list(map(f,[10, 20 ,30]))
[0.17, 0.33, 0.5]

2021-01-18 04:53:23 -0600 commented question How to use for loops and assign values to array

Could you please provide your code ? To format it, you select the code and click on the 101011 button on top of the edition box.

2021-01-18 04:52:05 -0600 answered a question I should store binary values in an array

I am not completely sure about your question (please provide more details if i do not understand correctly), but you can transform the string '1000' into the list of its letters as follows:

sage: list(a.binary())
['1', '0', '0', '0']


Note however that each entry is a string, not an integer. If you want a list of integers, you can transform each letter into an element of ZZ:

sage: [ZZ(i) for i in a.binary()]
[1, 0, 0, 0]


The bits and digits methods can give these bits (or "binary digits") directly as integers, ordered the other way around:

sage: a.bits()
[0, 0, 0, 1]

sage: a.digits(base=2)
[0, 0, 0, 1]

2021-01-13 20:01:50 -0600 answered a question Converting multivariable polynomial with complex coefficients to a polynomial with integer coefficients

There seems not to be a conversion from CC to ZZ, but there is one from CC to RR and one from RR to ZZ, so you can do:

sage: p = poly.change_ring(RR).change_ring(ZZ) ; p
A^2 + 2*A*B + B^2 + 2
sage: p.parent()
Multivariate Polynomial Ring in A, B over Integer Ring

2021-01-07 09:07:36 -0600 commented question Pb with headers in table()

It works for me, i can not reproduce you issue when i remove the two #

2021-01-07 09:05:18 -0600 edited question 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). 2021-01-07 09:04:51 -0600 commented question Pb with headers in table() In any case, when you have some issue, you should provide a minimal example showing the problem. 2021-01-07 05:35:28 -0600 commented question Pb with headers in table() Some code is missiing: NameError: name 'All_pref' is not defined  What 'All_pref' ? 2021-01-06 09:03:16 -0600 received badge Necromancer (source) 2021-01-06 09:02:58 -0600 received badge Nice Answer (source) 2021-01-06 06:05:35 -0600 answered a question Title for table I looked into the source code of table and there is unfortunately no title or footer attribute, so you have to hack something yourself. I guess you are using the notebook, so you have to modify the html version of the table, with the following method : table ->html -> string -> add some title -> html back -> display: rows = [['a', 'b', 'c'], [100,2,3], [4,5,60]] t = table(rows, header_row=True) title = "My title" footer = "My footer" s = str(html(t)) new = '<h1>{}</h1> {}<h3>{}</h3>'.format(title,s,footer)  Now, you can see your hacked table with html(new)  You can change the size of the title and footer my modifying the <h1> and <h3> tags. 2021-01-06 05:49:47 -0600 answered a question Centering the cells of a table and the use of tiny size Regarding the "\tiny doesn't work" part, you should add a $ before the LaTeX formula and you should either escape the \ with another \ or use a raw string:

sage: cond1 = ['$\\tiny{}{}{}{}$'.format(*w) for w in Ap]
sage: cond1 = [r'$\tiny{}{}{}{}$'.format(*w) for w in Ap]


Regarding the table, it needs a list of lists, not just a list, so use extra brackets; and you want headers for the columns, so they form a row of headers or "header row".

sage: t3 = table([total_score_de_Borda], header_row=cond3)
sage: t3
$A$   $B$   $C$   $D$
+-----+-----+-----+-----+
717   691   669   613

2021-01-05 23:55:50 -0600 answered a question Flatten relations

You can do:

sage: A = list(var('A_%d' % i) for i in (0..3))
sage: A
[A_0, A_1, A_2, A_3]
sage: B = [1, 2 * A_0, A_0 + A_1^2, A_1 * A_2]


You can generically construct the list of equations as follows:

sage: [A[i] == b for i,b in enumerate(B)]
[A_0 == 1, A_1 == 2*A_0, A_2 == A_1^2 + A_0, A_3 == A_1*A_2]


And you can solve the system:

sage: solve([A[i] == b for i,b in enumerate(B)], A)
[[A_0 == 1, A_1 == 2, A_2 == 5, A_3 == 10]]

2021-01-05 23:47:42 -0600 commented answer Changing labels of a graph and access edge thickness

Two other workarounds are:

• to relabel the vertex 4 as the string '4': D.relabel(['A','B','C','D',4])
• relabelf the vertex 4 as the string E : D.relabel(['A','B','C','D',4])

Note that the vertices of your original graph are 0,1,2,3,4, that is, there are 5 vertices.

2021-01-05 23:44:45 -0600 commented answer Changing labels of a graph and access edge thickness

Because the vertices of your new graph are 'A', 'B', 'C', 'D', 4 and since 'A' and 4 are not comparable (a string vs an integer), apparently, you need to add sort=False option to prevent sorting :

sage: D.edges(labels=False, sort=False)
[('A', 'B'), ('A', 'C'), ('A', 'D'), ('A', 4), ('B', 'C'), ('B', 'D'), ('B', 4), ('C', 'D'), ('C', 4), ('D', 4)]


I would say that raising an error in such case is a kind of bug.

2021-01-05 23:16:58 -0600 answered a question How to find a element in elliptic curve ?(code added)

What you are looking for is the discrete logarithm:

sage: x = G.discrete_log(Q) ; x
1155

sage: Q == G * x
True

2021-01-05 05:51:49 -0600 answered a question Changing labels of a graph and access edge thickness

You can relabel the graph with the relabel method:

sage: D.relabel(['A','B','C','D'])


check

sage: D.relabel?


for more options.

Regarding coloring the vertices, you can do

sage: D.show(vertex_colors={'blue':[0,2],'green':[1],'black':[3]})


see

sage: D.plot?


for more plotting options.

There might be one somewhere, but i do not see an edge-thickness option either in the documentation. However, looking into the source code of the GraphPlot class:

sage: from sage.graphs.graph_plot import GraphPlot
sage: GraphPlot??


It seems that you can do:

sage: D.show(edge_thickness=4)


Also, there is a edge_style option which can be one of 'solid', 'dashed', 'dotted', dashdot', 'None'.

2021-01-01 04:40:42 -0600 commented question Lost %display latex

Could you please upload the ipynb file somewhere so that we could understand what is happening ?

2020-12-31 12:29:54 -0600 answered a question can i run a period end if the last 18 months have not been done

You are probably refering to the sage accounting software. This forum is about the SageMath mathematics software.

2020-12-31 04:56:51 -0600 answered a question Keeping the word in a list of letters

When you type:

sage: w = Word(["A","B","C","D"])
sage: w
word: ABCD


what you get is the representation of the word w, you cant turn it into a string as follows:

sage: str(w)
'ABCD'

2020-12-26 16:03:24 -0600 answered a question Finding absolute values of roots of polynomials with Sage

## Polynomials with complex coefficients

You can define the ring of (numerical) polynomials over C as follows:

sage: R.<x> = CDF[]
sage: R
Univariate Polynomial Ring in x over Complex Double Field


You can construct a random polynomial of degree 30 as follows:

sage: P = R.random_element(degree=30)
sage: P
(0.7368648392813568 + 0.7644659236040987*I)*x^30 + (-0.9521231496916671 - 0.5668264771579159*I)*x^29 + (-0.5602325090820397 + 0.08373185660033844*I)*x^28 + (0.11778992480095218 - 0.2031034081348333*I)*x^27 + (0.3516830229409873 + 0.2968075058912192*I)*x^26 + (-0.7794485386929075 + 0.35282724454074765*I)*x^25 + (0.9529334155548153 - 0.10858391867189021*I)*x^24 + (0.4346153404358597 - 0.7919849906353298*I)*x^23 + (-0.4122547991033889 - 0.09369196690243964*I)*x^22 + (0.9072745543379173 - 0.93084223388219*I)*x^21 + (0.0917339388366103 + 0.8400827723548798*I)*x^20 + (0.620441590530908 + 0.5497959418695815*I)*x^19 + (0.08961053619498971 - 0.3245694231244378*I)*x^18 + (-0.1573830771827882 - 0.0999821789852311*I)*x^17 + (-0.42868409209771885 + 0.17826524252278442*I)*x^16 + (0.08423322767931607 - 0.7883353014539329*I)*x^15 + (-0.4854333236724999 + 0.14977131931558807*I)*x^14 + (-0.44684046421460066 - 0.46310410665013624*I)*x^13 + (0.6526594274639133 - 0.4196336531832292*I)*x^12 + (-0.27787355156700233 + 0.10848474232286232*I)*x^11 + (-0.11101383721798008 - 0.5037475397998767*I)*x^10 + (-0.13186950326025015 - 0.4838574269429168*I)*x^9 + (0.8187926299228285 + 0.8711795580308974*I)*x^8 + (-0.6860149090655201 - 0.9849078620505949*I)*x^7 + (-0.6918369434398146 - 0.9814493553853534*I)*x^6 + (0.3499220158155265 + 0.5747414242705378*I)*x^5 + (-0.893601061756806 + 0.5607846129706036*I)*x^4 + (-0.12889260181776785 + 0.7202322287337615*I)*x^3 + (-0.6940468382565192 - 0.5557200414145016*I)*x^2 + (-0.08633744827278456 + 0.7424063585043299*I)*x + 0.6230123145504038 + 0.6286232382291024*I


You can find its roots as follows:

sage: P.roots(multiplicities=False)
[-1.0120138172468134 + 0.20426669296859173*I,
-0.962581077360827 - 0.5296864154447034*I,
-0.9364728333831983 - 0.24073599552387334*I,
-0.9201821425300504 + 0.002487918823541706*I,
-0.8599059855418224 + 0.492490723674138*I,
-0.8215080191130956 - 0.6427711927416188*I,
-0.7327655570630038 + 0.6808285540382258*I,
-0.7017713764174295 + 0.9067735719613969*I,
-0.6414579210848824 + 0.1305690899208492*I,
-0.5346277142391518 - 0.7813046856018692*I,
-0.36837899733455526 - 0.896830748646684*I,
-0.3534478170558439 + 0.7077101949275129*I,
-0.28232967917268137 + 0.9677582197606973*I,
-0.22178572802727103 - 0.9734268214408631*I,
0.015053958533473745 + 1.035138545876896*I,
0.09170010634309536 - 1.0719575404124397*I,
0.23422262713071448 + 0.9812411153412857*I,
0.243546812209695 - 1.029432097206379*I,
0.39934906552852045 - 0.8111814833649242*I,
0.4716233302309813 + 0.8546354765171169*I,
0.582436456639921 - 0.7624604937976489*I,
0.6491856986029882 + 0.6138112252444622*I,
0.7124110338205422 + 0.4351851664034465*I,
0.7570474447707015 + 0.7787758630291586*I,
0.831513193382847 - 0.6444495428445836*I,
0.9648971684027969 - 0.38704090145535897*I,
0.9660222981279798 + 0.24237600403657947*I,
0.9892771693661305 + 0.06311132544291641*I,
1.1525531039685055 + 0.017246602835138347*I,
1.2950663367376647 - 0.618272306837997*I]


You can construct the list of its absolute values as follows:

sage: [abs(r) for r in P.roots(multiplicities=False)]
[1.0324228049373916,
1.0986946933519746,
0.9669204658117574,
0.9201855058471996,
0.9909517732340606,
1.0430868763845154,
1.0002364128602976,
1.1466130016559397,
0.6546117565132008,
0.946712102265528,
0.9695403433562648,
0.7910619946539459,
1.0081002031822746,
0.9983730193955808,
1.0352480045031056,
1.0758726123247224,
1.0088083888906871,
1.0578494658958941,
0.9041543425171509,
0.9761303003901686,
0.9594676808655002,
0.8934239147833227,
0.8348147160698889,
1.0860997553036549,
1.052012074095318,
1.0396283975493898,
0.995964461119574,
0.9912882311559164,
1.152682134318386,
1.4350809949107028]


## Monic integer polynomials

Likewise define the ring of polynomials in x with integer coefficients:

sage: Zx = ZZ['x']
sage: x = Zx.gen()


Pick a random monic polynomial of degree 56:

sage: q = Zx.random_element(degree=56)  # not necessarily monic
sage: p = (1 - q[56])*x^56 + q  # now monic by making leading coefficient 1
x^56 - x^55 + x^54 - 7*x^53 - 2*x^52 - x^51 + 5*x^50 - x^49 - x^48 + x^47
- 3*x^44 + 3*x^43 + 3*x^42 + 20*x^41 - x^40 + x^39 + 125*x^38 + 9*x^37
- x^36 - 2*x^35 + 3*x^34 + 10*x^32 + x^30 + 99*x^29 + 7*x^27 + 13*x^25
+ x^23 + x^22 + 2*x^21 + 3*x^20 + 2*x^19 + x^17 + 2*x^14 - x^12 + 5*x^11
+ x^10 - x^8 + 7*x^7 - x^6 + x^5 - 5*x^4 - x^3 + 5*x^2 + x - 1


Get the sorted list of absolute values of its complex roots:

sage: sorted(set(abs(z) for z in p.complex_roots()))
[0.392775879097575, 0.618313001041181, 0.829872478969433,
0.876156325725046, 0.877139969220623, 0.896140603140608,
0.897355058131500, 0.898822808765931, 0.902218110575174,
0.908268048474002, 0.909765827992206, 0.914374431830909,
0.923321003752644, 0.935403911031256, 0.938567671569716,
0.970873370350356, 0.972725264654593, 0.975123271228316,
0.977132068373407, 1.01049931640877, 1.15177593823796,
1.16627154233445, 1.18058797182489, 1.21320658003016,
1.21544302417961, 1.23985793698233, 1.26758074663977,
1.28869109993426, 1.80658377491657, 2.17180464952677]

2020-12-19 07:55:05 -0600 commented question Understanding sqrt of sage

You should provide the construction of J, C and f so that people can reproduce your situation.

2020-12-18 02:23:05 -0600 answered a question Quickly recalling the definition of a temporary function to make minor edits?

From the console, type d (the first letter of def f(x):), followed by the up arrow to browse the history. If you typed too many commands starting with d between the definition of f and the current time, you can type a larger prefix, like de or def f follwed with the up arrow.

2020-12-18 02:20:07 -0600 edited question Is it possible to know the corresponding graph labeling after using "relabel()"?

I am trying to generate the following cayley graph

G=AlternatingGroup(5)
S=[(1,2,3),(1,2,4),(1,2,5)]
C=G.cayley_graph(generators=S, simple=True)
U=C.to_undirected()
U.vertices()

[(), (3,4,5), (3,5,4), (2,3)(4,5), (2,3,4), (2,3,5), (2,4,3), (2,4,5), (2,4)(3,5), (2,5,3), (2,5,4), (2,5)(3,4), (1,2)(4,5), (1,2)(3,4), (1,2)(3,5), (1,2,3), (1,2,3,4,5), (1,2,3,5,4), (1,2,4,5,3), (1,2,4), (1,2,4,3,5), (1,2,5,4,3), (1,2,5), (1,2,5,3,4), (1,3,2), (1,3,4,5,2), (1,3,5,4,2), (1,3)(4,5), (1,3,4), (1,3,5), (1,3)(2,4), (1,3,2,4,5), (1,3,5,2,4), (1,3)(2,5), (1,3,2,5,4), (1,3,4,2,5), (1,4,5,3,2), (1,4,2), (1,4,3,5,2), (1,4,3), (1,4,5), (1,4)(3,5), (1,4,5,2,3), (1,4)(2,3), (1,4,2,3,5), (1,4,2,5,3), (1,4,3,2,5), (1,4)(2,5), (1,5,4,3,2), (1,5,2), (1,5,3,4,2), (1,5,3), (1,5,4), (1,5)(3,4), (1,5,4,2,3), (1,5)(2,3), (1,5,2,3,4), (1,5,2,4,3), (1,5,3,2,4), (1,5)(2,4)]


Here, I used the "relabel()" function and I got the following vertices

U.relabel()
V= U.vertices()
V

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59]


Is it possible to know the corresponding labels? Like for example what is the corresponding permutation for 0?