ecterrab

14540 Reputation

24 Badges

20 years, 22 days

MaplePrimes Activity


These are replies submitted by ecterrab

@mistel 

I intended to show you how you can make it work, just: "define the action of the operator H on Kets"

Once you understand the idea you can adjust the procedure shown to handle more situations, say different than the one you posted. For example: if you want to use the same definition of H with all Kets (including C Kets) change op(2, K) by op(2..-1, K). If you want to restrict the action of H to only Kets A and B then change "if K::Ket then" by "if K::Ket and op(1, K)::identical(A, B) then". If you want H to accumulate no more than 4 indices then instead of "if K::Ket ..." use "if (procname::Not(indexed) or nops(procname) < 4) and K::Ket ..."; and so on. 

Of course if you are going to define H as a procedure, you need to know the Maple language 101. For that, the documentation is pretty good, and the language is just incredibly simple and easy to use.

IMPORTANT: give a look at the help page ?Physics,Library, there you will find a whole programming language for Physics, approx 200 commands, one of them is a subpackage with approx 100 Physics types. All that can be extremely helpful at the time of writing simple or complicated programs to tell the Maple system more precisely what you want to do.

In one thing, however, you caught me sleeping: in my reply I wrote the else clause with 'H . K'. It makes sense. But to use both algebra rules (say for C) and a procedure definition for H (say for A and B), the internal code was expecting that clause to be 'H(K)'. Therefore, replace 'H . K' by 'H(K)' in that procedure definition and then you can use both algebra rules (that you defined for C Kets) and the procedure definition for whatever else (A and B Kets) .

Anyway, I adjusted that in the code too, and uploaded a new version 272 of the Maplesoft Physics Updates so that after installing it, the procedure I posted in the previous reply will work as expected  in both cases, with 'H . K' or 'H(K)' in the else clause.

Summarizing: there is no bug here, just one idea: code H, according to what you need.

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

To get some help you need to post the problem itself, within a Maple worksheet, formulated as much as you can.

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

@vv 
 

Maple has subs, eval and subs[eval], and you can eval(subs(...))) . All together they provide enormous flexibility. The following example shows the differences between these commands. Suppose you have the (artificially unevaluated, for the purpose of this example) expression:

'exp(0)+exp(sin(x))'

exp(0)+exp(sin(x))

(1)

The simplest and oldest manipulation: substitute x = 0: the substitution is performed, the expression, however, is not evaluated

subs(x = 0, 'exp(0)+exp(sin(x))')

exp(0)+exp(sin(0))

(2)

Suppose now you want to evaluate only the subexpressions where a substitution happened: use subs[eval]

subs[eval](x = 0, 'exp(0)+exp(sin(x))')

exp(0)+1

(3)

If you want to substitute and then evaluate everything, you can use eval@subs

eval(subs(x = 0, 'exp(0)+exp(sin(x))'))

2

(4)

So subs[eval] is not the same as eval@subs. Still, you can obtain the same result (3) using eval alone, ie substitute and evaluate only the subexpressions that changed after substituting

eval('exp(0)+exp(sin(x))', x = 0)

exp(0)+1

(5)

Right. But then why having eval and subs[eval] and why the help page warning "use subs[eval] with care"? Because subs performs substitutions regardless of whether they are syntactically or mathematically correct (these two different things can be wrong). For example, consider

'exp(0)+diff(sin(x), x)'

exp(0)+diff(sin(x), x)

(6)

Substituting x = 0 in this diff construction is wrong, however if you want to do that, for any reason you may have, you can substitute

subs(x = 0, 'exp(0)+diff(sin(x), x)')

exp(0)+diff(sin(0), 0)

(7)

Therefore, if you use subs[eval], the wrongly constructed derivative is evaluated, resulting in

subs[eval](x = 0, 'exp(0)+diff(sin(x), x)')

