Skip to main content
Improved code formatting
Source Link
m_goldberg
  • 108.1k
  • 16
  • 104
  • 259

I tried to define a simple rule defining how \[Lambda]λ acts on \[Psi][n]ψ[n]:

myrule1 = \[Lambda]λ \[Psi][n_]ψ[n_] -> \[Alpha][nα[n + 1]  \[Psi][nψ[n + 1];

The result I get is correct provided there's just one \[Lambda]λ on the RHS of \[Psi][n]ψ[n]. For instance:

\[Lambda]^2λ^2  \[Psi][n]ψ[n] //. myrule1

isn't computed at all. On the other hand, if I do it step by step:

\[Lambda]λ \[Alpha][1α[1 + n] \[Psi][1ψ[1 + n] /. myrule1

I get the correct result. I tried to define a new rule:

myrule2 = \[Lambda]^m_λ^m_ \[Psi][n_]ψ[n_] -> \[Alpha][nα[n + 1] \[Lambda]^λ^(m - 1) \[Psi][nψ[n + 1];

but it doesn't work. Since the recursive method seemed to work, I created a function which multiplies \[Psi][m]ψ[m] by \[Lambda]λ n times:

times\[Lambda][n_]timesλ[n_] := Nest[Times[\[Lambda]Nest[Times[λ, #] /. myrule1 &, \[Psi][m]ψ[m], n] &

But this is a very crude way of solving this problem.

Do you have any other ideas?

I tried to define a simple rule defining how \[Lambda] acts on \[Psi][n]:

myrule1 = \[Lambda] \[Psi][n_] -> \[Alpha][n + 1]  \[Psi][n + 1];

The result I get is correct provided there's just one \[Lambda] on the RHS of \[Psi][n]. For instance:

\[Lambda]^2  \[Psi][n] //. myrule1

isn't computed at all. On the other hand, if I do it step by step:

\[Lambda] \[Alpha][1 + n] \[Psi][1 + n] /. myrule1

I get the correct result. I tried to define a new rule:

myrule2 = \[Lambda]^m_ \[Psi][n_] -> \[Alpha][n + 1] \[Lambda]^(m - 1) \[Psi][n + 1];

but it doesn't work. Since the recursive method seemed to work, I created a function which multiplies \[Psi][m] by \[Lambda] n times:

times\[Lambda][n_] := Nest[Times[\[Lambda], #] /. myrule1 &, \[Psi][m], n] &

But this is a very crude way of solving this problem.

Do you have any other ideas?

I tried to define a simple rule defining how λ acts on ψ[n]:

myrule1 = λ ψ[n_] -> α[n + 1]  ψ[n + 1];

The result I get is correct provided there's just one λ on the RHS of ψ[n]. For instance:

λ^2  ψ[n] //. myrule1

isn't computed at all. On the other hand, if I do it step by step:

λ α[1 + n] ψ[1 + n] /. myrule1

I get the correct result. I tried to define a new rule:

myrule2 = λ^m_ ψ[n_] -> α[n + 1] λ^(m - 1) ψ[n + 1];

but it doesn't work. Since the recursive method seemed to work, I created a function which multiplies ψ[m] by λ n times:

timesλ[n_] := Nest[Times[λ, #] /. myrule1 &, ψ[m], n] &

But this is a very crude way of solving this problem.

Do you have any other ideas?

added 6 characters in body
Source Link
Oleksandr R.
  • 23.1k
  • 4
  • 87
  • 126

I tried to define a simple rule definigdefining how [Lambda]\[Lambda] acts on [Psi][n]\[Psi][n]:

myrule1 = \[Lambda] \[Psi][n_] -> \[Alpha][n + 1]  \[Psi][n + 1];

The result I get is correct provided there's just one [Lambda]\[Lambda] on the RHS of [Psi][n]\[Psi][n]. For instance:

\[Lambda]^2  \[Psi][n] //. myrule1

isn't computed at all. On the other hand, if I do it step by step:

\[Lambda] \[Alpha][1 + n] \[Psi][1 + n] /. myrule1

I get the correct result. I tried to define a new rule:

myrule2 = \[Lambda]^m_ \[Psi][n_] -> \[Alpha][n + 1] \[Lambda]^(
 m - 1) \[Psi][n + 1];

but it doesn't work. Since the recursive method seemed to work, I created a function which multiplies [Psi][m]\[Psi][m] by [Lambda] n\[Lambda] n times:

times\[Lambda][n_] := Nest[Times[\[Lambda], #] /. myrule1 &, \[Psi][m], n] &

Nest[Times[[Lambda], #] /. myrule1 &, [Psi][m], n] & ButBut this is a very crude way of solving this problem.

Do you have any other ideas?

I tried to define a simple rule definig how [Lambda] acts on [Psi][n]:

myrule1 = \[Lambda] \[Psi][n_] -> \[Alpha][n + 1]  \[Psi][n + 1];

The result I get is correct provided there's just one [Lambda] on the RHS of [Psi][n]. For instance:

\[Lambda]^2  \[Psi][n] //. myrule1

isn't computed at all. On the other hand, if I do it step by step:

\[Lambda] \[Alpha][1 + n] \[Psi][1 + n] /. myrule1

I get the correct result. I tried to define a new rule:

myrule2 = \[Lambda]^m_ \[Psi][n_] -> \[Alpha][n + 1] \[Lambda]^(
 m - 1) \[Psi][n + 1];

but it doesn't work. Since the recursive method seemed to work, I created a function which multiplies [Psi][m] by [Lambda] n times:

times\[Lambda][n_] := 

Nest[Times[[Lambda], #] /. myrule1 &, [Psi][m], n] & But this is a very crude way of solving this problem.

Do you have any other ideas?

I tried to define a simple rule defining how \[Lambda] acts on \[Psi][n]:

myrule1 = \[Lambda] \[Psi][n_] -> \[Alpha][n + 1]  \[Psi][n + 1];

The result I get is correct provided there's just one \[Lambda] on the RHS of \[Psi][n]. For instance:

\[Lambda]^2  \[Psi][n] //. myrule1

isn't computed at all. On the other hand, if I do it step by step:

\[Lambda] \[Alpha][1 + n] \[Psi][1 + n] /. myrule1

I get the correct result. I tried to define a new rule:

myrule2 = \[Lambda]^m_ \[Psi][n_] -> \[Alpha][n + 1] \[Lambda]^(m - 1) \[Psi][n + 1];

but it doesn't work. Since the recursive method seemed to work, I created a function which multiplies \[Psi][m] by \[Lambda] n times:

times\[Lambda][n_] := Nest[Times[\[Lambda], #] /. myrule1 &, \[Psi][m], n] &

But this is a very crude way of solving this problem.

Do you have any other ideas?

Source Link
Grzegorz Rut
  • 1.2k
  • 8
  • 19

Efficient way of setting up a rule

I tried to define a simple rule definig how [Lambda] acts on [Psi][n]:

myrule1 = \[Lambda] \[Psi][n_] -> \[Alpha][n + 1]  \[Psi][n + 1];

The result I get is correct provided there's just one [Lambda] on the RHS of [Psi][n]. For instance:

\[Lambda]^2  \[Psi][n] //. myrule1

isn't computed at all. On the other hand, if I do it step by step:

\[Lambda] \[Alpha][1 + n] \[Psi][1 + n] /. myrule1

I get the correct result. I tried to define a new rule:

myrule2 = \[Lambda]^m_ \[Psi][n_] -> \[Alpha][n + 1] \[Lambda]^(
m - 1) \[Psi][n + 1];

but it doesn't work. Since the recursive method seemed to work, I created a function which multiplies [Psi][m] by [Lambda] n times:

times\[Lambda][n_] := 

Nest[Times[[Lambda], #] /. myrule1 &, [Psi][m], n] & But this is a very crude way of solving this problem.

Do you have any other ideas?