Note that there are some explanatory texts on larger screens.

plurals
  1. PONoncommutative Multiplication and Negative coeffcients at the Beginning of an Expression in Mathematica
    primarykey
    data
    text
    <p>With the help of some very gracious stackoverflow contributors <a href="https://stackoverflow.com/questions/5023863/redefine-noncommutative-multiplication-in-mathematica">in this post</a>, I have the following new definition for <code>NonCommutativeMultiply (**)</code> in Mathematica: </p> <p><code> Unprotect[NonCommutativeMultiply];<br> ClearAll[NonCommutativeMultiply]<br> NonCommutativeMultiply[] := 1<br> NonCommutativeMultiply[___, 0, ___] := 0<br> NonCommutativeMultiply[a___, 1, b___] := a ** b<br> NonCommutativeMultiply[a___, i_Integer, b___] := i*a ** b<br> NonCommutativeMultiply[a_] := a<br> c___ ** Subscript[a_, i_] ** Subscript[b_, j_] ** d___ /; i &gt; j :=<br> c ** Subscript[b, j] ** Subscript[a, i] ** d<br> SetAttributes[NonCommutativeMultiply, {OneIdentity, Flat}]<br> Protect[NonCommutativeMultiply];</code> </p> <p>This multiplication is great, however, it does not deal with negative values at the beginning of an expression, i.e.,<br> <code>a**b**c + (-q)**c**a</code><br> should simplify to<br> <code>a**b**c - q**c**a</code><br> and it will not. </p> <p>In my multiplication, the variable <code>q</code> (and any integer scaler) is commutative; I am still trying to write a <code>SetCommutative</code> function, without success. I am not in desperate need of <code>SetCommutative</code>, it would just be nice. </p> <p>It would also be helpful if I were able to pull all of the <code>q's</code> to the beginning of each expression, i.e.,:<br> <code>a**b**c + a**b**q**c**a</code><br> should simplify to:<br> <code>a**b**c + q**a**b**c**a</code><br> and similarly, combining these two issues:<br> <code>a**b**c + a**c**(-q)**b</code><br> should simplify to:<br> <code>a**b**c - q**a**c**b</code> </p> <p>At the current time, I would like to figure out how to deal with these negative variables at the beginning of an expression and how to pull the <code>q's</code> and <code>(-q)'s</code> to the front as above. I have tried to deal with the two issues mentioned here using <code>ReplaceRepeated (\\.)</code>, but so far I have had no success. </p> <p>All ideas are welcome, thanks...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload