Pascal4QM

453 Reputation

12 Badges

5 years, 342 days

MaplePrimes Activity


These are answers submitted by Pascal4QM

Hi,
 

restart; with(Physics)

Coordinates(X = [x1, x2, x3, x4])

`Default differentiation variables for d_, D_ and dAlembertian are:`*{X = (x1, x2, x3, x4)}

 

`Systems of spacetime Coordinates are:`*{X = (x1, x2, x3, x4)}

 

{X}

(1)

Setup(metric = F1(X)*dx1^2+F2(X)*dx2^2+F3(X)*dx3^2+F4(X)*dx4^2)

[metric = {(1, 1) = F1(X), (2, 2) = F2(X), (3, 3) = F3(X), (4, 4) = F4(X)}]

(2)

g_[]

Physics:-g_[mu, nu] = Matrix(%id = 18446746283142732966)

(3)

``


 

Download ArbDiagMetric.mw

As shown by Kitonum, Physics is the good framework for these problems. It is possible to go further using the keyword "differentialoperators", see the attached mw.

Also interesting:

https://www.mapleprimes.com/posts/208710-Quantum-Commutation-Rules-Basics

 


 

``

``

``

Define B as an Hermitian operator, and A as a differential operator with respect to some  differentiation variables, for instance: x,y,z.

restart; with(Physics)

Setup(hermitianoperators = {B, x, y, z}, differentialoperators = {[A, [x, y, z]]})

[differentialoperators = {[A, [x, y, z]]}, hermitianoperators = {B, x, y, z}]

(1)

(A+B)^3

Physics:-`^`(A+B, 3)

(2)

Now, A and B are non-commutative

Expand(Physics[`^`](A+B, 3))

Physics:-`^`(A, 3)+Physics:-`*`(Physics:-`^`(A, 2), B)+Physics:-`*`(A, B, A)+Physics:-`*`(A, Physics:-`^`(B, 2))+Physics:-`*`(B, Physics:-`^`(A, 2))+Physics:-`*`(B, A, B)+Physics:-`*`(Physics:-`^`(B, 2), A)+Physics:-`^`(B, 3)

(3)

It is even possible to factor it back

Factor(Physics[`^`](A, 3)+Physics[`*`](Physics[`^`](A, 2), B)+Physics[`*`](A, B, A)+Physics[`*`](A, Physics[`^`](B, 2))+Physics[`*`](B, Physics[`^`](A, 2))+Physics[`*`](B, A, B)+Physics[`*`](Physics[`^`](B, 2), A)+Physics[`^`](B, 3))

Physics:-`^`(A+B, 3)

(4)

Now, to convert A^3 to a nested function, it must be applied to something that depends on x, y, z:

A^3*F(x, y, z)

Physics:-`*`(Physics:-`^`(A, 3), F(x, y, z))

(5)

Library:-ApplyProductsOfDifferentialOperators(Physics[`*`](Physics[`^`](A, 3), F(x, y, z)))

A(A(A(F(x, y, z))))

(6)

Library:-ApplyProductsOfDifferentialOperators((Physics[`^`](A, 3)+Physics[`*`](Physics[`^`](A, 2), B)+Physics[`*`](A, B, A)+Physics[`*`](A, Physics[`^`](B, 2))+Physics[`*`](B, Physics[`^`](A, 2))+Physics[`*`](B, A, B)+Physics[`*`](Physics[`^`](B, 2), A)+Physics[`^`](B, 3))*F(x, y, z))

A(A(A(F(x, y, z))))+A(A(Physics:-`*`(B, F(x, y, z))))+A(Physics:-`*`(B, A(F(x, y, z))))+A(Physics:-`*`(Physics:-`^`(B, 2), F(x, y, z)))+Physics:-`*`(B, A(A(F(x, y, z))))+Physics:-`*`(B, A(Physics:-`*`(B, F(x, y, z))))+Physics:-`*`(Physics:-`^`(B, 2), A(F(x, y, z)))+Physics:-`*`(Physics:-`^`(B, 3), F(x, y, z))

(7)

If required, it is possible to give an explicit value to A

A := proc (ee) options operator, arrow; diff(ee, x, y, z) end proc

proc (ee) options operator, arrow; Physics:-diff(ee, x, y, z) end proc

(8)

A(A(A(F(x, y, z))))

Physics:-diff(Physics:-diff(Physics:-diff(Physics:-diff(Physics:-diff(Physics:-diff(Physics:-diff(Physics:-diff(diff(F(x, y, z), x), y), z), x), y), z), x), y), z)

(9)

``


 

Download PhysicsOperators.mw

Hi,

That's a common case, that is however only partly supported by the Physics Package. A workaround is to  use "algebrarules" in two steps. First definine a "zero" function. Indeed, to be parametrized, algebrarules needs to find the indicices on both sides of a commutator. In a second step, define this zero function so that it always return 0:

