## 453 Reputation

5 years, 342 days

Hi,

 >
 >
 (1)
 >
 (2)
 >
 (3)
 >

## Physics and Differential Operator...

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.

 >
 >
 (1)
 >
 (2)

Now, A and B are non-commutative

 >
 (3)

It is even possible to factor it back

 >
 (4)

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

 >
 (5)
 >
 (6)
 >
 (7)

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

 >
 (8)
 >
 (9)
 >

## algebrarules...

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])[ - ]

```

## Physics Tensor...

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.

(Updated)

This example will only works with Maple 2018

 >
 >

Define a dimension 3 space with Cartesian feature

 >
 (1)

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

 >
 (2)

Finally, set the diagonal elements to 1

 >
 (3)

To see non-zero elements

 >
 (4)

Or individually

 >
 (5)
 >
 (6)

It is possible to gather many properties on this tensor

 >
 (7)
 >
 (8)

Or to make contractions, and many manipulations

 >
 (9)
 >
 (10)
 >

## Define...

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]
```

## Physics Package...

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

```

## Algebrarules...

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]);

## Select...

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.

## No Bug And convert...

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.

 >

 >

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...

 >
 (1)

...and that

 >
 (2)

Accordingly, the following is correct

 >
 (3)

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

 >
 (4)

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

For the expression , a good practice is to use convert:

 >
 (5)

 >
 (6)
 >
 (7)

To see how it works step by step

 >
 (8)
 >
 (9)
 >
 (10)

For me, using  seems to be fine

 >
 (11)
 >
 (12)

Last remark. Assuming is very good, but single shot. So, if you need to use  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

 >
 (13)
 >
 (14)
 >

## selectremove...

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

## Special Function...

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)

 >
 >
 (1)
 >
 >

## Typesetting BUG...

@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.

 >

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

 >
 >
 (1)

Copy & Paste or Click & Drag (1)

 >
 (2)

The same with Array

 >
 (3)

Copy & Paste or Click & Drag (3)

 >
 (4)
 >
 (5)

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

 >
 (6)
 >

## Dataplot...

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.

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]

## Shift+F5...

 1 2 3 4 Page 3 of 4
﻿