Error, invalid input: diff received 0, which is not valid for its 2nd argument

 

 

while if you use eval you get it right

eval('exp(0)+diff(sin(x), x)', x = 0)

exp(0)+eval(diff(sin(x), x), {x = 0})

(8)

A case where the substitution is syntatically correct but (I'd say) mathematically wrong

Int(exp(x*s), x = a .. b)

Int(exp(x*s), x = a .. b)

(9)

In the above, s does not depend on x. One could argue that substituting s = f(x) would make sense only if done after you performed the integration. Still, for any reason one may want to substitute s = f(x) before performing the integration. You can do both

subs(s = f(x), Int(exp(x*s), x = a .. b))

Int(exp(x*f(x)), x = a .. b)

(10)

eval(Int(exp(x*s), x = a .. b), s = f(x))

eval(Int(exp(x*s), x = a .. b), {s = f(x)})

(11)

In summary: eval is safer, but if you know what you are doing, subs or subs[eval] are "faster" (although in 99.99% of the time you cannot measure the difference). The reason why subs[eval] is faster is because it happens all within the Maple kernel (C program) while eval will consult first the existence of a library (Maple language compiled code) routine of the form `eval/F` where F is the function being evaluated. You can check: there is eval/diff, eval/int, eval/sum, eval/eval, and some others. For all those, eval is safer than subs. When, for all the functions F in expression, there exists no eval/F, generally speaking, there is no difference between subs[eval] and eval.

NULL


 

Download subs_versus_eval.mw

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

@Carl Love 

What you say is not a rule, nor a documented design. For example, pdsolve introduces sums with summation indices (see a recent post I made about pdsolve tackling PDE & BC), and I intentionally removed all these _n from around: you now see a clean 'n', at most 'n' and 'n1' which for me already looks ugly ... I'd never write n1 with paper and pencil. Likewise, integral transforms used by pdsolve to solve PDEs are return with neat greek letters as integration variables, not the old '_U' still used by the inttrans package.

In the same line, all the FunctionAdvisor is moving from these old _U style to a clean 't' etc.

The answer to the original question of this thread was given by Tom Leslie: in ?pdsolve it is clearly said what _c[n] represents, and the information that they are "separation constants", not arbitrary constants coming from ODE integration, is relevant in the PDE context. That is why they are different, visually and computationally.

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

Hi @Rouben Rostamian  

I realize there are different opinions, but I prefer the current design. I wrote this program more than 20 years ago, primarily because of my work on differential equations, it even got transported into the Physics package as Physics:-CompactDisplay. This is a very popular Maple command. In my opinion, the observation by vv, a case where a function with is applied to different variables and you happen to be interested in the different derivatives is unusual to justify this change you suggest. It would add complexity to the code and to the different cases I'd need to remember at the time of looking at the screen.

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

@mistel 

My comments appear below in italic while your original text is non-italic. I also transformed your Maple "document" into a Maple "worksheet", really easier to edit and work with. You can always set "worksheet" as your default mode in the Maple preferences.

 

Below, any few changes to your input lines are mentioned explicitly. As usual to reproduce the input/output you see please verify that you have installed the latest Maplesoft Physics Updates, version 268 or higher.

 

Physics:-Version()[2]

`2018, December 27, 10:45 hours, version in the MapleCloud: 268, version installed in this computer: 268`

(1)

with(Physics)

 

If H is an operator that acts on the same space as C, then indicate that from the beginning. I am then including H in hilbertspaces in your input:

Setup(redo, hermitianoperators = {H}, hilbertspaces = {{A, C, H}, {B, C, H}}, quantumbasisdimension = {A = 1 .. Na, B = 1 .. Nb, C[1] = 1 .. Na, C[2] = 1 .. Nb}, quantumdiscretebasis = {A, B, C}, bracketrules = {%Bracket(Bra(A, i), Ket(C, j, k)) = delta[i, j]*Ket(B, k), %Bracket(Bra(B, i), Ket(C, j, k)) = delta[i, k]*Ket(A, j), %Bracket(Bra(C, i, j), H, Ket(C, k, l)) = H[i, j, k, l]})

[bracketrules = {%Bracket(%Bra(A, i), %Ket(C, j, k)) = Physics:-KroneckerDelta[i, j]*Physics:-Ket(B, k), %Bracket(%Bra(B, i), %Ket(C, j, k)) = Physics:-KroneckerDelta[i, k]*Physics:-Ket(A, j), %Bracket(%Bra(C, i, j), H, %Ket(C, k, l)) = H[i, j, k, l]}, disjointedspaces = {{A, C, H}, {B, C, H}}, hermitianoperators = {H}, quantumbasisdimension = {A = 1 .. Na, B = 1 .. Nb, C[1] = 1 .. Na, C[2] = 1 .. Nb}, quantumdiscretebasis = {A, B, C}]

(2)

Ket(C, k, l) = Ket(A, k).Ket(B, l)

Physics:-Ket(C, k, l) = Physics:-`*`(Physics:-Ket(A, k), Physics:-Ket(B, l))

(3)

Bra(C, i, j) = Bra(A, i).Bra(B, j)

Physics:-Bra(C, i, j) = Physics:-`*`(Physics:-Bra(A, i), Physics:-Bra(B, j))

(4)

This works

Bra(C, i, j).H.Ket(C, k, l)

H[i, j, k, l]

(5)

Bra(A, i).Bra(B, j).Ket(A, k).Ket(B, l)

Physics:-KroneckerDelta[i, k]*Physics:-KroneckerDelta[j, l]

(6)

This does not work``

Bra(A, i).Bra(B, j).H.Ket(A, k).Ket(B, l)

Physics:-`*`(Physics:-Bra(A, i), Physics:-Bracket(Physics:-Bra(B, j), H, Physics:-Ket(A, k)), Physics:-Ket(B, l))

(7)

Bracket(Bra(A, i).Bra(B, j), H, Ket(A, k).Ket(B, l))

Physics:-`*`(Physics:-Bra(A, i), Physics:-Bra(B, j), Physics:-`.`(H, Physics:-Ket(A, k)), Physics:-Ket(B, l))

(8)

What I want

Bra(A, i)*Bra(B, j)*H*Ket(A, k)*Ket(B, l) = Bra(C, i, j)*H*Ket(C, k, l)

Physics:-`*`(Physics:-Bra(A, i), Physics:-Bra(B, j), H, Physics:-Ket(A, k), Physics:-Ket(B, l)) = Physics:-`*`(Physics:-Bra(C, i, j), H, Physics:-Ket(C, k, l))

(9)

Bra(C, i, j)*H*Ket(C, k, l) = Bra(C, i, j).H.Ket(C, k, l)

Physics:-`*`(Physics:-Bra(C, i, j), H, Physics:-Ket(C, k, l)) = H[i, j, k, l]

(10)


I see. You have a couple of issues here:

 

1. 

The right-hand side of (10) is an operator while, normally, it would be a real scalar. Solution: you can always substitute H by some scalar, say H at the end.

2. 

Since Hbelongs to a tensor product of spaces, it can be an entangled operator, i.e. one that you cannot represent as a product of "A[i]  times B[j]" , so how would you represent, for example Bra(B, j)*H*Ket(A, k)? That is relevant since you want to compute `&otimes;`(Bra(A, i), Bra(B, j))*H*`&otimes;`(Ket(A, k), Ket(B, l)) and if you intend to do that all with algebra rules you need a computational representation for Bra(B, j)*H*Ket(A, k)that is not just itself.

 

Because of 2. I don't think what you want is possible by only using algebra rules in some natural way. The best approach in a case like this one is to take advantage of the possibility of defining the action of a quantum operator over a Ket. I.e.define Has a procedure.

 

Basically, what you want is:
 

"if H is applied to a Ket then

    if H itself is indexed then
        return H accumulating its indices, followed by the index of the Ket
    else

        return H indexed by the index of the Ket;
otherwise
    return the dot product operation uncomputed, unevaluated

"

 

In Maple language that is written as

 

 
"H := K ->   if K::Ket then      if procname::'indexed' then         H[op(procname), op(2, K)]     else          H[op(2, K)]     fi  else      'H . K'  fi:"

 

Let's see this definition  in action. Start by erasing all Physics performance remember tables, that remember results like (7) computed before the definition of H

Library:-Forget()

 

Then you have

H.Ket(A, k)

H[k]

(11)

Bra(B, j).H

H[j]

(12)

Bra(B, j).H.Ket(A, k)

H[j, k]

(13)

and this is already what you wanted to compute:

Bra(A, i).Bra(B, j).H.Ket(A, k).Ket(B, l)

H[i, j, k, l]

(14)

Bracket(Bra(A, i).Bra(B, j), H, Ket(A, k).Ket(B, l))

H[i, j, k, l]

(15)

``


 

Download algebra_rules_(reviewed_II).mw

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

@Rouben Rostamian  

It was a genuine question, I do not use rhetorical flourish or irony - I don't believe in that as valuable communication tools, I think rather the opposite. My question was targeting the kind of answer you gave, to improve the paragraphs of this help page. I will make explicit that "all differentiation variables" refer to differentiation variables in general, also for functions that were not declared, and that by differentiation variables I mean their display in derivatives, ie. that all derivatives are displayed indexed after you turn this ON.

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

@tomleslie 

Yes, this was a typo in the Example 8 of the previous post on PDE & BC. It was, however, a fortunate typo :) Example 8, after correcting the typo, is also solvable, and the no solution you observed actually pointed to a place in the new routines where an extra tweak was necessary. Example 8 (without the typo) is now solvable after installing the Maplesoft Physics Updates version 266 or higher.

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