restart; with(Physics);
Setup(noncommutativeprefix = {u, v, w});
               [noncommutativeprefix = {u, v, w}]
Setup(algebrarules = {%Commutator(u[m], u[n]) = zero(m, n)}):

zero := proc (m, n) options operator, arrow; 0 end proc;
                      zero := (m, n) -> 0
Commutator(u[4], u[5]);
                               0
Commutator(u[4], v[5]);
                      (u[4]commav[5])[ - ]

 

 

 

 

Hi,

The most straightforward is to use “table”, or Array, as Kitonum showed. There is however a way to define true tensor within Maple, including a metric, if necessary. Here is a short demonstration with an attached worksheet. Note: you must have Maple 2018 to reproduce the lines below.

Rank_4_Tensor.mw
 

(Updated)

This example will only works with Maple 2018

restart

with(Physics)

Define a dimension 3 space with Cartesian feature

Setup(coordinates = cartesian, dimension = 3, metric = Euclidean, spacetimeindices = lowercaselatin, quiet, minimizetensorcomponents = true)

[coordinatesystems = {X}, dimension = 3, metric = {(1, 1) = 1, (2, 2) = 1, (3, 3) = 1}, minimizetensorcomponents = true, spacetimeindices = lowercaselatin]

(1)

Then, define a rank 4 tensor with all element equal to zero

Define(T[m, n, o, p] = 0)

`Defined objects with tensor properties`

 

{Physics:-Dgamma[a], Physics:-Psigma[a], T[m, n, o, p], Physics:-d_[a], Physics:-g_[a, b], Physics:-KroneckerDelta[a, b], Physics:-LeviCivita[a, b, c], Physics:-SpaceTimeVector[a](X)}

(2)

Finally, set the diagonal elements to 1

Library:-RedefineTensorComponent({T[1, 1, 1, 1] = 1, T[2, 2, 2, 2] = 1, T[3, 3, 3, 3] = 1})

[T[a, b, c, d] = (Array(1..3, 1..3, 1..3, 1..3, {(1, 1, 1, 1) = 1, (1, 1, 1, 2) = 1, (1, 1, 1, 3) = 1, (1, 1, 2, 1) = 1, (1, 1, 2, 2) = 1, (1, 1, 2, 3) = 1, (1, 1, 3, 1) = 1, (1, 1, 3, 2) = 1, (1, 1, 3, 3) = 1, (1, 2, 1, 1) = 0, (1, 2, 1, 2) = 0, (1, 2, 1, 3) = 0, (1, 2, 2, 1) = 0, (1, 2, 2, 2) = 0, (1, 2, 2, 3) = 0, (1, 2, 3, 1) = 0, (1, 2, 3, 2) = 0, (1, 2, 3, 3) = 0, (1, 3, 1, 1) = 0, (1, 3, 1, 2) = 0, (1, 3, 1, 3) = 0, (1, 3, 2, 1) = 0, (1, 3, 2, 2) = 0, (1, 3, 2, 3) = 0, (1, 3, 3, 1) = 0, (1, 3, 3, 2) = 0, (1, 3, 3, 3) = 0, (2, 1, 1, 1) = 0, (2, 1, 1, 2) = 0, (2, 1, 1, 3) = 0, (2, 1, 2, 1) = 0, (2, 1, 2, 2) = 0, (2, 1, 2, 3) = 0, (2, 1, 3, 1) = 0, (2, 1, 3, 2) = 0, (2, 1, 3, 3) = 0, (2, 2, 1, 1) = 0, (2, 2, 1, 2) = 0, (2, 2, 1, 3) = 0, (2, 2, 2, 1) = 0, (2, 2, 2, 2) = 0, (2, 2, 2, 3) = 0, (2, 2, 3, 1) = 0, (2, 2, 3, 2) = 0, (2, 2, 3, 3) = 0, (2, 3, 1, 1) = 0, (2, 3, 1, 2) = 0, (2, 3, 1, 3) = 0, (2, 3, 2, 1) = 0, (2, 3, 2, 2) = 0, (2, 3, 2, 3) = 0, (2, 3, 3, 1) = 0, (2, 3, 3, 2) = 0, (2, 3, 3, 3) = 0, (3, 1, 1, 1) = 0, (3, 1, 1, 2) = 0, (3, 1, 1, 3) = 0, (3, 1, 2, 1) = 0, (3, 1, 2, 2) = 0, (3, 1, 2, 3) = 0, (3, 1, 3, 1) = 0, (3, 1, 3, 2) = 0, (3, 1, 3, 3) = 0, (3, 2, 1, 1) = 0, (3, 2, 1, 2) = 0, (3, 2, 1, 3) = 0, (3, 2, 2, 1) = 0, (3, 2, 2, 2) = 0, (3, 2, 2, 3) = 0, (3, 2, 3, 1) = 0, (3, 2, 3, 2) = 0, (3, 2, 3, 3) = 0, (3, 3, 1, 1) = 0, (3, 3, 1, 2) = 0, (3, 3, 1, 3) = 0, (3, 3, 2, 1) = 0, (3, 3, 2, 2) = 0, (3, 3, 2, 3) = 0, (3, 3, 3, 1) = 0, (3, 3, 3, 2) = 0, (3, 3, 3, 3) = 0}))]

