ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 19 Apr 2021 23:01:41 +0200How to install sage to one existing virtualenv?https://ask.sagemath.org/question/56736/how-to-install-sage-to-one-existing-virtualenv/Hi there, I'm kind of new to sage. I have an existing python virtualenv managed by pyenv used by my jupyter notebook. I'd like to install sage to this existing python3 env so that my jupyter notebooks can immediately import sage and use it. I'm wondering how I should do this.
Thank you!reapor_yurneroMon, 19 Apr 2021 23:01:41 +0200https://ask.sagemath.org/question/56736/Quotient of polynomial ring over integers not workinghttps://ask.sagemath.org/question/56734/quotient-of-polynomial-ring-over-integers-not-working/I have a problem. I want Sage to calculate in $\mathbb Z[x]/\langle4,2x,x^2\rangle$ but none of the relations are being calculated/recognized properly:
sage: R.<x> = ZZ[]
sage: I = R.ideal(4,2*x,x^2)
sage: S.<a> = R.quotient(I)
sage: a^2 # the output should be 0
a^2
sage: 2*a # the output should be 0
2*a
sage: S(2)+S(2) # the output should be 0
4
When I introduce a superfluous variable $y$ and consider $\mathbb Z[x,y]/\langle4,2x,x^2,y\rangle$ instead, which is practically the same ring (i.e. isomorphic), then it seems to work:
sage: R.<x,y> = ZZ[]
sage: I = R.ideal(4,2*x,x^2,y)
sage: S.<a,b> = R.quotient(I)
sage: a^2
0
sage: 2*a
0
sage: S(2)+S(2)
0
But now look at this:
sage: S(2)+S(3) # the output should be 1
5
How can I solve this problem?ThrashMon, 19 Apr 2021 22:33:39 +0200https://ask.sagemath.org/question/56734/What implementation does sage use for solve?https://ask.sagemath.org/question/56730/what-implementation-does-sage-use-for-solve/What algorithm does sage use when you solve polynomials with the solve() function? MathAllOverThePlaceMon, 19 Apr 2021 20:48:21 +0200https://ask.sagemath.org/question/56730/Differential operatorhttps://ask.sagemath.org/question/56728/differential-operator/Assuming:
f(x) = 3*x
g(x) = 4*x
m = matrix([[f],[g]])
Is it possible to define L as:
L M
[d/dx] * m = [3]
[4]
?zannasMon, 19 Apr 2021 12:00:41 +0200https://ask.sagemath.org/question/56728/Why don't log rules work for symbolic values?https://ask.sagemath.org/question/56724/why-dont-log-rules-work-for-symbolic-values/Log rules are working for actual values, but fail for symbolic ones. What am I doing wrong?
var('a b')
c = bool(log(a*b) == log(a) + log(b));print(c)
c = bool(log(5*3) == log(5) + log(3));print(c)
c = log(5*3).n(); print(c)
c = log(5).n() + log(3).n(); print(c)
False
False
2.70805020110221
2.70805020110221cybervigilanteMon, 19 Apr 2021 06:17:20 +0200https://ask.sagemath.org/question/56724/Running a for cycle in parallelhttps://ask.sagemath.org/question/56692/running-a-for-cycle-in-parallel/I have an algorithm that I need to speed up.
I would like to parallelize computations
the main part I need to speed up is the following
> for r2 in Subsets(V2,k-4):
check2(fuse(v,r2),k)
this gives as output three values b1, b2, b3 that are global and for any input check2 can either leave them unchanged or increase them by 1.
I tried looking into @parallel but it doens't seem to fit my requirements.
How can I parallelize that (I can use up to 16 cores)?
This is the whole code (minus all the parts that do, I can't publish it all):
P2=[]
def P_2(q,n,S): %creates the set P2
I2R=[]
I2S=[]
I3=[]
I3R=[]
I6=[]
I8=[]
def IG(k): %creates a set of indeces vectors
def coll(x,y,z): %checks if 3 given tuples are collinear
A=[x,y,z]
M = matrix(A)
if M.determinant()==0:
return 'true'
def cone(v): %defines a function to be used in conic()
def conic(x1,x2,x3,x4,x5,x6): %checks if 6 given tuples are on a conic
A=[cone(x1),cone(x2),cone(x3),cone(x4),cone(x5),cone(x6)]
M = matrix(A)
if M.determinant()==0:
return 'true'
def cube(v): %defines a function to be used in SIcubic()
def dxcube(v): %defines a function to be used in SIcubic()
def dycube(v): %defines a function to be used in SIcubic()
def dzcube(v): %defines a function to be used in SIcubic()
def SIcubic(x1,x2,x3,x4,x5,x6,x7,x8): %checks if 8 given tuples are on a special cubic
v1='false'
v=[x1,x2,x3,x4,x5,x6,x7,x8]
for a in range(8):
x=v[a]
A=[]
A.append(dxcube(x))
A.append(dycube(x))
A.append(dzcube(x))
for t in range(8):
if t!=a:
y=v[t]
A.append(cube(y))
M = matrix(A)
if M.determinant()==0:
v1='true'
return v1
b1=0
b2=0
b3=0
def check(s,k): %checks a vector s of lenght k
global b1
global b2
global b3
IG(k)
q1=0
q2=0
q3=0
for i3 in I3:
a0=i3[0]
a1=i3[1]
a2=i3[2]
if coll(s[a0],s[a1],s[a2])=='true':
q1=1
q2=1
q3=1
break
if q2==0:
if k>5:
if q==0:
for i6 in I6:
a0=i6[0]
a1=i6[1]
a2=i6[2]
a3=i6[3]
a4=i6[4]
a5=i6[5]
if conic(s[a0],s[a1],s[a2],s[a3],s[a4],s[a5])=='true':
q2=1
q3=1
break
if q3==0:
if k>7:
for i8 in I8:
a0=i8[0]
a1=i8[1]
a2=i8[2]
a3=i8[3]
a4=i8[4]
a5=i8[5]
a6=i8[6]
a7=i8[7]
if SIcubic(s[a0],s[a1],s[a2],s[a3],s[a4],s[a5],s[a6],s[a7])=='true':
q3=1
break
b1=b1+q1
b2=b2+q2
b3=b3+q3
return b1
return b2
return b3
b1=0
def check1(s,a): %checks a vector s and an element a
global b1
q1=0
for i2 in I2S:
a0=i2[0]
a1=i2[1]
if coll(s[a0],s[a1],a)=='true':
q1=1
break
b1=b1+q1
return b1
b1=0
b2=0
b3=0
def check2(s,k): %checks a vector s of lenght k
global b1
global b2
global b3
q1=0
q2=0
q3=0
for i3 in I3R:
a0=i3[0]
a1=i3[1]
a2=i3[2]
if coll(s[a0],s[a1],s[a2])=='true':
q1=1
q2=1
q3=1
break
if q2==0:
if k>5:
for i6 in I6:
a0=i6[0]
a1=i6[1]
a2=i6[2]
a3=i6[3]
a4=i6[4]
a5=i6[5]
if conic(s[a0],s[a1],s[a2],s[a3],s[a4],s[a5])=='true':
q2=1
q3=1
break
if q3==0:
if k>7:
for i8 in I8:
a0=i8[0]
a1=i8[1]
a2=i8[2]
a3=i8[3]
a4=i8[4]
a5=i8[5]
a6=i8[6]
a7=i8[7]
if SIcubic(s[a0],s[a1],s[a2],s[a3],s[a4],s[a5],s[a6],s[a7])=='true':
q3=1
break
b1=b1+q1
b2=b2+q2
b3=b3+q3
return b1
return b2
return b3
t=1
def TOT(P,q,n,k): %computes a polynomial depending on q,n,k,P
def fuse(s,t): %fuses two vectors into 1 (see repsonse to answere)
sn=[]
def Count(S,q,n,k): %main function
IG(k)
global b1
global b2
global b3
l1=0
l2=0
l3=0
y=q^n
s=len(S)
v=[(0,0,1),(0,1,0),(1,0,0),(1,1,1)]
V1=copy(S)
V1.remove((1,0,0))
V1.remove((0,1,0))
V1.remove((0,0,1))
V1.remove((1,1,1))
if k<4:
b1=0
for s in Subsets(S,k):
check(s,k)
l1=b1*factorial(k)
if k>4:
V2=copy(V1)
for r1 in V1:
b1=0
b2=0
b3=0
check1(v,r1)
if b1==1:
V2.remove(r1)
s2=len(V2)
l1=l1+binomial(s-4,k-4)-binomial(s2,k-4)
l2=l2+binomial(s-4,k-4)-binomial(s2,k-4)
l3=l3+binomial(s-4,k-4)-binomial(s2,k-4)
b1=0
b2=0
b3=0
for r2 in Subsets(V2,k-4):
check2(fuse(v,r2),k)
l1=l1+b1
l2=l2+b2
l3=l3+b3
l1=l1*(y^2+y+1)*(y^3-y)*(y^3-y^2)*factorial(k-4)
l2=l2*(y^2+y+1)*(y^3-y)*(y^3-y^2)*factorial(k-4)
l3=l3*(y^2+y+1)*(y^3-y)*(y^3-y^2)*factorial(k-4)
g1=t-l1
g2=t-l2
g3=t-l3
print('There are ', g1/factorial(k) , ' unordered', k,'-tuples in general linear position')
print('There are ', g1 , ' ordered', k ,'-tuples in general linear position')
print('There are ', g2/factorial(k) , ' unordered', k,'-tuples in general linear and conic position')
print('There are ', g2 , ' ordered', k ,'-tuples in general linear and conic position')
print('There are ', g3/factorial(k) , ' unordered', k,'-tuples in general position')
print('There are ', g3 , ' ordered', k ,'-tuples in general position')
def Active(q,n,k): %every fucntion I need to run reduced into 1
P2=[]
P_2(q,n,P2)
TOT(P2,q,n,k)
Count(P2,q,n,k)Alain NgalaniSat, 17 Apr 2021 19:21:14 +0200https://ask.sagemath.org/question/56692/Computing the factored multiplicative order of an extension field tries to solve an unnecessarily hard factoring problemhttps://ask.sagemath.org/question/56710/computing-the-factored-multiplicative-order-of-an-extension-field-tries-to-solve-an-unnecessarily-hard-factoring-problem/There seems to be a unnecessary performance problem with constructing large extension fields:
sage: p = 0x24000000000024000130e0000d7f70e4a803ca76f439266f443f9a5cda8a6c7be4a7a5fe8fadffd6a2a7e8c30006b9459ffffcd300000001
sage: GF(p^2)
This hangs trying to factor the 891-bit integer $p^2 - 1$, which is longer than the longest solved RSA Challenge number. (As it happens, the hard part of this factorization is a 675-bit integer which is still impractical.)
It is not unreasonable that constructing the extension field requires knowing the factorization of the multiplicative order. (You can get around this by constructing it with a specific modulus, but then many operations, e.g. taking roots, require this factorization anyway.)
However, we know that $p^2 - 1$ splits as $(p-1)(p+1)$, and factoring those may be much more feasible:
sage: factor(p-1)
2^32 * 3^4 * 17 * 67 * 293 * 349 * 1997 * 19556633 * 44179799701097 * 1461985442088199434216480729118540833655826472878315075486478169293801719414121837587283877
sage: factor(p+1)
2 * 313 * 751 * 2003 * 2671 * 738231097 * 55047696457335561580180364861378466840614260303507426009866606293225963076275651294902969015038913167956483928299
(this takes less than a second on my desktop).
In general, computing the multiplicative order of an extension field should take advantage of the factorization of $p^k - 1$ as a polynomial. There might also be other cases where we know the factorization by construction, and should be able to provide it.dairaSun, 18 Apr 2021 12:48:15 +0200https://ask.sagemath.org/question/56710/Formatting plot titlehttps://ask.sagemath.org/question/56685/formatting-plot-title/ I am not able to find formatting options for `title` for `plot`. Here's the code,
p1 = plot(fresnel_sin(t), (t, -pi, pi), ticks=[pi/4,0.1], tick_formatter=[pi,None], legend_label=r'$f(x) = \int_0^x \sin(\frac{\pi t^2}{2})dt$', axes_labels=[r'$x$', r'$f(x)$'], axes_labels_size=1.5, title='Fresnel\'s sin', title_pos=(0.5,1.1))
p1.set_legend_options(back_color=(0.9,0.9,0.9), shadow=False, font_size=14, loc=(0,0.7))
p1.show()
The `title` font is relatively small, I am not able to change it without making it look displeasing. I've tried the following modification,
p1 = plot(fresnel_sin(t), (t, -pi, pi), ticks=[pi/4,0.1], tick_formatter=[pi,None], legend_label=r'$f(x) = \int_0^x \sin(\frac{\pi t^2}{2})dt$', axes_labels=[r'$x$', r'$f(x)$'], axes_labels_size=1.5)
p1.set_legend_options(back_color=(0.9,0.9,0.9), shadow=False, font_size=14, loc=(0,0.7))
p2 = text('Fresnel\'s sin ', (1.5, 0.9), fontsize=14, color='black')
p1 + p2
But it's not what I want. Using `text` doesn't seem to do it(or so I think). Need some help here :).debojit2178Sat, 17 Apr 2021 12:59:34 +0200https://ask.sagemath.org/question/56685/Obtaining the polynomial given its list of coefficients while using SageMath as an imported library in pythonhttps://ask.sagemath.org/question/56698/obtaining-the-polynomial-given-its-list-of-coefficients-while-using-sagemath-as-an-imported-library-in-python/ Hi,
I have imported the SageMath library in my python code.
If I have a list
`[1,5,4,5,22,0,0,1]`
And I need to generate a 7th degree polynomial from this, how should I proceed?
I tried using the methods given online, but it either crashes or gives me a clearly wrong answer ( I'm trying to find all the real roots by using `real_roots()` or `roots()` )
Any help would be appreciated.KanaadSat, 17 Apr 2021 21:00:39 +0200https://ask.sagemath.org/question/56698/Construct polynomial ring from list of variableshttps://ask.sagemath.org/question/56699/construct-polynomial-ring-from-list-of-variables/In constructing polynomial rings, documentation says that diamond brackets are used "to make the variable ready for use after you define the ring", but the variables are entered explicitly: `R.<x,y>` .
What if I have a list of (an unknown number of) variables?
E.g. if I have xs = [x_1,x_2,x_3], I want to construct a polynomial ring and subsequently manipulate x_1 + x_2, etc., within that ring instead of "symbolic ring". I'd like to do something like `R.<xs>` but that doesn't seem to work.weafpiojasdfSun, 18 Apr 2021 03:19:54 +0200https://ask.sagemath.org/question/56699/xmin and xmax doesn't work within parametric plot.https://ask.sagemath.org/question/56701/xmin-and-xmax-doesnt-work-within-parametric-plot/ Restricting the range with `xmin` and `xmax` doesn't work with parametric plot. Here's the code,
cs_01 = parametric_plot([fresnel_cos(t), fresnel_sin(t)], (t, -1.5*pi, 1.5*pi), ticks=[pi/8, 0.2], tick_formatter=[pi, None], axes_labels=['$x(t)$', '$y(t)$'], axes_labels_size=1.5, plot_points=500, xmin=-pi/4, xmax=pi/4, ymin=-0.8, ymax=0.8, fontsize=12)
cs_01_text_01 = text(r'$x(t) = \int_0^t\cos(\frac{\pi u^2}{2})du$', (-pi/2,0.8), fontsize=13, color='black', bounding_box={'boxstyle':'round', 'fc':(0.9,0.9,0.9), 'ec':'w'})
cs_01_text_02 = text(r'$y(t) = \int_0^t\sin(\frac{\pi u^2}{2})du$', (-pi/2,0.4), fontsize=13, color='black', bounding_box={'boxstyle':'round', 'fc':(0.9,0.9,0.9), 'ec':'w'})
cs_01_text_03 = text('Clothoid or Cornu spiral', (0, 1.15), fontsize=14, color='black', fontweight='bold')
cs_01 + cs_01_text_01 + cs_01_text_02 + cs_01_text_03
But when provided within `show` it works,
cs_01 = parametric_plot([fresnel_cos(t), fresnel_sin(t)], (t, -1.5*pi, 1.5*pi), ticks=[pi/8, 0.2], tick_formatter=[pi, None], axes_labels=['$x(t)$', '$y(t)$'], axes_labels_size=1.5, plot_points=500, ymin=-0.8, ymax=0.8, fontsize=12) + \
text(r'$x(t) = \int_0^t\cos(\frac{\pi u^2}{2})du$', (-pi/2,0.8), fontsize=13, color='black', bounding_box={'boxstyle':'round', 'fc':(0.9,0.9,0.9), 'ec':'w'}) + \
text(r'$y(t) = \int_0^t\sin(\frac{\pi u^2}{2})du$', (-pi/2,0.4), fontsize=13, color='black', bounding_box={'boxstyle':'round', 'fc':(0.9,0.9,0.9), 'ec':'w'}) + \
text('Clothoid or Cornu spiral', (0, 1.15), fontsize=14, color='black', fontweight='bold')
cs_01.show(xmin=-pi/4, xmax=pi/4)
I don't know why it's happening. Is it supposed to work like that?debojit2178Sun, 18 Apr 2021 04:58:43 +0200https://ask.sagemath.org/question/56701/optimize matrix elements to obtain certain eigenvalueshttps://ask.sagemath.org/question/56693/optimize-matrix-elements-to-obtain-certain-eigenvalues/Greetings to all,
someone could tell me if possible (and what I should learn, where I should start looking) to solve the following problem:
I have built a Matrix: (its a dynamical matrix build from force constants matrices), the elements of the matrix are symbolic expressions that depends of certain variables (in particular unknown force constants). I know the eigenvalues of this matrix at certain "points of 2 coordinates" (coordinates are variables of the expression that defines the elements of the array).
So, solving a linear system of equations (the equations are determinated by the "expression that sage return for the eigenvalues at these points" == "and the experimental eigenvalue that i measured") i get a numeric value for the variables (that's what my problem is all about).
But the problem is that the values of my own correspond to experimental values, and so I have achieved good constants for 4 points, but I need to adjust them to a set of values of my own, to a curve (the curve -its not only only are a set of curves- is the relation dispersion for bidimensional materials, graphene, BN, etc.) . So i need adjust the values of constants for optimize the adjust to the curve
We can consider a 2x2 matrix, D, and its elements depend of the constants alpha1, alpha2, alpha3 and alpha4, and the point where it's evaluated (q_x, q_y). Well i know that at point (0,0) the eigenvalues are 0 and 830, so i obtain the equation for the eigenvalues:
-6*(alpha1+alpha2)= 630; 0=0
and other equations at other points (at simetric points of first Brilluin Zone). Sagemath solves the linear system of equations an i can determine the constans. Then I rewrite the D matrix with the constants determined (alpha1=1.4, alpha2=2.5, and so ...), and obtain the eigenvalues of the D matrix at other points (pairs of q_x, q_y): the matrix still depends on the points [q_x, q_y]. So, what i want is, starting with the initial value of the constants that i obtained from first points, adjust them so that the matrix's eigenvalues best fit the experimental eigenvalues that i have.
On page 13 of [Noebook-Casimir.pdf](https://github.com/CasimirVictoria/TFG-Semiconductores_2D/blob/master/Notebook-Casimir.pdf) you can see what i mean.CasimirVictoriaSat, 17 Apr 2021 19:22:37 +0200https://ask.sagemath.org/question/56693/Segmentation fault calling is_irreducible()https://ask.sagemath.org/question/56676/segmentation-fault-calling-is_irreducible/ sage: R.<X> = PolynomialRing(GF(17^2))
sage: (X^2).is_irreducible()
---------------------------------------------------------------------------
SignalError Traceback (most recent call last)
<ipython-input-143-f9ef3e37d5e5> in <module>
----> 1 (X**Integer(2)).is_irreducible()
/usr/lib/python3/dist-packages/sage/rings/polynomial/polynomial_zz_pex.pyx in sage.rings.polynomial.polynomial_zz_pex.Polynomial_ZZ_pEX.is_irreducible (build/cythonized/sage/rings/polynomial/polynomial_zz_pex.cpp:16857)()
350 self._parent._modulus.restore()
351 if algorithm=="fast_when_false":
--> 352 sig_on()
353 res = ZZ_pEX_IterIrredTest(self.x)
354 sig_off()
SignalError: Segmentation fault
sage: version()
'SageMath version 9.2, Release Date: 2020-10-24'
dairaFri, 16 Apr 2021 20:10:00 +0200https://ask.sagemath.org/question/56676/Reset interact control between two useshttps://ask.sagemath.org/question/56682/reset-interact-control-between-two-uses/I use *interact* and between two evaluation, I would like the control to come back to its default position, how could I do that?
Here is a simplified example:
a = 0
@interact
def _(b = selector([(-1,""),(0,"0"),(1,"1"),(2,"2")]), auto_update=False):
global a
if b != -1:
a = a + b
print(a)
I would like the selector to come back to the position (-1,"") after an evaluation.
Would someone know how to do that?SBSat, 17 Apr 2021 09:08:44 +0200https://ask.sagemath.org/question/56682/¿Cómo se puede pasar variables del script de sage en la plantilla html a otro script?https://ask.sagemath.org/question/56680/como-se-puede-pasar-variables-del-script-de-sage-en-la-plantilla-html-a-otro-script/Quisiera saber si existe la posibilidad de pasar las variables que se hacen dentro del <script type="text/x-sage"></script> a otro script como <script type="text/javascript"></script>
Si existe la posibilidad quisiera saber como hacerlo
Muchas GraciasJhon MinaSat, 17 Apr 2021 04:54:06 +0200https://ask.sagemath.org/question/56680/matrix_plot not returning any outputs in subroutineshttps://ask.sagemath.org/question/56666/matrix_plot-not-returning-any-outputs-in-subroutines/ A=identity_matrix(2)
def f(n):
matrix_plot(n*A)
f(5)
I'm puzzled as the command `matrix_plot(5*A)` works fine on itself, but it produces no output when it goes inside a subroutine as in the above SageMath code.
I'd appreciate any help with understanding why this is so/resolving this.
PS I have tested this both on Sagecell.sagemath.org and a local installation.
user2021Thu, 15 Apr 2021 22:56:30 +0200https://ask.sagemath.org/question/56666/Cannot evaluate symbolic expression to a numerical valuehttps://ask.sagemath.org/question/56672/cannot-evaluate-symbolic-expression-to-a-numerical-value/ I'm trying to do this:
```
(sqrt(10*y*(10-y))+sqrt(1000)*acos(sqrt(y/10))-15*sqrt(2*6.673*10^(-11)*50000000000)).roots( ring=RealField(100))
```
Unfortunately I get the error in the title.
Also any other way of solving the above equation numerically would be appreciated. I was able to do it in maxima using `find_root` but was hoping for a better function (one that doesn't require specifying an interval). I couldn't use find_root in sage because it returns the error 'unable to simplify to float approximation' and ofcourse `solve` doesn't return explicit solutions.Dr. BananaFri, 16 Apr 2021 17:06:47 +0200https://ask.sagemath.org/question/56672/Sagemath and Jsxgraph inside the same html filehttps://ask.sagemath.org/question/56671/sagemath-and-jsxgraph-inside-the-same-html-file/I am perfectly aware that this is a border question. `@animate` is very slow. This renders it pratically unusable in case of delegating the work on html sheet. So I have tried to use `Jsxgraph` which looks nice. All works as expected and I can add here my html file if some one is interested.
But I have a problem, `mathjax` doesnt display properly inside `Jsxgraph`.
Is there some one interested to help me to solve this problem ? I do not know if this is a specific problem or an interaction between the two.CyrilleFri, 16 Apr 2021 15:49:37 +0200https://ask.sagemath.org/question/56671/How can I request the cooperation of sagemath mathematicians and programmers for a project?https://ask.sagemath.org/question/56614/how-can-i-request-the-cooperation-of-sagemath-mathematicians-and-programmers-for-a-project/My name is Alberico Lepore and I am an aspiring self-taught amateur and for about six years I have been looking for factorization in computationally acceptable times.
I have come to the point of verifying that resolving the type of systems listed below resolves the factorization.
Here you will find my work:
https://www.linkedin.com/feed/update/urn:li:ugcPost:6777160628965535744/
or
https://github.com/Piunosei/gerva_factorization/blob/main/Transformation-of-the-factorization-problem-into-a-problem-of-solving-a-non-linear-system%20(5).pdf
Is written:
- in an almost unpresentable way
- the case x odd is missing
- (*) and is redundant
(*) as it is possible to establish the range of log_2 (x) and log_2 (y)
My problem is to solve the resulting nonlinear system.
all small variables belong to Z
all big variables belong to N
If N = p * q and p + q = 8 * x + 4 then q-p = 4 * y-2 then
p = (4*x+1-2*(y-1))
q = (4*x+3+2*(y-1))
let's study the case
x is even and y is odd
Examples N=8979
(x+1+1)/2 is even then a = 1-(x+1+1)/2
(x+1+1)/2 is even odd a = (x+1+1)/2
(|a|+1)/2 is even then b = 1-(|a|+1)/2
(|a|+1)/2 is even odd b = (|a|+1)/2
(|b|+1)/2 is even then c = 1-(|b|+1)/2
(|b|+1)/2 is even odd c = (|b|+1)/2
(|c|+1)/2 is even then -1 = 1-(|c|+1)/2
(|c|+1)/2 is even odd -1 = (|c|+1)/2
then
16 <= x <= 30
S>D
D>C
C>B
B>A
A>M
and
(y+1)/2 is even then v = 1-(y+1)/2
(y+1)/2 is even odd v = (y+1)/2
(|v|+1)/2 is even then u = 1-(|v|+1)/2
(|v|+1)/2 is even odd u = (|v|+1)/2
(|u|+1)/2 is even then -1 = 1-(|u|+1)/2
(|u|+1)/2 is even odd -1 = (|u|+1)/2
then
9 <= y <= 15
S>T
T>U
U>V
V>(3*N-1)/8
then this system will have a single solution
var('N p q x y M a b c A B C D u v S T U V')
eq0 = N-8979 == 0
eq1 = 3*(((2*(3*N-1)/8-3*y+1)/24)+3*x*(x+1)/2)+1-V == 0
eq2 = -(3*N-1)/8+3*x*(x+1)/2-3*y*(y-1)/2+(3*x+1)*(3*x+2)/2 == 0
eq3 = 3*(((2*V-3*v+1)/24)+3*x*(x+1)/2)+1-U == 0
eq4 = V+3*v*(v-1)/2-12*x*(x+1)/2-1 == 0
eq5 = 3*(((2*U-3*u+1)/24)+3*x*(x+1)/2)+1-T == 0
eq6 = U+3*u*(u-1)/2-12*x*(x+1)/2-1 == 0
eq7 = 3*(((2*T+3+1)/24)+3*x*(x+1)/2)+1-S == 0
eq8 = T+3-12*x*(x+1)/2-1 == 0
eq9 = 3*(((2*S-3*1+1)/24)+3*x*(x+1)/2)+1-S == 0
eq10 = v*(v-1)/2 -(y-1)*(y+1)/8 == 0
eq11 = u*(u-1)/2 -(v-1)*(v+1)/8 == 0
eq12 = 1 -(u-1)*(u+1)/8 == 0
eq13 = a*(a-1)/2 -(x+1-1)*(x+1+1)/8 == 0
eq14 = b*(b-1)/2 -(a-1)*(a+1)/8 == 0
eq15 = c*(c-1)/2 -(b-1)*(b+1)/8 == 0
eq16 = 1 -(c-1)*(c+1)/8 == 0
eq18 = -M+9*((2*(3*N-1)/8 - 3*y + 1)/24+(y-1)*(y+1)/8)+1 == 0
eq19 = 3*((2*M - 3*(x+1) + 1)/24 + (3*x*(x + 1))/2) + 1 - A == 0
eq20 = -M + (3*x*(x + 1))/2 - (3*x*(x + 1))/2 + ((3*x + 1)*(3*x + 2))/2 == 0
eq21 = 3*((2*A - 3*a + 1)/24 + (3*x*(x + 1))/2) + 1 - B == 0
eq22 = A + (3*a*(a - 1))/2 - (12*x*(x + 1))/2 - 1 == 0
eq23 = 3*((2*B - 3*b + 1)/24 + (3*x*(x + 1))/2) + 1 - C == 0
eq24 = B + (3*b*(b - 1))/2 - (12*x*(x + 1))/2 - 1 == 0
eq25 = 3*((2*C - 3*c + 1)/24 + (3*x*(x + 1))/2) + 1 - D == 0
eq26 = C + (3*c*(c - 1))/2 - (12*x*(x + 1))/2 - 1 == 0
eq26 = 3*((2*D + 3 + 1)/24 + (3*x*(x + 1))/2) + 1 - S == 0
eq27 = D + 3 - (12*x*(x + 1))/2 - 1 == 0
eq28 = 3*((2*S - 3*1 + 1)/24 + (3*x*(x + 1))/2) + 1 - S == 0
eq29 = p - (4*x+1-2*(y-1)) == 0
eq30 = q - (4*x+3+2*(y-1)) == 0
solutions = solve([eq0,eq1,eq2,eq3,eq4,eq5,eq6,eq7,eq8,eq9,eq10,eq11,eq12,eq13,eq14,eq15,eq16,eq18,eq19,eq20,eq21,eq22,eq23,eq24,eq25,eq26,eq27,eq28,eq29,eq30],N,p,q,x,y,M,a,b,c,A,B,C,D,u,v,S,T,U,V)
sol = solutions
print(sol)
OUTPUT
(N, p, q, x, y, M, a, b, c, A, B, C, D, u, v, S, T, U, V)
[
[N == 8979, p == 73, q == 123, x == 24, y == 13, M == 2701, a == 13, b == 7, c == -3, A == 3367, B == 3538, C == 3583, D == 3598, u == -3, v == 7, S == 3601, T == 3598, U == 3583, V == 3538]
]
Will you kindly help me to solve this non-linear system in the lowest possible computational cost?
***************************************************************************************
EDIT:
after @vdelecroix replied, I found this other way
import time
Start_Time = time.time()
var('N p q x y M a b c A B C D u v S T U V')
eq0 = N-8979 == 0
eq1 = 3*(((2*(3*N-1)/8-3*y+1)/24)+3*x*(x+1)/2)+1-V == 0
eq2 = -(3*N-1)/8+3*x*(x+1)/2-3*y*(y-1)/2+(3*x+1)*(3*x+2)/2 == 0
eq3 = 3*(((2*V-3*v+1)/24)+3*x*(x+1)/2)+1-U == 0
eq4 = V+3*v*(v-1)/2-12*x*(x+1)/2-1 == 0
eq5 = 3*(((2*U-3*u+1)/24)+3*x*(x+1)/2)+1-T == 0
eq6 = U+3*u*(u-1)/2-12*x*(x+1)/2-1 == 0
eq7 = 3*(((2*T+3+1)/24)+3*x*(x+1)/2)+1-S == 0
eq8 = T+3-12*x*(x+1)/2-1 == 0
eq18 = -M+9*((2*(3*N-1)/8 - 3*y + 1)/24+(y-1)*(y+1)/8)+1 == 0
eq19 = 3*((2*M - 3*(x+1) + 1)/24 + (3*x*(x + 1))/2) + 1 - A == 0
eq20 = -M + (3*x*(x + 1))/2 - (3*x*(x + 1))/2 + ((3*x + 1)*(3*x + 2))/2 == 0
eq21 = 3*((2*A - 3*a + 1)/24 + (3*x*(x + 1))/2) + 1 - B == 0
eq22 = A + (3*a*(a - 1))/2 - (12*x*(x + 1))/2 - 1 == 0
eq23 = 3*((2*B - 3*b + 1)/24 + (3*x*(x + 1))/2) + 1 - C == 0
eq24 = B + (3*b*(b - 1))/2 - (12*x*(x + 1))/2 - 1 == 0
eq25 = 3*((2*C - 3*c + 1)/24 + (3*x*(x + 1))/2) + 1 - D == 0
eq26 = C + (3*c*(c - 1))/2 - (12*x*(x + 1))/2 - 1 == 0
eq26 = 3*((2*D + 3 + 1)/24 + (3*x*(x + 1))/2) + 1 - S == 0
eq27 = D + 3 - (12*x*(x + 1))/2 - 1 == 0
eq29 = p - (4*x+1-2*(y-1)) == 0
eq30 = q - (4*x+3+2*(y-1)) == 0
eq31 =(3*N-1)/8+3*(y*(y-1)/2-(v^2-v)/2) -V == 0
eq32 =(3*N-1)/8+3*(y*(y-1)/2-(u^2-u)/2) -U == 0
eq33 =(3*N-1)/8+3*(y*(y-1)/2-1) - T == 0
eq34 =(3*N-1)/8+3*(y*(y-1)/2) - S == 0
eq35 =M+3*(x*(x+1)/2-(a^2-a)/2) -A == 0
eq36 =M+3*(x*(x+1)/2-(b^2-b)/2) -B == 0
eq37 =M+3*(x*(x+1)/2-(c^2-c)/2) -C == 0
eq38 =M+3*(x*(x+1)/2-1) -D == 0
solutions = solve([eq0,eq1,eq2,eq3,eq4,eq5,eq6,eq7,eq8,eq18,eq19,eq20,eq21,eq22,eq23,eq24,eq25,eq26,eq27,eq29,eq30,eq31,eq32,eq33,eq34,eq35,eq36,eq37,eq38],N,p,q,x,y,M,a,b,c,A,B,C,D,u,v,S,T,U,V)
sol = solutions
Execution_Time = time.time() - Start_Time
print (Execution_Time)
print(sol)
OUTPUT on my old computer
(N, p, q, x, y, M, a, b, c, A, B, C, D, u, v, S, T, U, V)
1.2627530097961426
[
[N == 8979, p == 73, q == 123, x == 24, y == 13, M == 2701, a == 13, b == 7, c == -3, A == 3367, B == 3538, C == 3583, D == 3598, u == -3, v == 7, S == 3601, T == 3598, U == 3583, V == 3538]
]P_1_6Sun, 11 Apr 2021 11:55:34 +0200https://ask.sagemath.org/question/56614/What is the philosophy behind mathematics?https://ask.sagemath.org/question/56668/what-is-the-philosophy-behind-mathematics/ I’ve always been very bad at understanding mathematics and very good at understanding philosophy so I figured that perhaps by learning what mathematics is philosophically I might be able to better understand mathematics.
I think people with different types of intelligences view reality differently. I would say that a top world athlete and a top world scientist view reality differently for example. I want to view reality how a mathematician does to help my ability to do mathematics.andrew81Fri, 16 Apr 2021 10:26:35 +0200https://ask.sagemath.org/question/56668/Why `unable to convert (sin(h(x)), cos(h(x))) to a symbolic expression`?https://ask.sagemath.org/question/52289/why-unable-to-convert-sinhx-coshx-to-a-symbolic-expression/ f(x) = (sin(x), cos(x))
h = function('h', nargs=1)
f(h(x))
works fine and produces (sin(h(x)), cos(h(x))). However, if I try to assign that to a function:
g(x) = f(h(x))
TypeError: unable to convert (sin(h(x)), cos(h(x))) to a symbolic expression
How can I compose functions like this?martincmartinWed, 01 Jul 2020 22:42:06 +0200https://ask.sagemath.org/question/52289/Ring not recognized as a PIDhttps://ask.sagemath.org/question/56648/ring-not-recognized-as-a-pid/I need to work with finitely generated modules over a PID, which the localization at a prime of the ring of Gaussian integers. It happens to be a PID, but if I try to execute the following code:
K.<i> = NumberField(x^2 + 1)
R = K.maximal_order().localization(7)
MS = span([[0, 1, 0]], R)
I get this error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-41-97a6c80cace8> in <module>
----> 1 MS = span([[Integer(0),Integer(1),Integer(0)]],R)
/opt/sagemath-9.2/local/lib/python3.7/site-packages/sage/modules/free_module.py in span(gens, base_ring, check, already_echelonized)
686 if R not in PrincipalIdealDomains():
687 raise TypeError("The base_ring (= %s) must be a principal ideal "
--> 688 "domain." % R)
689 if not gens:
690 return FreeModule(R, 0)
TypeError: The base_ring (= Gaussian Integers in Number Field in i with defining polynomial x^2 + 1 localized at (7,)) must be a principal ideal domain.
I have tried with `R = K.maximal_order()` and `R = ZZ.localization(5)`, but they yield similar errors. So I understand that Sage doesn't automatically recognize those rings as PIDs, even though they are and there is a constructive way to find the generator of an ideal.
Is there a way for me to get Sage to see my ring as a PID?Mickaël MontessinosWed, 14 Apr 2021 08:23:43 +0200https://ask.sagemath.org/question/56648/Power Series Ring over p-adics: TypeError: unhashablehttps://ask.sagemath.org/question/56581/power-series-ring-over-p-adics-typeerror-unhashable/I'm trying to construct a power series with coefficients in an Eisenstein extension of Qq, the unramified extension of the p-adic rationals. The following code works when a=1, but when a=2, I get the error: "TypeError: unhashable type: 'sage.rings.padics.qadic_flint_CR.qAdicCappedRelativeElement'".
p = 3
a = 2
ZZq.<xi> = Qq(p^a)
R.<x_pi> = ZZq[]
Zpi.<pi> = QuotientRing(R, R.ideal(x_pi^(p-1)+p))
L.<x> = PowerSeriesRing(Zpi)
Does anyone know a way to fix this for a>1?
Thank you!Alboin.matt@gmail.comFri, 09 Apr 2021 22:05:41 +0200https://ask.sagemath.org/question/56581/Moving a shift entered result as a code in another filehttps://ask.sagemath.org/question/56645/moving-a-shift-entered-result-as-a-code-in-another-file/So suppose I did tons of code and end up with this result.
![C:\fakepath\Screenshot (82).png](/upfiles/16183768387013993.png)
I want to use this result in a new code, say another new file.
If I copy and paste this, it would not work as I would have to
manually put parenthesis around each exponent. Is there
some way to convert this output to code (basically the polynomials
with the parenthesis on the exponents) and transport it to another file?whatupmattWed, 14 Apr 2021 07:08:38 +0200https://ask.sagemath.org/question/56645/How to find and plot both steady periodic solution and actual solution?https://ask.sagemath.org/question/56632/how-to-find-and-plot-both-steady-periodic-solution-and-actual-solution/ Hi!
I haven't been able to figure out how to do this in Sage,
Let's say I have the differential equation with initial values
x''+4x'+5x=15cos(4t), x(0)=0, x'(0)=0
And want to find both the steady periodic solution as well as the full solution
When I put in
f=function('f')(x)
de=diff(f,x,2)+4*diff(f,x)+5*f==15*cos(4*x)
z=desolve_laplace(de,dvar=f,ics=[0,0,0])
show(expand(z))
I get
165/377*cos(x)*e^(-2*x) - 630/377*e^(-2*x)*sin(x) - 165/377*cos(4*x) + 240/377*sin(4*x)
But the answer is actually
Xsp(t) = 0.773cos(4t-2.173)
X(t) = 0.773cos(4t-2.173)+1.727e^(-2t) *cos(t-4.969)
And I have no idea how to graph this, but I'm pretty sure that's fairly easy.
I know there's the manual way of doing everything, but that takes a lot of time and I think Sage can do it better and faster
I appreciate all help!Presto.creatorTue, 13 Apr 2021 02:05:34 +0200https://ask.sagemath.org/question/56632/Pickling fast_callable wrappershttps://ask.sagemath.org/question/56639/pickling-fast_callable-wrappers/ I am trying to parallelize a code that must evaluate a specific function on several different inputs.
The function is obtained by taking a (really big) symbolic expression and calling the method fast_callable on it. Now, what I need to do is to "describe" the function to all the compute nodes. Unfortunately, I can not find a way to pickle the wrapper that fast_callable returns.
Indeed, if I try the following
from pickle import dumps
a = x^2 + 3 * x
b = fast_callable(a, vars=(x,))
dumps(b)
I get
TypeError: cannot pickle 'sage.ext.interpreters.wrapper_py.Wrapper_py' object
I have tried with pickle, with cPickle, with dill and with SagePickler, with no luck. Is there any way to export the callable objects? Otherwise, is there an easy workaround for this?
The only one that I come out with would be to pass the symbolic expression instead of passing the output of fast_callable but, taking into account that it takes more that 15 minutes to execute the fast_callable function on my symbolic expression, this will neglect any improvement that I get from parallelizing my code.stepTue, 13 Apr 2021 22:39:11 +0200https://ask.sagemath.org/question/56639/possible bug: kernel of ring homomorphismhttps://ask.sagemath.org/question/55618/possible-bug-kernel-of-ring-homomorphism/ The kernel of a ring homomorphism to a quotient ring gives unexpected results:
A.<t> = QQ[]
B.<x,y> = QQ[]
H = B.quotient(B.ideal([B.1]))
f = A.hom([H.0], H)
f
f.kernel()
outputs:
Ring morphism:
From: Univariate Polynomial Ring in t over Rational Field
To: Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (y)
Defn: t |--> xbar
Principal ideal (t) of Univariate Polynomial Ring in t over Rational Field
whereas the kernel of f:A[t]->B[x,y]->B[x,y]/(y), for f(t)=x should be (0).
Why?makosSun, 07 Feb 2021 17:41:51 +0100https://ask.sagemath.org/question/55618/output options for sagecellhttps://ask.sagemath.org/question/56635/output-options-for-sagecell/I'm working on a project where one program communicates to a sagecell server to calculate certain formulas. I managed to use the web api of sagecell to compute requests but the problem is that the output is meant to be displayed and not further used by a program.
For the request:
a = solve(x^2 + 3*x + 2, x);
print(a)
I receive this output:
{
execute_reply: {
status: 'ok',
execution_count: 1,
user_expressions: {},
payload: []
},
success: true,
stdout: '[\nx == -2,\nx == -1\n]\n'
}
My question is now, is there a way to get something like a JSON output or anything else that is computer readable and does not require to be parsed?Philipp MTue, 13 Apr 2021 11:01:52 +0200https://ask.sagemath.org/question/56635/interact: different behavior concerning **kwargs in SageCell an Jupyter notebookhttps://ask.sagemath.org/question/56620/interact-different-behavior-concerning-kwargs-in-sagecell-an-jupyter-notebook/I'm trying to use the output of one interact as the input for number of control elements in a second interact. The following examle code works in Sage Jupyter notebook but fails in SageCell (Unfortunately I can't post a link to SageCell due to my low karma).
I don't understand why it fails and how I can make the code run in SageCell.
@interact
def f(s=slider([1,2], default=1)):
kwargs = { f"C_{i}": checkbox() for i in range(s)}
print(kwargs)
@interact(**kwargs)
def f2(**kwargs):
for key, value in kwargs.items():
print(f"{key} is {value}")
VittMon, 12 Apr 2021 01:35:24 +0200https://ask.sagemath.org/question/56620/Is there a way to compute the "correct" distributional answer, -4*pi*dirac_delta(r), as the Laplacian of 1/r (in spherical coordinates on Euclidean space)?https://ask.sagemath.org/question/56621/is-there-a-way-to-compute-the-correct-distributional-answer-4pidirac_deltar-as-the-laplacian-of-1r-in-spherical-coordinates-on-euclidean-space/**Background:** I'm putting together an EM notebook for educational purposes, and would like to be able to show demonstrations of Gauss's Law (for example). However, for completely understandable and obvious reasons, integrating `(1/r^2*r_hat).div()` over the unit ball just gives `0`. Computing the flux of `(1/r^2*r_hat)` through the unit sphere gives the expected result, of course, but I'd hoped to directly demonstrate that it's proportional to the volume integral.perfectly_oddMon, 12 Apr 2021 06:19:54 +0200https://ask.sagemath.org/question/56621/