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.Sun, 18 Apr 2021 12:48:15 +0200Formatting 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/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/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/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)?Alain NgalaniSat, 17 Apr 2021 19:21:14 +0200https://ask.sagemath.org/question/56692/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/Parametric plot doesn't work as expectedhttps://ask.sagemath.org/question/56591/parametric-plot-doesnt-work-as-expected/I'm working on some visualizations. In fact, I'd like to vizualize lines
and curves on the projective plane. I started with something very easy:
draw a line on sphere. I figured out the following.
Compute intersection of a plane with the unit sphere:
sage: x, y, z = var('x y z')
sage: sol = solve([x + y + z == 0.0, x^2 + y^2 + z^2 == 1.0], y, z)
sage: sol
[[y == -1/2*x - 1/2*sqrt(-3*x^2 + 2), z == -1/2*x + 1/2*sqrt(-3*x^2 + 2)],
[y == -1/2*x + 1/2*sqrt(-3*x^2 + 2), z == -1/2*x - 1/2*sqrt(-3*x^2 + 2)]]
Draw the plane, the sphere, and their intersection:
sage: p = implicit_plot3d(x + y + z, (x, -5, 5), (y, -5, 5), (z, -5, 5), color="blue", opacity=0.2)
sage: p += implicit_plot3d(x^2 + y^2 + z^2 - 1, (x, -5, 5), (y, -5, 5), (z, -5, 5), color="red", opacity=0.4)
sage: for s in sol:
....: p += parametric_plot3d([x, y.subs(s[0]), z.subs(s[1])], (x, -5.0, 5.0), color="green")
sage: show(p)
![Plane, sphere and their intersection](https://zielony-backlog.pl/wp-content/uploads/2021/04/screenshot1.png)
I believe the computation is correct.
However I'm not satisfied with the resulting plot.
Instead of a smooth line (like a tilted equator)
I have strange "triangles" at opposite points of
the sphere.
What can I do about it?pawel.bogdanSat, 10 Apr 2021 16:59:16 +0200https://ask.sagemath.org/question/56591/Simplify factorials Questionhttps://ask.sagemath.org/question/56593/simplify-factorials-question/Hi , sorry this may seem so easy but i'm just starting sage !
I want this code to show the answer, how can i do that ? how can i change the code ?
n=var('n)
f=factorial(2*n + 3)/factorial(n + 1)
f.simplify_factorial()
output is :
factorial(2*n + 3)/factorial(n + 1)SoheilKSat, 10 Apr 2021 17:38:56 +0200https://ask.sagemath.org/question/56593/inequalities in sagemathhttps://ask.sagemath.org/question/56610/inequalities-in-sagemath/ var('x y M a b c d A B C D t u v S T U V')
eq1 = 3*(((2*3367-3*y+1)/24)+3*x*(x+1)/2)+1-V == 0
eq2 = -3367+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*t+1)/24)+3*x*(x+1)/2)+1-S == 0
eq8 = T+3*t*(t-1)/2-12*x*(x+1)/2-1 == 0
eq9 = 3*(((2*S-3*1+1)/24)+3*x*(x+1)/2)+1-S == 0
eq18 = -M+9*((2*3367 - 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*d + 1)/24 + (3*x*(x + 1))/2) + 1 - S == 0
eq27 = D + (3*d*(d - 1))/2 - (12*x*(x + 1))/2 - 1 == 0
eq28 = 3*((2*S - 3*1 + 1)/24 + (3*x*(x + 1))/2) + 1 - S == 0
eq29 = x-24 == 0
assume(x-1 >= 0 , y-1 >= 0 , A-M > 0 , B-A > 0 , C-B > 0 , D-C > 0 , S-D >0 , V-3367 > 0 , U-V > 0 , T-U > 0 , S-T > 0)
solutions = solve([eq1,eq2,eq3,eq4,eq5,eq6,eq7,eq8,eq9,eq18,eq19,eq20,eq21,eq22,eq23,eq24,eq25,eq26,eq27,eq28,eq29],x,y,M,a,b,c,d,A,B,C,D,t,u,v,S,T,U,V)
sol0 = solutions[0]
print(sol0[0])
print(sol0[1])
print(sol0[2])
print(sol0[3])
print(sol0[4])
print(sol0[5])
print(sol0[6])
print(sol0[7])
print(sol0[8])
print(sol0[9])
print(sol0[10])
print(sol0[11])
print(sol0[12])
print(sol0[13])
print(sol0[14])
print(sol0[15])
print(sol0[16])
print(sol0[17])
output
(x, y, M, a, b, c, d, A, B, C, D, t, u, v, S, T, U, V)
x == 24
y == 13
M == 2701
a == -12
b == (13/2)
c == (-149/16)
d == 1
A == 3367
B == (28379/8)
C == (114737/32)
D == 3601
t == -1
u == -3
v == 7
S == 3601
T == 3598
U == 3583
V == 3538
Error
D==S
but assume(.... , S-D > 0 , .....)
How do you use assumes () well?
P_1_6Sun, 11 Apr 2021 08:14:28 +0200https://ask.sagemath.org/question/56610/Possible problem in bezier_path.pyhttps://ask.sagemath.org/question/56608/possible-problem-in-bezier_pathpy/ It seems that the path that is stored by BezierPath is not correct.
Let
p2d = [[(3.0,0.0),(3.0,0.13),(2.94,0.25),(2.8,0.35)],
[(2.7,0.44),(2.6,0.5),(2.5,0.5)],
[(2.36,0.5),(2.24,0.44),(2.14,0.35)],
[(2.05,0.25),(2.0,0.13),(2.0,6.1e-17)]]
then
bezier_path(p2d)[0].path
is different than the given path p2d. There are several consequences to this, for example, the stored path cannot be fed again to bezier_path, so this won't work (results in weird errors):
bezier_path(bezier_path(p2d)[0].path)
and also affects the plot3d method of the class.
The issue seems to stem from line 64 of bezier_path.py:
vertices = self.path[0]
Since the list of vertices changes size after the line so does self.path. I believe the line should be
vertices = deepcopy(self.path[0])RozaThSun, 11 Apr 2021 02:07:59 +0200https://ask.sagemath.org/question/56608/Problem with plotting a 3d Bezier curvehttps://ask.sagemath.org/question/56590/problem-with-plotting-a-3d-bezier-curve/ I have a problem with plotting a Bezier spline in 3d.
In 2d this simply works:
p2d = [[(3.0,0.0),(3.0,0.13),(2.94,0.25),(2.8,0.35)],
[(2.7,0.44),(2.6,0.5),(2.5,0.5)],
[(2.36,0.5),(2.24,0.44),(2.14,0.35)],
[(2.05,0.25),(2.0,0.13),(2.0,6.1e-17)]]
bezier_path(p2d)
But when I want to plot it in 3d, this line
bezier_path(p2d).plot3d()
or
p3d = [[(3.0,0.0,0.0),(3.0,0.13,0.0),(2.94,0.25,0.0),(2.8,0.35,0.0)],
[(2.7,0.44,0.0),(2.6,0.5,0.0),(2.5,0.5,0.0)],
[(2.36,0.5,0.0),(2.24,0.44,0.0),(2.14,0.35,0.0)],
[(2.05,0.25,0.0),(2.0,0.13,0.0),(2.0,6.1e-17,0.0)]]
bezier3d(p3d)
both give me the following error: TypeError: unable to convert -(t - 1)^3 to an integer.
What am I doing wrong?RozaThSat, 10 Apr 2021 09:12:55 +0200https://ask.sagemath.org/question/56590/