(3)

To see non-zero elements

T[nonzero]

T[a, b, c, d] = {(1, 1, 1, 1) = 1, (2, 2, 2, 2) = 1, (3, 3, 3, 3) = 1}

(4)

Or individually

T[2, 2, 2, 2]

1

(5)

T[1, 2, 3, 3]

0

(6)

It is possible to gather many properties on this tensor

Library:-NumberOfIndependentTensorComponents(T)

1

(7)

Library:-GetTensorSymmetryProperties(T)

{[3, 4], [1, 2, 3, 4]}, {}

(8)

Or to make contractions, and many manipulations

TensorArray(T[2, 2, m, n])

Matrix(%id = 18446746699811402686)

(9)

SumOverRepeatedIndices(T[a, a, b, c])

T[1, 1, b, c]+T[2, 2, b, c]+T[3, 3, b, c]

(10)

``


 

Download Rank_4_Tensor.mw

 

Hi,

nn is not correctly defined. k[mu] should also be defined as a tensor, otherwise, it will not be considered as such.

Here is you code rewritten to get the expected result:

with(Physics); Setup(dimension = 4);
Setup(metric = {(1, 1) = -1, (2, 2) = -1, (3, 3) = -1, (4, 4) = 1});
 [metric = {(1, 1) = -1, (2, 2) = -1, (3, 3) = -1, (4, 4) = 1}]
Setup(mathematicalnotation = true); Coordinates(X, quiet);
                 [mathematicalnotation = true]
                              {X}
Define(k[mu], quiet);

nn[mu] = Matrix(1, 4, {(1, 1) = 0, (1, 2) = 0, (1, 3) = 0, (1, 4) = 1});
                     nn[mu] = [0  0  0  1]

Define(%, quiet);

nn[mu]*k[mu];
                         nn[mu] k[~mu]

SumOverRepeatedIndices(%);
                             k[~4]

 

You should have a look at the Physics Package, just enter ?Physics to get some help. Note that indices starts at 1, the notation is therefore slightly different. Many useful quantities are predefined: d_, the indexed differential operator with respect to the spacetime variables, but also D_, the indexed covariant differential operator with respect to curvilinear spacetime coordinates. Additionally, you can define additional tensor using "Define".

restart; with(Physics);

Coordinates(X = [x, y, z, t]);

X[1];
                               x
X[4];
                               t

 

You might accurately define the algebra at will. Notice the inert form %AntiCommutator when entering the definition for the first time.

 

restart; with(Physics):
Setup(algebrarules = {%AntiCommutator(Dgamma[mu], Dgamma[nu]) = 2*g_[mu, nu]});


AntiCommutator(Dgamma[mu], Dgamma[nu]);
                     2 Physics:-g_[mu, nu]
AntiCommutator(Dgamma[1], Dgamma[2]);
                               0
AntiCommutator(Dgamma[3], Dgamma[3]);
                               -2
AntiCommutator(Dgamma[`~3`], Dgamma[3]);

 

 

Hi,

this is not the appropriate syntax. One could use "is" to test a relation:

restart;
a := [1, 2, 3, 4, 5];
                      a := [1, 2, 3, 4, 5]
is(a < 4);
Error, (in property/ConvertRelation) invalid relation arguments

Which logically gives an error. The syntax you wrote is rather the Matlab way of programming than the Maple one. “select” might be a good solution:

restart;
a := [1, 2, 3, 4, 5];
                      a := [1, 2, 3, 4, 5]
b := select(proc (u) options operator, arrow; is(u < 4) end proc, a);
                         b := [1, 2, 3]
b, c := selectremove(proc (u) options operator, arrow; is(u < 4) end proc, a);
                   b, c := [1, 2, 3], [4, 5]

The functions "map" and "andmap" are also of interest for these operations.

Hi,

Using at the same time "evalc" and "assuming z::complex" is contradictory. The purpose of evalc is to consider that everything is real, so you asked Maple to consider z to be real and complex!!

A very good way to adress your problem is to use convert, see the attached mw.

NULL

NULL

NULLNULL

NULL

restart; interface(imaginaryunit = i)

