expand noncommutative products over sums, Commutators, Brackets, etc. - Maple Programming Help

Physics[Expand] - expand noncommutative products over sums, Commutators, Brackets, etc.

 Calling Sequence Expand(expr)

Parameters

 expr - any expression

Description

 • The Expand command expands powers and distributes products over sums, where the products can be expressed with the * and ^ operators in the Physics package, or with the commutative (:-*, :-^) or inert (%*, %^) versions of them. Expand also expands the Commutator and AntiCommutator functions of the Physics package, Brackets and Inverse of products. The products resulting from these expansions are all returned normalized using Normal.
 • After the Physics package has been loaded, the functionality provided by Expand is also automatically provided through the standard expand command. However expand additionally expands mathematical functions, something that Expand does not do.
 Note: For the conventions adopted to represent noncommutative and anticommutative objects, see Setup and the types anticommutative and noncommutative.

Examples

 > $\mathrm{with}\left(\mathrm{Physics}\right):$
 > $\mathrm{Setup}\left(\mathrm{mathematicalnotation}=\mathrm{true}\right)$
 $\left[{\mathrm{mathematicalnotation}}{=}{\mathrm{true}}\right]$ (1)

For illustration purposes, first set $\mathrm{\theta }$ and $Q$ as prefixes to identify anticommutative variables and functions, and $Z$ to identify noncommutative ones (see Setup for details).

 > $\mathrm{Setup}\left(\mathrm{anticommutativeprefix}=\left\{Q,\mathrm{\theta }\right\},\mathrm{noncommutativeprefix}=Z\right)$
 $\left[{\mathrm{anticommutativeprefix}}{=}\left\{{Q}{,}{\mathrm{\theta }}\right\}{,}{\mathrm{noncommutativeprefix}}{=}\left\{{Z}\right\}\right]$ (2)

Consider now the noncommutative product between anticommutative objects and related sums.

 > $\mathrm{Q1}\left(\mathrm{Q1}+\mathrm{Q3}\left(\mathrm{Q4}+\mathrm{Q5}\right)\right)\mathrm{Q6}$
 ${\mathrm{Q1}}{}\left({\mathrm{Q1}}{+}{\mathrm{Q3}}{}\left({\mathrm{Q4}}{+}{\mathrm{Q5}}\right)\right){}{\mathrm{Q6}}$ (3)

You can get the expanded form of this product using expand or Expand:

 > $\mathrm{Expand}\left(\right)$
 ${\mathrm{Q1}}{}{\mathrm{Q3}}{}{\mathrm{Q4}}{}{\mathrm{Q6}}{+}{\mathrm{Q1}}{}{\mathrm{Q3}}{}{\mathrm{Q5}}{}{\mathrm{Q6}}$ (4)

Note that in the expanded representation, all * products are distributed. The following is a more complicated example, involving anticommutative and noncommutative objects.

 > $a\left(h\left(\mathrm{\theta }\right)+b\right)\mathrm{Q1}\mathrm{Z1}\mathrm{Q2}\mathrm{Q4}+\mathrm{Z3}\mathrm{Q5}c\left(\mathrm{Q3}-\mathrm{Q6}\right)f\left(\mathrm{\theta }\right)$
 ${a}{}\left({h}{}\left({\mathrm{\theta }}\right){+}{b}\right){}{\mathrm{Q1}}{}{\mathrm{Q2}}{}{\mathrm{Q4}}{}{\mathrm{Z1}}{+}{c}{}{f}{}\left({\mathrm{\theta }}\right){}{\mathrm{Q5}}{}\left({\mathrm{Q3}}{-}{\mathrm{Q6}}\right){}{\mathrm{Z3}}$ (5)
 > $\mathrm{Expand}\left(\right)$
 ${a}{}{h}{}\left({\mathrm{\theta }}\right){}{\mathrm{Q1}}{}{\mathrm{Q2}}{}{\mathrm{Q4}}{}{\mathrm{Z1}}{+}{a}{}{b}{}{\mathrm{Q1}}{}{\mathrm{Q2}}{}{\mathrm{Q4}}{}{\mathrm{Z1}}{-}{c}{}{f}{}\left({\mathrm{\theta }}\right){}{\mathrm{Q3}}{}{\mathrm{Q5}}{}{\mathrm{Z3}}{-}{c}{}{f}{}\left({\mathrm{\theta }}\right){}{\mathrm{Q5}}{}{\mathrm{Q6}}{}{\mathrm{Z3}}$ (6)

