Mathematica Mathematica : Noncommutative Multiply and Replacement Rules

Click For Summary
SUMMARY

The discussion focuses on the implementation of noncommutative multiplication and replacement rules in Mathematica for ordering expressions based on character values. The user defines a function, Val[a_], to convert characters to their ASCII values and applies replacement rules to reorder the expression GH[a].GH[b].GH[c].GH[d].GH[b]. Despite the presence of defined rules, the user encounters issues with the rules not applying as expected, leading to confusion about the evaluation process. The final working solution is provided using the Sort function, which successfully orders the elements as intended.

PREREQUISITES
  • Familiarity with Mathematica syntax and functions
  • Understanding of noncommutative algebra concepts
  • Knowledge of character encoding and ASCII values
  • Experience with replacement rules and pattern matching in Mathematica
NEXT STEPS
  • Explore advanced pattern matching techniques in Mathematica
  • Learn about the evaluation order in Mathematica expressions
  • Investigate the use of custom sorting algorithms in Mathematica
  • Study the implications of noncommutative operations in algebraic structures
USEFUL FOR

This discussion is beneficial for Mathematica users, particularly those working with symbolic computation, noncommutative algebra, and anyone looking to optimize expression manipulation and ordering in their code.

Hepth
Science Advisor
Gold Member
Messages
457
Reaction score
40
Code:
Val[a_] := ToCharacterCode[ToString[a]][[1]];
GH[a].GH[b].GH[c].GH[d].GH[b] //. {GH[a_].GH[b_] :> If[Val[a] > Val[b], GH[b].GH[a], GH[a].GH[b]]}

I have the noncommutative multiply of GH[a].GH.GH[c].GH[d].GH

My goal is to order these in increasing charcter value. (Val is the function to convert to basically ascii code).

Shouldn't this work? And give GH[a].GH.GH.GH[c].GH[d] at the end?


Notice also that
Code:
GH[a].GH[b].GH[c].GH[d].GH[b]

GH[a].GH[b].GH[c].GH[d].GH[b] //. {
(A_).GH[a_].GH[b_].(B_) :> 
   A.If[Val[a] > Val[b], GH[b].GH[a], GH[a].GH[b]].B,
  (A_).GH[a_].GH[b_] :> 
   A.If[Val[a] > Val[b], GH[b].GH[a], GH[a].GH[b]],
  GH[a_].GH[b_].(B_) :> 
   If[Val[a] > Val[b], GH[b].GH[a], GH[a].GH[b]].B,
  GH[a_].GH[b_] :> If[Val[a] > Val[b], GH[b].GH[a], GH[a].GH[b]]}


GH[a].GH[b].GH[c].GH[d].GH[b] //. {
  (A_).GH[a_].GH[b_] :> A.If[Val[a] > Val[b], GH[b].GH[a], GH[a].GH[b]]
  }

Even though the rule in the 2nd one exists in the replacements of the first, it doesn't apply. I think the problem comes in the fact that its applying a rule to the position right before the last two, and once that is evaluated, does not re-evaluate it, even though no real action was taken. Though I guess if you consider it replacing itself an action, then that's what it did.

Any ideas? Even if its a different method. This is something that I'm trying to write in a much more complicated way, and I need to figure out how these work.

Thanks!
 
Physics news on Phys.org
Code:
In[1]:= Val[a_] := ToCharacterCode[ToString[a]][[1]]; 
GH[a].GH[b].GH[c].GH[d].GH[b] //. Dot[h___, GH[a_], GH[b_], t___] /;
   Val[a]>Val[b]:>Dot[h,GH[b],GH[a],t]

Out[1]= GH[a].GH[b].GH[b].GH[c].GH[d]

Or

Code:
In[2]:= Sort[GH[a].GH[b].GH[c].GH[d].GH[b]]

Out[2]= GH[a].GH[b].GH[b].GH[c].GH[d]
 
Last edited:

Similar threads

  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 15 ·
Replies
15
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
20
Views
5K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 52 ·
2
Replies
52
Views
13K
  • · Replies 1 ·
Replies
1
Views
6K