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.Mon, 05 Aug 2019 10:29:55 -0500Substituting symbolic expressions for mixed differential forms.http://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 10:29:55 -0500http://ask.sagemath.org/question/47397/Matrices not equal, but entries are. Why?http://ask.sagemath.org/question/7516/matrices-not-equal-but-entries-are-why/Hi,
I've created a class which derives from RingElement and a class which derives from Ring, and made the latter the parent of the former. I have then placed the "elements" of this new ring I've constructed as entries into a matrix.
Given another such matrix with the same dimensions as the first, I have constructed its entries to be the same as the entries of the first matrix. The same means that when we compare entry (i,j) in the first matrix to entry (i,j) in the second, they are equal.
Why do the matrices not compare as equal? Is there anything you see in this error which could help me easily remedy this?
Here is the error I get:
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "_sage_input_58.py", line 10, in
> <module>
> exec compile(u'open("___code___.py","w").write("#
> -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("dnYgPSBtYXRyaXhfY2xlYW5lZF91cF9yZWR1Y3Rpb24oQV9BQikKQV9BQiA9PSBtYXRyaXhfY2xlYW5lZF91cF9yZWR1Y3Rpb24oQV9BQikuZ2V0X21hdHJpeF9BKCk="),globals())+"\\n");
> execfile(os.path.abspath("___code___.py"))
> File "", line 1, in <module>
> File "/tmp/tmplS8fJ8/___code___.py", line
> 3, in <module>
> exec compile(u'A_AB == matrix_cleaned_up_reduction(A_AB).get_matrix_A()
> File "", line 1, in <module>
> File "matrix_generic_dense.pyx", line 167,
> in
> sage.matrix.matrix_generic_dense.Matrix_generic_dense.__richcmp__
> (sage/matrix/matrix_generic_dense.c:3036)
> File "element.pyx", line 876, in
> sage.structure.element.Element._richcmp
> (sage/structure/element.c:8370) File
> "element.pyx", line 923, in
> sage.structure.element.Element._richcmp_c_impl
> (sage/structure/element.c:8671) File
> "matrix_dense.pyx", line 126, in
> sage.matrix.matrix_dense.Matrix_dense._cmp_c_impl
> (sage/matrix/matrix_dense.c:2757)
> File "element.pyx", line 913, in
> sage.structure.element.Element.__cmp__
> (sage/structure/element.c:8541) File
> "element.pyx", line 809, in
> sage.structure.element.Element._cmp
> (sage/structure/element.c:7239) File
> "coerce.pyx", line 880, in
> sage.structure.coerce.CoercionModel_cache_maps.canonical_coercion
> (sage/structure/coerce.c:8296) File
> "coerce.pyx", line 1419, in
> sage.structure.coerce.CoercionModel_cache_maps._coercion_error
> (sage/structure/coerce.c:14011)
> RuntimeError: There is a bug in the
> coercion code in Sage. Both x
> (=[((((1)(2)(3)(4), _, {{1}}, {{2},
> {1}}, {{2}, {3}, {1}}), {}), ())]) and
> y (=[((((1)(2)(3)(4), _, {{1}}, {{2},
> {1}}, {{2}, {3}, {1}}), {}), ())]) are
> supposed to have identical parents but
> they don't. In fact, x has parent
> 'Combinatorial Scalar Ring' whereas y
> has parent 'Combinatorial Scalar Ring'
> Original elements [((((1)(2)(3)(4), _,
> {{1}}, {{2}, {1}}, {{2}, {3}, {1}}),
> {}), ())] (parent Combinatorial Scalar
> Ring) and [((((1)(2)(3)(4), _, {{1}},
> {{2}, {1}}, {{2}, {3}, {1}}), {}),
> ())] (parent Combinatorial Scalar
> Ring) and maps <type 'NoneType'> None
> <type
> 'sage.structure.coerce_maps.DefaultConvertMap_unique'>
> Conversion map: From: Combinatorial
> Scalar Ring To: Combinatorial
> Scalar Ring
SLOtoSFThu, 15 Nov 2012 08:45:43 -0600http://ask.sagemath.org/question/7516/