sursumCorda

922 Reputation

13 Badges

2 years, 206 days

MaplePrimes Activity


These are replies submitted by sursumCorda

@nm Thanks. There are also other less nice things in Maple. While I believe that somebody has noticed them before, I cannot find such questions/posts in this forum. For example,

subs[eval](x = 1, '1 - x'):
(subs[eval](x = 1, '1 - x')):
1 - subs[eval](x = 1, 'x'):
1 - (subs[eval](x = 1, 'x')):
use x = 1 in 1 - x end:

 are all allowed, but strangely, 

(use x = 1 in 1 - x end):
1 - use x = 1 in x end:
1 - (use x = 1 in x end):

 is invalid. This is just a trivial example, yet it is still typical. If I wish to do so, I shall have to use 

1 - if true then use x = 1 in x end fi:

or

1 - (to 1 do use x = 1 in x end od):

which is quite awkward.

@vv Thanks. In this example, although I can use "output=..." for LinearAlgebra:-Eigenvectors, this is not valid for MTM:-eig. 

The major problem is: if someone sends me an encrypted procedure that uses built-in keyword `_nresults` but do not provide any output option, when I only request the second output and he/she rejects modifying the source code, shall I have to assign a worthless variable (and then clear it) instead of simply ignoring it at the beginnibg in the syntax level?

@nm I change some options such that the plot looks more attractive, yet I also do not know how to translate Mma's StreamPoints (that is, closeness of streamlines) back into Maple. 

Here is the same thing in Mathematica

According to How to | Plot a Vector Field, Mma's StreamPlot is not identical to Maple's DEtools:-phaseportrait/DEtools:-DEplot; the equivalent seems to be VectorPlot

Unfortunately, I do not know how to explicitly draw streamlines (in other words, flow paths, instead of field vectors) in Maple.

@ider I do not know how to fix it. (Though you can use a until-loop, this will be somewhat clumsy.) But the reason is written in the documentation: 

The environment variable Order … does not necessarily represent the order of the error term ….

@mmcdara Oops, I recently found that ArrayTools:-Partition almost perfectly meets my needs (though its name appeared to be irrelevant to “sorting”). When I searched the help system for partial sorting, the second item in the "Search Results" was linked to this command in fact, but unfortunately, I just neglected it since it seemed to be used to partition or split an array into several sub-arrays …. 

@Carl Love Thanks. The documentation of Procedures says: 

Within a procedure, during the execution of its statementSequence, local variables have single level evaluation. This means that using a variable in an expression will yield the current value of that variable, rather than first evaluating that value. … 
The use statement causes a syntactic transform of its body, according to the substitutions specified in the sequence of binding forms. It is unlike simple substitution, however, in that it behaves properly with respect to the static scoping rules of the Maple language. 

One may infer that a variable declared local is visible in a nested scope (provided that no (conflicting) re-declaration exists) and any inner namesake will be in agreement with it in surrounding procedures. However, the experiment seems to mean that proc/use inserts local symbols (in this example, CompSeq) only into the actual statement body and does not insert such symbols into code (in this example, `convert/CompSeq`) that is called from body but does not explicitly appear in body.
As a result, even if CompSeq has already been localized before invoking `convert/CompSeq` in the environment, the CompSeq on line 45 of `convert/CompSeq` is still unable to access and inherit definitions from the outer local CompSeq

Ming-Ho Yee wrote that line 4 does not update the mapping created on line 1, so in your translation, the “:-” prefix (in other words, setting a global variable) should not be alowed to be used. In the next post, Ming-Ho Yee additionally wrote that: if your definition of dynamic scope is “a variable is bound to the most recent assignment during the program’s execution”, then it is not correct to say R is dynamically scoped. Moreover, running the program provided by this blog post in Maple returns 1. Accordingly, in my view, the core of Maple kernel only implements lexical scoping (proc) and read‐only lexical variables (use). 

@nm Here is a example that using a plain name is unsafe.
This works well: 

verify(2, 1, greater_than);
 = 
                              true

But if I happen to make a assignment …? 

