Ask Your Question
1

Type error in matrix of differential forms

asked 2018-02-22 10:07:48 +0100

Jonathan gravatar image

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?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2018-02-23 01:15:09 +0100

eric_g gravatar image

For dealing with differential forms with Sage, I would recommend to use the manifold implementation instead of the CoordinatePatch version, which is being deprecated (cf. the Trac ticket #24444). Could you please try with this version and tell whether the problem persists?

edit flag offensive delete link more

Comments

Thank you, it would be good to add this in the documentation of CoordinatePatch, etc. Also, the manifold implementation does not seem to support an algebra of differential forms (only a module) and seems a bit slower, but maybe I can get by using just exterior algebras over the symbolic ring...

Jonathan gravatar imageJonathan ( 2018-02-26 12:11:05 +0100 )edit

It's true that the parent of a differential form of degree p is the module of differential forms of that degree and not the algebra of all differental forms. Unfortunately, this prevents you to form a matrix of differential forms... Regarding the documentation, it has been edited in the ticket #24444 and will be effective in Sage 8.2: a deprecation warning will be issued when calling CoordinatePatch.

eric_g gravatar imageeric_g ( 2018-02-28 17:34:58 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-02-22 10:07:48 +0100

Seen: 345 times

Last updated: Feb 23 '18