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, 05 Aug 2019 17:29:55 +0200Substituting symbolic expressions for mixed differential forms.https://ask.sagemath.org/question/47397/substituting-symbolic-expressions-for-mixed-differential-forms/I'm doing some computations with matrices differential forms, and the run times are extremely long. So in an attempt to
keep run times down, I'm attempting to do matrix computations with symbolic terms, and then later replacing them with the mixed forms I want.
However, there's the coercion from mixed forms into the symbolic ring, and this is presenting a problem for me.
As a toy example of what I'm trying to do, I have the set up (say)
Sage: p=1
Sage: q=2
Sage: M = Manifold((2*p*q), 'M', field='complex')
Sage: U = M.open_subset('U')
Sage: x = U.chart(names=tuple('x_%d' % i for i in range(2*p*q)))
Sage: eU = x.frame()
Sage: d = [M.diff_form(1) for i in range(q)]
Sage: for i in range(q):
Sage: d[i][i] = x[i]
Sage: D = [M.mixed_form(comp=([0, d[i], 0, 0, 0])) for i in range(q)]
Sage: c = {(i): var("c_{}".format(i)) for i in range(q)}
Sage: exp = 0
Sage: for i in range(q):
Sage: for j in range(q):
Sage: exp = exp + c[i]*c[j]
Now, in my actual project I will have many of these variables, so it's not feasible to manually type them into one substitution at once, so I need to do it with a for loop, so I try
Sage: for i in range(q):
Sage: exp.subs({c[i] : D[i]})
But this is where I get the coercion error.
As mentioned, the actual computations I'm dealing with involve large matrices of mixed forms, and the run times would be WAY shorter if I can do it all in symbolic matrices, and then transfer the expressions I get out (which come from taking a trace). How might I be able to achieve this? sum8tionMon, 05 Aug 2019 17:29:55 +0200https://ask.sagemath.org/question/47397/Characteristic polynomial of symbolic matrix of size 7https://ask.sagemath.org/question/43839/characteristic-polynomial-of-symbolic-matrix-of-size-7/There is a problem when computing the characteristic polynomial of a matrix of size greater than 7 containing a large number of symbolic variables.
<pre><code>a = SR.var('a', 100)
M = identity_matrix(SR, 7)
for i in range(7):
for j in range(7):
M[i,j] = a[i*7+j]
print(M.charpoly().degree()) # prints 5
</code></pre>
The value it should print is 7. Over $\mathbb{Z}[a_0,a_1,\dots]$, the result is correct.
I use Sage 8.3 (Release Date: 2018-08-03), installed from the official repository of Archlinux. The bug is present both in command line and with `sage file.sage` (if I copy and paste the code above).ScreenNameSat, 06 Oct 2018 08:04:49 +0200https://ask.sagemath.org/question/43839/problems with product of vector of symbols with square matrixhttps://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?stablumWed, 10 Sep 2014 00:32:46 +0200https://ask.sagemath.org/question/24077/