@Preben Alsholm 

Your observations make sense to me. Here is some info regarding Physics:-Version() that may help to determine what is going on with nm's Maple installation. The output of Physics:-Version() is as follows:

  • The MapleCloud version reported is the one reported by PackageTools:-GetProperty(5137472255164416, "X-CloudVersion")
  • The library reported, from where Physics is being loaded, is the first library in the list returned by LibraryTools:-FindLibrary('Physics')
  • The timestamp is the one returned by LibraryTools:-Timestamp(P)[1]
  • The version reported as "installed in your computer" is the one returned by PackageTools:-IsPackageInstalled("Physics Updates", ':-output = :-version')

From what you say, somehow, PackageTools:-IsPackageInstalled("Physics Updates", ':-output = :-version') is telling that version 264 is there. So it found Physics Updates (the whole or portions of it) in the toolbox\2018 directory. I would remove everything below toolsbox\2018, entirely, then check what is being reported. Likewise, if I were to re-install Maple, I would first uninstall Maple, using its unistaller, then remove, manually, all the Maple directory, using the File Manager, then re-install it.

Finally, suppose you have Maple working fine again. If the problem in your computer happens only when you use PackageTools:-Install, I can't imagine what could that be (support@maplesoft.com can) but I can suggest a workaround. In your maple.ini (in mac it is called .mapleinit) you can set the value of libname. Set it as in

