acer

32333 Reputation

29 Badges

19 years, 320 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

For me, the most interesting bit of the above post is the methodology of programmatically importing data from tables in HTML files into a Maple session.

The use of StringTools:-Metaphone looks fun, in an over-the-top way.

I look forward to seeing the way the Sockets package was used to grab the HTML directly from the remote server. See also here.

For those who would wish to fully automate these tasks (to grab, manupulate, and analyze web-published data that changes often), such methods could be very useful.

acer

Ok, thanks. There is something going on with print of a proc from within a procedure, but I'm not sure exactly what.

I got the following to work, in the Standard GUI in Linux,

mint := proc(f,extras::string:="")
local fname,k,oldiface;
   fname := "/tmp/foo";
   oldiface := interface('verboseproc');
   interface('verboseproc'=3);
   writeto(fname);
   printf("%a := ", f);
   printf("%a",eval(f));
   printf(":\n");
   writeto(terminal):
   fclose(fname);
   interface('verboseproc'=oldiface);
   k:=ssystem(cat("/usr/local/maple/maple12.01/bin/mint ",extras," ",fname));
   if k[1]>=0 then printf("%s",k[2]); end if;
   NULL; 
end proc:

mint(`convert/CompSeq`);

It could be made nicer, by using StringTools to Drop the mint preamble text in the 2nd operand of the result from ssystem.

acer

Thanks Alejandro,

Does it work in the Standard GUI for you, if you set interface('verboseproc'=3) outside of the procedure?

Is it a surprise to anyone else, if verboseproc could not be set inside a proc in a Standard worksheet?

acer

It's a consequence of the module's having `option package`.

Without `option package`, one can assign to the export without having first unprotected it. In that case, issuing `with` on the module causes a Warning (but succeeds).

> restart:
> myD:=module() option package; export D; end module:
> with(myD);
                                      [D]
> D:=4: 17*D;
Error, attempting to assign to `D` which is protected
                                     17 D
 
> restart:
> myD:=module() export D; end module:
> with(myD);
Warning, myD is not a correctly formed package - option `package' is missing
                                      [D]

> D:=4: 17*D;
                                      68
It wasn't actually due to the fact that global :-D is protected.
> restart:
> myG:=module() option package; export G; end module:
> with(myG):
> G:=4;
Error, attempting to assign to `G` which is protected

> restart:
> myG:=module() export G; end module:
> with(myG):
Warning, myG is not a correctly formed package - option `package' is missing
> G:=4;
                                    G := 4

I guess that the idea is that one would want package exports (but not all other modules' exports) to be protected. Discounting the Warning message, there is some flexibility.

An alternative is to use bind directly,

> restart:
> myD:=module() export D; end module:

> bind(myD:-D);
                                       D
 
> D:=4: 17*D;
                                      68
 
> :-D(sin);
                                      cos
> convert(diff(f(x),x),:-D);
                                    D(f)(x)
 
> eval(%,f=tan);
                                            2
                                  1 + tan(x)

acer

It's a consequence of the module's having `option package`.

Without `option package`, one can assign to the export without having first unprotected it. In that case, issuing `with` on the module causes a Warning (but succeeds).

> restart:
> myD:=module() option package; export D; end module:
> with(myD);
                                      [D]
> D:=4: 17*D;
Error, attempting to assign to `D` which is protected
                                     17 D
 
> restart:
> myD:=module() export D; end module:
> with(myD);
Warning, myD is not a correctly formed package - option `package' is missing
                                      [D]

> D:=4: 17*D;
                                      68
It wasn't actually due to the fact that global :-D is protected.
> restart:
> myG:=module() option package; export G; end module:
> with(myG):
> G:=4;
Error, attempting to assign to `G` which is protected

> restart:
> myG:=module() export G; end module:
> with(myG):
Warning, myG is not a correctly formed package - option `package' is missing
> G:=4;
                                    G := 4

I guess that the idea is that one would want package exports (but not all other modules' exports) to be protected. Discounting the Warning message, there is some flexibility.

An alternative is to use bind directly,

> restart:
> myD:=module() export D; end module:

> bind(myD:-D);
                                       D
 
> D:=4: 17*D;
                                      68
 
> :-D(sin);
                                      cos
> convert(diff(f(x),x),:-D);
                                    D(f)(x)
 
> eval(%,f=tan);
                                            2
                                  1 + tan(x)

acer

> convert(simplify(diff(sqrt(u(x)^2),x)),abs) assuming u(x)::real;
                                     /d      \
                                u(x) |-- u(x)|
                                     \dx     /
                                --------------
                                   | u(x) |
 
> PDEtools:-declare(u(x));
                        u(x) will now be displayed as u
 
> convert(simplify(diff(sqrt(u(x)^2),x)),abs) assuming u(x)::real;
                                    u u[x]
                                    ------
                                    | u |

acer

I agree with you that the task of wholly scripted generation of plots (in any interface of Maple) is important. As far as I know, that is not possible (in any interface) if the plot must have typeset 2D Math and be exported as bmp/gif/jpeg. For some people, the bit about it being wholly scripted is important.

The statement that commandline interface is not "intended" for plotting reads as doublethink for me.

But it could be true that there is no secret, hidden command to get the desired effects. In the commandline interface, plot will eventually call INTERFACE_PLOT. I suspect that is a call to something which is not a Library function, nor a kernel built-in, but rather a function of the interface itself. In Standard, there likely is java code which does the rest of the work, and in commandline it is something inside the cmaple binary.

Trying to fool the commandline interface, by some crude assignments like the following, didn't bypass anything.

IsWorksheetInterface():=true:
Plot:-CheckStandardInterface(('feature') = "caption"):=true:

Now consider, if the commandline interface can fire up the java runtime in order to throw up graphical plots when the plotdevice is set to 'maplets' (and indeed it can and does!) then it could in principle start it up to access Standard's plot export functions too. It should be fixable.

acer

I agree with you that the task of wholly scripted generation of plots (in any interface of Maple) is important. As far as I know, that is not possible (in any interface) if the plot must have typeset 2D Math and be exported as bmp/gif/jpeg. For some people, the bit about it being wholly scripted is important.

The statement that commandline interface is not "intended" for plotting reads as doublethink for me.

But it could be true that there is no secret, hidden command to get the desired effects. In the commandline interface, plot will eventually call INTERFACE_PLOT. I suspect that is a call to something which is not a Library function, nor a kernel built-in, but rather a function of the interface itself. In Standard, there likely is java code which does the rest of the work, and in commandline it is something inside the cmaple binary.

Trying to fool the commandline interface, by some crude assignments like the following, didn't bypass anything.

IsWorksheetInterface():=true:
Plot:-CheckStandardInterface(('feature') = "caption"):=true:

Now consider, if the commandline interface can fire up the java runtime in order to throw up graphical plots when the plotdevice is set to 'maplets' (and indeed it can and does!) then it could in principle start it up to access Standard's plot export functions too. It should be fixable.

acer

Don't both Axel's and Alec's methods simply create new lists (via `map`) and overwrite the argument name with that? That's not much different from overwriting the name L one level higher with  the assignment L:=newvalues(L). Either way, new lists get created, which is unnecessary creation of structures that will need to get garbage collected.

As far as I know, substituting into a list also does a list copy (although it may render the original immediately garbage-collectible). It too is inefficient and unnecessarily produces garbage.

Perhaps you could use a table for this, as an efficiently mutable data structure? Or an Array, if the number of elements is fixed.

If the task is a highly recursive one then efficiency issues (such as the cost of the extra garbage collection of the unnecessary data structures) may make a big impact on performance.

By "great shortcut" did you mean that you found it easier to code, using side-effects on list argument names, or that you found it ran faster? Could it not be done easily with tables or Arrays, with extra saving to kernelopts(bytesused)?

acer

Don't both Axel's and Alec's methods simply create new lists (via `map`) and overwrite the argument name with that? That's not much different from overwriting the name L one level higher with  the assignment L:=newvalues(L). Either way, new lists get created, which is unnecessary creation of structures that will need to get garbage collected.

As far as I know, substituting into a list also does a list copy (although it may render the original immediately garbage-collectible). It too is inefficient and unnecessarily produces garbage.

Perhaps you could use a table for this, as an efficiently mutable data structure? Or an Array, if the number of elements is fixed.

If the task is a highly recursive one then efficiency issues (such as the cost of the extra garbage collection of the unnecessary data structures) may make a big impact on performance.

By "great shortcut" did you mean that you found it easier to code, using side-effects on list argument names, or that you found it ran faster? Could it not be done easily with tables or Arrays, with extra saving to kernelopts(bytesused)?

acer

I didn't understand the original question correctly, sorry. I don't know a way to get typeset greek symbols (or 2D Math) into a bmp/gif/jpeg image of a plot directly from the commandline interface, using only scripted Maple.

acer

I didn't understand the original question correctly, sorry. I don't know a way to get typeset greek symbols (or 2D Math) into a bmp/gif/jpeg image of a plot directly from the commandline interface, using only scripted Maple.

acer

Taking your plot above as an example, in the Standard GUI I might do it something like this,

plotsetup(ps,plotoutput="/tmp/foo.ps"):

plot(sin(x),x=-Pi..Pi,caption=typeset(y=sin(x),", ",-Pi < x,`< `,Pi));

That produces the plot in the output file, with the greek symbol for pi, and no mouse action required.

It would be nice the mathematical typsetting power separated away from Maple's semantic preconceptions. See above, the trick needed to typeset pi &lt; x &lt; pi.

I don't know of a way entirely programatically to get the symbol for pi in the output file from the commandline interface, without resorting to textplot and changing the font in the plot call. In that interface, one can also issue plotsetup(maplets) and then export with the mouse from the pop-up plotting Maplet's menu. But it's not the same.

acer

Taking your plot above as an example, in the Standard GUI I might do it something like this,

plotsetup(ps,plotoutput="/tmp/foo.ps"):

plot(sin(x),x=-Pi..Pi,caption=typeset(y=sin(x),", ",-Pi < x,`< `,Pi));

That produces the plot in the output file, with the greek symbol for pi, and no mouse action required.

It would be nice the mathematical typsetting power separated away from Maple's semantic preconceptions. See above, the trick needed to typeset pi &lt; x &lt; pi.

I don't know of a way entirely programatically to get the symbol for pi in the output file from the commandline interface, without resorting to textplot and changing the font in the plot call. In that interface, one can also issue plotsetup(maplets) and then export with the mouse from the pop-up plotting Maplet's menu. But it's not the same.

acer

I'm not sure why maplemint is still a Library routine, when it is not kept as up-to-date as the standalone executable `mint` and also does not have as many options.

Perhaps the maplemint command should be changed, to simply call out to mint. Here's a really crude Linux-specific version of that, just to illustrate.

> mint := proc(f,extras::string:="")
> local fname,oldiface;
>   fname := "/tmp/foo";
>   oldiface := interface('verboseproc');
>   interface('verboseproc'=3);
>   writeto(fname);
>   printf("%a := ", f);
>   print(f);
>   printf(":\n");
>   writeto(terminal):
>   fclose(fname);
>   interface('verboseproc'=oldiface);
>   system(cat("/usr/local/maple/maple12.01/bin/mint ",extras," ",fname));
>   NULL;
> end proc:
>
> mint(`convert/CompSeq`);
    |\^/|      Maple 12 Diagnostic Program
._|\|   |/|_.  Copyright (c) Maplesoft, a division of Waterloo Maple Inc. 2007
 \  MINT   /   All rights reserved. Maple is a trademark of
 <____ ____>   Waterloo Maple Inc.
      |
Procedure convert/CompSeq( e1 ) on lines 1 to 77
  These local variables were used but never assigned a value:  result
>
> mint(`convert/CompSeq`,"-i 3");
    |\^/|      Maple 12 Diagnostic Program
._|\|   |/|_.  Copyright (c) Maplesoft, a division of Waterloo Maple Inc. 2007
 \  MINT   /   All rights reserved. Maple is a trademark of
 <____ ____>   Waterloo Maple Inc.
      |
Nested Anonymous Procedure proc( s ) on lines 44 to 56
  There are 2 equations used as statements on lines 50, 54
  Global names usage:  `&:=`, `&function`
Procedure convert/CompSeq( e1 ) on lines 1 to 77
  These local variables were used but never assigned a value:  result
  Global names usage:  `&%`, `&%%`, `&%%%`, `&ERROR`, `&RETURN`, `&args`,
      `&break`, `&done`, `&expseq`, `&for`, `&function`, `&hashtab`, `&if`,
      `&local`, `&next`, `&proc`, `&quit`, `&read`, `&save`, `&series`,
      `&statseq`, `&stop`, CompSeq, globals, locals, params, `||enate`
Global names used in this file:  `convert/CompSeq`

There are many ways to improve the above, naturally. The call to `system` could be replaced by an appropriate `ssystem` call, so that the ascii description at the top of mint's output could be removed. And it could be platform independent, etc, etc.

acer

First 508 509 510 511 512 513 514 Last Page 510 of 591