Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
2  
Could augment with a second form \[Lambda]^(j_ /; IntegerQ[j] && j >= 1) \[Psi][n_] -> \[Alpha][ n + j] \[Psi][n + j] –  Daniel Lichtblau Feb 5 '13 at 15:51
    
Thanks! The rule you suggest is incorrect, but the idea is ok. –  Gregory Rut Feb 6 '13 at 12:13
    
Ah, yes, I missed the need for a product. I think the @m_goldberg variation sounds better... –  Daniel Lichtblau Feb 6 '13 at 14:47
add comment

2 Answers

up vote 4 down vote accepted

If you look at the full form versions of λ ψ[n] and λ^k ψ[n]

λ ψ[n] // FullForm

Times[λ, ψ[n]]

λ^k ψ[n] // FullForm

Times[Power[λ, k],ψ[n]]

you see that the second expression can't match your rule because it contains Power. Therefore, as Daniel Lichtblau suggests, you need to have two rules.

rules = {λ ψ[n_] -> α[1 + n] ψ[1 + n],
         λ^j_ ψ[n_] -> Product[α[s], {s, n + 1, n + j}] ψ[j + n]};

Now you can get both

λ ψ[n] /. rules

α[1 + n] ψ[1 + n]

and

λ^k ψ[n] /. rules

Product[α[s], {s, n + 1, n + k}] ψ[k + n]

share|improve this answer
    
Looks good, thanks! It is weird that myrule2 didn't bring any output, it 'almost' works on another pc (one λ is left because of different Head on RHS, as you mentioned). –  Gregory Rut Feb 6 '13 at 12:26
    
It appears that Gregory is not following this thread but I think you may learn something from the answer I just posted. –  Mr.Wizard Mar 5 '13 at 23:38
add comment

Preliminary

This can be done with a single rule and an Optional pattern because Power has the attribute OneIdentity. As the documentation states:

The fact that Times has attribute OneIdentity allows a pattern like n_. x_ to match x.

Observe:

{2^y, 3} /. a_Integer^b_. :> {a, b}
{{2, y}, {3, 1}}

(Power has an internal default of one.)

Note also that I use RuleDelayed (short form :>) and not Rule; this is necessary to correctly localize named patterns on the right hand side of the rule.

Your operation

With this knowledge we can now adjust your rule2; with this formulation we will need ReplaceRepeated (short form //.):

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

λ^3 ψ[n] //. rule
α[1 + n] α[2 + n] α[3 + n] ψ[3 + n]

Or if you prefer, the Product formulation:

rule2 = λ^j_. ψ[n_] :> Product[α[n + s], {s, j}] ψ[j + n];

λ ψ[n] /. rule2

λ^2 ψ[n] /. rule2
α[1 + n] ψ[1 + n]

α[1 + n] α[2 + n] ψ[2 + n]
share|improve this answer
    
Thanks, that's a very nice solution. –  Gregory Rut Sep 13 '13 at 18:52
    
@Gregory Welcome back to the site. I'm glad you found this helpful even now. :-) –  Mr.Wizard Sep 15 '13 at 17:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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