libname := "the directory you prefer", libname:
 
Then, libraries (.mla or .maple) found in "the directory you prefer" will be scanned before those found in the (default directories of) libname. All this is explained in ?libname. Then download any package (not using PackageTools:-Install, just downloading them), and place the downloaded .maple file in "the directory you prefer". Then open Maple and everything found in "the directory you prefer" will be loaded from there instead of from the default directories of libname. That is a way to install the package manually, without using PackageTools:-Install. The drawback of this approach is that you need to manually install/uninstall every time, 

BTW another question: what is the value of libname for you? It should contain the toolbox directory.

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

@nm 

You mentioned many things. Let me see if I can help you with this not-understood problem you are having.

  • Physics:-Version tells you mainly three things: the directory from where Physics is being loaded (it could be present in many places but it is always loaded only from one place), the version in the MapleCloud and the version installed in your computer.
  • Physics comes with Maple, installed within the Maple library (for Maple 2018.2, that is updates.mla).  The "Physics Updates" library, however, is always found in ".../maple/toolbox/2018/Physics Updates", where "..." represents your particular configuration. From what you posted, apparently, "..." is "C:\Users\me"
  • There is no relevance in whether you use \ or /, the Maple system handle both path separators in equal footing.
  • After you Package:-Install or PackageUninstall something, you always need to restart (in your worksheet and cmaple session, apparently, you didn't restart).
  • You can also install the package manually:
    • Open your File Manager, go to C:\Users\me\maple\toolbox\2018, and delete the Physics Updates directory.
    • Go the Maplesoft R&D Physics webpage and download the "Physics Updates" package (apparently, you already have it downloaded)
    • Open cmaple and enter PackageTools:-Install("the full path of the file Physics+Updates.mla"). In my case, that reads PackageTools:-Install("/Users/ecterrab/Downloads/Physics+Updates.maple"); the package installs fine. Or otherwise there is a permission problem (more at the end)
    • Open the worksheet I posted in this thread, Update_v.264.mw, and execute it: the two PDE problems should get solved.

Now, independent of resolving the problem manually, from all the information you gave, I'd imagine there is indeed a problem in your computer regarding permissions, The error in cmaple you show is "permission denied when trying to copy to C:\Users\me\maple\toolbox/2018/Physics Updates/lib/UpdatesPhysics2018.help". I use Macintosh but note that other people using windows (e.g. tomleslie) are not having this permission problem. There is for sure a way to adjust the rights so that you, as an administrator of your computer, can allow Maple to copy a file from one place to another.

Hope this time it fixes the problem ... Best

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

@nm

I already uploaded v.264, then installed it in my copy of Maple, it worked fine. Version 264 has several refinements that make the code find a solution for some more difficult examples. These are two of them:
 

Articolo's textbook example 7.9.1

pde[1] := diff(u(r, theta, t), t, t) = (diff(u(r, theta, t), r)+r*(diff(u(r, theta, t), r, r))+(diff(u(r, theta, t), theta, theta))/r)/(4*r)

iv[1] := u(1, theta, t) = 0, u(r, 0, t) = 0, u(r, (1/2)*Pi, t) = 0, u(r, theta, 0) = (-r^4+r^2)*sin(2*theta), (D[3](u))(r, theta, 0) = 0

pdsolve([pde[1], iv[1]])

u(r, theta, t) = `casesplit/ans`(Sum(-(1/6)*sin(2*theta)*(BesselJ(0, lambda[n]*r)*lambda[n]*r-2*BesselJ(1, lambda[n]*r))*cos((1/2)*lambda[n]*t)*hypergeom([], [5], -(1/4)*lambda[n]^2)/((hypergeom([2, 5/2], [3, 3, 4], -lambda[n]^2)*lambda[n]-hypergeom([3/2, 2, 2], [1, 3, 3, 3], -lambda[n]^2)*lambda[n])*r), n = 1 .. infinity), {And(lambda[n] = BesselJZeros(2, n), 0 <= lambda[n])})

(1)


Articolo's Exercise 7.15, with 6 BC/IV, two for each variable

pde[2] := diff(u(x, y, t), t, t) = 1/4*(diff(u(x, y, t), x, x)+diff(u(x, y, t), y, y))-(1/10)*(diff(u(x, y, t), t))

iv[2] := (D[1](u))(0, y, t) = 0, (D[1](u))(1, y, t)+u(1, y, t) = 0, (D[2](u))(x, 0, t)-u(x, 0, t) = 0, (D[2](u))(x, 1, t) = 0, u(x, y, 0) = (1-(1/3)*x^2)*(1-(1/3)*(y-1)^2), (D[3](u))(x, y, 0) = 0

 

This problem is tricky ... There are three independent variables, therefore two eigenvalues (constants that appear separating variables by product) in the Sturm-Liouville problem. But after solving the separated system and also for the eigenvalues, the second eigenvalue is equal to the first one, and in addition cannot be expressed in terms of known functions, because the equation it solves cannot be inverted.

 

The solution to the problem is now computable in v.264

 

pdsolve([pde[2], iv[2]])

u(x, y, t) = `casesplit/ans`(Sum((1/6)*(exp((1/10)*t*(-200*lambda[n]^2+1)^(1/2))*(-200*lambda[n]^2+1)^(1/2)+exp((1/10)*t*(-200*lambda[n]^2+1)^(1/2))+(-200*lambda[n]^2+1)^(1/2)-1)*(cos(lambda[n]*y)*lambda[n]+sin(lambda[n]*y))*exp(-(1/20)*t*((-200*lambda[n]^2+1)^(1/2)+1))*(6*lambda[n]^2*cos(lambda[n])^2+cos(lambda[n])^2-5*lambda[n]^2-1)*cos(lambda[n]*x)*(lambda[n]^2*sin(lambda[n])-lambda[n]*cos(lambda[n])+sin(lambda[n]))/((-200*lambda[n]^2+1)^(1/2)*(-cos(lambda[n])^4+(sin(lambda[n])*lambda[n]-1)*cos(lambda[n])^3+(lambda[n]^2+sin(lambda[n])*lambda[n]+1)*cos(lambda[n])^2+(lambda[n]^2+2*sin(lambda[n])*lambda[n]+1)*cos(lambda[n])+lambda[n]*(lambda[n]+sin(lambda[n])))*(cos(lambda[n])-1)*lambda[n]^4), n = 0 .. infinity), {And(tan(lambda[n])*lambda[n]-1 = 0, 0 <= lambda[n])})

(2)

``


 

Download Update_v.264.mw

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

@Preben Alsholm 

You missed solve's option 'allsolutions' (one could argue it should be used by default, that is another story). With it, you have:

@Preben Alsholm 

I saw this comment by you only today. The distrubuted Maplesoft Physics Updates got updated with the _libraryversion number of Maple 2018.2.1 a week or so ago. Since then, the Warning message you saw is not displayed.

In regards to your comment, there is the "why" and the "what message".

The "why": as you know the Maplesoft Physics Updates pack not just updates to Physics but also to the Differential Equations and Mathematical Functions code, and bug fixes not in those three areas but necessary for them to work properly, some of these mentioned in previous Mapleprimes posts.

Now, Maple is a very interconnected set of software routines. If you use an adjustment in the code written for Maple 2018.2 with a different library, e.g. 2018.1, or the other way around, I cannot assure you that all the things will work as intended. That is the "why" of the message, that includes a sentence (not shown in your comment) that indicates from where you can download an update for the version of Maple you have.

I imagine you know the "why" above but didn't find the message appropriate anyway, So, what message would you find more appropriate for this situation?

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

@John Fredsted 

The current Maplesoft Physics Updates will not work well in previous Maple releases. Many of its features depend on things that only exist in Maple 2018, and several fixes only work as expected with the library of Maple 2018. I'd suggest you to install the latest Maplesoft Physics Updates for Maple 2017, but it does not include the change I did yesterday regarding this issue you mentioned.

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

@lucenalex 

I'm a bit overloaded today and tomorrow but will try to find time to show how to formulate the problem - hopefully before a couple of days from today.

Best

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

First 28 29 30 31 32 33 34 Last Page 30 of 64