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, 03 Jan 2019 09:36:01 -0600Quaternion * integerhttp://ask.sagemath.org/question/44869/quaternion-integer/ how can i multiply my own quaternion group elements with a normal integer?
it says this:
unsupported operand parent(s) for +: 'Integer Ring' and '<class 'quater'>'SpreeterThu, 03 Jan 2019 09:36:01 -0600http://ask.sagemath.org/question/44869/Multiplication of elements of tower fieldshttp://ask.sagemath.org/question/39835/multiplication-of-elements-of-tower-fields/Let
p=13
R = GF(p)
_.<v> = PolynomialRing(R)
R4.<v> = R.extension(v^4 - 2, 'v')
_.<w> = PolynomialRing(R4)
R16.<w> = R4.extension(w^4-v, 'w')
I need to compute
f1 = R16(1)
for i in range(34):
A=R4.random_element() #in my case, this is not random, its derived by an function
f1 = f1^2*A #this is not the whole code, but it displayes the problem
This element stays allways in R4. But the result i expect, is an element of R16.
So: How can I tell sage to use the R16 multiplication instead? I need a full degree 15 polynomial. If it is possible, in one variable (w, since w^4=v).
Furthermore: How can I tell Sage to print any coefficient in Hex?ShalecWed, 29 Nov 2017 02:31:10 -0600http://ask.sagemath.org/question/39835/Elliptic curve scalar multiplication algorithmhttp://ask.sagemath.org/question/32886/elliptic-curve-scalar-multiplication-algorithm/ I'm doing a prespective on supersinguar elliptic curves. I was wondering how saga calculates scalar multiplications? Does it just calculate it naively or does it use succesive doubling as default? Til is most interesting since there are well known ways of making "shortcuts" when oberating with supersingular curves, but does sage use these?BelphegorFri, 25 Mar 2016 08:41:10 -0500http://ask.sagemath.org/question/32886/problems with product of vector of symbols with square matrixhttp://ask.sagemath.org/question/24077/problems-with-product-of-vector-of-symbols-with-square-matrix/ Hi,
I am trying to do some experiments with symbols (variable vector) and multiplications with a coefficient matrix.
The code is the following:
A = matrix(QQ,[
[2,1,2,-6],
[-1,2,1,7],
[3,-1,-3,-1],
[1,5,6,0]
])
k = A.transpose().kernel()
basis = k.basis()[0]
t = 'real'
var('x1')
assume(x1,t)
var('x2')
assume(x2,t)
var('x3')
assume(x3,t)
var('x4')
assume(x4,t)
x = vector([x1,x2,x3,x4])
print "x",x
xT = x.transpose()
print "xT",xT
print "A*x",A*x
print "xT*A",xT*A
with the following output:
x (x1, x2, x3, x4)
xT [x1]
[x2]
[x3]
[x4]
A*x (2*x1 + x2 + 2*x3 - 6*x4, -x1 + 2*x2 + x3 + 7*x4, 3*x1 - x2 - 3*x3 - x4, x1 + 5*x2 + 6*x3)
xT*A
Traceback (most recent call last):
File "", line 1, in <module>
File "/tmp/tmpuVBZ96/___code___.py", line 27, in <module>
exec compile(u'print "xT*A",xT*A
File "", line 1, in <module>
File "element.pyx", line 2751, in sage.structure.element.Matrix.__mul__ (sage/structure/element.c:19587)
File "coerce.pyx", line 856, in sage.structure.coerce.CoercionModel_cache_maps.bin_op (sage/structure /coerce.c:8169)
TypeError: unsupported operand parent(s) for '*': 'Full MatrixSpace of 4 by 1 dense matrices over Symbolic Ring' and 'Full MatrixSpace of 4 by 4 dense matrices over Rational Field'
As you can see, `A*x` was successful, but `xT*A` is giving an exception. Do you have any idea on why? How would you solve this?stablumTue, 09 Sep 2014 17:32:46 -0500http://ask.sagemath.org/question/24077/How to do mul(function, i=1..n); like in Maple?http://ask.sagemath.org/question/8564/how-to-do-mulfunction-i1n-like-in-maple/I want to a product of polynomials which I define in Maple as
f := n->mul((1+x^k),k=1..n);
The obvious choice, mimicking Sage's 'sum' command does not work. I can't do
def f(n):
return mul((1+x^k),k,1,n)
Instead I had to use
def S(n,k):
return mul(1+x^(k+1) for k in range(n))
Maybe my problem is another, so I'll post my whole problem and traceback:
def S(n,k):
s = mul(1+x^(i+1) for i in range(n))
return s.expand().coeff(x^k)
def H(n,k):
return sum(sum( S(2*i+1,b)*S(n-2*i-3,k-(2*i+2)-b),b,0,k-(2*i+2)),i,0,floor((n-5)/4))
H(121,4)
Traceback (most recent call last): return sum(sum( S(2*i+1,b)*S(n-2*i-3,k-(2*i+2)-b),b,0,k-(2*i+2)),i,0,floor((n-5)/4))
File "", line 1, in <module>
File "/tmp/tmpKvQFbK/___code___.py", line 10, in <module>
exec compile(u'H(_sage_const_121 ,_sage_const_4 )
File "", line 1, in <module>
File "/tmp/tmpKvQFbK/___code___.py", line 9, in H
return sum(sum( S(_sage_const_2 *i+_sage_const_1 ,b)*S(n-_sage_const_2 *i-_sage_const_3 ,k-(_sage_const_2 *i+_sage_const_2 )-b),b,_sage_const_0 ,k-(_sage_const_2 *i+_sage_const_2 )),i,_sage_const_0 ,floor((n-_sage_const_5 )/_sage_const_4 ))
File "/tmp/tmpKvQFbK/___code___.py", line 4, in S
s = mul(_sage_const_1 +x**(i+_sage_const_1 ) for i in range(n))
TypeError: range() integer end argument expected, got sage.symbolic.expression.Expression.
All advice is welcome.alejandroericksonTue, 03 Jan 2012 17:00:17 -0600http://ask.sagemath.org/question/8564/Speeding up matrix multiplication?http://ask.sagemath.org/question/8438/speeding-up-matrix-multiplication/I'm currently trying write code to compute with overconvergent modular symbols. In iterating a Hecke operator, the key (i.e. most time consuming) operation that is performed tons of times is simply taking the product of a large dense matrix say $M$ with a vector $v$, both with integral entries.
More precisely, let $p$ be a (relatively small) prime (think $p=11$) and $N$ some integer (think 100). I have an $N$ by $N$ matrix and am interested in quickly computing the product $M \cdot v$ modulo $p^N$.
I am simply using the intrinsic SAGE command of multiplying a matrix by a vector, and I was surprised to see that working with matrices over ${\bf Z}/p^n{\bf Z}$ was much (i.e. 10 times) slower than working with matrices over ${\bf Z}$.
My question: is there a faster way to do this computation than using SAGE's intrinsic matrix times a vector command over ${\bf Z}$?
Robert PollackFri, 04 Nov 2011 11:46:03 -0500http://ask.sagemath.org/question/8438/basic algebra with several variables-why won't it work?http://ask.sagemath.org/question/8317/basic-algebra-with-several-variables-why-wont-it-work/Hi,
I'm trying to use Sage-Notebook as a basic calculator and want to do some basic algebra for two variables. However, it keeps giving me syntax error messages when I type in the below. What am I doing wrong?
x, y = var('x, y')
solve([20*(6400-x-2y)==0, 80*(3200-x-y)==0], x, y)
Traceback (click to the left of this block for traceback)
...
SyntaxError: invalid syntax
Thank you!HunMon, 26 Sep 2011 12:12:19 -0500http://ask.sagemath.org/question/8317/Univariate Polynomial Multiplicationhttp://ask.sagemath.org/question/8241/univariate-polynomial-multiplication/What algorithms does sage use for univariate polynomial multiplication?
In particular, I am curious about the algorithm used for multiplication over finite fields and polynomials with coefficients in Z or Q.
More generally, is there an easy way to look under the hood and trace down the exact functions being called in the event I have a question like this again?mathmajorThu, 21 Jul 2011 11:30:28 -0500http://ask.sagemath.org/question/8241/bool gives another unexpected resulthttp://ask.sagemath.org/question/8175/bool-gives-another-unexpected-result/Here is the output
sage: var('c,u,v',domain=RR);assume(v>0,u>0,c>u,c>v);
(c, u, v)
sage: assumptions()
[v > 0, u > 0, c > u, c > v]
sage: bool(c^2 - u*v >= 0)
False
sage: bool(c^2 - u^2 >= 0)
True
sage: bool(c^2 - v^2 >= 0)
True
I don't see how c^2 - v*u can not be larger than or equal to zero. Why does this happen? Is there a workaround?omoplataMon, 20 Jun 2011 15:23:48 -0500http://ask.sagemath.org/question/8175/Matrix Multiplicationhttp://ask.sagemath.org/question/7833/matrix-multiplication/I am trying to multiply the following:
Iz=1/2*matrix(2,2,[[1,0],[0,-1]])
a=(1,0)
Iz*a
This should work, what am I doing wrong? I would expect (1/2, 0)
Sage returns the following error:
Traceback (click to the left of this block for traceback)
...
TypeError: 'sage.matrix.matrix_rational_dense.Matrix_rational_dense'
object cannot be interpreted as an index
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_sage_input_149.py", line 10, in <module>
exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("SXo9MS8yKm1hdHJpeCgyLDIsW1sxLDBdLFswLC0xXV0pO0l6CmE9KDEsMCkKSXoqYQ=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
File "", line 1, in <module>
File "/tmp/tmpJoBb2Y/___code___.py", line 5, in <module>
exec compile(u'Iz*a
File "", line 1, in <module>
File "element.pyx", line 2260, in sage.structure.element.Matrix.__mul__ (sage/structure/element.c:14881)
File "coerce.pyx", line 759, in sage.structure.coerce.CoercionModel_cache_maps.bin_op (sage/structure/coerce.c:6940)
TypeError: 'sage.matrix.matrix_rational_dense.Matrix_rational_dense' object cannot be interpreted as an index
Thanx
mhfreyTue, 28 Dec 2010 11:15:18 -0600http://ask.sagemath.org/question/7833/Is it possible to get implicitly multiplied output?http://ask.sagemath.org/question/7609/is-it-possible-to-get-implicitly-multiplied-output/With `implicit_multiplication(True)`, we can enter expressions using spaces instead of `*` to separate multiplied subexpressions:
`sage: var('x, y, z')
sage: implicit_multiplication(True)
sage: 3 x^4 y + 2 z sin(x z 3 y) - 3 y^2
3*x^4*y - 3*y^2 + 2*z*sin(3*x*y*z)
`
This works similarly for polynomials.
Is it possible to set (or implement practically) an option that automatically postparses output to use implicit multiplication? For example,
`
sage: R.<a,b,c> = QQ[]; R
Multivariate Polynomial Ring in a, b, c over Rational Field
sage: implicit_multiplication_output(True)
sage: R.random_element()
1/7 a b - 1/4 a c - c^2 + c
`
Mitesh PatelSat, 21 Aug 2010 22:39:55 -0500http://ask.sagemath.org/question/7609/