Preben Alsholm

13653 Reputation

22 Badges

19 years, 309 days

MaplePrimes Activity


These are replies submitted by Preben Alsholm

I wasn't aware of your previous posting until acer pointed it out.
Now I realize that you already received answers from several highly competent people on the very same topic.

@sursumCorda I tried  besides the E result from yesterday in separate worksheets.
I used the same x and y as yesterday.
Here is the dollar code and also the results for both:
 

read "C:/Users/pkals/Desktop/tempxy.m";
x[1..10]; # Just a test

Edollar:=CodeTools:-Usage(f~(x,` $`,y),iterations=10):
# Edollar: memory used=0.62GiB, alloc change=1.21GiB, cpu time=42.60s, real time=10.48s, gc time=37.04s
# E:       memory used=0.62GiB, alloc change=0.96GiB, cpu time=42.25s, real time=9.81s, gc time=37.36s
# Yesterday: E: memory used=0.62GiB, alloc change=0.99GiB, cpu time=38.94s, real time=9.63s, gc time=34.31s

As I see it if there is a real difference then it's Edollar being worse.
In any case I can't conclude that the one is faster than the other.
In fact I think that before executing f~ the dollar is taken away somehow. Try this were a and b are just names:
 

f(a, ` $`,b); # No ~
lprint(%);
f~(a, ` $`,b); # with ~
lprint(%);

 

@sursumCorda  Yes, I did a test consisting in first generating x and y. Then saving them to my Desktop as an .m file.

My Maple is set up to use a new engine for every worksheet.
So in two different worksheets I did elementwise (E) and zip (Z) separately.
Here is the E:
 

read "C:/Users/pkals/Desktop/tempxy.m";
x[1..10]; # Just a check
E:=CodeTools:-Usage(f~(x,y),iterations=10):
E alone: memory used=0.62GiB, alloc change=0.99GiB, cpu time=38.94s, real time=9.63s, gc time=34.31s

and here is Z:

read "C:/Users/pkals/Desktop/tempxy.m";
x[1..10]; # Just a check
Z:=CodeTools:-Usage(zip(f,x,y),iterations=10):
# Z alone: memory used=0.62GiB, alloc change=0.96GiB, cpu time=44.97s, real time=11.24s, gc time=39.90s

 

Did you expect elementwise and zip to take the almost exact same time?
They don't look that way to me.
Your own results above don't look very different to me.
I tried myself:
 

restart;
x := combinat:-randperm(10^7):
y := combinat:-randperm(10^7):
E:=CodeTools:-Usage(f~(x,y),iterations=10):
# E: memory used=0.62GiB, alloc change=1.18GiB, cpu time=44.64s, real time=10.22s, gc time=39.70s
Z:=CodeTools:-Usage(zip(f,x,y),iterations=10):
# Z: memory used=0.52GiB, alloc change=72.29MiB, cpu time=15.26s, real time=6.16s, gc time=10.58s
evalb(E=Z); #true

Incidentally to me your own results about elementwise and map don't appear wildly different either:
https://www.mapleprimes.com/questions/235932-Why-Is-Map-Slower-Than-

Surely the uses of map and `~` have some overlap.
But their respective domains of operation are different.
Here are two examples where `~` doesn't work:
 

map(simplify,sqrt(a^2)+sqrt(b^2)) assuming a>0,b<0;
f~([a,b],[a,b,c]); #error
map2(f,[a,b],[a,b,c]);

 

@nm On purpose I didn't do that becase it won't have any effect in RootOF.
Notice this:
 

S4:=singular(1/(cos(x)*sin(x)*Psi(1/x)),x);
subs(_Z=ZZZZZ,{S4}); # The substitution is made yes, but:
%; # back to _Z
RootOf(sin(x),x); # Look at the result

For more look at ?RootOf in particular the examples.

_Z is protected exactly because of its use here:
Try assigning to _Z as in _Z:=1234;
Also try:
 