Now you can use the usual Maple commands to manipulate this expression. For example, note the existence of common factors entering the commutative products of this expression; you can take advantage of them to simplify it.

 > $\mathrm{convert}\left(,\mathrm{horner}\right)$
 ${a}{}\left({h}{}\left({\mathrm{\theta }}\right){}{\mathrm{Q1}}{}{\mathrm{Q2}}{}{\mathrm{Q4}}{}{\mathrm{Z1}}{+}{b}{}{\mathrm{Q1}}{}{\mathrm{Q2}}{}{\mathrm{Q4}}{}{\mathrm{Z1}}\right){+}{c}{}\left({-}{f}{}\left({\mathrm{\theta }}\right){}{\mathrm{Q3}}{}{\mathrm{Q5}}{}{\mathrm{Z3}}{-}{f}{}\left({\mathrm{\theta }}\right){}{\mathrm{Q5}}{}{\mathrm{Q6}}{}{\mathrm{Z3}}\right)$ (7)

To additionally expand also the mathematical functions, use expand instead of Expand; compare for instance these two results:

 > $\mathrm{Z3}\mathrm{Q5}c\left(\mathrm{Q3}-\mathrm{Q6}\right)\mathrm{cos}\left(a+b\right)$
 ${c}{}{\mathrm{cos}}{}\left({a}{+}{b}\right){}{\mathrm{Q5}}{}\left({\mathrm{Q3}}{-}{\mathrm{Q6}}\right){}{\mathrm{Z3}}$ (8)
 > $\mathrm{Expand}\left(\right)$
 ${-}{c}{}{\mathrm{cos}}{}\left({a}{+}{b}\right){}{\mathrm{Q3}}{}{\mathrm{Q5}}{}{\mathrm{Z3}}{-}{c}{}{\mathrm{cos}}{}\left({a}{+}{b}\right){}{\mathrm{Q5}}{}{\mathrm{Q6}}{}{\mathrm{Z3}}$ (9)
 > $\mathrm{expand}\left(\right)$
 ${-}{c}{}{\mathrm{cos}}{}\left({a}\right){}{\mathrm{cos}}{}\left({b}\right){}{\mathrm{Q3}}{}{\mathrm{Q5}}{}{\mathrm{Z3}}{-}{c}{}{\mathrm{cos}}{}\left({a}\right){}{\mathrm{cos}}{}\left({b}\right){}{\mathrm{Q5}}{}{\mathrm{Q6}}{}{\mathrm{Z3}}{+}{c}{}{\mathrm{sin}}{}\left({a}\right){}{\mathrm{sin}}{}\left({b}\right){}{\mathrm{Q3}}{}{\mathrm{Q5}}{}{\mathrm{Z3}}{+}{c}{}{\mathrm{sin}}{}\left({a}\right){}{\mathrm{sin}}{}\left({b}\right){}{\mathrm{Q5}}{}{\mathrm{Q6}}{}{\mathrm{Z3}}$ (10)

Expansion of Brackets over sums happen automatically but for inert Brackets you can use Expand

 > $\mathrm{Setup}\left(\mathrm{quantumoperators}=\left\{A,B\right\}\right)$
 $\left[{\mathrm{quantumoperators}}{=}\left\{{A}{,}{B}\right\}\right]$ (11)
 > $\mathrm{%Bracket}\left(\mathrm{Bra}\left(\mathrm{\phi }\right),aA+bB+c,\mathrm{Ket}\left(\mathrm{\psi }\right)\right)$
 ${\mathrm{%Bracket}}{}\left({\mathrm{Bra}}{}\left({\mathrm{φ}}\right){,}{A}{}{a}{+}{B}{}{b}{+}{c}{,}{\mathrm{Ket}}{}\left({\mathrm{ψ}}\right)\right)$ (12)
 > $\mathrm{Expand}\left(\right)$
 ${a}{}{\mathrm{%Bracket}}{}\left({\mathrm{Bra}}{}\left({\mathrm{φ}}\right){,}{A}{,}{\mathrm{Ket}}{}\left({\mathrm{ψ}}\right)\right){+}{b}{}{\mathrm{%Bracket}}{}\left({\mathrm{Bra}}{}\left({\mathrm{φ}}\right){,}{B}{,}{\mathrm{Ket}}{}\left({\mathrm{ψ}}\right)\right){+}{c}{}{\mathrm{%Bracket}}{}\left({\mathrm{Bra}}{}\left({\mathrm{φ}}\right){,}{\mathrm{Ket}}{}\left({\mathrm{ψ}}\right)\right)$ (13)
 >