ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 28 Mar 2019 20:00:40 -0500How do I get the result of right_kernel into a matrix?http://ask.sagemath.org/question/45935/how-do-i-get-the-result-of-right_kernel-into-a-matrix/Hello,
I have a simple program I am running where I define a matrix C, then define
B=C.right_kernel()
I would then like to create another matrix, D, that is a block matrix with C and B as blocks, C on top of B. So far my code for that is
Dlist = []
for i in range(len(rowsofmatrix)):
Dlist.append(C[i,:])
for i in range(20-len(rowsofmatrix)):
Dlist.append(B[i,:])
where rowsofmatrix is a list I used to define the matrix C. The Dlist.append(C[I,:]) works just fine, but the second one involving B does not, and I imagine this has something to do with the form of B. Is there a way I can express B as a regular matrix? Or, alternatively, is there a better way to do this altogether?
ThankscaucherThu, 28 Mar 2019 20:00:40 -0500http://ask.sagemath.org/question/45935/Finding the kernel of a matrix in a non-integral domainhttp://ask.sagemath.org/question/44815/finding-the-kernel-of-a-matrix-in-a-non-integral-domain/I have been trying to find the kernel of the matrix in a quotient, for example.
If we have the following quotient ring in sage:
R.<t> = PolynomialRing(GF(3),'t')
I = R.ideal([t^3])
S = R.quotient_ring(I);
and if I try to find the kernel of the matrix:
E = Matrix(S, ([[0+a*t+b*t^2, 1+a*t+b*t^2, 0+a*t+b*t^2, 0+a*t+b*t^2],
[0+a*t+b*t^2, 0+a*t+b*t^2, 0+a*t+b*t^2, 0+a*t+b*t^2],
[0+a*t+b*t^2, 0+a*t+b*t^2, 0+a*t+b*t^2, 1+a*t+b*t^2],
[0+a*t+b*t^2, 0+a*t+b*t^2, 0+a*t+b*t^2,0+a*t+b*t^2]]))
E.kernel()
It gives me the following error: NotImplementedError.
I guess this is because F3[x]/(x^3) is not an integral domain but I would like a way around it.
Thanks in advance.abelSun, 30 Dec 2018 12:11:11 -0600http://ask.sagemath.org/question/44815/Finding the kernel of a non-integral domainhttp://ask.sagemath.org/question/44814/finding-the-kernel-of-a-non-integral-domain/I have been trying to find the kernel of the matrix in a quotient, for example.
If we have the following quotient ring in sage:
R.<t> = PolynomialRing(GF(3),'t')
I = R.ideal([t^3])
S = R.quotient_ring(I);
and if I try to find the kernel of the matrix:
E = Matrix(S, ([[0+a*t+b*t^2, 1+a*t+b*t^2, 0+a*t+b*t^2, 0+a*t+b*t^2],
[0+a*t+b*t^2, 0+a*t+b*t^2, 0+a*t+b*t^2, 0+a*t+b*t^2],
[0+a*t+b*t^2, 0+a*t+b*t^2, 0+a*t+b*t^2, 1+a*t+b*t^2],
[0+a*t+b*t^2, 0+a*t+b*t^2, 0+a*t+b*t^2,0+a*t+b*t^2]]))
E.kernel()
It gives me the following error: NotImplementedError.
I guess this is because F3[x]/(x^3) is not an integral domain but I would like a way around it.
Thanks in advance. abelSun, 30 Dec 2018 12:09:21 -0600http://ask.sagemath.org/question/44814/kernel of a matrix defined over polynomial ringshttp://ask.sagemath.org/question/42453/kernel-of-a-matrix-defined-over-polynomial-rings/ I have a matrix defined as a function of variables in a polynomial ring defined over finite field as follows-
Gr.<xp,yp>=LaurentPolynomialRing(GF(2));
M=Matrix(Gr,[[xp-1,0],
[yp-1,0],
[0,(yp^(-1))-1],
[0,-(xp^(-1))+1]]);
I want to calculate the kernel of this matrix but the kernel function
M.kernel()
gives an error. What am I doing wrong?arpitSun, 27 May 2018 17:40:42 -0500http://ask.sagemath.org/question/42453/sagews vs jupyter notebook, and choices of kernelshttp://ask.sagemath.org/question/42394/sagews-vs-jupyter-notebook-and-choices-of-kernels/I'm making a few notebooks for educational use and I'm looking for guidance as to what I should be using: a sage worksheet running Jupyter, or a Jupyter notebook. For the most part, I want users to be able to run existing Python programs.
(I also want them to run some Haskell programs, and for this, the choice is clearer: I want the Jupyter notebook because I can set the mode to Haskell.)
I don't see anything here that offers comparisons, and so here are some of the issues on my mind.
I find the Jupyter notebook cell system more to my liking than a sagews. I believe that users would also, but I have no real experience with that.
I think there's more documentation here for the sagews (right?), but there's more out there on the Jupyter notebook.
I'd like some support for simple tables containing text and numbers; nothing fancier. Is there a difference there?
A final issue: is there any difference in terms of displaying html, either in the application itself or in separate windows?
And on a related point: what is the difference between a sagews set up to run a Jupyter kernel via
py3 = jupyter("python3")
and one via
a3 = jupyter("anaconda3")
Is this an orthogonal issue, or is it related to my overall question?
Larry MossTue, 22 May 2018 12:39:58 -0500http://ask.sagemath.org/question/42394/cokernel of a map between modules over polynomial ringshttp://ask.sagemath.org/question/42154/cokernel-of-a-map-between-modules-over-polynomial-rings/Define a polynomial ring $R$ as $F_{2}\left[x_{1},x_{1}^{-1},....x_{D},x_{D}^{-1}\right]$ where $D$ is the dimension and $\mathbb{F}_{2}$ is a binary field.
Let $G$ be a free $R$-module of some labels and has rank $t$. $P$
be a free $R$-module of Pauli operators. $\sigma$ is a map from
$G$ to $P$. I want to write a snippet to calculate the cokernel
of this map.
Just for example (taken from page 54 of arxiv.1305.6973 or page 41 of arxiv.1607.01387),
though this is not essential for the question, I can have two ``interaction''
terms in terms of 2-dimensional Pauli operators $X$, $Z$ and Identity
operator $I$ on 4 sites with two 2-dimensional systems per site as
$
II(0,0)-IX(0,1)-XI(1,0)-XX(1,1)
$
and
$
ZZ(0,0)-IZ(0,1)-ZI(1,0)-II(1,1)
$
where on each site $\left(x,y\right)$ (mentioned in the bracket after
the Pauli operators), the first(second) Pauli acts on the first(second)
two dimensional system on that site. The map $\sigma$ can be written
as
$
\sigma=\left(\begin{array}{cc}
y+xy & 0 \\
x+xy & 0 \\
0 & 1+y \\
0 & 1+x
\end{array}\right)
$
where for example, $y+xy$ is a polynomial that specifies the action
on the first two dimensional system as
$
y+x y=0 \hspace{1mm} x^0 y^0+ 1 \hspace{1mm} x^0 y^1+0 \hspace{1mm} x^1 y^0 +1 \hspace{1mm} x^1 y^1
$
where the exponents are the coordinates of the sites and coefficients
$0$ and $1$ imply whether there is a Pauli acting or not.arpitTue, 24 Apr 2018 21:02:38 -0500http://ask.sagemath.org/question/42154/Speed up calculation of left kernelhttp://ask.sagemath.org/question/41200/speed-up-calculation-of-left-kernel/ Is there any way to accelerate the calculation of the left kernel of a matrix? It could be by allowing sage to use more memory or using some parallelism, for instance.
I have a 1230 x 74 dense matrix over Integer Ring
A = Matrix(ZZ, 1230, 74)
and when I try to use
A.left_kernel()
the calculations doesn't finish (it has run for three days and then I interrupted the script).Hilder Vítor Lima PereiraTue, 20 Feb 2018 08:33:49 -0600http://ask.sagemath.org/question/41200/Bug report: Kernel dies after 1 hour while dividing polynomialshttp://ask.sagemath.org/question/40935/bug-report-kernel-dies-after-1-hour-while-dividing-polynomials/I want to submit an **error report** for SAGE 7.0 and 8.0:
The division of two polynomials in an ideal causes an **kernel death** after one hour of computation.
Singular performs the calculation in about **10 seconds**.
**Sage source code:**
Q.<E,F,X,Y> = QQ['E', 'F', 'X', 'Y'];
i1 = F^4+(E^3+E^2-E+2)*F^3+(E^3-3*E+1)*F^2-(E^4+2*E)*F+E^3+E^2;
i2 = Y^2+(E^3+E^2*(3*F+2)-E*(F^2-2*F-1)-F*(F^2+3*F+1))*X*Y+(F*(E+1)*(E-F)*(E+F+1)^2*(E^2+E-F)*(E^2+E*F+E-F^2-F))*Y-X^3-(F*(E+1)*(E-F)*(E+F+1)*(E^2+E-F))*X^2;
J = Q.ideal(i1, i2);
R.<e,f,x,y> = QuotientRing(Q, J);
poly1 = x^4+(-e^2*f^4+e^4*f+2*e^3*f^2-e*f^4-2*e*f^3+2*f^4+2*e^2*f-6*e*f^2+f^3+5*e^2-5*e*f+11*f^2-17*e+18*f+16)*x^3+(-2*e^3-2*e^2*f+e*f^2+f^3-3*e^2+2*f^2-e+f)*x^2*y+(-6*e^2*f^5+11*e*f^6-3*f^7+3*e^6-6*e^5*f+17*e^4*f^2-69*e^2*f^4+5*e*f^5+17*f^6-5*e^5+26*e^4*f+83*e^3*f^2-106*e^2*f^3-104*e*f^4+71*f^5-28*e^4+66*e^3*f+57*e^2*f^2-149*e*f^3+54*f^4-55*e^3+78*e^2*f+9*e*f^2-32*f^3-35*e^2+70*e*f-35*f^2)*x^2+(-e^2*f^7-e^7*f-3*e^6*f^2-2*e^2*f^6-e*f^7-5*e^6*f-e^5*f^2-6*e^2*f^5-6*e*f^6+2*f^7+3*e^5*f-2*e^4*f^2-2*e^2*f^4-15*e*f^5+2*f^6-2*e^5-7*e^4*f-4*e^3*f^2-9*e^2*f^3-4*e*f^4+3*e^4+20*e^3*f-43*e^2*f^2-21*e*f^3+28*f^4-e^3-32*e^2*f-61*e*f^2+61*f^3-22*e^2-53*e*f+59*f^2-16*e+16*f)*x*y+(e^6+2*e^5*f+3*e^5-4*e^3*f^2-2*e^2*f^3+2*e*f^4+f^5+3*e^4-5*e^2*f^2+2*f^4+3*e^3-3*e^2*f-e*f^2+4*f^3-3*e^2+e*f-9*f^2+17*e-18*f-16)*y^2+(11*e*f^9-3*f^10-3*e^9-5*e^7*f^2-101*e^2*f^7+30*e*f^8+11*f^9-e^8-32*e^7*f-74*e^6*f^2-422*e^2*f^6-117*e*f^7+121*f^8+35*e^7-39*e^6*f-134*e^5*f^2-486*e^2*f^5-660*e*f^6+276*f^7+141*e^6-106*e^5*f-226*e^4*f^2+384*e^2*f^4-1019*e*f^5+36*f^6+189*e^5-367*e^4*f-681*e^3*f^2+1382*e^2*f^3+130*e*f^4-884*f^5+61*e^4-1019*e^3*f+565*e^2*f^2+1914*e*f^3-1521*f^4-251*e^3-499*e^2*f+1751*e*f^2-1001*f^3-231*e^2+462*e*f-231*f^2)*y;
poly2 = x+e^5*f+e^4*f^2-e^2*f^4+2*e^4*f+e^3*f^2-3*e^2*f^3+f^5+3*e^3*f-3*e^2*f^2-3*e*f^3+3*f^4+e^3+e^2*f-5*e*f^2+3*f^3+e^2-2*e*f+f^2;
print (poly1 / poly2);
**Singular source code:**
In Singular you cannot use the operator "/" to divide polynomials, since "non divisible terms" will be discarded and set to zero, see manual [https://www.singular.uni-kl.de/Manual/4-0-3/sing_150.htm#SEC189](https://www.singular.uni-kl.de/Manual/4-0-3/sing_150.htm#SEC189).
So in Singular we have to use the "lift" command to calculate the quotient "poly 1 / poly2":
ring R = 0,(x,y,e,f),dp;
poly i1 = f^4+(e^3+e^2-e+2)*f^3+(e^3-3*e+1)*f^2-(e^4+2*e)*f+e^3+e^2;
poly i2 = y^2 + (e^3 + e^2*(3*f+2) - e*(f^2-2*f-1) - f*(f^2+3*f+1))*x*y + (f * (e+1) * (e-f) * (e+f+1)^2 * (e^2+e-f) * (e^2+e*f+e-f^2-f)) * y - x^3 - (f * (e+ 1) * (e-f) * (e+f+1) * (e^2+e-f)) * x^2;
ideal I = i1,i2;
ideal J = std(I);
poly poly1 = x^4 + (-e^2*f^4 + e^4*f + 2*e^3*f^2 - e*f^4 - 2*e*f^3 + 2*f^4 + 2*e^2*
f - 6*e*f^2 + f^3 + 5*e^2 - 5*e*f + 11*f^2 - 17*e + 18*f + 16)*x^3 + (-2*e^3 - 2
*e^2*f + e*f^2 + f^3 - 3*e^2 + 2*f^2 - e + f)*x^2*y + (-6*e^2*f^5 + 11*e*f^6 - 3
*f^7 + 3*e^6 - 6*e^5*f + 17*e^4*f^2 - 69*e^2*f^4 + 5*e*f^5 + 17*f^6 - 5*e^5 + 26
*e^4*f + 83*e^3*f^2 - 106*e^2*f^3 - 104*e*f^4 + 71*f^5 - 28*e^4 + 66*e^3*f + 57*
e^2*f^2 - 149*e*f^3 + 54*f^4 - 55*e^3 + 78*e^2*f + 9*e*f^2 - 32*f^3 - 35*e^2 + 7
0*e*f - 35*f^2)*x^2 + (-e^2*f^7 - e^7*f - 3*e^6*f^2 - 2*e^2*f^6 - e*f^7 - 5*e^6*
f - e^5*f^2 - 6*e^2*f^5 - 6*e*f^6 + 2*f^7 + 3*e^5*f - 2*e^4*f^2 - 2*e^2*f^4 - 15
*e*f^5 + 2*f^6 - 2*e^5 - 7*e^4*f - 4*e^3*f^2 - 9*e^2*f^3 - 4*e*f^4 + 3*e^4 + 20*
e^3*f - 43*e^2*f^2 - 21*e*f^3 + 28*f^4 - e^3 - 32*e^2*f - 61*e*f^2 + 61*f^3 - 22
*e^2 - 53*e*f + 59*f^2 - 16*e + 16*f)*x*y + (e^6 + 2*e^5*f + 3*e^5 - 4*e^3*f^2 -
2*e^2*f^3 + 2*e*f^4 + f^5 + 3*e^4 - 5*e^2*f^2 + 2*f^4 + 3*e^3 - 3*e^2*f - e*f^2
+ 4*f^3 - 3*e^2 + e*f - 9*f^2 + 17*e - 18*f - 16)*y^2 + (11*e*f^9 - 3*f^10 - 3*
e^9 - 5*e^7*f^2 - 101*e^2*f^7 + 30*e*f^8 + 11*f^9 - e^8 - 32*e^7*f - 74*e^6*f^2
- 422*e^2*f^6 - 117*e*f^7 + 121*f^8 + 35*e^7 - 39*e^6*f - 134*e^5*f^2 - 486*e^2*
f^5 - 660*e*f^6 + 276*f^7 + 141*e^6 - 106*e^5*f - 226*e^4*f^2 + 384*e^2*f^4 - 10
19*e*f^5 + 36*f^6 + 189*e^5 - 367*e^4*f - 681*e^3*f^2 + 1382*e^2*f^3 + 130*e*f^4
- 884*f^5 + 61*e^4 - 1019*e^3*f + 565*e^2*f^2 + 1914*e*f^3 - 1521*f^4 - 251*e^3
- 499*e^2*f + 1751*e*f^2 - 1001*f^3 - 231*e^2 + 462*e*f - 231*f^2)*y;
poly poly2 = x + e^5*f + e^4*f^2 - e^2*f^4 + 2*e^4*f + e^3*f^2 - 3*e^2*f^3 + f^5
+ 3*e^3*f - 3*e^2*f^2 - 3*e*f^3 + 3*f^4 + e^3 + e^2*f - 5*e*f^2 + 3*f^3 + e^2 - 2*e*f
+ f^2;
poly t1 = lift(poly2,poly1)[1,1];
**Singular output:**
t1;
-ye9+5ye7f2-5ye8+7ye7f+15ye6f2+4ye2f6-2yef7+x2e6-10ye7-2x2e5f+14ye6f-x2e4f2+20ye5f2+26ye2f5+yef6-5yf7+3x2e5-11ye6-7x2e4f+22ye5f+3ye4f2+4x2e2f3-2x2ef4+49ye2f4+43yef5-22yf6+3x2e4+4ye5-12x2e3f-7ye4f+10x2e2f2-27ye3f2+4x2ef3+10ye2f3-5x2f4+91yef4-18yf5-x2e3+xye3+29ye4-5x2e2f+7xye2f+11ye3f+13x2ef2-2xyef2-99ye2f2-7x2f3-2xyf3-4yef3+63yf4-2x2e2+3xye2+73ye3+4x2ef+6xyef-29ye2f-2x2f2-7xyf2-161yef2+117yf3-2x3+2xye+53ye2-2xyf-106yef+53yf2+3y2Patrick ReichertFri, 02 Feb 2018 11:14:30 -0600http://ask.sagemath.org/question/40935/Calculation Kernel of a matrixhttp://ask.sagemath.org/question/39575/calculation-kernel-of-a-matrix/I'm trying to write a program in which one part is related to calculation of kernel of a matrix. Its output and expected output are different. For example,
A = [[1, 0, 1], [1, 0, 0], [0, 1, 1], [0, 1, 0], [0, 0, 1], [-1, 0, 0], [0, 0, -1], [0, -1, 1], [0, -1, 0], [-1, 0, 1]]
A is the matrix whose kernel is wanted.
When I calculate its kernel with some programs they give output different, my program is as well. But, when I try to calculate its kernel some others, like SAGE, give output,
1 0 0 0 0 0 0 -2 2 1
0 1 0 0 0 0 0 -1 1 1
0 0 1 0 0 0 0 -1 2 0
0 0 0 1 0 0 0 0 1 0
0 0 0 0 1 0 0 -1 1 0
0 0 0 0 0 1 0 1 -1 -1
0 0 0 0 0 0 1 1 -1 0
The above one is what I expect as output. What is the point that I may overlook?
Here is my procedure to calculate the kernel in my program,
A.transposeInPlace();
FullPivLU<MatrixXf> lu(A);
MatrixXf A_null_space = lu.kernel();
A_null_space.transposeInPlace();
But in that way, I get different then expected one, but SAGE gives the above matrix that actually I expect.
0.5 0 -1 1 0 0 0 0 0 0.5
-0.5 0 -0 0 1 0 0 0 0 -0.5
0.5 0 -0 0 0 1 0 0 0 -0.5
0.5 0 -0 0 0 0 1 0 0 0.5
-1 0 1 0 0 0 0 1 0 -1
-0.5 0 1 0 0 0 0 0 1 -0.5
-0.5 1 -0 0 0 0 0 0 0 0.5
**I'm really but really confused because both matrix seem right! How come?**
Sage's output proof,
https://i.stack.imgur.com/F3ryq.png
My program's output proof,
https://i.stack.imgur.com/7Mw8y.pngstudentboyWed, 15 Nov 2017 08:38:29 -0600http://ask.sagemath.org/question/39575/python 2 kernel keeps dyinghttp://ask.sagemath.org/question/37544/python-2-kernel-keeps-dying/ I have SageMath 7.3 installed from binaries and 7.6 compiled from source on my debian linux system, but in both, the python 2 kernel keeps dying when I use it in jupyter. It just dies, restarts, dies etc., making it entirely unusable. Did anyone experience this problem before? What could I do to get it to run? Thanks for your help!stanTue, 09 May 2017 02:01:26 -0500http://ask.sagemath.org/question/37544/Sage cell server dead after one request from clienthttp://ask.sagemath.org/question/36776/sage-cell-server-dead-after-one-request-from-client/ I want to access the SAGE cell server programatically from Python 3. I found [this example](https://github.com/sagemath/sagecell/blob/master/contrib/sagecell-client/sagecell-client.py) here, which uses the Websockets interface.
It works nice and smooth, but only for exactly **one request**, because after that the `execution_state` of the connection is `dead`. The [documentation](https://github.com/sagemath/sagecell/wiki/Messages) even describes that:
You’ll get a kernel dead message on the IOPub channel when the cell times out. If you don’t have
interacts, it will time out pretty much immediately. If you do have interacts, then the timeout
is something 30 or 60 seconds between each execute_request.
If I connect each time anew it will be slower for me and waste much more resources on the server side (I guess), so it would be best if I could somehow re-use the connection. Timeout only needs to be some 1-5 seconds, basically a couple of RTTs of the Internet.
Is there anything I could do?wrognWed, 01 Mar 2017 08:47:08 -0600http://ask.sagemath.org/question/36776/Does right_kernel_matrix support assumptions over the symbolic ring?http://ask.sagemath.org/question/34385/does-right_kernel_matrix-support-assumptions-over-the-symbolic-ring/I'm trying to a basis for the kernel of a symbolic matrix. However, exactly quite what the kernel is depends on the assumptions that have been made. It seems that although other matrix functions (e.g. calculating the inverse) respect assumptions the kernel function doesn't. Here is an example:
var('x,y')
M = Matrix(SR, [[x, 0],[0,y]])
print(~M) # Gives expected inverse [[1/x, 0], [0,1/y]]
print(M.right_kernel_matrix()) # Gives [] as expected (if x, y != 0 then M is invertible so has trivial kernel)
assume(x == 0)
# print(~M) # Throws an error (ZeroDivisionError)
print(M.right_kernel_matrix()) # Still gives [], whereas the kernel now has basis [(1, 0)]
Am I missing something here? Is it possible to use this function with assumptions?exodusTue, 09 Aug 2016 09:51:57 -0500http://ask.sagemath.org/question/34385/How to find Kernel of a Matrix in $\mathbb{Z}/n$http://ask.sagemath.org/question/33890/how-to-find-kernel-of-a-matrix-in-mathbbzn/ When I tried to find it directly using
A.kernel()
it said
Cannot compute a matrix kernel over Ring of integers modulo 11053185041
vishbThu, 23 Jun 2016 01:16:00 -0500http://ask.sagemath.org/question/33890/Accessing the "Echelon basis matrix" of kernel of a Matrixhttp://ask.sagemath.org/question/33897/accessing-the-echelon-basis-matrix-of-kernel-of-a-matrix/ For any matrix **A** when we type
A.kernel()
It returns
A.kernel()
Free module of degree 45 and rank 12 over Integer Ring
Echelon basis matrix:`[ 1 0 -1][ 0 1 2][ 0 0 0]`
How to I access this Echelon basis matrix directly?
I have tried this
A.kernel.echelon_form()
but it says
TypeError: echelon_form() takes at least 2 arguments (1 given)
vishbThu, 23 Jun 2016 09:15:06 -0500http://ask.sagemath.org/question/33897/How to prevent memory leak when solving a linear system of equations using left_kernel ?http://ask.sagemath.org/question/10330/how-to-prevent-memory-leak-when-solving-a-linear-system-of-equations-using-left_kernel/I am having a problem when running the left_kernel function multiple times. Every time I call the function It takes a new part of the memory although I do not create new variables. I tried finding out where does the memory disappear, but without any luck.
here is an example code:
sage: mat
69 x 70 dense matrix over Symbolic Ring (type 'print mat.str()' to see all of the entries)
sage: get_memory_usage() #memory check before call
1170.34765625
sage: Inter_mat=mat.transpose()
sage: Solution=Inter_mat.left_kernel()
sage: get_memory_usage() #memory check after 1st call
1190.5390625
sage: Inter_mat=mat.transpose()
sage: Solution=Inter_mat.left_kernel()
sage: get_memory_usage() #memory check after 2nd call
1194.73828125
sage: Inter_mat=mat.transpose()
sage: Solution=Inter_mat.left_kernel()
sage: get_memory_usage() #memory check after 3rd call
1217.76953125
As you can see every time I call the function, the memory usage increases. Is there a way to release the memory that was used in a previous call ? My program stops after a few iterations because of lack of memory.
Update: (Creating the matrix "mat")
mat=[]
for Coord in range(len(M_col)):
if(M[M_row[Coord],M_col[Coord]]!=0):
s=M[M_row[Coord],M_col[Coord]]
if(s==1):
temp_v=vector(Poly)(x=a^M_col[Coord],y=FIELDinfoBook[M_row[Coord]])
mat.append(vector(W,temp_v))
else:
up=[i for i in range(s)]
down=list(up)
down.reverse()
for Cup in range(s):
for Cdown in range(s):
if(up[Cup]+down[Cdown]<s):
temp_v=list(zero_vector(sum(Len_Poly)))
for j in range(down[Cdown],l+1):
for i in range(up[Cup],Len_Poly[j]):
comb1=len(Combinations(j,down[Cdown]).list())
comb2=len(Combinations(i,up[Cup]).list())
temp=comb1*comb2*x^(i-up[Cup])*y^(j-down[Cdown])
temp=temp(x=a^M_col[Coord],y=FIELDinfoBook[M_row[Coord]])
temp_v[Len_Poly_inc[j]+i]=(temp)
mat.append(vector(temp_v))
The matrix M is a sparse matrix with integers (mostly ones) at certain positions. M_col and M_row are lists with the locations of nonzero elements.
sage: M
64 x 63 dense matrix over Integer Ring (type 'print M.str()' to see all of the entries)
Poly is a list of bivariate polynomials created like this:
Poly=[]
for j in range(l+1):
for i in range(Len_Poly[j]):
Poly.append(x^i*y^j)
And l=1 , Len_poly=[63, 7] and Len_poly_inc=[0, 63, 70]
M. H. M.Mon, 08 Jul 2013 02:00:19 -0500http://ask.sagemath.org/question/10330/polynomial kernelhttp://ask.sagemath.org/question/10285/polynomial-kernel/Is there any particular reason why computing the kernel of a matrix over a polynomial ring might fail? Consider the following example:
sage: PR.<x1, x2, x3, y1, y2, y3> = QQ[]
sage: def P(t):
... u = 1 - t
... x = x1*t*t + x2*t*u*2 + x3*u*u
... y = y1*t*t + y2*t*u*2 + y3*u*u
... return (x, y)
sage: def C(t):
... x, y = P(t)
... return vector(PR, [x^2, y^2, x*y, x, y, 1])
sage: M = Matrix([C(t) for t in [0, 1, -1, 2, 1/2]])
sage: M.right_kernel()
Traceback (most recent call last):
...
ArithmeticError: Ideal Ideal (x3^2, x1^2) of Multivariate Polynomial Ring
in x1, x2, x3, y1, y2, y3 over Rational Field not principal
It seems to me as if being able to compute the reduced echelon form (using the `frac` method) should be enough to actually compute a kernel as well, without any additional requirements. I will demonstrate this in an answer below. So why does computing the echelon form work, but computing the kernel not?
MvGMon, 08 Jul 2013 01:40:13 -0500http://ask.sagemath.org/question/10285/Calculating an Orthonormal Basishttp://ask.sagemath.org/question/9039/calculating-an-orthonormal-basis/Hi, I'm still quite inexperienced with Sage at the moment, so forgive me if this is a basic issue. I am trying to produce an orthonormal basis, I have created the orthogonal complement to my original basis by taking its left nullspace using kernel() I now want to use gram_schmidt() to produce a normalised version. I am unsure however what ring my input matrix should be over. QQbar won't work for me, but I am worried that the RDF result I get will not retain the linear independence that I need, as it says in the documentation for gram_schmidt() that under RDF, *"no attempt is made to recognize linear dependence with approximate calculations"*
My input matrix is the following;
[ 0 -1 0 0 1 0 0 0 0 0 0 0]
[-1/2 0 0 -1/2 0 0 1 0 0 0 0 0]
[-1/2 -1 0 1/2 0 0 0 1 0 0 0 0]
[-1/2 0 0 -1/2 0 0 0 0 0 1 0 0]
[ 1/2 -1 0 -1/2 0 0 0 0 0 0 1 0]
[ 0 0 -1 0 0 -1 0 0 1 0 0 1]
if I change the ring of this matrix to RDF, gram_schmidt() runs but the inexact entries of -0.0 and what is clearly 1/sqrt(2) are not so useful.
[ 0.0 -0.408248290464 0.353553390593
-0.288675134595 0.353553390593 -1.32686526214e-17]
[ 0.707106781187 -8.67632788532e-17 0.353553390593
-1.40946282423e-17 -0.353553390593 -1.72861506093e-17]
[ -0.0 0.0 0.0
1.9952420559e-17 3.41114374126e-17 -0.5]
[ -0.0 -0.408248290464 -0.353553390593
-0.288675134595 -0.353553390593 4.70626515093e-17]
[ -0.707106781187 3.12521276219e-17 0.353553390593
6.96057794736e-17 -0.353553390593 -1.72861506093e-17]
[ -0.0 0.0 -0.0
0.0 0.0 -0.5]
[ -0.0 0.816496580928 5.51587855252e-17
-0.288675134595 -7.45998857306e-17 1.68969994439e-17]
[ -0.0 0.0 -0.707106781187
9.67672224796e-18 5.13672629661e-18 0.0]
[ -0.0 0.0 -0.0
0.0 0.0 0.5]
[ -0.0 0.0 -0.0
0.866025403784 -2.24700900248e-17 -1.5111067779e-17]
[ -0.0 0.0 -0.0
0.0 0.707106781187 1.24852656425e-17]
[ -0.0 0.0 -0.0
0.0 0.0 0.5]
Does anybody know where I've gone wrong here? Is there another more reliable method for computing an orthonormal basis that I could use? Thanks again for putting up with a newbie!
best regards
BrianBrianLoudonThu, 07 Jun 2012 01:31:06 -0500http://ask.sagemath.org/question/9039/Converting kernel to matrixhttp://ask.sagemath.org/question/7859/converting-kernel-to-matrix/I construct a matrix A and compute its kernel by
A = matrix(GF(2),vectors)
B = A.kernel()
Now I want to convert B to a matrix, such that I can use .nrows() and other matrix-methods, how to do that?MustafaSun, 09 Jan 2011 00:15:35 -0600http://ask.sagemath.org/question/7859/