Noncommutative Multiplication and Negative coeffcients at the Beginning of an Expression in Mathematica -


with of gracious stackoverflow contributors in post, have following new definition noncommutativemultiply (**) in mathematica:

unprotect[noncommutativemultiply];
clearall[noncommutativemultiply]
noncommutativemultiply[] := 1
noncommutativemultiply[___, 0, ___] := 0
noncommutativemultiply[a___, 1, b___] := ** b
noncommutativemultiply[a___, i_integer, b___] := i*a ** b
noncommutativemultiply[a_] := a
c___ ** subscript[a_, i_] ** subscript[b_, j_] ** d___ /; > j :=
c ** subscript[b, j] ** subscript[a, i] ** d
setattributes[noncommutativemultiply, {oneidentity, flat}]
protect[noncommutativemultiply];

this multiplication great, however, not deal negative values @ beginning of expression, i.e.,
a**b**c + (-q)**c**a
should simplify to
a**b**c - q**c**a
, not.

in multiplication, variable q (and integer scaler) commutative; still trying write setcommutative function, without success. not in desperate need of setcommutative, nice.

it helpful if able pull of q's beginning of each expression, i.e.,:
a**b**c + a**b**q**c**a
should simplify to:
a**b**c + q**a**b**c**a
, similarly, combining these 2 issues:
a**b**c + a**c**(-q)**b
should simplify to:
a**b**c - q**a**c**b

at current time, figure out how deal these negative variables @ beginning of expression , how pull q's , (-q)'s front above. have tried deal 2 issues mentioned here using replacerepeated (\\.), far have had no success.

all ideas welcome, thanks...

the key doing realize mathematica represents a-b a+((-1)*b), can see

in[1]= fullform[a-b] out[2]= plus[a,times[-1,b]] 

for first part of question, have add rule:

noncommutativemultiply[times[-1, a_], b__] := - ** b 

or can catch sign position:

noncommutativemultiply[a___, times[-1, b_], c___] := - ** b ** c 

update -- part 2. general problem getting scalars front pattern _integer in current rule spot things manifestly integers. wont spot q integer in construction assuming[{element[q, integers]}, a**q**b].
achieve this, need examine assumptions, process expensive put in global transformation table. instead write transformation function apply manually (and maybe remove current rule form global table). might work:

ncmscalarreduce[e_] := e //.  {     noncommutativemultiply[a___, i_ /; simplify@element[i, reals],b___]      :> ** b } 

the rule used above uses simplify explicitly query assumptions, can set globally assigning $assumptions or locally using assuming:

assuming[{q \[element] reals},   ncmscalarreduce[c ** (-q) ** c]]  

returns -q c**c.

hth


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -