Welcome to Cadabra Q&A, where you can ask questions and receive answers from other members of the community.
0 votes

Hi,

I am trying to use Cadabra2 in IPython Notebooks. However, I get errors when I try to copy commands from the "Cadabra inside IPython/Jupyter" tutorial. For example, the following code

from cadabra2 import *
from IPython.display import display, Math, Latex

ex=Ex(r"A_{m n}")
Symmetric(ex)

gives the following error:
__init__(): incompatible constructor arguments. The following argument types are supported: 1. cadabra2.Symmetric(ex: cadabra2.Ex, param: cadabra2.Ex)

The samme happens if I try to initialize indices. It seems the functions giving error expects two arguments rather than one. Am I doing something wrong?

Thanks in advance.

asked in Bug reports by

1 Answer

+1 vote

The param argument should have been optional, but at some point we stripped out the default value for that argument, and since the Cadabra preparser fills it in automatically, no-one noticed.

Until this is fixed, you can use

Symmetric(ex, Ex(''))

in place of your last line (that is, set param equal to an empty expression).

answered by (37.9k points)

Great, thank you!

May I ask what is the correct way to specify optional arguments? The following does not seem to be correct

Indices(Ex(r"{m,n,p,q,r,s,t}"), Ex('fixed'))

I apologize if this is available in the documentation somewhere.

The documentation on how to use Cadabra directly from Python is very minimal, so please do ask if you get stuck (or, alternatively, switch to using the Cadabra notebook; life is much easier there).

Your example should read

Indices(Ex(r"{m,n,p,q,r,s,t}"), Ex(r"position=fixed"))

Note that if you have previously (in the same session) declared this index set in a different way, the type info will not get overwritten.

Thanks again. I will give IPython a shot, but if it is too much trouble I will consider switching to Cadabra notebook.

In principle, if someone would volunteer to write an IPython/Jupyter kernel for Cadabra, this could all be much nicer there too ;-)

...