Message Boards Message Boards

0
|
2120 Views
|
2 Replies
|
1 Total Likes
View groups...
Share
Share this post:
GROUPS:

Replace variables with general arguments with functions of the arguments

Posted 9 years ago

Hello, I am manipulating lists of pairs of elements like {x[i][t] y[j][1],y[j][1]y[k][t1]...}. Each element has two indices and I would like to replace each pair by a function as follows:

when there are two x's: x[i][t] x[j][t1] -> A[i,j,t,t1] ; when there is one x and one: x[i][t] y[j][t1] -> B[i,j,t,t1] ; when there are any 2 y's: y[j][t1] y[k][t1] -> 0.

where A,B are functions of 4 arguments that I have defined elsewhere. I would like to do this without having to give explicit values to the i,j,t,t1 and loop over them. How could this be done? Thank you in advance and best wishes,

Stefano

2 Replies

You can try with a replacement rule:

repl = {x[i_][t_] x[j_][t1_] :> A[i, j, t, t1],
   x[i_][t_] y[j_][t1_] :> B[i, j, t, t1],
   y[i_][t_] y[j_][t1_] -> 0};
{x[i][t] y[j][1], y[j][1] y[k][t1]} /. repl
POSTED BY: Gianluca Gorni

This works, thank you!

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract