Selecting parts of expressions
In many other computer algebra systems, you can select parts of results using the mouse, paste them into a new input cell, and then continue the computation. Naively this sounds like a nice feature to have, and it is indeed quite useful for quick computations. However, for larger projects, this feature quickly becomes a major source of trouble. Once you use the cut-n-paste technique, you are no longer able to make any changes in cells before the one with pasted content. Or rather, you can make changes, but they will not automatically propagate to into the pasted cell. Any effect of the change at the top of the notebook will have to be evaluated until the point of the cut-n-paste, and then you have to do the cut-n-paste again by hand. Now this is fine if you just do a quick computation, as you will probably know precisely what you want to cut-n-paste. But if you give your notebook to someone else, this may no longer be clear. Worse, if you do not look at your notebook for some time, and then return after a few months (or years), you will most likely have forgotten completely what was the logic for the particular cut. For this reason, Cadabra does not support cut-n-paste of output. But that does not mean that you cannot select parts of expressions for subsequent computation. For that, Cadabra has a more systematic logic, which is built around thezoom
and unzoom
commands.Zooming into an expression
If you have a large expression, and want to select a part of it for further manipulation, while temporarily ignoring the rest, use thezoom
command. It takes an expression and a pattern,
and then suppresses all terms in the expression which do not match the pattern. An example:ex:= \int{ c A + c**2 B + c D + c**2 A }{x};
\(\displaystyle{}\int \left(c A+{c}^{2} B+c D+{c}^{2} A\right)\,\,{\rm d}x\)
\int{c A + (c)**2 B + c D + (c)**2 A}{x}
zoom(_, $c Q??$);
\(\displaystyle{}\int \left(c A+ ... +c D+ ... \right)\,\,{\rm d}x\)
\int{c A + ... + c D + ... }{x}
This has selected all terms with a single factor of $c$, and suppressed the other ones (but keeping
a reminder that those terms are still there, in the form of the dots). You can now work on the visible
terms as usual, e.g. doing a substitution,
substitute(_, $A -> E$);
\(\displaystyle{}\int \left(c E+ ... +c D+ ... \right)\,\,{\rm d}x\)
\int{c E + ... + c D + ... }{x}
In order to get back to the full expression, use
unzoom
,unzoom(_);
\(\displaystyle{}\int \left(c E+{c}^{2} B+c D+{c}^{2} A\right)\,\,{\rm d}x\)
\int{c E + (c)**2 B + c D + (c)**2 A}{x}
As you can see, the substitution has only changed the terms which were visible at the time.