Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I see this instance for the first time, so the answer is a dry one, only pointing to the error. It comes, because the "magic" is not implemented. In fact, sage: christoffel['^j_kl'] produces the error. Going into it, i.e. rather in its implementation via

christoffel.__getitem__('^j_kl')

the caller is the method christoffel.__getitem__ . Inspecting it in the sage interpreter via

sage: christoffel.__getitem__??

we see that this method is not ready for use in the above context. The method tries to parse the data for the "known purposes", so first, it is parsing the arguments, here only '^j_kl''. I was not starting the debugger, but it is a good chance that we run into this code:

        else:
            format_type = args[-1]
            indices = args[:-1]
    if isinstance(indices, slice):
        return self._get_list(indices, no_format, format_type)
    else:
        sign, ind = self._ordered_indices(indices)
        if (sign == 0) or (ind not in self._comp): # the value is zero:

so it goes into indices = args[:-1], which makes the indices variable be ^k_k, which is of course nonsense from the mathematical point of view. (And format_type gets the last letter.) Now the error message comes from something like

sage: christoffel = gg.christoffel_symbols()
sage: try:
....:     christoffel._ordered_indices('^j_k')
....: except ValueError:
....:     import traceback
....:     traceback.print_exc()
....:     
Traceback (most recent call last):
  File "<ipython-input-247-b13ce8540566>", line 2, in <module>
    christoffel._ordered_indices('^j_k')
  File "/usr/lib/python2.7/site-packages/sage/tensor/modules/comp.py", line 3101, in _ordered_indices
    ind = list(self._check_indices(indices))
  File "/usr/lib/python2.7/site-packages/sage/tensor/modules/comp.py", line 660, in _check_indices
    " while {} are provided").format(self._nid, len(ind)))
ValueError: wrong number of indices: 3 expected, while 4 are provided
sage:

Note: The method that crashes would work for instance for:

sage: christoffel._ordered_indices((2,1,0))
(1, (2, 0, 1))

As a rule, personally, i do not expect that "similar classes" have "similar magic", because the developers may differ, so much of the implementation may be designed in an other way, often so that features of the "other class" are not implemented / implementable (without hard work).

I see this instance for the first time, so the answer is a dry one, only pointing to the error. It comes, because the "magic" is not implemented. In fact, sage: christoffel['^j_kl'] produces the error. Going into it, i.e. rather in its implementation via

christoffel.__getitem__('^j_kl')

the caller is the method christoffel.__getitem__ . Inspecting it in the sage interpreter via

sage: christoffel.__getitem__??

we see that this method is not ready for use in the above context. The method tries to parse the data for the "known purposes", so first, it is parsing the arguments, here only '^j_kl'''^j_kl'. I was not starting the debugger, but it is a good chance that we run into this code:

        else:
            format_type = args[-1]
            indices = args[:-1]
    if isinstance(indices, slice):
        return self._get_list(indices, no_format, format_type)
    else:
        sign, ind = self._ordered_indices(indices)
        if (sign == 0) or (ind not in self._comp): # the value is zero:

so it goes into indices = args[:-1], which makes the indices variable be ^k_k^j_k, which is of course nonsense from the mathematical point of view. (And format_type gets the last letter.) Now the error message comes from something like

sage: christoffel = gg.christoffel_symbols()
sage: try:
....:     christoffel._ordered_indices('^j_k')
....: except ValueError:
....:     import traceback
....:     traceback.print_exc()
....:     
Traceback (most recent call last):
  File "<ipython-input-247-b13ce8540566>", line 2, in <module>
    christoffel._ordered_indices('^j_k')
  File "/usr/lib/python2.7/site-packages/sage/tensor/modules/comp.py", line 3101, in _ordered_indices
    ind = list(self._check_indices(indices))
  File "/usr/lib/python2.7/site-packages/sage/tensor/modules/comp.py", line 660, in _check_indices
    " while {} are provided").format(self._nid, len(ind)))
ValueError: wrong number of indices: 3 expected, while 4 are provided
sage:

Note: The method that crashes would work for instance for:

sage: christoffel._ordered_indices((2,1,0))
(1, (2, 0, 1))

As a rule, personally, i do not expect that "similar classes" have "similar magic", because the developers may differ, so much of the implementation may be designed in an other way, often so that features of the "other class" are not implemented / implementable (without hard work).