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

I tried the example on page 37 of the Cadabra Book

ex:= A + B3 + C7;
substitute(_, $A + M? + N? | \regex{M?}{"[A-Z]7"} -> \sin(M? N?\)/N?$);

In jupyter I got this error :


Traceback (most recent call last):
  File "/usr/local/lib/python3.12/dist-packages/cadabra2_jupyter/kernel.py", line 57, in do_execute
    self._execute_python(pycode)
  File "/usr/local/lib/python3.12/dist-packages/cadabra2_jupyter/kernel.py", line 111, in _execute_python
    self._sandbox_context(pycode)
  File "/usr/local/lib/python3.12/dist-packages/cadabra2_jupyter/context.py", line 51, in __call__
    exec(code, self._sandbox)
  File "<string>", line 2
    substitute(_, ""Ex(r'''A + M? + N? | \regex{M?}{"[A-Z]7"} -> \sin(M? N?)/N?''', False)); display(_)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?

The command line simply crash :

> ex:= A + B3 + C7; A + B3 + C7 > substitute(_\, $A + M? + N? | \regex{M?}{"[A-Z]7"} -> \sin(M? N?)/N?$);

Terminated by user interrupt.


I'm using Cadabra 2.5.12

in Bug reports by (340 points)

I do some search and it look like that the problem come from cadabra::convert_line. Still searching.

In fact the bug is in replace_dollar_expressions() which is called by convert_line(). I have a solution that work but I don't have made extensive test. So it may broke something else. Let me know if you want my solution.

1 Answer

+2 votes

If you have a fix please open an issue in github and attach a fix (or open a pull request).

(Regex is a feature I almost never use anymore, and was written before I started introducing rigid tests, so this does not surprise me at all).

by (86.3k points)

Ok, I will open an issue. I have to clean up the code before. Lot of trace to remove...

Done. I found a bug with a similar problem. bug # 230. I have attached the .cc file with my code and added a comment in that issue.

...