Ask Your Question

Revision history [back]

Type error in matrix of differential forms

I'm having problems tracing the exact problem in my code: I have matrices of differential forms and at some point I get type errors.

Consider the following example:

class Test:
    def __init__(self):
        self.z = var('z')
        self.U = CoordinatePatch([self.z])
        self.D = DifferentialForms(self.U)
        self.d = self.D.gens()
        self.M = Matrix(self.D,2)

        print self.M
        self.M[0,0] = self.d[0]
        print self.M

        print (self.M.base_ring() is self.D)

The first instance works without error, from the second onward I get a type error:

┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 7.5.1, Release Date: 2017-01-15                   │
│ Type "notebook()" for the browser-based notebook interface.        │
│ Type "help()" for help.                                            │
└────────────────────────────────────────────────────────────────────┘
sage: load('bugtest.sage')
sage: Test()
[0 0]
[0 0]
[dz  0]
[ 0  0]
True
<__main__.Test instance at 0x1edc7cbd8>
sage: Test()
[0 0]
[0 0]
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-d1e5fd9e553c> in <module>()
----> 1 Test()

<string> in __init__(self)

/Applications/sage-7.5.1/src/sage/matrix/matrix0.pyx in sage.matrix.matrix0.Matrix.__repr__ (/Applications/sage-7.5.1/src/build/cythonized/sage/matrix/matrix0.c:11464)()
   1664         """
   1665         if self._nrows < max_rows and self._ncols < max_cols:
-> 1666             return self.str()
   1667         if self.is_sparse():
   1668             s = 'sparse'

/Applications/sage-7.5.1/src/sage/matrix/matrix0.pyx in sage.matrix.matrix0.Matrix.str (/Applications/sage-7.5.1/src/build/cythonized/sage/matrix/matrix0.c:13504)()
   1876                 rep = rep_mapping.get(x)
   1877             else:
-> 1878                 rep = repr(x)
   1879             S.append(rep)
   1880 

/Applications/sage-7.5.1/src/sage/structure/sage_object.pyx in sage.structure.sage_object.SageObject.__repr__ (/Applications/sage-7.5.1/src/build/cythonized/sage/structure/sage_object.c:2691)()
    190             return str(type(self))
    191         else:
--> 192             result = repr_func()
    193             if isinstance(result, unicode):
    194                 # Py3 compatibility: allow _repr_ to return unicode

/Applications/sage-7.5.1/local/lib/python2.7/site-packages/sage/tensor/differential_form_element.pyc in _repr_(self)
   1006         format = DifferentialFormFormatter(self.parent().base_space())
   1007         output = [format.repr(comp, fun) \
-> 1008                       for (comp, fun) in self._components.items()]
   1009         return ' + '.join(output)
   1010 

/Applications/sage-7.5.1/local/lib/python2.7/site-packages/sage/tensor/differential_form_element.pyc in repr(self, comp, fun)
    161             [('d%r' % self._space.coordinate(c)) for c in comp])
    162 
--> 163         if fun == 1 and len(comp) > 0:
    164             # We have a non-trivial form whose component function is 1,
    165             # so we just return the formatted form part and ignore the 1.

/Applications/sage-7.5.1/src/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression.__nonzero__ (/Applications/sage-7.5.1/src/build/cythonized/sage/symbolic/expression.cpp:17020)()
   2574                 return self.operator()(self.lhs().pyobject(), self.rhs().pyobject())
   2575 
-> 2576             pynac_result = decide_relational(self._gobj)
   2577             if pynac_result == relational_undecidable:
   2578                 raise ValueError('undecidable relation: ' + repr(self))

/Applications/sage-7.5.1/src/sage/structure/element.pyx in sage.structure.element.Element.__add__ (/Applications/sage-7.5.1/src/build/cythonized/sage/structure/element.c:11198)()
   1234         # Left and right are Sage elements => use coercion model
   1235         if BOTH_ARE_ELEMENT(cl):
-> 1236             return coercion_model.bin_op(left, right, add)
   1237 
   1238         try:

/Applications/sage-7.5.1/src/sage/structure/coerce.pyx in sage.structure.coerce.CoercionModel_cache_maps.bin_op (/Applications/sage-7.5.1/src/build/cythonized/sage/structure/coerce.c:10496)()
   1105         # We should really include the underlying error.
   1106         # This causes so much headache.
-> 1107         raise bin_op_exception(op, x, y)
   1108 
   1109     cpdef canonical_coercion(self, x, y):

TypeError: unsupported operand parent(s) for '+': 'Algebra of differential forms in the variables z' and 'Integer Ring'

Maybe the symbolic variable is not "safe" inside a class?