ASKSAGE: Sage Q&A Forum - Latest question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 25 Jan 2021 11:28:19 -0600Solving the Schrodinger equation using sage (Well)https://ask.sagemath.org/question/55455/solving-the-schrodinger-equation-using-sage-well/I'm trying to solve the SchrΓΆdinger equation through Sage, for the potential well.
I wrote:
k, a = var('k, a')
psi = function('psi')(x)
eqs = diff(psi, x, 2) + k^(2)*psi == 0
assume(k > 0, a > 0)
EQS = function('EQS')(x)
EQS = desolve(eqs, psi, ivar=x)
A, B, c = var('A, B, c')
result0 = A*cos(k*0) + B*sin(k*0) == 0
result1 = B*sin(k*a) == 0
assume(B > 0)
How can i find the constants A and B through boundary conditions?
My conditions are: Psi(0)=0 and Psi(a)=0.
If i put it in desolve function it return me zero.
So i tried to work with the equations separated but i cannot figure out
how to get `k=n*pi/a` (the expected result).GrimMon, 25 Jan 2021 11:28:19 -0600https://ask.sagemath.org/question/55455/Arithmetic operation is not working in finite field GF(4091^2)?https://ask.sagemath.org/question/55451/arithmetic-operation-is-not-working-in-finite-field-gf40912/I am facing problem during arithmetic operation in $ GF(4091^2)$. But everything working fine in $ GF(13^2)$ as
Var('x')
F.<x> = GF(13^2)
a=F.fetch_int(150)+F.fetch_int(97)
print a
How can I fix this?MKSMon, 25 Jan 2021 07:31:08 -0600https://ask.sagemath.org/question/55451/How to do arithmetic operation of elements in finite field?https://ask.sagemath.org/question/55450/how-to-do-arithmetic-operation-of-elements-in-finite-field/Let us consider an example:
Var('x')
F.<x> = GF(13^2)
We consider two elements `2*x + 11, 3*x + 2` corresponding to the integers `37` and `41` respectively. Now we can operate them as
a=F.fetch_int(37)+F.fetch_int(41)
m=F.fetch_int(37)*F.fetch_int(41)
We have `a=4*x + 10 , m= 4*x + 10`
In reverse way we can get the corresponding integers as :
ai=a.integer_representation()
mi=m.integer_representation()
That is, `ai=65, mi=62`
How can I do the same for the field `GF(251)` using the same function?MKSMon, 25 Jan 2021 06:35:17 -0600https://ask.sagemath.org/question/55450/integral of function with sgn (x,I) insidehttps://ask.sagemath.org/question/55428/integral-of-function-with-sgn-xi-inside/HI
I encounter a problem on an integral calculation, and I do not know how to find a workaround.
(I mean a mathematically correct workaround, not the questionable tinkering of replacing SGN (f (x, I))
by -1 !!! that I did to get a numeric value ;-) ).
if I comment out lines (77,78) and (128,129) I get an error:
**ValueError: The function to be integrated depends on 2 variables (x, z),
and so cannot be integrated in one dimension.
Please fix additional variables with the 'params' argument**
Does somebody knows what 'params' I must set in function numerical_integral ?
[code on sagecell](https://sagecell.sagemath.org/?z=eJztWF9v2zgSfw-Q70A4D5JixhXlFJcW1QGLxRW7QFAsmhaXwnUCRqJtYmVRS9KJ1KLf_YakKNOwk3bb4u7l3CIWh_OfM_OjpVbiIR6dfP9nlKDjI2W1_CrWzUYzdLWRC1owJBZIrxhSzYpJXtAKaclpvawYonWJrj-gpqJ1IP-jXtxTGUct7qLk-Ei-2axzcnzkqZfiAbfvG9yZh-59Y3iOj06QFJu65PUS3dNqw9Tx0R9aXebIfWazdEKm_3jxHKN0At9pNscIaNPp8-fnhvYiIxcvHO3i_CKdGlqWZhc9KSXnZCs6t8rf0DVTlyhHM2cjaruURBgFHyCRbJfk-HaIQPh1o6O5iYNVFW8US0EteZadqr-kjs_amwyNEUn6pf2bJUDKkkGCgER7WggVk2cvThuePFO89s8DVwZcTsn5s-mp12sMN5WGvYorfdtUQscmexgVohIyj-4go-Cx4p9YPk2Bv9G3ojECnyPLEr1EnilaCck_iVrT6pZWfFmvWa3NfsUW2uzfM6lNEe3u3gmtxTr64jwZg5ubdaxZq-Ma8ozRPSu0kHGjE4xOT539BC2ERG4fvOE1-sSbeDgajEwQSTKorHjNYigFtzGbzmdkPh8W8224UjzU4Kpe8eLPmimVZ9gKK91VLI9KqlasjPYUW0VkPktBVeoVk1CxS9E36R3nfN1UvOD9gfjKOOtw3OIUkwTHnfvutQsJPckG8VCKWJkJwVsXB7EOeMTD01azx60uJWO1a0LzT14BX4c_Jbn9tsVmWvgmM2V81t1k5kDkVdnmJV8sYnmFW0wcqRtInSVRBUXA4vRV-2pn2YXLXeXon6l1xc0hiYxC1KKXaISNTTxCHzXqyZ0nd868yuO-ygxrMimkUOq2kaLcFDrY6hITwgn6HZWijjTaKIaM-KQWch0n-I4V1NA4lKRCtLRTid4ptNjUheaiNsKeyVTwRqG3YQh5CjOwVG9AXe4SCNrhyG6ysX0iw1MGT4mPtlQ-IOXiNP5YktMVJEbIkkkz1nmt2VJS4xVGH_A1sL_-_e3VO9RQqaE4oWeh7csBAkwF25JFI6vuDxhmMAagctzz2DxD3cx8uWLkSxDawE4VCGQWdIctRbTgVZV_Tl8ioHxxy76-ToqiiByFVs2K5pNp4m19f4c4-b0WCRxM-oXz8EC3POHCt7SLEZ_Y02jXvM4hUe2atjnATNevu35NVQO1d2tPyawXfGkn8UVwoAsulUYNZ4DWJav4mmtWorsOOX9RsZH3DGGXgH5lsHt7njA9264HcotEf10aLZf5bO462xMmtGlYXcYGgPPcJz05wPC-GfZJckhFa1UEOT_AYpQEB-F8oVIKQPucpKaXDtxLTPnSJaQAwtIPwmVGGeafmak--5cUgOpfbQPTYfTRYNZntb04hfZgufX1Xe_rF_QR5x_x6PhoDOLQkLefR-PKqIx9Mkzg49GXm_0NYjcQtHsgbtPqWe29aCuQzSdypWBK9SlMnGKT5kckpocknMUTMInRIHcF2pN-0Y8cYIDwzP-ys3_bkRmeO3JPsx4fQUwf0jz2o4r1AgASQX56H4PEeK-rJVxI9Gqdj5acFlZnI0FZbPVuLaS5_YKoXEvBiDb18ADDncFhw_GpZT3McFMxCyDEbZKfkWGc1wBJ9nhve3crVFADEoP36AGcsapMn3kV6IzsujFRmzuluYZr-K23GQMzNhJB41vmrc7XPauZ-sgHGHCmyOi1hbgMmAyXebgG8_shuEyleL-I9opksPbalv222n1H9J1AFxoAaDAV4hAa3LpO0-Fe8cjlH5diTWFcRpLRKkq-Bd-uWAFl3AOc5EuTuUcQDvUQRwKII49DXDZAHAkgLvt-iPsv2_ohOCUH4DSA-ycvnk-Y_0YoJT8DSvdg7yRAiA5RqDGg9fdOn28yfzWAIHo1QBUxUPUEb7bHG9hqe1s_BLnZ1yCXfBVys58Dub7j9jF322z7gGuPt1__PchVob3_Y-73YO6Jmb_kp4Lu4xr9NP8KVhOvhFiIJBYih5zt4ByxIOKYB6lejPyPEX7ryNcxficm8gTM2zBDXnIQ6MmQjmvjxiNQD1v7WD-pD-G9oQ6W-z7fB_2_g_kkCEULHTStHYqofzdpx4fXH2gKLw9QoWOv0w0yd_DRO6_3F6v3lx29Nsm_QeNxodG7FROSmV_REe5phhtH5ve15XwLd4MIm7cQybaw_s1MUSBaKYHuIdxFZ-8WhbXhIoaRtt5UmjdVZ94PmG1JS75RJrDMvtZAVCMtGn8zAcxmySiwYqZksWLFn7BtWM0rWp8R5bVzl6rsJsvPrYRhuxcVHIOjT_OLUGknNlvfvfZd10GsWMGReL_3D9xmxonB9LK3r9BG7y446QVgY1OBo1ZCw43O4Yj78SQKTWsN3fQfz7k1aQ==&lang=sage&interacts=eJyLjgUAARUAuQ==)
show("###########################################################")
show("Compute Surface of the spherical triangle and XY plan")
show("###########################################################")
var('x,y')
rNum=1
var('xLow,xUp,yLow,yUp')
# rounding values
PtsL= [[0.13795, 0.37902], [0.33554, 0.92189], [0.84803, 0.2028], [0.80141, 0.37902]]
PtsNamesL = [ 'xy01', 'xy12', 'xy02', 'xyCut']
ellipse0 = 1/2*sqrt(-x^2 + 1)*sqrt(-sqrt(2) + 2)
ellipse1 = x*cos(1/9*pi)/sin(1/9*pi)
ellipse2 = sqrt(-4/3*x^2 + 1)
plt = list_plot(PtsL, color='blue', size=30)
pt_opt = {'color': 'blue', 'horizontal_alignment': 'left', 'vertical_alignment': 'bottom'}
plt += sum(text(name, vector(pt), **pt_opt) for name, pt in zip(PtsNamesL, PtsL))
plt += line([[0, PtsL[3][1]], PtsL[3]], color='brown', thickness=2, linestyle='dashed')
plt += line([[PtsL[1][0], 0], PtsL[1]], color='blue', thickness=2, linestyle='dashed')
plt+=implicit_plot(ellipse0-y,(x,0,1),(y,0,1),color='orange')
plt+=plot(ellipse1,(x,0.1,PtsL[1][0]),color='yellow')
plt+=implicit_plot(ellipse2-y,(x,0,1),(y,0,1),color='green')
rS(x,y,z)=(x,y,sqrt(rNum^2-x^2-y^2))
rSdx=diff(rS,x,1)
rSdy=diff(rS,y,1)
assume(0<x<1)
assume(0<y<1)
assume(rNum^2-x^2-y^2 >0)
show("r diff x : ",rSdx," \t r diff y : ",rSdy)
rSds=(vector(rSdx).cross_product(vector(rSdy)))
# I don't use rSds.norm(),because it is adding abs function
# because for us R^2-x^2-y^2 >=0
dsNorm=sqrt(rSds[0]^2+rSds[1]^2+rSds[2]^2)
show("ds : ",rSds," \t norm : ",dsNorm)
show("order of integration, Y,X : FIRST part, left side of the blue line ")
Pxy0 = plt
Pxy0+= plot([ellipse0, ellipse1], (PtsL[0][0], PtsL[1][0]), fill={0: [1]}, fillcolor='#ccc', fillalpha=.3)
Pxy0+=implicit_plot(ellipse0-y,(x,0,1),(y,0,1),color='orange')
Pxy0+=plot(ellipse1,(x,(PtsL[0][0]),(PtsL[1][0])),color='yellow')
Pxy0+=implicit_plot(ellipse2-y,(x,0,1),(y,0,1),color='green')
Pxy0.show(xmin=0, xmax=1, ymin=0, ymax=1, aspect_ratio=1, figsize=8)
show("first piece delimited by yellow curve ,orange curve and blue line in xy plan")
eqLimitL=[]
eqLimitL.append(yLow==ellipse0)
eqLimitL.append(yUp==ellipse1)
eqLimitL.append(xLow==PtsL[0][0])
eqLimitL.append(xUp==PtsL[1][0])
arrondi=10
# spherical triangle partaged in two pieces
# first piece delimited by yellow curve ,orange curve and blue line in xy plan
show(LatexExpr(r"\text{surface of first piece of spherical Triangle} \,=\,"
+r"\int_{"+latex(eqLimitL[0])+"}^{"+latex(eqLimitL[1])+"} " \
+r"\int_{xLow="+latex(round(eqLimitL[2].rhs(),arrondi))+"}^{xUp="+latex(round(eqLimitL[3].rhs(),arrondi))+"} " \
#+r", "+latex(rS[2])+latex(dsNorm)+r" \, \, dy \, dx"))
+r", "+latex(dsNorm)+r" \, \, dy \, dx"))
intY0=(integrate(dsNorm,y,eqLimitL[0].rhs(),eqLimitL[1].rhs(),algorithm="giac"))
print(intY0)
intY00=intY0
#show(" below we replace sgn function by fsgn(x)=-1 because numerical_integral can't integrate with sgn ")
fsgn(x)= -1
intY00=intY0.substitute_function(sgn,fsgn)
show("intY0 with sgn Function: ", intY0)
show("intY00 subs of sgn: ", intY00)
intYX00=numerical_integral(intY00,eqLimitL[2].rhs(),eqLimitL[3].rhs())
show("First spherical surface piece after numerical integration : ", intYX00)
var('xLow,xUp,yLow,yUp',domain='real')
show("order of integration, Y,X : Second part, rigth side of the blue line ")
Pxy1 = plt
Pxy1+= plot([ellipse0, ellipse2], (PtsL[1][0], PtsL[2][0]), fill={0: [1]}, fillcolor='#ccc', fillalpha=.3)
Pxy1+= plot([ellipse0, ellipse2], (PtsL[1][0], PtsL[2][0]), fill={0: [1]}, fillcolor='#ccc', fillalpha=.3)
Pxy1+=implicit_plot(ellipse0-y,(x,0,1),(y,0,1),color='orange')
Pxy1+=plot(ellipse1,(x,PtsL[0][0],PtsL[1][0]),color='yellow')
Pxy1+=implicit_plot(ellipse2-y,(x,0,1),(y,0,1),color='green')
Pxy1.show(xmin=0, xmax=1, ymin=0, ymax=1, aspect_ratio=1, figsize=8)
eqLimitL=[]
# delimited y area
#assume(PtsL[2][1]<=ellipse0 <=PtsL[1][1])
#assume(PtsL[2][1]<=ellipse2 <=PtsL[1][1])
# delimited x area
eqLimitL.append(yLow==ellipse0)
eqLimitL.append(yUp==ellipse2)
eqLimitL.append(xLow==PtsL[1][0])
eqLimitL.append(xUp==PtsL[2][0])
arrondi=10
# spherical triangle partaged in two pieces
# Second piece delimited by blue line ,orange curve and green curve in xy plan
show(LatexExpr(r"\text{surface of second piece of spherical Triangle} \,=\,"
+r"\int_{"+latex(eqLimitL[0])+"}^{"+latex(eqLimitL[1])+"} " \
+r"\int_{xLow="+latex(round(eqLimitL[2].rhs(),arrondi))+"}^{xUp="+latex(round(eqLimitL[3].rhs(),arrondi))+"} " \
#+r", "+latex(rS[2])+latex(dsNorm)+r" \, \, dy \, dx"))
+r", "+latex(dsNorm)+r" \, \, dy \, dx"))
#intY1=(integrate(dsNorm,y,eqLimitL[0].rhs(),eqLimitL[1].rhs(),algorithm="giac"))
intY1=(integrate(dsNorm,y,yLow,yUp,algorithm="giac"))
print(intY1)
intY11=intY1.subs(eqLimitL)
show("intY1 : ",intY11)
intY111=intY11
#show(" below we replace sgn function by fsgn(x)=-1 because numerical_integral can't integrate with sgn ")
fsgn(x)= -1
intY111=intY11.substitute_function(sgn,fsgn)
show("intY11 with sgn Function: ", intY11)
show("intY111 subs of sgn: ", intY111)
intYX111=numerical_integral(intY111,eqLimitL[2].rhs().n(),eqLimitL[3].rhs().n())
show("Second spherical surface piece after numerical integration : ", intYX111)
show("total Triangle area Computed by surface integration: ", intYX00[0]+intYX111[0])
#show('Total TriAngle Area Computed with Harriot Theorem : ',HarriotArea,' \t with R = ',rNum)
#show(" We can also verify the computation in multiplying the radius by 2(rNum at top of the file)")
#show(" and check that the surface is multiplied by 2^2=4 and the volume by 2^3=8")
#show(" you can also check the computation by changing the spherical surface with the condition,")
#show(" that this surface should be contained in first octant ")
![sphere 3D](/upfiles/16113903406909965.gif)ortolljSat, 23 Jan 2021 02:19:33 -0600https://ask.sagemath.org/question/55428/Generating only the ranks of elliptic curves that can be found provably correctlyhttps://ask.sagemath.org/question/9615/generating-only-the-ranks-of-elliptic-curves-that-can-be-found-provably-correctly/Hello! I am trying to compute the rank for a large number of elliptic curves. I know that this is not always doable in a provably correct manner, so I would like to write up a piece of code that will go through my list of elliptic curves, calculate the rank provably correctly if possible, and skip those elliptic curves for which the rank cannot be computed provably correctly. Is there a simple way to do this? Thanks!Juanhe TanThu, 06 Dec 2012 16:06:33 -0600https://ask.sagemath.org/question/9615/Link between notebookshttps://ask.sagemath.org/question/55434/link-between-notebooks/ I wonder if it is possible to link two notebooks. That is open a notebook aware of the code in an other ?CyrilleSun, 24 Jan 2021 03:39:08 -0600https://ask.sagemath.org/question/55434/Linear programming with a strange resulthttps://ask.sagemath.org/question/55430/linear-programming-with-a-strange-result/ I have encoutered a strange behavior in solving a linear program.
def sol_zero_sum_game(M=matrix([[1,-1], [-1,1]]),code=1) :
dim = M.nrows()
U=ones_matrix(dim,dim)
zsg=MixedIntegerLinearProgram(maximization=False, solver="GLPK")
x=zsg.new_variable(real=True,nonnegative=True, indices=[0..dim-1])
minM=min(min(M))
Id= identity_matrix(dim)
M1=(abs(minM)+1)*U+M
Bzsgl=M1*x
zsg.set_objective(sum(x[i] for i in range(dim)))
zsg.solve()
xx=zsg.get_values(x)
#show(xx)
for i in range(0,dim) :
zsg.add_constraint(Bzsgl[i]>=1)
if code==1 :
return zsg.show()
if code==2 :
return xx
The above code can display the program for the following `G` matrix :
G=matrix([[1,-1], [-1,1]])
sol_zero_sum_game(G,1)
The solution is given by :
G=matrix([[1,-1], [-1,1]])
sol_zero_sum_game(G,2)
which gives `{0: 0.0, 1: 0.0}` as a solution. But this is obviously false since after substitution of $(0,0)$ in the constrains it doesn't work. As this is the formalisation of a game I know that the solution is $(0.25, 0.25)$ as confirmed by an other software LIPS (see the screen capture below).
![image description](/upfiles/16114008054195529.png)
I have certainly made a mistake but I can't see where. Thanks for help.CyrilleSat, 23 Jan 2021 05:21:18 -0600https://ask.sagemath.org/question/55430/How can I compute a fixed field over the p-adicshttps://ask.sagemath.org/question/55336/how-can-i-compute-a-fixed-field-over-the-p-adics/I have problems to implement the following set up:
I want to have a field $K = \mathbb{Q}_3$ and an extension $L = \mathbb{Q}_3(\alpha)$ over $K$ where $f:=\min_K(\alpha) = x^4 - 3x^2 + 18$. This extension has degree $4$ and ramification index $2$. Furthermore, let $F/K$ be the unique unramified extension of $K$ of degree $4$ which is generated by a primitive $5$-th root of unity $\zeta_5$.
Then one can show that $\varphi: \alpha \mapsto \frac{(2 \alpha^2 - 3)\sqrt{-\frac{2}{7}}}{\alpha},$ $\zeta_5 \mapsto \zeta_5^3$ is an element of the Galois group of $LF/K$. Now let $L' = (LF)^{\langle \varphi \rangle}$. This must be a quadratic and totally ramified extension of $K$. There are only two possibilities for that: $K(\sqrt{3})$ or $K(\sqrt{-3})$.
**Question**: How to determine whether $L' = K(\sqrt{3})$ or $L' = K(\sqrt{-3})$ (or equivalently, $\varphi(\sqrt{3}) = \sqrt{3}$ or $\varphi(\sqrt{-3}) = \sqrt{-3}$)?
Since I only have only superficial knowledge about Sage, I was not even able to set up the easy things like the field $L$ properly. When I use
K = Qp(3)
R.<x> = ZZ[]
f = x^4 - 3*x^2 + 18
L.<alpha> = K.extension(f)
I get an error that my polynomial $f$ must be either unramified or Eisenstein (which of course does not exist since $L/K$ is neither unramified nor totally ramified). Furthermore, I have no idea how to approach with my problem with Sage otherwise. And since computation by hand is pretty hard in this case (I already tried!), it would be nice to solve with problem here, so I can use it for similar computations in the future.
Could you please help me with this problem?RotdatMon, 18 Jan 2021 09:41:46 -0600https://ask.sagemath.org/question/55336/How to do low degree computation in a Free Algebra ?https://ask.sagemath.org/question/55269/how-to-do-low-degree-computation-in-a-free-algebra/Say $F$ is a free algebra over $n$ generators of degree $1$, and i want to compute in this algebra but i only need to get my expressions up to degree $k$. For example, if $k=2$, $(ab +a)*b$ should be $ab$.
For now, i have been doing the computation and truncating everything above degree $k$, but the time complexity is too high when i launch a big computation.
I am actually asking how to compute in the tensor Algebra $T(V)$ modulo $T_{\geq k}(V)$. For free Lie algebras, this can be done using nilpotent Lie algebras, (for example `L = LieAlgebra(QQ, 3, step=3)` implements a 3-nilpotent free Lie algebra). How to do this with free algebras ?qfaesThu, 14 Jan 2021 09:03:58 -0600https://ask.sagemath.org/question/55269/when I must declare f= or f(x,y)= ?https://ask.sagemath.org/question/55417/when-i-must-declare-f-or-fxy/HI
Sorry for this really basic SageMath question ;-( :
Does anyone know the reason why an error is generated when I uncomment the 3rd line?
and is it possible when a function was declared (f(x)=) object to return to (f=) object ?
and when I must declare f(x)= , or simply f= ?
despite the reading of [Some Common Issues with Functions](https://doc.sagemath.org/html/en/tutorial/tour_functions.html)
var('x')
SGN=(x+2)*(x+1)*(x-1)*(x+1)
#SGN(x)=(x+2)*(x+1)*(x-1)*(x+1)
show(SGN.parent())
f(x)=1/x*sin(x)
plt=plot(f,(x,-3,3),color='blue')
plt+=plot(SGN,(x,-3,3),color='black',linestyle='dashed')
plt+=plot(sgn(SGN),(x,-5,5),color='gray',linestyle='dashed')
show(plt,xmin=-2,xmax=2,ymin=-3,ymax=3, aspect_ratio=1)
show(numerical_integral(f,0,2)[0])
show(numerical_integral(-sgn(SGN)*f,0,1)[0]+numerical_integral(sgn(SGN)*f,1,2)[0])ortolljFri, 22 Jan 2021 04:32:00 -0600https://ask.sagemath.org/question/55417/How do I understand the result of symbolic integralshttps://ask.sagemath.org/question/7574/how-do-i-understand-the-result-of-symbolic-integrals/So now I know how to integrate, but when I type in
sage: deriv=diff((exp(x)-1)/x,x); deriv
e^x/x - (e^x - 1)/x^2
sage: deriv.integrate(x)
-1/x + Ei(x) - gamma(-1, -x)
why don't I get back `(exp(x)-1)/x +C `?
Philipp SchneiderWed, 18 Aug 2010 13:04:12 -0500https://ask.sagemath.org/question/7574/Issues with Reed-Solomon encoderhttps://ask.sagemath.org/question/55386/issues-with-reed-solomon-encoder/I am trying out the Reed-Solomon encoder in Sage and I have found it to exhibit a curious behavior. I first create an encoder for a $(7,3)$-Reed Solomon code as follows
sage: F.<a> = GF(8,name='a',modulus=x^3+x+1)
....: Fx.<x> = F[]
....: C = codes.ReedSolomonCode(F, 7, 3)
....: E = C.encoder("EvaluationPolynomial")
Now I can write
sage: E.encode(x)
(1, a, a^2, a + 1, a^2 + a, a^2 + a + 1, a^2 + 1)
Or
sage: E.encode(a*x^0+a^2*x+x^2)
(a^2 + a + 1, a^2 + 1, a, 0, a^2 + 1, 0, a^2 + a + 1)
But I get when I write the following
sage: E.encode(a)
I get the following error
"AttributeError: 'sage.rings.finite_rings.element_givaro.FiniteField_givaroElement' object has no attribute 'degree'"
If I instead write
sage: E.encode(a*x^0)
Everything works as intended. Is this how it is supposed to work? Does one always need an "$x$" to be part of a term, even when one actually has a constant term? Is there a better way to do it? joakim_uhlinWed, 20 Jan 2021 08:44:24 -0600https://ask.sagemath.org/question/55386/Mysterious "must have a value" errorhttps://ask.sagemath.org/question/55375/mysterious-must-have-a-value-error/I am using CoCalc to experiment with some GAP functionality in Sage. I am trying to run the following code.
G = gap.SmallGroup(64, 134)
R = gap.ResolutionPrimePowerGroupRadical(G, 10)
This yields the following error.
RuntimeError: Gap produced error output
Error, Variable: 'ResolutionPrimePowerGroupRadical' must have a value
What does this mean, and how do I solve this issue?PalomarWed, 20 Jan 2021 04:51:15 -0600https://ask.sagemath.org/question/55375/Cluster transitivityhttps://ask.sagemath.org/question/55411/cluster-transitivity/The *cluster transitivity* (the fraction of closed triangles ) of g is equal to:
C =(number of triangles) Γ 3/(number of connected triples)
Formula (7.28) Networks Mark Newman (2018)
I would like to ask you about the method cluster_transitivity() It gives 0.0853107962707866 for this network:
http://snap.stanford.edu/data/email-Enron.html , but a table from this page shows that Fraction of closed triangles is 0.03015. **So, these two number are not equal.**
If I omit 3 in the formula (7.28) and I get 0.0284369320902622.
**Why?**
On this page: http://snap.stanford.edu/data/index.html (at the end),
we have a definition of the fraction of closed triangles: Number of connected triples of nodes / number of (undirected) length 2 pathsSYLAThu, 21 Jan 2021 09:26:34 -0600https://ask.sagemath.org/question/55411/Which hash function can be used to get $w=H(d)\in F^n$ case?https://ask.sagemath.org/question/55408/which-hash-function-can-be-used-to-get-whdin-fn-case/I am trying to implement a cryptographic scheme. For a arbitrary message $d$ , I need a Hash Function $\mathbb{H}$ that can compute the hash value $w=\mathbb{H}(d)\in \mathbb{F}^n$. Here $F$ is a finite field of order four.
I can not find any hash function which outputs field values.
Can someone please help and show me the right direction?Sri1729Thu, 21 Jan 2021 04:50:33 -0600https://ask.sagemath.org/question/55408/Solve returns bad resultshttps://ask.sagemath.org/question/55395/solve-returns-bad-results/ I'm trying to use Sage to determine if a collection of (polynomial) inequalities has a solution or not. Ideally, I think I should use qepcad but I am having problems getting it to install. I thought I would try to see if standalone Sage would do the trick and began working with the solve function to get familiar with it. Already I'm running into very weird results. For example I run the following code:
x,y = var('x,y')
circ = x**2 + y**2 == 1
line = y == x
badIneq = y > 1
Now, if I execute
solve([circ, line], x)
it returns [] instead of the two solutions I expect. Furthermore, the code
assume(x,'real')
assume(y,'real')
solve([circ, badIneq], x)
is expected to return no solutions but instead it returns [[y - 1 > 0, x^2 + y^2 - 1 == 0]].
I must be doing something wrong but I can't figure out what it is. Thanks.
skepleyWed, 20 Jan 2021 12:04:12 -0600https://ask.sagemath.org/question/55395/How to import rings in python modulehttps://ask.sagemath.org/question/55403/how-to-import-rings-in-python-module/I'm trying to build a sage 9 code into a format of python module with .py file, and run the module in the sage command line. Most of the issue could be fixed through this webpage https://doc.sagemath.org/html/en/tutorial/programming.html by importing packages with command line such as
import_statements('is_integer')
i.e. set up the sage environment manually. However, a built in mechanism in sage was the usage of rings. i.e.
1/3 in sage automatically returned 1/3 in rational ring, but when put the code in python module and run it in sage command line.
sage: module_name.value1
was in class 'float' or 'int'
How to set up the environment so that the module could run operation in sage rings automatically?ShoutOutAndCalculateThu, 21 Jan 2021 00:10:55 -0600https://ask.sagemath.org/question/55403/wsl W10 Ubuntu2004 JupyterLab future upgradehttps://ask.sagemath.org/question/55390/wsl-w10-ubuntu2004-jupyterlab-future-upgrade/HI
[Installing optional packages ](https://ask.sagemath.org/question/53294/installing-optional-packages-infinite-loop/?comment=55017#post-id-55017)
When SageMath9.3 will be released, do I wiil need to do only these commands ?
or will there be a shorter procedure
because the make will take a long time (3 hours on my old PC, and 2 hours on my new PC)
3.Download and extract the source tarball into a subfolder of your home directory
cd ~wget http://www.mirrorservice.org/sites/www.sagemath.org/src/sage-9.3.tar.gz
tar xvf sage-9.3.tar.gz
4.Start building
cd sage-9.3/
./configure
makeortolljWed, 20 Jan 2021 10:12:48 -0600https://ask.sagemath.org/question/55390/Transforming a list of listhttps://ask.sagemath.org/question/55378/transforming-a-list-of-list/I have two lists :
l1=[([π°,π±],π°),([π°,π²],π²),([π±,π²],π±)]
l2=[[33,27],[25,35],[42,18]]
This two list must be read like this `([A, B], A)` : `A` win in the duel with `B` and the score are `33` for `A` and `27` for `B`. I would like to transfer this information in a table or a matrix such that in line one has the score of each duelist against the others that is :
`A = [[0,33,25],[27,0, 42],[35,18,0]]`
of course this is an example. The solution must be generic. In the time I have tried to find an elegant solution, I have encountered the following problem : how to remove `Rien` from all the sublist in :
`l3=[[33,ππππ,25,ππππ,ππππ,ππππ],[ππππ,27,ππππ,ππππ,42,ππππ],[ππππ,ππππ,ππππ,35,ππππ,18]]`
and insert the `0`according to the `A` matrix. Thanks for your help.CyrilleWed, 20 Jan 2021 06:19:24 -0600https://ask.sagemath.org/question/55378/How to index all elements of a finite field?https://ask.sagemath.org/question/55374/how-to-index-all-elements-of-a-finite-field/I would like to assign an integer corresponding to element of a finite field $GF(p^m)$, where $p^m\in[ {13^2,3^5, 131,137,139,251}] $
**MWE:**
F.<x> = GF(3^5, impl='givaro')
THe elements of GF(3^5) are 0,1,2,x,x^2 etc, we would like to indexing each element such as $0-->0, 1-->1,2-->2,x-->3, x^2--4$ etc. Not only that, if I call any element for example if I call x^2 it should rerun 4 and conversely.
This process should work for the field order prime $p^m, m=1$ also.
How can I do this?MKSWed, 20 Jan 2021 03:52:20 -0600https://ask.sagemath.org/question/55374/Tensor product of elements of non-free algebrashttps://ask.sagemath.org/question/55365/tensor-product-of-elements-of-non-free-algebras/In SageMath 9.1 I am unable to execute the code
a = SteenrodAlgebra(2).an_element()
M = CombinatorialFreeModule(GF(2), 's,t,u')
s = M.basis()['s']
T = tensor([a,s])
which is copied verbatim from this [answer](https://ask.sagemath.org/question/8750/what-is-the-name-of-a-tensor-product/?answer=13310#post-id-13310) posted back in 2012. Instead, I get AttributeError on the tensor command. Is there some ingredient I'm missing?
More to the point, I am unable to run
N = 2
k.<w> = CyclotomicField(N)
A.<X,Z> = FreeAlgebra(k, 2)
F = A.monoid()
X, Z = F.gens()
monomials = [X^i*Z^j for j in range(0,N) for i in range(0,N)]
MS = MatrixSpace(k, len(monomials))
matrices = [
# matrix showing the action of the first generator, X, on the monomials
MS([0, 1, 0, 0, # 1*X = X
1, 0, 0, 0, # X*X = 1
0, 0, 0, -1, # Z*X = -XZ
0, 0, -1, 0 # XZ*X = -Z
]),
# matrix showing the action of the second generator, Z, on the monomials
MS([0, 0, 1, 0, # 1*Z = Z
0, 0, 0, 1, # X*Z = XZ
1, 0, 0, 0, # Z*Z = 1
0, 1, 0, 0 # XZ*Z = X
]),
]
B.<X,Z> = A.quotient(monomials, matrices)
tensor( (X*Z,X) )
which is the code I'm actually interested in. In this instance I get AssertionError on the tensor command. Is there some restriction on using tensor on non-free algebras? The code below executes fine:
N = 3
k.<w> = CyclotomicField(N)
A.<X,Z> = FreeAlgebra(k, 2)
tensor( (X*Z,X) )Will OrrickTue, 19 Jan 2021 14:04:27 -0600https://ask.sagemath.org/question/55365/Possible inconsistency in symbolic limitshttps://ask.sagemath.org/question/55370/possible-inconsistency-in-symbolic-limits/I was trying to manipulate some symbolic expressions and got an unexpected error.
Here is a minimal example,
u=integrate(x**3/(exp(x)-1),(x,0,oo))
The expression is quite messy, but the result is known. When I try to use any simplification routine, like
u.simplify()
sage displays the error message
RuntimeError: ECL says: Error executing code in Maxima: limit: direction must be either 'plus' or 'minus'; found: _SAGE_VAR_minus
As far I understood, the expression is defining lateral limits by symbolic variables, while maxima handle such limits as strings. If it is the case there is an internal conflict here. Is it the case?cav_rtTue, 19 Jan 2021 19:58:40 -0600https://ask.sagemath.org/question/55370/Ranging the Z axishttps://ask.sagemath.org/question/55355/ranging-the-z-axis/I am plotting arrangements of hyperplanes. Like this one:
H3.<x, y, z> = HyperplaneArrangements(QQ)
A = H3([(1, 2, 1), 0],
[(-4, -3, -2), 0],
[(3, 3, -2), 0],
[(1, -4, 3), 0],
[(-2, 2, 1), 0])
A.plot(ranges=[(-1, 1), (-1, 1)], aspect_ratio=(1, 1, 0.25))
![Hyperplane arrangement](/upfiles/16110758982120743.png)
The problem is I need the z axis to range from -1 to 1 rather than from -4 to 4.
Is there a way to change that?LarsTue, 19 Jan 2021 08:36:01 -0600https://ask.sagemath.org/question/55355/Solving symbolic equations to IntegerModRing(26)https://ask.sagemath.org/question/55359/solving-symbolic-equations-to-integermodring26/ To solve the Hill Cipher a have setup symbolic equations;
R = IntegerModRing(26)
a,b,c,d,x1,x2 = var('k_1,k_2,k_3,k_4,x1,x2')
K = Matrix(SR,[[a,b],[c,d]]); K
print(K)
pl = vector(SR,[1,29])
ci = vector(SR,[8,21])
eq1,eq2 = (K*pl-ci)
pl = vector(SR,[25,22])
ci = vector(SR,[x1,i])
eq3,eq4 = (K*pl-ci)
pl = vector(SR,[7,16])
ci = vector(SR,[x2,19])
eq5,eq6 = (K*pl-ci)
solve((eq1,eq2,eq3,eq4,eq5,eq6), [a,b,c,d,x1,x2])
There is a problem that The symbolic equations are not working modulo 26. For example, the first equation is
k_1 + 29*k_2 - 8
So how can I properly turn them into modulo 26 and solve the equations in modulo 26?
klxTue, 19 Jan 2021 10:21:56 -0600https://ask.sagemath.org/question/55359/Random polynomial of degree 1https://ask.sagemath.org/question/55348/random-polynomial-of-degree-1/Having defined
- the finite field `K` of size 4 in `a`
- a polynomial ring `R1` over `K`
one can ask for a random element using the `random_element` method.
The random polynomial I obtained that way was of degree two:
sage: K.<a> = FiniteField(4)
sage: R1 = PolynomialRing(K, ['z%s' % p for p in range(1, 3)])
sage: R1.random_element()
(a)*z1*z2 + (a + 1)*z2^2 + z1 + (a)*z2
If I only want a random linear polynomial from this ring, how can I get one?Sri1729Tue, 19 Jan 2021 00:00:12 -0600https://ask.sagemath.org/question/55348/Multiply polynomials from different ringshttps://ask.sagemath.org/question/55351/multiply-polynomials-from-different-rings/Suppose I take a polynomial from $K[x]$, say $x^2 + 5x$,
and another polynomial from $K[y]$, say $y^3$.
I want to formally multiply them and get $x^2y^3 + 5xy^3$ as the output.
How can I do that?
Note: `K` is the finite field of size 4 in `a`.
My efforts:
sage: K.<a> = FiniteField(4)
sage: R_1 = PolynomialRing(K, ['z%s' % p for p in range(1, 3)])
sage: R_2 = PolynomialRing(K, ['x%s' % p for p in range(1, 3)])
sage: pp = R_1.random_element()
sage: pp
(a + 1)*z1^2 + (a)*z1*z2 + (a + 1)*z2 + (a)
sage: qq = R_2.random_element()
sage: qq
x1*x2 + (a + 1)*x2^2 + x1 + 1
When I do `pp*qq` I get the following output
unsupported operand parent(s) for *: 'Multivariate Polynomial Ring
in z1, z2 over Finite Field in a of size 2^2' and 'Multivariate Polynomial
Ring in x1, x2 over Finite Field in a of size 2^2'Sri1729Tue, 19 Jan 2021 03:36:55 -0600https://ask.sagemath.org/question/55351/Print scaling factors in eta-productshttps://ask.sagemath.org/question/55347/print-scaling-factors-in-eta-products/I have the useful command:
EtaGroup(8).basis()[0].r(2)
which will return the first exponent in `(eta_2)^-4 (eta_4)^12 (eta_8)^-8`; namely -4. Similarly
EtaGroup(8).basis()[0].r(4)
will return `12` etc. I want to extract the scaling factors though. That is, I want to print 2 or 4 or 8 in the expression `(eta_2)^-4 (eta_4)^12 (eta_8)^-8`
How??
FundamentalDomainMon, 18 Jan 2021 18:03:30 -0600https://ask.sagemath.org/question/55347/"Affine diagonalization algorithm" in n-dimensions?https://ask.sagemath.org/question/55345/affine-diagonalization-algorithm-in-n-dimensions/Does Sage have a general implementation of the "affine diagonalization algorithm"
for n-dimensional vector spaces?
I found some pseudo-code, see page 15 (in section 3 "affine diagonalization" which begins on page 12) of
- [Lecture 21: Surfaces](https://cs.nyu.edu/yap/bks/egc/09/21Surfaces.pdf) in [Robust geometric computation](https://cs.nyu.edu/yap/bks/egc/)
Searching online led me also to this answer from 2008 where someone does it with Maple:
- [Maple primes: Normal forms for quadratic functions](https://www.mapleprimes.com/posts/38766-Normal-Forms-For-Quadratic-Functions)
but unfortunately, I cannot open the `.mws` file (I get an error message concerning the version number).
Thank you very much for the help.BernMon, 18 Jan 2021 12:59:25 -0600https://ask.sagemath.org/question/55345/Centering the cells of a table and the use of tiny sizehttps://ask.sagemath.org/question/55144/centering-the-cells-of-a-table-and-the-use-of-tiny-size/I change my question to clarify.
In the following code (I have integrated the solution for `\tiny`):
First define a function:
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
Then use it:
cand = ["A", "B", "C", "D"]
ne1 = [18, 16, 14, 12, 11, 20, 19, 14, 16, 12, 2, 1, 0, 0, 20, 16, 13, 15, 11, 10, 9, 8, 7, 5]
ne = ne1
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(total_score_de_Borda, header_column=cond3)
show(cond3,total_score_de_Borda)
everything works fine apart from the `header_column=cond3` (without it I have no problem) and as `show(cond3, total_score_de_Borda)` shows, the two elements have the same length.CyrilleWed, 06 Jan 2021 03:11:06 -0600https://ask.sagemath.org/question/55144/Rounding the values of a mappinghttps://ask.sagemath.org/question/55284/rounding-the-values-of-a-mapping/The problem is only with the `round(, 2)` code
f(x)=round((1/add([10, 20 ,30]))*x,2)
percent_votes_cand=list(map(f,[10, 20 ,30]))
percent_votes_cand
This gives an error since `round()` couldn't be applied to a theoretical argument. The following code works but I want to obtain truncated to 2 digits percentages not elements of QCyrilleFri, 15 Jan 2021 08:11:13 -0600https://ask.sagemath.org/question/55284/