4.1 Manipulating an expression

4.1.1 ExpandNonCommutativeMultiply[expr]

Aliases: NCE,NCExpand
Description: ExpandNonCommutativeMultiply[expr] expands out NonCommutativeMultiply’s in expr. It is the noncommutative generalization of the Mma Expand command.
Arguments: expr is an algebraic expression.
Comments / Limitations: None

4.1.2 NCCollect[expr, aListOfVariables]

Aliases: NCC
Description: NCCollect[expr,aListOfV ariables] collects terms of expression expr according to the elements of aListOfV ariables and attempts to combine them using a particular list of rules called rulesCollect. NCCollect is weaker than NCStrongCollect in that first-order and second-order terms are not collected together. NCCollect uses NCDecompose, and then NCStrongCollect, and then NCCompose.
Arguments: expr is an algebraic expression. aListOfV ariables is a list of variables.
Comments / Limitations: While NCCollect[expr,x] always returns mathematically correct expressions, it may not collect x from as many terms as it should. If expr has been expanded in the previous step, the problem does not arise. If not, the pattern match behind NCCollect may not get entirely inside of every factor where x appears.

4.1.3 NCStrongCollect[expr, aListOfVariables]

Aliases: NCSC
Description: It collects terms of expression expr according to the elements of aListOfV ariables and attempts to combine them using the particular list of rules called rulesCollect. In the noncommutative case, the Taylor expansion, and hence the collect function, is not uniquely specified. This collect function often collects too much and while mathematically correct is often stronger than you want. For example, x will factor out of terms where it appears both linearly a quadratically thus mixing orders.
Arguments: expr is an algebraic expression. aListOfV ariables is a list of variables.
Comments / Limitations: Not well documented.

4.1.4 NCCollectSymmetric[expr]

Aliases: NCCSym
Description: None
Arguments: expr is an algebraic expression.
Comments / Limitations: None

4.1.5 NCTermsOfDegree[expr,aListOfVariables,indices]

Aliases: None
Description: NCTermsOfDegree[expr,aListOfV ariables,indices] returns an expression such that each term is homogeneous of degree given by the indices in the variables of aListOfV ariables. For example, NCTermsOfDegree[x**y**x+x**x**y+x**x+ x**w,{x,y},indices] returns x**x**y +x**y **x if indices = {2, 1}, return x**w if indices = {1, 0}, return x **x if indices = {2, 0} and returns 0 otherwise. This is like Mathematica’s Coefficient command, but for the noncommuting case. However, it actually gives the terms and not the coefficients of the terms.
Arguments: expr is an algebraic expression, aListOfV ariables is a list of variables and indices is a list of positive integers which is the same length as aList.
Comments / Limitations: Not available before NCAlgebra 1.0

4.1.6 NCSolve[expr1==expr2,var]

Aliases: None
Description: NCSolve[expr1 == expr2,var] solves some simple equations which are linear in the unknown var. Note that in the noncommutative case, many equations such as Lyapunov equations cannot be solved for an unknown. This obviously is a limitation on the NCSolve command.
Arguments: expr1 and expr2 are Mathematica expressions. var is a single variable.
Comments / Limitations: See description.

4.1.7 Substitute[expr,aListOfRules,(Optional On)]

Aliases: Sub
Description: It repeatedly replaces one symbol or sub-expression in the expression by another expression as specified by the rule. (See Wolfram’s Mathematica 2.* book page 54.) More recently, we wrote the Transform command (§4.1.11) which apprears to be better.
Arguments: expr is an algebraic expression. aListOfRules is a single rule or list of rules specifying the substitution to be made. On = save rules to Rules.temp, temporarily over-riding SaveRules[Off]. ‘Off’ cannot over-ride SaveRules[On].
Comments / Limitations: The symbols /. and //. are often used in Mathematica as methods for substituting one expression for another. This method of substitution often does not work when the expression to be substituted is a subexpression within a (noncommutative) product. This Substitute command is the noncommutative analogue to //.

4.1.8 SubstituteSymmetric[expr, aListOfRules, (optional On)]

Aliases: SubSym
Description: When a rule specifies that a b, then SubSym also makes the replacement tp[a] tp[b].
Arguments: expr is an algebraic expression. aListOfRules is a single rule or list of rules specifying the substitution to be made. On = save rules to Rules.temp, temporarily over-rides SaveRules[Off]. ’Off’ can not over-ride SaveRules[On].
Comments / Limitations: None

4.1.9 SubstituteSingleReplace[expr, aListOfRules, (optional On)]