greater_than := 0: # accidentally 
verify(2, 1, greater_than);
 = 
                             false

verify(2, 1, evaln(greater_than));
Error, (in verify) verification `greater_than` does not exist
verify(2, 1, 'greater_than');
Error, (in verify) verification `greater_than` does not exist

Certainly I can obtain the correct result after deleting definitions; however, this means that using plain names is less safe (No warning here!) after all.

@Carl Love I'm not sure if I have understood right, yet the following instance appears to imply the use of lexical scoping:

:-CompSeq := -1: # the computation sequence below is from CompSeq 
(proc($) local CompSeq: convert([x = a + b, i = a*b, j = x + i, y = a + sin(x)], procedure, 'locals' = {i, j}, 'globals' = {x, y}, 'params' = {a, b}) end)();
Error, (in convert/list) too many levels of recursion
use CompSeq = 'CompSeq' in convert([x = a + b, i = a*b, j = x + i, y = a + sin(x)], procedure, 'locals' = {i, j}, 'globals' = {x, y}, 'params' = {a, b}) end;
Error, (in convert/CompSeq) too many levels of recursion

It seems that I'll have either to temporarily clear `CompSeq` or to provisionally modify `convert/CompSeq` during the execution. 

@C_R This is because Maple and Mathematica use different argument conventions. Though convert("-2 EllipticE[1/2 ([Pi]/2 - x), 2]", 'FromMma'); returns -2*EllipticE(sin(1/4*Pi - 1/2*x), sqrt(2)), in Maple, 

> ArrayTools:-Alias(<seq(simplify(fnormal(subs[eval](x = Pi*\
> i, -2*EllipticE(sin(1/4*Pi - 1/2*x), sqrt(2))))), i = -6. .. 6, 1/2)>, [6, 4], C_order);
                         [1.198140235     0.    -1.198140235    -1.198140235 - 1.198140234 I]
                         [                                                                  ]
                         [-1.198140235    0.    1.198140235     1.198140235 + 1.198140234 I ]
                         [                                                                  ]
                         [1.198140235     0.    -1.198140235    -1.198140235 - 1.198140234 I]
                         [                                                                  ]
                         [-1.198140235    0.    1.198140235     1.198140235 + 1.198140234 I ]
                         [                                                                  ]
                         [1.198140235     0.    -1.198140235    -1.198140235 - 1.198140234 I]
                         [                                                                  ]
                         [-1.198140235    0.    1.198140235     1.198140235 + 1.198140234 I ]

while in Mathematica, 

In[2]:= Multicolumn[
         Chop[Table[-2. EllipticE[1/4 (\[Pi] - 2 x), 2], {x, -6 \[Pi], 
            6 \[Pi], \[Pi]/2}]], {6, 4}, Alignment \[Rule] Center, 
         Appearance \[Rule] "Horizontal"]

Out[2]= -8.38698 - 7.18884 I   -7.18884 - 7.18884 I   -5.9907 - 7.18884 I    -5.9907 - 5.9907 I

        -5.9907 - 4.79256 I    -4.79256 - 4.79256 I   -3.59442 - 4.79256 I   -3.59442 - 3.59442 I

        -3.59442 - 2.39628 I   -2.39628 - 2.39628 I   -1.19814 - 2.39628 I   -1.19814 - 1.19814 I

        -1.19814               0                      1.19814                1.19814 + 1.19814 I

        1.19814 + 2.39628 I    2.39628 + 2.39628 I    3.59442 + 2.39628 I    3.59442 + 3.59442 I

        3.59442 + 4.79256 I    4.79256 + 4.79256 I    5.9907 + 4.79256 I     5.9907 + 5.9907 I

So specifying the assumption is, in effect, not unnecessary: 

simplify(diff(-2*EllipticE(sin(1/4*Pi - 1/2*x), sqrt(2)), x) - sqrt(sin(x)), assume = [x in RealRange(-Pi/2, 3*Pi/2)]);
 = 
                               0

 

