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 have a function which has something like

myFunc[q,a state[c,d]]

a could be anything, and I want to tell Mathematica that this part of the function is linear, so that the coefficient of state[c,d] can be taken outside so that it achieves this result

a myFunc[q,state[c,d]]

Can this be done?

Why is this important? I'm doing simulations on quantum mechanics, and operators have to be linear with respect to numbers, and this is important to make calculations easier.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

You can try this

myFunc[q_, f_ + g_] := myFunc[q, f] + myFunc[q, g]
myFunc[q_, a_ f_state] := a myFunc[q, f] /; FreeQ[a, state]

So that

myFunc[q, a state[c, d]]
   a myFunc[q, state[c,d] ]

and

myFunc[q, a state[c, d] + b  state[e, h]]
   a myFunc[q, state[c, d]] + b myFunc[q, state[e, h]]

You can still assign a specific definition to myFunc[q_, f_state].

share|improve this answer
    
Thank you so much, you're a genius :) –  The Quantum Physicist Dec 10 '13 at 16:16
4  
You are Flattening me. --- No, wait... –  Peltio Dec 10 '13 at 17:41

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.