Aliases: SubSingleRep
Description: Replaces one symbol or sub-expression in the expression by another expression as specified by the rule. (See Wolfram’s Mathematica 2.* page 54.)
Arguments: expr is an algebraic expression. aListOfRules is a single rule or list of rules specifying the substitution to be made. On = save rules to Rules.temp, temporarily over-rides SaveRules[Off]. ‘Off’ can not over-ride SaveRules[On].
Comments / Limitations: The symbols /. and //. are often used in Mathematica as methods for substituting one expression for another. This method of substitution often does not work when the expression to be substituted is a subexpression within a (noncommutative) product. This Substitute command is the noncommutative analogue to /.

4.1.10 SubstituteAll[expr, aListOfRules, (optional On)]

Aliases: SubAll
Description: For every rule a b, SubAll also replaces,
tp[a] → tp[b]  inv[a] →  inv[b]   rt[a] → rt[b].
Arguments: expr is an algebraic expression. aListOfRules is a single rule or list of rules specifying the substitution to be made. On = save rules to Rules.temp, temporarily over-riding SaveRules[Off]. ’Off’ can not over-ride SaveRules[On].
Comments / Limitations: None

4.1.11 Transform[expr,aListOfRules]

Aliases: Transform
Description: None
Arguments: Transform is essentially a more efficient version of Substitute. It has the same functionality as Substitute.
Comments / Limitations: expr is an algebraic expression. aListOfRules is a single rule or list of rules specifying the substitution to be made.

Beware: Transform only applies rules once rather than repeatedly.

4.1.12 GrabIndeterminants[ aListOfPolynomialsOrRules]

Aliases: none
Description: GrabIndeterminants[L] returns the indeterminates found in the list of (noncommutative) expressions or rules L. For example, GrabIndeterminants[ { x**Inv[x]**x + Tp[Inv[x+a]], 3 + 4 Inv[a]**b**Inv[a] + x }] returns
{ x,  Inv[x],  Tp[Inv[x+a]],    Inv[a],  b  }.
Arguments: aListOfPolynomialsOrRules is a list of (noncommutative) expressions or rules.
Comments / Limitations:

4.1.13 GrabVariables[ aListOfPolynomialsOrRules ]

Aliases: none
Description: GrabVariables[ aListOfPolynomialsOrRules ] returns the variables found in the list of (noncommutative) expressions or rules aListOfPolynomialsOrRules. It is similar to the Mathematica command Variables[] which takes as an argument a list of polynomials in commutative variables or functions of variables. For example,
GrabVariables[   {  x**Inv[x]**x   + Tp[Inv[x+a]],    3 + 4  Inv[a]**b**Inv[a]    + x  }]
returns
{ x,  a, b  }.
Arguments: aListOfPolynomialsOrRules is a list of (noncommutative) expressions or rules.
Comments / Limitations:

4.1.14 NCBackward[expr]

Aliases: NCB
Description: It applies the rules
inv[Id - B * *A] * *B →  B * *inv[Id - A * *B]
inv[Id -  B * *A] * *inv[A] → inv[A] * *inv[Id - A * *B]
Arguments: expr is an algebraic expression.
Comments / Limitations: None

4.1.15 NCForward[expr]

Aliases: NCF
Description: It applies the rules
B * *inv[Id - A * *B] →  inv[Id - B * *A] * *B
inv[B] * *inv[Id - B * *A] →  inv[Id - B * *A] * *inv[A]
Arguments: expr is an algebraic expression.
Comments / Limitations: None

4.1.16 NCMonomial[expr]

Aliases: None
Description: NCMonomail changes the look of an expression by replacing nth integer powers of the NonCommutative variable x, with the product of n copies of x. For example, NCMonomial[2x2 + 5x4] evaluates to 2x **x + 5x **x **x **x and NCMonomial[(x2) **z **x] evaluates to x **x **z **x.
Arguments: Any noncommutative expression.
Comments / Limitations: The program greatly eases the task of typing in polynomials. For example, instead of typing x = x**x**x**x**x**x**x**x**x**x**x**x**y**x**x, one can type x = NCMono[(x12)**y**(x2)]. NCMono expands only integer exponents. This program will be (or has been, depending on the version of code which you have) superseded by NCMonomial and NCUnMonomial. NCMonomial implements the same functionality as NCMonomial and NCUnMonomial reverses the process. Caution: Mathematica treats x**y2 as (x**y)2 and so to have Mathematica acknowledge x**y2 then input x**(y2) exactly. This has nothing to do with NCAlgebra or NCMonomial.

4.1.17 NCUnMonomial[expr]

Aliases: None
Description: NCUnMonomial reverses what NCMonomial does. NCUnMonomial changes the look of an expression by replacing a product of n copies of x with xn. For example, NCUnMonomial[2x **x + 5x **x **x **x] evaluates to 2x2 + 5x4 and NCUnMonomial[x **x **z **x] evaluates to (x2) **z **x.
Arguments: Any noncommutative expression.
Comments / Limitations: See NCMonomial. NCAlgebra does not effectively manipulate expressions involving powers (such as (x2))