@C_R I think that if I suppose that 0 ≤ x ≤ π, a simpler solution will be obtained as follows: According to Reciprocal-Modulus Transformation, we may have EllipticE(z, k) - (1 - k**2)*EllipticF(z, k) = k*EllipticE(k*z, 1/k) (But is this still correct for z > 1???). So after simplifying the result given by Maple manually, . And then 

f := (simplify@@2)(1/combine(1/eval(int(sqrt(sin(x)), x), 2*EllipticE(sqrt(sin(x) + 1), sqrt(2)/2) - EllipticF(sqrt(sin(x) + 1), sqrt(2)/2) = sqrt(2)*EllipticE(cos(1/2*(Pi/2 - x)), sqrt(2))))) assuming x in RealRange(0, Pi);
 = 
                                  /   /1      1  \   (1/2)\
     -2 I signum(cos(x)) EllipticE|sin|- Pi + - x|, 2     |
                                  \   \4      2  /        /

Compare:

g := convert("-2 EllipticE[1/2 ([Pi]/2 - x), 2]", 'FromMma'); # Note that (*Maple's *)EllipticE(x, k)(*Mathematica's *)EllipticE[ϕ, m], where x = sin(ϕ) and m = k2. 
 = 
                         /   /1      1  \         \
             -2 EllipticE|sin|- Pi - - x|, sqrt(2)|
                         \   \4      2  /         /

seq(MmaTranslator:-Mma:-Chop(evalf(subs(x = j*Pi, (f - g) - (1 - I)*sqrt(2/Pi)*signum(cos(x))*GAMMA(3/4)^2)), 2^(-10)), j = 0 .. 1, 1/20);
 = 
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0

Unfortunately, I am not sure if this is mathematically correct …. 

I do not know why Maple is unable to reduce those trigonometric functions in the result, yet I additionally find that Maple fails to fully simplify the corresponding definite integration as well:

simplify(int(sqrt(sin(x)), x = Pi/2 .. Pi));
 = 
     /          /1  (1/2)\              /1  (1/2)\\  (1/2)
     |-EllipticK|- 2     | + 2 EllipticE|- 2     || 2     
     \          \2       /              \2       //       

In[1]:= Integrate[Sqrt[Sin[x]], {x, \[Pi]/2, \[Pi]}]

             2         3 2
Out[1]= Sqrt[--] Gamma[-]
             Pi        4

Perharps Maple has forgotten some of what the developers once taught it ….

@Carl Love & @mmcdara Many thanks. Maybe such functionalities can be built into the underlying core so that Maple can sort rows of the rtable in-place.

@nm Thanks for your advice. But they behave differently. For example, 

ArrayTools:-SortBy(<4, 1, 1 | 0, 2, 5 | 7, 9, 8>, [.., 1]);
                           [1  2  9]
                           [       ]
                           [1  5  8]
                           [       ]
                           [4  0  7]

ArrayTools:-SortBy(<4, 1, 1 | 0, 2, 5 | 7, 9, 8>, 'column', [1, 3, 2]);
Error, (in ArrayTools:-SortBy) for 2-D rtable, expecting either list of indices or keyword column/row and index to specify what is to be sorted

while my purpose is: first sort the rows of the input 2-D array in specific order based on the elements in the specified column, then sort rows that have equal elements in the specified column based on the elements in the next specified column, and so forth. (Also, I hope that there will be a multidimensional analogue.)

@mmcdara Thanks for your test. I think that when working with Statistics, perharps using Sort@Trim is better (since they are in the same toolchain).
As for your last point, the reason is that you only measure the average time (instead of the total time). The MatLab code given in that Blog is: 

    tic
    for i=1:300
        y=mink(x,j*100);
    end
    minkResults(j)=toc;

 So “CodeTools:-Usage(..., 'interations' = 300)” should be changed to something like

to 5 do (*warm up the code to avoid its first-time costs*) od:
time[real]('(Statistics:-Sort@Statistics:-Trim)( … )' $ 3e2);

 Besides, though there exists a one-dimensional Statistics:-Sort function, is there a similar sortrows/sortcols in Maple?

@dharr Thanks. This is also useful, because the input data can contain any element.

3 4 5 6 7 8 9 Last Page 5 of 19