1
$\begingroup$

I am trying to transform an expression to a list of rules and after that plot its graph. The expression has the following form

num \[LeftAngleBracket] fi[a,x], fi[c,y] \[RightAngleBracket] \[LeftAngleBracket] fi[b,x],fi[a,x] \[RightAngleBracket] \[LeftAngleBracket] fi[a,y],fi[b,x] \[RightAngleBracket]

By using the below substitution

/. \[LeftAngleBracket] fi[a_,x_], fi[b_,y_] \[RightAngleBracket] -> KroneckerDelta[a, b] UndirectedEdge[x, y]

I get

num (KroneckerDelta[a, b])^2 (UndirectedEdge[x, y])^2 UndirectedEdge[x, x]  KroneckerDelta[a, c] 

Here begins the main point of my question. My challenge is to separate the UndirectedEdge terms and create a list of them for plotting a graph. The other terms in the expression must appear as the factor of the Graph. In fact, I want to get something like this

num (KroneckerDelta[a, b])^2   KroneckerDelta[a, c] {UndirectedEdge[x, y],UndirectedEdge[x, y], UndirectedEdge[x, x]}

I tried the command

Cases[%, _UndirectedEdge | _Power]

that delivers a list of rules as follow

{(UndirectedEdge[x, y])^2 , UndirectedEdge[x, x]}

but the power of UndirectedEdge ruins the result for the Graph command. I would appreciate any light on this problem.

$\endgroup$
  • $\begingroup$ It's not clear to me what you are doing. Can you provide working code? <a> is not valid syntax. It's also not clear to me why you are trying to do arithmetic on UndirectedEdge. It makes no sense to do that. It would help if you explained the problem in plain language (rather than try to explain your non-working solution attempt), and then illustrate it with a simplified but complete example. $\endgroup$ – Szabolcs Sep 18 at 11:38
  • $\begingroup$ @Szabolcs, thanks very much for your attention. I made some changes into my question. I hope it be more clear now. In fact, I'm not doing arithmetic on UndirectedEdge. The Mathematica automatically transforms UndirectedEdge[x,y] UndirectedEdge[x,y] into (UndirectedEdge[x,y])^2. $\endgroup$ – Vahid Sep 18 at 12:29
  • $\begingroup$ You are multiplying together UndirectedEdge expressions, which makes no sense. In this example it is explicit: KroneckerDelta[a, b] UndirectedEdge[x, y]. Why are you doing this? $\endgroup$ – Szabolcs Sep 18 at 14:17
  • $\begingroup$ @Szabolcs, this multiplication is the result of the substitution, in the second code. Resuming, In the beginning I have an expression like f[x] <a,b><a,b><b,c>. I would like to transform it to f[x] {UndirectedEdge[a,b] , UndirectedEdge[a,b] , UndirectedEdge[b,c]}. Then I can make a plot of the Graph inside the list. $\endgroup$ – Vahid Sep 18 at 14:50
  • $\begingroup$ Not just the substitution, you are explicitly including yet another multiplication on the LHS of the rule. Why don't you just use Cases instead of trying to put UndirectedEdge in arithmetic expressions (where it does not belong)? Use the 3rd argument of Cases with Infinity to search at all levels. $\endgroup$ – Szabolcs Sep 18 at 15:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.