Could someone explain me of this bit of code below is correct:
- Is it possible to define a function with a second bracket, see below, i.e.
f[x_][y_]
? And what does this implement? What does the syntax
[C_s]
do?i[a_,b_][C_s]:=ReplacePart[C,{a->C[[b]],b->C[[a]]}]
Edit
So let me a bit more detailed:
This is the code I want to understand, and that has to implement the function $$ S_{1,2} = \frac{i}{h(x)}\mathbb{P}_{1,2}+\mathbb{I}_{1,2}\,,$$ where $\mathbb{P}_{1,2}$ is the permutation operator and $\mathbb{I}_{1,2}$ is the identity operator, acting on the state 1 and state 2, of a three particle state defined by:
probe=s[{a1,x1},{a2,x2},{a3,x3}];
The code is the following:
i[a_,b_][C_s]:=ReplacePart[C,{a->C[[b]],b->C[[a]]}]
p[a_,b_][C_s]:=ReplacePart[C,{{a,2}->C[[b,2]],{b,2}->C[[a,2]]}]
S[a_,b_][A]:=A/.Cs:>Block[{xa=C[[a,2]],xb=C[[b,2]]},(I/h[xa-xb])p[a,b][C]+i[a,b][C]]
I do not understand how the last line can work; what is de `Cs' referring to?
C_
is not valid. You could haveC_List
and then only arguments of typeList
would work there. But I don't know of as
type $\endgroup$s
, then it's perfectly valid to useC_s
in a pattern. It means a single argument with head ('type')s
. $\endgroup$C_s
to actually readC_S
? As written, it will match tos[...]
but notS[...]
. $\endgroup$C
- it's a reserved symbol. $\endgroup$