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

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.

in Bug reports by

2 Answers

+2 votes

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).

by (80.3k 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 ;-)

+1 vote

My old answer is no longer relevant; the current version (2.3.0 onwards) handles your example just fine.

by (80.3k points)
...