Using at the same "evalc" and "assuming z::complex" is contradictory. The purpose of evalc is to consider that everything is real, so you asked Maple to consider z to be real and complex!!

Therefore, it is correct that...

evalc(Im(z))

0

(1)

...and that

evalc(Re(z))

z

(2)

Accordingly, the following is correct

evalc(Re((Re(z)+I*Im(z))^2))

z^2

(3)

One can also notice, that by default, Maple consider that z is complex:

coulditbe(z::complex)

true

(4)

So, unless very special case, the assumption "z::complex" is useless most of the time.

 

For the expression z-Re(z)-I*Im(z), a good practice is to use convert:

z-Re(z)-I*Im(z)

z-Re(z)-I*Im(z)

(5)

 

convert(z-Re(z)-I*Im(z), abs)

0

(6)

convert(z-Re(z)-I*Im(z), conjugate)

0

(7)

To see how it works step by step

convert(z, conjugate); convert(Re(z), conjugate); convert(I*Im(z), conjugate)

z

 

(1/2)*z+(1/2)*conjugate(z)

 

(1/2)*z-(1/2)*conjugate(z)

(8)

Re(z)^2+Im(z)^2-abs(z)^2

Re(z)^2+Im(z)^2-abs(z)^2

(9)

simplify(convert(Re(z)^2+Im(z)^2-abs(z)^2, abs))

0

(10)

For me, using z = x+I*y seems to be fine

conjugate(sin(x+I*y))

sin(conjugate(x+I*y))

(11)

`assuming`([expand(sin(conjugate(x+I*y)))], [real])

sin(x)*cosh(y)-I*cos(x)*sinh(y)

(12)

Last remark. Assuming is very good, but single shot. So, if you need to use z = x+I*y many times, the best is to define x and y as real. I advise not using "assume" that is very old. The best is the Physics:-Assume

Physics:-Assume(x, real, y, real)

{x::real}, {y::real}

(13)

expand(sin(conjugate(x+I*y)))

sin(x)*cosh(y)-I*cos(x)*sinh(y)

(14)

NULL

NULL

NULL

NULL


 

Download ConvertConjugate.mw

Hi,

You could try:

g := -18+2*x-8*y+5*z = 0

A, B := selectremove(proc (u) options operator, arrow; is(u::integer) end proc, lhs(g))

B = rhs(g)-A

GAMMA(z) is a special function that is closely related to the factorial function for positive integers. If you'd like you can convert your expression back to factorial with

convert(GAMMA(n), factorial)

or

convert(MyExpression, factorial)

You can also have more information with: (works for all Maple's special functions)

FunctionAdvisor(GAMMA)
 

restart

convert(GAMMA(n), factorial)

factorial(n-1)

(1)

FunctionAdvisor(GAMMA)

``

 

Download GammaFunction.mw

 

@Thorreign I have the same. That's a bug that came around with the new M2017 Typesetting. There is the same with "Array", that I think is used to build "Matrix". That's annoying, but I don't see any workaround. Here is a method for an elementwise assignment.


 

NULL

NULL

NULL

NULL

http://www.mapleprimes.com/questions/222532-Maple-2017-Copying-Matrix-Gives-rtable

restart

Matrix(2, 2)

Matrix(%id = 18446745744643851198)

(1)

Copy & Paste or Click & Drag (1)

_rtable[18446745744643851678]

_rtable[18446745744643851678]

(2)

The same with Array

Array(1 .. 3, 1 .. 3, fill = 1)

Array(%id = 18446745744682795006)

(3)

Copy & Paste or Click & Drag (3)

_rtable[18446745744682795006]

_rtable[18446745744682795006]

(4)

M := Matrix(2, 2)

Matrix(%id = 18446746290399400654)

(5)

To make an element wise change do as follow. Note the use of "( )" instead of "[ ]" for the indexation

M(2, 2) := exp(x)

Matrix(%id = 18446746290399400654)

(6)

``


 

Download MatrixCopyAndPaste.mwMatrixCopyAndPaste.mw

First, I think there is an error for the position iteration, it should be X[n+1]:=X[n]+P[n] with no extra term.

In Maple there is a function "poincare", see help("DEtools,poincare"). However, it is not well adapted to the standard map.

The solution I see is quite straightforward: create an array for both P and X, see help("Array"). Then, fill the arrays by iteration inside a for loop, plot the result with dataplot. Do that again for your set of initial conditions.

You can overload an operator, see help("overload").

For your example, it could give:

ListOperations := module () export `+`; option package; 

`+` := proc (a::list, b::list) option overload; [op(a), op(b)] end proc:

end module:


with(ListOperations);
                              [+]
[a, b, c]+[d, e, f];
                       [a, b, c, d, e, f]
 

 

1 2 3 4 Page 3 of 4