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

Hi and thanks as always for Cdb.

I am trying to implement a function that does its work only on the "zoomed" part of an expression.

For example, please consider the algorithm posted for expand_nabla(); a ref to that algorithm is below. I am using that algorithm and it works

But, when I zoom in on a specific term in an expression and call expand_nabla(), the call will still expand all instances of nabla rather than just the zoomed instance.

I think that the key point is as follows. There is a loop in expand_nabla that says

for nabla in ex[r'\nabla']:

The filter ex[r'\nabla'] returns all instances of \nabla but I want only the instances that appear in the zoom.

Any advice on how to change expand_nabla() so it would be zoom-sensitive?

Thanks GPN

related to an answer for: Expansion of covariant derivative
in General questions by (2.0k points)
edited by

2 Answers

+2 votes
 
Best answer

Good one. Everything which is hidden by zoom is wrapped inside an \ldots{...} node. So in principle you can avoid acting on those hidden terms by checking whether your node has an \ldots parent node.

Unfortunately, there isn't really anything that helps with that, unless you want to give up the simple way of walking the expression tree as in that covariant derivative example.

Fortunately, this was trivial to add on the C++ side. I have just pushed 2.4.5 which does the right thing and makes ExNode iterators jump over hidden nodes. Can you let me know if that works for you? (or let me know if you need a binary package if you cannot build from source).

by (82.6k points)
selected by

Thank you! I do indeed need a binary package. I am working on Ubuntu Linux 22.04 (inside Windows 11 with WSL2) and my current package - which works well with my config - is

https://cadabra.science/packages/ubuntu2204/cadabra2-2.4.3.5-jammy.deb

If you give me a link to the new binary (packaged for Ubuntu 22.04 as above please) I will test it ASAP.

Thanks again

GPN

Works. Thank you!

0 votes

For the time being I have found a rather inelegant solution.

Instead of using zoom/unzoom use take_match/replace_match.

I share this here as maybe it helps someone else or maybe someone has a better idea...

by (2.0k points)

take_match/replace_match are the old way of selecting sub-expressions, and there are likely still several bugs lurking inside. See my answer for the 'proper' solution.

...