Cadabra
a field-theory motivated approach to computer algebra

zoom

Only show selected terms in a sum, and restrict subsequent algorithms to these terms.
Often you want manipulations to only apply to a selected subset of terms in a large sum. The zoom algorithm makes only certain terms visible, representing the remaining terms with dots. Any subsequent algorithms will only act on these visible terms. Here is an expression with 5 terms,
ex:=\int{ A_{m n} + B_{m n} C + D_{m} F_{n} C + T_{m n} + B_{m n} R}{x};
\(\displaystyle{}\int \left(A_{m n}+B_{m n} C+D_{m} F_{n} C+T_{m n}+B_{m n} R\right)\,\,{\rm d}x\)
\int{A_{m n} + B_{m n} C + D_{m} F_{n} C + T_{m n} + B_{m n} R}{x}
In order to restrict attention only to the terms containing a $B_{m n}$ factor, we use
zoom(_, $B_{m n} Q??$);
\(\displaystyle{}\int \left( ... +B_{m n} C+ ... +B_{m n} R\right)\,\,{\rm d}x\)
\int{ ... + B_{m n} C + ... + B_{m n} R}{x}
Subsequent algorithms only work on the visible terms above, not on the terms hidden inside the dots,
substitute(_, $C->Q$);
\(\displaystyle{}\int \left( ... +B_{m n} Q+ ... +B_{m n} R\right)\,\,{\rm d}x\)
\int{ ... + B_{m n} Q + ... + B_{m n} R}{x}
To make the hidden terms visible again, use unzoom, and note that the third term below has remained unaffected by the substitution above,
unzoom(_);
\(\displaystyle{}\int \left(A_{m n}+B_{m n} Q+D_{m} F_{n} C+T_{m n}+B_{m n} R\right)\,\,{\rm d}x\)
\int{A_{m n} + B_{m n} Q + D_{m} F_{n} C + T_{m n} + B_{m n} R}{x}
The zoom/unzoom combination is somewhat similar to the old deprecated take_match/replace_match algorithms, but makes it more clear that terms have been suppressed.
It is possible to give zoom a list of patterns, in which case each term that is kept must match at least one of these patterns. See the examples below.
ex:= x A1 + x**2 A2 + y A3 + y**2 A4;
\(\displaystyle{}x {A_{1}}+{x}^{2} {A_{2}}+y {A_{3}}+{y}^{2} {A_{4}}\)
x A1 + (x)**2 A2 + y A3 + (y)**2 A4
zoom(ex, ${x A??, y A??}$);
\(\displaystyle{}x {A_{1}}+ ... +y {A_{3}}+ ... \)
x A1 + ... + y A3 + ...
unzoom(ex);
\(\displaystyle{}x {A_{1}}+{x}^{2} {A_{2}}+y {A_{3}}+{y}^{2} {A_{4}}\)
x A1 + (x)**2 A2 + y A3 + (y)**2 A4
zoom(ex, ${x A??, x**2 A??}$);
\(\displaystyle{}x {A_{1}}+{x}^{2} {A_{2}}+ ... \)
x A1 + (x)**2 A2 + ...
Copyright © 2001-2024 Kasper Peeters
Questions? info@cadabra.science