a bug in "physics"? + one question

let me show a little problem i've found in physics package (if it really is the problem in package), and especially in Bra, Ket, and in product operators

first

 

lets calculate a product of a projector and a Ket:

sum(Ket(Psi,s).Bra(Psi,s),s=-n..n).Ket(Psi,1)

in this case the result would be obviosly Ket(Psi,1) and it's true.

Let's modify it now:

sum(Ket(Psi,s+1).Bra(Psi,s),s=-n..n).Ket(Psi,1)

this string will not be evaluated as Ket(Psi,2) (at least i was not able to find any possible way to do it)

still the correct answer will be given with this line :

sum(Ket(Psi,s+1).Bra(Psi,s),s=-10..10).Ket(Psi,1)

or this lineS:

A.Ket(Psi,1)

but not in this case :

subs(n=10, sum(Ket(Psi,s+1).Bra(Psi,s),s=-n..n).Ket(Psi,1))

The main difference  is that in "wrong" cases (which do not give correct result) the 'dot product' operator is automatically substituted by a '* product' (both of them are taken from physics package, and not the default).

In case of normal product, the bracket is not defined, so the expression is not simplified.

can anyone suggest how to avoid this automatic substitution (or how can i define a BraKet with normal product operator? or is this really a bug, which will be corrected (it's present in Maple11 and in Maple12) someday?

 

and another question.

the -> operator "creates" a function: x->f(x) . is there any possibility to put on the left side of this expression NOT ONLY variables, but any more complex structure? for example something similar to this: a[x,y]->a[f(x),y]

It can be done easily for example with Wolfram Matematica, but I can't do in with Maple =(

Thanks in anvance and sorry for my english

 

 

Composition operator

<p>Using the composition operator @, or @@ the repeated composition operator, you can use/build more complex structure, if I don't misunderstand your second question.</p>

more complex structure

There is some support for pattern matching in Maple, eg:

applyrule(a(u::symbol,v::symbol)=a(f(u),v),sin(a(x,y)));

                           sin(a(f(x), y))
alec's picture

2nd question

That can be done, for example, as

F:=a->applyop(f,1,a);

F(a[x,y]);
                              a[f(x), y]

or

G:=curry(applyop,f,1);

G(a[x,y]);
                              a[f(x), y]

Alec

Re: a bug in "physics"? + one question

Hi,

The fact that Sum(Ket(Psi, s+1) . Bra(Psi,s),s=-n..n) . Ket(Psi,1); is not evaluated to Ket(Psi,2) is a weakness to be fixed. The replacement of the dot operator -`.` by the non-commutative -`*` is a bug to be fixed - the fix may be in place in the first dot release. It is not visible in your post but you use sum, not Sum. Using sum, when you take s = -10..10, the sum is expanded and so the dot product works over one term at a time, receiving zero for all of them but for one that returns Ket(Psi,2). When you use subs(n = 10, `....`) the substitution is performed but the sum is not executed, so you fall in that situation (weakness) where the operation is not performed. To have the substitution and the operation evaluated use eval instead of subs. Regarding this other example where you first substitute and in the next line you perform the dot product, as you show (A . Ket(Psi,1)) the sum is performed not when you substitute but when you execute the `.` product in the second line, so that also works. By the way these computations are expected to return the same result with Sum or sum.

Regarding your question: no, in Maple you cannot define a mapping where the parameters are not of type symbol (what you call more complex structures). You can of course obtain the same behavior with the appropriate `->` mapping but it doesn't look as nice nor it can be entered so easily. For example, for your a[x,y] -> a[f(x), y] you can use (A::a[anything, anything]) -> a[f(op(1, A)), op(2, A)]

Edgardo S. Cheb-Terrab
Physics, Maplesoft

 

Thanks a lot for your

Thanks a lot for your answers! I'll try suggested ways!

GL&HF!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
}