1
$\begingroup$

I have an expression where terms Transpose[R].R appear. R is a matrix with the property Transpose[R].R=IdentityMatrix[3].

How do I remove all the sub-expressions of type Transpose[R].R from an expression? Example: suppose I have the expression:

A.B.Transpose[R].R.C

I want to transform it into

A.B.C
$\endgroup$

closed as off-topic by user9660, MarcoB, m_goldberg, Kuba, ubpdqn Jun 29 '16 at 11:41

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Community, MarcoB, m_goldberg, Kuba, ubpdqn
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    $\begingroup$ /. Transpose[x_].x_ -> Sequence[]. Have you read the documentation re: patterns, replacement, etc? This is not an interactive documentation answer site :-) Also, avoid using uppercase initials for your symbols - or you're asking for trouble. $\endgroup$ – ciao Jul 21 '15 at 22:19
  • 1
    $\begingroup$ @ciao Fantastic, thanks a lot. Yes, I always ask only after searching the documentation, which did not show Sequence[] where I looked. How did you learn about this command? $\endgroup$ – space_voyager Jul 21 '15 at 22:21
  • $\begingroup$ Sequence is in the documentation... and the documentation certainly is not a cookbook for pattern machinations, though it does have copious examples. Best way to learn those kind of things is peruse the docs, find something interesting, and play with it in "what if" kind of ways. I've found that to be most effective teaching others term-rewriting languages like MMA. $\endgroup$ – ciao Jul 21 '15 at 22:24
  • $\begingroup$ @ciao. Thanks. Can you tell me one last thing. What would I write for xyz if I want in Select[expr,!FreeQ[#,xyz]&] to select any term of expr which contains a pattern R.(something, don't care what).R? Thanks a lot! $\endgroup$ – space_voyager Jul 21 '15 at 22:30
  • 2
    $\begingroup$ Incidentally ciao's replacement relies on special evaluation rules for Dot due to it having the Flat attribute. This is something in which you should invest the time to understand. $\endgroup$ – Mr.Wizard Jul 21 '15 at 22:32
2
$\begingroup$

I suppose you would like something like this?

Select[A.B.Transpose[R].R.T, FreeQ[#, R] &]

This mainly used the expression's tree like property. Due to Dot's Flat Property, the whole expression will actually looks like Dot[A,B,Transpose[R],R,T], thus this code can generate the result you want:

A.B.T

Note that I've change your C to T cause C is a built in symbol.....

Or you may use this if you only want to remove it when Transpose[R] and R are ordered in this particular way:

A.B.Transpose[R].R.T //. Dot[x___, Transpose[R], R, y___] -> Dot[x, y]

(*A.B.T*)
$\endgroup$
  • $\begingroup$ Your first method doesn't work on A.B.R.Transpose[R].R.T, just on the OP's toy example. $\endgroup$ – Michael E2 Jun 28 '16 at 16:39
  • $\begingroup$ It worked~ Though a incorrect result as it will delete everthing related to R...... $\endgroup$ – Wjx Jul 1 '16 at 11:16

Not the answer you're looking for? Browse other questions tagged or ask your own question.