Items tagged with physics physics Tagged Items Feed

Hi all,


I'm trying to initialize a 4-vector and promote it as a tensor in Maple 16 using the Physics package. My attempt so far has been unsuccessful :) 

This 4-vector needs to be a function of the coordinates X. What I'm trying to do is to allocate terms by terms my tensor as indicated in my attempt below. Everything looks fine (the query is telling me F2 is a tensor) but when I'm trying to compute contravariant quantities, I can't obtain an answer for a given coordinate (here F2[~n](X) is not equal du v_1(X))... Finally, the last line, computing the sum over all the indexes is not giving me an answer... 


restart; with(Physics):
Setup(coordinatesystems = cartesian):








Surely, something is wrong in my way of defining a spacetime tensor. What would be the solution to obtain a decent contravariant F2?


Another more or less related question would be to know how to compute a taylor expansion of a function itself i.e. 1/(1+f(X))~ 1-f(X) since f<<1? Would there be a built-in fonction to do such a thing?


Many thanks!




I`m new with the Physics package. I have a Hamiltonian in a lattice written in terms of creation and annihilation operators. The Question is, How can I label a Creation and an Annihiliation operator for each site in the Lattice. WIth this, I can compute mean values and other stuffs associated with the Hamiltonian.


Many thanks in advance

Two new things recently added to the latest version of Physics available on Maplesoft's R&D Physics webpage are worth mentioning outside the framework of Physics.

  • automaticsimplification. This means that after "Physics:-Setup(automaticsimplification=true)", the output corresponding to every single input (literally) gets automatically simplified in size before being returned to the screen. This is fantastically convenient for interactive work in most situations.

  • Add Physics:-Library:-Assume, to perform the same operations one typically performs with the  assume command, but without the side effect that the variables get redefined. So the variables do not get redefined, they only receive assumptions.

This new Assume implements the concept of an "extended assuming". It permits re-using expressions involving the variables being assumed, expressions that were entered before the assumptions were placed, as well as reusing all the expressions computed while the variables had assumptions, even after removing the variable's assumptions. None of this is possible when placing assumptions using the standard assume. The new routine also permits placing assumptions on global variables that have special meaning, that cannot be redefined, e.g. the cartesian, cylindrical or spherical coordinates sets, or the coordinates of a coordinate spacetime system within the Physics package, etc.




This is Physics from today:


`2014, December 9, 16:51 hours`


Automatic simplification is here. At this point automaticsimplification is OFF by default.


[automaticsimplification = false]


Hence, for instance, if you input the following expression, the computer just echoes your input:

Physics:-`*`(a, c)+Physics:-`*`(a, d)+Physics:-`*`(b, c)+Physics:-`*`(b, d)



There is however some structure behind (1.3) and, in most situations, it is convenient to have these structures
apparent, in part because they frequently provide hints on how to proceed ahead, but also because a more
compact expression is, roughly speaking, simpler to understand. To see this
automaticsimplification in action,
turn it ON:

Setup(automaticsimplification = true)

[automaticsimplification = true]


Recall this same expression (you could input it with the equation label (1.3) as well) 

Physics:-`*`(a, c)+Physics:-`*`(a, d)+Physics:-`*`(b, c)+Physics:-`*`(b, d)



What happened: this output, as everything else after you set automaticsimplification = true and with no
exceptions, is now further processed with simplify/size before being returned. And enjoy computing with frankly
shorter expressions all around! And no need anymore for "simplify(%, size)" every three or four input lines.

Another  example, typical in computer algebra where expressions become uncomfortably large and difficult to
read: convert the following input to 2D math input mode first, in order to compare what is being entered with the
automatically simplified output on the screen

-Physics:-`*`(Physics:-`*`(Physics:-`*`(3, sin(x)^(1/2)), cos(x)^2), sin(x)^m)+Physics:-`*`(Physics:-`*`(Physics:-`*`(3, sin(x)^(1/2)), cos(x)^2), cos(x)^n)+Physics:-`*`(Physics:-`*`(Physics:-`*`(4, sin(x)^(1/2)), cos(x)^4), sin(x)^m)-Physics:-`*`(Physics:-`*`(Physics:-`*`(4, sin(x)^(1/2)), cos(x)^4), cos(x)^n)



You can turn automaticsimplification OFF the same way

Setup(automaticsimplification = false)

[automaticsimplification = false]


New Library:-Assume facility; welcome to the world of "extended assuming" :)


Consider a generic variable, x. Nothing is known about it



  nothing known about this object


Each variable has associated a number that depends on the session, and the computer (internally) uses this
number to refer to the variable.




When using the assume  command to place assumptions on a variable, this number, associated to it, changes,
for example:

assume(0 < x and x < Physics:-`*`(Pi, 1/2))




Indeed, the variable x got redefined and renamed, it is not anymore the variable x referenced in (1.8).


Originally x, renamed x~:

  is assumed to be: RealRange(Open(0),Open(1/2*Pi))


The semantics may seem confusing but that is what happened, you enter x and the computer thinks x~, not x 
anymore.This means two things:

1) all the equations/expressions, entered before placing the assumptions on x using assume, involve a variable x 
that is different than the one that exists after placing the assumptions, and so these previous expressions
be reused
. They involve a different variable.

2) Also, because, after placing the assumptions using assume, x refers to a different object, programs that depend
on the
x that existed before placing the assumptions will not recognize the new x redefined by assume .


For example, if x was part of a coordinate system and the spacetime metric g[mu, nu]depends on it, the new variable x
redefined within assume, being a different symbol, will not be recognized as part of the dependency of "g[mu,nu]." This
posed constant obstacles to working with curved spacetimes that depend on parameters or on coordinates that
have a restricted range. These problems are resolved entirely with this new
Library:-Assume, because it does not
redefine the variables. It only places assumptions on them, and in this sense it works like
assuming , not assume .
As another example, all the
Physics:-Vectors commands look for the cartesian, cylindrical or spherical coordinates
[x, y, z], [rho, phi, z], [r, theta, phi] in order to determine how to proceed, but these variables disappear if you use
assume to place assumptions on them. For that reason, only assuming  was fully compatible with Physics, not assume.


To undo assumptions placed using the assume command one reassigns the variable x to itself:

x := 'x'



Check the numerical address: it is again equal to (1.8) 




·All these issues get resolved with the new Library:-Assume, that uses all the implementation of the existing 
assume command but with a different approach: the variables being assumed do not get redefined, and hence:
a) you can reuse expressions/equations entered before placing the assumptions, you can also undo the
assumptions and reuse results obtained with assumptions. This is the concept of an
extended assuming. Also,
commands that depend on these assumed variables will all continue to work normally, before, during or after
placing the assumption, because
the variables do not get redefined.




  nothing known about this object


So this simplification attempt accomplishes nothing




Let's assume now that 0 < x and x < (1/2)*Pi

Library:-Assume(0 < x and x < Physics:-`*`(Pi, 1/2))

{x::(RealRange(Open(0), Open((1/2)*Pi)))}


The new command echoes the internal format representing the assumption placed.

a) The address is still the same as (1.8)




So the variable did not get redefined. The system however knows about the assumption - all the machinery of the
assume command is being used


Originally x, renamed x:

  is assumed to be: RealRange(Open(0),Open(1/2*Pi))


Note that the renaming is to the variable itself - i.e. no renaming.

Hence, expressions entered before placing assumptions can be reused. For example, for (1.12), we now have




To clear the assumptions on x, you can use either of Library:-Assume(x=x) or Library:-Assume(clear = {x, ...}) in
the case of many variables being cleared in one go, or in the case of a single variable being cleared:

Library:-Assume(clear = x)



  nothing known about this object


The implementation includes the additionally functionality, for that purpose add the keyword
anywhere in the calling sequence. For example:


{x::(RealRange(Open(0), infinity))}



Originally x, renamed x:

  is assumed to be: RealRange(Open(0),infinity)


Library:-Assume(additionally, x < 1)

{x::(RealRange(Open(0), Open(1)))}


Library:-Assume(x = x)

In summary, the new Library:-Assume command implements the concept of an extended assuming, that can be
turned ON and OFF at will at any moment without changing the variables involved.



Edgardo S. Cheb-Terrab
Physics, Differential Equations and Mathematical Functions, Maplesoft

Hello everybody,

I will start a course in mastering QM in a MOOC format (Massive Open Online Course).  Up to now, I always do the calculation by hand and sometimes with the LinearAlgebra package.  But now I need to do the calculation more rapidly.  So I decided to learn how to use this package for this course.


The help system give a too generalized way to do it.  Even by looking the example, I didn't find praticle example to it.  So is there a generous person who could take a little bit of hi time to show me how to do it by using an exemple that yo will find attach to this post.


Thank you in advance for your trouble.

Besgt regards.


Mario Lemelin
Maple 18.2 Win 7 and Ubuntu 14.04 - 64 bits
MapleSim 7 Win 7 and Ubuntu 14.04 - 64 bits messagerie : téléphone :  (819) 376-0987

Partial rectification for the Physics:-Simplify and Physics:-Library:-SortProducts procedures dealing with Fermi annihilation/creation operators

This post will be useful for physicists dealing with Fermi annihilation/creation operators. Physics Package provides plenty of powerful tools for quantum operators handling, however some of them often fail to render correct result.  In particular incorrect behaviour with respect to Fermi annihilation/creation operators is observed for routines Simplify and SortProducts.  In this post I present my procedures S*implifyFermionicOperators and SortProductsFermi which partially solve these issues.

Problems with Physics Package routines


Short explanation of custom routines SimplifyFermionicOperators and SortProductsFermi


"Details for SimplifyFermionicOperators(z,prefix)"


"Details for SortProductsFermi(x,L,prefix)"


Weak points


Final notes



As title , there has 2 balls(A and B) which I can change Quality 、Radius and Position for two dimensions(x and y axis),

A has a velocity and B quiescence , let A strike to B .

As shown below


I did a sample ,but i can't make it accurately .

I want to let my sample like the below sample



I am trying to extract the terms that are a product of a commutative part and an operator part from the input expression. That is I am trying to extract a terms like a*A.B where A and B are quantum pperators.

I am trying to do it by creating corresponding structured type:

Physics[Setup](op = {A, B}, quiet);

`type/ProdComOp` := `&*`(commutative, specfunc(anything, Physics:-`*`));
z0 := u*A.B-A+k*B+B.A.B+g;
z1 := z0+v*A.B.A;
S1 := indets(z1, ProdComOp);

and all it is Ok. The result is 
But if

z2 := z0-v*A.B.A; 
S2 := indets(z2, ProdComOp);

however I expected to receive the same as S1.

How to handle the sign of the commutative part? Thank you.

I want to simulate Inelastic collision



There has 2 ball which I can change  Quality and Radius.




one ball  move to another stirless ball with diferent angle

Presentations of the first national congress of civil engineering developed at the University Cesar Vallejo. From 10 to 12 November 2014.



(in spanish)

Lenin Araujo Castillo

Physics Pure

Computer Science





Hi. I need to test if a variable is a dot-product of "anything"-s (usually it is quantum operators).
I try the following

Physics:-Setup(mathematicalnotation = true);
Physics:-Setup(anticommutativeprefix = psi);
ap1 := Physics:-Creation(psi, 1, notation = explicit);
am1 := Physics:-Annihilation(psi, 1, notation = explicit);
ap2 := Physics:-Creation(psi, 2, notation = explicit);
am2 := Physics:-Annihilation(psi, 2, notation = explicit);

z1 := ap1.am1.ap2:
type(z1, ('`.`')(anything));

and get



z2 := a*b*c; 
type(z2, (':-`*`')(anything));



I studied ?type,structured and other sources but didn't find any answer.


I figured I'd start a new thread for odd things I come across whilst using the new physics package. 

I have found this, and am not sure if it is expected. 




Setup(mathematicalnotation = true):


Setup(Commutator(Psigma[i], Psigma[j]) = Physics:-`*`(Physics:-`*`(I, ep_[i, j, k]), Psigma[k]), AntiCommutator(Psigma[i], Psigma[j]) = Physics:-`*`(2, kd_[i, j]));

[algebrarules = {%AntiCommutator(Physics:-Psigma[i], Physics:-Psigma[j]) = 2*Physics:-KroneckerDelta[i, j], %Commutator(Physics:-Psigma[i], Physics:-Psigma[j]) = I*Physics:-LeviCivita[i, j, k]*Physics:-Psigma[k]}]














EDIT 2: Ok, here is what I am trying to do with Maple.

I have the following expression:




 (j times)

Now the above expression should be zero. I get a set of equations in orders of lambda. The H matrices are known. I only need to find the S matrices.

Anyways, the HOffDiag is the sum above and the GetAdvCommutator0 is this nested commutator. And I need this sum evaluated up to order n (n is a given input-number) in lambda. The rest is really not that performance hungry.



EDIT: Ok, it realy seems that this sum of commutators is something that takes Maple forever. I have written a new MWE. Is it possible to speed things up? Maybe using assumptions or so?


restart;with(Physics):with(LinearAlgebra): Setup(mathematicalnotation=true):Setup(noncommutativeprefix={M,H,S});

[noncommutativeprefix = {H, M, S}]


    if power <= 0 then return M fi:
    if power = 1 then

        return mtaylor(Commutator(M,add(lambda^l*S[l],l=1..order)),lambda, order+1) fi:
    return mtaylor(Commutator(GetAdvCommutator0(power-1,order,M),add(lambda^l*S[l],l=1..order)),lambda,order+1):
end proc:


HOffDiag(3); # still fast

lambda^3*Physics:-Commutator(H[0], S[3])+lambda^2*Physics:-Commutator(H[0], S[2])+lambda*Physics:-Commutator(H[0], S[1])+(1/6)*lambda^3*Physics:-Commutator(Physics:-Commutator(Physics:-Commutator(H[0], S[1]), S[1]), S[1])+lambda^2*Physics:-Commutator(H[1], S[1])+lambda^3*Physics:-Commutator(H[1], S[2])+lambda*H[2]+(1/2)*lambda^3*Physics:-Commutator(Physics:-Commutator(H[2], S[1]), S[1])


HOffDiag(6); # takes a very long time, I didn't even try entering higher numbers

Warning,  computation interrupted



I know this question is really unspecific. However, since I am still new to Maple, and since you don't program with Maple as you would do with c++, I would appreciate some advise. I have written a program in Maple and I don't know if it works correctly. All I know is, it is pretty slow :(.

So if anyone of you could just have a short look at my attached worksheet and could tell me, if I at some point used an obvious "don't", I would greatly appreciate it.






A Maple worksheet


Setup Maple




[noncommutativeprefix = {H, MA, MB, S}]




Input parameter



H0:=Matrix([[ 0 , 0 , 0 , 0 ],
            [ 0 , 0 , 0 , 0 ],
            [ 0 , 0 , U , 0 ],
            [ 0 , 0 , 0 , U ]]);

H0 := Matrix(4, 4, {(1, 1) = 0, (1, 2) = 0, (1, 3) = 0, (1, 4) = 0, (2, 1) = 0, (2, 2) = 0, (2, 3) = 0, (2, 4) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = U, (3, 4) = 0, (4, 1) = 0, (4, 2) = 0, (4, 3) = 0, (4, 4) = U})


H1:=Matrix([[ 0 , 0 , 0 , 0 ],
            [ 0 , 0 , 0 , 0 ],
            [ 0 , 0 , 0 , 0 ],
            [ 0 , 0 , 0 , 0 ]]);

H1 := Matrix(4, 4, {(1, 1) = 0, (1, 2) = 0, (1, 3) = 0, (1, 4) = 0, (2, 1) = 0, (2, 2) = 0, (2, 3) = 0, (2, 4) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = 0, (3, 4) = 0, (4, 1) = 0, (4, 2) = 0, (4, 3) = 0, (4, 4) = 0})


H2:=Matrix([[  0 , 0 , -t , -t ],
            [  0 , 0 ,  t ,  t ],
            [ -t , t ,  0 ,  0 ],
            [ -t , t ,  0 ,  0 ]]);

H2 := Matrix(4, 4, {(1, 1) = 0, (1, 2) = 0, (1, 3) = -t, (1, 4) = -t, (2, 1) = 0, (2, 2) = 0, (2, 3) = t, (2, 4) = t, (3, 1) = -t, (3, 2) = t, (3, 3) = 0, (3, 4) = 0, (4, 1) = -t, (4, 2) = t, (4, 3) = 0, (4, 4) = 0})


orderNumber:= 4 ;







Define all necessary functions




    local Comm:
    if power <= 0 then return H[0] fi:
    if power = 1 then return add(coeff(Commutator(H[0],add(lambda^l*S[l],l=1..order)),lambda,n)*lambda^n,n=0..order) fi:
    return add(coeff(Commutator(GetAdvCommutator0(power-1,order),add(lambda^l*S[l],l=1..order)),lambda,n)*lambda^n,n=0..order):
end proc:

    local Comm:
    if power <= 0 then return lambda*H[1] fi:
    if power = 1 then return add(coeff(Commutator(lambda*H[1],add(lambda^l*S[l],l=1..order)),lambda,n)*lambda^n,n=0..order) fi:
    return add(coeff(Commutator(GetAdvCommutator1(power-1,order),add(lambda^l*S[l],l=1..order)),lambda,n)*lambda^n,n=0..order):
end proc:

    local Comm:
    if power <= 0 then return lambda*H[2] fi:
    if power = 1 then return add(coeff(Commutator(lambda*H[2],add(lambda^l*S[l],l=1..order)),lambda,n)*lambda^n,n=0..order) fi:
    return add(coeff(Commutator(GetAdvCommutator2(power-1,order),add(lambda^l*S[l],l=1..order)),lambda,n)*lambda^n,n=0..order):
end proc:








computeHBlockDiag:=proc( n::posint,firstBlockWidth::posint, H0::Matrix, H1::Matrix, H2::Matrix )
    local expr, Orders, i, eq, j, eq2, orders,smatrices,rows::posint,evallist,m,l,cols,Hdiag,ff;
    expr:=HOffDiag(n);       # !!!!! this one is one of the slowest parts I think                                     
    for i from 1 to n do                                          
        for j from 1 to i-1 do

    for i from 1 to n do
        for j from 1 to i-1 do
        for m from 1 to firstBlockWidth do
            for l from firstBlockWidth+1 to rows do

    expr:=HOnDiag(n);            # !!!!! and this one of course (almost identical to the one above)                                       
    evallist:= [op(evallist), H[0]=H0,S[n]=smatrices[n]];

    return Hdiag;
end proc:





Matrix(4, 4, {(1, 1) = -2*t^2/U, (1, 2) = 2*t^2/U, (1, 3) = 0, (1, 4) = 0, (2, 1) = 2*t^2/U, (2, 2) = -2*t^2/U, (2, 3) = 0, (2, 4) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = U+2*t^2/U, (3, 4) = 2*t^2/U, (4, 1) = 0, (4, 2) = 0, (4, 3) = 2*t^2/U, (4, 4) = U+2*t^2/U})



Vector(4, {(1) = 0, (2) = U, (3) = -4*t^2/U, (4) = (U^2+4*t^2)/U})








Matrix(4, 4, {(1, 1) = -2*t^2/U, (1, 2) = 2*t^2/U, (1, 3) = 0, (1, 4) = 0, (2, 1) = 2*t^2/U, (2, 2) = -2*t^2/U, (2, 3) = 0, (2, 4) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = U+2*t^2/U, (3, 4) = 2*t^2/U, (4, 1) = 0, (4, 2) = 0, (4, 3) = 2*t^2/U, (4, 4) = U+2*t^2/U})


#Not so fast


Matrix(4, 4, {(1, 1) = -2*t^2/U-(8/3)*t^4/U^3, (1, 2) = 2*t^2/U+(8/3)*t^4/U^3, (1, 3) = 0, (1, 4) = 0, (2, 1) = 2*t^2/U+(8/3)*t^4/U^3, (2, 2) = -2*t^2/U-(8/3)*t^4/U^3, (2, 3) = 0, (2, 4) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = U+2*t^2/U+(8/3)*t^4/U^3, (3, 4) = 2*t^2/U+(8/3)*t^4/U^3, (4, 1) = 0, (4, 2) = 0, (4, 3) = 2*t^2/U+(8/3)*t^4/U^3, (4, 4) = U+2*t^2/U+(8/3)*t^4/U^3})


#Already pretty slow :(


Warning,  computation interrupted







I've noticed there are settings to set the type of index for spinors or gauge index in the physics package. i.e Setup(spinorindices=lowercaselatin). I also notice there is a setting for specifying the form of tetrads. 

I cannot find any further documention or examples on how to use these functions. Could anyone point me in the direction of a text or help function as to how these are implemented. 

Simple examples of things I am trying to do:

> with(Physics); Setup(spinorindices=lowercaselatin, metric = <some_line_element>)

> tetrad[`mu`,`~a`] = Matrix(<some tetrad matrix>) 

> Define(%)

I recieve the following error: invalid input: unknown uses a 2nd argument, a, which is missing.

I am hoping for a tensor that uses the metric to raise/lower the `mu` component and the minkowskian metric to raise/lower the `a` component. 

If there is further documentation that I am missing, I'm happy to check that out instead of asking lots of questions here. 

Thanks again.


This may be just my lack of maple syntax, however I cannot seem to find a way to add upper indicies in tensors (without first converting them to some other object, array, matrix etc)

In the physics package an example is just the metric tensor. 

I am trying to do something like this:



add(g_[~mu,2], mu=1..2) 

Is there an easy way of summing upper indicies? Obviously lower indicies work, because the add/sum command recognizes the variable to iterate. 

Thanks in advance,



1 2 3 4 5 6 7 Last Page 1 of 9