restart;
local _Z;
RootOf(sin(x),x);

Notice the global version :-_Z in RootOf

@nm Here is a somewhat more automated approach. As of now it only handles N,NN, and Z.
Notice that assign is only used once.

restart;
#S4:=singular(1/(cos(x)*sin(x))+Psi(1/x),x);
S4:=singular(1/(cos(x))+Psi(1/x),x); 
idts:=indets([S4],`local`);
S:=convert~(idts,string);
idts;

resZ,resNoZ:=selectremove(s->evalb(s[2]="Z"),S);
resN,resNoN:=selectremove(s->evalb(s[2]="N"),resNoZ);
resNN,resNoNN:=selectremove(s->evalb(s[2..3]="NN"),resN);
numZ:=numelems(resZ);
numNN:=numelems(resNN);
numN:=numelems(resNoNN);
`union`(idts[1..numN]=~N,idts[numN+1..numNN]=~NN,idts[numN+numNN+1..numZ+numNN]=~Z) ;
assign(%);
S4;


 

@nm I did something that in your case will look like this:

restart;

S4:=singular(1/(cos(x)*sin(x))+Psi(1/x),x);
idts:=indets([S4],`local`);

idts[1]=~NN;

assign(%);

idts;

idts[-2..-1]=~Z; # Don't use _Z

assign(%);

idts;

S4;

 

@Axel Vogt Yes indeed. I was looking into that myself. I was first thinking of making use of StringTools.
But turning names into strings, manipulating them, and then parsing makes the variables global.
But here is another ad hoc example:
 

restart;
S1:=singular(Psi(1/x)*1/sin(x));
S2:=singular(Psi(1/x)*x/sin(x));
S3:=singular(Psi(1/x)*x^2/sin(x));
idts:=indets(`union`(S1,S2,S3),`local`);
idts[1..3]=~NN;
assign(%);
idts;
idts[-3..-1]=~Z; # Don't use _Z
assign(%);
idts;
`union`(S1,S2,S3);

To my point about not using StringTools here is the obstacle:
In my original idts above (before any use of assign) you can try:
 

idts:=indets(`union`(S1,S2,S3),`local`);
S:=convert~(idts,string);
parse~(S);
select(type,%,`local`); #Empty

 

@Carl Love I quite agree. I don't get those warnings though. My setting for warnlevel is 3 (the default).
I wonder why nm gets them and I don't.

convert(179.9087476,'units','arcdeg','rad');

 

@nm You can submit a bug report directly from MaplePrimes:
Go to the top of the page just under the MaplePrimes heading.
There you find the horizontal list starting with Questions and ending with More.
Click on More and you will see "Submit Software Change Request".
Software Change Request (SCR) is a euphemism for bug report.

Are you able to do anything at all to begin with? Like just typing 2+2; and getting 4 when you press enter.
If not it might be a license issue. You could talk to the person at your school who takes care of such matters.

@abert Maybe another example can throw some light on this.
 

restart;
q:=proc() local z; z end proc;
q(); # returns an 'escaped' local
%-z; # z - z
z1:=q();
z1;
addressof(z1);
addressof(z);

You see that there are two different names: the global z and the escaped local also printed as z.
You could continue with this:
 

z2:=q();
addressof(z2);
z-z1-z2; # z-z-z

The idea of creating local names for use in some context is actually exemplified in a very old and undocumented procedure called `tools/gensym` ("generate (local) symbol"):
 

showstat(`tools/gensym`);

There is correspondingly this one:
 

showstat(`tools/genglobal`);

Thus if you continue with this:
 

z3:=`tools/gensym`(z);
z-z1-z2-z3; # z-z-z-z
z4:=`tools/genglobal`(z1);
z-z1-z2-z3-z4; # z-z-z-z-z0

Looking at the addresses of the global z1 and the loval it evalutes to:
 

addressof('z1');
addressof(z1);

They are different.

First 11 12 13 14 15 16 17 Last Page 13 of 229