Joe Riel

7864 Reputation

22 Badges

14 years, 257 days

MaplePrimes Activity


These are replies submitted by Joe Riel

@Carl Love The answer is that I wasn't thinking about thread-safety. It's good that you brought that up.

Be sure to define and check the corner cases.  Specifically, what do you want for, say, [1,1,2,2].  Is 1 or 2 the second-highest element?  What about [1,1,1,1]?  Or for the empty list (Maple's max returns -infinity).

@Carl Love Nice explanation and example. A nit---probably best ignored---is that Maple error messages generally start with a lower case letter, they look better that way as the usual output is "Error, <the error message>".

You could use two prismatic joints to enforce a planar motion.  The planar joint could also be used.  A different approach would be to use the sphere-rectangle contact, though that would allow motion off the surface (bouncing).

@a_simsim It helps to know why two backslashes are required, in a Maple string, to represent a Windows directory separator. The backslash is used as an escape character, to permit entering special characters (new-lines, tabs, arbitrary ascii). As such, to enter the escape character itself, you need two of them, the first "escapes" the second.

Have someone do it for you. Snarky answer aside, what are you trying to make efficient?  The execution of the procedure, or the creation of the procedure? The usual concern is the former. 

@Ramakrishnan On line 95 there is a call to SetProperty that is missing its package name (should be DT:-SetProperty); without the package name it returns unevaluated.

In the embedded component code sections, the "use DocumentTools in ... end use;" wrappers are no longer needed as there are no exports of DocumentTools being used in the code.  It probably isn't worthwhile to remove the wrappers, but it is something to consider for the next worksheet.

 

@Carl Love Nice extension, particulary the use of an operator for a positional argument. Hmm. Is there a type 'operator'? There should be.  Probably there should be a check for the number of dimensions of an rtable; it seems unlikely anyone would want to sort a 2 or higher dimensioned rtable by the linear order.

@Kitonum The OP should be aware that this method is horrendously inefficient.  The issue is that every swap generates an entirely new list.  Such manipulations should be done on a mutable structure; here an Array or Vector would be appropriate. The changes to the code are easy:

BubbleSort := proc(L::list(numeric))
local A, n, k, m;
    A := Array(L);
    n := upperbound(A,1);
    for k from 0 to n-2 do
        for m from 1 to n-k-1 do
            if A[m] > A[m+1] then
                # swap elements at indices m, m+1
                (A[m],A[m+1]) := (A[m+1],A[m]);
            end if;
        od;
    od;
    convert(A, list);
end proc:

To expand on acer's response, there are two usages of the uses keyword:  uses DocumentTools and uses DT=DocumentTools.  The former makes all the exports of DocumentTools available in the procedure (or module).  The latter provides a shorthand that expands subsequent uses of DT to DocumentTools.  While the former may be more convenient, if you unintentionally use an export of DocumentTools the result may not be what you expect. Further, if at a later date new exports are added to DocumentTools, there may be a conflict with your code. Unless it is throwaway code, I invariably use the second form; I find it safer and clearer.  A minor downside with using the second form is that mint (Maple's syntax checker) will throw occasional nags about the shortname being undeclared.

Curiously, the issue doesn't seem to be due to the attempted creation of the MutableSet, but rather the evaluation of the expression in the seq.  That is

CodeTools:-Usage(seq(CodeTools:-Usage([seq(C[i+1],i=1..N-1)]):
memory used=212.87MiB, alloc change=0 bytes, cpu time=6.32s, real time=5.56s, gc time=1.36s

But the following doesn't finish in a reasonable time:

CodeTools:-Usage(seq(CodeTools:-Usage([seq(C[i+1]-C[i],i=1..N-1)]):

Will submit this as a bug.

.

@tomleslie I'm not seeing the basis for the simple expression.  Consider the case when n=2.  The correct answer is clearly 2, but the expression gives 3. Regardless, the answer for the OP's question has to be an integer.

@Rim It would be useful to post these equations in an accessible manner; retyping from a picture is error prone and tedious.  Does Simplify mean something different than simplify?

 

@vv Better would be n -> mods(n+1,3), or the inert expression %mods(n+1,3).

@Kitonum Expanding on that,

(**) y1 := rsolve({b(n)+b(n-1)+b(n-2)=0, b(0)=1, b(1)=-1, b(2)=0}, b(n)):
(**) y2 := evalc(y1);
                                                         2 n Pi         1/2     2 n Pi
                                               y2 := cos(------) - 1/3 3    sin(------)
                                                           3                      3

(**) y3 := expand(subs(n = 3*j+k, y2)):
(**) y4 := simplify(y3) assuming j :: integer;
                                                           1/2     2 Pi k        2 Pi k
                                               y4 := -1/3 3    sin(------) + cos(------)
                                                                     3             3
(**) seq(eval(y4, k=kk), kk=0..2);
                                                               1, -1, 0

On the other hand, I think it is more convincing to solve for b(n) as b(n) = -b(n-1) - b(n-2) and then compute the results manually.

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