Joe Riel

9660 Reputation

23 Badges

20 years, 20 days

MaplePrimes Activity


These are replies submitted by Joe Riel

By normal Maple instructions I believe you mean, among other things, the use of the assignment operator (:=).   That cannot be done because the Maple assignment operator is not a first-order expression (with luck I'm using that term correctly).  That is, one cannot pass an expression with an assignment operator around as would be necessary to pass it to dsolve.   Maple assignments are statements that are executed.  The usual way to get around that is to pass a procedure that does the assignment to dsolve.  There are performance reasons that that is not supported.  The event handling is done in compiled code and requiring it to handle callbacks to Maple library code would be expensive.  

It may be possible to extend dsolve's event loop to handle compilable Maple procedures in the actions, however, that would not allow a table structure, though it would allow an rtable structure.  Consequently you'd only be able to save so many points---upto the allocated size of the rtable.

The help page could be better.  I'll submit a change request for an example using discrete variables.

 

Querying and setting kernelopts stuff would be nice. I can see the advantage of being able to do this without affecting the worksheet.  There is a trade-off in that saving the worksheet doesn't save the settings; I suppose one could provide a means to insert the commands that assign the current settings into the worksheet.

Quite a few of the settings in interface don't apply to Standard, however, being able to easily change some, say verboseproc, might be nice. It's not clear how a maplet would improve things, unless it could be launched more easily (and nearly as quickly) as typing the command. 

You are welcome.  Thank you for an excellent follow-up question.

You are welcome.  Thank you for an excellent follow-up question.

Yes, that is a completely safe use.  Technically the name title should be right-quoted so that this would work even if you had assigned a value to a global variable named title. Also safe would be

test2 := proc(txt)
uses setoptions = plots:-setoptions;
    setoptions('title' = txt);
end proc:

Not safe is

test3 := proc(txt)
uses plots;
   setoptions('title' = txt)
end proc:

The reason that is not safe is that the statetment `uses plots' makes any of the exports in plots available for use in the procedure.  If txt were an export of plots, this code would not work.  Just because txt (or any symbol) is not an export now does not mean that a future version of plots might not have such an export.  To see that this could be an issue, substitute `init' (which is an export of plots) for txt:

test4 := proc(init)
uses plots;
   setoptions('title' = init)
end proc:

That code does not work because in the body of the procedure the occurrence of init is replaced with the init export of plots and not the parameter.  So if you wrote the code this way and then upgraded to a version of Maple in which plots exported txt (admittedly unlikely), your code would fail and it would probably not be immediately clear why. If plots exported the symbol `title' it would also fail, though you can avoid that by using ':-title' (right quoted for protection).

The way I prefer to use uses is to assign a shortcut for the package name (for the plots package, which has a nice short name, I wouldn't bother).  I also prepend a percent sign to the abbreviation.  The reason for that is to remind me that that symbol in the source code is a `uses' abbreviation and not a real symbol. Note that the interpreted procedure does not contain a uses statement and all uses of %ST are expanded to StringTools.

test5 := proc(txt)
uses %ST = StringTools;
    %ST:-HasAlpha(txt);
end proc:
   

Yes, that is a completely safe use.  Technically the name title should be right-quoted so that this would work even if you had assigned a value to a global variable named title. Also safe would be

test2 := proc(txt)
uses setoptions = plots:-setoptions;
    setoptions('title' = txt);
end proc:

Not safe is

test3 := proc(txt)
uses plots;
   setoptions('title' = txt)
end proc:

The reason that is not safe is that the statetment `uses plots' makes any of the exports in plots available for use in the procedure.  If txt were an export of plots, this code would not work.  Just because txt (or any symbol) is not an export now does not mean that a future version of plots might not have such an export.  To see that this could be an issue, substitute `init' (which is an export of plots) for txt:

test4 := proc(init)
uses plots;
   setoptions('title' = init)
end proc:

That code does not work because in the body of the procedure the occurrence of init is replaced with the init export of plots and not the parameter.  So if you wrote the code this way and then upgraded to a version of Maple in which plots exported txt (admittedly unlikely), your code would fail and it would probably not be immediately clear why. If plots exported the symbol `title' it would also fail, though you can avoid that by using ':-title' (right quoted for protection).

The way I prefer to use uses is to assign a shortcut for the package name (for the plots package, which has a nice short name, I wouldn't bother).  I also prepend a percent sign to the abbreviation.  The reason for that is to remind me that that symbol in the source code is a `uses' abbreviation and not a real symbol. Note that the interpreted procedure does not contain a uses statement and all uses of %ST are expanded to StringTools.

test5 := proc(txt)
uses %ST = StringTools;
    %ST:-HasAlpha(txt);
end proc:
   
> y := sin(3*t) + 3*t*cos(3*t); 
                                  y := sin(3 t) + 3 t cos(3 t)

> Y := inttrans[laplace](y,t,s);
                                                   2
                                                6 s
                                         Y := ---------
                                                2     2
                                              (s  + 9)

(post edit): corrected y to match OP.

Yeah, I noticed that.  The basic loop is pretty much identical, even the choice of local names and the titles posts (ignoring my misspelling).

Yeah, I noticed that.  The basic loop is pretty much identical, even the choice of local names and the titles posts (ignoring my misspelling).

Quicker than mine (yours ran in 1.44 seconds on my machine), which isn't surprising since I used procedure calls in the loop. 

Quicker than mine (yours ran in 1.44 seconds on my machine), which isn't surprising since I used procedure calls in the loop. 

You must not have written particularly efficient Maple code.  Here is my first attempt, which ran in 2.5 seconds (and took me about five minutes to write):

IsLychral := proc(n)
local m;
    m := n;
    to 50 do
        m := m + Reverse(m);
        if IsPalindrome(m) then
            return false;
        end if;
    end do;
    return true;
end proc:

Reverse := proc(n)
option cache;
uses ST = StringTools;
    sscanf(ST:-Reverse(convert(n,'string')), "%d")[]
end proc:

IsPalindrome := proc(n)
option cache;
uses ST = StringTools;
    if length(n)::even
    and modp(n,11) <> 0 then
        return false;
    else
        return ST:-IsPalindrome(convert(n,'string'));
    end if;
end proc:
time(nops(select(IsLychral, [seq(1..10\000)])));
                                          2.460

I got 249.  Is that correct?

You must not have written particularly efficient Maple code.  Here is my first attempt, which ran in 2.5 seconds (and took me about five minutes to write):

IsLychral := proc(n)
local m;
    m := n;
    to 50 do
        m := m + Reverse(m);
        if IsPalindrome(m) then
            return false;
        end if;
    end do;
    return true;
end proc:

Reverse := proc(n)
option cache;
uses ST = StringTools;
    sscanf(ST:-Reverse(convert(n,'string')), "%d")[]
end proc:

IsPalindrome := proc(n)
option cache;
uses ST = StringTools;
    if length(n)::even
    and modp(n,11) <> 0 then
        return false;
    else
        return ST:-IsPalindrome(convert(n,'string'));
    end if;
end proc:
time(nops(select(IsLychral, [seq(1..10\000)])));
                                          2.460

I got 249.  Is that correct?

I would put it the other way: the use statement is a shortcut for the :- operator.  That is, use allows you to reference the module one time and thus access any of its exports.  It is easier than writing the full name (modulename:-exportname) but has hidden dangers.  For example, a module might have a lot of exports, some you don't want to locally bind.  A safer form is the equation:

use exportname = somemodule:-exportname in
     exportname(...); ... ;
end use

It is never correct to use the with command in a procedure.  See the help page for with on this.

First 123 124 125 126 127 128 129 Last Page 125 of 195